From nicolas.geoffray at lip6.fr Wed Apr 1 05:23:37 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 01 Apr 2009 12:23:37 -0000 Subject: [vmkit-commits] [vmkit] r68199 - in /vmkit/trunk/lib/JnJVM: Compiler/JITInfo.cpp VMCore/JavaTypes.cpp VMCore/JavaTypes.h Message-ID: <200904011223.n31CNe3K006109@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 1 07:23:28 2009 New Revision: 68199 URL: http://llvm.org/viewvc/llvm-project?rev=68199&view=rev Log: Change naming of signatures in AOT .ll files. Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=68199&r1=68198&r2=68199&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Wed Apr 1 07:23:28 2009 @@ -335,19 +335,22 @@ JavaLLVMCompiler* Mod = (JavaLLVMCompiler*)signature->initialLoader->getCompiler(); - const char* name = 0; + Function* res = 0; if (Mod->isStaticCompiling()) { - name = virt ? signature->printString("virtual_buf") : - signature->printString("static_buf"); + const char* type = virt ? "virtual_buf" : "static_buf"; + char* buf = (char*)alloca((signature->keyName->size << 1) + 1 + 11); + signature->nativeName(buf, type); + res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), + GlobalValue::InternalLinkage, buf, + Mod->getLLVMModule()); + + } else { - name = ""; + res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), + GlobalValue::InternalLinkage, "", + Mod->getLLVMModule()); } - Function* res = Function::Create(virt ? getVirtualBufType() : - getStaticBufType(), - GlobalValue::InternalLinkage, name, - Mod->getLLVMModule()); - BasicBlock* currentBlock = BasicBlock::Create("enter", res); Function::arg_iterator i = res->arg_begin(); Value *obj, *ptr, *func; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp?rev=68199&r1=68198&r2=68199&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp Wed Apr 1 07:23:28 2009 @@ -130,3 +130,39 @@ } return _virtualCallAP; } + + +void Signdef::nativeName(char* ptr, const char* ext) const { + sint32 i = 0; + while (i < keyName->size) { + char c = keyName->elements[i++]; + if (c == I_PARG) { + ptr[0] = '_'; + ptr[1] = '_'; + ptr += 2; + } else if (c == '/') { + ptr[0] = '_'; + ++ptr; + } else if (c == '_') { + ptr[0] = '_'; + ptr[1] = '1'; + ptr += 2; + } else if (c == I_END_REF) { + ptr[0] = '_'; + ptr[1] = '2'; + ptr += 2; + } else if (c == I_TAB) { + ptr[0] = '_'; + ptr[1] = '3'; + ptr += 2; + } else if (c == I_PARD) { + break; + } else { + ptr[0] = c; + ++ptr; + } + } + + assert(ext && "I need an extension"); + memcpy(ptr, ext, strlen(ext) + 1); +} Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h?rev=68199&r1=68198&r2=68199&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.h Wed Apr 1 07:23:28 2009 @@ -284,6 +284,10 @@ /// printString - Print the signature with the following extension. /// const char* printString(const char* ext = "") const; + + /// nativeName - Get a native name for callbacks emitted AOT. + /// + void nativeName(char* buf, const char* ext) const; /// printWithSign - Print the signature of a method with the method's class /// and name. From nicolas.geoffray at lip6.fr Wed Apr 1 05:27:37 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 01 Apr 2009 12:27:37 -0000 Subject: [vmkit-commits] [vmkit] r68200 - /vmkit/trunk/include/jnjvm/JavaCompiler.h Message-ID: <200904011227.n31CRb54006278@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 1 07:27:34 2009 New Revision: 68200 URL: http://llvm.org/viewvc/llvm-project?rev=68200&view=rev Log: Add failing bodies to JavaCompiler's methods. Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JavaCompiler.h?rev=68200&r1=68199&r2=68200&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JavaCompiler.h (original) +++ vmkit/trunk/include/jnjvm/JavaCompiler.h Wed Apr 1 07:27:34 2009 @@ -2,6 +2,8 @@ #ifndef JAVA_COMPILER_H #define JAVA_COMPILER_H +#include +#include #include namespace jnjvm { @@ -13,18 +15,57 @@ class JavaCompiler { public: - virtual void* materializeFunction(JavaMethod* meth) = 0; - virtual void setMethod(JavaMethod* meth, void* ptr, const char* name) = 0; - virtual bool isStaticCompiling() = 0; - virtual void resolveVirtualClass(Class* cl) = 0; - virtual void resolveStaticClass(Class* cl) = 0; - - virtual JavaCompiler* Create(const std::string&) = 0; - - virtual void staticCallBuf(Signdef* sign) = 0; - virtual void virtualCallBuf(Signdef* sign) = 0; - virtual void staticCallAP(Signdef* sign) = 0; - virtual void virtualCallAP(Signdef* sign) = 0; + virtual JavaCompiler* Create(const std::string&) { + return this; + } + + virtual void* materializeFunction(JavaMethod* meth) { + fprintf(stderr, "Materializing a function in an empty compiler"); + abort(); + return 0; + } + + virtual void setMethod(JavaMethod* meth, void* ptr, const char* name) { + fprintf(stderr, "Implement me"); + abort(); + } + + virtual bool isStaticCompiling() { + fprintf(stderr, "Checking static compilation in an empty compiler"); + abort(); + return false; + } + + virtual void resolveVirtualClass(Class* cl) { + fprintf(stderr, "Resolving a class in an empty compiler"); + abort(); + } + + virtual void resolveStaticClass(Class* cl) { + fprintf(stderr, "Resolving a class in an empty compiler"); + abort(); + } + + + virtual void staticCallBuf(Signdef* sign) { + fprintf(stderr, "Asking for a callback in an empty compiler"); + abort(); + } + + virtual void virtualCallBuf(Signdef* sign) { + fprintf(stderr, "Asking for a callback in an empty compiler"); + abort(); + } + + virtual void staticCallAP(Signdef* sign) { + fprintf(stderr, "Asking for a callback in an empty compiler"); + abort(); + } + + virtual void virtualCallAP(Signdef* sign) { + fprintf(stderr, "Asking for a callback in an empty compiler"); + abort(); + } virtual ~JavaCompiler() {} From nicolas.geoffray at lip6.fr Wed Apr 1 05:29:01 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 01 Apr 2009 12:29:01 -0000 Subject: [vmkit-commits] [vmkit] r68201 - /vmkit/trunk/include/jnjvm/JavaCompiler.h Message-ID: <200904011229.n31CT1CN006332@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 1 07:29:01 2009 New Revision: 68201 URL: http://llvm.org/viewvc/llvm-project?rev=68201&view=rev Log: Add license header. Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JavaCompiler.h?rev=68201&r1=68200&r2=68201&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JavaCompiler.h (original) +++ vmkit/trunk/include/jnjvm/JavaCompiler.h Wed Apr 1 07:29:01 2009 @@ -1,3 +1,11 @@ +//===------- JavaCompiler.h - Jnjvm interface for the compiler ------------===// +// +// The VMKit project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// #ifndef JAVA_COMPILER_H #define JAVA_COMPILER_H From nicolas.geoffray at lip6.fr Wed Apr 1 05:30:50 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 01 Apr 2009 12:30:50 -0000 Subject: [vmkit-commits] [vmkit] r68202 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/VMCore/Jnjvm.cpp tools/vmjc/vmjc.cpp Message-ID: <200904011230.n31CUpne006403@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 1 07:30:47 2009 New Revision: 68202 URL: http://llvm.org/viewvc/llvm-project?rev=68202&view=rev Log: Add support for a --main option in vmjc that will generate a "main" function in the resulting .ll file. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/tools/vmjc/vmjc.cpp Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=68202&r1=68201&r2=68202&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Wed Apr 1 07:30:47 2009 @@ -654,6 +654,7 @@ void compileFile(JnjvmClassLoader* JCL, const char* name); void compileClass(Class* cl); + void generateMain(const char* name, bool jit); private: void compileAllStubs(Signdef* sign); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=68202&r1=68201&r2=68202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Wed Apr 1 07:30:47 2009 @@ -1532,7 +1532,7 @@ realName[size - 6] = 0; const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName); Class* cl = bootstrapLoader->constructClass(utf8, res); - classes.push_back(cl); + classes.push_back(cl); } } @@ -1563,8 +1563,15 @@ } } else { + char* realName = (char*)alloca(size + 1); + if (size > 6 && !strcmp(&name[size - 6], ".class")) { + memcpy(realName, name, size - 6); + realName[size - 6] = 0; + } else { + memcpy(realName, name, size + 1); + } - const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(name); + const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName); UserClass* cl = bootstrapLoader->loadName(utf8, true, true); cl->setOwnerClass(JavaThread::get()); M->compileClass(cl); @@ -1623,3 +1630,34 @@ sign->getVirtualCallBuf(); // getVirtualCallAP(); } + +void JavaAOTCompiler::generateMain(const char* name, bool jit) { + + // Type Definitions + std::vector FuncArgs; + FuncArgs.push_back(Type::Int32Ty); + FuncArgs.push_back(PointerType::getUnqual(JavaIntrinsics.ptrType)); + + FunctionType* FuncTy = FunctionType::get(Type::Int32Ty, FuncArgs, false); + + Function* MainFunc = Function::Create(FuncTy, GlobalValue::ExternalLinkage, + "main", TheModule); + BasicBlock* currentBlock = BasicBlock::Create("enter", MainFunc); + + Function::arg_iterator FuncVals = MainFunc->arg_begin(); + Value* Argc = FuncVals++; + Value* Argv = FuncVals++; + Value* Args[3] = { Argc, Argv, ConstantArray::get(name, true) }; + + FuncArgs.push_back(Args[2]->getType()); + + FuncTy = FunctionType::get(Type::Int32Ty, FuncArgs, false); + + Function* CalledFunc = + Function::Create(FuncTy, GlobalValue::ExternalLinkage, + jit ? "StartWithJIT" : "StartWithoutJIT", TheModule); + + Value* res = CallInst::Create(CalledFunc, Args, Args + 3, "", currentBlock); + ReturnInst::Create(res, currentBlock); + +} Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=68202&r1=68201&r2=68202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Wed Apr 1 07:30:47 2009 @@ -13,6 +13,10 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/Support/ManagedStatic.h" + +#include "MvmGC.h" +#include "mvm/VirtualMachine.h" #include "JavaConstantPool.h" #include "JavaThread.h" @@ -210,3 +214,26 @@ return res; } + +// Helper function to run an executable with a JIT +extern "C" int StartJnjvmWithJIT(int argc, char** argv, char* mainClass) { + llvm::llvm_shutdown_obj X; + + mvm::MvmModule::initialise(); + mvm::Object::initialise(); + Collector::initialise(0); + + char** newArgv = new char*[argc + 1]; + memcpy(newArgv, argv, argc * sizeof(void*)); + newArgv[argc] = mainClass; + + JavaJITCompiler* Comp = new JavaJITCompiler("JITModule"); + mvm::MvmModule::AddStandardCompilePasses(); + JnjvmClassLoader* JCL = mvm::VirtualMachine::initialiseJVM(Comp); + mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(JCL); + vm->runApplication(argc + 1, newArgv); + vm->waitForExit(); + + delete newArgv; + return 0; +} Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=68202&r1=68201&r2=68202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Wed Apr 1 07:30:47 2009 @@ -19,6 +19,7 @@ #include "debug.h" #include "mvm/Threads/Thread.h" +#include "MvmGC.h" #include "ClasspathReflect.h" #include "JavaArray.h" @@ -1121,3 +1122,23 @@ } FunctionMapLock.release(); } + +// 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]; + memcpy(newArgv, argv, argc * sizeof(void*)); + newArgv[argc] = mainClass; + + JavaCompiler* Comp = new JavaCompiler(); + JnjvmClassLoader* JCL = mvm::VirtualMachine::initialiseJVM(Comp); + mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(JCL); + vm->runApplication(argc + 1, newArgv); + vm->waitForExit(); + + delete newArgv; + + return 0; +} Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=68202&r1=68201&r2=68202&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Wed Apr 1 07:30:47 2009 @@ -64,6 +64,12 @@ static cl::opt Force("f", cl::desc("Overwrite output files")); +static cl::opt +MainClass("main", cl::desc("Specify main class")); + +static cl::opt +WithJIT("with-jit", cl::desc("Generate main function with JIT support")); + static cl::opt DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden); @@ -219,6 +225,11 @@ if (AssumeCompiled) MAOT->assumeCompiled = true; MAOT->compileFile(JCL, InputFilename.c_str()); + if (!MainClass.empty()) { + MAOT->generateMain(MainClass.c_str(), WithJIT); + } + + if (DontPrint) { // Just use stdout. We won't actually print anything on it. } else if (OutputFilename != "") { // Specified an output filename? From nicolas.geoffray at lip6.fr Thu Apr 2 07:10:14 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:10:14 -0000 Subject: [vmkit-commits] [vmkit] r68305 - in /vmkit/trunk/tools/llcj: ./ LinkPaths.h.in Makefile libjnjvm/ libjnjvm/Makefile llcj.cpp Message-ID: <200904021410.n32EAE7q017270@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:10:13 2009 New Revision: 68305 URL: http://llvm.org/viewvc/llvm-project?rev=68305&view=rev Log: Add a driver for generating executable files out of Java files. Added: vmkit/trunk/tools/llcj/ vmkit/trunk/tools/llcj/LinkPaths.h.in vmkit/trunk/tools/llcj/Makefile (with props) vmkit/trunk/tools/llcj/libjnjvm/ vmkit/trunk/tools/llcj/libjnjvm/Makefile (with props) vmkit/trunk/tools/llcj/llcj.cpp Added: vmkit/trunk/tools/llcj/LinkPaths.h.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/LinkPaths.h.in?rev=68305&view=auto ============================================================================== --- vmkit/trunk/tools/llcj/LinkPaths.h.in (added) +++ vmkit/trunk/tools/llcj/LinkPaths.h.in Thu Apr 2 09:10:13 2009 @@ -0,0 +1,14 @@ +//===---- LinkPaths.h - Library paths for generating executables ----------===// +// +// VMKit +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +#define LLVMLibs "-L at LLVM_OBJ@/Release/lib"; +#define VMKITLibs1 "-L at abs_top_objdir@/Release/lib"; +#define VMKITLibs2 "-L at abs_top_srcdir@/Release/lib"; +#define VMKITLibs3 "-L at PROJ_INSTALL_ROOT@/lib"; Added: vmkit/trunk/tools/llcj/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/Makefile?rev=68305&view=auto ============================================================================== --- vmkit/trunk/tools/llcj/Makefile (added) +++ vmkit/trunk/tools/llcj/Makefile Thu Apr 2 09:10:13 2009 @@ -0,0 +1,18 @@ +##===- tools/llcj/Makefile ---------------------------------*- Makefile -*-===## +# +# The vmkit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../.. + +DIRS = libjnjvm + +include $(LEVEL)/Makefile.config + +TOOLNAME = llcj +LINK_COMPONENTS = support + +include $(LEVEL)/Makefile.common Propchange: vmkit/trunk/tools/llcj/Makefile ------------------------------------------------------------------------------ svn:executable = * Added: vmkit/trunk/tools/llcj/libjnjvm/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/libjnjvm/Makefile?rev=68305&view=auto ============================================================================== --- vmkit/trunk/tools/llcj/libjnjvm/Makefile (added) +++ vmkit/trunk/tools/llcj/libjnjvm/Makefile Thu Apr 2 09:10:13 2009 @@ -0,0 +1,17 @@ +##===- tools/llcj/libjnjvm/Makefile-------------------------*- Makefile -*-===## +# +# The vmkit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../../.. + +include $(LEVEL)/Makefile.config + +VMKIT_LIBRARYNAME = jnjvm +VMKIT_BUILD_ARCHIVE = 1 +USEDLIBS = Allocator CommonThread Mvm JnJVM Classpath $(GCLIB) + +include $(LEVEL)/Makefile.common Propchange: vmkit/trunk/tools/llcj/libjnjvm/Makefile ------------------------------------------------------------------------------ svn:executable = * Added: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=68305&view=auto ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (added) +++ vmkit/trunk/tools/llcj/llcj.cpp Thu Apr 2 09:10:13 2009 @@ -0,0 +1,207 @@ +//===------------- llcj.cpp - Java ahead of time compiler -----------------===// +// +// The VMKit project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/ManagedStatic.h" +#include "llvm/System/Path.h" +#include "llvm/System/Program.h" +#include "llvm/System/Signals.h" + +#include "LinkPaths.h" + +using namespace llvm; + +int main(int argc, char **argv) { + llvm_shutdown_obj X; // Call llvm_shutdown() on exit. + + bool SaveTemps = false; + char* opt = 0; + + const char** vmjcArgv = new const char*[argc + 5]; + int vmjcArgc = 1; + const char** gccArgv = new const char*[argc + 32]; + int gccArgc = 1; + + bool runGCC = true; + char* className = 0; + + for (int i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "-shared")) { + gccArgv[gccArgc++] = argv[i]; + } else if (!strcmp(argv[i], "-O1") || !strcmp(argv[i], "-O2") || + !strcmp(argv[i], "-O3")) { + opt = argv[i]; + vmjcArgv[vmjcArgc++] = (char*)"-std-compile-opts"; + } else if (argv[i][0] == '-' && argv[i][1] == 'S') { + runGCC = false; + } else if (argv[i][0] == '-' && argv[i][1] == 'c') { + gccArgv[gccArgc++] = argv[i]; + } else if (argv[i][0] == '-' && argv[i][1] == 'l') { + gccArgv[gccArgc++] = argv[i]; + } else if (argv[i][0] == '-' && argv[i][1] == 'L') { + gccArgv[gccArgc++] = argv[i]; + } else if (argv[i][0] == '-' && argv[i][1] == 'W') { + gccArgv[gccArgc++] = argv[i]; + } else if (argv[i][0] == '-' && argv[i][1] == 'o') { + gccArgv[gccArgc++] = argv[i++]; + gccArgv[gccArgc] = argv[i]; + } else if (argv[i][0] != '-') { + char* name = argv[i]; + int len = strlen(name); + if (len > 4 && (!strcmp(&name[len - 4], ".jar") || + !strcmp(&name[len - 4], ".zip"))) { + vmjcArgv[vmjcArgc++] = name; + className = strndup(name, len - 4); + } else if (len > 6 && !strcmp(&name[len - 6], ".class")) { + vmjcArgv[vmjcArgc++] = name; + className = strndup(name, len - 6); + } else { + gccArgv[gccArgc++] = name; + } + } else if (!strcmp(argv[i], "--help")) { + fprintf(stderr, "Usage: llcj [options] file ...\n" + "The Java to native compiler. Run vmjc --help for more " + "information on the real AOT compiler.\n"); + delete gccArgv; + delete vmjcArgv; + if (className) free(className); + return 0; + } else { + vmjcArgv[vmjcArgc++] = argv[i]; + } + } + + vmjcArgv[vmjcArgc] = 0; + gccArgv[gccArgc] = 0; + + std::string errMsg; + + const sys::Path& tempDir = SaveTemps + ? sys::Path(sys::Path::GetCurrentDirectory()) + : sys::Path(sys::Path::GetTemporaryDirectory()); + + sys::Path Out = tempDir; + int res = 0; + sys::Path Prog; + + if (!className) { + fprintf(stderr, "No Java file specified.... Abort\n"); + goto cleanup; + } + + Prog = sys::Program::FindProgramByName("vmjc"); + + if (Prog.isEmpty()) { + fprintf(stderr, "Can't find vmjc.... Abort\n"); + goto cleanup; + } + + Out.appendComponent(className); + Out.appendSuffix("bc"); + + vmjcArgv[0] = Prog.toString().c_str(); + vmjcArgv[vmjcArgc++] = "-f"; + vmjcArgv[vmjcArgc++] = "-o"; + vmjcArgv[vmjcArgc++] = Out.toString().c_str(); + + res = sys::Program::ExecuteAndWait(Prog, vmjcArgv); + + if (!res && opt) { + sys::Path OptOut = tempDir; + OptOut.appendComponent("llvmopt"); + OptOut.appendSuffix("bc"); + + sys::Path Prog = sys::Program::FindProgramByName("opt"); + + if (Prog.isEmpty()) { + fprintf(stderr, "Can't find opt.... Abort\n"); + goto cleanup; + } + + const char* optArgv[7]; + optArgv[0] = Prog.toString().c_str(); + optArgv[1] = Out.toString().c_str(); + optArgv[2] = "-f"; + optArgv[3] = "-o"; + optArgv[4] = OptOut.toString().c_str(); + if (opt) { + optArgv[5] = opt; + optArgv[6] = 0; + } else { + optArgv[5] = 0; + } + + res = sys::Program::ExecuteAndWait(Prog, optArgv); + Out = OptOut; + } + + if (!res) { + sys::Path LlcOut = tempDir; + LlcOut.appendComponent(className); + LlcOut.appendSuffix("s"); + + sys::Path Prog = sys::Program::FindProgramByName("llc"); + + if (Prog.isEmpty()) { + fprintf(stderr, "Can't find llc.... Abort\n"); + goto cleanup; + } + + const char* llcArgv[8]; + llcArgv[0] = Prog.toString().c_str(); + llcArgv[1] = Out.toString().c_str(); + llcArgv[2] = "-relocation-model=pic"; + llcArgv[3] = "-disable-fp-elim"; + llcArgv[4] = "-f"; + llcArgv[5] = "-o"; + llcArgv[6] = LlcOut.toString().c_str(); + llcArgv[7] = 0; + + res = sys::Program::ExecuteAndWait(Prog, llcArgv); + Out = LlcOut; + } + + if (!res && runGCC) { + sys::Path Prog = sys::Program::FindProgramByName("g++"); + + if (Prog.isEmpty()) { + fprintf(stderr, "Can't find gcc.... Abort\n"); + goto cleanup; + } + + gccArgv[0] = Prog.toString().c_str(); + gccArgv[gccArgc++] = Out.toString().c_str(); + gccArgv[gccArgc++] = LLVMLibs; + gccArgv[gccArgc++] = VMKITLibs1; + gccArgv[gccArgc++] = VMKITLibs2; + gccArgv[gccArgc++] = VMKITLibs3; + gccArgv[gccArgc++] = "-pthread"; + gccArgv[gccArgc++] = "-lgc"; // does not hurt to add it + gccArgv[gccArgc++] = "-lm"; + gccArgv[gccArgc++] = "-ldl"; + gccArgv[gccArgc++] = "-lz"; + gccArgv[gccArgc++] = "-ljnjvm"; + gccArgv[gccArgc++] = "-lvmjc"; + gccArgv[gccArgc++] = "-lLLVMSupport"; + gccArgv[gccArgc++] = 0; + + res = sys::Program::ExecuteAndWait(Prog, gccArgv); + + } + +cleanup: + if (!SaveTemps) + tempDir.eraseFromDisk(true); + + delete gccArgv; + delete vmjcArgv; + free(className); + + return 0; +} + From nicolas.geoffray at lip6.fr Thu Apr 2 07:17:54 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:17:54 -0000 Subject: [vmkit-commits] [vmkit] r68306 - /vmkit/trunk/Makefile.common.in Message-ID: <200904021417.n32EHs0S017577@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:17:54 2009 New Revision: 68306 URL: http://llvm.org/viewvc/llvm-project?rev=68306&view=rev Log: Fix comment. Modified: vmkit/trunk/Makefile.common.in Modified: vmkit/trunk/Makefile.common.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.common.in?rev=68306&r1=68305&r2=68306&view=diff ============================================================================== --- vmkit/trunk/Makefile.common.in (original) +++ vmkit/trunk/Makefile.common.in Thu Apr 2 09:17:54 2009 @@ -32,9 +32,9 @@ # Pnet location PNETLIB = @pnetlocalprefix@ -# GC configuration LIBS += -lz +# GC configuration ifeq ($(GCLIB), BoehmGC) LIBS += -lgc endif From nicolas.geoffray at lip6.fr Thu Apr 2 07:18:18 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:18:18 -0000 Subject: [vmkit-commits] [vmkit] r68307 - /vmkit/trunk/autoconf/configure.ac Message-ID: <200904021418.n32EIIZr017599@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:18:18 2009 New Revision: 68307 URL: http://llvm.org/viewvc/llvm-project?rev=68307&view=rev Log: Add a new file to be configured. Modified: vmkit/trunk/autoconf/configure.ac Modified: vmkit/trunk/autoconf/configure.ac URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/autoconf/configure.ac?rev=68307&r1=68306&r2=68307&view=diff ============================================================================== --- vmkit/trunk/autoconf/configure.ac (original) +++ vmkit/trunk/autoconf/configure.ac Thu Apr 2 09:18:18 2009 @@ -555,6 +555,7 @@ AC_CONFIG_FILES([lib/JnJVM/Classpath/Classpath.h]) AC_CONFIG_FILES([lib/N3/PNetLib/PNetPath.inc]) AC_CONFIG_FILES([lib/N3/Mono/MonoPath.inc]) +AC_CONFIG_FILES([tools/llcj/LinkPaths.h]) dnl Do special configuration of Makefiles AC_CONFIG_MAKEFILE(Makefile) From nicolas.geoffray at lip6.fr Thu Apr 2 07:18:41 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:18:41 -0000 Subject: [vmkit-commits] [vmkit] r68308 - /vmkit/trunk/configure Message-ID: <200904021418.n32EIfoq017622@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:18:41 2009 New Revision: 68308 URL: http://llvm.org/viewvc/llvm-project?rev=68308&view=rev Log: Regenerate. Modified: vmkit/trunk/configure Modified: vmkit/trunk/configure URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/configure?rev=68308&r1=68307&r2=68308&view=diff ============================================================================== --- vmkit/trunk/configure (original) +++ vmkit/trunk/configure Thu Apr 2 09:18:41 2009 @@ -7195,6 +7195,8 @@ ac_config_files="$ac_config_files lib/N3/Mono/MonoPath.inc" +ac_config_files="$ac_config_files tools/llcj/LinkPaths.h" + ac_config_commands="$ac_config_commands Makefile" @@ -7773,6 +7775,7 @@ "lib/JnJVM/Classpath/Classpath.h") CONFIG_FILES="$CONFIG_FILES lib/JnJVM/Classpath/Classpath.h" ;; "lib/N3/PNetLib/PNetPath.inc") CONFIG_FILES="$CONFIG_FILES lib/N3/PNetLib/PNetPath.inc" ;; "lib/N3/Mono/MonoPath.inc") CONFIG_FILES="$CONFIG_FILES lib/N3/Mono/MonoPath.inc" ;; + "tools/llcj/LinkPaths.h") CONFIG_FILES="$CONFIG_FILES tools/llcj/LinkPaths.h" ;; "Makefile") CONFIG_COMMANDS="$CONFIG_COMMANDS Makefile" ;; "lib/Makefile") CONFIG_COMMANDS="$CONFIG_COMMANDS lib/Makefile" ;; From nicolas.geoffray at lip6.fr Thu Apr 2 07:29:30 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:29:30 -0000 Subject: [vmkit-commits] [vmkit] r68309 - /vmkit/trunk/Makefile.rules Message-ID: <200904021429.n32ETUVX018112@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:29:30 2009 New Revision: 68309 URL: http://llvm.org/viewvc/llvm-project?rev=68309&view=rev Log: Add a rule to create archives. Modified: vmkit/trunk/Makefile.rules Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=68309&r1=68308&r2=68309&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Thu Apr 2 09:29:30 2009 @@ -75,3 +75,25 @@ clean-local:: $(Verb) $(RM) -f glibj.zip.s glibj.zip.bc glibj-optimized.zip.bc endif + + + +ifdef VMKIT_BUILD_ARCHIVE + +LibName.A := $(LibDir)/lib$(VMKIT_LIBRARYNAME).a + +all-local:: $(LibName.A) + +$(LibName.A): $(ProjLibsPaths) $(LibDir)/.dir + $(Echo) Building $(BuildMode) Archive Library $(notdir $@) + -$(Verb) $(RM) -f $@ + $(Verb) $(Archive) $@ $(ProjLibsPaths) + $(Verb) $(Ranlib) $@ + +clean-local:: +ifneq ($(strip $(LibName.A)),) + -$(Verb) $(RM) -f $(LibName.A) +endif + +endif + From nicolas.geoffray at lip6.fr Thu Apr 2 07:29:51 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:29:51 -0000 Subject: [vmkit-commits] [vmkit] r68310 - /vmkit/trunk/tools/Makefile Message-ID: <200904021429.n32ETpRX018139@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:29:50 2009 New Revision: 68310 URL: http://llvm.org/viewvc/llvm-project?rev=68310&view=rev Log: Build llcj also. Modified: vmkit/trunk/tools/Makefile Modified: vmkit/trunk/tools/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/Makefile?rev=68310&r1=68309&r2=68310&view=diff ============================================================================== --- vmkit/trunk/tools/Makefile (original) +++ vmkit/trunk/tools/Makefile Thu Apr 2 09:29:50 2009 @@ -15,6 +15,7 @@ ifeq ($(WITH_JNJVM), 1) PARALLEL_DIRS += jnjvm PARALLEL_DIRS += vmjc + PARALLEL_DIRS += llcj endif ifeq ($(WITH_N3_MONO), 1) From nicolas.geoffray at lip6.fr Thu Apr 2 07:30:55 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:30:55 -0000 Subject: [vmkit-commits] [vmkit] r68311 - /vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904021430.n32EUtFw018193@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:30:55 2009 New Revision: 68311 URL: http://llvm.org/viewvc/llvm-project?rev=68311&view=rev Log: Fix call of main function. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=68311&r1=68310&r2=68311&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Thu Apr 2 09:30:55 2009 @@ -1579,9 +1579,6 @@ M->CreateStaticInitializer(); - // Print stats before quitting. - M->printStats(); - } catch(std::string str) { fprintf(stderr, "Error : %s\n", str.c_str()); } @@ -1643,11 +1640,22 @@ Function* MainFunc = Function::Create(FuncTy, GlobalValue::ExternalLinkage, "main", TheModule); BasicBlock* currentBlock = BasicBlock::Create("enter", MainFunc); - + + GlobalVariable* GvarArrayStr = new GlobalVariable( + ArrayType::get(Type::Int8Ty, strlen(name) + 1), true, + GlobalValue::InternalLinkage, 0, "mainClass", TheModule); + + + Constant* NameArray = ConstantArray::get(name, true); + GvarArrayStr->setInitializer(NameArray); + Value* Indices[2] = { JavaIntrinsics.constantZero, + JavaIntrinsics.constantZero }; + Value* ArgName = ConstantExpr::getGetElementPtr(GvarArrayStr, Indices, 2); + Function::arg_iterator FuncVals = MainFunc->arg_begin(); Value* Argc = FuncVals++; Value* Argv = FuncVals++; - Value* Args[3] = { Argc, Argv, ConstantArray::get(name, true) }; + Value* Args[3] = { Argc, Argv, ArgName }; FuncArgs.push_back(Args[2]->getType()); @@ -1655,7 +1663,8 @@ Function* CalledFunc = Function::Create(FuncTy, GlobalValue::ExternalLinkage, - jit ? "StartWithJIT" : "StartWithoutJIT", TheModule); + jit ? "StartJnjvmWithJIT" : "StartJnjvmWithoutJIT", + TheModule); Value* res = CallInst::Create(CalledFunc, Args, Args + 3, "", currentBlock); ReturnInst::Create(res, currentBlock); From nicolas.geoffray at lip6.fr Thu Apr 2 07:31:29 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:31:29 -0000 Subject: [vmkit-commits] [vmkit] r68312 - /vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Message-ID: <200904021431.n32EVUtj018216@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:31:29 2009 New Revision: 68312 URL: http://llvm.org/viewvc/llvm-project?rev=68312&view=rev Log: Args are in char*, not void*. Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=68312&r1=68311&r2=68312&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Apr 2 09:31:29 2009 @@ -1129,7 +1129,7 @@ Collector::initialise(0); char** newArgv = new char*[argc + 1]; - memcpy(newArgv, argv, argc * sizeof(void*)); + memcpy(newArgv, argv, argc * sizeof(char*)); newArgv[argc] = mainClass; JavaCompiler* Comp = new JavaCompiler(); From nicolas.geoffray at lip6.fr Thu Apr 2 07:32:21 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:32:21 -0000 Subject: [vmkit-commits] [vmkit] r68313 - /vmkit/trunk/tools/vmjc/libvmjc/Makefile Message-ID: <200904021432.n32EWLk6018258@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:32:21 2009 New Revision: 68313 URL: http://llvm.org/viewvc/llvm-project?rev=68313&view=rev Log: Remove double assignment. Modified: vmkit/trunk/tools/vmjc/libvmjc/Makefile Modified: vmkit/trunk/tools/vmjc/libvmjc/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/libvmjc/Makefile?rev=68313&r1=68312&r2=68313&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/libvmjc/Makefile (original) +++ vmkit/trunk/tools/vmjc/libvmjc/Makefile Thu Apr 2 09:32:21 2009 @@ -8,9 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL = ../../.. - -LEVEL = ../../.. - include $(LEVEL)/Makefile.config LIBRARYNAME = libvmjc From nicolas.geoffray at lip6.fr Thu Apr 2 07:35:23 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:35:23 -0000 Subject: [vmkit-commits] [vmkit] r68314 - in /vmkit/trunk: include/mvm/VirtualMachine.h lib/JnJVM/VMCore/JavaInitialise.cpp lib/JnJVM/VMCore/JnjvmClassLoader.cpp lib/JnJVM/VMCore/JnjvmClassLoader.h tools/vmjc/vmjc.cpp Message-ID: <200904021435.n32EZNiQ018366@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:35:22 2009 New Revision: 68314 URL: http://llvm.org/viewvc/llvm-project?rev=68314&view=rev Log: Add an argument to the creation of a bootstrap loader to specify that we want the loader to find lbvmjc.so. Modified: vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h vmkit/trunk/tools/vmjc/vmjc.cpp Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=68314&r1=68313&r2=68314&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Thu Apr 2 09:35:22 2009 @@ -56,7 +56,8 @@ /// waitForExit - Wait until the virtual machine stops its execution. virtual void waitForExit() = 0; - static jnjvm::JnjvmClassLoader* initialiseJVM(jnjvm::JavaCompiler* C = 0); + static jnjvm::JnjvmClassLoader* initialiseJVM(jnjvm::JavaCompiler* C, + bool dlLoad = true); static VirtualMachine* createJVM(jnjvm::JnjvmClassLoader* C = 0); static CompilationUnit* initialiseCLIVM(); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=68314&r1=68313&r2=68314&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Thu Apr 2 09:35:22 2009 @@ -74,9 +74,9 @@ #else JnjvmClassLoader* -mvm::VirtualMachine::initialiseJVM(JavaCompiler* Comp) { +mvm::VirtualMachine::initialiseJVM(JavaCompiler* Comp, bool dlLoad) { initialiseVT(); - return gc_new(JnjvmBootstrapLoader)(Comp); + return gc_new(JnjvmBootstrapLoader)(Comp, dlLoad); } mvm::VirtualMachine* mvm::VirtualMachine::createJVM(JnjvmClassLoader* C) { Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=68314&r1=68313&r2=68314&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Thu Apr 2 09:35:22 2009 @@ -63,7 +63,7 @@ typedef void (*static_init_t)(JnjvmClassLoader*); -JnjvmBootstrapLoader::JnjvmBootstrapLoader(JavaCompiler* Comp) { +JnjvmBootstrapLoader::JnjvmBootstrapLoader(JavaCompiler* Comp, bool dlLoad) { hashUTF8 = new(allocator) UTF8Map(allocator, 0); classes = new(allocator) ClassMap(); @@ -164,19 +164,21 @@ // Now that native types have been loaded, try to find if we have a // pre-compiled rt.jar - nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); - if (nativeHandle) { - // Found it! - SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object"); - - if (SuperArray) { - ClassArray::SuperArray = (Class*)SuperArray->getInternal(); - // We have the java/lang/Object class, execute the static initializer. - static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; - assert(init && "Loaded the wrong boot library"); - init(this); - ClassArray::initialiseVT(SuperArray); - } + if (dlLoad) { + nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); + if (nativeHandle) { + // Found it! + SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object"); + + if (SuperArray) { + ClassArray::SuperArray = (Class*)SuperArray->getInternal(); + // We have the java/lang/Object class, execute the static initializer. + static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; + assert(init && "Loaded the wrong boot library"); + init(this); + ClassArray::initialiseVT(SuperArray); + } + } } // We haven't found a pre-compiled rt.jar, load the root class ourself. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=68314&r1=68313&r2=68314&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Thu Apr 2 09:35:22 2009 @@ -337,9 +337,10 @@ void analyseClasspathEnv(const char*); /// createBootstrapLoader - Creates the bootstrap loader, first thing - /// to do before any execution of a JVM. + /// to do before any execution of a JVM. Also try to load libvmjc.so + /// if dlLoad is not false. /// - JnjvmBootstrapLoader(JavaCompiler* Comp); + JnjvmBootstrapLoader(JavaCompiler* Comp, bool dlLoad = true); JnjvmBootstrapLoader() {} virtual JavaString* UTF8ToStr(const UTF8* utf8); Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=68314&r1=68313&r2=68314&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Thu Apr 2 09:35:22 2009 @@ -111,6 +111,11 @@ static cl::opt WithClinit("with-clinit", cl::desc("Clinit the given file")); +static cl::opt +PrintStats("print-aot-stats", + cl::desc("Print stats by the AOT compiler")); + + inline void addPass(FunctionPassManager *PM, Pass *P) { @@ -209,7 +214,7 @@ Collector::initialise(0); Collector::enable(0); - JnjvmClassLoader* JCL = mvm::VirtualMachine::initialiseJVM(Comp); + JnjvmClassLoader* JCL = mvm::VirtualMachine::initialiseJVM(Comp, false); addCommandLinePass(argv); if (!WithClinit.empty()) { @@ -229,6 +234,8 @@ MAOT->generateMain(MainClass.c_str(), WithJIT); } + if (PrintStats) + MAOT->printStats(); if (DontPrint) { // Just use stdout. We won't actually print anything on it. From nicolas.geoffray at lip6.fr Thu Apr 2 07:42:41 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 14:42:41 -0000 Subject: [vmkit-commits] [vmkit] r68315 - /vmkit/trunk/tools/llcj/llcj.cpp Message-ID: <200904021442.n32EggVt018605@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 09:42:41 2009 New Revision: 68315 URL: http://llvm.org/viewvc/llvm-project?rev=68315&view=rev Log: Fix typo. Modified: vmkit/trunk/tools/llcj/llcj.cpp Modified: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=68315&r1=68314&r2=68315&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (original) +++ vmkit/trunk/tools/llcj/llcj.cpp Thu Apr 2 09:42:41 2009 @@ -49,7 +49,7 @@ gccArgv[gccArgc++] = argv[i]; } else if (argv[i][0] == '-' && argv[i][1] == 'o') { gccArgv[gccArgc++] = argv[i++]; - gccArgv[gccArgc] = argv[i]; + gccArgv[gccArgc++] = argv[i]; } else if (argv[i][0] != '-') { char* name = argv[i]; int len = strlen(name); @@ -189,7 +189,7 @@ gccArgv[gccArgc++] = "-lvmjc"; gccArgv[gccArgc++] = "-lLLVMSupport"; gccArgv[gccArgc++] = 0; - + res = sys::Program::ExecuteAndWait(Prog, gccArgv); } From nicolas.geoffray at lip6.fr Thu Apr 2 08:06:38 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 15:06:38 -0000 Subject: [vmkit-commits] [vmkit] r68317 - in /vmkit/trunk: include/jnjvm/JavaCompiler.h lib/JnJVM/Compiler/JITInfo.cpp lib/JnJVM/VMCore/JavaTypes.cpp tools/llcj/llcj.cpp Message-ID: <200904021506.n32F6cxA019513@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 10:06:38 2009 New Revision: 68317 URL: http://llvm.org/viewvc/llvm-project?rev=68317&view=rev Log: Add some code to try dlsym signature callbacks instead of always generating them. Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp vmkit/trunk/tools/llcj/llcj.cpp Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JavaCompiler.h?rev=68317&r1=68316&r2=68317&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JavaCompiler.h (original) +++ vmkit/trunk/include/jnjvm/JavaCompiler.h Thu Apr 2 10:06:38 2009 @@ -34,8 +34,6 @@ } virtual void setMethod(JavaMethod* meth, void* ptr, const char* name) { - fprintf(stderr, "Implement me"); - abort(); } virtual bool isStaticCompiling() { Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=68317&r1=68316&r2=68317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Thu Apr 2 10:06:38 2009 @@ -341,13 +341,13 @@ char* buf = (char*)alloca((signature->keyName->size << 1) + 1 + 11); signature->nativeName(buf, type); res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), - GlobalValue::InternalLinkage, buf, + GlobalValue::ExternalLinkage, buf, Mod->getLLVMModule()); } else { res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), - GlobalValue::InternalLinkage, "", + GlobalValue::ExternalLinkage, "", Mod->getLLVMModule()); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp?rev=68317&r1=68316&r2=68317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaTypes.cpp Thu Apr 2 10:06:38 2009 @@ -105,28 +105,48 @@ intptr_t Signdef::staticCallBuf() { if (!_staticCallBuf) { - initialLoader->getCompiler()->staticCallBuf(this); + char* buf = (char*)alloca((keyName->size << 1) + 1 + 11); + nativeName(buf, "static_buf"); + bool unused = false; + _staticCallBuf = initialLoader->loadInLib(buf, unused); + if (!_staticCallBuf) + initialLoader->getCompiler()->staticCallBuf(this); } return _staticCallBuf; } intptr_t Signdef::virtualCallBuf() { if (!_virtualCallBuf) { - initialLoader->getCompiler()->virtualCallBuf(this); + char* buf = (char*)alloca((keyName->size << 1) + 1 + 11); + nativeName(buf, "virtual_buf"); + bool unused = false; + _virtualCallBuf = initialLoader->loadInLib(buf, unused); + if (!_virtualCallBuf) + initialLoader->getCompiler()->virtualCallBuf(this); } return _virtualCallBuf; } intptr_t Signdef::staticCallAP() { if (!_staticCallAP) { - initialLoader->getCompiler()->staticCallAP(this); + char* buf = (char*)alloca((keyName->size << 1) + 1 + 11); + nativeName(buf, "static_ap"); + bool unused = false; + _staticCallAP = initialLoader->loadInLib(buf, unused); + if (!_staticCallAP) + initialLoader->getCompiler()->staticCallAP(this); } return _staticCallAP; } intptr_t Signdef::virtualCallAP() { if (!_virtualCallAP) { - initialLoader->getCompiler()->virtualCallAP(this); + char* buf = (char*)alloca((keyName->size << 1) + 1 + 11); + nativeName(buf, "virtual_ap"); + bool unused = false; + _virtualCallAP = initialLoader->loadInLib(buf, unused); + if (!_virtualCallAP) + initialLoader->getCompiler()->virtualCallAP(this); } return _virtualCallAP; } Modified: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=68317&r1=68316&r2=68317&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (original) +++ vmkit/trunk/tools/llcj/llcj.cpp Thu Apr 2 10:06:38 2009 @@ -29,10 +29,12 @@ bool runGCC = true; char* className = 0; + bool shared = false; for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-shared")) { gccArgv[gccArgc++] = argv[i]; + shared = true; } else if (!strcmp(argv[i], "-O1") || !strcmp(argv[i], "-O2") || !strcmp(argv[i], "-O3")) { opt = argv[i]; @@ -141,7 +143,13 @@ } if (!res) { - sys::Path LlcOut = tempDir; + sys::Path LlcOut; + + if (runGCC) + LlcOut= tempDir; + else + LlcOut = sys::Path(sys::Path::GetCurrentDirectory()); + LlcOut.appendComponent(className); LlcOut.appendSuffix("s"); @@ -153,14 +161,15 @@ } const char* llcArgv[8]; - llcArgv[0] = Prog.toString().c_str(); - llcArgv[1] = Out.toString().c_str(); - llcArgv[2] = "-relocation-model=pic"; - llcArgv[3] = "-disable-fp-elim"; - llcArgv[4] = "-f"; - llcArgv[5] = "-o"; - llcArgv[6] = LlcOut.toString().c_str(); - llcArgv[7] = 0; + int i = 0; + llcArgv[i++] = Prog.toString().c_str(); + llcArgv[i++] = Out.toString().c_str(); + if (shared) llcArgv[i++] = "-relocation-model=pic"; + llcArgv[i++] = "-disable-fp-elim"; + llcArgv[i++] = "-f"; + llcArgv[i++] = "-o"; + llcArgv[i++] = LlcOut.toString().c_str(); + llcArgv[i++] = 0; res = sys::Program::ExecuteAndWait(Prog, llcArgv); Out = LlcOut; @@ -188,6 +197,7 @@ gccArgv[gccArgc++] = "-ljnjvm"; gccArgv[gccArgc++] = "-lvmjc"; gccArgv[gccArgc++] = "-lLLVMSupport"; + gccArgv[gccArgc++] = "-rdynamic"; gccArgv[gccArgc++] = 0; res = sys::Program::ExecuteAndWait(Prog, gccArgv); From nicolas.geoffray at lip6.fr Thu Apr 2 09:46:06 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 02 Apr 2009 16:46:06 -0000 Subject: [vmkit-commits] [vmkit] r68323 - in /vmkit/trunk: include/jnjvm/JavaCompiler.h lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/JnjvmClassLoader.cpp lib/JnJVM/VMCore/JnjvmClassLoader.h tools/llcj/llcj.cpp Message-ID: <200904021646.n32Gk6BK023785@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 2 11:46:06 2009 New Revision: 68323 URL: http://llvm.org/viewvc/llvm-project?rev=68323&view=rev Log: Add a few turnarounds for running Java executable files. Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h vmkit/trunk/tools/llcj/llcj.cpp Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JavaCompiler.h?rev=68323&r1=68322&r2=68323&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JavaCompiler.h (original) +++ vmkit/trunk/include/jnjvm/JavaCompiler.h Thu Apr 2 11:46:06 2009 @@ -37,8 +37,6 @@ } virtual bool isStaticCompiling() { - fprintf(stderr, "Checking static compilation in an empty compiler"); - abort(); return false; } Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=68323&r1=68322&r2=68323&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Apr 2 11:46:06 2009 @@ -886,8 +886,16 @@ void Jnjvm::executeClass(const char* className, ArrayObject* args) { try { - const UTF8* name = appClassLoader->asciizConstructUTF8(className); - UserClass* cl = (UserClass*)appClassLoader->loadName(name, true, true); + + // First try to see if we are a self-contained executable. + UserClass* cl = appClassLoader->loadClassFromSelf(this, className); + + // If not, load the class. + if (!cl) { + const UTF8* name = appClassLoader->asciizConstructUTF8(className); + cl = (UserClass*)appClassLoader->loadName(name, true, true); + } + cl->initialiseClass(this); const UTF8* funcSign = Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=68323&r1=68322&r2=68323&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Thu Apr 2 11:46:06 2009 @@ -1020,6 +1020,17 @@ } } +Class* JnjvmClassLoader::loadClassFromSelf(Jnjvm* vm, const char* name) { + assert(classes->map.size() == 0); + Class* cl = (Class*)dlsym(SELF_HANDLE, name); + if (cl) { + static_init_t init = (static_init_t)(uintptr_t)cl->classLoader; + init(this); + insertAllMethodsInVM(vm); + } + return cl; +} + // Extern "C" functions called by the vmjc static intializer. extern "C" void vmjcAddPreCompiledClass(JnjvmClassLoader* JCL, Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=68323&r1=68322&r2=68323&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Thu Apr 2 11:46:06 2009 @@ -277,6 +277,10 @@ /// this class file. /// void loadLibFromFile(Jnjvm* vm, const char* name); + + /// loadClassFromSelf - Load the main class if we are an executable. + /// + Class* loadClassFromSelf(Jnjvm* vm, const char* name); }; Modified: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=68323&r1=68322&r2=68323&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (original) +++ vmkit/trunk/tools/llcj/llcj.cpp Thu Apr 2 11:46:06 2009 @@ -197,7 +197,9 @@ gccArgv[gccArgc++] = "-ljnjvm"; gccArgv[gccArgc++] = "-lvmjc"; gccArgv[gccArgc++] = "-lLLVMSupport"; +#if !defined(__MACH__) gccArgv[gccArgc++] = "-rdynamic"; +#endif gccArgv[gccArgc++] = 0; res = sys::Program::ExecuteAndWait(Prog, gccArgv); From nicolas.geoffray at lip6.fr Fri Apr 3 01:40:41 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 03 Apr 2009 08:40:41 -0000 Subject: [vmkit-commits] [vmkit] r68378 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Message-ID: <200904030840.n338efic005890@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 3 03:40:40 2009 New Revision: 68378 URL: http://llvm.org/viewvc/llvm-project?rev=68378&view=rev Log: Do not look at rp if there is no file. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=68378&r1=68377&r2=68378&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Fri Apr 3 03:40:40 2009 @@ -860,7 +860,7 @@ char* rp = (char*)alloca(PATH_MAX); memset(rp, 0, PATH_MAX); rp = realpath(buf, rp); - if (rp[PATH_MAX - 1] == 0 && strlen(rp) != 0) { + if (rp && rp[PATH_MAX - 1] == 0 && strlen(rp) != 0) { struct stat st; stat(rp, &st); if ((st.st_mode & S_IFMT) == S_IFDIR) { From nicolas.geoffray at lip6.fr Fri Apr 3 06:38:24 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 03 Apr 2009 13:38:24 -0000 Subject: [vmkit-commits] [vmkit] r68386 - in /vmkit/trunk/tools/llcj: LinkPaths.h.in Makefile llcj.cpp Message-ID: <200904031338.n33DcWoZ022038@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 3 08:37:56 2009 New Revision: 68386 URL: http://llvm.org/viewvc/llvm-project?rev=68386&view=rev Log: Make room for generating executables with LLVM JIT, but wait until I figure out how to use llvm-config properly. Modified: vmkit/trunk/tools/llcj/LinkPaths.h.in vmkit/trunk/tools/llcj/Makefile vmkit/trunk/tools/llcj/llcj.cpp Modified: vmkit/trunk/tools/llcj/LinkPaths.h.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/LinkPaths.h.in?rev=68386&r1=68385&r2=68386&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/LinkPaths.h.in (original) +++ vmkit/trunk/tools/llcj/LinkPaths.h.in Fri Apr 3 08:37:56 2009 @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// -#define LLVMLibs "-L at LLVM_OBJ@/Release/lib"; -#define VMKITLibs1 "-L at abs_top_objdir@/Release/lib"; -#define VMKITLibs2 "-L at abs_top_srcdir@/Release/lib"; -#define VMKITLibs3 "-L at PROJ_INSTALL_ROOT@/lib"; +#define LLVMLibs "@LLVM_OBJ@" +#define VMKITLibs1 "-L at abs_top_objdir@/Release/lib" +#define VMKITLibs2 "-L at abs_top_srcdir@/Release/lib" +#define VMKITLibs3 "-L at PROJ_INSTALL_ROOT@/lib" Modified: vmkit/trunk/tools/llcj/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/Makefile?rev=68386&r1=68385&r2=68386&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/Makefile (original) +++ vmkit/trunk/tools/llcj/Makefile Fri Apr 3 08:37:56 2009 @@ -8,7 +8,7 @@ ##===----------------------------------------------------------------------===## LEVEL = ../.. -DIRS = libjnjvm +DIRS = libjnjvm libjnjvmjit include $(LEVEL)/Makefile.config Modified: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=68386&r1=68385&r2=68386&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (original) +++ vmkit/trunk/tools/llcj/llcj.cpp Fri Apr 3 08:37:56 2009 @@ -30,11 +30,16 @@ bool runGCC = true; char* className = 0; bool shared = false; + bool withJIT = false; for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-shared")) { gccArgv[gccArgc++] = argv[i]; shared = true; + } else if (!strcmp(argv[i], "-with-jit") || + !strcmp(argv[i], "--with-jit")) { + withJIT = true; + vmjcArgv[vmjcArgc++] = argv[i]; } else if (!strcmp(argv[i], "-O1") || !strcmp(argv[i], "-O2") || !strcmp(argv[i], "-O3")) { opt = argv[i]; @@ -58,9 +63,19 @@ if (len > 4 && (!strcmp(&name[len - 4], ".jar") || !strcmp(&name[len - 4], ".zip"))) { vmjcArgv[vmjcArgc++] = name; + char* slash = strrchr(name, '/'); + if (slash) { + name = slash; + len = strlen(name); + } className = strndup(name, len - 4); } else if (len > 6 && !strcmp(&name[len - 6], ".class")) { vmjcArgv[vmjcArgc++] = name; + char* slash = strrchr(name, '/'); + if (slash) { + name = slash; + len = strlen(name); + } className = strndup(name, len - 6); } else { gccArgv[gccArgc++] = name; @@ -110,9 +125,9 @@ vmjcArgv[vmjcArgc++] = "-f"; vmjcArgv[vmjcArgc++] = "-o"; vmjcArgv[vmjcArgc++] = Out.toString().c_str(); - + res = sys::Program::ExecuteAndWait(Prog, vmjcArgv); - + if (!res && opt) { sys::Path OptOut = tempDir; OptOut.appendComponent("llvmopt"); @@ -185,7 +200,7 @@ gccArgv[0] = Prog.toString().c_str(); gccArgv[gccArgc++] = Out.toString().c_str(); - gccArgv[gccArgc++] = LLVMLibs; + gccArgv[gccArgc++] = "-L"LLVMLibs"/Release/lib"; gccArgv[gccArgc++] = VMKITLibs1; gccArgv[gccArgc++] = VMKITLibs2; gccArgv[gccArgc++] = VMKITLibs3; @@ -194,7 +209,11 @@ gccArgv[gccArgc++] = "-lm"; gccArgv[gccArgc++] = "-ldl"; gccArgv[gccArgc++] = "-lz"; - gccArgv[gccArgc++] = "-ljnjvm"; + if (withJIT) { + gccArgv[gccArgc++] = "-ljnjvmjit"; + } else { + gccArgv[gccArgc++] = "-ljnjvm"; + } gccArgv[gccArgc++] = "-lvmjc"; gccArgv[gccArgc++] = "-lLLVMSupport"; #if !defined(__MACH__) From nicolas.geoffray at lip6.fr Mon Apr 6 07:42:40 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 06 Apr 2009 14:42:40 -0000 Subject: [vmkit-commits] [vmkit] r68444 - /vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Message-ID: <200904061442.n36EghfF003467@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 6 09:42:25 2009 New Revision: 68444 URL: http://llvm.org/viewvc/llvm-project?rev=68444&view=rev Log: Trace threads before tracing their stacks. Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp?rev=68444&r1=68443&r2=68444&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Mon Apr 6 09:42:25 2009 @@ -53,6 +53,16 @@ threads->synchronize(); #endif + mvm::Thread* th = th->get(); + mvm::Thread* tcur = th; + + // First, trace threads. + do { + th->tracer(); + tcur = (mvm::Thread*)tcur->next(); + } while (tcur != th); + + // Then trace stack objects. for(cur=used_nodes->next(); cur!=used_nodes; cur=cur->next()) trace(cur); From nicolas.geoffray at lip6.fr Tue Apr 7 15:00:39 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 07 Apr 2009 22:00:39 -0000 Subject: [vmkit-commits] [vmkit] r68556 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Message-ID: <200904072200.n37M0dQP030107@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 7 17:00:38 2009 New Revision: 68556 URL: http://llvm.org/viewvc/llvm-project?rev=68556&view=rev Log: Fix compilation error. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=68556&r1=68555&r2=68556&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Tue Apr 7 17:00:38 2009 @@ -35,7 +35,7 @@ #include "jnjvm/JnjvmModule.h" -#if DEBUG > 0 && JNJVM_COMPILE > 0 +#if DEBUG > 0 && (JNJVM_COMPILE > 0 || JNJVM_EXECUTE > 0) #include "jnjvm/OpcodeNames.def" #endif From nicolas.geoffray at lip6.fr Wed Apr 8 04:07:08 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 08 Apr 2009 11:07:08 -0000 Subject: [vmkit-commits] [vmkit] r68604 - in /vmkit/trunk: include/mvm/Allocator.h include/mvm/VirtualMachine.h lib/JnJVM/Classpath/ClasspathReflect.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaInitialise.cpp lib/JnJVM/VMCore/JavaThread.h lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h lib/JnJVM/VMCore/JnjvmClassLoader.cpp lib/JnJVM/VMCore/JnjvmClassLoader.h lib/JnJVM/VMCore/VirtualTables.cpp lib/Mvm/GCMmap2/gccollector.cpp lib/N3/VMCore/N3.cpp lib/N3/VMCore/VirtualTables.cpp Message-ID: <200904081107.n38B7C8c006716@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 8 06:06:50 2009 New Revision: 68604 URL: http://llvm.org/viewvc/llvm-project?rev=68604&view=rev Log: Simplify core code in the presence of GC classes. The Jnjvm class and the JnjvmClassloader class are now non-GC allocated. Modified: vmkit/trunk/include/mvm/Allocator.h vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h 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/GCMmap2/gccollector.cpp vmkit/trunk/lib/N3/VMCore/N3.cpp vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp Modified: vmkit/trunk/include/mvm/Allocator.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Allocator.h?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Allocator.h (original) +++ vmkit/trunk/include/mvm/Allocator.h Wed Apr 8 06:06:50 2009 @@ -64,13 +64,14 @@ class BumpPtrAllocator { private: - LockNormal TheLock; + SpinLock TheLock; llvm::BumpPtrAllocator Allocator; public: void* Allocate(size_t sz) { - TheLock.lock(); + TheLock.acquire(); void* res = Allocator.Allocate(sz, sizeof(void*)); - TheLock.unlock(); + TheLock.release(); + memset(res, 0, sz); return res; } Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Wed Apr 8 06:06:50 2009 @@ -33,7 +33,7 @@ /// VirtualMachine - This class is the root of virtual machine classes. It /// defines what a VM should be. /// -class VirtualMachine : public mvm::Object { +class VirtualMachine : public mvm::PermanentObject { protected: VirtualMachine() { @@ -48,7 +48,9 @@ #endif } public: - + + virtual void TRACER {} + /// runApplication - Run an application. The application name is in /// the arguments, hence it is the virtual machine's job to parse them. virtual void runApplication(int argc, char** argv) = 0; Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h Wed Apr 8 06:06:50 2009 @@ -37,7 +37,10 @@ obj->pd->MARK_AND_TRACE; obj->signers->MARK_AND_TRACE; obj->constructor->MARK_AND_TRACE; - if (obj->vmdata) obj->vmdata->classLoader->MARK_AND_TRACE; + if (obj->vmdata) { + JavaObject* Obj = obj->vmdata->classLoader->getJavaClassLoader(); + if (Obj) Obj->MARK_AND_TRACE; + } } }; Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Wed Apr 8 06:06:50 2009 @@ -1611,7 +1611,8 @@ void JavaAOTCompiler::compileFile(JnjvmClassLoader* JCL, const char* n) { name = n; - Jnjvm* vm = gc_new(Jnjvm)((JnjvmBootstrapLoader*)JCL); + mvm::BumpPtrAllocator A; + Jnjvm* vm = new(A) Jnjvm(A, (JnjvmBootstrapLoader*)JCL); JavaThread* th = new JavaThread(0, 0, vm); vm->setBootstrapThread(th); th->start((void (*)(mvm::Thread*))mainCompilerStart); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Wed Apr 8 06:06:50 2009 @@ -739,16 +739,16 @@ void Class::readParents(Reader& reader) { uint16 superEntry = reader.readU2(); - const UTF8* superUTF8 = superEntry ? - ctpInfo->resolveClassName(superEntry) : 0; + // Use the depth field to store the super entry, to not touch super. The + // super field is used during GC scanning and must only be of one type. + depth = superEntry; uint16 nbI = reader.readU2(); - // Use the super field to store the UTF8. since the field is never - // used before actually loading the super, this is harmless. - super = (Class*)superUTF8; // Use the regular interface array to store the UTF8s. Since this array // is never used before actually loading the interfaces, this is harmless. + // During GC scanning, the check is made on super. So the array of + // interfaces is not used if super is null. interfaces = (Class**) classLoader->allocator.Allocate(nbI * sizeof(Class*)); nbInterfaces = nbI; @@ -758,7 +758,13 @@ } void UserClass::loadParents() { - const UTF8* superUTF8 = (const UTF8*)super; + const UTF8* superUTF8 = depth ? ctpInfo->resolveClassName(depth) : 0; + // W prevent the GC from scanning the interfaces until they + // are loaded. So we temporarly consider that this class does not + // have any interfaces. This is harmless because the class is being + // resolved and can not be used elsewhere for getting its interfaces. + uint32 realNbInterfaces = nbInterfaces; + nbInterfaces = 0; if (superUTF8 == 0) { depth = 0; display = (CommonClass**) @@ -774,10 +780,13 @@ display[depth] = this; } - for (unsigned i = 0; i < nbInterfaces; i++) + for (unsigned i = 0; i < realNbInterfaces; i++) interfaces[i] = ((UserClass*)classLoader->loadName((const UTF8*)interfaces[i], true, true)); + + // Interfaces are loaded, put the real number back in place. + nbInterfaces = realNbInterfaces; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Wed Apr 8 06:06:50 2009 @@ -11,8 +11,8 @@ #include "JavaArray.h" #include "JavaObject.h" -#include "JavaThread.h" #include "Jnjvm.h" +#include "JnjvmClassLoader.h" #ifdef ISOLATE_SHARING #include "SharedMaps.h" @@ -32,11 +32,9 @@ X fake; \ X::VT = ((void**)(void*)(&fake))[0]; } - INIT(JavaThread); - INIT(Jnjvm); - INIT(JnjvmBootstrapLoader); - INIT(JnjvmClassLoader); INIT(LockObj); + INIT(VMClassLoader); + #ifdef ISOLATE_SHARING INIT(JnjvmSharedLoader); INIT(SharedClassByteMap); @@ -66,9 +64,11 @@ } mvm::VirtualMachine* mvm::VirtualMachine::createJVM(JnjvClassLoader* JCL) { + mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator(); + mvm::BumpPtrAllocator* C = new mvm::BumpPtrAllocator(); JnjvmBootstraLoader* bootstrapLoader = - gc_new(JnjvmBootstrapLoader)(JCL->getCompiler()); - Jnjvm* vm = gc_new(Jnjvm)(bootstrapLoader); + new(*C) JnjvmBootstrapLoader(*C, JCL->getCompiler()); + Jnjvm* vm = new(*A) Jnjvm(*A, bootstrapLoader); return vm; } #else @@ -76,11 +76,13 @@ JnjvmClassLoader* mvm::VirtualMachine::initialiseJVM(JavaCompiler* Comp, bool dlLoad) { initialiseVT(); - return gc_new(JnjvmBootstrapLoader)(Comp, dlLoad); + mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator(); + return new(*A) JnjvmBootstrapLoader(*A, Comp, dlLoad); } mvm::VirtualMachine* mvm::VirtualMachine::createJVM(JnjvmClassLoader* C) { - Jnjvm* vm = gc_new(Jnjvm)((JnjvmBootstrapLoader*)C); + mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator(); + Jnjvm* vm = new(*A) Jnjvm(*A, (JnjvmBootstrapLoader*)C); return vm; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h Wed Apr 8 06:06:50 2009 @@ -56,11 +56,6 @@ public: - /// VT - The virtual table of JavaThread objects, so that we know - /// if a thread is a JavaThread. - /// - static VirtualTable *VT; - /// jniEnv - The JNI environment of the thread. /// void* jniEnv; @@ -268,12 +263,6 @@ uint32_t eipIndex; #endif - /// isJavaThread - Is the given thread a Java thread? - /// - static bool isJavaThread(mvm::Thread* th) { - return ((void**)th)[0] == VT; - } - }; } // end namespace jnjvm Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Wed Apr 8 06:06:50 2009 @@ -1002,15 +1002,13 @@ static void serviceCPUMonitor(mvm::Thread* th) { while (true) { sleep(1); - for(mvm::Thread* cur = (mvm::Thread*)th->next(); cur != th; - cur = (mvm::Thread*)cur->next()) { - if (JavaThread::isJavaThread(cur)) { + for(JavaThread* cur = (Java*)th->next(); cur != th; + cur = (JavaThread*)cur->next()) { JavaThread* th = (JavaThread*)cur; if (!(th->StateWaiting)) { mvm::VirtualMachine* executingVM = cur->MyVM; assert(executingVM && "Thread with no VM!"); ++executingVM->executionTime; - } } } } @@ -1047,7 +1045,8 @@ } } -Jnjvm::Jnjvm(JnjvmBootstrapLoader* loader) : VirtualMachine() { +Jnjvm::Jnjvm(mvm::BumpPtrAllocator& Alloc, JnjvmBootstrapLoader* loader) : + VirtualMachine(), allocator(Alloc) { classpath = getenv("CLASSPATH"); if (!classpath) classpath = "."; Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Wed Apr 8 06:06:50 2009 @@ -105,7 +105,7 @@ public: /// allocator - Memory allocator of this JVM. /// - mvm::BumpPtrAllocator allocator; + mvm::BumpPtrAllocator& allocator; /// throwable - The java/lang/Throwable class. In an isolate /// environment, generated code references this field. @@ -170,10 +170,6 @@ public: - /// VT - The virtual table of this class. - /// - static VirtualTable* VT; - /// print - Prints the JVM for debugging purposes. /// virtual void print(mvm::PrintBuffer* buf) const; @@ -312,14 +308,6 @@ /// ~Jnjvm(); - /// Jnjvm - Allocate a default JVM, for VT initialization. - /// - Jnjvm() { -#ifdef ISOLATE - IsolateID = 0; -#endif - } - /// addProperty - Adds a new property in the postProperties map. /// void addProperty(char* key, char* value); @@ -332,7 +320,7 @@ /// Jnjvm - Allocates a new JVM. /// - Jnjvm(JnjvmBootstrapLoader* loader); + Jnjvm(mvm::BumpPtrAllocator& Alloc, JnjvmBootstrapLoader* loader); /// runApplication - Runs the application with the given command line. /// User-visible function, inherited by the VirtualMachine class. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Wed Apr 8 06:06:50 2009 @@ -63,7 +63,10 @@ typedef void (*static_init_t)(JnjvmClassLoader*); -JnjvmBootstrapLoader::JnjvmBootstrapLoader(JavaCompiler* Comp, bool dlLoad) { +JnjvmBootstrapLoader::JnjvmBootstrapLoader(mvm::BumpPtrAllocator& Alloc, + JavaCompiler* Comp, + bool dlLoad) : + JnjvmClassLoader(Alloc) { hashUTF8 = new(allocator) UTF8Map(allocator, 0); classes = new(allocator) ClassMap(); @@ -277,8 +280,9 @@ } -JnjvmClassLoader::JnjvmClassLoader(JnjvmClassLoader& JCL, JavaObject* loader, - Jnjvm* I) { +JnjvmClassLoader::JnjvmClassLoader(mvm::BumpPtrAllocator& Alloc, + JnjvmClassLoader& JCL, JavaObject* loader, + Jnjvm* I) : allocator(Alloc) { bootstrapLoader = JCL.bootstrapLoader; TheCompiler = bootstrapLoader->getCompiler()->Create("Applicative loader"); @@ -300,7 +304,7 @@ /// If the appClassLoader is already set in the isolate, then we need /// a new one each time a class loader is allocated. if (isolate->appClassLoader) { - isolate = gc_new(Jnjvm)(bootstrapLoader); + isolate = new Jnjvm(allocator, bootstrapLoader); isolate->memoryLimit = 4000000; isolate->threadLimit = 10; isolate->parent = I->parent; @@ -776,14 +780,25 @@ if (loader == 0) return vm->bootstrapLoader; - + + JnjvmClassLoader* JCL = 0; Classpath* upcalls = vm->bootstrapLoader->upcalls; - JnjvmClassLoader* JCL = - (JnjvmClassLoader*)(upcalls->vmdataClassLoader->getObjectField(loader)); + VMClassLoader* vmdata = + (VMClassLoader*)(upcalls->vmdataClassLoader->getObjectField(loader)); - if (!JCL) { - JCL = gc_new(JnjvmClassLoader)(*vm->bootstrapLoader, loader, vm); - (upcalls->vmdataClassLoader->setObjectField(loader, (JavaObject*)JCL)); + if (!vmdata) { + loader->acquire(); + vmdata = + (VMClassLoader*)(upcalls->vmdataClassLoader->getObjectField(loader)); + if (!vmdata) { + mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator(); + JCL = new(*A) JnjvmClassLoader(*A, *vm->bootstrapLoader, loader, vm); + vmdata = gc_new(VMClassLoader)(JCL); + (upcalls->vmdataClassLoader->setObjectField(loader, (JavaObject*)vmdata)); + } + loader->release(); + } else { + JCL = vmdata->getClassLoader(); } return JCL; @@ -823,7 +838,13 @@ allocator.Deallocate(javaSignatures); } + for (std::vector::iterator i = nativeLibs.begin(); + i < nativeLibs.end(); ++i) { + dlclose(*i); + } + delete TheCompiler; + delete &allocator; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Wed Apr 8 06:06:50 2009 @@ -17,9 +17,7 @@ #include "types.h" #include "mvm/Allocator.h" -#include "mvm/CompilationUnit.h" #include "mvm/Object.h" -#include "mvm/PrintBuffer.h" #include "JnjvmConfig.h" @@ -45,11 +43,12 @@ class UTF8Map; class ZipArchive; + /// JnjvmClassLoader - Runtime representation of a class loader. It contains /// its own tables (signatures, UTF8, types) which are mapped to a single /// table for non-isolate environments. /// -class JnjvmClassLoader : public mvm::Object { +class JnjvmClassLoader : public mvm::PermanentObject { private: /// isolate - Which isolate defined me? Null for the bootstrap class loader. @@ -73,10 +72,13 @@ /// JnjvmClassLoader - Allocate a user-defined class loader. Called on /// first use of a Java class loader. /// - JnjvmClassLoader(JnjvmClassLoader& JCL, JavaObject* loader, Jnjvm* isolate); + JnjvmClassLoader(mvm::BumpPtrAllocator& Alloc, JnjvmClassLoader& JCL, + JavaObject* loader, Jnjvm* isolate); protected: + JnjvmClassLoader(mvm::BumpPtrAllocator& Alloc) : allocator(Alloc) {} + /// TheCompiler - The Java compiler for this class loader. /// JavaCompiler* TheCompiler; @@ -95,14 +97,10 @@ public: - /// VT - The virtual table of this class. - /// - static VirtualTable* VT; - /// allocator - Reference to the memory allocator, which will allocate UTF8s, /// signatures and types. /// - mvm::BumpPtrAllocator allocator; + mvm::BumpPtrAllocator& allocator; /// getIsolate - Returns the isolate that created this class loader. /// @@ -128,12 +126,6 @@ /// virtual void TRACER; - /// print - String representation of the loader for debugging purposes. - /// - virtual void print(mvm::PrintBuffer* buf) const { - buf->write("Java class loader<>"); - } - /// getJnjvmLoaderFromJavaObject - Return the Jnjvm runtime representation /// of the given class loader. /// @@ -212,17 +204,6 @@ /// ~JnjvmClassLoader(); - /// JnjvmClassLoader - Default constructor, zeroes the field. - /// - JnjvmClassLoader() { - hashUTF8 = 0; - javaTypes = 0; - javaSignatures = 0; - TheCompiler = 0; - isolate = 0; - classes = 0; - } - /// loadClass - The user class that defines the loadClass method. /// UserClass* loadClass; @@ -313,20 +294,10 @@ public: - /// VT - The virtual table of this class. - /// - static VirtualTable* VT; - /// tracer - Traces instances of this class. /// virtual void TRACER; - /// print - String representation of the loader, for debugging purposes. - /// - virtual void print(mvm::PrintBuffer* buf) const { - buf->write("Jnjvm bootstrap loader<>"); - } - /// libClasspathEnv - The paths for dynamic libraries of Classpath, separated /// by ':'. /// @@ -344,8 +315,8 @@ /// to do before any execution of a JVM. Also try to load libvmjc.so /// if dlLoad is not false. /// - JnjvmBootstrapLoader(JavaCompiler* Comp, bool dlLoad = true); - JnjvmBootstrapLoader() {} + JnjvmBootstrapLoader(mvm::BumpPtrAllocator& Alloc, JavaCompiler* Comp, + bool dlLoad = true); virtual JavaString* UTF8ToStr(const UTF8* utf8); @@ -418,6 +389,48 @@ ~JnjvmBootstrapLoader(); }; +/// VMClassLoader - The vmdata object that will be placed in and will only +/// be referenced by the java.lang.Classloader Java object. Having a +/// separate class between VMClassLoader and JnjvmClassLoader allows to +/// have a JnjvmClassLoader non-GC object. Also the finalizer of this class +/// will delete the internal class loader and we do not have to implement +/// hacks in the java.lang.Classloader finalizer. +class VMClassLoader : public mvm::Object { +private: + + /// JCL - The internal class loader. + /// + JnjvmClassLoader* JCL; + +public: + + /// VT - The VirtualTable for this GC-class. + static VirtualTable* VT; + + /// TRACER - Trace the internal class loader. + virtual void TRACER { + JCL->CALL_TRACER; + } + + /// ~VMClassLoader - Delete the internal class loader. + /// + ~VMClassLoader() { + if (JCL) JCL->~JnjvmClassLoader(); + } + + /// VMClassLoader - Default constructors. + /// + VMClassLoader(JnjvmClassLoader* J) : JCL(J) {} + VMClassLoader() : JCL(0) {} + + /// getClassLoader - Get the internal class loader. + /// + JnjvmClassLoader* getClassLoader() { + return JCL; + } + +}; + } // end namespace jnjvm #endif // JNJVM_CLASSLOADER_H Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Wed Apr 8 06:06:50 2009 @@ -1,11 +1,24 @@ //===--- VirtualTables.cpp - Virtual methods for JnJVM objects ------------===// // -// JnJVM +// The VMKit project // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// This file contains GC specific tracing functions. It is used by the +// GCMmap2 garbage collector and may be of use for other GCs. Boehm GC does +// not use these functions. +// +// The file is divided into four parts: +// (1) Declaration of internal GC classes. +// (2) Tracing roots of objects: regular object, native array, object array. +// (3) Tracing a class loader, which involves tracing the Java objects +// referenced by classes. +// (4) Tracing the roots of a program: the JVM and the threads. +// +//===----------------------------------------------------------------------===// #include "mvm/Object.h" @@ -21,68 +34,126 @@ using namespace jnjvm; +//===----------------------------------------------------------------------===// +// List of classes that will be GC-allocated. One should try to keep this +// list as minimal as possible, and a GC class must be defined only if +// absolutely necessary. If there is an easy way to avoid it, do it! Only +// Java classes should be GC classes. +// Having many GC classes gives more work to the GC for the scanning phase +// and for the relocation phase (for copying collectors. +// +// In JnJVM, we identified two cases where we really need to declare GC +// classes: the fat lock object and the class loader. +// +// For the fat lock there are many design decisions that we could make to +// make it a non-GC class. We leave this as a TODO. +// +// For the class loader, we decided that this was the best solution because +// otherwise it would involve hacks on the java.lang.Classloader class. +// Therefore, we create a new GC class with a finalize method that will +// delete the internal class loader when the Java object class loader is +// not reachable anymore. This also relies on the java.lang.Classloader class +// referencing an object of type VMClassLoader (this is the case in GNU +// Classpath with the vmdata field). +//===----------------------------------------------------------------------===// + #define INIT(X) VirtualTable* X::VT = 0 - INIT(JavaThread); - INIT(Jnjvm); - INIT(JnjvmBootstrapLoader); - INIT(JnjvmClassLoader); INIT(LockObj); + INIT(VMClassLoader); #undef INIT -void ArrayObject::TRACER { - if (getClass()) getClass()->classLoader->MARK_AND_TRACE; +//===----------------------------------------------------------------------===// +// Root trace methods for Java objects. There are three types of roots: +// (1) Object whose class is not an array: needs to trace the classloader and +// the lock. +// (2) Object whose class is an array of objects: needs to trace root (1) and +// all elements in the array. +// (3) Object whose class is a native array: only needs to trace the lock. The +// classloader is the bootstrap loader and is traced by the JVM. +//===----------------------------------------------------------------------===// + + +/// Method for scanning the root of an object. This method is called by all +/// JavObjects except native Java arrays. +void JavaObject::tracer() { + if (getClass()) getClass()->classLoader->getJavaClassLoader()->markAndTrace(); + LockObj* l = lockObj(); + if (l) l->markAndTrace(); +} + +extern "C" void JavaObjectTracer(JavaObject* obj) { + obj->JavaObject::tracer(); +} + +/// Method for scanning an array whose elements are JavaObjects. This method is +/// called by all non-native Java arrays. +void ArrayObject::tracer() { + JavaObject::tracer(); for (sint32 i = 0; i < size; i++) { if (elements[i]) elements[i]->MARK_AND_TRACE; - } - LockObj* l = lockObj(); - if (l) l->MARK_AND_TRACE; + } } -#ifdef MULTIPLE_GC -extern "C" void ArrayObjectTracer(ArrayObject* obj, Collector* GC) { -#else extern "C" void ArrayObjectTracer(ArrayObject* obj) { -#endif - obj->CALL_TRACER; + obj->ArrayObject::tracer(); +} + +/// Method for scanning a native array. Only scan the lock. The classloader of +/// the class is the bootstrap loader and therefore does not need to be +/// scanned here. +void JavaArray::tracer() { + LockObj* l = lockObj(); + if (l) l->markAndTrace(); } -#ifdef MULTIPLE_GC -extern "C" void JavaArrayTracer(JavaArray* obj, Collector* GC) { -#else extern "C" void JavaArrayTracer(JavaArray* obj) { -#endif - LockObj* l = obj->lockObj(); - if (l) l->MARK_AND_TRACE; + obj->JavaArray::tracer(); } -void JavaArray::TRACER {} -#define TRACE_VECTOR(type,alloc,name) { \ - for (std::vector >::iterator i = name.begin(), \ - e = name.end(); i!= e; ++i) { \ - (*i)->MARK_AND_TRACE; }} +//===----------------------------------------------------------------------===// +// Support for scanning Java objects referenced by classes. All classes must +// trace: +// (1) The classloader of the parents (super and interfaces) as well as its +// own class loader. +// (2) The delegatee object (java.lang.Class) if it exists. +// +// Additionaly, non-primitive and non-array classes mus trace: +// (3) The bytes that represent the class file. +// (4) The static instance. +// (5) The class loaders referenced indirectly in the class file (TODO). +//===----------------------------------------------------------------------===// + -void CommonClass::TRACER { - if (super) super->classLoader->MARK_AND_TRACE; - for (uint32 i = 0; i < nbInterfaces; ++i) { - interfaces[i]->classLoader->MARK_AND_TRACE; +void CommonClass::tracer() { + + if (super && super->classLoader) { + JavaObject* Obj = super->classLoader->getJavaClassLoader(); + if (Obj) Obj->markAndTrace(); + + for (uint32 i = 0; i < nbInterfaces; ++i) { + if (interfaces[i]->classLoader) + interfaces[i]->classLoader->getJavaClassLoader()->markAndTrace(); + } } - classLoader->MARK_AND_TRACE; + + if (classLoader) + classLoader->getJavaClassLoader()->markAndTrace(); + for (uint32 i = 0; i < NR_ISOLATES; ++i) { // If the delegatee was static allocated, we want to trace its fields. if (delegatee[i]) { - delegatee[i]->CALL_TRACER; - delegatee[i]->MARK_AND_TRACE; + delegatee[i]->tracer(); + delegatee[i]->markAndTrace(); } } - } -void Class::TRACER { - CommonClass::CALL_TRACER; - bytes->MARK_AND_TRACE; +void Class::tracer() { + CommonClass::tracer(); + bytes->markAndTrace(); for (uint32 i =0; i < NR_ISOLATES; ++i) { TaskClassMirror &M = IsolateInfo[i]; @@ -92,88 +163,47 @@ } } -void JavaObject::TRACER { - if (getClass()) getClass()->classLoader->MARK_AND_TRACE; - LockObj* l = lockObj(); - if (l) l->MARK_AND_TRACE; -} - -#ifdef MULTIPLE_GC -extern "C" void JavaObjectTracer(JavaObject* obj, Collector* GC) { -#else -extern "C" void JavaObjectTracer(JavaObject* obj) { -#endif - if (obj->getClass()) obj->getClass()->classLoader->MARK_AND_TRACE; - LockObj* l = obj->lockObj(); - if (l) l->MARK_AND_TRACE; -} +//===----------------------------------------------------------------------===// +// Support for scanning a classloader. A classloader must trace: +// (1) All the classes it has loaded. +// (2) All the strings referenced in class files. +// +// The class loader does not need to trace its java.lang.Classloader Java object +// because if we end up here, this means that the Java object is already being +// scanned. Only the Java object traces the class loader. +// +// Additionaly, the bootstrap loader must trace: +// (3) The delegatees of native array classes. Since these classes are not in +// the class map and they are not GC-allocated, we must trace the objects +// referenced by the delegatees. +//===----------------------------------------------------------------------===// -static void traceClassMap(ClassMap* classes) { +void JnjvmClassLoader::tracer() { + for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end(); i!= e; ++i) { CommonClass* cl = i->second; - if (cl->isClass()) cl->asClass()->CALL_TRACER; - else cl->CALL_TRACER; + if (cl->isClass()) cl->asClass()->tracer(); + else cl->tracer(); } -} - -void JavaThread::TRACER { - javaThread->MARK_AND_TRACE; - if (pendingException) pendingException->MARK_AND_TRACE; -#ifdef SERVICE - ServiceException->MARK_AND_TRACE; -#endif -} - -void Jnjvm::TRACER { - appClassLoader->MARK_AND_TRACE; - TRACE_VECTOR(JavaObject*, gc_allocator, globalRefs); - bootstrapLoader->MARK_AND_TRACE; -#if defined(ISOLATE_SHARING) - JnjvmSharedLoader::sharedLoader->MARK_AND_TRACE; -#endif - mvm::Thread* th = th->get(); - th->CALL_TRACER; - for (mvm::Thread* cur = (mvm::Thread*)th->next(); cur != th; - cur = (mvm::Thread*)cur->next()) { - cur->CALL_TRACER; - } - -#ifdef SERVICE - parent->MARK_AND_TRACE; -#endif -} - -void JnjvmClassLoader::TRACER { - javaLoader->MARK_AND_TRACE; - traceClassMap(classes); - isolate->MARK_AND_TRACE; for (std::vector >::iterator i = strings.begin(), e = strings.end(); i!= e; ++i) { - (*i)->MARK_AND_TRACE; + (*i)->markAndTrace(); // If the string was static allocated, we want to trace its lock. LockObj* l = (*i)->lockObj(); - if (l) l->MARK_AND_TRACE; + if (l) l->markAndTrace(); } + } -void JnjvmBootstrapLoader::TRACER { - - traceClassMap(classes); - - for (std::vector >::iterator i = - bootstrapLoader->strings.begin(), - e = bootstrapLoader->strings.end(); i!= e; ++i) { - (*i)->MARK_AND_TRACE; - // If the string was static allocated, we want to trace its lock. - LockObj* l = (*i)->lockObj(); - if (l) l->MARK_AND_TRACE; - } +void JnjvmBootstrapLoader::tracer() { + + JnjvmClassLoader::tracer(); #define TRACE_DELEGATEE(prim) \ - prim->CALL_TRACER; + prim->tracer(); TRACE_DELEGATEE(upcalls->OfVoid); TRACE_DELEGATEE(upcalls->OfBool); @@ -186,3 +216,44 @@ TRACE_DELEGATEE(upcalls->OfDouble); #undef TRACE_DELEGATEE } + +//===----------------------------------------------------------------------===// +// Support for scanning the roots of a program: JVM and threads. The JVM +// must trace: +// (1) The bootstrap class loader: where core classes live. +// (2) The applicative class loader: the JVM may be the ony one referencing it. +// (3) Global references from JNI. +// +// The threads must trace: +// (1) Their stack (already done by the GC in the case of GCMmap2 or Boehm) +// (2) Their pending exception if there is one. +// (3) The java.lang.Thread delegate. +//===----------------------------------------------------------------------===// + + +void Jnjvm::tracer() { + bootstrapLoader->tracer(); + + appClassLoader->getJavaClassLoader()->markAndTrace(); + + for (std::vector >::iterator + i = globalRefs.begin(), e = globalRefs.end(); i!= e; ++i) { + (*i)->markAndTrace(); + } + +#if defined(ISOLATE_SHARING) + JnjvmSharedLoader::sharedLoader->markAndTrace(); +#endif + +#ifdef SERVICE + parent->tracer(); +#endif +} + +void JavaThread::tracer() { + if (pendingException) pendingException->markAndTrace(); + javaThread->markAndTrace(); +#ifdef SERVICE + ServiceException->markAndTrace(); +#endif +} Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Wed Apr 8 06:06:50 2009 @@ -56,13 +56,16 @@ mvm::Thread* th = th->get(); mvm::Thread* tcur = th; - // First, trace threads. + // First, trace the VM. + th->MyVM->tracer(); + + // Second, trace the threads. do { th->tracer(); tcur = (mvm::Thread*)tcur->next(); } while (tcur != th); - // Then trace stack objects. + // Third, trace stack objects. for(cur=used_nodes->next(); cur!=used_nodes; cur=cur->next()) trace(cur); Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3.cpp Wed Apr 8 06:06:50 2009 @@ -58,7 +58,8 @@ } N3* N3::allocateBootstrap() { - N3 *vm= gc_new(N3)(); + mvm::BumpPtrAllocator * A = new mvm::BumpPtrAllocator(); + N3 *vm= new(*A) N3(); std::string str = mvm::MvmModule::executionEngine->getTargetData()->getStringRepresentation(); @@ -82,7 +83,8 @@ N3* N3::allocate(const char* name, N3* parent) { - N3 *vm= gc_new(N3)(); + mvm::BumpPtrAllocator * A = new mvm::BumpPtrAllocator(); + N3 *vm= new(*A) N3(); std::string str = mvm::MvmModule::executionEngine->getTargetData()->getStringRepresentation(); Modified: vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp?rev=68604&r1=68603&r2=68604&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp Wed Apr 8 06:06:50 2009 @@ -156,7 +156,7 @@ TRACE_VECTOR(VMField*, staticFields, std::allocator); delegatee->MARK_AND_TRACE; TRACE_VECTOR(VMCommonClass*, display, std::allocator); - vm->MARK_AND_TRACE; + vm->CALL_TRACER; assembly->MARK_AND_TRACE; //funcs->MARK_AND_TRACE; @@ -227,7 +227,7 @@ void VMThread::TRACER { vmThread->MARK_AND_TRACE; - vm->MARK_AND_TRACE; + vm->CALL_TRACER; //lock->MARK_AND_TRACE; //varcond->MARK_AND_TRACE; pendingException->MARK_AND_TRACE; @@ -270,7 +270,7 @@ rsrcSection->MARK_AND_TRACE; relocSection->MARK_AND_TRACE; CLIHeader->MARK_AND_TRACE; - vm->MARK_AND_TRACE; + vm->CALL_TRACER; delegatee->MARK_AND_TRACE; // TODO trace assembly refs... } From nicolas.geoffray at lip6.fr Wed Apr 8 04:57:17 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 08 Apr 2009 11:57:17 -0000 Subject: [vmkit-commits] [vmkit] r68605 - /vmkit/trunk/tools/llcj/llcj.cpp Message-ID: <200904081157.n38BvIEw008505@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 8 06:57:13 2009 New Revision: 68605 URL: http://llvm.org/viewvc/llvm-project?rev=68605&view=rev Log: Don't use the non-portable strndup. Modified: vmkit/trunk/tools/llcj/llcj.cpp Modified: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=68605&r1=68604&r2=68605&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (original) +++ vmkit/trunk/tools/llcj/llcj.cpp Wed Apr 8 06:57:13 2009 @@ -68,7 +68,8 @@ name = slash; len = strlen(name); } - className = strndup(name, len - 4); + className = strdup(name); + className[len - 4] = 0; } else if (len > 6 && !strcmp(&name[len - 6], ".class")) { vmjcArgv[vmjcArgc++] = name; char* slash = strrchr(name, '/'); @@ -76,7 +77,8 @@ name = slash; len = strlen(name); } - className = strndup(name, len - 6); + className = strdup(name); + className[len - 6] = 0; } else { gccArgv[gccArgc++] = name; } From nicolas.geoffray at lip6.fr Wed Apr 8 04:58:43 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 08 Apr 2009 11:58:43 -0000 Subject: [vmkit-commits] [vmkit] r68606 - in /vmkit/trunk/tools/llcj/libjnjvmjit: ./ Makefile Message-ID: <200904081158.n38BwikE008568@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 8 06:58:43 2009 New Revision: 68606 URL: http://llvm.org/viewvc/llvm-project?rev=68606&view=rev Log: Forgot these files while implementing llcj. Added: vmkit/trunk/tools/llcj/libjnjvmjit/ vmkit/trunk/tools/llcj/libjnjvmjit/Makefile (with props) Added: vmkit/trunk/tools/llcj/libjnjvmjit/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/libjnjvmjit/Makefile?rev=68606&view=auto ============================================================================== --- vmkit/trunk/tools/llcj/libjnjvmjit/Makefile (added) +++ vmkit/trunk/tools/llcj/libjnjvmjit/Makefile Wed Apr 8 06:58:43 2009 @@ -0,0 +1,18 @@ +##===- tools/llcj/libjnjvm/Makefile-------------------------*- Makefile -*-===## +# +# The vmkit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../../.. + +include $(LEVEL)/Makefile.config + +VMKIT_LIBRARYNAME = jnjvmjit +VMKIT_BUILD_ARCHIVE = 1 +USEDLIBS = Allocator CommonThread Mvm JnJVM Classpath $(GCLIB) MvmCompiler \ + JnjvmCompiler + +include $(LEVEL)/Makefile.common Propchange: vmkit/trunk/tools/llcj/libjnjvmjit/Makefile ------------------------------------------------------------------------------ svn:executable = * From nicolas.geoffray at lip6.fr Wed Apr 8 06:56:39 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 08 Apr 2009 13:56:39 -0000 Subject: [vmkit-commits] [vmkit] r68608 - in /vmkit/trunk: include/mvm/JIT.h include/mvm/Threads/Locks.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/Compiler/JavaJIT.cpp lib/JnJVM/Compiler/JavaJITOpcodes.cpp lib/Mvm/Compiler/JIT.cpp Message-ID: <200904081356.n38Duf2v013256@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 8 08:56:36 2009 New Revision: 68608 URL: http://llvm.org/viewvc/llvm-project?rev=68608&view=rev Log: Put back thin locks instead of biased locks because we need safe points for a correct implementation. Modified: vmkit/trunk/include/mvm/JIT.h vmkit/trunk/include/mvm/Threads/Locks.h vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=68608&r1=68607&r2=68608&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Wed Apr 8 08:56:36 2009 @@ -109,6 +109,7 @@ llvm::Function* llvm_atomic_lcs_i16; llvm::Function* llvm_atomic_lcs_i32; llvm::Function* llvm_atomic_lcs_i64; + llvm::Function* llvm_atomic_lcs_ptr; static llvm::ConstantInt* constantInt8Zero; @@ -151,9 +152,9 @@ static llvm::Constant* constantPtrNull; static llvm::ConstantInt* constantPtrSize; static llvm::ConstantInt* constantThreadIDMask; - static llvm::ConstantInt* constantLockedMask; - static llvm::ConstantInt* constantThreadFreeMask; + static llvm::ConstantInt* constantFatMask; static llvm::ConstantInt* constantPtrOne; + static llvm::ConstantInt* constantPtrZero; static const llvm::PointerType* ptrType; static const llvm::PointerType* ptr32Type; static const llvm::PointerType* ptrPtrType; Modified: vmkit/trunk/include/mvm/Threads/Locks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Locks.h?rev=68608&r1=68607&r2=68608&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Locks.h (original) +++ vmkit/trunk/include/mvm/Threads/Locks.h Wed Apr 8 08:56:36 2009 @@ -148,13 +148,10 @@ #endif static const uint64_t ThinMask = 0x7FFFFF00; - static const uint64_t ReservedMask = 0X7FFFFFFF; static const uint64_t ThinCountMask = 0xFF; -/// ThinLock - This class is an implementation of thin locks with reservation. -/// The creator of the lock reserves this lock so that a lock only needs -/// a comparison and not an expensive compare and swap. The template class +/// ThinLock - This class is an implementation of thin locks. The template class /// TFatLock is a virtual machine specific fat lock. /// template @@ -166,7 +163,7 @@ /// we have reached 0xFF locks. void overflowThinLock(Owner* O = 0) { TFatLock* obj = TFatLock::allocate(O); - obj->acquireAll(256); + obj->acquireAll(257); lock = ((uintptr_t)obj >> 1) | FatMask; } @@ -174,7 +171,7 @@ /// creating this lock. /// void initialise() { - lock = (uintptr_t)mvm::Thread::get()->getThreadID(); + lock = 0; } /// ThinLock - Calls initialize. @@ -188,65 +185,54 @@ TFatLock* changeToFatlock(Owner* O) { if (!(lock & FatMask)) { TFatLock* obj = TFatLock::allocate(O); - uintptr_t val = ((uintptr_t)obj >> 1) | FatMask; - uint32 count = lock & ThinCountMask; - obj->acquireAll(count); + uint32 val = (((uint32) obj) >> 1) | FatMask; + uint32 count = lock & 0xFF; + obj->acquireAll(count + 1); lock = val; return obj; } else { return (TFatLock*)(lock << 1); } } - /// acquire - Acquire the lock. void acquire(Owner* O = 0) { uint64_t id = mvm::Thread::get()->getThreadID(); - if ((lock & ReservedMask) == id) { - lock |= 1; - } else if ((lock & ThinMask) == id) { - if ((lock & ThinCountMask) == ThinCountMask) { - overflowThinLock(O); - } else { - ++lock; - } - } else { - uintptr_t currentLock = lock & ThinMask; - uintptr_t val = - (uintptr_t)__sync_val_compare_and_swap((uintptr_t)&lock, currentLock, - (id + 1)); - if (val != currentLock) { - if (val & FatMask) { -end: - //fat lock! - TFatLock* obj = (TFatLock*)(lock << 1); - obj->acquire(); + uintptr_t val = __sync_val_compare_and_swap((uintptr_t)&lock, 0, id); + + if (val != 0) { + //fat! + if (!(val & FatMask)) { + if ((val & ThinMask) == id) { + if ((val & ThinCountMask) != ThinCountMask) { + lock++; + } else { + overflowThinLock(O); + } } else { TFatLock* obj = TFatLock::allocate(O); - val = ((uintptr_t)obj >> 1) | FatMask; - uint32 count = 0; + uintptr_t val = ((uintptr_t)obj >> 1) | FatMask; loop: - if (lock & FatMask) goto end; - - while ((lock & ThinCountMask) != 0) { + uint32 count = 0; + while (lock) { if (lock & FatMask) { #ifdef USE_GC_BOEHM delete obj; #endif goto end; } - else { - mvm::Thread::yield(&count); - } + else mvm::Thread::yield(&count); } - currentLock = lock & ThinMask; - uintptr_t test = - (uintptr_t)__sync_val_compare_and_swap((uintptr_t)&lock, - currentLock, val); - if (test != currentLock) goto loop; + uintptr_t test = __sync_val_compare_and_swap((uintptr_t*)&lock, 0, val); + if (test) goto loop; obj->acquire(); } + } else { + +end: + TFatLock* obj = (TFatLock*)(lock << 1); + obj->acquire(); } } } @@ -254,12 +240,14 @@ /// release - Release the lock. void release() { uint64 id = mvm::Thread::get()->getThreadID(); - if ((lock & ThinMask) == id) { - --lock; - } else { + if (lock == id) { + lock = 0; + } else if (lock & FatMask) { TFatLock* obj = (TFatLock*)(lock << 1); obj->release(); - } + } else { + lock--; + } } /// broadcast - Wakes up all threads waiting for this lock. @@ -283,7 +271,8 @@ /// lock. bool owner() { uint64 id = mvm::Thread::get()->getThreadID(); - if ((lock & ThinMask) == id) return true; + if (id == lock) return true; + if ((lock & 0x7FFFFF00) == id) return true; if (lock & FatMask) { TFatLock* obj = (TFatLock*)(lock << 1); return obj->owner(); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=68608&r1=68607&r2=68608&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Wed Apr 8 08:56:36 2009 @@ -384,8 +384,7 @@ Elmts.push_back(Cl); // lock - Constant* L = ConstantInt::get(Type::Int64Ty, - mvm::Thread::get()->getThreadID()); + Constant* L = ConstantInt::get(Type::Int64Ty, 0); Elmts.push_back(ConstantExpr::getIntToPtr(L, JnjvmModule::ptrType)); return ConstantStruct::get(STy, Elmts); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=68608&r1=68607&r2=68608&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Wed Apr 8 08:56:36 2009 @@ -386,85 +386,154 @@ return llvmFunction; } - void JavaJIT::monitorEnter(Value* obj) { - - Value* gep[2] = { module->constantZero, - module->JavaObjectLockOffsetConstant }; - Value* lockPtr = GetElementPtrInst::Create(obj, gep, gep + 2, "", + std::vector gep; + gep.push_back(module->constantZero); + gep.push_back(module->JavaObjectLockOffsetConstant); + Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", currentBlock); - Value* lock = new LoadInst(lockPtr, "", currentBlock); - lock = new PtrToIntInst(lock, module->pointerSizeType, "", currentBlock); - Value* lockMask = BinaryOperator::CreateAnd(lock, - module->constantThreadFreeMask, - "", currentBlock); + lockPtr = new BitCastInst(lockPtr, + PointerType::getUnqual(module->pointerSizeType), + "", currentBlock); Value* threadId = getCurrentThread(); threadId = new PtrToIntInst(threadId, module->pointerSizeType, "", currentBlock); + + std::vector atomicArgs; + atomicArgs.push_back(lockPtr); + atomicArgs.push_back(module->constantPtrZero); + atomicArgs.push_back(threadId); + + // Do the atomic compare and swap. + Value* atomic = CallInst::Create(module->llvm_atomic_lcs_ptr, + atomicArgs.begin(), atomicArgs.end(), "", + currentBlock); - Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lockMask, threadId, "", - currentBlock); + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, atomic, module->constantPtrZero, + "", currentBlock); - BasicBlock* ThinLockBB = createBasicBlock("thread local"); + BasicBlock* OK = createBasicBlock("synchronize passed"); + BasicBlock* NotOK = createBasicBlock("synchronize did not pass"); BasicBlock* FatLockBB = createBasicBlock("fat lock"); - BasicBlock* EndLockBB = createBasicBlock("End lock"); + BasicBlock* ThinLockBB = createBasicBlock("thin lock"); + + BranchInst::Create(OK, NotOK, cmp, currentBlock); + + currentBlock = NotOK; + + // The compare and swap did not pass, look if it's a thin lock + Value* isThin = BinaryOperator::CreateAnd(atomic, module->constantFatMask, "", + currentBlock); + cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantZero, "", + currentBlock); BranchInst::Create(ThinLockBB, FatLockBB, cmp, currentBlock); + // It's a thin lock. Look if we're the owner of this lock. currentBlock = ThinLockBB; - Value* increment = BinaryOperator::CreateAdd(lock, module->constantPtrOne, "", - currentBlock); - increment = new IntToPtrInst(increment, module->ptrType, "", currentBlock); - new StoreInst(increment, lockPtr, false, currentBlock); - BranchInst::Create(EndLockBB, currentBlock); + Value* idMask = ConstantInt::get(module->pointerSizeType, 0x7FFFFF00); + Value* cptMask = ConstantInt::get(module->pointerSizeType, 0xFF); + Value* IdInLock = BinaryOperator::CreateAnd(atomic, idMask, "", currentBlock); + Value* owner = new ICmpInst(ICmpInst::ICMP_EQ, threadId, IdInLock, "", + currentBlock); + + BasicBlock* OwnerBB = createBasicBlock("owner thread"); + + BranchInst::Create(OwnerBB, FatLockBB, owner, currentBlock); + currentBlock = OwnerBB; + + // OK, we are the owner, now check if the counter will overflow. + Value* count = BinaryOperator::CreateAnd(atomic, cptMask, "", currentBlock); + cmp = new ICmpInst(ICmpInst::ICMP_ULT, count, cptMask, "", currentBlock); + + BasicBlock* IncCounterBB = createBasicBlock("Increment counter"); + BasicBlock* OverflowCounterBB = createBasicBlock("Overflow counter"); + + BranchInst::Create(IncCounterBB, OverflowCounterBB, cmp, currentBlock); + currentBlock = IncCounterBB; + + // The counter will not overflow, increment it. + Value* Add = BinaryOperator::CreateAdd(module->constantPtrOne, atomic, "", + currentBlock); + new StoreInst(Add, lockPtr, false, currentBlock); + BranchInst::Create(OK, currentBlock); + currentBlock = OverflowCounterBB; + + // The counter will overflow, call this function to create a new lock, + // lock it 0x101 times, and pass. + CallInst::Create(module->OverflowThinLockFunction, obj, "", + currentBlock); + BranchInst::Create(OK, currentBlock); + currentBlock = FatLockBB; - // Either it's a fat lock or there is contention or it's not thread local or - // it's locked at least once. + // Either it's a fat lock or there is contention. CallInst::Create(module->AquireObjectFunction, obj, "", currentBlock); - - BranchInst::Create(EndLockBB, currentBlock); - currentBlock = EndLockBB; + BranchInst::Create(OK, currentBlock); + currentBlock = OK; } void JavaJIT::monitorExit(Value* obj) { - Value* gep[2] = { module->constantZero, - module->JavaObjectLockOffsetConstant }; - Value* lockPtr = GetElementPtrInst::Create(obj, gep, gep + 2, "", + std::vector gep; + gep.push_back(module->constantZero); + gep.push_back(module->JavaObjectLockOffsetConstant); + Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", currentBlock); + lockPtr = new BitCastInst(lockPtr, + PointerType::getUnqual(module->pointerSizeType), + "", currentBlock); Value* lock = new LoadInst(lockPtr, "", currentBlock); - lock = new PtrToIntInst(lock, module->pointerSizeType, "", currentBlock); - Value* lockMask = BinaryOperator::CreateAnd(lock, module->constantLockedMask, - "", currentBlock); + Value* threadId = getCurrentThread(); threadId = new PtrToIntInst(threadId, module->pointerSizeType, "", currentBlock); - Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lockMask, threadId, "", + + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lock, threadId, "", currentBlock); BasicBlock* EndUnlock = createBasicBlock("end unlock"); - BasicBlock* ThinLockBB = createBasicBlock("desynchronize thin lock"); + BasicBlock* LockedOnceBB = createBasicBlock("desynchronize thin lock"); + BasicBlock* NotLockedOnceBB = + createBasicBlock("simple desynchronize did not pass"); BasicBlock* FatLockBB = createBasicBlock("fat lock"); + BasicBlock* ThinLockBB = createBasicBlock("thin lock"); + + BranchInst::Create(LockedOnceBB, NotLockedOnceBB, cmp, currentBlock); + + // Locked once, set zero + currentBlock = LockedOnceBB; + new StoreInst(module->constantPtrZero, lockPtr, false, currentBlock); + BranchInst::Create(EndUnlock, currentBlock); + + currentBlock = NotLockedOnceBB; + // Look if the lock is thin. + Value* isThin = BinaryOperator::CreateAnd(lock, module->constantFatMask, "", + currentBlock); + cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantPtrZero, "", + currentBlock); BranchInst::Create(ThinLockBB, FatLockBB, cmp, currentBlock); - // Locked by the thread, decrement. currentBlock = ThinLockBB; - Value* decrement = BinaryOperator::CreateSub(lock, module->constantPtrOne, "", - currentBlock); - decrement = new IntToPtrInst(decrement, module->ptrType, "", currentBlock); - new StoreInst(decrement, lockPtr, false, currentBlock); + + // Decrement the counter. + Value* Sub = BinaryOperator::CreateSub(lock, module->constantPtrOne, "", + currentBlock); + new StoreInst(Sub, lockPtr, false, currentBlock); BranchInst::Create(EndUnlock, currentBlock); - // Either it's a fat lock or there is contention or it's not thread local. currentBlock = FatLockBB; + + // Either it's a fat lock or there is contention. CallInst::Create(module->ReleaseObjectFunction, obj, "", currentBlock); BranchInst::Create(EndUnlock, currentBlock); currentBlock = EndUnlock; } + + #ifdef ISOLATE_SHARING Value* JavaJIT::getStaticInstanceCtp() { Value* cl = getClassCtp(); @@ -1517,14 +1586,6 @@ Cl = new BitCastInst(Cl, module->JavaCommonClassType, "", currentBlock); new StoreInst(Cl, GEP, currentBlock); - Value* gep2[2] = { module->constantZero, - module->JavaObjectLockOffsetConstant }; - Value* lockPtr = GetElementPtrInst::Create(val, gep2, gep2 + 2, "", - currentBlock); - Value* threadId = getCurrentThread(); - threadId = new BitCastInst(threadId, module->ptrType, "", currentBlock); - new StoreInst(threadId, lockPtr, currentBlock); - push(val, false); } Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=68608&r1=68607&r2=68608&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Wed Apr 8 08:56:36 2009 @@ -1950,16 +1950,6 @@ GEP = GetElementPtrInst::Create(res, gep, gep + 2, "", currentBlock); new StoreInst(valCl, GEP, currentBlock); - Value* gep1[2] = { module->constantZero, - module->JavaObjectLockOffsetConstant }; - Value* lockPtr = GetElementPtrInst::Create(res, gep1, gep1 + 2, - "", currentBlock); - Value* threadId = getCurrentThread(); - - threadId = new BitCastInst(threadId, module->ptrType, "", currentBlock); - - new StoreInst(threadId, lockPtr, currentBlock); - push(res, false); break; Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=68608&r1=68607&r2=68608&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Wed Apr 8 08:56:36 2009 @@ -117,9 +117,10 @@ constantDoubleMinusZero = ConstantFP::get(Type::DoubleTy, -0.0); constantFloatMinusZero = ConstantFP::get(Type::FloatTy, -0.0f); constantThreadIDMask = ConstantInt::get(pointerSizeType, mvm::Thread::IDMask); - constantLockedMask = ConstantInt::get(pointerSizeType, ThinMask); - constantThreadFreeMask = ConstantInt::get(pointerSizeType, ReservedMask); + constantFatMask = ConstantInt::get(pointerSizeType, + pointerSizeType == Type::Int32Ty ? 0x80000000 : 0x8000000000000000LL); constantPtrOne = ConstantInt::get(pointerSizeType, 1); + constantPtrZero = ConstantInt::get(pointerSizeType, 0); constantPtrNull = Constant::getNullValue(ptrType); constantPtrSize = ConstantInt::get(Type::Int32Ty, sizeof(void*)); @@ -189,6 +190,9 @@ llvm_atomic_lcs_i16 = module->getFunction("llvm.atomic.cmp.swap.i16.p0i16"); llvm_atomic_lcs_i32 = module->getFunction("llvm.atomic.cmp.swap.i32.p0i32"); llvm_atomic_lcs_i64 = module->getFunction("llvm.atomic.cmp.swap.i64.p0i64"); + + llvm_atomic_lcs_ptr = pointerSizeType == Type::Int32Ty ? llvm_atomic_lcs_i32 : + llvm_atomic_lcs_i64; } @@ -232,9 +236,9 @@ llvm::Constant* MvmModule::constantPtrNull; llvm::ConstantInt* MvmModule::constantPtrSize; llvm::ConstantInt* MvmModule::constantThreadIDMask; -llvm::ConstantInt* MvmModule::constantLockedMask; -llvm::ConstantInt* MvmModule::constantThreadFreeMask; +llvm::ConstantInt* MvmModule::constantFatMask; llvm::ConstantInt* MvmModule::constantPtrOne; +llvm::ConstantInt* MvmModule::constantPtrZero; const llvm::PointerType* MvmModule::ptrType; const llvm::PointerType* MvmModule::ptr32Type; const llvm::PointerType* MvmModule::ptrPtrType; From nicolas.geoffray at lip6.fr Wed Apr 8 07:50:02 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 08 Apr 2009 14:50:02 -0000 Subject: [vmkit-commits] [vmkit] r68609 - in /vmkit/trunk/lib/JnJVM: Compiler/JavaJITCompiler.cpp VMCore/Jnjvm.cpp Message-ID: <200904081450.n38Eo2SJ015301@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 8 09:49:59 2009 New Revision: 68609 URL: http://llvm.org/viewvc/llvm-project?rev=68609&view=rev Log: Fix command line when generating a Java executable. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=68609&r1=68608&r2=68609&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Wed Apr 8 09:49:59 2009 @@ -224,8 +224,9 @@ Collector::initialise(0); char** newArgv = new char*[argc + 1]; - memcpy(newArgv, argv, argc * sizeof(void*)); - newArgv[argc] = mainClass; + memcpy(newArgv + 1, argv, argc * sizeof(void*)); + newArgv[0] = newArgv[1]; + newArgv[1] = mainClass; JavaJITCompiler* Comp = new JavaJITCompiler("JITModule"); mvm::MvmModule::AddStandardCompilePasses(); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=68609&r1=68608&r2=68609&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Wed Apr 8 09:49:59 2009 @@ -1136,8 +1136,9 @@ Collector::initialise(0); char** newArgv = new char*[argc + 1]; - memcpy(newArgv, argv, argc * sizeof(char*)); - newArgv[argc] = mainClass; + memcpy(newArgv + 1, argv, argc * sizeof(char*)); + newArgv[0] = newArgv[1]; + newArgv[1] = mainClass; JavaCompiler* Comp = new JavaCompiler(); JnjvmClassLoader* JCL = mvm::VirtualMachine::initialiseJVM(Comp); From nicolas.geoffray at lip6.fr Wed Apr 8 14:06:23 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 08 Apr 2009 21:06:23 -0000 Subject: [vmkit-commits] [vmkit] r68643 - /vmkit/trunk/tools/vmjc/vmjc.cpp Message-ID: <200904082106.n38L6NW5032434@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 8 16:06:23 2009 New Revision: 68643 URL: http://llvm.org/viewvc/llvm-project?rev=68643&view=rev Log: Link with all LLVM components. Modified: vmkit/trunk/tools/vmjc/vmjc.cpp Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=68643&r1=68642&r2=68643&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Wed Apr 8 16:06:23 2009 @@ -15,10 +15,13 @@ // //===----------------------------------------------------------------------===// +#include "llvm/LinkAllPasses.h" +#include "llvm/LinkAllVMCore.h" #include "llvm/Module.h" #include "llvm/ModuleProvider.h" #include "llvm/PassManager.h" #include "llvm/Assembly/PrintModulePass.h" +#include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/Config/config.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" From nicolas.geoffray at lip6.fr Wed Apr 8 14:07:52 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 08 Apr 2009 21:07:52 -0000 Subject: [vmkit-commits] [vmkit] r68644 - in /vmkit/trunk/lib: JnJVM/Compiler/JnjvmModule.cpp Mvm/Compiler/EscapeAnalysis.cpp Message-ID: <200904082107.n38L7qsj032695@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 8 16:07:52 2009 New Revision: 68644 URL: http://llvm.org/viewvc/llvm-project?rev=68644&view=rev Log: Do not stack allocate allocations which happen during a loop. Hopefully that will be supported some day... Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=68644&r1=68643&r2=68644&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Wed Apr 8 16:07:52 2009 @@ -529,7 +529,7 @@ } namespace mvm { - llvm::FunctionPass* createEscapeAnalysisPass(llvm::Function*); + llvm::FunctionPass* createEscapeAnalysisPass(); } namespace jnjvm { @@ -545,7 +545,6 @@ JavaFunctionPasses = new FunctionPassManager(TheModuleProvider); JavaFunctionPasses->add(new TargetData(TheModule)); - Function* func = JavaIntrinsics.JavaObjectAllocateFunction; - JavaFunctionPasses->add(mvm::createEscapeAnalysisPass(func)); + JavaFunctionPasses->add(mvm::createEscapeAnalysisPass()); JavaFunctionPasses->add(createLowerConstantCallsPass()); } Modified: vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp?rev=68644&r1=68643&r2=68644&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Wed Apr 8 16:07:52 2009 @@ -11,13 +11,15 @@ #include "llvm/Constants.h" #include "llvm/Function.h" #include "llvm/GlobalVariable.h" +#include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Instructions.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include #include -#include "unistd.h" #include "mvm/GC/GC.h" @@ -29,24 +31,38 @@ public: static char ID; uint64_t pageSize; - EscapeAnalysis(Function* alloc = 0) : - FunctionPass((intptr_t)&ID) { - Allocator = alloc; + EscapeAnalysis() : FunctionPass((intptr_t)&ID) { pageSize = getpagesize(); } + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); + } + virtual bool runOnFunction(Function &F); + private: - Function* Allocator; bool processMalloc(Instruction* I, Value* Size, Value* VT); }; + char EscapeAnalysis::ID = 0; RegisterPass X("EscapeAnalysis", "Escape Analysis Pass"); bool EscapeAnalysis::runOnFunction(Function& F) { bool Changed = false; + Function* Allocator = F.getParent()->getFunction("gcmalloc"); + if (!Allocator) return Changed; + + LoopInfo* LI = &getAnalysis(); + for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { - BasicBlock *Cur = BI; + BasicBlock *Cur = BI; + + // Don't bother if we're in a loop. We rely on the memory manager to + // allocate with a bump pointer allocator. Sure we could analyze more + // to see if the object could in fact be stack allocated, but just be + // lazy for now. + if (LI->getLoopFor(Cur)) continue; for (BasicBlock::iterator II = Cur->begin(), IE = Cur->end(); II != IE;) { Instruction *I = II; @@ -162,8 +178,8 @@ } namespace mvm { -FunctionPass* createEscapeAnalysisPass(llvm::Function* alloc) { - - return new EscapeAnalysis(alloc); +FunctionPass* createEscapeAnalysisPass() { + return new EscapeAnalysis(); } + } From nicolas.geoffray at lip6.fr Thu Apr 9 00:22:04 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 09 Apr 2009 07:22:04 -0000 Subject: [vmkit-commits] [vmkit] r68702 - /vmkit/trunk/tools/llcj/llcj.cpp Message-ID: <200904090722.n397M4R0026556@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 9 02:22:04 2009 New Revision: 68702 URL: http://llvm.org/viewvc/llvm-project?rev=68702&view=rev Log: Prefix and suffix of LLVMLibs were already set. Modified: vmkit/trunk/tools/llcj/llcj.cpp Modified: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=68702&r1=68701&r2=68702&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (original) +++ vmkit/trunk/tools/llcj/llcj.cpp Thu Apr 9 02:22:04 2009 @@ -202,7 +202,7 @@ gccArgv[0] = Prog.toString().c_str(); gccArgv[gccArgc++] = Out.toString().c_str(); - gccArgv[gccArgc++] = "-L"LLVMLibs"/Release/lib"; + gccArgv[gccArgc++] = LLVMLibs; gccArgv[gccArgc++] = VMKITLibs1; gccArgv[gccArgc++] = VMKITLibs2; gccArgv[gccArgc++] = VMKITLibs3; From nicolas.geoffray at lip6.fr Thu Apr 9 03:19:42 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 09 Apr 2009 10:19:42 -0000 Subject: [vmkit-commits] [vmkit] r68704 - in /vmkit/trunk: include/mvm/GC/GC.h lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaInitialise.cpp lib/JnJVM/VMCore/Jnjvm.cpp lib/Mvm/Runtime/Object.cpp lib/N3/VMCore/CLIJit.cpp lib/N3/VMCore/N3Initialise.cpp Message-ID: <200904091019.n39AJiML012052@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 9 05:19:33 2009 New Revision: 68704 URL: http://llvm.org/viewvc/llvm-project?rev=68704&view=rev Log: Give a real type to virtual tables. Modified: vmkit/trunk/include/mvm/GC/GC.h 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/JavaInitialise.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/Mvm/Runtime/Object.cpp vmkit/trunk/lib/N3/VMCore/CLIJit.cpp vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Modified: vmkit/trunk/include/mvm/GC/GC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/include/mvm/GC/GC.h (original) +++ vmkit/trunk/include/mvm/GC/GC.h Thu Apr 9 05:19:33 2009 @@ -11,11 +11,15 @@ #ifndef MVM_GC_H #define MVM_GC_H -#include +#include typedef void (*gc_lock_recovery_fct_t)(int, int, int, int, int, int, int, int); -typedef void VirtualTable; +struct VirtualTable { + uintptr_t destructor; + uintptr_t operatorDelete; + uintptr_t tracer; +}; class gcRoot { public: Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Thu Apr 9 05:19:33 2009 @@ -148,7 +148,8 @@ #ifndef WITHOUT_VTABLE VirtualTable* VT = cl->virtualVT; - + + assert(VT); // Fill the virtual table with function pointers. ExecutionEngine* EE = mvm::MvmModule::executionEngine; for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Apr 9 05:19:33 2009 @@ -125,7 +125,7 @@ assert(super->virtualVT && "Super does not have a VT!"); memcpy(VT, super->virtualVT, cl->super->virtualTableSize * sizeof(void*)); } else { - VT = JavaObjectVT; + VT = (VirtualTable*)JavaObjectVT; } cl->virtualVT = VT; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Apr 9 05:19:33 2009 @@ -330,7 +330,8 @@ uint32 primSize = cl->isPrimitive() ? cl->asPrimitiveClass()->primSize : sizeof(JavaObject*); - VirtualTable* VT = cl->isPrimitive() ? JavaArrayVT : ArrayObjectVT; + VirtualTable* VT = (VirtualTable*) + (cl->isPrimitive() ? JavaArrayVT : ArrayObjectVT); uint32 size = sizeof(JavaObject) + sizeof(ssize_t) + n * primSize; JavaArray* res = (JavaArray*)allocator.allocateManagedObject(size, VT); res->initialise(this); @@ -343,7 +344,8 @@ uint32 primSize = cl->isPrimitive() ? cl->asPrimitiveClass()->primSize : sizeof(JavaObject*); - VirtualTable* VT = cl->isPrimitive() ? JavaArrayVT : ArrayObjectVT; + VirtualTable* VT = (VirtualTable*) + (cl->isPrimitive() ? JavaArrayVT : ArrayObjectVT); uint32 size = sizeof(JavaObject) + sizeof(ssize_t) + n * primSize; JavaArray* res = (JavaArray*)allocator.Allocate(size); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Thu Apr 9 05:19:33 2009 @@ -30,7 +30,7 @@ # define INIT(X) { \ X fake; \ - X::VT = ((void**)(void*)(&fake))[0]; } + X::VT = ((VirtualTable**)(void*)(&fake))[0]; } INIT(LockObj); INIT(VMClassLoader); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Apr 9 05:19:33 2009 @@ -787,7 +787,8 @@ void* stringVT = ((void*)upcalls->newString->getVirtualVT()); uint32 size = upcalls->newString->virtualTableSize * sizeof(void*); if (!JavaString::internStringVT) { - JavaString::internStringVT = bootstrapLoader->allocator.Allocate(size); + JavaString::internStringVT = + (VirtualTable*)bootstrapLoader->allocator.Allocate(size); memcpy(JavaString::internStringVT, stringVT, size); ((void**)(JavaString::internStringVT))[VT_DESTRUCTOR_OFFSET] = (void*)(uintptr_t)JavaString::stringDestructor; Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Thu Apr 9 05:19:33 2009 @@ -46,7 +46,7 @@ void Object::initialise() { # define INIT(X) { \ X fake; \ - X::VT = ((void**)(void*)(&fake))[0]; } + X::VT = ((VirtualTable**)(void*)(&fake))[0]; } INIT(NativeString); INIT(PrintBuffer); Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Thu Apr 9 05:19:33 2009 @@ -145,7 +145,7 @@ #endif VirtualTable* CLIJit::makeArrayVT(VMClassArray* cl) { - VirtualTable * res = malloc(VT_SIZE); + VirtualTable * res = (VirtualTable*)malloc(VT_SIZE); memcpy(res, VMObject::VT, VT_SIZE); #ifdef WITH_TRACER Function* func = Function::Create(markAndTraceLLVMType, @@ -244,7 +244,7 @@ } VirtualTable* CLIJit::makeVT(VMClass* cl, bool stat) { - VirtualTable * res = malloc(VT_SIZE); + VirtualTable * res = (VirtualTable*)malloc(VT_SIZE); memcpy(res, VMObject::VT, VT_SIZE); #ifdef WITH_TRACER const Type* type = stat ? cl->staticType : cl->virtualType; Modified: vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp?rev=68704&r1=68703&r2=68704&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Thu Apr 9 05:19:33 2009 @@ -166,7 +166,7 @@ # define INIT(X) { \ X fake; \ - X::VT = ((void**)(void*)(&fake))[0]; } + X::VT = ((VirtualTable**)(void*)(&fake))[0]; } INIT(Assembly); INIT(Header); From nicolas.geoffray at lip6.fr Thu Apr 9 05:32:11 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 09 Apr 2009 12:32:11 -0000 Subject: [vmkit-commits] [vmkit] r68706 - /vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Message-ID: <200904091232.n39CWChH016430@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 9 07:32:08 2009 New Revision: 68706 URL: http://llvm.org/viewvc/llvm-project?rev=68706&view=rev Log: Trace the appClassLoader only if it has been set! Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=68706&r1=68705&r2=68706&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Thu Apr 9 07:32:08 2009 @@ -232,9 +232,9 @@ void Jnjvm::tracer() { - bootstrapLoader->tracer(); + bootstrapLoader->tracer(); - appClassLoader->getJavaClassLoader()->markAndTrace(); + if (appClassLoader) appClassLoader->getJavaClassLoader()->markAndTrace(); for (std::vector >::iterator i = globalRefs.begin(), e = globalRefs.end(); i!= e; ++i) { From nicolas.geoffray at lip6.fr Thu Apr 9 11:35:21 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 09 Apr 2009 18:35:21 -0000 Subject: [vmkit-commits] [vmkit] r68722 - /vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Message-ID: <200904091835.n39IZLT6030505@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 9 13:35:21 2009 New Revision: 68722 URL: http://llvm.org/viewvc/llvm-project?rev=68722&view=rev Log: Remove tab. Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=68722&r1=68721&r2=68722&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Thu Apr 9 13:35:21 2009 @@ -232,7 +232,7 @@ void Jnjvm::tracer() { - bootstrapLoader->tracer(); + bootstrapLoader->tracer(); if (appClassLoader) appClassLoader->getJavaClassLoader()->markAndTrace(); From nicolas.geoffray at lip6.fr Fri Apr 10 06:05:11 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 10 Apr 2009 13:05:11 -0000 Subject: [vmkit-commits] [vmkit] r68779 - in /vmkit/trunk: include/jnjvm/ include/mvm/ include/mvm/GC/ lib/JnJVM/Compiler/ lib/JnJVM/LLVMRuntime/ lib/JnJVM/VMCore/ tools/llcj/ Message-ID: <200904101305.n3AD5FBn016346@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 10 08:05:01 2009 New Revision: 68779 URL: http://llvm.org/viewvc/llvm-project?rev=68779&view=rev Log: Move from a 3-word header to a 2-word header for Java objects. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/include/mvm/GC/GC.h vmkit/trunk/include/mvm/Object.h vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll 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/JavaString.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaString.h vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp vmkit/trunk/tools/llcj/LinkPaths.h.in Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Fri Apr 10 08:05:01 2009 @@ -45,6 +45,7 @@ class JavaMethod; class JavaObject; class JavaString; +class JavaVirtualTable; class JnjvmClassLoader; class JnjvmModule; class Typedef; @@ -194,7 +195,7 @@ static llvm::ConstantInt* JavaArraySizeOffsetConstant; static llvm::ConstantInt* JavaArrayElementsOffsetConstant; static llvm::ConstantInt* JavaObjectLockOffsetConstant; - static llvm::ConstantInt* JavaObjectClassOffsetConstant; + static llvm::ConstantInt* JavaObjectVTOffsetConstant; static const llvm::Type* JavaArrayUInt8Type; static const llvm::Type* JavaArraySInt8Type; @@ -291,6 +292,7 @@ llvm::Function* GetClassFunction; llvm::Function* JavaObjectAllocateFunction; llvm::Function* GetVTFromClassFunction; + llvm::Function* GetVTFromClassArrayFunction; llvm::Function* GetObjectSizeFromClassFunction; llvm::Function* GetLockFunction; @@ -306,6 +308,7 @@ static llvm::ConstantInt* OffsetObjectSizeInClassConstant; static llvm::ConstantInt* OffsetVTInClassConstant; + static llvm::ConstantInt* OffsetVTInClassArrayConstant; static llvm::ConstantInt* OffsetDepthInClassConstant; static llvm::ConstantInt* OffsetDisplayInClassConstant; static llvm::ConstantInt* OffsetTaskClassMirrorInClassConstant; @@ -316,6 +319,10 @@ static llvm::ConstantInt* OffsetJavaExceptionInThreadConstant; static llvm::ConstantInt* OffsetCXXExceptionInThreadConstant; + static llvm::ConstantInt* OffsetClassInVTConstant; + static llvm::ConstantInt* OffsetDepthInVTConstant; + static llvm::ConstantInt* OffsetDisplayInVTConstant; + static llvm::ConstantInt* ClassReadyConstant; static llvm::Constant* JavaObjectNullConstant; @@ -353,9 +360,6 @@ } #endif - llvm::Constant* PrimitiveArrayVT; - llvm::Constant* ReferenceArrayVT; - void internalMakeVT(Class* cl); void addJavaPasses(); @@ -400,9 +404,6 @@ virtual ~JavaLLVMCompiler(); - llvm::Constant* getReferenceArrayVT(); - llvm::Constant* getPrimitiveArrayVT(); - void resolveVirtualClass(Class* cl); void resolveStaticClass(Class* cl); static llvm::Function* getMethod(JavaMethod* meth); @@ -419,7 +420,7 @@ virtual llvm::Constant* getNativeClass(CommonClass* cl) = 0; virtual llvm::Constant* getJavaClass(CommonClass* cl) = 0; virtual llvm::Constant* getStaticInstance(Class* cl) = 0; - virtual llvm::Constant* getVirtualTable(Class* cl) = 0; + virtual llvm::Constant* getVirtualTable(JavaVirtualTable*) = 0; virtual llvm::Constant* getMethodInClass(JavaMethod* meth) = 0; virtual llvm::Constant* getEnveloppe(Enveloppe* enveloppe) = 0; @@ -484,7 +485,7 @@ virtual llvm::Constant* getNativeClass(CommonClass* cl); virtual llvm::Constant* getJavaClass(CommonClass* cl); virtual llvm::Constant* getStaticInstance(Class* cl); - virtual llvm::Constant* getVirtualTable(Class* cl); + virtual llvm::Constant* getVirtualTable(JavaVirtualTable*); virtual llvm::Constant* getMethodInClass(JavaMethod* meth); virtual llvm::Constant* getEnveloppe(Enveloppe* enveloppe); @@ -534,7 +535,7 @@ virtual llvm::Constant* getNativeClass(CommonClass* cl); virtual llvm::Constant* getJavaClass(CommonClass* cl); virtual llvm::Constant* getStaticInstance(Class* cl); - virtual llvm::Constant* getVirtualTable(Class* cl); + virtual llvm::Constant* getVirtualTable(JavaVirtualTable*); virtual llvm::Constant* getMethodInClass(JavaMethod* meth); virtual llvm::Constant* getEnveloppe(Enveloppe* enveloppe); @@ -558,7 +559,7 @@ #endif //--------------- Static compiler specific functions -----------------------// - llvm::Constant* CreateConstantFromVT(Class* classDef); + llvm::Constant* CreateConstantFromVT(JavaVirtualTable* VT); llvm::Constant* CreateConstantFromUTF8(const UTF8* val); llvm::Constant* CreateConstantFromEnveloppe(Enveloppe* val); llvm::Constant* CreateConstantFromCacheNode(CacheNode* CN); @@ -582,7 +583,7 @@ std::map nativeClasses; std::map arrayClasses; std::map javaClasses; - std::map virtualTables; + std::map virtualTables; std::map staticInstances; std::map constantPools; std::map strings; @@ -607,7 +608,7 @@ typedef std::map::iterator java_class_iterator; - typedef std::map::iterator + typedef std::map::iterator virtual_table_iterator; typedef std::map::iterator Modified: vmkit/trunk/include/mvm/GC/GC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/include/mvm/GC/GC.h (original) +++ vmkit/trunk/include/mvm/GC/GC.h Fri Apr 10 08:05:01 2009 @@ -19,6 +19,10 @@ uintptr_t destructor; uintptr_t operatorDelete; uintptr_t tracer; + + uintptr_t* getFunctions() { + return &destructor; + } }; class gcRoot { @@ -29,6 +33,18 @@ #else virtual void tracer(void) {} #endif + + /// getVirtualTable - Returns the virtual table of this object. + /// + VirtualTable* getVirtualTable() const { + return ((VirtualTable**)(this))[0]; + } + + /// setVirtualTable - Sets the virtual table of this object. + /// + void setVirtualTable(VirtualTable* VT) { + ((VirtualTable**)(this))[0] = VT; + } }; typedef void (*destructor_t)(void*); Modified: vmkit/trunk/include/mvm/Object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Object.h?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Object.h (original) +++ vmkit/trunk/include/mvm/Object.h Fri Apr 10 08:05:01 2009 @@ -33,18 +33,6 @@ class Object : public gc { public: - /// getVirtualTable - Returns the virtual table of this object. - /// - VirtualTable* getVirtualTable() const { - return ((VirtualTable**)(this))[0]; - } - - /// setVirtualTable - Sets the virtual table of this object. - /// - void setVirtualTable(VirtualTable* VT) { - ((VirtualTable**)(this))[0] = VT; - } - /// printString - Returns a string representation of this object. /// char *printString(void) const; Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Fri Apr 10 08:05:01 2009 @@ -33,9 +33,9 @@ using namespace jnjvm; using namespace llvm; -extern void* JavaArrayVT[]; -extern void* ArrayObjectVT[]; -extern void* JavaObjectVT[]; +extern JavaVirtualTable JavaArrayVT; +extern JavaVirtualTable ArrayObjectVT; +extern JavaVirtualTable JavaObjectVT; extern ClassArray ArrayOfBool; extern ClassArray ArrayOfByte; @@ -153,7 +153,7 @@ return SI->second; } else { assert(str && "No string given"); - LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo((Class*)str->getClass()); + LLVMClassInfo* LCI = getClassInfo((Class*)str->getClass()); const llvm::Type* Ty = LCI->getVirtualType(); GlobalVariable* varGV = new GlobalVariable(Ty->getContainedType(0), false, @@ -302,18 +302,25 @@ } } -Constant* JavaAOTCompiler::getVirtualTable(Class* classDef) { - LLVMClassInfo* LCI = getClassInfo((Class*)classDef); - LCI->getVirtualType(); +Constant* JavaAOTCompiler::getVirtualTable(JavaVirtualTable* VT) { + CommonClass* classDef = VT->cl; + uint32 size = 0; + if (classDef->isClass()) { + LLVMClassInfo* LCI = getClassInfo(classDef->asClass()); + LCI->getVirtualType(); + size = classDef->asClass()->virtualTableSize; + } else { + size = classDef->super->virtualTableSize; + } llvm::Constant* res = 0; virtual_table_iterator End = virtualTables.end(); - virtual_table_iterator I = virtualTables.find(classDef); + virtual_table_iterator I = virtualTables.find(VT); if (I == End) { const ArrayType* ATy = dyn_cast(JnjvmModule::VTType->getContainedType(0)); const PointerType* PTy = dyn_cast(ATy->getContainedType(0)); - ATy = ArrayType::get(PTy, classDef->virtualTableSize); + ATy = ArrayType::get(PTy, size); // Do not set a virtual table as a constant, because the runtime may // modify it. GlobalVariable* varGV = new GlobalVariable(ATy, false, @@ -324,10 +331,10 @@ res = ConstantExpr::getCast(Instruction::BitCast, varGV, JnjvmModule::VTType); - virtualTables.insert(std::make_pair(classDef, res)); + virtualTables.insert(std::make_pair(VT, res)); if (isCompiling(classDef)) { - Constant* C = CreateConstantFromVT(classDef); + Constant* C = CreateConstantFromVT(VT); varGV->setInitializer(C); } @@ -365,24 +372,11 @@ // virtual table if (cl->isClass()) { - Elmts.push_back(getVirtualTable(cl->asClass())); + Elmts.push_back(getVirtualTable(cl->asClass()->virtualVT)); } else { - ClassArray* clA = cl->asArrayClass(); - if (clA->baseClass()->isPrimitive()) { - Elmts.push_back(PrimitiveArrayVT); - } else { - Elmts.push_back(ReferenceArrayVT); - } + Elmts.push_back(getVirtualTable(cl->asArrayClass()->virtualVT)); } - // classof - Constant* Cl = getNativeClass(cl); - Constant* ClGEPs[2] = { JnjvmModule::constantZero, - JnjvmModule::constantZero }; - Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2); - - Elmts.push_back(Cl); - // lock Constant* L = ConstantInt::get(Type::Int64Ty, 0); Elmts.push_back(ConstantExpr::getIntToPtr(L, JnjvmModule::ptrType)); @@ -848,6 +842,9 @@ Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2); ClassElts.push_back(Cl); + + // virtualTable + ClassElts.push_back(getVirtualTable(cl->virtualVT)); return ConstantStruct::get(STy, ClassElts); } @@ -866,7 +863,7 @@ ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualSize)); // virtualTable - ClassElts.push_back(getVirtualTable(cl)); + ClassElts.push_back(getVirtualTable(cl->virtualVT)); // IsolateInfo const ArrayType* ATy = dyn_cast(STy->getContainedType(3)); @@ -1151,9 +1148,12 @@ } } -Constant* JavaAOTCompiler::CreateConstantFromVT(Class* classDef) { - uint32 size = classDef->virtualTableSize; - VirtualTable* VT = classDef->virtualVT; +Constant* JavaAOTCompiler::CreateConstantFromVT(JavaVirtualTable* VT) { + CommonClass* classDef = VT->cl; + uint32 size = classDef->isArray() ? classDef->super->virtualTableSize : + classDef->asClass()->virtualTableSize; + JavaVirtualTable* RealVT = classDef->isArray() ? classDef->super->virtualVT : + VT; const ArrayType* ATy = dyn_cast(JnjvmModule::VTType->getContainedType(0)); const PointerType* PTy = dyn_cast(ATy->getContainedType(0)); @@ -1164,7 +1164,7 @@ // Destructor Function* Finalizer = 0; - JavaMethod* meth = ((JavaMethod**)VT)[0]; + JavaMethod* meth = (JavaMethod*)(RealVT->destructor); if (meth) { LLVMMethodInfo* LMI = getMethodInfo(meth); Finalizer = LMI->getMethod(); @@ -1177,21 +1177,61 @@ // Tracer #ifdef WITH_TRACER - Function* Tracer = makeTracer(classDef, false); + Function* Tracer = 0; + if (classDef->isArray()) { + if (classDef->asArrayClass()->baseClass()->isPrimitive()) { + Tracer = JavaIntrinsics.JavaArrayTracerFunction; + } else { + Tracer = JavaIntrinsics.ArrayObjectTracerFunction; + } + } else { + Tracer = makeTracer(classDef->asClass(), false); + } + Elemts.push_back(Tracer ? ConstantExpr::getCast(Instruction::BitCast, Tracer, PTy) : N); #else Elemts.push_back(N); #endif - // Printer - Elemts.push_back(ConstantExpr::getBitCast(ObjectPrinter, PTy)); + // Class + Elemts.push_back(ConstantExpr::getCast(Instruction::BitCast, + getNativeClass(classDef), PTy)); + + // depth + Elemts.push_back(ConstantExpr::getIntToPtr( + ConstantInt::get(Type::Int64Ty, VT->depth), PTy)); - // Hashcode - Elemts.push_back(N); + // display + const ArrayType* DTy = ArrayType::get(JnjvmModule::JavaCommonClassType, + VT->depth + 1); + + std::vector TempElmts; + Constant* ClGEPs[2] = { JnjvmModule::constantZero, + JnjvmModule::constantZero }; - for (uint32 i = VT_NB_FUNCS; i < size; ++i) { - JavaMethod* meth = ((JavaMethod**)VT)[i]; + + for (uint32 i = 0; i <= VT->depth; ++i) { + Constant* Cl = getNativeClass(VT->display[i]); + if (Cl->getType() != JnjvmModule::JavaCommonClassType) + Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2); + + TempElmts.push_back(Cl); + } + + Constant* display = ConstantArray::get(DTy, TempElmts); + TempElmts.clear(); + display = new GlobalVariable(DTy, true, GlobalValue::InternalLinkage, + display, "", getLLVMModule()); + + display = ConstantExpr::getCast(Instruction::BitCast, display, PTy); + + Elemts.push_back(display); + + + // methods + for (uint32 i = JavaVirtualTable::getFirstJavaMethodIndex(); i < size; ++i) { + JavaMethod* meth = ((JavaMethod**)RealVT)[i]; LLVMMethodInfo* LMI = getMethodInfo(meth); Function* F = LMI->getMethod(); if (isAbstract(meth->access)) { @@ -1231,18 +1271,7 @@ generateStubs = true; assumeCompiled = false; - const Type* ATy = JnjvmModule::VTType->getContainedType(0); - PrimitiveArrayVT = new GlobalVariable(ATy, true, - GlobalValue::ExternalLinkage, - 0, "JavaArrayVT", getLLVMModule()); - - ReferenceArrayVT = new GlobalVariable(ATy, true, - GlobalValue::ExternalLinkage, - 0, "ArrayObjectVT", getLLVMModule()); - - - - ATy = JnjvmModule::JavaClassArrayType->getContainedType(0); + const Type* ATy = JnjvmModule::JavaClassArrayType->getContainedType(0); GlobalVariable* varGV = 0; #define PRIMITIVE_ARRAY(name) \ @@ -1444,7 +1473,11 @@ JavaMethod& meth = cl->virtualMethods[i]; ((void**)VT)[meth.offset] = &meth; } - if (!cl->super) ((void**)VT)[0] = 0; + + if (!cl->super) { + VT->destructor = 0; + ClassArray::initialiseVT(); + } #endif } Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Fri Apr 10 08:05:01 2009 @@ -1564,9 +1564,16 @@ Value* Size = 0; if (cl) { - VT = TheCompiler->getVirtualTable(cl); + VT = TheCompiler->getVirtualTable(cl->virtualVT); LLVMClassInfo* LCI = TheCompiler->getClassInfo(cl); Size = LCI->getVirtualSize(); + + bool needsCheck = needsInitialisationCheck(cl, compilingClass); + if (needsCheck) { + Cl = invoke(module->ForceInitialisationCheckFunction, Cl, "", + currentBlock); + } + } else { VT = CallInst::Create(module->GetVTFromClassFunction, Cl, "", currentBlock); @@ -1577,15 +1584,6 @@ Value* val = invoke(module->JavaObjectAllocateFunction, Size, VT, "", currentBlock); - // Set the class - - Value* gep[2] = { module->constantZero, - module->JavaObjectClassOffsetConstant }; - Value* GEP = GetElementPtrInst::Create(val, gep, gep + 2, "", - currentBlock); - Cl = new BitCastInst(Cl, module->JavaCommonClassType, "", currentBlock); - new StoreInst(Cl, GEP, currentBlock); - push(val, false); } Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Fri Apr 10 08:05:01 2009 @@ -27,8 +27,8 @@ using namespace jnjvm; using namespace llvm; -extern void* JavaArrayVT[]; -extern void* ArrayObjectVT[]; +extern JavaVirtualTable JavaArrayVT; +extern JavaVirtualTable ArrayObjectVT; Constant* JavaJITCompiler::getNativeClass(CommonClass* classDef) { const llvm::Type* Ty = classDef->isClass() ? JnjvmModule::JavaClassType : @@ -103,13 +103,13 @@ return ConstantExpr::getIntToPtr(CI, JnjvmModule::ptrType); } -Constant* JavaJITCompiler::getVirtualTable(Class* classDef) { - LLVMClassInfo* LCI = getClassInfo((Class*)classDef); - LCI->getVirtualType(); +Constant* JavaJITCompiler::getVirtualTable(JavaVirtualTable* VT) { + if (VT->cl->isClass()) { + LLVMClassInfo* LCI = getClassInfo(VT->cl->asClass()); + LCI->getVirtualType(); + } - assert(classDef->virtualVT && "Virtual VT not created"); - void* ptr = classDef->virtualVT; - ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(ptr)); + ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64_t(VT)); return ConstantExpr::getIntToPtr(CI, JnjvmModule::VTType); } @@ -126,12 +126,6 @@ JavaJITCompiler::JavaJITCompiler(const std::string &ModuleID) : JavaLLVMCompiler(ModuleID) { - ConstantInt* CI = ConstantInt::get(Type::Int64Ty, uint64(JavaArrayVT)); - PrimitiveArrayVT = ConstantExpr::getIntToPtr(CI, JnjvmModule::VTType); - - CI = ConstantInt::get(Type::Int64Ty, uint64(ArrayObjectVT)); - ReferenceArrayVT = ConstantExpr::getIntToPtr(CI, JnjvmModule::VTType); - TheModuleProvider = new JnjvmModuleProvider(TheModule); addJavaPasses(); } @@ -147,7 +141,7 @@ internalMakeVT(cl); #ifndef WITHOUT_VTABLE - VirtualTable* VT = cl->virtualVT; + JavaVirtualTable* VT = cl->virtualVT; assert(VT); // Fill the virtual table with function pointers. @@ -161,25 +155,26 @@ // if there is none, or if it is empty. if (meth.offset == 0) { #if defined(ISOLATE_SHARING) || defined(USE_GC_BOEHM) - ((void**)VT)[0] = 0; + VT->destructor = 0; #else Function* func = parseFunction(&meth); if (!cl->super) { meth.canBeInlined = true; - ((void**)VT)[0] = 0; + VT->destructor = 0; } else { Function::iterator BB = func->begin(); BasicBlock::iterator I = BB->begin(); if (isa(I)) { - ((void**)VT)[0] = 0; + VT->destructor = 0; } else { // LLVM does not allow recursive compilation. Create the code now. - ((void**)VT)[0] = EE->getPointerToFunction(func); + VT->destructor = (uintptr_t)EE->getPointerToFunction(func); } } #endif } else { - ((void**)VT)[meth.offset] = EE->getPointerToFunctionOrStub(func); + VT->getFunctions()[meth.offset] = + (uintptr_t)EE->getPointerToFunctionOrStub(func); } } @@ -187,14 +182,14 @@ Function* func = makeTracer(cl, false); void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func); - ((void**)VT)[VT_TRACER_OFFSET] = codePtr; + VT->tracer = (uintptr_t)codePtr; func->deleteBody(); #endif // If there is no super, then it's the first VT that we allocate. Assign // this VT to native types. if (!(cl->super)) { - ClassArray::initialiseVT(cl); + ClassArray::initialiseVT(); } #endif } Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Fri Apr 10 08:05:01 2009 @@ -1861,7 +1861,7 @@ LLVMAssessorInfo& LAI = LLVMAssessorInfo::AssessorInfo[charId]; sizeElement = LAI.sizeInBytesConstant; - TheVT = TheCompiler->getPrimitiveArrayVT(); + TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); } else { uint16 index = readU2(bytecodes, i); CommonClass* cl = 0; @@ -1886,17 +1886,21 @@ valCl = new BitCastInst(valCl, module->JavaCommonClassType, "", currentBlock); } + TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); } else { const llvm::Type* Ty = - PointerType::getUnqual(module->JavaCommonClassType); + PointerType::getUnqual(module->JavaClassArrayType); Value* args[2]= { valCl, Constant::getNullValue(Ty) }; valCl = CallInst::Create(module->GetArrayClassFunction, args, args + 2, "", currentBlock); + TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, valCl, "", + currentBlock); + valCl = new BitCastInst(valCl, module->JavaCommonClassType, "", + currentBlock); } sizeElement = module->constantPtrSize; - TheVT = TheCompiler->getReferenceArrayVT(); } Value* arg1 = popAsInt(); @@ -1944,12 +1948,6 @@ arg1 = new IntToPtrInst(arg1, module->ptrType, "", currentBlock); new StoreInst(arg1, GEP, currentBlock); - // Set the class - Value* gep[2] = { module->constantZero, - module->JavaObjectClassOffsetConstant }; - GEP = GetElementPtrInst::Create(res, gep, gep + 2, "", currentBlock); - new StoreInst(valCl, GEP, currentBlock); - push(res, false); break; Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Fri Apr 10 08:05:01 2009 @@ -29,7 +29,7 @@ using namespace llvm; -extern void* JavaObjectVT[]; +extern JavaVirtualTable JavaObjectVT; #ifdef WITH_TRACER const llvm::FunctionType* JnjvmModule::MarkAndTraceType = 0; @@ -65,6 +65,7 @@ llvm::Constant* JnjvmModule::JavaArraySizeConstant; llvm::ConstantInt* JnjvmModule::OffsetObjectSizeInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetVTInClassConstant; +llvm::ConstantInt* JnjvmModule::OffsetVTInClassArrayConstant; llvm::ConstantInt* JnjvmModule::OffsetDepthInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetDisplayInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetTaskClassMirrorInClassConstant; @@ -82,7 +83,10 @@ llvm::ConstantInt* JnjvmModule::JavaArrayElementsOffsetConstant; llvm::ConstantInt* JnjvmModule::JavaArraySizeOffsetConstant; llvm::ConstantInt* JnjvmModule::JavaObjectLockOffsetConstant; -llvm::ConstantInt* JnjvmModule::JavaObjectClassOffsetConstant; +llvm::ConstantInt* JnjvmModule::JavaObjectVTOffsetConstant; +llvm::ConstantInt* JnjvmModule::OffsetClassInVTConstant; +llvm::ConstantInt* JnjvmModule::OffsetDepthInVTConstant; +llvm::ConstantInt* JnjvmModule::OffsetDisplayInVTConstant; JavaLLVMCompiler::JavaLLVMCompiler(const std::string& str) : @@ -114,18 +118,22 @@ } } - VirtualTable* VT = 0; + JavaVirtualTable* VT = 0; if (cl->super) { - uint64 size = cl->virtualTableSize; + uint32 size = cl->virtualTableSize; mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - VT = (VirtualTable*)allocator.Allocate(size * sizeof(void*)); - Class* super = (Class*)cl->super; - assert(cl->virtualTableSize >= cl->super->virtualTableSize && + Class* super = cl->super; + assert(cl->virtualTableSize >= super->virtualTableSize && "Super VT bigger than own VT"); assert(super->virtualVT && "Super does not have a VT!"); - memcpy(VT, super->virtualVT, cl->super->virtualTableSize * sizeof(void*)); + VT = new(allocator, size) JavaVirtualTable(cl); } else { - VT = (VirtualTable*)JavaObjectVT; + VT = &JavaObjectVT; + VT->depth = 0; + VT->display = (CommonClass**) + cl->classLoader->allocator.Allocate(sizeof(CommonClass*)); + VT->display[0] = cl; + } cl->virtualVT = VT; @@ -220,10 +228,10 @@ void JavaLLVMCompiler::internalMakeVT(Class* cl) { - VirtualTable* VT = 0; + JavaVirtualTable* VT = 0; #ifdef WITHOUT_VTABLE mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - VT = (VirtualTable*)allocator.Allocate(VT_SIZE); + VT = (JavaVirtualTable*)allocator.Allocate(VT_SIZE); memcpy(VT, JavaObjectVT, VT_SIZE); cl->virtualVT = VT; #else @@ -234,7 +242,7 @@ cl->virtualTableSize = cl->super->virtualTableSize; } else { - cl->virtualTableSize = VT_NB_FUNCS; + cl->virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); } // Allocate the virtual table. @@ -344,14 +352,18 @@ JavaArrayElementsOffsetConstant = mvm::MvmModule::constantTwo; JavaArraySizeOffsetConstant = mvm::MvmModule::constantOne; - JavaObjectLockOffsetConstant = mvm::MvmModule::constantTwo; - JavaObjectClassOffsetConstant = mvm::MvmModule::constantOne; + JavaObjectLockOffsetConstant = mvm::MvmModule::constantOne; + JavaObjectVTOffsetConstant = mvm::MvmModule::constantZero; + OffsetClassInVTConstant = mvm::MvmModule::constantThree; + OffsetDepthInVTConstant = mvm::MvmModule::constantFour; + OffsetDisplayInVTConstant = mvm::MvmModule::constantFive; OffsetDisplayInClassConstant = mvm::MvmModule::constantZero; OffsetDepthInClassConstant = mvm::MvmModule::constantOne; OffsetObjectSizeInClassConstant = mvm::MvmModule::constantOne; OffsetVTInClassConstant = mvm::MvmModule::constantTwo; + OffsetVTInClassArrayConstant = mvm::MvmModule::constantTwo; OffsetTaskClassMirrorInClassConstant = mvm::MvmModule::constantThree; OffsetStaticInstanceInTaskClassMirrorConstant = mvm::MvmModule::constantTwo; OffsetStatusInTaskClassMirrorConstant = mvm::MvmModule::constantZero; @@ -365,14 +377,6 @@ LLVMAssessorInfo::initialise(); } -Constant* JavaLLVMCompiler::getReferenceArrayVT() { - return ReferenceArrayVT; -} - -Constant* JavaLLVMCompiler::getPrimitiveArrayVT() { - return PrimitiveArrayVT; -} - Function* JavaLLVMCompiler::getMethod(JavaMethod* meth) { return getMethodInfo(meth)->getMethod(); } @@ -417,6 +421,7 @@ GetClassFunction = module->getFunction("getClass"); ClassLookupFunction = module->getFunction("classLookup"); GetVTFromClassFunction = module->getFunction("getVTFromClass"); + GetVTFromClassArrayFunction = module->getFunction("getVTFromClassArray"); GetObjectSizeFromClassFunction = module->getFunction("getObjectSizeFromClass"); Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Fri Apr 10 08:05:01 2009 @@ -177,10 +177,18 @@ Changed = true; Value* val = Call.getArgument(0); // get the object Value* args2[2] = { module->constantZero, - module->JavaObjectClassOffsetConstant }; - Value* classPtr = GetElementPtrInst::Create(val, args2, args2 + 2, - "", CI); - Value* cl = new LoadInst(classPtr, "", CI); + module->JavaObjectVTOffsetConstant }; + Value* VTPtr = GetElementPtrInst::Create(val, args2, args2 + 2, + "", CI); + Value* VT = new LoadInst(VTPtr, "", CI); + Value* args3[2] = { module->constantZero, + module->OffsetClassInVTConstant }; + + Value* clPtr = GetElementPtrInst::Create(VT, args3, args3 + 2, + "", CI); + Value* cl = new LoadInst(clPtr, "", CI); + cl = new BitCastInst(cl, module->JavaCommonClassType, "", CI); + CI->replaceAllUsesWith(cl); CI->eraseFromParent(); } else if (V == module->GetVTFromClassFunction) { @@ -194,6 +202,17 @@ Value* VT = new LoadInst(VTPtr, "", CI); CI->replaceAllUsesWith(VT); CI->eraseFromParent(); + } else if (V == module->GetVTFromClassArrayFunction) { + Changed = true; + + Value* val = Call.getArgument(0); + Value* indexes[2] = { module->constantZero, + module->OffsetVTInClassArrayConstant }; + Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, + "", CI); + Value* VT = new LoadInst(VTPtr, "", CI); + CI->replaceAllUsesWith(VT); + CI->eraseFromParent(); } else if (V == module->GetObjectSizeFromClassFunction) { Changed = true; @@ -432,9 +451,9 @@ I->getParent()->getTerminator()->eraseFromParent(); Constant* init = - Constant::getNullValue(module->JavaCommonClassType); + Constant::getNullValue(module->JavaClassArrayType); GlobalVariable* GV = - new GlobalVariable(module->JavaCommonClassType, false, + new GlobalVariable(module->JavaClassArrayType, false, GlobalValue::ExternalLinkage, init, "", TheCompiler->getLLVMModule()); @@ -444,7 +463,7 @@ BasicBlock* OKBlock = BasicBlock::Create("", &F); BasicBlock* NotOKBlock = BasicBlock::Create("", &F); - PHINode* node = PHINode::Create(module->JavaCommonClassType, "", + PHINode* node = PHINode::Create(module->JavaClassArrayType, "", OKBlock); node->addIncoming(LoadedGV, CI->getParent()); Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Fri Apr 10 08:05:01 2009 @@ -5,8 +5,8 @@ ;;; A virtual table is an array of function pointers. %VT = type [0 x i32 (...)*] -;;; The root of all Java Objects: a VT, a class and a lock. -%JavaObject = type { %VT*, %JavaCommonClass*, i8* } +;;; The root of all Java Objects: a VT and a lock. +%JavaObject = type { %VT*, i8* } ;;; Types for Java arrays. A size of 0 means an undefined size. %JavaArray = type { %JavaObject, i8* } @@ -61,7 +61,7 @@ %UTF8*, %UTF8*, i8, i8*, i32, i8* } %JavaClassPrimitive = type { %JavaCommonClass, i32 } -%JavaClassArray = type { %JavaCommonClass, %JavaCommonClass* } +%JavaClassArray = type { %JavaCommonClass, %JavaCommonClass*, %VT* } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Constant calls for Jnjvm runtime internal objects field accesses ;;;;;;;;; @@ -85,6 +85,10 @@ ;;; getVTFromClass - Get the VT of a class from its runtime representation. declare %VT* @getVTFromClass(%JavaClass*) readnone +;;; getVTFromClassArray - Get the VT of an array class from its runtime +;;; representation. +declare %VT* @getVTFromClassArray(%JavaClassArray*) readnone + ;;; getObjectSizeFromClass - Get the size of a class from its runtime ;;; representation. declare i32 @getObjectSizeFromClass(%JavaClass*) readnone @@ -188,8 +192,8 @@ declare %JavaObject* @jnjvmRuntimeDelegatee(%JavaCommonClass*) readnone ;;; getArrayClass - Get the array user class of the user class. -declare %JavaCommonClass* @getArrayClass(%JavaCommonClass*, - %JavaCommonClass**) readnone +declare %JavaClassArray* @getArrayClass(%JavaCommonClass*, + %JavaClassArray**) readnone declare i8 @getFinalInt8Field(i8*) readnone declare i16 @getFinalInt16Field(i16*) readnone Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Fri Apr 10 08:05:01 2009 @@ -40,8 +40,10 @@ Class* ClassArray::SuperArray; Class** ClassArray::InterfacesArray; -extern void* JavaArrayVT[]; -extern void* ArrayObjectVT[]; +extern JavaVirtualTable JavaObjectVT; + +extern "C" void JavaArrayTracer(JavaObject*); +extern "C" void ArrayObjectTracer(JavaObject*); Attribut::Attribut(const UTF8* name, uint32 length, uint32 offset) { @@ -255,7 +257,7 @@ } } -CommonClass::CommonClass(JnjvmClassLoader* loader, const UTF8* n) { +void CommonClass::init(JnjvmClassLoader* loader, const UTF8* n) { name = n; classLoader = loader; nbInterfaces = 0; @@ -302,13 +304,17 @@ memset(IsolateInfo, 0, sizeof(TaskClassMirror) * NR_ISOLATES); } -ClassArray::ClassArray(JnjvmClassLoader* loader, const UTF8* n, - UserCommonClass* base) : - CommonClass(loader, n) { +void ClassArray::init(JnjvmClassLoader* loader, const UTF8* n, + UserCommonClass* base) { _baseClass = base; super = ClassArray::SuperArray; interfaces = ClassArray::InterfacesArray; nbInterfaces = 2; + + uint32 size = JavaVirtualTable::getNumMethods(); + virtualVT = new(loader->allocator, size) JavaVirtualTable(this); + virtualVT->tracer = (uintptr_t)ArrayObjectTracer; + depth = 1; display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*)); display[0] = ClassArray::SuperArray; @@ -330,8 +336,7 @@ uint32 primSize = cl->isPrimitive() ? cl->asPrimitiveClass()->primSize : sizeof(JavaObject*); - VirtualTable* VT = (VirtualTable*) - (cl->isPrimitive() ? JavaArrayVT : ArrayObjectVT); + VirtualTable* VT = virtualVT; uint32 size = sizeof(JavaObject) + sizeof(ssize_t) + n * primSize; JavaArray* res = (JavaArray*)allocator.allocateManagedObject(size, VT); res->initialise(this); @@ -344,8 +349,7 @@ uint32 primSize = cl->isPrimitive() ? cl->asPrimitiveClass()->primSize : sizeof(JavaObject*); - VirtualTable* VT = (VirtualTable*) - (cl->isPrimitive() ? JavaArrayVT : ArrayObjectVT); + VirtualTable* VT = virtualVT; uint32 size = sizeof(JavaObject) + sizeof(ssize_t) + n * primSize; JavaArray* res = (JavaArray*)allocator.Allocate(size); @@ -537,6 +541,7 @@ assert((this->isInitializing() || classLoader->getCompiler()->isStaticCompiling()) && "Uninitialized class when allocating."); + assert(getVirtualVT() && "No VT\n"); JavaObject* res = (JavaObject*)vm->gcAllocator.allocateManagedObject(getVirtualSize(), getVirtualVT()); @@ -1257,15 +1262,75 @@ } -void ClassArray::initialiseVT(Class* cl) { - uint32 size = (cl->virtualTableSize - VT_NB_FUNCS) * sizeof(void*); - - #define COPY(CLASS) \ - memcpy((void*)((uintptr_t)CLASS + VT_SIZE), \ - (void*)((uintptr_t)cl->virtualVT + VT_SIZE), size); +void ClassArray::initialiseVT() { + + Class* cl = ClassArray::SuperArray; + assert(cl && "Initializing array VT without a super for arrays"); + assert(cl->virtualVT->init && "Initializing array VT before JavaObjectVT"); + + // Set the values in the JavaObject VT + cl->virtualVT->depth = 0; + cl->virtualVT->cl = cl; + cl->virtualVT->display = cl->display; + + Classpath* upcalls = cl->classLoader->bootstrapLoader->upcalls; - COPY(JavaArrayVT) - COPY(ArrayObjectVT) + #define COPY(CLASS) \ + memcpy(CLASS->virtualVT->getFirstJavaMethod(), \ + cl->virtualVT->getFirstJavaMethod(), \ + sizeof(uintptr_t) * JavaVirtualTable::getNumJavaMethods()); \ + CLASS->super = cl; \ + CLASS->display[0] = cl; \ + CLASS->display[1] = CLASS; + + COPY(upcalls->ArrayOfBool) + COPY(upcalls->ArrayOfByte) + COPY(upcalls->ArrayOfChar) + COPY(upcalls->ArrayOfShort) + COPY(upcalls->ArrayOfInt) + COPY(upcalls->ArrayOfFloat) + COPY(upcalls->ArrayOfDouble) + COPY(upcalls->ArrayOfLong) + COPY(upcalls->ArrayOfObject) + COPY(upcalls->ArrayOfString) #undef COPY + +} + +JavaVirtualTable::JavaVirtualTable(Class* C) { + + // (1) Copy the super VT into the current VT. + uint32 size = C->super->virtualTableSize * sizeof(uintptr_t); + memcpy(this, C->super->virtualVT, size); + + // (2) Set the class of this VT. + cl = C; + + // (3) Set depth and display for fast dynamic type checking. + depth = cl->super->virtualVT->depth + 1; + mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; + display = (CommonClass**) + allocator.Allocate(sizeof(CommonClass*) * (depth + 1)); + size = depth * sizeof(UserCommonClass*); + memcpy(display, cl->super->virtualVT->display, size); + display[depth] = C; } + +JavaVirtualTable::JavaVirtualTable(ClassArray* C) { + + // (1) Copy the super VT into the current VT. + uint32 size = getNumMethods() * sizeof(uintptr_t); + memcpy(this, &JavaObjectVT, size); + + // (2) Set the class of this VT. + cl = C; + + // (3) Set depth and display for fast dynamic type checking. + depth = 1; + mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; + display = (CommonClass**)allocator.Allocate(sizeof(CommonClass*) * 2); + display[0] = C->super; + display[1] = C; +} + Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Fri Apr 10 08:05:01 2009 @@ -37,6 +37,7 @@ class JavaField; class JavaMethod; class JavaObject; +class JavaVirtualTable; class Reader; class Signdef; class Typedef; @@ -114,7 +115,6 @@ }; - /// TaskClassMirror - The isolate specific class information: the initialization /// state and the static instance. In a non-isolate environment, there is only /// one instance of a TaskClassMirror per Class. @@ -305,7 +305,9 @@ /// CommonClass - Create a class with th given name. /// - CommonClass(JnjvmClassLoader* loader, const UTF8* name); + CommonClass(JnjvmClassLoader* loader, const UTF8* name) { + init(loader, name); + } /// ~CommonClass - Free memory used by this class, and remove it from /// metadata. @@ -316,19 +318,16 @@ /// CommonClass(); + /// init - initialize the class. + /// + void init(JnjvmClassLoader* JCL, const UTF8* n); + /// setInterfaces - Set the interfaces of the class. /// void setInterfaces(Class** I) { interfaces = I; } - - /// setSuper - Set the super of the class. - /// - void setSuper(Class* S) { - super = S; - display[0] = (CommonClass*)S; - } - + /// toPrimitive - Returns the primitive class which represents /// this class, ie void for java/lang/Void. /// @@ -367,6 +366,7 @@ return GC_MALLOC(sz); } #endif + }; /// ClassPrimitive - This class represents internal classes for primitive @@ -447,7 +447,7 @@ /// virtualVT - The virtual table of instances of this class. /// - VirtualTable* virtualVT; + JavaVirtualTable* virtualVT; /// IsolateInfo - Per isolate informations for static instances and /// initialization state. @@ -553,7 +553,7 @@ /// getVirtualVT - Get the virtual VT of instances of this class. /// - VirtualTable* getVirtualVT() { return virtualVT; } + JavaVirtualTable* getVirtualVT() { return virtualVT; } /// getOwnerClass - Get the thread that is currently initializing the class. /// @@ -897,6 +897,10 @@ /// CommonClass* _baseClass; + /// virtualVT - The virtual table of this array class. + /// + JavaVirtualTable* virtualVT; + /// baseClass - Get the base class of this array class. /// CommonClass* baseClass() const { @@ -906,15 +910,22 @@ /// doNew - Allocate a new array in the given vm. /// JavaArray* doNew(sint32 n, Jnjvm* vm); - - /// ClassArray - Empty constructor for VT. + + /// init - Initialize the array class. + /// + void init(JnjvmClassLoader* loader, const UTF8* name, + UserCommonClass* baseClass); + + /// ClassArray - Empty constructor. /// ClassArray() {} /// ClassArray - Construct a Java array class with the given name. /// ClassArray(JnjvmClassLoader* loader, const UTF8* name, - UserCommonClass* baseClass); + UserCommonClass* baseClass) : CommonClass (loader, name) { + init(loader, name, baseClass); + } /// SuperArray - The super of class arrays. Namely java/lang/Object. /// @@ -927,7 +938,8 @@ /// initialiseVT - Initialise the primitive and reference array VT. /// super is the java/lang/Object class. /// - static void initialiseVT(Class* super); + static void initialiseVT(); + }; /// JavaMethod - This class represents Java methods. @@ -1317,6 +1329,53 @@ }; +class JavaVirtualTable : public VirtualTable { +public: + CommonClass* cl; + size_t depth; + CommonClass** display; + + uintptr_t init; + uintptr_t equals; + uintptr_t hashCode; + uintptr_t toString; + uintptr_t clone; + uintptr_t getClass; + uintptr_t notify; + uintptr_t notifyAll; + uintptr_t waitIndefinitely; + uintptr_t waitMs; + uintptr_t waitMsNs; + + void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator, + uint32 nbMethods) { + return allocator.Allocate(sizeof(uintptr_t) * (nbMethods)); + } + + JavaVirtualTable(Class* C); + + JavaVirtualTable(ClassArray* C); + + JavaVirtualTable() {} + + uintptr_t* getFirstJavaMethod() { + return &init; + } + + static uint32_t getFirstJavaMethodIndex() { + return 6; + } + + static uint32_t getNumMethods() { + return 17; + } + + static uint32_t getNumJavaMethods() { + return 11; + } + +}; + } // end namespace jnjvm Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Fri Apr 10 08:05:01 2009 @@ -10,6 +10,7 @@ #include "mvm/VirtualMachine.h" #include "JavaArray.h" +#include "JavaClass.h" #include "JavaObject.h" #include "Jnjvm.h" #include "JnjvmClassLoader.h" @@ -22,9 +23,7 @@ using namespace jnjvm; -void* JavaArrayVT[12 + VT_SIZE]; -void* ArrayObjectVT[12 + VT_SIZE]; -void* JavaObjectVT[12 + VT_SIZE]; +JavaVirtualTable JavaObjectVT; static void initialiseVT() { @@ -47,12 +46,10 @@ #define INIT(X) { \ X fake; \ void* V = ((void**)(void*)(&fake))[0]; \ - memcpy(X##VT, V, VT_SIZE); \ - ((void**)X##VT)[0] = 0; } + memcpy(&(X##VT), V, sizeof(VirtualTable)); \ + X##VT.destructor = 0; } INIT(JavaObject); - INIT(JavaArray); - INIT(ArrayObject); #undef INIT } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Fri Apr 10 08:05:01 2009 @@ -75,17 +75,6 @@ return res; } -extern "C" void printJavaObject(const JavaObject* obj, mvm::PrintBuffer* buf) { - buf->write("JavaObject<"); - CommonClass::printClassName(obj->getClass()->getName(), buf); - buf->write(">"); -} - -void JavaObject::print(mvm::PrintBuffer* buf) const { - printJavaObject(this, buf); -} - - void JavaObject::waitIntern(struct timeval* info, bool timed) { if (owner()) { @@ -164,7 +153,7 @@ JavaObject* obj = this; if (!signature->isPrimitive()) { - if (obj && !(obj->classOf->isOfTypeName(vm, signature->getName()))) { + if (obj && !(obj->getClass()->isOfTypeName(vm, signature->getName()))) { vm->illegalArgumentException("wrong type argument"); } ((JavaObject**)buf)[0] = obj; @@ -173,7 +162,7 @@ } else if (obj == 0) { vm->illegalArgumentException(""); } else { - UserCommonClass* cl = obj->classOf; + UserCommonClass* cl = obj->getClass(); UserClassPrimitive* value = cl->toPrimitive(vm); PrimitiveTypedef* prim = (PrimitiveTypedef*)signature; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Fri Apr 10 08:05:01 2009 @@ -57,7 +57,7 @@ /// LockObj - This class represents a Java monitor. /// -class LockObj : public mvm::Object { +class LockObj : public gc { friend class JavaObject; private: @@ -105,6 +105,8 @@ return &varcond; } + /// VT - LockObj is GC-allocated, so we must make the VT explicit. + /// static VirtualTable* VT; ~LockObj() {} @@ -114,26 +116,21 @@ /// JavaObject - This class represents a Java object. /// -class JavaObject : public mvm::Object { +class JavaObject : public gc { private: /// waitIntern - internal wait on a monitor /// void waitIntern(struct timeval *info, bool timed); - /// classOf - The class of this object. - /// - UserCommonClass* classOf; - public: /// getClass - Returns the class of this object. /// UserCommonClass* getClass() const { - return classOf; + return ((JavaVirtualTable*)getVirtualTable())->cl; } - /// lock - The monitor of this object. Most of the time null. /// mvm::ThinLock lock; @@ -157,7 +154,7 @@ /// void notifyAll(); - /// overflowThinLokc - Notify that the thin lock has overflowed. + /// overflowThinLock - Notify that the thin lock has overflowed. /// void overflowThinLock() { lock.overflowThinLock(); @@ -166,14 +163,13 @@ /// initialise - Initialises the object. /// void initialise(UserCommonClass* cl) { - this->classOf = cl; } /// instanceOf - Is this object's class of type the given class? /// bool instanceOf(UserCommonClass* cl) { if (!this) return false; - else return this->classOf->isAssignableFrom(cl); + else return this->getClass()->isAssignableFrom(cl); } /// acquire - Acquire the lock on this object. @@ -199,7 +195,6 @@ if (obj == 0) JavaThread::get()->getJVM()->nullPointerException(""); #endif - virtual void print(mvm::PrintBuffer* buf) const; virtual void TRACER; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp Fri Apr 10 08:05:01 2009 @@ -17,15 +17,16 @@ using namespace jnjvm; -VirtualTable* JavaString::internStringVT = 0; +JavaVirtualTable* JavaString::internStringVT = 0; JavaString* JavaString::stringDup(const UTF8*& utf8, Jnjvm* vm) { UserClass* cl = vm->upcalls->newString; JavaString* res = (JavaString*)cl->doNew(vm); // It's a hashed string, set the destructor so that the string - // removes itself from the vm string map. - res->setVirtualTable(internStringVT); + // removes itself from the vm string map. Do this ony if + // internStringVT exists (in case of AOT). + if (internStringVT) res->setVirtualTable(internStringVT); // No need to call the Java function: both the Java function and // this function do the same thing. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaString.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaString.h?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaString.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaString.h Fri Apr 10 08:05:01 2009 @@ -16,7 +16,6 @@ namespace jnjvm { -class ArrayUInt16; class Jnjvm; class JavaString : public JavaObject { @@ -33,7 +32,7 @@ char* strToAsciiz(); const UTF8* strToUTF8(Jnjvm* vm); - static VirtualTable* internStringVT; + static JavaVirtualTable* internStringVT; }; } // end namespace jnjvm Modified: vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jni.cpp Fri Apr 10 08:05:01 2009 @@ -95,8 +95,8 @@ } else if (cl == upcalls->newMethod) { return (jmethodID)((JavaObjectConstructor*)meth)->getInternalMethod(); } else { - vm->unknownError("%s is not a constructor or a method", - meth->printString()); + vm->unknownError("Not a constructor or a method: %s", + meth->getClass()->printString()); } END_JNI_EXCEPTION Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Fri Apr 10 08:05:01 2009 @@ -784,14 +784,17 @@ // placed in the hashmap. This VT will have its destructor set so // that the string is removed when deallocated. upcalls->newString->resolveClass(); - void* stringVT = ((void*)upcalls->newString->getVirtualVT()); - uint32 size = upcalls->newString->virtualTableSize * sizeof(void*); if (!JavaString::internStringVT) { + JavaVirtualTable* stringVT = upcalls->newString->getVirtualVT(); + uint32 size = upcalls->newString->virtualTableSize * sizeof(uintptr_t); + JavaString::internStringVT = - (VirtualTable*)bootstrapLoader->allocator.Allocate(size); + (JavaVirtualTable*)bootstrapLoader->allocator.Allocate(size); + memcpy(JavaString::internStringVT, stringVT, size); - ((void**)(JavaString::internStringVT))[VT_DESTRUCTOR_OFFSET] = - (void*)(uintptr_t)JavaString::stringDestructor; + + JavaString::internStringVT->destructor = + (uintptr_t)JavaString::stringDestructor; } upcalls->newString->initialiseClass(this); Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Fri Apr 10 08:05:01 2009 @@ -61,6 +61,8 @@ ClassArray ArrayOfDouble; ClassArray ArrayOfLong; +extern "C" void JavaArrayTracer(JavaObject*); + typedef void (*static_init_t)(JnjvmClassLoader*); JnjvmBootstrapLoader::JnjvmBootstrapLoader(mvm::BumpPtrAllocator& Alloc, @@ -179,7 +181,7 @@ static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; assert(init && "Loaded the wrong boot library"); init(this); - ClassArray::initialiseVT(SuperArray); + ClassArray::initialiseVT(); } } } @@ -193,20 +195,6 @@ } - // Set the super of array classes. -#define SET_PARENT(CLASS) \ - CLASS.setSuper(SuperArray); \ - - SET_PARENT(ArrayOfBool) - SET_PARENT(ArrayOfByte) - SET_PARENT(ArrayOfChar) - SET_PARENT(ArrayOfShort) - SET_PARENT(ArrayOfInt) - SET_PARENT(ArrayOfFloat) - SET_PARENT(ArrayOfDouble) - SET_PARENT(ArrayOfLong) -#undef SET_PARENT - // Initialize interfaces of array classes. InterfacesArray[0] = loadName(asciizConstructUTF8("java/lang/Cloneable"), false, false); @@ -632,8 +620,10 @@ JnjvmBootstrapLoader::constructPrimitiveArray(ClassArray& cl, const UTF8* name, ClassPrimitive* baseClass) { - cl = ClassArray(this, name, baseClass); + cl.CommonClass::init(this, name); + cl.ClassArray::init(this, name, baseClass); classes->map.insert(std::make_pair(name, &cl)); + cl.virtualVT->tracer = (uintptr_t)JavaArrayTracer; return &cl; } Modified: vmkit/trunk/tools/llcj/LinkPaths.h.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/LinkPaths.h.in?rev=68779&r1=68778&r2=68779&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/LinkPaths.h.in (original) +++ vmkit/trunk/tools/llcj/LinkPaths.h.in Fri Apr 10 08:05:01 2009 @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// -#define LLVMLibs "@LLVM_OBJ@" +#define LLVMLibs "-L at LLVM_OBJ@/Release/lib" #define VMKITLibs1 "-L at abs_top_objdir@/Release/lib" #define VMKITLibs2 "-L at abs_top_srcdir@/Release/lib" #define VMKITLibs3 "-L at PROJ_INSTALL_ROOT@/lib" From nicolas.geoffray at lip6.fr Fri Apr 10 07:16:16 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 10 Apr 2009 14:16:16 -0000 Subject: [vmkit-commits] [vmkit] r68780 - in /vmkit/trunk/lib/JnJVM: Compiler/JavaAOTCompiler.cpp VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/JnjvmClassLoader.cpp Message-ID: <200904101416.n3AEGGJt018833@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 10 09:16:15 2009 New Revision: 68780 URL: http://llvm.org/viewvc/llvm-project?rev=68780&view=rev Log: Make virtual tables of native arrays static in the program, so that AOT files can link with them. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=68780&r1=68779&r2=68780&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Fri Apr 10 09:16:15 2009 @@ -34,8 +34,6 @@ using namespace llvm; extern JavaVirtualTable JavaArrayVT; -extern JavaVirtualTable ArrayObjectVT; -extern JavaVirtualTable JavaObjectVT; extern ClassArray ArrayOfBool; extern ClassArray ArrayOfByte; @@ -1277,7 +1275,11 @@ #define PRIMITIVE_ARRAY(name) \ varGV = new GlobalVariable(ATy, true, GlobalValue::ExternalLinkage, \ 0, #name, getLLVMModule()); \ - arrayClasses.insert(std::make_pair(&name, varGV)); + arrayClasses.insert(std::make_pair(&name, varGV)); \ + varGV = new GlobalVariable(JnjvmModule::VTType->getContainedType(0), true, \ + GlobalValue::ExternalLinkage, \ + 0, #name"VT", getLLVMModule()); \ + virtualTables.insert(std::make_pair(name.virtualVT, varGV)); PRIMITIVE_ARRAY(ArrayOfBool) PRIMITIVE_ARRAY(ArrayOfByte) Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=68780&r1=68779&r2=68780&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Fri Apr 10 09:16:15 2009 @@ -322,6 +322,25 @@ access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC | JNJVM_ARRAY; } +void ClassArray::initPrimitive(JnjvmClassLoader* loader, const UTF8* n, + UserCommonClass* base) { + CommonClass::init(loader, n); + + _baseClass = base; + super = ClassArray::SuperArray; + interfaces = ClassArray::InterfacesArray; + nbInterfaces = 2; + + virtualVT->tracer = (uintptr_t)JavaArrayTracer; + virtualVT->cl = this; + + depth = 1; + display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*)); + display[0] = ClassArray::SuperArray; + display[1] = this; + access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC | JNJVM_ARRAY; +} + JavaArray* UserClassArray::doNew(sint32 n, Jnjvm* vm) { if (n < 0) vm->negativeArraySizeException(n); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=68780&r1=68779&r2=68780&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Fri Apr 10 09:16:15 2009 @@ -915,10 +915,15 @@ /// void init(JnjvmClassLoader* loader, const UTF8* name, UserCommonClass* baseClass); + + /// initPrimitive - Initialize the primitive array class. + /// + void initPrimitive(JnjvmClassLoader* loader, const UTF8* name, + UserCommonClass* baseClass); - /// ClassArray - Empty constructor. + /// ClassArray - Constructor with a VT. /// - ClassArray() {} + ClassArray(JavaVirtualTable& VT) { virtualVT = &VT; } /// ClassArray - Construct a Java array class with the given name. /// Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=68780&r1=68779&r2=68780&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Fri Apr 10 09:16:15 2009 @@ -52,14 +52,23 @@ using namespace jnjvm; -ClassArray ArrayOfBool; -ClassArray ArrayOfByte; -ClassArray ArrayOfChar; -ClassArray ArrayOfShort; -ClassArray ArrayOfInt; -ClassArray ArrayOfFloat; -ClassArray ArrayOfDouble; -ClassArray ArrayOfLong; +JavaVirtualTable ArrayOfBoolVT; +JavaVirtualTable ArrayOfByteVT; +JavaVirtualTable ArrayOfCharVT; +JavaVirtualTable ArrayOfShortVT; +JavaVirtualTable ArrayOfIntVT; +JavaVirtualTable ArrayOfFloatVT; +JavaVirtualTable ArrayOfDoubleVT; +JavaVirtualTable ArrayOfLongVT; + +ClassArray ArrayOfBool(ArrayOfBoolVT); +ClassArray ArrayOfByte(ArrayOfByteVT); +ClassArray ArrayOfChar(ArrayOfCharVT); +ClassArray ArrayOfShort(ArrayOfShortVT); +ClassArray ArrayOfInt(ArrayOfIntVT); +ClassArray ArrayOfFloat(ArrayOfFloatVT); +ClassArray ArrayOfDouble(ArrayOfDoubleVT); +ClassArray ArrayOfLong(ArrayOfLongVT); extern "C" void JavaArrayTracer(JavaObject*); @@ -620,10 +629,8 @@ JnjvmBootstrapLoader::constructPrimitiveArray(ClassArray& cl, const UTF8* name, ClassPrimitive* baseClass) { - cl.CommonClass::init(this, name); - cl.ClassArray::init(this, name, baseClass); + cl.initPrimitive(this, name, baseClass); classes->map.insert(std::make_pair(name, &cl)); - cl.virtualVT->tracer = (uintptr_t)JavaArrayTracer; return &cl; } From nicolas.geoffray at lip6.fr Fri Apr 10 23:10:12 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 11 Apr 2009 06:10:12 -0000 Subject: [vmkit-commits] [vmkit] r68861 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Message-ID: <200904110610.n3B6ACGC020541@zion.cs.uiuc.edu> Author: geoffray Date: Sat Apr 11 01:10:12 2009 New Revision: 68861 URL: http://llvm.org/viewvc/llvm-project?rev=68861&view=rev Log: Get the VT from the class array, if we static compile. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=68861&r1=68860&r2=68861&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Sat Apr 11 01:10:12 2009 @@ -1849,9 +1849,6 @@ compilingClass->classLoader->bootstrapLoader; UserClassArray* dcl = loader->getArrayClass(id); valCl = TheCompiler->getNativeClass(dcl); - if (valCl->getType() != module->JavaCommonClassType) - valCl = new BitCastInst(valCl, module->JavaCommonClassType, "", - currentBlock); #else Value* args[2] = { isolateLocal, ConstantInt::get(Type::Int32Ty, id - 4) }; @@ -1861,7 +1858,12 @@ LLVMAssessorInfo& LAI = LLVMAssessorInfo::AssessorInfo[charId]; sizeElement = LAI.sizeInBytesConstant; - TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); + if (TheCompiler->isStaticCompiling()) { + TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, + valCl, "", currentBlock); + } else { + TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); + } } else { uint16 index = readU2(bytecodes, i); CommonClass* cl = 0; @@ -1880,13 +1882,11 @@ if (TheCompiler->isStaticCompiling() && valCl->getType() != module->JavaClassArrayType) { valCl = new LoadInst(valCl, "", currentBlock); + TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, + valCl, "", currentBlock); + } else { + TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); } - - if (valCl->getType() != module->JavaCommonClassType) { - valCl = new BitCastInst(valCl, module->JavaCommonClassType, "", - currentBlock); - } - TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); } else { const llvm::Type* Ty = @@ -1894,10 +1894,6 @@ Value* args[2]= { valCl, Constant::getNullValue(Ty) }; valCl = CallInst::Create(module->GetArrayClassFunction, args, args + 2, "", currentBlock); - TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, valCl, "", - currentBlock); - valCl = new BitCastInst(valCl, module->JavaCommonClassType, "", - currentBlock); } sizeElement = module->constantPtrSize; From nicolas.geoffray at lip6.fr Fri Apr 10 23:25:13 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 11 Apr 2009 06:25:13 -0000 Subject: [vmkit-commits] [vmkit] r68862 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Message-ID: <200904110625.n3B6PDrL021037@zion.cs.uiuc.edu> Author: geoffray Date: Sat Apr 11 01:25:12 2009 New Revision: 68862 URL: http://llvm.org/viewvc/llvm-project?rev=68862&view=rev Log: Mindo from previous commit. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=68862&r1=68861&r2=68862&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Sat Apr 11 01:25:12 2009 @@ -1894,6 +1894,8 @@ Value* args[2]= { valCl, Constant::getNullValue(Ty) }; valCl = CallInst::Create(module->GetArrayClassFunction, args, args + 2, "", currentBlock); + TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, valCl, "", + currentBlock); } sizeElement = module->constantPtrSize; From nicolas.geoffray at lip6.fr Tue Apr 14 02:18:12 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 09:18:12 -0000 Subject: [vmkit-commits] [vmkit] r69037 - in /vmkit/trunk/lib/JnJVM: Compiler/JavaAOTCompiler.cpp Compiler/JavaJIT.h Compiler/JavaJITOpcodes.cpp Compiler/JnjvmModule.cpp VMCore/JavaClass.cpp VMCore/JavaClass.h Message-ID: <200904140918.n3E9IG7u018930@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 04:17:54 2009 New Revision: 69037 URL: http://llvm.org/viewvc/llvm-project?rev=69037&view=rev Log: The display of VT is made of VTs, not classes. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69037&r1=69036&r2=69037&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Tue Apr 14 04:17:54 2009 @@ -1201,24 +1201,17 @@ ConstantInt::get(Type::Int64Ty, VT->depth), PTy)); // display - const ArrayType* DTy = ArrayType::get(JnjvmModule::JavaCommonClassType, + const ArrayType* DTy = ArrayType::get(JnjvmModule::VTType, VT->depth + 1); std::vector TempElmts; - Constant* ClGEPs[2] = { JnjvmModule::constantZero, - JnjvmModule::constantZero }; - - for (uint32 i = 0; i <= VT->depth; ++i) { - Constant* Cl = getNativeClass(VT->display[i]); - if (Cl->getType() != JnjvmModule::JavaCommonClassType) - Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2); - + Constant* Cl = getVirtualTable(VT->display[i]); TempElmts.push_back(Cl); } - Constant* display = ConstantArray::get(DTy, TempElmts); TempElmts.clear(); + display = new GlobalVariable(DTy, true, GlobalValue::InternalLinkage, display, "", getLLVMModule()); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h?rev=69037&r1=69036&r2=69037&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h Tue Apr 14 04:17:54 2009 @@ -114,13 +114,6 @@ void convertValue(llvm::Value*& val, const llvm::Type* t1, llvm::BasicBlock* currentBlock, bool usign); - /// getConstantPoolAt - Return the value at the given index of the constant - /// pool. The generated code invokes the resolver if the constant pool - /// contains no value at the index. - llvm::Value* getConstantPoolAt(uint32 index, llvm::Function* resolver, - const llvm::Type* returnType, - llvm::Value* addArg, bool doThrow = true); - /// getCurrentThread - Emit code to get the current thread. llvm::Value* getCurrentThread(); @@ -350,7 +343,15 @@ /// of the returned value is Class. llvm::Value* getResolvedClass(uint16 index, bool clinit, bool doThrow, UserClass** alreadyResolved); + + /// getConstantPoolAt - Return the value at the given index of the constant + /// pool. The generated code invokes the resolver if the constant pool + /// contains no value at the index. + llvm::Value* getConstantPoolAt(uint32 index, llvm::Function* resolver, + const llvm::Type* returnType, + llvm::Value* addArg, bool doThrow = true); + llvm::Value* getResolvedVirtualTable(uint16 index, bool doThrow, bool clinit); //===----------------------- Java method calls ---------------------------===// Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=69037&r1=69036&r2=69037&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Tue Apr 14 04:17:54 2009 @@ -2009,7 +2009,7 @@ node->addIncoming(ConstantInt::getFalse(), currentBlock); Value* objCl = CallInst::Create(module->GetClassFunction, obj, "", ifFalse); - Value* classArgs[2] = { objCl, clVar }; + Value* classArgs[2] = { objCl, clVar }; if (isInterface(cl->access)) { Value* res = CallInst::Create(module->ImplementsFunction, Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69037&r1=69036&r2=69037&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Tue Apr 14 04:17:54 2009 @@ -130,9 +130,9 @@ } else { VT = &JavaObjectVT; VT->depth = 0; - VT->display = (CommonClass**) - cl->classLoader->allocator.Allocate(sizeof(CommonClass*)); - VT->display[0] = cl; + VT->display = (JavaVirtualTable**) + cl->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*)); + VT->display[0] = VT; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69037&r1=69036&r2=69037&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Tue Apr 14 04:17:54 2009 @@ -1290,7 +1290,9 @@ // Set the values in the JavaObject VT cl->virtualVT->depth = 0; cl->virtualVT->cl = cl; - cl->virtualVT->display = cl->display; + cl->virtualVT->display = (JavaVirtualTable**) + cl->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*)); + cl->virtualVT->display[0] = cl->virtualVT; Classpath* upcalls = cl->classLoader->bootstrapLoader->upcalls; @@ -1329,11 +1331,11 @@ // (3) Set depth and display for fast dynamic type checking. depth = cl->super->virtualVT->depth + 1; mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - display = (CommonClass**) - allocator.Allocate(sizeof(CommonClass*) * (depth + 1)); - size = depth * sizeof(UserCommonClass*); + display = (JavaVirtualTable**) + allocator.Allocate(sizeof(JavaVirtualTable*) * (depth + 1)); + size = depth * sizeof(JavaVirtualTable*); memcpy(display, cl->super->virtualVT->display, size); - display[depth] = C; + display[depth] = this; } JavaVirtualTable::JavaVirtualTable(ClassArray* C) { @@ -1348,8 +1350,9 @@ // (3) Set depth and display for fast dynamic type checking. depth = 1; mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - display = (CommonClass**)allocator.Allocate(sizeof(CommonClass*) * 2); - display[0] = C->super; - display[1] = C; + display = + (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2); + display[0] = &JavaObjectVT; + display[1] = this; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69037&r1=69036&r2=69037&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Tue Apr 14 04:17:54 2009 @@ -1338,7 +1338,7 @@ public: CommonClass* cl; size_t depth; - CommonClass** display; + JavaVirtualTable** display; uintptr_t init; uintptr_t equals; From nicolas.geoffray at lip6.fr Tue Apr 14 02:20:27 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 09:20:27 -0000 Subject: [vmkit-commits] [vmkit] r69038 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h Message-ID: <200904140920.n3E9KSgd019015@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 04:20:23 2009 New Revision: 69038 URL: http://llvm.org/viewvc/llvm-project?rev=69038&view=rev Log: This wasn't supposed to get in. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h?rev=69038&r1=69037&r2=69038&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.h Tue Apr 14 04:20:23 2009 @@ -351,8 +351,6 @@ const llvm::Type* returnType, llvm::Value* addArg, bool doThrow = true); - llvm::Value* getResolvedVirtualTable(uint16 index, bool doThrow, bool clinit); - //===----------------------- Java method calls ---------------------------===// /// makeArgs - Insert the arguments of a method in the vector. The arguments From nicolas.geoffray at lip6.fr Tue Apr 14 05:23:42 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 12:23:42 -0000 Subject: [vmkit-commits] [vmkit] r69039 - /vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Message-ID: <200904141223.n3ECNgaY025631@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 07:23:39 2009 New Revision: 69039 URL: http://llvm.org/viewvc/llvm-project?rev=69039&view=rev Log: Improve escape analysis pass with NoCapture and loop handling. Modified: vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Modified: vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp?rev=69039&r1=69038&r2=69039&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Tue Apr 14 07:23:39 2009 @@ -1,6 +1,6 @@ //===------EscapeAnalysis.cpp - Simple LLVM escape analysis ---------------===// // -// The Micro Virtual Machine +// The VMKit project // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. @@ -15,6 +15,7 @@ #include "llvm/Pass.h" #include "llvm/Instructions.h" #include "llvm/Analysis/LoopInfo.h" +#include "llvm/Support/CallSite.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" @@ -42,7 +43,7 @@ virtual bool runOnFunction(Function &F); private: - bool processMalloc(Instruction* I, Value* Size, Value* VT); + bool processMalloc(Instruction* I, Value* Size, Value* VT, Loop* CurLoop); }; char EscapeAnalysis::ID = 0; @@ -58,22 +59,47 @@ for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { BasicBlock *Cur = BI; - // Don't bother if we're in a loop. We rely on the memory manager to - // allocate with a bump pointer allocator. Sure we could analyze more - // to see if the object could in fact be stack allocated, but just be - // lazy for now. - if (LI->getLoopFor(Cur)) continue; + // Get the parent loop if there is one. If the allocation happens in a loop + // we must make sure that the allocated value is not used outside of + // the loop. If the allocation does not escape and it is only used inside + // the loop, we will hoist the allocation in the pre-header of the loop. + Loop* CurLoop = LI->getLoopFor(Cur); + if (CurLoop) { + Loop* NextLoop = CurLoop->getParentLoop(); + while (NextLoop) { + CurLoop = NextLoop; + NextLoop = CurLoop->getParentLoop(); + } + } for (BasicBlock::iterator II = Cur->begin(), IE = Cur->end(); II != IE;) { Instruction *I = II; II++; - if (CallInst *CI = dyn_cast(I)) { - if (CI->getOperand(0) == Allocator) { - Changed |= processMalloc(CI, CI->getOperand(1), CI->getOperand(2)); - } - } else if (InvokeInst *CI = dyn_cast(I)) { - if (CI->getOperand(0) == Allocator) { - Changed |= processMalloc(CI, CI->getOperand(3), CI->getOperand(4)); + CallSite Call = CallSite::get(I); + if (Call.getInstruction() && Call.getCalledValue() == Allocator) { + + if (CurLoop) { + bool escapesLoop = false; + for (Value::use_iterator U = I->use_begin(), E = I->use_end(); + U != E; ++U) { + if (Instruction* II = dyn_cast(U)) { + BasicBlock* BBU = II->getParent(); + if (!CurLoop->contains(BBU)) { + escapesLoop = true; + break; + } + } + } + + if (escapesLoop) continue; + } + + if (CallInst *CI = dyn_cast(I)) { + Changed |= processMalloc(CI, CI->getOperand(1), CI->getOperand(2), + CurLoop); + } else if (InvokeInst *CI = dyn_cast(I)) { + Changed |= processMalloc(CI, CI->getOperand(3), CI->getOperand(4), + CurLoop); } } } @@ -88,16 +114,22 @@ for (Value::use_iterator I = Ins->use_begin(), E = Ins->use_end(); I != E; ++I) { if (Instruction* II = dyn_cast(I)) { - if (CallInst* CI = dyn_cast(II)) { - if (!CI->onlyReadsMemory()) return true; - } - else if (InvokeInst* CI = dyn_cast(II)) { - if (!CI->onlyReadsMemory()) return true; - } - else if (dyn_cast(II)) { + if (II->getOpcode() == Instruction::Call || + II->getOpcode() == Instruction::Invoke) { + + CallSite CS = CallSite::get(II); + if (!CS.onlyReadsMemory()) return true; + + CallSite::arg_iterator B = CS.arg_begin(), E = CS.arg_end(); + for (CallSite::arg_iterator A = B; A != E; ++A) { + if (A->get() == Ins && + !CS.paramHasAttr(A - B + 1, Attribute::NoCapture)) { + return true; + } + } + } else if (dyn_cast(II)) { if (escapes(II, visited)) return true; - } - else if (StoreInst* SI = dyn_cast(II)) { + } else if (StoreInst* SI = dyn_cast(II)) { if (AllocaInst * AI = dyn_cast(SI->getOperand(1))) { if (!visited[AI]) { visited[AI] = true; @@ -106,17 +138,15 @@ } else if (SI->getOperand(0) == Ins) { return true; } - } - else if (dyn_cast(II)) { + } else if (dyn_cast(II)) { if (isa(II->getType())) { if (escapes(II, visited)) return true; // allocas } - } - else if (dyn_cast(II)) { + } else if (dyn_cast(II)) { if (escapes(II, visited)) return true; - } - else if (dyn_cast(II)) return true; - else if (dyn_cast(II)) { + } else if (dyn_cast(II)) { + return true; + } else if (dyn_cast(II)) { if (!visited[II]) { visited[II] = true; if (escapes(II, visited)) return true; @@ -129,7 +159,8 @@ return false; } -bool EscapeAnalysis::processMalloc(Instruction* I, Value* Size, Value* VT) { +bool EscapeAnalysis::processMalloc(Instruction* I, Value* Size, Value* VT, + Loop* CurLoop) { Instruction* Alloc = I; ConstantInt* CI = dyn_cast(Size); @@ -154,6 +185,14 @@ } else { return false; } + + // The object does not have a finalizer and is never used. Remove the + // allocation as it will not have side effects. + if (!hasFinalizer && !Alloc->getNumUses()) { + DOUT << "Escape analysis removes instruction " << *Alloc << ": "; + Alloc->eraseFromParent(); + return true; + } uint64_t NSize = CI->getZExtValue(); // If the class has a finalize method, do not stack allocate the object. @@ -161,6 +200,19 @@ std::map visited; bool esc = escapes(Alloc, visited); if (!esc) { + + if (CurLoop) { + // The object does not escape and is only used in the loop where it + // is allocated. We hoist the allocation in the pre-header so that + // we don't end up with tons of allocations on the stack. + BasicBlock* BB = CurLoop->getLoopPreheader(); + assert(BB && "No Preheader!"); + DOUT << "Escape analysis hoisting to " << BB->getName() << ": "; + DOUT << *Alloc; + Alloc->removeFromParent(); + BB->getInstList().insert(BB->getTerminator(), Alloc); + } + AllocaInst* AI = new AllocaInst(Type::Int8Ty, Size, "", Alloc); BitCastInst* BI = new BitCastInst(AI, Alloc->getType(), "", Alloc); DOUT << "escape" << Alloc->getParent()->getParent()->getName() << "\n"; From nicolas.geoffray at lip6.fr Tue Apr 14 06:11:05 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 13:11:05 -0000 Subject: [vmkit-commits] [vmkit] r69040 - /vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Message-ID: <200904141311.n3EDB561027293@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 08:11:03 2009 New Revision: 69040 URL: http://llvm.org/viewvc/llvm-project?rev=69040&view=rev Log: Also look at what a function returns, when the object is given to the function. Modified: vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Modified: vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp?rev=69040&r1=69039&r2=69040&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/EscapeAnalysis.cpp Tue Apr 14 08:11:03 2009 @@ -127,6 +127,12 @@ return true; } } + + // We must also consider the value returned by the function. + if (II->getType() == Ins->getType()) { + if (escapes(II, visited)) return true; + } + } else if (dyn_cast(II)) { if (escapes(II, visited)) return true; } else if (StoreInst* SI = dyn_cast(II)) { From nicolas.geoffray at lip6.fr Tue Apr 14 09:26:16 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 16:26:16 -0000 Subject: [vmkit-commits] [vmkit] r69042 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/JavaInitialise.cpp lib/JnJVM/VMCore/JnjvmClassLoader.cpp lib/JnJVM/VMCore/JnjvmClassLoader.h Message-ID: <200904141626.n3EGQHp8002907@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 11:26:15 2009 New Revision: 69042 URL: http://llvm.org/viewvc/llvm-project?rev=69042&view=rev Log: Remove all statically allocated internal classes and VT. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h 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/JnjvmClassLoader.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Tue Apr 14 11:26:15 2009 @@ -369,11 +369,6 @@ bool enabledException; - /// allocateVT - Allocate a VT for the class. The VT will be the VT of - /// instances of the class. - void allocateVT(Class* cl); - - virtual void makeVT(Class* cl) = 0; Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Tue Apr 14 11:26:15 2009 @@ -33,17 +33,6 @@ using namespace jnjvm; using namespace llvm; -extern JavaVirtualTable JavaArrayVT; - -extern ClassArray ArrayOfBool; -extern ClassArray ArrayOfByte; -extern ClassArray ArrayOfChar; -extern ClassArray ArrayOfShort; -extern ClassArray ArrayOfInt; -extern ClassArray ArrayOfFloat; -extern ClassArray ArrayOfDouble; -extern ClassArray ArrayOfLong; - bool JavaAOTCompiler::isCompiling(const CommonClass* cl) const { if (cl->isClass()) { // A class is being static compiled if owner class is not null. @@ -1113,7 +1102,7 @@ const StructType* STy = StructType::get(Elemts); std::vector Cts; - Cts.push_back(CreateConstantForBaseObject(&ArrayOfChar)); + Cts.push_back(CreateConstantForBaseObject(val->getClass())); Cts.push_back(ConstantInt::get(JnjvmModule::pointerSizeType, val->size)); std::vector Vals; @@ -1262,29 +1251,6 @@ generateStubs = true; assumeCompiled = false; - const Type* ATy = JnjvmModule::JavaClassArrayType->getContainedType(0); - GlobalVariable* varGV = 0; - -#define PRIMITIVE_ARRAY(name) \ - varGV = new GlobalVariable(ATy, true, GlobalValue::ExternalLinkage, \ - 0, #name, getLLVMModule()); \ - arrayClasses.insert(std::make_pair(&name, varGV)); \ - varGV = new GlobalVariable(JnjvmModule::VTType->getContainedType(0), true, \ - GlobalValue::ExternalLinkage, \ - 0, #name"VT", getLLVMModule()); \ - virtualTables.insert(std::make_pair(name.virtualVT, varGV)); - - PRIMITIVE_ARRAY(ArrayOfBool) - PRIMITIVE_ARRAY(ArrayOfByte) - PRIMITIVE_ARRAY(ArrayOfChar) - PRIMITIVE_ARRAY(ArrayOfShort) - PRIMITIVE_ARRAY(ArrayOfInt) - PRIMITIVE_ARRAY(ArrayOfFloat) - PRIMITIVE_ARRAY(ArrayOfDouble) - PRIMITIVE_ARRAY(ArrayOfLong) - -#undef PRIMITIVE_ARRAY - std::vector llvmArgs; llvmArgs.push_back(JnjvmModule::ptrType); // class loader. const FunctionType* FTy = FunctionType::get(Type::VoidTy, llvmArgs, false); @@ -1462,18 +1428,11 @@ void JavaAOTCompiler::makeVT(Class* cl) { internalMakeVT(cl); -#ifndef WITHOUT_VTABLE VirtualTable* VT = cl->virtualVT; for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { JavaMethod& meth = cl->virtualMethods[i]; ((void**)VT)[meth.offset] = &meth; } - - if (!cl->super) { - VT->destructor = 0; - ClassArray::initialiseVT(); - } -#endif } void JavaAOTCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) { Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Tue Apr 14 11:26:15 2009 @@ -27,9 +27,6 @@ using namespace jnjvm; using namespace llvm; -extern JavaVirtualTable JavaArrayVT; -extern JavaVirtualTable ArrayObjectVT; - Constant* JavaJITCompiler::getNativeClass(CommonClass* classDef) { const llvm::Type* Ty = classDef->isClass() ? JnjvmModule::JavaClassType : JnjvmModule::JavaCommonClassType; @@ -88,14 +85,13 @@ assert(0 && "Should not be here"); abort(); #endif - void* obj = ((Class*)classDef)->getStaticInstance(); + void* obj = classDef->getStaticInstance(); if (!obj) { - Class* cl = (Class*)classDef; classDef->acquire(); - obj = cl->getStaticInstance(); + obj = classDef->getStaticInstance(); if (!obj) { // Allocate now so that compiled code can reference it. - obj = cl->allocateStaticInstance(JavaThread::get()->getJVM()); + obj = classDef->allocateStaticInstance(JavaThread::get()->getJVM()); } classDef->release(); } @@ -140,10 +136,9 @@ void JavaJITCompiler::makeVT(Class* cl) { internalMakeVT(cl); -#ifndef WITHOUT_VTABLE - JavaVirtualTable* VT = cl->virtualVT; - - assert(VT); + JavaVirtualTable* VT = cl->virtualVT; + assert(VT && "No VT was allocated!"); + // Fill the virtual table with function pointers. ExecutionEngine* EE = mvm::MvmModule::executionEngine; for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { @@ -154,22 +149,14 @@ // 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) - VT->destructor = 0; -#else - Function* func = parseFunction(&meth); +#if !defined(ISOLATE_SHARING) && !defined(USE_GC_BOEHM) if (!cl->super) { meth.canBeInlined = true; - VT->destructor = 0; } else { - Function::iterator BB = func->begin(); - BasicBlock::iterator I = BB->begin(); - if (isa(I)) { - VT->destructor = 0; - } else { // LLVM does not allow recursive compilation. Create the code now. + // TODO: improve this when we have proper initialization. + Function* func = parseFunction(&meth); VT->destructor = (uintptr_t)EE->getPointerToFunction(func); - } } #endif } else { @@ -186,12 +173,6 @@ func->deleteBody(); #endif - // If there is no super, then it's the first VT that we allocate. Assign - // this VT to native types. - if (!(cl->super)) { - ClassArray::initialiseVT(); - } -#endif } void JavaJITCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) { @@ -232,5 +213,5 @@ vm->waitForExit(); delete newArgv; - return 0; + return 0; } Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Tue Apr 14 11:26:15 2009 @@ -28,9 +28,6 @@ using namespace jnjvm; using namespace llvm; - -extern JavaVirtualTable JavaObjectVT; - #ifdef WITH_TRACER const llvm::FunctionType* JnjvmModule::MarkAndTraceType = 0; #endif @@ -95,52 +92,6 @@ enabledException = true; } -#ifndef WITHOUT_VTABLE -void JavaLLVMCompiler::allocateVT(Class* cl) { - for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { - JavaMethod& meth = cl->virtualMethods[i]; - if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) { - meth.offset = 0; - } else { - JavaMethod* parent = cl->super? - cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true, - 0) : - 0; - - uint64_t offset = 0; - if (!parent) { - offset = cl->virtualTableSize++; - meth.offset = offset; - } else { - offset = parent->offset; - meth.offset = parent->offset; - } - } - } - - JavaVirtualTable* VT = 0; - if (cl->super) { - uint32 size = cl->virtualTableSize; - mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - Class* super = cl->super; - assert(cl->virtualTableSize >= super->virtualTableSize && - "Super VT bigger than own VT"); - assert(super->virtualVT && "Super does not have a VT!"); - VT = new(allocator, size) JavaVirtualTable(cl); - } else { - VT = &JavaObjectVT; - VT->depth = 0; - VT->display = (JavaVirtualTable**) - cl->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*)); - VT->display[0] = VT; - - } - - cl->virtualVT = VT; -} -#endif - - #ifdef WITH_TRACER llvm::Function* JavaLLVMCompiler::internalMakeTracer(Class* cl, bool stat) { @@ -228,27 +179,30 @@ void JavaLLVMCompiler::internalMakeVT(Class* cl) { - JavaVirtualTable* VT = 0; -#ifdef WITHOUT_VTABLE - mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - VT = (JavaVirtualTable*)allocator.Allocate(VT_SIZE); - memcpy(VT, JavaObjectVT, VT_SIZE); - cl->virtualVT = VT; -#else - if (cl->super) { - if (isStaticCompiling() && !cl->super->virtualVT) { - makeVT(cl->super); - } + for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { + JavaMethod& meth = cl->virtualMethods[i]; + if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) { + meth.offset = 0; + } else { + JavaMethod* parent = cl->super? + cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true, + 0) : + 0; - cl->virtualTableSize = cl->super->virtualTableSize; - } else { - cl->virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); + uint64_t offset = 0; + if (!parent) { + offset = cl->virtualTableSize++; + meth.offset = offset; + } else { + offset = parent->offset; + meth.offset = parent->offset; + } + } } - // Allocate the virtual table. - allocateVT(cl); - VT = cl->virtualVT; -#endif + uint32 size = cl->virtualTableSize; + mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; + cl->virtualVT = new(allocator, size) JavaVirtualTable(cl); } void JavaLLVMCompiler::resolveVirtualClass(Class* cl) { Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Tue Apr 14 11:26:15 2009 @@ -40,9 +40,8 @@ Class* ClassArray::SuperArray; Class** ClassArray::InterfacesArray; -extern JavaVirtualTable JavaObjectVT; - extern "C" void JavaArrayTracer(JavaObject*); +extern "C" void JavaObjectTracer(JavaObject*); extern "C" void ArrayObjectTracer(JavaObject*); Attribut::Attribut(const UTF8* name, uint32 length, @@ -257,7 +256,7 @@ } } -void CommonClass::init(JnjvmClassLoader* loader, const UTF8* n) { +CommonClass::CommonClass(JnjvmClassLoader* loader, const UTF8* n) { name = n; classLoader = loader; nbInterfaces = 0; @@ -304,8 +303,8 @@ memset(IsolateInfo, 0, sizeof(TaskClassMirror) * NR_ISOLATES); } -void ClassArray::init(JnjvmClassLoader* loader, const UTF8* n, - UserCommonClass* base) { +ClassArray::ClassArray(JnjvmClassLoader* loader, const UTF8* n, + UserCommonClass* base) : CommonClass(loader, n) { _baseClass = base; super = ClassArray::SuperArray; interfaces = ClassArray::InterfacesArray; @@ -313,26 +312,6 @@ uint32 size = JavaVirtualTable::getNumMethods(); virtualVT = new(loader->allocator, size) JavaVirtualTable(this); - virtualVT->tracer = (uintptr_t)ArrayObjectTracer; - - depth = 1; - display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*)); - display[0] = ClassArray::SuperArray; - display[1] = this; - access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC | JNJVM_ARRAY; -} - -void ClassArray::initPrimitive(JnjvmClassLoader* loader, const UTF8* n, - UserCommonClass* base) { - CommonClass::init(loader, n); - - _baseClass = base; - super = ClassArray::SuperArray; - interfaces = ClassArray::InterfacesArray; - nbInterfaces = 2; - - virtualVT->tracer = (uintptr_t)JavaArrayTracer; - virtualVT->cl = this; depth = 1; display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*)); @@ -796,6 +775,7 @@ display = (CommonClass**) classLoader->allocator.Allocate(sizeof(CommonClass*)); display[0] = this; + virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); } else { super = classLoader->loadName(superUTF8, true, true); depth = super->depth + 1; @@ -804,6 +784,7 @@ allocator.Allocate(sizeof(CommonClass*) * (depth + 1)); memcpy(display, super->display, depth * sizeof(UserCommonClass*)); display[depth] = this; + virtualTableSize = super->virtualTableSize; } for (unsigned i = 0; i < realNbInterfaces; i++) @@ -855,7 +836,7 @@ Attribut* Class::readAttributs(Reader& reader, uint16& size) { uint16 nba = reader.readU2(); - + Attribut* attributs = new(classLoader->allocator) Attribut[nba]; for (int i = 0; i < nba; i++) { @@ -974,6 +955,7 @@ if (!needsInitialisationCheck()) { setInitializationState(ready); } + if (!super) ClassArray::initialiseVT(); setOwnerClass(0); broadcastClass(); release(); @@ -1312,47 +1294,91 @@ COPY(upcalls->ArrayOfFloat) COPY(upcalls->ArrayOfDouble) COPY(upcalls->ArrayOfLong) - COPY(upcalls->ArrayOfObject) - COPY(upcalls->ArrayOfString) #undef COPY - + + JnjvmClassLoader* JCL = cl->classLoader; + // Load array classes that JnJVM internally uses. + upcalls->ArrayOfString = + JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/String;")); + + upcalls->ArrayOfObject = + JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/Object;")); } JavaVirtualTable::JavaVirtualTable(Class* C) { + + if (C->super) { + // (1) Copy the super VT into the current VT. + uint32 size = C->super->virtualTableSize * sizeof(uintptr_t); + memcpy(this, C->super->virtualVT, size); + + // (2) Set the class of this VT. + cl = C; - // (1) Copy the super VT into the current VT. - uint32 size = C->super->virtualTableSize * sizeof(uintptr_t); - memcpy(this, C->super->virtualVT, size); + // (3) Set depth and display for fast dynamic type checking. + depth = C->super->virtualVT->depth + 1; + mvm::BumpPtrAllocator& allocator = C->classLoader->allocator; + display = (JavaVirtualTable**) + allocator.Allocate(sizeof(JavaVirtualTable*) * (depth + 1)); + size = depth * sizeof(JavaVirtualTable*); + memcpy(display, C->super->virtualVT->display, size); + display[depth] = this; + } else { + // (1) Set the tracer, destructor and delete + tracer = (uintptr_t)JavaObjectTracer; + destructor = 0; + operatorDelete = 0; + + // (2) Set the class of this VT. + cl = C; + + // (3) Set depth and display for fast dynamic type checking. + depth = 0; + display = (JavaVirtualTable**) + C->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*)); + display[0] = this; + destructor = 0; + } - // (2) Set the class of this VT. - cl = C; - // (3) Set depth and display for fast dynamic type checking. - depth = cl->super->virtualVT->depth + 1; - mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - display = (JavaVirtualTable**) - allocator.Allocate(sizeof(JavaVirtualTable*) * (depth + 1)); - size = depth * sizeof(JavaVirtualTable*); - memcpy(display, cl->super->virtualVT->display, size); - display[depth] = this; } JavaVirtualTable::JavaVirtualTable(ClassArray* C) { + + if (!C->baseClass()->isPrimitive()) { + // (1) Copy the super VT into the current VT. + uint32 size = getNumMethods() * sizeof(uintptr_t); + memcpy(this, C->super->virtualVT, size); + tracer = (uintptr_t)ArrayObjectTracer; - // (1) Copy the super VT into the current VT. - uint32 size = getNumMethods() * sizeof(uintptr_t); - memcpy(this, &JavaObjectVT, size); - - // (2) Set the class of this VT. - cl = C; + // (2) Set the class of this VT. + cl = C; - // (3) Set depth and display for fast dynamic type checking. - depth = 1; - mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - display = - (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2); - display[0] = &JavaObjectVT; - display[1] = this; + // (3) Set depth and display for fast dynamic type checking. + depth = 1; + mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; + display = + (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2); + display[0] = C->super->virtualVT; + display[1] = this; + } else { + // (1) Set the tracer, destructor and delete + tracer = (uintptr_t)JavaArrayTracer; + destructor = 0; + operatorDelete = 0; + + // (2) Set the class of this VT. + cl = C; + + // (3) Set depth and display for fast dynamic type checking. Since + // JavaObject has not been loaded yet, don't use super. + depth = 1; + mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; + display = + (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2); + display[0] = 0; + display[1] = this; + } } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Tue Apr 14 11:26:15 2009 @@ -305,9 +305,7 @@ /// CommonClass - Create a class with th given name. /// - CommonClass(JnjvmClassLoader* loader, const UTF8* name) { - init(loader, name); - } + CommonClass(JnjvmClassLoader* loader, const UTF8* name); /// ~CommonClass - Free memory used by this class, and remove it from /// metadata. @@ -318,10 +316,6 @@ /// CommonClass(); - /// init - initialize the class. - /// - void init(JnjvmClassLoader* JCL, const UTF8* n); - /// setInterfaces - Set the interfaces of the class. /// void setInterfaces(Class** I) { @@ -911,26 +905,10 @@ /// JavaArray* doNew(sint32 n, Jnjvm* vm); - /// init - Initialize the array class. - /// - void init(JnjvmClassLoader* loader, const UTF8* name, - UserCommonClass* baseClass); - - /// initPrimitive - Initialize the primitive array class. - /// - void initPrimitive(JnjvmClassLoader* loader, const UTF8* name, - UserCommonClass* baseClass); - - /// ClassArray - Constructor with a VT. - /// - ClassArray(JavaVirtualTable& VT) { virtualVT = &VT; } - /// ClassArray - Construct a Java array class with the given name. /// ClassArray(JnjvmClassLoader* loader, const UTF8* name, - UserCommonClass* baseClass) : CommonClass (loader, name) { - init(loader, name, baseClass); - } + UserCommonClass* baseClass); /// SuperArray - The super of class arrays. Namely java/lang/Object. /// Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Tue Apr 14 11:26:15 2009 @@ -23,8 +23,6 @@ using namespace jnjvm; -JavaVirtualTable JavaObjectVT; - static void initialiseVT() { # define INIT(X) { \ @@ -43,14 +41,6 @@ #endif #undef INIT -#define INIT(X) { \ - X fake; \ - void* V = ((void**)(void*)(&fake))[0]; \ - memcpy(&(X##VT), V, sizeof(VirtualTable)); \ - X##VT.destructor = 0; } - - INIT(JavaObject); -#undef INIT } #ifdef ISOLATE_SHARING Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Tue Apr 14 11:26:15 2009 @@ -52,26 +52,6 @@ using namespace jnjvm; -JavaVirtualTable ArrayOfBoolVT; -JavaVirtualTable ArrayOfByteVT; -JavaVirtualTable ArrayOfCharVT; -JavaVirtualTable ArrayOfShortVT; -JavaVirtualTable ArrayOfIntVT; -JavaVirtualTable ArrayOfFloatVT; -JavaVirtualTable ArrayOfDoubleVT; -JavaVirtualTable ArrayOfLongVT; - -ClassArray ArrayOfBool(ArrayOfBoolVT); -ClassArray ArrayOfByte(ArrayOfByteVT); -ClassArray ArrayOfChar(ArrayOfCharVT); -ClassArray ArrayOfShort(ArrayOfShortVT); -ClassArray ArrayOfInt(ArrayOfIntVT); -ClassArray ArrayOfFloat(ArrayOfFloatVT); -ClassArray ArrayOfDouble(ArrayOfDoubleVT); -ClassArray ArrayOfLong(ArrayOfLongVT); - -extern "C" void JavaArrayTracer(JavaObject*); - typedef void (*static_init_t)(JnjvmClassLoader*); JnjvmBootstrapLoader::JnjvmBootstrapLoader(mvm::BumpPtrAllocator& Alloc, @@ -117,36 +97,28 @@ upcalls->OfByte = UPCALL_PRIMITIVE_CLASS(this, "byte", 1); // Create the primitive arrays. - upcalls->ArrayOfChar = constructPrimitiveArray(ArrayOfChar, - asciizConstructUTF8("[C"), + upcalls->ArrayOfChar = constructPrimitiveArray(asciizConstructUTF8("[C"), upcalls->OfChar); - upcalls->ArrayOfByte = constructPrimitiveArray(ArrayOfByte, - asciizConstructUTF8("[B"), + upcalls->ArrayOfByte = constructPrimitiveArray(asciizConstructUTF8("[B"), upcalls->OfByte); - upcalls->ArrayOfInt = constructPrimitiveArray(ArrayOfInt, - asciizConstructUTF8("[I"), + upcalls->ArrayOfInt = constructPrimitiveArray(asciizConstructUTF8("[I"), upcalls->OfInt); - upcalls->ArrayOfBool = constructPrimitiveArray(ArrayOfBool, - asciizConstructUTF8("[Z"), + upcalls->ArrayOfBool = constructPrimitiveArray(asciizConstructUTF8("[Z"), upcalls->OfBool); - upcalls->ArrayOfLong = constructPrimitiveArray(ArrayOfLong, - asciizConstructUTF8("[J"), + upcalls->ArrayOfLong = constructPrimitiveArray(asciizConstructUTF8("[J"), upcalls->OfLong); - upcalls->ArrayOfFloat = constructPrimitiveArray(ArrayOfFloat, - asciizConstructUTF8("[F"), + upcalls->ArrayOfFloat = constructPrimitiveArray(asciizConstructUTF8("[F"), upcalls->OfFloat); - upcalls->ArrayOfDouble = constructPrimitiveArray(ArrayOfDouble, - asciizConstructUTF8("[D"), + upcalls->ArrayOfDouble = constructPrimitiveArray(asciizConstructUTF8("[D"), upcalls->OfDouble); - upcalls->ArrayOfShort = constructPrimitiveArray(ArrayOfShort, - asciizConstructUTF8("[S"), + upcalls->ArrayOfShort = constructPrimitiveArray(asciizConstructUTF8("[S"), upcalls->OfShort); // Fill the maps. @@ -179,25 +151,31 @@ // Now that native types have been loaded, try to find if we have a // pre-compiled rt.jar if (dlLoad) { - nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); - if (nativeHandle) { - // Found it! - SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object"); + SuperArray = (Class*)dlsym(SELF_HANDLE, "java.lang.Object"); + if (!SuperArray) { + nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); + if (nativeHandle) { + // Found it! + SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object"); + } + } - if (SuperArray) { - ClassArray::SuperArray = (Class*)SuperArray->getInternal(); - // We have the java/lang/Object class, execute the static initializer. - static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; - assert(init && "Loaded the wrong boot library"); - init(this); - ClassArray::initialiseVT(); - } + if (SuperArray) { + ClassArray::SuperArray = (Class*)SuperArray->getInternal(); + // We have the java/lang/Object class, execute the static initializer. + static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; + assert(init && "Loaded the wrong boot library"); + init(this); + ClassArray::initialiseVT(); } } // We haven't found a pre-compiled rt.jar, load the root class ourself. if (!SuperArray) { - + + // We can not resolve java.lang.Object yet, because we may not be + // running in a Java thread, and we may not have a compiler + // available. SuperArray = loadName(asciizConstructUTF8("java/lang/Object"), false, false); ClassArray::SuperArray = (Class*)SuperArray->getInternal(); @@ -213,13 +191,6 @@ ClassArray::InterfacesArray[0] = (Class*)InterfacesArray[0]->getInternal(); ClassArray::InterfacesArray[1] = (Class*)(InterfacesArray[1]->getInternal()); - - // Load array classes that JnJVM internally uses. - upcalls->ArrayOfString = - constructArray(asciizConstructUTF8("[Ljava/lang/String;")); - - upcalls->ArrayOfObject = - constructArray(asciizConstructUTF8("[Ljava/lang/Object;")); Attribut::codeAttribut = asciizConstructUTF8("Code"); @@ -626,12 +597,12 @@ } ClassArray* -JnjvmBootstrapLoader::constructPrimitiveArray(ClassArray& cl, const UTF8* name, +JnjvmBootstrapLoader::constructPrimitiveArray(const UTF8* name, ClassPrimitive* baseClass) { - cl.initPrimitive(this, name, baseClass); - classes->map.insert(std::make_pair(name, &cl)); - return &cl; + ClassArray* cl = new(allocator) UserClassArray(this, name, baseClass); + classes->map.insert(std::make_pair(name, cl)); + return cl; } Typedef* JnjvmClassLoader::internalConstructType(const UTF8* name) { Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=69042&r1=69041&r2=69042&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Tue Apr 14 11:26:15 2009 @@ -289,7 +289,7 @@ /// constructPrimitiveArray - Hashes the primitive array. /// - ClassArray* constructPrimitiveArray(ClassArray& cl, const UTF8* name, + ClassArray* constructPrimitiveArray(const UTF8* name, ClassPrimitive* prim); public: From nicolas.geoffray at lip6.fr Tue Apr 14 09:54:57 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 16:54:57 -0000 Subject: [vmkit-commits] [vmkit] r69047 - /vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904141654.n3EGsv3Y004339@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 11:54:55 2009 New Revision: 69047 URL: http://llvm.org/viewvc/llvm-project?rev=69047&view=rev Log: UTF8s do not need VTs. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69047&r1=69046&r2=69047&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Tue Apr 14 11:54:55 2009 @@ -358,7 +358,9 @@ std::vector Elmts; // virtual table - if (cl->isClass()) { + if (!cl) { + Elmts.push_back(Constant::getNullValue(JnjvmModule::VTType)); + } else if (cl->isClass()) { Elmts.push_back(getVirtualTable(cl->asClass()->virtualVT)); } else { Elmts.push_back(getVirtualTable(cl->asArrayClass()->virtualVT)); @@ -1102,7 +1104,7 @@ const StructType* STy = StructType::get(Elemts); std::vector Cts; - Cts.push_back(CreateConstantForBaseObject(val->getClass())); + Cts.push_back(CreateConstantForBaseObject(0)); Cts.push_back(ConstantInt::get(JnjvmModule::pointerSizeType, val->size)); std::vector Vals; From nicolas.geoffray at lip6.fr Tue Apr 14 09:55:32 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 16:55:32 -0000 Subject: [vmkit-commits] [vmkit] r69048 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Message-ID: <200904141655.n3EGtXtq004377@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 11:55:32 2009 New Revision: 69048 URL: http://llvm.org/viewvc/llvm-project?rev=69048&view=rev Log: Bugfix for static compilation. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=69048&r1=69047&r2=69048&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Tue Apr 14 11:55:32 2009 @@ -1858,9 +1858,11 @@ LLVMAssessorInfo& LAI = LLVMAssessorInfo::AssessorInfo[charId]; sizeElement = LAI.sizeInBytesConstant; - if (TheCompiler->isStaticCompiling()) { - TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, - valCl, "", currentBlock); + if (TheCompiler->isStaticCompiling() && + valCl->getType() != module->JavaClassArrayType) { + valCl = new LoadInst(valCl, "", currentBlock); + TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, + valCl, "", currentBlock); } else { TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); } From nicolas.geoffray at lip6.fr Tue Apr 14 15:15:40 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 22:15:40 -0000 Subject: [vmkit-commits] [vmkit] r69085 - in /vmkit/trunk/lib/JnJVM/VMCore: JnjvmClassLoader.cpp JnjvmClassLoader.h Message-ID: <200904142215.n3EMFeVt017121@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 17:15:40 2009 New Revision: 69085 URL: http://llvm.org/viewvc/llvm-project?rev=69085&view=rev Log: Code cleanup. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69085&r1=69084&r2=69085&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Tue Apr 14 17:15:40 2009 @@ -97,29 +97,29 @@ upcalls->OfByte = UPCALL_PRIMITIVE_CLASS(this, "byte", 1); // Create the primitive arrays. - upcalls->ArrayOfChar = constructPrimitiveArray(asciizConstructUTF8("[C"), - upcalls->OfChar); + upcalls->ArrayOfChar = constructArray(asciizConstructUTF8("[C"), + upcalls->OfChar); - upcalls->ArrayOfByte = constructPrimitiveArray(asciizConstructUTF8("[B"), - upcalls->OfByte); + upcalls->ArrayOfByte = constructArray(asciizConstructUTF8("[B"), + upcalls->OfByte); - upcalls->ArrayOfInt = constructPrimitiveArray(asciizConstructUTF8("[I"), - upcalls->OfInt); + upcalls->ArrayOfInt = constructArray(asciizConstructUTF8("[I"), + upcalls->OfInt); - upcalls->ArrayOfBool = constructPrimitiveArray(asciizConstructUTF8("[Z"), - upcalls->OfBool); + upcalls->ArrayOfBool = constructArray(asciizConstructUTF8("[Z"), + upcalls->OfBool); - upcalls->ArrayOfLong = constructPrimitiveArray(asciizConstructUTF8("[J"), - upcalls->OfLong); + upcalls->ArrayOfLong = constructArray(asciizConstructUTF8("[J"), + upcalls->OfLong); - upcalls->ArrayOfFloat = constructPrimitiveArray(asciizConstructUTF8("[F"), - upcalls->OfFloat); + upcalls->ArrayOfFloat = constructArray(asciizConstructUTF8("[F"), + upcalls->OfFloat); - upcalls->ArrayOfDouble = constructPrimitiveArray(asciizConstructUTF8("[D"), - upcalls->OfDouble); + upcalls->ArrayOfDouble = constructArray(asciizConstructUTF8("[D"), + upcalls->OfDouble); - upcalls->ArrayOfShort = constructPrimitiveArray(asciizConstructUTF8("[S"), - upcalls->OfShort); + upcalls->ArrayOfShort = constructArray(asciizConstructUTF8("[S"), + upcalls->OfShort); // Fill the maps. primitiveMap[I_VOID] = upcalls->OfVoid; @@ -596,15 +596,6 @@ return res; } -ClassArray* -JnjvmBootstrapLoader::constructPrimitiveArray(const UTF8* name, - ClassPrimitive* baseClass) { - - ClassArray* cl = new(allocator) UserClassArray(this, name, baseClass); - classes->map.insert(std::make_pair(name, cl)); - return cl; -} - Typedef* JnjvmClassLoader::internalConstructType(const UTF8* name) { short int cur = name->elements[0]; Typedef* res = 0; Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=69085&r1=69084&r2=69085&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Tue Apr 14 17:15:40 2009 @@ -287,11 +287,6 @@ /// ArrayUInt8* openName(const UTF8* utf8); - /// constructPrimitiveArray - Hashes the primitive array. - /// - ClassArray* constructPrimitiveArray(const UTF8* name, - ClassPrimitive* prim); - public: /// tracer - Traces instances of this class. From nicolas.geoffray at lip6.fr Tue Apr 14 15:18:04 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 22:18:04 -0000 Subject: [vmkit-commits] [vmkit] r69088 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Message-ID: <200904142218.n3EMI4uC017266@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 17:18:04 2009 New Revision: 69088 URL: http://llvm.org/viewvc/llvm-project?rev=69088&view=rev Log: Fix formatting. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=69088&r1=69087&r2=69088&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Tue Apr 14 17:18:04 2009 @@ -1858,11 +1858,11 @@ LLVMAssessorInfo& LAI = LLVMAssessorInfo::AssessorInfo[charId]; sizeElement = LAI.sizeInBytesConstant; - if (TheCompiler->isStaticCompiling() && + if (TheCompiler->isStaticCompiling() && valCl->getType() != module->JavaClassArrayType) { - valCl = new LoadInst(valCl, "", currentBlock); - TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, - valCl, "", currentBlock); + valCl = new LoadInst(valCl, "", currentBlock); + TheVT = CallInst::Create(module->GetVTFromClassArrayFunction, + valCl, "", currentBlock); } else { TheVT = TheCompiler->getVirtualTable(dcl->virtualVT); } From nicolas.geoffray at lip6.fr Tue Apr 14 15:19:19 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 14 Apr 2009 22:19:19 -0000 Subject: [vmkit-commits] [vmkit] r69089 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904142219.n3EMJJ3E017315@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 14 17:19:18 2009 New Revision: 69089 URL: http://llvm.org/viewvc/llvm-project?rev=69089&view=rev Log: Add a boolean flag to verify if we're compiling rt.jar, and always lookup native arrays at boot time of a statically compiled library. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=69089&r1=69088&r2=69089&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Tue Apr 14 17:19:18 2009 @@ -640,6 +640,8 @@ bool generateTracers; bool generateStubs; bool assumeCompiled; + + bool compileRT; void CreateStaticInitializer(); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69089&r1=69088&r2=69089&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Tue Apr 14 17:19:18 2009 @@ -1252,6 +1252,7 @@ generateTracers = true; generateStubs = true; assumeCompiled = false; + compileRT = false; std::vector llvmArgs; llvmArgs.push_back(JnjvmModule::ptrType); // class loader. @@ -1396,12 +1397,10 @@ for (array_class_iterator i = arrayClasses.begin(), e = arrayClasses.end(); i != e; ++i) { - if (!(i->first->baseClass()->isPrimitive())) { - Args[0] = loader; - Args[1] = i->second; - Args[2] = getUTF8(i->first->name); - CallInst::Create(GetClassArray, Args, Args + 3, "", currentBlock); - } + Args[0] = loader; + Args[1] = i->second; + Args[2] = getUTF8(i->first->name); + CallInst::Create(GetClassArray, Args, Args + 3, "", currentBlock); } @@ -1520,6 +1519,7 @@ realName[size - 6] = 0; const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName); Class* cl = bootstrapLoader->constructClass(utf8, res); + if (cl == ClassArray::SuperArray) M->compileRT = true; classes.push_back(cl); } } From nicolas.geoffray at lip6.fr Wed Apr 15 01:57:18 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 08:57:18 -0000 Subject: [vmkit-commits] [vmkit] r69159 - /vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904150857.n3F8vKma017143@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 03:56:57 2009 New Revision: 69159 URL: http://llvm.org/viewvc/llvm-project?rev=69159&view=rev Log: Not giving a class tu UTF8 was stupid: utf8s are stored in strings. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69159&r1=69158&r2=69159&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Wed Apr 15 03:56:57 2009 @@ -357,10 +357,7 @@ std::vector Elmts; - // virtual table - if (!cl) { - Elmts.push_back(Constant::getNullValue(JnjvmModule::VTType)); - } else if (cl->isClass()) { + if (cl->isClass()) { Elmts.push_back(getVirtualTable(cl->asClass()->virtualVT)); } else { Elmts.push_back(getVirtualTable(cl->asArrayClass()->virtualVT)); @@ -1104,7 +1101,8 @@ const StructType* STy = StructType::get(Elemts); std::vector Cts; - Cts.push_back(CreateConstantForBaseObject(0)); + CommonClass* cl = JavaThread::get()->getJVM()->upcalls->ArrayOfChar; + Cts.push_back(CreateConstantForBaseObject(cl)); Cts.push_back(ConstantInt::get(JnjvmModule::pointerSizeType, val->size)); std::vector Vals; From nicolas.geoffray at lip6.fr Wed Apr 15 06:24:38 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 13:24:38 -0000 Subject: [vmkit-commits] [vmkit] r69160 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Message-ID: <200904151324.n3FDOdOF026073@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 08:24:37 2009 New Revision: 69160 URL: http://llvm.org/viewvc/llvm-project?rev=69160&view=rev Log: Constify some functions. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69160&r1=69159&r2=69160&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Wed Apr 15 08:24:37 2009 @@ -231,6 +231,14 @@ return 0; } + /// asClass - Returns the class as a user-defined class + /// if it is not a primitive or an array. + /// + const UserClass* asClass() const { + if (isClass()) return (const UserClass*)this; + return 0; + } + /// asPrimitiveClass - Returns the class if it's a primitive class. /// UserClassPrimitive* asPrimitiveClass() { @@ -238,12 +246,22 @@ return 0; } + const UserClassPrimitive* asPrimitiveClass() const { + if (isPrimitive()) return (const UserClassPrimitive*)this; + return 0; + } + /// asArrayClass - Returns the class if it's an array class. /// UserClassArray* asArrayClass() { if (isArray()) return (UserClassArray*)this; return 0; } + + const UserClassArray* asArrayClass() const { + if (isArray()) return (const UserClassArray*)this; + return 0; + } /// printClassName - Adds a string representation of this class in the /// given buffer. @@ -551,7 +569,7 @@ /// getOwnerClass - Get the thread that is currently initializing the class. /// - mvm::Thread* getOwnerClass() { + mvm::Thread* getOwnerClass() const { return ownerClass; } @@ -563,13 +581,13 @@ /// getOuterClass - Get the class that contains the definition of this class. /// - Class* getOuterClass() { + Class* getOuterClass() const { return outerClass; } /// getInnterClasses - Get the classes that this class defines. /// - Class** getInnerClasses() { + Class** getInnerClasses() const { return innerClasses; } @@ -604,10 +622,10 @@ bool recurse, Class** definingClass); /// Assessor methods. - JavaField* getStaticFields() { return staticFields; } - JavaField* getVirtualFields() { return virtualFields; } - JavaMethod* getStaticMethods() { return staticMethods; } - JavaMethod* getVirtualMethods() { return virtualMethods; } + JavaField* getStaticFields() const { return staticFields; } + JavaField* getVirtualFields() const { return virtualFields; } + JavaMethod* getStaticMethods() const { return staticMethods; } + JavaMethod* getVirtualMethods() const { return virtualMethods; } /// setInnerAccess - Set the access flags of this inner class. @@ -618,7 +636,7 @@ /// getStaticSize - Get the size of the static instance. /// - uint32 getStaticSize() { + uint32 getStaticSize() const { return staticSize; } @@ -679,13 +697,13 @@ /// getConstantPool - Get the constant pool of the class. /// - JavaConstantPool* getConstantPool() { + JavaConstantPool* getConstantPool() const { return ctpInfo; } /// getBytes - Get the bytes of the class file. /// - ArrayUInt8* getBytes() { + ArrayUInt8* getBytes() const { return bytes; } From nicolas.geoffray at lip6.fr Wed Apr 15 07:22:19 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 14:22:19 -0000 Subject: [vmkit-commits] [vmkit] r69161 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904151422.n3FEMKpU027983@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 09:22:15 2009 New Revision: 69161 URL: http://llvm.org/viewvc/llvm-project?rev=69161&view=rev Log: Don't forget to update the display of native array classes. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69161&r1=69160&r2=69161&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Wed Apr 15 09:22:15 2009 @@ -1284,7 +1284,8 @@ sizeof(uintptr_t) * JavaVirtualTable::getNumJavaMethods()); \ CLASS->super = cl; \ CLASS->display[0] = cl; \ - CLASS->display[1] = CLASS; + CLASS->display[1] = CLASS; \ + CLASS->virtualVT->display[0] = cl->virtualVT; COPY(upcalls->ArrayOfBool) COPY(upcalls->ArrayOfByte) From nicolas.geoffray at lip6.fr Wed Apr 15 07:23:30 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 14:23:30 -0000 Subject: [vmkit-commits] [vmkit] r69162 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Message-ID: <200904151423.n3FENUTa028058@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 09:23:29 2009 New Revision: 69162 URL: http://llvm.org/viewvc/llvm-project?rev=69162&view=rev Log: First thing is to look if we have a libvmjc.so file, so that we do not attempt to create primitive classes that are already in libvmjc.so. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69162&r1=69161&r2=69162&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Wed Apr 15 09:23:29 2009 @@ -85,16 +85,59 @@ ClassArray::InterfacesArray = (Class**)allocator.Allocate(2 * sizeof(UserClass*)); - // Create the primitive classes. - upcalls->OfChar = UPCALL_PRIMITIVE_CLASS(this, "char", 2); - upcalls->OfBool = UPCALL_PRIMITIVE_CLASS(this, "boolean", 1); - upcalls->OfShort = UPCALL_PRIMITIVE_CLASS(this, "short", 2); - upcalls->OfInt = UPCALL_PRIMITIVE_CLASS(this, "int", 4); - upcalls->OfLong = UPCALL_PRIMITIVE_CLASS(this, "long", 8); - upcalls->OfFloat = UPCALL_PRIMITIVE_CLASS(this, "float", 4); - upcalls->OfDouble = UPCALL_PRIMITIVE_CLASS(this, "double", 8); - upcalls->OfVoid = UPCALL_PRIMITIVE_CLASS(this, "void", 0); - upcalls->OfByte = UPCALL_PRIMITIVE_CLASS(this, "byte", 1); + // Try to find if we have a pre-compiled rt.jar + if (dlLoad) { + SuperArray = (Class*)dlsym(SELF_HANDLE, "java.lang.Object"); + if (!SuperArray) { + nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); + if (nativeHandle) { + // Found it! + SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object"); + } + } + + if (SuperArray) { + ClassArray::SuperArray = (Class*)SuperArray->getInternal(); + + // Get the native classes. + upcalls->OfVoid = (ClassPrimitive*)dlsym(nativeHandle, "void"); + upcalls->OfBool = (ClassPrimitive*)dlsym(nativeHandle, "boolean"); + upcalls->OfByte = (ClassPrimitive*)dlsym(nativeHandle, "byte"); + upcalls->OfChar = (ClassPrimitive*)dlsym(nativeHandle, "char"); + upcalls->OfShort = (ClassPrimitive*)dlsym(nativeHandle, "short"); + upcalls->OfInt = (ClassPrimitive*)dlsym(nativeHandle, "int"); + upcalls->OfFloat = (ClassPrimitive*)dlsym(nativeHandle, "float"); + upcalls->OfLong = (ClassPrimitive*)dlsym(nativeHandle, "long"); + upcalls->OfDouble = (ClassPrimitive*)dlsym(nativeHandle, "double"); + + // Get the base object arrays. + upcalls->ArrayOfString = + constructArray(asciizConstructUTF8("[Ljava/lang/String;")); + + upcalls->ArrayOfObject = + constructArray(asciizConstructUTF8("[Ljava/lang/Object;")); + + // We have the java/lang/Object class, execute the static initializer. + static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; + assert(init && "Loaded the wrong boot library"); + init(this); + + + } + } + + if (!upcalls->OfChar) { + // Create the primitive classes. + upcalls->OfChar = UPCALL_PRIMITIVE_CLASS(this, "char", 2); + upcalls->OfBool = UPCALL_PRIMITIVE_CLASS(this, "boolean", 1); + upcalls->OfShort = UPCALL_PRIMITIVE_CLASS(this, "short", 2); + upcalls->OfInt = UPCALL_PRIMITIVE_CLASS(this, "int", 4); + upcalls->OfLong = UPCALL_PRIMITIVE_CLASS(this, "long", 8); + upcalls->OfFloat = UPCALL_PRIMITIVE_CLASS(this, "float", 4); + upcalls->OfDouble = UPCALL_PRIMITIVE_CLASS(this, "double", 8); + upcalls->OfVoid = UPCALL_PRIMITIVE_CLASS(this, "void", 0); + upcalls->OfByte = UPCALL_PRIMITIVE_CLASS(this, "byte", 1); + } // Create the primitive arrays. upcalls->ArrayOfChar = constructArray(asciizConstructUTF8("[C"), @@ -147,29 +190,7 @@ // array classes. analyseClasspathEnv(bootClasspathEnv); - - // Now that native types have been loaded, try to find if we have a - // pre-compiled rt.jar - if (dlLoad) { - SuperArray = (Class*)dlsym(SELF_HANDLE, "java.lang.Object"); - if (!SuperArray) { - nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); - if (nativeHandle) { - // Found it! - SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object"); - } - } - - if (SuperArray) { - ClassArray::SuperArray = (Class*)SuperArray->getInternal(); - // We have the java/lang/Object class, execute the static initializer. - static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; - assert(init && "Loaded the wrong boot library"); - init(this); - ClassArray::initialiseVT(); - } - } - + // We haven't found a pre-compiled rt.jar, load the root class ourself. if (!SuperArray) { From nicolas.geoffray at lip6.fr Wed Apr 15 07:24:45 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 14:24:45 -0000 Subject: [vmkit-commits] [vmkit] r69163 - /vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904151424.n3FEOjqJ028099@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 09:24:44 2009 New Revision: 69163 URL: http://llvm.org/viewvc/llvm-project?rev=69163&view=rev Log: Improvements when compiling rt.jar. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69163&r1=69162&r2=69163&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Wed Apr 15 09:24:44 2009 @@ -36,9 +36,11 @@ bool JavaAOTCompiler::isCompiling(const CommonClass* cl) const { if (cl->isClass()) { // A class is being static compiled if owner class is not null. - return (((Class*)cl)->getOwnerClass() != 0); + return cl->asClass()->getOwnerClass() != 0; } else if (cl->isArray()) { - return isCompiling(((ClassArray*)cl)->baseClass()); + return isCompiling(cl->asArrayClass()->baseClass()); + } else if (cl->isPrimitive() && compileRT) { + return true; } else { return false; } @@ -46,10 +48,8 @@ Constant* JavaAOTCompiler::getNativeClass(CommonClass* classDef) { - if (classDef->isClass() || - (classDef->isArray() && isCompiling(classDef)) || - (assumeCompiled && !(classDef->isArray() && - classDef->asArrayClass()->baseClass()->isPrimitive()))) { + if (classDef->isClass() || isCompiling(classDef) || assumeCompiled) { + native_class_iterator End = nativeClasses.end(); native_class_iterator I = nativeClasses.find(classDef); if (I == End) { @@ -57,6 +57,8 @@ if (classDef->isArray()) { Ty = JnjvmModule::JavaClassArrayType->getContainedType(0); + } else if (classDef->isPrimitive()) { + Ty = JnjvmModule::JavaClassPrimitiveType->getContainedType(0); } else { Ty = JnjvmModule::JavaClassType->getContainedType(0); } @@ -67,11 +69,15 @@ nativeClasses.insert(std::make_pair(classDef, varGV)); - if (classDef->isClass() && isCompiling(classDef->asClass())) { - Constant* C = CreateConstantFromClass((Class*)classDef); + if (classDef->isClass() && isCompiling(classDef)) { + Constant* C = CreateConstantFromClass(classDef->asClass()); varGV->setInitializer(C); } else if (classDef->isArray()) { - Constant* C = CreateConstantFromClassArray((ClassArray*)classDef); + Constant* C = CreateConstantFromClassArray(classDef->asArrayClass()); + varGV->setInitializer(C); + } else if (classDef->isPrimitive()) { + Constant* C = + CreateConstantFromClassPrimitive(classDef->asPrimitiveClass()); varGV->setInitializer(C); } @@ -82,7 +88,7 @@ } } else if (classDef->isArray()) { array_class_iterator End = arrayClasses.end(); - array_class_iterator I = arrayClasses.find((ClassArray*)classDef); + array_class_iterator I = arrayClasses.find(classDef->asArrayClass()); if (I == End) { const llvm::Type* Ty = JnjvmModule::JavaClassArrayType; @@ -91,13 +97,13 @@ Constant::getNullValue(Ty), classDef->printString(), getLLVMModule()); - arrayClasses.insert(std::make_pair((ClassArray*)classDef, varGV)); + arrayClasses.insert(std::make_pair(classDef->asArrayClass(), varGV)); return varGV; } else { return I->second; } - } else if (classDef->isPrimitive()) { - assert(0 && "implement me"); + } else { + assert(0 && "Implement me"); } return 0; } @@ -140,7 +146,7 @@ return SI->second; } else { assert(str && "No string given"); - LLVMClassInfo* LCI = getClassInfo((Class*)str->getClass()); + LLVMClassInfo* LCI = getClassInfo(str->getClass()->asClass()); const llvm::Type* Ty = LCI->getVirtualType(); GlobalVariable* varGV = new GlobalVariable(Ty->getContainedType(0), false, @@ -176,7 +182,7 @@ java_class_iterator I = javaClasses.find(cl); if (I == End) { Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass; - LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(javaClass); + LLVMClassInfo* LCI = getClassInfo(javaClass); const llvm::Type* Ty = LCI->getVirtualType(); GlobalVariable* varGV = @@ -342,7 +348,8 @@ varGV = new GlobalVariable(valPtrType, true, GlobalValue::InternalLinkage, - Constant::getNullValue(valPtrType), "", getLLVMModule()); + Constant::getNullValue(valPtrType), "", + getLLVMModule()); nativeFunctions.insert(std::make_pair(meth, varGV)); return varGV; @@ -498,8 +505,8 @@ } Constant* JavaAOTCompiler::CreateConstantFromJavaString(JavaString* str) { - Class* cl = (Class*)str->getClass(); - LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl); + Class* cl = str->getClass()->asClass(); + LLVMClassInfo* LCI = getClassInfo(cl); const StructType* STy = dyn_cast(LCI->getVirtualType()->getContainedType(0)); @@ -1562,30 +1569,45 @@ cl->setOwnerClass(JavaThread::get()); M->compileClass(cl); } - + + if (M->compileRT) { + // Make sure that if we compile RT, the native classes are emitted. + M->getNativeClass(bootstrapLoader->upcalls->OfVoid); + M->getNativeClass(bootstrapLoader->upcalls->OfBool); + M->getNativeClass(bootstrapLoader->upcalls->OfByte); + M->getNativeClass(bootstrapLoader->upcalls->OfChar); + M->getNativeClass(bootstrapLoader->upcalls->OfShort); + M->getNativeClass(bootstrapLoader->upcalls->OfInt); + M->getNativeClass(bootstrapLoader->upcalls->OfFloat); + M->getNativeClass(bootstrapLoader->upcalls->OfLong); + M->getNativeClass(bootstrapLoader->upcalls->OfDouble); + + // Also do not allow inling of some functions. +#define SET_INLINE(NAME) { \ + const UTF8* name = vm->asciizToUTF8(NAME); \ + Class* cl = (Class*)bootstrapLoader->lookupClass(name); \ + if (cl) M->setNoInline(cl); } + + SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater" + "$AtomicReferenceFieldUpdaterImpl") + SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater" + "$AtomicIntegerFieldUpdaterImpl") + SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" + "$CASUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" + "$LockedUpdater") +#undef SET_INLINE + } + M->CreateStaticInitializer(); } catch(std::string str) { fprintf(stderr, "Error : %s\n", str.c_str()); } -#define SET_INLINE(NAME) { \ - const UTF8* name = vm->asciizToUTF8(NAME); \ - Class* cl = (Class*)vm->bootstrapLoader->lookupClass(name); \ - if (cl) M->setNoInline(cl); } - - SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater" - "$AtomicReferenceFieldUpdaterImpl") - SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater" - "$AtomicIntegerFieldUpdaterImpl") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" - "$CASUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" - "$LockedUpdater") -#undef SET_INLINE vm->threadSystem.nonDaemonLock.lock(); --(vm->threadSystem.nonDaemonThreads); From nicolas.geoffray at lip6.fr Wed Apr 15 07:29:53 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 14:29:53 -0000 Subject: [vmkit-commits] [vmkit] r69164 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Message-ID: <200904151429.n3FETsQw028289@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 09:29:52 2009 New Revision: 69164 URL: http://llvm.org/viewvc/llvm-project?rev=69164&view=rev Log: Get array classes after calling the init method. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69164&r1=69163&r2=69164&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Wed Apr 15 09:29:52 2009 @@ -110,18 +110,20 @@ upcalls->OfLong = (ClassPrimitive*)dlsym(nativeHandle, "long"); upcalls->OfDouble = (ClassPrimitive*)dlsym(nativeHandle, "double"); - // Get the base object arrays. - upcalls->ArrayOfString = - constructArray(asciizConstructUTF8("[Ljava/lang/String;")); - - upcalls->ArrayOfObject = - constructArray(asciizConstructUTF8("[Ljava/lang/Object;")); // We have the java/lang/Object class, execute the static initializer. static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; assert(init && "Loaded the wrong boot library"); init(this); + // Get the base object arrays after the init, because init puts arrays + // in the class loader map. + upcalls->ArrayOfString = + constructArray(asciizConstructUTF8("[Ljava/lang/String;")); + + upcalls->ArrayOfObject = + constructArray(asciizConstructUTF8("[Ljava/lang/Object;")); + } } From nicolas.geoffray at lip6.fr Wed Apr 15 10:38:25 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 17:38:25 -0000 Subject: [vmkit-commits] [vmkit] r69185 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904151738.n3FHcRfS003060@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 12:38:18 2009 New Revision: 69185 URL: http://llvm.org/viewvc/llvm-project?rev=69185&view=rev Log: Code cleanup. No functionality changes. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69185&r1=69184&r2=69185&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Wed Apr 15 12:38:18 2009 @@ -84,26 +84,6 @@ classLoader->allocator.Deallocate(display); } -CommonClass::CommonClass() { - display = 0; - nbInterfaces = 0; - access = 0; -} - -Class::Class() : CommonClass() { - virtualVT = 0; - ctpInfo = 0; - JInfo = 0; - outerClass = 0; - innerOuterResolved = false; - nbInnerClasses = 0; - nbVirtualFields = 0; - nbStaticFields = 0; - nbVirtualMethods = 0; - nbStaticMethods = 0; - ownerClass = 0; -} - Class::~Class() { for (uint32 i = 0; i < nbAttributs; ++i) { Attribut* cur = &(attributs[i]); From nicolas.geoffray at lip6.fr Wed Apr 15 14:26:57 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 21:26:57 -0000 Subject: [vmkit-commits] [vmkit] r69223 - /vmkit/trunk/include/mvm/VirtualMachine.h Message-ID: <200904152126.n3FLQwbV011412@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 16:26:54 2009 New Revision: 69223 URL: http://llvm.org/viewvc/llvm-project?rev=69223&view=rev Log: Fix compilation warning. Modified: vmkit/trunk/include/mvm/VirtualMachine.h Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=69223&r1=69222&r2=69223&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Wed Apr 15 16:26:54 2009 @@ -51,6 +51,8 @@ virtual void TRACER {} + virtual ~VirtualMachine() {} + /// runApplication - Run an application. The application name is in /// the arguments, hence it is the virtual machine's job to parse them. virtual void runApplication(int argc, char** argv) = 0; From nicolas.geoffray at lip6.fr Wed Apr 15 14:30:39 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 15 Apr 2009 21:30:39 -0000 Subject: [vmkit-commits] [vmkit] r69224 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Message-ID: <200904152130.n3FLUd9Y011547@zion.cs.uiuc.edu> Author: geoffray Date: Wed Apr 15 16:30:38 2009 New Revision: 69224 URL: http://llvm.org/viewvc/llvm-project?rev=69224&view=rev Log: Fix compilation warning. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=69224&r1=69223&r2=69224&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Wed Apr 15 16:30:38 2009 @@ -202,7 +202,7 @@ /// ~JnjvmClassLoader - Destroy the loader: destroy the tables, JIT module and /// module provider. /// - ~JnjvmClassLoader(); + virtual ~JnjvmClassLoader(); /// loadClass - The user class that defines the loadClass method. /// @@ -381,7 +381,7 @@ return arrayTable[id - 4]; } - ~JnjvmBootstrapLoader(); + virtual ~JnjvmBootstrapLoader(); }; /// VMClassLoader - The vmdata object that will be placed in and will only From nicolas.geoffray at lip6.fr Thu Apr 16 02:03:35 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 09:03:35 -0000 Subject: [vmkit-commits] [vmkit] r69278 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Message-ID: <200904160903.n3G93aeW005505@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 04:03:30 2009 New Revision: 69278 URL: http://llvm.org/viewvc/llvm-project?rev=69278&view=rev Log: code cleanup. No functioanltiy changes. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69278&r1=69277&r2=69278&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Apr 16 04:03:30 2009 @@ -80,7 +80,7 @@ /// Attribut(const UTF8* name, uint32 length, uint32 offset); Attribut() {} - + /// codeAttribut - The "Code" JVM attribut. This is a method attribut for /// finding the bytecode of a method in the .class file. // @@ -330,10 +330,6 @@ /// ~CommonClass(); - /// CommonClass - Default constructor. - /// - CommonClass(); - /// setInterfaces - Set the interfaces of the class. /// void setInterfaces(Class** I) { @@ -358,7 +354,7 @@ #if !defined(ISOLATE) && !defined(ISOLATE_SHARING) /// getDelegatee - Get the java/lang/Class object representing this class. /// - JavaObject* getDelegatee() { + JavaObject* getDelegatee() const { return delegatee[0]; } @@ -561,11 +557,11 @@ /// getVirtualSize - Get the virtual size of instances of this class. /// - uint32 getVirtualSize() { return virtualSize; } + uint32 getVirtualSize() const { return virtualSize; } /// getVirtualVT - Get the virtual VT of instances of this class. /// - JavaVirtualTable* getVirtualVT() { return virtualVT; } + JavaVirtualTable* getVirtualVT() const { return virtualVT; } /// getOwnerClass - Get the thread that is currently initializing the class. /// @@ -1357,8 +1353,6 @@ JavaVirtualTable(ClassArray* C); - JavaVirtualTable() {} - uintptr_t* getFirstJavaMethod() { return &init; } From nicolas.geoffray at lip6.fr Thu Apr 16 02:07:04 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 09:07:04 -0000 Subject: [vmkit-commits] [vmkit] r69279 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904160907.n3G974Cc005701@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 04:07:00 2009 New Revision: 69279 URL: http://llvm.org/viewvc/llvm-project?rev=69279&view=rev Log: Instead of loader super and interfaces when a class is resolved, load it when the class is being loaded. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69279&r1=69278&r2=69279&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Apr 16 04:07:00 2009 @@ -726,7 +726,10 @@ uint16 superEntry = reader.readU2(); // Use the depth field to store the super entry, to not touch super. The // super field is used during GC scanning and must only be of one type. - depth = superEntry; + if (superEntry) { + const UTF8* superUTF8 = ctpInfo->resolveClassName(superEntry); + super = classLoader->loadName(superUTF8, false, true); + } uint16 nbI = reader.readU2(); @@ -737,27 +740,26 @@ interfaces = (Class**) classLoader->allocator.Allocate(nbI * sizeof(Class*)); nbInterfaces = nbI; - for (int i = 0; i < nbI; i++) - interfaces[i] = (Class*)ctpInfo->resolveClassName(reader.readU2()); + for (int i = 0; i < nbI; i++) { + const UTF8* name = ctpInfo->resolveClassName(reader.readU2()); + interfaces[i] = classLoader->loadName(name, false, true); + } } void UserClass::loadParents() { - const UTF8* superUTF8 = depth ? ctpInfo->resolveClassName(depth) : 0; // W prevent the GC from scanning the interfaces until they // are loaded. So we temporarly consider that this class does not // have any interfaces. This is harmless because the class is being // resolved and can not be used elsewhere for getting its interfaces. - uint32 realNbInterfaces = nbInterfaces; - nbInterfaces = 0; - if (superUTF8 == 0) { + if (super == 0) { depth = 0; display = (CommonClass**) classLoader->allocator.Allocate(sizeof(CommonClass*)); display[0] = this; virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); } else { - super = classLoader->loadName(superUTF8, true, true); + super->resolveClass(); depth = super->depth + 1; mvm::BumpPtrAllocator& allocator = classLoader->allocator; display = (CommonClass**) @@ -767,13 +769,8 @@ virtualTableSize = super->virtualTableSize; } - for (unsigned i = 0; i < realNbInterfaces; i++) - interfaces[i] = - ((UserClass*)classLoader->loadName((const UTF8*)interfaces[i], - true, true)); - - // Interfaces are loaded, put the real number back in place. - nbInterfaces = realNbInterfaces; + for (unsigned i = 0; i < nbInterfaces; i++) + interfaces[i]->resolveClass(); } From nicolas.geoffray at lip6.fr Thu Apr 16 02:02:16 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 09:02:16 -0000 Subject: [vmkit-commits] [vmkit] r69277 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Message-ID: <200904160902.n3G92Hd2005460@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 04:02:12 2009 New Revision: 69277 URL: http://llvm.org/viewvc/llvm-project?rev=69277&view=rev Log: Constify some functions. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=69277&r1=69276&r2=69277&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Thu Apr 16 04:02:12 2009 @@ -104,11 +104,11 @@ /// getIsolate - Returns the isolate that created this class loader. /// - Jnjvm* getIsolate() { return isolate; } + Jnjvm* getIsolate() const { return isolate; } /// getClasses - Returns the classes this class loader has loaded. /// - ClassMap* getClasses() { return classes; } + ClassMap* getClasses() const { return classes; } /// hashUTF8 - Tables of UTF8s defined by this class loader. /// @@ -116,7 +116,7 @@ /// getCompiler - Get the Java compiler of this class loader. /// - JavaCompiler* getCompiler() { return TheCompiler; } + JavaCompiler* getCompiler() const { return TheCompiler; } /// setCompiler - Set the compiler of classes loaded by this class loader. /// @@ -133,7 +133,7 @@ /// getJavaClassLoader - Return the Java representation of this class loader. /// - JavaObject* getJavaClassLoader() { + JavaObject* getJavaClassLoader() const { return javaLoader; } From nicolas.geoffray at lip6.fr Thu Apr 16 03:20:17 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 10:20:17 -0000 Subject: [vmkit-commits] [vmkit] r69280 - in /vmkit/trunk/lib/JnJVM/VMCore: JnjvmClassLoader.cpp VirtualTables.cpp Message-ID: <200904161020.n3GAKIt2010659@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 05:20:08 2009 New Revision: 69280 URL: http://llvm.org/viewvc/llvm-project?rev=69280&view=rev Log: When a class loader initiates loading of a class, we add it to its class map. This allows to record which class loaders are referenced by a class loader. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69280&r1=69279&r2=69280&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Thu Apr 16 05:20:08 2009 @@ -401,6 +401,15 @@ vm->noClassDefFoundError(name); } + if (cl && cl->classLoader != this) { + classes->lock.lock(); + ClassMap::iterator End = classes->map.end(); + ClassMap::iterator I = classes->map.find(name); + if (I == End) + classes->map.insert(std::make_pair(name, cl)); + classes->lock.unlock(); + } + return cl; } Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=69280&r1=69279&r2=69280&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Thu Apr 16 05:20:08 2009 @@ -120,10 +120,9 @@ // own class loader. // (2) The delegatee object (java.lang.Class) if it exists. // -// Additionaly, non-primitive and non-array classes mus trace: +// Additionaly, non-primitive and non-array classes must trace: // (3) The bytes that represent the class file. // (4) The static instance. -// (5) The class loaders referenced indirectly in the class file (TODO). //===----------------------------------------------------------------------===// @@ -165,15 +164,17 @@ //===----------------------------------------------------------------------===// // Support for scanning a classloader. A classloader must trace: -// (1) All the classes it has loaded. -// (2) All the strings referenced in class files. +// (1) All the classes it has loaded (located in the classmap). +// (2) All the class it has initiated loading and therefore references (located +// in the classmap). +// (3) All the strings referenced in class files. // // The class loader does not need to trace its java.lang.Classloader Java object // because if we end up here, this means that the Java object is already being // scanned. Only the Java object traces the class loader. // // Additionaly, the bootstrap loader must trace: -// (3) The delegatees of native array classes. Since these classes are not in +// (4) The delegatees of native array classes. Since these classes are not in // the class map and they are not GC-allocated, we must trace the objects // referenced by the delegatees. //===----------------------------------------------------------------------===// From nicolas.geoffray at lip6.fr Thu Apr 16 03:53:39 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 10:53:39 -0000 Subject: [vmkit-commits] [vmkit] r69281 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaClass.cpp JavaClass.h JnjvmClassLoader.cpp Message-ID: <200904161053.n3GArfDw012837@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 05:53:29 2009 New Revision: 69281 URL: http://llvm.org/viewvc/llvm-project?rev=69281&view=rev Log: Move resolution of classes to initialiseVT, when java.lang.Object gets resolved. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69281&r1=69280&r2=69281&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Apr 16 05:53:29 2009 @@ -739,11 +739,11 @@ // interfaces is not used if super is null. interfaces = (Class**) classLoader->allocator.Allocate(nbI * sizeof(Class*)); - nbInterfaces = nbI; for (int i = 0; i < nbI; i++) { const UTF8* name = ctpInfo->resolveClassName(reader.readU2()); interfaces[i] = classLoader->loadName(name, false, true); } + nbInterfaces = nbI; } @@ -932,7 +932,7 @@ if (!needsInitialisationCheck()) { setInitializationState(ready); } - if (!super) ClassArray::initialiseVT(); + if (!super) ClassArray::initialiseVT(this); setOwnerClass(0); broadcastClass(); release(); @@ -1240,8 +1240,20 @@ } -void ClassArray::initialiseVT() { - +void ClassArray::initialiseVT(Class* javaLangObject) { + + ClassArray::SuperArray = javaLangObject; + JnjvmClassLoader* JCL = javaLangObject->classLoader; + + // Initialize interfaces of array classes. + ClassArray::InterfacesArray[0] = + JCL->loadName(JCL->asciizConstructUTF8("java/lang/Cloneable"), + false, false); + + ClassArray::InterfacesArray[1] = + JCL->loadName(JCL->asciizConstructUTF8("java/io/Serializable"), + false, false); + Class* cl = ClassArray::SuperArray; assert(cl && "Initializing array VT without a super for arrays"); assert(cl->virtualVT->init && "Initializing array VT before JavaObjectVT"); @@ -1275,7 +1287,6 @@ #undef COPY - JnjvmClassLoader* JCL = cl->classLoader; // Load array classes that JnJVM internally uses. upcalls->ArrayOfString = JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/String;")); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69281&r1=69280&r2=69281&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Apr 16 05:53:29 2009 @@ -935,7 +935,7 @@ /// initialiseVT - Initialise the primitive and reference array VT. /// super is the java/lang/Object class. /// - static void initialiseVT(); + static void initialiseVT(Class* javaLangObject); }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69281&r1=69280&r2=69281&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Thu Apr 16 05:53:29 2009 @@ -77,14 +77,7 @@ upcalls = new(allocator) Classpath(); bootstrapLoader = this; - - // Allocate interfaces. - InterfacesArray = - (Class**)allocator.Allocate(2 * sizeof(UserClass*)); - - ClassArray::InterfacesArray = - (Class**)allocator.Allocate(2 * sizeof(UserClass*)); - + // Try to find if we have a pre-compiled rt.jar if (dlLoad) { SuperArray = (Class*)dlsym(SELF_HANDLE, "java.lang.Object"); @@ -124,11 +117,17 @@ upcalls->ArrayOfObject = constructArray(asciizConstructUTF8("[Ljava/lang/Object;")); + InterfacesArray = upcalls->ArrayOfObject->interfaces; + ClassArray::InterfacesArray = InterfacesArray; } } if (!upcalls->OfChar) { + // Allocate interfaces. + InterfacesArray = (Class**)allocator.Allocate(2 * sizeof(UserClass*)); + ClassArray::InterfacesArray = InterfacesArray; + // Create the primitive classes. upcalls->OfChar = UPCALL_PRIMITIVE_CLASS(this, "char", 2); upcalls->OfBool = UPCALL_PRIMITIVE_CLASS(this, "boolean", 1); @@ -191,31 +190,7 @@ // hold the .zip file, we call the function after creation of the // array classes. analyseClasspathEnv(bootClasspathEnv); - - - // We haven't found a pre-compiled rt.jar, load the root class ourself. - if (!SuperArray) { - - // We can not resolve java.lang.Object yet, because we may not be - // running in a Java thread, and we may not have a compiler - // available. - SuperArray = loadName(asciizConstructUTF8("java/lang/Object"), false, - false); - ClassArray::SuperArray = (Class*)SuperArray->getInternal(); - - } - - // Initialize interfaces of array classes. - InterfacesArray[0] = loadName(asciizConstructUTF8("java/lang/Cloneable"), - false, false); - InterfacesArray[1] = loadName(asciizConstructUTF8("java/io/Serializable"), - false, false); - - ClassArray::InterfacesArray[0] = (Class*)InterfacesArray[0]->getInternal(); - ClassArray::InterfacesArray[1] = (Class*)(InterfacesArray[1]->getInternal()); - - Attribut::codeAttribut = asciizConstructUTF8("Code"); Attribut::exceptionsAttribut = asciizConstructUTF8("Exceptions"); Attribut::constantAttribut = asciizConstructUTF8("ConstantValue"); From nicolas.geoffray at lip6.fr Thu Apr 16 04:01:30 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 11:01:30 -0000 Subject: [vmkit-commits] [vmkit] r69282 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904161101.n3GB1VO9013412@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 06:01:21 2009 New Revision: 69282 URL: http://llvm.org/viewvc/llvm-project?rev=69282&view=rev Log: Remove obsolete comments. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69282&r1=69281&r2=69282&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Apr 16 06:01:21 2009 @@ -724,8 +724,6 @@ void Class::readParents(Reader& reader) { uint16 superEntry = reader.readU2(); - // Use the depth field to store the super entry, to not touch super. The - // super field is used during GC scanning and must only be of one type. if (superEntry) { const UTF8* superUTF8 = ctpInfo->resolveClassName(superEntry); super = classLoader->loadName(superUTF8, false, true); @@ -733,12 +731,11 @@ uint16 nbI = reader.readU2(); - // Use the regular interface array to store the UTF8s. Since this array - // is never used before actually loading the interfaces, this is harmless. - // During GC scanning, the check is made on super. So the array of - // interfaces is not used if super is null. interfaces = (Class**) classLoader->allocator.Allocate(nbI * sizeof(Class*)); + + // Do not set nbInterfaces yet, we may be interrupted by the GC + // in anon-cooperative environment. for (int i = 0; i < nbI; i++) { const UTF8* name = ctpInfo->resolveClassName(reader.readU2()); interfaces[i] = classLoader->loadName(name, false, true); From nicolas.geoffray at lip6.fr Thu Apr 16 04:02:59 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 11:02:59 -0000 Subject: [vmkit-commits] [vmkit] r69283 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904161102.n3GB2x4N013514@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 06:02:59 2009 New Revision: 69283 URL: http://llvm.org/viewvc/llvm-project?rev=69283&view=rev Log: Remove obsolete comment. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69283&r1=69282&r2=69283&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Apr 16 06:02:59 2009 @@ -745,10 +745,6 @@ } void UserClass::loadParents() { - // W prevent the GC from scanning the interfaces until they - // are loaded. So we temporarly consider that this class does not - // have any interfaces. This is harmless because the class is being - // resolved and can not be used elsewhere for getting its interfaces. if (super == 0) { depth = 0; display = (CommonClass**) From nicolas.geoffray at lip6.fr Thu Apr 16 06:22:17 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 13:22:17 -0000 Subject: [vmkit-commits] [vmkit] r69285 - in /vmkit/trunk/lib/JnJVM: Compiler/JavaJITCompiler.cpp VMCore/Jnjvm.cpp Message-ID: <200904161322.n3GDMIFZ020584@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 08:22:16 2009 New Revision: 69285 URL: http://llvm.org/viewvc/llvm-project?rev=69285&view=rev Log: Fix mindo. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=69285&r1=69284&r2=69285&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Thu Apr 16 08:22:16 2009 @@ -212,6 +212,6 @@ vm->runApplication(argc + 1, newArgv); vm->waitForExit(); - delete newArgv; + delete[] newArgv; return 0; } Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69285&r1=69284&r2=69285&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Apr 16 08:22:16 2009 @@ -1150,7 +1150,7 @@ vm->runApplication(argc + 1, newArgv); vm->waitForExit(); - delete newArgv; + delete[] newArgv; return 0; } From nicolas.geoffray at lip6.fr Thu Apr 16 15:01:26 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 22:01:26 -0000 Subject: [vmkit-commits] [vmkit] r69317 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMClassLoader.cpp Compiler/JavaJITCompiler.cpp Compiler/JnjvmModule.cpp VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/JavaConstantPool.cpp VMCore/JavaConstantPool.h VMCore/JnjvmClassLoader.cpp Message-ID: <200904162201.n3GM1R9U005218@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 17:01:26 2009 New Revision: 69317 URL: http://llvm.org/viewvc/llvm-project?rev=69317&view=rev Log: Support initiating class loaders. Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.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/JavaConstantPool.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp Thu Apr 16 17:01:26 2009 @@ -61,9 +61,10 @@ Jnjvm* vm = JavaThread::get()->getJVM(); JavaString* name = (JavaString*)_name; const UTF8* utf8 = name->strToUTF8(vm); + const UTF8* internalName = utf8->javaToInternal(vm, 0, utf8->size); JnjvmClassLoader* JCL = JnjvmClassLoader::getJnjvmLoaderFromJavaObject((JavaObject*)loader, vm); - UserCommonClass* cl = JCL->lookupClass(utf8); + UserCommonClass* cl = JCL->lookupClass(internalName); if (cl) res = (jclass)(cl->getClassDelegatee(vm)); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Thu Apr 16 17:01:26 2009 @@ -153,10 +153,7 @@ if (!cl->super) { meth.canBeInlined = true; } else { - // LLVM does not allow recursive compilation. Create the code now. - // TODO: improve this when we have proper initialization. - Function* func = parseFunction(&meth); - VT->destructor = (uintptr_t)EE->getPointerToFunction(func); + VT->destructor = (uintptr_t)EE->getPointerToFunctionOrStub(func); } #endif } else { Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Apr 16 17:01:26 2009 @@ -201,6 +201,14 @@ } uint32 size = cl->virtualTableSize; + if (cl->super) { + if (!(cl->virtualTableSize >= cl->super->virtualTableSize)) { + fprintf(stderr, "cl = %s et super = %s\n", cl->printString(), cl->super->printString()); + } + assert(cl->virtualTableSize >= cl->super->virtualTableSize && + "Size of virtual table less than super!"); + } + mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; cl->virtualVT = new(allocator, size) JavaVirtualTable(cl); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Apr 16 17:01:26 2009 @@ -727,6 +727,17 @@ if (superEntry) { const UTF8* superUTF8 = ctpInfo->resolveClassName(superEntry); super = classLoader->loadName(superUTF8, false, true); + depth = super->depth + 1; + mvm::BumpPtrAllocator& allocator = classLoader->allocator; + display = (CommonClass**) + allocator.Allocate(sizeof(CommonClass*) * (depth + 1)); + memcpy(display, super->display, depth * sizeof(UserCommonClass*)); + display[depth] = this; + } else { + depth = 0; + display = (CommonClass**) + classLoader->allocator.Allocate(sizeof(CommonClass*)); + display[0] = this; } uint16 nbI = reader.readU2(); @@ -745,25 +756,15 @@ } void UserClass::loadParents() { - if (super == 0) { - depth = 0; - display = (CommonClass**) - classLoader->allocator.Allocate(sizeof(CommonClass*)); - display[0] = this; - virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); - } else { + if (super) { super->resolveClass(); - depth = super->depth + 1; - mvm::BumpPtrAllocator& allocator = classLoader->allocator; - display = (CommonClass**) - allocator.Allocate(sizeof(CommonClass*) * (depth + 1)); - memcpy(display, super->display, depth * sizeof(UserCommonClass*)); - display[depth] = this; virtualTableSize = super->virtualTableSize; + } else { + virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); } for (unsigned i = 0; i < nbInterfaces; i++) - interfaces[i]->resolveClass(); + interfaces[i]->resolveClass(); } @@ -791,7 +792,9 @@ reader.readU2(); uint16 catche = reader.readU2(); - if (catche) meth.classDef->ctpInfo->loadClass(catche); + if (catche) { + meth.classDef->ctpInfo->loadClass(catche, false); + } } } } @@ -913,19 +916,24 @@ release(); } else if (!isResolving()) { setOwnerClass(JavaThread::get()); - readClass(); + setIsResolving(); release(); + loadParents(); - loadExceptions(); - acquire(); JavaCompiler *Comp = classLoader->getCompiler(); Comp->resolveVirtualClass(this); Comp->resolveStaticClass(this); - setResolved(); - if (!needsInitialisationCheck()) { + loadExceptions(); + if (!super) ClassArray::initialiseVT(this); + + bool init = needsInitialisationCheck(); + + acquire(); + if (!init) { setInitializationState(ready); + } else { + setResolved(); } - if (!super) ClassArray::initialiseVT(this); setOwnerClass(0); broadcastClass(); release(); @@ -1213,7 +1221,7 @@ bool UserClass::needsInitialisationCheck() { - if (!isClassRead()) return true; + if (!isResolved()) return true; if (isReady()) return false; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Apr 16 17:01:26 2009 @@ -50,11 +50,12 @@ /// #define loaded 0 /// The .class file has been found. #define classRead 1 /// The .class file has been read. -#define resolved 2 /// The class has been resolved. -#define vmjc 3 /// The class is defined in a shared library. -#define inClinit 4 /// The class is cliniting. -#define ready 5 /// The class is ready to be used. -#define erroneous 6 /// The class is in an erroneous state. +#define resolving 2 /// The class file is being resolved. +#define resolved 3 /// The class has been resolved. +#define vmjc 4 /// The class is defined in a shared library. +#define inClinit 5 /// The class is cliniting. +#define ready 6 /// The class is ready to be used. +#define erroneous 7 /// The class is in an erroneous state. /// Attribut - This class represents JVM attributes to Java class, methods and @@ -789,6 +790,12 @@ getCurrentTaskClassMirror().status = classRead; } + /// setIsResolving - The class file is being resolved. + /// + void setIsResolving() { + getCurrentTaskClassMirror().status = resolving; + } + #else @@ -810,6 +817,12 @@ } } + void setIsResolving() { + for (uint32 i = 0; i < NR_ISOLATES; ++i) { + IsolateInfo[i].status = resolving; + } + } + void setErroneous() { for (uint32 i = 0; i < NR_ISOLATES; ++i) { IsolateInfo[i].status = erroneous; @@ -871,7 +884,7 @@ /// isResolving - Is the class currently being resolved? /// bool isResolving() { - return getCurrentTaskClassMirror().status == classRead; + return getCurrentTaskClassMirror().status == resolving; } /// isClassRead - Has the .class file been read? Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp Thu Apr 16 17:01:26 2009 @@ -278,7 +278,7 @@ else return UTF8At(ctpDef[index]); } -CommonClass* JavaConstantPool::loadClass(uint32 index) { +CommonClass* JavaConstantPool::loadClass(uint32 index, bool resolve) { CommonClass* temp = isClassLoaded(index); #ifndef ISOLATE_SHARING if (!temp) { @@ -288,7 +288,7 @@ temp = loader->constructArray(name); } else { // Put into ctpRes because there is only one representation of the class - temp = loader->loadName(name, true, false); + temp = loader->loadName(name, resolve, false); } ctpRes[index] = temp; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.h Thu Apr 16 17:01:26 2009 @@ -248,7 +248,7 @@ /// ie when the class will be used and not yet resolved, and also for /// loading exceptions when JITting catch clauses. /// - CommonClass* loadClass(uint32 index); + CommonClass* loadClass(uint32 index, bool resolve = true); /// JavaConstantPool - Reads the bytecode of the class to get /// the initial types and constants definitions. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69317&r1=69316&r2=69317&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Thu Apr 16 17:01:26 2009 @@ -379,9 +379,9 @@ if (cl && cl->classLoader != this) { classes->lock.lock(); ClassMap::iterator End = classes->map.end(); - ClassMap::iterator I = classes->map.find(name); + ClassMap::iterator I = classes->map.find(cl->name); if (I == End) - classes->map.insert(std::make_pair(name, cl)); + classes->map.insert(std::make_pair(cl->name, cl)); classes->lock.unlock(); } @@ -562,7 +562,19 @@ UserCommonClass* cl = loadBaseClass(name, 1, name->size - 1); assert(cl && "no base class for an array"); JnjvmClassLoader* ld = cl->classLoader; - return ld->constructArray(name, cl); + UserClassArray* res = ld->constructArray(name, cl); + + // We are an initiating clas loader. + if (res && res->classLoader != this) { + classes->lock.lock(); + ClassMap::iterator End = classes->map.end(); + ClassMap::iterator I = classes->map.find(res->name); + if (I == End) + classes->map.insert(std::make_pair(res->name, res)); + classes->lock.unlock(); + } + + return res; } UserClass* JnjvmClassLoader::constructClass(const UTF8* name, @@ -580,6 +592,12 @@ res = ((UserClass*)(I->second)); } classes->lock.unlock(); + + res->acquire(); + if (!res->isClassRead()) res->readClass(); + res->release(); + + return res; } From nicolas.geoffray at lip6.fr Thu Apr 16 15:17:35 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 16 Apr 2009 22:17:35 -0000 Subject: [vmkit-commits] [vmkit] r69318 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMClassLoader.cpp VMCore/Jnjvm.cpp VMCore/Jnjvm.h Message-ID: <200904162217.n3GMHZmr005796@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 16 17:17:34 2009 New Revision: 69318 URL: http://llvm.org/viewvc/llvm-project?rev=69318&view=rev Log: Throw a linkage error when a class is being defined twice. Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp?rev=69318&r1=69317&r2=69318&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp Thu Apr 16 17:17:34 2009 @@ -125,9 +125,16 @@ JavaString* str = (JavaString*)_str; const UTF8* name = str->value->javaToInternal(vm, str->offset, str->count); - UserClass* cl = JCL->constructClass(name, (ArrayUInt8*)bytes); + UserCommonClass* cl = JCL->lookupClass(name); + + if (!cl) { + UserClass* cl = JCL->constructClass(name, (ArrayUInt8*)bytes); - res = (jclass)(cl->getClassDelegatee(vm, (JavaObject*)pd)); + res = (jclass)(cl->getClassDelegatee(vm, (JavaObject*)pd)); + } else { + JavaObject* obj = vm->CreateLinkageError("duplicate class definition"); + JavaThread::get()->throwException(obj); + } END_NATIVE_EXCEPTION Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69318&r1=69317&r2=69318&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Apr 16 17:17:34 2009 @@ -331,6 +331,11 @@ upcalls->InitClassCastException, ""); } +JavaObject* Jnjvm::CreateLinkageError(const char* msg) { + return CreateError(upcalls->LinkageError, + upcalls->InitLinkageError, msg); +} + void Jnjvm::illegalAccessException(const char* msg) { error(upcalls->IllegalAccessException, upcalls->InitIllegalAccessException, msg); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=69318&r1=69317&r2=69318&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Thu Apr 16 17:17:34 2009 @@ -251,6 +251,7 @@ JavaObject* CreateIndexOutOfBoundsException(sint32 entry); JavaObject* CreateNegativeArraySizeException(); JavaObject* CreateClassCastException(JavaObject* obj, UserCommonClass* cl); + JavaObject* CreateLinkageError(const char* msg = ""); /// Exceptions - These are the only exceptions VMKit will make. /// From nicolas.geoffray at lip6.fr Fri Apr 17 06:07:11 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 17 Apr 2009 13:07:11 -0000 Subject: [vmkit-commits] [vmkit] r69349 - in /vmkit/trunk/lib/JnJVM: Compiler/ExceptionsCheck.inc VMCore/JavaRuntimeJIT.cpp Message-ID: <200904171307.n3HD7CDj007555@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 17 08:07:09 2009 New Revision: 69349 URL: http://llvm.org/viewvc/llvm-project?rev=69349&view=rev Log: Because runtime intrinsics were marked readnone, LLVM was moving things around it. And the exception check could be moved before the call. We trick LLVM by using the return value of these runtime intrinsics: these functions never return null, so if the return value equals to the current exception (which may be null), then branch to the an exception handler. Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc?rev=69349&r1=69348&r2=69349&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc (original) +++ vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc Fri Apr 17 08:07:09 2009 @@ -19,9 +19,21 @@ BasicBlock* ifNormal = createBasicBlock("no exception block"); + Value* test = 0; Constant* zero = module->JavaObjectNullConstant; - Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", - currentBlock); + + // If F is a runtime intrinsic that does not access memory, use a hack + // that will prevent LLVM from moving the exception check: runtime + // intrinsics return the exception if an exception was raised. + if (F == module->InitialisationCheckFunction || + F == module->GetConstantPoolAtFunction || + F == module->GetArrayClassFunction || + F == module->GetClassDelegateeFunction) { + test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); + test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + } else { + test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + } BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock); @@ -57,9 +69,17 @@ BasicBlock* ifNormal = createBasicBlock("no exception block"); + Value* test = 0; Constant* zero = module->JavaObjectNullConstant; - Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", - currentBlock); + if (F == module->InitialisationCheckFunction || + F == module->GetConstantPoolAtFunction || + F == module->GetArrayClassFunction || + F == module->GetClassDelegateeFunction) { + test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); + test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + } else { + test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + } BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock); @@ -95,11 +115,19 @@ Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock); BasicBlock* ifNormal = createBasicBlock("no exception block"); - + + Value* test = 0; Constant* zero = module->JavaObjectNullConstant; - Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", - currentBlock); - + if (F == module->InitialisationCheckFunction || + F == module->GetConstantPoolAtFunction || + F == module->GetArrayClassFunction || + F == module->GetClassDelegateeFunction) { + test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); + test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + } else { + test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + } + BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock); if (!currentExceptionBlock->empty()) { @@ -132,9 +160,17 @@ BasicBlock* ifNormal = createBasicBlock("no exception block"); + Value* test = 0; Constant* zero = module->JavaObjectNullConstant; - Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", - currentBlock); + if (F == module->InitialisationCheckFunction || + F == module->GetConstantPoolAtFunction || + F == module->GetArrayClassFunction || + F == module->GetClassDelegateeFunction) { + test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); + test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + } else { + test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + } BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=69349&r1=69348&r2=69349&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Fri Apr 17 08:07:09 2009 @@ -125,6 +125,11 @@ END_NATIVE_EXCEPTION + // Since the function is marked readnone, LLVM may move it after the + // exception check. Therefore, we trick LLVM to check the return value of the + // function. + JavaObject* obj = JavaThread::get()->pendingException; + if (obj) return (void*)obj; return res; } @@ -164,6 +169,11 @@ END_NATIVE_EXCEPTION + // Since the function is marked readnone, LLVM may move it after the + // exception check. Therefore, we trick LLVM to check the return value of the + // function. + JavaObject* obj = JavaThread::get()->pendingException; + if (obj) return (void*)obj; return res; } @@ -209,6 +219,11 @@ END_NATIVE_EXCEPTION + // Since the function is marked readnone, LLVM may move it after the + // exception check. Therefore, we trick LLVM to check the return value of the + // function. + JavaObject* obj = JavaThread::get()->pendingException; + if (obj) return (void*)obj; return res; } #endif @@ -230,7 +245,12 @@ res = (void*)cl; END_NATIVE_EXCEPTION - + + // Since the function is marked readnone, LLVM may move it after the + // exception check. Therefore, we trick LLVM to check the return value of the + // function. + JavaObject* obj = JavaThread::get()->pendingException; + if (obj) return (void*)obj; return res; } @@ -243,6 +263,12 @@ cl->initialiseClass(JavaThread::get()->getJVM()); END_NATIVE_EXCEPTION + + // Since the function is marked readnone, LLVM may move it after the + // exception check. Therefore, we trick LLVM to check the return value of the + // function. + JavaObject* obj = JavaThread::get()->pendingException; + if (obj) return (UserCommonClass*)obj; return cl; } @@ -254,7 +280,12 @@ Jnjvm* vm = JavaThread::get()->getJVM(); res = cl->getClassDelegatee(vm); END_NATIVE_EXCEPTION - + + // Since the function is marked readnone, LLVM may move it after the + // exception check. Therefore, we trick LLVM to check the return value of the + // function. + JavaObject* obj = JavaThread::get()->pendingException; + if (obj) return obj; return res; } @@ -322,6 +353,11 @@ END_NATIVE_EXCEPTION + // Since the function is marked readnone, LLVM may move it after the + // exception check. Therefore, we trick LLVM to check the return value of the + // function. + JavaObject* obj = JavaThread::get()->pendingException; + if (obj) return (UserClassArray*)obj; return res; } From nicolas.geoffray at lip6.fr Sat Apr 18 05:54:59 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 18 Apr 2009 12:54:59 -0000 Subject: [vmkit-commits] [vmkit] r69442 - /vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc Message-ID: <200904181255.n3ICt1Mk029322@zion.cs.uiuc.edu> Author: geoffray Date: Sat Apr 18 07:54:42 2009 New Revision: 69442 URL: http://llvm.org/viewvc/llvm-project?rev=69442&view=rev Log: As it turns out, a readnone function may return 0 (what if the application direclty calls finalize?). So do an extra check that there is indeed an exception. Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc?rev=69442&r1=69441&r2=69442&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc (original) +++ vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc Sat Apr 18 07:54:42 2009 @@ -31,6 +31,8 @@ F == module->GetClassDelegateeFunction) { test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + Value* T = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + test = BinaryOperator::CreateAnd(test, T, "", currentBlock); } else { test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); } @@ -77,6 +79,8 @@ F == module->GetClassDelegateeFunction) { test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + Value* T = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + test = BinaryOperator::CreateAnd(test, T, "", currentBlock); } else { test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); } @@ -124,6 +128,8 @@ F == module->GetClassDelegateeFunction) { test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + Value* T = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + test = BinaryOperator::CreateAnd(test, T, "", currentBlock); } else { test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); } @@ -168,6 +174,8 @@ F == module->GetClassDelegateeFunction) { test = new BitCastInst(res, module->JavaObjectType, "", currentBlock); test = new ICmpInst(ICmpInst::ICMP_EQ, test, obj, "", currentBlock); + Value* T = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); + test = BinaryOperator::CreateAnd(test, T, "", currentBlock); } else { test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "", currentBlock); } From nicolas.geoffray at lip6.fr Sat Apr 18 06:08:26 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 18 Apr 2009 13:08:26 -0000 Subject: [vmkit-commits] [vmkit] r69443 - in /vmkit/trunk/lib/JnJVM: Compiler/JITInfo.cpp Compiler/JavaAOTCompiler.cpp Compiler/JnjvmModule.cpp VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/LockedMap.h Message-ID: <200904181308.n3ID8Sce029778@zion.cs.uiuc.edu> Author: geoffray Date: Sat Apr 18 08:07:59 2009 New Revision: 69443 URL: http://llvm.org/viewvc/llvm-project?rev=69443&view=rev Log: Implement the algorithm from Click et al.'s paper: "Fast Subtype Checking in the HotSpot JVM" (JGI'02). This improves over the current situation in cases of array and interface subchecking. Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.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/LockedMap.h Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=69443&r1=69442&r2=69443&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Sat Apr 18 08:07:59 2009 @@ -72,10 +72,10 @@ uint64 size = JnjvmModule::getTypeSize(structType); classDef->virtualSize = (uint32)size; virtualSizeConstant = ConstantInt::get(Type::Int32Ty, size); - + if (!Mod->isStaticCompiling()) { if (!classDef->virtualVT) { - Mod->makeVT((Class*)classDef); + Mod->makeVT(classDef); } else { #ifdef WITH_TRACER // So the class is vmjc'ed. Create the virtual tracer. @@ -84,8 +84,8 @@ "markAndTraceObject", Mod->getLLVMModule()); - void* ptr = ((void**)classDef->virtualVT)[VT_TRACER_OFFSET]; - JnjvmModule::executionEngine->addGlobalMapping(func, ptr); + uintptr_t ptr = classDef->virtualVT->tracer; + JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr); virtualTracerFunction = func; #endif } Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69443&r1=69442&r2=69443&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Sat Apr 18 08:07:59 2009 @@ -1196,13 +1196,35 @@ Elemts.push_back(ConstantExpr::getIntToPtr( ConstantInt::get(Type::Int64Ty, VT->depth), PTy)); + // offset + Elemts.push_back(ConstantExpr::getIntToPtr( + ConstantInt::get(Type::Int64Ty, VT->offset), PTy)); + + // cache + Elemts.push_back(ConstantExpr::getIntToPtr( + ConstantInt::get(Type::Int64Ty, VT->cache), PTy)); + // display + for (uint32 i = 0; i < JavaVirtualTable::getDisplayLength(); ++i) { + if (VT->display[i]) { + Constant* Temp = getVirtualTable(VT->display[i]); + Temp = ConstantExpr::getBitCast(Temp, PTy); + Elemts.push_back(Temp); + } else + Elemts.push_back(Constant::getNullValue(PTy)); + } + + // nbSecondaryTypes + Elemts.push_back(ConstantExpr::getIntToPtr( + ConstantInt::get(Type::Int64Ty, VT->nbSecondaryTypes), PTy)); + + // secondaryTypes const ArrayType* DTy = ArrayType::get(JnjvmModule::VTType, - VT->depth + 1); + VT->nbSecondaryTypes); std::vector TempElmts; - for (uint32 i = 0; i <= VT->depth; ++i) { - Constant* Cl = getVirtualTable(VT->display[i]); + for (uint32 i = 0; i < VT->nbSecondaryTypes; ++i) { + Constant* Cl = getVirtualTable(VT->secondaryTypes[i]); TempElmts.push_back(Cl); } Constant* display = ConstantArray::get(DTy, TempElmts); @@ -1439,6 +1461,7 @@ JavaMethod& meth = cl->virtualMethods[i]; ((void**)VT)[meth.offset] = &meth; } + if (!cl->super) VT->destructor = 0; } void JavaAOTCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) { Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69443&r1=69442&r2=69443&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Sat Apr 18 08:07:59 2009 @@ -475,14 +475,16 @@ if (func->hasNotBeenReadFromBitcode()) { // We are jitting. Take the lock. JnjvmModule::protectIR(); - JavaJIT jit(this, meth, func); - if (isNative(meth->access)) { - jit.nativeCompile(); - JnjvmModule::runPasses(func, JavaNativeFunctionPasses); - } else { - jit.javaCompile(); - JnjvmModule::runPasses(func, JnjvmModule::globalFunctionPasses); - JnjvmModule::runPasses(func, JavaFunctionPasses); + if (func->hasNotBeenReadFromBitcode()) { + JavaJIT jit(this, meth, func); + if (isNative(meth->access)) { + jit.nativeCompile(); + JnjvmModule::runPasses(func, JavaNativeFunctionPasses); + } else { + jit.javaCompile(); + JnjvmModule::runPasses(func, JnjvmModule::globalFunctionPasses); + JnjvmModule::runPasses(func, JavaFunctionPasses); + } } JnjvmModule::unprotectIR(); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69443&r1=69442&r2=69443&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sat Apr 18 08:07:59 2009 @@ -347,15 +347,12 @@ th->throwException(th->ServiceException); } #endif - classDef->acquire(); - if (code == 0) { - code = classDef->classLoader->getCompiler()->materializeFunction(this); - Jnjvm* vm = JavaThread::get()->getJVM(); - vm->addMethodInFunctionMap(this, code); - } - classDef->release(); - return code; + code = classDef->classLoader->getCompiler()->materializeFunction(this); + Jnjvm* vm = JavaThread::get()->getJVM(); + vm->addMethodInFunctionMap(this, code); } + + return code; } void JavaMethod::setCompiledPtr(void* ptr, const char* name) { @@ -1240,42 +1237,47 @@ return false; } - void ClassArray::initialiseVT(Class* javaLangObject) { ClassArray::SuperArray = javaLangObject; JnjvmClassLoader* JCL = javaLangObject->classLoader; + Classpath* upcalls = JCL->bootstrapLoader->upcalls; + + assert(javaLangObject->virtualVT->init && + "Initializing array VT before JavaObjectVT"); - // Initialize interfaces of array classes. + // Load and resolve interfaces of array classes. We resolve them now + // so that the secondary type list of array VTs can reference them. ClassArray::InterfacesArray[0] = JCL->loadName(JCL->asciizConstructUTF8("java/lang/Cloneable"), - false, false); + true, false); ClassArray::InterfacesArray[1] = JCL->loadName(JCL->asciizConstructUTF8("java/io/Serializable"), - false, false); + true, false); + + // Load base array classes that JnJVM internally uses. Now that the interfaces + // have been loaded, the secondary type can be safely created. + upcalls->ArrayOfString = + JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/String;")); - Class* cl = ClassArray::SuperArray; - assert(cl && "Initializing array VT without a super for arrays"); - assert(cl->virtualVT->init && "Initializing array VT before JavaObjectVT"); - - // Set the values in the JavaObject VT - cl->virtualVT->depth = 0; - cl->virtualVT->cl = cl; - cl->virtualVT->display = (JavaVirtualTable**) - cl->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*)); - cl->virtualVT->display[0] = cl->virtualVT; + upcalls->ArrayOfObject = + JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/Object;")); - Classpath* upcalls = cl->classLoader->bootstrapLoader->upcalls; + // Update native array classes. A few things have not been set properly + // when loading these classes because java.lang.Object and java.lang.Object[] + // were not loaded yet. Correct that now by updating these classes. #define COPY(CLASS) \ memcpy(CLASS->virtualVT->getFirstJavaMethod(), \ - cl->virtualVT->getFirstJavaMethod(), \ + javaLangObject->virtualVT->getFirstJavaMethod(), \ sizeof(uintptr_t) * JavaVirtualTable::getNumJavaMethods()); \ - CLASS->super = cl; \ - CLASS->display[0] = cl; \ + CLASS->super = javaLangObject; \ + CLASS->display[0] = javaLangObject; \ CLASS->display[1] = CLASS; \ - CLASS->virtualVT->display[0] = cl->virtualVT; + CLASS->virtualVT->display[0] = javaLangObject->virtualVT; \ + CLASS->virtualVT->secondaryTypes = \ + upcalls->ArrayOfObject->virtualVT->secondaryTypes; \ COPY(upcalls->ArrayOfBool) COPY(upcalls->ArrayOfByte) @@ -1288,47 +1290,67 @@ #undef COPY - // Load array classes that JnJVM internally uses. - upcalls->ArrayOfString = - JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/String;")); - - upcalls->ArrayOfObject = - JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/Object;")); } JavaVirtualTable::JavaVirtualTable(Class* C) { if (C->super) { - // (1) Copy the super VT into the current VT. + // Copy the super VT into the current VT. uint32 size = C->super->virtualTableSize * sizeof(uintptr_t); memcpy(this, C->super->virtualVT, size); - // (2) Set the class of this VT. + // Set the class of this VT. cl = C; - // (3) Set depth and display for fast dynamic type checking. - depth = C->super->virtualVT->depth + 1; + // Set depth and display for fast dynamic type checking. + JavaVirtualTable* superVT = C->super->virtualVT; + depth = superVT->depth + 1; + nbSecondaryTypes = superVT->nbSecondaryTypes + cl->nbInterfaces; + + uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth; + memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*)); + if (depth < getDisplayLength()) { + display[depth] = this; + offset = getCacheIndex() + depth + 1; + } else { + offset = getCacheIndex(); + ++nbSecondaryTypes; + } + mvm::BumpPtrAllocator& allocator = C->classLoader->allocator; - display = (JavaVirtualTable**) - allocator.Allocate(sizeof(JavaVirtualTable*) * (depth + 1)); - size = depth * sizeof(JavaVirtualTable*); - memcpy(display, C->super->virtualVT->display, size); - display[depth] = this; + secondaryTypes = (JavaVirtualTable**) + allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes); + + if (offset == getCacheIndex()) { + secondaryTypes[0] = this; + } + + if (superVT->nbSecondaryTypes) { + memcpy(secondaryTypes + 1, superVT->secondaryTypes, + sizeof(JavaVirtualTable*) * superVT->nbSecondaryTypes); + } + + for (uint32 i = 0; i < cl->nbInterfaces; ++i) { + JavaVirtualTable* cur = cl->interfaces[i]->virtualVT; + secondaryTypes[superVT->nbSecondaryTypes + 1 + i] = cur; + } + } else { - // (1) Set the tracer, destructor and delete + // Set the tracer, destructor and delete tracer = (uintptr_t)JavaObjectTracer; destructor = 0; operatorDelete = 0; - // (2) Set the class of this VT. + // Set the class of this VT. cl = C; - // (3) Set depth and display for fast dynamic type checking. + // Set depth and display for fast dynamic type checking. + // java.lang.Object does not have any secondary types. + offset = getCacheIndex() + 1; depth = 0; - display = (JavaVirtualTable**) - C->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*)); display[0] = this; destructor = 0; + nbSecondaryTypes = 0; } @@ -1337,38 +1359,157 @@ JavaVirtualTable::JavaVirtualTable(ClassArray* C) { if (!C->baseClass()->isPrimitive()) { - // (1) Copy the super VT into the current VT. + // Copy the super VT into the current VT. uint32 size = getNumMethods() * sizeof(uintptr_t); memcpy(this, C->super->virtualVT, size); tracer = (uintptr_t)ArrayObjectTracer; - // (2) Set the class of this VT. + // Set the class of this VT. cl = C; - // (3) Set depth and display for fast dynamic type checking. - depth = 1; - mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - display = - (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2); - display[0] = C->super->virtualVT; - display[1] = this; + // Set depth and display for fast dynamic type checking. + JnjvmClassLoader* JCL = cl->classLoader; + Classpath* upcalls = JCL->bootstrapLoader->upcalls; + + if (upcalls->ArrayOfObject) { + UserCommonClass* temp = C->baseClass(); + uint32 dim = 1; + while (temp->isArray()) { + temp = temp->asArrayClass()->baseClass(); + ++dim; + } + + bool newSecondaryTypes = false; + if (temp->isPrimitive()) { + --dim; + temp = C->super; + } else if (temp == C->super) { + --dim; + newSecondaryTypes = true; + } else { + temp = temp->super; + } + + const UTF8* name = JCL->constructArrayName(dim, temp->name); + ClassArray* super = JCL->constructArray(name); + JavaVirtualTable* superVT = super->virtualVT; + depth = superVT->depth + 1; + + uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth; + memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*)); + if (depth < getDisplayLength()) display[depth] = this; + + mvm::BumpPtrAllocator& allocator = JCL->allocator; + + if (!newSecondaryTypes) { + if (depth < getDisplayLength()) { + nbSecondaryTypes = superVT->nbSecondaryTypes; + secondaryTypes = superVT->secondaryTypes; + } else { + nbSecondaryTypes = superVT->nbSecondaryTypes + 1; + secondaryTypes = (JavaVirtualTable**) + allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes); + secondaryTypes[0] = this; + memcpy(secondaryTypes + 1 , superVT->secondaryTypes, + superVT->nbSecondaryTypes * sizeof(JavaVirtualTable*)); + } + } 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. + + // If we're superior than the display limit, we must make room for one + // slot that will contain the current VT. + uint32 outOfDepth = 0; + if (depth >= getDisplayLength()) outOfDepth = 1; + + assert(cl->nbInterfaces == 2 && "Arrays have more than 2 interface?"); + + // The list of secondary types is composed of: + // (1) The list of secondary types of super array. + // (2) The array of inherited interfaces with the same dimensions. + // (3) This VT, if its depth is superior than the display size. + nbSecondaryTypes = superVT->nbSecondaryTypes + 2 + outOfDepth; + + secondaryTypes = (JavaVirtualTable**) + allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes); + + // First, copy the list of secondary types from super array. + memcpy(secondaryTypes + outOfDepth, superVT->secondaryTypes, + superVT->nbSecondaryTypes * sizeof(JavaVirtualTable*)); + + // If the depth is superior than the display size, put the current VT + // at the beginning of the list. + if (outOfDepth) secondaryTypes[0] = this; + + // Load Cloneable[...] and Serializable[...] + const UTF8* name = JCL->constructArrayName(dim, cl->interfaces[0]->name); + ClassArray* firstInterface = JCL->constructArray(name); + name = JCL->constructArrayName(dim, cl->interfaces[1]->name); + ClassArray* secondInterface = JCL->constructArray(name); + + uint32 index = superVT->nbSecondaryTypes + outOfDepth; + + // Put Cloneable[...] and Serializable[...] at the end of the list. + secondaryTypes[index] = firstInterface->virtualVT; + secondaryTypes[index + 1] = secondInterface->virtualVT; + + // If the depth is greater than the display size, + // Cloneable[...] and Serializable[...] have their own list of + // secondary types, and we must therefore tell them that they + // implement themselves. + // If the depth is less than than the display size, there is nothing + // to do: the array of secondary types has been created before loading + // the interface arrays, so the interface arrays already reference + // the array. + if (outOfDepth) { + firstInterface->virtualVT->secondaryTypes[index] = + firstInterface->virtualVT; + firstInterface->virtualVT->secondaryTypes[index + 1] = + secondInterface->virtualVT; + secondInterface->virtualVT->secondaryTypes[index] = + firstInterface->virtualVT; + secondInterface->virtualVT->secondaryTypes[index + 1] = + secondInterface->virtualVT; + } + } + + } else { + // This is java.lang.Object[]. + depth = 1; + display[0] = C->super->virtualVT; + display[1] = this; + nbSecondaryTypes = 2; + + mvm::BumpPtrAllocator& allocator = JCL->allocator; + secondaryTypes = (JavaVirtualTable**) + allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes); + + // The interfaces have already been resolved. + secondaryTypes[0] = cl->interfaces[0]->virtualVT; + secondaryTypes[1] = cl->interfaces[1]->virtualVT; + } + } else { - // (1) Set the tracer, destructor and delete + // Set the tracer, destructor and delete tracer = (uintptr_t)JavaArrayTracer; destructor = 0; operatorDelete = 0; - // (2) Set the class of this VT. + // Set the class of this VT. cl = C; - // (3) Set depth and display for fast dynamic type checking. Since + // Set depth and display for fast dynamic type checking. Since // JavaObject has not been loaded yet, don't use super. depth = 1; - mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - display = - (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2); display[0] = 0; display[1] = this; + nbSecondaryTypes = 2; + + // The list of secondary types has not been allocated yet by + // java.lang.Object[]. The initialiseVT function will update the current + // array to point to java.lang.Object[]'s secondary list. } } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69443&r1=69442&r2=69443&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Apr 18 08:07:59 2009 @@ -1343,7 +1343,11 @@ public: CommonClass* cl; size_t depth; - JavaVirtualTable** display; + size_t offset; + size_t cache; + JavaVirtualTable* display[8]; + size_t nbSecondaryTypes; + JavaVirtualTable** secondaryTypes; uintptr_t init; uintptr_t equals; @@ -1356,6 +1360,7 @@ uintptr_t waitIndefinitely; uintptr_t waitMs; uintptr_t waitMsNs; + uintptr_t virtualMethods[1]; void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator, uint32 nbMethods) { @@ -1369,19 +1374,28 @@ uintptr_t* getFirstJavaMethod() { return &init; } - + static uint32_t getFirstJavaMethodIndex() { - return 6; + return 17; } static uint32_t getNumMethods() { - return 17; + return 28; } static uint32_t getNumJavaMethods() { return 11; } + static uint32_t getDisplayLength() { + return 8; + } + +private: + static uint32_t getCacheIndex() { + return 6; + } + }; Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h?rev=69443&r1=69442&r2=69443&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h Sat Apr 18 08:07:59 2009 @@ -44,13 +44,13 @@ } }; -template +template class LockedMap : public mvm::PermanentObject { public: typedef typename std::map::iterator iterator; typedef Container (*funcCreate)(Key& V, Meta meta); - mvm::LockNormal lock; + TLock lock; std::map > > map; @@ -137,7 +137,8 @@ }; class ClassMap : - public LockedMap { + public LockedMap { #ifdef USE_GC_BOEHM public: @@ -148,7 +149,7 @@ }; class StringMap : - public LockedMap { + public LockedMap { public: void insert(JavaString* str); From nicolas.geoffray at lip6.fr Sat Apr 18 06:29:25 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 18 Apr 2009 13:29:25 -0000 Subject: [vmkit-commits] [vmkit] r69444 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904181329.n3IDTQCU030559@zion.cs.uiuc.edu> Author: geoffray Date: Sat Apr 18 08:29:18 2009 New Revision: 69444 URL: http://llvm.org/viewvc/llvm-project?rev=69444&view=rev Log: Fix mindo. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69444&r1=69443&r2=69444&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sat Apr 18 08:29:18 2009 @@ -1309,30 +1309,34 @@ uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth; memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*)); + uint32 outOfDepth = 0; if (depth < getDisplayLength()) { display[depth] = this; offset = getCacheIndex() + depth + 1; } else { offset = getCacheIndex(); ++nbSecondaryTypes; + outOfDepth = 1; } mvm::BumpPtrAllocator& allocator = C->classLoader->allocator; secondaryTypes = (JavaVirtualTable**) allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes); - if (offset == getCacheIndex()) { + if (outOfDepth) { secondaryTypes[0] = this; } if (superVT->nbSecondaryTypes) { - memcpy(secondaryTypes + 1, superVT->secondaryTypes, + memcpy(secondaryTypes + outOfDepth, superVT->secondaryTypes, sizeof(JavaVirtualTable*) * superVT->nbSecondaryTypes); } for (uint32 i = 0; i < cl->nbInterfaces; ++i) { JavaVirtualTable* cur = cl->interfaces[i]->virtualVT; - secondaryTypes[superVT->nbSecondaryTypes + 1 + i] = cur; + assert(cur && "Interface not resolved!\n"); + uint32 index = superVT->nbSecondaryTypes + outOfDepth + i; + secondaryTypes[index] = cur; } } else { From nicolas.geoffray at lip6.fr Sat Apr 18 06:36:46 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 18 Apr 2009 13:36:46 -0000 Subject: [vmkit-commits] [vmkit] r69445 - in /vmkit/trunk: lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/JnjvmClassLoader.cpp lib/N3/VMCore/VMClass.h tools/llcj/llcj.cpp tools/vmkit/Launcher.cpp Message-ID: <200904181336.n3IDalnS030774@zion.cs.uiuc.edu> Author: geoffray Date: Sat Apr 18 08:36:34 2009 New Revision: 69445 URL: http://llvm.org/viewvc/llvm-project?rev=69445&view=rev Log: Fix compilation with gcc3.4 and gcc4.4. Patch by Xerxes Ranby! Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/N3/VMCore/VMClass.h vmkit/trunk/tools/llcj/llcj.cpp vmkit/trunk/tools/vmkit/Launcher.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69445&r1=69444&r2=69445&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sat Apr 18 08:36:34 2009 @@ -512,7 +512,7 @@ } extern "C" int sys_strnstr(const char *haystack, const char *needle) { - char * res = strstr(haystack, needle); + char * res = (char*)strstr(haystack, needle); if (res) return res - haystack; else return -1; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69445&r1=69444&r2=69445&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sat Apr 18 08:36:34 2009 @@ -996,7 +996,7 @@ const char* file) { char* soName = (char*)alloca(strlen(name) + strlen(DYLD_EXTENSION)); - char* ptr = strrchr(name, '/'); + char* ptr = (char*)strrchr(name, '/'); sprintf(soName, "%s%s", ptr ? ptr + 1 : name, DYLD_EXTENSION); void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL); if (handle) { Modified: vmkit/trunk/lib/N3/VMCore/VMClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.h?rev=69445&r1=69444&r2=69445&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.h (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.h Sat Apr 18 08:36:34 2009 @@ -21,6 +21,8 @@ #include "llvm/Function.h" #include "llvm/Type.h" +#include + namespace n3 { class ArraySInt32; Modified: vmkit/trunk/tools/llcj/llcj.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/llcj/llcj.cpp?rev=69445&r1=69444&r2=69445&view=diff ============================================================================== --- vmkit/trunk/tools/llcj/llcj.cpp (original) +++ vmkit/trunk/tools/llcj/llcj.cpp Sat Apr 18 08:36:34 2009 @@ -14,6 +14,10 @@ #include "LinkPaths.h" +#include +#include +#include + using namespace llvm; int main(int argc, char **argv) { Modified: vmkit/trunk/tools/vmkit/Launcher.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmkit/Launcher.cpp?rev=69445&r1=69444&r2=69445&view=diff ============================================================================== --- vmkit/trunk/tools/vmkit/Launcher.cpp (original) +++ vmkit/trunk/tools/vmkit/Launcher.cpp Sat Apr 18 08:36:34 2009 @@ -164,7 +164,7 @@ #if WITH_N3 mvm::CompilationUnit* CLICompiler = mvm::VirtualMachine::initialiseCLIVM(); - MyCl.vmlets["net"] = (mvm::VirtualMachine::createCLIVM); + MyCl.vmlets["net"] = (create_vm_t)(mvm::VirtualMachine::createCLIVM); MyCl.compilers["net"] = CLICompiler; #endif MyCl.start(); From nicolas.geoffray at lip6.fr Sun Apr 19 12:09:19 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 19 Apr 2009 19:09:19 -0000 Subject: [vmkit-commits] [vmkit] r69533 - in /vmkit/trunk: include/jnjvm/ lib/JnJVM/Classpath/ lib/JnJVM/Compiler/ lib/JnJVM/LLVMRuntime/ lib/JnJVM/VMCore/ Message-ID: <200904191909.n3JJ9KWd019293@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 19 14:09:19 2009 New Revision: 69533 URL: http://llvm.org/viewvc/llvm-project?rev=69533&view=rev Log: Move to the new subtype checking implementation when jitting Java code (the function call still needs to be lowered) and finally implement the long-awaiting array-store check! Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sun Apr 19 14:09:19 2009 @@ -66,6 +66,7 @@ class LLVMClassInfo : public mvm::JITInfo { + friend class JavaJITCompiler; friend class JavaLLVMCompiler; private: Class* classDef; @@ -253,10 +254,7 @@ #ifndef WITHOUT_VTABLE llvm::Function* VirtualLookupFunction; #endif - llvm::Function* InstanceOfFunction; llvm::Function* IsAssignableFromFunction; - llvm::Function* ImplementsFunction; - llvm::Function* InstantiationOfArrayFunction; llvm::Function* GetDepthFunction; llvm::Function* GetClassInDisplayFunction; llvm::Function* GetStaticInstanceFunction; @@ -293,7 +291,9 @@ llvm::Function* JavaObjectAllocateFunction; llvm::Function* GetVTFromClassFunction; llvm::Function* GetVTFromClassArrayFunction; + llvm::Function* GetVTFromCommonClassFunction; llvm::Function* GetObjectSizeFromClassFunction; + llvm::Function* GetBaseClassVTFromVTFunction; llvm::Function* GetLockFunction; llvm::Function* OverflowThinLockFunction; @@ -308,7 +308,6 @@ static llvm::ConstantInt* OffsetObjectSizeInClassConstant; static llvm::ConstantInt* OffsetVTInClassConstant; - static llvm::ConstantInt* OffsetVTInClassArrayConstant; static llvm::ConstantInt* OffsetDepthInClassConstant; static llvm::ConstantInt* OffsetDisplayInClassConstant; static llvm::ConstantInt* OffsetTaskClassMirrorInClassConstant; @@ -322,6 +321,7 @@ static llvm::ConstantInt* OffsetClassInVTConstant; static llvm::ConstantInt* OffsetDepthInVTConstant; static llvm::ConstantInt* OffsetDisplayInVTConstant; + static llvm::ConstantInt* OffsetBaseClassVTInVTConstant; static llvm::ConstantInt* ClassReadyConstant; @@ -335,6 +335,7 @@ llvm::Function* ClassCastExceptionFunction; llvm::Function* OutOfMemoryErrorFunction; llvm::Function* NegativeArraySizeExceptionFunction; + llvm::Function* ArrayStoreExceptionFunction; JnjvmModule(llvm::Module*); @@ -360,8 +361,6 @@ } #endif - void internalMakeVT(Class* cl); - void addJavaPasses(); private: Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp Sun Apr 19 14:09:19 2009 @@ -109,7 +109,7 @@ while (i != e) { JavaMethod* meth = vm->IPToMethod(*i); assert(meth && "Wrong stack trace"); - if (meth->classDef->subclassOf(vm->upcalls->newThrowable)) { + if (meth->classDef->isAssignableFrom(vm->upcalls->newThrowable)) { ++i; ++index; } else break; Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Sun Apr 19 14:09:19 2009 @@ -73,26 +73,7 @@ classDef->virtualSize = (uint32)size; virtualSizeConstant = ConstantInt::get(Type::Int32Ty, size); - if (!Mod->isStaticCompiling()) { - if (!classDef->virtualVT) { - Mod->makeVT(classDef); - } else { -#ifdef WITH_TRACER - // So the class is vmjc'ed. Create the virtual tracer. - Function* func = Function::Create(JnjvmModule::MarkAndTraceType, - GlobalValue::ExternalLinkage, - "markAndTraceObject", - Mod->getLLVMModule()); - - uintptr_t ptr = classDef->virtualVT->tracer; - JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr); - virtualTracerFunction = func; -#endif - } - } else { - Mod->makeVT(classDef); - } - + Mod->makeVT(classDef); } return virtualType; Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Sun Apr 19 14:09:19 2009 @@ -364,11 +364,8 @@ std::vector Elmts; - if (cl->isClass()) { - Elmts.push_back(getVirtualTable(cl->asClass()->virtualVT)); - } else { - Elmts.push_back(getVirtualTable(cl->asArrayClass()->virtualVT)); - } + // VT + Elmts.push_back(getVirtualTable(cl->virtualVT)); // lock Constant* L = ConstantInt::get(Type::Int64Ty, 0); @@ -666,7 +663,14 @@ Constant* loader = ConstantExpr::getBitCast(StaticInitializer, JnjvmModule::ptrType); CommonClassElts.push_back(loader); - + + // virtualTable + if (cl->virtualVT) { + CommonClassElts.push_back(getVirtualTable(cl->virtualVT)); + } else { + TempTy = JnjvmModule::VTType; + CommonClassElts.push_back(Constant::getNullValue(TempTy)); + } return ConstantStruct::get(STy, CommonClassElts); } @@ -836,9 +840,6 @@ ClassElts.push_back(Cl); - // virtualTable - ClassElts.push_back(getVirtualTable(cl->virtualVT)); - return ConstantStruct::get(STy, ClassElts); } @@ -855,11 +856,8 @@ // virtualSize ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualSize)); - // virtualTable - ClassElts.push_back(getVirtualTable(cl->virtualVT)); - // IsolateInfo - const ArrayType* ATy = dyn_cast(STy->getContainedType(3)); + const ArrayType* ATy = dyn_cast(STy->getContainedType(2)); assert(ATy && "Malformed type"); const StructType* TCMTy = dyn_cast(ATy->getContainedType(0)); @@ -1201,8 +1199,7 @@ ConstantInt::get(Type::Int64Ty, VT->offset), PTy)); // cache - Elemts.push_back(ConstantExpr::getIntToPtr( - ConstantInt::get(Type::Int64Ty, VT->cache), PTy)); + Elemts.push_back(N); // display for (uint32 i = 0; i < JavaVirtualTable::getDisplayLength(); ++i) { @@ -1210,8 +1207,9 @@ Constant* Temp = getVirtualTable(VT->display[i]); Temp = ConstantExpr::getBitCast(Temp, PTy); Elemts.push_back(Temp); - } else + } else { Elemts.push_back(Constant::getNullValue(PTy)); + } } // nbSecondaryTypes @@ -1236,6 +1234,15 @@ display = ConstantExpr::getCast(Instruction::BitCast, display, PTy); Elemts.push_back(display); + + // baseClassVT + if (VT->baseClassVT) { + Constant* Temp = getVirtualTable(VT->baseClassVT); + Temp = ConstantExpr::getBitCast(Temp, PTy); + Elemts.push_back(Temp); + } else { + Elemts.push_back(Constant::getNullValue(PTy)); + } // methods @@ -1455,8 +1462,16 @@ } void JavaAOTCompiler::makeVT(Class* cl) { - internalMakeVT(cl); - VirtualTable* VT = cl->virtualVT; + JavaVirtualTable* VT = cl->virtualVT; + + if (cl->super) { + // Copy the super VT into the current VT. + uint32 size = cl->super->virtualTableSize - + JavaVirtualTable::getFirstJavaMethodIndex(); + memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(), + size * sizeof(uintptr_t)); + } + for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { JavaMethod& meth = cl->virtualMethods[i]; ((void**)VT)[meth.offset] = &meth; Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Sun Apr 19 14:09:19 2009 @@ -49,7 +49,7 @@ return true; #else - if (cl->isReadyForCompilation() || compilingClass->subclassOf(cl)) { + if (cl->isReadyForCompilation() || compilingClass->isAssignableFrom(cl)) { return false; } Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 19 14:09:19 2009 @@ -134,11 +134,37 @@ #endif void JavaJITCompiler::makeVT(Class* cl) { - internalMakeVT(cl); - JavaVirtualTable* VT = cl->virtualVT; assert(VT && "No VT was allocated!"); +#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. + uint32 size = cl->super->virtualTableSize - + JavaVirtualTable::getFirstJavaMethodIndex(); + memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(), + size * sizeof(uintptr_t)); + } + + // Fill the virtual table with function pointers. ExecutionEngine* EE = mvm::MvmModule::executionEngine; for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Sun Apr 19 14:09:19 2009 @@ -654,6 +654,41 @@ Value* obj = pop(); Value* ptr = verifyAndComputePtr(obj, index, module->JavaArrayObjectType); + + if (TheCompiler->hasExceptionsEnabled()) { + + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, val, + module->JavaObjectNullConstant, + "", currentBlock); + + BasicBlock* endBlock = createBasicBlock("end array store check"); + BasicBlock* checkBlock = createBasicBlock("array store check"); + BasicBlock* exceptionBlock = + createBasicBlock("array store exception"); + BranchInst::Create(endBlock, checkBlock, cmp, currentBlock); + currentBlock = checkBlock; + + Value* valVT = CallInst::Create(module->GetVTFunction, val, "", + currentBlock); + + Value* objVT = CallInst::Create(module->GetVTFunction, obj, "", + currentBlock); + objVT = CallInst::Create(module->GetBaseClassVTFromVTFunction, objVT, + "", currentBlock); + + Value* VTArgs[2] = { valVT, objVT }; + + Value* res = CallInst::Create(module->IsAssignableFromFunction, + VTArgs, VTArgs + 2, "", currentBlock); + + BranchInst::Create(endBlock, exceptionBlock, res, currentBlock); + + currentBlock = exceptionBlock; + throwException(module->ArrayStoreExceptionFunction, VTArgs, 1); + + currentBlock = endBlock; + } + new StoreInst(val, ptr, false, currentBlock); break; } @@ -1978,7 +2013,6 @@ BasicBlock* exceptionCheckcast = 0; BasicBlock* endCheckcast = 0; - Value* result = 0; uint16 index = readU2(bytecodes, i); UserCommonClass* cl = 0; @@ -1988,6 +2022,8 @@ Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, obj, module->JavaObjectNullConstant, "", currentBlock); + BasicBlock* endBlock = createBasicBlock("end type compare"); + PHINode* node = PHINode::Create(Type::Int1Ty, "", endBlock); if (checkcast) { exceptionCheckcast = createBasicBlock("false checkcast"); @@ -2000,91 +2036,41 @@ currentBlock = exceptionCheckcast; throwException(module->ClassCastExceptionFunction, args, 2); currentBlock = ifFalse; - } - - if (cl) { - - BasicBlock* ifTrue = createBasicBlock("true type compare"); + } else { BasicBlock* ifFalse = createBasicBlock("false type compare"); - BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock); - PHINode* node = PHINode::Create(Type::Int1Ty, "", ifTrue); + BranchInst::Create(endBlock, ifFalse, cmp, currentBlock); node->addIncoming(ConstantInt::getFalse(), currentBlock); - Value* objCl = CallInst::Create(module->GetClassFunction, obj, "", - ifFalse); - Value* classArgs[2] = { objCl, clVar }; - - if (isInterface(cl->access)) { - Value* res = CallInst::Create(module->ImplementsFunction, - classArgs, classArgs + 2, "", - ifFalse); - node->addIncoming(res, ifFalse); - BranchInst::Create(ifTrue, ifFalse); - } else { - cmp = new ICmpInst(ICmpInst::ICMP_EQ, objCl, clVar, "", ifFalse); - BasicBlock* notEquals = createBasicBlock("false compare"); - BranchInst::Create(ifTrue, notEquals, cmp, ifFalse); - node->addIncoming(ConstantInt::getTrue(), ifFalse); - - if (cl->isPrimitive()) { - fprintf(stderr, "implement me"); - abort(); - } else if (cl->isArray()) { - Value* res = - CallInst::Create(module->InstantiationOfArrayFunction, - classArgs, classArgs + 2, "", notEquals); - node->addIncoming(res, notEquals); - BranchInst::Create(ifTrue, notEquals); - } else { - Value* depthCl; - if (cl->asClass()->isResolved()) { - depthCl = ConstantInt::get(Type::Int32Ty, cl->depth); - } else { - depthCl = CallInst::Create(module->GetDepthFunction, - clVar, "", notEquals); - } - - Value* depthClObj = CallInst::Create(module->GetDepthFunction, - objCl, "", notEquals); - Value* cmp = new ICmpInst(ICmpInst::ICMP_ULE, depthCl, depthClObj, - "", notEquals); - - BasicBlock* supDepth = createBasicBlock("superior depth"); - - BranchInst::Create(supDepth, ifTrue, cmp, notEquals); - node->addIncoming(ConstantInt::getFalse(), notEquals); - - Value* inDisplay = CallInst::Create(module->GetDisplayFunction, - objCl, "", supDepth); - - Value* displayArgs[2] = { inDisplay, depthCl }; - Value* clInDisplay = - CallInst::Create(module->GetClassInDisplayFunction, displayArgs, - displayArgs + 2, "", supDepth); - - cmp = new ICmpInst(ICmpInst::ICMP_EQ, clInDisplay, clVar, "", - supDepth); - BranchInst::Create(ifTrue, supDepth); - - node->addIncoming(cmp, supDepth); - } - } - - currentBlock = ifTrue; - result = node; + currentBlock = ifFalse; + } + Value* TheVT = 0; + if (!cl) { + TheVT = CallInst::Create(module->GetVTFromCommonClassFunction, + clVar, "", currentBlock); } else { - result = CallInst::Create(module->InstanceOfFunction, args, - args + 2, "", currentBlock); - + TheVT = TheCompiler->getVirtualTable(cl->virtualVT); } + + Value* objVT = CallInst::Create(module->GetVTFunction, obj, "", + currentBlock); + Value* classArgs[2] = { objVT, TheVT }; + + Value* res = CallInst::Create(module->IsAssignableFromFunction, + classArgs, classArgs + 2, "", + currentBlock); + + node->addIncoming(res, currentBlock); + BranchInst::Create(endBlock, currentBlock); + currentBlock = endBlock; + if (checkcast) { - BranchInst::Create(endCheckcast, exceptionCheckcast, result, + BranchInst::Create(endCheckcast, exceptionCheckcast, node, currentBlock); currentBlock = endCheckcast; } else { pop(); - push(new ZExtInst(result, Type::Int32Ty, "", currentBlock), + push(new ZExtInst(node, Type::Int32Ty, "", currentBlock), false); } Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Sun Apr 19 14:09:19 2009 @@ -62,7 +62,6 @@ llvm::Constant* JnjvmModule::JavaArraySizeConstant; llvm::ConstantInt* JnjvmModule::OffsetObjectSizeInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetVTInClassConstant; -llvm::ConstantInt* JnjvmModule::OffsetVTInClassArrayConstant; llvm::ConstantInt* JnjvmModule::OffsetDepthInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetDisplayInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetTaskClassMirrorInClassConstant; @@ -84,6 +83,7 @@ llvm::ConstantInt* JnjvmModule::OffsetClassInVTConstant; llvm::ConstantInt* JnjvmModule::OffsetDepthInVTConstant; llvm::ConstantInt* JnjvmModule::OffsetDisplayInVTConstant; +llvm::ConstantInt* JnjvmModule::OffsetBaseClassVTInVTConstant; JavaLLVMCompiler::JavaLLVMCompiler(const std::string& str) : @@ -176,43 +176,6 @@ } #endif - -void JavaLLVMCompiler::internalMakeVT(Class* cl) { - - for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { - JavaMethod& meth = cl->virtualMethods[i]; - if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) { - meth.offset = 0; - } else { - JavaMethod* parent = cl->super? - cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true, - 0) : - 0; - - uint64_t offset = 0; - if (!parent) { - offset = cl->virtualTableSize++; - meth.offset = offset; - } else { - offset = parent->offset; - meth.offset = parent->offset; - } - } - } - - uint32 size = cl->virtualTableSize; - if (cl->super) { - if (!(cl->virtualTableSize >= cl->super->virtualTableSize)) { - fprintf(stderr, "cl = %s et super = %s\n", cl->printString(), cl->super->printString()); - } - assert(cl->virtualTableSize >= cl->super->virtualTableSize && - "Size of virtual table less than super!"); - } - - mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator; - cl->virtualVT = new(allocator, size) JavaVirtualTable(cl); -} - void JavaLLVMCompiler::resolveVirtualClass(Class* cl) { // Lock here because we may be called by a class resolver mvm::MvmModule::protectIR(); @@ -319,14 +282,14 @@ OffsetClassInVTConstant = mvm::MvmModule::constantThree; OffsetDepthInVTConstant = mvm::MvmModule::constantFour; OffsetDisplayInVTConstant = mvm::MvmModule::constantFive; + OffsetBaseClassVTInVTConstant = ConstantInt::get(Type::Int32Ty, 17); OffsetDisplayInClassConstant = mvm::MvmModule::constantZero; OffsetDepthInClassConstant = mvm::MvmModule::constantOne; OffsetObjectSizeInClassConstant = mvm::MvmModule::constantOne; - OffsetVTInClassConstant = mvm::MvmModule::constantTwo; - OffsetVTInClassArrayConstant = mvm::MvmModule::constantTwo; - OffsetTaskClassMirrorInClassConstant = mvm::MvmModule::constantThree; + OffsetVTInClassConstant = ConstantInt::get(Type::Int32Ty, 9); + OffsetTaskClassMirrorInClassConstant = mvm::MvmModule::constantTwo; OffsetStaticInstanceInTaskClassMirrorConstant = mvm::MvmModule::constantTwo; OffsetStatusInTaskClassMirrorConstant = mvm::MvmModule::constantZero; OffsetInitializedInTaskClassMirrorConstant = mvm::MvmModule::constantOne; @@ -384,15 +347,14 @@ ClassLookupFunction = module->getFunction("classLookup"); GetVTFromClassFunction = module->getFunction("getVTFromClass"); GetVTFromClassArrayFunction = module->getFunction("getVTFromClassArray"); + GetVTFromCommonClassFunction = module->getFunction("getVTFromCommonClass"); + GetBaseClassVTFromVTFunction = module->getFunction("getBaseClassVTFromVT"); GetObjectSizeFromClassFunction = module->getFunction("getObjectSizeFromClass"); GetClassDelegateeFunction = module->getFunction("getClassDelegatee"); RuntimeDelegateeFunction = module->getFunction("jnjvmRuntimeDelegatee"); - InstanceOfFunction = module->getFunction("instanceOf"); - IsAssignableFromFunction = module->getFunction("isAssignableFrom"); - ImplementsFunction = module->getFunction("implements"); - InstantiationOfArrayFunction = module->getFunction("instantiationOfArray"); + IsAssignableFromFunction = module->getFunction("jnjvmIsAssignableFrom"); GetDepthFunction = module->getFunction("getDepth"); GetStaticInstanceFunction = module->getFunction("getStaticInstance"); GetDisplayFunction = module->getFunction("getDisplay"); @@ -416,6 +378,7 @@ NegativeArraySizeExceptionFunction = module->getFunction("negativeArraySizeException"); OutOfMemoryErrorFunction = module->getFunction("outOfMemoryError"); + ArrayStoreExceptionFunction = module->getFunction("jnjvmArrayStoreException"); JavaObjectAllocateFunction = module->getFunction("gcmalloc"); Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Sun Apr 19 14:09:19 2009 @@ -195,6 +195,18 @@ Changed = true; Value* val = Call.getArgument(0); + Value* indexes[3] = { module->constantZero, + module->constantZero, + module->OffsetVTInClassConstant }; + Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 3, + "", CI); + Value* VT = new LoadInst(VTPtr, "", CI); + CI->replaceAllUsesWith(VT); + CI->eraseFromParent(); + } else if (V == module->GetVTFromCommonClassFunction) { + Changed = true; + + Value* val = Call.getArgument(0); Value* indexes[2] = { module->constantZero, module->OffsetVTInClassConstant }; Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, @@ -206,11 +218,24 @@ Changed = true; Value* val = Call.getArgument(0); - Value* indexes[2] = { module->constantZero, - module->OffsetVTInClassArrayConstant }; + Value* indexes[3] = { module->constantZero, + module->constantZero, + module->OffsetVTInClassConstant }; + Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 3, + "", CI); + Value* VT = new LoadInst(VTPtr, "", CI); + CI->replaceAllUsesWith(VT); + CI->eraseFromParent(); + } else if (V == module->GetBaseClassVTFromVTFunction) { + Changed = true; + + Value* val = Call.getArgument(0); + Value* indexes[2] = { module->constantZero, + module->OffsetBaseClassVTInVTConstant }; Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, "", CI); Value* VT = new LoadInst(VTPtr, "", CI); + VT = new BitCastInst(VT, module->VTType, "", CI); CI->replaceAllUsesWith(VT); CI->eraseFromParent(); } else if (V == module->GetObjectSizeFromClassFunction) { Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Sun Apr 19 14:09:19 2009 @@ -61,7 +61,7 @@ %UTF8*, %UTF8*, i8, i8*, i32, i8* } %JavaClassPrimitive = type { %JavaCommonClass, i32 } -%JavaClassArray = type { %JavaCommonClass, %JavaCommonClass*, %VT* } +%JavaClassArray = type { %JavaCommonClass, %JavaCommonClass* } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Constant calls for Jnjvm runtime internal objects field accesses ;;;;;;;;; @@ -82,6 +82,10 @@ ;;; getLock - Get the lock of an object. declare i8* @getLock(%JavaObject*) +;;; getVTFromCommonClass - Get the VT of a class from its runtime +;;; representation. +declare %VT* @getVTFromCommonClass(%JavaCommonClass*) readnone + ;;; getVTFromClass - Get the VT of a class from its runtime representation. declare %VT* @getVTFromClass(%JavaClass*) readnone @@ -93,6 +97,10 @@ ;;; representation. declare i32 @getObjectSizeFromClass(%JavaClass*) readnone +;;; getBaseClassVTFromVT - Get the VT of the base class of an array, or the +;;; VT of the array class of a regular class. +declare %VT* @getBaseClassVTFromVT(%VT*) readnone + ;;; getDisplay - Get the display array of this class. declare %JavaCommonClass** @getDisplay(%JavaCommonClass*) readnone @@ -169,17 +177,8 @@ ;;; overflows declare void @overflowThinLock(%JavaObject*) -;;; isAssignableFrom - Returns if the objet's class implements the given class. -declare i1 @instanceOf(%JavaObject*, %JavaCommonClass*) readnone - -;;; isAssignableFrom - Returns if the class implements the given class. -declare i1 @isAssignableFrom(%JavaCommonClass*, %JavaCommonClass*) readnone - -;;; implements - Returns if the class implements the given interface. -declare i1 @implements(%JavaCommonClass*, %JavaCommonClass*) readnone - -;;; instantiationOfArray - Returns if the class implements the given array. -declare i1 @instantiationOfArray(%JavaCommonClass*, %JavaCommonClass*) readnone +;;; isAssignableFrom - Returns if a type is a subtype of another type. +declare i1 @jnjvmIsAssignableFrom(%VT*, %VT*) readnone ;;; getClassDelegatee - Returns the java/lang/Class representation of the ;;; class. This method is lowered to the GEP to the class delegatee in @@ -212,6 +211,7 @@ declare %JavaObject* @indexOutOfBoundsException(%JavaObject*, i32) declare %JavaObject* @negativeArraySizeException(i32) declare %JavaObject* @outOfMemoryError(i32) +declare %JavaObject* @jnjvmArrayStoreException(%VT*) declare void @JavaThreadThrowException(%JavaObject*) declare void @jniProceedPendingException() Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll Sun Apr 19 14:09:19 2009 @@ -5,10 +5,11 @@ %Jnjvm = type { %VT*, %JavaClass*, [9 x %JavaClass*] } %JavaCommonClass = type { %JavaCommonClass**, i32, [32 x %JavaObject*], - i16, %JavaClass**, i16, %UTF8*, %JavaClass*, i8* } + i16, %JavaClass**, i16, %UTF8*, %JavaClass*, i8*, + %VT* } -%JavaClass = type { %JavaCommonClass, i32, %VT*, [32 x %TaskClassMirror], i8*, +%JavaClass = type { %JavaCommonClass, i32, [32 x %TaskClassMirror], i8*, %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*, i16, %JavaClass**, i16, %JavaClass*, i16, i8, i32, i32, i8*, Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll Sun Apr 19 14:09:19 2009 @@ -3,11 +3,11 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %JavaCommonClass = type { %JavaCommonClass**, i32, [1 x %JavaObject*], i16, - %JavaClass**, i16, %UTF8*, %JavaClass*, i8* } + %JavaClass**, i16, %UTF8*, %JavaClass*, i8*, %VT* } -%JavaClass = type { %JavaCommonClass, i32, %VT*, [1 x %TaskClassMirror], i8*, - %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, - %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*, +%JavaClass = type { %JavaCommonClass, i32, [1 x %TaskClassMirror], i8*, + %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, + %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*, i16, %JavaClass**, i16, %JavaClass*, i16, i8, i32, i32, i8*, void (i8*)* } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sun Apr 19 14:09:19 2009 @@ -253,6 +253,8 @@ display = (CommonClass**)loader->allocator.Allocate(sizeof(CommonClass*)); display[0] = this; depth = 0; + uint32 size = JavaVirtualTable::getBaseSize(); + virtualVT = new(loader->allocator, size) JavaVirtualTable(this); access = ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC | JNJVM_PRIMITIVE; primSize = nb; } @@ -290,7 +292,7 @@ interfaces = ClassArray::InterfacesArray; nbInterfaces = 2; - uint32 size = JavaVirtualTable::getNumMethods(); + uint32 size = JavaVirtualTable::getBaseSize(); virtualVT = new(loader->allocator, size) JavaVirtualTable(this); depth = 1; @@ -604,15 +606,43 @@ } bool UserCommonClass::isAssignableFrom(UserCommonClass* cl) { + bool res = false; if (this == cl) { - return true; + res = true; } else if (cl->isInterface()) { - return this->implements(cl); + res = this->implements(cl); } else if (cl->isArray()) { - return this->instantiationOfArray((UserClassArray*)cl); + res = this->instantiationOfArray((UserClassArray*)cl); } else { - return this->subclassOf(cl); + res = this->subclassOf(cl); } + if(virtualVT && cl->virtualVT && res != virtualVT->isSubtypeOf(cl->virtualVT)) { + fprintf(stderr, "wrong result for %s and %s\n", printString(), cl->printString()); + fprintf(stderr, "I have offset = %d\n", cl->virtualVT->offset); + fprintf(stderr, "I have secondary types = %d\n", virtualVT->nbSecondaryTypes); + fprintf(stderr, "I have secondary types = %s\n", virtualVT->secondaryTypes[0]->cl->printString()); + fprintf(stderr, "I have secondary types = %d\n", virtualVT->secondaryTypes[0]->cl->super->virtualVT->nbSecondaryTypes); + fprintf(stderr, "I have secondary types = %s\n", virtualVT->secondaryTypes[0]->cl->super->printString()); + fprintf(stderr, "I have secondary types = %d\n", virtualVT->secondaryTypes[0]->cl->nbInterfaces); + abort(); + } + return res; +} + +bool JavaVirtualTable::isSubtypeOf(JavaVirtualTable* otherVT) { + + if (otherVT == ((JavaVirtualTable**)this)[otherVT->offset]) return true; + else if (otherVT->offset != getCacheIndex()) return false; + else if (this == otherVT) return true; + else { + for (uint32 i = 0; i < nbSecondaryTypes; ++i) { + if (secondaryTypes[i] == otherVT) { + cache = otherVT; + return true; + } + } + } + return false; } void JavaField::InitField(void* obj, uint64 val) { @@ -730,11 +760,13 @@ allocator.Allocate(sizeof(CommonClass*) * (depth + 1)); memcpy(display, super->display, depth * sizeof(UserCommonClass*)); display[depth] = this; + virtualTableSize = super->virtualTableSize; } else { depth = 0; display = (CommonClass**) classLoader->allocator.Allocate(sizeof(CommonClass*)); display[0] = this; + virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); } uint16 nbI = reader.readU2(); @@ -753,12 +785,8 @@ } void UserClass::loadParents() { - if (super) { + if (super) super->resolveClass(); - virtualTableSize = super->virtualTableSize; - } else { - virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); - } for (unsigned i = 0; i < nbInterfaces; i++) interfaces[i]->resolveClass(); @@ -846,6 +874,38 @@ } } +void Class::makeVT() { + + for (uint32 i = 0; i < nbVirtualMethods; ++i) { + JavaMethod& meth = virtualMethods[i]; + if (meth.name->equals(classLoader->bootstrapLoader->finalize)) { + meth.offset = 0; + } else { + JavaMethod* parent = super? + super->lookupMethodDontThrow(meth.name, meth.type, false, true, 0) : + 0; + + uint64_t offset = 0; + if (!parent) { + offset = virtualTableSize++; + meth.offset = offset; + } else { + offset = parent->offset; + meth.offset = parent->offset; + } + } + } + + if (super) { + assert(virtualTableSize >= super->virtualTableSize && + "Size of virtual table less than super!"); + } + + mvm::BumpPtrAllocator& allocator = classLoader->allocator; + virtualVT = new(allocator, virtualTableSize) JavaVirtualTable(this); +} + + void Class::readMethods(Reader& reader) { uint16 nbMethods = reader.readU2(); virtualMethods = new(classLoader->allocator) JavaMethod[nbMethods]; @@ -901,6 +961,7 @@ readParents(reader); readFields(reader); readMethods(reader); + makeVT(); attributs = readAttributs(reader, nbAttributs); setIsRead(); } @@ -1258,13 +1319,12 @@ // Load base array classes that JnJVM internally uses. Now that the interfaces // have been loaded, the secondary type can be safely created. + upcalls->ArrayOfObject = + JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/Object;")); + upcalls->ArrayOfString = JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/String;")); - upcalls->ArrayOfObject = - JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/Object;")); - - // Update native array classes. A few things have not been set properly // when loading these classes because java.lang.Object and java.lang.Object[] // were not loaded yet. Correct that now by updating these classes. @@ -1295,10 +1355,6 @@ JavaVirtualTable::JavaVirtualTable(Class* C) { if (C->super) { - // Copy the super VT into the current VT. - uint32 size = C->super->virtualTableSize * sizeof(uintptr_t); - memcpy(this, C->super->virtualVT, size); - // Set the class of this VT. cl = C; @@ -1306,11 +1362,17 @@ JavaVirtualTable* superVT = C->super->virtualVT; depth = superVT->depth + 1; nbSecondaryTypes = superVT->nbSecondaryTypes + cl->nbInterfaces; + + for (uint32 i = 0; i < cl->nbInterfaces; ++i) { + nbSecondaryTypes += cl->interfaces[i]->virtualVT->nbSecondaryTypes; + } uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth; memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*)); uint32 outOfDepth = 0; - if (depth < getDisplayLength()) { + if (C->isInterface()) { + offset = getCacheIndex(); + } else if (depth < getDisplayLength()) { display[depth] = this; offset = getCacheIndex() + depth + 1; } else { @@ -1338,6 +1400,15 @@ uint32 index = superVT->nbSecondaryTypes + outOfDepth + i; secondaryTypes[index] = cur; } + + uint32 lastIndex = superVT->nbSecondaryTypes + cl->nbInterfaces + + outOfDepth; + + for (uint32 i = 0; i < cl->nbInterfaces; ++i) { + JavaVirtualTable* cur = cl->interfaces[i]->virtualVT; + memcpy(secondaryTypes + lastIndex, cur->secondaryTypes, + sizeof(JavaVirtualTable*) * cur->nbSecondaryTypes); + } } else { // Set the tracer, destructor and delete @@ -1361,11 +1432,16 @@ } JavaVirtualTable::JavaVirtualTable(ClassArray* C) { - + + baseClassVT = C->baseClass()->virtualVT; + assert(baseClassVT && "Not base VT when creating an array"); + if (!C->baseClass()->isPrimitive()) { // Copy the super VT into the current VT. - uint32 size = getNumMethods() * sizeof(uintptr_t); - memcpy(this, C->super->virtualVT, size); + uint32 size = (getBaseSize() - getFirstJavaMethodIndex()); + memcpy(this->getFirstJavaMethod(), + C->super->virtualVT->getFirstJavaMethod(), + size * sizeof(uintptr_t)); tracer = (uintptr_t)ArrayObjectTracer; // Set the class of this VT. @@ -1401,7 +1477,12 @@ uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth; memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*)); - if (depth < getDisplayLength()) display[depth] = this; + if (depth < getDisplayLength()) { + display[depth] = this; + offset = getCacheIndex() + depth + 1; + } else { + offset = getCacheIndex(); + } mvm::BumpPtrAllocator& allocator = JCL->allocator; @@ -1484,7 +1565,8 @@ depth = 1; display[0] = C->super->virtualVT; display[1] = this; - nbSecondaryTypes = 2; + offset = getCacheIndex() + 2; + nbSecondaryTypes = 2; mvm::BumpPtrAllocator& allocator = JCL->allocator; secondaryTypes = (JavaVirtualTable**) @@ -1510,6 +1592,7 @@ display[0] = 0; display[1] = this; nbSecondaryTypes = 2; + offset = getCacheIndex() + 2; // The list of secondary types has not been allocated yet by // java.lang.Object[]. The initialiseVT function will update the current @@ -1517,3 +1600,11 @@ } } + +JavaVirtualTable::JavaVirtualTable(ClassPrimitive* C) { + // Only used for subtype checking + depth = 0; + display[0] = this; + nbSecondaryTypes = 0; + offset = getCacheIndex() + 1; +} Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sun Apr 19 14:09:19 2009 @@ -187,6 +187,11 @@ /// classLoader - The Jnjvm class loader that loaded the class. /// JnjvmClassLoader* classLoader; + + /// virtualVT - The virtual table of instances of this class. + /// + JavaVirtualTable* virtualVT; + //===----------------------------------------------------------------------===// // @@ -454,10 +459,6 @@ /// uint32 virtualSize; - /// virtualVT - The virtual table of instances of this class. - /// - JavaVirtualTable* virtualVT; - /// IsolateInfo - Per isolate informations for static instances and /// initialization state. /// @@ -900,7 +901,13 @@ /// needsInitialisationCheck - Does the method need an initialisation check? /// bool needsInitialisationCheck(); - + +private: + + /// makeVT - Create the virtual table of this class. + /// + void makeVT(); + }; /// ClassArray - This class represents Java array classes. @@ -918,10 +925,6 @@ /// CommonClass* _baseClass; - /// virtualVT - The virtual table of this array class. - /// - JavaVirtualTable* virtualVT; - /// baseClass - Get the base class of this array class. /// CommonClass* baseClass() const { @@ -1339,16 +1342,52 @@ }; +/// JavaVirtualTable - This class is the virtual table of instances of +/// Java classes. Besides holding function pointers for virtual calls, +/// it contains a bunch of information useful for fast dynamic type checking. +/// These are placed here for fast access of information from a Java object +/// (that only points to the VT, not the class). +/// class JavaVirtualTable : public VirtualTable { public: + + /// cl - The class which defined this virtual table. + /// CommonClass* cl; + + /// depth - The super hierarchy depth of the class. + /// size_t depth; + + /// offset - Offset in the virtual table where this virtual + /// table may be pointed. The offset is the cache if the class + /// is an interface or depth is too big, or an offset in the display. + /// size_t offset; - size_t cache; + + /// cache - The cached result for better type checks on secondary types. + /// + JavaVirtualTable* cache; + + /// display - Array of super classes. + /// JavaVirtualTable* display[8]; + + /// nbSecondaryTypes - The length of the secondary type list. + /// size_t nbSecondaryTypes; + + /// secondaryTypes - The list of secondary types of this type. These + /// are the interface and all the supers whose depth is too big. + /// JavaVirtualTable** secondaryTypes; + /// baseClass - Holds the base class VT of an array, or the array class VT + /// of a regular class. + /// + JavaVirtualTable* baseClassVT; + + /// Java methods for the virtual table functions. uintptr_t init; uintptr_t equals; uintptr_t hashCode; @@ -1362,40 +1401,67 @@ uintptr_t waitMsNs; uintptr_t virtualMethods[1]; + /// operator new - Allocates a JavaVirtualTable with the given size. The + /// size must contain the additional information for type checking, as well + /// as the function pointers. + /// void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator, uint32 nbMethods) { return allocator.Allocate(sizeof(uintptr_t) * (nbMethods)); } + /// JavaVirtualTable - Create JavaVirtualTable objects for classes, array + /// classes and primitive classes. + /// JavaVirtualTable(Class* C); - JavaVirtualTable(ClassArray* C); + JavaVirtualTable(ClassPrimitive* C); + + /// getFirstJavaMethod - Get the byte offset of the first Java method + /// (). + /// uintptr_t* getFirstJavaMethod() { return &init; } + /// getFirstJavaMethodIndex - Get the word offset of the first Java method. + /// static uint32_t getFirstJavaMethodIndex() { - return 17; + return 18; } - static uint32_t getNumMethods() { - return 28; + /// getBaseSize - Get the size of the java.lang.Object virtual table. + /// + static uint32_t getBaseSize() { + return 29; } + /// getNumJavaMethods - Get the number of methods of the java.lang.Object + /// class. + /// static uint32_t getNumJavaMethods() { return 11; } + /// getDisplayLength - Get the length of the display (primary type) array. + /// static uint32_t getDisplayLength() { return 8; } -private: + /// getCacheIndex - Get the word offset of the type cache. + /// static uint32_t getCacheIndex() { return 6; } + /// isSubtypeOf - Returns true if the given VT is a subtype of the this + /// VT. + /// + bool isSubtypeOf(JavaVirtualTable* VT); + + }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Sun Apr 19 14:09:19 2009 @@ -409,24 +409,9 @@ } // Never throws. -extern "C" bool instanceOf(JavaObject* obj, UserCommonClass* cl) { - return obj->instanceOf(cl); -} - -// Never throws. -extern "C" bool instantiationOfArray(UserCommonClass* cl1, - UserClassArray* cl2) { - return cl1->instantiationOfArray(cl2); -} - -// Never throws. -extern "C" bool implements(UserCommonClass* cl1, UserCommonClass* cl2) { - return cl1->implements(cl2); -} - -// Never throws. -extern "C" bool isAssignableFrom(UserCommonClass* cl1, UserCommonClass* cl2) { - return cl1->isAssignableFrom(cl2); +extern "C" bool jnjvmIsAssignableFrom(JavaVirtualTable* VT1, + JavaVirtualTable* VT2) { + return VT1->isSubtypeOf(VT2); } // Does not call any Java code. @@ -542,22 +527,39 @@ return exc; } +// Creates a Java object and then throws it. +extern "C" JavaObject* jnjvmArrayStoreException(JavaVirtualTable* VT) { + JavaObject *exc = 0; + JavaThread *th = JavaThread::get(); + + BEGIN_NATIVE_EXCEPTION(1) + + exc = th->getJVM()->CreateArrayStoreException(VT); + + END_NATIVE_EXCEPTION + +#ifdef DWARF_EXCEPTIONS + th->throwException(exc); +#else + th->pendingException = exc; +#endif + + return exc; +} + extern "C" void printMethodStart(JavaMethod* meth) { - printf("[%p] executing %s\n", (void*)mvm::Thread::get(), + fprintf(stderr, "[%p] executing %s\n", (void*)mvm::Thread::get(), meth->printString()); - fflush(stdout); } extern "C" void printMethodEnd(JavaMethod* meth) { - printf("[%p] return from %s\n", (void*)mvm::Thread::get(), + fprintf(stderr, "[%p] return from %s\n", (void*)mvm::Thread::get(), meth->printString()); - fflush(stdout); } extern "C" void printExecution(uint32 opcode, uint32 index, JavaMethod* meth) { - printf("[%p] executing %s %s at %d\n", (void*)mvm::Thread::get(), + fprintf(stderr, "[%p] executing %s %s at %d\n", (void*)mvm::Thread::get(), meth->printString(), OpcodeNames[opcode], index); - fflush(stdout); } #ifdef SERVICE Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Apr 19 14:09:19 2009 @@ -325,6 +325,12 @@ "Java heap space"); } +JavaObject* Jnjvm::CreateArrayStoreException(JavaVirtualTable* VT) { + return CreateError(upcalls->ArrayStoreException, + upcalls->InitArrayStoreException, + VT->cl->printString()); +} + JavaObject* Jnjvm::CreateClassCastException(JavaObject* obj, UserCommonClass* cl) { return CreateError(upcalls->ClassCastException, Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=69533&r1=69532&r2=69533&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sun Apr 19 14:09:19 2009 @@ -252,6 +252,7 @@ JavaObject* CreateNegativeArraySizeException(); JavaObject* CreateClassCastException(JavaObject* obj, UserCommonClass* cl); JavaObject* CreateLinkageError(const char* msg = ""); + JavaObject* CreateArrayStoreException(JavaVirtualTable* VT); /// Exceptions - These are the only exceptions VMKit will make. /// From nicolas.geoffray at lip6.fr Sun Apr 19 12:28:34 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 19 Apr 2009 19:28:34 -0000 Subject: [vmkit-commits] [vmkit] r69535 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaClass.cpp JavaClass.h Message-ID: <200904191928.n3JJSY2I019865@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 19 14:28:34 2009 New Revision: 69535 URL: http://llvm.org/viewvc/llvm-project?rev=69535&view=rev Log: This was supposed to get in in the previous commit. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69535&r1=69534&r2=69535&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sun Apr 19 14:28:34 2009 @@ -565,68 +565,9 @@ } } -bool UserCommonClass::implements(UserCommonClass* cl) { - if (this == cl) return true; - else { - for (uint16 i = 0; i < nbInterfaces; ++i) { - Class* I = interfaces[i]; - if (I == cl) return true; - else if (I->implements(cl)) return true; - } - if (super) { - return super->implements(cl); - } - } - return false; -} - -bool UserCommonClass::instantiationOfArray(UserClassArray* cl) { - if (this == cl) return true; - else { - if (isArray()) { - UserCommonClass* baseThis = ((UserClassArray*)this)->baseClass(); - UserCommonClass* baseCl = ((UserClassArray*)cl)->baseClass(); - - if (baseThis->isInterface() && baseCl->isInterface()) { - return baseThis->implements(baseCl); - } else { - return baseThis->isAssignableFrom(baseCl); - } - } - } - return false; -} - -bool UserCommonClass::subclassOf(UserCommonClass* cl) { - if (cl->depth <= depth) { - return display[cl->depth] == cl; - } else { - return false; - } -} - bool UserCommonClass::isAssignableFrom(UserCommonClass* cl) { - bool res = false; - if (this == cl) { - res = true; - } else if (cl->isInterface()) { - res = this->implements(cl); - } else if (cl->isArray()) { - res = this->instantiationOfArray((UserClassArray*)cl); - } else { - res = this->subclassOf(cl); - } - if(virtualVT && cl->virtualVT && res != virtualVT->isSubtypeOf(cl->virtualVT)) { - fprintf(stderr, "wrong result for %s and %s\n", printString(), cl->printString()); - fprintf(stderr, "I have offset = %d\n", cl->virtualVT->offset); - fprintf(stderr, "I have secondary types = %d\n", virtualVT->nbSecondaryTypes); - fprintf(stderr, "I have secondary types = %s\n", virtualVT->secondaryTypes[0]->cl->printString()); - fprintf(stderr, "I have secondary types = %d\n", virtualVT->secondaryTypes[0]->cl->super->virtualVT->nbSecondaryTypes); - fprintf(stderr, "I have secondary types = %s\n", virtualVT->secondaryTypes[0]->cl->super->printString()); - fprintf(stderr, "I have secondary types = %d\n", virtualVT->secondaryTypes[0]->cl->nbInterfaces); - abort(); - } - return res; + assert(virtualVT && cl->virtualVT); + return virtualVT->isSubtypeOf(cl->virtualVT); } bool JavaVirtualTable::isSubtypeOf(JavaVirtualTable* otherVT) { Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69535&r1=69534&r2=69535&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sun Apr 19 14:28:34 2009 @@ -302,21 +302,6 @@ /// bool isOfTypeName(Jnjvm* vm, const UTF8* Tname); - /// implements - Does this class implement the given class? Returns true if - /// the class is in the interface class hierarchy. - /// - bool implements(CommonClass* cl); - - /// instantationOfArray - If this class is an array class, does its subclass - /// implements the given array class subclass? - /// - bool instantiationOfArray(ClassArray* cl); - - /// subclassOf - If this class is a regular class, is it a subclass of the - /// given class? - /// - bool subclassOf(CommonClass* cl); - /// isAssignableFrom - Is this class assignable from the given class? The /// classes may be of any type. /// From nicolas.geoffray at lip6.fr Mon Apr 20 04:45:20 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 11:45:20 -0000 Subject: [vmkit-commits] [vmkit] r69588 - /vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Message-ID: <200904201145.n3KBjLEl026635@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 06:45:18 2009 New Revision: 69588 URL: http://llvm.org/viewvc/llvm-project?rev=69588&view=rev Log: Remove trailing whitespaces. Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp?rev=69588&r1=69587&r2=69588&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Mon Apr 20 06:45:18 2009 @@ -261,7 +261,7 @@ CI->eraseFromParent(); } else if (V == module->GetDisplayFunction) { Changed = true; - Value* val = Call.getArgument(0); + Value* val = Call.getArgument(0); Value* indexes[2] = { module->constantZero, module->OffsetDisplayInClassConstant }; Value* DisplayPtr = GetElementPtrInst::Create(val, indexes, @@ -271,8 +271,8 @@ CI->eraseFromParent(); } else if (V == module->GetClassInDisplayFunction) { Changed = true; - Value* val = Call.getArgument(0); - Value* depth = Call.getArgument(1); + Value* val = Call.getArgument(0); + Value* depth = Call.getArgument(1); Value* ClassPtr = GetElementPtrInst::Create(val, depth, "", CI); Value* Class = new LoadInst(ClassPtr, "", CI); CI->replaceAllUsesWith(Class); From nicolas.geoffray at lip6.fr Mon Apr 20 04:46:29 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 11:46:29 -0000 Subject: [vmkit-commits] [vmkit] r69589 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904201146.n3KBkTVr026724@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 06:46:28 2009 New Revision: 69589 URL: http://llvm.org/viewvc/llvm-project?rev=69589&view=rev Log: Don't forget to set the class of a virtual table for native classes. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69589&r1=69588&r2=69589&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Apr 20 06:46:28 2009 @@ -1544,6 +1544,7 @@ JavaVirtualTable::JavaVirtualTable(ClassPrimitive* C) { // Only used for subtype checking + cl = C; depth = 0; display[0] = this; nbSecondaryTypes = 0; From nicolas.geoffray at lip6.fr Mon Apr 20 05:14:49 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 12:14:49 -0000 Subject: [vmkit-commits] [vmkit] r69590 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904201214.n3KCEwuP028785@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 07:14:24 2009 New Revision: 69590 URL: http://llvm.org/viewvc/llvm-project?rev=69590&view=rev Log: Adjust lastIndex when filling the secondaryTypes list. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69590&r1=69589&r2=69590&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Apr 20 07:14:24 2009 @@ -1349,6 +1349,7 @@ JavaVirtualTable* cur = cl->interfaces[i]->virtualVT; memcpy(secondaryTypes + lastIndex, cur->secondaryTypes, sizeof(JavaVirtualTable*) * cur->nbSecondaryTypes); + lastIndex += cur->nbSecondaryTypes; } } else { From nicolas.geoffray at lip6.fr Mon Apr 20 05:17:06 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 12:17:06 -0000 Subject: [vmkit-commits] [vmkit] r69591 - /vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904201217.n3KCH73Z028974@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 07:17:06 2009 New Revision: 69591 URL: http://llvm.org/viewvc/llvm-project?rev=69591&view=rev Log: Bugfixes when generating a VT. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69591&r1=69590&r2=69591&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Mon Apr 20 07:17:06 2009 @@ -303,7 +303,7 @@ LCI->getVirtualType(); size = classDef->asClass()->virtualTableSize; } else { - size = classDef->super->virtualTableSize; + size = JavaVirtualTable::getBaseSize(); } llvm::Constant* res = 0; virtual_table_iterator End = virtualTables.end(); @@ -1142,10 +1142,11 @@ Constant* JavaAOTCompiler::CreateConstantFromVT(JavaVirtualTable* VT) { CommonClass* classDef = VT->cl; - uint32 size = classDef->isArray() ? classDef->super->virtualTableSize : - classDef->asClass()->virtualTableSize; - JavaVirtualTable* RealVT = classDef->isArray() ? classDef->super->virtualVT : - VT; + uint32 size = classDef->isClass() ? classDef->asClass()->virtualTableSize : + JavaVirtualTable::getBaseSize(); + JavaVirtualTable* RealVT = classDef->isClass() ? + VT : ClassArray::SuperArray->virtualVT; + const ArrayType* ATy = dyn_cast(JnjvmModule::VTType->getContainedType(0)); const PointerType* PTy = dyn_cast(ATy->getContainedType(0)); @@ -1176,7 +1177,7 @@ } else { Tracer = JavaIntrinsics.ArrayObjectTracerFunction; } - } else { + } else if (classDef->isClass()) { Tracer = makeTracer(classDef->asClass(), false); } @@ -1222,6 +1223,7 @@ std::vector TempElmts; for (uint32 i = 0; i < VT->nbSecondaryTypes; ++i) { + assert(VT->secondaryTypes[i] && "No secondary type"); Constant* Cl = getVirtualTable(VT->secondaryTypes[i]); TempElmts.push_back(Cl); } From nicolas.geoffray at lip6.fr Mon Apr 20 06:22:44 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 13:22:44 -0000 Subject: [vmkit-commits] [vmkit] r69592 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904201322.n3KDMjXT031176@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 08:22:41 2009 New Revision: 69592 URL: http://llvm.org/viewvc/llvm-project?rev=69592&view=rev Log: Interface arrays always are secondary types. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69592&r1=69591&r2=69592&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Apr 20 08:22:41 2009 @@ -1402,6 +1402,7 @@ } bool newSecondaryTypes = false; + bool intf = temp->isInterface(); if (temp->isPrimitive()) { --dim; temp = C->super; @@ -1419,7 +1420,7 @@ uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth; memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*)); - if (depth < getDisplayLength()) { + if (depth < getDisplayLength() && !intf) { display[depth] = this; offset = getCacheIndex() + depth + 1; } else { From nicolas.geoffray at lip6.fr Mon Apr 20 06:50:29 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 13:50:29 -0000 Subject: [vmkit-commits] [vmkit] r69593 - in /vmkit/trunk/lib/JnJVM/VMCore: Jnjvm.cpp JnjvmClassLoader.cpp Message-ID: <200904201350.n3KDoXLG031984@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 08:50:08 2009 New Revision: 69593 URL: http://llvm.org/viewvc/llvm-project?rev=69593&view=rev Log: Remove casting by giving correct types to locals. Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69593&r1=69592&r2=69593&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon Apr 20 08:50:08 2009 @@ -518,7 +518,7 @@ } extern "C" int sys_strnstr(const char *haystack, const char *needle) { - char * res = (char*)strstr(haystack, needle); + const char* res = strstr(haystack, needle); if (res) return res - haystack; else return -1; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=69593&r1=69592&r2=69593&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Mon Apr 20 08:50:08 2009 @@ -996,7 +996,7 @@ const char* file) { char* soName = (char*)alloca(strlen(name) + strlen(DYLD_EXTENSION)); - char* ptr = (char*)strrchr(name, '/'); + const char* ptr = strrchr(name, '/'); sprintf(soName, "%s%s", ptr ? ptr + 1 : name, DYLD_EXTENSION); void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL); if (handle) { From nicolas.geoffray at lip6.fr Mon Apr 20 09:24:02 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 16:24:02 -0000 Subject: [vmkit-commits] [vmkit] r69600 - /vmkit/trunk/include/mvm/Threads/Locks.h Message-ID: <200904201624.n3KGO2Vv004926@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 11:24:01 2009 New Revision: 69600 URL: http://llvm.org/viewvc/llvm-project?rev=69600&view=rev Log: Fix casting to size_t instead of uint32 for a pointer. Modified: vmkit/trunk/include/mvm/Threads/Locks.h Modified: vmkit/trunk/include/mvm/Threads/Locks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Locks.h?rev=69600&r1=69599&r2=69600&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Locks.h (original) +++ vmkit/trunk/include/mvm/Threads/Locks.h Mon Apr 20 11:24:01 2009 @@ -185,7 +185,7 @@ TFatLock* changeToFatlock(Owner* O) { if (!(lock & FatMask)) { TFatLock* obj = TFatLock::allocate(O); - uint32 val = (((uint32) obj) >> 1) | FatMask; + size_t val = (((size_t) obj) >> 1) | FatMask; uint32 count = lock & 0xFF; obj->acquireAll(count + 1); lock = val; From nicolas.geoffray at lip6.fr Mon Apr 20 09:24:19 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 16:24:19 -0000 Subject: [vmkit-commits] [vmkit] r69601 - /vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Message-ID: <200904201624.n3KGOJej004947@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 11:24:18 2009 New Revision: 69601 URL: http://llvm.org/viewvc/llvm-project?rev=69601&view=rev Log: Remove compilation warning. Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=69601&r1=69600&r2=69601&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Mon Apr 20 11:24:18 2009 @@ -93,8 +93,6 @@ fields.push_back(LAI.llvmType); } - JavaLLVMCompiler* Mod = - (JavaLLVMCompiler*)cl->classLoader->getCompiler(); StructType* structType = StructType::get(fields, false); staticType = PointerType::getUnqual(structType); const TargetData* targetData = JnjvmModule::TheTargetData; @@ -108,6 +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) From nicolas.geoffray at lip6.fr Mon Apr 20 09:33:14 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 16:33:14 -0000 Subject: [vmkit-commits] [vmkit] r69603 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Message-ID: <200904201633.n3KGXEOl005375@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 11:33:13 2009 New Revision: 69603 URL: http://llvm.org/viewvc/llvm-project?rev=69603&view=rev Log: Set the correct constant type in monitorEnter. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=69603&r1=69602&r2=69603&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Mon Apr 20 11:33:13 2009 @@ -424,7 +424,7 @@ // The compare and swap did not pass, look if it's a thin lock Value* isThin = BinaryOperator::CreateAnd(atomic, module->constantFatMask, "", currentBlock); - cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantZero, "", + cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantPtrZero, "", currentBlock); BranchInst::Create(ThinLockBB, FatLockBB, cmp, currentBlock); From nicolas.geoffray at lip6.fr Mon Apr 20 09:47:57 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 20 Apr 2009 16:47:57 -0000 Subject: [vmkit-commits] [vmkit] r69604 - /vmkit/trunk/include/mvm/Allocator.h Message-ID: <200904201647.n3KGlvPX006045@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 20 11:47:57 2009 New Revision: 69604 URL: http://llvm.org/viewvc/llvm-project?rev=69604&view=rev Log: Don't use the bump pointer when being with Boehm. Modified: vmkit/trunk/include/mvm/Allocator.h Modified: vmkit/trunk/include/mvm/Allocator.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Allocator.h?rev=69604&r1=69603&r2=69604&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Allocator.h (original) +++ vmkit/trunk/include/mvm/Allocator.h Mon Apr 20 11:47:57 2009 @@ -68,11 +68,15 @@ llvm::BumpPtrAllocator Allocator; public: void* Allocate(size_t sz) { +#ifdef USE_GC_BOEHM + return GC_MALLOC(sz); +#else TheLock.acquire(); void* res = Allocator.Allocate(sz, sizeof(void*)); TheLock.release(); memset(res, 0, sz); return res; +#endif } void Deallocate(void* obj) {} From nicolas.geoffray at lip6.fr Tue Apr 21 00:46:20 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 21 Apr 2009 07:46:20 -0000 Subject: [vmkit-commits] [vmkit] r69671 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Message-ID: <200904210746.n3L7kLpL007439@zion.cs.uiuc.edu> Author: geoffray Date: Tue Apr 21 02:46:20 2009 New Revision: 69671 URL: http://llvm.org/viewvc/llvm-project?rev=69671&view=rev Log: Interfaces are not initialized by classes that implement them. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=69671&r1=69670&r2=69671&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Tue Apr 21 02:46:20 2009 @@ -49,7 +49,8 @@ return true; #else - if (cl->isReadyForCompilation() || compilingClass->isAssignableFrom(cl)) { + if (cl->isReadyForCompilation() || + (!cl->isInterface() && compilingClass->isAssignableFrom(cl))) { return false; } From nicolas.geoffray at lip6.fr Thu Apr 23 00:45:45 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 07:45:45 -0000 Subject: [vmkit-commits] [vmkit] r69876 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/ExceptionsCheck.inc lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/Compiler/LowerConstantCalls.cpp lib/JnJVM/LLVMRuntime/runtime-default.ll lib/JnJVM/LLVMRuntime/runtime-isolate.ll lib/JnJVM/LLVMRuntime/runtime-single.ll lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaClass.h Message-ID: <200904230745.n3N7jl7P021243@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 02:45:45 2009 New Revision: 69876 URL: http://llvm.org/viewvc/llvm-project?rev=69876&view=rev Log: Remove unused fields in CommonClass. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Thu Apr 23 02:45:45 2009 @@ -255,10 +255,11 @@ llvm::Function* VirtualLookupFunction; #endif llvm::Function* IsAssignableFromFunction; + llvm::Function* IsSecondaryClassFunction; llvm::Function* GetDepthFunction; - llvm::Function* GetClassInDisplayFunction; - llvm::Function* GetStaticInstanceFunction; llvm::Function* GetDisplayFunction; + llvm::Function* GetVTInDisplayFunction; + llvm::Function* GetStaticInstanceFunction; llvm::Function* AquireObjectFunction; llvm::Function* ReleaseObjectFunction; llvm::Function* GetConstantPoolAtFunction; @@ -308,8 +309,6 @@ static llvm::ConstantInt* OffsetObjectSizeInClassConstant; static llvm::ConstantInt* OffsetVTInClassConstant; - static llvm::ConstantInt* OffsetDepthInClassConstant; - static llvm::ConstantInt* OffsetDisplayInClassConstant; static llvm::ConstantInt* OffsetTaskClassMirrorInClassConstant; static llvm::ConstantInt* OffsetStaticInstanceInTaskClassMirrorConstant; static llvm::ConstantInt* OffsetInitializedInTaskClassMirrorConstant; Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc (original) +++ vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc Thu Apr 23 02:45:45 2009 @@ -377,21 +377,10 @@ currentBlock = cur->tester; - Value* clVar = 0; -#ifdef ISOLATE_SHARING - // We're dealing with exceptions, don't catch the exception if the class can - // not be found. - if (cur->catche) clVar = getResolvedClass(cur->catche, false, false, 0); - else clVar = CallInst::Create(module->GetJnjvmExceptionClassFunction, - isolateLocal, "", currentBlock); -#else - // We know catchClass exists because we have loaded all exceptions catched - // by the method when we loaded the class that defined this method. - clVar = TheCompiler->getNativeClass(cur->catchClass); -#endif - if (clVar->getType() != module->JavaCommonClassType) - clVar = new BitCastInst(clVar, module->JavaCommonClassType, "", - currentBlock); + assert(cur->catchClass && + "Class not loaded when reading the exception table"); + + Value* VTVar = TheCompiler->getVirtualTable(cur->catchClass->virtualVT); #ifdef SERVICE @@ -425,38 +414,30 @@ #endif // Get the Java exception. - Value* obj = currentBlock->begin(); + Value* obj = currentBlock->begin(); - Value* objCl = CallInst::Create(module->GetClassFunction, obj, "", + Value* objVT = CallInst::Create(module->GetVTFunction, obj, "", currentBlock); - Value* depthCl = ConstantInt::get(Type::Int32Ty, cur->catchClass->depth); - Value* depthClObj = CallInst::Create(module->GetDepthFunction, objCl, "", - currentBlock); - - // Compare the exception with the exception class we catch. - Value* cmp = new ICmpInst(ICmpInst::ICMP_ULE, depthCl, depthClObj, "", - currentBlock); - - BasicBlock* supDepth = createBasicBlock("superior depth"); + uint32 depth = cur->catchClass->virtualVT->depth; + Value* depthCl = ConstantInt::get(Type::Int32Ty, depth); + + if (depth >= JavaVirtualTable::getDisplayLength()) { + assert(0 && "Implement me"); + } - // Add the Java exception in the phi node of the next block. - if (javaNode) - javaNode->addIncoming(obj, currentBlock); - BranchInst::Create(supDepth, bbNext, cmp, currentBlock); - currentBlock = supDepth; Value* inDisplay = CallInst::Create(module->GetDisplayFunction, - objCl, "", currentBlock); + objVT, "", currentBlock); Value* displayArgs[2] = { inDisplay, depthCl }; - Value* clInDisplay = CallInst::Create(module->GetClassInDisplayFunction, + Value* VTInDisplay = CallInst::Create(module->GetVTInDisplayFunction, displayArgs, displayArgs + 2, "", currentBlock); - cmp = new ICmpInst(ICmpInst::ICMP_EQ, clInDisplay, clVar, "", - currentBlock); + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, VTInDisplay, VTVar, "", + currentBlock); // Add the Java exception in the phi node of the handler. Instruction* insn = cur->javaHandler->begin(); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Thu Apr 23 02:45:45 2009 @@ -448,11 +448,11 @@ // JavaObject Constant* CurConstant = CreateConstantForBaseObject(obj->getClass()); - for (uint32 j = 0; j <= cl->depth; ++j) { + for (uint32 j = 0; j <= cl->virtualVT->depth; ++j) { std::vector TempElts; Elmts.push_back(CurConstant); TempElts.push_back(CurConstant); - Class* curCl = cl->display[j]->asClass(); + Class* curCl = cl->virtualVT->display[j]->cl->asClass(); LLVMClassInfo* LCI = getClassInfo(curCl); const StructType* STy = dyn_cast(LCI->getVirtualType()->getContainedType(0)); @@ -584,39 +584,14 @@ Constant* JavaAOTCompiler::CreateConstantFromCommonClass(CommonClass* cl) { const StructType* STy = dyn_cast(JnjvmModule::JavaCommonClassType->getContainedType(0)); - - const ArrayType* ATy = ArrayType::get(JnjvmModule::JavaCommonClassType, - cl->depth + 1); + const llvm::Type* TempTy = 0; + std::vector CommonClassElts; std::vector TempElmts; - Constant* ClGEPs[2] = { JnjvmModule::constantZero, - JnjvmModule::constantZero }; - - // display - for (uint32 i = 0; i <= cl->depth; ++i) { - Constant* Cl = getNativeClass(cl->display[i]); - if (Cl->getType() != JnjvmModule::JavaCommonClassType) - Cl = ConstantExpr::getGetElementPtr(Cl, ClGEPs, 2); - - TempElmts.push_back(Cl); - } - - Constant* display = ConstantArray::get(ATy, TempElmts); - TempElmts.clear(); - display = new GlobalVariable(ATy, true, GlobalValue::InternalLinkage, - display, "", getLLVMModule()); - const llvm::Type* TempTy = JnjvmModule::JavaCommonClassType; - display = ConstantExpr::getCast(Instruction::BitCast, display, - PointerType::getUnqual(TempTy)); - CommonClassElts.push_back(display); - - // depth - CommonClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->depth)); - // delegatee - ATy = dyn_cast(STy->getContainedType(2)); + const ArrayType* ATy = dyn_cast(STy->getContainedType(2)); assert(ATy && "Malformed type"); Constant* TCM[1] = { getJavaClass(cl) }; Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Apr 23 02:45:45 2009 @@ -62,8 +62,6 @@ llvm::Constant* JnjvmModule::JavaArraySizeConstant; llvm::ConstantInt* JnjvmModule::OffsetObjectSizeInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetVTInClassConstant; -llvm::ConstantInt* JnjvmModule::OffsetDepthInClassConstant; -llvm::ConstantInt* JnjvmModule::OffsetDisplayInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetTaskClassMirrorInClassConstant; llvm::ConstantInt* JnjvmModule::OffsetStaticInstanceInTaskClassMirrorConstant; llvm::ConstantInt* JnjvmModule::OffsetStatusInTaskClassMirrorConstant; @@ -281,14 +279,11 @@ JavaObjectVTOffsetConstant = mvm::MvmModule::constantZero; OffsetClassInVTConstant = mvm::MvmModule::constantThree; OffsetDepthInVTConstant = mvm::MvmModule::constantFour; - OffsetDisplayInVTConstant = mvm::MvmModule::constantFive; + OffsetDisplayInVTConstant = mvm::MvmModule::constantSeven; OffsetBaseClassVTInVTConstant = ConstantInt::get(Type::Int32Ty, 17); - OffsetDisplayInClassConstant = mvm::MvmModule::constantZero; - OffsetDepthInClassConstant = mvm::MvmModule::constantOne; - OffsetObjectSizeInClassConstant = mvm::MvmModule::constantOne; - OffsetVTInClassConstant = ConstantInt::get(Type::Int32Ty, 9); + OffsetVTInClassConstant = ConstantInt::get(Type::Int32Ty, 7); OffsetTaskClassMirrorInClassConstant = mvm::MvmModule::constantTwo; OffsetStaticInstanceInTaskClassMirrorConstant = mvm::MvmModule::constantTwo; OffsetStatusInTaskClassMirrorConstant = mvm::MvmModule::constantZero; @@ -355,10 +350,11 @@ GetClassDelegateeFunction = module->getFunction("getClassDelegatee"); RuntimeDelegateeFunction = module->getFunction("jnjvmRuntimeDelegatee"); IsAssignableFromFunction = module->getFunction("jnjvmIsAssignableFrom"); + IsSecondaryClassFunction = module->getFunction("isSecondaryClass"); GetDepthFunction = module->getFunction("getDepth"); GetStaticInstanceFunction = module->getFunction("getStaticInstance"); GetDisplayFunction = module->getFunction("getDisplay"); - GetClassInDisplayFunction = module->getFunction("getClassInDisplay"); + GetVTInDisplayFunction = module->getFunction("getVTInDisplay"); AquireObjectFunction = module->getFunction("JavaObjectAquire"); ReleaseObjectFunction = module->getFunction("JavaObjectRelease"); OverflowThinLockFunction = module->getFunction("overflowThinLock"); Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Thu Apr 23 02:45:45 2009 @@ -102,7 +102,7 @@ static Value* getDelegatee(JnjvmModule* module, Value* Arg, Instruction* CI) { Value* GEP[2] = { module->constantZero, - module->constantTwo }; + module->constantZero }; Value* TCMArray = GetElementPtrInst::Create(Arg, GEP, GEP + 2, "", CI); Value* GEP2[2] = { module->constantZero, module->constantZero }; @@ -253,23 +253,25 @@ Changed = true; Value* val = Call.getArgument(0); Value* indexes[2] = { module->constantZero, - module->OffsetDepthInClassConstant }; + module->OffsetDepthInVTConstant }; Value* DepthPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, "", CI); Value* Depth = new LoadInst(DepthPtr, "", CI); + Depth = new PtrToIntInst(Depth, Type::Int32Ty, "", CI); CI->replaceAllUsesWith(Depth); CI->eraseFromParent(); } else if (V == module->GetDisplayFunction) { Changed = true; Value* val = Call.getArgument(0); Value* indexes[2] = { module->constantZero, - module->OffsetDisplayInClassConstant }; + module->OffsetDisplayInVTConstant }; Value* DisplayPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, "", CI); - Value* Display = new LoadInst(DisplayPtr, "", CI); - CI->replaceAllUsesWith(Display); + const llvm::Type* Ty = PointerType::getUnqual(module->VTType); + DisplayPtr = new BitCastInst(DisplayPtr, Ty, "", CI); + CI->replaceAllUsesWith(DisplayPtr); CI->eraseFromParent(); - } else if (V == module->GetClassInDisplayFunction) { + } else if (V == module->GetVTInDisplayFunction) { Changed = true; Value* val = Call.getArgument(0); Value* depth = Call.getArgument(1); @@ -521,6 +523,19 @@ Value* res = new LoadInst(val, "", CI); CI->replaceAllUsesWith(res); CI->eraseFromParent(); + } else if (V == module->IsSecondaryClassFunction) { + Changed = true; + Value* VT1 = Call.getArgument(0); + Value* VT2 = Call.getArgument(0); + + Value* args[2] = { VT1, VT2 }; + CallInst* res = CallInst::Create(module->IsAssignableFromFunction, + args, args + 2, "", CI); + CI->replaceAllUsesWith(res); + CI->eraseFromParent(); + + + break; } #ifdef ISOLATE_SHARING else if (V == module->GetCtpClassFunction) { Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Thu Apr 23 02:45:45 2009 @@ -101,14 +101,14 @@ ;;; VT of the array class of a regular class. declare %VT* @getBaseClassVTFromVT(%VT*) readnone -;;; getDisplay - Get the display array of this class. -declare %JavaCommonClass** @getDisplay(%JavaCommonClass*) readnone +;;; getDisplay - Get the display array of this VT. +declare %VT** @getDisplay(%VT*) readnone -;;; getClassInDisplay - Get the super class at the given offset. -declare %JavaCommonClass* @getClassInDisplay(%JavaCommonClass**, i32) readnone +;;; getVTInDisplay - Get the super class at the given offset. +declare %VT* @getVTInDisplay(%VT**, i32) readnone -;;; getDepth - Get the depth of the class. -declare i32 @getDepth(%JavaCommonClass*) readnone +;;; getDepth - Get the depth of the VT. +declare i32 @getDepth(%VT*) readnone ;;; getStaticInstance - Get the static instance of this class. declare i8* @getStaticInstance(%JavaClass*) readnone @@ -180,6 +180,10 @@ ;;; isAssignableFrom - Returns if a type is a subtype of another type. declare i1 @jnjvmIsAssignableFrom(%VT*, %VT*) readnone +;;; isAssignableFrom - Returns if a type is a secondary super type of +;;; another type. +declare i1 @isSecondaryClass(%VT*, %VT*) readnone + ;;; getClassDelegatee - Returns the java/lang/Class representation of the ;;; class. This method is lowered to the GEP to the class delegatee in ;;; the common class. Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll Thu Apr 23 02:45:45 2009 @@ -4,7 +4,7 @@ %Jnjvm = type { %VT*, %JavaClass*, [9 x %JavaClass*] } -%JavaCommonClass = type { %JavaCommonClass**, i32, [32 x %JavaObject*], +%JavaCommonClass = type { [32 x %JavaObject*], i16, %JavaClass**, i16, %UTF8*, %JavaClass*, i8*, %VT* } Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll Thu Apr 23 02:45:45 2009 @@ -2,7 +2,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;; Isolate specific types ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -%JavaCommonClass = type { %JavaCommonClass**, i32, [1 x %JavaObject*], i16, +%JavaCommonClass = type { [1 x %JavaObject*], i16, %JavaClass**, i16, %UTF8*, %JavaClass*, i8*, %VT* } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Apr 23 02:45:45 2009 @@ -81,7 +81,6 @@ } CommonClass::~CommonClass() { - classLoader->allocator.Deallocate(display); } Class::~Class() { @@ -250,9 +249,6 @@ uint32 nb) : CommonClass(loader, n) { - display = (CommonClass**)loader->allocator.Allocate(sizeof(CommonClass*)); - display[0] = this; - depth = 0; uint32 size = JavaVirtualTable::getBaseSize(); virtualVT = new(loader->allocator, size) JavaVirtualTable(this); access = ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC | JNJVM_PRIMITIVE; @@ -268,7 +264,6 @@ JInfo = 0; outerClass = 0; innerOuterResolved = false; - display = 0; nbInnerClasses = 0; staticTracer = 0; nbVirtualMethods = 0; @@ -295,10 +290,6 @@ uint32 size = JavaVirtualTable::getBaseSize(); virtualVT = new(loader->allocator, size) JavaVirtualTable(this); - depth = 1; - display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*)); - display[0] = ClassArray::SuperArray; - display[1] = this; access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC | JNJVM_ARRAY; } @@ -695,18 +686,8 @@ if (superEntry) { const UTF8* superUTF8 = ctpInfo->resolveClassName(superEntry); super = classLoader->loadName(superUTF8, false, true); - depth = super->depth + 1; - mvm::BumpPtrAllocator& allocator = classLoader->allocator; - display = (CommonClass**) - allocator.Allocate(sizeof(CommonClass*) * (depth + 1)); - memcpy(display, super->display, depth * sizeof(UserCommonClass*)); - display[depth] = this; virtualTableSize = super->virtualTableSize; } else { - depth = 0; - display = (CommonClass**) - classLoader->allocator.Allocate(sizeof(CommonClass*)); - display[0] = this; virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex(); } @@ -1274,8 +1255,6 @@ javaLangObject->virtualVT->getFirstJavaMethod(), \ sizeof(uintptr_t) * JavaVirtualTable::getNumJavaMethods()); \ CLASS->super = javaLangObject; \ - CLASS->display[0] = javaLangObject; \ - CLASS->display[1] = CLASS; \ CLASS->virtualVT->display[0] = javaLangObject->virtualVT; \ CLASS->virtualVT->secondaryTypes = \ upcalls->ArrayOfObject->virtualVT->secondaryTypes; \ Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69876&r1=69875&r2=69876&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Apr 23 02:45:45 2009 @@ -57,6 +57,141 @@ #define ready 6 /// The class is ready to be used. #define erroneous 7 /// The class is in an erroneous state. +/// JavaVirtualTable - This class is the virtual table of instances of +/// Java classes. Besides holding function pointers for virtual calls, +/// it contains a bunch of information useful for fast dynamic type checking. +/// These are placed here for fast access of information from a Java object +/// (that only points to the VT, not the class). +/// +class JavaVirtualTable : public VirtualTable { +public: + + /// cl - The class which defined this virtual table. + /// + CommonClass* cl; + + /// depth - The super hierarchy depth of the class. + /// + size_t depth; + + /// offset - Offset in the virtual table where this virtual + /// table may be pointed. The offset is the cache if the class + /// is an interface or depth is too big, or an offset in the display. + /// + size_t offset; + + /// cache - The cached result for better type checks on secondary types. + /// + JavaVirtualTable* cache; + + /// display - Array of super classes. + /// + JavaVirtualTable* display[8]; + + /// nbSecondaryTypes - The length of the secondary type list. + /// + size_t nbSecondaryTypes; + + /// secondaryTypes - The list of secondary types of this type. These + /// are the interface and all the supers whose depth is too big. + /// + JavaVirtualTable** secondaryTypes; + + /// baseClass - Holds the base class VT of an array, or the array class VT + /// of a regular class. + /// + JavaVirtualTable* baseClassVT; + + /// Java methods for the virtual table functions. + uintptr_t init; + uintptr_t equals; + uintptr_t hashCode; + uintptr_t toString; + uintptr_t clone; + uintptr_t getClass; + uintptr_t notify; + uintptr_t notifyAll; + uintptr_t waitIndefinitely; + uintptr_t waitMs; + uintptr_t waitMsNs; + uintptr_t virtualMethods[1]; + + /// operator new - Allocates a JavaVirtualTable with the given size. The + /// size must contain the additional information for type checking, as well + /// as the function pointers. + /// + void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator, + uint32 nbMethods) { + return allocator.Allocate(sizeof(uintptr_t) * (nbMethods)); + } + + /// JavaVirtualTable - Create JavaVirtualTable objects for classes, array + /// classes and primitive classes. + /// + JavaVirtualTable(Class* C); + JavaVirtualTable(ClassArray* C); + JavaVirtualTable(ClassPrimitive* C); + + + /// getFirstJavaMethod - Get the byte offset of the first Java method + /// (). + /// + uintptr_t* getFirstJavaMethod() { + return &init; + } + + /// getFirstJavaMethodIndex - Get the word offset of the first Java method. + /// + static uint32_t getFirstJavaMethodIndex() { + return 18; + } + + /// getBaseSize - Get the size of the java.lang.Object virtual table. + /// + static uint32_t getBaseSize() { + return 29; + } + + /// getNumJavaMethods - Get the number of methods of the java.lang.Object + /// class. + /// + static uint32_t getNumJavaMethods() { + return 11; + } + + /// getDisplayLength - Get the length of the display (primary type) array. + /// + static uint32_t getDisplayLength() { + return 8; + } + + /// getCacheIndex - Get the word offset of the type cache. + /// + static uint32_t getCacheIndex() { + return 6; + } + + /// getOffsetIndex - Get the word offset of the type cache. + /// + static uint32_t getOffsetIndex() { + return 5; + } + + /// getSecondaryTypesIndex - Get the word offset of the secondary types + /// list. + /// + static uint32_t getSecondaryTypesIndex() { + return 5; + } + + /// isSubtypeOf - Returns true if the given VT is a subtype of the this + /// VT. + /// + bool isSubtypeOf(JavaVirtualTable* VT); + + +}; + /// Attribut - This class represents JVM attributes to Java class, methods and /// fields located in the .class file. @@ -154,15 +289,6 @@ // //===----------------------------------------------------------------------===// - /// display - The class hierarchy of supers for this class. - /// - CommonClass** display; - - /// depth - The depth of this class in its class hierarchy. - /// display[depth] contains the class. - /// - uint32 depth; - /// delegatees - The java/lang/Class delegatee. /// JavaObject* delegatee[NR_ISOLATES]; @@ -198,7 +324,12 @@ // End field declaration. // //===----------------------------------------------------------------------===// - + + bool isSecondaryClass() { + return isInterface() || + virtualVT->depth >= JavaVirtualTable::getDisplayLength(); + } + // Assessor methods. uint32 getAccess() const { return access; } Class** getInterfaces() const { return interfaces; } @@ -1327,128 +1458,6 @@ }; -/// JavaVirtualTable - This class is the virtual table of instances of -/// Java classes. Besides holding function pointers for virtual calls, -/// it contains a bunch of information useful for fast dynamic type checking. -/// These are placed here for fast access of information from a Java object -/// (that only points to the VT, not the class). -/// -class JavaVirtualTable : public VirtualTable { -public: - - /// cl - The class which defined this virtual table. - /// - CommonClass* cl; - - /// depth - The super hierarchy depth of the class. - /// - size_t depth; - - /// offset - Offset in the virtual table where this virtual - /// table may be pointed. The offset is the cache if the class - /// is an interface or depth is too big, or an offset in the display. - /// - size_t offset; - - /// cache - The cached result for better type checks on secondary types. - /// - JavaVirtualTable* cache; - - /// display - Array of super classes. - /// - JavaVirtualTable* display[8]; - - /// nbSecondaryTypes - The length of the secondary type list. - /// - size_t nbSecondaryTypes; - - /// secondaryTypes - The list of secondary types of this type. These - /// are the interface and all the supers whose depth is too big. - /// - JavaVirtualTable** secondaryTypes; - - /// baseClass - Holds the base class VT of an array, or the array class VT - /// of a regular class. - /// - JavaVirtualTable* baseClassVT; - - /// Java methods for the virtual table functions. - uintptr_t init; - uintptr_t equals; - uintptr_t hashCode; - uintptr_t toString; - uintptr_t clone; - uintptr_t getClass; - uintptr_t notify; - uintptr_t notifyAll; - uintptr_t waitIndefinitely; - uintptr_t waitMs; - uintptr_t waitMsNs; - uintptr_t virtualMethods[1]; - - /// operator new - Allocates a JavaVirtualTable with the given size. The - /// size must contain the additional information for type checking, as well - /// as the function pointers. - /// - void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator, - uint32 nbMethods) { - return allocator.Allocate(sizeof(uintptr_t) * (nbMethods)); - } - - /// JavaVirtualTable - Create JavaVirtualTable objects for classes, array - /// classes and primitive classes. - /// - JavaVirtualTable(Class* C); - JavaVirtualTable(ClassArray* C); - JavaVirtualTable(ClassPrimitive* C); - - - /// getFirstJavaMethod - Get the byte offset of the first Java method - /// (). - /// - uintptr_t* getFirstJavaMethod() { - return &init; - } - - /// getFirstJavaMethodIndex - Get the word offset of the first Java method. - /// - static uint32_t getFirstJavaMethodIndex() { - return 18; - } - - /// getBaseSize - Get the size of the java.lang.Object virtual table. - /// - static uint32_t getBaseSize() { - return 29; - } - - /// getNumJavaMethods - Get the number of methods of the java.lang.Object - /// class. - /// - static uint32_t getNumJavaMethods() { - return 11; - } - - /// getDisplayLength - Get the length of the display (primary type) array. - /// - static uint32_t getDisplayLength() { - return 8; - } - - /// getCacheIndex - Get the word offset of the type cache. - /// - static uint32_t getCacheIndex() { - return 6; - } - - /// isSubtypeOf - Returns true if the given VT is a subtype of the this - /// VT. - /// - bool isSubtypeOf(JavaVirtualTable* VT); - - -}; - } // end namespace jnjvm From nicolas.geoffray at lip6.fr Thu Apr 23 01:27:40 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 08:27:40 -0000 Subject: [vmkit-commits] [vmkit] r69881 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Message-ID: <200904230827.n3N8Re25026584@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 03:27:39 2009 New Revision: 69881 URL: http://llvm.org/viewvc/llvm-project?rev=69881&view=rev Log: A class if of secondary type iff its offset is the cache value. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69881&r1=69880&r2=69881&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Apr 23 03:27:39 2009 @@ -326,8 +326,7 @@ //===----------------------------------------------------------------------===// bool isSecondaryClass() { - return isInterface() || - virtualVT->depth >= JavaVirtualTable::getDisplayLength(); + return virtualVT->offset == JavaVirtualTable::getCacheIndex(); } // Assessor methods. From nicolas.geoffray at lip6.fr Thu Apr 23 01:31:06 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 08:31:06 -0000 Subject: [vmkit-commits] [vmkit] r69882 - in /vmkit/trunk/lib/JnJVM/Compiler: ExceptionsCheck.inc JavaJITOpcodes.cpp LowerConstantCalls.cpp Message-ID: <200904230831.n3N8V6Ec026711@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 03:31:05 2009 New Revision: 69882 URL: http://llvm.org/viewvc/llvm-project?rev=69882&view=rev Log: Start lowering of runtime type checks in the compiler. Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc?rev=69882&r1=69881&r2=69882&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc (original) +++ vmkit/trunk/lib/JnJVM/Compiler/ExceptionsCheck.inc Thu Apr 23 03:31:05 2009 @@ -421,23 +421,28 @@ uint32 depth = cur->catchClass->virtualVT->depth; Value* depthCl = ConstantInt::get(Type::Int32Ty, depth); - + Value* cmp = 0; + if (depth >= JavaVirtualTable::getDisplayLength()) { - assert(0 && "Implement me"); - } - - - - Value* inDisplay = CallInst::Create(module->GetDisplayFunction, - objVT, "", currentBlock); + Value* classArgs[2] = { objVT, VTVar }; + + cmp = CallInst::Create(module->IsSecondaryClassFunction, + classArgs, classArgs + 2, "", + currentBlock); + + } else { + + Value* inDisplay = CallInst::Create(module->GetDisplayFunction, + objVT, "", currentBlock); - Value* displayArgs[2] = { inDisplay, depthCl }; - Value* VTInDisplay = CallInst::Create(module->GetVTInDisplayFunction, - displayArgs, displayArgs + 2, "", - currentBlock); + Value* displayArgs[2] = { inDisplay, depthCl }; + Value* VTInDisplay = CallInst::Create(module->GetVTInDisplayFunction, + displayArgs, displayArgs + 2, "", + currentBlock); - Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, VTInDisplay, VTVar, "", - currentBlock); + cmp = new ICmpInst(ICmpInst::ICMP_EQ, VTInDisplay, VTVar, "", + currentBlock); + } // Add the Java exception in the phi node of the handler. Instruction* insn = cur->javaHandler->begin(); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=69882&r1=69881&r2=69882&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Thu Apr 23 03:31:05 2009 @@ -2055,10 +2055,33 @@ Value* objVT = CallInst::Create(module->GetVTFunction, obj, "", currentBlock); Value* classArgs[2] = { objVT, TheVT }; - - Value* res = CallInst::Create(module->IsAssignableFromFunction, - classArgs, classArgs + 2, "", - currentBlock); + + Value* res = 0; + if (cl) { + if (cl->isSecondaryClass()) { + res = CallInst::Create(module->IsSecondaryClassFunction, + classArgs, classArgs + 2, "", + currentBlock); + } else { + Value* inDisplay = CallInst::Create(module->GetDisplayFunction, + objVT, "", currentBlock); + + uint32 depth = cl->virtualVT->depth; + ConstantInt* CI = ConstantInt::get(Type::Int32Ty, depth); + Value* displayArgs[2] = { inDisplay, CI }; + Value* VTInDisplay = + CallInst::Create(module->GetVTInDisplayFunction, + displayArgs, displayArgs + 2, "", + currentBlock); + + res = new ICmpInst(ICmpInst::ICMP_EQ, VTInDisplay, TheVT, "", + currentBlock); + } + } else { + res = CallInst::Create(module->IsAssignableFromFunction, + classArgs, classArgs + 2, "", + currentBlock); + } node->addIncoming(res, currentBlock); BranchInst::Create(endBlock, currentBlock); Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp?rev=69882&r1=69881&r2=69882&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Thu Apr 23 03:31:05 2009 @@ -526,16 +526,13 @@ } else if (V == module->IsSecondaryClassFunction) { Changed = true; Value* VT1 = Call.getArgument(0); - Value* VT2 = Call.getArgument(0); + Value* VT2 = Call.getArgument(1); Value* args[2] = { VT1, VT2 }; CallInst* res = CallInst::Create(module->IsAssignableFromFunction, args, args + 2, "", CI); CI->replaceAllUsesWith(res); CI->eraseFromParent(); - - - break; } #ifdef ISOLATE_SHARING else if (V == module->GetCtpClassFunction) { From nicolas.geoffray at lip6.fr Thu Apr 23 04:23:13 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 11:23:13 -0000 Subject: [vmkit-commits] [vmkit] r69885 - in /vmkit/trunk/lib/JnJVM: Compiler/JnjvmModule.cpp Compiler/LowerConstantCalls.cpp LLVMRuntime/runtime-default.ll VMCore/JavaClass.h VMCore/JavaRuntimeJIT.cpp Message-ID: <200904231123.n3NBNFoa000923@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 06:22:53 2009 New Revision: 69885 URL: http://llvm.org/viewvc/llvm-project?rev=69885&view=rev Log: Inline dynamic runtime checks. Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69885&r1=69884&r2=69885&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Apr 23 06:22:53 2009 @@ -349,7 +349,7 @@ GetClassDelegateeFunction = module->getFunction("getClassDelegatee"); RuntimeDelegateeFunction = module->getFunction("jnjvmRuntimeDelegatee"); - IsAssignableFromFunction = module->getFunction("jnjvmIsAssignableFrom"); + IsAssignableFromFunction = module->getFunction("isAssignableFrom"); IsSecondaryClassFunction = module->getFunction("isSecondaryClass"); GetDepthFunction = module->getFunction("getDepth"); GetStaticInstanceFunction = module->getFunction("getStaticInstance"); Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp?rev=69885&r1=69884&r2=69885&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Thu Apr 23 06:22:53 2009 @@ -523,16 +523,165 @@ Value* res = new LoadInst(val, "", CI); CI->replaceAllUsesWith(res); CI->eraseFromParent(); + } else if (V == module->IsAssignableFromFunction) { + Changed = true; + Value* VT1 = Call.getArgument(0); + Value* VT2 = Call.getArgument(1); + + BasicBlock* EndBlock = II->getParent()->splitBasicBlock(II); + I->getParent()->getTerminator()->eraseFromParent(); + + BasicBlock* CurEndBlock = BasicBlock::Create("", &F); + BasicBlock* FailedBlock = BasicBlock::Create("", &F); + PHINode* node = PHINode::Create(Type::Int1Ty, "", CurEndBlock); + + ConstantInt* CC = ConstantInt::get(Type::Int32Ty, + JavaVirtualTable::getOffsetIndex()); + Value* indices[2] = { module->constantZero, CC }; + Value* Offset = GetElementPtrInst::Create(VT2, indices, indices + 2, + "", CI); + Offset = new LoadInst(Offset, "", false, CI); + Offset = new PtrToIntInst(Offset, Type::Int32Ty, "", CI); + indices[1] = Offset; + Value* CurVT = GetElementPtrInst::Create(VT1, indices, indices + 2, + "", CI); + CurVT = new LoadInst(CurVT, "", false, CI); + CurVT = new BitCastInst(CurVT, module->VTType, "", CI); + + Value* res = new ICmpInst(ICmpInst::ICMP_EQ, CurVT, VT2, "", CI); + + node->addIncoming(ConstantInt::getTrue(), CI->getParent()); + BranchInst::Create(CurEndBlock, FailedBlock, res, CI); + + Value* Args[2] = { VT1, VT2 }; + res = CallInst::Create(module->IsSecondaryClassFunction, Args, + Args + 2, "", FailedBlock); + + node->addIncoming(res, FailedBlock); + BranchInst::Create(CurEndBlock, FailedBlock); + + // Branch to the next block. + BranchInst::Create(EndBlock, CurEndBlock); + + // We can now replace the previous instruction. + CI->replaceAllUsesWith(node); + CI->eraseFromParent(); + + // Reanalyse the current block. + break; + } else if (V == module->IsSecondaryClassFunction) { Changed = true; Value* VT1 = Call.getArgument(0); Value* VT2 = Call.getArgument(1); + + BasicBlock* EndBlock = II->getParent()->splitBasicBlock(II); + I->getParent()->getTerminator()->eraseFromParent(); - Value* args[2] = { VT1, VT2 }; - CallInst* res = CallInst::Create(module->IsAssignableFromFunction, - args, args + 2, "", CI); - CI->replaceAllUsesWith(res); + + BasicBlock* Preheader = BasicBlock::Create("preheader", &F); + BasicBlock* BB4 = BasicBlock::Create("BB4", &F); + BasicBlock* BB5 = BasicBlock::Create("BB5", &F); + BasicBlock* BB6 = BasicBlock::Create("BB6", &F); + BasicBlock* BB7 = BasicBlock::Create("BB7", &F); + BasicBlock* BB9 = BasicBlock::Create("BB9", &F); + const Type* Ty = PointerType::getUnqual(module->VTType); + + PHINode* resFwd = PHINode::Create(Type::Int32Ty, "", BB7); + + // This corresponds to: + // if (VT1.cache == VT2 || VT1 == VT2) goto end with true; + // else goto headerLoop; + ConstantInt* cacheIndex = + ConstantInt::get(Type::Int32Ty, JavaVirtualTable::getCacheIndex()); + Value* indices[2] = { module->constantZero, cacheIndex }; + Instruction* CachePtr = + GetElementPtrInst::Create(VT1, indices, indices + 2, "", CI); + CachePtr = new BitCastInst(CachePtr, Ty, "", CI); + Value* Cache = new LoadInst(CachePtr, "", false, CI); + ICmpInst* cmp1 = new ICmpInst(ICmpInst::ICMP_EQ, Cache, VT2, "", CI); + ICmpInst* cmp2 = new ICmpInst(ICmpInst::ICMP_EQ, VT1, VT2, "", CI); + BinaryOperator* Or = BinaryOperator::Create(Instruction::Or, cmp1, + cmp2, "", CI); + BranchInst::Create(BB9, Preheader, Or, CI); + + // First test failed. Go into the loop. The Preheader looks like this: + // headerLoop: + // types = VT1->secondaryTypes; + // size = VT1->nbSecondaryTypes; + // i = 0; + // goto test; + ConstantInt* sizeIndex = ConstantInt::get(Type::Int32Ty, + JavaVirtualTable::getNumSecondaryTypesIndex()); + indices[1] = sizeIndex; + Instruction* Size = GetElementPtrInst::Create(VT1, indices, + indices + 2, "", + Preheader); + Size = new LoadInst(Size, "", false, Preheader); + Size = new PtrToIntInst(Size, Type::Int32Ty, "", Preheader); + + ConstantInt* secondaryTypesIndex = ConstantInt::get(Type::Int32Ty, + JavaVirtualTable::getSecondaryTypesIndex()); + indices[1] = secondaryTypesIndex; + Instruction* secondaryTypes = + GetElementPtrInst::Create(VT1, indices, indices + 2, "", Preheader); + secondaryTypes = new LoadInst(secondaryTypes, "", false, Preheader); + secondaryTypes = new BitCastInst(secondaryTypes, Ty, "", Preheader); + BranchInst::Create(BB7, Preheader); + + // Here is the test if the current secondary type is VT2. + // test: + // CurVT = types[i]; + // if (CurVT == VT2) goto update cache; + // est goto inc; + Instruction* CurVT = GetElementPtrInst::Create(secondaryTypes, resFwd, + "", BB4); + CurVT = new LoadInst(CurVT, "", false, BB4); + cmp1 = new ICmpInst(ICmpInst::ICMP_EQ, CurVT, VT2, "", BB4); + BranchInst::Create(BB5, BB6, cmp1, BB4); + + // Increment i if the previous test failed + // inc: + // ++i; + // goto endLoopTest; + BinaryOperator* IndVar = + BinaryOperator::CreateAdd(resFwd, module->constantOne, "", BB6); + BranchInst::Create(BB7, BB6); + + // Verify that we haven't reached the end of the loop: + // endLoopTest: + // if (i < size) goto test + // else goto end with false + resFwd->reserveOperandSpace(2); + resFwd->addIncoming(module->constantZero, Preheader); + resFwd->addIncoming(IndVar, BB6); + + cmp1 = new ICmpInst(ICmpInst::ICMP_SGT, Size, resFwd, "", BB7); + BranchInst::Create(BB4, BB9, cmp1, BB7); + + // Update the cache if the result is found. + // updateCache: + // VT1->cache = result + // goto end with true + new StoreInst(VT2, CachePtr, false, BB5); + BranchInst::Create(BB9, BB5); + + // Final block, that gets the result. + PHINode* node = PHINode::Create(Type::Int1Ty, "", BB9); + node->reserveOperandSpace(3); + node->addIncoming(ConstantInt::getTrue(), CI->getParent()); + node->addIncoming(ConstantInt::getFalse(), BB7); + node->addIncoming(ConstantInt::getTrue(), BB5); + + // Don't forget to jump to the next block. + BranchInst::Create(EndBlock, BB9); + + // We can now replace the previous instruction + CI->replaceAllUsesWith(node); CI->eraseFromParent(); + + // And reanalyse the current block. + break; } #ifdef ISOLATE_SHARING else if (V == module->GetCtpClassFunction) { Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=69885&r1=69884&r2=69885&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Thu Apr 23 06:22:53 2009 @@ -178,9 +178,9 @@ declare void @overflowThinLock(%JavaObject*) ;;; isAssignableFrom - Returns if a type is a subtype of another type. -declare i1 @jnjvmIsAssignableFrom(%VT*, %VT*) readnone +declare i1 @isAssignableFrom(%VT*, %VT*) readnone -;;; isAssignableFrom - Returns if a type is a secondary super type of +;;; isSecondaryClass - Returns if a type is a secondary super type of ;;; another type. declare i1 @isSecondaryClass(%VT*, %VT*) readnone Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=69885&r1=69884&r2=69885&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Apr 23 06:22:53 2009 @@ -98,7 +98,7 @@ JavaVirtualTable** secondaryTypes; /// baseClass - Holds the base class VT of an array, or the array class VT - /// of a regular class. + /// of a regular class. Used for AASTORE checks. /// JavaVirtualTable* baseClassVT; @@ -181,7 +181,14 @@ /// list. /// static uint32_t getSecondaryTypesIndex() { - return 5; + return 16; + } + + /// getNumSecondaryTypesIndex - Get the word offset of the number of + /// secondary types. + /// + static uint32_t getNumSecondaryTypesIndex() { + return 15; } /// isSubtypeOf - Returns true if the given VT is a subtype of the this Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=69885&r1=69884&r2=69885&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Thu Apr 23 06:22:53 2009 @@ -408,12 +408,6 @@ obj->release(); } -// Never throws. -extern "C" bool jnjvmIsAssignableFrom(JavaVirtualTable* VT1, - JavaVirtualTable* VT2) { - return VT1->isSubtypeOf(VT2); -} - // Does not call any Java code. extern "C" void JavaThreadThrowException(JavaObject* obj) { return JavaThread::get()->throwException(obj); From nicolas.geoffray at lip6.fr Thu Apr 23 04:47:32 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 11:47:32 -0000 Subject: [vmkit-commits] [vmkit] r69886 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMRuntime.cpp Compiler/JnjvmModule.cpp LLVMRuntime/runtime-default.ll LLVMRuntime/runtime-isolate.ll LLVMRuntime/runtime-service.ll VMCore/JavaRuntimeJIT.cpp Message-ID: <200904231147.n3NBlYJ5001974@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 06:47:14 2009 New Revision: 69886 URL: http://llvm.org/viewvc/llvm-project?rev=69886&view=rev Log: Make namking more consistent (all jnjvm runtime functions are named with a "jnjvm" prefix). Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-service.ll vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp?rev=69886&r1=69885&r2=69886&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp Thu Apr 23 06:47:14 2009 @@ -75,7 +75,7 @@ #endif typedef int (*onLoad_t)(const void**, void*); -extern "C" void jniProceedPendingException(); +extern "C" void jnjvmJNIProceedPendingException(); // Calls the JNI_OnLoad function of a dynamic library. void callOnLoad(void* res, JnjvmClassLoader* loader, Jnjvm* vm) { @@ -92,7 +92,7 @@ if (setjmp((jumpbuf_t)buf) == 0) { onLoad(&vm->javavmEnv, res); } - jniProceedPendingException(); + jnjvmJNIProceedPendingException(); } } Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69886&r1=69885&r2=69886&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Apr 23 06:47:14 2009 @@ -327,8 +327,8 @@ module->addTypeName("CacheNode", CacheNodeType); module->addTypeName("Enveloppe", EnveloppeType); - InterfaceLookupFunction = module->getFunction("jnjvmVirtualLookup"); - MultiCallNewFunction = module->getFunction("multiCallNew"); + InterfaceLookupFunction = module->getFunction("jnjvmInterfaceLookup"); + MultiCallNewFunction = module->getFunction("jnjvmMultiCallNew"); ForceLoadedCheckFunction = module->getFunction("forceLoadedCheck"); InitialisationCheckFunction = module->getFunction("initialisationCheck"); ForceInitialisationCheckFunction = @@ -339,7 +339,7 @@ ArrayLengthFunction = module->getFunction("arrayLength"); GetVTFunction = module->getFunction("getVT"); GetClassFunction = module->getFunction("getClass"); - ClassLookupFunction = module->getFunction("classLookup"); + ClassLookupFunction = module->getFunction("jnjvmClassLookup"); GetVTFromClassFunction = module->getFunction("getVTFromClass"); GetVTFromClassArrayFunction = module->getFunction("getVTFromClassArray"); GetVTFromCommonClassFunction = module->getFunction("getVTFromCommonClass"); @@ -355,36 +355,36 @@ GetStaticInstanceFunction = module->getFunction("getStaticInstance"); GetDisplayFunction = module->getFunction("getDisplay"); GetVTInDisplayFunction = module->getFunction("getVTInDisplay"); - AquireObjectFunction = module->getFunction("JavaObjectAquire"); - ReleaseObjectFunction = module->getFunction("JavaObjectRelease"); - OverflowThinLockFunction = module->getFunction("overflowThinLock"); + AquireObjectFunction = module->getFunction("jnjvmJavaObjectAquire"); + ReleaseObjectFunction = module->getFunction("jnjvmJavaObjectRelease"); + OverflowThinLockFunction = module->getFunction("jnjvmOverflowThinLock"); - VirtualFieldLookupFunction = module->getFunction("virtualFieldLookup"); - StaticFieldLookupFunction = module->getFunction("staticFieldLookup"); + VirtualFieldLookupFunction = module->getFunction("jnjvmVirtualFieldLookup"); + StaticFieldLookupFunction = module->getFunction("jnjvmStaticFieldLookup"); JniProceedPendingExceptionFunction = - module->getFunction("jniProceedPendingException"); - GetSJLJBufferFunction = module->getFunction("getSJLJBuffer"); + module->getFunction("jnjvmJNIProceedPendingException"); + GetSJLJBufferFunction = module->getFunction("jnjvmGetSJLJBuffer"); NullPointerExceptionFunction = module->getFunction("jnjvmNullPointerException"); ClassCastExceptionFunction = module->getFunction("jnjvmClassCastException"); IndexOutOfBoundsExceptionFunction = - module->getFunction("indexOutOfBoundsException"); + module->getFunction("jnjvmIndexOutOfBoundsException"); NegativeArraySizeExceptionFunction = - module->getFunction("negativeArraySizeException"); - OutOfMemoryErrorFunction = module->getFunction("outOfMemoryError"); + module->getFunction("jnjvmNegativeArraySizeException"); + OutOfMemoryErrorFunction = module->getFunction("jnjvmOutOfMemoryError"); ArrayStoreExceptionFunction = module->getFunction("jnjvmArrayStoreException"); JavaObjectAllocateFunction = module->getFunction("gcmalloc"); - PrintExecutionFunction = module->getFunction("printExecution"); - PrintMethodStartFunction = module->getFunction("printMethodStart"); - PrintMethodEndFunction = module->getFunction("printMethodEnd"); + PrintExecutionFunction = module->getFunction("jnjvmPrintExecution"); + PrintMethodStartFunction = module->getFunction("jnjvmPrintMethodStart"); + PrintMethodEndFunction = module->getFunction("jnjvmPrintMethodEnd"); - ThrowExceptionFunction = module->getFunction("JavaThreadThrowException"); + ThrowExceptionFunction = module->getFunction("jnjvmThrowException"); - GetArrayClassFunction = module->getFunction("getArrayClass"); + GetArrayClassFunction = module->getFunction("jnjvmGetArrayClass"); GetFinalInt8FieldFunction = module->getFunction("getFinalInt8Field"); GetFinalInt16FieldFunction = module->getFunction("getFinalInt16Field"); @@ -395,22 +395,22 @@ GetFinalObjectFieldFunction = module->getFunction("getFinalObjectField"); #ifdef ISOLATE - StringLookupFunction = module->getFunction("stringLookup"); + StringLookupFunction = module->getFunction("jnjvmStringLookup"); #ifdef ISOLATE_SHARING - EnveloppeLookupFunction = module->getFunction("enveloppeLookup"); + EnveloppeLookupFunction = module->getFunction("jnjvmEnveloppeLookup"); GetCtpCacheNodeFunction = module->getFunction("getCtpCacheNode"); GetCtpClassFunction = module->getFunction("getCtpClass"); GetJnjvmExceptionClassFunction = module->getFunction("getJnjvmExceptionClass"); GetJnjvmArrayClassFunction = module->getFunction("getJnjvmArrayClass"); - StaticCtpLookupFunction = module->getFunction("staticCtpLookup"); - SpecialCtpLookupFunction = module->getFunction("specialCtpLookup"); + StaticCtpLookupFunction = module->getFunction("jnjvmStaticCtpLookup"); + SpecialCtpLookupFunction = module->getFunction("jnjvmSpecialCtpLookup"); #endif #endif #ifdef SERVICE - ServiceCallStartFunction = module->getFunction("serviceCallStart"); - ServiceCallStopFunction = module->getFunction("serviceCallStop"); + ServiceCallStartFunction = module->getFunction("jnjvmServiceCallStart"); + ServiceCallStopFunction = module->getFunction("jnjvmServiceCallStop"); #endif #ifdef WITH_TRACER @@ -421,7 +421,7 @@ #endif #ifndef WITHOUT_VTABLE - VirtualLookupFunction = module->getFunction("vtableLookup"); + VirtualLookupFunction = module->getFunction("jnjvmVirtualTableLookup"); #endif GetLockFunction = module->getFunction("getLock"); Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=69886&r1=69885&r2=69886&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Thu Apr 23 06:47:14 2009 @@ -118,12 +118,12 @@ ;;;;;;;;;;;;;;;;;;;;;;;; Generic Runtime methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; virtualLookup - Used for interface calls. -declare i8* @jnjvmVirtualLookup(%CacheNode*, %JavaObject*) +;;; jnjvmInterfaceLookup - Used for interface calls. +declare i8* @jnjvmInterfaceLookup(%CacheNode*, %JavaObject*) -;;; multiCallNew - Allocate multi-dimensional arrays. This will go to allocation -;;; specific methods. -declare %JavaObject* @multiCallNew(%JavaCommonClass*, i32, ...) +;;; jnjvmMultiCallNew - Allocate multi-dimensional arrays. This will go to +;;; allocation specific methods. +declare %JavaObject* @jnjvmMultiCallNew(%JavaCommonClass*, i32, ...) ;;; initialisationCheck - Checks if the class has been initialized and ;;; initializes if not. This is used for initialization barriers in an isolate @@ -149,33 +149,33 @@ declare i8* @getConstantPoolAt(i8* (%JavaClass*, i32, ...)*, i8**, %JavaClass*, i32, ...) readnone -;;; vtableLookup - Look up the offset in a virtual table of a specific -;;; function. This function takes a class and an index to lookup in the +;;; jnjvmVirtualTableLookup - Look up the offset in a virtual table of a +;;; specific function. This function takes a class and an index to lookup in the ;;; constant pool and returns and stores it in the constant pool cache. -declare i8* @vtableLookup(%JavaClass*, i32, ...) +declare i8* @jnjvmVirtualTableLookup(%JavaClass*, i32, ...) -;;; newLookup - Look up a specific class. The function takes a class and an -;;; index to lookup in the constant pool and returns and stores it in the +;;; jnjvmClassLookup - Look up a specific class. The function takes a class and +;;; an index to lookup in the constant pool and returns and stores it in the ;;; constant pool cache. -declare i8* @classLookup(%JavaClass*, i32, ...) +declare i8* @jnjvmClassLookup(%JavaClass*, i32, ...) -;;; virtualFieldLookup - Look up a specific virtual field. -declare i8* @virtualFieldLookup(%JavaClass*, i32, ...) +;;; jnjvmVirtualFieldLookup - Look up a specific virtual field. +declare i8* @jnjvmVirtualFieldLookup(%JavaClass*, i32, ...) -;;; staticFieldLookup - Look up a specific static field. -declare i8* @staticFieldLookup(%JavaClass*, i32, ...) +;;; jnjvmStaticFieldLookup - Look up a specific static field. +declare i8* @jnjvmStaticFieldLookup(%JavaClass*, i32, ...) -;;; JavaObjectAquire - This function is called when starting a synchronized +;;; jnjvmJavaObjectAquire - This function is called when starting a synchronized ;;; block or method. -declare void @JavaObjectAquire(%JavaObject*) +declare void @jnjvmJavaObjectAquire(%JavaObject*) -;;; JavaObjectRelease - This function is called when leaving a synchronized +;;; jnjvmJavaObjectRelease - This function is called when leaving a synchronized ;;; block or method. -declare void @JavaObjectRelease(%JavaObject*) +declare void @jnjvmJavaObjectRelease(%JavaObject*) -;;; overflowThinLock - Change a thin lock to a fat lock when the thin lock +;;; jnjvmOverflowThinLock - Change a thin lock to a fat lock when the thin lock ;;; overflows -declare void @overflowThinLock(%JavaObject*) +declare void @jnjvmOverflowThinLock(%JavaObject*) ;;; isAssignableFrom - Returns if a type is a subtype of another type. declare i1 @isAssignableFrom(%VT*, %VT*) readnone @@ -194,9 +194,9 @@ ;;; yet. declare %JavaObject* @jnjvmRuntimeDelegatee(%JavaCommonClass*) readnone -;;; getArrayClass - Get the array user class of the user class. -declare %JavaClassArray* @getArrayClass(%JavaCommonClass*, - %JavaClassArray**) readnone +;;; jnjvmGetArrayClass - Get the array user class of the user class. +declare %JavaClassArray* @jnjvmGetArrayClass(%JavaCommonClass*, + %JavaClassArray**) readnone declare i8 @getFinalInt8Field(i8*) readnone declare i16 @getFinalInt16Field(i16*) readnone @@ -212,14 +212,14 @@ declare %JavaObject* @jnjvmNullPointerException() declare %JavaObject* @jnjvmClassCastException(%JavaObject*, %JavaCommonClass*) -declare %JavaObject* @indexOutOfBoundsException(%JavaObject*, i32) -declare %JavaObject* @negativeArraySizeException(i32) -declare %JavaObject* @outOfMemoryError(i32) +declare %JavaObject* @jnjvmIndexOutOfBoundsException(%JavaObject*, i32) +declare %JavaObject* @jnjvmNegativeArraySizeException(i32) +declare %JavaObject* @jnjvmOutOfMemoryError(i32) declare %JavaObject* @jnjvmArrayStoreException(%VT*) -declare void @JavaThreadThrowException(%JavaObject*) +declare void @jnjvmThrowException(%JavaObject*) -declare void @jniProceedPendingException() -declare i8* @getSJLJBuffer() +declare void @jnjvmJNIProceedPendingException() +declare i8* @jnjvmGetSJLJBuffer() declare %JavaObject* @gcmalloc(i32, %VT*) @@ -227,6 +227,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Debugging methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -declare void @printExecution(i32, i32, %JavaMethod*) -declare void @printMethodStart(%JavaMethod*) -declare void @printMethodEnd(%JavaMethod*) +declare void @jnjvmPrintExecution(i32, i32, %JavaMethod*) +declare void @jnjvmPrintMethodStart(%JavaMethod*) +declare void @jnjvmPrintMethodEnd(%JavaMethod*) Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll?rev=69886&r1=69885&r2=69886&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll Thu Apr 23 06:47:14 2009 @@ -19,20 +19,20 @@ ;;;;;;;;;;;;;;;;;;;;;;;; Isolate specific methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; enveloppeLookup - Find the enveloppe for the current user class. -declare i8* @enveloppeLookup(%JavaClass*, i32, ...) readnone +;;; jnjvmEnveloppeLookup - Find the enveloppe for the current user class. +declare i8* @jnjvmEnveloppeLookup(%JavaClass*, i32, ...) readnone -;;; stringLookup - Find the isolate-specific string at the given offset in the -;;; constant pool. -declare i8* @stringLookup(%JavaClass*, i32, ...) readnone - -;;; staticCtpLookup - Find the user constant pool at the given offset in the -;;; constant pool. -declare i8* @staticCtpLookup(%JavaClass*, i32, ...) readnone - -;;; specialCtpLookup - Find the user constant pool at the given offset in the -;;; constant pool. -declare i8** @specialCtpLookup(i8**, i32, i8**) readnone +;;; jnjvmStringLookup - Find the isolate-specific string at the given offset in +;;; the constant pool. +declare i8* @jnjvmStringLookup(%JavaClass*, i32, ...) readnone + +;;; jnjvmStaticCtpLookup - Find the user constant pool at the given offset in +;;; the constant pool. +declare i8* @jnjvmStaticCtpLookup(%JavaClass*, i32, ...) readnone + +;;; jnjvmSpecialCtpLookup - Find the user constant pool at the given offset in +;;; the constant pool. +declare i8** @jnjvmSpecialCtpLookup(i8**, i32, i8**) readnone ;;; getCtpCacheNode - Get the constant pool cache of a cache node. This is a ;;; constant call because the cache node never changes. Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-service.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-service.ll?rev=69886&r1=69885&r2=69886&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-service.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-service.ll Thu Apr 23 06:47:14 2009 @@ -2,8 +2,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;; Service specific methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; serviceCallStart - Mark the switching between services. -declare void @serviceCallStart(i8*, i8*) +;;; jnjvmServiceCallStart - Mark the switching between services. +declare void @jnjvmServiceCallStart(i8*, i8*) -;;; serviceCallStop - Mark the switching between services. -declare void @serviceCallStop(i8*, i8*) +;;; jnjvmServiceCallStop - Mark the switching between services. +declare void @jnjvmServiceCallStop(i8*, i8*) Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=69886&r1=69885&r2=69886&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Thu Apr 23 06:47:14 2009 @@ -25,7 +25,7 @@ using namespace jnjvm; // Throws if the method is not found. -extern "C" void* jnjvmVirtualLookup(CacheNode* cache, JavaObject *obj) { +extern "C" void* jnjvmInterfaceLookup(CacheNode* cache, JavaObject *obj) { void* res = 0; @@ -99,7 +99,7 @@ } // Throws if the field is not found. -extern "C" void* virtualFieldLookup(UserClass* caller, uint32 index) { +extern "C" void* jnjvmVirtualFieldLookup(UserClass* caller, uint32 index) { void* res = 0; @@ -134,7 +134,7 @@ } // Throws if the field or its class is not found. -extern "C" void* staticFieldLookup(UserClass* caller, uint32 index) { +extern "C" void* jnjvmStaticFieldLookup(UserClass* caller, uint32 index) { void* res = 0; @@ -179,7 +179,7 @@ #ifndef WITHOUT_VTABLE // Throws if the method is not found. -extern "C" void* vtableLookup(UserClass* caller, uint32 index, ...) { +extern "C" void* jnjvmVirtualTableLookup(UserClass* caller, uint32 index, ...) { void* res = 0; @@ -229,7 +229,7 @@ #endif // Throws if the class is not found. -extern "C" void* classLookup(UserClass* caller, uint32 index) { +extern "C" void* jnjvmClassLookup(UserClass* caller, uint32 index) { void* res = 0; @@ -318,7 +318,7 @@ } // Throws if one of the dimension is negative. -extern "C" JavaArray* multiCallNew(UserClassArray* cl, uint32 len, ...) { +extern "C" JavaArray* jnjvmMultiCallNew(UserClassArray* cl, uint32 len, ...) { JavaArray* res = 0; BEGIN_NATIVE_EXCEPTION(1) @@ -338,8 +338,8 @@ } // Throws if the class can not be resolved. -extern "C" UserClassArray* getArrayClass(UserCommonClass* cl, - UserClassArray** dcl) { +extern "C" UserClassArray* jnjvmGetArrayClass(UserCommonClass* cl, + UserClassArray** dcl) { UserClassArray* res = 0; BEGIN_NATIVE_EXCEPTION(1) @@ -362,7 +362,7 @@ } // Does not call Java code. -extern "C" void jniProceedPendingException() { +extern "C" void jnjvmJNIProceedPendingException() { JavaThread* th = JavaThread::get(); jmp_buf* buf = th->sjlj_buffers.back(); @@ -384,7 +384,7 @@ } // Never throws. -extern "C" void* getSJLJBuffer() { +extern "C" void* jnjvmGetSJLJBuffer() { JavaThread* th = JavaThread::get(); mvm::Allocator& allocator = th->getJVM()->gcAllocator; void** buf = (void**)allocator.allocateTemporaryMemory(sizeof(jmp_buf)); @@ -399,22 +399,22 @@ } // Never throws. -extern "C" void JavaObjectAquire(JavaObject* obj) { +extern "C" void jnjvmJavaObjectAquire(JavaObject* obj) { obj->acquire(); } // Never throws. -extern "C" void JavaObjectRelease(JavaObject* obj) { +extern "C" void jnjvmJavaObjectRelease(JavaObject* obj) { obj->release(); } // Does not call any Java code. -extern "C" void JavaThreadThrowException(JavaObject* obj) { +extern "C" void jnjvmThrowException(JavaObject* obj) { return JavaThread::get()->throwException(obj); } // Never throws. -extern "C" void overflowThinLock(JavaObject* obj) { +extern "C" void jnjvmOverflowThinLock(JavaObject* obj) { obj->overflowThinLock(); } @@ -440,7 +440,7 @@ } // Creates a Java object and then throws it. -extern "C" JavaObject* negativeArraySizeException(sint32 val) { +extern "C" JavaObject* jnjvmNegativeArraySizeException(sint32 val) { JavaObject *exc = 0; JavaThread *th = JavaThread::get(); @@ -460,7 +460,7 @@ } // Creates a Java object and then throws it. -extern "C" JavaObject* outOfMemoryError(sint32 val) { +extern "C" JavaObject* jnjvmOutOfMemoryError(sint32 val) { JavaObject *exc = 0; JavaThread *th = JavaThread::get(); @@ -501,8 +501,8 @@ } // Creates a Java object and then throws it. -extern "C" JavaObject* indexOutOfBoundsException(JavaObject* obj, - sint32 index) { +extern "C" JavaObject* jnjvmIndexOutOfBoundsException(JavaObject* obj, + sint32 index) { JavaObject *exc = 0; JavaThread *th = JavaThread::get(); From nicolas.geoffray at lip6.fr Thu Apr 23 05:07:17 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 12:07:17 -0000 Subject: [vmkit-commits] [vmkit] r69887 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/JavaJITOpcodes.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/LLVMRuntime/runtime-default.ll lib/JnJVM/VMCore/JavaRuntimeJIT.cpp lib/JnJVM/VMCore/JavaUpcalls.cpp lib/JnJVM/VMCore/JavaUpcalls.h lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h Message-ID: <200904231207.n3NC7KBj002690@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 07:07:08 2009 New Revision: 69887 URL: http://llvm.org/viewvc/llvm-project?rev=69887&view=rev Log: Implement division by zero exceptions. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.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 Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Thu Apr 23 07:07:08 2009 @@ -335,6 +335,7 @@ llvm::Function* OutOfMemoryErrorFunction; llvm::Function* NegativeArraySizeExceptionFunction; llvm::Function* ArrayStoreExceptionFunction; + llvm::Function* ArithmeticExceptionFunction; JnjvmModule(llvm::Module*); Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Thu Apr 23 07:07:08 2009 @@ -931,6 +931,18 @@ case IDIV : { Value* val2 = popAsInt(); Value* val1 = popAsInt(); + if (TheCompiler->hasExceptionsEnabled()) { + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, val2, + module->constantZero, + "", currentBlock); + BasicBlock* ifFalse = createBasicBlock("non null div"); + BasicBlock* ifTrue = createBasicBlock("null div"); + + BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock); + currentBlock = ifTrue; + throwException(module->ArithmeticExceptionFunction, 0, 0); + currentBlock = ifFalse; + } push(BinaryOperator::CreateSDiv(val1, val2, "", currentBlock), false); break; @@ -941,6 +953,18 @@ llvm::Value* val2 = pop(); pop(); llvm::Value* val1 = pop(); + if (TheCompiler->hasExceptionsEnabled()) { + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, val2, + module->constantLongZero, + "", currentBlock); + BasicBlock* ifFalse = createBasicBlock("non null div"); + BasicBlock* ifTrue = createBasicBlock("null div"); + + BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock); + currentBlock = ifTrue; + throwException(module->ArithmeticExceptionFunction, 0, 0); + currentBlock = ifFalse; + } push(BinaryOperator::CreateSDiv(val1, val2, "", currentBlock), false); push(module->constantZero, false); Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Apr 23 07:07:08 2009 @@ -375,6 +375,7 @@ module->getFunction("jnjvmNegativeArraySizeException"); OutOfMemoryErrorFunction = module->getFunction("jnjvmOutOfMemoryError"); ArrayStoreExceptionFunction = module->getFunction("jnjvmArrayStoreException"); + ArithmeticExceptionFunction = module->getFunction("jnjvmArithmeticException"); JavaObjectAllocateFunction = module->getFunction("gcmalloc"); Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Thu Apr 23 07:07:08 2009 @@ -216,6 +216,7 @@ declare %JavaObject* @jnjvmNegativeArraySizeException(i32) declare %JavaObject* @jnjvmOutOfMemoryError(i32) declare %JavaObject* @jnjvmArrayStoreException(%VT*) +declare %JavaObject* @jnjvmArithmeticException() declare void @jnjvmThrowException(%JavaObject*) declare void @jnjvmJNIProceedPendingException() Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Thu Apr 23 07:07:08 2009 @@ -480,6 +480,26 @@ } // Creates a Java object and then throws it. +extern "C" JavaObject* jnjvmArithmeticException() { + JavaObject *exc = 0; + JavaThread *th = JavaThread::get(); + + BEGIN_NATIVE_EXCEPTION(1) + + exc = th->getJVM()->CreateArithmeticException(); + + END_NATIVE_EXCEPTION + +#ifdef DWARF_EXCEPTIONS + th->throwException(exc); +#else + th->pendingException = exc; +#endif + + return exc; +} + +// Creates a Java object and then throws it. extern "C" JavaObject* jnjvmClassCastException(JavaObject* obj, UserCommonClass* cl) { JavaObject *exc = 0; @@ -541,24 +561,24 @@ return exc; } -extern "C" void printMethodStart(JavaMethod* meth) { +extern "C" void jnjvmPrintMethodStart(JavaMethod* meth) { fprintf(stderr, "[%p] executing %s\n", (void*)mvm::Thread::get(), meth->printString()); } -extern "C" void printMethodEnd(JavaMethod* meth) { +extern "C" void jnjvmPrintMethodEnd(JavaMethod* meth) { fprintf(stderr, "[%p] return from %s\n", (void*)mvm::Thread::get(), meth->printString()); } -extern "C" void printExecution(uint32 opcode, uint32 index, JavaMethod* meth) { +extern "C" void jnjvmPrintExecution(uint32 opcode, uint32 index, JavaMethod* meth) { fprintf(stderr, "[%p] executing %s %s at %d\n", (void*)mvm::Thread::get(), meth->printString(), OpcodeNames[opcode], index); } #ifdef SERVICE -extern "C" void serviceCallStart(Jnjvm* OldService, +extern "C" void jnjvmServiceCallStart(Jnjvm* OldService, Jnjvm* NewService) { fprintf(stderr, "I have switched from %d to %d\n", OldService->IsolateID, NewService->IsolateID); @@ -566,7 +586,7 @@ fprintf(stderr, "Now the thread id is %d\n", mvm::Thread::get()->IsolateID); } -extern "C" void serviceCallStop(Jnjvm* OldService, +extern "C" void jnjvmServiceCallStop(Jnjvm* OldService, Jnjvm* NewService) { fprintf(stderr, "End service call\n"); } @@ -574,7 +594,7 @@ #endif #ifdef ISOLATE -extern "C" void* stringLookup(UserClass* cl, uint32 index) { +extern "C" void* jnjvmStringLookup(UserClass* cl, uint32 index) { UserConstantPool* ctpInfo = cl->getConstantPool(); const UTF8* utf8 = ctpInfo->UTF8AtForString(index); JavaString* str = JavaThread::get()->getJVM()->internalUTF8ToStr(utf8); @@ -585,7 +605,7 @@ } #ifdef ISOLATE_SHARING -extern "C" void* enveloppeLookup(UserClass* cl, uint32 index) { +extern "C" void* jnjvmEnveloppeLookup(UserClass* cl, uint32 index) { UserConstantPool* ctpInfo = cl->getConstantPool(); mvm::Allocator* allocator = cl->classLoader->allocator; Enveloppe* enveloppe = new(allocator) Enveloppe(ctpInfo, index); @@ -593,7 +613,7 @@ return (void*)enveloppe; } -extern "C" void* staticCtpLookup(UserClass* cl, uint32 index) { +extern "C" void* jnjvmStaticCtpLookup(UserClass* cl, uint32 index) { UserConstantPool* ctpInfo = cl->getConstantPool(); JavaConstantPool* shared = ctpInfo->getSharedPool(); uint32 clIndex = shared->getClassIndexFromMethod(index); @@ -612,9 +632,9 @@ return (void*)methodCl->getConstantPool(); } -extern "C" UserConstantPool* specialCtpLookup(UserConstantPool* ctpInfo, - uint32 index, - UserConstantPool** res) { +extern "C" UserConstantPool* jnjvmSpecialCtpLookup(UserConstantPool* ctpInfo, + uint32 index, + UserConstantPool** res) { JavaConstantPool* shared = ctpInfo->getSharedPool(); uint32 clIndex = shared->getClassIndexFromMethod(index); UserClass* refCl = (UserClass*)ctpInfo->loadClass(clIndex); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Thu Apr 23 07:07:08 2009 @@ -141,6 +141,7 @@ Class* Classpath::StackOverflowError; Class* Classpath::UnknownError; Class* Classpath::ClassNotFoundException; +Class* Classpath::ArithmeticException; JavaMethod* Classpath::InitInvocationTargetException; JavaMethod* Classpath::InitArrayStoreException; @@ -172,6 +173,7 @@ JavaMethod* Classpath::InitStackOverflowError; JavaMethod* Classpath::InitUnknownError; JavaMethod* Classpath::InitClassNotFoundException; +JavaMethod* Classpath::InitArithmeticException; JavaMethod* Classpath::InitObject; JavaMethod* Classpath::ErrorWithExcpNoClassDefFoundError; @@ -538,6 +540,7 @@ UPCALL_CLASS_EXCEPTION(loader, StackOverflowError); UPCALL_CLASS_EXCEPTION(loader, UnknownError); UPCALL_CLASS_EXCEPTION(loader, ClassNotFoundException); + UPCALL_CLASS_EXCEPTION(loader, ArithmeticException); UPCALL_METHOD_EXCEPTION(loader, InvocationTargetException); UPCALL_METHOD_EXCEPTION(loader, ArrayStoreException); @@ -569,6 +572,7 @@ UPCALL_METHOD_EXCEPTION(loader, StackOverflowError); UPCALL_METHOD_EXCEPTION(loader, UnknownError); UPCALL_METHOD_EXCEPTION(loader, ClassNotFoundException); + UPCALL_METHOD_EXCEPTION(loader, ArithmeticException); UPCALL_METHOD_WITH_EXCEPTION(loader, NoClassDefFoundError); UPCALL_METHOD_WITH_EXCEPTION(loader, ExceptionInInitializerError); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h Thu Apr 23 07:07:08 2009 @@ -173,6 +173,7 @@ ISOLATE_STATIC UserClass* StackOverflowError; ISOLATE_STATIC UserClass* UnknownError; ISOLATE_STATIC UserClass* ClassNotFoundException; + ISOLATE_STATIC UserClass* ArithmeticException; ISOLATE_STATIC JavaMethod* InitInvocationTargetException; ISOLATE_STATIC JavaMethod* InitArrayStoreException; @@ -204,6 +205,7 @@ ISOLATE_STATIC JavaMethod* InitStackOverflowError; ISOLATE_STATIC JavaMethod* InitUnknownError; ISOLATE_STATIC JavaMethod* InitClassNotFoundException; + ISOLATE_STATIC JavaMethod* InitArithmeticException; ISOLATE_STATIC JavaMethod* InitObject; Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Apr 23 07:07:08 2009 @@ -314,6 +314,11 @@ upcalls->InitNegativeArraySizeException, 0); } +JavaObject* Jnjvm::CreateArithmeticException() { + return CreateError(upcalls->ArithmeticException, + upcalls->InitArithmeticException, "/ by zero"); +} + JavaObject* Jnjvm::CreateNullPointerException() { return CreateError(upcalls->NullPointerException, upcalls->InitNullPointerException, 0); @@ -881,6 +886,7 @@ LOAD_CLASS(upcalls->StackOverflowError); LOAD_CLASS(upcalls->UnknownError); LOAD_CLASS(upcalls->ClassNotFoundException); + LOAD_CLASS(upcalls->ArithmeticException); #undef LOAD_CLASS loadAppClassLoader(); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=69887&r1=69886&r2=69887&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Thu Apr 23 07:07:08 2009 @@ -253,6 +253,7 @@ JavaObject* CreateClassCastException(JavaObject* obj, UserCommonClass* cl); JavaObject* CreateLinkageError(const char* msg = ""); JavaObject* CreateArrayStoreException(JavaVirtualTable* VT); + JavaObject* CreateArithmeticException(); /// Exceptions - These are the only exceptions VMKit will make. /// From nicolas.geoffray at lip6.fr Thu Apr 23 06:17:50 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 13:17:50 -0000 Subject: [vmkit-commits] [vmkit] r69888 - /vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904231317.n3NDHubh005027@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 08:17:31 2009 New Revision: 69888 URL: http://llvm.org/viewvc/llvm-project?rev=69888&view=rev Log: Fix field index of delegatee. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69888&r1=69887&r2=69888&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Thu Apr 23 08:17:31 2009 @@ -591,7 +591,7 @@ std::vector TempElmts; // delegatee - const ArrayType* ATy = dyn_cast(STy->getContainedType(2)); + const ArrayType* ATy = dyn_cast(STy->getContainedType(0)); assert(ATy && "Malformed type"); Constant* TCM[1] = { getJavaClass(cl) }; From nicolas.geoffray at lip6.fr Thu Apr 23 06:59:19 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 13:59:19 -0000 Subject: [vmkit-commits] [vmkit] r69889 - /vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp Message-ID: <200904231359.n3NDxMRT006466@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 08:58:59 2009 New Revision: 69889 URL: http://llvm.org/viewvc/llvm-project?rev=69889&view=rev Log: The module provider should never try to initialise a class. Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp?rev=69889&r1=69888&r2=69889&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp Thu Apr 23 08:58:59 2009 @@ -122,9 +122,7 @@ "The method's offset is greater than the virtual table size"); ((void**)meth->classDef->virtualVT)[offset] = val; } else { -#ifndef ISOLATE_SHARING - meth->classDef->initialiseClass(JavaThread::get()->getJVM()); -#endif + assert(meth->classDef->isInitializing() && "Class not ready"); } return false; From nicolas.geoffray at lip6.fr Thu Apr 23 07:29:21 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 14:29:21 -0000 Subject: [vmkit-commits] [vmkit] r69890 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h include/mvm/JIT.h include/mvm/Threads/Thread.h lib/JnJVM/Classpath/ClasspathReflect.h lib/JnJVM/Classpath/ClasspathVMThrowable.cpp lib/JnJVM/Compiler/JavaJIT.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/LLVMRuntime/runtime-default.ll lib/JnJVM/VMCore/JavaRuntimeJIT.cpp lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h lib/Mvm/Compiler/JIT.cpp Message-ID: <200904231429.n3NETOiA007406@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 09:29:04 2009 New Revision: 69890 URL: http://llvm.org/viewvc/llvm-project?rev=69890&view=rev Log: Implement stack overflow checks in Java code. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/include/mvm/JIT.h vmkit/trunk/include/mvm/Threads/Thread.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Thu Apr 23 09:29:04 2009 @@ -333,6 +333,7 @@ llvm::Function* IndexOutOfBoundsExceptionFunction; llvm::Function* ClassCastExceptionFunction; llvm::Function* OutOfMemoryErrorFunction; + llvm::Function* StackOverflowErrorFunction; llvm::Function* NegativeArraySizeExceptionFunction; llvm::Function* ArrayStoreExceptionFunction; llvm::Function* ArithmeticExceptionFunction; Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Thu Apr 23 09:29:04 2009 @@ -152,6 +152,7 @@ static llvm::Constant* constantPtrNull; static llvm::ConstantInt* constantPtrSize; static llvm::ConstantInt* constantThreadIDMask; + static llvm::ConstantInt* constantStackOverflowMask; static llvm::ConstantInt* constantFatMask; static llvm::ConstantInt* constantPtrOne; static llvm::ConstantInt* constantPtrZero; Modified: vmkit/trunk/include/mvm/Threads/Thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Thread.h (original) +++ vmkit/trunk/include/mvm/Threads/Thread.h Thu Apr 23 09:29:04 2009 @@ -185,6 +185,12 @@ /// static const uint64_t IDMask = 0x7FF00000; + /// OverflowMask - Apply this mask to implement overflow checks. For + /// efficiency, we lower the available size of the stack: it can never go + /// under 0xC0000 + /// + static const uint64_t StackOverflowMask = 0xC0000; + /// operator new - Allocate the Thread object as well as the stack for this /// Thread. The thread object is inlined in the stack. /// Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h Thu Apr 23 09:29:04 2009 @@ -17,6 +17,8 @@ #include #include +extern "C" jnjvm::JavaObject* internalFillInStackTrace(jnjvm::JavaObject*); + namespace jnjvm { class JavaObjectClass : public JavaObject { @@ -130,6 +132,22 @@ }; + +class JavaObjectThrowable : public JavaObject { +private: + JavaObject* detailedMessage; + JavaObject* cause; + JavaObject* stackTrace; + JavaObject* vmState; + +public: + void fillInStackTrace() { + cause = this; + vmState = internalFillInStackTrace(this); + stackTrace = 0; + } +}; + } #endif Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp Thu Apr 23 09:29:04 2009 @@ -27,17 +27,7 @@ extern "C" { -JNIEXPORT jobject JNICALL Java_java_lang_VMThrowable_fillInStackTrace( -#ifdef NATIVE_JNI -JNIEnv *env, -jclass clazz, -#endif -jobject throwable) { - - jobject res = 0; - - BEGIN_NATIVE_EXCEPTION(0) - +JavaObject* internalFillInStackTrace(JavaObject* throwable) { JavaThread* th = JavaThread::get(); Jnjvm* vm = th->getJVM(); @@ -51,7 +41,21 @@ JavaObject* vmThrowable = vm->upcalls->newVMThrowable->doNew(vm); uint64 ptr = (uint64)vmThrowable + vm->upcalls->vmDataVMThrowable->ptrOffset; ((JavaObject**)ptr)[0] = (JavaObject*)stack; - res = (jobject)vmThrowable; + return vmThrowable; +} + +JNIEXPORT jobject JNICALL Java_java_lang_VMThrowable_fillInStackTrace( +#ifdef NATIVE_JNI +JNIEnv *env, +jclass clazz, +#endif +jobject throwable) { + + jobject res = 0; + + BEGIN_NATIVE_EXCEPTION(0) + + res = (jobject)internalFillInStackTrace((JavaObject*)throwable); END_NATIVE_EXCEPTION Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Thu Apr 23 09:29:04 2009 @@ -761,6 +761,7 @@ objectLocals.push_back(new AllocaInst(module->JavaObjectType, "", currentBlock)); } + uint32 index = 0; uint32 count = 0; @@ -878,8 +879,30 @@ endNode = llvm::PHINode::Create(returnType, "", endBlock); } + + if (isSynchro(compilingMethod->access)) beginSynchronize(); + + // Variables have been allocated and the lock has been taken. Do the stack + // check now: if there is an exception, we will go to the lock release code. + currentExceptionBlock = opcodeInfos[0].exceptionBlock; + Value* FrameAddr = CallInst::Create(module->llvm_frameaddress, + module->constantZero, "", currentBlock); + FrameAddr = new PtrToIntInst(FrameAddr, module->pointerSizeType, "", + currentBlock); + Value* stackCheck = + BinaryOperator::CreateAnd(FrameAddr, module->constantStackOverflowMask, "", + currentBlock); + + stackCheck = new ICmpInst(ICmpInst::ICMP_EQ, stackCheck, + module->constantPtrZero, "", currentBlock); + BasicBlock* stackOverflow = createBasicBlock("stack overflow"); + BasicBlock* noStackOverflow = createBasicBlock("no stack overflow"); + BranchInst::Create(stackOverflow, noStackOverflow, stackCheck, currentBlock); + currentBlock = stackOverflow; + throwException(module->StackOverflowErrorFunction, 0, 0); + currentBlock = noStackOverflow; compileOpcodes(&compilingClass->bytes->elements[start], codeLen); Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Thu Apr 23 09:29:04 2009 @@ -374,6 +374,7 @@ NegativeArraySizeExceptionFunction = module->getFunction("jnjvmNegativeArraySizeException"); OutOfMemoryErrorFunction = module->getFunction("jnjvmOutOfMemoryError"); + StackOverflowErrorFunction = module->getFunction("jnjvmStackOverflowError"); ArrayStoreExceptionFunction = module->getFunction("jnjvmArrayStoreException"); ArithmeticExceptionFunction = module->getFunction("jnjvmArithmeticException"); Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Thu Apr 23 09:29:04 2009 @@ -215,6 +215,7 @@ declare %JavaObject* @jnjvmIndexOutOfBoundsException(%JavaObject*, i32) declare %JavaObject* @jnjvmNegativeArraySizeException(i32) declare %JavaObject* @jnjvmOutOfMemoryError(i32) +declare %JavaObject* @jnjvmStackOverflowError() declare %JavaObject* @jnjvmArrayStoreException(%VT*) declare %JavaObject* @jnjvmArithmeticException() declare void @jnjvmThrowException(%JavaObject*) Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Thu Apr 23 09:29:04 2009 @@ -480,6 +480,26 @@ } // Creates a Java object and then throws it. +extern "C" JavaObject* jnjvmStackOverflowError() { + JavaObject *exc = 0; + JavaThread *th = JavaThread::get(); + + BEGIN_NATIVE_EXCEPTION(1) + + exc = th->getJVM()->CreateStackOverflowError(); + + END_NATIVE_EXCEPTION + +#ifdef DWARF_EXCEPTIONS + th->throwException(exc); +#else + th->pendingException = exc; +#endif + + return exc; +} + +// Creates a Java object and then throws it. extern "C" JavaObject* jnjvmArithmeticException() { JavaObject *exc = 0; JavaThread *th = JavaThread::get(); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Apr 23 09:29:04 2009 @@ -330,6 +330,13 @@ "Java heap space"); } +JavaObject* Jnjvm::CreateStackOverflowError() { + // Don't call init, or else we'll get a new stack overflow error. + JavaObject* obj = upcalls->StackOverflowError->doNew(this); + ((JavaObjectThrowable*)obj)->fillInStackTrace(); + return obj; +} + JavaObject* Jnjvm::CreateArrayStoreException(JavaVirtualTable* VT) { return CreateError(upcalls->ArrayStoreException, upcalls->InitArrayStoreException, @@ -939,8 +946,8 @@ upcalls->uncaughtException->invokeIntSpecial(this, upcalls->threadGroup, group, obj, exc); }catch(...) { - fprintf(stderr, "Even uncaught exception throwed an exception!\n"); - abort(); + fprintf(stderr, "Exception in thread \"main\": " + "Can not print stack trace.\n"); } } } Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Thu Apr 23 09:29:04 2009 @@ -254,6 +254,7 @@ JavaObject* CreateLinkageError(const char* msg = ""); JavaObject* CreateArrayStoreException(JavaVirtualTable* VT); JavaObject* CreateArithmeticException(); + JavaObject* CreateStackOverflowError(); /// Exceptions - These are the only exceptions VMKit will make. /// Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=69890&r1=69889&r2=69890&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Thu Apr 23 09:29:04 2009 @@ -117,6 +117,8 @@ constantDoubleMinusZero = ConstantFP::get(Type::DoubleTy, -0.0); constantFloatMinusZero = ConstantFP::get(Type::FloatTy, -0.0f); constantThreadIDMask = ConstantInt::get(pointerSizeType, mvm::Thread::IDMask); + constantStackOverflowMask = + ConstantInt::get(pointerSizeType, mvm::Thread::StackOverflowMask); constantFatMask = ConstantInt::get(pointerSizeType, pointerSizeType == Type::Int32Ty ? 0x80000000 : 0x8000000000000000LL); constantPtrOne = ConstantInt::get(pointerSizeType, 1); @@ -236,6 +238,7 @@ llvm::Constant* MvmModule::constantPtrNull; llvm::ConstantInt* MvmModule::constantPtrSize; llvm::ConstantInt* MvmModule::constantThreadIDMask; +llvm::ConstantInt* MvmModule::constantStackOverflowMask; llvm::ConstantInt* MvmModule::constantFatMask; llvm::ConstantInt* MvmModule::constantPtrOne; llvm::ConstantInt* MvmModule::constantPtrZero; From nicolas.geoffray at lip6.fr Thu Apr 23 12:06:09 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 19:06:09 -0000 Subject: [vmkit-commits] [vmkit] r69906 - in /vmkit/trunk/lib/Mvm: CommonThread/ctthread.cpp Runtime/Sigsegv.cpp Message-ID: <200904231906.n3NJ69XG016613@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 14:06:08 2009 New Revision: 69906 URL: http://llvm.org/viewvc/llvm-project?rev=69906&view=rev Log: Catch and diagnose SIGSEGV errors. This will work when LLVM will stop registering its handler during a function pass. Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=69906&r1=69905&r2=69906&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Thu Apr 23 14:06:08 2009 @@ -13,7 +13,7 @@ #include "mvm/Threads/Thread.h" #include -#include +#include #include #include #include @@ -134,6 +134,14 @@ /// machine specific. StackThreadManager TheStackManager; +extern void sigsegvHandler(int, siginfo_t*, void*); + +void coucou(int* a) { + int * blah = (int*)alloca(16); + blah[0] = 3; + a[1] = 2; + coucou(blah); +} /// internalThreadStart - The initial function called by a thread. Sets some /// thread specific data, registers the thread to the GC and calls the @@ -141,6 +149,25 @@ /// void Thread::internalThreadStart(mvm::Thread* th) { th->baseSP = (void*)&th; + + // Set an alternate stack for handling stack overflows from VM code. + stack_t sigsegvStack; + sigsegvStack.ss_size = getpagesize(); + sigsegvStack.ss_flags = 0; + sigsegvStack.ss_sp = (void*)th; + sigaltstack(&sigsegvStack, NULL); + + // Set the SIGSEGV handler to diagnose errors. + struct sigaction sa; + sigset_t mask; + sigfillset(&mask); + sa.sa_flags = SA_ONSTACK | SA_SIGINFO; + sa.sa_mask = mask; + sa.sa_sigaction = sigsegvHandler; + sigaction(SIGSEGV, &sa, NULL); + + coucou((int*)alloca(16)); + #ifdef ISOLATE assert(th->MyVM && "VM not set in a thread"); th->IsolateID = th->MyVM->IsolateID; @@ -151,6 +178,8 @@ } + + /// start - Called by the creator of the thread to run the new thread. /// The thread is in a detached state, because each virtual machine has /// its own way of waiting for created threads. Modified: vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp?rev=69906&r1=69905&r2=69906&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp Thu Apr 23 14:06:08 2009 @@ -1,6 +1,6 @@ //===----------- Sigsegv.cc - Sigsegv default handling --------------------===// // -// The Micro Virtual Machine +// The VMKit project // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// -#include "MvmGC.h" +#include "mvm/VirtualMachine.h" #include "mvm/Threads/Thread.h" #include @@ -16,14 +16,12 @@ using namespace mvm; -void (*client_sigsegv_handler)(int, void *) = 0; - #if defined(__MACH__) && defined(__i386__) #include "ucontext.h" #endif -void sigsegv_handler(int n, siginfo_t *_info, void *context) { - void *addr = _info->si_addr; +void sigsegvHandler(int n, siginfo_t *_info, void *context) { + uintptr_t addr = (uintptr_t)_info->si_addr; #if defined(__i386__) struct frame { struct frame *caller; @@ -47,16 +45,20 @@ caller->ip = (void *)((ucontext_t*)context)->uc_mcontext.gregs[REG_EIP]; #endif #endif - - /* Free the GC if it sisgegv'd. No other collection is possible */ - Collector::die_if_sigsegv_occured_during_collection(addr); - - // sys_exit(0); - if(client_sigsegv_handler) - client_sigsegv_handler(n, addr); - else - signal(SIGSEGV, SIG_DFL); - + + mvm::Thread* th = mvm::Thread::get(); + if (addr > (uintptr_t)th->getThreadID() && addr < (uintptr_t)th->baseSP) { + fprintf(stderr, "Stack overflow in VM code or in JNI code. If it is from\n" + "the VM, it is either from the JIT, the GC or the runtime." + "\nThis has to be fixed in the VM: VMKit makes sure that\n" + "the bottom of the stack is always available when entering" + "\nthe VM.\n"); + } else { + fprintf(stderr, "I received a SIGSEGV: either the VM code or an external\n" + "native method is bogus. Aborting...\n"); + } + abort(); + #if defined(__i386__) caller->ip = caller_ip; /* restore the caller ip */ #endif From nicolas.geoffray at lip6.fr Thu Apr 23 12:08:05 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 19:08:05 -0000 Subject: [vmkit-commits] [vmkit] r69907 - in /vmkit/trunk/lib/Mvm: CommonThread/Sigsegv.cpp Runtime/Sigsegv.cpp Message-ID: <200904231908.n3NJ85RP016768@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 14:08:05 2009 New Revision: 69907 URL: http://llvm.org/viewvc/llvm-project?rev=69907&view=rev Log: Move the sigsegv handler to the CommonThread directory. Added: vmkit/trunk/lib/Mvm/CommonThread/Sigsegv.cpp - copied unchanged from r69906, vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp Removed: vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp Removed: vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp?rev=69906&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Sigsegv.cpp (removed) @@ -1,65 +0,0 @@ -//===----------- Sigsegv.cc - Sigsegv default handling --------------------===// -// -// The VMKit project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - - -#include "mvm/VirtualMachine.h" -#include "mvm/Threads/Thread.h" - -#include -#include - -using namespace mvm; - -#if defined(__MACH__) && defined(__i386__) -#include "ucontext.h" -#endif - -void sigsegvHandler(int n, siginfo_t *_info, void *context) { - uintptr_t addr = (uintptr_t)_info->si_addr; -#if defined(__i386__) - struct frame { - struct frame *caller; - void *ip; - }; - - /* my frame */ - struct frame *fp; - /* get it */ - asm ("mov %%ebp, %0" : "=&r"(fp)); - /* my caller */ - struct frame *caller = fp->caller; - /* preserve my caller if I return from the handler */ - void *caller_ip = caller->ip; - -#if defined(__MACH__) - //.gregs[REG_EIP]; /* just like it's on the stack.. */ - caller->ip = (void *)((ucontext_t*)context)->uc_mcontext->__ss.__eip; -#else - /* just like it's on the stack... */ - caller->ip = (void *)((ucontext_t*)context)->uc_mcontext.gregs[REG_EIP]; -#endif -#endif - - mvm::Thread* th = mvm::Thread::get(); - if (addr > (uintptr_t)th->getThreadID() && addr < (uintptr_t)th->baseSP) { - fprintf(stderr, "Stack overflow in VM code or in JNI code. If it is from\n" - "the VM, it is either from the JIT, the GC or the runtime." - "\nThis has to be fixed in the VM: VMKit makes sure that\n" - "the bottom of the stack is always available when entering" - "\nthe VM.\n"); - } else { - fprintf(stderr, "I received a SIGSEGV: either the VM code or an external\n" - "native method is bogus. Aborting...\n"); - } - abort(); - -#if defined(__i386__) - caller->ip = caller_ip; /* restore the caller ip */ -#endif -} From nicolas.geoffray at lip6.fr Thu Apr 23 13:03:40 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 20:03:40 -0000 Subject: [vmkit-commits] [vmkit] r69916 - /vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Message-ID: <200904232003.n3NK3eLX018603@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 15:03:40 2009 New Revision: 69916 URL: http://llvm.org/viewvc/llvm-project?rev=69916&view=rev Log: Wow, this should have never been there! Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=69916&r1=69915&r2=69916&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Thu Apr 23 15:03:40 2009 @@ -136,13 +136,6 @@ extern void sigsegvHandler(int, siginfo_t*, void*); -void coucou(int* a) { - int * blah = (int*)alloca(16); - blah[0] = 3; - a[1] = 2; - coucou(blah); -} - /// internalThreadStart - The initial function called by a thread. Sets some /// thread specific data, registers the thread to the GC and calls the /// given routine of th. @@ -166,8 +159,6 @@ sa.sa_sigaction = sigsegvHandler; sigaction(SIGSEGV, &sa, NULL); - coucou((int*)alloca(16)); - #ifdef ISOLATE assert(th->MyVM && "VM not set in a thread"); th->IsolateID = th->MyVM->IsolateID; From nicolas.geoffray at lip6.fr Thu Apr 23 14:24:03 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 23 Apr 2009 21:24:03 -0000 Subject: [vmkit-commits] [vmkit] r69920 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Message-ID: <200904232124.n3NLO4ow021477@zion.cs.uiuc.edu> Author: geoffray Date: Thu Apr 23 16:24:03 2009 New Revision: 69920 URL: http://llvm.org/viewvc/llvm-project?rev=69920&view=rev Log: Enable stack overflow check only of exceptions are enabled. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp?rev=69920&r1=69919&r2=69920&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJIT.cpp Thu Apr 23 16:24:03 2009 @@ -883,26 +883,29 @@ if (isSynchro(compilingMethod->access)) beginSynchronize(); - - // Variables have been allocated and the lock has been taken. Do the stack - // check now: if there is an exception, we will go to the lock release code. - currentExceptionBlock = opcodeInfos[0].exceptionBlock; - Value* FrameAddr = CallInst::Create(module->llvm_frameaddress, - module->constantZero, "", currentBlock); - FrameAddr = new PtrToIntInst(FrameAddr, module->pointerSizeType, "", - currentBlock); - Value* stackCheck = - BinaryOperator::CreateAnd(FrameAddr, module->constantStackOverflowMask, "", - currentBlock); - - stackCheck = new ICmpInst(ICmpInst::ICMP_EQ, stackCheck, - module->constantPtrZero, "", currentBlock); - BasicBlock* stackOverflow = createBasicBlock("stack overflow"); - BasicBlock* noStackOverflow = createBasicBlock("no stack overflow"); - BranchInst::Create(stackOverflow, noStackOverflow, stackCheck, currentBlock); - currentBlock = stackOverflow; - throwException(module->StackOverflowErrorFunction, 0, 0); - currentBlock = noStackOverflow; + + if (TheCompiler->hasExceptionsEnabled()) { + // Variables have been allocated and the lock has been taken. Do the stack + // check now: if there is an exception, we will go to the lock release code. + currentExceptionBlock = opcodeInfos[0].exceptionBlock; + Value* FrameAddr = CallInst::Create(module->llvm_frameaddress, + module->constantZero, "", currentBlock); + FrameAddr = new PtrToIntInst(FrameAddr, module->pointerSizeType, "", + currentBlock); + Value* stackCheck = + BinaryOperator::CreateAnd(FrameAddr, module->constantStackOverflowMask, + "", currentBlock); + + stackCheck = new ICmpInst(ICmpInst::ICMP_EQ, stackCheck, + module->constantPtrZero, "", currentBlock); + BasicBlock* stackOverflow = createBasicBlock("stack overflow"); + BasicBlock* noStackOverflow = createBasicBlock("no stack overflow"); + BranchInst::Create(stackOverflow, noStackOverflow, stackCheck, + currentBlock); + currentBlock = stackOverflow; + throwException(module->StackOverflowErrorFunction, 0, 0); + currentBlock = noStackOverflow; + } compileOpcodes(&compilingClass->bytes->elements[start], codeLen); From nicolas.geoffray at lip6.fr Fri Apr 24 04:31:36 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 24 Apr 2009 11:31:36 -0000 Subject: [vmkit-commits] [vmkit] r69966 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaUpcalls.cpp JavaUpcalls.h Jnjvm.cpp Jnjvm.h Message-ID: <200904241131.n3OBVqgf028271@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 24 06:30:54 2009 New Revision: 69966 URL: http://llvm.org/viewvc/llvm-project?rev=69966&view=rev Log: Factorize code for thread initialization. Modified: 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 Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=69966&r1=69965&r2=69966&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Fri Apr 24 06:30:54 2009 @@ -207,38 +207,43 @@ #endif -void Classpath::createInitialThread(Jnjvm* vm, JavaObject* th) { - JnjvmClassLoader* JCL = vm->bootstrapLoader; - JCL->loadName(newVMThread->getName(), true, true); - newVMThread->initialiseClass(vm); +void Classpath::CreateJavaThread(Jnjvm* vm, JavaThread* myth, + const char* thName, JavaObject* Group) { + JavaObject* th = newThread->doNew(vm); + myth->javaThread = th; JavaObject* vmth = newVMThread->doNew(vm); - name->setObjectField(th, (JavaObject*)vm->asciizToStr("main")); + + name->setObjectField(th, (JavaObject*)vm->asciizToStr(thName)); priority->setInt32Field(th, (uint32)1); daemon->setInt8Field(th, (uint32)0); vmThread->setObjectField(th, vmth); assocThread->setObjectField(vmth, th); running->setInt8Field(vmth, (uint32)1); + vmdataVMThread->setObjectField(vmth, (JavaObject*)myth); - JCL->loadName(threadGroup->getName(), true, true); - threadGroup->initialiseClass(vm); - void* Stat = threadGroup->getStaticInstance(); - JavaObject* RG = rootGroup->getObjectField(Stat); - group->setObjectField(th, RG); - groupAddThread->invokeIntSpecial(vm, threadGroup, RG, th); + group->setObjectField(th, Group); + groupAddThread->invokeIntSpecial(vm, threadGroup, Group, th); + + finaliseCreateInitialThread->invokeIntStatic(vm, inheritableThreadLocal, th); } -void Classpath::mapInitialThread(Jnjvm* vm) { - JnjvmClassLoader* JCL = vm->bootstrapLoader; - JCL->loadName(newThread->getName(), true, true); +void Classpath::InitializeThreading(Jnjvm* vm) { + // Resolve and initialize classes first. + newThread->resolveClass(); newThread->initialiseClass(vm); - JavaObject* th = newThread->doNew(vm); - createInitialThread(vm, th); - JavaThread* myth = JavaThread::get(); - myth->javaThread = th; - JavaObject* vmth = vmThread->getObjectField(th); - vmdataVMThread->setObjectField(vmth, (JavaObject*)myth); - finaliseCreateInitialThread->invokeIntStatic(vm, inheritableThreadLocal, th); + + newVMThread->resolveClass(); + newVMThread->initialiseClass(vm); + + threadGroup->resolveClass(); + threadGroup->initialiseClass(vm); + + // Create the main thread + void* Stat = threadGroup->getStaticInstance(); + JavaObject* RG = rootGroup->getObjectField(Stat); + assert(vm->getBootstrapThread() && "VM did not set its bootstrap thread"); + CreateJavaThread(vm, vm->getBootstrapThread(), "main", RG); } extern "C" JavaString* nativeInternString(JavaString* obj) { Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h?rev=69966&r1=69965&r2=69966&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h Fri Apr 24 06:30:54 2009 @@ -213,8 +213,6 @@ ISOLATE_STATIC JavaMethod* ErrorWithExcpExceptionInInitializerError; ISOLATE_STATIC JavaMethod* ErrorWithExcpInvocationTargetException; - ISOLATE_STATIC void createInitialThread(Jnjvm* vm, JavaObject* th); - ISOLATE_STATIC void mapInitialThread(Jnjvm* vm); ISOLATE_STATIC UserClassArray* ArrayOfByte; @@ -241,6 +239,13 @@ ISOLATE_STATIC JavaField* methodClass; ISOLATE_STATIC JavaField* fieldClass; ISOLATE_STATIC JavaField* constructorClass; + +private: + ISOLATE_STATIC void CreateJavaThread(Jnjvm* vm, JavaThread* myth, + const char* name, JavaObject* Group); + +public: + ISOLATE_STATIC void InitializeThreading(Jnjvm* vm); }; Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69966&r1=69965&r2=69966&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Fri Apr 24 06:30:54 2009 @@ -786,10 +786,6 @@ return appClassLoader; } -void Jnjvm::mapInitialThread() { - upcalls->mapInitialThread(this); -} - void Jnjvm::loadBootstrap() { JnjvmClassLoader* loader = bootstrapLoader; @@ -851,7 +847,7 @@ #endif // The initialization code of the classes initialized below may require // to get the Java thread, so we create the Java thread object first. - mapInitialThread(); + upcalls->InitializeThreading(this); LOAD_CLASS(upcalls->newStackTraceElement); LOAD_CLASS(upcalls->newVMThrowable); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=69966&r1=69965&r2=69966&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Fri Apr 24 06:30:54 2009 @@ -137,11 +137,6 @@ /// JnjvmClassLoader* loadAppClassLoader(); - /// mapInitialThread - Maps the initial native thread to a java/lang/Thread - /// object. - /// - void mapInitialThread(); - /// loadBootstrap - Bootstraps the JVM, getting the class loader, initializing /// bootstrap classes (e.g. java/lang/Class, java/lang/*Exception) and /// mapping the initial thread. @@ -307,6 +302,10 @@ /// setBootstrapThread - Set the bootstrap thread of this VM. /// void setBootstrapThread(JavaThread* th) { bootstrapThread = th; } + + /// getBootstrapThread - Get the bootstrap thread of this VM. + /// + JavaThread* getBootstrapThread() const { return bootstrapThread; } /// ~Jnjvm - Destroy the JVM. /// From nicolas.geoffray at lip6.fr Fri Apr 24 11:29:15 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 24 Apr 2009 18:29:15 -0000 Subject: [vmkit-commits] [vmkit] r69986 - /vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Message-ID: <200904241829.n3OITLhR011642@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 24 13:28:56 2009 New Revision: 69986 URL: http://llvm.org/viewvc/llvm-project?rev=69986&view=rev Log: Only static calls need an initialization check. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=69986&r1=69985&r2=69986&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Fri Apr 24 13:28:56 2009 @@ -58,10 +58,6 @@ #define INVOKE(TYPE, TYPE_NAME, FUNC_TYPE_VIRTUAL_AP, FUNC_TYPE_STATIC_AP, FUNC_TYPE_VIRTUAL_BUF, FUNC_TYPE_STATIC_BUF) \ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) { \ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ verifyNull(obj); \ Signdef* sign = getSignature(); \ uintptr_t buf = (uintptr_t)alloca(sign->nbArguments * sizeof(uint64)); \ @@ -81,11 +77,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ Signdef* sign = getSignature(); \ uintptr_t buf = (uintptr_t)alloca(sign->nbArguments * sizeof(uint64)); \ @@ -106,7 +97,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticAP(Jnjvm* vm, UserClass* cl, va_list ap) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ @@ -128,13 +119,7 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ - \ Signdef* sign = getSignature(); \ void* func = (((void***)obj)[0])[offset];\ JavaThread* th = JavaThread::get(); \ @@ -150,11 +135,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ @@ -172,7 +152,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticBuf(Jnjvm* vm, UserClass* cl, void* buf) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ @@ -219,11 +199,6 @@ #define INVOKE(TYPE, TYPE_NAME, FUNC_TYPE_VIRTUAL_AP, FUNC_TYPE_STATIC_AP, FUNC_TYPE_VIRTUAL_BUF, FUNC_TYPE_STATIC_BUF) \ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) { \ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj); \ void* func = (((void***)obj)[0])[offset];\ Signdef* sign = getSignature(); \ @@ -240,11 +215,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ @@ -262,7 +232,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticAP(Jnjvm* vm, UserClass* cl, va_list ap) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ @@ -281,11 +251,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = (((void***)obj)[0])[offset];\ Signdef* sign = getSignature(); \ @@ -302,11 +267,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ @@ -324,7 +284,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticBuf(Jnjvm* vm, UserClass* cl, void* buf) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ @@ -374,10 +334,6 @@ #define INVOKE(TYPE, TYPE_NAME, FUNC_TYPE_VIRTUAL_AP, FUNC_TYPE_STATIC_AP, FUNC_TYPE_VIRTUAL_BUF, FUNC_TYPE_STATIC_BUF) \ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) { \ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ verifyNull(obj); \ Signdef* sign = getSignature(); \ uintptr_t buf = (uintptr_t)alloca(sign->nbArguments * sizeof(uint64)); \ @@ -396,11 +352,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ Signdef* sign = getSignature(); \ uintptr_t buf = (uintptr_t)alloca(sign->nbArguments * sizeof(uint64)); \ @@ -420,7 +371,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticAP(Jnjvm* vm, UserClass* cl, va_list ap) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ @@ -441,13 +392,7 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ - \ Signdef* sign = getSignature(); \ void* func = (((void***)obj)[0])[offset];\ JavaThread* th = JavaThread::get(); \ @@ -462,11 +407,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ @@ -483,7 +423,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticBuf(Jnjvm* vm, UserClass* cl, void* buf) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ @@ -529,11 +469,6 @@ #define INVOKE(TYPE, TYPE_NAME, FUNC_TYPE_VIRTUAL_AP, FUNC_TYPE_STATIC_AP, FUNC_TYPE_VIRTUAL_BUF, FUNC_TYPE_STATIC_BUF) \ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) { \ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj); \ void* func = (((void***)obj)[0])[offset];\ Signdef* sign = getSignature(); \ @@ -549,11 +484,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ @@ -570,7 +500,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticAP(Jnjvm* vm, UserClass* cl, va_list ap) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ @@ -588,11 +518,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = (((void***)obj)[0])[offset];\ Signdef* sign = getSignature(); \ @@ -608,11 +533,6 @@ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ - if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ - cl->initialiseClass(vm); \ - } \ - \ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ @@ -629,7 +549,7 @@ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticBuf(Jnjvm* vm, UserClass* cl, void* buf) {\ if (!cl->isReady()) { \ - cl->classLoader->loadName(cl->getName(), true, true); \ + cl->resolveClass(); \ cl->initialiseClass(vm); \ } \ \ From nicolas.geoffray at lip6.fr Fri Apr 24 15:28:29 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 24 Apr 2009 22:28:29 -0000 Subject: [vmkit-commits] [vmkit] r69997 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904242228.n3OMSTtG020432@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 24 17:28:29 2009 New Revision: 69997 URL: http://llvm.org/viewvc/llvm-project?rev=69997&view=rev Log: Update initialization state if a class does not need initialization. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=69997&r1=69996&r2=69997&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Fri Apr 24 17:28:29 2009 @@ -906,14 +906,10 @@ loadExceptions(); if (!super) ClassArray::initialiseVT(this); - bool init = needsInitialisationCheck(); + bool needInit = needsInitialisationCheck(); acquire(); - if (!init) { - setInitializationState(ready); - } else { - setResolved(); - } + if (needInit) setResolved(); setOwnerClass(0); broadcastClass(); release(); @@ -1217,6 +1213,7 @@ if (meth) return true; + setInitializationState(ready); return false; } From nicolas.geoffray at lip6.fr Fri Apr 24 15:30:56 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 24 Apr 2009 22:30:56 -0000 Subject: [vmkit-commits] [vmkit] r69999 - in /vmkit/trunk: include/mvm/VirtualMachine.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/VMCore/JavaMetaJIT.cpp lib/JnJVM/VMCore/JavaString.cpp lib/JnJVM/VMCore/JavaUpcalls.cpp lib/JnJVM/VMCore/JavaUpcalls.h lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h lib/Mvm/BoehmGC/MvmGC.h lib/Mvm/GCMmap2/MvmGC.h lib/Mvm/GCMmap2/gc.cpp lib/Mvm/GCMmap2/gccollector.cpp lib/Mvm/GCMmap2/gccollector.h lib/Mvm/Runtime/Object.cpp Message-ID: <200904242230.n3OMUvth020541@zion.cs.uiuc.edu> Author: geoffray Date: Fri Apr 24 17:30:56 2009 New Revision: 69999 URL: http://llvm.org/viewvc/llvm-project?rev=69999&view=rev Log: Support for finalization in GCMmap2! Modified: vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaString.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/Mvm/BoehmGC/MvmGC.h vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h vmkit/trunk/lib/Mvm/Runtime/Object.cpp Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Fri Apr 24 17:30:56 2009 @@ -18,11 +18,23 @@ #include "mvm/Allocator.h" #include "mvm/CompilationUnit.h" #include "mvm/Object.h" +#include "mvm/Threads/Cond.h" #include "mvm/Threads/Locks.h" #include #include + +// Same values than JikesRVM +#define INITIAL_QUEUE_SIZE 256 +#define GROW_FACTOR 2 + +#if (__WORDSIZE == 64) +#define LOG_BYTES_IN_ADDRESS 3 +#else +#define LOG_BYTES_IN_ADDRESS 2 +#endif + namespace jnjvm { class JavaCompiler; class JnjvmClassLoader; @@ -46,6 +58,12 @@ status = 1; _since_last_collection = 4*1024*1024; #endif + + FinalizationQueue = new gc*[INITIAL_QUEUE_SIZE]; + QueueLength = INITIAL_QUEUE_SIZE; + + ToBeFinalized = new gc*[INITIAL_QUEUE_SIZE]; + ToBeFinalizedLength = INITIAL_QUEUE_SIZE; } public: @@ -102,6 +120,96 @@ return (T*)I->second; } +private: + /// FinalizationQueueLock - A lock to protect access to the queue. + /// + mvm::SpinLock FinalizationQueueLock; + + /// finalizationQueue - A list of allocated objets that contain a finalize + /// method. + /// + gc** FinalizationQueue; + + /// CurrentIndex - Current index in the queue of finalizable objects. + /// + uint32 CurrentIndex; + + /// QueueLength - Current length of the queue of finalizable objects. + /// + uint32 QueueLength; + + /// growQueue - Grow the queue of finalizable objects. + /// + void growQueue(); + + /// ToBeFinalized - List of objects that are scheduled to be finalized. + /// + gc** ToBeFinalized; + + /// ToBeFinalizedLength - Current length of the queue of objects scheduled + /// for finalization. + /// + uint32 ToBeFinalizedLength; + + /// CurrentFinalizedIndex - The current index in the ToBeFinalized queue + /// that will be sceduled for finalization. + /// + uint32 CurrentFinalizedIndex; + + /// LastFinalizedIndex - The last index in the ToBeFinalized queue whose + /// finalize method has been called. + /// + uint32 LastFinalizedIndex; + + /// finalizationCond - Condition variable to wake up finalization threads. + /// + mvm::Cond FinalizationCond; + + /// finalizationLock - Lock for the condition variable. + /// + mvm::LockNormal FinalizationLock; + + /// countFinalized - The number of entries to be finalized. + /// + uint32 countFinalized() { + return (LastFinalizedIndex - CurrentFinalizedIndex + ToBeFinalizedLength) + % ToBeFinalizedLength; + } + + /// freeFinalized - The number of entries available in the ToBeFinalized + /// queue. + /// + uint32 freeFinalized() { + return ToBeFinalizedLength - countFinalized(); + } + +protected: + /// invokeFinalizer - Invoke the finalizer of the object. This may involve + /// changing the environment, e.g. going to native to Java. + /// + virtual void invokeFinalizer(gc*) {} + + +public: + /// finalizerStart - The start function of a finalizer. Will poll the + /// finalizationQueue. + /// + static void finalizerStart(mvm::Thread*); + + /// addFinalizationCandidate - Add an object to the queue of objects with + /// a finalization method. + /// + void addFinalizationCandidate(gc*); + + /// scanFinalizationQueue - Scan objets with a finalized method and schedule + /// them for finalization if they are not live. + /// + void scanFinalizationQueue(); + + /// wakeUpFinalizers - Wake the finalizers. + /// + void wakeUpFinalizers() { FinalizationCond.broadcast(); } + #ifdef ISOLATE size_t IsolateID; #endif Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Fri Apr 24 17:30:56 2009 @@ -1637,7 +1637,7 @@ mvm::BumpPtrAllocator A; Jnjvm* vm = new(A) Jnjvm(A, (JnjvmBootstrapLoader*)JCL); JavaThread* th = new JavaThread(0, 0, vm); - vm->setBootstrapThread(th); + vm->setMainThread(th); th->start((void (*)(mvm::Thread*))mainCompilerStart); vm->waitForExit(); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Fri Apr 24 17:30:56 2009 @@ -15,6 +15,7 @@ #include "JavaObject.h" #include "JavaThread.h" #include "JavaTypes.h" +#include "JavaUpcalls.h" #include "Jnjvm.h" using namespace jnjvm; @@ -624,3 +625,11 @@ INVOKE(JavaObject*, JavaObject, object_virtual_ap, object_static_ap, object_virtual_buf, object_static_buf) #undef INVOKE + + +void Jnjvm::invokeFinalizer(gc* _obj) { + JavaObject* obj = (JavaObject*)_obj; + JavaMethod* meth = upcalls->FinalizeObject; + UserClass* cl = obj->getClass()->asClass(); + meth->invokeIntVirtualBuf(this, cl, obj, 0); +} Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp Fri Apr 24 17:30:56 2009 @@ -28,6 +28,10 @@ // internStringVT exists (in case of AOT). if (internStringVT) res->setVirtualTable(internStringVT); + // The GC did not have this info. Now we do, so inform the finalizers + // that this is a finalization candidate. + vm->addFinalizationCandidate(res); + // No need to call the Java function: both the Java function and // this function do the same thing. res->value = utf8; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Fri Apr 24 17:30:56 2009 @@ -38,7 +38,9 @@ JavaMethod* Classpath::finaliseCreateInitialThread; JavaMethod* Classpath::initVMThread; JavaMethod* Classpath::groupAddThread; -JavaField* Classpath::name; +JavaMethod* Classpath::initGroup; +JavaField* Classpath::groupName; +JavaField* Classpath::threadName; JavaField* Classpath::priority; JavaField* Classpath::daemon; JavaField* Classpath::group; @@ -175,6 +177,7 @@ JavaMethod* Classpath::InitClassNotFoundException; JavaMethod* Classpath::InitArithmeticException; JavaMethod* Classpath::InitObject; +JavaMethod* Classpath::FinalizeObject; JavaMethod* Classpath::ErrorWithExcpNoClassDefFoundError; JavaMethod* Classpath::ErrorWithExcpExceptionInInitializerError; @@ -214,7 +217,7 @@ myth->javaThread = th; JavaObject* vmth = newVMThread->doNew(vm); - name->setObjectField(th, (JavaObject*)vm->asciizToStr(thName)); + threadName->setObjectField(th, (JavaObject*)vm->asciizToStr(thName)); priority->setInt32Field(th, (uint32)1); daemon->setInt8Field(th, (uint32)0); vmThread->setObjectField(th, vmth); @@ -239,11 +242,22 @@ threadGroup->resolveClass(); threadGroup->initialiseClass(vm); - // Create the main thread + // Create the main thread. void* Stat = threadGroup->getStaticInstance(); JavaObject* RG = rootGroup->getObjectField(Stat); - assert(vm->getBootstrapThread() && "VM did not set its bootstrap thread"); - CreateJavaThread(vm, vm->getBootstrapThread(), "main", RG); + assert(vm->getMainThread() && "VM did not set its bootstrap thread"); + CreateJavaThread(vm, vm->getMainThread(), "main", RG); + + // Create the "system" group. + JavaObject* SystemGroup = threadGroup->doNew(vm); + initGroup->invokeIntSpecial(vm, threadGroup, SystemGroup); + JavaObject* systemName = (JavaObject*)vm->asciizToStr("system"); + groupName->setObjectField(SystemGroup, systemName); + + // And create the finalizer thread. + assert(vm->getFinalizerThread() && "VM did not set its finalizer thread"); + CreateJavaThread(vm, vm->getFinalizerThread(), "Finalizer", SystemGroup); + } extern "C" JavaString* nativeInternString(JavaString* obj) { @@ -585,6 +599,9 @@ InitObject = UPCALL_METHOD(loader, "java/lang/Object", "", "()V", ACC_VIRTUAL); + + FinalizeObject = UPCALL_METHOD(loader, "java/lang/Object", "finalize", "()V", + ACC_VIRTUAL); newThread = UPCALL_CLASS(loader, "java/lang/Thread"); @@ -619,7 +636,15 @@ UPCALL_METHOD(loader, "java/lang/ThreadGroup", "addThread", "(Ljava/lang/Thread;)V", ACC_VIRTUAL); - name = + initGroup = + UPCALL_METHOD(loader, "java/lang/ThreadGroup", "", + "()V", ACC_VIRTUAL); + + groupName = + UPCALL_FIELD(loader, "java/lang/ThreadGroup", "name", "Ljava/lang/String;", + ACC_VIRTUAL); + + threadName = UPCALL_FIELD(loader, "java/lang/Thread", "name", "Ljava/lang/String;", ACC_VIRTUAL); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h Fri Apr 24 17:30:56 2009 @@ -131,7 +131,9 @@ ISOLATE_STATIC JavaMethod* initVMThread; ISOLATE_STATIC JavaMethod* runVMThread; ISOLATE_STATIC JavaMethod* groupAddThread; - ISOLATE_STATIC JavaField* name; + ISOLATE_STATIC JavaMethod* initGroup; + ISOLATE_STATIC JavaField* groupName; + ISOLATE_STATIC JavaField* threadName; ISOLATE_STATIC JavaField* priority; ISOLATE_STATIC JavaField* daemon; ISOLATE_STATIC JavaField* group; @@ -208,6 +210,7 @@ ISOLATE_STATIC JavaMethod* InitArithmeticException; ISOLATE_STATIC JavaMethod* InitObject; + ISOLATE_STATIC JavaMethod* FinalizeObject; ISOLATE_STATIC JavaMethod* ErrorWithExcpNoClassDefFoundError; ISOLATE_STATIC JavaMethod* ErrorWithExcpExceptionInInitializerError; Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Fri Apr 24 17:30:56 2009 @@ -814,6 +814,10 @@ JavaString::internStringVT->destructor = (uintptr_t)JavaString::stringDestructor; + + // Tell the finalizer that this is a native destructor. + JavaString::internStringVT->operatorDelete = + (uintptr_t)JavaString::stringDestructor; } upcalls->newString->initialiseClass(this); @@ -981,7 +985,7 @@ void Jnjvm::mainJavaStart(JavaThread* thread) { Jnjvm* vm = thread->getJVM(); - vm->bootstrapThread = thread; + vm->mainThread = thread; vm->loadBootstrap(); @@ -1062,8 +1066,11 @@ th->start(serviceCPUMonitor); #endif - bootstrapThread = new JavaThread(0, 0, this); - bootstrapThread->start((void (*)(mvm::Thread*))mainJavaStart); + finalizerThread = new JavaThread(0, 0, this); + finalizerThread->start((void (*)(mvm::Thread*))finalizerStart); + + mainThread = new JavaThread(0, 0, this); + mainThread->start((void (*)(mvm::Thread*))mainJavaStart); } else { threadSystem.nonDaemonThreads = 0; } Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Fri Apr 24 17:30:56 2009 @@ -113,10 +113,14 @@ private: - /// bootstrapThread - The initial thread of this JVM. + /// mainThread - The initial thread of this JVM. /// - JavaThread* bootstrapThread; + JavaThread* mainThread; + /// finalizerThread - The initial thread of this JVM. + /// + JavaThread* finalizerThread; + /// CreateError - Creates a Java object of the specified exception class /// and calling its function. /// @@ -301,11 +305,19 @@ /// setBootstrapThread - Set the bootstrap thread of this VM. /// - void setBootstrapThread(JavaThread* th) { bootstrapThread = th; } + void setMainThread(JavaThread* th) { mainThread = th; } /// getBootstrapThread - Get the bootstrap thread of this VM. /// - JavaThread* getBootstrapThread() const { return bootstrapThread; } + JavaThread* getMainThread() const { return mainThread; } + + /// setFinalizerThread - Set the first finalizer thread of this VM. + /// + void setFinalizerThread(JavaThread* th) { finalizerThread = th; } + + /// getFinalizerThread - Get the finalizer thread of this VM. + /// + JavaThread* getFinalizerThread() const { return finalizerThread; } /// ~Jnjvm - Destroy the JVM. /// @@ -348,6 +360,9 @@ virtual void stopService(); #endif +protected: + virtual void invokeFinalizer(gc*); + }; Modified: vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h (original) +++ vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h Fri Apr 24 17:30:56 2009 @@ -143,6 +143,10 @@ if(GC_get_heap_size() < size) GC_expand_hp(size - GC_get_heap_size()); } + + static bool isLive() { + return true; + } }; Modified: vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h Fri Apr 24 17:30:56 2009 @@ -87,6 +87,7 @@ static int getTotalMemory(void); static void setMaxMemory(size_t); static void setMinMemory(size_t); + static bool isLive(void* ptr); }; #endif Modified: vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp Fri Apr 24 17:30:56 2009 @@ -173,6 +173,10 @@ #endif } +bool Collector::isLive(void* ptr) { + return GCCollector::isLive(ptr); +} + void GCThread::waitCollection() { mvm::Thread* th = mvm::Thread::get(); unsigned int cm = GCCollector::current_mark; Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Fri Apr 24 17:30:56 2009 @@ -71,63 +71,31 @@ if(_marker) _marker(0); + + status = stat_finalize; +#ifdef HAVE_PTHREAD + threads->collectionFinished(); +#endif + Thread::get()->MyVM->scanFinalizationQueue(); + /* finalize */ GCChunkNode finalizable; finalizable.attrape(unused_nodes); - status = stat_alloc; - - unlock(); - /* kill everyone */ GCChunkNode *next = 0; - -#ifdef SERVICE - Thread* th = Thread::get(); - VirtualMachine* OldVM = th->MyVM; -#endif - - - for(cur=finalizable.next(); cur!=&finalizable; cur=next) { -#ifdef SERVICE - mvm::VirtualMachine* NewVM = cur->meta; - if (NewVM) { - NewVM->memoryUsed -= real_nbb(cur); - th->MyVM = NewVM; - th->IsolateID = NewVM->IsolateID; - } -#endif - register gc_header *c = cur->chunk(); - next = cur->next(); - - destructor_t dest = c->getDestructor(); - if (dest) { - try { - dest(c); - } catch(...) { - mvm::Thread::get()->clearException(); - } - } - } -#ifdef SERVICE - th->IsolateID = OldVM->IsolateID; - th->MyVM = OldVM; -#endif - - next = 0; for(cur=finalizable.next(); cur!=&finalizable; cur=next) { //printf(" !!!! reject %p [%p]\n", cur->chunk()->_2gc(), cur); next = cur->next(); allocator->reject_chunk(cur); } + status = stat_alloc; + + Thread::get()->MyVM->wakeUpFinalizers(); - lock(); -#ifdef HAVE_PTHREAD - threads->collectionFinished(); -#endif } void GCCollector::collect_unprotect() { Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h Fri Apr 24 17:30:56 2009 @@ -201,6 +201,10 @@ unlock(); + + if (vt->destructor) + mvm::Thread::get()->MyVM->addFinalizationCandidate((gc*)p->_2gc()); + return p->_2gc(); #endif } @@ -283,6 +287,13 @@ static inline bool isMarked(GCChunkNode *node) { return node->mark() == (current_mark & 1); } + + static bool isLive(void* ptr) { + GCChunkNode *node = o2node(ptr); + + if(node && isMarked(node)) return true; + else return false; + } static inline void mark(GCChunkNode *node) { node->_mark(current_mark & 1); Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=69999&r1=69998&r2=69999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Fri Apr 24 17:30:56 2009 @@ -14,6 +14,7 @@ #include "mvm/Allocator.h" #include "mvm/Object.h" #include "mvm/PrintBuffer.h" +#include "mvm/VirtualMachine.h" #include "mvm/Threads/Thread.h" using namespace mvm; @@ -128,3 +129,90 @@ } buf->write("\""); } + + +void VirtualMachine::finalizerStart(mvm::Thread* th) { + VirtualMachine* vm = th->MyVM; + + while (true) { + vm->FinalizationLock.lock(); + while (vm->CurrentFinalizedIndex == 0) { + vm->FinalizationCond.wait(&vm->FinalizationLock); + } + vm->FinalizationLock.unlock(); + + while (true) { + vm->FinalizationQueueLock.acquire(); + gc* res = 0; + if (vm->CurrentFinalizedIndex != 0) { + res = vm->ToBeFinalized[--vm->CurrentFinalizedIndex]; + } + vm->FinalizationQueueLock.release(); + if (!res) break; + + VirtualTable* VT = res->getVirtualTable(); + try { + if (VT->operatorDelete) { + // It's a native method! + destructor_t dest = (destructor_t)VT->destructor; + dest(res); + } else { + vm->invokeFinalizer(res); + } + } catch(...) { + } + } + } +} + +void VirtualMachine::growQueue() { + if (CurrentIndex >= QueueLength) { + uint32 newLength = QueueLength * GROW_FACTOR; + gc** newQueue = new gc*[newLength]; + for (uint32 i = 0; i < QueueLength; ++i) newQueue[i] = FinalizationQueue[i]; + FinalizationQueue = newQueue; + QueueLength = newLength; + + newLength = ToBeFinalizedLength * GROW_FACTOR; + newQueue = new gc*[newLength]; + for (uint32 i = 0; i < ToBeFinalizedLength; ++i) newQueue[i] = ToBeFinalized[i]; + ToBeFinalized = newQueue; + ToBeFinalizedLength = newLength; + } +} + + +void VirtualMachine::addFinalizationCandidate(gc* obj) { + FinalizationQueueLock.acquire(); + + if (CurrentIndex >= QueueLength) { + growQueue(); + } + + FinalizationQueue[CurrentIndex++] = obj; + FinalizationQueueLock.release(); +} + +void VirtualMachine::scanFinalizationQueue() { + FinalizationQueueLock.acquire(); + uint32 NewIndex = 0; + for (uint32 i = 0; i < CurrentIndex; ++i) { + gc* obj = FinalizationQueue[i]; + + if (!Collector::isLive(obj)) { + obj->markAndTrace(); + /* Add to object table */ + ToBeFinalized[CurrentFinalizedIndex++] = obj; + } else { + FinalizationQueue[NewIndex++] = obj; + } + } + CurrentIndex = NewIndex; + + for (uint32 i = 0; i < CurrentFinalizedIndex; ++i) { + gc* obj = ToBeFinalized[i]; + obj->markAndTrace(); + } + FinalizationQueueLock.release(); + +} From nicolas.geoffray at lip6.fr Sat Apr 25 07:44:48 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 25 Apr 2009 14:44:48 -0000 Subject: [vmkit-commits] [vmkit] r70045 - /vmkit/trunk/lib/Mvm/Runtime/Object.cpp Message-ID: <200904251444.n3PEim0P027647@zion.cs.uiuc.edu> Author: geoffray Date: Sat Apr 25 09:44:46 2009 New Revision: 70045 URL: http://llvm.org/viewvc/llvm-project?rev=70045&view=rev Log: Delete the previous tables after changing them. Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=70045&r1=70044&r2=70045&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sat Apr 25 09:44:46 2009 @@ -170,12 +170,14 @@ uint32 newLength = QueueLength * GROW_FACTOR; gc** newQueue = new gc*[newLength]; for (uint32 i = 0; i < QueueLength; ++i) newQueue[i] = FinalizationQueue[i]; + delete[] FinalizationQueue; FinalizationQueue = newQueue; QueueLength = newLength; newLength = ToBeFinalizedLength * GROW_FACTOR; newQueue = new gc*[newLength]; for (uint32 i = 0; i < ToBeFinalizedLength; ++i) newQueue[i] = ToBeFinalized[i]; + delete[] ToBeFinalized; ToBeFinalized = newQueue; ToBeFinalizedLength = newLength; } From nicolas.geoffray at lip6.fr Sun Apr 26 02:16:53 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 09:16:53 -0000 Subject: [vmkit-commits] [vmkit] r70119 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h include/mvm/VirtualMachine.h lib/JnJVM/Classpath/ClasspathReflect.h lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/VMCore/JavaMetaJIT.cpp lib/JnJVM/VMCore/JavaUpcalls.cpp lib/JnJVM/VMCore/JavaUpcalls.h lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h lib/Mvm/GCMmap2/gccollector.cpp lib/Mvm/Runtime/Object.cpp Message-ID: <200904260917.n3Q9H4hC010761@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 04:16:48 2009 New Revision: 70119 URL: http://llvm.org/viewvc/llvm-project?rev=70119&view=rev Log: Support for Weak/Soft/Phantom references in GCMmap2. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.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/Mvm/GCMmap2/gccollector.cpp vmkit/trunk/lib/Mvm/Runtime/Object.cpp Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sun Apr 26 04:16:48 2009 @@ -66,6 +66,7 @@ class LLVMClassInfo : public mvm::JITInfo { + friend class JavaAOTCompiler; friend class JavaJITCompiler; friend class JavaLLVMCompiler; private: Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Sun Apr 26 04:16:48 2009 @@ -42,13 +42,57 @@ namespace mvm { +class VirtualMachine; + +class ReferenceQueue { +private: + gc** References; + uint32 QueueLength; + uint32 CurrentIndex; + mvm::SpinLock QueueLock; + uint8_t semantics; + + gc* processReference(gc*, VirtualMachine*); +public: + + static const uint8_t WEAK = 1; + static const uint8_t SOFT = 2; + static const uint8_t PHANTOM = 3; + + ReferenceQueue(uint8_t s) { + References = new gc*[INITIAL_QUEUE_SIZE]; + QueueLength = INITIAL_QUEUE_SIZE; + CurrentIndex = 0; + semantics = s; + } + + void addReference(gc* ref) { + QueueLock.acquire(); + if (CurrentIndex >= QueueLength) { + uint32 newLength = QueueLength * GROW_FACTOR; + gc** newQueue = new gc*[newLength]; + for (uint32 i = 0; i < QueueLength; ++i) newQueue[i] = References[i]; + delete[] References; + References = newQueue; + QueueLength = newLength; + } + References[CurrentIndex++] = ref; + QueueLock.release(); + } + + void scan(VirtualMachine* vm); +}; + /// VirtualMachine - This class is the root of virtual machine classes. It /// defines what a VM should be. /// class VirtualMachine : public mvm::PermanentObject { protected: - VirtualMachine() { + VirtualMachine() : + WeakReferencesQueue(ReferenceQueue::WEAK), + SoftReferencesQueue(ReferenceQueue::SOFT), + PhantomReferencesQueue(ReferenceQueue::PHANTOM) { #ifdef SERVICE memoryLimit = ~0; executionLimit = ~0; @@ -64,6 +108,7 @@ ToBeFinalized = new gc*[INITIAL_QUEUE_SIZE]; ToBeFinalizedLength = INITIAL_QUEUE_SIZE; + } public: @@ -183,6 +228,18 @@ return ToBeFinalizedLength - countFinalized(); } + /// WeakReferencesQueue - The queue of weak references. + /// + ReferenceQueue WeakReferencesQueue; + + /// SoftReferencesQueue - The queue of soft references. + /// + ReferenceQueue SoftReferencesQueue; + + /// PhantomReferencesQueue - The queue of phantom references. + /// + ReferenceQueue PhantomReferencesQueue; + protected: /// invokeFinalizer - Invoke the finalizer of the object. This may involve /// changing the environment, e.g. going to native to Java. @@ -210,6 +267,60 @@ /// void wakeUpFinalizers() { FinalizationCond.broadcast(); } + /// scanWeakReferencesQueue - Scan all weak references. Called by the GC + /// before scanning the finalization queue. + /// + void scanWeakReferencesQueue() { + WeakReferencesQueue.scan(this); + } + + /// scanSoftReferencesQueue - Scan all soft references. Called by the GC + /// before scanning the finalization queue. + /// + void scanSoftReferencesQueue() { + SoftReferencesQueue.scan(this); + } + + /// scanPhantomReferencesQueue - Scan all phantom references. Called by the GC + /// after the finalization queue. + /// + void scanPhantomReferencesQueue() { + PhantomReferencesQueue.scan(this); + } + + /// addWeakReference - Add a weak reference to the queue. + /// + void addWeakReference(gc* ref) { + WeakReferencesQueue.addReference(ref); + } + + /// addSoftReference - Add a weak reference to the queue. + /// + void addSoftReference(gc* ref) { + SoftReferencesQueue.addReference(ref); + } + + /// addPhantomReference - Add a weak reference to the queue. + /// + void addPhantomReference(gc* ref) { + PhantomReferencesQueue.addReference(ref); + } + + /// clearReferent - Clear the referent in a reference. Should be overriden + /// by the VM. + /// + virtual void clearReferent(gc*) {} + + /// getReferent - Get the referent of the reference. Should be overriden + /// by the VM. + // + virtual gc* getReferent(gc*) { return 0; } + + /// enqueueReference - Calls the enqueue method. Should be overriden + /// by the VM. + /// + virtual bool enqueueReference(gc*) { return false; } + #ifdef ISOLATE size_t IsolateID; #endif Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h Sun Apr 26 04:16:48 2009 @@ -148,6 +148,27 @@ } }; +class JavaObjectReference : public JavaObject { +private: + JavaObject* referent; + JavaObject* queue; + JavaObject* nextOnQueue; + +public: + void init(JavaObject* r, JavaObject* q) { + referent = r; + queue = q; + } + + JavaObject* getReferent() const { return referent; } + void setReferent(JavaObject* r) { referent = r; } + + static void STATIC_TRACER(JavaObjectReference) { + obj->queue->MARK_AND_TRACE; + obj->nextOnQueue->MARK_AND_TRACE; + } +}; + } #endif Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 26 04:16:48 2009 @@ -138,18 +138,22 @@ assert(VT && "No VT was allocated!"); #ifdef WITH_TRACER - if (VT->init) { - // So the class is vmjc'ed. Create the virtual tracer. + if (VT->tracer) { + // So the class has a tracer because either a) the class was vmjced or + // b) the boot sequence has set it. Create the tracer as an external + // function. Function* func = Function::Create(JnjvmModule::MarkAndTraceType, GlobalValue::ExternalLinkage, - "markAndTraceObject", - getLLVMModule()); + "", getLLVMModule()); uintptr_t ptr = VT->tracer; JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr); LLVMClassInfo* LCI = getClassInfo(cl); LCI->virtualTracerFunction = func; + } + + if (VT->init) { // The VT hash already been filled by the AOT compiler so there // is nothing left to do! return; @@ -189,11 +193,13 @@ } #ifdef WITH_TRACER - Function* func = makeTracer(cl, false); + if (!VT->tracer) { + Function* func = makeTracer(cl, false); - void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func); - VT->tracer = (uintptr_t)codePtr; - func->deleteBody(); + void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func); + VT->tracer = (uintptr_t)codePtr; + func->deleteBody(); + } #endif } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Sun Apr 26 04:16:48 2009 @@ -633,3 +633,10 @@ UserClass* cl = obj->getClass()->asClass(); meth->invokeIntVirtualBuf(this, cl, obj, 0); } + +bool Jnjvm::enqueueReference(gc* _obj) { + JavaObject* obj = (JavaObject*)_obj; + JavaMethod* meth = upcalls->EnqueueReference; + UserClass* cl = obj->getClass()->asClass(); + return (bool)meth->invokeIntVirtualBuf(this, cl, obj, 0); +} Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Sun Apr 26 04:16:48 2009 @@ -208,6 +208,9 @@ JavaField* Classpath::fieldClass; JavaField* Classpath::constructorClass; +JavaMethod* Classpath::EnqueueReference; +Class* Classpath::newReference; + #endif void Classpath::CreateJavaThread(Jnjvm* vm, JavaThread* myth, @@ -336,6 +339,44 @@ extern "C" void nativePropertiesPostInit(JavaObject* prop); +extern "C" void nativeInitWeakReference(JavaObjectReference* reference, + JavaObject* referent) { + reference->init(referent, 0); + JavaThread::get()->getJVM()->addWeakReference(reference); + +} + +extern "C" void nativeInitWeakReferenceQ(JavaObjectReference* reference, + JavaObject* referent, + JavaObject* queue) { + reference->init(referent, queue); + JavaThread::get()->getJVM()->addWeakReference(reference); + +} + +extern "C" void nativeInitSoftReference(JavaObjectReference* reference, + JavaObject* referent) { + reference->init(referent, 0); + JavaThread::get()->getJVM()->addSoftReference(reference); + +} + +extern "C" void nativeInitSoftReferenceQ(JavaObjectReference* reference, + JavaObject* referent, + JavaObject* queue) { + reference->init(referent, queue); + JavaThread::get()->getJVM()->addSoftReference(reference); + +} + +extern "C" void nativeInitPhantomReferenceQ(JavaObjectReference* reference, + JavaObject* referent, + JavaObject* queue) { + reference->init(referent, queue); + JavaThread::get()->getJVM()->addPhantomReference(reference); + +} + void Classpath::initialiseClasspath(JnjvmClassLoader* loader) { newClassLoader = @@ -745,5 +786,64 @@ ACC_VIRTUAL); getAnnotations->setCompiledPtr((void*)(intptr_t)nativeGetDeclaredAnnotations, "nativeGetDeclaredAnnotations"); + + newReference = + loader->loadName(loader->asciizConstructUTF8("java/lang/ref/Reference"), + false, false); + + assert(!newReference->isResolved() && "Reference class already resolved"); + JavaVirtualTable* ptr = newReference->getVirtualVT(); + ptr->tracer = (uintptr_t)JavaObjectReference::staticTracer; + + EnqueueReference = + UPCALL_METHOD(loader, "java/lang/ref/Reference", "enqueue", "()Z", + ACC_VIRTUAL); + + JavaMethod* initWeakReference = + UPCALL_METHOD(loader, "java/lang/ref/WeakReference", "", + "(Ljava/lang/Object;)V", + ACC_VIRTUAL); + initWeakReference->setCompiledPtr((void*)(intptr_t)nativeInitWeakReference, + "nativeInitWeakReference"); + + initWeakReference = + UPCALL_METHOD(loader, "java/lang/ref/WeakReference", "", + "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V", + ACC_VIRTUAL); + initWeakReference->setCompiledPtr((void*)(intptr_t)nativeInitWeakReferenceQ, + "nativeInitWeakReferenceQ"); + + JavaMethod* initSoftReference = + UPCALL_METHOD(loader, "java/lang/ref/SoftReference", "", + "(Ljava/lang/Object;)V", + ACC_VIRTUAL); + initSoftReference->setCompiledPtr((void*)(intptr_t)nativeInitSoftReference, + "nativeInitSoftReference"); + + initSoftReference = + UPCALL_METHOD(loader, "java/lang/ref/WeakReference", "", + "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V", + ACC_VIRTUAL); + initSoftReference->setCompiledPtr((void*)(intptr_t)nativeInitSoftReferenceQ, + "nativeInitSoftReferenceQ"); + + JavaMethod* initPhantomReference = + UPCALL_METHOD(loader, "java/lang/ref/PhantomReference", "", + "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V", + ACC_VIRTUAL); + initPhantomReference->setCompiledPtr( + (void*)(intptr_t)nativeInitPhantomReferenceQ, + "nativeInitPhantomReferenceQ"); + + +} + +gc* Jnjvm::getReferent(gc* _obj) { + JavaObjectReference* obj = (JavaObjectReference*)_obj; + return obj->getReferent(); } +void Jnjvm::clearReferent(gc* _obj) { + JavaObjectReference* obj = (JavaObjectReference*)_obj; + obj->setReferent(0); +} Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h Sun Apr 26 04:16:48 2009 @@ -242,6 +242,9 @@ ISOLATE_STATIC JavaField* methodClass; ISOLATE_STATIC JavaField* fieldClass; ISOLATE_STATIC JavaField* constructorClass; + + ISOLATE_STATIC JavaMethod* EnqueueReference; + ISOLATE_STATIC Class* newReference; private: ISOLATE_STATIC void CreateJavaThread(Jnjvm* vm, JavaThread* myth, Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Apr 26 04:16:48 2009 @@ -845,7 +845,7 @@ LOAD_CLASS(upcalls->newVMThread); ptr = ((uintptr_t*)upcalls->newVMThread->getVirtualVT()); ptr[VT_DESTRUCTOR_OFFSET] = (uintptr_t)JavaObjectVMThread::staticDestructor; - + #ifdef SERVICE if (!IsolateID) #endif Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sun Apr 26 04:16:48 2009 @@ -363,6 +363,10 @@ protected: virtual void invokeFinalizer(gc*); +public: + virtual void clearReferent(gc*); + virtual gc* getReferent(gc*); + virtual bool enqueueReference(gc*); }; Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Sun Apr 26 04:16:48 2009 @@ -78,7 +78,17 @@ threads->collectionFinished(); #endif - Thread::get()->MyVM->scanFinalizationQueue(); + VirtualMachine* vm = Thread::get()->MyVM; + + // Scan soft and weak reference queues. + vm->scanWeakReferencesQueue(); + vm->scanSoftReferencesQueue(); + + // Scan finalization queue. + vm->scanFinalizationQueue(); + + // Now that the finalization queue has been scanned, scan the phantom queue. + vm->scanPhantomReferencesQueue(); /* finalize */ GCChunkNode finalizable; @@ -92,7 +102,8 @@ allocator->reject_chunk(cur); } status = stat_alloc; - + + // Collection finished. Wake up the finalizers if they are waiting. Thread::get()->MyVM->wakeUpFinalizers(); Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=70119&r1=70118&r2=70119&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sun Apr 26 04:16:48 2009 @@ -218,3 +218,44 @@ FinalizationQueueLock.release(); } + +gc* ReferenceQueue::processReference(gc* reference, VirtualMachine* vm) { + if (!Collector::isLive(reference)) { + vm->clearReferent(reference); + return 0; + } + + gc* referent = vm->getReferent(reference); + + if (!referent) return 0; + + if (semantics == SOFT) { + // TODO: are we are out of memory? Consider that we always are for now. + if (false) { + referent->markAndTrace(); + } + } else if (semantics == PHANTOM) { + // Nothing to do. + } + + if (Collector::isLive(referent)) { + return reference; + } else { + vm->clearReferent(reference); + vm->enqueueReference(reference); + return 0; + } +} + + +void ReferenceQueue::scan(VirtualMachine* vm) { + uint32 NewIndex = 0; + + for (uint32 i = 0; i < CurrentIndex; ++i) { + gc* obj = References[i]; + processReference(obj, vm); + } + + CurrentIndex = NewIndex; + +} From nicolas.geoffray at lip6.fr Sun Apr 26 02:51:56 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 09:51:56 -0000 Subject: [vmkit-commits] [vmkit] r70120 - /vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Message-ID: <200904260952.n3Q9q5Qt028935@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 04:51:21 2009 New Revision: 70120 URL: http://llvm.org/viewvc/llvm-project?rev=70120&view=rev Log: Invoke enqueue, directly. We do not want to call an overriden enqueue. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=70120&r1=70119&r2=70120&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Sun Apr 26 04:51:21 2009 @@ -638,5 +638,5 @@ JavaObject* obj = (JavaObject*)_obj; JavaMethod* meth = upcalls->EnqueueReference; UserClass* cl = obj->getClass()->asClass(); - return (bool)meth->invokeIntVirtualBuf(this, cl, obj, 0); + return (bool)meth->invokeIntSpecialBuf(this, cl, obj, 0); } From nicolas.geoffray at lip6.fr Sun Apr 26 04:41:54 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 11:41:54 -0000 Subject: [vmkit-commits] [vmkit] r70123 - in /vmkit/trunk: include/jnjvm/JavaCompiler.h include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/JavaUpcalls.cpp lib/JnJVM/VMCore/Jnjvm.cpp Message-ID: <200904261141.n3QBfxH2008072@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 06:41:24 2009 New Revision: 70123 URL: http://llvm.org/viewvc/llvm-project?rev=70123&view=rev Log: Change tracer and destructor of internal Java classes during classpath initialization, not jnjvm initialization. Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h vmkit/trunk/include/jnjvm/JnjvmModule.h vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/include/jnjvm/JavaCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JavaCompiler.h?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JavaCompiler.h (original) +++ vmkit/trunk/include/jnjvm/JavaCompiler.h Sun Apr 26 06:41:24 2009 @@ -18,6 +18,7 @@ class Class; class JavaMethod; +class JavaVirtualTable; class Signdef; class JavaCompiler { @@ -36,6 +37,15 @@ virtual void setMethod(JavaMethod* meth, void* ptr, const char* name) { } + virtual void setTracer(JavaVirtualTable* VT, uintptr_t ptr, + const char* name) { + } + + virtual void setDestructor(JavaVirtualTable* VT, uintptr_t ptr, + const char* name) { + } + + virtual bool isStaticCompiling() { return false; } Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sun Apr 26 06:41:24 2009 @@ -425,8 +425,11 @@ virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr) = 0; virtual void setMethod(JavaMethod* meth, void* ptr, const char* name) = 0; + virtual void setTracer(JavaVirtualTable* VT, uintptr_t ptr, + const char* name) = 0; + virtual void setDestructor(JavaVirtualTable* VT, uintptr_t ptr, + const char* name) = 0; - #ifdef SERVICE virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where) = 0; #endif @@ -490,6 +493,10 @@ virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr); virtual void setMethod(JavaMethod* meth, void* ptr, const char* name); + virtual void setTracer(JavaVirtualTable* VT, uintptr_t ptr, + const char* name); + virtual void setDestructor(JavaVirtualTable* VT, uintptr_t ptr, + const char* name); #ifdef SERVICE @@ -540,6 +547,10 @@ virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr); virtual void setMethod(JavaMethod* meth, void* ptr, const char* name); + virtual void setTracer(JavaVirtualTable* VT, uintptr_t ptr, + const char* name); + virtual void setDestructor(JavaVirtualTable* VT, uintptr_t ptr, + const char* name); #ifdef SERVICE Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Sun Apr 26 06:41:24 2009 @@ -1462,6 +1462,24 @@ func->setLinkage(GlobalValue::ExternalLinkage); } +void JavaAOTCompiler::setTracer(JavaVirtualTable* VT, uintptr_t ptr, + const char* name) { + 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; + VT->operatorDelete = (uintptr_t)name; +} + Function* JavaAOTCompiler::addCallback(Class* cl, uint16 index, Signdef* sign, bool stat) { Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 26 06:41:24 2009 @@ -212,6 +212,26 @@ func->setLinkage(GlobalValue::ExternalLinkage); } +void JavaJITCompiler::setTracer(JavaVirtualTable* VT, uintptr_t ptr, + const char* name) { + // So the class has a tracer because either a) the class was vmjced or + // b) the boot sequence has set it. Create the tracer as an external + // function. + Function* func = Function::Create(JnjvmModule::MarkAndTraceType, + GlobalValue::ExternalLinkage, + name, getLLVMModule()); + + JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr); + LLVMClassInfo* LCI = getClassInfo(VT->cl->asClass()); + LCI->virtualTracerFunction = func; +} + +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. +} + void* JavaJITCompiler::materializeFunction(JavaMethod* meth) { Function* func = parseFunction(meth); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sun Apr 26 06:41:24 2009 @@ -360,6 +360,17 @@ classDef->release(); } +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); +} + const char* JavaMethod::printString() const { mvm::PrintBuffer *buf= mvm::PrintBuffer::alloc(); buf->write("JavaMethod<"); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sun Apr 26 06:41:24 2009 @@ -196,6 +196,15 @@ /// bool isSubtypeOf(JavaVirtualTable* VT); + /// setNativeTracer - Set the tracer of this virtual table as a method + /// defined by JnJVM. + /// + void setNativeTracer(uintptr_t tracer, const char* name); + + /// setNativeDestructor - Set the destructor of this virtual table as a method + /// defined by JnJVM. + /// + void setNativeDestructor(uintptr_t tracer, const char* name); }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Sun Apr 26 06:41:24 2009 @@ -377,6 +377,30 @@ } +extern "C" void nativeJavaObjectClassTracer(JavaObjectClass* obj) { + JavaObjectClass::staticTracer(obj); +} + +extern "C" void nativeJavaObjectFieldTracer(JavaObjectField* obj) { + JavaObjectField::staticTracer(obj); +} + +extern "C" void nativeJavaObjectMethodTracer(JavaObjectMethod* obj) { + JavaObjectMethod::staticTracer(obj); +} + +extern "C" void nativeJavaObjectConstructorTracer(JavaObjectConstructor* obj) { + JavaObjectConstructor::staticTracer(obj); +} + +extern "C" void nativeJavaObjectReferenceTracer(JavaObjectReference* obj) { + JavaObjectReference::staticTracer(obj); +} + +extern "C" void nativeJavaObjectVMThreadDestructor(JavaObjectVMThread* obj) { + JavaObjectVMThread::staticDestructor(obj); +} + void Classpath::initialiseClasspath(JnjvmClassLoader* loader) { newClassLoader = @@ -787,6 +811,15 @@ getAnnotations->setCompiledPtr((void*)(intptr_t)nativeGetDeclaredAnnotations, "nativeGetDeclaredAnnotations"); +//===----------------------------------------------------------------------===// +// +// Weak/Soft/Phantom references support. We modify each constructor to register +// the reference to the VM. Also, the tracer of the Reference class is modified +// to not trace the referent. +// +//===----------------------------------------------------------------------===// + + newReference = loader->loadName(loader->asciizConstructUTF8("java/lang/ref/Reference"), false, false); @@ -835,7 +868,39 @@ (void*)(intptr_t)nativeInitPhantomReferenceQ, "nativeInitPhantomReferenceQ"); - + newReference->getVirtualVT()->setNativeTracer( + (uintptr_t)nativeJavaObjectReferenceTracer, + "nativeJavaObjectReferenceTracer"); + +//===----------------------------------------------------------------------===// +// +// To make classes non GC-allocated, we have to bypass the tracer functions of +// java.lang.Class, java.lang.reflect.Field, java.lang.reflect.Method and +// java.lang.reflect.constructor. The new tracer functions trace the classloader +// instead of the class/field/method. +// +//===----------------------------------------------------------------------===// + + newClass->getVirtualVT()->setNativeTracer( + (uintptr_t)nativeJavaObjectClassTracer, + "nativeJavaObjectClassTracer"); + + newConstructor->getVirtualVT()->setNativeTracer( + (uintptr_t)nativeJavaObjectConstructorTracer, + "nativeJavaObjectConstructorTracer"); + + newMethod->getVirtualVT()->setNativeTracer( + (uintptr_t)nativeJavaObjectMethodTracer, + "nativeJavaObjectMethodTracer"); + + newField->getVirtualVT()->setNativeTracer( + (uintptr_t)nativeJavaObjectFieldTracer, + "nativeJavaObjectFieldTracer"); + + + newVMThread->getVirtualVT()->setNativeDestructor( + (uintptr_t)nativeJavaObjectVMThreadDestructor, + "nativeJavaObjectVMThreadDestructorr"); } gc* Jnjvm::getReferent(gc* _obj) { Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=70123&r1=70122&r2=70123&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Apr 26 06:41:24 2009 @@ -820,32 +820,7 @@ (uintptr_t)JavaString::stringDestructor; } upcalls->newString->initialiseClass(this); - - // To make classes non GC-allocated, we have to bypass the tracer - // functions of java.lang.Class, java.lang.reflect.Field, - // java.lang.reflect.Method and java.lang.reflect.constructor. The new - // tracer functions trace the classloader instead of the class/field/method. - LOAD_CLASS(upcalls->newClass); - uintptr_t* ptr = ((uintptr_t*)upcalls->newClass->getVirtualVT()); - ptr[VT_TRACER_OFFSET] = (uintptr_t)JavaObjectClass::staticTracer; - - LOAD_CLASS(upcalls->newConstructor); - ptr = ((uintptr_t*)upcalls->newConstructor->getVirtualVT()); - ptr[VT_TRACER_OFFSET] = (uintptr_t)JavaObjectConstructor::staticTracer; - - - LOAD_CLASS(upcalls->newMethod); - ptr = ((uintptr_t*)upcalls->newMethod->getVirtualVT()); - ptr[VT_TRACER_OFFSET] = (uintptr_t)JavaObjectMethod::staticTracer; - - LOAD_CLASS(upcalls->newField); - ptr = ((uintptr_t*)upcalls->newField->getVirtualVT()); - ptr[VT_TRACER_OFFSET] = (uintptr_t)JavaObjectField::staticTracer; - - LOAD_CLASS(upcalls->newVMThread); - ptr = ((uintptr_t*)upcalls->newVMThread->getVirtualVT()); - ptr[VT_DESTRUCTOR_OFFSET] = (uintptr_t)JavaObjectVMThread::staticDestructor; - + #ifdef SERVICE if (!IsolateID) #endif @@ -853,6 +828,11 @@ // to get the Java thread, so we create the Java thread object first. upcalls->InitializeThreading(this); + LOAD_CLASS(upcalls->newClass); + LOAD_CLASS(upcalls->newConstructor); + LOAD_CLASS(upcalls->newField); + LOAD_CLASS(upcalls->newMethod); + LOAD_CLASS(upcalls->newVMThread); LOAD_CLASS(upcalls->newStackTraceElement); LOAD_CLASS(upcalls->newVMThrowable); LOAD_CLASS(upcalls->boolClass); From nicolas.geoffray at lip6.fr Sun Apr 26 06:28:15 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 13:28:15 -0000 Subject: [vmkit-commits] [vmkit] r70124 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/JITInfo.cpp lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/LLVMRuntime/runtime-multi-mmap.ll lib/JnJVM/LLVMRuntime/runtime-single-mmap.ll lib/JnJVM/VMCore/VirtualTables.cpp Message-ID: <200904261328.n3QDSGbZ011208@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 08:28:02 2009 New Revision: 70124 URL: http://llvm.org/viewvc/llvm-project?rev=70124&view=rev Log: Code changes when creating tracers. Optimize the case when there is nothing to trace. Modified: vmkit/trunk/include/jnjvm/JnjvmModule.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/LLVMRuntime/runtime-multi-mmap.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single-mmap.ll vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/include/jnjvm/JnjvmModule.h (original) +++ vmkit/trunk/include/jnjvm/JnjvmModule.h Sun Apr 26 08:28:02 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/lib/JnJVM/Compiler/JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp?rev=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Sun Apr 26 08:28:02 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=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Sun Apr 26 08:28:02 2009 @@ -1028,7 +1028,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 +1154,7 @@ Tracer = JavaIntrinsics.ArrayObjectTracerFunction; } } else if (classDef->isClass()) { - Tracer = makeTracer(classDef->asClass(), false); + Tracer = getClassInfo(classDef->asClass())->getVirtualTracer(); } Elemts.push_back(Tracer ? @@ -1241,7 +1242,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); @@ -1453,7 +1454,12 @@ 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,7 +1473,7 @@ Function* func = Function::Create(JnjvmModule::MarkAndTraceType, GlobalValue::ExternalLinkage, name, getLLVMModule()); - + LLVMClassInfo* LCI = getClassInfo(VT->cl->asClass()); LCI->virtualTracerFunction = func; } Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 26 08:28:02 2009 @@ -136,6 +136,8 @@ void JavaJITCompiler::makeVT(Class* cl) { JavaVirtualTable* VT = cl->virtualVT; assert(VT && "No VT was allocated!"); + + LLVMClassInfo* LCI = getClassInfo(cl); #ifdef WITH_TRACER if (VT->tracer) { @@ -148,7 +150,6 @@ uintptr_t ptr = VT->tracer; JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr); - LLVMClassInfo* LCI = getClassInfo(cl); LCI->virtualTracerFunction = func; } @@ -193,17 +194,29 @@ } #ifdef WITH_TRACER - if (!VT->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); Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Sun Apr 26 08:28:02 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/LLVMRuntime/runtime-multi-mmap.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-multi-mmap.ll?rev=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-multi-mmap.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-multi-mmap.ll Sun Apr 26 08:28:02 2009 @@ -6,3 +6,4 @@ declare void @JavaObjectTracer(%JavaObject*, i8*) declare void @JavaArrayTracer(%JavaObject*, i8*) declare void @ArrayObjectTracer(%JavaObject*, i8*) +declare void @EmptyTracer(%JavaObject*, i8*) Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single-mmap.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single-mmap.ll?rev=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single-mmap.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single-mmap.ll Sun Apr 26 08:28:02 2009 @@ -6,3 +6,4 @@ declare void @JavaObjectTracer(%JavaObject*) declare void @JavaArrayTracer(%JavaObject*) declare void @ArrayObjectTracer(%JavaObject*) +declare void @EmptyTracer(%JavaObject*) Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=70124&r1=70123&r2=70124&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Sun Apr 26 08:28:02 2009 @@ -65,6 +65,12 @@ #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: // (1) Object whose class is not an array: needs to trace the classloader and // the lock. @@ -156,8 +162,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); } } } From nicolas.geoffray at lip6.fr Sun Apr 26 07:30:42 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 14:30:42 -0000 Subject: [vmkit-commits] [vmkit] r70126 - /vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Message-ID: <200904261430.n3QEUjYd013019@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 09:30:22 2009 New Revision: 70126 URL: http://llvm.org/viewvc/llvm-project?rev=70126&view=rev Log: Only put the info in the operatorDelete. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=70126&r1=70125&r2=70126&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Sun Apr 26 09:30:22 2009 @@ -1480,9 +1480,8 @@ 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; } From nicolas.geoffray at lip6.fr Sun Apr 26 07:53:02 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 14:53:02 -0000 Subject: [vmkit-commits] [vmkit] r70127 - in /vmkit/trunk/lib/JnJVM: Compiler/JavaJITCompiler.cpp VMCore/JavaClass.cpp Message-ID: <200904261453.n3QEr4v4013774@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 09:52:55 2009 New Revision: 70127 URL: http://llvm.org/viewvc/llvm-project?rev=70127&view=rev Log: Let the compiler decide what it wants to do with the virtual table. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70127&r1=70126&r2=70127&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 26 09:52:55 2009 @@ -237,6 +237,7 @@ 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, Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=70127&r1=70126&r2=70127&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sun Apr 26 09:52:55 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); } From nicolas.geoffray at lip6.fr Sun Apr 26 08:10:23 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 15:10:23 -0000 Subject: [vmkit-commits] [vmkit] r70128 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Message-ID: <200904261510.n3QFAP5U014330@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 10:10:11 2009 New Revision: 70128 URL: http://llvm.org/viewvc/llvm-project?rev=70128&view=rev Log: Set the tracer when a class was vmjc'ed. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=70128&r1=70127&r2=70128&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sun Apr 26 10:10:11 2009 @@ -1047,6 +1047,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; } From nicolas.geoffray at lip6.fr Sun Apr 26 08:11:25 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 15:11:25 -0000 Subject: [vmkit-commits] [vmkit] r70129 - in /vmkit/trunk/lib/JnJVM/Compiler: JavaAOTCompiler.cpp JavaJITCompiler.cpp Message-ID: <200904261511.n3QFBPYT014379@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 10:11:24 2009 New Revision: 70129 URL: http://llvm.org/viewvc/llvm-project?rev=70129&view=rev Log: Don't forget to copy the finalizer from the super class. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=70129&r1=70128&r2=70129&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Sun Apr 26 10:11:24 2009 @@ -1448,6 +1448,7 @@ 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) { Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70129&r1=70128&r2=70129&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 26 10:11:24 2009 @@ -139,27 +139,11 @@ LLVMClassInfo* LCI = getClassInfo(cl); -#ifdef WITH_TRACER - if (VT->tracer) { - // So the class has a tracer because either a) the class was vmjced or - // b) the boot sequence has set it. Create the tracer as an external - // function. - Function* func = Function::Create(JnjvmModule::MarkAndTraceType, - GlobalValue::ExternalLinkage, - "", getLLVMModule()); - - uintptr_t ptr = VT->tracer; - JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr); - LCI->virtualTracerFunction = func; - - } - if (VT->init) { // 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. @@ -167,6 +151,7 @@ JavaVirtualTable::getFirstJavaMethodIndex(); memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(), size * sizeof(uintptr_t)); + VT->destructor = cl->super->virtualVT->destructor; } @@ -180,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); From nicolas.geoffray at lip6.fr Sun Apr 26 09:28:20 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 16:28:20 -0000 Subject: [vmkit-commits] [vmkit] r70130 - /vmkit/trunk/include/mvm/GC/GC.h Message-ID: <200904261628.n3QGSNGE017332@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 11:28:07 2009 New Revision: 70130 URL: http://llvm.org/viewvc/llvm-project?rev=70130&view=rev Log: Add a getter. Modified: vmkit/trunk/include/mvm/GC/GC.h Modified: vmkit/trunk/include/mvm/GC/GC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=70130&r1=70129&r2=70130&view=diff ============================================================================== --- vmkit/trunk/include/mvm/GC/GC.h (original) +++ vmkit/trunk/include/mvm/GC/GC.h Sun Apr 26 11:28:07 2009 @@ -54,7 +54,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; } }; From nicolas.geoffray at lip6.fr Sun Apr 26 09:29:02 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 16:29:02 -0000 Subject: [vmkit-commits] [vmkit] r70131 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Message-ID: <200904261629.n3QGT2uX017361@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 11:29:02 2009 New Revision: 70131 URL: http://llvm.org/viewvc/llvm-project?rev=70131&view=rev Log: It's the compiler job to set the destructor, not the VT. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70131&r1=70130&r2=70131&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 26 11:29:02 2009 @@ -225,8 +225,8 @@ 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) { From nicolas.geoffray at lip6.fr Sun Apr 26 09:30:52 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 16:30:52 -0000 Subject: [vmkit-commits] [vmkit] r70132 - /vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Message-ID: <200904261630.n3QGUqok017435@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 11:30:52 2009 New Revision: 70132 URL: http://llvm.org/viewvc/llvm-project?rev=70132&view=rev Log: Fix typo. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=70132&r1=70131&r2=70132&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Sun Apr 26 11:30:52 2009 @@ -900,7 +900,7 @@ newVMThread->getVirtualVT()->setNativeDestructor( (uintptr_t)nativeJavaObjectVMThreadDestructor, - "nativeJavaObjectVMThreadDestructorr"); + "nativeJavaObjectVMThreadDestructor"); } gc* Jnjvm::getReferent(gc* _obj) { From nicolas.geoffray at lip6.fr Sun Apr 26 09:36:50 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 16:36:50 -0000 Subject: [vmkit-commits] [vmkit] r70133 - /vmkit/trunk/lib/Mvm/Runtime/Object.cpp Message-ID: <200904261636.n3QGaoSa017605@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 11:36:50 2009 New Revision: 70133 URL: http://llvm.org/viewvc/llvm-project?rev=70133&view=rev Log: NativeString and PrintBuffer do not have a destructor. Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=70133&r1=70132&r2=70133&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sun Apr 26 11:36:50 2009 @@ -47,7 +47,9 @@ void Object::initialise() { # define INIT(X) { \ X fake; \ - X::VT = ((VirtualTable**)(void*)(&fake))[0]; } + X::VT = ((VirtualTable**)(void*)(&fake))[0]; \ + X::VT->operatorDelete = 0; \ + X::VT->destructor = 0; } INIT(NativeString); INIT(PrintBuffer); @@ -56,7 +58,7 @@ } void PrintBuffer::TRACER { - ((PrintBuffer *)this)->contents()->MARK_AND_TRACE; + this->contents()->MARK_AND_TRACE; } From nicolas.geoffray at lip6.fr Sun Apr 26 11:19:53 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 18:19:53 -0000 Subject: [vmkit-commits] [vmkit] r70141 - in /vmkit/trunk: include/mvm/GC/GC.h include/mvm/Object.h include/mvm/PrintBuffer.h lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/VMCore/JavaInitialise.cpp lib/JnJVM/VMCore/Jnjvm.cpp lib/Mvm/Runtime/Object.cpp tools/jnjvm/Main.cpp tools/n3-mono/Main.cpp tools/n3-pnetlib/Main.cpp tools/vmjc/vmjc.cpp tools/vmkit/Launcher.cpp Message-ID: <200904261819.n3QIJr2R020764@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 13:19:52 2009 New Revision: 70141 URL: http://llvm.org/viewvc/llvm-project?rev=70141&view=rev Log: Create virtual tables statically and remove mvm::Object::initialize from the boot sequence. Modified: vmkit/trunk/include/mvm/GC/GC.h vmkit/trunk/include/mvm/Object.h vmkit/trunk/include/mvm/PrintBuffer.h vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.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/mvm/GC/GC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/include/mvm/GC/GC.h (original) +++ vmkit/trunk/include/mvm/GC/GC.h Sun Apr 26 13:19:52 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 { Modified: vmkit/trunk/include/mvm/Object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Object.h?rev=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Object.h (original) +++ vmkit/trunk/include/mvm/Object.h Sun Apr 26 13:19:52 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=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/include/mvm/PrintBuffer.h (original) +++ vmkit/trunk/include/mvm/PrintBuffer.h Sun Apr 26 13:19:52 2009 @@ -10,8 +10,8 @@ #ifndef MVM_PRINTBUFFER_H #define MVM_PRINTBUFFER_H -#include // sprintf -#include // memcpy +#include // sprintf +#include // 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 = new(&VT) PrintBuffer(); 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/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Sun Apr 26 13:19:52 2009 @@ -243,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/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Sun Apr 26 13:19:52 2009 @@ -32,6 +32,9 @@ INIT(LockObj); INIT(VMClassLoader); + LockObj::VT->destructor = 0; + LockObj::VT->operatorDelete = 0; + VMClassLoader::VT->operatorDelete = VMClassLoader::VT->destructor; #ifdef ISOLATE_SHARING INIT(JnjvmSharedLoader); INIT(SharedClassByteMap); Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Apr 26 13:19:52 2009 @@ -1143,7 +1143,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/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sun Apr 26 13:19:52 2009 @@ -20,8 +20,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); @@ -44,24 +44,6 @@ } -void Object::initialise() { -# define INIT(X) { \ - X fake; \ - X::VT = ((VirtualTable**)(void*)(&fake))[0]; \ - X::VT->operatorDelete = 0; \ - X::VT->destructor = 0; } - - INIT(NativeString); - INIT(PrintBuffer); - -#undef INIT -} - -void PrintBuffer::TRACER { - 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=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/tools/jnjvm/Main.cpp (original) +++ vmkit/trunk/tools/jnjvm/Main.cpp Sun Apr 26 13:19:52 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=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/tools/n3-mono/Main.cpp (original) +++ vmkit/trunk/tools/n3-mono/Main.cpp Sun Apr 26 13:19:52 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=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/tools/n3-pnetlib/Main.cpp (original) +++ vmkit/trunk/tools/n3-pnetlib/Main.cpp Sun Apr 26 13:19:52 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=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Sun Apr 26 13:19:52 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=70141&r1=70140&r2=70141&view=diff ============================================================================== --- vmkit/trunk/tools/vmkit/Launcher.cpp (original) +++ vmkit/trunk/tools/vmkit/Launcher.cpp Sun Apr 26 13:19:52 2009 @@ -133,7 +133,6 @@ } mvm::MvmModule::initialise(Fast); - mvm::Object::initialise(); Collector::initialise(0); if (VMToRun == RunJava) { From nicolas.geoffray at lip6.fr Sun Apr 26 12:22:34 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 19:22:34 -0000 Subject: [vmkit-commits] [vmkit] r70146 - /vmkit/trunk/include/mvm/PrintBuffer.h Message-ID: <200904261922.n3QJMYVw022930@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 14:22:34 2009 New Revision: 70146 URL: http://llvm.org/viewvc/llvm-project?rev=70146&view=rev Log: Use gc::operator new instead of new. Modified: vmkit/trunk/include/mvm/PrintBuffer.h Modified: vmkit/trunk/include/mvm/PrintBuffer.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/PrintBuffer.h?rev=70146&r1=70145&r2=70146&view=diff ============================================================================== --- vmkit/trunk/include/mvm/PrintBuffer.h (original) +++ vmkit/trunk/include/mvm/PrintBuffer.h Sun Apr 26 14:22:34 2009 @@ -179,7 +179,7 @@ /// alloc - Allocates a default PrintBuffer. /// static PrintBuffer *alloc(void) { - PrintBuffer* pbf = new(&VT) PrintBuffer(); + PrintBuffer* pbf = (PrintBuffer*)gc::operator new(sizeof(PrintBuffer), &VT); pbf->capacity= 32; pbf->writePosition= 0; pbf->setContents(NativeString::alloc(pbf->capacity)); From nicolas.geoffray at lip6.fr Sun Apr 26 13:17:09 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 20:17:09 -0000 Subject: [vmkit-commits] [vmkit] r70154 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaInitialise.cpp JavaObject.cpp JavaObject.h JnjvmClassLoader.cpp JnjvmClassLoader.h VirtualTables.cpp Message-ID: <200904262017.n3QKHAKM025055@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 15:17:09 2009 New Revision: 70154 URL: http://llvm.org/viewvc/llvm-project?rev=70154&view=rev Log: Control the VTs of native GC objects, namely VMClassLoader and LockObj. Modified: 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/JnjvmClassLoader.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=70154&r1=70153&r2=70154&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Sun Apr 26 15:17:09 2009 @@ -23,32 +23,8 @@ using namespace jnjvm; -static void initialiseVT() { - -# define INIT(X) { \ - X fake; \ - X::VT = ((VirtualTable**)(void*)(&fake))[0]; } - - INIT(LockObj); - INIT(VMClassLoader); - - LockObj::VT->destructor = 0; - LockObj::VT->operatorDelete = 0; - VMClassLoader::VT->operatorDelete = VMClassLoader::VT->destructor; -#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; } @@ -65,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=70154&r1=70153&r2=70154&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Sun Apr 26 15:17:09 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=70154&r1=70153&r2=70154&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Sun Apr 26 15:17:09 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/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=70154&r1=70153&r2=70154&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sun Apr 26 15:17:09 2009 @@ -777,7 +777,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(); Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=70154&r1=70153&r2=70154&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Sun Apr 26 15:17:09 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) { + 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=70154&r1=70153&r2=70154&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Sun Apr 26 15:17:09 2009 @@ -57,12 +57,11 @@ // 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); - -#undef INIT +VirtualTable LockObj::VT(0, 0, (uintptr_t)VirtualTable::emptyTracer); //===----------------------------------------------------------------------===// // Empty tracer for static tracers of classes that do not declare static From nicolas.geoffray at lip6.fr Sun Apr 26 14:11:10 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 26 Apr 2009 21:11:10 -0000 Subject: [vmkit-commits] [vmkit] r70161 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904262111.n3QLBAmd026898@zion.cs.uiuc.edu> Author: geoffray Date: Sun Apr 26 16:11:10 2009 New Revision: 70161 URL: http://llvm.org/viewvc/llvm-project?rev=70161&view=rev Log: I am _so_ buggy. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=70161&r1=70160&r2=70161&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sun Apr 26 16:11:10 2009 @@ -808,7 +808,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? From nicolas.geoffray at lip6.fr Mon Apr 27 01:33:03 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 27 Apr 2009 08:33:03 -0000 Subject: [vmkit-commits] [vmkit] r70200 - /vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Message-ID: <200904270833.n3R8X3cC026207@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 27 03:33:02 2009 New Revision: 70200 URL: http://llvm.org/viewvc/llvm-project?rev=70200&view=rev Log: Bugfix when creating secondary types. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=70200&r1=70199&r2=70200&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Apr 27 03:33:02 2009 @@ -1303,8 +1303,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; @@ -1379,29 +1383,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*)); @@ -1410,27 +1430,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. From nicolas.geoffray at lip6.fr Mon Apr 27 01:55:17 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 27 Apr 2009 08:55:17 -0000 Subject: [vmkit-commits] [vmkit] r70201 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Message-ID: <200904270855.n3R8tIoJ027082@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 27 03:55:05 2009 New Revision: 70201 URL: http://llvm.org/viewvc/llvm-project?rev=70201&view=rev Log: Don't trace the class loader if there ain't any. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=70201&r1=70200&r2=70201&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Mon Apr 27 03:55:05 2009 @@ -411,7 +411,7 @@ /// TRACER - Trace the internal class loader. static void STATIC_TRACER(VMClassLoader) { - obj->JCL->CALL_TRACER; + if (obj->JCL) obj->JCL->CALL_TRACER; } /// ~VMClassLoader - Delete the internal class loader. From nicolas.geoffray at lip6.fr Mon Apr 27 02:01:44 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 27 Apr 2009 09:01:44 -0000 Subject: [vmkit-commits] [vmkit] r70202 - in /vmkit/trunk/lib/JnJVM: Compiler/JavaAOTCompiler.cpp LLVMRuntime/runtime-isolate.ll LLVMRuntime/runtime-single.ll VMCore/JavaClass.cpp VMCore/JavaClass.h VMCore/Jnjvm.cpp Message-ID: <200904270901.n3R91kOE027297@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 27 04:01:19 2009 New Revision: 70202 URL: http://llvm.org/viewvc/llvm-project?rev=70202&view=rev Log: Fix inner and outer when their index is zero and implement anonymous classes. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=70202&r1=70201&r2=70202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Mon Apr 27 04:01:19 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)); Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll?rev=70202&r1=70201&r2=70202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll Mon Apr 27 04:01:19 2009 @@ -12,8 +12,8 @@ %JavaClass = type { %JavaCommonClass, i32, [32 x %TaskClassMirror], i8*, %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*, - i16, %JavaClass**, i16, %JavaClass*, i16, i8, i32, i32, i8*, - void (i8*)* } + i16, %JavaClass**, i16, %JavaClass*, i16, i8, i8, i32, i32, + i8*, void (i8*)* } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;; Isolate specific methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll?rev=70202&r1=70201&r2=70202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-single.ll Mon Apr 27 04:01:19 2009 @@ -9,5 +9,5 @@ %JavaClass = type { %JavaCommonClass, i32, [1 x %TaskClassMirror], i8*, %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*, - i16, %JavaClass**, i16, %JavaClass*, i16, i8, i32, i32, i8*, - void (i8*)* } + i16, %JavaClass**, i16, %JavaClass*, i16, i8, i8, i32, i32, + i8*, void (i8*)* } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=70202&r1=70201&r2=70202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon Apr 27 04:01:19 2009 @@ -947,11 +947,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; @@ -961,6 +962,7 @@ classLoader->allocator.Allocate(nbi * sizeof(Class*)); } clInner->setInnerAccess(accessFlags); + if (!innerName) isAnonymous = true; innerClasses[nbInnerClasses++] = clInner; } } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=70202&r1=70201&r2=70202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Mon Apr 27 04:01:19 2009 @@ -672,6 +672,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/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=70202&r1=70201&r2=70202&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon Apr 27 04:01:19 2009 @@ -432,6 +432,7 @@ } void Jnjvm::classFormatError(const char* msg, ...) { + JavaThread::get()->printBacktrace(); error(upcalls->ClassFormatError, upcalls->InitClassFormatError, msg); From nicolas.geoffray at lip6.fr Mon Apr 27 02:08:50 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 27 Apr 2009 09:08:50 -0000 Subject: [vmkit-commits] [vmkit] r70203 - /vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Message-ID: <200904270908.n3R98sM3027647@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 27 04:08:37 2009 New Revision: 70203 URL: http://llvm.org/viewvc/llvm-project?rev=70203&view=rev Log: Remove unintentional code from last commit. Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=70203&r1=70202&r2=70203&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon Apr 27 04:08:37 2009 @@ -432,7 +432,6 @@ } void Jnjvm::classFormatError(const char* msg, ...) { - JavaThread::get()->printBacktrace(); error(upcalls->ClassFormatError, upcalls->InitClassFormatError, msg); From nicolas.geoffray at lip6.fr Mon Apr 27 03:25:33 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 27 Apr 2009 10:25:33 -0000 Subject: [vmkit-commits] [vmkit] r70204 - /vmkit/trunk/lib/Mvm/Runtime/Object.cpp Message-ID: <200904271025.n3RAPaxW030752@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 27 05:25:22 2009 New Revision: 70204 URL: http://llvm.org/viewvc/llvm-project?rev=70204&view=rev Log: Grow the finalized queue if it is not big enough. Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=70204&r1=70203&r2=70204&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Mon Apr 27 05:25:22 2009 @@ -187,6 +187,9 @@ if (!Collector::isLive(obj)) { obj->markAndTrace(); + + if (CurrentFinalizedIndex >= ToBeFinalizedLength) growQueue(); + /* Add to object table */ ToBeFinalized[CurrentFinalizedIndex++] = obj; } else { From nicolas.geoffray at lip6.fr Mon Apr 27 04:49:55 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 27 Apr 2009 11:49:55 -0000 Subject: [vmkit-commits] [vmkit] r70206 - /vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Message-ID: <200904271149.n3RBnvBk001179@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 27 06:49:44 2009 New Revision: 70206 URL: http://llvm.org/viewvc/llvm-project?rev=70206&view=rev Log: Protect deletion of LLVM functions. Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=70206&r1=70205&r2=70206&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Mon Apr 27 06:49:44 2009 @@ -233,7 +233,9 @@ Function* func = parseFunction(meth); void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(func); + mvm::MvmModule::protectIR(); func->deleteBody(); + mvm::MvmModule::unprotectIR(); return res; } From nicolas.geoffray at lip6.fr Mon Apr 27 06:33:32 2009 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 27 Apr 2009 13:33:32 -0000 Subject: [vmkit-commits] [vmkit] r70207 - /vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Message-ID: <200904271333.n3RDXY5O004502@zion.cs.uiuc.edu> Author: geoffray Date: Mon Apr 27 08:33:22 2009 New Revision: 70207 URL: http://llvm.org/viewvc/llvm-project?rev=70207&view=rev Log: Set the tracer before someone else tries to. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=70207&r1=70206&r2=70207&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Mon Apr 27 08:33:22 2009 @@ -823,10 +823,12 @@ newReference = loader->loadName(loader->asciizConstructUTF8("java/lang/ref/Reference"), false, false); - + + newReference->getVirtualVT()->setNativeTracer( + (uintptr_t)nativeJavaObjectReferenceTracer, + "nativeJavaObjectReferenceTracer"); + assert(!newReference->isResolved() && "Reference class already resolved"); - JavaVirtualTable* ptr = newReference->getVirtualVT(); - ptr->tracer = (uintptr_t)JavaObjectReference::staticTracer; EnqueueReference = UPCALL_METHOD(loader, "java/lang/ref/Reference", "enqueue", "()Z", @@ -868,9 +870,6 @@ (void*)(intptr_t)nativeInitPhantomReferenceQ, "nativeInitPhantomReferenceQ"); - newReference->getVirtualVT()->setNativeTracer( - (uintptr_t)nativeJavaObjectReferenceTracer, - "nativeJavaObjectReferenceTracer"); //===----------------------------------------------------------------------===// //