org.jikesrvm.compilers.baseline
Class BuildReferenceMaps

java.lang.Object
  extended by org.jikesrvm.compilers.baseline.BuildReferenceMaps
All Implemented Interfaces:
BytecodeConstants, ClassLoaderConstants, BBConstants

final class BuildReferenceMaps
extends Object
implements BytecodeConstants, ClassLoaderConstants, BBConstants

This class builds the reference and non-reference maps for a given method. The maps are recorded with ReferenceMaps. This class works with the baseline compiler, calculating the maps for local variables (including parameters), and the java operand stack. Given the basic blocks mapped out by BuildBB determine for each GC point (call sites and new's, etc) what the stack and variable maps are. Note that this class deals with reference maps (the term "stack maps" was not used as it is too ambiguous - does "stack" refer to the java operand stack or a C-like stack?; when processing java bytecodes it seemed best to use "stack" for java operand stack.)


Nested Class Summary
private static class BuildReferenceMaps.PrimitiveSize
           
 
Field Summary
(package private)  int JSRSubNext
           
(package private) static byte NON_REFERENCE
          The entry in the reference map contains a value that is not a reference.
(package private) static byte NOT_SET
          The entry in the reference map is not set in a JSR body.
(package private) static byte REFERENCE
          The entry in the reference map contains a value that is a reference.
(package private) static byte RETURN_ADDRESS
          The entry in the reference map contains a JSR return address.
(package private) static byte SET_TO_NONREFERENCE
          The entry in the reference map is set to a value that is not a reference within a JSR body.
(package private) static byte SET_TO_REFERENCE
          The entry in the reference map is set to a value that is a reference within a JSR body.
(package private)  int workStkTop
           
 
Fields inherited from interface org.jikesrvm.classloader.BytecodeConstants
JBC_aaload, JBC_aastore, JBC_aconst_null, JBC_aload, JBC_aload_0, JBC_aload_1, JBC_aload_2, JBC_aload_3, JBC_anewarray, JBC_areturn, JBC_arraylength, JBC_astore, JBC_astore_0, JBC_astore_1, JBC_astore_2, JBC_astore_3, JBC_athrow, JBC_baload, JBC_bastore, JBC_bipush, JBC_caload, JBC_castore, JBC_checkcast, JBC_d2f, JBC_d2i, JBC_d2l, JBC_dadd, JBC_daload, JBC_dastore, JBC_dcmpg, JBC_dcmpl, JBC_dconst_0, JBC_dconst_1, JBC_ddiv, JBC_dload, JBC_dload_0, JBC_dload_1, JBC_dload_2, JBC_dload_3, JBC_dmul, JBC_dneg, JBC_drem, JBC_dreturn, JBC_dstore, JBC_dstore_0, JBC_dstore_1, JBC_dstore_2, JBC_dstore_3, JBC_dsub, JBC_dup, JBC_dup_x1, JBC_dup_x2, JBC_dup2, JBC_dup2_x1, JBC_dup2_x2, JBC_f2d, JBC_f2i, JBC_f2l, JBC_fadd, JBC_faload, JBC_fastore, JBC_fcmpg, JBC_fcmpl, JBC_fconst_0, JBC_fconst_1, JBC_fconst_2, JBC_fdiv, JBC_fload, JBC_fload_0, JBC_fload_1, JBC_fload_2, JBC_fload_3, JBC_fmul, JBC_fneg, JBC_frem, JBC_freturn, JBC_fstore, JBC_fstore_0, JBC_fstore_1, JBC_fstore_2, JBC_fstore_3, JBC_fsub, JBC_getfield, JBC_getstatic, JBC_goto, JBC_goto_w, JBC_i2d, JBC_i2f, JBC_i2l, JBC_iadd, JBC_iaload, JBC_iand, JBC_iastore, JBC_iconst_0, JBC_iconst_1, JBC_iconst_2, JBC_iconst_3, JBC_iconst_4, JBC_iconst_5, JBC_iconst_m1, JBC_idiv, JBC_if_acmpeq, JBC_if_acmpne, JBC_if_icmpeq, JBC_if_icmpge, JBC_if_icmpgt, JBC_if_icmple, JBC_if_icmplt, JBC_if_icmpne, JBC_ifeq, JBC_ifge, JBC_ifgt, JBC_ifle, JBC_iflt, JBC_ifne, JBC_ifnonnull, JBC_ifnull, JBC_iinc, JBC_iload, JBC_iload_0, JBC_iload_1, JBC_iload_2, JBC_iload_3, JBC_impdep1, JBC_impdep2, JBC_imul, JBC_ineg, JBC_instanceof, JBC_int2byte, JBC_int2char, JBC_int2short, JBC_invokeinterface, JBC_invokespecial, JBC_invokestatic, JBC_invokevirtual, JBC_ior, JBC_irem, JBC_ireturn, JBC_ishl, JBC_ishr, JBC_istore, JBC_istore_0, JBC_istore_1, JBC_istore_2, JBC_istore_3, JBC_isub, JBC_iushr, JBC_ixor, JBC_jsr, JBC_jsr_w, JBC_l2d, JBC_l2f, JBC_l2i, JBC_ladd, JBC_laload, JBC_land, JBC_lastore, JBC_lcmp, JBC_lconst_0, JBC_lconst_1, JBC_ldc, JBC_ldc_w, JBC_ldc2_w, JBC_ldiv, JBC_length, JBC_lload, JBC_lload_0, JBC_lload_1, JBC_lload_2, JBC_lload_3, JBC_lmul, JBC_lneg, JBC_lookupswitch, JBC_lor, JBC_lrem, JBC_lreturn, JBC_lshl, JBC_lshr, JBC_lstore, JBC_lstore_0, JBC_lstore_1, JBC_lstore_2, JBC_lstore_3, JBC_lsub, JBC_lushr, JBC_lxor, JBC_monitorenter, JBC_monitorexit, JBC_multianewarray, JBC_name, JBC_new, JBC_newarray, JBC_nop, JBC_pop, JBC_pop2, JBC_putfield, JBC_putstatic, JBC_ret, JBC_return, JBC_saload, JBC_sastore, JBC_sipush, JBC_swap, JBC_tableswitch, JBC_wide, JBC_xxxunusedxxx
 
Fields inherited from interface org.jikesrvm.classloader.ClassLoaderConstants
ACC_ABSTRACT, ACC_ANNOTATION, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VOLATILE, APPLICABLE_TO_CLASSES, APPLICABLE_TO_FIELDS, APPLICABLE_TO_METHODS, ArrayTypeCode, BooleanTypeCode, BRIDGE, ByteTypeCode, CharTypeCode, CLASS_INITIALIZED, CLASS_INITIALIZER_FAILED, CLASS_INITIALIZING, CLASS_INSTANTIATED, CLASS_LOADED, CLASS_RESOLVED, CLASS_VACANT, ClassTypeCode, CP_CLASS, CP_DOUBLE, CP_FLOAT, CP_INT, CP_LONG, CP_MEMBER, CP_STRING, CP_UTF, DoubleTypeCode, FloatTypeCode, IntTypeCode, LongTypeCode, ShortTypeCode, TAG_DOUBLE, TAG_FIELDREF, TAG_FLOAT, TAG_INT, TAG_INTERFACE_METHODREF, TAG_LONG, TAG_MEMBERNAME_AND_DESCRIPTOR, TAG_METHODREF, TAG_STRING, TAG_TYPEREF, TAG_UNUSED, TAG_UTF, VARARGS, VoidTypeCode
 
Fields inherited from interface org.jikesrvm.compilers.baseline.BBConstants
ADDRESS_TYPE, CONDITIONAL_, CONDITIONALTARGET, DOUBLE_TYPE, DUMMYBLOCK, EXCEPTIONHANDLER, EXITBLOCK, FALLTHRU_, FALLTHRUTARGET, FLOAT_TYPE, HASHANDLER_, INJSR_, INT_TYPE, JSRENTRY, LENGTH_MASK, LONG_TYPE, LONGHALF_TYPE, METHODENTRY, NOTBLOCK, STARTBLOCK, TARGET_, TRYHANDLERSTART, TRYSTART_, UNCONDITIONALTARGET, VOID_TYPE
 
Constructor Summary
BuildReferenceMaps()
           
 
Method Summary
private  short[] addToWorkStk(short blockNum, short[] workStk)
           
private  short[] addUniqueToWorkStk(short blockNum, short[] workStk)
           
 void buildReferenceMaps(NormalMethod method, int[] stackHeights, byte[] localTypes, ReferenceMaps referenceMaps, BuildBB buildBB)
          After the analysis of the blocks of a method, examine the byte codes again, to determine the reference maps for the gc points.
private  short[] computeJSRNextMaps(short nextBBNum, int maplength, int JSRSubIndex, boolean JSRisinJSRSub, byte[][] bbMaps, int[] blockStkTop, JSRSubroutineInfo[] JSRSubs, int currBBStkEmpty, short[] workStk)
           
private  short[] processBranchBB(short brBBNum, int currBBStkTop, byte[] currBBMap, int currBBStkEmpty, boolean inJSRSub, byte[][] bbMaps, int[] blockStkTop, PendingRETInfo currPendingRET, PendingRETInfo[] bbPendingRETs, short[] workStk)
           
private  int processInvoke(MethodReference target, int byteindex, int currBBStkTop, byte[] currBBMap, boolean isStatic, boolean inJSRSub, ReferenceMaps referenceMaps, PendingRETInfo currPendingRET, boolean blockSeen, int currBBStkEmpty)
           
private  short[] processJSR(int JSRBBNum, int JSRSubStartIndex, short brBBNum, short nextBBNum, byte[][] bbMaps, int currBBStkTop, byte[] currBBMap, int currBBStkEmpty, int[] blockStkTop, PendingRETInfo[] bbPendingRETs, PendingRETInfo currPendingRET, JSRSubroutineInfo[] JSRSubs, short[] workStk)
           
private  void setHandlersMapsNonRef(int localVariable, BuildReferenceMaps.PrimitiveSize wordCount, int[] reachableHandlerBBNums, int reachableHandlerCount, boolean inJSRSub, byte[][] bbMaps)
          For each of the reachable handlers (catch blocks) from the try block, track that the local variable given by the index with 1 or 2 words, has been set to a non reference value (eg int, float, etc)
private  void setHandlersMapsRef(int localVariable, int[] reachableHandlerBBNums, int reachableHandlerCount, byte[][] bbMaps)
          For each of the reachable handlers (catch blocks) from the try block, track that the local variable given by the index, has been set to a reference value.
private  void setHandlersMapsReturnAddress(int localVariable, int[] reachableHandlerBBNums, int reachableHandlerCount, byte[][] bbMaps)
          For each of the reachable handlers (catch blocks) from the try block, track that the local variable given by the index, has been set to a return address value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NON_REFERENCE

static final byte NON_REFERENCE
The entry in the reference map contains a value that is not a reference.

See Also:
Constant Field Values

REFERENCE

static final byte REFERENCE
The entry in the reference map contains a value that is a reference.

See Also:
Constant Field Values

RETURN_ADDRESS

static final byte RETURN_ADDRESS
The entry in the reference map contains a JSR return address.

See Also:
Constant Field Values

NOT_SET

static final byte NOT_SET
The entry in the reference map is not set in a JSR body.

See Also:
Constant Field Values

SET_TO_REFERENCE

static final byte SET_TO_REFERENCE
The entry in the reference map is set to a value that is a reference within a JSR body.

See Also:
Constant Field Values

SET_TO_NONREFERENCE

static final byte SET_TO_NONREFERENCE
The entry in the reference map is set to a value that is not a reference within a JSR body.

See Also:
Constant Field Values

workStkTop

int workStkTop

JSRSubNext

int JSRSubNext
Constructor Detail

BuildReferenceMaps

BuildReferenceMaps()
Method Detail

buildReferenceMaps

public void buildReferenceMaps(NormalMethod method,
                               int[] stackHeights,
                               byte[] localTypes,
                               ReferenceMaps referenceMaps,
                               BuildBB buildBB)
After the analysis of the blocks of a method, examine the byte codes again, to determine the reference maps for the gc points. Record the maps with referenceMaps.


addToWorkStk

private short[] addToWorkStk(short blockNum,
                             short[] workStk)

addUniqueToWorkStk

private short[] addUniqueToWorkStk(short blockNum,
                                   short[] workStk)

processBranchBB

private short[] processBranchBB(short brBBNum,
                                int currBBStkTop,
                                byte[] currBBMap,
                                int currBBStkEmpty,
                                boolean inJSRSub,
                                byte[][] bbMaps,
                                int[] blockStkTop,
                                PendingRETInfo currPendingRET,
                                PendingRETInfo[] bbPendingRETs,
                                short[] workStk)

processInvoke

private int processInvoke(MethodReference target,
                          int byteindex,
                          int currBBStkTop,
                          byte[] currBBMap,
                          boolean isStatic,
                          boolean inJSRSub,
                          ReferenceMaps referenceMaps,
                          PendingRETInfo currPendingRET,
                          boolean blockSeen,
                          int currBBStkEmpty)

processJSR

private short[] processJSR(int JSRBBNum,
                           int JSRSubStartIndex,
                           short brBBNum,
                           short nextBBNum,
                           byte[][] bbMaps,
                           int currBBStkTop,
                           byte[] currBBMap,
                           int currBBStkEmpty,
                           int[] blockStkTop,
                           PendingRETInfo[] bbPendingRETs,
                           PendingRETInfo currPendingRET,
                           JSRSubroutineInfo[] JSRSubs,
                           short[] workStk)

computeJSRNextMaps

private short[] computeJSRNextMaps(short nextBBNum,
                                   int maplength,
                                   int JSRSubIndex,
                                   boolean JSRisinJSRSub,
                                   byte[][] bbMaps,
                                   int[] blockStkTop,
                                   JSRSubroutineInfo[] JSRSubs,
                                   int currBBStkEmpty,
                                   short[] workStk)

setHandlersMapsNonRef

private void setHandlersMapsNonRef(int localVariable,
                                   BuildReferenceMaps.PrimitiveSize wordCount,
                                   int[] reachableHandlerBBNums,
                                   int reachableHandlerCount,
                                   boolean inJSRSub,
                                   byte[][] bbMaps)
For each of the reachable handlers (catch blocks) from the try block, track that the local variable given by the index with 1 or 2 words, has been set to a non reference value (eg int, float, etc)

Parameters:
localVariable - Variable index in the map
wordCount - 2 for doubles and longs, 1 otherwise
reachableHandlerBBNums - The array with all the block numbers of reachable handlers
reachableHandlerCount - 0 through reachableHandlerCount - 1 will all be valid array indices
inJSRSub - TODO Document ME XXX
bbMaps - TODO Document ME XXX

setHandlersMapsRef

private void setHandlersMapsRef(int localVariable,
                                int[] reachableHandlerBBNums,
                                int reachableHandlerCount,
                                byte[][] bbMaps)
For each of the reachable handlers (catch blocks) from the try block, track that the local variable given by the index, has been set to a reference value. Only call this method if the try block is in a JSR subroutine. If a non-reference value becomes a reference value, then it can not be used as as reference value within the handler (there is a path to the handler where the value is not a reference) so mark the local variable as a non-reference if we are tracking the difference maps (for a JSR subroutine).

Parameters:
localVariable - Variable index in the map
reachableHandlerBBNums - The array with all the block numbers of reachable handlers
reachableHandlerCount - 0 through reachableHandlerCount - 1 will all be valid array indices
bbMaps - TODO Document ME XXX

setHandlersMapsReturnAddress

private void setHandlersMapsReturnAddress(int localVariable,
                                          int[] reachableHandlerBBNums,
                                          int reachableHandlerCount,
                                          byte[][] bbMaps)
For each of the reachable handlers (catch blocks) from the try block, track that the local variable given by the index, has been set to a return address value. Only call this routine within a JSR subroutine. If a non-reference, or reference value becomes a return address value, then it cannot be used as any of these values within the handler (there is a path to the handler where the value is not an internal reference, and a path where it is an internal reference) so mark the local variable as a non-reference if we are tracking the difference maps (for a JSR subroutine).

Parameters:
localVariable - variable index in the map
reachableHandlerBBNums - the array with all the block numbers of reachable handlers
reachableHandlerCount - 0 through reachableHandlerCount - 1 will all be valid array indices
bbMaps - TODO Document ME XXX