Node:Mixing Java and Prolog, Next:, Previous:Mixing C and Prolog, Up:Top



Mixing Java and Prolog

Jasper is a bi-directional interface between Java and SICStus. The Java-side of the interface consists of a Java package (se.sics.jasper) containing classes representing the SICStus run-time system (SICStus, SPTerm, etc). The Prolog part is designed as a library module (library(jasper)).

The library module library(jasper) (see Jasper) provides functionality for controlling the loading and unloading the JVM (Java Virtual Machine), method call functionality (jasper_call/4), and predicates for managing object references.

Jasper can be used in two modes, depending on which system acts as Parent Application. If Java is the parent application, the SICStus runtime kernel will be loaded into the JVM using the System.loadLibrary() method (this is done indirectly when instantiating a SICStus object). In this mode, SICStus is loaded as a runtime system (see Runtime Systems).

As of SICStus 3.9, it is possible to use Jasper in multi threaded mode. This means that several Java threads can call SICStus runtime via a server thread. The communication between the client threads and the server thread is hidden from the programmer, and the API is based on Java Interfaces which are implemented both by the multi thread capable classes and the pre-3.9 classes which are restricted to single threaded mode. The decision whether to run in single thread mode or in multi threaded mode can thus be left until runtime.

If SICStus is the parent application, Java will be loaded as a foreign resource using the query use_module(library(jasper)). The Java engine is initialized using jasper_initialize/[1-2].