Operating System - OpenVMS
1821437 Members
3003 Online
109633 Solutions
New Discussion юеВ

[Java JNI] Loading a shared image

 
Bernhard Dorninger
New Member

[Java JNI] Loading a shared image

Hi!

I am using Java 1.4.2 under OpenVMS 7.3.1 with ODS-5.

From our application, which is highly dynamic and plugin oriented, we load and unload Java components at runtime. Sometimes we have to integrate legacy code, which is done via JNI.
The problem is, that loading the SHRs the way HP suggests in their JNI example is not applicable for us, since this would require us to define a symbol for each installed library (and drop it when the component is uninstalled).

Java.lang.System provides two methods to load native code:
System.loadLibrary(String libname) --> this one requires a defined symbol
System.load(String path) --> takes an absolute path to the SHR.

Can anyone tell me which path syntax is expected by System.load?
4 REPLIES 4
Robert Gezelter
Honored Contributor

Re: [Java JNI] Loading a shared image

Bernhard,

Perhaps I am mis-understanding some element of your problem description, but System.loadLibrary does not require a "symbol". The -libmame- parameter is used as a logical name (not a symbol).

Unloading dynamically loaded code is a whole different topic, and has complications (which I would expect, on first glance, to have other, deeper issues).

I have used this interface successfully. It does obey the logical name (for the native code; java code still needs to be on CLASSPATH).

Defining the logical name to point to different places from within java code should not be a problem (with the appropriate auxilliary code to invoke the system services to define/redefine the logical name).

I hope that the above is helpful.

- Bob Gezelter, http://www.rlgsc.com
Bernhard Dorninger
New Member

Re: [Java JNI] Loading a shared image

Thanks, Robert.

Do you have any hints where to find code that allows the use of OpenVMS commands from within java?
I think that Runtime.exec(..) won't do, because this call spawns another process.

And, of course UNloading the native code is really a different issue and it's not supported by the Java API at all.

However, i still try to get System.load(pathname) to work, since this would render a logical name unnecessary (so I hope at least..)
Can't test this before Tuesday, since I have no access to an OpenVMS machine from home....

regards,
Bernhard
Robert Gezelter
Honored Contributor

Re: [Java JNI] Loading a shared image

Bernhard,

I have not needed to do things in this particular way (yet), but the following should work.

To the best of my knowledge, there is no restriction on the number of native mode libraries that you can connect to. I would thus do what you are attempting in the following way:
- Loan a basic JNI library which allows you to define/redefine a logical name in the process logical name table.
- Use that basic library to define the logical name.
- Then issue the loadLibrary function.

Since, as we noted earlier, unload is a whole different story, I would be careful to make sure that the quotas were sufficient, otherwise you will effectively be creating a situation with much the same virtual address behavior as a "memory leak".

I hope that the preceeding is helpful.

- Bob Gezelter, http://www.rlgsc.com
Bojan Nemec
Honored Contributor

Re: [Java JNI] Loading a shared image

Bernhard,

A little hint abbout shared images loaded in run time. I am not shure but the shared images are probably loaded using the LIB$FIND_IMAGE_SYMBOL run time library function.

When using LIB$FIND_IMAGE_SYMBOL you must have different image names/ logical names which points to different images. If you define the same logical name to two different images the function will not load the second image.

Example:
You have two shareable images with the same function:

void shrfunc () {printf ("Image A\n");}

and

void shrfunc () {printf ("Image B\n");}

(both linked /share with SYMBOL_VECTOR=(shrfunc=PROCEDURE) option)

Now the main program which loads and execute both image functions:

$DESCRIPTOR (logical_name , "MYSHAREIMAGE");
$DESCRIPTOR (procedure_name , "SHRFUNC");
$DESCRIPTOR (imagea , "dev:[dir]imagea.exe");
$DESCRIPTOR (imageb , "dev:[dir]imageb.exe");
void (*procedure) ();

lib$set_logical (&logical_name , &imagea);
lib$find_image_symbol (&logical_name , &procedure_name , &procedure);
(*procedure)();

lib$set_logical (&logical_name , &imageb);
lib$find_image_symbol (&logical_name , &procedure_name , &procedure);
(*procedure)();

Now the result (output) is

Image A
Image A

and not

Image A
Image B

what is supposed to be the result!

So when you define the logical name, give to each image a different name.

Bojan