public class BytecodeLoader
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
BytecodeLoader.Loader |
| Constructor and Description |
|---|
BytecodeLoader() |
| Modifier and Type | Method and Description |
|---|---|
static void |
fixPyBytecode(java.lang.Class<? extends ContainsPyBytecode> c)
This method looks for Python bytecode stored in string literals.
|
static boolean |
getIgnoreSerialVersionUID()
Only relevant in presence of oversized methods or functions, this tells whether or not
to ignore
serialVersionUID associated with the corresponding code objects. |
static java.lang.Class<?> |
makeClass(java.lang.String name,
byte[] data,
java.lang.Class<?>... referents)
Turn the Java class file 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 class file data into a Java class.
|
static PyCode |
makeCode(java.lang.String name,
byte[] data,
java.lang.String filename)
Turn the Java class file data for a compiled Python module into a
PyCode object, by
constructing an instance of the named class and calling the instance's
PyRunnable.getMain(). |
static void |
setIgnoreSerialVersionUID(boolean value)
Only relevant in presence of oversized methods or functions, this controls whether or
not to ignore
serialVersionUID associated with the corresponding code objects. |
public static boolean getIgnoreSerialVersionUID()
serialVersionUID associated with the corresponding code objects.
Default value is true.
See setIgnoreSerialVersionUID(boolean) for details.serialVersionUID data is ignored when PyBytecode
objects are parsed via Java serialization in fixPyBytecode(Class),
default is truesetIgnoreSerialVersionUID(boolean),
fixPyBytecode(Class)public static void setIgnoreSerialVersionUID(boolean value)
serialVersionUID associated with the corresponding code objects.
Methods and functions in Python might not be compilable to JVM bytecode if they exceed a
certain size. In that case, Jython can use compiled CPython bytecode (as in .pyc
files) instead. This bytecode is embedded into the module's $py.class file by
storing the PyBytecode object via Java serialization in string constants.
This mechanism can break compatibility with older Jython versions if computed values
of serialVersionUID changed due to subtle code adjustments. Usually, compatibility
is not actually broken, so Jython bypasses the check for serialVersionUID as far
as objects comprised by a PyBytecode object are concerned.
This option allows to control that behavior. By setting it to false, a strict check
for serialVersionUID is required. By default, the value of this option is
true and the check is bypassed.value - indicates whether or not serialVersionUID data is to be ignored when
PyBytecode objects are parsed via Java serialization in
fixPyBytecode(Class), default is true.getIgnoreSerialVersionUID(),
fixPyBytecode(Class),
Solve serialization backward
incompatibility of oversized methods and functions.,
Clarification on compile
(Module or method too large)public static java.lang.Class<?> makeClass(java.lang.String name,
byte[] data,
java.lang.Class<?>... referents)
name - fully-qualified binary name of the classdata - a class file as a byte arrayreferents - super-classes and interfaces that the new class will reference.public static java.lang.Class<?> makeClass(java.lang.String name,
java.util.List<java.lang.Class<?>> referents,
byte[] data)
name - the name of the classreferents - super-classes and interfaces that the new class will reference.data - a class file as a byte arraypublic static void fixPyBytecode(java.lang.Class<? extends ContainsPyBytecode> c) throws java.lang.IllegalAccessException, java.lang.NoSuchFieldException, java.io.IOException, java.lang.ClassNotFoundException
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 split
into several literals with the following naming-scheme.
The marker-interface ContainsPyBytecode indicates that a class
contains (static final) literals of the following scheme:
___' indicates a bytecode-containing string literal
0_' indicates that no splitting occurred
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.
java.lang.IllegalAccessExceptionjava.lang.NoSuchFieldExceptionjava.io.IOExceptionjava.lang.ClassNotFoundExceptionContainsPyBytecodepublic static PyCode makeCode(java.lang.String name, byte[] data, java.lang.String filename)
PyCode object, by
constructing an instance of the named class and calling the instance's
PyRunnable.getMain().name - fully-qualified binary name of the classdata - a class file as a byte arrayfilename - to provide to the constructor of the named classPyCode object produced by the named class' getMain