korat.instrumentation.bytecode
Class ArrayBytecodesVisitor

java.lang.Object
  extended by korat.instrumentation.bytecode.VisitorSupport
      extended by korat.instrumentation.bytecode.JavassistInstructionVisitor
          extended by korat.instrumentation.bytecode.ArrayBytecodesVisitor
All Implemented Interfaces:
BytecodeVisitor

public class ArrayBytecodesVisitor
extends JavassistInstructionVisitor

Visitor that handles each bytecode instruction in order to instrument all accesses to array fields.

Author:
Aleksandar Milicevic

Field Summary
private static String[] koratArrayClassNames
           This is used when replacing NEWARRAY bytecode instructions.
 
Fields inherited from class korat.instrumentation.bytecode.JavassistInstructionVisitor
booleanType, byteType, charType, classPool, classType, constPool, doubleType, floatType, intType, longType, objectType, operandStack, shortType, stringType, voidType
 
Constructor Summary
ArrayBytecodesVisitor(ClassPool classPool, ConstPool constPool, OperandStack operandStack)
           
 
Method Summary
private  void delegateANewArray(int cpIdx, CodeIterator cit, int idx)
           
private  void delegateArrayAccess(String methodName, CtClass retType, CtClass[] args, CodeIterator cit, int idx)
          Replaces all kinds of array accesses (ARRAYLENGTH, IALOAD, IASTORE, LALOAD, LASTORE, ...) with the specified method call.
private  void delegateArrayGetfield(int cpIdx, CodeIterator cit, int idx)
          Replaces retrieval of the array field with the retrieval of its corresponding KoratArray field.
private  void delegateArrayPutfield(int cpIdx, CodeIterator cit, int idx)
          Replaces setting array field with the setting its corresponding KoratArray field.
private  void delegateNewArray(int arrayType, CodeIterator cit, int idx)
          Replaces creation of the array with the creation of the KoratArray field.
private  CtClass getKoratArrayType(CtClass opType)
           
 void visitAALOAD(BytecodeInstruction instr)
           
 void visitAASTORE(BytecodeInstruction instr)
           
 void visitANEWARRAY(BytecodeInstruction instr)
           
 void visitARRAYLENGTH(BytecodeInstruction instr)
          array.length -> __korat_KoratArray_array.getLength()
 void visitBALOAD(BytecodeInstruction instr)
          byteArray[i] -> __korat_KoratArray_byteArray.get(i)
 void visitBASTORE(BytecodeInstruction instr)
          byteArray[i] = x -> __korat_KoratArray_byteArray.set(i, x)
 void visitCALOAD(BytecodeInstruction instr)
          charArray[i] -> __korat_KoratArray_charArray.get(i)
 void visitCASTORE(BytecodeInstruction instr)
          charArray[i] = x -> __korat_KoratArray_charArray.set(i, x)
 void visitDALOAD(BytecodeInstruction instr)
          doubleArray[i] -> __korat_KoratArray_doubleArray.get(i)
 void visitDASTORE(BytecodeInstruction instr)
          doubleArray[i] = x -> __korat_KoratArray_doubleArray.set(i, x)
 void visitFALOAD(BytecodeInstruction instr)
          floatArray[i] -> __korat_KoratArray_floatArray.get(i)
 void visitFASTORE(BytecodeInstruction instr)
          floatArray[i] = x -> __korat_KoratArray_floatArray.set(i, x)
 void visitGETFIELD(BytecodeInstruction instr)
           
 void visitIALOAD(BytecodeInstruction instr)
          intArray[i] -> __korat_KoratArray_intArray.get(i)
 void visitIASTORE(BytecodeInstruction instr)
          intArray[i] = x -> __korat_KoratArray_intArray.set(i, x)
 void visitLALOAD(BytecodeInstruction instr)
          longArray[i] -> __korat_KoratArray_longArray.get(i)
 void visitLASTORE(BytecodeInstruction instr)
          longArray[i] = x -> __korat_KoratArray_longArray.set(i, x)
 void visitNEWARRAY(BytecodeInstruction instr)
           
 void visitPUTFIELD(BytecodeInstruction instr)
           
 void visitSALOAD(BytecodeInstruction instr)
          shortArray[i] -> __korat_KoratArray_shortArray.get(i)
 void visitSASTORE(BytecodeInstruction instr)
          shortArray[i] = x -> __korat_KoratArray_shortArray.set(i, x)
 
