[vmkit-commits] [vmkit] r61488 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaMetaJIT.cpp JavaThread.cpp JavaThread.h Jni.cpp NativeUtil.h
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Tue Dec 30 02:08:35 PST 2008
Author: geoffray
Date: Tue Dec 30 04:08:05 2008
New Revision: 61488
URL: http://llvm.org/viewvc/llvm-project?rev=61488&view=rev
Log:
Commentify and rename some functions for clarification.
Modified:
vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h
vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp
vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.h
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=61488&r1=61487&r2=61488&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Tue Dec 30 04:08:05 2008
@@ -83,7 +83,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -113,7 +113,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -142,7 +142,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -170,7 +170,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -197,7 +197,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -223,7 +223,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -278,7 +278,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -305,7 +305,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -331,7 +331,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -358,7 +358,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -385,7 +385,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
@@ -411,7 +411,7 @@
} \
if (excp) { \
th->pendingException = excp; \
- th->returnFromJava(); \
+ th->throwFromJava(); \
} \
th->endJava(); \
return res; \
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp?rev=61488&r1=61487&r2=61488&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Tue Dec 30 04:08:05 2008
@@ -26,11 +26,6 @@
const unsigned int JavaThread::StateWaiting = 1;
const unsigned int JavaThread::StateInterrupted = 2;
-void JavaThread::print(mvm::PrintBuffer* buf) const {
- buf->write("Thread:");
- if (javaThread) javaThread->print(buf);
-}
-
JavaThread::JavaThread(JavaObject* thread, JavaObject* vmth, Jnjvm* isolate) {
javaThread = thread;
vmThread = vmth;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h?rev=61488&r1=61487&r2=61488&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h Tue Dec 30 04:08:05 2008
@@ -25,43 +25,101 @@
class JavaObject;
class Jnjvm;
+/// JavaThread - This class is the internal representation of a Java thread.
+/// It maintains thread-specific information such as its state, the current
+/// exception if there is one, the layout of the stack, etc.
+///
class JavaThread : public mvm::Thread {
+
+
public:
+
+ /// VT - The virtual table of JavaThread objects, so that we know
+ /// if a thread is a JavaThread.
+ ///
static VirtualTable *VT;
+
+ /// javaThread - The Java representation of this thread.
+ ///
JavaObject* javaThread;
+
+ /// vmThread - The VMThread object of this thread.
+ ///
JavaObject* vmThread;
+
+ /// lock - This lock is used when waiting or being notified or interrupted.
+ ///
mvm::LockNormal lock;
+
+ /// varcond - Condition variable when the thread needs to be awaken from
+ /// a wait.
+ ///
mvm::Cond varcond;
+
+ /// pendingException - The Java exception currently pending.
+ ///
JavaObject* pendingException;
+
+ /// internalPendingException - The C++ exception currencty pending.
+ ///
void* internalPendingException;
- uint32 interruptFlag;
- uint32 state;
- std::vector<jmp_buf*> sjlj_buffers;
- std::vector<void*> addresses;
+ /// interruptFlag - Has this thread been interrupted?
+ ///
+ uint32 interruptFlag;
+
static const unsigned int StateRunning;
static const unsigned int StateWaiting;
static const unsigned int StateInterrupted;
- void print(mvm::PrintBuffer *buf) const;
+ /// state - The current state of this thread: Running, Waiting or Interrupted.
+ uint32 state;
+
+ /// sjlj_buffers - Setjmp buffers pushed when entering a non-JVM native
+ /// function and popped when leaving the function. The buffer is used when
+ /// the native function throws an exception through a JNI throwException call.
+ ///
+ std::vector<jmp_buf*> sjlj_buffers;
+
+ /// addresses - The list of return addresses which represent native/Java cross
+ /// calls.
+ ///
+ std::vector<void*> addresses;
+
+ /// tracer - Traces GC-objects pointed by this thread object.
+ ///
virtual void TRACER;
+
+ /// JavaThread - Empty constructor, used to get the VT.
+ ///
JavaThread() {
#ifdef SERVICE
replacedEIPs = 0;
#endif
}
+
+ /// ~JavaThread - Delete any potential malloc'ed objects used by this thread.
+ ///
~JavaThread();
+ /// JavaThread - Creates a Java thread.
+ ///
JavaThread(JavaObject* thread, JavaObject* vmThread, Jnjvm* isolate);
+ /// get - Get the current thread as a JnJVM object.
+ ///
static JavaThread* get() {
return (JavaThread*)mvm::Thread::get();
}
+ /// getJVM - Get the JnJVM in which this thread executes.
+ ///
Jnjvm* getJVM() {
return (Jnjvm*)MyVM;
}
+ /// currentThread - Return the current thread as a Java object.
+ ///
static JavaObject* currentThread() {
JavaThread* result = get();
if (result != 0)
@@ -69,21 +127,26 @@
else
return 0;
}
-
+
+ /// getException - Return the C++ specific exception object.
+ ///
static void* getException() {
// 32 = sizeof(_Unwind_Exception) in libgcc...
return (void*)
((uintptr_t)JavaThread::get()->internalPendingException - 32);
}
- /// throwException - Throws the given exception in the current thread.
+ /// throwException - Throw the given exception in the current thread.
///
static void throwException(JavaObject* obj);
- /// throwPendingException - Throws a pending exception created by JNI.
+ /// throwPendingException - Throw a pending exception created by JNI.
///
static void throwPendingException();
+ /// compareException - Compare the pending exception's class with the
+ /// given class.
+ ///
static bool compareException(UserClass* cl) {
JavaObject* pe = JavaThread::get()->pendingException;
assert(pe && "no pending exception?");
@@ -91,11 +154,15 @@
return val;
}
+ /// getJavaException - Return the pending exception.
+ ///
static JavaObject* getJavaException() {
return JavaThread::get()->pendingException;
}
- void returnFromJNI() {
+ /// throwFromJNI - Throw an exception after executing JNI code.
+ ///
+ void throwFromJNI() {
assert(sjlj_buffers.size());
#if defined(__MACH__)
longjmp((int*)sjlj_buffers.back(), 1);
@@ -104,23 +171,36 @@
#endif
}
- void returnFromNative() {
+ /// throwFromNative - Throw an exception after executing Native code.
+ ///
+ void throwFromNative() {
addresses.pop_back();
throwPendingException();
}
- void returnFromJava() {
+ /// throwFromJava - Throw an exception after executing Java code.
+ ///
+ void throwFromJava() {
addresses.pop_back();
throwPendingException();
}
+ /// startNative - Record that we are entering native code.
+ ///
void startNative(int level);
+
+ /// startJava - Record that we are entering Java code.
+ ///
void startJava();
+ /// endNative - Record that we are leaving native code.
+ ///
void endNative() {
addresses.pop_back();
}
+ /// endNative - Record that we are leaving Java code.
+ ///
void endJava() {
addresses.pop_back();
}
@@ -136,30 +216,42 @@
/// getJavaFrameContext - Fill the vector with Java frames
/// currently on the stack.
+ ///
void getJavaFrameContext(std::vector<void*>& context);
- /// printString - Prints the class.
- char *printString() const {
- mvm::PrintBuffer *buf = mvm::PrintBuffer::alloc();
- print(buf);
- return buf->contents()->cString();
+private:
+ /// internalClearException - Clear the C++ and Java exceptions
+ /// currently pending.
+ ///
+ virtual void internalClearException() {
+ pendingException = 0;
+ internalPendingException = 0;
}
+public:
+
#ifdef SERVICE
+ /// ServiceException - The exception that will be thrown if a bundle is
+ /// stopped.
JavaObject* ServiceException;
+
+ /// replacedEIPs - List of instruction pointers which must be replaced
+ /// to a function that throws an exception. We maintain this list and update
+ /// the stack correctly so that Dwarf unwinding does not complain.
+ ///
void** replacedEIPs;
+
+ /// eipIndex - The current index in the replacedIPs list.
+ ///
uint32_t eipIndex;
#endif
+ /// isJavaThread - Is the given thread a Java thread?
+ ///
static bool isJavaThread(mvm::Thread* th) {
return ((void**)th)[0] == VT;
}
-private:
- virtual void internalClearException() {
- pendingException = 0;
- internalPendingException = 0;
- }
};
} // end namespace jnjvm
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp?rev=61488&r1=61487&r2=61488&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp Tue Dec 30 04:08:05 2008
@@ -145,7 +145,7 @@
false, true, 0);
init->invokeIntSpecial(vm, realCl, res, vm->asciizToStr(msg));
th->pendingException = res;
- th->returnFromJNI();
+ th->throwFromJNI();
return 1;
END_JNI_EXCEPTION
Modified: vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.h?rev=61488&r1=61487&r2=61488&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.h Tue Dec 30 04:08:05 2008
@@ -37,7 +37,7 @@
} \
if (excp) { \
__th->pendingException = excp; \
- __th->returnFromNative(); \
+ __th->throwFromNative(); \
} \
__th->endNative();
@@ -53,7 +53,7 @@
if (excp) { \
JavaThread* th = JavaThread::get(); \
th->pendingException = excp; \
- th->returnFromJNI(); \
+ th->throwFromJNI(); \
}
class NativeUtil {
More information about the vmkit-commits
mailing list