Class Klass

java.lang.Object
  |
  +--JavaElement
        |
        +--Klass

class Klass
extends JavaElement
implements JVM


Field Summary
(package private)  int access_flags
           
(package private)  AttributeTable attributes
           
(package private) static boolean[] BytecodeUsed
          array giving the bytecodes used in our program.
private static java.util.Hashtable Classes
          hashtable: classname string -> Klass object.
(package private)  int classIndex
          the index of this class in structures like the ClassTable.
(package private) static int CLASSINFO_ARRAY
          code for a scalar-array class.
(package private) static int CLASSINFO_ARRAYOFOBJECTS
          code for an object-array class.
(package private) static int CLASSINFO_OBJECT
          code for a normal class.
(package private) static java.util.Vector ClassList
          vector of all Klass objects.
(package private)  java.lang.String className
          name of the class. classname in slash-syntax for ordinary classes, signature with '[' for array classes, signature enclosed in dashes for primitive types.
(package private)  ConstantPool constant_pool
           
(package private)  int dataSize
          data size of the instance fields, not including management overhead.
(package private)  FieldInfo[] fields
           
(package private)  int fullVtableSize
          number of entries in the virtual-or-interface function table for this class.
(package private)  int instanceofClassIndex
          the index of this class for 'instanceof' checks.
(package private) static java.util.Vector instanceofTargetClassList
          vector of all target classes for 'instanceof' checks.
(package private)  Klass[] interfaces
           
(package private)  boolean[] itable
          the 'instanceof' compatibility array for this class.
(package private)  int magic
           
(package private)  int major_version
           
(package private)  MethodInfo[] methods
           
(package private)  int minor_version
           
(package private) static java.util.Vector neededObjectFields
          vector of all needed static fields of object type.
(package private) static java.util.Vector neededScalarFields
          vector of all needed static fields of scalar type.
(package private)  java.util.Vector subclasses
          (for a class) list of direct subclasses -or- (for an interface) list of subinterfaces and directly implementing classes.
(package private)  Klass superclass
           
(package private) static java.util.Vector targetClassList
          vector of all classes having an explicit representation in our resulting target code.
(package private)  java.util.Vector vtable
          the virtual-or-interface function table of this class.
 
Fields inherited from class JavaElement
EXACT_INSTANCE_NEEDED, INSTANCE_NEEDED, NEEDED, NEEDED_INSTANCEOF, NEEDED_VIRTUALLY, neededModeAddOn, neededModeBasic, neededReasons, UNNEEDED
 
Constructor Summary
(package private) Klass(java.lang.String classname)
          construct a non-loaded class (like an array class) that's completely defined by its name/Signature.
(package private) Klass(java.lang.String classname, java.io.InputStream instream)
          construct a class from a class file
 
Method Summary
private  void addAllSubclasses(java.util.Vector coll)
           
private  void addAllSuperclasses(java.util.Vector coll)
           
(package private)  void addSubclass(Klass cl)
          helper method for the contruction's phase: register a subclass.
(package private) static void assignAllClassIndices()
          assign class indices to all needed classes.
(package private) static java.util.Vector clinitOrdering()
          compute an appropriate ordering of the needed <clinit> methods.
(package private)  void fillItable()
          compute the 'instanceof' class compatibility table 'itable' for this class.
(package private)  FieldInfo findField(java.lang.String name)
          finds a field with a given name.
(package private)  MethodInfo findMethod(java.lang.String name)
          finds a method with given name in this class and its superclasses.
(package private)  MethodInfo findMethod(java.lang.String name, java.lang.String signature)
          finds a method with given name and signature (exact!)
(package private) static Klass forName(java.lang.String name)
          returns a class descriptor for a class with a given name.
(package private) static Klass forSignature(java.lang.String signature)
          returns a class descriptor for a given type signature.
(package private) static boolean[] getAllBytecodesUsed()
          returns an array showing all bytecodes used in all classes.
(package private)  java.util.Vector getAllSubclasses()
          return a Vector of all (currently known) subclasses.
(package private)  java.util.Vector getAllSuperclasses()
          return a Vector of all superclasses and implemented interfaces.
(package private)  java.lang.String getSignature()
          returns the classname in signature syntax.
