# HG changeset patch # User Lukas Stadler # Date 1397495507 -7200 # Node ID c73ce0dd35832a759ed8fc7880d3018556a29092 # Parent 607e33885130073578fe842d7110d55ff5a27bee add support for skipping stack frames in StackIntrospection.getStackTrace diff -r 607e33885130 -r c73ce0dd3583 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/stack/StackIntrospection.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/stack/StackIntrospection.java Mon Apr 14 18:46:56 2014 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/stack/StackIntrospection.java Mon Apr 14 19:11:47 2014 +0200 @@ -35,5 +35,5 @@ * @param matchingMethods if this is non-{@code null}, then only matching stack frames are * returned */ - Iterable getStackTrace(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods); + Iterable getStackTrace(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip); } diff -r 607e33885130 -r c73ce0dd3583 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Apr 14 18:46:56 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Apr 14 19:11:47 2014 +0200 @@ -445,12 +445,12 @@ } } - public Iterable getStackTrace(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods) { + public Iterable getStackTrace(ResolvedJavaMethod[] initialMethods, ResolvedJavaMethod[] matchingMethods, int initialSkip) { final long[] initialMetaMethods = toMeta(initialMethods); final long[] matchingMetaMethods = toMeta(matchingMethods); class StackFrameIterator implements Iterator { - private HotSpotStackFrameReference current = compilerToVm.getNextStackFrame(null, initialMetaMethods); + private HotSpotStackFrameReference current = compilerToVm.getNextStackFrame(null, initialMetaMethods, initialSkip); // we don't want to read ahead if hasNext isn't called private boolean advanced = true; @@ -467,7 +467,7 @@ private void update() { if (!advanced) { - current = compilerToVm.getNextStackFrame(current, matchingMetaMethods); + current = compilerToVm.getNextStackFrame(current, matchingMetaMethods, 0); advanced = true; } } diff -r 607e33885130 -r c73ce0dd3583 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon Apr 14 18:46:56 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon Apr 14 19:11:47 2014 +0200 @@ -343,7 +343,7 @@ * returned * @return the frame, or {@code null} if the end of the stack was reached during the search */ - HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods); + HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip); /** * Materialized all virtual objects within the given stack frame and update the locals within diff -r 607e33885130 -r c73ce0dd3583 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Mon Apr 14 18:46:56 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Mon Apr 14 19:11:47 2014 +0200 @@ -179,7 +179,7 @@ public native boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level); - public native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods); + public native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip); public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); diff -r 607e33885130 -r c73ce0dd3583 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Mon Apr 14 18:46:56 2014 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Mon Apr 14 19:11:47 2014 +0200 @@ -229,10 +229,7 @@ if (stackIntrospection == null) { stackIntrospection = Graal.getRequiredCapability(StackIntrospection.class); } - final Iterator frames = stackIntrospection.getStackTrace(anyFrameMethod, anyFrameMethod).iterator(); - assert frames.hasNext(); - InspectedFrame calltarget = frames.next(); - assert calltarget.getMethod().equals(callTargetMethod[0]); + final Iterator frames = stackIntrospection.getStackTrace(anyFrameMethod, anyFrameMethod, 1).iterator(); class FrameIterator implements Iterator { public boolean hasNext() { @@ -263,7 +260,7 @@ if (stackIntrospection == null) { stackIntrospection = Graal.getRequiredCapability(StackIntrospection.class); } - Iterator frames = stackIntrospection.getStackTrace(callTargetMethod, callTargetMethod).iterator(); + Iterator frames = stackIntrospection.getStackTrace(callTargetMethod, callTargetMethod, 0).iterator(); if (frames.hasNext()) { return new HotSpotFrameInstance.CallTargetFrame(frames.next(), true); } else { diff -r 607e33885130 -r c73ce0dd3583 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Mon Apr 14 18:46:56 2014 +0200 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Mon Apr 14 19:11:47 2014 +0200 @@ -797,8 +797,7 @@ return false; } -// public native HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, ResolvedJavaMethod method); -C2V_VMENTRY(jobject, getNextStackFrame, (JNIEnv *env, jobject compilerToVM, jobject hs_frame, jlongArray methods)) +C2V_VMENTRY(jobject, getNextStackFrame, (JNIEnv *env, jobject compilerToVM, jobject hs_frame, jlongArray methods, jint initialSkip)) ResourceMark rm; if (!thread->has_last_Java_frame()) return NULL; @@ -851,39 +850,47 @@ // compiled method frame compiledVFrame* cvf = compiledVFrame::cast(vf); if (methods == NULL || matches(methods, cvf->method())) { - GrowableArray* objects = cvf->scope()->objects(); - bool reallocated = false; - if (objects != NULL) { - reallocated = Deoptimization::realloc_objects(thread, fst.current(), objects, THREAD); - if (reallocated) { - Deoptimization::reassign_fields(fst.current(), fst.register_map(), objects); + if (initialSkip > 0) { + initialSkip --; + } else { + GrowableArray* objects = cvf->scope()->objects(); + bool reallocated = false; + if (objects != NULL) { + reallocated = Deoptimization::realloc_objects(thread, fst.current(), objects, THREAD); + if (reallocated) { + Deoptimization::reassign_fields(fst.current(), fst.register_map(), objects); + } + + GrowableArray* local_values = cvf->scope()->locals(); + typeArrayHandle array = oopFactory::new_boolArray(local_values->length(), thread); + for (int i = 0; i < local_values->length(); i++) { + ScopeValue* value = local_values->at(i); + if (value->is_object()) { + array->bool_at_put(i, true); + } + } + HotSpotStackFrameReference::set_localIsVirtual(result, array()); + } else { + HotSpotStackFrameReference::set_localIsVirtual(result, NULL); } - GrowableArray* local_values = cvf->scope()->locals(); - typeArrayHandle array = oopFactory::new_boolArray(local_values->length(), thread); - for (int i = 0; i < local_values->length(); i++) { - ScopeValue* value = local_values->at(i); - if (value->is_object()) { - array->bool_at_put(i, true); - } - } - HotSpotStackFrameReference::set_localIsVirtual(result, array()); - } else { - HotSpotStackFrameReference::set_localIsVirtual(result, NULL); + locals = cvf->locals(); + HotSpotStackFrameReference::set_bci(result, cvf->bci()); + HotSpotStackFrameReference::set_metaspaceMethod(result, (jlong) cvf->method()); } - - locals = cvf->locals(); - HotSpotStackFrameReference::set_bci(result, cvf->bci()); - HotSpotStackFrameReference::set_metaspaceMethod(result, (jlong) cvf->method()); } } else if (vf->is_interpreted_frame()) { // interpreted method frame interpretedVFrame* ivf = interpretedVFrame::cast(vf); if (methods == NULL || matches(methods, ivf->method())) { - locals = ivf->locals(); - HotSpotStackFrameReference::set_bci(result, ivf->bci()); - HotSpotStackFrameReference::set_metaspaceMethod(result, (jlong) ivf->method()); - HotSpotStackFrameReference::set_localIsVirtual(result, NULL); + if (initialSkip > 0) { + initialSkip --; + } else { + locals = ivf->locals(); + HotSpotStackFrameReference::set_bci(result, ivf->bci()); + HotSpotStackFrameReference::set_metaspaceMethod(result, (jlong) ivf->method()); + HotSpotStackFrameReference::set_localIsVirtual(result, NULL); + } } } @@ -1096,7 +1103,7 @@ {CC"isMature", CC"("METASPACE_METHOD_DATA")Z", FN_PTR(isMature)}, {CC"hasCompiledCodeForOSR", CC"("METASPACE_METHOD"II)Z", FN_PTR(hasCompiledCodeForOSR)}, {CC"getTimeStamp", CC"()J", FN_PTR(getTimeStamp)}, - {CC"getNextStackFrame", CC"("HS_STACK_FRAME_REF "[J)"HS_STACK_FRAME_REF, FN_PTR(getNextStackFrame)}, + {CC"getNextStackFrame", CC"("HS_STACK_FRAME_REF "[JI)"HS_STACK_FRAME_REF, FN_PTR(getNextStackFrame)}, {CC"materializeVirtualObjects", CC"("HS_STACK_FRAME_REF"Z)V", FN_PTR(materializeVirtualObjects)}, };