Skip to content

Fix reflective toolbox producing invalid bytecode #44

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

Merged
merged 1 commit into from
Dec 8, 2011

Conversation

xeno-by
Copy link
Contributor

@xeno-by xeno-by commented Dec 7, 2011

Wrapper method for AST undergoing a reflective compilation
has been incorrectly marked as static.

This was off the radars until one day the code being compiled declared
a top-level method. During flatten that method got hoisted into the
wrapper module, and its invocation got translated into an instance
call upon the module. This led to static wrapper method trying to call
an instance method, and that blew up the bytecode verifier. More info:
https://issues.scala-lang.org/browse/SI-5266.

Fixes SI-5266, review by @odersky.

Wrapper method for AST undergoing a reflective compilation
has been incorrectly marked as static.

This was off the radars until one day the code being compiled declared
a top-level method. During flatten that method got hoisted into the
wrapper module, and its invocation got translated into an instance
call upon the module. This led to static wrapper method trying to call
an instance method, and that blew up the bytecode verifier. More info:
https://issues.scala-lang.org/browse/SI-5266.

Fixes SI-5266, review by @odersky.
@paulp paulp merged commit a6152b4 into scala:master Dec 8, 2011
gkossakowski added a commit to gkossakowski/scala that referenced this pull request Jan 11, 2012
Merge latest changes from trunk
densh pushed a commit to densh/scala that referenced this pull request May 5, 2013
lrytz added a commit to lrytz/scala that referenced this pull request Jun 22, 2015
used revision:
scala/scala-java8-compat@9253ed9e7a

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
lrytz added a commit to lrytz/scala that referenced this pull request Jun 23, 2015
used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
lrytz added a commit to lrytz/scala that referenced this pull request Jun 23, 2015
used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
lrytz added a commit to lrytz/scala that referenced this pull request Jun 23, 2015
used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
lrytz added a commit to lrytz/scala that referenced this pull request Jun 23, 2015
including LambdaDeserializer

used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
retronym referenced this pull request in retronym/scala Jun 25, 2015
And also embed LambdaDeserializer

used revision:

   scala/scala-java8-compat@9253ed9

demo:

```
% ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic #44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     #46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  #34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
```
lrytz added a commit to lrytz/scala that referenced this pull request Jun 30, 2015
including LambdaDeserializer

used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
lrytz added a commit to lrytz/scala that referenced this pull request Jun 30, 2015
including LambdaDeserializer

used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
lrytz added a commit to lrytz/scala that referenced this pull request Jun 30, 2015
including LambdaDeserializer

used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
lrytz added a commit to lrytz/scala that referenced this pull request Jun 30, 2015
including LambdaDeserializer

used revision:
scala/scala-java8-compat@9253ed9

demo:

ant -Dlocker.skip=1
build/quick/bin/scala -Ydelambdafy:method -Ybackend:GenBCode -Yopt:closure-elimination -target:jvm-1.8
scala> class C { def f = {val f: Int => Int = x => x + 1; f(10) } }
scala> :javap C
  public int f();
         0: invokedynamic scala#44,  0             // InvokeDynamic #0:apply$mcII$sp:()Lscala/compat/java8/JFunction1$mcII$sp;
         5: checkcast     scala#46                 // class scala/Function1
         8: astore_1
         9: aload_1
        10: bipush        10
        12: istore_2
        13: pop
        14: iload_2
        15: invokestatic  scala#34                 // Method $line3$$read$C$$$anonfun$1:(I)I
        18: ireturn
da-liii pushed a commit to da-liii/scala that referenced this pull request Nov 11, 2018
Alkimia frameworks branch was merged into master
bishabosha added a commit to bishabosha/scala that referenced this pull request Feb 20, 2020
Add `@compileTimeOnly` annotation to unpickled inline def definitions
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.

2 participants