[vmkit-commits] [vmkit] r180524 - Incinerator now provides API to help follow stale reference holders.(cherry picked from commit d1ca1585c74ead60bca8a13143dcf5a9c847469b)

Peter Senna Tschudin peter.senna at gmail.com
Thu Apr 25 10:21:32 PDT 2013


Author: peter.senna
Date: Thu Apr 25 12:20:02 2013
New Revision: 180524

URL: http://llvm.org/viewvc/llvm-project?rev=180524&view=rev
Log:
Incinerator now provides API to help follow stale reference holders.(cherry picked from commit d1ca1585c74ead60bca8a13143dcf5a9c847469b)

Modified:
    vmkit/trunk/incinerator/osgi/src/j3/J3Mgr.java
    vmkit/trunk/incinerator/osgi/src/j3/vm/OSGi.java
    vmkit/trunk/incinerator/osgi/src/j3mgr/J3MgrImpl.java
    vmkit/trunk/incinerator/tests/debug.txt
    vmkit/trunk/incinerator/tests/ijvm.tests.BundleMgmtStress/src/ijvm/tests/BundleMgmtStress/Activator.java
    vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/j3/VMCore/Jnjvm.h
    vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp
    vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp
    vmkit/trunk/lib/vmkit/CommonThread/ObjectLocks.cpp

Modified: vmkit/trunk/incinerator/osgi/src/j3/J3Mgr.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/incinerator/osgi/src/j3/J3Mgr.java?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/incinerator/osgi/src/j3/J3Mgr.java (original)
+++ vmkit/trunk/incinerator/osgi/src/j3/J3Mgr.java Thu Apr 25 12:20:02 2013
@@ -14,5 +14,7 @@ public interface J3Mgr
 	public void setBundleStaleReferenceCorrected(
 		String bundleNameOrID, String corrected) throws Throwable;
 	public void isBundleStaleReferenceCorrected(
-		String bundleNameOrID) throws Throwable;
+			String bundleNameOrID) throws Throwable;
+	public void dumpReferencesToObject(
+			String objectPointer) throws Throwable;
 }

Modified: vmkit/trunk/incinerator/osgi/src/j3/vm/OSGi.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/incinerator/osgi/src/j3/vm/OSGi.java?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/incinerator/osgi/src/j3/vm/OSGi.java (original)
+++ vmkit/trunk/incinerator/osgi/src/j3/vm/OSGi.java Thu Apr 25 12:20:02 2013
@@ -5,6 +5,9 @@ public class OSGi
 	// OSGi hooks and information gathering
 	public static native void associateBundleClass(long bundleID, Class classObject);
     public static native void notifyBundleUninstalled(long bundleID);
+    
+    public static native long[] getReferencesToObject(long objectPointer);
+    public static native String dumpObject(long objectPointer);
 	
 	// Commands
     public static native void setBundleStaleReferenceCorrected(long bundleID, boolean corrected);

Modified: vmkit/trunk/incinerator/osgi/src/j3mgr/J3MgrImpl.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/incinerator/osgi/src/j3mgr/J3MgrImpl.java?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/incinerator/osgi/src/j3mgr/J3MgrImpl.java (original)
+++ vmkit/trunk/incinerator/osgi/src/j3mgr/J3MgrImpl.java Thu Apr 25 12:20:02 2013
@@ -1,5 +1,8 @@
 package j3mgr;
 
+import java.util.Set;
+import java.util.TreeSet;
+
 import j3.J3Mgr;
 
 import org.osgi.framework.Bundle;
@@ -119,4 +122,53 @@ public class J3MgrImpl
 	{
 		j3.vm.OSGi.dumpClassLoaderBundles();
 	}
