[vmkit-commits] [vmkit] r61496 - in /vmkit/trunk: include/mvm/JIT.h include/mvm/Threads/Thread.h include/mvm/VirtualMachine.h lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp lib/JnJVM/Classpath/ClasspathVMThrowable.cpp lib/JnJVM/VMCore/JavaThread.cpp lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h lib/Mvm/Runtime/JIT.cpp lib/N3/VMCore/BackTrace.cpp lib/N3/VMCore/MSCorlib.cpp lib/N3/VMCore/N3ModuleProvider.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Tue Dec 30 07:10:55 PST 2008
Author: geoffray
Date: Tue Dec 30 09:10:36 2008
New Revision: 61496
URL: http://llvm.org/viewvc/llvm-project?rev=61496&view=rev
Log:
Move the function map one up in the virtual machine hierarchy so that
N3 can also use it.
Modified:
vmkit/trunk/include/mvm/JIT.h
vmkit/trunk/include/mvm/Threads/Thread.h
vmkit/trunk/include/mvm/VirtualMachine.h
vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp
vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
vmkit/trunk/lib/Mvm/Runtime/JIT.cpp
vmkit/trunk/lib/N3/VMCore/BackTrace.cpp
vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp
vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
Modified: vmkit/trunk/include/mvm/JIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Tue Dec 30 09:10:36 2008
@@ -28,7 +28,6 @@
class LockNormal;
class MvmMemoryManager;
-class Thread;
const double MaxDouble = +INFINITY; //1.0 / 0.0;
const double MinDouble = -INFINITY;//-1.0 / 0.0;
@@ -166,7 +165,6 @@
static int disassemble(unsigned int* addr);
- static int getBacktrace(void** stack, int size);
static const llvm::Function* getCodeFromPointer(void* addr);
static void addMethodInfo(void* end, const llvm::Function* F);
Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Tue Dec 30 09:10:36 2008
@@ -195,6 +195,18 @@
VirtualMachine* stoppingService;
#endif
+ /// getBacktrace - Return the back trace of this thread.
+ ///
+ int getBacktrace(void** stack, int size) {
+ void** addr = (void**)__builtin_frame_address(0);
+ int cpt = 0;
+ while (addr && cpt < size && addr < baseSP && addr < addr[0]) {
+ addr = (void**)addr[0];
+ stack[cpt++] = (void**)FRAME_IP(addr);
+ }
+ return cpt;
+ }
+
};
Modified: vmkit/trunk/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/VirtualMachine.h (original)
+++ vmkit/trunk/include/mvm/VirtualMachine.h Tue Dec 30 09:10:36 2008
@@ -20,6 +20,9 @@
#include "mvm/Object.h"
#include "mvm/Threads/Locks.h"
+#include <cassert>
+#include <map>
+
namespace mvm {
/// VirtualMachine - This class is the root of virtual machine classes. It
@@ -56,7 +59,41 @@
static CompilationUnit* initialiseCLIVM();
static VirtualMachine* createCLIVM(CompilationUnit* C = 0);
+
+protected:
+
+ /// JavaFunctionMap - Map of Java method to function pointers. This map is
+ /// used when walking the stack so that VMKit knows which Java method is
+ /// executing on the stack.
+ ///
+ std::map<void*, void*> Functions;
+
+ /// FunctionMapLock - Spin lock to protect the JavaFunctionMap.
+ ///
+ mvm::SpinLock FunctionMapLock;
+
+public:
+ /// addMethodInFunctionMap - A new method pointer in the function map.
+ ///
+ template <typename T>
+ void addMethodInFunctionMap(T* meth, void* addr) {
+ FunctionMapLock.acquire();
+ Functions.insert(std::make_pair((void*)addr, meth));
+ FunctionMapLock.release();
+ }
+ /// IPToJavaMethod - Map an instruction pointer to the Java method.
+ ///
+ template <typename T> T* IPToMethod(void* ip) {
+ FunctionMapLock.acquire();
+ std::map<void*, void*>::iterator I = Functions.upper_bound(ip);
+ assert(I != Functions.begin() && "Wrong value in function map");
+ FunctionMapLock.release();
+
+ // Decrement because we had the "greater than" value.
+ I--;
+ return (T*)I->second;
+ }
#ifdef ISOLATE
size_t IsolateID;
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMStackWalker.cpp Tue Dec 30 09:10:36 2008
@@ -47,7 +47,7 @@
uint32 index = 0;
for (; i != e; ++i) {
- JavaMethod* meth = vm->IPToJavaMethod(*i);
+ JavaMethod* meth = vm->IPToMethod<JavaMethod>(*i);
assert(meth && "Wrong stack trace");
res->elements[index++] = meth->classDef->getClassDelegatee(vm);
}
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp Tue Dec 30 09:10:36 2008
@@ -104,7 +104,7 @@
std::vector<void*>::iterator i = stack->begin(), e = stack->end();
uint32 index = 0;
while (i != e) {
- JavaMethod* meth = vm->IPToJavaMethod(*i);
+ JavaMethod* meth = vm->IPToMethod<JavaMethod>(*i);
assert(meth && "Wrong stack trace");
if (meth->classDef->subclassOf(vm->upcalls->newThrowable)) {
++i;
@@ -117,7 +117,7 @@
index = 0;
for (; i != e; ++i) {
- JavaMethod* meth = vm->IPToJavaMethod(*i);
+ JavaMethod* meth = vm->IPToMethod<JavaMethod>(*i);
assert(meth && "Wrong stack trace");
res->elements[index++] = consStackElement(meth, *i);
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Tue Dec 30 09:10:36 2008
@@ -106,7 +106,7 @@
addr = (void**)addr[0];
void* ip = FRAME_IP(addr);
- JavaMethod* meth = getJVM()->IPToJavaMethod(ip);
+ JavaMethod* meth = getJVM()->IPToMethod<JavaMethod>(ip);
return meth->classDef;
}
@@ -168,7 +168,7 @@
do {
void* ip = FRAME_IP(addr);
- JavaMethod* meth = vm->IPToJavaMethod(ip);
+ JavaMethod* meth = vm->IPToMethod<JavaMethod>(ip);
assert(meth && "Wrong stack");
fprintf(stderr, "; %p in %s\n", ip, meth->printString());
addr = (void**)addr[0];
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Tue Dec 30 09:10:36 2008
@@ -1199,38 +1199,20 @@
-void Jnjvm::addMethodInFunctionMap(JavaMethod* meth, void* addr) {
- FunctionMapLock.acquire();
- JavaFunctionMap.insert(std::make_pair(addr, meth));
- FunctionMapLock.release();
-}
-
void Jnjvm::removeMethodsInFunctionMap(JnjvmClassLoader* loader) {
// Loop over all methods in the map to find which ones belong
// to this class loader.
FunctionMapLock.acquire();
- std::map<void*, JavaMethod*>::iterator temp;
- for (std::map<void*, JavaMethod*>::iterator i = JavaFunctionMap.begin(),
- e = JavaFunctionMap.end(); i != e;) {
- if (i->second->classDef->classLoader == loader) {
+ std::map<void*, void*>::iterator temp;
+ for (std::map<void*, void*>::iterator i = Functions.begin(),
+ e = Functions.end(); i != e;) {
+ if (((JavaMethod*)i->second)->classDef->classLoader == loader) {
temp = i;
++i;
- JavaFunctionMap.erase(temp);
+ Functions.erase(temp);
} else {
++i;
}
}
FunctionMapLock.release();
}
-
-JavaMethod* Jnjvm::IPToJavaMethod(void* Addr) {
- FunctionMapLock.acquire();
- std::map<void*, JavaMethod*>::iterator I = JavaFunctionMap.upper_bound(Addr);
- assert(I != JavaFunctionMap.begin() && "Wrong value in function map");
- FunctionMapLock.release();
-
- // Decrement because we had the "greater than" value.
- I--;
- return I->second;
-
-}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Tue Dec 30 09:10:36 2008
@@ -342,32 +342,11 @@
///
virtual void waitForExit();
-private:
-
- /// JavaFunctionMap - Map of Java method to function pointers. This map is
- /// used when walking the stack so that VMKit knows which Java method is
- /// executing on the stack.
- ///
- std::map<void*, JavaMethod*> JavaFunctionMap;
-
- /// FunctionMapLock - Spin lock to protect the JavaFunctionMap.
- ///
- mvm::SpinLock FunctionMapLock;
-
-public:
- /// addMethodInFunctionMap - A new method pointer in the function map.
- ///
- void addMethodInFunctionMap(JavaMethod* meth, void* addr);
-
/// removeMethodsInFunctionMap - Removes all methods compiled by this
/// class loader from the function map.
///
void removeMethodsInFunctionMap(JnjvmClassLoader* loader);
- /// IPToJavaMethod - Map an instruction pointer to the Java method.
- ///
- JavaMethod* IPToJavaMethod(void* ip);
-
#ifdef ISOLATE
static Jnjvm* RunningIsolates[NR_ISOLATES];
static mvm::LockNormal IsolateLock;
Modified: vmkit/trunk/lib/Mvm/Runtime/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/JIT.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Tue Dec 30 09:10:36 2008
@@ -266,17 +266,6 @@
pm->run(*func);
}
-int MvmModule::getBacktrace(void** stack, int size) {
- void** addr = (void**)__builtin_frame_address(0);
- int cpt = 0;
- void* baseSP = mvm::Thread::get()->baseSP;
- while (addr && cpt < size && addr < baseSP && addr < addr[0]) {
- addr = (void**)addr[0];
- stack[cpt++] = (void**)FRAME_IP(addr);
- }
- return cpt;
-}
-
static LockNormal lock;
static std::map<void*, const llvm::Function*> pointerMap;
Modified: vmkit/trunk/lib/N3/VMCore/BackTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/BackTrace.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/BackTrace.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/BackTrace.cpp Tue Dec 30 09:10:36 2008
@@ -23,64 +23,18 @@
using namespace n3;
+// Do a backtrace until we know when we cross native -> CLI boundaries.
void CLIJit::printBacktrace() {
int* ips[100];
- int real_size = mvm::MvmModule::getBacktrace((void**)(void*)ips, 100);
+ int real_size = mvm::Thread::get()->getBacktrace((void**)(void*)ips, 100);
int n = 0;
while (n < real_size) {
- const llvm::Function* F = mvm::MvmModule::getCodeFromPointer(ips[n++]);
- if (F) {
- VMMethod* meth = CLIJit::getMethod(F);
- if (meth) {
- printf("; %p in %s\n", (void*)ips[n - 1], meth->printString());
- } else {
- printf("; %p in %s\n", (void*)ips[n - 1], "unknown");
- }
+ Dl_info info;
+ int res = dladdr(ips[n++], &info);
+ if (res != 0) {
+ fprintf(stderr, "; %p in %s\n", (void*)ips[n - 1], info.dli_sname);
} else {
- Dl_info info;
- int res = dladdr(ips[n++], &info);
- if (res != 0) {
- printf("; %p in %s\n", (void*)ips[n - 1], info.dli_sname);
- } else {
- printf("; %p in Unknown\n", (void*)ips[n - 1]);
- }
+ fprintf(stderr, "; %p in .Net method\n", (void*)ips[n - 1]);
}
}
}
-
-
-
-Assembly* Assembly::getExecutingAssembly() {
- int* ips[5];
- int real_size = mvm::MvmModule::getBacktrace((void**)(void*)ips, 5);
- int n = 0;
- while (n < real_size) {
- const llvm::Function* F = mvm::MvmModule::getCodeFromPointer(ips[n++]);
- if (F) {
- VMMethod* meth = CLIJit::getMethod(F);
- if (meth) {
- return meth->classDef->assembly;
- }
- }
- }
- return 0;
-}
-
-Assembly* Assembly::getCallingAssembly() {
- int* ips[5];
- int real_size = mvm::MvmModule::getBacktrace((void**)(void*)ips, 5);
- int n = 0;
- int i = 0;
- while (n < real_size) {
- const llvm::Function* F = mvm::MvmModule::getCodeFromPointer(ips[n++]);
- if (F) {
- VMMethod* meth = CLIJit::getMethod(F);
- if (meth && i >= 1) {
- return meth->classDef->assembly;
- } else {
- ++i;
- }
- }
- }
- return 0;
-}
Modified: vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp Tue Dec 30 09:10:36 2008
@@ -74,15 +74,44 @@
extern "C" VMObject* System_Reflection_Assembly_GetCallingAssembly() {
- Assembly* ass = Assembly::getCallingAssembly();
- assert(ass);
- return ass->getAssemblyDelegatee();
+ // Call to this function.
+ void** cur = (void**)__builtin_frame_address(0);
+
+ // Stub from CLI to native.
+ cur = (void**)cur[0];
+
+ // The CLI function.
+ cur = (void**)cur[0];
+
+ // The caller of the CLI function;
+ cur = (void**)cur[0];
+
+ VirtualMachine* vm = VMThread::get()->vm;
+
+ VMMethod* meth = vm->IPToMethod<VMMethod>(FRAME_IP(cur));
+
+ assert(meth && "Wrong stack");
+
+ return meth->classDef->assembly->getAssemblyDelegatee();
}
extern "C" VMObject* System_Reflection_Assembly_GetExecutingAssembly() {
- Assembly* ass = Assembly::getExecutingAssembly();
- assert(ass);
- return ass->getAssemblyDelegatee();
+ // Call to this function.
+ void** cur = (void**)__builtin_frame_address(0);
+
+ // Stub from CLI to native.
+ cur = (void**)cur[0];
+
+ // The CLI function.
+ cur = (void**)cur[0];
+
+ VirtualMachine* vm = VMThread::get()->vm;
+
+ VMMethod* meth = vm->IPToMethod<VMMethod>(FRAME_IP(cur));
+
+ assert(meth && "Wrong stack");
+
+ return meth->classDef->assembly->getAssemblyDelegatee();
}
extern "C" void System_Reflection_Assembly_LoadFromFile() {
Modified: vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp?rev=61496&r1=61495&r2=61496&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/N3ModuleProvider.cpp Tue Dec 30 09:10:36 2008
@@ -15,7 +15,9 @@
#include "Assembly.h"
#include "CLIJit.h"
#include "N3ModuleProvider.h"
+#include "VirtualMachine.h"
#include "VMClass.h"
+#include "VMThread.h"
using namespace llvm;
using namespace n3;
@@ -38,6 +40,8 @@
CLIJit::compile(meth->classDef, meth);
void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(meth->methPtr);
meth->code = res;
+ VirtualMachine* vm = VMThread::get()->vm;
+ vm->addMethodInFunctionMap(meth, res);
}
meth->classDef->release();
meth->classDef->resolveStatic(true, NULL);
More information about the vmkit-commits
mailing list