org.jikesrvm.classloader
Class TypeReference

java.lang.Object
  extended by org.jikesrvm.classloader.TypeReference

public final class TypeReference
extends Object

A class to represent the reference in a class file to some type (class, primitive or array). A type reference is uniquely defined by

Resolving a TypeReference to a RVMType can be an expensive operation. Therefore we canonicalize TypeReference instances and cache the result of resolution.


Field Summary
static TypeReference Address
           
static TypeReference AddressArray
           
static TypeReference BaselineNoRegisters
           
static TypeReference BaselineSaveLSRegisters
           
(package private) static TypeReference baseReflectionClass
          Abstract base of reflective method invoker classes
static TypeReference Boolean
           
static TypeReference BooleanArray
           
static TypeReference Byte
           
static TypeReference ByteArray
           
static TypeReference Char
           
static TypeReference CharArray
           
static TypeReference Class
           
(package private)  ClassLoader classloader
          The initiating class loader
private static ImmutableEntryHashSetRVM<ClassLoader> clDict
           
static TypeReference Code
           
static TypeReference CodeArray
           
private static ImmutableEntryHashSetRVM<TypeReference> dictionary
          Used to canonicalize TypeReferences
static TypeReference Double
           
static TypeReference DoubleArray
           
static TypeReference DynamicBridge
           
static TypeReference ExceptionTable
           
static TypeReference Extent
           
static TypeReference ExtentArray
           
static TypeReference Float
           
static TypeReference FloatArray
           
static TypeReference FunctionTable
           
(package private)  int id
          The id of this type reference.
static TypeReference IMT
           
static TypeReference Int
           
static TypeReference IntArray
           
static TypeReference Interruptible
           
static TypeReference ITable
           
static TypeReference ITableArray
           
static TypeReference JavaIoSerializable
           
static TypeReference JavaLangArithmeticException
           
static TypeReference JavaLangArrayIndexOutOfBoundsException
           
static TypeReference JavaLangArrayStoreException
           
static TypeReference JavaLangClass
           
static TypeReference JavaLangClassCastException
           
static TypeReference JavaLangCloneable
           
static TypeReference JavaLangError
           
static TypeReference JavaLangIllegalMonitorStateException
           
static TypeReference JavaLangNegativeArraySizeException
           
static TypeReference JavaLangNullPointerException
           
static TypeReference JavaLangObject
           
static TypeReference JavaLangObjectArray
           
static TypeReference JavaLangRefReference
           
static TypeReference JavaLangString
           
static TypeReference JavaLangSystem
           
static TypeReference JavaLangThrowable
           
static TypeReference JNIFunctions
           
static TypeReference LinkageTripletTable
           
private static int LOG_ROW_SIZE
          2^LOG_ROW_SIZE is the number of elements per row
static TypeReference LogicallyUninterruptible
           
static TypeReference Long
           
static TypeReference LongArray
           
static TypeReference Magic
           
(package private)  Atom name
          The type name.
static TypeReference NativeBridge
           
private static int nextId
          Used to assign Ids.
static TypeReference NoCheckStore
           
static TypeReference NonMoving
           
static TypeReference NonMovingAllocation
           
static TypeReference NULL_TYPE
           
static TypeReference ObjectReference
           
static TypeReference ObjectReferenceArray
           
static TypeReference Offset
           
static TypeReference OffsetArray
           
static TypeReference OptimizationPlanner
           
static TypeReference Preemptible
           
static TypeReference ReferenceFieldsVary
           
static TypeReference ReferenceMaps
           
private static int ROW_MASK
          Mask to ascertain row from id number
static TypeReference RVMArray
           
static TypeReference SaveVolatile
           
static TypeReference Short
           
static TypeReference ShortArray
           
static TypeReference SpecializedMethodInvoke
           
static TypeReference SysCall
           
static TypeReference Thread
           
static TypeReference TIB
           
private  RVMType type
          The RVMType instance that this type reference resolves to.
static TypeReference Type
           
private static TypeReference[][] types
          Dictionary of all TypeReference instances.
static TypeReference Uninterruptible
           
static TypeReference UninterruptibleNoWarn
           
static TypeReference Unpreemptible
           
