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