js.tinyvm
Class Binary

java.lang.Object
  extended by js.tinyvm.Binary

public class Binary
extends java.lang.Object

Abstraction for dumped binary.


Constructor Summary
Binary(boolean useAll)
          Constructor.
 
Method Summary
protected  void addClassRecord(java.lang.String className, ClassRecord classRecord)
          Add a class.
static Binary createFromClosureOf(java.lang.String[] entryClassNames, ClassPath classPath, boolean all)
          Create closure.
 void dump(IByteWriter writer)
          Dump.
 void dumpDebug(java.io.OutputStream fos)
          Dump debug data.
 int getClassIndex(ClassRecord classRecord)
          Get index of class in binary by its class record.
 int getClassIndex(java.lang.String className)
          Get index of class in binary by its signature.
 ClassRecord getClassRecord(java.lang.String className)
          Get class record with given signature.
 ClassRecord getClassRecordForArray(ClassRecord elementClass)
          Return the class the represents an array of the given type and dimension.
 int getConstantIndex(ConstantRecord constantRecord)
          Get index of constant in binary by its constant record.
 ConstantRecord getConstantRecord(int index)
          Get constant record with given index.
 int getGeneration()
          Return the current marking generation.
 int getTotalNumExceptionRecords()
           
 int getTotalNumInstanceFields()
           
 int getTotalNumMethods()
           
 boolean hasMain(java.lang.String className)
          Has class in binary a public static void main (String[] args) method?
 void initOffsets()
           
 boolean isSpecialSignature(Signature aSig)
           
 void log(ToolProgressMonitor monitor)
           
 void markClassUsed(ClassRecord classRecord, boolean instance)
          Mark the given class as actually used.
 void markUsed(java.lang.String[] entryClassNames)
           
 void printInterfaces()
           
 void processClasses(java.lang.String[] entryClassNames, ClassPath classPath)
           
 void processCode(boolean aPostProcess)
           
 void processConstants()
           
 void processFields()
           
 void processMethods()
          Calls storeMethods on all the classes of the closure previously computed with processClasses.
 void processOptimizedClasses()
          Optimize the number and order of classes.
 void processOptimizedConstants()
          Store constant values in an optimal fashion.
 void processOptimizedFields()
           
 void processOptimizedMethods()
           
 void processSpecialSignatures()
           
 void setRunTimeOptions(int opt)
           
 void storeComponents()
           
 boolean useAll()
          Return true if unused methods/classes etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Binary

public Binary(boolean useAll)
Constructor.

Parameters:
useAll - true if all classes/methods etc. should be included
Method Detail

dump

public void dump(IByteWriter writer)
          throws TinyVMException
Dump.

Parameters:
writer -
Throws:
TinyVMException

dumpDebug

public void dumpDebug(java.io.OutputStream fos)
               throws java.io.IOException
Dump debug data.

Parameters:
fos - FileOutputStream
Throws:
java.io.IOException

addClassRecord

protected void addClassRecord(java.lang.String className,
                              ClassRecord classRecord)
Add a class.

Parameters:
className - class name with '/'
classRecord -

hasMain

public boolean hasMain(java.lang.String className)
Has class in binary a public static void main (String[] args) method?

Parameters:
className - class name with '/'
Returns:

getClassRecord

public ClassRecord getClassRecord(java.lang.String className)
Get class record with given signature.

Parameters:
className - class name with '/'
Returns:
class record or null if not found

getClassRecordForArray

public ClassRecord getClassRecordForArray(ClassRecord elementClass)
                                   throws TinyVMException
Return the class the represents an array of the given type and dimension.

Parameters:
elementClass -
Returns:
class record or null if not found or the array is a primitive array.
Throws:
TinyVMException

getClassIndex

public int getClassIndex(java.lang.String className)
Get index of class in binary by its signature.

Parameters:
className - class name with '/'
Returns:
index of class in binary or -1 if not found

getClassIndex

public int getClassIndex(ClassRecord classRecord)
Get index of class in binary by its class record.

Parameters:
classRecord -
Returns:
index of class in binary or -1 if not found

markClassUsed

public void markClassUsed(ClassRecord classRecord,
                          boolean instance)
Mark the given class as actually used.

Parameters:
classRecord - the class to be marked
instance -

getGeneration

public int getGeneration()
Return the current marking generation. This is used to ensure that for each new iteration (or generation) of the recursive mark we will walk all of the code at least once.

Returns:
current generation

getConstantRecord

public ConstantRecord getConstantRecord(int index)
Get constant record with given index.

Parameters:
index -
Returns:
constant record or null if not found

getConstantIndex

public int getConstantIndex(ConstantRecord constantRecord)
Get index of constant in binary by its constant record.

Parameters:
constantRecord -
Returns:
index of constant in binary or -1 if not found

useAll

public boolean useAll()
Return true if unused methods/classes etc. should still be included in the output file.

Returns:

createFromClosureOf

public static Binary createFromClosureOf(java.lang.String[] entryClassNames,
                                         ClassPath classPath,
                                         boolean all)
                                  throws TinyVMException
Create closure.

Parameters:
entryClassNames - names of entry class with '/'
classPath - class path
all - do not filter classes?
Returns:
Throws:
TinyVMException

processClasses

public void processClasses(java.lang.String[] entryClassNames,
                           ClassPath classPath)
                    throws TinyVMException
Throws:
TinyVMException

processOptimizedClasses

public void processOptimizedClasses()
                             throws TinyVMException
Optimize the number and order of classes. We make a pass of all of the classes and select only those that are actually used. We also optimize the order of the classes in an attempt to minimize the size of the interface maps.

Throws:
TinyVMException

markUsed

public void markUsed(java.lang.String[] entryClassNames)
              throws TinyVMException
Throws:
TinyVMException

processSpecialSignatures

public void processSpecialSignatures()

isSpecialSignature

public boolean isSpecialSignature(Signature aSig)

processConstants

public void processConstants()
                      throws TinyVMException
Throws:
TinyVMException

processOptimizedConstants

public void processOptimizedConstants()
                               throws TinyVMException
Store constant values in an optimal fashion. We only include constants that are actually used. We also arrange to store constant values correctly aligned so that they can be accessed directly by the VM. We order the constants to allow fast access to the commanly used int/float types.

Throws:
TinyVMException

processMethods

public void processMethods()
                    throws TinyVMException
Calls storeMethods on all the classes of the closure previously computed with processClasses.

Throws:
TinyVMException

processOptimizedMethods

public void processOptimizedMethods()
                             throws TinyVMException
Throws:
TinyVMException

processFields

public void processFields()
                   throws TinyVMException
Throws:
TinyVMException

printInterfaces

public void printInterfaces()
                     throws TinyVMException
Throws:
TinyVMException

processOptimizedFields

public void processOptimizedFields()
                            throws TinyVMException
Throws:
TinyVMException

processCode

public void processCode(boolean aPostProcess)
                 throws TinyVMException
Throws:
TinyVMException

storeComponents

public void storeComponents()

initOffsets

public void initOffsets()
                 throws TinyVMException
Throws:
TinyVMException

setRunTimeOptions

public void setRunTimeOptions(int opt)

getTotalNumMethods

public int getTotalNumMethods()

getTotalNumInstanceFields

public int getTotalNumInstanceFields()

getTotalNumExceptionRecords

public int getTotalNumExceptionRecords()

log

public void log(ToolProgressMonitor monitor)
         throws TinyVMException
Throws:
TinyVMException