static TypeReference UnpreemptibleNoWarn
           
static TypeReference Untraced
           
static TypeReference VALIDATION_TYPE
           
static TypeReference Void
           
static TypeReference Word
           
static TypeReference WordArray
           
 
Constructor Summary
private TypeReference(ClassLoader cl, Atom tn, int id)
          Constructor
 
Method Summary
private static void canonicalizeCL(ClassLoader cl)
           
 boolean definitelyDifferent(TypeReference that)
          Do this and that definitely refer to the different types?
 boolean definitelySame(TypeReference that)
          Do this and that definitely refer to the same type?
 boolean equals(Object other)
          Are two keys equivalent?
static TypeReference findOrCreate(Class<?> klass)
          Convert a java.lang.Class into a type reference the slow way.
static TypeReference findOrCreate(ClassLoader cl, Atom tn)
          Find or create the canonical TypeReference instance for the given pair.
static TypeReference findOrCreate(String tn)
          Shorthand for doing a find or create for a type reference that should be created using the bootstrap classloader.
static TypeReference findOrCreateInternal(ClassLoader cl, Atom tn)
          Find or create the canonical TypeReference instance for the given pair without type descriptor parsing.
 TypeReference getArrayElementType()
          Get the element type of for this array type
 TypeReference getArrayTypeForElementType()
          Get array type corresponding to "this" array element type.
 ClassLoader getClassLoader()
           
static ImmutableEntryHashSetRVM<ClassLoader> getCLDict()
           
 int getDimensionality()
          Return the dimensionality of the type.
 int getId()
           
 TypeReference getInnermostElementType()
          Return the innermost element type reference for an array
 int getMemoryBytes()
          How many bytes do values of this type take?
 Atom getName()
           
 int getStackWords()
          How many java stack/local words do value of this type take?
static TypeReference getTypeRef(int id)
          Get the canonical type reference given its id.
 int hashCode()
          Hash value based on name, used for canonical type dictionary
 boolean isAddressType()
          Does 'this' refer to Address
 boolean isArrayType()
          Does 'this' refer to an array?
 boolean isBooleanType()
          Is this the type reference for the boolean primitive type?
 boolean isByteType()
          Is this the type reference for the byte primitive type?
 boolean isCharType()
          Is this the type reference for the char primitive type?
 boolean isClassType()
          Does 'this' refer to a class?
 boolean isCodeArrayType()
          Does 'this' refer to CodeArray
 boolean isCodeType()
          Does 'this' refer to Code
 boolean isDoubleType()
          Is this the type reference for the double primitive type?
 boolean isExtentType()
          Does 'this' refer to Extent
 boolean isFloatType()
          Is this the type reference for the float primitive type?
 boolean isIntLikeType()
          Is this the type reference for an int-like (1, 8, 16, or 32 bit integral) primitive type?
 boolean isIntType()
          Is this the type reference for the int primitive type?
 boolean isLoaded()
          Return true if the type for type reference has been loaded.
 boolean isLongType()
          Is this the type reference for the long primitive type?
 boolean isMagicType()
          Does 'this' refer to Magic?
 boolean isOffsetType()
          Does 'this' refer to Offset
 boolean isPrimitiveType()
          Does 'this' refer to a primitive type
 boolean isReferenceType()
          Does 'this' refer to a reference type
 boolean isResolved()
          Return true if the type for type reference has been loaded and it is resolved.
 boolean isRuntimeTable()
          Does 'this' refer to a runtime table type?
 boolean isShortType()
          Is this the type reference for the short primitive type?
 boolean isUnboxedArrayType()
          Does 'this' refer to WordArray, AddressArray, OffsetArray or ExtentArray
 boolean isUnboxedType()
          Does 'this' refer to an unboxed type.
 boolean isVoidType()
          Is this the type reference for the void primitive type?
 boolean isWordArrayType()
          Does 'this' refer to WordArray, AddressArray, OffsetArray or ExtentArray
 boolean isWordLikeType()
          Does 'this' refer to Word, Address, Offset or Extent
 boolean isWordType()
          Does 'this' refer to Word
 RVMType peekType()
           
 RVMType resolve()
          Force the resolution of the type reference.
