osprey.jvm

Functions to manange the Java Virtual Machine (JVM)

c

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

addClasspath(path)

Adds the given path to the class path.

The next call to start will use this classpath to launch the JVM.

Arguments

  • path str: the classpath entry, usually a path to a .jar file, of a folder of .class files.

makeClasspath

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

setNativesDir(path)

Sets the directory for native libraries.

The next call to start will use this directory to launch the JVM.

start_with_args

start_with_args(jrePath, jvmArgs)

Start the JVM with the given arguments.

Settings accumulated by addClasspath and setNativesDir are ignored.

Arguments

  • jrePath str: Path to the JVM installation folder
  • jvmArgs [str]: Command-line arguments to pass to the JVM

start

start(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

  • jrePath str: Path to the JVM installation folder
  • heapSizeMiB int: The size of the JVM heap, in Mebibytes, ie the -Xmx flag.
  • enableAssertions bool: True to enable Java assertions, ie the -ea flag.
  • stackSizeMiB 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.

  • garbageSizeMiB 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.
  • allowRemoteManagement bool: True to turn on JMX remote management.
  • attachJvmDebugger bool: True to turn on the JVM debugger service, see Attaching a Debugger.

shutdown

shutdown()

Shuts down the JVM and releases all its resources from the process. The Python VM will keep running as usual though.

toArrayList

toArrayList(items)

Convert the python list into a java ArrayList object.

Arguments

  • items []: the python list

Returns

ArrayList

toFile

toFile(path)

Converts a path into a java File object.

Arguments

  • path str: A path

Returns

File

getJavaClass

getJavaClass(classname)

Returns the class object for the given class name.

Arguments

  • classname 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

Class

getInnerClass

getInnerClass(jclass, inner_class_name)

Gets the inner class from the Java outer class.

Arguments

  • jclass: The JPype object representing the Java class, provided by a class factory like c.
  • inner_class_name str: The simple name of the inner class.

Returns

Class

boxDouble

boxDouble(val)

Converts the python floating-point number into a Java Double object.

Arguments

  • val float: the number

Returns

Double

boxInt

boxInt(val)

Converts the python integer number into a Java Integer object.

Arguments

  • val int: the number

Returns

Integer

boxLong

boxLong(val)

Converts the python integer number into a Java Long object.

Arguments

  • val int: the number

Returns

Long