Functions to manange the Java Virtual Machine (JVM)
Class factory for JVM runtime classes.
Osprey exposes raw Java classes to Python code using a bridge library called JPype. To access the raw Java classes from Python code, call properties and functions on this factory object.
For example, to construct an instance of a Java class called ArrayList
in the package java.util
call its constructor:
osprey.jvm.c.java.util.ArrayList()
Currently, the java.*
and javax.*
packages are supported.
addClasspath(path)
Adds the given path to the class path.
The next call to start
will use this classpath to launch the JVM.
Arguments
str
: the classpath entry, usually a path to a .jar
file, of a folder of .class
files.makeClasspath()
Returns the classpath that has been collected by addClasspath
.
Returns
str
where all classpath entries have been joined by the system classpath separator character.
setNativesDir(path)
Sets the directory for native libraries.
The next call to start
will use this directory to launch the JVM.
start_with_args(jrePath, jvmArgs)
Start the JVM with the given arguments.
Settings accumulated by addClasspath
and setNativesDir
are ignored.
Arguments
str
: Path to the JVM installation folder[str]
: Command-line arguments to pass to the JVMstart(jrePath, heapSizeMiB=1024, enableAssertions=False, stackSizeMiB=None, garbageSizeMiB=None, allowRemoteManagement=False, attachJvmDebugger=False)
Starts the JVM using the settings accumulated by addClasspath
and setNativesDir
,
as well as settings from the keyword arguments.
Arguments
str
: Path to the JVM installation folderint
: The size of the JVM heap, in Mebibytes, ie the -Xmx
flag.bool
: True to enable Java assertions, ie the -ea
flag.int
: The size of the JVM stack, in Mebibytes, ie the -Xss
flag.
You can leave this at the default value, unless the JVM crashes with an error saying the stack size is too small. Then try running your program again with a larger stack size.
int
: The size of the JVM heap reserved for garbage collection, in Mebibytes, ie the -XX:MaxNewSize
flag.
By default, the JVM will reserve roughly 1/3 of the heap for garbage collection, but this may
be inefficient for Osprey runs that need a lot of non-garbage memory.
To reserve more non-garbage memory for Osprey calculations and less memory for garbage collection,
supply a value here to limit the garbage reservation to a fixed size.
Often, a gibibyte or two is plenty of memory for garbage collection, but the total heap size
may be much larger than a few gibibytes.bool
: True
to turn on JMX remote management.bool
: True
to turn on the JVM debugger service, see Attaching a Debugger.shutdown()
Shuts down the JVM and releases all its resources from the process. The Python VM will keep running as usual though.
toArrayList(items)
Convert the python list into a java ArrayList
object.
Arguments
[]
: the python listReturns
toFile(path)
Converts a path into a java File
object.
Arguments
str
: A pathReturns
getJavaClass(classname)
Returns the class object for the given class name.
Arguments
str
: The fully-qualified name of a Java class.
Inner classes should be separated from outer classes with a $
character,
rather than a .
character.Returns
getInnerClass(jclass, inner_class_name)
Gets the inner class from the Java outer class.
Arguments
c
.str
: The simple name of the inner class.Returns
boxDouble(val)
Converts the python floating-point number into a Java Double
object.
Arguments
float
: the numberReturns
boxInt(val)
Converts the python integer number into a Java Integer
object.
Arguments
int
: the numberReturns
boxLong(val)
Converts the python integer number into a Java Long
object.
Arguments
int
: the numberReturns