[vmkit-commits] [vmkit] r197987 - Add few jni and jvm functions. Execute more than 20115 opcodes! Happy christmas :)

Gael Thomas gael.thomas at lip6.fr
Tue Dec 24 11:02:34 PST 2013


Author: gthomas
Date: Tue Dec 24 13:02:33 2013
New Revision: 197987

URL: http://llvm.org/viewvc/llvm-project?rev=197987&view=rev
Log:
Add few jni and jvm functions. Execute more than 20115 opcodes! Happy christmas :)


Modified:
    vmkit/branches/mcjit/include/j3/j3class.h
    vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
    vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc
    vmkit/branches/mcjit/lib/j3/vm/j3class.cc
    vmkit/branches/mcjit/lib/j3/vm/j3options.cc

Modified: vmkit/branches/mcjit/include/j3/j3class.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197987&r1=197986&r2=197987&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3class.h (original)
+++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 13:02:33 2013
@@ -52,6 +52,9 @@ namespace j3 {
 	public:
 		J3Type(J3ClassLoader* loader, const vmkit::Name* name);
 
+		uint64_t                    getLogSize();
+		uint64_t                    getSizeInBits();
+
 		void*                       getSymbolAddress();
 
 		virtual llvm::GlobalValue*  llvmDescriptor(llvm::Module* module) { return 0; }

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=197987&r1=197986&r2=197987&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Tue Dec 24 13:02:33 2013
@@ -1,5 +1,6 @@
 #include "vmkit/config.h"
 #include "vmkit/system.h"
+#include "vmkit/safepoint.h"
 #include "j3/j3object.h"
 #include "j3/j3lib.h"
 #include "j3/j3config.h"
@@ -7,6 +8,7 @@
 #include "j3/j3thread.h"
 #include "j3/j3classloader.h"
 #include "j3/j3class.h"
+#include "j3/j3method.h"
 #include "jvm.h"
 
 #include <dlfcn.h>
@@ -220,7 +222,37 @@ jobject JNICALL JVM_NewMultiArray(JNIEnv
  * to be marked with sun.reflect.CallerSensitive.  The JVM will throw
  * an error if it is not marked propertly.
  */
-jclass JNICALL JVM_GetCallerClass(JNIEnv* env, int depth) { enterJVM(); NYI(); leaveJVM(); }
+jclass JNICALL JVM_GetCallerClass(JNIEnv* env, int depth) { 
+	jclass res;
+	enterJVM(); 
+
+	if(depth != -1)
+		J3::internalError(L"depth should be -1 while it is %d", depth);
+
+	depth = 3;
+	J3Method* caller = 0;
+	J3* vm = J3Thread::get()->vm();
+	vmkit::Safepoint* sf = 0;
+	vmkit::StackWalker walker;
+
+	while(!caller && walker.next()) {
+		vmkit::Safepoint* sf = vm->getSafepoint(walker.ip());
+
+		if(sf) {
+			if(!--depth)
+				caller = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self;
+		}
+	}
+
+	if(!caller)
+		J3::internalError(L"unable to find caller class, what should I do?");
+
+	res = caller->cl()->javaClass();
+
+	leaveJVM(); 
+
+	return res;
+}
 
 
 /*
@@ -914,4 +946,18 @@ jobjectArray JNICALL JVM_GetThreadStateN
  *
  * ==========================================================================
  */
-void JNICALL JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size) { enterJVM(); NYI(); leaveJVM(); }
+void JNICALL JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size) { 
+	enterJVM(); 
+  memset(info, 0, sizeof(info_size));
+
+  info->jvm_version = (8 << 24) | (0 << 16) | 0;
+  info->update_version = 0;
+  info->special_update_version = 0;
+
+  // when we add a new capability in the jvm_version_info struct, we should also
+  // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat
+  // counter defined in runtimeService.cpp.
+  info->is_attach_supported = 0;//AttachListener::is_attach_supported();
+
+	leaveJVM(); 
+}

Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc?rev=197987&r1=197986&r2=197987&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc Tue Dec 24 13:02:33 2013
@@ -1,10 +1,37 @@
 #include "j3/j3jni.h"
 #include "j3/j3object.h"
+#include "j3/j3thread.h"
+#include "j3/j3class.h"
+#include "j3/j3classloader.h"
+#include "j3/j3.h"
+
+#include "llvm/IR/DataLayout.h"
 
 using namespace j3;
 
 extern "C" {
-	JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(J3Object*) {
+	JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv* env, jclass cls) {
 		// Nothing, we define the Unsafe methods with the expected signatures.
 	}
+
+	/// arrayBaseOffset - Offset from the array object where the actual
+	/// element data begins.
+	///
+	JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv* env, jobject unsafe, jclass clazz) {
+		return sizeof(J3ArrayObject);
+	}
+
+	/// arrayIndexScale - Indexing scale for the element type in
+	/// the specified array.  For use with arrayBaseOffset,
+	/// NthElementPtr = ArrayObject + BaseOffset + N*IndexScale
+	/// Return '0' if our JVM stores the elements in a way that
+	/// makes this type of access impossible or unsupported.
+	///
+	JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv* env, jobject unsafe, jclass clazz) {
+		return J3ObjectType::nativeClass(clazz)->asArrayClass()->component()->getLogSize();
+	}
+
+	JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv* env, jobject unsafe) {
+		return J3Thread::get()->vm()->objectClass->getSizeInBits()>>3;
+	}
 }

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=197987&r1=197986&r2=197987&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 13:02:33 2013
@@ -71,6 +71,24 @@ J3ArrayClass* J3Type::getArray(uint32_t
 	return prof > 1 ? _array->getArray(prof-1) : _array;
 }
 
+uint64_t J3Type::getLogSize() {
+	uint32_t res = getSizeInBits();
+
+	switch(res) {
+		case 1:
+		case 8:  return 0;
+		case 16: return 1;
+		case 32: return 2;
+		case 64: return 3;
+		default:
+			J3::internalError(L"unexpected type");
+	}
+}
+
+uint64_t J3Type::getSizeInBits() {
+	return loader()->vm()->dataLayout()->getTypeSizeInBits(llvmType());
+}
+
 bool J3Type::isAssignableTo(J3Type* parent) {
 	resolve();
 	parent->resolve();
@@ -956,3 +974,4 @@ J3Primitive::J3Primitive(J3ClassLoader*
 	_nativeNameLength = 1;
 	_vt = J3VirtualTable::create(this);
 }
+

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=197987&r1=197986&r2=197987&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Tue Dec 24 13:02:33 2013
@@ -15,7 +15,7 @@ J3Options::J3Options() {
 
 	debugEnterIndent = 1;
 
-	debugExecute = 0;
+	debugExecute = 2;
 	debugLoad = 0;
 	debugResolve = 0;
 	debugIniting = 0;





More information about the vmkit-commits mailing list