use of com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError in project graal by oracle.
the class EagerlyLoadedJavaStackAccess method getCurrentThreadStackFrameCount.
private static int getCurrentThreadStackFrameCount(JvmtiEnv jvmti) {
CIntPointer countPointer = StackValue.get(CIntPointer.class);
JvmtiError error = jvmti.getFunctions().GetFrameCount().invoke(jvmti, nullHandle(), countPointer);
if (error.equals(JvmtiError.JVMTI_ERROR_WRONG_PHASE)) {
return -1;
}
check(error);
return countPointer.read();
}
use of com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError in project graal by oracle.
the class JavaStackTraceCreator method getSourceFileName.
private String getSourceFileName(JNIObjectHandle clazz) {
CCharPointerPointer sourceFileNamePointer = StackValue.get(CCharPointerPointer.class);
JvmtiError errorCode = jvmti.getFunctions().GetSourceFileName().invoke(jvmti, clazz, sourceFileNamePointer);
if (errorCode == JvmtiError.JVMTI_ERROR_NONE) {
String sourceFileName = Support.fromCString(sourceFileNamePointer.read());
jvmti.getFunctions().Deallocate().invoke(jvmti, sourceFileNamePointer.read());
return sourceFileName;
} else {
return null;
}
}
use of com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError in project graal by oracle.
the class JavaStackTraceCreator method getFrameSourceLineNumber.
private static int getFrameSourceLineNumber(JvmtiEnv jvmti, JvmtiFrameInfo frameInfo) {
CIntPointer entryCountPointer = StackValue.get(CIntPointer.class);
WordPointer lineEntryTablePointer = StackValue.get(WordPointer.class);
JvmtiError errorCode = jvmti.getFunctions().GetLineNumberTable().invoke(jvmti, frameInfo.getMethod(), entryCountPointer, lineEntryTablePointer);
if (errorCode == JvmtiError.JVMTI_ERROR_MUST_POSSESS_CAPABILITY || errorCode == JvmtiError.JVMTI_ERROR_ABSENT_INFORMATION) {
return LINE_NUMBER_UNAVAILABLE;
}
check(errorCode);
int entryCount = entryCountPointer.read();
Pointer lineEntryTable = lineEntryTablePointer.read();
VMError.guarantee(lineEntryTable.isNonNull());
int previousLineNumber = LINE_NUMBER_UNAVAILABLE;
for (int i = 0; i < entryCount; ++i) {
JvmtiLineNumberEntry entry = (JvmtiLineNumberEntry) lineEntryTable.add(i * SizeOf.get(JvmtiLineNumberEntry.class));
if (entry.getStartLocation() > frameInfo.getLocation()) {
break;
}
previousLineNumber = entry.getLineNumber();
}
jvmti.getFunctions().Deallocate().invoke(jvmti, lineEntryTable);
return previousLineNumber;
}
use of com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError in project graal by oracle.
the class BreakpointInterceptor method installBreakpoint.
private static Breakpoint installBreakpoint(JNIEnvironment jni, BreakpointSpecification br, Map<Long, Breakpoint> map, JNIObjectHandle knownClass) {
JNIObjectHandle clazz = knownClass;
if (clazz.equal(nullHandle())) {
clazz = resolveBreakpointClass(jni, br.className, br.optional);
if (clazz.equal(nullHandle())) {
guarantee(br.optional);
return null;
}
}
JNIMethodId method = resolveBreakpointMethod(jni, clazz, br.methodName, br.signature, br.optional);
JvmtiError result = jvmtiFunctions().SetBreakpoint().invoke(jvmtiEnv(), method, 0L);
if (result != JvmtiError.JVMTI_ERROR_NONE) {
guarantee(br.optional, "Setting breakpoint failed");
return null;
}
Breakpoint bp = new Breakpoint(br, clazz, method);
guarantee(map.put(method.rawValue(), bp) == null, "Duplicate breakpoint: " + bp);
return bp;
}
use of com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError in project graal by oracle.
the class EagerlyLoadedJavaStackAccess method getCurrentThreadStackTrace.
/**
* Returns the stack trace of the current thread.
*
* The returned array contains the current thread's stack, with the first element representing
* the top of the stack. Elements in the array correspond to the raw value of JNIMethodId of the
* particular method on the stack.
*/
private static JNIMethodId[] getCurrentThreadStackTrace() {
JvmtiEnv jvmti = Support.jvmtiEnv();
int threadStackFrameCount = getCurrentThreadStackFrameCount(jvmti);
if (threadStackFrameCount < 0) {
return new JNIMethodId[0];
}
/*
* If we are unlucky, we may have a phase change while the stack trace entries are being
* initialized.
*/
boolean wrongPhase = false;
int iterationCount = threadStackFrameCount / STACK_FRAMES_PER_ITERATION;
if (threadStackFrameCount % STACK_FRAMES_PER_ITERATION > 0) {
iterationCount = iterationCount + 1;
}
JNIMethodId[] stackTraceJMethodIDs = new JNIMethodId[threadStackFrameCount];
int frameInfoSize = SizeOf.get(JvmtiFrameInfo.class);
Pointer stackFramesBuffer = UnmanagedMemory.malloc(frameInfoSize * STACK_FRAMES_PER_ITERATION);
CIntPointer readFrameCount = StackValue.get(CIntPointer.class);
/* Build the stack trace incrementally in chunks of STACK_FRAMES_PER_ITERATION frames. */
for (int i = 0; i < iterationCount; ++i) {
JvmtiError error = jvmti.getFunctions().GetStackTrace().invoke(jvmti, nullHandle(), i * STACK_FRAMES_PER_ITERATION, STACK_FRAMES_PER_ITERATION, (WordPointer) stackFramesBuffer, readFrameCount);
if (error.equals(JvmtiError.JVMTI_ERROR_WRONG_PHASE)) {
wrongPhase = true;
break;
}
check(error);
for (int j = 0; j < readFrameCount.read(); ++j) {
JvmtiFrameInfo frameInfo = (JvmtiFrameInfo) stackFramesBuffer.add(j * frameInfoSize);
stackTraceJMethodIDs[i * STACK_FRAMES_PER_ITERATION + j] = frameInfo.getMethod();
}
}
UnmanagedMemory.free(stackFramesBuffer);
return wrongPhase ? null : stackTraceJMethodIDs;
}
Aggregations