[Jython-checkins] jython: Added tests for large methods and functions that exceed JVM method-size
stefan.richthofer
jython-checkins at python.org
Mon Jan 9 04:15:19 EST 2017
https://hg.python.org/jython/rev/86411e78fda0
changeset: 7994:86411e78fda0
user: Stefan Richthofer <stefan.richthofer at gmx.de>
date: Mon Jan 09 10:15:06 2017 +0100
summary:
Added tests for large methods and functions that exceed JVM method-size restriction.
files:
Lib/test/test_large_method_bytecode_jy.py | 87 +++++++++++
NEWS | 1 +
src/org/python/compiler/Module.java | 7 +-
3 files changed, 91 insertions(+), 4 deletions(-)
diff --git a/Lib/test/test_large_method_bytecode_jy.py b/Lib/test/test_large_method_bytecode_jy.py
new file mode 100644
--- /dev/null
+++ b/Lib/test/test_large_method_bytecode_jy.py
@@ -0,0 +1,87 @@
+"""
+Tests Jython's capability to handle Python-functions and
+methods that are so long that their JVM-bytecode exceeds
+JVM method size restrictions.
+The case that the main module code exceeds maximal length
+is somewhat special, so it is explicitly tested.
+
+Note: As of this writing, a CPython 2.7 bytecode-file (.pyc)
+ is required for each module that contains an oversized
+ function. The pyc-file is only required at compile-time
+ in the sense that if you pre-compile py-files to classes,
+ you won't need to distribute the pyc-file; it gets
+ embedded into the class-file.
+"""
+
+import unittest
+from test import test_support
+
+class large_method_tests(unittest.TestCase):
+ '''Tests some oversized functions and methods.
+ '''
+
+ @classmethod
+ def setUpClass(cls):
+ import large_methods as _large_methods
+ global large_methods
+ large_methods = _large_methods
+
+ def test_large_func(self):
+ '''Tests a function that slightly exceeds maximal JMV method
+ length. It is internally represented as CPython bytecode.
+ '''
+ self.assertEqual(large_methods.large_function(), 'large 2300')
+
+ def test_large_method(self):
+ '''Tests a method that slightly exceeds maximal JMV method
+ length. It is internally represented as CPython bytecode.
+ '''
+ cl = large_methods.OversizedMethodHolder()
+ self.assertEqual(cl.large_function(), 'large_method 2300')
+
+ def test_very_large_func(self):
+ '''Here we test a function that is so large that its Python bytecode
+ exceeds maximal String-literal length. It is automatically split up
+ into several literals.
+ '''
+ self.assertEqual(large_methods.very_large_function(), 'very large 58900')
+
+ def test_small_func(self):
+ '''We assert that ordinary-sized, i.e. JVM-bytecode methods still work
+ in context of PyBytecode.
+ '''
+ self.assertEqual(large_methods.small_function(), 'small 10')
+
+class large_module_tests(unittest.TestCase):
+ '''Tests a module with oversized main-code.
+ So the whole module is represented as a single PyBytecode object.
+ Additionally same tests as in large_method_tests are applied.
+ '''
+
+ @classmethod
+ def setUpClass(cls):
+ import large_module as _large_module
+ global large_module
+ large_module = _large_module
+
+ def test_large_module_main(self):
+ '''Tests the module's oversized main-code.
+ '''
+ self.assertEqual(large_module.count, 2310)
+
+ def test_large_module_method(self):
+ cl2 = large_module.OversizedMethodHolder()
+ self.assertEqual(cl2.large_function(), 'large_method 2300')
+
+ def test_large_module_large_func(self):
+ self.assertEqual(large_module.large_function(), 'large 2300')
+
+ def test_large_module_very_large_func(self):
+ self.assertEqual(large_module.very_large_function(), 'very large 58900')
+
+ def test_large_module_small_func(self):
+ self.assertEqual(large_module.small_function(), 'small 10')
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@
Jython 2.7.1rc1
Bugs fixed
+ - [ 2515 ] typing module doesn't import
- [ 2538 ] Test failures in test_unittest
- [ 2293 ] "java.lang.IllegalArgumentException: java.lang.IllegalArgumentException:
Cannot create PyString with non-byte value" triggered after adding
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
@@ -859,13 +859,12 @@
// Probably this cannot yield cycles, so cycle-proof stuff
// is out-commented for now. (everything regarding 'allCodes')
PyBytecode bcode = buffer.pop();
- //System.out.println("PyBytecode: "+bcode.co_name+" of size "+bcode.co_code.length);
if (bcode.co_code.length > thresh) {
largest_m_codes.add(bcode);
} else {
- // If a function needs to be done as bytecode, we create all inner
- // PyCode-items (classes, functions, methods) also as bytecode
- // implicitly, so no need so look at them individually.
+ // If a function needs to be represented as CPython bytecode, we create
+ // all inner PyCode-items (classes, functions, methods) also as CPython
+ // bytecode implicitly, so no need so look at them individually.
// Maybe we can later optimize this such that inner methods can be
// JVM-bytecode as well (if not oversized themselves).
for (PyObject item: bcode.co_consts) {
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list