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