Methods inherited from class korat.instrumentation.bytecode.JavassistInstructionVisitor
checkArrayType, checkArrayType, checkArrayType
 
Methods inherited from class korat.instrumentation.bytecode.VisitorSupport
postVisit, preVisit, visitACONST_NULL, visitALOAD_0, visitALOAD_1, visitALOAD_2, visitALOAD_3, visitALOAD, visitARETURN, visitASTORE_0, visitASTORE_1, visitASTORE_2, visitASTORE_3, visitASTORE, visitATHROW, visitBIPUSH, visitBREAKPOINT, visitCHECKCAST, visitD2F, visitD2I, visitD2L, visitDADD, visitDCMPG, visitDCMPL, visitDCONST_0, visitDCONST_1, visitDDIV, visitDLOAD_0, visitDLOAD_1, visitDLOAD_2, visitDLOAD_3, visitDLOAD, visitDMUL, visitDNEG, visitDREM, visitDRETURN, visitDSTORE_0, visitDSTORE_1, visitDSTORE_2, visitDSTORE_3, visitDSTORE, visitDSUB, visitDUP_X1, visitDUP_X2, visitDUP, visitDUP2_X1, visitDUP2_X2, visitDUP2, visitF2D, visitF2I, visitF2L, visitFADD, visitFCMPG, visitFCMPL, visitFCONST_0, visitFCONST_1, visitFCONST_2, visitFDIV, visitFLOAD_0, visitFLOAD_1, visitFLOAD_2, visitFLOAD_3, visitFLOAD, visitFMUL, visitFNEG, visitFREM, visitFRETURN, visitFSTORE_0, visitFSTORE_1, visitFSTORE_2, visitFSTORE_3, visitFSTORE, visitFSUB, visitGETSTATIC, visitGOTO_W, visitGOTO, visitI2B, visitI2C, visitI2D, visitI2F, visitI2L, visitI2S, visitIADD, visitIAND, visitICONST_0, visitICONST_1, visitICONST_2, visitICONST_3, visitICONST_4, visitICONST_5, visitICONST_M1, visitIDIV, visitIF_ACMPEQ, visitIF_ACMPNE, visitIF_ICMPEQ, visitIF_ICMPGE, visitIF_ICMPGT, visitIF_ICMPLE, visitIF_ICMPLT, visitIF_ICMPNE, visitIFEQ, visitIFGE, visitIFGT, visitIFLE, visitIFLT, visitIFNE, visitIFNONNULL, visitIFNULL, visitIINC, visitILOAD_0, visitILOAD_1, visitILOAD_2, visitILOAD_3, visitILOAD, visitIMPDEP1, visitIMPDEP2, visitIMUL, visitINEG, visitINSTANCEOF, visitINVOKEINTERFACE, visitINVOKESPECIAL, visitINVOKESTATIC, visitINVOKEVIRTUAL, visitIOR, visitIREM, visitIRETURN, visitISHL, visitISHR, visitISTORE_0, visitISTORE_1, visitISTORE_2, visitISTORE_3, visitISTORE, visitISUB, visitIUSHR, visitIXOR, visitJSR_W, visitJSR, visitL2D, visitL2F, visitL2I, visitLADD, visitLAND, visitLCMP, visitLCONST_0, visitLCONST_1, visitLDC_W, visitLDC, visitLDC2_W, visitLDIV, visitLLOAD_0, visitLLOAD_1, visitLLOAD_2, visitLLOAD_3, visitLLOAD, visitLMUL, visitLNEG, visitLOOKUPSWITCH, visitLOR, visitLREM, visitLRETURN, visitLSHL, visitLSHR, visitLSTORE_0, visitLSTORE_1, visitLSTORE_2, visitLSTORE_3, visitLSTORE, visitLSUB, visitLUSHR, visitLXOR, visitMONITORENTER, visitMONITOREXIT, visitMULTIANEWARRAY, visitNEW, visitNOP, visitPOP, visitPOP2, visitPUTSTATIC, visitRET, visitRETURN, visitSIPUSH, visitSWAP, visitTABLESWITCH, visitWIDE
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

