Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LambdaMetafactory related issues #470

Closed
DarkDimius opened this issue Apr 10, 2015 · 4 comments
Closed

LambdaMetafactory related issues #470

DarkDimius opened this issue Apr 10, 2015 · 4 comments

Comments

@DarkDimius
Copy link
Contributor

object O {
  val x: String => String = a => a
  def main(args: Array[String]): Unit = {
  }
}

Current status: on 802a93b, after fixing invocation type I get

Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
    at java.lang.invoke.CallSite.makeSite(CallSite.java:328)
    at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:296)
    at O$.<init>(A.scala:1)
    at O$.<clinit>(A.scala)
    at O.main(A.scala)
Caused by: java.lang.invoke.LambdaConversionException: Incorrect number of parameters for instance method invokeSpecial O$.$anonfun$$init$$1:(String)String; 0 captured parameters, 1 functional interface method parameters, 1 implementation parameters
    at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:193)
    at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
    at java.lang.invoke.CallSite.makeSite(CallSite.java:289)
    ... 4 more
dark@reco /tmp/t $ javap -p -s -l -verbose O$
Classfile /private/tmp/t/O$.class
  Last modified Apr 10, 2015; size 1188 bytes
  MD5 checksum bb135abd9c605d63ae7638fd35278f89
  Compiled from "A.scala"
