コード例 #1
0
ファイル: test_JyNI_gc.py プロジェクト: clonly/JyNI
	def test_gc_list_cycle(self):
		#print "test_gc_list_cycle"
		l = (123, [0, "test1"])
		l[1][0] = l
		#We create weak reference to l to monitor collection by Java-GC:
		wkl = WeakReference(l)
		DemoExtension.argCountToString(l)
		del l
		self.assertIsNotNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		runGC()
		self.assertIsNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		del wkl
コード例 #2
0
    def get_jython_free_mem(self):
        # Force garbage collection first.
        from java.lang import Runtime
        from java.lang.ref import WeakReference
        from java.lang import Object
        from java.lang import System
        obj = Object()
        ref = WeakReference(obj)
        obj = None
        while ref.get() is not None:
            System.gc()

        # Calculate approx. available memory.
        return Runtime.getRuntime().freeMemory()
コード例 #3
0
ファイル: test_JyNI_gc.py プロジェクト: javifalces/JyNI
	def test_gc_list_cycle(self):
		#print "test_gc_list_cycle"
		clearCurrentLeaks()
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		l = (123, [0, "test1"])
		l[1][0] = l
		#We create weak reference to l to monitor collection by Java-GC:
		wkl = WeakReference(l)
		DemoExtension.argCountToString(l)
		del l
		self.assertIsNotNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		runGC()
		self.assertIsNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		del wkl
コード例 #4
0
ファイル: test_JyNI_gc.py プロジェクト: clonly/JyNI
	def test_gc_dict_cycle(self):
		#print "test_gc_dict_cycle"
		l = (123, {'a': 0, 'b': "test3"})
		l[1]['a'] = l
		#We create weak reference to l to monitor collection by Java-GC:
		wkl = WeakReference(l)
		DemoExtension.argCountToString(l)
		del l
		self.assertIsNotNone(wkl.get())
		#monitor.listLeaks()
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 3)
		runGC()
		self.assertIsNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		#print ""
		#monitor.listLeaks()
		del wkl
コード例 #5
0
ファイル: test_JyNI_gc.py プロジェクト: Stewori/JyNI-unstable
	def test_gc_list_cycle2(self):
		#print "test_gc_list_cycle2"
		clearCurrentLeaks()
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		l2 = (127, [0, "test2"])
		l2[1][0] = l2
		#We create weak reference to l to monitor collection by Java-GC:
		wkl = WeakReference(l2)
		DemoExtension.argCountToString(l2)
		self.assertIsNotNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		runGC()
		self.assertIsNotNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 3)
		del l2
		runGC()
		self.assertIsNone(wkl.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		del wkl
コード例 #6
0
ファイル: test_JyNI_gc.py プロジェクト: javifalces/JyNI
	def test_gc_list_modify_silent(self):
		#print "test_gc_list_modify_silent"
		clearCurrentLeaks()
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		l = [0, "test1"]
		d = {'a': 7, 'b': "test6"}
		wkl = WeakReference(l)
		wkd = WeakReference(d)
		wkl2 = weakref.ref(l)
		wkd2 = weakref.ref(d)
		self.assertIsNotNone(wkl.get())
		self.assertIsNotNone(wkd.get())
		self.assertIsNotNone(wkl2())
		self.assertIsNotNone(wkd2())
		DemoExtension.listSetIndex(l, 0, d)
		del d
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		runGC()
		self.assertFalse(monitor.lastClearGraphValid)
		self.assertIsNotNone(wkl.get())
		self.assertIsNone(wkd.get())
		self.assertIsNotNone(wkl2())
		self.assertIsNotNone(wkd2())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 3)
		self.assertIsNotNone(l[0])
		self.assertEqual(len(l[0]), 2)
		del l
		runGC()
		self.assertTrue(monitor.lastClearGraphValid)

		# For some reason resurrected objects persist one more
		# gc-cycle in principle. So we have to run gc again before
		# we can observe wkd2 to die. It is currently unclear whether
		# this behavior is a JyNI-bug or natural Java-gc behavior,
		# but for now (with some evidence) we assume the latter.
		# Note: Since WeakRef-support wkd2 actually keeps the native
		# referent alive for one more cycle. So also the monitor-refcount
		# test only passes after another gc-run now.
		runGC()
		self.assertTrue(monitor.lastClearGraphValid)
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		self.assertIsNone(wkl2())
		self.assertIsNone(wkd2())
