[Jython-checkins] jython: Treat illegal reflective access in test_gc_jy.

jeff.allen jython-checkins at python.org
Tue Oct 23 03:05:17 EDT 2018


https://hg.python.org/jython/rev/dc1ffb710882
changeset:   8189:dc1ffb710882
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Tue Oct 23 06:56:02 2018 +0100
summary:
  Treat illegal reflective access in test_gc_jy.

By default we no longer use reflection when traversing cyclic isolates (cyclic
garbage) so that reflective access warnings will not be produced. However,
we enable it, for one class of test case only, on Java versions less than 9.

The clauses of the original test are made individual tests to aid debug.

files:
  Lib/test/test_gc_jy.py         |  73 ++++++++++++---------
  src/org/python/modules/gc.java |   2 +-
  2 files changed, 41 insertions(+), 34 deletions(-)


diff --git a/Lib/test/test_gc_jy.py b/Lib/test/test_gc_jy.py
--- a/Lib/test/test_gc_jy.py
+++ b/Lib/test/test_gc_jy.py
@@ -33,7 +33,7 @@
             gc.stopMonitoring()
         except Exception:
             pass
-     
+
     @classmethod
     def tearDownClass(cls):
         try:
@@ -371,7 +371,7 @@
         class Test_Resurrection(object):
             def __init__(self, name):
                 self.name = name
-            
+
             def __repr__(self):
                 return "<"+self.name+">"
 
@@ -385,7 +385,7 @@
         c = Test_Resurrection("c")
         c.a = a
         c.toResurrect = Test_Finalizable("d")
-         
+
         del a
         del c
         self.assertNotEqual(gc.collect(), 0)
@@ -552,7 +552,7 @@
         class Test_Resurrection(object):
             def __init__(self, name):
                 self.name = name
-            
+
             def __repr__(self):
                 return "<"+self.name+">"
 
@@ -566,7 +566,7 @@
         c = Test_Resurrection("c")
         c.a = a
         c.toResurrect = Test_Finalizable("d")
-         
+
         del a
         del c
         self.assertNotEqual(gc.collect(), 0)
@@ -616,31 +616,31 @@
     def test_raw_forced_delayedFinalization(self):
         #print "test_raw_forced_delayedFinalization"
         comments = []
-    
+
         class Test_JavaAbortFinalizable(Object):
             def __init__(self, name, toAbort):
                 self.name = name
                 self.toAbort = toAbort
-    
+
             def __repr__(self):
                 return "<"+self.name+">"
-    
+
             def finalize(self):
                 gc.notifyPreFinalization()
                 comments.append("del "+self.name)
                 gc.abortDelayedFinalization(self.toAbort)
                 gc.notifyPostFinalization()
-    
+
         class Test_Finalizable(object):
             def __init__(self, name):
                 self.name = name
-    
+
             def __repr__(self):
                 return "<"+self.name+">"
-    
+
             def __del__(self):
                 comments.append("del "+self.name)
-        
+
         def callback(obj):
             comments.append("callback0")
 
@@ -666,12 +666,12 @@
     def test_raw_forced_delayedWeakrefCallback(self):
         comments = []
         resurrected = []
-         
+
         class Test_JavaResurrectFinalizable(Object):
             def __init__(self, name, toResurrect):
                 self.name = name
                 self.toResurrect = toResurrect
-         
+
             def __repr__(self):
                 return "<"+self.name+">"
 
@@ -684,20 +684,20 @@
                 # We manually restore weak references:
                 gc.restoreWeakReferences(self.toResurrect)
                 gc.notifyPostFinalization()
-    
+
         class Test_Finalizable(object):
             def __init__(self, name):
                 self.name = name
-    
+
             def __repr__(self):
                 return "<"+self.name+">"
-    
+
             def __del__(self):
                 comments.append("del "+self.name)
-    
+
         def callback(obj):
             comments.append("callback")
-    
+
         a = Test_Finalizable("a")
         b = Test_JavaResurrectFinalizable("b", a)
         wa = weakref.ref(a, callback)
