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
def run4(): import DemoExtension JyNI.JyRefMonitor_setMemDebugFlags(1) l = ([0, "test"],) l[0][0] = l DemoExtension.argCountToString(l) del l #l[0][1] = None print "Leaks before GC:" monitor.listLeaks() System.gc() time.sleep(2) print "Leaks after GC:" monitor.listLeaks()
def run4(): import DemoExtension JyNI.JyRefMonitor_setMemDebugFlags(1) l = ([0, "test"], ) l[0][0] = l DemoExtension.argCountToString(l) del l #l[0][1] = None print "Leaks before GC:" monitor.listLeaks() System.gc() time.sleep(2) print "Leaks after GC:" monitor.listLeaks()
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
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
def test_argument_passing(self): self.assertEqual( DemoExtension.concatFirstWithLastString.__doc__, "Concatenates first with last element. Returns empty string, if less than two args are available.", ) self.assertEqual(DemoExtension.concatFirstWithLastString("begin_", "ignore", "ignore too", "end"), "begin_end") self.assertEqual(DemoExtension.argCountToString.__doc__, "Returns number of arguments as string.") self.assertEqual(DemoExtension.argCountToString("a", "b", "c", "d", "e", "f"), "(6)")
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
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)
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)
def test_argument_passing(self): self.assertEqual( DemoExtension.concatFirstWithLastString.__doc__, "Concatenates first with last element. Returns empty string, if less than two args are available." ) self.assertEqual( DemoExtension.concatFirstWithLastString("begin_", "ignore", "ignore too", "end"), "begin_end") self.assertEqual(DemoExtension.argCountToString.__doc__, "Returns number of arguments as string.") self.assertEqual( DemoExtension.argCountToString("a", "b", "c", "d", "e", "f"), "(6)")
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 "===="
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 "===="
#from java.lang import System #print "System.currentTimeMillis: "+str(System.currentTimeMillis()) print "" print "--------Hello World----------" print DemoExtension.hello_world print DemoExtension.hello_world.__doc__ DemoExtension.hello_world() print "" print "--------Argument passing----------" print DemoExtension.concatFirstWithLastString.__doc__ print DemoExtension.concatFirstWithLastString("begin_", "ignore", "ignore too", "end") print DemoExtension.argCountToString.__doc__ print DemoExtension.argCountToString("a", "b", "c", "d", "e", "f") print "" print "--------Argument passing with keywords----------" DemoExtension.keywordTest("first", "second", right = "Hey", wrong = "nothing") print "(in JyNI-case see bottom for native outputs)" print "" print "----------------Integer passing-----------------" print DemoExtension.intSquare.__doc__ print DemoExtension.intSquare print DemoExtension.intSquare.__class__ print DemoExtension.intSquare.__name__ print "Native square result of 16: "+str(DemoExtension.intSquare(16)) print "Native square result of -19: "+str(DemoExtension.intSquare(19))
# 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 # _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 ""
#from java.lang import System #print "System.currentTimeMillis: "+str(System.currentTimeMillis()) print "" print "--------Hello World----------" print DemoExtension.hello_world print DemoExtension.hello_world.__doc__ DemoExtension.hello_world() print "" print "--------Argument passing----------" print DemoExtension.concatFirstWithLastString.__doc__ print DemoExtension.concatFirstWithLastString("begin_", "ignore", "ignore too", "end") print DemoExtension.argCountToString.__doc__ print DemoExtension.argCountToString("a", "b", "c", "d", "e", "f") print "" print "--------Argument passing with keywords----------" DemoExtension.keywordTest("first", "second", right="Hey", wrong="nothing") print "(in JyNI-case see bottom for native outputs)" print "" print "----------------Integer passing-----------------" print DemoExtension.intSquare.__doc__ print DemoExtension.intSquare print DemoExtension.intSquare.__class__ print DemoExtension.intSquare.__name__ print "Native square result of 16: " + str(DemoExtension.intSquare(16)) print "Native square result of -19: " + str(DemoExtension.intSquare(19))