[vmkit-commits] [vmkit] r198023 - begin to bootstrap the thread system
Gael Thomas
gael.thomas at lip6.fr
Wed Dec 25 10:54:58 PST 2013
Author: gthomas
Date: Wed Dec 25 12:54:57 2013
New Revision: 198023
URL: http://llvm.org/viewvc/llvm-project?rev=198023&view=rev
Log:
begin to bootstrap the thread system
Added:
vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc
Modified:
vmkit/branches/mcjit/include/j3/j3.h
vmkit/branches/mcjit/include/j3/j3lib.h
vmkit/branches/mcjit/include/j3/j3thread.h
vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
vmkit/branches/mcjit/lib/j3/vm/j3.cc
vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
vmkit/branches/mcjit/lib/j3/vm/j3method.cc
vmkit/branches/mcjit/lib/j3/vm/j3options.cc
vmkit/branches/mcjit/lib/j3/vm/j3thread.cc
Modified: vmkit/branches/mcjit/include/j3/j3.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3.h (original)
+++ vmkit/branches/mcjit/include/j3/j3.h Wed Dec 25 12:54:57 2013
@@ -65,6 +65,8 @@ namespace j3 {
J3Method* classInit;
J3Field* classVMData;
+ J3Field* threadVMData;
+
const vmkit::Name* codeAttr;
const vmkit::Name* constantValueAttr;
const vmkit::Name* initName;
Modified: vmkit/branches/mcjit/include/j3/j3lib.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3lib.h?rev=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3lib.h (original)
+++ vmkit/branches/mcjit/include/j3/j3lib.h Wed Dec 25 12:54:57 2013
@@ -5,12 +5,15 @@
#include <vector>
namespace j3 {
+ class J3;
class J3ClassBytes;
class J3Lib {
public:
static const char* systemClassesArchives();
static int loadSystemLibraries(std::vector<void*, vmkit::StdAllocator<void*> >* handles);
+
+ static void bootstrap(J3* vm);
};
}
Modified: vmkit/branches/mcjit/include/j3/j3thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3thread.h (original)
+++ vmkit/branches/mcjit/include/j3/j3thread.h Wed Dec 25 12:54:57 2013
@@ -23,11 +23,15 @@ namespace j3 {
JNIEnv _jniEnv;
J3LocalReferences _localReferences;
J3ObjectHandle* _pendingException;
+ J3ObjectHandle* _javaThread;
J3Thread(J3* vm, vmkit::BumpAllocator* allocator);
public:
static J3Thread* create(J3* j3);
+ void assocJavaThread(J3ObjectHandle* javaThread);
+ J3ObjectHandle* javaThread() { return _javaThread; }
+
J3Method* getJavaCaller(uint32_t level=0);
uint32_t interfaceMethodIndex() { return _interfaceMethodIndex; }
Added: vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc?rev=198023&view=auto
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc (added)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc Wed Dec 25 12:54:57 2013
@@ -0,0 +1,109 @@
+#include "vmkit/config.h"
+
+#include "j3/j3.h"
+#include "j3/j3lib.h"
+#include "j3/j3config.h"
+#include "j3/j3constants.h"
+#include "j3/j3classloader.h"
+#include "j3/j3method.h"
+#include "j3/j3class.h"
+#include "j3/j3thread.h"
+
+#include <dlfcn.h>
+
+using namespace j3;
+
+#ifdef LINUX_OS
+#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib/amd64"
+#else
+#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib"
+#endif
+
+static const char* rtjar = OPENJDK_HOME"jre/lib/rt.jar";
+
+void J3Lib::bootstrap(J3* vm) {
+ J3ObjectHandle* prev = J3Thread::get()->tell();
+
+ J3Method* sysThreadGroupInit = vm->initialClassLoader->method(0,
+ L"java/lang/ThreadGroup",
+ J3Cst::initName,
+ L"()V");
+ J3ObjectHandle* sysThreadGroup = J3ObjectHandle::doNewObject(sysThreadGroupInit->cl());
+ sysThreadGroupInit->invokeSpecial(sysThreadGroup);
+
+
+ J3Method* appThreadGroupInit = vm->initialClassLoader->method(0,
+ L"java/lang/ThreadGroup",
+ J3Cst::initName,
+ L"(Ljava/lang/ThreadGroup;Ljava/lang/String;)V");
+ J3ObjectHandle* appThreadGroup = J3ObjectHandle::doNewObject(appThreadGroupInit->cl());
+ appThreadGroupInit->invokeSpecial(appThreadGroup, sysThreadGroup, vm->utfToString("main"));
+
+ J3Method* threadInit = vm->initialClassLoader->method(0,
+ L"java/lang/Thread",
+ J3Cst::initName,
+ L"(Ljava/lang/ThreadGroup;Ljava/lang/String;)V");
+ J3ObjectHandle* mainThread = vm->initialClassLoader->globalReferences()->add(J3ObjectHandle::doNewObject(threadInit->cl()));
+
+ J3Thread::get()->assocJavaThread(mainThread);
+ mainThread->setInteger(threadInit->cl()->findVirtualField(vm->names()->get(L"priority"), vm->typeInteger), 5);
+
+ threadInit->invokeSpecial(mainThread, appThreadGroup, vm->utfToString("main"));
+
+ fprintf(stderr, "main thread is at %p\n", threadInit);
+ abort();
+
+ vm->initialClassLoader->method(J3Cst::ACC_STATIC, L"java/lang/System", L"initializeSystemClass", L"()V")->invokeStatic();
+
+ J3Thread::get()->restore(prev);
+}
+
+const char* J3Lib::systemClassesArchives() {
+ return rtjar;
+}
+
+int J3Lib::loadSystemLibraries(std::vector<void*, vmkit::StdAllocator<void*> >* nativeLibraries) {
+ /* JavaRuntimeSupport checks for a symbol defined in this library */
+ void* h0 = dlopen(OPENJDK_LIBPATH"/libinstrument"SHLIBEXT, RTLD_LAZY | RTLD_GLOBAL);
+ void* handle = dlopen(OPENJDK_LIBPATH"/libjava"SHLIBEXT, RTLD_LAZY | RTLD_LOCAL);
+
+ if(!handle || !h0) {
+ fprintf(stderr, "Fatal: unable to find java system library: %s\n", dlerror());
+ abort();
+ }
+
+ nativeLibraries->push_back(handle);
+
+ return 0;
+}
+
+
+#if 0
+// from openjdk
+
+
+// Creates the initial Thread
+static oop create_initial_thread(Handle thread_group, JavaThread* thread, TRAPS) {
+ Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL);
+ instanceKlassHandle klass (THREAD, k);
+ instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);
+
+ java_lang_Thread::set_thread(thread_oop(), thread);
+ java_lang_Thread::set_priority(thread_oop(), NormPriority);
+ thread->set_threadObj(thread_oop());
+
+ Handle string = java_lang_String::create_from_str("main", CHECK_NULL);
+
+ JavaValue result(T_VOID);
+ JavaCalls::call_special(&result, thread_oop,
+ klass,
+ vmSymbols::object_initializer_name(),
+ vmSymbols::threadgroup_string_void_signature(),
+ thread_group,
+ string,
+ CHECK_NULL);
+ return thread_oop();
+}
+
+// Creates the initial ThreadGroup
+#endif
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=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Wed Dec 25 12:54:57 2013
@@ -1,9 +1,4 @@
-#include "vmkit/config.h"
-#include "vmkit/system.h"
#include "vmkit/safepoint.h"
-#include "j3/j3object.h"
-#include "j3/j3lib.h"
-#include "j3/j3config.h"
#include "j3/j3.h"
#include "j3/j3thread.h"
#include "j3/j3classloader.h"
@@ -11,8 +6,6 @@
#include "j3/j3method.h"
#include "jvm.h"
-#include <dlfcn.h>
-
using namespace j3;
#define enterJVM()
@@ -20,33 +13,6 @@ using namespace j3;
#define NYI() { J3Thread::get()->vm()->internalError(L"not yet implemented: '%s'", __PRETTY_FUNCTION__); }
-#ifdef LINUX_OS
-#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib/amd64"
-#else
-#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib"
-#endif
-
-static const char* rtjar = OPENJDK_HOME"jre/lib/rt.jar";
-
-const char* J3Lib::systemClassesArchives() {
- return rtjar;
-}
-
-int J3Lib::loadSystemLibraries(std::vector<void*, vmkit::StdAllocator<void*> >* nativeLibraries) {
- /* JavaRuntimeSupport checks for a symbol defined in this library */
- void* h0 = dlopen(OPENJDK_LIBPATH"/libinstrument"SHLIBEXT, RTLD_LAZY | RTLD_GLOBAL);
- void* handle = dlopen(OPENJDK_LIBPATH"/libjava"SHLIBEXT, RTLD_LAZY | RTLD_LOCAL);
-
- if(!handle || !h0) {
- fprintf(stderr, "Fatal: unable to find java system library: %s\n", dlerror());
- abort();
- }
-
- nativeLibraries->push_back(handle);
-
- return 0;
-}
-
/*************************************************************************
PART 0
@@ -82,7 +48,20 @@ jstring JNICALL JVM_InternString(JNIEnv*
*/
jlong JNICALL JVM_CurrentTimeMillis(JNIEnv* env, jclass ignored) { enterJVM(); NYI(); leaveJVM(); }
jlong JNICALL JVM_NanoTime(JNIEnv* env, jclass ignored) { enterJVM(); NYI(); leaveJVM(); }
-void JNICALL JVM_ArrayCopy(JNIEnv* env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) { enterJVM(); NYI(); leaveJVM(); }
+void JNICALL JVM_ArrayCopy(JNIEnv* env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) {
+ enterJVM();
+
+ printf("to array copy: %p and %p\n", src->vt(), dst->vt());
+
+ J3Type* srcType = src->vt()->type();
+ J3Type* dstType = dst->vt()->type();
+
+ fprintf(stderr, "%ls to %ls\n", srcType->name()->cStr(), dstType->name()->cStr());
+
+ NYI();
+ leaveJVM();
+}
+
jobject JNICALL JVM_InitProperties(JNIEnv* env, jobject p) { enterJVM(); NYI(); leaveJVM(); }
/*
@@ -157,7 +136,15 @@ void JNICALL JVM_ResumeThread(JNIEnv* en
void JNICALL JVM_SetThreadPriority(JNIEnv* env, jobject thread, jint prio) { enterJVM(); NYI(); leaveJVM(); }
void JNICALL JVM_Yield(JNIEnv* env, jclass threadClass) { enterJVM(); NYI(); leaveJVM(); }
void JNICALL JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis) { enterJVM(); NYI(); leaveJVM(); }
-jobject JNICALL JVM_CurrentThread(JNIEnv* env, jclass threadClass) { enterJVM(); NYI(); leaveJVM(); }
+
+jobject JNICALL JVM_CurrentThread(JNIEnv* env, jclass threadClass) {
+ jobject res;
+ enterJVM();
+ res = J3Thread::get()->javaThread();
+ leaveJVM();
+ return res;
+}
+
jint JNICALL JVM_CountStackFrames(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); }
void JNICALL JVM_Interrupt(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); }
jboolean JNICALL JVM_IsInterrupted(JNIEnv* env, jobject thread, jboolean clearInterrupted) { enterJVM(); NYI(); leaveJVM(); }
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=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Wed Dec 25 12:54:57 2013
@@ -9,6 +9,7 @@
#include "j3/j3method.h"
#include "j3/j3thread.h"
#include "j3/j3trampoline.h"
+#include "j3/j3lib.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/DerivedTypes.h"
@@ -101,7 +102,10 @@ void J3::start(int argc, char** argv) {
classInit = initialClassLoader->method(0, classClass, initName, names()->get(L"()V"));
classVMData = classClass->findVirtualField(hf.name(), hf.type());
- initialClassLoader->method(J3Cst::ACC_STATIC, L"java/lang/System", L"initializeSystemClass", L"()V")->invokeStatic();
+ threadVMData = initialClassLoader->getClass(names()->get("java/lang/Thread"))
+ ->findVirtualField(names()->get(L"eetop"), typeLong);
+
+ J3Lib::bootstrap(this);
}
JNIEnv* J3::jniEnv() {
@@ -205,4 +209,3 @@ void J3::printStackTrace() {
}
}
}
-
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=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Wed Dec 25 12:54:57 2013
@@ -252,6 +252,7 @@ void J3CodeGen::invoke(J3Method* target,
llvm::Value* res;
if(exceptionNodes[curExceptionNode]->landingPad) {
+ //llvm::BasicBlock* after = forwardBranch("invoke-after", codeReader->tell(), 0, 0);
llvm::BasicBlock* after = newBB("invoke-after");
res = builder->CreateInvoke(func, after, exceptionNodes[curExceptionNode]->landingPad, args);
bb = after;
@@ -763,9 +764,9 @@ void J3CodeGen::translate() {
//printf("Meta stack after: %p\n", metaStack);
}
- if(opInfos[javaPC].bb)
+ if(opInfos[javaPC].bb || bb->empty())
opInfos[javaPC].insn = bb->begin();
- else
+ else
opInfos[javaPC].insn = bb->end()->getPrevNode();
uint8_t bc = codeReader->readU1();
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=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Wed Dec 25 12:54:57 2013
@@ -51,7 +51,7 @@ uint32_t J3Method::index() {
void* J3Method::fnPtr() {
if(!_fnPtr) {
- //fprintf(stderr, "materializing: %ls::%ls%ls\n", cl()->name()->cStr(), name()->cStr(), sign()->cStr());
+ //fprintf(stderr, "materializing: %ls::%ls%ls\n", this, cl()->name()->cStr(), name()->cStr(), sign()->cStr());
if(!isResolved()) {
if(cl()->loader()->vm()->options()->debugLinking)
fprintf(stderr, "linking %ls::%ls\n", cl()->name()->cStr(), name()->cStr());
Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Wed Dec 25 12:54:57 2013
@@ -19,7 +19,7 @@ J3Options::J3Options() {
debugLoad = 0;
debugResolve = 0;
debugIniting = 0;
- debugTranslate = 0;
+ debugTranslate = 3;
debugLinking = 0;
genDebugExecute = debugExecute ? 1 : 0;
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=198023&r1=198022&r2=198023&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Wed Dec 25 12:54:57 2013
@@ -43,6 +43,11 @@ void J3Thread::ensureCapacity(uint32_t c
_localReferences.ensureCapacity(capacity);
}
+void J3Thread::assocJavaThread(J3ObjectHandle* javaThread) {
+ _javaThread = javaThread;
+ _javaThread->setLong(vm()->threadVMData, (int64_t)(uintptr_t)this);
+}
+
J3ObjectHandle* J3Thread::push(J3ObjectHandle* handle) {
return _localReferences.push(handle);
}
More information about the vmkit-commits
mailing list