[armedbear-devel] Understanding JVM code
Mark Evenson
evenson at panix.com
Tue Mar 9 10:51:15 UTC 2010
In working on the PROGV problems, I can't understand why the following simple case works with JVM.
For the forms (attached in progv.lisp):
(defvar *a* "initial")
(defun foo ()
(progv '(*a*) '((symbol-value '*a*))
(setf *a* "foo")
(return-from foo 42)))
You get the following JVM code:
0: invokestatic #27; //Method org/armedbear/lisp/LispThread.currentThread:()Lorg/armedbear/lisp/LispThread;
3: astore_1
4: getstatic #31; //Field OBJSTR106:Lorg/armedbear/lisp/LispObject;
7: getstatic #33; //Field OBJSTR107:Lorg/armedbear/lisp/LispObject;
10: aload_1
11: invokevirtual #37; //Method org/armedbear/lisp/LispThread.markSpecialBindings:()Lorg/armedbear/lisp/SpecialBindingsMark;
14: astore_2
15: aload_1
16: invokestatic #43; //Method org/armedbear/lisp/Lisp.progvBindVars:(Lorg/armedbear/lisp/LispObject;Lorg/armedbear/lisp/LispObject;Lorg/armedbear/lisp/LispThread;)V
19: aload_1
20: getstatic #45; //Field SYM108_A:Lorg/armedbear/lisp/Symbol;
23: getstatic #47; //Field STR109:Lorg/armedbear/lisp/SimpleString;
26: invokevirtual #51; //Method org/armedbear/lisp/LispThread.setSpecialVariable:(Lorg/armedbear/lisp/Symbol;Lorg/armedbear/lisp/LispObject;)Lorg/armedbear/lisp/LispObject;
29: pop
30: getstatic #53; //Field FIXNUM_42:Lorg/armedbear/lisp/LispInteger;
33: areturn
34: aload_1
35: aload_2
36: invokevirtual #57; //Method org/armedbear/lisp/LispThread.resetSpecialBindings:(Lorg/armedbear/lisp/SpecialBindingsMark;)V
39: athrow
40: aload_1
41: aload_2
42: invokevirtual #57; //Method org/armedbear/lisp/LispThread.resetSpecialBindings:(Lorg/armedbear/lisp/SpecialBindingsMark;)V
45: areturn
What I don't understand is how the *A* binding is restored at all. But ABCL executes this code correctly, restoring *A* to the string "initial" after an execution of FOO. But as you see in the code, the SETF is executed in line 26, then the return value is discarded via pop, then the return value is put on the stack in line 30, and then the method returns via ARETURN. None of the exception handlers which invoke resetSpecialBindings at the end of the the code (lines 34-39, 40-45) are executed at all. So how does the special variable get reset? Is there something happening in the autoloaded that intercepts with a proxy that resets things?
Searching for a reasonable JVM debugger that doesn't assume you are compiling from Java doesn't seem to turn up much. Does anyone have a trick for following the JVM executing such code?
Very confused,
Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: progv.lisp
Type: application/octet-stream
Size: 126 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20100309/25001971/attachment.obj>
-------------- next part --------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: progv-1.javap
Type: application/octet-stream
Size: 9676 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20100309/25001971/attachment-0001.obj>
-------------- next part --------------
--
"A screaming comes across the sky. It has happened before, but there is nothing to compare to it now."
More information about the armedbear-devel
mailing list