[armedbear-devel] Understanding JVM code

Alessio Stalla alessiostalla at gmail.com
Tue Mar 9 10:56:48 UTC 2010


On Tue, Mar 9, 2010 at 11:51 AM, Mark Evenson <evenson at panix.com> wrote:
> 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?

Are you sure those are both exception handlers, and there's not a
finally block instead? I don't know how those constructs translate to
bytecode, but if I had to implement special variables in Java, I would
use try-finally to restore them.

Alessio

> 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
>
>
>
>
>
> --
> "A screaming comes across the sky.  It has happened before, but there is nothing to compare to it now."
>
>
>
>
>
> _______________________________________________
> armedbear-devel mailing list
> armedbear-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
>
>




More information about the armedbear-devel mailing list