Commit 3ca962c
committed
Make all lambda impl methods static
Motivation:
- Avoid introducing public virtual methods. (javac uses private methods,
but we prefer to make the public to support important AOT inlining
use cases)
- No more need for unsightly expanded names in lambda stack traces!
- CHA in on HotSpot is great at devirtualizing, but that doesn't mean
we *should* emit non-virtual methods as virtual so pervasively.
```
// Entering paste mode (ctrl-D to finish)
package com.acme.wizzle.wozzle; class C { def foo = () => ??? }
// Exiting paste mode, now interpreting.
scala> new com.acme.wizzle.wozzle.C().foo
res0: () => Nothing = com.acme.wizzle.wozzle.C$$Lambda$1986/43856716@100f9bbe
scala> new com.acme.wizzle.wozzle.C().foo.apply()
scala.NotImplementedError: an implementation is missing
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:284)
at com.acme.wizzle.wozzle.C.$anonfun$1(<pastie>:1)
... 30 elided
scala> :paste -raw
// Entering paste mode (ctrl-D to finish)
package p1; class StaticAllTheThings { def foo = () => ""; def bar = () => foo; def baz = () => this }
// Exiting paste mode, now interpreting.
scala> :javap -private -c p1.StaticAllTheThings
Compiled from "<pastie>"
public class p1.StaticAllTheThings {
public scala.Function0<java.lang.String> foo();
Code:
0: invokedynamic #38, 0 // InvokeDynamic #0:apply:()Lscala/Function0;
5: areturn
public scala.Function0<scala.Function0<java.lang.String>> bar();
Code:
0: aload_0
1: invokedynamic #49, 0 // InvokeDynamic #1:apply:(Lp1/StaticAllTheThings;)Lscala/Function0;
6: areturn
public scala.Function0<p1.StaticAllTheThings> baz();
Code:
0: aload_0
1: invokedynamic #58, 0 // InvokeDynamic #2:apply:(Lp1/StaticAllTheThings;)Lscala/Function0;
6: areturn
public static final java.lang.String $anonfun$1();
Code:
0: ldc #60 // String
2: areturn
public static final scala.Function0 $anonfun$2(p1.StaticAllTheThings);
Code:
0: aload_0
1: invokevirtual #63 // Method foo:()Lscala/Function0;
4: areturn
public static final p1.StaticAllTheThings $anonfun$3(p1.StaticAllTheThings);
Code:
0: aload_0
1: areturn
public p1.StaticAllTheThings();
Code:
0: aload_0
1: invokespecial #67 // Method java/lang/Object."<init>":()V
4: return
private static java.lang.Object $deserializeLambda$(java.lang.invoke.SerializedLambda);
Code:
0: aload_0
1: invokedynamic #79, 0 // InvokeDynamic #3:lambdaDeserialize:(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;
6: areturn
}
```1 parent ed38fbc commit 3ca962c
1 file changed
+31
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | | - | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
93 | | - | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
| 123 | + | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
126 | | - | |
| 128 | + | |
127 | 129 | | |
128 | 130 | | |
129 | 131 | | |
| |||
210 | 212 | | |
211 | 213 | | |
212 | 214 | | |
213 | | - | |
| 215 | + | |
| 216 | + | |
214 | 217 | | |
215 | 218 | | |
216 | 219 | | |
| |||
223 | 226 | | |
224 | 227 | | |
225 | 228 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 229 | + | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
255 | | - | |
| 256 | + | |
| 257 | + | |
256 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
257 | 277 | | |
258 | 278 | | |
259 | | - | |
| 279 | + | |
260 | 280 | | |
261 | 281 | | |
262 | 282 | | |
| |||
0 commit comments