koratArrayClassNames

private static String[] koratArrayClassNames

This is used when replacing NEWARRAY bytecode instructions. NEWARRAY is used for arrays of primitive types creation. NEWARRAY instruction is 2 byte long. The second byte represents the primitive type of the array: 4 - boolean, 5 - char, and so on. koratClassNames maps those byte numbers to KoratArray class names.

Constructor Detail

ArrayBytecodesVisitor

public ArrayBytecodesVisitor(ClassPool classPool,
                             ConstPool constPool,
                             OperandStack operandStack)
Method Detail

delegateArrayGetfield

private void delegateArrayGetfield(int cpIdx,
                                   CodeIterator cit,
                                   int idx)
Replaces retrieval of the array field with the retrieval of its corresponding KoratArray field.

Parameters:
cit - - CodeIterator
idx - - current position in the cit
cpIdx - - index for the array field in the cPool
Throws:
NotFoundException

visitGETFIELD

public void visitGETFIELD(BytecodeInstruction instr)
Specified by:
visitGETFIELD in interface BytecodeVisitor
Overrides:
visitGETFIELD in class VisitorSupport

delegateArrayPutfield

private void delegateArrayPutfield(int cpIdx,
                                   CodeIterator cit,
                                   int idx)
Replaces setting array field with the setting its corresponding KoratArray field.

Parameters:
cit - - iterator through method's body code
idx - - current position in the cit
cpIdx - - index for the array field in the cPool
Throws:
NotFoundException

visitPUTFIELD

public void visitPUTFIELD(BytecodeInstruction instr)
Specified by:
visitPUTFIELD in interface BytecodeVisitor
Overrides:
visitPUTFIELD in class VisitorSupport

delegateNewArray

private void delegateNewArray(int arrayType,
                              CodeIterator cit,
                              int idx)
Replaces creation of the array with the creation of the KoratArray field. Just invokes its constructor with the int parameter that represents the length of the array.

Parameters:
arrayType - - type of array in terms of JVM
cit - - iterator through method's body code
idx - - current position in the cit
Throws:
BadBytecode

visitNEWARRAY

public void visitNEWARRAY(BytecodeInstruction instr)
Specified by:
visitNEWARRAY in interface BytecodeVisitor
Overrides:
visitNEWARRAY in class VisitorSupport

delegateANewArray

private void delegateANewArray(int cpIdx,
                               CodeIterator cit,
                               int idx)

visitANEWARRAY

public void visitANEWARRAY(BytecodeInstruction instr)
Specified by:
visitANEWARRAY in interface BytecodeVisitor
Overrides:
visitANEWARRAY in class VisitorSupport

delegateArrayAccess

private void delegateArrayAccess(String methodName,
                                 CtClass retType,
                                 CtClass[] args,
                                 CodeIterator cit,
                                 int idx)
Replaces all kinds of array accesses (ARRAYLENGTH, IALOAD, IASTORE, LALOAD, LASTORE, ...) with the specified method call.

Parameters:
cit - - code iterator
idx - - current position in the cit
methodName - - name of the method to be called
retType - - return type of the method to be called
args - - actual arguments for the method to be called
Throws:
BadBytecode

getKoratArrayType

private CtClass getKoratArrayType(CtClass opType)

visitAALOAD

public void visitAALOAD(BytecodeInstruction instr)
Specified by:
visitAALOAD in interface BytecodeVisitor
Overrides:
visitAALOAD in class VisitorSupport

visitAASTORE

public void visitAASTORE(BytecodeInstruction instr)
Specified by:
visitAASTORE in interface BytecodeVisitor
Overrides:
visitAASTORE in class VisitorSupport

visitARRAYLENGTH

public void visitARRAYLENGTH(BytecodeInstruction instr)
array.length -> __korat_KoratArray_array.getLength()