コード例 #7
0
ファイル: test_JyNI_gc.py プロジェクト: Stewori/JyNI-unstable
	def test_gc_list_modify_silent(self):
		#print "test_gc_list_modify_silent"
		clearCurrentLeaks()
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		l = [0, "test1"]
		d = {'a': 7, 'b': "test6"}
		wkl = WeakReference(l)
		wkd = WeakReference(d)
		wkl2 = weakref.ref(l)
		wkd2 = weakref.ref(d)
		self.assertIsNotNone(wkl.get())
		self.assertIsNotNone(wkd.get())
		self.assertIsNotNone(wkl2())
		self.assertIsNotNone(wkd2())
		DemoExtension.listSetIndex(l, 0, d)
		del d
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		#monitor.listAll()
		runGC()
		#monitor.listAll()
		self.assertFalse(monitor.lastClearGraphValid)
		self.assertIsNotNone(wkl.get())
		self.assertIsNone(wkd.get())
		self.assertIsNotNone(wkl2())
		self.assertIsNotNone(wkd2())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 3)
		self.assertIsNotNone(l[0])
		self.assertEqual(len(l[0]), 2)
		del l
		runGC()
		#monitor.listAll()
		self.assertTrue(monitor.lastClearGraphValid)

 		# For some reason resurrected objects persist one more
 		# gc-cycle in principle. So we have to run gc again before
 		# we can observe wkd2 to die. It is currently unclear whether
 		# this behavior is a JyNI-bug or natural Java-gc behavior,
 		# but for now (with some evidence) we assume the latter.
		# Note: Since WeakRef-support wkd2 actually keeps the native
		# referent alive for one more cycle. So also the monitor-refcount
		# test only passes after another gc-run now.
 		runGC()
 		#monitor.listAll()
		self.assertTrue(monitor.lastClearGraphValid)

		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		self.assertIsNone(wkl2())
		self.assertIsNone(wkd2())
コード例 #8
0
ファイル: test_JyNI_gc.py プロジェクト: javifalces/JyNI
	def test_gc_list_modify_update(self):
		#print "test_gc_list_modify_update"
		clearCurrentLeaks()
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		l = [0, "test1"]
		d = {'a': 7, 'b': "test6"}
		#We create weak reference to l to monitor collection by Java-GC:
		wkl = WeakReference(l)
		wkd = WeakReference(d)
		#l[0] = d
		DemoExtension.argCountToString(l)
		l[0] = d
		del d
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		runGC()
		self.assertIsNotNone(wkl.get())
		self.assertIsNotNone(wkd.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 3)
		del l
		runGC()
		self.assertIsNone(wkl.get())
		self.assertIsNone(wkd.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
コード例 #9
0
ファイル: test_JyNI_gc.py プロジェクト: clonly/JyNI
	def test_gc_list_modify_silent(self):
		#print "test_gc_list_modify_silent"
		l = [0, "test1"]
		d = {'a': 7, 'b': "test6"}
		wkl = WeakReference(l)
		wkd = WeakReference(d)
		wkl2 = weakref.ref(l)
		wkd2 = weakref.ref(d)
		self.assertIsNotNone(wkl.get())
		self.assertIsNotNone(wkd.get())
		self.assertIsNotNone(wkl2())
		self.assertIsNotNone(wkd2())
		DemoExtension.listSetIndex(l, 0, d)
		del d
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		#print "run1"
		runGC()
		#print "run1 done"
		self.assertFalse(monitor.lastClearGraphValid)
		self.assertIsNotNone(wkl.get())
		self.assertIsNone(wkd.get())
		self.assertIsNotNone(wkl2())
		self.assertIsNotNone(wkd2())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 3)
		self.assertIsNotNone(l[0])
		self.assertEqual(len(l[0]), 2)
		del l
		#print "run2"
		runGC()
		#print "run2 done"
		self.assertTrue(monitor.lastClearGraphValid)
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
		self.assertIsNone(wkl2())
		# For some reason resurrected objects persist one more
		# gc-cycle in principle. So we have to run gc again before
		# we can observe wkd2 to die. It is currently unclear whether
		# this behavior is a JyNI-bug or natural Java-gc behavior,
		# but for now (with some evidence) we assume the latter.
		#print "run3"
		runGC()
		#print "run3 done"
		self.assertIsNone(wkd2())
コード例 #10
0
ファイル: test_JyNI_gc.py プロジェクト: clonly/JyNI
	def test_gc_list_modify_update(self):
		#print "test_gc_list_modify_update"
		l = [0, "test1"]
		d = {'a': 7, 'b': "test6"}
		#We create weak reference to l to monitor collection by Java-GC:
		wkl = WeakReference(l)
		wkd = WeakReference(d)
		#l[0] = d
		DemoExtension.argCountToString(l)
		l[0] = d
		del d
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 4)
		runGC()
		self.assertIsNotNone(wkl.get())
		self.assertIsNotNone(wkd.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 3)
		del l
		runGC()
		self.assertIsNone(wkl.get())
		self.assertIsNone(wkd.get())
		self.assertEqual(len(monitor.getCurrentNativeLeaks()), 0)
コード例 #11
0
ファイル: JyNIRefMonitor.py プロジェクト: lokuz/JyNI
def run1():
	JyNI.JyRefMonitor_setMemDebugFlags(1)
	JyWeakReferenceGC.monitorNativeCollection = True
	
	# PyType  <- Make native ref-cycle test with heap type to test partly-stub-mode.
	# PySet, but no native link to other PyObject
	# PyFrozenSet, "
	# PyCode, not GC-relevant in CPython
	
	import DemoExtension
	
	#Note:
	# For now we attempt to verify JyNI's GC-functionality independently from
	# Jython concepts like Jython weak references or Jython GC-module.
	# So we use java.lang.ref.WeakReference and java.lang.System.gc to monitor
	# and control Java-gc.
	
	#JyNI.JyRefMonitor_setMemDebugFlags(1)
	#JyWeakReferenceGC.monitorNativeCollection = True

	#l = (123,)
	l = ([0, "test"],)
	l[0][0] = l
	#l = (123, {'a': 0, 'b': "test"})
	#l[1]['a'] = l
	#We create weak reference to l to monitor collection by Java-GC:
	wkl = WeakReference(l)
	print "weak(l): "+str(wkl.get())
	
	# We pass down l to some native method. We don't care for the method itself,
	# but conversion to native side causes creation of native PyObjects that
	# correspond to l and its elements. We will then track the life-cycle of these.
	print "make l native..."
	
	DemoExtension.argCountToString(l)
	
	#print "argCountToString.__doc__-address: "+str(JyNI.lookupNativeHandle(DemoExtension.argCountToString.__doc__))
	#print "We access a method-doc as this used to cause problems with GC:"
	#print "    "+DemoExtension.argCountToString.__doc__
	#print "Native static objects so far:"
	#print JyNI.nativeStaticPyObjectHeads.keySet()
	
	print "Delete l... (but GC not yet ran)"
	del l
	#l = None
	print "weak(l) after del: "+str(wkl.get())
	print ""
	# monitor.list-methods display the following format:
	# [native pointer]{'' | '_GC_J' | '_J'} ([type]) #[native ref-count]: [repr] *[creation time]
	# _GC_J means that JyNI tracks the object
	# _J means that a JyNI-GC-head exists, but the object is not actually treated by GC
	# This can serve monitoring purposes or soft-keep-alive (c.f. java.lang.ref.SoftReference)
	# for caching.
	print "Leaks before GC:"
	monitor.listLeaks()
	print ""

	# By inserting this line you can confirm that native
	# leaks would persist if JyNI-GC is not working:
	#JyWeakReferenceGC.nativecollectionEnabled = False

	print "calling Java-GC..."
	System.gc()
	time.sleep(2)
	print "weak(l) after GC: "+str(wkl.get())
	print ""
	monitor.listWouldDeleteNative()
	print ""
	print "leaks after GC:"
	monitor.listLeaks()
	print ""
	print "    "+DemoExtension.argCountToString.__doc__
	monitor.listLeaks()
	#print "----"
	#print monitor.listAll()
	print ""
	print "===="
	print "exit"
	print "===="
