Package org.python.core
Class BytecodeLoader
- java.lang.Object
-
- org.python.core.BytecodeLoader
-
public class BytecodeLoader extends java.lang.Object
Utility class for loading compiled python modules and java classes defined in python modules.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BytecodeLoader.Loader
-
Constructor Summary
Constructors Constructor Description BytecodeLoader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
fixPyBytecode(java.lang.Class<? extends ContainsPyBytecode> c)
This method looks for Python-Bytecode stored in String literals.static java.lang.Class<?>
makeClass(java.lang.String name, byte[] data, java.lang.Class<?>... referents)
Turn the java byte code in data into a java class.static java.lang.Class<?>
makeClass(java.lang.String name, java.util.List<java.lang.Class<?>> referents, byte[] data)
Turn the java byte code in data into a java class.static PyCode
makeCode(java.lang.String name, byte[] data, java.lang.String filename)
Turn the java byte code for a compiled python module into a java class.
-
-
-
Method Detail
-
makeClass
public static java.lang.Class<?> makeClass(java.lang.String name, byte[] data, java.lang.Class<?>... referents)
Turn the java byte code in data into a java class.- Parameters:
name
- the name of the classdata
- the java byte code.referents
- superclasses and interfaces that the new class will reference.
-
makeClass
public static java.lang.Class<?> makeClass(java.lang.String name, java.util.List<java.lang.Class<?>> referents, byte[] data)
Turn the java byte code in data into a java class.- Parameters:
name
- the name of the classreferents
- superclasses and interfaces that the new class will reference.data
- the java byte code.
-
fixPyBytecode
public static void fixPyBytecode(java.lang.Class<? extends ContainsPyBytecode> c) throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException, java.io.IOException, java.lang.ClassNotFoundException
This method looks for Python-Bytecode stored in String literals. While Java supports rather long strings, constrained only by int-addressing of arrays, it supports only up to 65535 characters in literals (not sure how escape-sequences are counted). To circumvent this limitation, the code is automatically splitted into several literals with the following naming-scheme. - The marker-interface 'ContainsPyBytecode' indicates that a class contains (static final) literals of the following scheme: - a prefix of '___' indicates a bytecode-containing string literal - a number indicating the number of parts follows - '0_' indicates that no splitting occurred - otherwise another number follows, naming the index of the literal - indexing starts at 0 Examples: ___0_method1 contains bytecode for method1 ___2_0_method2 contains first part of method2's bytecode ___2_1_method2 contains second part of method2's bytecode Note that this approach is provisional. In future, Jython might contain the bytecode directly as bytecode-objects. The current approach was feasible with much less complicated JVM bytecode-manipulation, but needs special treatment after class-loading.- Throws:
java.lang.IllegalAccessException
java.lang.NoSuchFieldException
java.io.IOException
java.lang.ClassNotFoundException
-
makeCode
public static PyCode makeCode(java.lang.String name, byte[] data, java.lang.String filename)
Turn the java byte code for a compiled python module into a java class.- Parameters:
name
- the name of the classdata
- the java byte code.
-
-