Launch new JVMs from Scala by remote control
Oubliette provides a convenient way to launch a new JVM instance by specifying the classpath, main method and arguments to be invoked. Classes may be pre-loaded, providing near-instantaneous JVM startup time. This provides similar functionality to invoking a main method through a classloader, but with significantly better isolation from the initiating JVM.
- launch JVM instances by specifying command-line parameters
- achieve near-instantaneous startup times by preloading classes
- automatically download Adoptium JDKs before launching
Oubliette can launch a new JVM, represented by an instance of Jvm
, from a
particular installed version of a JDK, represented by an instance of Jdk
.
This can either be done in a single command, Jdk#launch
, or through a series
of steps, which may make the final invocation step faster in some cases.
The simplest invocation is,
val jvm: Jvm = jdk.launch(classpath, main, args)
where classpath
is a List
of paths, main
is the name of the main class to
launch, and args
is a List
of arguments. The paths may be specified in any
type for which a GenericPathReader
instanceexists, as defined in
Anticipation, such as
java.io.File
.
From a Jvm
instance, methods such as Jvm#stdout
, Jvm#stderr
and
Jvm#stdin
provide access to the JVM's input and output streams, through a
LazyList[IArray[Byte]]
interface. Additionally, Jvm#pid
will give the
running JVM's process ID, and Jvm#abort
will abort execution.
But a JVM can be created without having it start execution. We can launch a new JVM with,
val jvm = jdk.init()
and provide it with the details it needs to run in steps, with:
Jvm#addClasspath
to add a path to the classpath,Jvm#addArg
to add a singleText
argument to themain
method,Jvm#setMain
to specify themain
method, and,Jvm#preload
to load the named classes early
Preloading classes offers the opportunity to prime the JVM instance to be as
ready as possible to invoke the specified main
method when the time comes.
This results in near-instantaneous startup times, provided the classes can be
loaded long enough before the main method is invoked.
A Jdk
instance can be created by specifying its version number, e.g. 17
,
and a path (in any path format) to its home directory, that is, the directory
which contains the bin
directory in which the java
executable resides. For
example:
val jdk = Jdk(14, java.io.File("/usr/lib/jdk"))
Adoptium provides prebuild OpenJDK binaries for
download, and Oubliette can automatically download and use them. This is as
simple as installing the Adoptium script to the filesystem with,
Adoptium.install()
, and calling get()
on the result, to fetch the most
recent version.
Other options (all with default values) for the get
method include,
version
, the JDK versionjre
, should betrue
if a JRE is preferred over a full JDKearly
, should betrue
if early-access binaries should be consideredforce
, to force download again, even if an existing installation exists
If an appropriate JDK can be found, then get
will return a Jdk
instance,
from which a Jvm
can be launched.
Oubliette is classified as embryonic. For reference, Soundness projects are categorized into one of the following five stability levels:
- embryonic: for experimental or demonstrative purposes only, without any guarantees of longevity
- fledgling: of proven utility, seeking contributions, but liable to significant redesigns
- maturescent: major design decisions broady settled, seeking probatory adoption and refinement
- dependable: production-ready, subject to controlled ongoing maintenance and enhancement; tagged as version
1.0.0
or later - adamantine: proven, reliable and production-ready, with no further breaking changes ever anticipated
Projects at any stability level, even embryonic projects, can still be used, as long as caution is taken to avoid a mismatch between the project's stability level and the required stability and maintainability of your own project.
Oubliette is designed to be small. Its entire source code currently consists of 120 lines of code.
Oubliette will ultimately be built by Fury, when it is published. In the meantime, two possibilities are offered, however they are acknowledged to be fragile, inadequately tested, and unsuitable for anything more than experimentation. They are provided only for the necessity of providing some answer to the question, "how can I try Oubliette?".
-
Copy the sources into your own project
Read the
fury
file in the repository root to understand Oubliette's build structure, dependencies and source location; the file format should be short and quite intuitive. Copy the sources into a source directory in your own project, then repeat (recursively) for each of the dependencies.The sources are compiled against the latest nightly release of Scala 3. There should be no problem to compile the project together with all of its dependencies in a single compilation.
-
Build with Wrath
Wrath is a bootstrapping script for building Oubliette and other projects in the absence of a fully-featured build tool. It is designed to read the
fury
file in the project directory, and produce a collection of JAR files which can be added to a classpath, by compiling the project and all of its dependencies, including the Scala compiler itself.Download the latest version of
wrath
, make it executable, and add it to your path, for example by copying it to/usr/local/bin/
.Clone this repository inside an empty directory, so that the build can safely make clones of repositories it depends on as peers of
oubliette
. Runwrath -F
in the repository root. This will download and compile the latest version of Scala, as well as all of Oubliette's dependencies.If the build was successful, the compiled JAR files can be found in the
.wrath/dist
directory.
Contributors to Oubliette are welcome and encouraged. New contributors may like to look for issues marked beginner.
We suggest that all contributors read the Contributing Guide to make the process of contributing to Oubliette easier.
Please do not contact project maintainers privately with questions unless there is a good reason to keep them private. While it can be tempting to repsond to such questions, private answers cannot be shared with a wider audience, and it can result in duplication of effort.
Oubliette was designed and developed by Jon Pretty, and commercial support and training on all aspects of Scala 3 is available from Propensive OÜ.
An oubliette is a dungeon into which a prisonner could be condemned for a lifetime, no longer interacting with the outside world; metaphorically, a separate JVM instance.
/ˌuːbliːˈet/
In general, Soundness project names are always chosen with some rationale, however it is usually frivolous. Each name is chosen for more for its uniqueness and intrigue than its concision or catchiness, and there is no bias towards names with positive or "nice" meanings—since many of the libraries perform some quite unpleasant tasks.
Names should be English words, though many are obscure or archaic, and it should be noted how willingly English adopts foreign words. Names are generally of Greek or Latin origin, and have often arrived in English via a romance language.
The logo shows the trapdoor entrance to an oubliette in a castle turret.
Oubliette is copyright © 2024 Jon Pretty & Propensive OÜ, and is made available under the Apache 2.0 License.