jasmin

JVM, the constant pool, the heap and the addresses

巧了我就是萌 提交于 2020-01-06 14:38:13
问题 If I create a new item in Jasmin assembly and then store it, I do it with the instruction aload, since it's an address: new Object dup invokespecial..... astore_3 ; load the object reference into local variable 3 Now, if I want to save a string from the constant pool... I would create it with ldc and then save it with aload as well: ldc "Great string" astore_3 ; save the reference to the actual string in the constant pool Now... are these addresses on the same form and the same number of

JVM instruction ALOAD_0 in the 'main' method points to 'args' instead of 'this'?

微笑、不失礼 提交于 2019-12-20 17:25:46
问题 I am trying to implement a subset of Java for an academic study. Well, I'm in the last stages (code generation) and I wrote a rather simple program to see how method arguments are handled: class Main { public static void main(String[] args) { System.out.println(args.length); } } Then I built it, and ran 'Main.class' through an online disassembler I found at: http://www.cs.cornell.edu/People/egs/kimera/disassembler.html I get the following implementation for the 'main' method: (the

JVM instruction ALOAD_0 in the 'main' method points to 'args' instead of 'this'?

一个人想着一个人 提交于 2019-12-20 17:25:12
问题 I am trying to implement a subset of Java for an academic study. Well, I'm in the last stages (code generation) and I wrote a rather simple program to see how method arguments are handled: class Main { public static void main(String[] args) { System.out.println(args.length); } } Then I built it, and ran 'Main.class' through an online disassembler I found at: http://www.cs.cornell.edu/People/egs/kimera/disassembler.html I get the following implementation for the 'main' method: (the

Howto use invokedynamic with Jasmin?

霸气de小男生 提交于 2019-12-19 11:29:18
问题 Here it says: Since 2.1 : [..] added the invokedynamic instruction Thus I suppose that it is possible to write instruction code containing invokedynamics with jasmin. However I could not find any documentation on the jasmin syntax and I just figured out how to use invokedynamic to get VerifyErrors with Jasmin, but not how to create a working example. How is this instruction correctly used in Jasmin? 回答1: Each invokedynamic bytecode should refer to a corresponding call site specifier (JVMS 6.5

Jasmin invoke a method using arguments

孤街浪徒 提交于 2019-12-13 08:01:27
问题 I'm writing a compiler that generates Jasmin code and I want to invoke a method using an argument, as follows: val test(val x) { return x; } val main (string[] args) { test(1); } This compiles to: .class public helloworld .super java/lang/Object .method public <init>()V aload_0 invokenonvirtual java/lang/Object/<init>()V return .end method .method public test(I)I .limit stack 4 .limit locals 3 iload 1 ireturn .end method .method public static main([Ljava/lang/String;)V .limit stack 4 .limit

Difference between JVM's LookupSwitch and TableSwitch?

梦想与她 提交于 2019-11-26 23:55:56
I have some difficulty to understand LookUpSwitch and TableSwitch in Java bytecode. If I understand well, both LookUpSwitch and TableSwitch correspond to the switch statement of Java source? Why one JAVA statement generates 2 different bytecodes? Jasmin documentation of each: LookupSwitch tableswitch The difference is that a lookupswitch uses a table with keys and labels , yet a tableswitch uses a table with labels only . When performing a tableswitch , the int value on top of stack is directly used as an index into the table to grab the jump destination and perform the jump immediately. The

Difference between JVM&#39;s LookupSwitch and TableSwitch?

假装没事ソ 提交于 2019-11-26 07:18:05
问题 I have some difficulty to understand LookUpSwitch and TableSwitch in Java bytecode. If I understand well, both LookUpSwitch and TableSwitch correspond to the switch statement of Java source? Why one JAVA statement generates 2 different bytecodes? Jasmin documentation of each: LookupSwitch tableswitch 回答1: The difference is that lookupswitch uses a table with keys and labels tableswitch uses a table with labels only . When performing a tableswitch , the int value on top of stack is directly