Skip to content

[TRIAL] Implement the invokeinterface operation, And fix the invokedynamic operation#130

Merged
m3m0r7 merged 7 commits intomasterfrom
implement-invokeinterface
May 6, 2019
Merged

[TRIAL] Implement the invokeinterface operation, And fix the invokedynamic operation#130
m3m0r7 merged 7 commits intomasterfrom
implement-invokeinterface

Conversation

@m3m0r7
Copy link
Copy Markdown
Member

@m3m0r7 m3m0r7 commented May 6, 2019

In my Java file:

class Test
{
    interface InterfaceTest
    {
        public String method(String name);
    }

    public static void main(String[] args)
    {
        InterfaceTest it = v -> { return "Hello" + v; };
        System.out.println(it.method(" World!"));
    }
}

@m3m0r7 m3m0r7 changed the title Implement the invokeinterface operation, And fix the invokedynamic operation Implement the invokeinterface operation, And fix the invokedynamic operation May 6, 2019
@m3m0r7 m3m0r7 changed the title Implement the invokeinterface operation, And fix the invokedynamic operation Implement the invokeinterface operation, And fix the invokedynamic operation May 6, 2019
@m3m0r7 m3m0r7 changed the title Implement the invokeinterface operation, And fix the invokedynamic operation Implement the invokeinterface operation, And fix the invokedynamic operation May 6, 2019
@m3m0r7 m3m0r7 changed the title Implement the invokeinterface operation, And fix the invokedynamic operation [TRIAL] Implement the invokeinterface operation, And fix the invokedynamic operation May 6, 2019
@m3m0r7
Copy link
Copy Markdown
Member Author

m3m0r7 commented May 6, 2019

In javap outputs:

  Test();
    descriptor: ()V
    flags: (0x0000)
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 1: 0

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=3, locals=2, args_size=1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         0: invokedynamic #2,  0              // InvokeDynamic #0:method:()LTest$InterfaceTest;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         5: astore_1
         6: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;
         9: aload_1
        10: ldc           #4                  // String World!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        12: invokeinterface #5,  2            // InterfaceMethod Test$InterfaceTest.method:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Ljava/lang/String;)Ljava/lang/String;
        17: invokevirtual #6                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
        20: return
      LineNumberTable:
        line 11: 0
        line 12: 6
        line 26: 20

  private static java.lang.String lambda$main$0(java.lang.String);
    descriptor: (Ljava/lang/String;)Ljava/lang/String;
    flags: (0x100a) ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1: invokedynamic #7,  0              // InvokeDynamic #1:makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         6: areturn
      LineNumberTable:
        line 11: 0
}
SourceFile: "Test.java"
NestMembers:
  Test$InterfaceTest
InnerClasses:
  static #11= #10 of #8;                  // InterfaceTest=class Test$InterfaceTest of class Test
  public static final #63= #62 of #67;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
BootstrapMethods:
  0: #26 REF_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:
      #27 (Ljava/lang/String;)Ljava/lang/String;
      #28 REF_invokeStatic Test.lambda$main$0:(Ljava/lang/String;)Ljava/lang/String;
      #27 (Ljava/lang/String;)Ljava/lang/String;
  1: #36 REF_invokeStatic java/lang/invoke/StringConcatFactory.makeConcatWithConstants:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
    Method arguments:
      #37 Hello\u0001

@m3m0r7
Copy link
Copy Markdown
Member Author

m3m0r7 commented May 6, 2019

In PHPJava outputs:

[2019-05-06 03:35:47] Test.INFO: Start class emulation  
[2019-05-06 03:35:47] Test.INFO: Minor version: 0  
[2019-05-06 03:35:47] Test.INFO: Major version: 55  
[2019-05-06 03:35:47] Test.INFO: JDK version: 11  
[2019-05-06 03:35:47] Test.INFO: Constant Pools: 69  
[2019-05-06 03:35:47] Test.INFO: Extracted interfaces: 0  
[2019-05-06 03:35:47] Test.INFO: Extracted fields: 0  
[2019-05-06 03:35:47] Test.DEBUG: Load an attribute: Code  
[2019-05-06 03:35:47] Test.DEBUG: Skip to load an attribute: LineNumberTable  
[2019-05-06 03:35:47] Test.DEBUG: Load an attribute: Code  
[2019-05-06 03:35:47] Test.DEBUG: Skip to load an attribute: LineNumberTable  
[2019-05-06 03:35:47] Test.DEBUG: Load an attribute: Code  
[2019-05-06 03:35:47] Test.DEBUG: Skip to load an attribute: LineNumberTable  
[2019-05-06 03:35:47] Test.INFO: Extracted methods: 3  
[2019-05-06 03:35:47] Test.DEBUG: Load an attribute: SourceFile  
[2019-05-06 03:35:47] Test.DEBUG: Skip to load an attribute: NestMembers  
[2019-05-06 03:35:47] Test.DEBUG: Load an attribute: InnerClasses  
[2019-05-06 03:35:47] Test.DEBUG: Load an attribute: BootstrapMethods  
[2019-05-06 03:35:47] Test.INFO: Extracted attributes: 4  
[2019-05-06 03:35:47] Test.INFO: End of Class  
[2019-05-06 03:35:47] Test.DEBUG: Call method: main  
[2019-05-06 03:35:47] Test.DEBUG: Passed descriptor is [Ljava.lang.String;  
[2019-05-06 03:35:47] Test.DEBUG: Find descriptor for [Ljava.lang.String;  
[2019-05-06 03:35:47] Test.INFO: Start operations: public static void main(java.lang.String[])  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0xBA invokedynamic   Stacks: 0    PC: 0        Used Memory: 2.12MB   Used Memory Peak: 2.19MB    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Start class emulation  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Minor version: 0  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Major version: 55  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: JDK version: 11  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Constant Pools: 13  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Extracted interfaces: 0  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Extracted fields: 0  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Extracted methods: 1  
[2019-05-06 03:35:47] Test$InterfaceTest.DEBUG: Load an attribute: SourceFile  
[2019-05-06 03:35:47] Test$InterfaceTest.DEBUG: Skip to load an attribute: NestHost  
[2019-05-06 03:35:47] Test$InterfaceTest.DEBUG: Load an attribute: InnerClasses  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Extracted attributes: 3  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: End of Class  
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0x4C astore1         Stacks: 1    PC: 5        Used Memory: 2.95MB   Used Memory Peak: 2.97MB    
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0xB2 getstatic       Stacks: 0    PC: 6        Used Memory: 2.95MB   Used Memory Peak: 2.99MB    
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0x2B aload1          Stacks: 1    PC: 9        Used Memory: 2.97MB   Used Memory Peak: 3.02MB    
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0x12 ldc             Stacks: 2    PC: 10       Used Memory: 2.98MB   Used Memory Peak: 3.02MB    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0xB9 invokeinterface Stacks: 3    PC: 12       Used Memory: 2.99MB   Used Memory Peak: 3.02MB    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2019-05-06 03:35:47] Test.DEBUG: Call method: lambda$main$0  
[2019-05-06 03:35:47] Test.DEBUG: Passed descriptor is LPHPJava.Packages.java.lang.String;  
[2019-05-06 03:35:47] Test.DEBUG: Find descriptor for Ljava.lang.String;  
[2019-05-06 03:35:47] Test.INFO: Start operations: private static synthetic java.lang.String lambda$main$0(java.lang.String)  
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0x2A aload0          Stacks: 0    PC: 0        Used Memory: 3.01MB   Used Memory Peak: 3.04MB    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0xBA invokedynamic   Stacks: 1    PC: 1        Used Memory: 3.01MB   Used Memory Peak: 3.05MB    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0xB0 areturn         Stacks: 1    PC: 6        Used Memory: 3.05MB   Used Memory Peak: 3.08MB    
[2019-05-06 03:35:47] Test.INFO: Finish operations: private static synthetic java.lang.String lambda$main$0(java.lang.String)  
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0xB6 invokevirtual   Stacks: 2    PC: 17       Used Memory: 3.04MB   Used Memory Peak: 3.09MB    
Hello World!
[2019-05-06 03:35:47] Test.DEBUG: OpCode: 0xB1 return          Stacks: 0    PC: 20       Used Memory: 3.13MB   Used Memory Peak: 3.15MB    
[2019-05-06 03:35:47] Test.INFO: Finish operations: public static void main(java.lang.String[])  
[2019-05-06 03:35:47] Test.INFO: Spent time: 0.080152034759521 sec.  
[2019-05-06 03:35:47] Test$InterfaceTest.INFO: Spent time: 0.01467490196228 sec. 

@m3m0r7 m3m0r7 merged commit 89d2609 into master May 6, 2019
@m3m0r7 m3m0r7 deleted the implement-invokeinterface branch May 6, 2019 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant