[vmkit-commits] [PATCH] Impl JVM_GetClassContext, refactor existing code into shared ClassContext.inc.

Will Dietz wdietz2 at illinois.edu
Sun Nov 6 18:58:29 PST 2011


Inlined below.

~Will

>From 4c7de028f511bf52c3601ce57beb02ffcb939420 Mon Sep 17 00:00:00 2001
From: Will Dietz <w at wdtz.org>
Date: Sat, 5 Nov 2011 20:47:15 -0500
Subject: [PATCH 2/8] Impl JVM_GetClassContext, refactor existing code into
 shared ClassContext.inc.

Also, fix ClassContext creation of wrong array type.
---
 lib/J3/ClassLib/ClassContext.inc                   |   36 ++++++++++++++++++++
 .../GNUClasspath/ClasspathVMStackWalker.inc        |   25 ++-----------
 lib/J3/ClassLib/OpenJDK/OpenJDK.inc                |   12 ++++++-
 3 files changed, 51 insertions(+), 22 deletions(-)
 create mode 100644 lib/J3/ClassLib/ClassContext.inc

diff --git a/lib/J3/ClassLib/ClassContext.inc b/lib/J3/ClassLib/ClassContext.inc
new file mode 100644
index 0000000..71c17d7
--- /dev/null
+++ b/lib/J3/ClassLib/ClassContext.inc
@@ -0,0 +1,36 @@
+//===------------ ClassContext.inc -- Implement GetClassContext
-----------===//
+//
+//                            The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+ArrayObject* GetClassContext() {
+  ArrayObject* result = NULL;
+  JavaObject* delegatee = NULL;
+  llvm_gcroot(result, 0);
+  llvm_gcroot(delegatee, 0);
+
+  JavaThread* th = JavaThread::get();
+  Jnjvm* vm = th->getJVM();
+  uint32 length = th->getFrameContextLength();
+
+  mvm::ThreadAllocator allocator;
+  uintptr_t* buffer = (uintptr_t*)allocator.Allocate(length *
sizeof(uintptr_t));
+
+  uint32 finalSize = th->getJavaFrameContext((void**)buffer);
+
+  result = (ArrayObject*)
+    vm->upcalls->classArrayClass->doNew(finalSize, vm);
+
+  for (uint32 i = 0; i != finalSize; ++i) {
+    JavaMethod* meth = ((JavaMethod**)buffer)[i];
+    assert(meth && "Wrong stack trace");
+    delegatee = meth->classDef->getClassDelegatee(vm);;
+    ArrayObject::setElement(result, delegatee, i);
+  }
+
+  return result;
+}
diff --git a/lib/J3/ClassLib/GNUClasspath/ClasspathVMStackWalker.inc
b/lib/J3/ClassLib/GNUClasspath/ClasspathVMStackWalker.inc
index b0c94e5..c51a246 100644
--- a/lib/J3/ClassLib/GNUClasspath/ClasspathVMStackWalker.inc
+++ b/lib/J3/ClassLib/GNUClasspath/ClasspathVMStackWalker.inc
@@ -19,6 +19,8 @@
 #include "JavaUpcalls.h"
 #include "Jnjvm.h"

+#include "ClassContext.inc"
+
 using namespace j3;

 extern "C" {
@@ -31,31 +33,12 @@ jclass clazz,
 ) {

   ArrayObject* result = NULL;
-  JavaObject* delegatee = NULL;
   llvm_gcroot(result, 0);
-  llvm_gcroot(delegatee, 0);

   BEGIN_NATIVE_EXCEPTION(0)

-  JavaThread* th = JavaThread::get();
-  Jnjvm* vm = th->getJVM();
-  uint32 length = th->getFrameContextLength();
-
-  mvm::ThreadAllocator allocator;
-  uintptr_t* buffer = (uintptr_t*)allocator.Allocate(length *
sizeof(uintptr_t));
-
-  uint32 finalSize = th->getJavaFrameContext((void**)buffer);
-
-  result = (ArrayObject*)
-    vm->upcalls->stackTraceArray->doNew(finalSize, vm);
-
-  for (uint32 i = 0; i != finalSize; ++i) {
-    JavaMethod* meth = ((JavaMethod**)buffer)[i];
-    assert(meth && "Wrong stack trace");
-    delegatee = meth->classDef->getClassDelegatee(vm);;
-    ArrayObject::setElement(result, delegatee, i);
-  }
-
+  result = GetClassContext();
+
   END_NATIVE_EXCEPTION

   return result;
diff --git a/lib/J3/ClassLib/OpenJDK/OpenJDK.inc
b/lib/J3/ClassLib/OpenJDK/OpenJDK.inc
index 947b7d3..012b021 100644
--- a/lib/J3/ClassLib/OpenJDK/OpenJDK.inc
+++ b/lib/J3/ClassLib/OpenJDK/OpenJDK.inc
@@ -12,6 +12,7 @@
 #include "Reader.h"

 #include "ArrayCopy.inc"
+#include "ClassContext.inc"
 #include "SetProperties.inc"
 #include "Object.inc"

@@ -672,7 +673,16 @@ JVM_CurrentClassLoader(JNIEnv *env) {

 JNIEXPORT jobjectArray JNICALL
 JVM_GetClassContext(JNIEnv *env) {
-  NYI();
+  ArrayObject * res = 0;
+  llvm_gcroot(res, 0);
+  BEGIN_JNI_EXCEPTION
+
+  res = GetClassContext();
+
+  RETURN_FROM_JNI((jobjectArray)th->pushJNIRef(res));
+  END_JNI_EXCEPTION
+
+  return 0;
 }

 JNIEXPORT jint JNICALL
-- 
1.7.5.1



More information about the vmkit-commits mailing list