[vmkit-commits] [vmkit] r55472 - in /vmkit/branches/isolate/lib/JnJVM: Isolate/IsolateCommonClass.cpp Isolate/IsolateCommonClass.h LLVMRuntime/runtime-default.ll VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/JavaJITOpcodes.cpp VMCore/Jnjvm.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Aug 28 07:51:36 PDT 2008
Author: geoffray
Date: Thu Aug 28 09:51:33 2008
New Revision: 55472
URL: http://llvm.org/viewvc/llvm-project?rev=55472&view=rev
Log:
Make getClassDelegatee and initialiseClass work for both UserCommonClass
and CommonClass.
Modified:
vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.cpp
vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.h
vmkit/branches/isolate/lib/JnJVM/LLVMRuntime/runtime-default.ll
vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.cpp
vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.h
vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
vmkit/branches/isolate/lib/JnJVM/VMCore/Jnjvm.cpp
Modified: vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.cpp?rev=55472&r1=55471&r2=55472&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.cpp (original)
+++ vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.cpp Thu Aug 28 09:51:33 2008
@@ -14,6 +14,12 @@
using namespace jnjvm;
+UserCommonClass::UserCommonClass() {
+ this->lockVar = mvm::Lock::allocRecursive();
+ this->condVar = mvm::Cond::allocCond();
+ this->status = loaded;
+}
+
UserClass::UserClass(JnjvmClassLoader* JCL, const UTF8* name,
ArrayUInt8* bytes) {
Class* cl = JnjvmSharedLoader::sharedLoader->constructSharedClass(name, bytes);
@@ -47,3 +53,5 @@
classLoader = JCL;
delegatee = 0;
}
+
+
Modified: vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.h?rev=55472&r1=55471&r2=55472&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.h (original)
+++ vmkit/branches/isolate/lib/JnJVM/Isolate/IsolateCommonClass.h Thu Aug 28 09:51:33 2008
@@ -30,13 +30,54 @@
class UserClassArray;
class UserConstantPool;
class UTF8;
+enum JavaState;
class UserCommonClass : public mvm::Object {
public:
- CommonClass* classDef;
+
+ //===----------------------------------------------------------------------===//
+//
+// Do not reorder these fields or add new ones! the LLVM runtime assumes that
+// classes have the following beginning layout.
+//
+//===----------------------------------------------------------------------===//
+
+
+ /// virtualSize - The size of instances of this class. Array classes do
+ /// not need this information, but to simplify accessing this field in
+ /// the JIT, we put this in here.
+ ///
+ uint32 virtualSize;
+
+ /// virtualVT - The virtual table of instances of this class. Like the
+ /// virtualSize field, array classes do not need this information. But we
+ /// simplify JIT generation to set it here.
+ ///
+ VirtualTable* virtualVT;
+
+ /// display - The class hierarchy of supers for this class. Array classes
+ /// do not need it.
+ ///
+ CommonClass** display;
+
+ /// depth - The depth of this class in its class hierarchy.
+ /// display[depth] contains the class. Array classes do not need it.
+ ///
+ uint32 depth;
+
+ /// status - The loading/resolve/initialization state of the class.
+ ///
+ JavaState status;
+
+//===----------------------------------------------------------------------===//
+//
+// New fields can be added from now, or reordered.
+//
+//===----------------------------------------------------------------------===//
+
JnjvmClassLoader* classLoader;
JavaObject* delegatee;
- uint8 status;
+ CommonClass* classDef;
virtual void TRACER;
@@ -66,6 +107,9 @@
UserClass* getSuper();
std::vector<UserClass*>* getInterfaces();
+ CommonClass::field_map* getStaticFields();
+ void resolveStaticClass();
+
JavaMethod* lookupMethodDontThrow(const UTF8* name, const UTF8* type,
bool isStatic, bool recurse);
@@ -97,6 +141,47 @@
UserConstantPool* getCtpCache();
UserClass* lookupClassFromMethod(JavaMethod* meth);
+
+ /// lockVar - When multiple threads want to initialize a class,
+ /// they must be synchronized so that it is only performed once
+ /// for a given class.
+ mvm::Lock* lockVar;
+
+ /// condVar - Used to wake threads waiting on the initialization
+ /// process of this class, done by another thread.
+ mvm::Cond* condVar;
+
+ /// acquire - Acquire this class lock.
+ ///
+ void acquire() {
+ lockVar->lock();
+ }
+
+ /// release - Release this class lock.
+ ///
+ void release() {
+ lockVar->unlock();
+ }
+
+ /// waitClass - Wait for the class to be loaded/initialized/resolved.
+ ///
+ void waitClass() {
+ condVar->wait(lockVar);
+ }
+
+ /// broadcastClass - Unblock threads that were waiting on the class being
+ /// loaded/initialized/resolved.
+ ///
+ void broadcastClass() {
+ condVar->broadcast();
+ }
+
+ /// ownerClass - Is the current thread the owner of this thread?
+ ///
+ bool ownerClass() {
+ return mvm::Lock::selfOwner(lockVar);
+ }
+
};
class UserClass : public UserCommonClass {
@@ -114,6 +199,7 @@
UserClass* getOuterClass();
void resolveInnerOuterClasses();
JavaObject* getStaticInstance();
+ void setStaticInstance(JavaObject* obj);
UserConstantPool* getConstantPool();
void setStaticSize(uint64 size);
Modified: vmkit/branches/isolate/lib/JnJVM/LLVMRuntime/runtime-default.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=55472&r1=55471&r2=55472&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/branches/isolate/lib/JnJVM/LLVMRuntime/runtime-default.ll Thu Aug 28 09:51:33 2008
@@ -5,14 +5,21 @@
;;; A virtual table is an array of function pointers.
%VT = type i32**
+;;; The type of a constant pool. This is only used in a multi vm environment.
+;;; Field 1 - The VT of constant pools.
+;;; Field 2 - The constant pool cache.
+%ConstantPool = type { %VT, i8** }
+
;;; The type of internal classes. This is not complete, but we only need
;;; the first fields for now.
;;; Field 1 - The VT of a class C++ object.
;;; Field 2 - The size of instances of this class.
;;; Field 3 - The VT of instances of this class.
;;; Field 4 - The list of super classes of this class.
-;;; Field 5 - The depth of the class in its super hierarchy
-%JavaClass = type { %VT, i32, %VT ,%JavaClass**, i32}
+;;; Field 5 - The depth of the class in its super hierarchy.
+;;; Field 6 - The class state (resolved, initialized, ...)
+;;; field 7 - The constant pool, only for multi vm environment.
+%JavaClass = type { %VT, i32, %VT ,%JavaClass**, i32, i32, %ConstantPool* }
;;; The root of all Java Objects: a VT, a class and a lock.
%JavaObject = type { %VT, %JavaClass*, i32 }
@@ -30,12 +37,13 @@
%ArrayUInt32 = type { %JavaObject, i32, [0 x i32] }
%ArrayUInt8 = type { %JavaObject, i32, [0 x i8] }
-;;; The CacheNode type. The second field is the last called method
-%CacheNode = type { i8*, %JavaClass*, %CacheNode*, %Enveloppe* }
+;;; The CacheNode type. The second field is the last called method. The
+;;; last field is for multi vm environment.
+%CacheNode = type { i8*, %JavaClass*, %CacheNode*, %Enveloppe*, %ConstantPool* }
;;; The Enveloppe type, which contains the first cache and all the info
;;; to lookup in the constant pool.
-%Enveloppe = type { %CacheNode*, i8*, i8*, i32 }
+%Enveloppe = type { %CacheNode*, %ConstantPool*, i8*, i32 }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; Constant calls for Jnjvm runtime internal objects field accesses ;;;;;;;;;
Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.cpp?rev=55472&r1=55471&r2=55472&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.cpp Thu Aug 28 09:51:33 2008
@@ -697,10 +697,7 @@
acquire();
if (status >= resolved) {
release();
- } else if (status < loaded) {
- release();
- JavaThread::get()->isolate->unknownError("try to resolve a not-read class");
- } else if (status == loaded || ownerClass()) {
+ } else if (status == loaded) {
if (isArray()) {
ClassArray* arrayCl = (ClassArray*)this;
CommonClass* baseClass = arrayCl->baseClass();
@@ -810,3 +807,7 @@
}
}
}
+
+void Class::resolveStaticClass() {
+ classLoader->TheModule->resolveStaticClass((Class*)this);
+}
Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.h?rev=55472&r1=55471&r2=55472&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/JavaClass.h Thu Aug 28 09:51:33 2008
@@ -48,12 +48,13 @@
///
typedef enum JavaState {
loaded = 0, /// The .class file has been found.
- classRead, /// The .class file has been read.
- prepared, /// The parents of this class has been resolved.
- resolved, /// The class has been resolved.
- clinitParent, /// The class is cliniting its parents.
- inClinit, /// The class is cliniting.
- ready /// The class is ready to be used.
+ classRead = 1, /// The .class file has been read.
+ prepared = 2, /// The parents of this class has been resolved.
+ resolved = 3, /// The class has been resolved.
+ clinitParent = 4, /// The class is cliniting its parents.
+ inClinit = 5, /// The class is cliniting.
+ ready = 6, /// The class is ready to be used.
+ dontuseenums = 0xffffffff /// dummy value to force the enum to be int32
}JavaState;
@@ -172,6 +173,9 @@
///
uint32 depth;
+ /// status - The loading/resolve/initialization state of the class.
+ ///
+ JavaState status;
//===----------------------------------------------------------------------===//
//
@@ -183,11 +187,11 @@
uint32 getVirtualSize() {
return virtualSize;
}
-
+
VirtualTable* getVirtualVT() {
return virtualVT;
}
-
+
/// virtualTableSize - The size of the virtual table of this class.
///
uint32 virtualTableSize;
@@ -233,10 +237,6 @@
const UTF8* getName() {
return name;
}
-
- /// status - The loading/resolve/initialization state of the class.
- ///
- JavaState status;
/// super - The parent of this class.
///
@@ -259,7 +259,7 @@
std::vector<const UTF8*> interfacesUTF8;
/// lockVar - When multiple threads want to load/resolve/initialize a class,
- /// they must be synchronized so that these steps are only performned once
+ /// they must be synchronized so that these steps are only performed once
/// for a given class.
mvm::Lock* lockVar;
@@ -306,6 +306,9 @@
///
method_map staticMethods;
+ field_map* getStaticFields() { return &staticFields; }
+ field_map* getVirtualFields() { return &virtualFields; }
+
/// constructMethod - Add a new method in this class method map.
///
JavaMethod* constructMethod(const UTF8* name, const UTF8* type,
@@ -427,6 +430,7 @@
/// initialize it.
///
void initialiseClass(Jnjvm* vm);
+
/// getStatus - Get the resolution/initialization status of this class.
///
@@ -545,12 +549,25 @@
/// staticVT - The virtual table of the static instance of this class.
///
VirtualTable* staticVT;
+
+ uint32 getStaticSize() {
+ return staticSize;
+ }
+
+ VirtualTable* getStaticVT() {
+ return staticVT;
+ }
+
#ifndef MULTIPLE_VM
/// doNew - Allocates a Java object whose class is this class.
///
JavaObject* doNew(Jnjvm* vm);
#endif
+
+ /// resolveStaticClass - Resolve the static type of the class.
+ ///
+ void resolveStaticClass();
/// print - Prints a string representation of this class in the buffer.
///
@@ -573,9 +590,14 @@
///
#ifndef MULTIPLE_VM
JavaObject* _staticInstance;
+
JavaObject* getStaticInstance() {
return _staticInstance;
}
+
+ void setStaticInstance(JavaObject* val) {
+ _staticInstance = val;
+ }
#endif
Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=55472&r1=55471&r2=55472&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Thu Aug 28 09:51:33 2008
@@ -1974,8 +1974,10 @@
case CHECKCAST : {
uint16 index = readU2(bytecodes, i);
+#ifndef MULTIPLE_VM
CommonClass* dcl =
compilingClass->ctpInfo->getMethodClassIfLoaded(index);
+#endif
Value* obj = top();
@@ -1989,12 +1991,14 @@
BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
currentBlock = ifFalse;
Value* clVar = 0;
+#ifndef MULTIPLE_VM
if (dcl) {
LLVMCommonClassInfo* LCI = module->getClassInfo(dcl);
clVar = LCI->getVar(this);
- } else {
+ } else
+#endif
clVar = getResolvedClass(index, false);
- }
+
std::vector<Value*> args;
args.push_back(obj);
args.push_back(clVar);
Modified: vmkit/branches/isolate/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/isolate/lib/JnJVM/VMCore/Jnjvm.cpp?rev=55472&r1=55471&r2=55472&view=diff
==============================================================================
--- vmkit/branches/isolate/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/branches/isolate/lib/JnJVM/VMCore/Jnjvm.cpp Thu Aug 28 09:51:33 2008
@@ -87,8 +87,7 @@
typedef void (*clinit_t)(Jnjvm* vm);
-#ifndef MULTIPLE_VM
-void CommonClass::initialiseClass(Jnjvm* vm) {
+void UserCommonClass::initialiseClass(Jnjvm* vm) {
// Primitives are initialized at boot time
if (isArray()) {
status = ready;
@@ -98,14 +97,15 @@
release();
} else if (status >= resolved && status != clinitParent &&
status != inClinit) {
- Class* cl = (Class*)this;
+ UserClass* cl = (UserClass*)this;
status = clinitParent;
release();
+ UserCommonClass* super = getSuper();
if (super) {
super->initialiseClass(vm);
}
-
- classLoader->TheModule->resolveStaticClass((Class*)this);
+
+ cl->resolveStaticClass();
status = inClinit;
JavaMethod* meth = lookupMethodDontThrow(Jnjvm::clinitName,
@@ -117,14 +117,16 @@
PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "%s\n", printString());
JavaObject* val =
- (JavaObject*)vm->allocator.allocateObject(cl->staticSize, cl->staticVT);
+ (JavaObject*)vm->allocator.allocateObject(cl->getStaticSize(),
+ cl->getStaticVT());
val->initialise(cl);
- for (CommonClass::field_iterator i = cl->staticFields.begin(),
- e = cl->staticFields.end(); i!= e; ++i) {
+ CommonClass::field_map* map = cl->getStaticFields();
+ for (CommonClass::field_iterator i = map->begin(), e = map->end(); i!= e;
+ ++i) {
i->second->initField(val);
}
- cl->_staticInstance = val;
+ cl->setStaticInstance(val);
if (meth) {
JavaObject* exc = 0;
@@ -160,7 +162,6 @@
}
}
}
-#endif
void Jnjvm::errorWithExcp(UserClass* cl, JavaMethod* init, const JavaObject* excp) {
@@ -329,8 +330,7 @@
postProperties.push_back(std::make_pair(key, value));
}
-#ifndef MULTIPLE_VM
-JavaObject* CommonClass::getClassDelegatee(Jnjvm* vm, JavaObject* pd) {
+JavaObject* UserCommonClass::getClassDelegatee(Jnjvm* vm, JavaObject* pd) {
acquire();
if (!(delegatee)) {
UserClass* cl = vm->upcalls->newClass;
@@ -347,7 +347,6 @@
release();
return delegatee;
}
-#endif
Jnjvm::~Jnjvm() {
#ifdef MULTIPLE_GC
More information about the vmkit-commits
mailing list