[Jython-checkins] jython: Enable test_large_method_bytecode_jy in regrtest (for less than Java 9).
jeff.allen
jython-checkins at python.org
Sun Jan 6 04:31:33 EST 2019
https://hg.python.org/jython/rev/291b0e7b0d55
changeset: 8213:291b0e7b0d55
user: Jeff Allen <ja.py at farowl.co.uk>
date: Sat Jan 05 05:07:10 2019 +0000
summary:
Enable test_large_method_bytecode_jy in regrtest (for less than Java 9).
Give test_large_method_bytecode_jy a test_main so that it runs under regrtest.
Also, the update to ASM 7.0 offers us a better way to detect oversized code in
Module.java.
files:
Lib/test/test_large_method_bytecode_jy.py | 11 ++++-
src/org/python/compiler/Module.java | 23 +++-------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/Lib/test/test_large_method_bytecode_jy.py b/Lib/test/test_large_method_bytecode_jy.py
--- a/Lib/test/test_large_method_bytecode_jy.py
+++ b/Lib/test/test_large_method_bytecode_jy.py
@@ -16,6 +16,7 @@
import unittest
from test import test_support
+ at unittest.skipIf(test_support.get_java_version() >= (9,), "Fails on Java 9+, see #2663")
class large_method_tests(unittest.TestCase):
'''Tests some oversized functions and methods.
'''
@@ -52,6 +53,7 @@
'''
self.assertEqual(large_methods.small_function(), 'small 10')
+ at unittest.skipIf(test_support.get_java_version() >= (9,), "Fails on Java 9+, issue #2663")
class large_module_tests(unittest.TestCase):
'''Tests a module with oversized main-code.
So the whole module is represented as a single PyBytecode object.
@@ -82,6 +84,11 @@
def test_large_module_small_func(self):
self.assertEqual(large_module.small_function(), 'small 10')
+def test_main():
+ test_support.run_unittest(
+ large_method_tests,
+ large_module_tests
+ )
+
if __name__ == "__main__":
- unittest.main()
-
+ test_main()
diff --git a/src/org/python/compiler/Module.java b/src/org/python/compiler/Module.java
--- a/src/org/python/compiler/Module.java
+++ b/src/org/python/compiler/Module.java
@@ -21,6 +21,7 @@
import javax.xml.bind.DatatypeConverter;
import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodTooLargeException;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.python.antlr.ParseException;
@@ -631,7 +632,7 @@
for (i = 0; i < labels.length; i++) {
labels[i] = new Label();
}
-
+
// Get index for function to call
code.iload(1);
code.tableswitch(0, labels.length - 1, def, labels);
@@ -840,7 +841,7 @@
}
}
}
-
+
private static String serializePyBytecode(PyBytecode btcode) throws java.io.IOException {
// For some reason we cannot do this using _marshal:
/*
@@ -871,7 +872,7 @@
}
private static final int maxLiteral = 65535;
-
+
/**
* This method stores Python-Bytecode in String literals.
* While Java supports rather long strings, constrained only by
@@ -930,15 +931,14 @@
Module module = new Module(name, filename, linenumbers, mtime);
_module_init(node, module, printResults, cflags);
module.write(ostream);
- } catch (RuntimeException re) {
- if (re.getMessage() != null && re.getMessage().equals("Method code too large!")) {
+ } catch (MethodTooLargeException re) {
PyBytecode btcode = loadPyBytecode(filename, true);
int thresh = 22000;
// No idea, how to determine at this point if a method is oversized, so we just try
// a threshold regarding Python code-length, while JVM restriction is actually about
// Java bytecode length. Anyway; given that code-lengths are strongly related, this
// should work well enough.
-
+
while (true) { // Always enjoy to write a line like this :)
try {
List<PyBytecode> largest_m_codes = new ArrayList<>();
@@ -993,12 +993,8 @@
_module_init(node, module, printResults, cflags);
module.write(ostream);
break;
- } catch (RuntimeException e) {
- if (re.getMessage() == null || !e.getMessage().equals("Method code too large!")) {
- throw e;
- } else {
- thresh -= 100;
- }
+ } catch (MethodTooLargeException e) {
+ thresh -= 100;
}
if (thresh == 10000) { /* This value should be well feasible by JVM-bytecode,
so something else must be wrong. */
@@ -1007,9 +1003,6 @@
"\nby PyBytecode-approach:\n"+filename);
}
}
- } else {
- throw re;
- }
}
}
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list