Commit f356a436 by Keith Seitz Committed by Keith Seitz

java-stack.h (ncodeMap): Declare.

        * include/java-stack.h (ncodeMap): Declare.
        (_Jv_StackTrace): Make _Jv_GetMethodDeclaringClass friend.
        * java/lang/Class.h (_Jv_GetMethodDeclaringClass): Declare.
        * java/lang/natClass.cc (_Jv_GetMethodDeclaringClass): New
        function.
        * stacktrace.cc (ncodeMap): Redefine from file global to global
        for class _Jv_StackTrace.
        (_Jv_StackTrace::UpdateNCodeMap): Add interpreted classes, too,
        so that _Jv_GetMethodDeclaringClass can find them all.
        (_Jv_StackTrace::ClassForFrame): Exclude interpreted classes.
        * jvmti.cc (_Jv_JVMTI_GetMethodDeclaringClass): New function.
        (_Jv_JVMTI_Interface): Define GetMethodDeclaringClass function.

From-SVN: r118100
parent 62baeb4f
2006-10-27 Keith Seitz <keiths@redhat.com>
* include/java-stack.h (ncodeMap): Declare.
(_Jv_StackTrace): Make _Jv_GetMethodDeclaringClass friend.
* java/lang/Class.h (_Jv_GetMethodDeclaringClass): Declare.
* java/lang/natClass.cc (_Jv_GetMethodDeclaringClass): New
function.
* stacktrace.cc (ncodeMap): Redefine from file global to global
for class _Jv_StackTrace.
(_Jv_StackTrace::UpdateNCodeMap): Add interpreted classes, too,
so that _Jv_GetMethodDeclaringClass can find them all.
(_Jv_StackTrace::ClassForFrame): Exclude interpreted classes.
* jvmti.cc (_Jv_JVMTI_GetMethodDeclaringClass): New function.
(_Jv_JVMTI_Interface): Define GetMethodDeclaringClass function.
2006-10-25 Andreas Tobler <a.tobler@schweiz.org> 2006-10-25 Andreas Tobler <a.tobler@schweiz.org>
* testsuite/libjava.jvmti/natevents.cc (do_callback_arg_tests): Replace * testsuite/libjava.jvmti/natevents.cc (do_callback_arg_tests): Replace
......
...@@ -23,6 +23,7 @@ details. */ ...@@ -23,6 +23,7 @@ details. */
#include <java/lang/StackTraceElement.h> #include <java/lang/StackTraceElement.h>
#include <java/lang/Throwable.h> #include <java/lang/Throwable.h>
#include <java/lang/Thread.h> #include <java/lang/Thread.h>
#include <java/util/IdentityHashMap.h>
#include <gnu/gcj/runtime/NameFinder.h> #include <gnu/gcj/runtime/NameFinder.h>
...@@ -102,6 +103,7 @@ private: ...@@ -102,6 +103,7 @@ private:
int length; int length;
_Jv_StackFrame frames[]; _Jv_StackFrame frames[];
static java::util::IdentityHashMap *ncodeMap;
static void UpdateNCodeMap (); static void UpdateNCodeMap ();
static jclass ClassForFrame (_Jv_StackFrame *frame); static jclass ClassForFrame (_Jv_StackFrame *frame);
static void FillInFrameInfo (_Jv_StackFrame *frame); static void FillInFrameInfo (_Jv_StackFrame *frame);
...@@ -126,7 +128,8 @@ public: ...@@ -126,7 +128,8 @@ public:
static JArray<jclass> *GetClassContext (jclass checkClass); static JArray<jclass> *GetClassContext (jclass checkClass);
static ClassLoader *GetFirstNonSystemClassLoader (void); static ClassLoader *GetFirstNonSystemClassLoader (void);
static jobjectArray GetAccessControlStack (); static jobjectArray GetAccessControlStack ();
friend jclass _Jv_GetMethodDeclaringClass (jmethodID);
}; };
// Information about a given address. // Information about a given address.
......
...@@ -290,6 +290,10 @@ class java::io::VMObjectStreamClass; ...@@ -290,6 +290,10 @@ class java::io::VMObjectStreamClass;
void _Jv_sharedlib_register_hook (jclass klass); void _Jv_sharedlib_register_hook (jclass klass);
/* Find the class that defines the given method. Returns NULL
if it cannot be found. Searches both interpreted and native
classes. */
jclass _Jv_GetMethodDeclaringClass (jmethodID method);
class java::lang::Class : public java::lang::Object class java::lang::Class : public java::lang::Object
{ {
......
...@@ -1267,3 +1267,12 @@ _Jv_GetClassNameUtf8 (jclass klass) ...@@ -1267,3 +1267,12 @@ _Jv_GetClassNameUtf8 (jclass klass)
{ {
return klass->name; return klass->name;
} }
jclass
_Jv_GetMethodDeclaringClass (jmethodID method)
{
_Jv_StackTrace::UpdateNCodeMap ();
jobject obj = reinterpret_cast<jobject> (method->ncode);
return reinterpret_cast<jclass> (_Jv_StackTrace::ncodeMap->get (obj));
}
...@@ -466,6 +466,24 @@ _Jv_JVMTI_IsMethodSynthetic (MAYBE_UNUSED jvmtiEnv *env, jmethodID method, ...@@ -466,6 +466,24 @@ _Jv_JVMTI_IsMethodSynthetic (MAYBE_UNUSED jvmtiEnv *env, jmethodID method,
} }
static jvmtiError JNICALL static jvmtiError JNICALL
_Jv_JVMTI_GetMethodDeclaringClass (MAYBE_UNUSED jvmtiEnv *env,
jmethodID method,
jclass *declaring_class_ptr)
{
REQUIRE_PHASE (env, JVMTI_PHASE_LIVE);
NULL_CHECK (declaring_class_ptr);
jclass klass = _Jv_GetMethodDeclaringClass (method);
if (klass != NULL)
{
*declaring_class_ptr = klass;
return JVMTI_ERROR_NONE;
}
return JVMTI_ERROR_INVALID_METHODID;
}
static jvmtiError JNICALL
_Jv_JVMTI_GetClassLoaderClasses (MAYBE_UNUSED jvmtiEnv *env, _Jv_JVMTI_GetClassLoaderClasses (MAYBE_UNUSED jvmtiEnv *env,
jobject init_loader, jobject init_loader,
jint *count_ptr, jint *count_ptr,
...@@ -1287,7 +1305,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface = ...@@ -1287,7 +1305,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface =
_Jv_JVMTI_GetFieldModifiers, // GetFieldModifiers _Jv_JVMTI_GetFieldModifiers, // GetFieldModifiers
_Jv_JVMTI_IsFieldSynthetic, // IsFieldSynthetic _Jv_JVMTI_IsFieldSynthetic, // IsFieldSynthetic
UNIMPLEMENTED, // GetMethodName UNIMPLEMENTED, // GetMethodName
UNIMPLEMENTED, // GetMethodDeclaringClass _Jv_JVMTI_GetMethodDeclaringClass, // GetMethodDeclaringClass
_Jv_JVMTI_GetMethodModifiers, // GetMethodModifers _Jv_JVMTI_GetMethodModifiers, // GetMethodModifers
RESERVED, // reserved67 RESERVED, // reserved67
UNIMPLEMENTED, // GetMaxLocals UNIMPLEMENTED, // GetMaxLocals
......
...@@ -23,7 +23,6 @@ details. */ ...@@ -23,7 +23,6 @@ details. */
#include <java/lang/Long.h> #include <java/lang/Long.h>
#include <java/security/AccessController.h> #include <java/security/AccessController.h>
#include <java/util/ArrayList.h> #include <java/util/ArrayList.h>
#include <java/util/IdentityHashMap.h>
#include <gnu/classpath/jdwp/Jdwp.h> #include <gnu/classpath/jdwp/Jdwp.h>
#include <gnu/java/lang/MainThread.h> #include <gnu/java/lang/MainThread.h>
#include <gnu/gcj/runtime/NameFinder.h> #include <gnu/gcj/runtime/NameFinder.h>
...@@ -41,7 +40,7 @@ using namespace gnu::gcj::runtime; ...@@ -41,7 +40,7 @@ using namespace gnu::gcj::runtime;
// NOTE: Currently this Map contradicts class GC for native classes. This map // NOTE: Currently this Map contradicts class GC for native classes. This map
// (and the "new class stack") will need to use WeakReferences in order to // (and the "new class stack") will need to use WeakReferences in order to
// enable native class GC. // enable native class GC.
static java::util::IdentityHashMap *ncodeMap; java::util::IdentityHashMap *_Jv_StackTrace::ncodeMap;
// Check the "class stack" for any classes initialized since we were last // Check the "class stack" for any classes initialized since we were last
// called, and add them to ncodeMap. // called, and add them to ncodeMap.
...@@ -56,21 +55,20 @@ _Jv_StackTrace::UpdateNCodeMap () ...@@ -56,21 +55,20 @@ _Jv_StackTrace::UpdateNCodeMap ()
jclass klass; jclass klass;
while ((klass = _Jv_PopClass ())) while ((klass = _Jv_PopClass ()))
if (!_Jv_IsInterpretedClass (klass)) {
{ //printf ("got %s\n", klass->name->data);
//printf ("got %s\n", klass->name->data); for (int i = 0; i < klass->method_count; i++)
for (int i = 0; i < klass->method_count; i++) {
{ _Jv_Method *method = &klass->methods[i];
_Jv_Method *method = &klass->methods[i]; void *ncode = method->ncode;
void *ncode = method->ncode; // Add non-abstract methods to ncodeMap.
// Add non-abstract methods to ncodeMap. if (ncode)
if (ncode) {
{ ncode = UNWRAP_FUNCTION_DESCRIPTOR (ncode);
ncode = UNWRAP_FUNCTION_DESCRIPTOR (ncode); ncodeMap->put ((java::lang::Object *) ncode, klass);
ncodeMap->put ((java::lang::Object *) ncode, klass); }
} }
} }
}
} }
// Given a native frame, return the class which this code belongs // Given a native frame, return the class which this code belongs
...@@ -85,7 +83,13 @@ _Jv_StackTrace::ClassForFrame (_Jv_StackFrame *frame) ...@@ -85,7 +83,13 @@ _Jv_StackTrace::ClassForFrame (_Jv_StackFrame *frame)
// look it up in ncodeMap // look it up in ncodeMap
if (frame->start_ip) if (frame->start_ip)
klass = (jclass) ncodeMap->get ((jobject) frame->start_ip); {
klass = (jclass) ncodeMap->get ((jobject) frame->start_ip);
// Exclude interpreted classes
if (klass != NULL && _Jv_IsInterpretedClass (klass))
klass = NULL;
}
return klass; return klass;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment