[vmkit-commits] [vmkit] r180519 - Updating stale references lookup and selection routine.
Peter Senna Tschudin
peter.senna at gmail.com
Thu Apr 25 10:20:50 PDT 2013
Author: peter.senna
Date: Thu Apr 25 12:19:18 2013
New Revision: 180519
URL: http://llvm.org/viewvc/llvm-project?rev=180519&view=rev
Log:
Updating stale references lookup and selection routine.
(cherry picked from commit dfde1ee13aac1d8db2cabe4ae7eed61bc1ca6992)
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/lib/j3/Compiler/JavaAOTCompiler.cpp
vmkit/trunk/lib/j3/LLVMRuntime/runtime-single.ll
vmkit/trunk/lib/j3/VMCore/JavaClass.h
vmkit/trunk/lib/j3/VMCore/Jnjvm.h
vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.cpp
vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.h
vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp
vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.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=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/incinerator/osgi/src/j3/J3Mgr.java (original)
+++ vmkit/trunk/incinerator/osgi/src/j3/J3Mgr.java Thu Apr 25 12:19:18 2013
@@ -1,20 +1,16 @@
package j3;
+import org.osgi.framework.Bundle;
+
public interface J3Mgr
{
- public void setBundleStaleReferenceCorrected(
- long bundleID, boolean corrected) throws Throwable;
- public boolean isBundleStaleReferenceCorrected(
- long bundleID) throws Throwable;
+ public void setBundleStaleReferenceCorrected(Bundle bundle, boolean corrected) throws Exception;
+ public boolean isBundleStaleReferenceCorrected(Bundle bundle) throws Exception;
// THE FOLLOWING METHODS ARE DEBUGGING HELPERS
// THEY SHOULD BE REMOVED IN PRODUCTION
- public void dumpClassLoaderBundles() throws Throwable;
- public void setBundleStaleReferenceCorrected(
- String bundleNameOrID, String corrected) throws Throwable;
- public void isBundleStaleReferenceCorrected(
- String bundleNameOrID) throws Throwable;
- public void dumpReferencesToObject(
- String objectPointer) throws Throwable;
+ public void dumpClassLoaderBundles();
+ public void setBundleStaleReferenceCorrected(String bundleName, String corrected) throws Exception;
+ public void isBundleStaleReferenceCorrected(String bundleName) throws Exception;
}
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=180519&r1=180518&r2=180519&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:19:18 2013
@@ -4,10 +4,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);
+ public static native void notifyBundleUninstalled(long bundleID);
+ public static native void notifyServiceUnregistered(long bundleID, Class classObject);
// 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=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/incinerator/osgi/src/j3mgr/J3MgrImpl.java (original)
+++ vmkit/trunk/incinerator/osgi/src/j3mgr/J3MgrImpl.java Thu Apr 25 12:19:18 2013
@@ -1,19 +1,16 @@
package j3mgr;
-import java.util.Set;
-import java.util.TreeSet;
-
import j3.J3Mgr;
+import org.osgi.framework.AllServiceListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.framework.ServiceEvent;
public class J3MgrImpl
- implements J3Mgr, BundleListener
+ implements J3Mgr, BundleListener, AllServiceListener
{
BundleContext context;
@@ -22,153 +19,68 @@ public class J3MgrImpl
context = bundleContext;
context.addBundleListener(this);
+ context.addServiceListener(this);
}
public void close()
{
context.removeBundleListener(this);
+ context.removeServiceListener(this);
context = null;
}
- public void setBundleStaleReferenceCorrected(
- long bundleID, boolean corrected) throws Throwable
+ public void setBundleStaleReferenceCorrected(Bundle bundle, boolean corrected) throws Exception
{
- j3.vm.OSGi.setBundleStaleReferenceCorrected(bundleID, corrected);
-
- if (!corrected || (context.getBundle(bundleID) != null))
- return; // Bundle ignored, or still installed
-
- // Inexistent bundle to be corrected, probably uninstalled,
- // Notify the VM now.
- j3.vm.OSGi.notifyBundleUninstalled(bundleID);
- refreshFramework();
+ j3.vm.OSGi.setBundleStaleReferenceCorrected(bundle.getBundleId(), corrected);
}
- public boolean isBundleStaleReferenceCorrected(
- long bundleID) throws Throwable
+ public boolean isBundleStaleReferenceCorrected(Bundle bundle) throws Exception
{
- return j3.vm.OSGi.isBundleStaleReferenceCorrected(bundleID);
+ return j3.vm.OSGi.isBundleStaleReferenceCorrected(bundle.getBundleId());
}
- public void bundleChanged(BundleEvent event)
+ public void serviceChanged(ServiceEvent event)
{
- if (event.getType() != BundleEvent.UNINSTALLED) return;
-
- try {
- j3.vm.OSGi.notifyBundleUninstalled(event.getBundle().getBundleId());
- refreshFramework();
- } catch (Throwable e) {}
+ if (event.getType() != ServiceEvent.UNREGISTERING) return;
+ // WARNING: Service is NOT yet unregistered here. Find a solution to know when it is.
+ j3.vm.OSGi.notifyServiceUnregistered(
+ event.getServiceReference().getBundle().getBundleId(),
+ context.getService(event.getServiceReference()).getClass()
+ );
}
-
- void refreshFramework()
+
+ public void bundleChanged(BundleEvent event)
{
- ServiceReference<?> pkgAdminRef =
- (ServiceReference<?>)context.getServiceReference(
- "org.osgi.service.packageadmin.PackageAdmin");
- PackageAdmin pkgAdmin = (PackageAdmin)context.getService(pkgAdminRef);
- pkgAdmin.refreshPackages(null);
- context.ungetService(pkgAdminRef);
+ if (event.getType() != BundleEvent.UNINSTALLED) return;
+ j3.vm.OSGi.notifyBundleUninstalled(event.getBundle().getBundleId());
}
// THE FOLLOWING METHODS ARE DEBUGGING HELPERS
// THEY SHOULD BE REMOVED IN PRODUCTION
- public void setBundleStaleReferenceCorrected(
- String bundleNameOrID, String corrected) throws Throwable
+ public void setBundleStaleReferenceCorrected(String bundleName, String corrected) throws Exception
{
- long bundleID = getBundleID(bundleNameOrID);
- if (bundleID == -1) throw new IllegalArgumentException(bundleNameOrID);
-
- setBundleStaleReferenceCorrected(bundleID, corrected.equals("yes"));
+ setBundleStaleReferenceCorrected(getBundle(bundleName), corrected.equals("yes"));
}
- public void isBundleStaleReferenceCorrected(
- String bundleNameOrID) throws Throwable
+ public void isBundleStaleReferenceCorrected(String bundleName) throws Exception
+ {
+ boolean value = isBundleStaleReferenceCorrected(getBundle(bundleName));
+ System.out.println("isBundleStaleReferenceCorrected(" + bundleName + ") = " + (value ? "yes" : "no"));
+ }
+
+ Bundle getBundle(String symbolicName)
{
- long bundleID = getBundleID(bundleNameOrID);
- if (bundleID == -1) throw new IllegalArgumentException(bundleNameOrID);
-
- boolean value = isBundleStaleReferenceCorrected(bundleID);
- System.out.println(
- "isBundleStaleReferenceCorrected(bundleID=" + bundleID + ") = " +
- (value ? "yes" : "no"));
- }
-
- long getBundleID(String symbolicNameOrID)
- {
- try {
- long bundleID = Long.parseLong(symbolicNameOrID);
-
- if (context.getBundle(bundleID) == null) {
- System.out.println(
- "WARNING: bundleID=" + bundleID +
- " is invalid, probably already uninstalled.");
- }
-
- return (bundleID < 0) ? -1 : bundleID;
- } catch (NumberFormatException e) {
- // This is not a bundle ID, it must be a symbolic name
- }
-
Bundle[] bundles = context.getBundles();
for (int i=0; i < bundles.length; ++i) {
- if (symbolicNameOrID.equals(bundles[i].getSymbolicName()))
- return bundles[i].getBundleId();
+ if (symbolicName.equals(bundles[i].getSymbolicName()))
+ return bundles[i];
}
- return -1;
+ return null;
}
- public void dumpClassLoaderBundles() throws Throwable
+ public void dumpClassLoaderBundles()
{
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=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/incinerator/tests/debug.txt (original)
+++ vmkit/trunk/incinerator/tests/debug.txt Thu Apr 25 12:19:18 2013
@@ -1,24 +1,14 @@
/home/koutheir/PhD/VMKit/vmkit_stale_ref/Debug+Asserts/bin/j3 -jar framework.jar -xargs /home/koutheir/PhD/VMKit/vmkit_stale_ref/tests/minimal.xargs
+framework call j3.J3Mgr resetReferencesToBundle ijvm.tests.AImpl
+
+framework call j3.J3Mgr resetReferencesToBundle ijvm.tests.Runner
+
+framework meminfo -gc
+
+bundles
+start 18
+
+framework call j3.J3Mgr dumpClassLoaderBundles
+
framework call j3.J3Mgr setBundleStaleReferenceCorrected ijvm.tests.AImpl yes
-framework call j3.J3Mgr setBundleStaleReferenceCorrected ijvm.tests.BImpl yes
-framework call j3.J3Mgr setBundleStaleReferenceCorrected ijvm.tests.CImpl yes
-stop 12
-stop 13
-stop 14
-
-start 12 13 14
-stop 12
-
-framework call j3.J3Mgr isBundleStaleReferenceCorrected 39
-framework call j3.J3Mgr setBundleStaleReferenceCorrected 8 yes
-
-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/lib/j3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/Compiler/JavaAOTCompiler.cpp?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/j3/Compiler/JavaAOTCompiler.cpp Thu Apr 25 12:19:18 2013
@@ -1393,6 +1393,9 @@ Constant* JavaAOTCompiler::CreateConstan
// minJDKVersionBuild
ClassElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), cl->minJDKVersionBuild));
+ // zombie
+ ClassElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), cl->zombie));
+
return ConstantStruct::get(STy, ClassElts);
}
Modified: vmkit/trunk/lib/j3/LLVMRuntime/runtime-single.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/LLVMRuntime/runtime-single.ll?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/LLVMRuntime/runtime-single.ll (original)
+++ vmkit/trunk/lib/j3/LLVMRuntime/runtime-single.ll Thu Apr 25 12:19:18 2013
@@ -10,4 +10,4 @@
%JavaClass = type { %JavaCommonClass, i32, i32, [1 x %TaskClassMirror],
%JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16,
%JavaMethod*, i16, i8*, %ClassBytes*, %JavaConstantPool*, %Attribute*,
- i16, %JavaClass**, i16, %JavaClass*, i16, i8, i8, i32, i32, i16, i16, i16 }
+ i16, %JavaClass**, i16, %JavaClass*, i16, i8, i8, i32, i32, i16, i16, i16, i8 }
Modified: vmkit/trunk/lib/j3/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaClass.h?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/j3/VMCore/JavaClass.h Thu Apr 25 12:19:18 2013
@@ -532,6 +532,11 @@ public:
uint16_t minJDKVersionMajor, minJDKVersionMinor, minJDKVersionBuild;
+ // A class becomes zombie when strong references to it exist in memory while:
+ // - Its defining bundle is uninstalled;
+ // - or it is an interface for an unregistered service.
+ bool zombie;
+
/// getVirtualSize - Get the virtual size of instances of this class.
///
uint32 getVirtualSize() const { return virtualSize; }
@@ -826,6 +831,9 @@ public:
static void getMinimalJDKVersion(uint16_t major, uint16_t minor, uint16_t& JDKMajor, uint16_t& JDKMinor, uint16_t& JDKBuild);
bool isClassVersionSupported(uint16_t major, uint16_t minor);
+
+ bool isZombie() const {return zombie;}
+ void markZombie(bool becomeZombie = true) {zombie = becomeZombie;}
};
/// ClassArray - This class represents Java array classes.
Modified: vmkit/trunk/lib/j3/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/Jnjvm.h?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/j3/VMCore/Jnjvm.h Thu Apr 25 12:19:18 2013
@@ -375,6 +375,9 @@ public:
void notifyBundleUninstalled(int64_t bundleID);
+ void notifyBundleUninstalled(int64_t bundleID);
+ void notifyServiceUnregistered(int64_t bundleID, class JavaObjectClass* classObject);
+
int64_t getClassLoaderBundleID(JnjvmClassLoader* loader);
JnjvmClassLoader* getBundleClassLoader(int64_t bundleID);
void setBundleClassLoader(int64_t bundleID, JnjvmClassLoader* loader);
Modified: vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.cpp?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.cpp Thu Apr 25 12:19:18 2013
@@ -32,7 +32,7 @@
#include "Classpath.h"
#include "ClasspathReflect.h"
#include "JavaClass.h"
-#include "j3/JavaCompiler.h"
+#include "JavaCompiler.h"
#include "JavaConstantPool.h"
#include "JavaString.h"
#include "JavaThread.h"
@@ -215,7 +215,7 @@ JnjvmBootstrapLoader::JnjvmBootstrapLoad
JnjvmClassLoader::JnjvmClassLoader(vmkit::BumpPtrAllocator& Alloc) :
allocator(Alloc)
#if RESET_STALE_REFERENCES
- ,staleRefCorrected(false), zombie(false)
+ ,staleRefCorrected(false)
#endif
{
}
@@ -225,7 +225,7 @@ JnjvmClassLoader::JnjvmClassLoader(vmkit
VMClassLoader* vmdata,
Jnjvm* VM) : allocator(Alloc)
#if RESET_STALE_REFERENCES
- ,staleRefCorrected(false), zombie(false)
+ ,staleRefCorrected(false)
#endif
{
llvm_gcroot(loader, 0);
@@ -324,11 +324,9 @@ UserClass* JnjvmBootstrapLoader::interna
if (slash) {
int packagelen = slash - cname;
const UTF8 * package = name->extract(hashUTF8, 0, packagelen);
- //classes->lock.lock();
lock.lock();
packages.insert(package);
lock.unlock();
- //classes->lock.unlock();
}
}
@@ -624,7 +622,7 @@ UserClass* JnjvmClassLoader::constructCl
JavaObject* excp = NULL;
llvm_gcroot(excp, 0);
UserClass* res = NULL;
- lock2.lock();
+ lock.lock();
classes->lock.lock();
res = (UserClass*) classes->map.lookup(name);
classes->lock.unlock();
@@ -647,7 +645,7 @@ UserClass* JnjvmClassLoader::constructCl
JavaThread::get()->clearException();
} END_CATCH;
}
- lock2.unlock();
+ lock.unlock();
if (excp != NULL) {
JavaThread::get()->throwException(excp);
}
@@ -1146,4 +1144,19 @@ void JnjvmClassLoader::setAssociatedBund
vm->setBundleClassLoader(newID, this);
}
+void JnjvmClassLoader::markZombie(bool becomeZombie)
+{
+ classes->lock.lock();
+
+ for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end(); i != e; ++i) {
+ CommonClass* ccl = i->second;
+ if (ccl->classLoader != this) continue;
+ if (!ccl->isClass() && !ccl->isInterface()) continue;
+
+ ccl->asClass()->markZombie(becomeZombie);
+ }
+
+ classes->lock.unlock();
+}
+
#endif
Modified: vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.h?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/j3/VMCore/JnjvmClassLoader.h Thu Apr 25 12:19:18 2013
@@ -115,15 +115,10 @@ protected:
///
SignMap* javaSignatures;
- /// lock - Lock when adding packages and Strings.
+ /// lock - Lock when loading classes.
///
vmkit::LockRecursive lock;
- /// lock2 - Lock when loading classes.
- ///
- vmkit::LockRecursive lock2;
-
-
/// registeredNatives - Stores the native function pointers corresponding
/// to methods that were defined through JNI's RegisterNatives mechanism.
///
@@ -338,11 +333,9 @@ public:
protected:
bool staleRefCorrected;
- bool zombie;
public:
- bool isZombie() const {return zombie;}
- void markZombie(bool becomeZombie = true) {zombie = becomeZombie;}
+ void markZombie(bool becomeZombie = true);
bool isStaleReferencesCorrectionEnabled() {return staleRefCorrected;}
void setStaleReferencesCorrectionEnabled(bool enable) {staleRefCorrected = enable;}
Modified: vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JnjvmIntOSGi.cpp Thu Apr 25 12:19:18 2013
@@ -1,22 +1,17 @@
#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;
#if RESET_STALE_REFERENCES
-#define DEBUG_VERBOSE_STALE_REF 1
-
namespace j3 {
void Jnjvm::setBundleStaleReferenceCorrected(int64_t bundleID, bool corrected)
@@ -25,14 +20,6 @@ void Jnjvm::setBundleStaleReferenceCorre
if (!loader) {
this->illegalArgumentException("Invalid bundle ID"); return;}
-#if DEBUG_VERBOSE_STALE_REF
- cerr << "Stale references to bundleID=" << bundleID << " are ";
- if (corrected)
- cerr << "corrected." << endl;
- else
- cerr << "no more corrected." << endl;
-#endif
-
loader->setStaleReferencesCorrectionEnabled(corrected);
}
@@ -56,38 +43,35 @@ void Jnjvm::notifyBundleUninstalled(int6
// Strong references to all its loaded classes will be reset in the next garbage collection.
loader->markZombie(true);
-#if DEBUG_VERBOSE_STALE_REF
- cerr << "Bundle uninstalled: bundleID=" << bundleID << endl;
-#endif
-
scanStaleReferences = true; // Enable stale references scanning
vmkit::Collector::collect(); // Start a garbage collection now
}
-void Jnjvm::dumpClassLoaderBundles()
+void Jnjvm::notifyServiceUnregistered(int64_t bundleID, JavaObjectClass* classObject)
{
- for (bundleClassLoadersType::const_iterator i = bundleClassLoaders.begin(), e = bundleClassLoaders.end(); i != e; ++i) {
- cerr << "classLoader=" << i->second << "\tbundleID=" << i->first << endl;
- }
-}
+ llvm_gcroot(classObject, 0);
-ArrayLong* Jnjvm::getReferencesToObject(const JavaObject* obj)
-{
- if (!obj) return NULL;
+ JnjvmClassLoader* loader = this->getBundleClassLoader(bundleID);
+ if (!loader) return;
- findReferencesToObject = obj;
- vmkit::Collector::collect();
+ if (!loader->isStaleReferencesCorrectionEnabled()) return;
- size_t count = foundReferencerObjects.size();
- ArrayLong* r = static_cast<ArrayLong*>(upcalls->ArrayOfLong->doNew(count, this));
- if (!r) {this->outOfMemoryError(); return r;}
+ CommonClass* ccl = JavaObjectClass::getClass(classObject);
+ if (!ccl->isClass() && !ccl->isInterface()) {
+ this->illegalArgumentException("Service class is not a class or an interface"); return;}
- ArrayLong::ElementType* elements = ArrayLong::getElements(r);
- for (size_t i=0; i < count; ++i) {
- elements[i] = reinterpret_cast<ArrayLong::ElementType>(foundReferencerObjects[i]);
- }
+ ccl->dump();
+ ccl->asClass()->markZombie(true);
- return r;
+ scanStaleReferences = true; // Enable stale references scanning
+// vmkit::Collector::collect(); // Start a garbage collection now
+}
+
+void Jnjvm::dumpClassLoaderBundles()
+{
+ for (bundleClassLoadersType::const_iterator i = bundleClassLoaders.begin(), e = bundleClassLoaders.end(); i != e; ++i) {
+ cerr << "classLoader=" << i->second << "\tbundleID=" << i->first << endl;
+ }
}
JnjvmClassLoader* Jnjvm::getBundleClassLoader(int64_t bundleID)
@@ -163,59 +147,46 @@ extern "C" void Java_j3_vm_OSGi_notifyBu
#endif
}
-extern "C" void Java_j3_vm_OSGi_setBundleStaleReferenceCorrected(jlong bundleID, jboolean corrected)
+extern "C" void Java_j3_vm_OSGi_notifyServiceUnregistered(jlong bundleID, JavaObjectClass* classObject)
{
-#if RESET_STALE_REFERENCES
-
- Jnjvm* vm = JavaThread::get()->getJVM();
- vm->setBundleStaleReferenceCorrected(bundleID, corrected);
-
-#endif
-}
+ llvm_gcroot(classObject, 0);
-extern "C" jboolean Java_j3_vm_OSGi_isBundleStaleReferenceCorrected(jlong bundleID)
-{
#if RESET_STALE_REFERENCES
Jnjvm* vm = JavaThread::get()->getJVM();
- return vm->isBundleStaleReferenceCorrected(bundleID);
+ vm->notifyServiceUnregistered(bundleID, classObject);
-#else
- return false;
#endif
}
-extern "C" void Java_j3_vm_OSGi_dumpClassLoaderBundles()
+extern "C" void Java_j3_vm_OSGi_setBundleStaleReferenceCorrected(jlong bundleID, jboolean corrected)
{
#if RESET_STALE_REFERENCES
Jnjvm* vm = JavaThread::get()->getJVM();
- vm->dumpClassLoaderBundles();
+ vm->setBundleStaleReferenceCorrected(bundleID, corrected);
#endif
}
-extern "C" ArrayLong* Java_j3_vm_OSGi_getReferencesToObject(jlong objectPointer)
+extern "C" jboolean Java_j3_vm_OSGi_isBundleStaleReferenceCorrected(jlong bundleID)
{
#if RESET_STALE_REFERENCES
Jnjvm* vm = JavaThread::get()->getJVM();
- return vm->getReferencesToObject(reinterpret_cast<const JavaObject*>((intptr_t)objectPointer));
+ return vm->isBundleStaleReferenceCorrected(bundleID);
+#else
+ return false;
#endif
}
-extern "C" JavaString* Java_j3_vm_OSGi_dumpObject(jlong objectPointer)
+extern "C" void Java_j3_vm_OSGi_dumpClassLoaderBundles()
{
#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());
+ vm->dumpClassLoaderBundles();
#endif
}
Modified: vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp?rev=180519&r1=180518&r2=180519&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/JnjvmStaleRef.cpp Thu Apr 25 12:19:18 2013
@@ -18,15 +18,12 @@ 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))
@@ -43,17 +40,6 @@ void Jnjvm::resetReferenceIfStale(const
// Don't touch fake Java objects that exist only as bridges between the
// Java object model and the C++ object model.
-
-#if DEBUG_VERBOSE_STALE_REF
-
- JnjvmClassLoader* loader = (**ref).getClassLoader();
- if (!loader->isZombie()) return;
-/*
- cerr << "WARNING: Ignored stale reference ref=" << ref << " obj=" << **ref;
- if (source) cerr << " source=" << *source;
- cerr << endl;
-*/
-#endif
}
void Jnjvm::resetReferenceIfStale(const JavaObject *source, VMStaticInstance** ref)
@@ -62,17 +48,6 @@ void Jnjvm::resetReferenceIfStale(const
// Don't touch fake Java objects that exist only as bridges between the
// Java object model and the C++ object model.
-
-#if DEBUG_VERBOSE_STALE_REF
-
- JnjvmClassLoader* loader = (**ref).getOwningClass()->classLoader;
- if (!loader->isZombie()) return;
-/*
- cerr << "WARNING: Ignored stale reference ref=" << ref << " obj=" << **ref;
- if (source) cerr << " source=" << *source;
- cerr << endl;
-*/
-#endif
}
void Jnjvm::resetReferenceIfStale(const JavaObject *source, JavaObject** ref)
@@ -83,8 +58,9 @@ void Jnjvm::resetReferenceIfStale(const
if (source) {
CommonClass* ccl = JavaObject::getClass(source);
- if (ccl->classLoader->isZombie())
- cerr << "WARNING: Source object is stale source=" << *source << endl;
+ if (ccl->isClass() || ccl->isInterface())
+ if (ccl->asClass()->isZombie())
+ cerr << "WARNING: Source object is stale source=" << *source << endl;
}
#endif
@@ -92,7 +68,8 @@ void Jnjvm::resetReferenceIfStale(const
CommonClass* ccl = JavaObject::getClass(*ref);
assert (ccl && "Object Class is not null.");
- if (!ccl->classLoader->isZombie()) return;
+ if (!ccl->isClass() && !ccl->isInterface()) return;
+ if (!ccl->asClass()->isZombie()) return;
#if DEBUG_VERBOSE_STALE_REF
More information about the vmkit-commits
mailing list