org.jikesrvm.classloader
Class ClassFileReader

java.lang.Object
  extended by org.jikesrvm.classloader.ClassFileReader
All Implemented Interfaces:
ClassLoaderConstants, Constants, HeapLayoutConstants, ThinLockConstants, TIBLayoutConstants, SizeConstants

public class ClassFileReader
extends Object
implements Constants, ClassLoaderConstants

Support code to parse a DataInputStream in the Java classfile format and create the appropriate instance of an RVMClass or UnboxedType. Also low-level support for our internal constant pool format.


Field Summary
 
Fields inherited from interface org.jikesrvm.Constants
NOT_REACHED, REFLECTION_FPRS_BITS, REFLECTION_FPRS_MASK, REFLECTION_GPRS_BITS, REFLECTION_GPRS_MASK
 
Fields inherited from interface org.jikesrvm.objectmodel.ThinLockConstants
TL_DEDICATED_U16_OFFSET, TL_DEDICATED_U16_SHIFT, TL_LOCK_COUNT_MASK, TL_LOCK_COUNT_SHIFT, TL_LOCK_COUNT_UNIT, TL_LOCK_ID_MASK, TL_LOCK_ID_SHIFT, TL_NUM_BITS_RC, TL_NUM_BITS_STAT, TL_NUM_BITS_TID, TL_STAT_BIASABLE, TL_STAT_FAT, TL_STAT_MASK, TL_STAT_SHIFT, TL_STAT_THIN, TL_THREAD_ID_MASK, TL_THREAD_ID_SHIFT, TL_UNLOCK_MASK
 
Fields inherited from interface org.jikesrvm.SizeConstants
BITS_IN_ADDRESS, BITS_IN_BOOLEAN, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_DOUBLE, BITS_IN_EXTENT, BITS_IN_FLOAT, BITS_IN_INT, BITS_IN_LONG, BITS_IN_OFFSET, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_EXTENT, BYTES_IN_FLOAT, BYTES_IN_INT, BYTES_IN_LONG, BYTES_IN_OFFSET, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BOOLEAN, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_DOUBLE, LOG_BITS_IN_EXTENT, LOG_BITS_IN_FLOAT, LOG_BITS_IN_INT, LOG_BITS_IN_LONG, LOG_BITS_IN_OFFSET, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_BOOLEAN, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_DOUBLE, LOG_BYTES_IN_EXTENT, LOG_BYTES_IN_FLOAT, LOG_BYTES_IN_INT, LOG_BYTES_IN_LONG, LOG_BYTES_IN_OFFSET, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD
 
Fields inherited from interface org.jikesrvm.objectmodel.TIBLayoutConstants
IMT_METHOD_SLOTS, NEEDS_DYNAMIC_LINK, TIB_ARRAY_ELEMENT_TIB_INDEX, TIB_DOES_IMPLEMENT_INDEX, TIB_FIRST_SPECIALIZED_METHOD_INDEX, TIB_FIRST_VIRTUAL_METHOD_INDEX, TIB_INTERFACE_DISPATCH_TABLE_INDEX, TIB_SUPERCLASS_IDS_INDEX, TIB_TYPE_INDEX
 
Fields inherited from interface org.jikesrvm.HeapLayoutConstants
BAD_MAP_COMPRESSION, BOOT_IMAGE_CODE_END, BOOT_IMAGE_CODE_SIZE, BOOT_IMAGE_CODE_START, BOOT_IMAGE_DATA_END, BOOT_IMAGE_DATA_SIZE, BOOT_IMAGE_DATA_START, BOOT_IMAGE_END, BOOT_IMAGE_RMAP_END, BOOT_IMAGE_RMAP_START, MAX_BOOT_IMAGE_RMAP_SIZE, MAXIMUM_MAPPABLE
 