Specified by:
visitARRAYLENGTH in interface BytecodeVisitor
Overrides:
visitARRAYLENGTH in class VisitorSupport

visitBALOAD

public void visitBALOAD(BytecodeInstruction instr)
byteArray[i] -> __korat_KoratArray_byteArray.get(i)

Specified by:
visitBALOAD in interface BytecodeVisitor
Overrides:
visitBALOAD in class VisitorSupport

visitBASTORE

public void visitBASTORE(BytecodeInstruction instr)
byteArray[i] = x -> __korat_KoratArray_byteArray.set(i, x)

Specified by:
visitBASTORE in interface BytecodeVisitor
Overrides:
visitBASTORE in class VisitorSupport

visitCALOAD

public void visitCALOAD(BytecodeInstruction instr)
charArray[i] -> __korat_KoratArray_charArray.get(i)

Specified by:
visitCALOAD in interface BytecodeVisitor
Overrides:
visitCALOAD in class VisitorSupport

visitCASTORE

public void visitCASTORE(BytecodeInstruction instr)
charArray[i] = x -> __korat_KoratArray_charArray.set(i, x)

Specified by:
visitCASTORE in interface BytecodeVisitor
Overrides:
visitCASTORE in class VisitorSupport

visitDALOAD

public void visitDALOAD(BytecodeInstruction instr)
doubleArray[i] -> __korat_KoratArray_doubleArray.get(i)

Specified by:
visitDALOAD in interface BytecodeVisitor
Overrides:
visitDALOAD in class VisitorSupport

visitDASTORE

public void visitDASTORE(BytecodeInstruction instr)
doubleArray[i] = x -> __korat_KoratArray_doubleArray.set(i, x)

Specified by:
visitDASTORE in interface BytecodeVisitor
Overrides:
visitDASTORE in class VisitorSupport

visitFALOAD

public void visitFALOAD(BytecodeInstruction instr)
floatArray[i] -> __korat_KoratArray_floatArray.get(i)

Specified by:
visitFALOAD in interface BytecodeVisitor
Overrides:
visitFALOAD in class VisitorSupport

visitFASTORE

public void visitFASTORE(BytecodeInstruction instr)
floatArray[i] = x -> __korat_KoratArray_floatArray.set(i, x)

Specified by:
visitFASTORE in interface BytecodeVisitor
Overrides:
visitFASTORE in class VisitorSupport

visitIALOAD

public void visitIALOAD(BytecodeInstruction instr)
intArray[i] -> __korat_KoratArray_intArray.get(i)

Specified by:
visitIALOAD in interface BytecodeVisitor
Overrides:
visitIALOAD in class VisitorSupport

visitIASTORE

public void visitIASTORE(BytecodeInstruction instr)
intArray[i] = x -> __korat_KoratArray_intArray.set(i, x)

Specified by:
visitIASTORE in interface BytecodeVisitor
Overrides:
visitIASTORE in class VisitorSupport

visitLALOAD

public void visitLALOAD(BytecodeInstruction instr)
longArray[i] -> __korat_KoratArray_longArray.get(i)

Specified by:
visitLALOAD in interface BytecodeVisitor
Overrides:
visitLALOAD in class VisitorSupport

visitLASTORE

public void visitLASTORE(BytecodeInstruction instr)
longArray[i] = x -> __korat_KoratArray_longArray.set(i, x)

Specified by:
visitLASTORE in interface BytecodeVisitor
Overrides:
visitLASTORE in class VisitorSupport

visitSALOAD

public void visitSALOAD(BytecodeInstruction instr)
shortArray[i] -> __korat_KoratArray_shortArray.get(i)

Specified by:
visitSALOAD in interface BytecodeVisitor
Overrides:
visitSALOAD in class VisitorSupport

visitSASTORE

public void visitSASTORE(BytecodeInstruction instr)
shortArray[i] = x -> __korat_KoratArray_shortArray.set(i, x)

Specified by:
visitSASTORE in interface BytecodeVisitor
Overrides:
visitSASTORE in class VisitorSupport