[vmkit-commits] [vmkit] r199616 - Remove the useless class J3MethodCode.

Gael Thomas gael.thomas at lip6.fr
Sun Jan 19 15:01:35 PST 2014


Author: gthomas
Date: Sun Jan 19 17:01:35 2014
New Revision: 199616

URL: http://llvm.org/viewvc/llvm-project?rev=199616&view=rev
Log:
Remove the useless class J3MethodCode.

Modified:
    vmkit/branches/mcjit/Makefile
    vmkit/branches/mcjit/include/j3/j3class.h
    vmkit/branches/mcjit/include/j3/j3classloader.h
    vmkit/branches/mcjit/include/j3/j3codegen.h
    vmkit/branches/mcjit/include/j3/j3method.h
    vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
    vmkit/branches/mcjit/lib/j3/vm/j3.cc
    vmkit/branches/mcjit/lib/j3/vm/j3class.cc
    vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc
    vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
    vmkit/branches/mcjit/lib/j3/vm/j3method.cc
    vmkit/branches/mcjit/lib/j3/vm/j3thread.cc

Modified: vmkit/branches/mcjit/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/Makefile (original)
+++ vmkit/branches/mcjit/Makefile Sun Jan 19 17:01:35 2014
@@ -5,6 +5,6 @@
 
 LEVEL := .
 
-DIRS := tools/vmkit-extract lib tools/j3 lib/mmtk
+DIRS := tools/vmkit-extract lib tools/j3 
 
 include $(LEVEL)/Makefile.rules