コード例 #12
0
ファイル: JyNIRefMonitor.py プロジェクト: lokuz/JyNI
def run3():
	JyNI.JyRefMonitor_setMemDebugFlags(1)
	JyWeakReferenceGC.monitorNativeCollection = True
	import DemoExtension
	
	#JyNI.JyRefMonitor_setMemDebugFlags(1)
	#JyWeakReferenceGC.monitorNativeCollection = True

	l = [0, "test1"]
# 	print l
# 	DemoExtension.listSetIndex(l, 0, 100.7)
# 	print l
	d = {'a': 7, 'b': "test6"}
	#We create weak reference to l to monitor collection by Java-GC:
	wkl = WeakReference(l)
	wkd = WeakReference(d)
	wkl2 = weakref.ref(l)
	wkd2 = weakref.ref(d)

	#Note:
	#=====
	#To make this work we'll have to ensure that d gets a GCHead even though
	#l doesn't recognize the insertion of d and thus would not explore it.
	#In fact every C-stub object must get a GCHead when going native, regardless
	#of whether it is inserted somewhere or not, because it might be silently
	#inserted and a GCHead is the only way to detect this and fix it.
	#Add a call (e.g. to size) to the dict in l on native side to test that
	#d still works (which it currently shouldn't).
	#Later use d's GCHead to detect the invalid graph and resurrect d's java-part.
	#Take care of the GIL here. CStubs must release the GIL when they detect a
	#failing backend, so the GC-thread can acquire it and resurrect the backend.
	#How to fix the weak reference etc?

	#l[0] = d
	print "weak(l): "+str(wkl.get())
	print "weak(d): "+str(wkd.get())
	print "weak2(l): "+str(wkl2())
	print "weak2(d): "+str(wkd2())
	print "make l native..."
	#l[0] = d
	#DemoExtension.argCountToString(l)
	#l[0] = d
	DemoExtension.listSetIndex(l, 0, d)

	print "Delete l... (but GC not yet ran)"
	#del l
	del d
	#l = None
	#print "weak(l) after del: "+str(wkl.get())
	print "weak(d) after del: "+str(wkd.get())
	print "weak2(d) after del: "+str(wkd2())
	print ""
	print "Leaks before GC:"
	monitor.listLeaks()
	print ""
	
	print "calling Java-GC..."
	System.gc()
	time.sleep(2)
# 	if monitor.lastClearGraphValid:
# 		print "valid graph"
# 	else:
# 		print "invalid graph"
# 	monitor.lastClearGraphValid = False
	print "weak(l) after GC: "+str(wkl.get())
	#print "l after GC: "+str(l)
	print "weak(d) after GC: "+str(wkd.get())
	print "weak2(l) after GC: "+str(wkl2())
	print "weak2(d) after GC: "+str(wkd2())
	wkd = WeakReference(l[0])
	print ""
	#monitor.listWouldDeleteNative()
	print ""
	#print "leaks after GC:"
	#monitor.listLeaks()
	print "l[0], i.e. d after gc:"
	#print l[0]
	#print len(l[0])
	
	print "------"
	print "del l..."
	del l
	System.gc()
	time.sleep(2)
# 	if monitor.lastClearGraphValid:
# 		print "valid graph"
# 	else:
# 		print "invalid graph"
# 	monitor.lastClearGraphValid = False
	print ""
	monitor.listWouldDeleteNative()
	print ""
	#print "leaks after GC (l deleted):"
	#monitor.listLeaks()
	#print DemoExtension.argCountToString.__doc__
	#monitor.listFreeStatus("dict")
	#monitor.listAll()
	#GlobalRef.processDelayedCallbacks()
	print "weak(d) after GC2: "+str(wkd.get())
	print "weak2(l) after GC2: "+str(wkl2())
	print "weak2(d) after GC2: "+str(wkd2())
	System.gc()
	time.sleep(2)
	print "weak(d) after GC3: "+str(wkd.get())
	monitor.listWouldDeleteNative()
	print ""
	print "leaks after GC3:"
	monitor.listLeaks()
	print ""
	print "===="
	print "exit"
	print "===="
コード例 #13
0
ファイル: JyNIRefMonitor.py プロジェクト: hackerlank/JyNI
def run1():
    JyNI.JyRefMonitor_setMemDebugFlags(1)
    JyWeakReferenceGC.monitorNativeCollection = True

    # PyType  <- Make native ref-cycle test with heap type to test partly-stub-mode.
    # PySet, but no native link to other PyObject
    # PyFrozenSet, "
    # PyCode, not GC-relevant in CPython

    import DemoExtension

    #Note:
    # For now we attempt to verify JyNI's GC-functionality independently from
    # Jython concepts like Jython weak references or Jython GC-module.
    # So we use java.lang.ref.WeakReference and java.lang.System.gc to monitor
    # and control Java-gc.

    #JyNI.JyRefMonitor_setMemDebugFlags(1)
    #JyWeakReferenceGC.monitorNativeCollection = True

    #l = (123,)
    l = ([0, "test"], )
    l[0][0] = l
    #l = (123, {'a': 0, 'b': "test"})
    #l[1]['a'] = l
    #We create weak reference to l to monitor collection by Java-GC:
    wkl = WeakReference(l)
    print "weak(l): " + str(wkl.get())

    # We pass down l to some native method. We don't care for the method itself,
    # but conversion to native side causes creation of native PyObjects that
    # correspond to l and its elements. We will then track the life-cycle of these.
    print "make l native..."

    DemoExtension.argCountToString(l)

    #print "argCountToString.__doc__-address: "+str(JyNI.lookupNativeHandle(DemoExtension.argCountToString.__doc__))
    #print "We access a method-doc as this used to cause problems with GC:"
    #print "    "+DemoExtension.argCountToString.__doc__
    #print "Native static objects so far:"
    #print JyNI.nativeStaticPyObjectHeads.keySet()

    print "Delete l... (but GC not yet ran)"
    del l
    #l = None
    print "weak(l) after del: " + str(wkl.get())
    print ""
    # monitor.list-methods display the following format:
    # [native pointer]{'' | '_GC_J' | '_J'} ([type]) #[native ref-count]: [repr] *[creation time]
    # _GC_J means that JyNI tracks the object
    # _J means that a JyNI-GC-head exists, but the object is not actually treated by GC
    # This can serve monitoring purposes or soft-keep-alive (c.f. java.lang.ref.SoftReference)
    # for caching.
    print "Leaks before GC:"
    monitor.listLeaks()
    print ""

    # By inserting this line you can confirm that native
    # leaks would persist if JyNI-GC is not working:
    #JyWeakReferenceGC.nativecollectionEnabled = False

    print "calling Java-GC..."
    System.gc()
    time.sleep(2)
    print "weak(l) after GC: " + str(wkl.get())
    print ""
    monitor.listWouldDeleteNative()
    print ""
    print "leaks after GC:"
    monitor.listLeaks()
    print ""
    print "    " + DemoExtension.argCountToString.__doc__
    monitor.listLeaks()
    #print "----"
    #print monitor.listAll()
    print ""
    print "===="
    print "exit"
    print "===="