(package private)  boolean hasSuperclass(Klass sup)
          check whether this class has a given class as direct or indirect superclass.
(package private)  boolean isCastableTo(Klass target)
          check whether a direct instance of this class can be cast to the 'target' class.
(package private)  void layoutFields()
          lay out the fields of this class.
(package private) static void layoutFieldsAll()
          lay out the fields for all classes
(package private) static void layoutItableAll()
          compute the 'instanceof' class compatibility table 'itable' for all classes.
(package private) static void layoutVtableAll()
          lay out the vtables for all classes and interfaces.
(package private)  void markBytecodesUsed(boolean[] bytecodesUsed)
          marks the bytecodes used in the needed methods of this class.
(package private)  void markNeeded(java.lang.Object reason, int mode)
          mark this class needed in a specific mode, adding logically to the current mode.
(package private)  void report()
           
(package private) static void reportAll()
          print to System.out a report on all classes and their elements.
 java.lang.String toString()
          the full name of this class.
(package private) static void updateAll()
          do one iteration to update the 'needed' state of all elements.
(package private)  void updateNeeded()
          update the 'needed' state of this class and the elements this class depends upon.
 void writeNeeded(java.lang.String baseDir)
          write a new classfile containing only the needed parts of this class.
(package private) static void writeNeededAll(java.lang.String baseDir)
          write all needed classes (only the needed elements) to new classfiles.
 
Methods inherited from class JavaElement
isNeeded, isNeeded
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

CLASSINFO_OBJECT

static final int CLASSINFO_OBJECT
code for a normal class.

CLASSINFO_ARRAY

static final int CLASSINFO_ARRAY
code for a scalar-array class.

CLASSINFO_ARRAYOFOBJECTS

static final int CLASSINFO_ARRAYOFOBJECTS
code for an object-array class.

Classes

private static java.util.Hashtable Classes
hashtable: classname string -> Klass object.

ClassList

static java.util.Vector ClassList
vector of all Klass objects.

targetClassList

static java.util.Vector targetClassList
vector of all classes having an explicit representation in our resulting target code. The field 'classIndex' is an index into this vector.

instanceofTargetClassList

static java.util.Vector instanceofTargetClassList
vector of all target classes for 'instanceof' checks. The field 'instanceofClassIndex' is an index into this vector.

neededScalarFields

static java.util.Vector neededScalarFields
vector of all needed static fields of scalar type. For these fields, 'FieldInfo.fieldIndex' is an index into this vector.

neededObjectFields

static java.util.Vector neededObjectFields
vector of all needed static fields of object type. For these fields, 'FieldInfo.fieldIndex' is an index into this vector.

BytecodeUsed

static boolean[] BytecodeUsed
array giving the bytecodes used in our program. 'BytecodeUsed[C] == true' means: bytecode C is used at least once in the code.

magic

int magic

minor_version

int minor_version

major_version

int major_version

constant_pool

ConstantPool constant_pool

access_flags

int access_flags

superclass

Klass superclass

interfaces

Klass[] interfaces

subclasses

java.util.Vector subclasses
(for a class) list of direct subclasses -or- (for an interface) list of subinterfaces and directly implementing classes.

fields

FieldInfo[] fields

methods

MethodInfo[] methods

attributes

AttributeTable attributes

className

java.lang.String className
name of the class. classname in slash-syntax for ordinary classes, signature with '[' for array classes, signature enclosed in dashes for primitive types.

classIndex

int classIndex
the index of this class in structures like the ClassTable.

instanceofClassIndex

int instanceofClassIndex
the index of this class for 'instanceof' checks.

dataSize

int dataSize
data size of the instance fields, not including management overhead.

fullVtableSize

int fullVtableSize
number of entries in the virtual-or-interface function table for this class. This field also counts the additional table entries for interface methods.

vtable

java.util.Vector vtable
the virtual-or-interface function table of this class.

itable

boolean[] itable
the 'instanceof' compatibility array for this class.

Let

Then 'itable[n]' is true if and only if 'I instanceof C' is true. The array is only filled for classes having instances (at least INSTANCE_NEEDED flag set).
Constructor Detail

Klass

Klass(java.lang.String classname)
construct a non-loaded class (like an array class) that's completely defined by its name/Signature.

