[vmkit-commits] [vmkit] r108828 - /vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Jul 20 05:26:36 PDT 2010


Author: geoffray
Date: Tue Jul 20 07:26:36 2010
New Revision: 108828

URL: http://llvm.org/viewvc/llvm-project?rev=108828&view=rev
Log:
Cosmetic change.


Modified:
    vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp

Modified: vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp?rev=108828&r1=108827&r2=108828&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp Tue Jul 20 07:26:36 2010
@@ -20,6 +20,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClasspathReflect.h"
 #include "JavaArray.h"
 #include "JavaClass.h"
 #include "JavaObject.h"
@@ -64,25 +65,62 @@
 
 //===----------------------------------------------------------------------===//
 // Trace methods for Java objects. There are four types of objects:
-// (1) Base object whose class is not an array: needs to trace the classloader
-//     and the lock.
-// (1) Object whose class is not an array: needs to trace the classloader, the
-//     lock and all the virtual fields.
-// (2) Object whose class is an array of objects: needs to trace root (1) and
-//     all elements in the array.
-// (3) Object whose class is a native array: only needs to trace the lock. The
+// (1) Regular object: needs to trace the classloader, and all the virtual
+//     fields.
+// (2) java.lang.ref.Reference objects: needs to trace the class loader and
+//     all the virtual fields except the referent.
+// (3) Object whose class is an array of objects: needs to trace the class loader
+//     and all elements in the array.
+// (4) Object whose class is a native array: nothing to trace. The
 //     classloader is the bootstrap loader and is traced by the JVM.
 //===----------------------------------------------------------------------===//
 
+/// Method for scanning regular objects.
+extern "C" void RegularObjectTracer(JavaObject* obj, uintptr_t closure) {
+  Class* cl = JavaObject::getClass(obj)->asClass();
+  assert(cl && "Not a class in regular tracer");
+  mvm::Collector::markAndTraceRoot(
+      cl->classLoader->getJavaClassLoaderPtr(), closure);
 
-/// Method for scanning the root of an object.
-extern "C" void JavaObjectTracer(JavaObject* obj, uintptr_t closure) {
-  CommonClass* cl = JavaObject::getClass(obj);
-  assert(cl && "No class");
+  while (cl->super != 0) {
+    for (uint32 i = 0; i < cl->nbVirtualFields; ++i) {
+      JavaField& field = cl->virtualFields[i];
+      if (field.isReference()) {
+        JavaObject** ptr = field.getInstanceObjectFieldPtr(obj);
+        mvm::Collector::markAndTrace(obj, ptr, closure);
+      }
+    }
+    cl = cl->super;
+  }
+}
+
+/// Method for scanning Java java.lang.ref.Reference objects.
+extern "C" void ObjectReferenceTracer(
+    JavaObjectReference* obj, uintptr_t closure) {
+  Class* cl = JavaObject::getClass(obj)->asClass();
+  assert(cl && "Not a class in reference tracer");
   mvm::Collector::markAndTraceRoot(
       cl->classLoader->getJavaClassLoaderPtr(), closure);
+
+  bool found = false;
+  while (cl->super != 0) {
+    for (uint32 i = 0; i < cl->nbVirtualFields; ++i) {
+      JavaField& field = cl->virtualFields[i];
+      if (field.isReference()) {
+        JavaObject** ptr = field.getInstanceObjectFieldPtr(obj);
+        if (ptr != JavaObjectReference::getReferentPtr(obj)) {
+          mvm::Collector::markAndTrace(obj, ptr, closure);
+        } else {
+          found = true;
+        }
+      }
+    }
+    cl = cl->super;
+  }
+  assert(found && "No referent in a reference");
 }
 
+
 /// Method for scanning an array whose elements are JavaObjects. This method is
 /// called by all non-native Java arrays.
 extern "C" void ArrayObjectTracer(ArrayObject* obj, uintptr_t closure) {
@@ -91,7 +129,6 @@
   mvm::Collector::markAndTraceRoot(
       cl->classLoader->getJavaClassLoaderPtr(), closure);
   
-
   for (sint32 i = 0; i < ArrayObject::getSize(obj); i++) {
     if (ArrayObject::getElement(obj, i) != NULL) {
       mvm::Collector::markAndTrace(
@@ -106,26 +143,6 @@
 extern "C" void JavaArrayTracer(JavaArray* obj, uintptr_t closure) {
 }
 
-/// Method for scanning regular objects.
-extern "C" void RegularObjectTracer(JavaObject* obj, uintptr_t closure) {
-  Class* cl = JavaObject::getClass(obj)->asClass();
-  assert(cl && "Not a class in regular tracer");
-  mvm::Collector::markAndTraceRoot(
-      cl->classLoader->getJavaClassLoaderPtr(), closure);
-
-  while (cl->super != 0) {
-    for (uint32 i = 0; i < cl->nbVirtualFields; ++i) {
-      JavaField& field = cl->virtualFields[i];
-      if (field.isReference()) {
-        JavaObject** ptr = field.getInstanceObjectFieldPtr(obj);
-        mvm::Collector::markAndTrace(obj, ptr, closure);
-      }
-    }
-    cl = cl->super;
-  }
-}
-
-
 //===----------------------------------------------------------------------===//
 // Support for scanning Java objects referenced by classes. All classes must
 // trace:
@@ -141,25 +158,27 @@
 
 void CommonClass::tracer(uintptr_t closure) {
   
-  if (super && super->classLoader) {
+  if (super != NULL && super->classLoader != NULL) {
     JavaObject** Obj = super->classLoader->getJavaClassLoaderPtr();
     if (*Obj) mvm::Collector::markAndTraceRoot(Obj, closure);
   
     for (uint32 i = 0; i < nbInterfaces; ++i) {
-      if (interfaces[i]->classLoader) {
+      if (interfaces[i]->classLoader != NULL) {
         JavaObject** Obj = interfaces[i]->classLoader->getJavaClassLoaderPtr();
-        if (*Obj) mvm::Collector::markAndTraceRoot(Obj, closure);
+        if ((*Obj) != NULL) mvm::Collector::markAndTraceRoot(Obj, closure);
       }
     }
   }
 
-  if (classLoader)
+  if (classLoader != NULL) {
     mvm::Collector::markAndTraceRoot(
         classLoader->getJavaClassLoaderPtr(), closure);
+  }
 
   for (uint32 i = 0; i < NR_ISOLATES; ++i) {
-    // If the delegatee was static allocated, we want to trace its fields.
-    if (delegatee[i]) {
+    if (delegatee[i] != NULL) {
+      // TODO: remove the call to tracer until no j.l.Class are allocated
+      // statically in AOT.
       delegatee[i]->tracer(closure);
       mvm::Collector::markAndTraceRoot(delegatee + i, closure);
     }





More information about the vmkit-commits mailing list