@@ -723,15 +723,15 @@
 
     def test_raw_forced_delayed(self):
         comments = []
-    
+
         class Test_JavaAbortFinalizable(Object):
             def __init__(self, name, toAbort):
                 self.name = name
                 self.toAbort = toAbort
-    
+
             def __repr__(self):
                 return "<"+self.name+">"
-    
+
             def finalize(self):
                 gc.notifyPreFinalization()
                 comments.append("del "+self.name)
@@ -826,7 +826,7 @@
         class Test_Resurrection(object):
             def __init__(self, name):
                 self.name = name
-            
+
             def __repr__(self):
                 return "<"+self.name+">"
 
@@ -926,7 +926,7 @@
         class Test_Resurrection(object):
             def __init__(self, name):
                 self.name = name
-            
+
             def __repr__(self):
                 return "<"+self.name+">"
 
@@ -976,7 +976,7 @@
         class Test_Resurrection(object):
             def __init__(self, name):
                 self.name = name
-            
+
             def __repr__(self):
                 return "<"+self.name+">"
 
@@ -1035,7 +1035,7 @@
         class Test_Resurrection(object):
             def __init__(self, name):
                 self.name = name
-            
+
             def __repr__(self):
                 return "<"+self.name+">"
 
@@ -1071,11 +1071,10 @@
         self.assertEqual(wc(), None)
 
 
- at unittest.skipUnless(test_support.is_jython,
-        '''
-        The test involves Java-classes and is thus not supported by
-        non-Jython interpreters.
-        ''')
+ at unittest.skipUnless(test_support.is_jython and test_support.get_java_version() < (9,),
+        "Test is specific to Java versions <9")
+        # From Java 9 onwards we get ugly warnings.
+        # See discussion in http://bugs.jython.org/issue2656
 class GCTests_Jy_TraverseByReflection(unittest.TestCase):
 
     @classmethod
@@ -1083,6 +1082,7 @@
         #Jython-specific block:
         try:
             cls.savedJythonGCFlags = gc.getJythonGCFlags()
+            gc.removeJythonGCFlags(gc.DONT_TRAVERSE_BY_REFLECTION)  # i.e. enable ...
             gc.addJythonGCFlags(gc.SUPPRESS_TRAVERSE_BY_REFLECTION_WARNING)
             gc.setMonitorGlobal(True)
         except Exception:
@@ -1096,25 +1096,32 @@
         except Exception:
             pass
 
-    def test_TraverseByReflection(self):
+    def test_Field(self):
         gc.collect()
-
         prt = GCTestHelper.reflectionTraverseTestField()
         del prt
         self.assertEqual(gc.collect(), 1)
 
+    def test_List(self):
+        gc.collect()
         prt = GCTestHelper.reflectionTraverseTestList()
         del prt
         self.assertEqual(gc.collect(), 1)
 
+    def test_Array(self):
+        gc.collect()
         prt = GCTestHelper.reflectionTraverseTestArray()
         del prt
         self.assertEqual(gc.collect(), 1)
 
+    def test_PyList(self):
+        gc.collect()
         prt = GCTestHelper.reflectionTraverseTestPyList()
         del prt
         self.assertEqual(gc.collect(), 2)
 
+    def test_Cycle(self):
+        gc.collect()
         prt = GCTestHelper.reflectionTraverseTestCycle()
         del prt
         self.assertEqual(gc.collect(), 0)
diff --git a/src/org/python/modules/gc.java b/src/org/python/modules/gc.java
--- a/src/org/python/modules/gc.java
+++ b/src/org/python/modules/gc.java
@@ -469,7 +469,7 @@
                                          DEBUG_OBJECTS |
                                          DEBUG_SAVEALL;
 
-    private static short gcFlags = 0;
+    private static short gcFlags = DONT_TRAVERSE_BY_REFLECTION;
     private static int debugFlags = 0;
     private static boolean monitorNonTraversable = false;
     private static boolean waitingForFinalizers = false;

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list