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 org.jikesrvm.VM;
016import org.jikesrvm.classloader.SpecializedMethodManager;
017
018/**
019 * Layout the TIB (Type Information Block).
020 *  <pre>
021 *  --------------------------------------------------------------------------------------------
022 *                        Type Information Block (TIB) Layout Constants
023 *  --------------------------------------------------------------------------------------------
024 *
025 *                                 Object[] (type info block)        RVMType (class info)
026 *                                    /                              /
027 *            +--------------------+              +--------------+
028 *            |    TIB pointer     |              |  TIB pointer |
029 *            +--------------------+              +--------------+
030 *            |      status        |              |    status    |
031 *            +--------------------+              +--------------+
032 *            |      length        |              |    field0    |
033 *            +--------------------+              +--------------+
034 *    TIB:  0:|       type         +------------&gt; |     ...      |
035 *            +--------------------+              +--------------+
036 *          1:|   superclass ids   +--&gt;           |   fieldN-1   |
037 *            +--------------------+              +--------------+
038 *          2:|  implements trits  +--&gt;
039 *            +--------------------+
040 *          3:|  array element TIB +--&gt;
041 *            +--------------------+
042 *          4:|     iTABLES/IMT    +--&gt;
043 *            +--------------------+
044 *          5:|  specialized 0     +--&gt;
045 *            +--------------------+
046 *            |       ...          +--&gt;
047 *            +--------------------+
048 *         V0:|  virtual method 0  +-----+
049 *            +--------------------+     |
050 *            |       ...          |     |                         INSTRUCTION[] (machine code)
051 *            +--------------------+     |                        /
052 *       VN-1:| virtual method N-1 |     |        +--------------+
053 *            +--------------------+     |        |  TIB pointer |
054 *                                       |        +--------------+
055 *                                       |        |    status    |
056 *                                       |        +--------------+
057 *                                       |        |    length    |
058 *                                       |        +--------------+
059 *                                       +-------&gt;|    code0     |
060 *                                                +--------------+
061 *                                                |      ...     |
062 *                                                +--------------+
063 *                                                |    codeN-1   |
064 *                                                +--------------+
065 *
066 * </pre>
067 */
068public final class TIBLayoutConstants {
069
070  /** Number of slots reserved for interface method pointers. */
071  public static final int IMT_METHOD_SLOTS = VM.BuildForIMTInterfaceInvocation ? 29 : 0;
072
073  /** First slot of TIB points to RVMType (slot 0 in above diagram). */
074  public static final int TIB_TYPE_INDEX = 0;
075
076  /** A vector of ids for classes that this one extends. See
077   DynamicTypeCheck.java */
078  public static final int TIB_SUPERCLASS_IDS_INDEX = TIB_TYPE_INDEX + 1;
079
080  /** Does this class implement the ith interface? See DynamicTypeCheck.java */
081  public static final int TIB_DOES_IMPLEMENT_INDEX = TIB_SUPERCLASS_IDS_INDEX + 1;
082
083  /** The TIB of the elements type of an array (may be {@code null} in fringe cases
084   *  when element type couldn't be resolved during array resolution).
085   *  Will be {@code null} when not an array.
086   */
087  public static final int TIB_ARRAY_ELEMENT_TIB_INDEX = TIB_DOES_IMPLEMENT_INDEX + 1;
088
089  /**
090   * A pointer to either an ITable or InterfaceMethodTable (IMT)
091   * depending on which dispatch implementation we are using.
092   */
093  public static final int TIB_INTERFACE_DISPATCH_TABLE_INDEX = TIB_ARRAY_ELEMENT_TIB_INDEX + 1;
094
095  /**
096   *  A set of 0 or more specialized methods used in the VM such as for GC scanning.
097   */
098  public static final int TIB_FIRST_SPECIALIZED_METHOD_INDEX = TIB_INTERFACE_DISPATCH_TABLE_INDEX + 1;
099
100  /**
101   * Next group of slots point to virtual method code blocks (slots V1..VN in above diagram).
102   */
103  public static final int TIB_FIRST_VIRTUAL_METHOD_INDEX = TIB_FIRST_SPECIALIZED_METHOD_INDEX + SpecializedMethodManager.numSpecializedMethods();
104
105  /**
106   * Special value returned by RVMClassLoader.getFieldOffset() or
107   * RVMClassLoader.getMethodOffset() to indicate fields or methods
108   * that must be accessed via dynamic linking code because their
109   * offset is not yet known or the class's static initializer has not
110   * yet been run.
111   *
112   *  We choose a value that will never match a valid jtoc-,
113   *  instance-, or virtual method table- offset. Short.MIN_VALUE+1 is
114   *  a good value:
115   *
116   *  <ul>
117   *  <li>the jtoc offsets are aligned and this value should be
118   *  too huge to address the table</li>
119   *  <li>instance field offsets are always &gt;= -4 (TODO check if this is still correct)</li>
120   *  <li>virtual method offsets are always positive w.r.t. TIB pointer</li>
121   *  <li>fits into a PowerPC 16bit immediate operand</li>
122   *   </ul>
123   */
124  public static final int NEEDS_DYNAMIC_LINK = Short.MIN_VALUE + 1;
125
126  private TIBLayoutConstants() {
127    // prevent instantiation
128  }
129
130}