private  RVMType resolveInternal()
           
(package private)  void setType(RVMType rt)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

classloader

final ClassLoader classloader
The initiating class loader


name

final Atom name
The type name. For example, the primitive type int is "I", the class java.lang.String is "Ljava/lang/String;"


id

final int id
The id of this type reference.


type

private RVMType type
The RVMType instance that this type reference resolves to. Null if the reference has not yet been resolved.


dictionary

private static final ImmutableEntryHashSetRVM<TypeReference> dictionary
Used to canonicalize TypeReferences


clDict

private static final ImmutableEntryHashSetRVM<ClassLoader> clDict

LOG_ROW_SIZE

private static final int LOG_ROW_SIZE
2^LOG_ROW_SIZE is the number of elements per row

See Also:
Constant Field Values

ROW_MASK

private static final int ROW_MASK
Mask to ascertain row from id number

See Also:
Constant Field Values

types

private static TypeReference[][] types
Dictionary of all TypeReference instances.


nextId

private static int nextId
Used to assign Ids. Id 0 is not used. Ids are compressed and stored in the constant pool (See RVMClass).


Void

public static final TypeReference Void

Boolean

public static final TypeReference Boolean

Byte

public static final TypeReference Byte

Char

public static final TypeReference Char

Short

public static final TypeReference Short

Int

public static final TypeReference Int

Long

public static final TypeReference Long

Float

public static final TypeReference Float

Double

public static final TypeReference Double

BooleanArray

public static final TypeReference BooleanArray

ByteArray

public static final TypeReference ByteArray

CharArray

public static final TypeReference CharArray

ShortArray

public static final TypeReference ShortArray

IntArray

public static final TypeReference IntArray

LongArray

public static final TypeReference LongArray

FloatArray

public static final TypeReference FloatArray

DoubleArray

public static final TypeReference DoubleArray

Word

public static final TypeReference Word

Address

public static final TypeReference Address

ObjectReference

public static final TypeReference ObjectReference

Offset

public static final TypeReference Offset

Extent

public static final TypeReference Extent

Code

public static final TypeReference Code

WordArray

public static final TypeReference WordArray

AddressArray

public static final TypeReference AddressArray

ObjectReferenceArray

public static final TypeReference ObjectReferenceArray

OffsetArray

public static final TypeReference OffsetArray

ExtentArray

public static final TypeReference ExtentArray

CodeArray

public static final TypeReference CodeArray

Magic

public static final TypeReference Magic

SysCall

public static final TypeReference SysCall

TIB

public static final TypeReference TIB

ITableArray

public static final TypeReference ITableArray

ITable

public static final TypeReference ITable

IMT

public static final TypeReference IMT

Thread

public static final TypeReference Thread

FunctionTable

public static final TypeReference FunctionTable

LinkageTripletTable

public static final TypeReference LinkageTripletTable

JavaLangObject

public static final TypeReference JavaLangObject

JavaLangClass

public static final TypeReference JavaLangClass

JavaLangString

public static final TypeReference JavaLangString

JavaLangCloneable

public static final TypeReference JavaLangCloneable

JavaIoSerializable

public static final TypeReference JavaIoSerializable

JavaLangRefReference

public static final TypeReference JavaLangRefReference

JavaLangSystem

public static final TypeReference JavaLangSystem

JavaLangObjectArray

public static final TypeReference JavaLangObjectArray

JavaLangThrowable

public static final TypeReference JavaLangThrowable

JavaLangError

public static final TypeReference JavaLangError

JavaLangNullPointerException

public static final TypeReference JavaLangNullPointerException

JavaLangArrayIndexOutOfBoundsException

public static final TypeReference JavaLangArrayIndexOutOfBoundsException

JavaLangArithmeticException

public static final TypeReference JavaLangArithmeticException

JavaLangArrayStoreException

public static final TypeReference JavaLangArrayStoreException

JavaLangClassCastException

public static final TypeReference JavaLangClassCastException

JavaLangNegativeArraySizeException

public static final TypeReference JavaLangNegativeArraySizeException

JavaLangIllegalMonitorStateException

public static final TypeReference JavaLangIllegalMonitorStateException

