java-interp.h: Added _Jv_Frame class and its two subclasses _Jv_InterpFrame and _Jv_NativeFrame.
2007-01-29 Kyle Galloway <kgallowa@redhat.com> * include/java-interp.h: Added _Jv_Frame class and its two subclasses _Jv_InterpFrame and _Jv_NativeFrame. Also moved _Jv_FrameType from java-stack.h. * include/java-stack.h: Removed _Jv_FrameType. * java/lang/Thread.java: Added frame member to hold new composite frame stack. * java/lang/Thread.h: Regenerated. * java/lang/Thread.class: Rebuilt. * jni.cc (_Jv_JNIMethod::call): Push a frame onto the stack when calling a JNI method. * jvmti.cc (_Jv_JVMTI_GetStackTrace): New Method. (_Jv_JVMTI_GetFrameCount): New method. * stacktrace.cc (UnwindTraceFn): Modified to use new _Jv_Frame classes. * testsuite/libjava.jvmti/interp/getstacktrace.jar: New test. * testsuite/libjava.jvmti/interp/natgetstacktrace.cc: New test. * testsuite/libjava.jvmti/interp/getstacktrace.h: New test. * testsuite/libjava.jvmti/interp/getstacktrace.jar: New test. * testsuite/libjava.jvmti/interp/getstacktrace.out: Output file for test. From-SVN: r121314
This commit is contained in:
parent
d75bf84344
commit
3927313117
15 changed files with 537 additions and 27 deletions
libjava/testsuite/libjava.jvmti/interp
21
libjava/testsuite/libjava.jvmti/interp/getstacktrace.h
Normal file
21
libjava/testsuite/libjava.jvmti/interp/getstacktrace.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
|
||||
#ifndef __getstacktrace__
|
||||
#define __getstacktrace__
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
JNIEXPORT void JNICALL Java_getstacktrace_natPlaceholder (JNIEnv *env, jobject);
|
||||
JNIEXPORT void JNICALL Java_getstacktrace_natRunner (JNIEnv *env, jobject);
|
||||
JNIEXPORT jint JNICALL Java_getstacktrace_do_1getstacktrace_1tests (JNIEnv *env, jclass, jobjectArray);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __getstacktrace__ */
|
BIN
libjava/testsuite/libjava.jvmti/interp/getstacktrace.jar
Normal file
BIN
libjava/testsuite/libjava.jvmti/interp/getstacktrace.jar
Normal file
Binary file not shown.
88
libjava/testsuite/libjava.jvmti/interp/getstacktrace.java
Normal file
88
libjava/testsuite/libjava.jvmti/interp/getstacktrace.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
public class getstacktrace
|
||||
extends Thread
|
||||
{
|
||||
public boolean done = false;
|
||||
|
||||
// num_frames is the number of frames > the original run () call so if
|
||||
// num_frames = 1, the thread will have 2 frames, the original Thread.run
|
||||
// call, plus one additional
|
||||
public int num_frames, thread_num;
|
||||
|
||||
public static int num_threads = 1;
|
||||
|
||||
static
|
||||
{
|
||||
System.loadLibrary("natgetstacktrace");
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
thread_num = num_threads++;
|
||||
num_frames = thread_num;
|
||||
|
||||
if (num_frames <= 1)
|
||||
{
|
||||
natRunner ();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (thread_num % 2 == 0)
|
||||
natPlaceholder ();
|
||||
else
|
||||
placeholder ();
|
||||
}
|
||||
}
|
||||
|
||||
public void placeholder ()
|
||||
{
|
||||
num_frames--;
|
||||
if (num_frames <= 1)
|
||||
{
|
||||
if (thread_num % 2 == 1)
|
||||
natRunner ();
|
||||
else
|
||||
runner ();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (thread_num % 2 == 0)
|
||||
natPlaceholder ();
|
||||
else
|
||||
placeholder ();
|
||||
}
|
||||
}
|
||||
|
||||
public void runner ()
|
||||
{
|
||||
done = true;
|
||||
while (done)
|
||||
yield ();
|
||||
}
|
||||
|
||||
public native void natPlaceholder ();
|
||||
public native void natRunner ();
|
||||
|
||||
public static native int do_getstacktrace_tests (Thread[] threads);
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
System.out.println ("JVMTI GetStackTrace Interpreted Test");
|
||||
|
||||
getstacktrace[] threads = new getstacktrace[10];
|
||||
|
||||
for (int i = 0; i < threads.length; i++)
|
||||
{
|
||||
threads[i] = new getstacktrace ();
|
||||
threads[i].start ();
|
||||
while (!threads[i].done)
|
||||
yield ();
|
||||
}
|
||||
|
||||
do_getstacktrace_tests (threads);
|
||||
|
||||
for (int i = 0; i < threads.length; i++)
|
||||
{
|
||||
threads[i].done = false;
|
||||
}
|
||||
}
|
||||
}
|
76
libjava/testsuite/libjava.jvmti/interp/getstacktrace.out
Normal file
76
libjava/testsuite/libjava.jvmti/interp/getstacktrace.out
Normal file
|
@ -0,0 +1,76 @@
|
|||
JVMTI GetStackTrace Interpreted Test
|
||||
Thread has 2 frames
|
||||
Frame 0 is native
|
||||
Frame 1 is interpreted
|
||||
Thread has 3 frames
|
||||
Frame 0 is interpreted
|
||||
Frame 1 is native
|
||||
Frame 2 is interpreted
|
||||
Thread has 4 frames
|
||||
Frame 0 is native
|
||||
Frame 1 is interpreted
|
||||
Frame 2 is interpreted
|
||||
Frame 3 is interpreted
|
||||
Thread has 5 frames
|
||||
Frame 0 is interpreted
|
||||
Frame 1 is native
|
||||
Frame 2 is native
|
||||
Frame 3 is native
|
||||
Frame 4 is interpreted
|
||||
Thread has 6 frames
|
||||
Frame 0 is native
|
||||
Frame 1 is interpreted
|
||||
Frame 2 is interpreted
|
||||
Frame 3 is interpreted
|
||||
Frame 4 is interpreted
|
||||
Frame 5 is interpreted
|
||||
Thread has 7 frames
|
||||
Frame 0 is interpreted
|
||||
Frame 1 is native
|
||||
Frame 2 is native
|
||||
Frame 3 is native
|
||||
Frame 4 is native
|
||||
Frame 5 is native
|
||||
Frame 6 is interpreted
|
||||
Thread has 8 frames
|
||||
Frame 0 is native
|
||||
Frame 1 is interpreted
|
||||
Frame 2 is interpreted
|
||||
Frame 3 is interpreted
|
||||
Frame 4 is interpreted
|
||||
Frame 5 is interpreted
|
||||
Frame 6 is interpreted
|
||||
Frame 7 is interpreted
|
||||
Thread has 9 frames
|
||||
Frame 0 is interpreted
|
||||
Frame 1 is native
|
||||
Frame 2 is native
|
||||
Frame 3 is native
|
||||
Frame 4 is native
|
||||
Frame 5 is native
|
||||
Frame 6 is native
|
||||
Frame 7 is native
|
||||
Frame 8 is interpreted
|
||||
Thread has 10 frames
|
||||
Frame 0 is native
|
||||
Frame 1 is interpreted
|
||||
Frame 2 is interpreted
|
||||
Frame 3 is interpreted
|
||||
Frame 4 is interpreted
|
||||
Frame 5 is interpreted
|
||||
Frame 6 is interpreted
|
||||
Frame 7 is interpreted
|
||||
Frame 8 is interpreted
|
||||
Frame 9 is interpreted
|
||||
Thread has 11 frames
|
||||
Frame 0 is interpreted
|
||||
Frame 1 is native
|
||||
Frame 2 is native
|
||||
Frame 3 is native
|
||||
Frame 4 is native
|
||||
Frame 5 is native
|
||||
Frame 6 is native
|
||||
Frame 7 is native
|
||||
Frame 8 is native
|
||||
Frame 9 is native
|
||||
Frame 10 is interpreted
|
144
libjava/testsuite/libjava.jvmti/interp/natgetstacktrace.cc
Normal file
144
libjava/testsuite/libjava.jvmti/interp/natgetstacktrace.cc
Normal file
|
@ -0,0 +1,144 @@
|
|||
#include <jni.h>
|
||||
|
||||
#include <jvmti.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "getstacktrace.h"
|
||||
|
||||
void
|
||||
printStackTrace (jvmtiFrameInfo *frames, jint frame_cnt)
|
||||
{
|
||||
printf ("Thread has %d frames\n", static_cast<int> (frame_cnt));
|
||||
|
||||
for (int i = 0; i < frame_cnt; i++)
|
||||
{
|
||||
jmethodID method = frames[i].method;
|
||||
jlocation location = frames[i].location;
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
printf ("Frame %d is native\n", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Frame %d is interpreted\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_getstacktrace_natPlaceholder (JNIEnv *env, jobject obj)
|
||||
{
|
||||
jclass klass = env->GetObjectClass (obj);
|
||||
jfieldID done_id = env->GetFieldID (klass, "done", "Z");
|
||||
jfieldID num_frames_id = env->GetFieldID (klass, "num_frames", "I");
|
||||
jfieldID thread_num_id = env->GetFieldID (klass, "thread_num", "I");
|
||||
|
||||
// num_frames--
|
||||
jint n_frames = env->GetIntField (obj, num_frames_id);
|
||||
n_frames--;
|
||||
env->SetIntField (obj, num_frames_id, n_frames);
|
||||
|
||||
jint t_num = env->GetIntField (obj, thread_num_id);
|
||||
|
||||
if (n_frames <= 1)
|
||||
{
|
||||
if (t_num % 2 == 1)
|
||||
{
|
||||
jmethodID natRunner_id = env->GetMethodID (klass, "natRunner", "()V");
|
||||
env->CallVoidMethod (obj, natRunner_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
jmethodID runner_id = env->GetMethodID (klass, "runner", "()V");
|
||||
env->CallVoidMethod (obj, runner_id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (t_num % 2 == 0)
|
||||
{
|
||||
jmethodID natPlaceholder_id = env->GetMethodID (klass,
|
||||
"natPlaceholder",
|
||||
"()V");
|
||||
env->CallVoidMethod (obj, natPlaceholder_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
jmethodID placeholder_id = env->GetMethodID (klass, "placeholder",
|
||||
"()V");
|
||||
env->CallVoidMethod (obj, placeholder_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_getstacktrace_natRunner (JNIEnv *env, jobject obj)
|
||||
{
|
||||
jclass klass = env->GetObjectClass (obj);
|
||||
jfieldID done_id = env->GetFieldID (klass, "done", "Z");
|
||||
|
||||
|
||||
jboolean done;
|
||||
done = true;
|
||||
env->SetBooleanField (obj, done_id, done);
|
||||
|
||||
do
|
||||
{
|
||||
done = env->GetBooleanField (obj, done_id);
|
||||
if (done == false)
|
||||
break;
|
||||
usleep (10);
|
||||
}
|
||||
while (done != false);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_getstacktrace_do_1getstacktrace_1tests
|
||||
(JNIEnv *env, jclass klass, jobjectArray thr_arr)
|
||||
{
|
||||
JavaVM *vm;
|
||||
jint err = env->GetJavaVM (&vm);
|
||||
if (err < 0)
|
||||
{
|
||||
fprintf (stderr, "error getting VM\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
jvmtiEnv *jvmti = NULL;
|
||||
vm->GetEnv ((void **) &jvmti, JVMTI_VERSION_1_0);
|
||||
|
||||
if (jvmti == NULL)
|
||||
{
|
||||
fprintf (stderr, "error getting jvmti environment\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
jint frame_cnt;
|
||||
jvmtiFrameInfo frames[30];
|
||||
|
||||
jvmtiError jerr;
|
||||
jthread thr;
|
||||
|
||||
jsize num_threads = env->GetArrayLength (thr_arr);
|
||||
|
||||
for (int i = 0; i < num_threads; i++)
|
||||
{
|
||||
thr = reinterpret_cast<jthread>
|
||||
(env->GetObjectArrayElement (thr_arr, static_cast<jsize> (i)));
|
||||
fflush (stdout);
|
||||
jerr = jvmti->GetStackTrace (thr, 0, 30, frames, &frame_cnt);
|
||||
if (jerr != JVMTI_ERROR_NONE)
|
||||
{
|
||||
char *error_name;
|
||||
jvmti->GetErrorName (jerr, &error_name);
|
||||
fprintf (stderr, "JVMTI Error: %s\n", error_name);
|
||||
jvmti->Deallocate (reinterpret_cast<unsigned char *> (error_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
printStackTrace (frames, frame_cnt);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue