From koutheir at gmail.com Thu Oct 3 04:01:01 2013 From: koutheir at gmail.com (Koutheir Attouchi) Date: Thu, 03 Oct 2013 11:01:01 -0000 Subject: [vmkit-commits] [vmkit] r191886 - J3 now supports calling Object.toString() to better debug objects. Message-ID: <20131003110102.2B74F2A6C029@llvm.org> Author: koutheir Date: Thu Oct 3 06:01:01 2013 New Revision: 191886 URL: http://llvm.org/viewvc/llvm-project?rev=191886&view=rev Log: J3 now supports calling Object.toString() to better debug objects. Modified: vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h vmkit/trunk/lib/j3/VMCore/JavaClass.cpp vmkit/trunk/lib/j3/VMCore/JavaObject.cpp vmkit/trunk/lib/j3/VMCore/JavaObject.h vmkit/trunk/lib/j3/VMCore/JavaString.cpp vmkit/trunk/lib/j3/VMCore/JavaString.h Modified: vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp Thu Oct 3 06:01:01 2013 @@ -206,6 +206,7 @@ JavaMethod* Classpath::InitArithmeticExc JavaMethod* Classpath::InitCloneNotSupportedException; JavaMethod* Classpath::InitObject; JavaMethod* Classpath::FinalizeObject; +JavaMethod* Classpath::toString; JavaMethod* Classpath::IntToString; JavaMethod* Classpath::SystemArraycopy; @@ -905,6 +906,9 @@ void Classpath::initialiseClasspath(Jnjv FinalizeObject = UPCALL_METHOD(loader, "java/lang/Object", "finalize", "()V", ACC_VIRTUAL); + + toString = UPCALL_METHOD(loader, "java/lang/Object", "toString", + "()Ljava/lang/String;", ACC_VIRTUAL); IntToString = UPCALL_METHOD(loader, "java/lang/Integer", "toString", "(II)Ljava/lang/String;", ACC_STATIC); Modified: vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h (original) +++ vmkit/trunk/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h Thu Oct 3 06:01:01 2013 @@ -251,6 +251,7 @@ public: ISOLATE_STATIC JavaMethod* InitObject; ISOLATE_STATIC JavaMethod* FinalizeObject; + ISOLATE_STATIC JavaMethod* toString; ISOLATE_STATIC JavaMethod* ErrorWithExcpNoClassDefFoundError; ISOLATE_STATIC JavaMethod* ErrorWithExcpExceptionInInitializerError; Modified: vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp Thu Oct 3 06:01:01 2013 @@ -197,6 +197,7 @@ JavaMethod* Classpath::InitArithmeticExc JavaMethod* Classpath::InitCloneNotSupportedException; JavaMethod* Classpath::InitObject; JavaMethod* Classpath::FinalizeObject; +JavaMethod* Classpath::toString; JavaMethod* Classpath::IntToString; JavaMethod* Classpath::SystemArraycopy; @@ -787,6 +788,9 @@ void Classpath::initialiseClasspath(Jnjv FinalizeObject = UPCALL_METHOD(loader, "java/lang/Object", "finalize", "()V", ACC_VIRTUAL); + toString = UPCALL_METHOD(loader, "java/lang/Object", "toString", + "()Ljava/lang/String;", ACC_VIRTUAL); + IntToString = UPCALL_METHOD(loader, "java/lang/Integer", "toString", "(II)Ljava/lang/String;", ACC_STATIC); Modified: vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h (original) +++ vmkit/trunk/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h Thu Oct 3 06:01:01 2013 @@ -240,6 +240,7 @@ public: ISOLATE_STATIC JavaMethod* InitObject; ISOLATE_STATIC JavaMethod* FinalizeObject; + ISOLATE_STATIC JavaMethod* toString; ISOLATE_STATIC JavaMethod* ErrorWithExcpNoClassDefFoundError; ISOLATE_STATIC JavaMethod* ErrorWithExcpExceptionInInitializerError; Modified: vmkit/trunk/lib/j3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaClass.cpp?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/j3/VMCore/JavaClass.cpp Thu Oct 3 06:01:01 2013 @@ -2349,8 +2349,8 @@ void JavaField::setStaticField(JavaObjec std::ostream& j3::operator << (std::ostream& os, const CommonClass& ccl) { - os << *ccl.name; - return (!ccl.super) ? (os << ';') : (os << ':' << *ccl.super); + return os << *ccl.name << ';'; +// return (!ccl.super) ? (os << ';') : (os << ':' << *ccl.super); } void CommonClass::dump() const Modified: vmkit/trunk/lib/j3/VMCore/JavaObject.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaObject.cpp?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/VMCore/JavaObject.cpp (original) +++ vmkit/trunk/lib/j3/VMCore/JavaObject.cpp Thu Oct 3 06:01:01 2013 @@ -387,9 +387,11 @@ bool JavaObject::instanceOf(JavaObject* std::ostream& j3::operator << (std::ostream& os, const JavaObject& obj) { JavaObject* javaLoader = NULL; - const JavaString* threadNameObj = NULL; + const JavaString* jstr = NULL; + const JavaObjectVMThread* vmthObj = NULL; llvm_gcroot(javaLoader, 0); - llvm_gcroot(threadNameObj, 0); + llvm_gcroot(jstr, 0); + llvm_gcroot(vmthObj, 0); if (VMClassLoader::isVMClassLoader(&obj)) { JnjvmClassLoader* loader = ((const VMClassLoader&)obj).getClassLoader(); @@ -416,24 +418,31 @@ std::ostream& j3::operator << (std::ostr os << &obj << "(class=" << *ccl; if (ccl == vm->upcalls->newThread) { - threadNameObj = static_cast( + jstr = static_cast( vm->upcalls->threadName->getInstanceObjectField( const_cast(&obj))); - char *threadName = JavaString::strToAsciiz(threadNameObj); - os << ",name=\"" << threadName << '\"'; - delete [] threadName; + os << ",name=" << *jstr; } #ifndef OpenJDKPath else if (ccl == vm->upcalls->newVMThread) { - const JavaObjectVMThread& vmthObj = (const JavaObjectVMThread&)obj; - for (int retries = 10; (!vmthObj.vmdata) && (retries >= 0); --retries) + vmthObj = static_cast(&obj); + for (int retries = 10; (!vmthObj->vmdata) && (retries >= 0); --retries) usleep(100); - if (const JavaObject* thObj = vmthObj.vmdata->currentThread()) + if (const JavaObject* thObj = vmthObj->vmdata->currentThread()) os << ",thread=" << *thObj; } #endif + else if (ccl == vm->upcalls->newClass) { + ccl = JavaObjectClass::getClass( + const_cast( + static_cast(&obj))); + + os << ",name=\"" << *ccl->asClass() << '\"'; + } else if (ccl == vm->upcalls->newString) { + os << ',' << static_cast(obj); + } os << ')'; } @@ -450,3 +459,22 @@ void JavaObject::dumpClass() const { JavaObject::getClass(this)->dump(); } + +void JavaObject::dumpToString() const +{ + JavaString* jstr = NULL; + llvm_gcroot(jstr, 0); + + if (VMClassLoader::isVMClassLoader(this) || VMStaticInstance::isVMStaticInstance(this)) + {cerr << "" << endl; return;} + + Class* cl = JavaObject::getClass(this)->asClass(); + if (!cl) {cerr << "" << endl; return;} + + Jnjvm* vm = cl->classLoader->getJVM(); + jstr = static_cast( + vm->upcalls->toString->invokeJavaObjectVirtual( + vm, cl, const_cast(this))); + + cerr << *jstr << endl; +} Modified: vmkit/trunk/lib/j3/VMCore/JavaObject.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaObject.h?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/VMCore/JavaObject.h (original) +++ vmkit/trunk/lib/j3/VMCore/JavaObject.h Thu Oct 3 06:01:01 2013 @@ -334,6 +334,7 @@ public: void dumpClass() const __attribute__((noinline)); void dump() const __attribute__((noinline)); friend std::ostream& operator << (std::ostream&, const JavaObject&); + void dumpToString() const __attribute__((noinline)); }; Modified: vmkit/trunk/lib/j3/VMCore/JavaString.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaString.cpp?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/VMCore/JavaString.cpp (original) +++ vmkit/trunk/lib/j3/VMCore/JavaString.cpp Thu Oct 3 06:01:01 2013 @@ -120,4 +120,12 @@ const UTF8* JavaString::javaToInternal(c return res; } +std::ostream& operator << (std::ostream& os, const JavaString& jstr) +{ + char *str = JavaString::strToAsciiz(&jstr); + os << '\"' << str << '\"'; + delete [] str; + return os; +} + } Modified: vmkit/trunk/lib/j3/VMCore/JavaString.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/JavaString.h?rev=191886&r1=191885&r2=191886&view=diff ============================================================================== --- vmkit/trunk/lib/j3/VMCore/JavaString.h (original) +++ vmkit/trunk/lib/j3/VMCore/JavaString.h Thu Oct 3 06:01:01 2013 @@ -62,6 +62,8 @@ class JavaString : public JavaObject { /// javaToInternal - Replaces all '/' into '.'. static const UTF8* javaToInternal(const JavaString* self, UTF8Map* map); + + friend std::ostream& operator << (std::ostream&, const JavaString&); }; } // end namespace j3 From koutheir at gmail.com Thu Oct 3 04:31:36 2013 From: koutheir at gmail.com (Koutheir Attouchi) Date: Thu, 03 Oct 2013 11:31:36 -0000 Subject: [vmkit-commits] [vmkit] r191887 - Improve debugging and tracing of objects and references. Message-ID: <20131003113136.A46ED2A6C029@llvm.org> Author: koutheir Date: Thu Oct 3 06:31:35 2013 New Revision: 191887 URL: http://llvm.org/viewvc/llvm-project?rev=191887&view=rev Log: Improve debugging and tracing of objects and references. Modified: vmkit/branches/incinerator/incinerator/knopflerfish.patch vmkit/branches/incinerator/incinerator/osgi/src/j3/J3Mgr.java vmkit/branches/incinerator/incinerator/osgi/src/j3/vm/OSGi.java vmkit/branches/incinerator/incinerator/osgi/src/j3mgr/J3MgrImpl.java vmkit/branches/incinerator/incinerator/tests/debug.txt vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.cpp vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.h vmkit/branches/incinerator/lib/j3/VMCore/JavaClass.cpp vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.cpp vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.h vmkit/branches/incinerator/lib/j3/VMCore/JavaString.cpp vmkit/branches/incinerator/lib/j3/VMCore/JavaString.h Modified: vmkit/branches/incinerator/incinerator/knopflerfish.patch URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/incinerator/knopflerfish.patch?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/incinerator/knopflerfish.patch (original) +++ vmkit/branches/incinerator/incinerator/knopflerfish.patch Thu Oct 3 06:31:35 2013 @@ -1,6 +1,6 @@ -diff -U 4 -H -d -p -r -N -- a/osgi/framework/src/j3/vm/OSGi.java b/osgi/framework/src/j3/vm/OSGi.java +diff -U 4 -H -d -p -r -N -- knopflerfish.verbatim/osgi/framework/src/j3/vm/OSGi.java knopflerfish/osgi/framework/src/j3/vm/OSGi.java --- a/osgi/framework/src/j3/vm/OSGi.java 1970-01-01 01:00:00.000000000 +0100 -+++ b/osgi/framework/src/j3/vm/OSGi.java 2013-07-03 17:15:27.382558975 +0200 ++++ b/osgi/framework/src/j3/vm/OSGi.java 2013-09-26 12:05:27.000000000 +0200 @@ -0,0 +1,6 @@ +package j3.vm; + @@ -8,26 +8,26 @@ diff -U 4 -H -d -p -r -N -- a/osgi/frame +{ + public static native void setBundleClassLoader(long bundleID, ClassLoader loaderObject); +} -diff -U 4 -H -d -p -r -N -- a/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java b/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java ---- a/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java 2013-07-03 17:24:51.446553603 +0200 -+++ b/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java 2013-07-03 17:17:48.950557625 +0200 -@@ -162,8 +162,9 @@ public class BundleGeneration implements - lazyExcludes = null; +diff -U 4 -H -d -p -r -N -- knopflerfish.verbatim/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java knopflerfish/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java +--- a/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java 2013-10-01 09:37:41.702234351 +0200 ++++ b/osgi/framework/src/org/knopflerfish/framework/BundleGeneration.java 2013-10-01 09:52:27.346257030 +0200 +@@ -208,8 +208,9 @@ public class BundleGeneration implements timeStamp = System.currentTimeMillis(); bpkgs = new BundlePackages(this, exportStr); + bundleRevision = new BundleRevisionImpl(this); classLoader = b.getClassLoader(); + j3.vm.OSGi.setBundleClassLoader(bundle.getBundleId(), classLoader); + processCapabilities(capabilityStr); } - /** -@@ -440,8 +441,9 @@ public class BundleGeneration implements +@@ -513,8 +514,9 @@ public class BundleGeneration implements } } - } + } classLoader = bundle.secure.newBundleClassLoader(this); + j3.vm.OSGi.setBundleClassLoader(bundle.getBundleId(), classLoader); return true; } - if (fragments != null) { + if (isFragmentHost()) { Modified: vmkit/branches/incinerator/incinerator/osgi/src/j3/J3Mgr.java URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/incinerator/osgi/src/j3/J3Mgr.java?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/incinerator/osgi/src/j3/J3Mgr.java (original) +++ vmkit/branches/incinerator/incinerator/osgi/src/j3/J3Mgr.java Thu Oct 3 06:31:35 2013 @@ -17,4 +17,5 @@ public interface J3Mgr public void isBundleStaleReferenceCorrected( String bundleNameOrID) throws Throwable; public void forceStaleReferenceScanning() throws Throwable; + public void forceSoftReferencesCollection(); } Modified: vmkit/branches/incinerator/incinerator/osgi/src/j3/vm/OSGi.java URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/incinerator/osgi/src/j3/vm/OSGi.java?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/incinerator/osgi/src/j3/vm/OSGi.java (original) +++ vmkit/branches/incinerator/incinerator/osgi/src/j3/vm/OSGi.java Thu Oct 3 06:31:35 2013 @@ -4,7 +4,7 @@ public class OSGi { // OSGi hooks and information gathering public static native void setBundleClassLoader(long bundleID, ClassLoader loaderObject); - public static native void notifyBundleUninstalled(long bundleID); + public static native void notifyBundleUninstalled(long bundleID); // Commands public static native void setBundleStaleReferenceCorrected(long bundleID, boolean corrected); Modified: vmkit/branches/incinerator/incinerator/osgi/src/j3mgr/J3MgrImpl.java URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/incinerator/osgi/src/j3mgr/J3MgrImpl.java?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/incinerator/osgi/src/j3mgr/J3MgrImpl.java (original) +++ vmkit/branches/incinerator/incinerator/osgi/src/j3mgr/J3MgrImpl.java Thu Oct 3 06:31:35 2013 @@ -1,5 +1,7 @@ package j3mgr; +import java.util.ArrayList; + import j3.J3Mgr; import org.osgi.framework.Bundle; @@ -134,4 +136,21 @@ public class J3MgrImpl { j3.vm.OSGi.forceStaleReferenceScanning(); } + + public void forceSoftReferencesCollection() + { + // In short, try to cause an OutOfMemory Exception + int maxmem = (int)Runtime.getRuntime().maxMemory(); + ArrayList dummy = new ArrayList(); + + try { + for (;;) { + dummy.add(new Short[maxmem]); + } + } catch (Throwable e) { + } finally { + dummy = null; + System.gc(); + } + } } Modified: vmkit/branches/incinerator/incinerator/tests/debug.txt URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/incinerator/tests/debug.txt?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/incinerator/tests/debug.txt (original) +++ vmkit/branches/incinerator/incinerator/tests/debug.txt Thu Oct 3 06:31:35 2013 @@ -1,3 +1,4 @@ +-X:gc:verbose=0 -jar framework.jar -xargs /home/koutheir/PhD/VMKit/incinerator/incinerator/tests/minimal.bug.xargs 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 @@ -41,3 +42,11 @@ STALE = {http/http_all-3.1.2.jar, userad call j3.J3Mgr forceStaleReferenceScanning fromupdate 15 file:/media/Data/Documents/PhD/VMKit/incinerator/incinerator/tests/ijvm.tests.Alarm_v2.0/out/ijvm.tests.Alarm_v2.0-2.0.0.jar + +enter framework +start 13 +stop 13 +uninstall 13 +refresh +meminfo -gc +call j3.J3Mgr dumpReferencesToObject Modified: vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp (original) +++ vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.cpp Thu Oct 3 06:31:35 2013 @@ -206,6 +206,7 @@ JavaMethod* Classpath::InitArithmeticExc JavaMethod* Classpath::InitCloneNotSupportedException; JavaMethod* Classpath::InitObject; JavaMethod* Classpath::FinalizeObject; +JavaMethod* Classpath::toString; JavaMethod* Classpath::IntToString; JavaMethod* Classpath::SystemArraycopy; @@ -905,6 +906,9 @@ void Classpath::initialiseClasspath(Jnjv FinalizeObject = UPCALL_METHOD(loader, "java/lang/Object", "finalize", "()V", ACC_VIRTUAL); + + toString = UPCALL_METHOD(loader, "java/lang/Object", "toString", + "()Ljava/lang/String;", ACC_VIRTUAL); IntToString = UPCALL_METHOD(loader, "java/lang/Integer", "toString", "(II)Ljava/lang/String;", ACC_STATIC); Modified: vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h (original) +++ vmkit/branches/incinerator/lib/j3/ClassLib/GNUClasspath/JavaUpcalls.h Thu Oct 3 06:31:35 2013 @@ -251,6 +251,7 @@ public: ISOLATE_STATIC JavaMethod* InitObject; ISOLATE_STATIC JavaMethod* FinalizeObject; + ISOLATE_STATIC JavaMethod* toString; ISOLATE_STATIC JavaMethod* ErrorWithExcpNoClassDefFoundError; ISOLATE_STATIC JavaMethod* ErrorWithExcpExceptionInInitializerError; Modified: vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp (original) +++ vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.cpp Thu Oct 3 06:31:35 2013 @@ -197,6 +197,7 @@ JavaMethod* Classpath::InitArithmeticExc JavaMethod* Classpath::InitCloneNotSupportedException; JavaMethod* Classpath::InitObject; JavaMethod* Classpath::FinalizeObject; +JavaMethod* Classpath::toString; JavaMethod* Classpath::IntToString; JavaMethod* Classpath::SystemArraycopy; @@ -787,6 +788,9 @@ void Classpath::initialiseClasspath(Jnjv FinalizeObject = UPCALL_METHOD(loader, "java/lang/Object", "finalize", "()V", ACC_VIRTUAL); + toString = UPCALL_METHOD(loader, "java/lang/Object", "toString", + "()Ljava/lang/String;", ACC_VIRTUAL); + IntToString = UPCALL_METHOD(loader, "java/lang/Integer", "toString", "(II)Ljava/lang/String;", ACC_STATIC); Modified: vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h (original) +++ vmkit/branches/incinerator/lib/j3/ClassLib/OpenJDK/JavaUpcalls.h Thu Oct 3 06:31:35 2013 @@ -240,6 +240,7 @@ public: ISOLATE_STATIC JavaMethod* InitObject; ISOLATE_STATIC JavaMethod* FinalizeObject; + ISOLATE_STATIC JavaMethod* toString; ISOLATE_STATIC JavaMethod* ErrorWithExcpNoClassDefFoundError; ISOLATE_STATIC JavaMethod* ErrorWithExcpExceptionInInitializerError; Modified: vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.cpp?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.cpp (original) +++ vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.cpp Thu Oct 3 06:31:35 2013 @@ -12,8 +12,6 @@ #if RESET_STALE_REFERENCES -#define DEBUG_VERBOSE_STALE_REF 0 - using namespace std; namespace j3 { @@ -22,8 +20,12 @@ Incinerator::Incinerator(Jnjvm* j3vm) : scanRef(Incinerator::scanRef_Disabled), scanStackRef(Incinerator::scanStackRef_Disabled), vm(j3vm), - needsStaleRefRescan(false), - findReferencesToObject(NULL) {} + needsStaleRefRescan(false) +#if DEBUG_OBJECT_REF_DUMPING + , findReferencesToObject(NULL) +#endif +{ +} Incinerator::~Incinerator() { @@ -171,12 +173,32 @@ void Incinerator::classLoaderUnloaded(Jn #endif } -void Incinerator::dumpReferencesToObject(JavaObject* object) const +#if DEBUG_OBJECT_REF_DUMPING + +void Incinerator::dumpReferencesToObject(const JavaObject* object) { - findReferencesToObject = object; - vmkit::Collector::collect(); + pendingRefObject.clear(); + pendingRefObject.push_back(object); + seenObjects.clear(); + + const JavaObject* obj = NULL; + do { + obj = pendingRefObject.back(); + pendingRefObject.pop_back(); + seenObjects.insert(obj); + + cerr << "dumpReferencesToObject: " << *obj << ", toString="; + obj->dumpToString(); + + findReferencesToObject = obj; + foundReferencerObjects.clear(); + setScanningInclusive(); + vmkit::Collector::collect(); + } while (!pendingRefObject.empty()); } +#endif + void Incinerator::forceStaleReferenceScanning() { setScanningInclusive(); @@ -194,7 +216,7 @@ void Incinerator::setScanningDisabled() scanStackRef = Incinerator::scanStackRef_Disabled; #if DEBUG_VERBOSE_STALE_REF - cerr << "Looking for stale references done." << endl; + cerr << "References scan done." << endl; #endif } @@ -204,34 +226,43 @@ void Incinerator::setScanningInclusive() scanStackRef = Incinerator::scanStackRef_Inclusive; #if DEBUG_VERBOSE_STALE_REF - cerr << "Looking for stale references..." << endl; + cerr << "References scan enabled." << endl; #endif } void Incinerator::setScanningExclusive() { +#if DEBUG_EXCLUDE_FINALIZABLE_STALE_OBJECTS scanRef = Incinerator::scanRef_Exclusive; scanStackRef = Incinerator::scanStackRef_Exclusive; #if DEBUG_VERBOSE_STALE_REF cerr << "Excluding stale references..." << endl; #endif + +#endif } void Incinerator::beforeCollection() { +#if DEBUG_OBJECT_REF_DUMPING if (findReferencesToObject != NULL) foundReferencerObjects.clear(); +#endif #if DEBUG_VERBOSE_STALE_REF if (needsStaleRefRescan) { cerr << "Some stale references were previously ignored due to" - " finalizable stale objects." - " Scanning for stale references enabled." << endl; + " finalizable stale objects." << endl; } #endif - if (!needsStaleRefRescan && !isScanningEnabled()) return; + if (!needsStaleRefRescan && !isScanningEnabled()) { +#if DEBUG_OBJECT_REF_DUMPING + if (!findReferencesToObject) +#endif + return; + } needsStaleRefRescan = false; setScanningInclusive(); @@ -239,6 +270,10 @@ void Incinerator::beforeCollection() void Incinerator::markingFinalizersDone() { +#if DEBUG_OBJECT_REF_DUMPING + if (findReferencesToObject != NULL) return; +#endif + if (!isScanningEnabled()) return; setScanningExclusive(); } @@ -256,7 +291,9 @@ void Incinerator::collectorPhaseComplete void Incinerator::afterCollection() { +#if DEBUG_OBJECT_REF_DUMPING findReferencesToObject = NULL; +#endif if (!isScanningEnabled()) return; @@ -273,12 +310,21 @@ void Incinerator::afterCollection() bool Incinerator::isStaleObject(const JavaObject* obj) { llvm_gcroot(obj, 0); - if (!obj || isVMObject(obj)) return false; - CommonClass* ccl = JavaObject::getClass(obj); - assert (ccl && "Object Class is not null."); + if (!obj) return false; + + const JnjvmClassLoader* loader = NULL; + if (VMClassLoader::isVMClassLoader(obj)) { + loader = ((const VMClassLoader*)obj)->getClassLoader(); + } else if (VMStaticInstance::isVMStaticInstance(obj)) { + loader = ((const VMStaticInstance*)obj)->getOwningClass()->classLoader; + } else { + CommonClass* ccl = JavaObject::getClass(obj); + assert (ccl && "Object Class is not null."); + + loader = ccl->classLoader; + } - JnjvmClassLoader* loader = ccl->classLoader; return loader->isStale() && loader->isStaleReferencesCorrectionEnabled(); } @@ -319,12 +365,51 @@ bool Incinerator::scanRef_Inclusive(Inci { llvm_gcroot(source, 0); - if (!ref || !isStaleObject(*ref)) return true; + if (!ref) return true; + +#if DEBUG_OBJECT_REF_DUMPING + if (incinerator.findReferencesToObject != NULL) { + if (incinerator.findReferencesToObject == *ref) { + if (!source) { + cout << *ref << " <-- (unknown)" << endl; + } else { + if (incinerator.foundReferencerObjects.insert(source).second) { + cout << *ref << " <-- " << *source << endl; + + if (incinerator.seenObjects.find(source) == incinerator.seenObjects.end()) { + // The source ref was not scanned before + std::deque::iterator + b = incinerator.pendingRefObject.begin(), + e = incinerator.pendingRefObject.end(); + + if (std::find(b, e, source) == e) { + // The source ref is not currently pending for scan + incinerator.pendingRefObject.push_front(source); + } + } + } + } + } + return true; + } +#endif + + if (!isStaleObject(*ref)) return true; #if DEBUG_VERBOSE_STALE_REF - cerr << "Stale ref: " << ref << "==>" << **ref << endl; + if (isVMObject(*ref)) + cerr << "Stale ref (VMObject): "; + else + cerr << "Stale ref: "; + + cerr << ref << " ==> " << **ref; + if (source) cerr << " source=" << *source; + cerr << endl; #endif + if (isVMObject(*ref)) + return true; + // Queue the stale reference to be eliminated. incinerator.staleRefList[ref] = source; @@ -334,6 +419,14 @@ bool Incinerator::scanRef_Inclusive(Inci bool Incinerator::scanStackRef_Inclusive(Incinerator& incinerator, const JavaMethod* method, JavaObject** ref) { +#if DEBUG_OBJECT_REF_DUMPING + if (ref != NULL && incinerator.findReferencesToObject != NULL) { + if (incinerator.findReferencesToObject == *ref) { + cout << "On stack of method=" << *method->name << " ,class=" << *method->classDef << endl; + } + } +#endif + #if DEBUG_VERBOSE_STALE_REF if (!ref || !(*ref)) return true; if (method && method->classDef->name->elements[0] == 'i') @@ -358,9 +451,12 @@ bool Incinerator::scanRef_Exclusive(Inci #if DEBUG_VERBOSE_STALE_REF if (!removed) - cerr << "Stale ref (ignored): " << ref << "==>" << **ref << endl; + cerr << "Stale ref (ignored): " << ref << " ==> " << **ref; else - cerr << "Excluded stale ref: " << ref << "==>" << **ref << endl; + cerr << "Excluded stale ref: " << ref << " ==> " << **ref; + + if (source) cerr << " source=" << *source; + cerr << endl; #endif } return true; // Trace this reference. @@ -379,6 +475,9 @@ bool Incinerator::scanStackRef_Exclusive void Incinerator::eliminateStaleRef(const JavaObject *source, JavaObject** ref) { + if (isVMObject(*ref)) + return; + CommonClass* ccl = JavaObject::getClass(*ref); assert (ccl && "Object Class is not null."); @@ -430,13 +529,17 @@ extern "C" jboolean Java_j3_vm_OSGi_isBu #endif } +#if DEBUG_OBJECT_REF_DUMPING + extern "C" void Java_j3_vm_OSGi_dumpReferencesToObject(jlong obj) { #if RESET_STALE_REFERENCES - j3::Incinerator::get()->dumpReferencesToObject(reinterpret_cast(obj)); + j3::Incinerator::get()->dumpReferencesToObject(reinterpret_cast(obj)); #endif } +#endif + extern "C" void Java_j3_vm_OSGi_forceStaleReferenceScanning() { #if RESET_STALE_REFERENCES Modified: vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.h?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.h (original) +++ vmkit/branches/incinerator/lib/j3/VMCore/Incinerator.h Thu Oct 3 06:31:35 2013 @@ -9,8 +9,14 @@ #include #include #include +#include +#include #include +#define DEBUG_VERBOSE_STALE_REF 1 +#define DEBUG_EXCLUDE_FINALIZABLE_STALE_OBJECTS 0 +#define DEBUG_OBJECT_REF_DUMPING 0 + namespace j3 { class Jnjvm; @@ -30,9 +36,12 @@ public: void setBundleStaleReferenceCorrected(OSGiGateway::bundle_id_t bundleID, bool corrected); bool isBundleStaleReferenceCorrected(OSGiGateway::bundle_id_t bundleID) const; void dumpClassLoaderBundles() const; - void dumpReferencesToObject(JavaObject* object) const; void forceStaleReferenceScanning(); +#if DEBUG_OBJECT_REF_DUMPING + void dumpReferencesToObject(const JavaObject* object); +#endif + OSGiGateway::bundle_id_t getClassLoaderBundleID(JnjvmClassLoader const * loader) const; void setBundleClassLoader(OSGiGateway::bundle_id_t bundleID, JnjvmClassLoader* loader); @@ -96,8 +105,15 @@ protected: StaleRefListType staleRefList; bool needsStaleRefRescan; - mutable JavaObject* findReferencesToObject; - std::vector foundReferencerObjects; +#if DEBUG_OBJECT_REF_DUMPING + + mutable const JavaObject* findReferencesToObject; + std::set foundReferencerObjects; + + std::deque pendingRefObject; + std::set seenObjects; + +#endif }; class IncineratorManagedClassLoader @@ -134,7 +150,10 @@ public: extern "C" void Java_j3_vm_OSGi_setBundleStaleReferenceCorrected(jlong bundleID, jboolean corrected); extern "C" jboolean Java_j3_vm_OSGi_isBundleStaleReferenceCorrected(jlong bundleID); -extern "C" void Java_j3_vm_OSGi_dumpReferencesToObject(jlong obj); extern "C" void Java_j3_vm_OSGi_forceStaleReferenceScanning(); +#if DEBUG_OBJECT_REF_DUMPING +extern "C" void Java_j3_vm_OSGi_dumpReferencesToObject(jlong obj); +#endif + #endif Modified: vmkit/branches/incinerator/lib/j3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/VMCore/JavaClass.cpp?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/VMCore/JavaClass.cpp (original) +++ vmkit/branches/incinerator/lib/j3/VMCore/JavaClass.cpp Thu Oct 3 06:31:35 2013 @@ -2349,8 +2349,8 @@ void JavaField::setStaticField(JavaObjec std::ostream& j3::operator << (std::ostream& os, const CommonClass& ccl) { - os << *ccl.name; - return (!ccl.super) ? (os << ';') : (os << ':' << *ccl.super); + return os << *ccl.name << ';'; +// return (!ccl.super) ? (os << ';') : (os << ':' << *ccl.super); } void CommonClass::dump() const Modified: vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.cpp?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.cpp (original) +++ vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.cpp Thu Oct 3 06:31:35 2013 @@ -387,9 +387,11 @@ bool JavaObject::instanceOf(JavaObject* std::ostream& j3::operator << (std::ostream& os, const JavaObject& obj) { JavaObject* javaLoader = NULL; - const JavaString* threadNameObj = NULL; + const JavaString* jstr = NULL; + const JavaObjectVMThread* vmthObj = NULL; llvm_gcroot(javaLoader, 0); - llvm_gcroot(threadNameObj, 0); + llvm_gcroot(jstr, 0); + llvm_gcroot(vmthObj, 0); if (VMClassLoader::isVMClassLoader(&obj)) { JnjvmClassLoader* loader = ((const VMClassLoader&)obj).getClassLoader(); @@ -416,24 +418,31 @@ std::ostream& j3::operator << (std::ostr os << &obj << "(class=" << *ccl; if (ccl == vm->upcalls->newThread) { - threadNameObj = static_cast( + jstr = static_cast( vm->upcalls->threadName->getInstanceObjectField( const_cast(&obj))); - char *threadName = JavaString::strToAsciiz(threadNameObj); - os << ",name=\"" << threadName << '\"'; - delete [] threadName; + os << ",name=" << *jstr; } #ifndef OpenJDKPath else if (ccl == vm->upcalls->newVMThread) { - const JavaObjectVMThread& vmthObj = (const JavaObjectVMThread&)obj; - for (int retries = 10; (!vmthObj.vmdata) && (retries >= 0); --retries) + vmthObj = static_cast(&obj); + for (int retries = 10; (!vmthObj->vmdata) && (retries >= 0); --retries) usleep(100); - if (const JavaObject* thObj = vmthObj.vmdata->currentThread()) + if (const JavaObject* thObj = vmthObj->vmdata->currentThread()) os << ",thread=" << *thObj; } #endif + else if (ccl == vm->upcalls->newClass) { + ccl = JavaObjectClass::getClass( + const_cast( + static_cast(&obj))); + + os << ",name=\"" << *ccl->asClass() << '\"'; + } else if (ccl == vm->upcalls->newString) { + os << ',' << static_cast(obj); + } os << ')'; } @@ -450,3 +459,22 @@ void JavaObject::dumpClass() const { JavaObject::getClass(this)->dump(); } + +void JavaObject::dumpToString() const +{ + JavaString* jstr = NULL; + llvm_gcroot(jstr, 0); + + if (VMClassLoader::isVMClassLoader(this) || VMStaticInstance::isVMStaticInstance(this)) + {cerr << "" << endl; return;} + + Class* cl = JavaObject::getClass(this)->asClass(); + if (!cl) {cerr << "" << endl; return;} + + Jnjvm* vm = cl->classLoader->getJVM(); + jstr = static_cast( + vm->upcalls->toString->invokeJavaObjectVirtual( + vm, cl, const_cast(this))); + + cerr << *jstr << endl; +} Modified: vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.h?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.h (original) +++ vmkit/branches/incinerator/lib/j3/VMCore/JavaObject.h Thu Oct 3 06:31:35 2013 @@ -334,6 +334,7 @@ public: void dumpClass() const __attribute__((noinline)); void dump() const __attribute__((noinline)); friend std::ostream& operator << (std::ostream&, const JavaObject&); + void dumpToString() const __attribute__((noinline)); }; Modified: vmkit/branches/incinerator/lib/j3/VMCore/JavaString.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/VMCore/JavaString.cpp?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/VMCore/JavaString.cpp (original) +++ vmkit/branches/incinerator/lib/j3/VMCore/JavaString.cpp Thu Oct 3 06:31:35 2013 @@ -120,4 +120,12 @@ const UTF8* JavaString::javaToInternal(c return res; } +std::ostream& operator << (std::ostream& os, const JavaString& jstr) +{ + char *str = JavaString::strToAsciiz(&jstr); + os << '\"' << str << '\"'; + delete [] str; + return os; +} + } Modified: vmkit/branches/incinerator/lib/j3/VMCore/JavaString.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/incinerator/lib/j3/VMCore/JavaString.h?rev=191887&r1=191886&r2=191887&view=diff ============================================================================== --- vmkit/branches/incinerator/lib/j3/VMCore/JavaString.h (original) +++ vmkit/branches/incinerator/lib/j3/VMCore/JavaString.h Thu Oct 3 06:31:35 2013 @@ -62,6 +62,8 @@ class JavaString : public JavaObject { /// javaToInternal - Replaces all '/' into '.'. static const UTF8* javaToInternal(const JavaString* self, UTF8Map* map); + + friend std::ostream& operator << (std::ostream&, const JavaString&); }; } // end namespace j3