Type

public static final TypeReference Type

Class

public static final TypeReference Class

NativeBridge

public static final TypeReference NativeBridge

DynamicBridge

public static final TypeReference DynamicBridge

SaveVolatile

public static final TypeReference SaveVolatile

Interruptible

public static final TypeReference Interruptible

LogicallyUninterruptible

public static final TypeReference LogicallyUninterruptible

Preemptible

public static final TypeReference Preemptible

UninterruptibleNoWarn

public static final TypeReference UninterruptibleNoWarn

UnpreemptibleNoWarn

public static final TypeReference UnpreemptibleNoWarn

Uninterruptible

public static final TypeReference Uninterruptible

NoCheckStore

public static final TypeReference NoCheckStore

Unpreemptible

public static final TypeReference Unpreemptible

SpecializedMethodInvoke

public static final TypeReference SpecializedMethodInvoke

Untraced

public static final TypeReference Untraced

NonMoving

public static final TypeReference NonMoving

NonMovingAllocation

public static final TypeReference NonMovingAllocation

BaselineNoRegisters

public static final TypeReference BaselineNoRegisters

BaselineSaveLSRegisters

public static final TypeReference BaselineSaveLSRegisters

ReferenceFieldsVary

public static final TypeReference ReferenceFieldsVary

ReferenceMaps

public static final TypeReference ReferenceMaps

JNIFunctions

public static final TypeReference JNIFunctions

RVMArray

public static final TypeReference RVMArray

baseReflectionClass

static final TypeReference baseReflectionClass
Abstract base of reflective method invoker classes


NULL_TYPE

public static final TypeReference NULL_TYPE

VALIDATION_TYPE

public static final TypeReference VALIDATION_TYPE

ExceptionTable

public static final TypeReference ExceptionTable

OptimizationPlanner

public static final TypeReference OptimizationPlanner
Constructor Detail

TypeReference

private TypeReference(ClassLoader cl,
                      Atom tn,
                      int id)
Constructor

Parameters:
cl - the classloader
tn - the type name
id - the numeric identifier
Method Detail

hashCode

public int hashCode()
Hash value based on name, used for canonical type dictionary

Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Are two keys equivalent? Used for canonical type dictionary. NB ignores id value

Overrides:
equals in class Object

findOrCreate

public static TypeReference findOrCreate(ClassLoader cl,
                                         Atom tn)
                                  throws IllegalArgumentException
Find or create the canonical TypeReference instance for the given pair.

Parameters:
cl - the classloader (defining/initiating depending on usage)
tn - the name of the type
Throws:
IllegalArgumentException - Needs to throw some kind of error in the case of a Atom that does not represent a type name.

findOrCreate

public static TypeReference findOrCreate(String tn)
Shorthand for doing a find or create for a type reference that should be created using the bootstrap classloader.

Parameters:
tn - type name

findOrCreate

public static TypeReference findOrCreate(Class<?> klass)
Convert a java.lang.Class into a type reference the slow way. For use in boot image writing

Parameters:
klass - java.lang.Class to convert to type reference

findOrCreateInternal

public static TypeReference findOrCreateInternal(ClassLoader cl,
                                                 Atom tn)
Find or create the canonical TypeReference instance for the given pair without type descriptor parsing.

Parameters:
cl - the classloader (defining/initiating depending on usage)
tn - the name of the type

canonicalizeCL

private static void canonicalizeCL(ClassLoader cl)

getCLDict

public static ImmutableEntryHashSetRVM<ClassLoader> getCLDict()

getTypeRef

public static TypeReference getTypeRef(int id)
Get the canonical type reference given its id. The unused id of 0 will return null.

Parameters:
id - the type references id
Returns:
the type reference

getClassLoader

public ClassLoader getClassLoader()
Returns:
the classloader component of this type reference

getName

public Atom getName()
Returns:
the type name component of this type reference

getArrayElementType

public TypeReference getArrayElementType()
Get the element type of for this array type


getArrayTypeForElementType

public TypeReference getArrayTypeForElementType()
Get array type corresponding to "this" array element type.


getDimensionality

