« Return to Thread: JNIPort for VisualWorks

JNIPort for VisualWorks available in Cincom Public Repository

by Joachim Geidel-2 :: Rate this Message:

Reply to Author | View in Thread

Hi all,

I just published a first version of a VisualWorks port of Chris Uppal's
JNIPort to the Cincom Public Repository.

JNIPort is an interface which makes it possible to use Java libraries
from Smalltalk. It invokes a Java VM using the Invocation Interface
functions of the Java Native Interface (JNI).

JNIPort consists of four bundles:
        JNIPort Prerequisites
        JNIPort
        JNIPort Tests
        JNIPort Tools
You will also need recent versions of the following packages:
        Registry
        Weaklings

For detailed documentation of JNIPort including examples see
        http://www.metagnostic.org/DolphinSmalltalk/JNIPort.html

To use callbacks from Java to Smalltalk and to run the unit tests, you
will need the files contained in the 'Extras' directory contained in the
archive which can be downloaded from Chris Uppal's web site:
        http://www.metagnostic.org/DolphinSmalltalk/JNIPort-Complete.zip
The archive also contains a copy of the complete documentation.

The bundle comment of JNIPort contains a few additional code samples:
computing "-3 abs" the hard way, and querying the JVM for the JNI
version number.

The current state of the port is clearly "work in progress". It does not
yet work, and the unit tests are failing. I have done the port on
Windows XP with Java 1.5.0 and have not tried any other configuration.

So far, it is possible to create a JVM instance connected to a real Java
VM ("JVM newWithDefaultSettings") and to execute low level JNI function
calls as shown in the code samples in the bundle comment. To run the
tests, you have to execute "JVM newWithDefaultSettings" first.

When a call of a Java method raises a Java exception (a Throwable),
JNIPort can not yet cope with the situation. It tries to find the
superclass of the Throwable, which fails with an "External access
failed". You'll run into this in the unit tests when you have the
complete code of JNIPort loaded and do not have the jar-files from the
Extras directory in the classpath.

I have tried to preserve the structure of the original code as much as
possible, but as the low level C APIs of VisualWorks and Dolphin
Smalltalk are quite different, there were lots of changes of low level
code. I also removed many of the methods which are specific to Dolphin,
and stripped down some supporting class libraries (in JNIPort
Prerequisites) to the bare minimum.

The VisualWorks port does not yet contain any GUI. Chris has implemented
a status monitoring tool with a configuration wizard, a tree view of the
(Java) class registry. When the mechanics are working, I would like to
add something similar to the VisualWorks version. Have a look at
http://www.metagnostic.org/DolphinSmalltalk/JNIPort/status-monitor.html
to see what the tools look like.

What's next:
- The tests must not fail.
- Creating a JVM for the tests might be implemented using a TestResource.
- The hard coded library path and library file names in JNIInterface
should be avoided, e.g. using the package External-Interface-Pragmas.
- Check the package FastCMethodPointers from the public repository; it
might enhance the performance of JNI function calls.
- General code cleaning. Remove unused and Dolphin specific methods.
- Make JVM creation more robust when Java classes corresponding to
wrapper classes in the image cannot be found in the classpath.
- Add a GUI.

If anybody would like to help finishing the port: load the code, and go
ahead. However, it might be a good idea to contact me, such that we can
avoid unnecessary parallel work. Please set the blessing level to "Work
in Progress" as long as the unit tests are failing.

Best regards,
Joachim Geidel

 « Return to Thread: JNIPort for VisualWorks