org.jikesrvm.compilers.common
Class RuntimeCompiler

java.lang.Object
  extended by org.jikesrvm.compilers.common.RuntimeCompiler
All Implemented Interfaces:
Callbacks.ExitMonitor, Constants, HeapLayoutConstants, ThinLockConstants, TIBLayoutConstants, SizeConstants

public class RuntimeCompiler
extends Object
implements Constants, Callbacks.ExitMonitor

Harness to select which compiler to dynamically compile a method in first invocation.

A place to put code common to all runtime compilers. This includes instrumentation code to get equivalent data for each of the runtime compilers.

We collect the following data for each compiler

  1. total number of methods complied by the compiler
  2. total compilation time in milliseconds.
  3. total number of bytes of bytecodes compiled by the compiler (under the assumption that there is no padding in the bytecode array and thus RVMMethod.getBytecodes().length is the number bytes of bytecode for a method)
  4. total number of machine code instructions generated by the compiler (under the assumption that there is no (excessive) padding in the machine code array and thus CompiledMethod.numberOfInsturctions() is a close enough approximation of the number of machinecodes generated)
Note that even if 3. & 4. are inflated due to padding, the numbers will still be an accurate measure of the space costs of the compile-only approach.


Field Summary
static byte BASELINE_COMPILER
           
protected static boolean compilationInProgress
          is opt compiler currently in use?
protected static boolean compilerEnabled
          is the opt compiler usable?
private static String[] earlyOptArgs
           
static byte JNI_COMPILER
           
private static String[] name
           
static byte OPT_COMPILER
           
static Object optimizationPlan
           
static Object options
           
private static int[] totalBCLength
           
private static double[] totalCompTime
           
private static double[] totalLogOfRates
           
private static int[] totalLogValueMethods
           
private static int[] totalMCLength
           
private static int[] totalMethods
           
 
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
 
Constructor Summary
RuntimeCompiler()
           
 
Method Summary
static CompiledMethod baselineCompile(NormalMethod method)
          This method will compile the passed method using the baseline compiler.
static void boot()
           
static CompiledMethod compile(NativeMethod method)
          Compile the stub for a native method when it is first invoked.
static CompiledMethod compile(NormalMethod method)
          Compile a Java method when it is first invoked.
protected static CompiledMethod fallback(NormalMethod method)
          This method uses the default compiler (baseline) to compile a method It is typically called when a more aggressive compilation fails.
static double getBaselineRate()
          Return the current estimate of basline-compiler rate, in bcb/msec
static String getCompilerName(byte compiler)
          returns the string version of compiler number, using the naming scheme in this file
 void notifyExit(int value)
          To be called when the VM is about to exit.
private static CompiledMethod optCompile(NormalMethod method, CompilationPlan plan)
          Attempt to compile the passed method with the Compiler.
static CompiledMethod optCompileWithFallBack(NormalMethod method)
          This method tries to compile the passed method with the Compiler, using the default compilation plan.
static CompiledMethod optCompileWithFallBack(NormalMethod method, CompilationPlan plan)
          This method tries to compile the passed method with the Compiler with the passed compilation plan.
private static CompiledMethod optCompileWithFallBackInternal(NormalMethod method, CompilationPlan plan)
          This real method that performs the opt compilation.
static void processCommandLineArg(String prefix, String arg)
           
static void processOptCommandLineArg(String prefix, String arg)
          Process command line argument destined for the opt compiler
static int recompileWithOpt(CompilationPlan plan)
          This method tries to compile the passed method with the Compiler.
static int recompileWithOpt(NormalMethod method)
          A wrapper method for those callers who don't want to make optimization plans
static CompiledMethod recompileWithOptOnStackSpecialization(CompilationPlan plan)
           
static void record(byte compiler, NativeMethod method, CompiledMethod compiledMethod)
          This method records the time and sizes (bytecode and machine code) for a compilation
static void record(byte compiler, NormalMethod method, CompiledMethod compiledMethod)
          This method records the time and sizes (bytecode and machine code) for a compilation.
private static void recordCompilation(byte compiler, int BCLength, int MCLength, double compTime)
          This method does the actual recording
static void report(boolean explain)
          This method produces a summary report of compilation activities
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JNI_COMPILER

public static final byte JNI_COMPILER
See Also:
Constant Field Values

BASELINE_COMPILER

public static final byte BASELINE_COMPILER
See Also:
Constant Field Values

OPT_COMPILER

public static final byte OPT_COMPILER
See Also:
Constant Field Values

name

private static final String[] name

totalMethods

private static int[] totalMethods

totalCompTime

private static double[] totalCompTime

totalBCLength

private static int[] totalBCLength

totalMCLength

private static int[] totalMCLength

totalLogOfRates

private static double[] totalLogOfRates

totalLogValueMethods

private static int[] totalLogValueMethods

earlyOptArgs

private static String[] earlyOptArgs

compilerEnabled

protected static boolean compilerEnabled
is the opt compiler usable? This will be the case after booting.


compilationInProgress

protected static boolean compilationInProgress
is opt compiler currently in use? This flag is used to detect/avoid recursive opt compilation (ie when opt compilation causes a method to be compiled). We also make all public entrypoints static synchronized methods because the opt compiler is not reentrant. There are two cases here:
  1. recursive opt compilation by the same thread (always bad)
  2. parallel opt compilation (currently bad because opt compiler is not reentrant, future ok)

