[llvm-commits] [vmkit] r51373 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMClass.cpp VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/JavaInitialise.cpp VMCore/JavaIsolate.cpp VMCore/JavaUpcalls.cpp VMCore/JavaUpcalls.h VMCore/Jnjvm.cpp VMCore/Jnjvm.h VMCore/JnjvmModule.cpp VMCore/JnjvmModule.h VMCore/LockedMap.h VMCore/VirtualTables.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Wed May 21 07:40:12 PDT 2008
Author: geoffray
Date: Wed May 21 09:40:12 2008
New Revision: 51373
URL: http://llvm.org/viewvc/llvm-project?rev=51373&view=rev
Log:
Methods and fields are now hashed in Class.
Modified:
vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp
vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h
vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClass.cpp Wed May 21 09:40:12 2008
@@ -83,12 +83,13 @@
if (cl->isArray || isInterface(cl->access)) {
return (jobject)ArrayObject::acons(0, Classpath::constructorArrayClass, vm);
} else {
- std::vector<JavaMethod*> meths = cl->virtualMethods;
+ CommonClass::method_map meths = cl->virtualMethods;
std::vector<JavaMethod*> res;
- for (std::vector<JavaMethod*>::iterator i = meths.begin(), e = meths.end();
+ for (CommonClass::method_iterator i = meths.begin(), e = meths.end();
i != e; ++i) {
- if ((*i)->name == Jnjvm::initName && (!publicOnly || isPublic((*i)->access))) {
- res.push_back(*i);
+ JavaMethod* meth = i->second;
+ if (meth->name == Jnjvm::initName && (!publicOnly || isPublic(meth->access))) {
+ res.push_back(meth);
}
}
@@ -121,19 +122,21 @@
if (cl->isArray) {
return (jobject)ArrayObject::acons(0, Classpath::methodArrayClass, vm);
} else {
- std::vector<JavaMethod*> meths = cl->virtualMethods;
+ CommonClass::method_map meths = cl->virtualMethods;
std::vector<JavaMethod*> res;
- for (std::vector<JavaMethod*>::iterator i = meths.begin(), e = meths.end();
+ for (CommonClass::method_iterator i = meths.begin(), e = meths.end();
i != e; ++i) {
- if ((*i)->name != Jnjvm::initName && (!publicOnly || isPublic((*i)->access))) {
- res.push_back(*i);
+ JavaMethod* meth = i->second;
+ if (meth->name != Jnjvm::initName && (!publicOnly || isPublic(meth->access))) {
+ res.push_back(meth);
}
}
meths = cl->staticMethods;
- for (std::vector<JavaMethod*>::iterator i = meths.begin(), e = meths.end();
+ for (CommonClass::method_iterator i = meths.begin(), e = meths.end();
i != e; ++i) {
- if ((*i)->name != Jnjvm::clinitName && (!publicOnly || isPublic((*i)->access))) {
- res.push_back(*i);
+ JavaMethod* meth = i->second;
+ if (meth->name != Jnjvm::clinitName && (!publicOnly || isPublic(meth->access))) {
+ res.push_back(meth);
}
}
@@ -299,19 +302,21 @@
if (cl->isArray) {
return (jobject)ArrayObject::acons(0, Classpath::fieldArrayClass, vm);
} else {
- std::vector<JavaField*> fields = cl->virtualFields;
+ CommonClass::field_map fields = cl->virtualFields;
std::vector<JavaField*> res;
- for (std::vector<JavaField*>::iterator i = fields.begin(), e = fields.end();
+ for (CommonClass::field_iterator i = fields.begin(), e = fields.end();
i != e; ++i) {
- if (!publicOnly || isPublic((*i)->access)) {
- res.push_back(*i);
+ JavaField* field = i->second;
+ if (!publicOnly || isPublic(field->access)) {
+ res.push_back(field);
}
}
fields = cl->staticFields;
- for (std::vector<JavaField*>::iterator i = fields.begin(), e = fields.end();
+ for (CommonClass::field_iterator i = fields.begin(), e = fields.end();
i != e; ++i) {
- if (!publicOnly || isPublic((*i)->access)) {
- res.push_back(*i);
+ JavaField* field = i->second;
+ if (!publicOnly || isPublic(field->access)) {
+ res.push_back(field);
}
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Wed May 21 09:40:12 2008
@@ -40,10 +40,6 @@
CommonClass* ClassArray::SuperArray = 0;
std::vector<Class*> ClassArray::InterfacesArray;
-std::vector<JavaMethod*> ClassArray::VirtualMethodsArray;
-std::vector<JavaMethod*> ClassArray::StaticMethodsArray;
-std::vector<JavaField*> ClassArray::VirtualFieldsArray;
-std::vector<JavaField*> ClassArray::StaticFieldsArray;
void Attribut::derive(const UTF8* name, unsigned int length,
const Reader* reader) {
@@ -230,20 +226,14 @@
const UTF8* type, bool isStatic,
bool recurse) {
- std::vector<JavaMethod*>* meths = (isStatic? &staticMethods :
- &virtualMethods);
+ FieldCmp CC(name, type);
+ method_map& map = isStatic ? staticMethods : virtualMethods;
+ method_iterator End = map.end();
+ method_iterator I = map.find(CC);
+ if (I != End) return I->second;
JavaMethod *cur = 0;
- for (std::vector<JavaMethod*>::iterator i = meths->begin(),
- e = meths->end(); i!= e; i++) {
- cur = *i;
- if (cur->name->equals(name) && cur->type->equals(type)) {
- return cur;
- }
- }
- cur = 0;
-
if (recurse) {
if (super) cur = super->lookupMethodDontThrow(name, type, isStatic,
recurse);
@@ -275,20 +265,14 @@
const UTF8* type, bool isStatic,
bool recurse) {
- std::vector<JavaField*>* fields = (isStatic? &staticFields : &virtualFields);
+ FieldCmp CC(name, type);
+ field_map& map = isStatic ? staticFields : virtualFields;
+ field_iterator End = map.end();
+ field_iterator I = map.find(CC);
+ if (I != End) return I->second;
JavaField *cur = 0;
- for (std::vector<JavaField*>::iterator i = fields->begin(),
- e = fields->end(); i!= e; i++) {
- cur = *i;
- if (cur->name->equals(name) && cur->type->equals(type)) {
- return cur;
- }
- }
-
- cur = 0;
-
if (recurse) {
if (super) cur = super->lookupFieldDontThrow(name, type, isStatic,
recurse);
@@ -504,3 +488,46 @@
}
}
#endif
+
+
+JavaMethod* CommonClass::constructMethod(const UTF8* name,
+ const UTF8* type, uint32 access) {
+ method_map& map = isStatic(access) ? staticMethods : virtualMethods;
+ FieldCmp CC(name, type);
+ method_iterator End = map.end();
+ method_iterator I = map.find(CC);
+ if (I == End) {
+ JavaMethod* method = vm_new(isolate, JavaMethod)();
+ method->name = name;
+ method->type = type;
+ method->classDef = (Class*)this;
+ method->signature = (Signdef*)isolate->constructType(type);
+ method->code = 0;
+ method->access = access;
+ map.insert(std::make_pair(CC, method));
+ return method;
+ } else {
+ return I->second;
+ }
+}
+
+JavaField* CommonClass::constructField(const UTF8* name,
+ const UTF8* type, uint32 access) {
+ field_map& map = isStatic(access) ? staticFields : virtualFields;
+ FieldCmp CC(name, type);
+ field_iterator End = map.end();
+ field_iterator I = map.find(CC);
+ if (I == End) {
+ JavaField* field = vm_new(isolate, JavaField)();
+ field->name = name;
+ field->type = type;
+ field->classDef = (Class*)this;
+ field->signature = isolate->constructType(type);
+ field->ptrOffset = 0;
+ field->access = access;
+ map.insert(std::make_pair(CC, field));
+ return field;
+ } else {
+ return I->second;
+ }
+}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Wed May 21 09:40:12 2008
@@ -10,6 +10,7 @@
#ifndef JNJVM_JAVA_CLASS_H
#define JNJVM_JAVA_CLASS_H
+#include <map>
#include <vector>
#include "types.h"
@@ -63,7 +64,24 @@
};
+
class CommonClass : public mvm::Object {
+private:
+
+class FieldCmp {
+public:
+ const UTF8* name;
+ const UTF8* type;
+
+ FieldCmp(const UTF8* n, const UTF8* t) : name(n), type(t) {}
+
+ inline bool operator<(const FieldCmp &cmp) const {
+ if (name < cmp.name) return true;
+ else if (name > cmp.name) return false;
+ else return type < cmp.type;
+ }
+};
+
public:
/// virtualSize - The size of instances of this class.
@@ -133,21 +151,38 @@
JavaObject* delegatee;
#endif
- /// virtualMethods - List of all the virtual methods defined by this class.
- /// This does not contain non-redefined super methods.
- std::vector<JavaMethod*> virtualMethods;
-
- /// staticMethods - List of all the static methods defined by this class.
- ///
- std::vector<JavaMethod*> staticMethods;
+ typedef std::map<const FieldCmp, JavaField*, std::less<FieldCmp>,
+ gc_allocator<std::pair<const FieldCmp, JavaField*> > >::iterator
+ field_iterator;
+
+ typedef std::map<const FieldCmp, JavaField*, std::less<FieldCmp>,
+ gc_allocator<std::pair<const FieldCmp, JavaField*> > >
+ field_map;
+
/// virtualFields - List of all the virtual fields defined in this class.
/// This does not contain non-redefined super fields.
- std::vector<JavaField*> virtualFields;
-
+ field_map virtualFields;
+
/// staticFields - List of all the static fields defined in this class.
///
- std::vector<JavaField*> staticFields;
+ field_map staticFields;
+
+ typedef std::map<const FieldCmp, JavaMethod*, std::less<FieldCmp>,
+ gc_allocator<std::pair<const FieldCmp, JavaMethod*> > >::iterator
+ method_iterator;
+
+ typedef std::map<const FieldCmp, JavaMethod*, std::less<FieldCmp>,
+ gc_allocator<std::pair<const FieldCmp, JavaMethod*> > >
+ method_map;
+
+ /// virtualMethods - List of all the virtual methods defined by this class.
+ /// This does not contain non-redefined super methods.
+ method_map virtualMethods;
+
+ /// staticMethods - List of all the static methods defined by this class.
+ ///
+ method_map staticMethods;
/// display - The class hierarchy of supers for this class.
///
@@ -157,6 +192,12 @@
/// display[depth - 1] contains the class.
uint32 depth;
+ JavaMethod* constructMethod(const UTF8* name, const UTF8* type,
+ uint32 access);
+
+ JavaField* constructField(const UTF8* name, const UTF8* type,
+ uint32 access);
+
static void printClassName(const UTF8* name, mvm::PrintBuffer* buf);
void initialise(Jnjvm* isolate, bool array);
@@ -297,10 +338,6 @@
static CommonClass* SuperArray;
static std::vector<Class*> InterfacesArray;
- static std::vector<JavaMethod*> VirtualMethodsArray;
- static std::vector<JavaMethod*> StaticMethodsArray;
- static std::vector<JavaField*> VirtualFieldsArray;
- static std::vector<JavaField*> StaticFieldsArray;
};
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Wed May 21 09:40:12 2008
@@ -63,8 +63,6 @@
INIT(ZipArchive);
INIT(UTF8Map);
INIT(ClassMap);
- INIT(FieldMap);
- INIT(MethodMap);
INIT(ZipFileMap);
INIT(StringMap);
INIT(jnjvm::TypeMap);
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaIsolate.cpp Wed May 21 09:40:12 2008
@@ -478,8 +478,6 @@
bootstrapVM->hashUTF8->copy(isolate->hashUTF8);
isolate->hashStr = vm_new(isolate, StringMap)();
isolate->bootstrapClasses = callingVM->bootstrapClasses;
- isolate->loadedMethods = vm_new(isolate, MethodMap)();
- isolate->loadedFields = vm_new(isolate, FieldMap)();
isolate->javaTypes = vm_new(isolate, TypeMap)();
isolate->globalRefsLock = mvm::Lock::allocNormal();
#ifdef MULTIPLE_VM
@@ -532,8 +530,6 @@
isolate->hashUTF8 = vm_new(isolate, UTF8Map)();
isolate->hashStr = vm_new(isolate, StringMap)();
isolate->bootstrapClasses = vm_new(isolate, ClassMap)();
- isolate->loadedMethods = vm_new(isolate, MethodMap)();
- isolate->loadedFields = vm_new(isolate, FieldMap)();
isolate->jniEnv = &JNI_JNIEnvTable;
isolate->javavmEnv = &JNI_JavaVMTable;
isolate->globalRefsLock = mvm::Lock::allocNormal();
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Wed May 21 09:40:12 2008
@@ -23,14 +23,14 @@
#include "JnjvmModule.h"
#define COMPILE_METHODS(cl) \
- for (std::vector<JavaMethod*>::iterator i = cl->virtualMethods.begin(), \
+ for (CommonClass::method_iterator i = cl->virtualMethods.begin(), \
e = cl->virtualMethods.end(); i!= e; ++i) { \
- (*i)->compiledPtr(); \
+ i->second->compiledPtr(); \
} \
\
- for (std::vector<JavaMethod*>::iterator i = cl->staticMethods.begin(), \
+ for (CommonClass::method_iterator i = cl->staticMethods.begin(), \
e = cl->staticMethods.end(); i!= e; ++i) { \
- (*i)->compiledPtr(); \
+ i->second->compiledPtr(); \
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h Wed May 21 09:40:12 2008
@@ -16,12 +16,12 @@
CommonClass::jnjvmClassLoader)
#define UPCALL_FIELD(vm, cl, name, type, acc) \
- vm->constructField(UPCALL_CLASS(vm, cl), vm->asciizConstructUTF8(name), \
- vm->asciizConstructUTF8(type), acc)
+ UPCALL_CLASS(vm, cl)->constructField(vm->asciizConstructUTF8(name), \
+ vm->asciizConstructUTF8(type), acc)
#define UPCALL_METHOD(vm, cl, name, type, acc) \
- vm->constructMethod(UPCALL_CLASS(vm, cl), vm->asciizConstructUTF8(name), \
- vm->asciizConstructUTF8(type), acc)
+ UPCALL_CLASS(vm, cl)->constructMethod(vm->asciizConstructUTF8(name), \
+ vm->asciizConstructUTF8(type), acc)
#define UPCALL_ARRAY_CLASS(vm, name, depth) \
vm->constructArray( \
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Wed May 21 09:40:12 2008
@@ -216,17 +216,17 @@
void Jnjvm::readFields(Class* cl, Reader* reader) {
unsigned short int nbFields = reader->readU2();
JavaCtpInfo* ctpInfo = cl->ctpInfo;
+ uint32 sindex = 0;
+ uint32 vindex = 0;
for (int i = 0; i < nbFields; i++) {
- unsigned short int access = reader->readU2();
+ uint16 access = reader->readU2();
const UTF8* name = ctpInfo->UTF8At(reader->readU2());
const UTF8* type = ctpInfo->UTF8At(reader->readU2());
- JavaField* field = constructField(cl, name, type, access);
+ JavaField* field = cl->constructField(name, type, access);
+ isStatic(access) ?
+ field->num = sindex++ :
+ field->num = vindex++;
readAttributs(cl, reader, field->attributs);
- if (isStatic(access)) {
- cl->staticFields.push_back(field);
- } else {
- cl->virtualFields.push_back(field);
- }
}
}
@@ -234,17 +234,12 @@
unsigned short int nbMethods = reader->readU2();
JavaCtpInfo* ctpInfo = cl->ctpInfo;
for (int i = 0; i < nbMethods; i++) {
- unsigned short int access = reader->readU2();
+ uint16 access = reader->readU2();
const UTF8* name = ctpInfo->UTF8At(reader->readU2());
const UTF8* type = ctpInfo->UTF8At(reader->readU2());
- JavaMethod* meth = constructMethod(cl, name, type, access);
+ JavaMethod* meth = cl->constructMethod(name, type, access);
readAttributs(cl, reader, meth->attributs);
- if (isStatic(access)) {
- cl->staticMethods.push_back(meth);
- } else {
- cl->virtualMethods.push_back(meth);
- }
- }
+ }
}
void Jnjvm::readClass(Class* cl) {
@@ -670,10 +665,6 @@
cl->_baseClass = 0;
cl->super = ClassArray::SuperArray;
cl->interfaces = ClassArray::InterfacesArray;
- cl->virtualMethods = ClassArray::VirtualMethodsArray;
- cl->staticMethods = ClassArray::StaticMethodsArray;
- cl->virtualFields = ClassArray::VirtualFieldsArray;
- cl->staticFields = ClassArray::StaticFieldsArray;
cl->depth = 1;
cl->display.push_back(ClassArray::SuperArray);
cl->display.push_back(cl);
@@ -756,49 +747,6 @@
}
}
-static JavaField* fieldDup(FieldCmp & cmp, Jnjvm *vm) {
- JavaField* field = vm_new(vm, JavaField)();
- field->name = cmp.name;
- field->type = cmp.type;
- field->classDef = (Class*)cmp.classDef;
- field->signature = vm->constructType(field->type);
- field->ptrOffset = 0;
- return field;
-}
-
-JavaField* Jnjvm::constructField(Class* cl, const UTF8* name, const UTF8* type,
- uint32 access){
- FieldCmp CC(name, cl, type, 0);
- JavaField* f = loadedFields->lookupOrCreate(CC, this, fieldDup);
- f->access = access;
- return f;
-}
-
-JavaField* Jnjvm::lookupField(CommonClass* cl, const UTF8* name,
- const UTF8* type) {
- FieldCmp CC(name, cl, type, 0);
- JavaField* f = loadedFields->lookup(CC);
- return f;
-}
-
-static JavaMethod* methodDup(FieldCmp & cmp, Jnjvm *vm) {
- JavaMethod* method = vm_new(vm, JavaMethod)();
- method->name = cmp.name;
- method->type = cmp.type;
- method->classDef = (Class*)cmp.classDef;
- method->signature = (Signdef*)vm->constructType(method->type);
- method->code = 0;
- method->access = cmp.access;
- return method;
-}
-
-JavaMethod* Jnjvm::constructMethod(Class* cl, const UTF8* name,
- const UTF8* type, uint32 access) {
- FieldCmp CC(name, cl, type, access);
- JavaMethod* f = loadedMethods->lookupOrCreate(CC, this, methodDup);
- return f;
-}
-
const UTF8* Jnjvm::asciizConstructUTF8(const char* asciiz) {
return hashUTF8->lookupOrCreateAsciiz(this, asciiz);
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Wed May 21 09:40:12 2008
@@ -202,14 +202,9 @@
ArrayUInt8* openName(const UTF8* utf8);
CommonClass* lookupClass(const UTF8* utf8, JavaObject* loader);
- JavaField* lookupField(CommonClass* cl, const UTF8* name, const UTF8* type);
ClassArray* constructArray(const UTF8* name, JavaObject* loader);
Class* constructClass(const UTF8* name, JavaObject* loader);
- JavaField* constructField(Class* cl, const UTF8* name, const UTF8* type,
- uint32 access);
- JavaMethod* constructMethod(Class* cl, const UTF8* name, const UTF8* type,
- uint32 access);
const UTF8* asciizConstructUTF8(const char* asciiz);
const UTF8* readerConstructUTF8(const uint16* buf, uint32 len);
JavaString* asciizToStr(const char* asciiz);
@@ -249,8 +244,6 @@
UTF8Map * hashUTF8;
StringMap * hashStr;
ClassMap* bootstrapClasses;
- MethodMap* loadedMethods;
- FieldMap* loadedFields;
TypeMap* javaTypes;
#ifdef MULTIPLE_VM
StaticInstanceMap* statics;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Wed May 21 09:40:12 2008
@@ -161,7 +161,7 @@
#ifndef WITHOUT_VTABLE
VirtualTable* JnjvmModule::allocateVT(Class* cl,
- std::vector<JavaMethod*>::iterator meths) {
+ CommonClass::method_iterator meths) {
if (meths == cl->virtualMethods.end()) {
uint64 size = cl->virtualTableSize;
VirtualTable* VT = (VirtualTable*)malloc(size * sizeof(void*));
@@ -173,7 +173,7 @@
}
return VT;
} else {
- JavaMethod* meth = *meths;
+ JavaMethod* meth = meths->second;
JavaMethod* parent = cl->super?
cl->super->lookupMethodDontThrow(meth->name, meth->type, false, true) : 0;
@@ -185,7 +185,7 @@
offset = parent->offset;
meth->offset = parent->offset;
}
- VirtualTable* VT = allocateVT(cl, meths + 1);
+ VirtualTable* VT = allocateVT(cl, ++meths);
LLVMMethodInfo* LMI = getMethodInfo(meth);
Function* func = LMI->getMethod();
ExecutionEngine* EE = mvm::jit::executionEngine;
@@ -235,7 +235,7 @@
#ifdef WITH_TRACER
LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl);
const Type* type = stat ? LCI->getStaticType() : LCI->getVirtualType();
- std::vector<JavaField*> &fields = stat ? cl->staticFields : cl->virtualFields;
+ CommonClass::field_map fields = stat ? cl->staticFields : cl->virtualFields;
Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
GlobalValue::ExternalLinkage,
@@ -268,10 +268,10 @@
}
#endif
- for (std::vector<JavaField*>::iterator i = fields.begin(),
- e = fields.end(); i!= e; ++i) {
- if ((*i)->signature->funcs->doTrace) {
- LLVMFieldInfo* LFI = getFieldInfo(*i);
+ for (CommonClass::field_iterator i = fields.begin(), e = fields.end();
+ i!= e; ++i) {
+ if (i->second->signature->funcs->doTrace) {
+ LLVMFieldInfo* LFI = getFieldInfo(i->second);
std::vector<Value*> args; //size = 2
args.push_back(zero);
args.push_back(LFI->getOffset());
@@ -312,6 +312,8 @@
const Type* LLVMClassInfo::getVirtualType() {
if (!virtualType) {
std::vector<const llvm::Type*> fields;
+ JavaField* array[classDef->virtualFields.size()];
+
if (classDef->super) {
LLVMClassInfo* CLI =
(LLVMClassInfo*)module->getClassInfo(classDef->super);
@@ -320,13 +322,17 @@
fields.push_back(JnjvmModule::JavaObjectType->getContainedType(0));
}
- uint32 index = 0;
- for (std::vector<JavaField*>::iterator i = classDef->virtualFields.begin(),
+ for (CommonClass::field_iterator i = classDef->virtualFields.begin(),
e = classDef->virtualFields.end(); i!= e; ++i) {
- uint8 id = (*i)->signature->funcs->numId;
+ JavaField* field = i->second;
+ array[field->num] = field;
+ }
+
+
+ for (uint32 index = 0; index < classDef->virtualFields.size(); ++index) {
+ uint8 id = array[index]->signature->funcs->numId;
LLVMAssessorInfo& LAI = LLVMAssessorInfo::AssessorInfo[id];
fields.push_back(LAI.llvmType);
- (*i)->num = index++;
}
StructType* structType = StructType::get(fields, false);
@@ -334,9 +340,10 @@
const TargetData* targetData = mvm::jit::executionEngine->getTargetData();
const StructLayout* sl = targetData->getStructLayout(structType);
- for (std::vector<JavaField*>::iterator i = classDef->virtualFields.begin(),
+ for (CommonClass::field_iterator i = classDef->virtualFields.begin(),
e = classDef->virtualFields.end(); i!= e; ++i) {
- (*i)->ptrOffset = sl->getElementOffset((*i)->num + 1);
+ JavaField* field = i->second;
+ field->ptrOffset = sl->getElementOffset(field->num + 1);
}
VirtualTable* VT = module->makeVT((Class*)classDef, false);
@@ -356,15 +363,20 @@
if (!staticType) {
Class* cl = (Class*)classDef;
std::vector<const llvm::Type*> fields;
+ JavaField* array[classDef->staticFields.size() + 1];
fields.push_back(JnjvmModule::JavaObjectType->getContainedType(0));
- uint32 index = 0;
- for (std::vector<JavaField*>::iterator i = classDef->staticFields.begin(),
- e = classDef->staticFields.end(); i!= e; ++i) {
- uint8 id = (*i)->signature->funcs->numId;
+ for (CommonClass::field_iterator i = classDef->staticFields.begin(),
+ e = classDef->staticFields.end(); i!= e; ++i) {
+ JavaField* field = i->second;
+ array[field->num] = field;
+ }
+
+ for (uint32 index = 0; index < classDef->staticFields.size(); ++index) {
+ JavaField* field = array[index];
+ uint8 id = field->signature->funcs->numId;
LLVMAssessorInfo& LAI = LLVMAssessorInfo::AssessorInfo[id];
fields.push_back(LAI.llvmType);
- (*i)->num = index++;
}
StructType* structType = StructType::get(fields, false);
@@ -372,9 +384,10 @@
const TargetData* targetData = mvm::jit::executionEngine->getTargetData();
const StructLayout* sl = targetData->getStructLayout(structType);
- for (std::vector<JavaField*>::iterator i = classDef->staticFields.begin(),
+ for (CommonClass::field_iterator i = classDef->staticFields.begin(),
e = classDef->staticFields.end(); i!= e; ++i) {
- (*i)->ptrOffset = sl->getElementOffset((*i)->num + 1);
+ JavaField* field = i->second;
+ field->ptrOffset = sl->getElementOffset(field->num + 1);
}
@@ -389,10 +402,10 @@
(JavaObject*)classDef->isolate->allocateObject(cl->staticSize,
cl->staticVT);
val->initialise(classDef);
- for (std::vector<JavaField*>::iterator i = cl->staticFields.begin(),
+ for (CommonClass::field_iterator i = cl->staticFields.begin(),
e = cl->staticFields.end(); i!= e; ++i) {
- (*i)->initField(val);
+ i->second->initField(val);
}
cl->_staticInstance = val;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h Wed May 21 09:40:12 2008
@@ -20,6 +20,8 @@
#include "llvm/Type.h"
#include "llvm/Value.h"
+#include "JavaClass.h"
+
namespace jnjvm {
class CommonClass;
@@ -248,7 +250,7 @@
field_iterator;
VirtualTable* makeVT(Class* cl, bool stat);
- VirtualTable* allocateVT(Class* cl, std::vector<JavaMethod*>::iterator meths);
+ VirtualTable* allocateVT(Class* cl, CommonClass::method_iterator meths);
public:
Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h Wed May 21 09:40:12 2008
@@ -134,25 +134,6 @@
void insert(const UTF8* val);
};
-class FieldCmp {
-public:
- const UTF8* name;
- CommonClass* classDef;
- const UTF8* type;
- uint32_t access;
-
- FieldCmp(const UTF8* n, CommonClass* c, const UTF8* t, uint32 a) : name(n), classDef(c),
- type(t), access(a) {}
-
- inline bool operator<(const FieldCmp &cmp) const {
- if (name < cmp.name) return true;
- else if (name > cmp.name) return false;
- else if (classDef < cmp.classDef) return true;
- else if (classDef > cmp.classDef) return false;
- else return type < cmp.type;
- }
-};
-
class ClassMap :
public LockedMap<const UTF8*, CommonClass*, ltutf8 > {
public:
@@ -165,30 +146,6 @@
virtual void TRACER;
};
-class FieldMap :
- public LockedMap<FieldCmp, JavaField*, std::less<FieldCmp> > {
-public:
- static VirtualTable* VT;
-
- FieldMap() {
- lock = mvm::Lock::allocNormal();
- }
-
- virtual void TRACER;
-};
-
-class MethodMap :
- public LockedMap<FieldCmp, JavaMethod*, std::less<FieldCmp> > {
-public:
- static VirtualTable* VT;
-
- MethodMap() {
- lock = mvm::Lock::allocNormal();
- }
-
- virtual void TRACER;
-};
-
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=51373&r1=51372&r2=51373&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Wed May 21 09:40:12 2008
@@ -62,8 +62,6 @@
INIT(ZipArchive);
INIT(UTF8Map);
INIT(ClassMap);
- INIT(FieldMap);
- INIT(MethodMap);
INIT(ZipFileMap);
INIT(StringMap);
INIT(TypeMap);
@@ -122,6 +120,27 @@
#ifndef MULTIPLE_VM
delegatee->MARK_AND_TRACE;
#endif
+
+ for (field_iterator i = virtualFields.begin(), e = virtualFields.end();
+ i!= e; ++i) {
+ i->second->MARK_AND_TRACE;
+ }
+
+ for (field_iterator i = staticFields.begin(), e = staticFields.end();
+ i!= e; ++i) {
+ i->second->MARK_AND_TRACE;
+ }
+
+ for (method_iterator i = staticMethods.begin(), e = staticMethods.end();
+ i!= e; ++i) {
+ i->second->MARK_AND_TRACE;
+ }
+
+ for (method_iterator i = virtualMethods.begin(), e = virtualMethods.end();
+ i!= e; ++i) {
+ i->second->MARK_AND_TRACE;
+ }
+
}
void Class::TRACER {
@@ -204,8 +223,6 @@
hashUTF8->MARK_AND_TRACE;
hashStr->MARK_AND_TRACE;
bootstrapClasses->MARK_AND_TRACE;
- loadedMethods->MARK_AND_TRACE;
- loadedFields->MARK_AND_TRACE;
javaTypes->MARK_AND_TRACE;
TRACE_VECTOR(JavaObject*, gc_allocator, globalRefs);
#ifdef MULTIPLE_VM
@@ -259,19 +276,6 @@
}
}
-void FieldMap::TRACER {
- for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
- i->second->MARK_AND_TRACE;
- }
-}
-
-
-void MethodMap::TRACER {
- for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
- i->second->MARK_AND_TRACE;
- }
-}
-
void ZipFileMap::TRACER {
for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
i->second->MARK_AND_TRACE;
More information about the llvm-commits
mailing list