Modified: vmkit/branches/mcjit/include/j3/j3class.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3class.h (original)
+++ vmkit/branches/mcjit/include/j3/j3class.h Sun Jan 19 17:01:35 2014
@@ -11,6 +11,7 @@
 
 namespace llvm {
 	class Type;
+	class Linker;
 }
 
 namespace vmkit {
@@ -229,6 +230,7 @@ namespace j3 {
 		J3Class(J3ClassLoader* loader, const vmkit::Name* name, J3ClassBytes* bytes, J3ObjectHandle* protectionDomain, const char* source);
 
 		void                aotCompile();
+		void                aotSnapshot(llvm::Linker* linker);
 
 		J3ObjectHandle*     clone(J3ObjectHandle* obj);
 

Modified: vmkit/branches/mcjit/include/j3/j3classloader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3classloader.h (original)
+++ vmkit/branches/mcjit/include/j3/j3classloader.h Sun Jan 19 17:01:35 2014
@@ -10,6 +10,10 @@
 
 #include "j3/j3object.h"
 
+namespace llvm {
+	class Linker;
+}
+
 namespace vmkit {
 	class Symbol;
 }
@@ -55,6 +59,8 @@ namespace j3 {
 	public:
 		J3ClassLoader(J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator);
 
+		void                          aotSnapshot(llvm::Linker* linker);
+
 		void                          addNativeLibrary(void* handle);
 
 		J3Type*                       getTypeInternal(J3ObjectType* from, const char* type, 

Modified: vmkit/branches/mcjit/include/j3/j3codegen.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3codegen.h (original)
+++ vmkit/branches/mcjit/include/j3/j3codegen.h Sun Jan 19 17:01:35 2014
@@ -84,7 +84,6 @@ namespace j3 {
 		uint32_t            wideReadS1();
 
 		llvm::Function*     buildFunction(J3Method* method, bool isStub=1);
-		llvm::Value*        methodDescriptor(J3Method* method);
 		llvm::Value*        typeDescriptor(J3ObjectType* objectType, llvm::Type* type);
 
 		llvm::Value*        spToCurrentThread(llvm::Value* sp);

Modified: vmkit/branches/mcjit/include/j3/j3method.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3method.h (original)
+++ vmkit/branches/mcjit/include/j3/j3method.h Sun Jan 19 17:01:35 2014
@@ -10,6 +10,7 @@
 namespace llvm {
 	class FunctionType;
 	class Function;
+	class Linker;
 }
 
 namespace vmkit {
@@ -27,18 +28,8 @@ namespace j3 {
 	class J3ObjectHandle;
 	class J3Signature;
 
-	class J3MethodCode : public vmkit::Symbol {
-	public:
-		J3Method* self;
-
-		J3MethodCode(J3Method* _self) { self = _self; }
-
-		void* getSymbolAddress();
-	};
-
 	class J3Method : public vmkit::Symbol {
 	public:
-		J3MethodCode                 _selfCode;
 		uint16_t                     _access;
 		J3Class*                     _cl;
 		const vmkit::Name*           _name;
@@ -60,9 +51,6 @@ namespace j3 {
 	public:
 		J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, J3Signature* signature);
 
-
-		J3MethodCode*       selfCode() { return &_selfCode; }
-
 		uint32_t            slot() { return _slot; }
 
 		static J3Method*    nativeMethod(J3ObjectHandle* handle);
@@ -77,7 +65,6 @@ namespace j3 {
 		void*               getSymbolAddress();
 
 		char*               llvmFunctionName(J3Class* from=0);
-		char*               llvmDescriptorName(J3Class* from=0);
 		char*               llvmStubName(J3Class* from=0);
 
 		void                postInitialise(uint32_t access, J3Attributes* attributes);
@@ -106,6 +93,7 @@ namespace j3 {
 		J3Value             invokeVirtual(J3ObjectHandle* obj, va_list va);
 
 		void                aotCompile();
+		void                aotSnapshot(llvm::Linker* linker);
 		void                ensureCompiled(bool withCaller, bool onlyTranslate=0);
 		J3Signature::function_t cxxCaller();
 		void*               fnPtr();

Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Sun Jan 19 17:01:35 2014
@@ -395,7 +395,7 @@ jint JNICALL JVM_GetStackTraceDepth(JNIE
 				vmkit::Safepoint* sf = vm->getSafepoint((void*)cur);
 
 				if(sf) {
-					J3Method* m = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self;
+					J3Method* m = (J3Method*)sf->unit()->getSymbol(sf->functionName());
 					if(ignore) {
 						if(m->name() == vm->initName && m->cl() == throwable->vt()->type()) {
 							ignore = 0;
@@ -452,7 +452,7 @@ jobject JNICALL JVM_GetStackTraceElement
 			fileName = vm->utfToString("??");
 		}
 	} else {
-		J3Method* m = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self;
+		J3Method* m = (J3Method*)sf->unit()->getSymbol(sf->functionName());
 		const vmkit::Name* cn = m->cl()->name();
 		uint32_t length = cn->length()+6;
 		uint32_t lastToken = 0;
@@ -645,7 +645,7 @@ jclass JNICALL JVM_GetCallerClass(JNIEnv
 
 		if(sf) {
 			if(!--depth)
-				caller = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self;
+				caller = (J3Method*)sf->unit()->getSymbol(sf->functionName());
 		}
 	}
 

Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sun Jan 19 17:01:35 2014
@@ -15,6 +15,8 @@
 
 #include "llvm/IR/Type.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Linker.h"
 
 #include "vmkit/safepoint.h"
 #include "vmkit/system.h"
@@ -207,12 +209,14 @@ void J3::compileApplication() {
 				char buf[name->length() - 5];
 				memcpy(buf, name->cStr(), name->length() - 6);
 				buf[name->length()-6] = 0;
-				J3Class* c = loader->getTypeFromQualified(0, buf)->asClass();
-
-				c->aotCompile();
+				loader->getTypeFromQualified(0, buf)->asClass()->aotCompile();
 			}
 		}
 	}
+
+	llvm::Module* res = new llvm::Module("yop", llvmContext());
+	llvm::Linker* linker = new llvm::Linker(res);
+	loader->aotSnapshot(linker);
 }
 
 void J3::runApplication() {
@@ -402,7 +406,7 @@ void J3::printStackTrace() {
 		vmkit::Safepoint* sf = J3Thread::get()->vm()->getSafepoint(walker.ip());
 
 		if(sf) {
-			J3Method* m = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self;
+			J3Method* m = (J3Method*)sf->unit()->getSymbol(sf->functionName());
 			fprintf(stderr, "    in %s::%s%s index %d\n", m->cl()->name()->cStr(), m->name()->cStr(),
 							m->signature()->name()->cStr(), sf->sourceIndex());
 		} else {

Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sun Jan 19 17:01:35 2014
@@ -332,6 +332,16 @@ void J3Class::aotCompile() {
 	}
 }
 
+void J3Class::aotSnapshot(llvm::Linker* linker) {
+	for(uint32_t i=0; i<nbMethods(); i++) {
+		methods()[i]->aotSnapshot(linker);
+	}
+
+	for(uint32_t i=0; i<staticLayout()->nbMethods(); i++) {
+		staticLayout()->methods()[i]->aotSnapshot(linker);
+	}
+}
+
 uint16_t J3Class::modifiers() {
 	return access();
 #if 0

Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Sun Jan 19 17:01:35 2014
@@ -109,6 +109,14 @@ J3Class* J3ClassLoader::defineClass(cons
 	return res;
 }
 
+void J3ClassLoader::aotSnapshot(llvm::Linker* linker) {
+	pthread_mutex_lock(&_mutexClasses);
+	for(vmkit::NameMap<J3Class*>::map::iterator it=classes.begin(); it!=classes.end(); it++) {
+		it->second->aotSnapshot(linker);
+	}
+	pthread_mutex_unlock(&_mutexClasses);
+}
+
 J3Class* J3ClassLoader::loadClass(const vmkit::Name* name) {
 	J3* vm = J3Thread::get()->vm();
 	return J3Class::nativeClass(vm->classLoaderClassLoadClass->invokeVirtual(_javaClassLoader, vm->nameToString(name)).valObject)->asClass();

Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Jan 19 17:01:35 2014
@@ -205,7 +205,7 @@ llvm::Value* J3CodeGen::unflatten(llvm::
 
 llvm::Function* J3CodeGen::buildFunction(J3Method* method, bool isStub) {
 	const char* id = (isStub && !method->fnPtr()) ? method->llvmStubName(cl) : method->llvmFunctionName(cl);
-	loader->addSymbol(id, method->selfCode());
+	loader->addSymbol(id, method);
 	return (llvm::Function*)module->getOrInsertFunction(id, method->signature()->functionType(method->access()));
 }
 
@@ -216,12 +216,6 @@ llvm::Value* J3CodeGen::typeDescriptor(J
 	return type == vm->typeJ3ObjectTypePtr ? v : builder->CreateBitCast(v, type);
 }
 
-llvm::Value* J3CodeGen::methodDescriptor(J3Method* method) {
-	const char* id = method->llvmDescriptorName();
-	loader->addSymbol(id, method);
-	return module->getOrInsertGlobal(id, vm->typeJ3Method);
-}
-
 llvm::Value* J3CodeGen::spToCurrentThread(llvm::Value* sp) {
 	return builder->CreateIntToPtr(builder->CreateAnd(builder->CreatePtrToInt(sp, uintPtrTy),
 																										llvm::ConstantInt::get(uintPtrTy, vmkit::Thread::getThreadMask())),

Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Sun Jan 19 17:01:35 2014
@@ -14,6 +14,7 @@
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Function.h"
+#include "llvm/Linker.h"
 
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
@@ -22,8 +23,7 @@
 
 using namespace j3;
 
-J3Method::J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, J3Signature* signature) :
-	_selfCode(this) {
+J3Method::J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, J3Signature* signature) {
 	_access = access;
 	_cl = cl;
 	_name = name;
@@ -59,6 +59,13 @@ void J3Method::aotCompile() {
 	}
 }
 
+void J3Method::aotSnapshot(llvm::Linker* linker) {
+	if(_llvmFunction) {
+		std::string err;
+		linker->linkInModule(_llvmFunction->getParent(), llvm::Linker::DestroySource, &err);
+	}
+}
+
 void J3Method::ensureCompiled(bool withCaller, bool onlyTranslate) {
 	if(!fnPtr() || (withCaller && !cxxCaller())) {
 		//fprintf(stderr, "materializing: %s::%s%s\n", cl()->name()->cStr(), name()->cStr(), signature()->name()->cStr());
@@ -82,12 +89,8 @@ void* J3Method::functionPointerOrVirtual
 	return _virtualTrampoline;
 }
 
-void* J3MethodCode::getSymbolAddress() {
-	return self->functionPointerOrStaticTrampoline();
-}
-
 void* J3Method::getSymbolAddress() {
-	return this;
+	return functionPointerOrStaticTrampoline();
 }
 
 void J3Method::setIndex(uint32_t index) { 
@@ -229,12 +232,6 @@ char* J3Method::llvmFunctionName(J3Class
 	return _llvmAllNames + 5;
 }
 
-char* J3Method::llvmDescriptorName(J3Class* from) {
-	if(!_llvmAllNames)
-		buildLLVMNames(from ? from : cl());
-	return _llvmAllNames + 4;
-}
-
 char* J3Method::llvmStubName(J3Class* from) {
 	if(!_llvmAllNames)
 		buildLLVMNames(from ? from : cl());

Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=199616&r1=199615&r2=199616&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Sun Jan 19 17:01:35 2014
@@ -40,7 +40,7 @@ J3Method* J3Thread::getJavaCaller(uint32
 		vmkit::Safepoint* sf = vm()->getSafepoint(walker.ip());
 
 		if(sf && !level--)
-			return ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self;
+			return (J3Method*)sf->unit()->getSymbol(sf->functionName());
 	}
 
 	return 0;





More information about the vmkit-commits mailing list