[plt-scheme] Embedding MzScheme in Java

From: Randal Walser (randal-walser at comcast.net)
Date: Tue Aug 8 18:02:17 EDT 2006

Thanks for the quick reply :)

>Setting the C stack base is most likely the problem. The call to
>scheme_handle_stack_overflow means that MzScheme thinks its running out
>of stack space.
>I think scheme_set_stack_base() will be necessary, but how do you
>manage to get the stack base within JNI? In other words, maybe you can
>show the calls to scheme_set_stack_base() and scheme-basic_env().

Like so, following your example in Inside MzScheme:

Java_test_init_mzscheme(JNIEnv* env, jobject obj) {

    int dummy;
    Scheme_Env* e;

    // scheme_set_stack_base(NULL,1);

    e = scheme_basic_env();



I've tried various permutations of scheme_set_stack_base arguments, as
I mentioned earlier.  I also tried setting the JVM thread stack to be
ridiculously large, but MzScheme still detects a stack overflow.  Hmmm ...
at first I thought the problem might have to do with garbage
collection, but the stack overflow exception happens early on, before
the GC kicks in (or so it appears to me).  Am I overlooking anything in
the code leading up to the scheme_basic_env call?

>I think special support for /MD isn't necessary anymore, and I dropped
>it in the latest upgrade of the GC. I will check into whether it's
>needed after all (and clean up the docs if it isn't). My guess is that
>this isn't the problem in your application, though.

For now I'm limiting my focus to the /MT case.  I'll need to link to
the multi threaded dll runtime later, but I'm sure you're right. I'll
have to figure out what's going on with stack size in either case.


Posted on the users mailing list.