Lab3: if evaluating all statements

44 views
Skip to first unread message

Niklas Logren

unread,
Mar 11, 2014, 8:50:25 AM3/11/14
to proglang-c...@googlegroups.com
Hi!
I'm having some trouble with jasmin. It seems to not jump when I want it to.
I have an if block that contains invalid code, but I expect the Java interpreter to jump past this block.

See this JVM code:

.class public Foo
.super java/lang/Object

.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method

.method public static main([Ljava/lang/String;)V
.limit locals 100
.limit stack 1000
iconst_0
ifeq L1 -- this should always branch?
iload 0 -- this results in runtime error
invokestatic Runtime/printInt(I)V
goto L0
L1:
bipush 42
invokestatic Runtime/printInt(I)V
L0:
return
.end method


When I compile it using Jasmin and run "java Foo", it complains that "Register 0 contains wrong type" because of "iload 0".
But shouldn't "ifeq L1" unconditionally jump? That is, shouldn't the above program work correctly?

Thanks in advance,
Niklas

Aarne Ranta

unread,
Mar 11, 2014, 8:53:15 AM3/11/14
to proglang-c...@googlegroups.com
The first argument of main is an array of strings, and not an integer, which make iload 0 invalid.

  Aarne.

dhausknecht

unread,
Mar 11, 2014, 8:58:57 AM3/11/14
to proglang-c...@googlegroups.com
the problem is a runtime byte code verification. That's also why good15 complains with 'j' which is not initialised (though it is of the correct type). To disable the verification use the -noverify flag. However, do so only when you're 100% sure what you're doing!

Niklas Logren

unread,
Mar 11, 2014, 9:02:57 AM3/11/14
to proglang-c...@googlegroups.com
Oh, so we are allowed to run test case good15.cc with -noverify? Awesome!

Also, thanks Aarne, that's a separate issue we hadn't discovered yet. :-)
Reply all
Reply to author
Forward
0 new messages