Klass

Klass(java.lang.String classname,
      java.io.InputStream instream)
throws java.io.IOException
construct a class from a class file
Method Detail

forName

static Klass forName(java.lang.String name)
returns a class descriptor for a class with a given name. The name can also be an array classname beginning with '['. Classnames in dot-syntax are converted to slash-syntax.

forSignature

static Klass forSignature(java.lang.String signature)
returns a class descriptor for a given type signature. Signature can be 'Lxxx;' or '[xxx' for normal classes or array classes, respectively.

addSubclass

void addSubclass(Klass cl)
helper method for the contruction's phase: register a subclass.

markNeeded

void markNeeded(java.lang.Object reason,
                int mode)
mark this class needed in a specific mode, adding logically to the current mode. As a side-effect, all elements that this one depends upon, are also marked 'needed' recursively.
Parameters:
reason - the reason why this element is needed (normally another JavaElement referencing this one).
mode - a mode constant describing how this element is needed.
Overrides:
markNeeded in class JavaElement

updateNeeded

void updateNeeded()
update the 'needed' state of this class and the elements this class depends upon.
Overrides:
updateNeeded in class JavaElement

updateAll

static void updateAll()
do one iteration to update the 'needed' state of all elements.

markBytecodesUsed

void markBytecodesUsed(boolean[] bytecodesUsed)
marks the bytecodes used in the needed methods of this class.

getAllBytecodesUsed

static boolean[] getAllBytecodesUsed()
returns an array showing all bytecodes used in all classes.
Returns:
a boolean array, indexed by bytecode, element='true' means that the corresponding bytecode is used.

layoutFields

void layoutFields()
lay out the fields of this class. This method computes the address offsets for the fields for this class.

layoutFieldsAll

static void layoutFieldsAll()
lay out the fields for all classes

layoutVtableAll

static void layoutVtableAll()
lay out the vtables for all classes and interfaces.

assignAllClassIndices

static void assignAllClassIndices()
assign class indices to all needed classes.

clinitOrdering

static java.util.Vector clinitOrdering()
compute an appropriate ordering of the needed <clinit> methods. Superclass clinit methods have to precede those of their subclasses.
Returns:
vector of all <clinit> methods in an appropriate ordering.

fillItable

void fillItable()
compute the 'instanceof' class compatibility table 'itable' for this class.

layoutItableAll

static void layoutItableAll()
compute the 'instanceof' class compatibility table 'itable' for all classes.

getSignature

java.lang.String getSignature()
returns the classname in signature syntax.

findField

FieldInfo findField(java.lang.String name)
finds a field with a given name.

findMethod

MethodInfo findMethod(java.lang.String name,
                      java.lang.String signature)
finds a method with given name and signature (exact!) in this class and its superclasses.

findMethod

MethodInfo findMethod(java.lang.String name)
finds a method with given name in this class and its superclasses.

isCastableTo

boolean isCastableTo(Klass target)
check whether a direct instance of this class can be cast to the 'target' class.

hasSuperclass

boolean hasSuperclass(Klass sup)
check whether this class has a given class as direct or indirect superclass.

getAllSuperclasses

java.util.Vector getAllSuperclasses()
return a Vector of all superclasses and implemented interfaces.

addAllSuperclasses

private void addAllSuperclasses(java.util.Vector coll)

getAllSubclasses

java.util.Vector getAllSubclasses()
return a Vector of all (currently known) subclasses. For an interface, all sub-interfaces and implementing classes are returned.

addAllSubclasses

private void addAllSubclasses(java.util.Vector coll)

writeNeeded

public void writeNeeded(java.lang.String baseDir)
                 throws java.io.IOException
write a new classfile containing only the needed parts of this class. The base directory is provided by the caller, the method uses (and creates) a subdirectory corresponding to the package of this class.

The method does its work by creating a new classfile from the internal representations of the class members.


writeNeededAll

static void writeNeededAll(java.lang.String baseDir)
write all needed classes (only the needed elements) to new classfiles.

toString

public java.lang.String toString()
the full name of this class.
Overrides:
toString in class java.lang.Object

report

void report()

reportAll

static void reportAll()
print to System.out a report on all classes and their elements.