NOTE: The associated code can be quite subtle, so please be absolutely sure you know what you're doing before modifying it!!!


options

public static final Object options

optimizationPlan

public static Object optimizationPlan
Constructor Detail

RuntimeCompiler

public RuntimeCompiler()
Method Detail

notifyExit

public void notifyExit(int value)
To be called when the VM is about to exit.

Specified by:
notifyExit in interface Callbacks.ExitMonitor
Parameters:
value - the exit value

record

public static void record(byte compiler,
                          NormalMethod method,
                          CompiledMethod compiledMethod)
This method records the time and sizes (bytecode and machine code) for a compilation.

Parameters:
compiler - the compiler used
method - the resulting RVMMethod
compiledMethod - the resulting compiled method

record

public static void record(byte compiler,
                          NativeMethod method,
                          CompiledMethod compiledMethod)
This method records the time and sizes (bytecode and machine code) for a compilation

Parameters:
compiler - the compiler used
method - the resulting RVMMethod
compiledMethod - the resulting compiled method

recordCompilation

private static void recordCompilation(byte compiler,
                                      int BCLength,
                                      int MCLength,
                                      double compTime)
This method does the actual recording

Parameters:
compiler - the compiler used
BCLength - the number of bytecodes in method source
MCLength - the length of the generated machine code
compTime - the compilation time in ms

report

public static void report(boolean explain)
This method produces a summary report of compilation activities

Parameters:
explain - Explains the metrics used in the report

getBaselineRate

public static double getBaselineRate()
Return the current estimate of basline-compiler rate, in bcb/msec


baselineCompile

public static CompiledMethod baselineCompile(NormalMethod method)
This method will compile the passed method using the baseline compiler.

Parameters:
method - the method to compile

processOptCommandLineArg

public static void processOptCommandLineArg(String prefix,
                                            String arg)
Process command line argument destined for the opt compiler


optCompile

private static CompiledMethod optCompile(NormalMethod method,
                                         CompilationPlan plan)
                                  throws OptimizingCompilerException
Attempt to compile the passed method with the Compiler. Don't handle OptimizingCompilerExceptions (leave it up to caller to decide what to do)

Precondition: compilationInProgress "lock" has been acquired

Parameters:
method - the method to compile
plan - the plan to use for compiling the method
Throws:
OptimizingCompilerException

optCompileWithFallBack

public static CompiledMethod optCompileWithFallBack(NormalMethod method)
This method tries to compile the passed method with the Compiler, using the default compilation plan. If this fails we will use the quicker compiler (baseline for now) The following is carefully crafted to avoid (infinte) recursive opt compilation for all combinations of bootimages & lazy/eager compilation. Be absolutely sure you know what you're doing before changing it !!!

Parameters:
method - the method to compile

optCompileWithFallBack

public static CompiledMethod optCompileWithFallBack(NormalMethod method,
                                                    CompilationPlan plan)
This method tries to compile the passed method with the Compiler with the passed compilation plan. If this fails we will use the quicker compiler (baseline for now) The following is carefully crafted to avoid (infinite) recursive opt compilation for all combinations of bootimages & lazy/eager compilation. Be absolutely sure you know what you're doing before changing it !!!

Parameters:
method - the method to compile
plan - the compilation plan to use for the compile

optCompileWithFallBackInternal

private static CompiledMethod optCompileWithFallBackInternal(NormalMethod method,
                                                             CompilationPlan plan)
This real method that performs the opt compilation.

Parameters:
method - the method to compile
plan - the compilation plan to use

recompileWithOptOnStackSpecialization

public static CompiledMethod recompileWithOptOnStackSpecialization(CompilationPlan plan)

recompileWithOpt

public static int recompileWithOpt(CompilationPlan plan)
This method tries to compile the passed method with the Compiler. It will install the new compiled method in the VM, if successful.

NOTE: the recompile method should never be invoked via RuntimeCompiler.compile; it does not have sufficient guards against recursive recompilation.

Parameters:
plan - the compilation plan to use
Returns:
the CMID of the new method if successful, -1 if the recompilation failed.

recompileWithOpt

public static int recompileWithOpt(NormalMethod method)
A wrapper method for those callers who don't want to make optimization plans

Parameters:
method - the method to recompile

fallback

protected static CompiledMethod fallback(NormalMethod method)
This method uses the default compiler (baseline) to compile a method It is typically called when a more aggressive compilation fails. This method is safe to invoke from RuntimeCompiler.compile.


boot

public static void boot()

processCommandLineArg

public static void processCommandLineArg(String prefix,
                                         String arg)

compile

public static CompiledMethod compile(NormalMethod method)
Compile a Java method when it is first invoked.

Parameters:
method - the method to compile
Returns:
its compiled method.

compile

public static CompiledMethod compile(NativeMethod method)
Compile the stub for a native method when it is first invoked.

Parameters:
method - the method to compile
Returns:
its compiled method.

getCompilerName

public static String getCompilerName(byte compiler)
returns the string version of compiler number, using the naming scheme in this file

Parameters:
compiler - the compiler of interest
Returns:
the string version of compiler number