[plt-scheme] Embedding MzScheme in Java
I'd like to embed MzScheme 352 in a Java app, via the JNI, but I'm
encountering what appears to be a thread stack issue during
MzScheme initialization (in scheme_basic_env). Before I dig any
deeper I thought I'd ask if I'm overlooking something obvious, or if
there's some fundamental reason MzScheme can't be called straightaway
through the JNI.
I've followed the instructions in section 1.2 of Inside PLT MzScheme,
but the HotSpot JVM (1.5.0_02-b09 mixed mode) reports an
EXCEPTION_ACCESS_VIOLATION somewhere within scheme_basic_env. After a
bit of debugging, I can see that a stack overflow is detected within
datum_to_syntax_inner and that the access violation occurs when
scheme_handle_stack_overflow tries to copy the stack (leading me to
think there's some sort of Java/MzScheme thread conflict).
Here's the call sequence leading up to the violation:
file line function called
---- ---- ---------------
(jni glue file) scheme_basic_env
env.c 416 scheme_init_eval
env.c 334 make_init_env
eval.c 489 scheme_datum_to_syntax
stxobj.c 4936 datum_to_syntax_inner
stxobj.c 4747 scheme_handle_stack_overflow
eval.c 522 scheme_setjmpup (i.e., scheme_setjmpup_relative)
setjmpup.c 543 scheme_copy_stack
setjmpup.c 320 memcpy
I've tried linking with the MzScheme and GC dlls
1) in their default form (compiled with the /MT MSVC option), and
2) with the /MD option and USE_MSVC_MD_LIBRARY defined, as
recommended in the plt/src/worksp/README file (for linking
to DLL-based C libraries).
I've also tried scheme_set_stack_base with all possible arg
combinations. In every case, the call sequence leading to the
violation is the same.
BTW, the README file in plt/src/worksp says that GC_pre_init should be
called when MzScheme links to a DLL-based C library, but apparently
GC_pre_init has disappeared from libmzgc. The function definition
used to be in src/mzscheme/gc/mark.c. So I'm wondering ... just what
was the purpose of GC_pre_init, and why has it disappeared?
Curiously, the GC_pre_init prototype is still in scheme.h, yet the
GC_pre_init function is nowhere to be found.
I'd greatly appreciate any advice anyone might offer.
Thanks,
Randal