+
+	public void dumpReferencesToObject(String objectPointer) throws Throwable
+	{
+		int radix = 10;
+		if (objectPointer.startsWith("0x")) {
+			objectPointer = objectPointer.substring(2);
+			radix = 16;
+		}
+
+		long obj = Long.parseLong(objectPointer, radix);
+		
+		dumpReferencesToObject(obj, null, 4);
+		System.out.println(";");
+	}
+	
+	public void dumpReferencesToObject(long obj, Set<Long> objects, int depth) throws Throwable
+	{
+		if (obj == 0) {
+			System.out.print("0x0");
+			return;
+		}
+/*		
+		if (objects == null)
+			objects = new TreeSet<Long>();
+		
+		Long Obj = new Long(obj);
+		if ((depth <= 0) || objects.contains(Obj)) {
+			System.out.print(j3.vm.OSGi.dumpObject(obj));
+			return;	// Already dumped or depth reached
+		}
+		objects.add(Obj);
+*/	
+		if (depth <= 0) {
+			System.out.print(j3.vm.OSGi.dumpObject(obj));
+			return;	// Already dumped or depth reached
+		}
+		
+		System.out.print(j3.vm.OSGi.dumpObject(obj) + "<<{");
+		long[] refs = j3.vm.OSGi.getReferencesToObject(obj);
+		if (refs != null && refs.length > 0) {
+			dumpReferencesToObject(refs[0], objects, depth - 1);
+			
+			for (int i=1; i < refs.length; ++i) {
+				System.out.print(",");
+				dumpReferencesToObject(refs[i], objects, depth - 1);
+			}
+		}
+		System.out.print("}");
+	}
 }

Modified: vmkit/trunk/incinerator/tests/debug.txt
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/incinerator/tests/debug.txt?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/incinerator/tests/debug.txt (original)
+++ vmkit/trunk/incinerator/tests/debug.txt Thu Apr 25 12:20:02 2013
@@ -11,6 +11,14 @@ start 12 13 14
 stop 12
 
 framework call j3.J3Mgr isBundleStaleReferenceCorrected 39
-framework call j3.J3Mgr setBundleStaleReferenceCorrected 15 yes
+framework call j3.J3Mgr setBundleStaleReferenceCorrected 8 yes
 
-framework call j3.J3Mgr dumpClassLoaderBundles
+call j3.J3Mgr dumpClassLoaderBundles
+
+enter framework
+stop 8
+uninstall 8
+refresh
+meminfo -gc
+call j3.J3Mgr setBundleStaleReferenceCorrected 8 yes
+call j3.J3Mgr dumpReferencesToObject 0x51934ab4

Modified: vmkit/trunk/incinerator/tests/ijvm.tests.BundleMgmtStress/src/ijvm/tests/BundleMgmtStress/Activator.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/incinerator/tests/ijvm.tests.BundleMgmtStress/src/ijvm/tests/BundleMgmtStress/Activator.java?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/incinerator/tests/ijvm.tests.BundleMgmtStress/src/ijvm/tests/BundleMgmtStress/Activator.java (original)
+++ vmkit/trunk/incinerator/tests/ijvm.tests.BundleMgmtStress/src/ijvm/tests/BundleMgmtStress/Activator.java Thu Apr 25 12:20:02 2013
@@ -12,8 +12,8 @@ public class Activator
 	implements BundleActivator, Runnable
 {
 	static final boolean correctStaleReferences = false;
-	static final String targetBundle = "file:///home/koutheir/PhD/VMKit/knopflerfish.verbatim/osgi/jars/http/http_all-3.1.2.jar";
-	static final long firstBundleID = 6;
+	static final String targetBundle = "file:///home/koutheir/PhD/VMKit/knopflerfish/osgi/jars/http/http_all-3.1.2.jar";
+	static final long firstBundleID = 8;
 	
 	BundleContext context;
 	Thread worker;
@@ -89,6 +89,7 @@ public class Activator
 				currentState == Bundle.STARTING) {
 				thisBundle.stop();
 			}
+			worker = null;
 		} catch (BundleException e) {
 			e.printStackTrace();
 		}
