[vmkit-commits] [vmkit] r70845 - in /vmkit/trunk: include/jnjvm/ include/mvm/ include/mvm/GC/ lib/JnJVM/Compiler/ lib/JnJVM/VMCore/ lib/Mvm/Runtime/ tools/jnjvm/ tools/n3-mono/ tools/n3-pnetlib/ tools/vmjc/ tools/vmkit/
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Mon May 4 02:19:57 PDT 2009
Author: geoffray
Date: Mon May 4 04:19:42 2009
New Revision: 70845
URL: http://llvm.org/viewvc/llvm-project?rev=70845&view=rev
Log:
Backport patches from revision 70207.
Modified:
vmkit/trunk/include/jnjvm/JnjvmModule.h
vmkit/trunk/include/mvm/GC/GC.h
vmkit/trunk/include/mvm/Object.h
vmkit/trunk/include/mvm/PrintBuffer.h
vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp
vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp
vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.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/JavaObject.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h
vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
vmkit/trunk/lib/Mvm/Runtime/Object.cpp
vmkit/trunk/tools/jnjvm/Main.cpp
vmkit/trunk/tools/n3-mono/Main.cpp
vmkit/trunk/tools/n3-pnetlib/Main.cpp
vmkit/trunk/tools/vmjc/vmjc.cpp
vmkit/trunk/tools/vmkit/Launcher.cpp
Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Mon May 4 04:19:42 2009
@@ -234,6 +234,7 @@
#ifdef WITH_TRACER
llvm::Function* MarkAndTraceFunction;
static const llvm::FunctionType* MarkAndTraceType;
+ llvm::Function* EmptyTracerFunction;
llvm::Function* JavaObjectTracerFunction;
llvm::Function* JavaArrayTracerFunction;
llvm::Function* ArrayObjectTracerFunction;
@@ -358,9 +359,7 @@
#ifdef WITH_TRACER
llvm::Function* internalMakeTracer(Class* cl, bool stat);
- virtual llvm::Function* makeTracer(Class* cl, bool stat) {
- return internalMakeTracer(cl, stat);
- }
+ virtual llvm::Function* makeTracer(Class* cl, bool stat) = 0;
#endif
void addJavaPasses();
@@ -502,6 +501,10 @@
#ifdef SERVICE
virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where);
#endif
+
+#ifdef WITH_TRACER
+ virtual llvm::Function* makeTracer(Class* cl, bool stat);
+#endif
virtual ~JavaJITCompiler() {}
Modified: vmkit/trunk/include/mvm/GC/GC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/GC/GC.h (original)
+++ vmkit/trunk/include/mvm/GC/GC.h Mon May 4 04:19:42 2009
@@ -23,6 +23,16 @@
uintptr_t* getFunctions() {
return &destructor;
}
+
+ VirtualTable(uintptr_t d, uintptr_t o, uintptr_t t) {
+ destructor = d;
+ operatorDelete = o;
+ tracer = t;
+ }
+
+ VirtualTable() {}
+
+ static void emptyTracer(void*) {}
};
class gcRoot {
@@ -54,7 +64,10 @@
VirtualTable *_XXX_vt;
inline gcRoot *_2gc() { return (gcRoot *)this; }
destructor_t getDestructor() {
- return ((destructor_t*)(this->_XXX_vt))[0];
+ return (destructor_t)this->_XXX_vt->destructor;
+ }
+ destructor_t getDelete() {
+ return (destructor_t)this->_XXX_vt->operatorDelete;
}
};
Modified: vmkit/trunk/include/mvm/Object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Object.h?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Object.h (original)
+++ vmkit/trunk/include/mvm/Object.h Mon May 4 04:19:42 2009
@@ -50,12 +50,6 @@
///
virtual intptr_t hashCode(){ return (intptr_t)this;}
- /// initialise - All virtual machines must call Object::initialise to
- /// property initialise the PrintBuffer and NativeString classes. These
- /// classes are mainly used for debugging but also for object hashing.
- ///
- static void initialise();
-
};
} // end namespace mvm
Modified: vmkit/trunk/include/mvm/PrintBuffer.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/PrintBuffer.h?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/PrintBuffer.h (original)
+++ vmkit/trunk/include/mvm/PrintBuffer.h Mon May 4 04:19:42 2009
@@ -10,8 +10,8 @@
#ifndef MVM_PRINTBUFFER_H
#define MVM_PRINTBUFFER_H
-#include <stdio.h> // sprintf
-#include <string.h> // memcpy
+#include <cstdio> // sprintf
+#include <cstring> // memcpy
#include "types.h"
#include "mvm/Object.h"
@@ -22,12 +22,12 @@
/// NativeString - This class is the equivalent of a char*, but allocated
/// by the GC, hence has a virtual table.
///
-class NativeString : public Object {
+class NativeString : public gc {
public:
/// VT - The virtual table of this class.
///
- static VirtualTable* VT;
+ static VirtualTable VT;
/// cString - Returns the C equivalent of the NativeString.
///
@@ -44,7 +44,7 @@
/// alloc - Allocates a NativeString of size len.
///
static inline NativeString *alloc(size_t len) {
- return (NativeString *)gc::operator new(len + sizeof(VirtualTable*), VT);
+ return (NativeString *)gc::operator new(len + sizeof(VirtualTable*), &VT);
}
/// realloc - Reallocate a native string of size len.
@@ -69,7 +69,7 @@
/// PrintBuffer - This class is a buffered string.
///
-class PrintBuffer : public Object {
+class PrintBuffer : public gc {
private:
/// _contents - The buffer.
@@ -90,7 +90,7 @@
/// VT - The virtual table of this class.
///
- static VirtualTable* VT;
+ static VirtualTable VT;
/// contents - Returns the buffer.
@@ -179,7 +179,7 @@
/// alloc - Allocates a default PrintBuffer.
///
static PrintBuffer *alloc(void) {
- PrintBuffer* pbf = gc_new(PrintBuffer)();
+ PrintBuffer* pbf = (PrintBuffer*)gc::operator new(sizeof(PrintBuffer), &VT);
pbf->capacity= 32;
pbf->writePosition= 0;
pbf->setContents(NativeString::alloc(pbf->capacity));
@@ -188,7 +188,9 @@
/// tracer - Traces this PrintBuffer.
///
- virtual void TRACER;
+ static void STATIC_TRACER(PrintBuffer) {
+ obj->contents()->MARK_AND_TRACE;
+ }
};
} // end namespace mvm
Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Mon May 4 04:19:42 2009
@@ -106,14 +106,8 @@
uint64 size = JnjvmModule::getTypeSize(structType);
cl->staticSize = size;
#ifdef WITH_TRACER
- JavaLLVMCompiler* Mod =
- (JavaLLVMCompiler*)cl->classLoader->getCompiler();
- if (!Mod->isStaticCompiling()) {
- Function* F = Mod->makeTracer(cl, true);
- cl->staticTracer = (void (*)(void*)) (uintptr_t)
- JnjvmModule::executionEngine->getPointerToFunction(F);
- F->deleteBody();
- }
+ JavaLLVMCompiler* Mod = (JavaLLVMCompiler*)cl->classLoader->getCompiler();
+ staticTracerFunction = Mod->makeTracer(cl, true);
#endif
}
return staticType;
Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Mon May 4 04:19:42 2009
@@ -1016,6 +1016,9 @@
// innerOuterResolved
ClassElts.push_back(ConstantInt::get(Type::Int8Ty, cl->innerOuterResolved));
+ // isAnonymous
+ ClassElts.push_back(ConstantInt::get(Type::Int8Ty, cl->isAnonymous));
+
// virtualTableSize
ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualTableSize));
@@ -1028,7 +1031,8 @@
// staticTracer
const Type* FTy = STy->getContainedType(STy->getNumContainedTypes() - 1);
#ifdef WITH_TRACER
- Function* F = makeTracer(cl, true);
+ Function* F = getClassInfo(cl)->getStaticTracer();
+ assert(F && "No static tracer");
Constant* staticTracer = ConstantExpr::getCast(Instruction::BitCast, F, FTy);
#else
Constant* staticTracer = ConstantExpr::getNullValue(FTy);
@@ -1153,7 +1157,7 @@
Tracer = JavaIntrinsics.ArrayObjectTracerFunction;
}
} else if (classDef->isClass()) {
- Tracer = makeTracer(classDef->asClass(), false);
+ Tracer = getClassInfo(classDef->asClass())->getVirtualTracer();
}
Elemts.push_back(Tracer ?
@@ -1241,7 +1245,7 @@
#ifdef WITH_TRACER
llvm::Function* JavaAOTCompiler::makeTracer(Class* cl, bool stat) {
- if (!generateTracers) {
+ if (!generateTracers || (!cl->super && !stat)) {
return JavaIntrinsics.JavaObjectTracerFunction;
} else {
return internalMakeTracer(cl, stat);
@@ -1447,13 +1451,19 @@
JavaVirtualTable::getFirstJavaMethodIndex();
memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(),
size * sizeof(uintptr_t));
+ VT->destructor = cl->super->virtualVT->destructor;
}
for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
JavaMethod& meth = cl->virtualMethods[i];
((void**)VT)[meth.offset] = &meth;
}
+
if (!cl->super) VT->destructor = 0;
+
+ LLVMClassInfo* LCI = getClassInfo(cl);
+ if (!LCI->virtualTracerFunction)
+ LCI->virtualTracerFunction = makeTracer(cl, false);
}
void JavaAOTCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) {
@@ -1467,16 +1477,15 @@
Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
GlobalValue::ExternalLinkage,
name, getLLVMModule());
-
+
LLVMClassInfo* LCI = getClassInfo(VT->cl->asClass());
LCI->virtualTracerFunction = func;
}
void JavaAOTCompiler::setDestructor(JavaVirtualTable* VT, uintptr_t ptr,
const char* name) {
- // Set the name info directly, the compiler will use the name to
- // create a LLVM function.
- VT->destructor = (uintptr_t)name;
+ // Set the name info into the operatorDelete directly, the compiler
+ // will use the name to create a LLVM function.
VT->operatorDelete = (uintptr_t)name;
}
Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Mon May 4 04:19:42 2009
@@ -136,25 +136,14 @@
void JavaJITCompiler::makeVT(Class* cl) {
JavaVirtualTable* VT = cl->virtualVT;
assert(VT && "No VT was allocated!");
+
+ LLVMClassInfo* LCI = getClassInfo(cl);
-#ifdef WITH_TRACER
if (VT->init) {
- // So the class is vmjc'ed. Create the virtual tracer.
- Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
- GlobalValue::ExternalLinkage,
- "markAndTraceObject",
- getLLVMModule());
-
- uintptr_t ptr = VT->tracer;
- JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr);
- LLVMClassInfo* LCI = getClassInfo(cl);
- LCI->virtualTracerFunction = func;
-
// The VT hash already been filled by the AOT compiler so there
// is nothing left to do!
return;
}
-#endif
if (cl->super) {
// Copy the super VT into the current VT.
@@ -162,6 +151,7 @@
JavaVirtualTable::getFirstJavaMethodIndex();
memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(),
size * sizeof(uintptr_t));
+ VT->destructor = cl->super->virtualVT->destructor;
}
@@ -175,13 +165,11 @@
// Special handling for finalize method. Don't put a finalizer
// if there is none, or if it is empty.
if (meth.offset == 0) {
-#if !defined(ISOLATE_SHARING) && !defined(USE_GC_BOEHM)
if (!cl->super) {
meth.canBeInlined = true;
} else {
VT->destructor = (uintptr_t)EE->getPointerToFunctionOrStub(func);
}
-#endif
} else {
VT->getFunctions()[meth.offset] =
(uintptr_t)EE->getPointerToFunctionOrStub(func);
@@ -189,15 +177,29 @@
}
#ifdef WITH_TRACER
- Function* func = makeTracer(cl, false);
-
- void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func);
- VT->tracer = (uintptr_t)codePtr;
- func->deleteBody();
+ if (!LCI->virtualTracerFunction) {
+ LCI->virtualTracerFunction = makeTracer(cl, false);
+ }
#endif
}
+Function* JavaJITCompiler::makeTracer(Class* cl, bool stat) {
+ Function* F = cl->super || stat ?
+ internalMakeTracer(cl, stat) : JavaIntrinsics.JavaObjectTracerFunction;
+
+ assert(F && "No tracer");
+ if (stat) {
+ cl->staticTracer = (void (*)(void*)) (uintptr_t)
+ JnjvmModule::executionEngine->getPointerToFunction(F);
+ } else {
+ void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(F);
+ cl->virtualVT->tracer = (uintptr_t)codePtr;
+ }
+ F->deleteBody();
+ return F;
+}
+
void JavaJITCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) {
Function* func = getMethodInfo(meth)->getMethod();
func->setName(name);
@@ -218,12 +220,13 @@
JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr);
LLVMClassInfo* LCI = getClassInfo(VT->cl->asClass());
LCI->virtualTracerFunction = func;
+ VT->tracer = ptr;
}
void JavaJITCompiler::setDestructor(JavaVirtualTable* VT, uintptr_t ptr,
const char* name) {
- // Nothing to do: the virtual table has already set its destructor
- // and no one uses the destructor as a LLVM function.
+ VT->destructor = ptr;
+ VT->operatorDelete = ptr;
}
void* JavaJITCompiler::materializeFunction(JavaMethod* meth) {
@@ -240,7 +243,6 @@
llvm::llvm_shutdown_obj X;
mvm::MvmModule::initialise();
- mvm::Object::initialise();
Collector::initialise(0);
char** newArgv = new char*[argc + 1];
Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Mon May 4 04:19:42 2009
@@ -105,6 +105,19 @@
nbFields = cl->nbVirtualFields;
}
+ uint32 nbReferenceFields = 0;
+ for (uint32 i = 0; i < nbFields; ++i) {
+ JavaField& cur = fields[i];
+ if (cur.getSignature()->trace()) {
+ ++nbReferenceFields;
+ }
+ }
+
+ if (!nbReferenceFields) {
+ if (stat) return JavaIntrinsics.EmptyTracerFunction;
+ else return getClassInfo(cl->super)->getVirtualTracer();
+ }
+
Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
GlobalValue::InternalLinkage,
"", getLLVMModule());
@@ -126,16 +139,9 @@
Args.end(), "", block);
} else {
- LLVMClassInfo* LCP = (LLVMClassInfo*)getClassInfo((Class*)(cl->super));
- Function* F = LCP->virtualTracerFunction;
- if (!F) {
- if (isStaticCompiling()) {
- F = internalMakeTracer(cl->super, false);
- } else {
- F = LCP->getVirtualTracer();
- }
- assert(F && "Still no virtual tracer for super");
- }
+ LLVMClassInfo* LCP = getClassInfo(cl->super);
+ Function* F = LCP->getVirtualTracer();
+ assert(F && "Still no virtual tracer for super");
CallInst::Create(F, Args.begin(), Args.end(), "", block);
}
}
@@ -164,12 +170,6 @@
ReturnInst::Create(block);
- if (!stat) {
- LCI->virtualTracerFunction = func;
- } else {
- LCI->staticTracerFunction = func;
- }
-
return func;
}
#endif
@@ -418,6 +418,7 @@
#ifdef WITH_TRACER
MarkAndTraceFunction = module->getFunction("MarkAndTrace");
JavaObjectTracerFunction = module->getFunction("JavaObjectTracer");
+ EmptyTracerFunction = module->getFunction("EmptyTracer");
JavaArrayTracerFunction = module->getFunction("JavaArrayTracer");
ArrayObjectTracerFunction = module->getFunction("ArrayObjectTracer");
#endif
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon May 4 04:19:42 2009
@@ -361,13 +361,10 @@
}
void JavaVirtualTable::setNativeTracer(uintptr_t ptr, const char* name) {
- tracer = ptr;
cl->classLoader->getCompiler()->setTracer(this, ptr, name);
}
void JavaVirtualTable::setNativeDestructor(uintptr_t ptr, const char* name) {
- destructor = ptr;
- operatorDelete = ptr;
cl->classLoader->getCompiler()->setDestructor(this, ptr, name);
}
@@ -812,7 +809,8 @@
for (uint32 i = 0; i < nbVirtualMethods; ++i) {
JavaMethod& meth = virtualMethods[i];
- if (meth.name->equals(classLoader->bootstrapLoader->finalize)) {
+ if (meth.name->equals(classLoader->bootstrapLoader->finalize) &&
+ meth.type->equals(classLoader->bootstrapLoader->clinitType)) {
meth.offset = 0;
} else {
JavaMethod* parent = super?
@@ -954,11 +952,12 @@
for (uint16 i = 0; i < nbi; ++i) {
uint16 inner = reader.readU2();
uint16 outer = reader.readU2();
- //uint16 innerName =
- reader.readU2();
+ uint16 innerName = reader.readU2();
uint16 accessFlags = reader.readU2();
- UserClass* clInner = (UserClass*)ctpInfo->loadClass(inner);
- UserClass* clOuter = (UserClass*)ctpInfo->loadClass(outer);
+ UserClass* clInner = 0;
+ UserClass* clOuter = 0;
+ if (inner) clInner = (UserClass*)ctpInfo->loadClass(inner);
+ if (outer) clOuter = (UserClass*)ctpInfo->loadClass(outer);
if (clInner == this) {
outerClass = clOuter;
@@ -968,6 +967,7 @@
classLoader->allocator.Allocate(nbi * sizeof(Class*));
}
clInner->setInnerAccess(accessFlags);
+ if (!innerName) isAnonymous = true;
innerClasses[nbInnerClasses++] = clInner;
}
}
@@ -1310,8 +1310,12 @@
offset = getCacheIndex() + depth + 1;
} else {
offset = getCacheIndex();
- ++nbSecondaryTypes;
- outOfDepth = 1;
+ // Add the super in the list of secondary types only if it is
+ // out of depth.
+ if (depth > getDisplayLength()) {
+ ++nbSecondaryTypes;
+ outOfDepth = 1;
+ }
}
mvm::BumpPtrAllocator& allocator = C->classLoader->allocator;
@@ -1388,29 +1392,45 @@
Classpath* upcalls = JCL->bootstrapLoader->upcalls;
if (upcalls->ArrayOfObject) {
- UserCommonClass* temp = C->baseClass();
+ UserCommonClass* base = C->baseClass();
uint32 dim = 1;
- while (temp->isArray()) {
- temp = temp->asArrayClass()->baseClass();
+ while (base->isArray()) {
+ base = base->asArrayClass()->baseClass();
++dim;
}
bool newSecondaryTypes = false;
- bool intf = temp->isInterface();
- if (temp->isPrimitive()) {
+ bool intf = base->isInterface();
+ const UTF8* superName = 0;
+
+ if (base->isPrimitive()) {
+ // If the base class is primitive, then the super is one
+ // dimension below, e.g. the super of int[][] is Object[].
--dim;
- temp = C->super;
- } else if (temp == C->super) {
+ superName = JCL->constructArrayName(dim, C->super->name);
+ } else if (base == C->super) {
+ // If the base class is java.lang.Object, then the super is one
+ // dimension below, e.g. the super of Object[][] is Object[].
+ // Also, the class is the first class in the dimension hierarchy,
+ // so it must create a new secondary type list.
--dim;
newSecondaryTypes = true;
+ superName = JCL->constructArrayName(dim, C->super->name);
} else {
- temp = temp->super;
+ // If the base class is any other class, interface or not,
+ // the super is of the dimension of the current array class,
+ // and whose base class is the super of this base class.
+ superName = JCL->constructArrayName(dim, base->super->name);
}
-
- const UTF8* name = JCL->constructArrayName(dim, temp->name);
- ClassArray* super = JCL->constructArray(name);
+
+ // Construct the super array class, e.g. java.lang.Object[] for
+ // java.lang.Class[].
+ ClassArray* super = JCL->constructArray(superName);
JavaVirtualTable* superVT = super->virtualVT;
depth = superVT->depth + 1;
+
+ // Record if we need to add the super in the list of secondary types.
+ uint32 addSuper = 0;
uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth;
memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*));
@@ -1419,27 +1439,51 @@
offset = getCacheIndex() + depth + 1;
} else {
offset = getCacheIndex();
+ // We add the super if the current class is an interface or if the super
+ // class is out of depth.
+ if (intf || depth != getDisplayLength()) addSuper = 1;
}
mvm::BumpPtrAllocator& allocator = JCL->allocator;
if (!newSecondaryTypes) {
- if (depth < getDisplayLength()) {
- nbSecondaryTypes = superVT->nbSecondaryTypes;
- secondaryTypes = superVT->secondaryTypes;
- } else {
- nbSecondaryTypes = superVT->nbSecondaryTypes + 1;
+ if (base->nbInterfaces || addSuper) {
+ // If the base class implements interfaces, we must also add the
+ // arrays of these interfaces, of the same dimension than this array
+ // class and add them to the secondary types list.
+ nbSecondaryTypes = base->nbInterfaces + superVT->nbSecondaryTypes +
+ addSuper;
secondaryTypes = (JavaVirtualTable**)
allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes);
- secondaryTypes[0] = this;
- memcpy(secondaryTypes + 1 , superVT->secondaryTypes,
+
+ // Put the super in the list of secondary types.
+ if (addSuper) secondaryTypes[0] = superVT;
+
+ // Copy the list of secondary types of the super.
+ memcpy(secondaryTypes + addSuper, superVT->secondaryTypes,
superVT->nbSecondaryTypes * sizeof(JavaVirtualTable*));
+
+ // Add our own secondary types: the interfaces of the base class put
+ // in the dimension of the current array class.
+ for (uint32 i = 0; i < base->nbInterfaces; ++i) {
+ const UTF8* name =
+ JCL->constructArrayName(dim, base->interfaces[i]->name);
+ ClassArray* interface = JCL->constructArray(name);
+ JavaVirtualTable* CurVT = interface->virtualVT;
+ secondaryTypes[i + superVT->nbSecondaryTypes + addSuper] = CurVT;
+ }
+ } else {
+ // If the super is not a secondary type and the base class does not
+ // implement any interface, we can reuse the list of secondary types
+ // of super.
+ nbSecondaryTypes = superVT->nbSecondaryTypes;
+ secondaryTypes = superVT->secondaryTypes;
}
} else {
// This is an Object[....] array class. It will create the list of
- // secondary types and all array classes of the same dimension will
- // point to this array.
+ // secondary types and all array classes of the same dimension whose
+ // base class does not have interfaces point to this array.
// If we're superior than the display limit, we must make room for one
// slot that will contain the current VT.
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Mon May 4 04:19:42 2009
@@ -671,6 +671,10 @@
///
bool innerOuterResolved;
+ /// isAnonymous - Is the class an anonymous class?
+ ///
+ bool isAnonymous;
+
/// virtualTableSize - The size of the virtual table of this class.
///
uint32 virtualTableSize;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Mon May 4 04:19:42 2009
@@ -23,29 +23,8 @@
using namespace jnjvm;
-static void initialiseVT() {
-
-# define INIT(X) { \
- X fake; \
- X::VT = ((VirtualTable**)(void*)(&fake))[0]; }
-
- INIT(LockObj);
- INIT(VMClassLoader);
-
-#ifdef ISOLATE_SHARING
- INIT(JnjvmSharedLoader);
- INIT(SharedClassByteMap);
- INIT(UserClass);
- INIT(UserClassArray);
- INIT(UserConstantPool);
-#endif
-#undef INIT
-
-}
-
#ifdef ISOLATE_SHARING
JnjvmClassLoader* mvm::VirtualMachine::initialiseJVM(JavaCompiler* Comp) {
- initialiseVT();
JnjvmSharedLoader::sharedLoader = JnjvmSharedLoader::createSharedLoader(Comp);
return JnjvmSharedLoader::sharedLoader;
}
@@ -62,7 +41,6 @@
JnjvmClassLoader*
mvm::VirtualMachine::initialiseJVM(JavaCompiler* Comp, bool dlLoad) {
- initialiseVT();
mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator();
return new(*A) JnjvmBootstrapLoader(*A, Comp, dlLoad);
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Mon May 4 04:19:42 2009
@@ -70,7 +70,12 @@
#ifdef USE_GC_BOEHM
LockObj* res = new LockObj();
#else
- LockObj* res = gc_new(LockObj)();
+ LockObj* res = new(&VT) LockObj();
+ // Set the virtual table to change what C++ did: by using the new operator
+ // C++ after the allocation will set its own VT. Since we want to call
+ // the C++ constructor (because it initializes the native data structures
+ // such as LockRecursive), we have to change the VT of this object.
+ res->setVirtualTable(&VT);
#endif
return res;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Mon May 4 04:19:42 2009
@@ -107,7 +107,7 @@
/// VT - LockObj is GC-allocated, so we must make the VT explicit.
///
- static VirtualTable* VT;
+ static VirtualTable VT;
~LockObj() {}
LockObj() {}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Mon May 4 04:19:42 2009
@@ -768,5 +768,5 @@
newVMThread->getVirtualVT()->setNativeDestructor(
(uintptr_t)nativeJavaObjectVMThreadDestructor,
- "nativeJavaObjectVMThreadDestructorr");
+ "nativeJavaObjectVMThreadDestructor");
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon May 4 04:19:42 2009
@@ -1136,7 +1136,6 @@
// Helper function to run Jnjvm without JIT.
extern "C" int StartJnjvmWithoutJIT(int argc, char** argv, char* mainClass) {
- mvm::Object::initialise();
Collector::initialise(0);
char** newArgv = new char*[argc + 1];
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Mon May 4 04:19:42 2009
@@ -769,7 +769,7 @@
if (!vmdata) {
mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator();
JCL = new(*A) JnjvmClassLoader(*A, *vm->bootstrapLoader, loader, vm);
- vmdata = gc_new(VMClassLoader)(JCL);
+ vmdata = VMClassLoader::allocate(JCL);
(upcalls->vmdataClassLoader->setObjectField(loader, (JavaObject*)vmdata));
}
loader->release();
@@ -1039,6 +1039,7 @@
realCl->staticMethods = realCl->virtualMethods + realCl->nbVirtualMethods;
realCl->staticFields = realCl->virtualFields + realCl->nbVirtualFields;
}
+ cl->virtualVT->setNativeTracer(cl->virtualVT->tracer, "");
JCL->getClasses()->map.insert(std::make_pair(cl->name, cl));
cl->classLoader = JCL;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Mon May 4 04:19:42 2009
@@ -399,24 +399,30 @@
public:
+ static VMClassLoader* allocate(JnjvmClassLoader* J) {
+ VMClassLoader* res =
+ (VMClassLoader*)gc::operator new(sizeof(VMClassLoader), &VT);
+ res->JCL = J;
+ return res;
+ }
+
/// VT - The VirtualTable for this GC-class.
- static VirtualTable* VT;
+ static VirtualTable VT;
/// TRACER - Trace the internal class loader.
- virtual void TRACER {
- JCL->CALL_TRACER;
+ static void STATIC_TRACER(VMClassLoader) {
+ if (obj->JCL) obj->JCL->CALL_TRACER;
}
/// ~VMClassLoader - Delete the internal class loader.
///
- ~VMClassLoader() {
- if (JCL) JCL->~JnjvmClassLoader();
+ static void staticDestructor(VMClassLoader* obj) {
+ if (obj->JCL) obj->JCL->~JnjvmClassLoader();
}
/// VMClassLoader - Default constructors.
///
VMClassLoader(JnjvmClassLoader* J) : JCL(J) {}
- VMClassLoader() : JCL(0) {}
/// getClassLoader - Get the internal class loader.
///
Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Mon May 4 04:19:42 2009
@@ -57,12 +57,17 @@
// Classpath with the vmdata field).
//===----------------------------------------------------------------------===//
-#define INIT(X) VirtualTable* X::VT = 0
+VirtualTable VMClassLoader::VT((uintptr_t)VMClassLoader::staticDestructor,
+ (uintptr_t)VMClassLoader::staticDestructor,
+ (uintptr_t)VMClassLoader::staticTracer);
- INIT(LockObj);
- INIT(VMClassLoader);
+VirtualTable LockObj::VT(0, 0, (uintptr_t)VirtualTable::emptyTracer);
-#undef INIT
+//===----------------------------------------------------------------------===//
+// Empty tracer for static tracers of classes that do not declare static
+// variables.
+//===----------------------------------------------------------------------===//
+extern "C" void EmptyTracer(void*) {}
//===----------------------------------------------------------------------===//
// Root trace methods for Java objects. There are three types of roots:
@@ -156,8 +161,8 @@
for (uint32 i =0; i < NR_ISOLATES; ++i) {
TaskClassMirror &M = IsolateInfo[i];
- if (M.staticInstance) {
- ((Class*)this)->staticTracer(M.staticInstance);
+ if (M.staticInstance && staticTracer != EmptyTracer) {
+ staticTracer(M.staticInstance);
}
}
}
Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Mon May 4 04:19:42 2009
@@ -19,8 +19,8 @@
using namespace mvm;
-VirtualTable *NativeString::VT = 0;
-VirtualTable *PrintBuffer::VT = 0;
+VirtualTable NativeString::VT(0, 0, (uintptr_t)VirtualTable::emptyTracer);
+VirtualTable PrintBuffer::VT(0, 0, (uintptr_t)PrintBuffer::staticTracer);
extern "C" void printFloat(float f) {
fprintf(stderr, "%f\n", f);
@@ -43,22 +43,6 @@
}
-void Object::initialise() {
-# define INIT(X) { \
- X fake; \
- X::VT = ((VirtualTable**)(void*)(&fake))[0]; }
-
- INIT(NativeString);
- INIT(PrintBuffer);
-
-#undef INIT
-}
-
-void PrintBuffer::TRACER {
- ((PrintBuffer *)this)->contents()->MARK_AND_TRACE;
-}
-
-
PrintBuffer *PrintBuffer::writeObj(const Object *obj) {
Object *beg = (Object*)Collector::begOf(obj);
Modified: vmkit/trunk/tools/jnjvm/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/jnjvm/Main.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/tools/jnjvm/Main.cpp (original)
+++ vmkit/trunk/tools/jnjvm/Main.cpp Mon May 4 04:19:42 2009
@@ -27,7 +27,6 @@
llvm::llvm_shutdown_obj X;
MvmModule::initialise();
- Object::initialise();
Collector::initialise(0);
JavaJITCompiler* Comp = new JavaJITCompiler("JITModule");
Modified: vmkit/trunk/tools/n3-mono/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-mono/Main.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/tools/n3-mono/Main.cpp (original)
+++ vmkit/trunk/tools/n3-mono/Main.cpp Mon May 4 04:19:42 2009
@@ -21,7 +21,6 @@
llvm::llvm_shutdown_obj X;
MvmModule::initialise();
- Object::initialise();
Collector::initialise(0);
VirtualMachine::initialiseCLIVM();
Modified: vmkit/trunk/tools/n3-pnetlib/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-pnetlib/Main.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/tools/n3-pnetlib/Main.cpp (original)
+++ vmkit/trunk/tools/n3-pnetlib/Main.cpp Mon May 4 04:19:42 2009
@@ -21,7 +21,6 @@
llvm::llvm_shutdown_obj X;
MvmModule::initialise();
- Object::initialise();
Collector::initialise(0);
VirtualMachine::initialiseCLIVM();
Modified: vmkit/trunk/tools/vmjc/vmjc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/tools/vmjc/vmjc.cpp (original)
+++ vmkit/trunk/tools/vmjc/vmjc.cpp Mon May 4 04:19:42 2009
@@ -213,7 +213,6 @@
Comp = new JavaJITCompiler("JIT");
}
- mvm::Object::initialise();
Collector::initialise(0);
Collector::enable(0);
Modified: vmkit/trunk/tools/vmkit/Launcher.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmkit/Launcher.cpp?rev=70845&r1=70844&r2=70845&view=diff
==============================================================================
--- vmkit/trunk/tools/vmkit/Launcher.cpp (original)
+++ vmkit/trunk/tools/vmkit/Launcher.cpp Mon May 4 04:19:42 2009
@@ -133,7 +133,6 @@
}
mvm::MvmModule::initialise(Fast ? CodeGenOpt::None : CodeGenOpt::Aggressive);
- mvm::Object::initialise();
Collector::initialise(0);
if (VMToRun == RunJava) {
More information about the vmkit-commits
mailing list