コード例 #14
0
ファイル: JyNIRefMonitor.py プロジェクト: hackerlank/JyNI
def run3():
    JyNI.JyRefMonitor_setMemDebugFlags(1)
    JyWeakReferenceGC.monitorNativeCollection = True
    import DemoExtension

    #JyNI.JyRefMonitor_setMemDebugFlags(1)
    #JyWeakReferenceGC.monitorNativeCollection = True

    l = [0, "test1"]
    # 	print l
    # 	DemoExtension.listSetIndex(l, 0, 100.7)
    # 	print l
    d = {'a': 7, 'b': "test6"}
    #We create weak reference to l to monitor collection by Java-GC:
    wkl = WeakReference(l)
    wkd = WeakReference(d)
    wkl2 = weakref.ref(l)
    wkd2 = weakref.ref(d)

    #Note:
    #=====
    #To make this work we'll have to ensure that d gets a GCHead even though
    #l doesn't recognize the insertion of d and thus would not explore it.
    #In fact every C-stub object must get a GCHead when going native, regardless
    #of whether it is inserted somewhere or not, because it might be silently
    #inserted and a GCHead is the only way to detect this and fix it.
    #Add a call (e.g. to size) to the dict in l on native side to test that
    #d still works (which it currently shouldn't).
    #Later use d's GCHead to detect the invalid graph and resurrect d's java-part.
    #Take care of the GIL here. CStubs must release the GIL when they detect a
    #failing backend, so the GC-thread can acquire it and resurrect the backend.
    #How to fix the weak reference etc?

    #l[0] = d
    print "weak(l): " + str(wkl.get())
    print "weak(d): " + str(wkd.get())
    print "weak2(l): " + str(wkl2())
    print "weak2(d): " + str(wkd2())
    print "make l native..."
    #l[0] = d
    #DemoExtension.argCountToString(l)
    #l[0] = d
    DemoExtension.listSetIndex(l, 0, d)

    print "Delete l... (but GC not yet ran)"
    #del l
    del d
    #l = None
    #print "weak(l) after del: "+str(wkl.get())
    print "weak(d) after del: " + str(wkd.get())
    print "weak2(d) after del: " + str(wkd2())
    print ""
    print "Leaks before GC:"
    monitor.listLeaks()
    print ""

    print "calling Java-GC..."
    System.gc()
    time.sleep(2)
    # 	if monitor.lastClearGraphValid:
    # 		print "valid graph"
    # 	else:
    # 		print "invalid graph"
    # 	monitor.lastClearGraphValid = False
    print "weak(l) after GC: " + str(wkl.get())
    #print "l after GC: "+str(l)
    print "weak(d) after GC: " + str(wkd.get())
    print "weak2(l) after GC: " + str(wkl2())
    print "weak2(d) after GC: " + str(wkd2())
    wkd = WeakReference(l[0])
    print ""
    #monitor.listWouldDeleteNative()
    print ""
    #print "leaks after GC:"
    #monitor.listLeaks()
    print "l[0], i.e. d after gc:"
    #print l[0]
    #print len(l[0])

    print "------"
    print "del l..."
    del l
    System.gc()
    time.sleep(2)
    # 	if monitor.lastClearGraphValid:
    # 		print "valid graph"
    # 	else:
    # 		print "invalid graph"
    # 	monitor.lastClearGraphValid = False
    print ""
    monitor.listWouldDeleteNative()
    print ""
    #print "leaks after GC (l deleted):"
    #monitor.listLeaks()
    #print DemoExtension.argCountToString.__doc__
    #monitor.listFreeStatus("dict")
    #monitor.listAll()
    #GlobalRef.processDelayedCallbacks()
    print "weak(d) after GC2: " + str(wkd.get())
    print "weak2(l) after GC2: " + str(wkl2())
    print "weak2(d) after GC2: " + str(wkd2())
    System.gc()
    time.sleep(2)
    print "weak(d) after GC3: " + str(wkd.get())
    monitor.listWouldDeleteNative()
    print ""
    print "leaks after GC3:"
    monitor.listLeaks()
    print ""
    print "===="
    print "exit"
    print "===="
コード例 #15
0
ファイル: JyNIRefMonitor.py プロジェクト: cristipp/JyNI
import DemoExtension

#Note:
# For now we attempt to verify JyNI's GC-functionality independently from
# Jython concepts like Jython weak references or Jython GC-module.
# So we use java.lang.ref.WeakReference and java.lang.System.gc to monitor
# and control Java-gc.

JyNI.JyRefMonitor_setMemDebugFlags(1)
JyWeakReferenceGC.monitorNativeCollection = True

l = (123, [0, "test"])
l[1][0] = l
#We create weak reference to l to monitor collection by Java-GC:
wkl = WeakReference(l)
print "weak(l): "+str(wkl.get())

# We pass down l to some native method. We don't care for the method itself,
# but conversion to native side causes creation of native PyObjects that
# correspond to l and its elements. We will then track the life-cycle of these.
print "make l native..."
DemoExtension.argCountToString(l)

print "Delete l... (but GC not yet ran)"
del l
print "weak(l) after del: "+str(wkl.get())
print ""
# monitor.list-methods display the following format:
# [native pointer]{'' | '_GC_J' | '_J'} ([type]) #[native ref-count]: [repr] *[creation time]
# _GC_J means that JyNI tracks the object