public int getDimensionality()
Return the dimensionality of the type. By convention, class types have dimensionality 0, primitives -1, and arrays the number of [ in their descriptor.


getInnermostElementType

public TypeReference getInnermostElementType()
Return the innermost element type reference for an array


isClassType

public boolean isClassType()
Does 'this' refer to a class?


isArrayType

public boolean isArrayType()
Does 'this' refer to an array?


isPrimitiveType

public boolean isPrimitiveType()
Does 'this' refer to a primitive type


isReferenceType

public boolean isReferenceType()
Does 'this' refer to a reference type


isWordLikeType

public boolean isWordLikeType()
Does 'this' refer to Word, Address, Offset or Extent


isWordType

public boolean isWordType()
Does 'this' refer to Word


isAddressType

public boolean isAddressType()
Does 'this' refer to Address


isOffsetType

public boolean isOffsetType()
Does 'this' refer to Offset


isExtentType

public boolean isExtentType()
Does 'this' refer to Extent


isUnboxedType

public boolean isUnboxedType()
Does 'this' refer to an unboxed type.


isCodeType

public boolean isCodeType()
Does 'this' refer to Code


isWordArrayType

public boolean isWordArrayType()
Does 'this' refer to WordArray, AddressArray, OffsetArray or ExtentArray


isUnboxedArrayType

public boolean isUnboxedArrayType()
Does 'this' refer to WordArray, AddressArray, OffsetArray or ExtentArray


isRuntimeTable

public boolean isRuntimeTable()
Does 'this' refer to a runtime table type?


isCodeArrayType

public boolean isCodeArrayType()
Does 'this' refer to CodeArray


isMagicType

public boolean isMagicType()
Does 'this' refer to Magic?


getStackWords

public int getStackWords()
How many java stack/local words do value of this type take?


getMemoryBytes

public int getMemoryBytes()
How many bytes do values of this type take?


getId

public int getId()
Returns:
the id to use for this type

isVoidType

public boolean isVoidType()
Is this the type reference for the void primitive type?


isBooleanType

public boolean isBooleanType()
Is this the type reference for the boolean primitive type?


isByteType

public boolean isByteType()
Is this the type reference for the byte primitive type?


isShortType

public boolean isShortType()
Is this the type reference for the short primitive type?


isCharType

public boolean isCharType()
Is this the type reference for the char primitive type?


isIntType

public boolean isIntType()
Is this the type reference for the int primitive type?


isLongType

public boolean isLongType()
Is this the type reference for the long primitive type?


isFloatType

public boolean isFloatType()
Is this the type reference for the float primitive type?


isDoubleType

public boolean isDoubleType()
Is this the type reference for the double primitive type?


isIntLikeType

public boolean isIntLikeType()
Is this the type reference for an int-like (1, 8, 16, or 32 bit integral) primitive type?


definitelyDifferent

public boolean definitelyDifferent(TypeReference that)
Do this and that definitely refer to the different types?


definitelySame

public boolean definitelySame(TypeReference that)
Do this and that definitely refer to the same type?


isLoaded

public boolean isLoaded()
Return true if the type for type reference has been loaded.


isResolved

public boolean isResolved()
Return true if the type for type reference has been loaded and it is resolved.


peekType

public RVMType peekType()
Returns:
the current value of resolvedType -- null if not yet resolved.

setType

void setType(RVMType rt)

resolve

public RVMType resolve()
                throws NoClassDefFoundError,
                       IllegalArgumentException
Force the resolution of the type reference. May cause class loading if a required class file hasn't been loaded before.

Returns:
the RVMType instance that this references resolves to.
Throws:
NoClassDefFoundError - When it cannot resolve a class. we go to the trouble of converting the class loader's ClassNotFoundException into this error, since we need to be able to throw NoClassDefFoundError for classes that we're loading whose existence was compile-time checked.
IllegalArgumentException - In case of a malformed class name (should never happen, since the right thing to do is probably to validate them as soon as we insert them into a TypeReference. This stinks. XXX)

resolveInternal

private RVMType resolveInternal()
                         throws NoClassDefFoundError,
                                IllegalArgumentException
Throws:
NoClassDefFoundError
IllegalArgumentException

toString

public String toString()
Overrides:
toString in class Object