Fields inherited from interface org.jikesrvm.classloader.ClassLoaderConstants
ACC_ABSTRACT, ACC_ANNOTATION, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VOLATILE, APPLICABLE_TO_CLASSES, APPLICABLE_TO_FIELDS, APPLICABLE_TO_METHODS, ArrayTypeCode, BooleanTypeCode, BRIDGE, ByteTypeCode, CharTypeCode, CLASS_INITIALIZED, CLASS_INITIALIZER_FAILED, CLASS_INITIALIZING, CLASS_INSTANTIATED, CLASS_LOADED, CLASS_RESOLVED, CLASS_VACANT, ClassTypeCode, CP_CLASS, CP_DOUBLE, CP_FLOAT, CP_INT, CP_LONG, CP_MEMBER, CP_STRING, CP_UTF, DoubleTypeCode, FloatTypeCode, IntTypeCode, LongTypeCode, ShortTypeCode, TAG_DOUBLE, TAG_FIELDREF, TAG_FLOAT, TAG_INT, TAG_INTERFACE_METHODREF, TAG_LONG, TAG_MEMBERNAME_AND_DESCRIPTOR, TAG_METHODREF, TAG_STRING, TAG_TYPEREF, TAG_UNUSED, TAG_UTF, VARARGS, VoidTypeCode
 
Constructor Summary
ClassFileReader()
           
 
Method Summary
(package private) static RVMMethod getClassInitializerMethod(RVMMethod[] declaredMethods)
          Return the class initializer method among the declared methods of the class
(package private) static FieldReference getFieldRef(int[] constantPool, int constantPoolIndex)
          Get contents of a "methodRef" constant pool entry.
(package private) static byte getLiteralDescription(int[] constantPool, int constantPoolIndex)
          Get description of a literal constant.
(package private) static Offset getLiteralOffset(int[] constantPool, int constantPoolIndex)
          Get offset of a literal constant, in bytes.
(package private) static int getLiteralSize(int[] constantPool, int constantPoolIndex)
           
(package private) static MethodReference getMethodRef(int[] constantPool, int constantPoolIndex)
          Get contents of a "methodRef" constant pool entry.
(package private) static TypeReference getTypeRef(int[] constantPool, int constantPoolIndex)
          Get contents of a "typeRef" constant pool entry.
(package private) static Atom getUtf(int[] constantPool, int constantPoolIndex)
          Get contents of a "utf" from a constant pool entry.
(package private) static int packCPEntry(byte type, int value)
           
(package private) static boolean packedCPTypeIsClassType(int cpValue)
           
(package private) static int packTempCPEntry(int index1, int index2)
           
(package private) static RVMClass readClass(TypeReference typeRef, DataInputStream input)
          Create an instance of a RVMClass.
(package private) static int[] readConstantPool(TypeReference typeRef, DataInputStream input)
          Parse and return the constant pool in a class file
(package private) static RVMField[] readDeclaredFields(TypeReference typeRef, DataInputStream input, int[] constantPool)
          Read the declared fields of the class being read
(package private) static RVMClass[] readDeclaredInterfaces(DataInputStream input, int[] constantPool)
          Read the list of interfaces implemented by the class being read
(package private) static RVMMethod[] readDeclaredMethods(TypeReference typeRef, DataInputStream input, int[] constantPool)
          Read the declared methods of the class being read
(package private) static RVMClass readSuperClass(DataInputStream input, int[] constantPool, short modifiers)
          Read the super class name, load and resolve the super class
(package private) static int readTypeRef(TypeReference typeRef, DataInputStream input, int[] constantPool)
          Read the class' TypeReference
(package private) static byte unpackCPType(int cpValue)
           
(package private) static int unpackSignedCPValue(int cpValue)
           
(package private) static int unpackTempCPIndex1(int cpValue)
           
(package private) static int unpackTempCPIndex2(int cpValue)
           
