Search in sources :

Example 1 with JvmtiError

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();
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) JvmtiError(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError)

Example 2 with JvmtiError

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;
    }
}
Also used : JvmtiError(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError) CCharPointerPointer(org.graalvm.nativeimage.c.type.CCharPointerPointer)

Example 3 with JvmtiError

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;
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) JvmtiLineNumberEntry(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiLineNumberEntry) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) JvmtiError(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError) CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) Pointer(org.graalvm.word.Pointer) CCharPointerPointer(org.graalvm.nativeimage.c.type.CCharPointerPointer) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Example 4 with JvmtiError

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;
}
Also used : JvmtiError(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError) JNIObjectHandle(com.oracle.svm.jni.nativeapi.JNIObjectHandle) JNIMethodId(com.oracle.svm.jni.nativeapi.JNIMethodId)

Example 5 with JvmtiError

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;
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) JvmtiError(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError) JvmtiFrameInfo(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiFrameInfo) CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) Pointer(org.graalvm.word.Pointer) JvmtiEnv(com.oracle.svm.jvmtiagentbase.jvmti.JvmtiEnv) JNIMethodId(com.oracle.svm.jni.nativeapi.JNIMethodId)

Aggregations

JvmtiError (com.oracle.svm.jvmtiagentbase.jvmti.JvmtiError)7 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)4 JNIMethodId (com.oracle.svm.jni.nativeapi.JNIMethodId)2 JNIObjectHandle (com.oracle.svm.jni.nativeapi.JNIObjectHandle)2 JvmtiFrameInfo (com.oracle.svm.jvmtiagentbase.jvmti.JvmtiFrameInfo)2 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)2 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)2 WordPointer (org.graalvm.nativeimage.c.type.WordPointer)2 Pointer (org.graalvm.word.Pointer)2 JvmtiEnv (com.oracle.svm.jvmtiagentbase.jvmti.JvmtiEnv)1 JvmtiLineNumberEntry (com.oracle.svm.jvmtiagentbase.jvmti.JvmtiLineNumberEntry)1