@@ -96,6 +97,8 @@ public class Activator
 	
 	void uninstallBundle(Bundle bundle) throws Throwable
 	{	
+		if (bundle == null) return;
+		
 		try {
 			j3mgr.setBundleStaleReferenceCorrected(
 				bundle.getBundleId(), correctStaleReferences);

Modified: vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp Thu Apr 25 12:20:02 2013
@@ -1318,7 +1318,7 @@ Jnjvm::Jnjvm(vmkit::BumpPtrAllocator& Al
              JnjvmBootstrapLoader* loader) : 
   VirtualMachine(Alloc, frames), lockSystem(Alloc)
 #if RESET_STALE_REFERENCES
-	, scanStaleReferences(false)
+	, scanStaleReferences(false), findReferencesToObject(NULL)
 #endif
 {
 
@@ -1358,13 +1358,20 @@ void Jnjvm::startCollection() {
 	fflush(stdout);
 #endif
 
-#if RESET_STALE_REFERENCES && DEBUG_VERBOSE_STALE_REF
+#if RESET_STALE_REFERENCES
+
+#if DEBUG_VERBOSE_STALE_REF
 
 	if (scanStaleReferences)
 		std::cerr << "Looking for stale references..." << std::endl;
 
 #endif
 
+	if (findReferencesToObject != NULL)
+		foundReferencerObjects.clear();
+
+#endif
+
   finalizerThread->FinalizationQueueLock.acquire();
   referenceThread->ToEnqueueLock.acquire();
   referenceThread->SoftReferencesQueue.acquire();
@@ -1384,6 +1391,7 @@ void Jnjvm::endCollectionBeforeUnlocking
 
 	// Stale references can no more exist, until a bundle is uninstalled later.
 	scanStaleReferences = false;
+	findReferencesToObject = NULL;
 
 #endif
 }

Modified: vmkit/trunk/lib/j3/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/Jnjvm.h?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/j3/VMCore/Jnjvm.h Thu Apr 25 12:20:02 2013
@@ -136,6 +136,7 @@ private:
   virtual void finalizeObject(gc* res);
   virtual void traceObject(gc* obj, word_t closure);
   virtual void setType(gc* header, void* type);
+  virtual void setType(void* header, void* type);
   virtual void* getType(gc* obj);
   virtual size_t getObjectSize(gc* obj);
   virtual const char* getObjectTypeName(gc* obj);
@@ -375,8 +376,6 @@ public:
 
   void notifyBundleUninstalled(int64_t bundleID);
 
-  void notifyBundleUninstalled(int64_t bundleID);
-
   int64_t getClassLoaderBundleID(JnjvmClassLoader* loader);
   JnjvmClassLoader* getBundleClassLoader(int64_t bundleID);
   void setBundleClassLoader(int64_t bundleID, JnjvmClassLoader* loader);

Modified: vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp Thu Apr 25 12:20:02 2013
@@ -1,11 +1,14 @@
 
 #include <algorithm>
 #include <iostream>
+#include <sstream>
 
 #include "VmkitGC.h"
 #include "Jnjvm.h"
 #include "ClasspathReflect.h"
+#include "JavaUpcalls.h"
 #include "j3/jni.h"
+#include "JavaArray.h"
 
 
 using namespace std;
@@ -68,6 +71,25 @@ void Jnjvm::dumpClassLoaderBundles()
 	}
 }
 
+ArrayLong* Jnjvm::getReferencesToObject(const JavaObject* obj)
+{
+	if (!obj) return NULL;
+
+	findReferencesToObject = obj;
+	vmkit::Collector::collect();
+
+	size_t count = foundReferencerObjects.size();
+	ArrayLong* r = static_cast<ArrayLong*>(upcalls->ArrayOfLong->doNew(count, this));
+	if (!r) {this->outOfMemoryError(); return r;}
+
+	ArrayLong::ElementType* elements = ArrayLong::getElements(r);
+	for (size_t i=0; i < count; ++i) {
+		elements[i] = reinterpret_cast<ArrayLong::ElementType>(foundReferencerObjects[i]);
+	}
+
+	return r;
+}
+
 JnjvmClassLoader* Jnjvm::getBundleClassLoader(int64_t bundleID)
 {
 	if (bundleID == -1) return NULL;
@@ -172,3 +194,28 @@ extern "C" void Java_j3_vm_OSGi_dumpClas
 
 #endif
 }
+
+extern "C" ArrayLong* Java_j3_vm_OSGi_getReferencesToObject(jlong objectPointer)
+{
+#if RESET_STALE_REFERENCES
+
+	Jnjvm* vm = JavaThread::get()->getJVM();
+	return vm->getReferencesToObject(reinterpret_cast<const JavaObject*>((intptr_t)objectPointer));
+
+#endif
+}
+
+extern "C" JavaString* Java_j3_vm_OSGi_dumpObject(jlong objectPointer)
+{
+#if RESET_STALE_REFERENCES
+
+	if (!objectPointer) return NULL;
+	const JavaObject& obj = *reinterpret_cast<const JavaObject*>((intptr_t)objectPointer);
+	std::ostringstream ss;
+	ss << obj;
+
+	Jnjvm* vm = JavaThread::get()->getJVM();
+	return vm->asciizToStr(ss.str().c_str());
+
+#endif
+}

Modified: vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp Thu Apr 25 12:20:02 2013
@@ -18,12 +18,15 @@ void Jnjvm::resetReferenceIfStale(const
 	JavaObject *src = NULL;
 	llvm_gcroot(src, 0);
 
-	if (!scanStaleReferences) return;	// Stale references scanning disabled
 	if (!ref || !(*ref)) return;	// Invalid or null reference
-
 	src = const_cast<JavaObject*>(reinterpret_cast<const JavaObject*>(source));
 	JavaObject **objRef = reinterpret_cast<JavaObject**>(ref);
 
+	if (findReferencesToObject == *objRef)
+		foundReferencerObjects.push_back(src);
+
+	if (!scanStaleReferences) return;	// Stale references scanning disabled
+
 	// Check the type of Java object. Some Java objects are not real object, but
 	// are bridges between Java and the VM objects.
 	if (VMClassLoader::isVMClassLoader(*objRef))

Modified: vmkit/trunk/lib/vmkit/CommonThread/ObjectLocks.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/vmkit/CommonThread/ObjectLocks.cpp?rev=180524&r1=180523&r2=180524&view=diff
==============================================================================
--- vmkit/trunk/lib/vmkit/CommonThread/ObjectLocks.cpp (original)
+++ vmkit/trunk/lib/vmkit/CommonThread/ObjectLocks.cpp Thu Apr 25 12:20:02 2013
@@ -45,7 +45,7 @@ void ThinLock::overflowThinLock(gc* obje
  
 /// initialise - Initialise the value of the lock.
 ///
-#if 0
+#if 1
 // Disable fat lock deflation code in ObjectLocks.cpp
 // Fixes occasional assertion failure when running on multi-core machine.
 void ThinLock::removeFatLock(FatLock* fatLock, LockSystem& table) {
@@ -156,7 +156,7 @@ void ThinLock::acquire(gc* object, LockS
         if (obj->acquire(object, table)) {
           assert((object->header() & FatMask) && "Inconsistent lock");
           assert((table.getFatLockFromID(object->header()) == obj) && "Inconsistent lock");
-          assert(owner(object, table) && "Not owner after acquiring fat lock!");
+          assert(owner(object, table) && "Not owner after acquring fat lock!");
           break;
         }
       }
@@ -303,7 +303,7 @@ void FatLock::release(gc* obj, LockSyste
   llvm_gcroot(obj, 0);
   assert(associatedObject && "No associated object when releasing");
   assert(associatedObject == obj && "Mismatch object in lock");
-#if 0
+#if 1
   // Disable fat lock deflation code in ObjectLocks.cpp
   // Fixes occasional assertion failure when running on multi-core machine.
   if (!waitingThreads && !lockingThreads &&
@@ -441,7 +441,6 @@ bool LockingThread::wait(
   }
   
   this->state = LockingThread::StateWaiting;
-
   if (l->firstThread) {
     assert(l->firstThread->prevWaiting && l->firstThread->nextWaiting &&
            "Inconsistent list");
@@ -504,7 +503,7 @@ bool LockingThread::wait(
       this->nextWaiting = NULL;
       this->prevWaiting = NULL;
     } else {
-      assert(!this->prevWaiting && "Inconsistent state");
+      assert(!this->prevWaiting && "Inconstitent state");
       // Notify lost, notify someone else.
       notify(self, table);
     }





More information about the vmkit-commits mailing list