[vmkit-commits] [vmkit] r61887 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaThread.cpp JavaThread.h JavaUpcalls.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Wed Jan 7 14:09:32 PST 2009
Author: geoffray
Date: Wed Jan 7 16:09:32 2009
New Revision: 61887
URL: http://llvm.org/viewvc/llvm-project?rev=61887&view=rev
Log:
Implement natively Java methods that inspect the stack.
Modified:
vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h
vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp?rev=61887&r1=61886&r2=61887&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Wed Jan 7 16:09:32 2009
@@ -134,6 +134,64 @@
}
}
+UserClass* JavaThread::getCallingClassLevel(uint32 level) {
+ std::vector<void*>::iterator it = addresses.end();
+ uint32 index = 0;
+
+ // Loop until we cross the first Java frame.
+ while (it != addresses.begin()) {
+
+ // Get the last Java frame.
+ void** addr = (void**)*(--it);
+
+ // Set the iterator to the next native -> Java call.
+ --it;
+
+ do {
+ void* ip = FRAME_IP(addr);
+ if (index == level) {
+ JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
+ return meth->classDef;
+ }
+ addr = (void**)addr[0];
+ ++index;
+ // We end walking the stack when we cross a native -> Java call. Here
+ // the iterator points to a native -> Java call. We dereference addr twice
+ // because a native -> Java call always contains the signature function.
+ } while (((void***)addr)[0][0] != *it);
+ }
+ return 0;
+}
+
+JavaObject* JavaThread::getNonNullClassLoader() {
+ std::vector<void*>::iterator it = addresses.end();
+
+ // Loop until we cross the first Java frame.
+ while (it != addresses.begin()) {
+
+ // Get the last Java frame.
+ void** addr = (void**)*(--it);
+
+ // Set the iterator to the next native -> Java call.
+ --it;
+
+ do {
+ void* ip = FRAME_IP(addr);
+ JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
+ JnjvmClassLoader* loader = meth->classDef->classLoader;
+ JavaObject* obj = loader->getJavaClassLoader();
+ if (obj) return obj;
+ addr = (void**)addr[0];
+ // We end walking the stack when we cross a native -> Java call. Here
+ // the iterator points to a native -> Java call. We dereference addr twice
+ // because a native -> Java call always contains the signature function.
+ } while (((void***)addr)[0][0] != *it);
+ }
+
+ return 0;
+}
+
+
void JavaThread::printJavaBacktrace() {
Jnjvm* vm = getJVM();
std::vector<void*> vals;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h?rev=61887&r1=61886&r2=61887&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h Wed Jan 7 16:09:32 2009
@@ -244,6 +244,16 @@
/// method on the stack.
///
UserClass* getCallingClass(uint32 level);
+
+ /// getCallingClassLevel - Get the Java method in the stack at the
+ /// specified level.
+ ///
+ UserClass* getCallingClassLevel(uint32 level);
+
+ /// getNonNullClassLoader - Get the first non-null class loader on the
+ /// stack.
+ ///
+ JavaObject* getNonNullClassLoader();
/// printBacktrace - Prints the backtrace of this thread.
///
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=61887&r1=61886&r2=61887&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Wed Jan 7 16:09:32 2009
@@ -258,7 +258,6 @@
JavaThread* th = JavaThread::get();
UserClass* cl = th->getCallingClass(1);
if (cl) res = cl->getClassDelegatee(th->getJVM());
-
END_NATIVE_EXCEPTION
return res;
@@ -277,6 +276,30 @@
return res;
}
+extern "C" JavaObject* nativeFirstNonNullClassLoader() {
+ JavaObject *res = 0;
+
+ BEGIN_NATIVE_EXCEPTION(0)
+ JavaThread* th = JavaThread::get();
+ res = th->getNonNullClassLoader();
+ END_NATIVE_EXCEPTION
+
+ return res;
+}
+
+extern "C" JavaObject* nativeGetCallerClass(uint32 index) {
+
+ JavaObject *res = 0;
+
+ BEGIN_NATIVE_EXCEPTION(0)
+ JavaThread* th = JavaThread::get();
+ UserClass* cl = th->getCallingClassLevel(index - 1);
+ if (cl) res = cl->getClassDelegatee(th->getJVM());
+ END_NATIVE_EXCEPTION
+
+ return res;
+}
+
extern "C" void nativePropertiesPostInit(JavaObject* prop);
@@ -640,6 +663,19 @@
nativeGetCallingClassLoader,
"nativeGetCallingClassLoader");
+ JavaMethod* firstNonNullClassLoader =
+ UPCALL_METHOD(loader, "gnu/classpath/VMStackWalker", "firstNonNullClassLoader",
+ "()Ljava/lang/ClassLoader;", ACC_STATIC);
+ firstNonNullClassLoader->setCompiledPtr((void*)(intptr_t)
+ nativeFirstNonNullClassLoader,
+ "nativeFirstNonNullClassLoader");
+
+ JavaMethod* getCallerClass =
+ UPCALL_METHOD(loader, "sun/reflect/Reflection", "getCallerClass",
+ "(I)Ljava/lang/Class;", ACC_STATIC);
+ getCallerClass->setCompiledPtr((void*)(intptr_t)nativeGetCallerClass,
+ "nativeGetCallerClass");
+
JavaMethod* postProperties =
UPCALL_METHOD(loader, "gnu/classpath/VMSystemProperties", "postInit",
"(Ljava/util/Properties;)V", ACC_STATIC);
More information about the vmkit-commits
mailing list