[plt-scheme] Embedding MzScheme in Java

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Aug 16 01:32:25 EDT 2006

At Mon, 14 Aug 2006 14:03:41 -0700, Randal Walser wrote:
> I finally figured out why I was getting an access violation when
> initializing MzScheme within a Java app.  The upshot is that MzScheme
> assumes Win32 embedding apps have a thread stack size of 1 MB, but
> Sun's HotSpot JVM native stack is only a quarter that size.

I can see how that problem would lead to a crash where MzScheme
overflows the stack instead of avoiding it. I can't quite see how it
would lead to the early crash in your previous stack trace, though.

>   scheme_stack_boundary += (STACK_SAFETY_MARGIN - 0x100000);
> after initializing scheme_stack_boundary to the scheme stack base, the
> result, in the case at hand, is (logically) a negative number because
> the Java native stack top is way lower than anticipated when MzScheme
> first gets control.

It seems like MzScheme would just think that the deepest point of the
stack is way deeper than it actually is. That should lead to late
overflow handling, instead of premature overflow handling.

Probably I'm overlooking something. In any case, it sounds like your
explanation make things work.

>   1) Provide a variant of scheme_set_stack_base with an argument that
>      explicitly tells MzScheme what size stack it's dealing with.

Makes sense to me. I added scheme_init_stack_bounds() in SVN:

 void scheme_set_stack_bounds(void *base, void *deepest, int no_auto_statics);

"deepest" corresponds to the stack not-quite-end, leaving some room for
overflow detection and handling. The amount of room in the default
calculation (i.e., STACK_SAFETY_MARGIN) is 50000 bytes.


Posted on the users mailing list.