001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.mmtk.utility.alloc;
014
015 import org.mmtk.utility.Constants;
016
017 import org.vmmagic.unboxed.*;
018 import org.vmmagic.pragma.*;
019
020 /**
021 * This plan implements constants and access methods for meta data
022 * that is embeded in allocation spaces (rather than kept on the
023 * side). The basic idea is that meta data be embeded at a very
024 * coarse power of two granularity for fast access, minimal wastage
025 * and by making the regions coarse, the contiguous meta-data will be
026 * relatively large and thus the probability of L1 conflict misses
027 * will be reduced (as compared with embedding meta-data at the start
028 * of each page which will cause those few cache lines corresponding
029 * to the start of each page to be heavily conflicted).
030 */
031 @Uninterruptible public final class EmbeddedMetaData implements Constants {
032
033 /* The (log of the) size of each region of meta data management */
034 public static final int LOG_BYTES_IN_REGION = 22;
035 public static final int BYTES_IN_REGION = 1 << LOG_BYTES_IN_REGION;
036 private static final Word REGION_MASK = Word.fromIntSignExtend(BYTES_IN_REGION - 1);
037 public static final int LOG_PAGES_IN_REGION = LOG_BYTES_IN_REGION - LOG_BYTES_IN_PAGE;
038 public static final int PAGES_IN_REGION = 1 << LOG_PAGES_IN_REGION;
039
040 /**
041 * Given an address, return the begining of the meta data for the
042 * region containing the address. This is a fast operation because
043 * it only involves masking out low order bits.
044 *
045 * @param address The address whose meta data is sought.
046 * @return The address of the start of the meta data for the meta
047 * region in which the address is located.
048 */
049 @Inline
050 public static Address getMetaDataBase(Address address) {
051 return address.toWord().and(REGION_MASK.not()).toAddress();
052 }
053
054 /**
055 * Given an address, the density (coverage) of a meta data type, and
056 * the granularity (alignment) of the meta data, return the offset
057 * into the meta data the address.
058 *
059 * @param address The address whose meta data offset is sought.
060 * @param logCoverage The log base two of the coverage of the meta
061 * data in question. For example, a value of 4 would indicate a
062 * coverage of 16; one metadata byte for every 16 bytes of data.
063 * @param logAlign The log base two of the aligment or granularity
064 * of the meta-data (it may be arranged in bytes, words, double
065 * words etc).
066 * @return The offset into the meta-data for this region, given the
067 * specified address and coverage and aligment requirements.
068 */
069 public static Extent getMetaDataOffset(Address address,
070 int logCoverage,
071 int logAlign) {
072 return address.toWord().and(REGION_MASK).rshl(logCoverage+logAlign).lsh(logAlign).toExtent();
073 }
074 }