public class Tools extends Object
The Tools class provides access to methods used by reflection, serialization, and dynamic class loading. Most applications should probably not use these methods directly, but should instead go through the API's intended for reflection, serialization, and class loading use.
Note an important distinction when using this class--that between method numbers and method
table indices. A method number starts at 0 with methods in the class object and is not
repeated in subclasses, except when a method is overridden. Method numbers are used to
invoke methods. Method table indices start at 0 within each class and refer only to methods declared
by that class. Reflection information is stored by method table index. Use the method
getMethodPrimitive(int,int,int)
to translate from method table index to method number.
getMethodPrimitive(int,int,int)
Modifier and Type | Field and Description |
---|---|
static int |
ARR_TYPE_MGC
Constant for the bytecode interpreter
|
static int |
ARRAY_GET_BYTE
Parameter to array_set
|
static int |
ARRAY_GET_CLASS_TYPE
Parameter to array_set
|
static int |
ARRAY_GET_DIM
Parameter to array_set
|
static int |
ARRAY_GET_INT
Parameter to array_set
|
static int |
ARRAY_GET_LENGTH
Parameter to array_set
|
static int |
ARRAY_GET_LONG
Parameter to array_set
|
static int |
ARRAY_GET_SHORT
Parameter to array_set
|
static int |
ARRAY_GET_TAG
Parameter to array_set
|
static int |
ARRAY_SET_BYTE
Parameter to array_set
|
static int |
ARRAY_SET_INT
Parameter to array_set
|
static int |
ARRAY_SET_LONG
Parameter to array_set
|
static int |
ARRAY_SET_OBJECT
Parameter to array_set
|
static int |
ARRAY_SET_SHORT
Parameter to array_set
|
static int |
cloneableClassNum
Class number for the class
java.lang.Cloneable . |
static int |
externalizableClassNum
Class number for the class
java.io.Externalizable . |
static int |
OBJ_TYPE_MGC
Constant for the bytecode interpreter
|
static int |
PRIM_TYPE_MGC
Constant for the bytecode interpreter
|
static int |
REF_ARR_TYPE_MGC
Constant for the bytecode interpreter
|
static int |
REFLECT_CLASS_FLAG
Does anyone use this? If so, call NSK at ...
|
static int |
REFLECT_INTERFACE_FLAG
Does anyone use this? If so, call NSK at ...
|
static int |
REFLECT_OBJ_ARRAY_FLAG
Does anyone use this? If so, call NSK at ...
|
static int |
REFLECT_PRIM_ARRAY_FLAG
Does anyone use this? If so, call NSK at ...
|
static int |
serializableClassNum
Class number for the class
java.io.Serializable . |
static int |
stringClassNum
Class number for the class
java.lang.String . |
Modifier and Type | Method and Description |
---|---|
static Object |
allocateClass(Class s)
Creates an object (but does not run it's constructor).
|
static long |
array_set(Object array,
int index,
int flags,
int iPrim,
Object obj,
long lPrim)
array_set get and sets array info/values.
|
static Object |
arrayNewInstance(Class x,
int size)
Creates a new array of type x.
|
static Object |
arrayNewInstance2(Class x,
int[] size)
help me!!! i need javadocs!!!
|
static Class |
createClassClass(int magicNum,
int type,
int componentType) |
static short |
findFieldByName(int classnum,
String compare)
findFieldByName finds the index of a field using it's string name.For example
fIndex = Tools.findFieldByName(IntegerCnum,\"TYPE\"); |
static short |
findFieldByName2(int classnum,
String compare)
findFieldByName2 finds field info on a specified field
|
static short |
findMethodByIndex(int value)
findMethodByIndex finds the index of a method using an entry from a stacktrace
dump.
|
static short |
findMethodByName(int classnum,
String compare)
findMethodByName finds the index of a method using it's string name.
|
static int |
findMethodByName2(int classnum,
String compare)
findMethodByName2 finds method info on a specified method
|
static int |
getAccessFlags(int classNumber)
Gets the access flags for a class.
|
static String |
getClassNameFromNum(int classnum)
Returns the name of the class from its class number.
|
static int |
getClassNumber(String className)
Maps a class name to a class number.
|
static int |
getClassNumberFromClass(Class cl)
Returns the class number of the class obj.
|
static Constructor |
getConstructorClass(int index,
int classnum)
getField/Method/ConstructorClass all return the appropriate class represented
by the index/classnum pair.
|
static int |
getDaClassNumber(Object o)
Returns the class number of the object.
|
static Field |
getFieldClass(int index,
int classnum)
getField/Method/ConstructorClass all return the appropriate class represented
by the index/classnum pair.
|
static int |
getFieldCount(int classnum)
Returns the number of static and instance fields in the class
represented by
classnum . |
static String |
getFieldName(int classnum,
int index)
help me!!! i need javadocs!!!
|
static String |
getFieldString(int classnum,
int index)
getFieldString gets the name string
of a field from the trash heap.
|
static int |
getFieldType(int classnum,
int index) |
static int |
getFieldValue(Object O,
int index,
int classnum)
getFieldValue, getFieldObjectValue, and getWideFieldValue
also all do the same thing - get values from fields.
|
static String |
getFullMethodDescriptor(int classnum,
int index)
Returns the descriptor string of a method in String format.
|
static int[] |
getInterfacesNative(int classNum)
Get the class numbers of the declared interfaces of this class.
|
static byte[] |
getMethodByteArray(int classnum,
int index,
int query)
Method info getter.The query parameter is an actual
index into the method record, which allows these methods to be used
as more info is stored there.
|
static Method |
getMethodClass(int index,
int classnum)
getField/Method/ConstructorClass all return the appropriate class represented
by the index/classnum pair.There's that stupid index/classnum parameter
mixup again! I must have been smokin' some serious...
|
static int |
getMethodCount(int classnum)
Returns the number of methods in the class represented by
classnum . |
static String |
getMethodName(int classnum,
int index)
help me!!! i need javadocs!!!
|
static int |
getMethodPrimitive(int clasnum,
int index,
int query)
Method info getter.The query parameter is an actual
index into the method record, which allows these methods to be used
as more info is stored there.
|
static String |
getMethodString(int classnum,
int index,
int query)
Method info getter.
|
static int |
getModifiers0(int classnum,
int index)
getModifers0 returns the modifiers for a given field
|
static Object |
getObjectFieldValue(Object O,
int index,
int classnum)
getFieldValue, getFieldObjectValue, and getWideFieldValue
also all do the same thing - get values from fields.Oh the embarrasment...
|
static int |
getStackTrace(int[] bt)
Traces the java stack for methods.
|
static Class |
getStoredClass(int classNumber)
Returns the
java.lang.Class object created when
running the static initializer of a class. |
static int |
getSuperclassNumber(int classNum)
Returns the class number of the superclass of the class represented by
classNum . |
static long |
getWideFieldValue(Object O,
int index,
int classnum)
getFieldValue, getFieldObjectValue, and getWideFieldValue
also all do the same thing - get values from fields.Oh the embarrasment...
|
static int |
inum2mnum(int classnum,
int inum)
Maps an interface number to the methodnumber that
implements it.
|
static long |
invoke0(int classnum,
int methodnum,
int[] args)
Dynamically runs a method.
|
static boolean |
isInterfaceAssignableFrom(int classNum,
int interfaceClassNum) |
static Object |
long2obj(long x)
long2obj convers a long return value into the object it came from.
|
static void |
markClassFindable(int cnum)
Marks a class to be findable by the
Class.forName(java.lang.String) method. |
static long |
obj2long(Object x)
Convers an object to a primitive for good casting.
|
static char |
prim2char(int prim)
help me!!! i need javadocs!!!
|
static Class |
prim2class(int prim)
help me!!! i need javadocs!!!
|
static int |
runInitializer(int classnumber) |
static void |
setFieldValue(Object O,
int index,
int classnum,
int value)
setFieldXXX sets the value inside a field.
|
static void |
setObjectFieldValue(Object O,
int index,
int classnum,
Object value)
setFieldXXX sets the value inside a field.
|
static void |
setWideFieldValue(Object O,
int index,
int classnum,
long value)
setFieldXXX sets the value inside a field.
|
static int |
strcmpF(String str1,
String str2)
String compare for field strings.
|
static int |
strcmpM(String str1,
String str2)
String compare for Method strings.
|
public static final int cloneableClassNum
java.lang.Cloneable
. Storage here allows
quick access routines without the penalty of searching the firmware for the class number.public static final int serializableClassNum
java.io.Serializable
. Storage here allows
quick access routines without the penalty of searching the firmware for the class number.public static final int externalizableClassNum
java.io.Externalizable
. Storage here allows
quick access routines without the penalty of searching the firmware for the class number.public static final int stringClassNum
java.lang.String
. Storage here allows
quick access routines without the penalty of searching the firmware for the class number.public static final int OBJ_TYPE_MGC
public static final int ARR_TYPE_MGC
public static final int REF_ARR_TYPE_MGC
public static final int PRIM_TYPE_MGC
public static final int REFLECT_CLASS_FLAG
public static final int REFLECT_INTERFACE_FLAG
public static final int REFLECT_PRIM_ARRAY_FLAG
public static final int REFLECT_OBJ_ARRAY_FLAG
public static final int ARRAY_SET_BYTE
public static final int ARRAY_SET_SHORT
public static final int ARRAY_SET_INT
public static final int ARRAY_SET_OBJECT
public static final int ARRAY_SET_LONG
public static final int ARRAY_GET_BYTE
public static final int ARRAY_GET_SHORT
public static final int ARRAY_GET_INT
public static final int ARRAY_GET_LONG
public static final int ARRAY_GET_TAG
public static final int ARRAY_GET_LENGTH
public static final int ARRAY_GET_CLASS_TYPE
public static final int ARRAY_GET_DIM
public static int getMethodCount(int classnum)
classnum
.classnum
- class number to count methods ofpublic static int getFieldCount(int classnum)
classnum
.classnum
- class number to count the fields inpublic static String getClassNameFromNum(int classnum)
classnum
- class number to get the name fromjava.lang.String
)
or null
if the class number is invalidpublic static Class getStoredClass(int classNumber)
java.lang.Class
object created when
running the static initializer of a class. If the Class
object does not exist, a new Class
object is created,
though the class is not initialized.classNumber
- class number to retrieve the Class
object forClass
object representing the class that this class
number belongs to, or null
if the class number
is invalidpublic static int runInitializer(int classnumber)
classnumber
- ?public static int getDaClassNumber(Object o)
o
- Class being queriedpublic static int getClassNumberFromClass(Class cl)
cl
- Class object being queriedpublic static int getClassNumber(String className)
className
- String name of class (e.g java.lang.String)public static int getSuperclassNumber(int classNum)
classNum
.classNum
- ?classNum
's superclass,
or -1
if the class has no superclassIllegalArgumentException
- if the class number is invalidpublic static int getAccessFlags(int classNumber)
classNumber
- ?public static void setFieldValue(Object O, int index, int classnum, int value)
O
- Object who'se field is to be setindex
- index of field to be setclassnum
- class number of field to be set. Allows for setting
of superclass numbersvalue
- Value to assign field.public static void setObjectFieldValue(Object O, int index, int classnum, Object value)
O
- Object who'se field is to be setindex
- index of field to be setclassnum
- class number of field to be set. Allows for setting
of superclass numbersvalue
- Value to assign field.public static void setWideFieldValue(Object O, int index, int classnum, long value)
O
- Object who'se field is to be setindex
- index of field to be setclassnum
- class number of field to be set. Allows for setting
of superclass numbersvalue
- Value to assign field.public static int getFieldValue(Object O, int index, int classnum)
O
- Object whose field is to be queriedindex
- index of field to be queriedclassnum
- classnum of field to be set.public static Object getObjectFieldValue(Object O, int index, int classnum)
O
- Object whose field is to be queriedindex
- index of field to be queriedclassnum
- classnum of field to be set.public static long getWideFieldValue(Object O, int index, int classnum)
O
- Object whose field is to be queriedindex
- index of field to be queriedclassnum
- classnum of field to be set.public static String getFieldString(int classnum, int index)
classnum
- class number of objectindex
- index into field tablepublic static int getFieldType(int classnum, int index)
classnum
- class number of objectindex
- index into field tablepublic static int getModifiers0(int classnum, int index)
classnum
- class number of objectindex
- index into field tablepublic static String getMethodString(int classnum, int index, int query)
classnum
- class number of objectindex
- index into method tablequery
- index into method entrypublic static int getMethodPrimitive(int clasnum, int index, int query)
clasnum
- class number of objectindex
- index into method tablequery
- index into method entrypublic static byte[] getMethodByteArray(int classnum, int index, int query)
classnum
- class number of objectindex
- index into method tablequery
- index into method entrypublic static long invoke0(int classnum, int methodnum, int[] args)
classnum
- class number of objectmethodnum
- NOT TO BE CONFUSED WITH METHOD INDEX. The method number of the method (queried with getMethodPrimitive.args
- Array of four byte values. All primitives must be converted to their primitive representation (Float.floatToIntBits, etc), all objects must be turned into ints (Tools.obj2long(...)).public static short findMethodByName(int classnum, String compare)
mIndex = Tools.findMethodByName(PrintStreamNum,\"println(Ljava.lang.String;)V\");
classnum
- class number to searchcompare
- String name of methodpublic static int findMethodByName2(int classnum, String compare)
classnum
- class number to searchcompare
- String name of methodpublic static short findFieldByName(int classnum, String compare)
fIndex = Tools.findFieldByName(IntegerCnum,\"TYPE\");
classnum
- class number to searchcompare
- String name of fieldpublic static short findFieldByName2(int classnum, String compare)
classnum
- class number to searchcompare
- String name of methodpublic static short findMethodByIndex(int value)
value
- entry from a stack trace dumppublic static Field getFieldClass(int index, int classnum)
index
- index into field/method tableclassnum
- class number of objectpublic static Method getMethodClass(int index, int classnum)
index
- index into field/method tableclassnum
- class number of objectpublic static Constructor getConstructorClass(int index, int classnum)
index
- index into field/method tableclassnum
- class number of objectpublic static long array_set(Object array, int index, int flags, int iPrim, Object obj, long lPrim)
obj2long
array
- array to operate onindex
- index of element in questionflags
- the following flags are available:iPrim
- for setting byte/short/int valuesobj
- for setting object valueslPrim
- for setting long valuespublic static Object arrayNewInstance(Class x, int size)
x
- Class class of type to be createssize
- Number of elementspublic static Object arrayNewInstance2(Class x, int[] size)
x
- ?size
- ?public static long obj2long(Object x)
x
- Object to change.public static Object long2obj(long x)
x
- object in long clothingpublic static Object allocateClass(Class s)
s
- Class class of object to create. Do not feed a primitive class.public static int getStackTrace(int[] bt)
bt
- int array - must be at least 64 entries long.public static int[] getInterfacesNative(int classNum)
classNum
- ?IllegalArgumentException
- if the class number is invalidpublic static int inum2mnum(int classnum, int inum)
classnum
- Classnumber of objectinum
- Interface method hash codepublic static int strcmpM(String str1, String str2)
method:(II)Ljava/lang/String;
and does a string compare on them.str1
- first method stringstr2
- second method stringpublic static int strcmpF(String str1, String str2)
field:Ljava.lang.Object;
and does a string compare on them. Ignores everything
after a colon.str1
- first field strigstr2
- second field stringpublic static String getMethodName(int classnum, int index)
classnum
- ?index
- ?public static String getFullMethodDescriptor(int classnum, int index)
void Float.intBitsToFloat(int)
would return (I)V.classnum
- class number to queryindex
- index of method in method tablepublic static String getFieldName(int classnum, int index)
classnum
- ?index
- ?public static char prim2char(int prim)
prim
- ?public static Class prim2class(int prim)
prim
- ?public static void markClassFindable(int cnum)
Marks a class to be findable by the Class.forName(java.lang.String)
method.
This function is only useful when cnum
refers to a dynamically loaded class.
This allows us to dynamically load some classes through the forName
method,
but also solve the name-space issue, since classes loaded by any other class loader
will not be findable by forName
.
This behavior makes our primordial class loader a little schizophrenic--the 'primordial' class loader is actually the primordial class loader plus a 'File System' class loader with special powers. This behavior may change in future releases.
cnum
- class number to mark as 'findable'public static boolean isInterfaceAssignableFrom(int classNum, int interfaceClassNum)
classNum
- ?interfaceClassNum
- ?public static Class createClassClass(int magicNum, int type, int componentType)
magicNum
- ?type
- ?componentType
- ?