[llvm-commits] [vmkit] r48944 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaArray.h JavaClass.cpp JavaInitialise.cpp JavaIsolate.cpp Jnjvm.cpp LockedMap.h ServiceDomain.cpp ServiceDomain.h VirtualTables.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sat Mar 29 05:20:30 PDT 2008
Author: geoffray
Date: Sat Mar 29 07:20:27 2008
New Revision: 48944
URL: http://llvm.org/viewvc/llvm-project?rev=48944&view=rev
Log:
Bugfixes and better isolation for isolates.
Added:
vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp
vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h
Modified:
vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h?rev=48944&r1=48943&r2=48944&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h Sat Mar 29 07:20:27 2008
@@ -124,6 +124,17 @@
static const UTF8* readerConstruct(Jnjvm *vm, uint16* buf, uint32 n);
const UTF8* extract(Jnjvm *vm, uint32 start, uint32 len) const;
+
+#ifdef SINGLE_VM
+ bool equals(const UTF8* other) const {
+ return this == other;
+ }
+#else
+ bool equals(const UTF8* other) const {
+ if (size != other->size) return false;
+ else return !memcmp(elements, other->elements, size * sizeof(uint16));
+ }
+#endif
};
} // end namespace jnjvm
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=48944&r1=48943&r2=48944&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sat Mar 29 07:20:27 2008
@@ -58,7 +58,7 @@
for (uint32 i = 0; i < vec->size(); i++) {
Attribut* cur = vec->at(i);
- if (cur->name == key) return cur;
+ if (cur->name->equals(key)) return cur;
}
return 0;
@@ -248,15 +248,6 @@
JavaMethod* CommonClass::lookupMethodDontThrow(const UTF8* name,
const UTF8* type, bool isStatic,
bool recurse) {
-#ifndef SINGLE_VM
- if (isolate == Jnjvm::bootstrapVM) {
- name = Jnjvm::bootstrapVM->readerConstructUTF8(name->elements,
- name->size);
- type = Jnjvm::bootstrapVM->readerConstructUTF8(type->elements,
- type->size);
-
- }
-#endif
std::vector<JavaMethod*>* meths = (isStatic? &staticMethods :
&virtualMethods);
@@ -267,7 +258,7 @@
while (!res && i < nbm) {
cur = meths->at(i);
- if (cur->name == name && cur->type == type) {
+ if (cur->name->equals(name) && cur->type->equals(type)) {
return cur;
}
++i;
@@ -305,16 +296,6 @@
const UTF8* type, bool isStatic,
bool recurse) {
-#ifndef SINGLE_VM
- if (isolate == Jnjvm::bootstrapVM) {
- name = Jnjvm::bootstrapVM->readerConstructUTF8(name->elements,
- name->size);
- type = Jnjvm::bootstrapVM->readerConstructUTF8(type->elements,
- type->size);
-
- }
-#endif
-
std::vector<JavaField*>* fields = (isStatic? &staticFields : &virtualFields);
JavaField *cur, *res = 0;
@@ -323,7 +304,7 @@
while (!res && i < nbm) {
cur = fields->at(i);
- if (cur->name == name && cur->type == type) {
+ if (cur->name->equals(name) && cur->type->equals(type)) {
return cur;
}
++i;
@@ -387,7 +368,7 @@
#endif
bool CommonClass::inheritName(const UTF8* Tname) {
- if (name == Tname) {
+ if (name->equals(Tname)) {
return true;
} else if (AssessorDesc::bogusClassToPrimitive(this)) {
return true;
@@ -527,7 +508,8 @@
mvm::jit::unprotectConstants();//->unlock();
mvm::jit::protectTypes();//->lock();
- cl->staticType = llvm::PointerType::getUnqual(llvm::StructType::get(fields, false));
+ cl->staticType =
+ llvm::PointerType::getUnqual(llvm::StructType::get(fields, false));
mvm::jit::unprotectTypes();//->unlock();
VirtualTable* VT = JavaJIT::makeVT(cl, true);
@@ -570,7 +552,8 @@
mvm::jit::unprotectConstants();//->unlock();
mvm::jit::protectTypes();//->lock();
- cl->virtualType = llvm::PointerType::getUnqual(llvm::StructType::get(fields, false));
+ cl->virtualType =
+ llvm::PointerType::getUnqual(llvm::StructType::get(fields, false));
mvm::jit::unprotectTypes();//->unlock();
VirtualTable* VT = JavaJIT::makeVT(cl, false);
@@ -614,7 +597,8 @@
JavaObject* Class::staticInstance() {
if (isolate == Jnjvm::bootstrapVM) {
Class* cl = this;
- std::pair<uint8, JavaObject*>* val = JavaThread::get()->isolate->statics->lookup(cl);
+ std::pair<uint8, JavaObject*>* val =
+ JavaThread::get()->isolate->statics->lookup(cl);
assert(val);
return val->second;
} else {
@@ -634,9 +618,11 @@
}
bool CommonClass::isReady() {
- if (isolate == Jnjvm::bootstrapVM) {
- Class* cl = this;
- std::pair<uint8, JavaObject*>* val = JavaThread::get()->isolate->statics->lookup(cl);
+ if (isolate == Jnjvm::bootstrapVM && !this->isArray &&
+ !AssessorDesc::bogusClassToPrimitive(this)) {
+ Class* cl = (Class*)this;
+ std::pair<uint8, JavaObject*>* val =
+ JavaThread::get()->isolate->statics->lookup(cl);
return val && val->first;
} else {
return status == ready;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=48944&r1=48943&r2=48944&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Sat Mar 29 07:20:27 2008
@@ -353,7 +353,11 @@
}
extern "C" int start_app(int argc, char** argv) {
+#if defined(SINGLE_VM) || defined(SERVICE_VM)
+ JavaIsolate* vm = (JavaIsolate*)JavaIsolate::bootstrapVM;
+#else
JavaIsolate* vm = JavaIsolate::allocateIsolate(JavaIsolate::bootstrapVM);
+#endif
vm->runMain(argc, argv);
return 0;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp?rev=48944&r1=48943&r2=48944&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp Sat Mar 29 07:20:27 2008
@@ -426,19 +426,12 @@
isolate->analyseClasspathEnv(isolate->bootClasspathEnv);
-#ifndef SINGLE_VM
isolate->functions = FunctionMap::allocate();
isolate->module = new llvm::Module("Isolate JnJVM");
isolate->protectModule = mvm::Lock::allocNormal();
isolate->TheModuleProvider = new JnjvmModuleProvider(isolate->module,
isolate->functions);
JavaJIT::initialiseJITIsolateVM(isolate);
-#else
- isolate->protectModule = callingVM->protectModule;
- isolate->functions = callingVM->functions;
- isolate->module = callingVM->module;
- isolate->TheModuleProvider = callingVM->TheModuleProvider;
-#endif
isolate->bootstrapThread = JavaThread::allocate(0, isolate);
JavaThread::threadKey->set(isolate->bootstrapThread);
@@ -449,7 +442,8 @@
isolate->appClassLoader = 0;
isolate->jniEnv = &JNI_JNIEnvTable;
isolate->javavmEnv = &JNI_JavaVMTable;
-#ifndef SINGLE_VM
+
+ // We copy so that bootstrap utf8 such as "<init>" are unique
isolate->hashUTF8 = bootstrapVM->hashUTF8->copy();
isolate->hashStr = StringMap::allocate();
isolate->bootstrapClasses = callingVM->bootstrapClasses;
@@ -459,15 +453,6 @@
isolate->globalRefsLock = mvm::Lock::allocNormal();
isolate->statics = StaticInstanceMap::allocate();
isolate->delegatees = DelegateeMap::allocate();
-#else
- isolate->hashUTF8 = callingVM->hashUTF8;
- isolate->hashStr = callingVM->hashStr;
- isolate->bootstrapClasses = callingVM->bootstrapClasses;
- isolate->loadedMethods = callingVM->loadedMethods;
- isolate->loadedFields = callingVM->loadedFields;
- isolate->javaTypes = callingVM->javaTypes;
- isolate->globalRefsLock = callingVM->globalRefsLock;
-#endif
return isolate;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=48944&r1=48943&r2=48944&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sat Mar 29 07:20:27 2008
@@ -34,6 +34,9 @@
#include "Jnjvm.h"
#include "LockedMap.h"
#include "Reader.h"
+#ifdef SERVICE_VM
+#include "ServiceDomain.h"
+#endif
#include "Zip.h"
using namespace jnjvm;
@@ -222,7 +225,7 @@
const UTF8* thisClassName =
ctpInfo->resolveClassName(reader->readU2());
- if (thisClassName != cl->name) {
+ if (!(thisClassName->equals(cl->name))) {
error(ClassFormatError, "try to load %s and found class named %s",
cl->printString(), thisClassName->printString());
}
@@ -292,7 +295,7 @@
#ifndef SINGLE_VM
std::pair<uint8, JavaObject*>* val = 0;
- if (this == bootstrapVM) {
+ if (this == bootstrapVM && !AssessorDesc::bogusClassToPrimitive(cl) && !cl->isArray) {
JavaObject* staticVar = ((Class*)cl)->createStaticInstance();
val = new std::pair<uint8, JavaObject*>(0, staticVar);
JavaThread::get()->isolate->statics->hash((Class*)cl, val);
@@ -319,7 +322,7 @@
cl->status = ready;
#ifndef SINGLE_VM
- if (this == bootstrapVM) {
+ if (this == bootstrapVM && !AssessorDesc::bogusClassToPrimitive(cl) && !cl->isArray) {
val->first = 1;
}
#endif
@@ -381,16 +384,6 @@
CommonClass* cl = lookupClass(name, loader);
const UTF8* bootstrapName = name;
-#ifndef SINGLE_VM
- if (!loader) {
- bootstrapName = bootstrapVM->readerConstructUTF8(name->elements,
- name->size);
- if (bootstrapName != name) {
- JavaThread::get()->isolate->hashUTF8->replace(name, bootstrapName);
- }
- cl = lookupClass(bootstrapName, loader);
- }
-#endif
if (!cl || cl->status == hashed) {
if (!loader) { // I have to load it
@@ -626,7 +619,7 @@
ServiceDomain* vm =
(ServiceDomain*)(*Classpath::vmdataClassLoader)(loader).PointerVal;
if (!vm) {
- vm = ServiceDomain::allocate();
+ vm = ServiceDomain::allocateService(Jnjvm::bootstrapVM);
(*Classpath::vmdataClassLoader)(loader, (JavaObject*)vm);
}
map = vm->classes;
@@ -676,7 +669,7 @@
ServiceDomain* vm =
(ServiceDomain*)(*Classpath::vmdataClassLoader)(loader).PointerVal;
if (!vm) {
- vm = ServiceDomain::allocate();
+ vm = ServiceDomain::allocateService(Jnjvm::bootstrapVM);
(*Classpath::vmdataClassLoader)(loader, (JavaObject*)vm);
}
map = vm->classes;
@@ -718,7 +711,7 @@
ServiceDomain* vm =
(ServiceDomain*)(*Classpath::vmdataClassLoader)(loader).PointerVal;
if (!vm) {
- vm = ServiceDomain::allocate();
+ vm = ServiceDomain::allocateService(Jnjvm::bootstrapVM);
(*Classpath::vmdataClassLoader)(loader, (JavaObject*)vm);
}
map = vm->classes;
Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h?rev=48944&r1=48943&r2=48944&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h Sat Mar 29 07:20:27 2008
@@ -31,6 +31,24 @@
class JavaObject;
class Jnjvm;
+struct ltutf8
+{
+#ifndef SINGLE_VM
+ bool operator()(const UTF8* s1, const UTF8* s2) const
+ {
+ if (s1->size < s2->size) return true;
+ else if (s1->size > s2->size) return false;
+ else return memcmp((const char*)s1->elements, (const char*)s2->elements,
+ s1->size * sizeof(uint16)) < 0;
+ }
+#else
+ bool operator()(const UTF8* s1, const UTF8* s2) const
+ {
+ return s1 < s2;
+ }
+#endif
+};
+
template<class Key, class Container, class Compare>
class LockedMap : public mvm::Object {
public:
@@ -136,7 +154,7 @@
};
class ClassMap :
- public LockedMap<const UTF8*, CommonClass*, std::less<const UTF8*> > {
+ public LockedMap<const UTF8*, CommonClass*, ltutf8 > {
public:
static VirtualTable* VT;
static ClassMap* allocate() {
@@ -197,6 +215,7 @@
}
};
+
class ZipFileMap : public LockedMap<const char*, ZipFile*, ltstr> {
public:
static VirtualTable* VT;
@@ -215,7 +234,7 @@
};
class StringMap :
- public LockedMap<const UTF8*, JavaString*, std::less<const UTF8*> > {
+ public LockedMap<const UTF8*, JavaString*, ltutf8 > {
public:
static VirtualTable* VT;
static StringMap* allocate() {
@@ -269,7 +288,7 @@
};
class TypeMap :
- public LockedMap<const UTF8*, Typedef*, std::less<const UTF8*> > {
+ public LockedMap<const UTF8*, Typedef*, ltutf8 > {
public:
static VirtualTable* VT;
@@ -308,6 +327,8 @@
//lock->markAndTrace();
for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
i->first->markAndTrace();
+ printf("i->second = %p\n", i->second);
+ printf("second again = %p\n", i->second->second);
i->second->second->markAndTrace();
}
}
Added: vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp?rev=48944&view=auto
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp (added)
+++ vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.cpp Sat Mar 29 07:20:27 2008
@@ -0,0 +1,78 @@
+//===------- ServiceDomain.cpp - Service domain description ---------------===//
+//
+// JnJVM
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mvm/JIT.h"
+
+#include "JavaJIT.h"
+#include "JnjvmModuleProvider.h"
+#include "ServiceDomain.h"
+
+extern "C" struct JNINativeInterface JNI_JNIEnvTable;
+extern "C" const struct JNIInvokeInterface JNI_JavaVMTable;
+
+using namespace jnjvm;
+
+void ServiceDomain::destroyer(size_t sz) {
+ mvm::jit::protectEngine->lock();
+ mvm::jit::executionEngine->removeModuleProvider(TheModuleProvider);
+ mvm::jit::protectEngine->unlock();
+ delete TheModuleProvider;
+ delete module;
+}
+
+void ServiceDomain::print(mvm::PrintBuffer* buf) const {
+ buf->write("Service domain: ");
+ buf->write(name);
+}
+
+ServiceDomain* ServiceDomain::allocateService(Jnjvm* callingVM) {
+ ServiceDomain* service = gc_new(ServiceDomain)();
+
+ service->functions = FunctionMap::allocate();
+ service->module = new llvm::Module("Service Domain");
+ service->protectModule = mvm::Lock::allocNormal();
+ service->TheModuleProvider = new JnjvmModuleProvider(service->module,
+ service->functions);
+ JavaJIT::initialiseJITIsolateVM(service);
+
+ service->name = "service";
+ service->jniEnv = &JNI_JNIEnvTable;
+ service->javavmEnv = &JNI_JavaVMTable;
+
+ // We copy so that bootstrap utf8 such as "<init>" are unique
+ service->hashUTF8 = callingVM->hashUTF8->copy();
+ service->hashStr = StringMap::allocate();
+ service->bootstrapClasses = callingVM->bootstrapClasses;
+ service->loadedMethods = MethodMap::allocate();
+ service->loadedFields = FieldMap::allocate();
+ service->javaTypes = jnjvm::TypeMap::allocate();
+ service->globalRefsLock = mvm::Lock::allocNormal();
+ service->statics = StaticInstanceMap::allocate();
+ service->delegatees = DelegateeMap::allocate();
+
+ // A service is related to a class loader
+ // Here are the classes it loaded
+ service->classes = ClassMap::allocate();
+
+ service->started = 0;
+ service->executionTime = 0;
+ service->memoryUsed = 0;
+ service->gcTriggered = 0;
+ service->numThreads = 0;
+
+ service->loadBootstrap();
+ return service;
+}
+
+void ServiceDomain::loadBootstrap() {
+ // load and initialise math since it is responsible for dlopen'ing
+ // libjavalang.so and we are optimizing some math operations
+ loadName(asciizConstructUTF8("java/lang/Math"),
+ CommonClass::jnjvmClassLoader, true, true, true);
+}
Added: vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h?rev=48944&view=auto
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h (added)
+++ vmkit/trunk/lib/JnJVM/VMCore/ServiceDomain.h Sat Mar 29 07:20:27 2008
@@ -0,0 +1,41 @@
+//===--------- ServiceDomain.h - Service domain description ---------------===//
+//
+// JnJVM
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef JNJVM_SERVICE_DOMAIN_H
+#define JNJVM_SERVICE_DOMAIN_H
+
+#include <sys/time.h>
+
+#include "Jnjvm.h"
+
+namespace jnjvm {
+
+class ClassMap;
+
+class ServiceDomain : public Jnjvm {
+public:
+ static VirtualTable* VT;
+
+ virtual void print(mvm::PrintBuffer* buf) const;
+ virtual void tracer(size_t sz);
+ virtual void destroyer(size_t sz);
+ void loadBootstrap();
+ static ServiceDomain* allocateService(Jnjvm* callingVM);
+
+ ClassMap* classes;
+ time_t started;
+ uint64 executionTime;
+ uint64 memoryUsed;
+ uint64 gcTriggered;
+ uint64 numThreads;
+};
+
+} // end namespace jnjvm
+
+#endif //JNJVM_SERVICE_DOMAIN_H
Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=48944&r1=48943&r2=48944&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Sat Mar 29 07:20:27 2008
@@ -22,6 +22,9 @@
#include "Jnjvm.h"
#include "LockedMap.h"
#include "Reader.h"
+#ifdef SERVICE_VM
+#include "ServiceDomain.h"
+#endif
#include "Zip.h"
using namespace jnjvm;
@@ -77,6 +80,9 @@
INIT(CacheNode);
INIT(Enveloppe);
INIT(DelegateeMap);
+#ifdef SERVICE_VM
+ INIT(ServiceDomain);
+#endif
#undef INIT
@@ -297,3 +303,9 @@
ctpInfo->markAndTrace();
//cacheLock->markAndTrace();
}
+
+#ifdef SERVICE_VM
+void ServiceDomain::tracer(size_t sz) {
+ Jnjvm::tracer(sz);
+}
+#endif
More information about the llvm-commits
mailing list