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