jni and garbage collection???

J

John McClain

I am running a webapp that calls JNI code which loads a powerbuilder .dll
and some powerbuilder code.
The problem I am having is this:
When I run the webapp and call powerbuilder functions through JNI and
PowerBuilder Native Interface code (a c++ .dll), it works for a while, but
then hangs. The pattern I have found to be consistent is that it hangs when
I wait a little while before making my next function call (via a jsp calling
a servlet calling JNI code). And here is the question - Why is my native
codes' state being changed or removed, and what would do that? Yes, I am
cleaning up after myself in the Native code

Does Garbage collection affect the loaded JNI code?

Is there some way to test / profile this ?

A general question - Is the native code loaded into the JVM address space or
does it reside outside of the JVM?
 
G

Gordon Beaton

The problem I am having is this:
When I run the webapp and call powerbuilder functions through JNI
and PowerBuilder Native Interface code (a c++ .dll), it works for a
while, but then hangs. The pattern I have found to be consistent is
that it hangs when I wait a little while before making my next
function call (via a jsp calling a servlet calling JNI code). And
here is the question - Why is my native codes' state being changed
or removed, and what would do that? Yes, I am cleaning up after
myself in the Native code

Does Garbage collection affect the loaded JNI code?

No, but that would depend how you define "affect" I suppose. Any Java
objects you create or access from your native code are subject to the
same reachability rules as objects created and accessed from Java
code. Anything you allocate with traditional native mechanisms (e.g.
malloc()) is immune to garbage collection.

One small difference is that the garbage collector doesn't know about
objects you no longer hold references to until you leave the current
context, i.e. when you return from the native method or call
PopLocalFrame().
Is there some way to test / profile this ?

A general question - Is the native code loaded into the JVM address
space or does it reside outside of the JVM?

Your code does exist in the same address space as the JVM, but the
garbage collector is not interested in anything but Java objects.

From your description of the problem, I'd say there is an error in
your native code. Look for stray pointers, uninitialized variables,
buffer overflows, or general pointer misuse, etc. Whenever native code
is part of the equation, hangs, crashes and other kinds of erratic
behaviour are rarely, if ever, caused by anything else.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,049
Members
48,769
Latest member
Clifft

Latest Threads

Top