use of org.jikesrvm.compilers.opt.runtimesupport.OptMachineCodeMap in project JikesRVM by JikesRVM.
the class DynamicCallGraphOrganizer method thresholdReached.
/**
* Process contents of buffer:
* add call graph edges and increment their weights.
*/
@Override
void thresholdReached() {
if (DEBUG)
VM.sysWriteln("DCG_Organizer.thresholdReached()");
for (int i = 0; i < bufferSize; i = i + 3) {
int calleeCMID = 0;
// FIXME: This is necessary but hacky and may not even be correct.
while (calleeCMID == 0) {
calleeCMID = buffer[i + 0];
}
CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(calleeCMID);
if (compiledMethod == null)
continue;
RVMMethod callee = compiledMethod.getMethod();
if (callee.isRuntimeServiceMethod()) {
if (DEBUG)
VM.sysWrite("Skipping sample with runtime service callee");
continue;
}
int callerCMID = buffer[i + 1];
compiledMethod = CompiledMethods.getCompiledMethod(callerCMID);
if (compiledMethod == null)
continue;
RVMMethod stackFrameCaller = compiledMethod.getMethod();
int MCOff = buffer[i + 2];
Offset MCOffset = Offset.fromIntSignExtend(buffer[i + 2]);
int bytecodeIndex = -1;
RVMMethod caller = null;
switch(compiledMethod.getCompilerType()) {
case CompiledMethod.TRAP:
case CompiledMethod.JNI:
if (DEBUG)
VM.sysWrite("Skipping sample with TRAP/JNI caller");
continue;
case CompiledMethod.BASELINE:
{
BaselineCompiledMethod baseCompiledMethod = (BaselineCompiledMethod) compiledMethod;
// note: the following call expects the offset in INSTRUCTIONS!
bytecodeIndex = baseCompiledMethod.findBytecodeIndexForInstruction(MCOffset);
caller = stackFrameCaller;
}
break;
case CompiledMethod.OPT:
{
OptCompiledMethod optCompiledMethod = (OptCompiledMethod) compiledMethod;
OptMachineCodeMap mc_map = optCompiledMethod.getMCMap();
try {
bytecodeIndex = mc_map.getBytecodeIndexForMCOffset(MCOffset);
if (bytecodeIndex == -1) {
// so skip the sample.
if (DEBUG) {
VM.sysWrite(" *** SKIP SAMPLE ", stackFrameCaller.toString());
VM.sysWrite("@", compiledMethod.toString());
VM.sysWrite(" at MC offset ", MCOff);
VM.sysWrite(" calling ", callee.toString());
VM.sysWriteln(" due to invalid bytecodeIndex");
}
// skip sample.
continue;
}
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
VM.sysWrite(" ***ERROR: getBytecodeIndexForMCOffset(", MCOffset);
VM.sysWriteln(") ArrayIndexOutOfBounds!");
e.printStackTrace();
if (VM.ErrorsFatal)
VM.sysFail("Exception in AI organizer.");
caller = stackFrameCaller;
// skip sample
continue;
} catch (OptimizingCompilerException e) {
VM.sysWrite("***Error: SKIP SAMPLE: can't find bytecode index in OPT compiled " + stackFrameCaller + "@" + compiledMethod + " at MC offset ", MCOff);
VM.sysWriteln("!");
if (VM.ErrorsFatal)
VM.sysFail("Exception in AI organizer.");
// skip sample
continue;
}
try {
caller = mc_map.getMethodForMCOffset(MCOffset);
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
VM.sysWrite(" ***ERROR: getMethodForMCOffset(", MCOffset);
VM.sysWriteln(") ArrayIndexOutOfBounds!");
e.printStackTrace();
if (VM.ErrorsFatal)
VM.sysFail("Exception in AI organizer.");
caller = stackFrameCaller;
continue;
} catch (OptimizingCompilerException e) {
VM.sysWrite("***Error: SKIP SAMPLE: can't find caller in OPT compiled " + stackFrameCaller + "@" + compiledMethod + " at MC offset ", MCOff);
VM.sysWriteln("!");
if (VM.ErrorsFatal)
VM.sysFail("Exception in AI organizer.");
// skip sample
continue;
}
if (caller == null) {
VM.sysWrite(" ***ERROR: getMethodForMCOffset(", MCOffset);
VM.sysWriteln(") returned null!");
caller = stackFrameCaller;
// skip sample
continue;
}
}
break;
}
// increment the call graph edge, adding it if needed
Controller.dcg.incrementEdge(caller, bytecodeIndex, callee);
}
if (thresholdReachedCount > 0) {
thresholdReachedCount--;
}
}
use of org.jikesrvm.compilers.opt.runtimesupport.OptMachineCodeMap in project JikesRVM by JikesRVM.
the class StackTrace method countFrames.
/**
* Count number of stack frames including those inlined by the opt compiler
* @param first the first compiled method to look from
* @param last the last compiled method to look to
* @return the number of stack frames
*/
private int countFrames(int first, int last) {
int numElements = 0;
if (!VM.BuildForOptCompiler) {
numElements = last - first + 1;
} else {
for (int i = first; i <= last; i++) {
CompiledMethod compiledMethod = getCompiledMethod(i);
if ((compiledMethod == null) || (compiledMethod.getCompilerType() != CompiledMethod.OPT)) {
// Invisible or non-opt compiled method
numElements++;
} else {
Offset instructionOffset = Offset.fromIntSignExtend(instructionOffsets[i]);
OptCompiledMethod optInfo = (OptCompiledMethod) compiledMethod;
OptMachineCodeMap map = optInfo.getMCMap();
int iei = map.getInlineEncodingForMCOffset(instructionOffset);
if (iei < 0) {
numElements++;
} else {
int[] inlineEncoding = map.inlineEncoding;
for (; iei >= 0; iei = OptEncodedCallSiteTree.getParent(iei, inlineEncoding)) {
numElements++;
}
}
}
}
}
return numElements;
}
use of org.jikesrvm.compilers.opt.runtimesupport.OptMachineCodeMap in project JikesRVM by JikesRVM.
the class TraceInterface method skipOwnFramesAndDump.
@Override
@NoInline
// This can't be uninterruptible --- it is an IO routine
@Interruptible
public Address skipOwnFramesAndDump(ObjectReference typeRef) {
TIB tib = Magic.addressAsTIB(typeRef.toAddress());
RVMMethod m = null;
int bci = -1;
int compiledMethodID = 0;
Offset ipOffset = Offset.zero();
Address fp = Magic.getFramePointer();
Address ip = Magic.getReturnAddressUnchecked(fp);
fp = Magic.getCallerFramePointer(fp);
// This code borrows heavily from RVMThread.dumpStack
final Address STACKFRAME_SENTINEL_FP = StackFrameLayout.getStackFrameSentinelFP();
final int INVISIBLE_METHOD_ID = StackFrameLayout.getInvisibleMethodID();
while (Magic.getCallerFramePointer(fp).NE(STACKFRAME_SENTINEL_FP)) {
compiledMethodID = Magic.getCompiledMethodID(fp);
if (compiledMethodID != INVISIBLE_METHOD_ID) {
// normal java frame(s)
CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(compiledMethodID);
if (compiledMethod.getCompilerType() != CompiledMethod.TRAP) {
ipOffset = compiledMethod.getInstructionOffset(ip);
m = compiledMethod.getMethod();
if (VM.BuildForOptCompiler && compiledMethod.getCompilerType() == CompiledMethod.OPT) {
OptCompiledMethod optInfo = (OptCompiledMethod) compiledMethod;
/* Opt stack frames may contain multiple inlined methods. */
OptMachineCodeMap map = optInfo.getMCMap();
int iei = map.getInlineEncodingForMCOffset(ipOffset);
if (iei >= 0) {
int[] inlineEncoding = map.inlineEncoding;
boolean allocCall = true;
bci = map.getBytecodeIndexForMCOffset(ipOffset);
for (int j = iei; j >= 0 && allocCall; j = OptEncodedCallSiteTree.getParent(j, inlineEncoding)) {
int mid = OptEncodedCallSiteTree.getMethodID(j, inlineEncoding);
m = MemberReference.getMethodRef(mid).getResolvedMember();
if (!isAllocCall(m.getName().getBytes()))
allocCall = false;
if (j > 0)
bci = OptEncodedCallSiteTree.getByteCodeOffset(j, inlineEncoding);
}
if (!allocCall)
break;
}
} else {
if (!isAllocCall(m.getName().getBytes())) {
BaselineCompiledMethod baseInfo = (BaselineCompiledMethod) compiledMethod;
final int INSTRUCTION_WIDTH = ArchConstants.getInstructionWidth();
bci = baseInfo.findBytecodeIndexForInstruction(ipOffset.toWord().lsh(INSTRUCTION_WIDTH).toOffset());
break;
}
}
}
}
ip = Magic.getReturnAddressUnchecked(fp);
fp = Magic.getCallerFramePointer(fp);
}
if (m != null) {
int allocid = (((compiledMethodID & 0x0000ffff) << 15) ^ ((compiledMethodID & 0xffff0000) >> 16) ^ ipOffset.toInt()) & ~0x80000000;
/* Now print the location string. */
VM.sysWrite('\n');
VM.writeHex(allocid);
VM.sysWrite('-');
VM.sysWrite('>');
VM.sysWrite('[');
VM.writeHex(compiledMethodID);
VM.sysWrite(']');
m.getDeclaringClass().getDescriptor().sysWrite();
VM.sysWrite(':');
m.getName().sysWrite();
m.getDescriptor().sysWrite();
VM.sysWrite(':');
VM.writeHex(bci);
VM.sysWrite('\t');
RVMType type = tib.getType();
type.getDescriptor().sysWrite();
VM.sysWrite('\n');
}
return fp;
}
use of org.jikesrvm.compilers.opt.runtimesupport.OptMachineCodeMap in project JikesRVM by JikesRVM.
the class StackTrace method buildStackTrace.
private Element[] buildStackTrace(int first, int last) {
Element[] elements = new Element[countFrames(first, last)];
if (!VM.BuildForOptCompiler) {
int element = 0;
for (int i = first; i <= last; i++) {
elements[element] = createStandardStackTraceElement(getCompiledMethod(i), instructionOffsets[i]);
element++;
}
} else {
int element = 0;
for (int i = first; i <= last; i++) {
CompiledMethod compiledMethod = getCompiledMethod(i);
if ((compiledMethod == null) || (compiledMethod.getCompilerType() != CompiledMethod.OPT)) {
// Invisible or non-opt compiled method
elements[element] = createStandardStackTraceElement(compiledMethod, instructionOffsets[i]);
element++;
} else {
Offset instructionOffset = Offset.fromIntSignExtend(instructionOffsets[i]);
OptCompiledMethod optInfo = (OptCompiledMethod) compiledMethod;
OptMachineCodeMap map = optInfo.getMCMap();
int iei = map.getInlineEncodingForMCOffset(instructionOffset);
if (iei < 0) {
elements[element] = createStandardStackTraceElement(compiledMethod, instructionOffsets[i]);
element++;
} else {
int[] inlineEncoding = map.inlineEncoding;
int bci = map.getBytecodeIndexForMCOffset(instructionOffset);
for (; iei >= 0; iei = OptEncodedCallSiteTree.getParent(iei, inlineEncoding)) {
int mid = OptEncodedCallSiteTree.getMethodID(iei, inlineEncoding);
RVMMethod method = MemberReference.getMethodRef(mid).getResolvedMember();
int lineNumber = ((NormalMethod) method).getLineNumberForBCIndex(bci);
elements[element] = createOptStackTraceElement(method, lineNumber, instructionOffset, bci);
element++;
if (iei > 0) {
bci = OptEncodedCallSiteTree.getByteCodeOffset(iei, inlineEncoding);
}
}
}
}
}
}
return elements;
}
Aggregations