Nested stack problem

James ketrenoj at
Wed Jul 12 18:23:39 PDT 2000

Ok, I got around the longjmp/setjmp problem w/ Mozilla by building Kaffe
w/ --with-threads=unix-pthreads.

Things were moving along well when my OJI plugin was a huge monolithic
function.  Now I am breaking it down so that it intiailizes in the correct
order (ie., a single JavaVM instance, multiple plugin instances).

The problem is that if I initialize the JVM within a nested function call,
and then attempt to use the JVM environment from a function that is nested
less than the call which initialized the JVM, the app segfaults.

Attached is a test program that illustrates the problem.  It is a simple
sample (see test.cpp).

Here is the general flow I need to use in order to work in Mozilla:

Mozilla initializes the class factory (nsKaffeFactory) for the plugin.  The
CreateInstance() method on this interface calls JNI_CreateJavaVM(...) and
caches the JNIEnv and JavaVM.  CreateInstance is used by Mozilla to obtain a
reference to an object that can host an individual APPLET.  So, Mozilla asks
nsKaffeFactory::CreateInstance for an nsKaffeApplet reference.
CreateInstance creates an nsKaffeApplet and provides the cached JNIEnv and
JavaVM values.  CreateInstance then returns.

Later on, Mozilla decides it wants to initialize the APPLET.  It then calls
Intialize, SetWindow, Start, etc. on the nsKaffeApplet.  Any attempt to use
any methods on JNIEnv in any of these methods results in a segfault.

I have determined the problem is being caused as a result of the use of
JNIEnv being done above the point in the stack where CreateJavaVM was

Does anyone know of a realistic work around?  Sure, I could modify the main
mozilla source so that it launches the JVM at the base of the stack before
it does ANYTHING else.  This would solve the problem, but would then create
a specific version of Mozilla just for Kaffe.


Thanks again,
ketrenoj at

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cpp
Type: application/octet-stream
Size: 3343 bytes
Desc: not available
Url : 

More information about the kaffe mailing list