public final class O$
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER
Constant pool:
   #1 = Utf8               O$
   #2 = Class              #1             // O$
   #3 = Utf8               java/lang/Object
   #4 = Class              #3             // java/lang/Object
   #5 = Utf8               A.scala
   #6 = Utf8               MODULE$
   #7 = Utf8               LO$;
   #8 = Utf8               x$$local
   #9 = Utf8               Lscala/Function1;
  #10 = Utf8               <clinit>
  #11 = Utf8               ()V
  #12 = Utf8               <init>
  #13 = NameAndType        #12:#11        // "<init>":()V
  #14 = Methodref          #2.#13         // O$."<init>":()V
  #15 = Methodref          #4.#13         // java/lang/Object."<init>":()V
  #16 = NameAndType        #6:#7          // MODULE$:LO$;
  #17 = Fieldref           #2.#16         // O$.MODULE$:LO$;
  #18 = Utf8               java/lang/invoke/LambdaMetafactory
  #19 = Class              #18            // java/lang/invoke/LambdaMetafactory
  #20 = Utf8               metafactory
  #21 = 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;
  #22 = NameAndType        #20:#21        // 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;
  #23 = Methodref          #19.#22        // 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;
  #24 = MethodHandle       #6:#23         // 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;
  #25 = Utf8               (Ljava/lang/Object;)Ljava/lang/Object;
  #26 = MethodType         #25            //  (Ljava/lang/Object;)Ljava/lang/Object;
  #27 = Utf8               $anonfun$$init$$1
  #28 = Utf8               (Ljava/lang/String;)Ljava/lang/String;
  #29 = NameAndType        #27:#28        // $anonfun$$init$$1:(Ljava/lang/String;)Ljava/lang/String;
  #30 = Methodref          #2.#29         // O$.$anonfun$$init$$1:(Ljava/lang/String;)Ljava/lang/String;
  #31 = MethodHandle       #7:#30         // invokespecial O$.$anonfun$$init$$1:(Ljava/lang/String;)Ljava/lang/String;
  #32 = MethodType         #28            //  (Ljava/lang/String;)Ljava/lang/String;
  #33 = Utf8               apply
  #34 = Utf8               ()Lscala/compat/java8/JFunction1;
  #35 = NameAndType        #33:#34        // apply:()Lscala/compat/java8/JFunction1;
  #36 = InvokeDynamic      #0:#35         // #0:apply:()Lscala/compat/java8/JFunction1;
  #37 = Utf8               this
  #38 = Utf8               x
  #39 = Utf8               ()Lscala/Function1;
  #40 = NameAndType        #8:#9          // x$$local:Lscala/Function1;
  #41 = Fieldref           #2.#40         // O$.x$$local:Lscala/Function1;
  #42 = Utf8               main
  #43 = Utf8               ([Ljava/lang/String;)V
  #44 = Utf8               args
  #45 = Utf8               [Ljava/lang/String;
  #46 = Utf8               a
  #47 = Utf8               Ljava/lang/String;
  #48 = Utf8               Code
  #49 = Utf8               LocalVariableTable
  #50 = Utf8               LineNumberTable
  #51 = Utf8               BootstrapMethods
  #52 = Utf8               SourceFile
  #53 = Utf8               ScalaSig
{
  public static final O$ MODULE$;
    descriptor: LO$;
    flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL

  private final scala.Function1 x$$local;
    descriptor: Lscala/Function1;
    flags: ACC_PRIVATE, ACC_FINAL

  public static {};
    descriptor: ()V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=0, args_size=0
         0: new           #2                  // class O$
         3: invokespecial #14                 // Method "<init>":()V
         6: return

  public O$();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=2, args_size=1
         0: aload_0
         1: invokespecial #15                 // Method java/lang/Object."<init>":()V
         4: aload_0
         5: putstatic     #17                 // Field MODULE$:LO$;
         8: invokedynamic #36,  0             // InvokeDynamic #0:apply:()Lscala/compat/java8/JFunction1;
        13: astore_1
        14: return
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      15     0  this   LO$;
      LineNumberTable:
        line 0: 0
        line 1: 8
        line 0: 14

  public scala.Function1 x();
    descriptor: ()Lscala/Function1;
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #41                 // Field x$$local:Lscala/Function1;
         4: areturn
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LO$;
      LineNumberTable:
        line 1: 0

  public void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC
    Code:
      stack=0, locals=2, args_size=2
         0: return
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       1     0  this   LO$;
            0       1     1  args   [Ljava/lang/String;
      LineNumberTable:
        line 2: 0

  private java.lang.String $anonfun$$init$$1(java.lang.String);
    descriptor: (Ljava/lang/String;)Ljava/lang/String;
    flags: ACC_PRIVATE
    Code:
      stack=1, locals=2, args_size=2
         0: aload_1
         1: areturn
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       2     0  this   LO$;
            0       2     1     a   Ljava/lang/String;
      LineNumberTable:
        line 1: 0
}
BootstrapMethods:
  0: #24 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:
      #26 (Ljava/lang/Object;)Ljava/lang/Object;
      #31 invokespecial O$.$anonfun$$init$$1:(Ljava/lang/String;)Ljava/lang/String;
      #32 (Ljava/lang/String;)Ljava/lang/String;
SourceFile: "A.scala"
Error: unknown attribute
  ScalaSig: length = 0x0
@DarkDimius DarkDimius self-assigned this Apr 10, 2015
@smarter
Copy link
Member

smarter commented Apr 10, 2015

It seems that the problem is that $anonfun$$init$$1 is not static.

@DarkDimius
Copy link
Contributor Author

Currently it shouldn't be static, as 'this' pointer is not added to closure
environment by lambdalift.

But making it static could be beneficial in terms of memory footprint.

On 10 April 2015 14:59:36 Guillaume Martres notifications@github.com wrote:

It seems that the problem is that $anonfun$$init$$1 is not static.


Reply to this email directly or view it on GitHub:
#470 (comment)

@DarkDimius
Copy link
Contributor Author

Invokespecial is used correctly here, as method is private.

I didn't yet had a look at this issue. Ill do it next week.

On 10 April 2015 14:59:36 Guillaume Martres notifications@github.com wrote:

It seems that the problem is that $anonfun$$init$$1 is not static.


Reply to this email directly or view it on GitHub:
#470 (comment)

@DarkDimius
Copy link
Contributor Author

Fixed in lampepfl/scala@09c4a52

DarkDimius added a commit to dotty-staging/dotty that referenced this issue Apr 16, 2015
This update allows to have non-static lambdas.
It doesn't mean that we should emit such,
as they are potential memory leak. See scala#480
Fixes scala#470
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Apr 16, 2015
This update allows to have non-static lambdas.
It doesn't mean that we should emit such,
as they are potential memory leak. See scala#480
Fixes scala#470
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants