groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: About the native-lambda branch
Date Sat, 13 Jan 2018 12:45:55 GMT

this looks quite promising

On 13.01.2018 12:24, Daniel Sun wrote:
> Hi Jochen,
> 
>       Here is an example:
> 
> ```
> import java.util.stream.Collectors;
> import java.util.stream.Stream;
> 
> public class Test1 {
>      public static void main(String[] args) {
>          p();
>      }
> 
>      public static void p() {
>           Stream.of(1, 2, 3).map(e -> e + 1).collect(Collectors.toList());
>      }
> }
> ```
> 
> Its bytecode is shown as follows, note `  public final static INNERCLASS
> java/lang/invoke/MethodHandles$Lookup java/lang/invoke/MethodHandles
> Lookup`, which I found is useless, so I removed it and all code works still
> well.
> 
> ```
> // class version 52.0 (52)
> // access flags 0x21
> public class Test1 {
> 
>    // compiled from: Test1.java
>    // access flags 0x19
>    public final static INNERCLASS java/lang/invoke/MethodHandles$Lookup
> java/lang/invoke/MethodHandles Lookup
> 
>    // access flags 0x1
>    public <init>()V
>     L0
>      LINENUMBER 4 L0
>      ALOAD 0
>      INVOKESPECIAL java/lang/Object.<init> ()V
>      RETURN
>      MAXSTACK = 1
>      MAXLOCALS = 1
> 
>    // access flags 0x9
>    public static main([Ljava/lang/String;)V
>     L0
>      LINENUMBER 6 L0
>      INVOKESTATIC Test1.p ()V
>     L1
>      LINENUMBER 7 L1
>      RETURN
>      MAXSTACK = 0
>      MAXLOCALS = 1
> 
>    // access flags 0x9
>    public static p()V
>     L0
>      LINENUMBER 10 L0
>      ICONST_3
>      ANEWARRAY java/lang/Integer
>      DUP
>      ICONST_0
>      ICONST_1
>      INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
>      AASTORE
>      DUP
>      ICONST_1
>      ICONST_2
>      INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
>      AASTORE
>      DUP
>      ICONST_2
>      ICONST_3
>      INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
>      AASTORE
>      INVOKESTATIC java/util/stream/Stream.of
> ([Ljava/lang/Object;)Ljava/util/stream/Stream;
>      INVOKEDYNAMIC apply()Ljava/util/function/Function; [
>        // handle kind 0x6 : 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;
>        // arguments:
>        (Ljava/lang/Object;)Ljava/lang/Object;,
>        // handle kind 0x6 : INVOKESTATIC
>        Test1.lambda$p$0(Ljava/lang/Integer;)Ljava/lang/Integer;,
>        (Ljava/lang/Integer;)Ljava/lang/Integer;
>      ]
>      INVOKEINTERFACE java/util/stream/Stream.map
> (Ljava/util/function/Function;)Ljava/util/stream/Stream;
>      INVOKESTATIC java/util/stream/Collectors.toList
> ()Ljava/util/stream/Collector;
>      INVOKEINTERFACE java/util/stream/Stream.collect
> (Ljava/util/stream/Collector;)Ljava/lang/Object;
>      POP
>     L1
>      LINENUMBER 11 L1
>      RETURN
>      MAXSTACK = 4
>      MAXLOCALS = 0
> 
>    // access flags 0x100A
>    private static synthetic
> lambda$p$0(Ljava/lang/Integer;)Ljava/lang/Integer;
>     L0
>      LINENUMBER 10 L0
>      ALOAD 0
>      INVOKEVIRTUAL java/lang/Integer.intValue ()I
>      ICONST_1
>      IADD
>      INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
>      ARETURN
>      MAXSTACK = 2
>      MAXLOCALS = 1
> }
> 
> ```
> 
> Cheers,
> Daniel.Sun
> 
> 
> 
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
> 


Mime
View raw message