[llvm-commits] [vmkit] r50422 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaInitialise.cpp JavaIsolate.cpp JavaObject.cpp ServiceDomain.cpp ServiceDomain.h
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Tue Apr 29 08:14:19 PDT 2008
Author: geoffray
Date: Tue Apr 29 10:14:19 2008
New Revision: 50422
URL: http://llvm.org/viewvc/llvm-project?rev=50422&view=rev
Log:
For a service environment:
- Provide Felix Hooks
- Perform thread monitoring
- Throw an exception when a service faults
Modified:
vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp
vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp
vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=50422&r1=50421&r2=50422&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Tue Apr 29 10:14:19 2008
@@ -233,7 +233,7 @@
sa.sa_sigaction = handler;
sa.sa_flags |= (SA_RESTART | SA_SIGINFO | SA_NODEFER);
sigaction(SIGSEGV, &sa, 0);
-
+
JavaJIT::initialise();
initialiseVT();
initialiseStatics();
@@ -249,7 +249,7 @@
#else
#ifdef SERVICE_VM
ServiceDomain* vm = ServiceDomain::allocateService((JavaIsolate*)Jnjvm::bootstrapVM);
- JavaThread::get()->isolate = vm;
+ vm->startExecution();
#else
JavaIsolate* vm = JavaIsolate::allocateIsolate(JavaIsolate::bootstrapVM);
#endif
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp?rev=50422&r1=50421&r2=50422&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp Tue Apr 29 10:14:19 2008
@@ -384,8 +384,7 @@
loadBootstrap();
#ifdef SERVICE_VM
- (*Classpath::vmdataClassLoader)(appClassLoader, (JavaObject*)this);
- Jnjvm::bootstrapVM->appClassLoader = appClassLoader;
+ ServiceDomain::initialise((ServiceDomain*)this);
#endif
if (info.agents.size()) {
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp?rev=50422&r1=50421&r2=50422&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Tue Apr 29 10:14:19 2008
@@ -120,7 +120,7 @@
#ifdef SERVICE_VM
ServiceDomain* vm = (ServiceDomain*)JavaThread::get()->isolate;
if (!(vm->GC->isMyObject(this))) {
- vm->serviceError("I'm locking an object I don't own");
+ vm->serviceError(vm, "I'm locking an object I don't own");
}
#endif
myLock(this)->aquire();
@@ -132,7 +132,7 @@
#ifdef SERVICE_VM
ServiceDomain* vm = (ServiceDomain*)JavaThread::get()->isolate;
if (!(vm->GC->isMyObject(this))) {
- vm->serviceError("I'm unlocking an object I don't own");
+ vm->serviceError(vm, "I'm unlocking an object I don't own");
}
#endif
lockObj->release();
Modified: vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp?rev=50422&r1=50421&r2=50422&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp Tue Apr 29 10:14:19 2008
@@ -27,6 +27,14 @@
llvm::Function* ServiceDomain::serviceCallStartLLVM;
llvm::Function* ServiceDomain::serviceCallStopLLVM;
+JavaMethod* ServiceDomain::ServiceErrorInit;
+Class* ServiceDomain::ServiceErrorClass;
+ServiceDomain* ServiceDomain::bootstrapDomain;
+
+// OSGi specific fields
+JavaField* ServiceDomain::OSGiFramework;
+JavaMethod* ServiceDomain::uninstallBundle;
+
GlobalVariable* ServiceDomain::llvmDelegatee() {
if (!_llvmDelegatee) {
@@ -116,13 +124,22 @@
service->numThreads = 0;
service->lock = mvm::Lock::allocNormal();
+ service->state = DomainLoaded;
return service;
}
-void ServiceDomain::serviceError(const char* str) {
- fprintf(stderr, str);
- JavaJIT::printBacktrace();
- abort();
+void ServiceDomain::serviceError(ServiceDomain* errorDomain,
+ const char* str) {
+ if (ServiceErrorClass) {
+ JavaObject* obj = (*ServiceErrorClass)(bootstrapDomain);
+ ServiceErrorInit->invokeIntVirtual(bootstrapDomain,
+ bootstrapDomain->asciizToStr(str),
+ errorDomain);
+ JavaThread::throwException(obj);
+ } else {
+ fprintf(stderr, str);
+ abort();
+ }
}
ServiceDomain* ServiceDomain::getDomainFromLoader(JavaObject* loader) {
@@ -131,6 +148,9 @@
return vm;
}
+#include "gccollector.h"
+#include "gcthread.h"
+
extern "C" void serviceCallStart(ServiceDomain* caller,
ServiceDomain* callee) {
assert(caller && "No caller in service start?");
@@ -139,11 +159,16 @@
"Caller not a service domain?");
assert(callee->getVirtualTable() == ServiceDomain::VT &&
"Callee not a service domain?");
+ if (callee->state != DomainLoaded) {
+ ServiceDomain::serviceError(callee, "calling a stopped bundle");
+ }
JavaThread* th = JavaThread::get();
th->isolate = callee;
caller->lock->lock();
caller->interactions[callee]++;
caller->lock->unlock();
+ mvm::GCThreadCollector* cur = mvm::GCCollector::threads->myloc();
+ cur->meta = callee;
}
extern "C" void serviceCallStop(ServiceDomain* caller,
@@ -154,7 +179,53 @@
"Caller not a service domain?");
assert(callee->getVirtualTable() == ServiceDomain::VT &&
"Callee not a service domain?");
+ if (caller->state != DomainLoaded) {
+ ServiceDomain::serviceError(caller, "Returning to a stopped bundle");
+ }
JavaThread* th = JavaThread::get();
th->isolate = caller;
+ mvm::GCThreadCollector* cur = mvm::GCCollector::threads->myloc();
+ cur->meta = caller;
}
+
+static int updateCPUUsage(void* unused) {
+ mvm::GCThreadCollector *cur;
+ while (true) {
+ sleep(1);
+ for(cur=(mvm::GCThreadCollector *)mvm::GCCollector::threads->base.next();
+ cur!=&(mvm::GCCollector::threads->base);
+ cur=(mvm::GCThreadCollector *)cur->next()) {
+ ServiceDomain* executingDomain = (ServiceDomain*)cur->meta;
+ if (executingDomain)
+ ++executingDomain->executionTime;
+ }
+ }
+}
+
+void ServiceDomain::initialise(ServiceDomain* boot) {
+ ServiceDomain::bootstrapDomain = boot;
+ Jnjvm::bootstrapVM->appClassLoader = boot->appClassLoader;
+ (*Classpath::vmdataClassLoader)(boot->appClassLoader, (JavaObject*)boot);
+ int tid = 0;
+ mvm::Thread::start(&tid, (int (*)(void *))updateCPUUsage, 0);
+ ServiceErrorClass = UPCALL_CLASS(Jnjvm::bootstrapVM, "JnJVMBundleException");
+ ServiceErrorInit = UPCALL_METHOD(Jnjvm::bootstrapVM, "JnjvmBundleException",
+ "<init>",
+ "(Ljava/lang/String;Ljava/lang/Object;)V",
+ ACC_VIRTUAL);
+ Class* MainClass = bootstrapDomain->constructClass(bootstrapDomain->asciizConstructUTF8("Main"),
+ Jnjvm::bootstrapVM->appClassLoader);
+ OSGiFramework = bootstrapDomain->constructField(MainClass, bootstrapDomain->asciizConstructUTF8("m_felix"),
+ bootstrapDomain->asciizConstructUTF8("Lorg/apache/felix/framework/Felix;"),
+ ACC_STATIC);
+ uninstallBundle = bootstrapDomain->constructMethod(OSGiFramework->classDef, bootstrapDomain->asciizConstructUTF8("uninstallBundle"),
+ bootstrapDomain->asciizConstructUTF8("(Lorg/apache/felix/framework/FelixBundle;)V"),
+ ACC_VIRTUAL);
+}
+
+void ServiceDomain::startExecution() {
+ JavaThread::get()->isolate = this;
+ mvm::GCThreadCollector* cur = mvm::GCCollector::threads->myloc();
+ cur->meta = this;
+}
Modified: vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h?rev=50422&r1=50421&r2=50422&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h Tue Apr 29 10:14:19 2008
@@ -30,6 +30,10 @@
class ClassMap;
+typedef enum DomainState {
+ DomainLoaded, DomainUnloading, DomainUnloaded
+}DomainState;
+
class ServiceDomain : public JavaIsolate {
private:
llvm::GlobalVariable* _llvmDelegatee;
@@ -41,22 +45,34 @@
virtual void destroyer(size_t sz);
static ServiceDomain* allocateService(JavaIsolate* callingVM);
llvm::GlobalVariable* llvmDelegatee();
- void serviceError(const char* str);
-
+ static void serviceError(ServiceDomain* error, const char* str);
+
mvm::Lock* lock;
ClassMap* classes;
uint64 executionTime;
uint64 numThreads;
std::map<ServiceDomain*, uint64> interactions;
+ DomainState state;
static ServiceDomain* getDomainFromLoader(JavaObject* loader);
static llvm::Function* serviceCallStartLLVM;
static llvm::Function* serviceCallStopLLVM;
+ static JavaMethod* ServiceErrorInit;
+ static Class* ServiceErrorClass;
+
+ static ServiceDomain* bootstrapDomain;
static bool isLockableDomain(Jnjvm* vm) {
- return (vm == Jnjvm::bootstrapVM ||
- vm == getDomainFromLoader(Jnjvm::bootstrapVM->appClassLoader));
+ return (vm == Jnjvm::bootstrapVM || vm == bootstrapDomain);
}
+
+ static void initialise(ServiceDomain* boot);
+ void startExecution();
+
+ // OSGi specific fields
+ static JavaField* OSGiFramework;
+ static JavaMethod* uninstallBundle;
+
};
} // end namespace jnjvm
More information about the llvm-commits
mailing list