(package private) static int unpackUnsignedCPValue(int cpValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFileReader

public ClassFileReader()
Method Detail

readConstantPool

static int[] readConstantPool(TypeReference typeRef,
                              DataInputStream input)
                       throws ClassFormatError,
                              IOException
Parse and return the constant pool in a class file

Parameters:
typeRef - the canonical type reference for this type.
input - the data stream from which to read the class's description.
Throws:
ClassFormatError
IOException

readTypeRef

static int readTypeRef(TypeReference typeRef,
                       DataInputStream input,
                       int[] constantPool)
                throws IOException,
                       ClassFormatError
Read the class' TypeReference

Parameters:
typeRef -
input -
constantPool -
Returns:
the constantPool index of the typeRef of the class we are reading
Throws:
IOException
ClassFormatError

readSuperClass

static RVMClass readSuperClass(DataInputStream input,
                               int[] constantPool,
                               short modifiers)
                        throws IOException,
                               NoClassDefFoundError
Read the super class name, load and resolve the super class

Parameters:
input -
constantPool -
modifiers -
Returns:
the super class of the class being read
Throws:
IOException
NoClassDefFoundError

readDeclaredInterfaces

static RVMClass[] readDeclaredInterfaces(DataInputStream input,
                                         int[] constantPool)
                                  throws IOException,
                                         NoClassDefFoundError
Read the list of interfaces implemented by the class being read

Parameters:
input -
constantPool -
Returns:
the interfaces implemented by the class
Throws:
IOException
NoClassDefFoundError

readDeclaredFields

static RVMField[] readDeclaredFields(TypeReference typeRef,
                                     DataInputStream input,
                                     int[] constantPool)
                              throws IOException
Read the declared fields of the class being read

Parameters:
typeRef -
input -
constantPool -
Returns:
the list of declared fields
Throws:
IOException

readDeclaredMethods

static RVMMethod[] readDeclaredMethods(TypeReference typeRef,
                                       DataInputStream input,
                                       int[] constantPool)
                                throws IOException
Read the declared methods of the class being read

Parameters:
typeRef -
input -
constantPool -
Returns:
the declared methods of the class
Throws:
IOException

getClassInitializerMethod

static RVMMethod getClassInitializerMethod(RVMMethod[] declaredMethods)
Return the class initializer method among the declared methods of the class

Parameters:
declaredMethods -
Returns:
the class initializer method of the class

readClass

static RVMClass readClass(TypeReference typeRef,
                          DataInputStream input)
                   throws ClassFormatError,
                          IOException
Create an instance of a RVMClass.

Parameters:
typeRef - the canonical type reference for this type.
input - the data stream from which to read the class's description.
Throws:
ClassFormatError
IOException

packCPEntry

static int packCPEntry(byte type,
                       int value)

unpackCPType

static byte unpackCPType(int cpValue)

unpackSignedCPValue

static int unpackSignedCPValue(int cpValue)

unpackUnsignedCPValue

static int unpackUnsignedCPValue(int cpValue)

packedCPTypeIsClassType

static boolean packedCPTypeIsClassType(int cpValue)

packTempCPEntry

static int packTempCPEntry(int index1,
                           int index2)

unpackTempCPIndex1

static int unpackTempCPIndex1(int cpValue)

unpackTempCPIndex2

static int unpackTempCPIndex2(int cpValue)

getLiteralSize

static int getLiteralSize(int[] constantPool,
                          int constantPoolIndex)

getLiteralOffset

static Offset getLiteralOffset(int[] constantPool,
                               int constantPoolIndex)
Get offset of a literal constant, in bytes. Offset is with respect to virtual machine's "table of contents" (jtoc).


getLiteralDescription

static byte getLiteralDescription(int[] constantPool,
                                  int constantPoolIndex)
Get description of a literal constant.


getTypeRef

static TypeReference getTypeRef(int[] constantPool,
                                int constantPoolIndex)
Get contents of a "typeRef" constant pool entry.

Returns:
type that was referenced

getMethodRef

static MethodReference getMethodRef(int[] constantPool,
                                    int constantPoolIndex)
Get contents of a "methodRef" constant pool entry.


getFieldRef

static FieldReference getFieldRef(int[] constantPool,
                                  int constantPoolIndex)
Get contents of a "methodRef" constant pool entry.


getUtf

static Atom getUtf(int[] constantPool,
                   int constantPoolIndex)
Get contents of a "utf" from a constant pool entry.