StackMapTable Notizen

This commit is contained in:
JanUlrich 2016-01-12 13:32:16 +01:00
parent ab7f56db6f
commit b069bb7b8f
7 changed files with 44 additions and 104 deletions

View File

@ -35,3 +35,9 @@
# TODO:
* Matrix Beispiel muss funktionieren (verschachtelter Lambda Ausdruck)
* Automatisch Bytecode generieren, wenn alle Typen eingesetzt sind
## StackMapTable
* Attribute für Codeattribut
* Wird für Sprünge im Bytecode benötigt
* Quelle: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.4

View File

@ -1,104 +0,0 @@
Classfile /home/janulrich/Development/eclipseworkspace/JavaCompilerCore/notizen/stan/lambdaBytecode/Lambda1.class
Last modified 20.08.2015; size 903 bytes
MD5 checksum acb53c553588f3c919f2b0e6359bbd94
class Lambda1
InnerClasses:
public static final #46= #45 of #49; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
BootstrapMethods:
0: #18 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#19 ()V
#20 invokestatic Lambda1.lambda$methode$0:()V
#19 ()V
minor version: 0
major version: 52
flags: ACC_SUPER
Constant pool:
#1 = Methodref #8.#16 // java/lang/Object."<init>":()V
#2 = InvokeDynamic #0:#21 // #0:run:()Ljava/lang/Runnable;
#3 = Methodref #7.#22 // Lambda1.methode:()Ljava/lang/Runnable;
#4 = InterfaceMethodref #23.#24 // java/lang/Runnable.run:()V
#5 = Fieldref #25.#26 // java/lang/System.out:Ljava/io/PrintStream;
#6 = Methodref #27.#28 // java/io/PrintStream.println:()V
#7 = Class #29 // Lambda1
#8 = Class #30 // java/lang/Object
#9 = Utf8 <init>
#10 = Utf8 ()V
#11 = Utf8 Code
#12 = Utf8 methode
#13 = Utf8 ()Ljava/lang/Runnable;
#14 = Utf8 methode2
#15 = Utf8 lambda$methode$0
#16 = NameAndType #9:#10 // "<init>":()V
#17 = Utf8 BootstrapMethods
#18 = MethodHandle #6:#31 // invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#19 = MethodType #10 // ()V
#20 = MethodHandle #6:#32 // invokestatic Lambda1.lambda$methode$0:()V
#21 = NameAndType #33:#13 // run:()Ljava/lang/Runnable;
#22 = NameAndType #12:#13 // methode:()Ljava/lang/Runnable;
#23 = Class #34 // java/lang/Runnable
#24 = NameAndType #33:#10 // run:()V
#25 = Class #35 // java/lang/System
#26 = NameAndType #36:#37 // out:Ljava/io/PrintStream;
#27 = Class #38 // java/io/PrintStream
#28 = NameAndType #39:#10 // println:()V
#29 = Utf8 Lambda1
#30 = Utf8 java/lang/Object
#31 = Methodref #40.#41 // java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#32 = Methodref #7.#42 // Lambda1.lambda$methode$0:()V
#33 = Utf8 run
#34 = Utf8 java/lang/Runnable
#35 = Utf8 java/lang/System
#36 = Utf8 out
#37 = Utf8 Ljava/io/PrintStream;
#38 = Utf8 java/io/PrintStream
#39 = Utf8 println
#40 = Class #43 // java/lang/invoke/LambdaMetafactory
#41 = NameAndType #44:#48 // metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#42 = NameAndType #15:#10 // lambda$methode$0:()V
#43 = Utf8 java/lang/invoke/LambdaMetafactory
#44 = Utf8 metafactory
#45 = Class #50 // java/lang/invoke/MethodHandles$Lookup
#46 = Utf8 Lookup
#47 = Utf8 InnerClasses
#48 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#49 = Class #51 // java/lang/invoke/MethodHandles
#50 = Utf8 java/lang/invoke/MethodHandles$Lookup
#51 = Utf8 java/lang/invoke/MethodHandles
{
Lambda1();
Signature: ()V
flags:
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
java.lang.Runnable methode();
Signature: ()Ljava/lang/Runnable;
flags:
Code:
stack=1, locals=1, args_size=1
0: invokedynamic #2, 0 // InvokeDynamic #0:run:()Ljava/lang/Runnable;
5: areturn
void methode2();
Signature: ()V
flags:
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokevirtual #3 // Method methode:()Ljava/lang/Runnable;
4: invokeinterface #4, 1 // InterfaceMethod java/lang/Runnable.run:()V
9: return
private static void lambda$methode$0();
Signature: ()V
flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC
Code:
stack=1, locals=0, args_size=0
0: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
3: invokevirtual #6 // Method java/io/PrintStream.println:()V
6: return
}

Binary file not shown.

View File

@ -0,0 +1,10 @@
# StackMapTable
* Attribute für Codeattribut
* Wird für Sprünge im Bytecode benötigt
* Quelle: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.4
## Generierung
* StackMapTable könnte generiert werden, indem im bytecode geschaut wird, wo Sprünge vorliegen.
* https://stackoverflow.com/questions/24927993/what-kind-of-java-code-requires-stackmap-frames#24930521
* It is illegal to have code after an unconditional branch without a stack map frame being provided for it.

View File

@ -0,0 +1,6 @@
class StackMapTest{
void methode(){
while(true){}
}
}

View File

@ -0,0 +1,8 @@
class StackMapTest2{
void methode(){
Integer i = 1;
while(System.out == null){
i+=1;}
}
}

View File

@ -0,0 +1,14 @@
class StackMapTest3{
void methode(){
Integer i = 1;
while(System.out == null){
i+=1;
}
System.out.println(i);
StackMapTest3 o = new StackMapTest3();
while(i<0){
i++;
}
}
}