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 */
013package org.mmtk.utility;
014
015import org.mmtk.utility.alloc.EmbeddedMetaData;
016import org.mmtk.vm.VM;
017
018/**
019 * MMTk follows the pattern set by Jikes RVM for defining sizes of
020 * primitive types thus:
021 *
022 * <pre>
023 * static final int LOG_BYTES_IN_INT = 2;
024 * static final int BYTES_IN_INT = 1&lt;&lt;LOG_BYTES_IN_INT;
025 * static final int LOG_BITS_IN_INT = LOG_BITS_IN_BYTE + LOG_BYTES_IN_INT;
026 * static final int BITS_IN_INT = 1&lt;&lt;LOG_BITS_IN_INT;
027 * </pre>
028 *
029 */
030public final class Constants {
031
032  /****************************************************************************
033   *
034   * MMTk constants
035   */
036
037  /**
038   *
039   */
040  public static final int INSTANCE_FIELD = 0;
041  public static final int ARRAY_ELEMENT = 1;
042
043
044  /****************************************************************************
045   *
046   * Generic sizes
047   */
048
049  /**
050   *
051   */
052  public static final byte LOG_BYTES_IN_BYTE = 0;
053  public static final int BYTES_IN_BYTE = 1;
054  public static final byte LOG_BITS_IN_BYTE = 3;
055  public static final int BITS_IN_BYTE = 1 << LOG_BITS_IN_BYTE;
056
057  public static final byte LOG_BYTES_IN_MBYTE = 20;
058  public static final int BYTES_IN_MBYTE = 1 << LOG_BYTES_IN_MBYTE;
059
060  public static final byte LOG_BYTES_IN_KBYTE = 10;
061  public static final int BYTES_IN_KBYTE = 1 << LOG_BYTES_IN_KBYTE;
062
063  /****************************************************************************
064   *
065   * Card scanning
066   */
067
068  /**
069   *
070   */
071  public static final boolean SUPPORT_CARD_SCANNING = false;
072  public static final int LOG_CARD_META_SIZE = 2;// each card consumes four bytes of metadata
073  public static final int LOG_CARD_UNITS = 10;  // number of units tracked per card
074  public static final int LOG_CARD_GRAIN = 0;   // track at byte grain, save shifting
075  public static final int LOG_CARD_BYTES = LOG_CARD_UNITS + LOG_CARD_GRAIN;
076  public static final int LOG_CARD_META_BYTES = EmbeddedMetaData.LOG_BYTES_IN_REGION - LOG_CARD_BYTES + LOG_CARD_META_SIZE;
077  public static final int LOG_CARD_META_PAGES = LOG_CARD_META_BYTES - VM.LOG_BYTES_IN_PAGE;
078  public static final int CARD_META_PAGES_PER_REGION = SUPPORT_CARD_SCANNING ? (1 << LOG_CARD_META_PAGES) : 0;
079  public static final int CARD_MASK = (1 << LOG_CARD_BYTES) - 1;
080
081
082  /****************************************************************************
083   *
084   * Java-specific sizes currently required by MMTk
085   *
086   * TODO MMTk should really become independent of these Java types
087   */
088
089  /**
090   *
091   */
092  public static final byte LOG_BYTES_IN_CHAR = 1;
093  public static final int BYTES_IN_CHAR = 1 << LOG_BYTES_IN_CHAR;
094  public static final byte LOG_BITS_IN_CHAR = LOG_BITS_IN_BYTE + LOG_BYTES_IN_CHAR;
095  public static final int BITS_IN_CHAR = 1 << LOG_BITS_IN_CHAR;
096
097  public static final byte LOG_BYTES_IN_SHORT = 1;
098  public static final int BYTES_IN_SHORT = 1 << LOG_BYTES_IN_SHORT;
099  public static final byte LOG_BITS_IN_SHORT = LOG_BITS_IN_BYTE + LOG_BYTES_IN_SHORT;
100  public static final int BITS_IN_SHORT = 1 << LOG_BITS_IN_SHORT;
101
102  public static final byte LOG_BYTES_IN_INT = 2;
103  public static final int BYTES_IN_INT = 1 << LOG_BYTES_IN_INT;
104  public static final byte LOG_BITS_IN_INT = LOG_BITS_IN_BYTE + LOG_BYTES_IN_INT;
105  public static final int BITS_IN_INT = 1 << LOG_BITS_IN_INT;
106
107  public static final int MAX_INT = 0x7fffffff;
108  public static final int MIN_INT = 0x80000000;
109
110  /****************************************************************************
111   *
112   * VM-Specific sizes
113   */
114
115  /**
116   *
117   */
118  public static final byte LOG_BYTES_IN_ADDRESS = VM.LOG_BYTES_IN_ADDRESS;
119  public static final int BYTES_IN_ADDRESS = 1 << LOG_BYTES_IN_ADDRESS;
120  public static final int LOG_BITS_IN_ADDRESS = LOG_BITS_IN_BYTE + LOG_BYTES_IN_ADDRESS;
121  public static final int BITS_IN_ADDRESS = 1 << LOG_BITS_IN_ADDRESS;
122
123  // Note that in MMTk we currently define WORD & ADDRESS to be the same size
124  public static final byte LOG_BYTES_IN_WORD = LOG_BYTES_IN_ADDRESS;
125  public static final int BYTES_IN_WORD = 1 << LOG_BYTES_IN_WORD;
126  public static final int LOG_BITS_IN_WORD = LOG_BITS_IN_BYTE + LOG_BYTES_IN_WORD;
127  public static final int BITS_IN_WORD = 1 << LOG_BITS_IN_WORD;
128
129  public static final byte LOG_BYTES_IN_PAGE = VM.LOG_BYTES_IN_PAGE;
130  public static final int BYTES_IN_PAGE = 1 << LOG_BYTES_IN_PAGE;
131  public static final int LOG_BITS_IN_PAGE = LOG_BITS_IN_BYTE + LOG_BYTES_IN_PAGE;
132  public static final int BITS_IN_PAGE = 1 << LOG_BITS_IN_PAGE;
133
134  /* Assume byte-addressability */
135  public static final byte LOG_BYTES_IN_ADDRESS_SPACE = (byte) BITS_IN_ADDRESS;
136
137  /**
138   * This value specifies the <i>minimum</i> allocation alignment
139   * requirement of the VM.  When making allocation requests, both
140   * <code>align</code> and <code>offset</code> must be multiples of
141   * <code>MIN_ALIGNMENT</code>.
142   *
143   * This value is required to be a power of 2.
144   */
145  public static final byte LOG_MIN_ALIGNMENT = VM.LOG_MIN_ALIGNMENT;
146  public static final int MIN_ALIGNMENT = 1 << LOG_MIN_ALIGNMENT;
147
148  /**
149   * The maximum alignment request the vm will make. This must be a
150   * power of two multiple of the minimum alignment.
151   */
152  public static final int MAX_ALIGNMENT = MIN_ALIGNMENT << VM.MAX_ALIGNMENT_SHIFT;
153
154  /**
155   * The VM will add at most this value minus BYTES_IN_INT bytes of
156   * padding to the front of an object that it places in a region of
157   * memory. This value must be a power of 2.
158   */
159  public static final int MAX_BYTES_PADDING = VM.MAX_BYTES_PADDING;
160
161  /**
162   * The VM will add at most this value minus BYTES_IN_INT bytes of
163   * padding to the front of an object that it places in a region of
164   * memory. This value must be a power of 2.
165   */
166  public static final int ALIGNMENT_VALUE = VM.ALIGNMENT_VALUE;
167}