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.jikesrvm.objectmodel;
014    
015    import org.jikesrvm.VM;
016    import org.jikesrvm.SizeConstants;
017    import org.jikesrvm.mm.mminterface.MemoryManagerConstants;
018    import org.vmmagic.unboxed.Offset;
019    import org.vmmagic.unboxed.Word;
020    
021    /**
022     * Constants for the JavaHeader.
023     *
024     * @see ObjectModel
025     */
026    public interface JavaHeaderConstants extends SizeConstants {
027    
028      /** Number of bytes in object's TIB pointer */
029      int TIB_BYTES = BYTES_IN_ADDRESS;
030      /** Number of bytes indicating an object's status */
031      int STATUS_BYTES = BYTES_IN_ADDRESS;
032    
033      int ALIGNMENT_MASK = 0x00000001;
034      int ALIGNMENT_VALUE = 0xdeadbeef;
035      int LOG_MIN_ALIGNMENT = LOG_BYTES_IN_INT;
036    
037      /**
038       * Number of bytes used to store the array length. We use 64 bits
039       * for the length on a 64 bit architecture as this makes the other
040       * words 8-byte aligned, and the header has to be 8-byte aligned.
041       */
042      int ARRAY_LENGTH_BYTES = VM.BuildFor64Addr ? BYTES_IN_ADDRESS : BYTES_IN_INT;
043    
044      /** Number of bytes used by the Java Header */
045      int JAVA_HEADER_BYTES = TIB_BYTES + STATUS_BYTES;
046      /** Number of bytes used by the GC Header */
047      int GC_HEADER_BYTES = MemoryManagerConstants.GC_HEADER_BYTES;
048      /** Number of bytes used by the miscellaneous header */
049      int MISC_HEADER_BYTES = MiscHeaderConstants.NUM_BYTES_HEADER;
050      /** Size of GC and miscellaneous headers */
051      int OTHER_HEADER_BYTES = GC_HEADER_BYTES + MISC_HEADER_BYTES;
052    
053      /** Offset of array length from object reference */
054      Offset ARRAY_LENGTH_OFFSET = Offset.fromIntSignExtend(-ARRAY_LENGTH_BYTES);
055      /** Offset of the first field from object reference */
056      Offset FIELD_ZERO_OFFSET = ARRAY_LENGTH_OFFSET;
057      /** Offset of the Java header from the object reference */
058      Offset JAVA_HEADER_OFFSET = ARRAY_LENGTH_OFFSET.minus(JAVA_HEADER_BYTES);
059      /** Offset of the miscellaneous header from the object reference */
060      Offset MISC_HEADER_OFFSET = JAVA_HEADER_OFFSET.minus(MISC_HEADER_BYTES);
061      /** Offset of the garbage collection header from the object reference */
062      Offset GC_HEADER_OFFSET = MISC_HEADER_OFFSET.minus(GC_HEADER_BYTES);
063      /** Offset of first element of an array */
064      Offset ARRAY_BASE_OFFSET = Offset.zero();
065    
066      /**
067       * This object model supports two schemes for hashcodes:
068       * (1) a 10 bit hash code in the object header
069       * (2) use the address of the object as its hashcode.
070       *     In a copying collector, this forces us to add a word
071       *     to copied objects that have had their hashcode taken.
072       */
073      boolean ADDRESS_BASED_HASHING = !MemoryManagerConstants.GENERATE_GC_TRACE;
074    
075      /** How many bits in the header are available for the GC and MISC headers? */
076      int NUM_AVAILABLE_BITS = ADDRESS_BASED_HASHING ? 8 : 2;
077    
078      /**
079       * Does this object model use the same header word to contain
080       * the TIB and a forwarding pointer?
081       */
082      boolean FORWARDING_PTR_OVERLAYS_TIB = false;
083    
084      /**
085       * Does this object model place the hash for a hashed and moved object
086       * after the data (at a dynamic offset)
087       */
088      boolean DYNAMIC_HASH_OFFSET = ADDRESS_BASED_HASHING && MemoryManagerConstants.NEEDS_LINEAR_SCAN;
089    
090      /**
091       * Can we perform a linear scan?
092       */
093      boolean ALLOWS_LINEAR_SCAN = true;
094    
095      /**
096       * Do we need to segregate arrays and scalars to do a linear scan?
097       */
098      boolean SEGREGATE_ARRAYS_FOR_LINEAR_SCAN = false;
099    
100      /*
101       * Stuff for address based hashing
102       */ Word HASH_STATE_UNHASHED = Word.zero();
103      Word HASH_STATE_HASHED = Word.one().lsh(8); //0x00000100
104      Word HASH_STATE_HASHED_AND_MOVED = Word.fromIntZeroExtend(3).lsh(8); //0x0000300
105      Word HASH_STATE_MASK = HASH_STATE_UNHASHED.or(HASH_STATE_HASHED).or(HASH_STATE_HASHED_AND_MOVED);
106    
107      int HASHCODE_BYTES = BYTES_IN_INT;
108      Offset HASHCODE_OFFSET = GC_HEADER_OFFSET.minus(HASHCODE_BYTES);
109    
110    }