[vmkit-commits] [vmkit] r76370 - /vmkit/trunk/lib/JnJVM/VMCore/JNIReferences.h
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Jul 19 09:40:25 PDT 2009
Author: geoffray
Date: Sun Jul 19 11:40:25 2009
New Revision: 76370
URL: http://llvm.org/viewvc/llvm-project?rev=76370&view=rev
Log:
Forgot this file from last commit.
Added:
vmkit/trunk/lib/JnJVM/VMCore/JNIReferences.h
Added: vmkit/trunk/lib/JnJVM/VMCore/JNIReferences.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JNIReferences.h?rev=76370&view=auto
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JNIReferences.h (added)
+++ vmkit/trunk/lib/JnJVM/VMCore/JNIReferences.h Sun Jul 19 11:40:25 2009
@@ -0,0 +1,88 @@
+//===--------- JNIReferences.cpp - Management of JNI references -----------===//
+//
+// The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef JNI_REFERENCES_H
+#define JNI_REFERENCES_H
+
+namespace jnjvm {
+
+class JavaObject;
+class JavaThread;
+
+#define MAXIMUM_REFERENCES 100
+
+class JNILocalReferences {
+ friend class JavaThread;
+
+private:
+ JNILocalReferences* prev;
+ uint32_t length;
+ JavaObject* localReferences[MAXIMUM_REFERENCES];
+
+public:
+
+ JNILocalReferences() {
+ prev = 0;
+ length = 0;
+ }
+
+ JavaObject** addJNIReference(JavaThread* th, JavaObject* obj);
+
+ void removeJNIReferences(JavaThread* th, uint32_t num);
+
+};
+
+class JNIGlobalReferences {
+ friend class Jnjvm;
+
+private:
+ JNIGlobalReferences* next;
+ JNIGlobalReferences* prev;
+ uint32_t length;
+ uint32_t count;
+ JavaObject* globalReferences[MAXIMUM_REFERENCES];
+
+
+public:
+ JNIGlobalReferences() {
+ next = 0;
+ prev = 0;
+ length = 0;
+ count = 0;
+ }
+
+ JavaObject** addJNIReference(JavaObject* obj) {
+ if (length == MAXIMUM_REFERENCES) {
+ if (!next) {
+ next = new JNIGlobalReferences();
+ next->prev = this;
+ }
+ return next->addJNIReference(obj);
+ } else {
+ ++count;
+ globalReferences[length] = obj;
+ return &globalReferences[length++];
+ }
+ }
+
+ void removeJNIReference(JavaObject** obj) {
+ if (((uintptr_t)obj >= (uintptr_t)globalReferences) &&
+ ((uintptr_t)obj) < (uintptr_t)(globalReferences + MAXIMUM_REFERENCES)) {
+ *obj = 0;
+ --count;
+ } else {
+ assert(next && "No global reference located there");
+ next->removeJNIReference(obj);
+ }
+ }
+};
+
+}
+
+#endif
More information about the vmkit-commits
mailing list