use of org.jikesrvm.compilers.opt.inlining.CallSiteTree in project JikesRVM by JikesRVM.
the class EncodedOSRMap method translateMap.
/**
* Translates a list of OSR_MapElement to encoding.
* <p>
* we can not trust the osrlist is in the increasing order of
* machine code offset. Sort it first.
*
* @param tempOsrMaps an empty list that will hold temporary
* OSR map information
* @param osrlist information about instructions and variables
* @param mcOffsets machine code offsets for the
* instructions
*/
private void translateMap(ArrayList<Integer> tempOsrMaps, LinkedList<VariableMapElement> osrlist, final MachineCodeOffsets mcOffsets) {
/* sort the list, use the mc offset of the index instruction
* as the key.
*/
int n = osrlist.size();
VariableMapElement[] osrarray = new VariableMapElement[n];
for (int i = 0; i < n; i++) {
osrarray[i] = osrlist.get(i);
}
/* ideally, the osrList should be in sorted order by MC offset,
* but I got once it is not in the order. To work correctly,
* sort it first.
*
* TODO: figure out why LiveAnalysis does not give correct order?
*/
if (n > 1) {
Arrays.sort(osrarray, new Comparator<VariableMapElement>() {
@Override
public int compare(VariableMapElement a, VariableMapElement b) {
return mcOffsets.getMachineCodeOffset(a.osr) - mcOffsets.getMachineCodeOffset(b.osr);
}
});
}
CallSiteTree inliningTree = new CallSiteTree();
for (int i = 0; i < n; i++) {
Instruction instr = osrarray[i].osr;
// add lining element, move sanity later
if (instr.position() != null) {
inliningTree.addLocation(instr.position());
}
}
for (int i = 0; i < n; i++) {
VariableMapElement elm = osrarray[i];
Instruction instr = elm.osr;
int iei = inliningTree.find(instr.position()).encodedOffset;
setIEIndex(i, iei);
// get osr map
LinkedList<MethodVariables> mVarList = elm.mvars;
int osrMapIndex = generateOsrMaps(tempOsrMaps, mVarList);
// use this offset, and adjust on extractState
int mcOffset = mcOffsets.getMachineCodeOffset(instr);
setMCOffset(i, mcOffset);
setOSRMapIndex(i, osrMapIndex);
setBCIndex(i, instr.getBytecodeIndex());
}
}
use of org.jikesrvm.compilers.opt.inlining.CallSiteTree in project JikesRVM by JikesRVM.
the class OptMachineCodeMap method generateMCInformation.
// //////////////////////////////////////////
// Create the map (at compile time)
// //////////////////////////////////////////
/**
* This method walks the IR map, and for each entry it creates
* the machine code mapping information for the entry.
* It is called during the compilation of the method, not at GC time.
* @param irMap the irmap to translate from
* @param DUMP_MAPS dump while we work
* @param mcOffsets machine code offset information
* @return the machine code map
*/
private static OptMachineCodeMap generateMCInformation(GCIRMap irMap, boolean DUMP_MAPS, MachineCodeOffsets mcOffsets) {
CallSiteTree inliningMap = new CallSiteTree();
int numEntries = 0;
// construct and encode the inlining information for those entries.
for (GCIRMapElement irMapElem : irMap) {
numEntries++;
Instruction instr = irMapElem.getInstruction();
if (instr.position() == null && instr.getBytecodeIndex() != INSTRUMENTATION_BCI) {
if ((VM.BuildForIA32 && org.jikesrvm.compilers.opt.ir.ia32.MIR_Call.conforms(instr) && org.jikesrvm.compilers.opt.ir.ia32.MIR_Call.hasMethod(instr)) || (VM.BuildForPowerPC && org.jikesrvm.compilers.opt.ir.ppc.MIR_Call.conforms(instr) && org.jikesrvm.compilers.opt.ir.ppc.MIR_Call.hasMethod(instr))) {
throw new OptimizingCompilerException("position required for all call instructions " + instr);
}
} else {
inliningMap.addLocation(instr.position());
}
}
// if no entries, then we are done.
if (numEntries == 0)
return emptyMachineCodeMap;
int[] inlineEncoding = OptEncodedCallSiteTree.getEncoding(inliningMap);
// (2) Encode the primary machine code mapping information and the GCMaps.
OptGCMap gcMapBuilder = new OptGCMap();
int[] tmpMC = new int[numEntries * SIZEOF_HUGE_ENTRY];
int lastMCInfoEntry = 0;
for (GCIRMapElement irMapElem : irMap) {
Instruction instr = irMapElem.getInstruction();
if (DUMP_MAPS)
VM.sysWrite("IR Map for " + instr + "\n\t" + irMapElem);
// retrieve the machine code offset (in bytes) from the instruction,
ensureCorrectMapConstruction(mcOffsets, instr);
int mco = mcOffsets.getMachineCodeOffset(instr);
if (mco < 0) {
VM.sysWrite("Negative machine code MCOffset found:" + mco);
Instruction i = irMapElem.getInstruction();
int machineCodeOffsetForI = mcOffsets.getMachineCodeOffset(i);
VM.sysWriteln(i.getBytecodeIndex() + ", " + i + ", " + machineCodeOffsetForI);
throw new OptimizingCompilerException("Negative machine code MCOffset found");
}
// create GC map and get GCI
int gci = gcMapBuilder.generateGCMapEntry(irMapElem);
// get bci information
int bci = instr.getBytecodeIndex();
if (bci < 0) {
if ((bci == UNKNOWN_BCI) && ((VM.BuildForIA32 && org.jikesrvm.compilers.opt.ir.ia32.MIR_Call.conforms(instr) && org.jikesrvm.compilers.opt.ir.ia32.MIR_Call.hasMethod(instr)) || (VM.BuildForPowerPC && org.jikesrvm.compilers.opt.ir.ppc.MIR_Call.conforms(instr) && org.jikesrvm.compilers.opt.ir.ppc.MIR_Call.hasMethod(instr)))) {
throw new OptimizingCompilerException("valid bytecode index required for all calls " + instr);
}
bci = -1;
}
// get index into inline encoding
int iei = -1;
if (instr.position() != null) {
iei = inliningMap.find(instr.position()).encodedOffset;
}
// set the call info
int cm = 0;
if ((VM.BuildForIA32 && org.jikesrvm.compilers.opt.ir.ia32.MIR_Call.conforms(instr)) || (VM.BuildForPowerPC && org.jikesrvm.compilers.opt.ir.ppc.MIR_Call.conforms(instr))) {
MethodOperand mo;
if (VM.BuildForIA32) {
mo = org.jikesrvm.compilers.opt.ir.ia32.MIR_Call.getMethod(instr);
} else {
if (VM.VerifyAssertions)
VM._assert(VM.BuildForPowerPC);
mo = org.jikesrvm.compilers.opt.ir.ppc.MIR_Call.getMethod(instr);
}
if (mo != null && mo.isGuardedInlineOffBranch()) {
cm = IS_GUARDED_CALL;
} else {
cm = IS_UNGUARDED_CALL;
}
}
// Encode this entry into MCInformation
if (bci < INVALID_BCI && iei < INVALID_IEI && gci < INVALID_GCI && mco < (OFFSET_MASK >>> OFFSET_SHIFT)) {
// use a small entry
if (bci == -1)
bci = INVALID_BCI;
if (iei == -1)
iei = INVALID_IEI;
if (gci == -1)
gci = INVALID_GCI;
if (VM.VerifyAssertions) {
VM._assert((cm & (CALL_MASK >>> CALL_SHIFT)) == cm);
VM._assert((bci & (BCI_MASK >>> BCI_SHIFT)) == bci);
VM._assert((iei & (IEI_MASK >>> IEI_SHIFT)) == iei);
VM._assert((gci & (GCI_MASK >>> GCI_SHIFT)) == gci);
VM._assert((mco & (OFFSET_MASK >>> OFFSET_SHIFT)) == mco);
}
int t = START_OF_ENTRY;
t |= (cm << CALL_SHIFT);
t |= (bci << BCI_SHIFT);
t |= (iei << IEI_SHIFT);
t |= (gci << GCI_SHIFT);
t |= (mco << OFFSET_SHIFT);
tmpMC[lastMCInfoEntry++] = t;
} else if (bci < BIG_INVALID_BCI && iei < BIG_INVALID_IEI && gci < BIG_INVALID_GCI && mco < (BIG_OFFSET_MASK >>> BIG_OFFSET_SHIFT)) {
// use a big entry
if (bci == -1)
bci = BIG_INVALID_BCI;
if (iei == -1)
iei = BIG_INVALID_IEI;
if (gci == -1)
gci = BIG_INVALID_GCI;
if (VM.VerifyAssertions) {
VM._assert((cm & (BIG_CALL_MASK >>> BIG_CALL_SHIFT)) == cm);
VM._assert((bci & (BIG_BCI_MASK >>> BIG_BCI_SHIFT)) == bci);
VM._assert((iei & (BIG_IEI_MASK >>> BIG_IEI_SHIFT)) == iei);
VM._assert((gci & (BIG_GCI_MASK >>> BIG_GCI_SHIFT)) == gci);
VM._assert((mco & (BIG_OFFSET_MASK >>> BIG_OFFSET_SHIFT)) == mco);
}
int startIdx = lastMCInfoEntry;
tmpMC[startIdx] = START_OF_BIG_ENTRY;
tmpMC[startIdx + BIG_CALL_IDX_ADJ] |= (cm << BIG_CALL_SHIFT);
tmpMC[startIdx + BIG_BCI_IDX_ADJ] |= (bci << BIG_BCI_SHIFT);
tmpMC[startIdx + BIG_OFFSET_IDX_ADJ] |= (mco << BIG_OFFSET_SHIFT);
tmpMC[startIdx + BIG_GCI_IDX_ADJ] |= (gci << BIG_GCI_SHIFT);
tmpMC[startIdx + BIG_IEI_IDX_ADJ] |= (iei << BIG_IEI_SHIFT);
lastMCInfoEntry += SIZEOF_BIG_ENTRY;
} else {
// use a huge entry
if (bci == -1)
bci = HUGE_INVALID_BCI;
if (iei == -1)
iei = HUGE_INVALID_IEI;
if (gci == -1)
gci = HUGE_INVALID_GCI;
if (VM.VerifyAssertions) {
VM._assert((cm & (HUGE_CALL_MASK >>> HUGE_CALL_SHIFT)) == cm);
VM._assert((bci & (HUGE_BCI_MASK >>> HUGE_BCI_SHIFT)) == bci);
VM._assert((iei & (HUGE_IEI_MASK >>> HUGE_IEI_SHIFT)) == iei);
VM._assert((gci & (HUGE_GCI_MASK >>> HUGE_GCI_SHIFT)) == gci);
VM._assert((mco & (HUGE_OFFSET_MASK >>> HUGE_OFFSET_SHIFT)) == mco);
}
int startIdx = lastMCInfoEntry;
tmpMC[startIdx] = START_OF_HUGE_ENTRY;
tmpMC[startIdx + HUGE_CALL_IDX_ADJ] |= (cm << HUGE_CALL_SHIFT);
tmpMC[startIdx + HUGE_BCI_IDX_ADJ] |= (bci << HUGE_BCI_SHIFT);
tmpMC[startIdx + HUGE_OFFSET_IDX_ADJ] |= (mco << HUGE_OFFSET_SHIFT);
tmpMC[startIdx + HUGE_GCI_IDX_ADJ] |= (gci << HUGE_GCI_SHIFT);
tmpMC[startIdx + HUGE_IEI_IDX_ADJ] |= (iei << HUGE_IEI_SHIFT);
lastMCInfoEntry += SIZEOF_HUGE_ENTRY;
}
}
int[] mcInformation = new int[lastMCInfoEntry];
System.arraycopy(tmpMC, 0, mcInformation, 0, mcInformation.length);
int[] gcMaps = gcMapBuilder.finish();
return new OptMachineCodeMap(mcInformation, gcMaps, inlineEncoding);
}
Aggregations