author | rfield |
Tue, 22 Oct 2013 16:53:21 -0700 | |
changeset 21489 | 018e34d4045f |
parent 21486 | 847de793f27a |
child 21492 | e7c8a164d7bd |
permissions | -rw-r--r-- |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1 |
/* |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
4 |
* |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
10 |
* |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
15 |
* accompanied this code). |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
16 |
* |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
20 |
* |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
23 |
* questions. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
24 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
25 |
package com.sun.tools.javac.comp; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
26 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
27 |
import com.sun.tools.javac.tree.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
28 |
import com.sun.tools.javac.tree.JCTree.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
29 |
import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
30 |
import com.sun.tools.javac.tree.TreeMaker; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
31 |
import com.sun.tools.javac.tree.TreeTranslator; |
17578 | 32 |
import com.sun.tools.javac.code.Attribute; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
33 |
import com.sun.tools.javac.code.Kinds; |
16300 | 34 |
import com.sun.tools.javac.code.Scope; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.code.Symbol; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
38 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.code.Symtab; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.code.Type; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.code.Type.MethodType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
43 |
import com.sun.tools.javac.code.Types; |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
44 |
import com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzerPreprocessor.*; |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
45 |
import com.sun.tools.javac.comp.Lower.BasicFreeVarCollector; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
46 |
import com.sun.tools.javac.jvm.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
47 |
import com.sun.tools.javac.util.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
48 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
49 |
import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
50 |
|
21486 | 51 |
import java.util.EnumMap; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
52 |
import java.util.HashMap; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
53 |
import java.util.LinkedHashMap; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
54 |
import java.util.Map; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
55 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
56 |
import static com.sun.tools.javac.comp.LambdaToMethod.LambdaSymbolKind.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
57 |
import static com.sun.tools.javac.code.Flags.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
58 |
import static com.sun.tools.javac.code.Kinds.*; |
16300 | 59 |
import static com.sun.tools.javac.code.TypeTag.*; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
60 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
61 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
62 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
63 |
* This pass desugars lambda expressions into static methods |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
64 |
* |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
65 |
* <p><b>This is NOT part of any supported API. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
66 |
* If you write code that depends on this, you do so at your own risk. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
67 |
* This code and its internal interfaces are subject to change or |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
68 |
* deletion without notice.</b> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
69 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
70 |
public class LambdaToMethod extends TreeTranslator { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
71 |
|
21486 | 72 |
private Attr attr; |
18386 | 73 |
private JCDiagnostic.Factory diags; |
74 |
private Log log; |
|
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
75 |
private Lower lower; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
76 |
private Names names; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
77 |
private Symtab syms; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
78 |
private Resolve rs; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
79 |
private TreeMaker make; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
80 |
private Types types; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
81 |
private TransTypes transTypes; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
82 |
private Env<AttrContext> attrEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
83 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
84 |
/** the analyzer scanner */ |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
85 |
private LambdaAnalyzerPreprocessor analyzer; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
86 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
87 |
/** map from lambda trees to translation contexts */ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
88 |
private Map<JCTree, TranslationContext<?>> contextMap; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
89 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
90 |
/** current translation context (visitor argument) */ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
91 |
private TranslationContext<?> context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
92 |
|
16300 | 93 |
/** info about the current class being processed */ |
94 |
private KlassInfo kInfo; |
|
95 |
||
18386 | 96 |
/** dump statistics about lambda code generation */ |
97 |
private boolean dumpLambdaToMethodStats; |
|
98 |
||
16300 | 99 |
/** Flag for alternate metafactories indicating the lambda object is intended to be serializable */ |
100 |
public static final int FLAG_SERIALIZABLE = 1 << 0; |
|
101 |
||
102 |
/** Flag for alternate metafactories indicating the lambda object has multiple targets */ |
|
103 |
public static final int FLAG_MARKERS = 1 << 1; |
|
104 |
||
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
105 |
/** Flag for alternate metafactories indicating the lambda object requires multiple bridges */ |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
106 |
public static final int FLAG_BRIDGES = 1 << 2; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
107 |
|
21486 | 108 |
// <editor-fold defaultstate="collapsed" desc="Instantiating"> |
109 |
protected static final Context.Key<LambdaToMethod> unlambdaKey = |
|
110 |
new Context.Key<LambdaToMethod>(); |
|
111 |
||
112 |
public static LambdaToMethod instance(Context context) { |
|
113 |
LambdaToMethod instance = context.get(unlambdaKey); |
|
114 |
if (instance == null) { |
|
115 |
instance = new LambdaToMethod(context); |
|
116 |
} |
|
117 |
return instance; |
|
118 |
} |
|
119 |
private LambdaToMethod(Context context) { |
|
120 |
context.put(unlambdaKey, this); |
|
121 |
diags = JCDiagnostic.Factory.instance(context); |
|
122 |
log = Log.instance(context); |
|
123 |
lower = Lower.instance(context); |
|
124 |
names = Names.instance(context); |
|
125 |
syms = Symtab.instance(context); |
|
126 |
rs = Resolve.instance(context); |
|
127 |
make = TreeMaker.instance(context); |
|
128 |
types = Types.instance(context); |
|
129 |
transTypes = TransTypes.instance(context); |
|
130 |
analyzer = new LambdaAnalyzerPreprocessor(); |
|
131 |
Options options = Options.instance(context); |
|
132 |
dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats"); |
|
133 |
attr = Attr.instance(context); |
|
134 |
} |
|
135 |
// </editor-fold> |
|
136 |
||
16300 | 137 |
private class KlassInfo { |
138 |
||
139 |
/** |
|
140 |
* list of methods to append |
|
141 |
*/ |
|
142 |
private ListBuffer<JCTree> appendedMethodList; |
|
143 |
||
144 |
/** |
|
145 |
* list of deserialization cases |
|
146 |
*/ |
|
147 |
private final Map<String, ListBuffer<JCStatement>> deserializeCases; |
|
148 |
||
149 |
/** |
|
150 |
* deserialize method symbol |
|
151 |
*/ |
|
152 |
private final MethodSymbol deserMethodSym; |
|
153 |
||
154 |
/** |
|
155 |
* deserialize method parameter symbol |
|
156 |
*/ |
|
157 |
private final VarSymbol deserParamSym; |
|
158 |
||
159 |
private KlassInfo(Symbol kSym) { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
160 |
appendedMethodList = new ListBuffer<>(); |
16300 | 161 |
deserializeCases = new HashMap<String, ListBuffer<JCStatement>>(); |
162 |
MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType, |
|
163 |
List.<Type>nil(), syms.methodClass); |
|
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
164 |
deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, kSym); |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
165 |
deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"), |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
166 |
syms.serializedLambdaType, deserMethodSym); |
16300 | 167 |
} |
168 |
||
169 |
private void addMethod(JCTree decl) { |
|
170 |
appendedMethodList = appendedMethodList.prepend(decl); |
|
171 |
} |
|
172 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
173 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
174 |
// <editor-fold defaultstate="collapsed" desc="translate methods"> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
175 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
176 |
public <T extends JCTree> T translate(T tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
177 |
TranslationContext<?> newContext = contextMap.get(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
178 |
return translate(tree, newContext != null ? newContext : context); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
179 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
180 |
|
17585
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
181 |
<T extends JCTree> T translate(T tree, TranslationContext<?> newContext) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
182 |
TranslationContext<?> prevContext = context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
183 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
184 |
context = newContext; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
185 |
return super.translate(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
186 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
187 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
188 |
context = prevContext; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
189 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
190 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
191 |
|
17585
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
192 |
<T extends JCTree> List<T> translate(List<T> trees, TranslationContext<?> newContext) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
193 |
ListBuffer<T> buf = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
194 |
for (T tree : trees) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
195 |
buf.append(translate(tree, newContext)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
196 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
197 |
return buf.toList(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
198 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
199 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
200 |
public JCTree translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
201 |
this.make = make; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
202 |
this.attrEnv = env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
203 |
this.context = null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
204 |
this.contextMap = new HashMap<JCTree, TranslationContext<?>>(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
205 |
return translate(cdef); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
206 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
207 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
208 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
209 |
// <editor-fold defaultstate="collapsed" desc="visitor methods"> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
210 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
211 |
* Visit a class. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
212 |
* Maintain the translatedMethodList across nested classes. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
213 |
* Append the translatedMethodList to the class after it is translated. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
214 |
* @param tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
215 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
216 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
217 |
public void visitClassDef(JCClassDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
218 |
if (tree.sym.owner.kind == PCK) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
219 |
//analyze class |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
220 |
tree = analyzer.analyzeAndPreprocessClass(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
221 |
} |
16300 | 222 |
KlassInfo prevKlassInfo = kInfo; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
223 |
try { |
16300 | 224 |
kInfo = new KlassInfo(tree.sym); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
225 |
super.visitClassDef(tree); |
16300 | 226 |
if (!kInfo.deserializeCases.isEmpty()) { |
227 |
kInfo.addMethod(makeDeserializeMethod(tree.sym)); |
|
228 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
229 |
//add all translated instance methods here |
16300 | 230 |
List<JCTree> newMethods = kInfo.appendedMethodList.toList(); |
231 |
tree.defs = tree.defs.appendList(newMethods); |
|
232 |
for (JCTree lambda : newMethods) { |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
233 |
tree.sym.members().enter(((JCMethodDecl)lambda).sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
234 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
235 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
236 |
} finally { |
16300 | 237 |
kInfo = prevKlassInfo; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
238 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
239 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
240 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
241 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
242 |
* Translate a lambda into a method to be inserted into the class. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
243 |
* Then replace the lambda site with an invokedynamic call of to lambda |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
244 |
* meta-factory, which will use the lambda method. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
245 |
* @param tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
246 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
247 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
248 |
public void visitLambda(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
249 |
LambdaTranslationContext localContext = (LambdaTranslationContext)context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
250 |
MethodSymbol sym = (MethodSymbol)localContext.translatedSym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
251 |
MethodType lambdaType = (MethodType) sym.type; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
252 |
|
17578 | 253 |
{ |
19651 | 254 |
Symbol owner = localContext.owner; |
17578 | 255 |
ListBuffer<Attribute.TypeCompound> ownerTypeAnnos = new ListBuffer<Attribute.TypeCompound>(); |
256 |
ListBuffer<Attribute.TypeCompound> lambdaTypeAnnos = new ListBuffer<Attribute.TypeCompound>(); |
|
257 |
||
258 |
for (Attribute.TypeCompound tc : owner.getRawTypeAttributes()) { |
|
259 |
if (tc.position.onLambda == tree) { |
|
260 |
lambdaTypeAnnos.append(tc); |
|
261 |
} else { |
|
262 |
ownerTypeAnnos.append(tc); |
|
263 |
} |
|
264 |
} |
|
265 |
if (lambdaTypeAnnos.nonEmpty()) { |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17585
diff
changeset
|
266 |
owner.setTypeAttributes(ownerTypeAnnos.toList()); |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17585
diff
changeset
|
267 |
sym.setTypeAttributes(lambdaTypeAnnos.toList()); |
17578 | 268 |
} |
269 |
} |
|
270 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
271 |
//create the method declaration hoisting the lambda body |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
272 |
JCMethodDecl lambdaDecl = make.MethodDef(make.Modifiers(sym.flags_field), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
273 |
sym.name, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
274 |
make.QualIdent(lambdaType.getReturnType().tsym), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
275 |
List.<JCTypeParameter>nil(), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
276 |
localContext.syntheticParams, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
277 |
lambdaType.getThrownTypes() == null ? |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
278 |
List.<JCExpression>nil() : |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
279 |
make.Types(lambdaType.getThrownTypes()), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
280 |
null, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
281 |
null); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
282 |
lambdaDecl.sym = sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
283 |
lambdaDecl.type = lambdaType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
284 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
285 |
//translate lambda body |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
286 |
//As the lambda body is translated, all references to lambda locals, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
287 |
//captured variables, enclosing members are adjusted accordingly |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
288 |
//to refer to the static method parameters (rather than i.e. acessing to |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
289 |
//captured members directly). |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
290 |
lambdaDecl.body = translate(makeLambdaBody(tree, lambdaDecl)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
291 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
292 |
//Add the method to the list of methods to be added to this class. |
16300 | 293 |
kInfo.addMethod(lambdaDecl); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
294 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
295 |
//now that we have generated a method for the lambda expression, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
296 |
//we can translate the lambda into a method reference pointing to the newly |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
297 |
//created method. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
298 |
// |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
299 |
//Note that we need to adjust the method handle so that it will match the |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
300 |
//signature of the SAM descriptor - this means that the method reference |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
301 |
//should be added the following synthetic arguments: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
302 |
// |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
303 |
// * the "this" argument if it is an instance method |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
304 |
// * enclosing locals captured by the lambda expression |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
305 |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
306 |
ListBuffer<JCExpression> syntheticInits = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
307 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
308 |
if (!sym.isStatic()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
309 |
syntheticInits.append(makeThis( |
16300 | 310 |
sym.owner.enclClass().asType(), |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
311 |
localContext.owner.enclClass())); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
312 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
313 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
314 |
//add captured locals |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
315 |
for (Symbol fv : localContext.getSymbolMap(CAPTURED_VAR).keySet()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
316 |
if (fv != localContext.self) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
317 |
JCTree captured_local = make.Ident(fv).setType(fv.type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
318 |
syntheticInits.append((JCExpression) captured_local); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
319 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
320 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
321 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
322 |
//then, determine the arguments to the indy call |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
323 |
List<JCExpression> indy_args = translate(syntheticInits.toList(), localContext.prev); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
324 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
325 |
//build a sam instance using an indy call to the meta-factory |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
326 |
int refKind = referenceKind(sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
327 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
328 |
//convert to an invokedynamic call |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
329 |
result = makeMetafactoryIndyCall(context, refKind, sym, indy_args); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
330 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
331 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
332 |
private JCIdent makeThis(Type type, Symbol owner) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
333 |
VarSymbol _this = new VarSymbol(PARAMETER | FINAL | SYNTHETIC, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
334 |
names._this, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
335 |
type, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
336 |
owner); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
337 |
return make.Ident(_this); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
338 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
339 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
340 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
341 |
* Translate a method reference into an invokedynamic call to the |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
342 |
* meta-factory. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
343 |
* @param tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
344 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
345 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
346 |
public void visitReference(JCMemberReference tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
347 |
ReferenceTranslationContext localContext = (ReferenceTranslationContext)context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
348 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
349 |
//first determine the method symbol to be used to generate the sam instance |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
350 |
//this is either the method reference symbol, or the bridged reference symbol |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
351 |
Symbol refSym = localContext.needsBridge() ? |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
352 |
localContext.bridgeSym : |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
353 |
tree.sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
354 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
355 |
//build the bridge method, if needed |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
356 |
if (localContext.needsBridge()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
357 |
bridgeMemberReference(tree, localContext); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
358 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
359 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
360 |
//the qualifying expression is treated as a special captured arg |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
361 |
JCExpression init; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
362 |
switch(tree.kind) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
363 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
364 |
case IMPLICIT_INNER: /** Inner :: new */ |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
365 |
case SUPER: /** super :: instMethod */ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
366 |
init = makeThis( |
16300 | 367 |
localContext.owner.enclClass().asType(), |
368 |
localContext.owner.enclClass()); |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
369 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
370 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
371 |
case BOUND: /** Expr :: instMethod */ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
372 |
init = tree.getQualifierExpression(); |
20245
c351f524fbc6
8024696: Missing null check in bound method reference capture
vromero
parents:
19941
diff
changeset
|
373 |
init = attr.makeNullCheck(init); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
374 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
375 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
376 |
case UNBOUND: /** Type :: instMethod */ |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
377 |
case STATIC: /** Type :: staticMethod */ |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
378 |
case TOPLEVEL: /** Top level :: new */ |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
379 |
case ARRAY_CTOR: /** ArrayType :: new */ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
380 |
init = null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
381 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
382 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
383 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
384 |
throw new InternalError("Should not have an invalid kind"); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
385 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
386 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
387 |
List<JCExpression> indy_args = init==null? List.<JCExpression>nil() : translate(List.of(init), localContext.prev); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
388 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
389 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
390 |
//build a sam instance using an indy call to the meta-factory |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
391 |
result = makeMetafactoryIndyCall(localContext, localContext.referenceKind(), refSym, indy_args); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
392 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
393 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
394 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
395 |
* Translate identifiers within a lambda to the mapped identifier |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
396 |
* @param tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
397 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
398 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
399 |
public void visitIdent(JCIdent tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
400 |
if (context == null || !analyzer.lambdaIdentSymbolFilter(tree.sym)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
401 |
super.visitIdent(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
402 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
403 |
LambdaTranslationContext lambdaContext = (LambdaTranslationContext) context; |
21486 | 404 |
JCTree ltree = lambdaContext.translate(tree); |
405 |
if (ltree != null) { |
|
406 |
result = ltree; |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
407 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
408 |
//access to untranslated symbols (i.e. compile-time constants, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
409 |
//members defined inside the lambda body, etc.) ) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
410 |
super.visitIdent(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
411 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
412 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
413 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
414 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
415 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
416 |
public void visitVarDef(JCVariableDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
417 |
LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
418 |
if (context != null && lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
419 |
JCExpression init = translate(tree.init); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
420 |
result = make.VarDef((VarSymbol)lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym), init); |
16300 | 421 |
} else if (context != null && lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) { |
422 |
JCExpression init = translate(tree.init); |
|
423 |
VarSymbol xsym = (VarSymbol)lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym); |
|
424 |
result = make.VarDef(xsym, init); |
|
425 |
// Replace the entered symbol for this variable |
|
426 |
Scope sc = tree.sym.owner.members(); |
|
427 |
if (sc != null) { |
|
428 |
sc.remove(tree.sym); |
|
429 |
sc.enter(xsym); |
|
430 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
431 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
432 |
super.visitVarDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
433 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
434 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
435 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
436 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
437 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
438 |
// <editor-fold defaultstate="collapsed" desc="Translation helper methods"> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
439 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
440 |
private JCBlock makeLambdaBody(JCLambda tree, JCMethodDecl lambdaMethodDecl) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
441 |
return tree.getBodyKind() == JCLambda.BodyKind.EXPRESSION ? |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
442 |
makeLambdaExpressionBody((JCExpression)tree.body, lambdaMethodDecl) : |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
443 |
makeLambdaStatementBody((JCBlock)tree.body, lambdaMethodDecl, tree.canCompleteNormally); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
444 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
445 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
446 |
private JCBlock makeLambdaExpressionBody(JCExpression expr, JCMethodDecl lambdaMethodDecl) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
447 |
Type restype = lambdaMethodDecl.type.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
448 |
boolean isLambda_void = expr.type.hasTag(VOID); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
449 |
boolean isTarget_void = restype.hasTag(VOID); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
450 |
boolean isTarget_Void = types.isSameType(restype, types.boxedClass(syms.voidType).type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
451 |
if (isTarget_void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
452 |
//target is void: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
453 |
// BODY; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
454 |
JCStatement stat = make.Exec(expr); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
455 |
return make.Block(0, List.<JCStatement>of(stat)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
456 |
} else if (isLambda_void && isTarget_Void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
457 |
//void to Void conversion: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
458 |
// BODY; return null; |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
459 |
ListBuffer<JCStatement> stats = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
460 |
stats.append(make.Exec(expr)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
461 |
stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType))); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
462 |
return make.Block(0, stats.toList()); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
463 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
464 |
//non-void to non-void conversion: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
465 |
// return (TYPE)BODY; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
466 |
JCExpression retExpr = transTypes.coerce(attrEnv, expr, restype); |
19487
9097d88f5e1f
8019486: javac, generates erroneous LVT for a test case with lambda code
vromero
parents:
18730
diff
changeset
|
467 |
return make.at(retExpr).Block(0, List.<JCStatement>of(make.Return(retExpr))); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
468 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
469 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
470 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
471 |
private JCBlock makeLambdaStatementBody(JCBlock block, final JCMethodDecl lambdaMethodDecl, boolean completeNormally) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
472 |
final Type restype = lambdaMethodDecl.type.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
473 |
final boolean isTarget_void = restype.hasTag(VOID); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
474 |
boolean isTarget_Void = types.isSameType(restype, types.boxedClass(syms.voidType).type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
475 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
476 |
class LambdaBodyTranslator extends TreeTranslator { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
477 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
478 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
479 |
public void visitClassDef(JCClassDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
480 |
//do NOT recurse on any inner classes |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
481 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
482 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
483 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
484 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
485 |
public void visitLambda(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
486 |
//do NOT recurse on any nested lambdas |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
487 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
488 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
489 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
490 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
491 |
public void visitReturn(JCReturn tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
492 |
boolean isLambda_void = tree.expr == null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
493 |
if (isTarget_void && !isLambda_void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
494 |
//Void to void conversion: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
495 |
// { TYPE $loc = RET-EXPR; return; } |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
496 |
VarSymbol loc = makeSyntheticVar(0, names.fromString("$loc"), tree.expr.type, lambdaMethodDecl.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
497 |
JCVariableDecl varDef = make.VarDef(loc, tree.expr); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
498 |
result = make.Block(0, List.<JCStatement>of(varDef, make.Return(null))); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
499 |
} else if (!isTarget_void || !isLambda_void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
500 |
//non-void to non-void conversion: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
501 |
// return (TYPE)RET-EXPR; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
502 |
tree.expr = transTypes.coerce(attrEnv, tree.expr, restype); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
503 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
504 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
505 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
506 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
507 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
508 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
509 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
510 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
511 |
JCBlock trans_block = new LambdaBodyTranslator().translate(block); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
512 |
if (completeNormally && isTarget_Void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
513 |
//there's no return statement and the lambda (possibly inferred) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
514 |
//return type is java.lang.Void; emit a synthetic return statement |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
515 |
trans_block.stats = trans_block.stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType))); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
516 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
517 |
return trans_block; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
518 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
519 |
|
16300 | 520 |
private JCMethodDecl makeDeserializeMethod(Symbol kSym) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
521 |
ListBuffer<JCCase> cases = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
522 |
ListBuffer<JCBreak> breaks = new ListBuffer<>(); |
16300 | 523 |
for (Map.Entry<String, ListBuffer<JCStatement>> entry : kInfo.deserializeCases.entrySet()) { |
524 |
JCBreak br = make.Break(null); |
|
525 |
breaks.add(br); |
|
526 |
List<JCStatement> stmts = entry.getValue().append(br).toList(); |
|
527 |
cases.add(make.Case(make.Literal(entry.getKey()), stmts)); |
|
528 |
} |
|
529 |
JCSwitch sw = make.Switch(deserGetter("getImplMethodName", syms.stringType), cases.toList()); |
|
530 |
for (JCBreak br : breaks) { |
|
531 |
br.target = sw; |
|
532 |
} |
|
533 |
JCBlock body = make.Block(0L, List.<JCStatement>of( |
|
534 |
sw, |
|
535 |
make.Throw(makeNewClass( |
|
536 |
syms.illegalArgumentExceptionType, |
|
537 |
List.<JCExpression>of(make.Literal("Invalid lambda deserialization")))))); |
|
538 |
JCMethodDecl deser = make.MethodDef(make.Modifiers(kInfo.deserMethodSym.flags()), |
|
539 |
names.deserializeLambda, |
|
540 |
make.QualIdent(kInfo.deserMethodSym.getReturnType().tsym), |
|
541 |
List.<JCTypeParameter>nil(), |
|
542 |
List.of(make.VarDef(kInfo.deserParamSym, null)), |
|
543 |
List.<JCExpression>nil(), |
|
544 |
body, |
|
545 |
null); |
|
546 |
deser.sym = kInfo.deserMethodSym; |
|
547 |
deser.type = kInfo.deserMethodSym.type; |
|
548 |
//System.err.printf("DESER: '%s'\n", deser); |
|
549 |
return deser; |
|
550 |
} |
|
551 |
||
552 |
/** Make an attributed class instance creation expression. |
|
553 |
* @param ctype The class type. |
|
554 |
* @param args The constructor arguments. |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
555 |
* @param cons The constructor symbol |
16300 | 556 |
*/ |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
557 |
JCNewClass makeNewClass(Type ctype, List<JCExpression> args, Symbol cons) { |
16300 | 558 |
JCNewClass tree = make.NewClass(null, |
559 |
null, make.QualIdent(ctype.tsym), args, null); |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
560 |
tree.constructor = cons; |
16300 | 561 |
tree.type = ctype; |
562 |
return tree; |
|
563 |
} |
|
564 |
||
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
565 |
/** Make an attributed class instance creation expression. |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
566 |
* @param ctype The class type. |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
567 |
* @param args The constructor arguments. |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
568 |
*/ |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
569 |
JCNewClass makeNewClass(Type ctype, List<JCExpression> args) { |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
570 |
return makeNewClass(ctype, args, |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
571 |
rs.resolveConstructor(null, attrEnv, ctype, TreeInfo.types(args), List.<Type>nil())); |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
572 |
} |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
573 |
|
16300 | 574 |
private void addDeserializationCase(int implMethodKind, Symbol refSym, Type targetType, MethodSymbol samSym, |
575 |
DiagnosticPosition pos, List<Object> staticArgs, MethodType indyType) { |
|
576 |
String functionalInterfaceClass = classSig(targetType); |
|
577 |
String functionalInterfaceMethodName = samSym.getSimpleName().toString(); |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
578 |
String functionalInterfaceMethodSignature = typeSig(types.erasure(samSym.type)); |
16335
4f7fe060522f
8009582: Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization
rfield
parents:
16332
diff
changeset
|
579 |
String implClass = classSig(types.erasure(refSym.owner.type)); |
16300 | 580 |
String implMethodName = refSym.getQualifiedName().toString(); |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
581 |
String implMethodSignature = typeSig(types.erasure(refSym.type)); |
16300 | 582 |
|
583 |
JCExpression kindTest = eqTest(syms.intType, deserGetter("getImplMethodKind", syms.intType), make.Literal(implMethodKind)); |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
584 |
ListBuffer<JCExpression> serArgs = new ListBuffer<>(); |
16300 | 585 |
int i = 0; |
586 |
for (Type t : indyType.getParameterTypes()) { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
587 |
List<JCExpression> indexAsArg = new ListBuffer<JCExpression>().append(make.Literal(i)).toList(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
588 |
List<Type> argTypes = new ListBuffer<Type>().append(syms.intType).toList(); |
16300 | 589 |
serArgs.add(make.TypeCast(types.erasure(t), deserGetter("getCapturedArg", syms.objectType, argTypes, indexAsArg))); |
590 |
++i; |
|
591 |
} |
|
592 |
JCStatement stmt = make.If( |
|
593 |
deserTest(deserTest(deserTest(deserTest(deserTest( |
|
594 |
kindTest, |
|
595 |
"getFunctionalInterfaceClass", functionalInterfaceClass), |
|
596 |
"getFunctionalInterfaceMethodName", functionalInterfaceMethodName), |
|
597 |
"getFunctionalInterfaceMethodSignature", functionalInterfaceMethodSignature), |
|
598 |
"getImplClass", implClass), |
|
599 |
"getImplMethodSignature", implMethodSignature), |
|
600 |
make.Return(makeIndyCall( |
|
601 |
pos, |
|
602 |
syms.lambdaMetafactory, |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
603 |
names.altMetafactory, |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
604 |
staticArgs, indyType, serArgs.toList(), samSym.name)), |
16300 | 605 |
null); |
606 |
ListBuffer<JCStatement> stmts = kInfo.deserializeCases.get(implMethodName); |
|
607 |
if (stmts == null) { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
608 |
stmts = new ListBuffer<>(); |
16300 | 609 |
kInfo.deserializeCases.put(implMethodName, stmts); |
610 |
} |
|
611 |
/**** |
|
612 |
System.err.printf("+++++++++++++++++\n"); |
|
613 |
System.err.printf("*functionalInterfaceClass: '%s'\n", functionalInterfaceClass); |
|
614 |
System.err.printf("*functionalInterfaceMethodName: '%s'\n", functionalInterfaceMethodName); |
|
615 |
System.err.printf("*functionalInterfaceMethodSignature: '%s'\n", functionalInterfaceMethodSignature); |
|
616 |
System.err.printf("*implMethodKind: %d\n", implMethodKind); |
|
617 |
System.err.printf("*implClass: '%s'\n", implClass); |
|
618 |
System.err.printf("*implMethodName: '%s'\n", implMethodName); |
|
619 |
System.err.printf("*implMethodSignature: '%s'\n", implMethodSignature); |
|
620 |
****/ |
|
621 |
stmts.append(stmt); |
|
622 |
} |
|
623 |
||
624 |
private JCExpression eqTest(Type argType, JCExpression arg1, JCExpression arg2) { |
|
625 |
JCBinary testExpr = make.Binary(JCTree.Tag.EQ, arg1, arg2); |
|
626 |
testExpr.operator = rs.resolveBinaryOperator(null, JCTree.Tag.EQ, attrEnv, argType, argType); |
|
627 |
testExpr.setType(syms.booleanType); |
|
628 |
return testExpr; |
|
629 |
} |
|
630 |
||
631 |
private JCExpression deserTest(JCExpression prev, String func, String lit) { |
|
632 |
MethodType eqmt = new MethodType(List.of(syms.objectType), syms.booleanType, List.<Type>nil(), syms.methodClass); |
|
633 |
Symbol eqsym = rs.resolveQualifiedMethod(null, attrEnv, syms.objectType, names.equals, List.of(syms.objectType), List.<Type>nil()); |
|
634 |
JCMethodInvocation eqtest = make.Apply( |
|
635 |
List.<JCExpression>nil(), |
|
636 |
make.Select(deserGetter(func, syms.stringType), eqsym).setType(eqmt), |
|
637 |
List.<JCExpression>of(make.Literal(lit))); |
|
638 |
eqtest.setType(syms.booleanType); |
|
639 |
JCBinary compound = make.Binary(JCTree.Tag.AND, prev, eqtest); |
|
640 |
compound.operator = rs.resolveBinaryOperator(null, JCTree.Tag.AND, attrEnv, syms.booleanType, syms.booleanType); |
|
641 |
compound.setType(syms.booleanType); |
|
642 |
return compound; |
|
643 |
} |
|
644 |
||
645 |
private JCExpression deserGetter(String func, Type type) { |
|
646 |
return deserGetter(func, type, List.<Type>nil(), List.<JCExpression>nil()); |
|
647 |
} |
|
648 |
||
649 |
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) { |
|
650 |
MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass); |
|
651 |
Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil()); |
|
652 |
return make.Apply( |
|
653 |
List.<JCExpression>nil(), |
|
654 |
make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), |
|
655 |
args).setType(type); |
|
656 |
} |
|
657 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
658 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
659 |
* Create new synthetic method with given flags, name, type, owner |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
660 |
*/ |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
661 |
private MethodSymbol makePrivateSyntheticMethod(long flags, Name name, Type type, Symbol owner) { |
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
662 |
return new MethodSymbol(flags | SYNTHETIC | PRIVATE, name, type, owner); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
663 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
664 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
665 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
666 |
* Create new synthetic variable with given flags, name, type, owner |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
667 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
668 |
private VarSymbol makeSyntheticVar(long flags, String name, Type type, Symbol owner) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
669 |
return makeSyntheticVar(flags, names.fromString(name), type, owner); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
670 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
671 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
672 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
673 |
* Create new synthetic variable with given flags, name, type, owner |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
674 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
675 |
private VarSymbol makeSyntheticVar(long flags, Name name, Type type, Symbol owner) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
676 |
return new VarSymbol(flags | SYNTHETIC, name, type, owner); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
677 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
678 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
679 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
680 |
* Set varargsElement field on a given tree (must be either a new class tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
681 |
* or a method call tree) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
682 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
683 |
private void setVarargsIfNeeded(JCTree tree, Type varargsElement) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
684 |
if (varargsElement != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
685 |
switch (tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
686 |
case APPLY: ((JCMethodInvocation)tree).varargsElement = varargsElement; break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
687 |
case NEWCLASS: ((JCNewClass)tree).varargsElement = varargsElement; break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
688 |
default: throw new AssertionError(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
689 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
690 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
691 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
692 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
693 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
694 |
* Convert method/constructor arguments by inserting appropriate cast |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
695 |
* as required by type-erasure - this is needed when bridging a lambda/method |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
696 |
* reference, as the bridged signature might require downcast to be compatible |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
697 |
* with the generated signature. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
698 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
699 |
private List<JCExpression> convertArgs(Symbol meth, List<JCExpression> args, Type varargsElement) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
700 |
Assert.check(meth.kind == Kinds.MTH); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
701 |
List<Type> formals = types.erasure(meth.type).getParameterTypes(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
702 |
if (varargsElement != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
703 |
Assert.check((meth.flags() & VARARGS) != 0); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
704 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
705 |
return transTypes.translateArgs(args, formals, varargsElement, attrEnv); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
706 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
707 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
708 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
709 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
710 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
711 |
* Generate an adapter method "bridge" for a method reference which cannot |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
712 |
* be used directly. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
713 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
714 |
private class MemberReferenceBridger { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
715 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
716 |
private final JCMemberReference tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
717 |
private final ReferenceTranslationContext localContext; |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
718 |
private final ListBuffer<JCExpression> args = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
719 |
private final ListBuffer<JCVariableDecl> params = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
720 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
721 |
MemberReferenceBridger(JCMemberReference tree, ReferenceTranslationContext localContext) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
722 |
this.tree = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
723 |
this.localContext = localContext; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
724 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
725 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
726 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
727 |
* Generate the bridge |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
728 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
729 |
JCMethodDecl bridge() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
730 |
int prevPos = make.pos; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
731 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
732 |
make.at(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
733 |
Type samDesc = localContext.bridgedRefSig(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
734 |
List<Type> samPTypes = samDesc.getParameterTypes(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
735 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
736 |
//an extra argument is prepended to the signature of the bridge in case |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
737 |
//the member reference is an instance method reference (in which case |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
738 |
//the receiver expression is passed to the bridge itself). |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
739 |
Type recType = null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
740 |
switch (tree.kind) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
741 |
case IMPLICIT_INNER: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
742 |
recType = tree.sym.owner.type.getEnclosingType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
743 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
744 |
case BOUND: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
745 |
recType = tree.getQualifierExpression().type; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
746 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
747 |
case UNBOUND: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
748 |
recType = samPTypes.head; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
749 |
samPTypes = samPTypes.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
750 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
751 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
752 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
753 |
//generate the parameter list for the bridged member reference - the |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
754 |
//bridge signature will match the signature of the target sam descriptor |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
755 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
756 |
VarSymbol rcvr = (recType == null) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
757 |
? null |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
758 |
: addParameter("rec$", recType, false); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
759 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
760 |
List<Type> refPTypes = tree.sym.type.getParameterTypes(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
761 |
int refSize = refPTypes.size(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
762 |
int samSize = samPTypes.size(); |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
763 |
// Last parameter to copy from referenced method |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
764 |
int last = localContext.needsVarArgsConversion() ? refSize - 1 : refSize; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
765 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
766 |
List<Type> l = refPTypes; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
767 |
// Use parameter types of the referenced method, excluding final var args |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
768 |
for (int i = 0; l.nonEmpty() && i < last; ++i) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
769 |
addParameter("x$" + i, l.head, true); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
770 |
l = l.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
771 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
772 |
// Flatten out the var args |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
773 |
for (int i = last; i < samSize; ++i) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
774 |
addParameter("xva$" + i, tree.varargsElement, true); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
775 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
776 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
777 |
//generate the bridge method declaration |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
778 |
JCMethodDecl bridgeDecl = make.MethodDef(make.Modifiers(localContext.bridgeSym.flags()), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
779 |
localContext.bridgeSym.name, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
780 |
make.QualIdent(samDesc.getReturnType().tsym), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
781 |
List.<JCTypeParameter>nil(), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
782 |
params.toList(), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
783 |
tree.sym.type.getThrownTypes() == null |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
784 |
? List.<JCExpression>nil() |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
785 |
: make.Types(tree.sym.type.getThrownTypes()), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
786 |
null, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
787 |
null); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
788 |
bridgeDecl.sym = (MethodSymbol) localContext.bridgeSym; |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
789 |
bridgeDecl.type = localContext.bridgeSym.type = |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
790 |
types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList())); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
791 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
792 |
//bridge method body generation - this can be either a method call or a |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
793 |
//new instance creation expression, depending on the member reference kind |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
794 |
JCExpression bridgeExpr = (tree.getMode() == ReferenceMode.INVOKE) |
16327
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
795 |
? bridgeExpressionInvoke(makeReceiver(rcvr)) |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
796 |
: bridgeExpressionNew(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
797 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
798 |
//the body is either a return expression containing a method call, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
799 |
//or the method call itself, depending on whether the return type of |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
800 |
//the bridge is non-void/void. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
801 |
bridgeDecl.body = makeLambdaExpressionBody(bridgeExpr, bridgeDecl); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
802 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
803 |
return bridgeDecl; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
804 |
} finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
805 |
make.at(prevPos); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
806 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
807 |
} |
16327
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
808 |
//where |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
809 |
private JCExpression makeReceiver(VarSymbol rcvr) { |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
810 |
if (rcvr == null) return null; |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
811 |
JCExpression rcvrExpr = make.Ident(rcvr); |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
812 |
Type rcvrType = tree.sym.enclClass().type; |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
813 |
if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) { |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
814 |
rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType); |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
815 |
} |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
816 |
return rcvrExpr; |
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
817 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
818 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
819 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
820 |
* determine the receiver of the bridged method call - the receiver can |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
821 |
* be either the synthetic receiver parameter or a type qualifier; the |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
822 |
* original qualifier expression is never used here, as it might refer |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
823 |
* to symbols not available in the static context of the bridge |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
824 |
*/ |
16327
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
825 |
private JCExpression bridgeExpressionInvoke(JCExpression rcvr) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
826 |
JCExpression qualifier = |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
827 |
tree.sym.isStatic() ? |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
828 |
make.Type(tree.sym.owner.type) : |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
829 |
(rcvr != null) ? |
16327
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
830 |
rcvr : |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
831 |
tree.getQualifierExpression(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
832 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
833 |
//create the qualifier expression |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
834 |
JCFieldAccess select = make.Select(qualifier, tree.sym.name); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
835 |
select.sym = tree.sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
836 |
select.type = tree.sym.erasure(types); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
837 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
838 |
//create the method call expression |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
839 |
JCExpression apply = make.Apply(List.<JCExpression>nil(), select, |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
840 |
convertArgs(tree.sym, args.toList(), tree.varargsElement)). |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
841 |
setType(tree.sym.erasure(types).getReturnType()); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
842 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
843 |
apply = transTypes.coerce(apply, localContext.generatedRefSig().getReturnType()); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
844 |
setVarargsIfNeeded(apply, tree.varargsElement); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
845 |
return apply; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
846 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
847 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
848 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
849 |
* the enclosing expression is either 'null' (no enclosing type) or set |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
850 |
* to the first bridge synthetic parameter |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
851 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
852 |
private JCExpression bridgeExpressionNew() { |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
853 |
if (tree.kind == ReferenceKind.ARRAY_CTOR) { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
854 |
//create the array creation expression |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
855 |
JCNewArray newArr = make.NewArray( |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
856 |
make.Type(types.elemtype(tree.getQualifierExpression().type)), |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
857 |
List.of(make.Ident(params.first())), |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
858 |
null); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
859 |
newArr.type = tree.getQualifierExpression().type; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
860 |
return newArr; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
861 |
} else { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
862 |
JCExpression encl = null; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
863 |
switch (tree.kind) { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
864 |
case UNBOUND: |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
865 |
case IMPLICIT_INNER: |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
866 |
encl = make.Ident(params.first()); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
867 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
868 |
|
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
869 |
//create the instance creation expression |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
870 |
JCNewClass newClass = make.NewClass(encl, |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
871 |
List.<JCExpression>nil(), |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
872 |
make.Type(tree.getQualifierExpression().type), |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
873 |
convertArgs(tree.sym, args.toList(), tree.varargsElement), |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
874 |
null); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
875 |
newClass.constructor = tree.sym; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
876 |
newClass.constructorType = tree.sym.erasure(types); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
877 |
newClass.type = tree.getQualifierExpression().type; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
878 |
setVarargsIfNeeded(newClass, tree.varargsElement); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
879 |
return newClass; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
880 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
881 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
882 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
883 |
private VarSymbol addParameter(String name, Type p, boolean genArg) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
884 |
VarSymbol vsym = new VarSymbol(0, names.fromString(name), p, localContext.bridgeSym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
885 |
params.append(make.VarDef(vsym, null)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
886 |
if (genArg) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
887 |
args.append(make.Ident(vsym)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
888 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
889 |
return vsym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
890 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
891 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
892 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
893 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
894 |
* Bridges a member reference - this is needed when: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
895 |
* * Var args in the referenced method need to be flattened away |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
896 |
* * super is used |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
897 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
898 |
private void bridgeMemberReference(JCMemberReference tree, ReferenceTranslationContext localContext) { |
16300 | 899 |
kInfo.addMethod(new MemberReferenceBridger(tree, localContext).bridge()); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
900 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
901 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
902 |
private MethodType typeToMethodType(Type mt) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
903 |
Type type = types.erasure(mt); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
904 |
return new MethodType(type.getParameterTypes(), |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
905 |
type.getReturnType(), |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
906 |
type.getThrownTypes(), |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
907 |
syms.methodClass); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
908 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
909 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
910 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
911 |
* Generate an indy method call to the meta factory |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
912 |
*/ |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
913 |
private JCExpression makeMetafactoryIndyCall(TranslationContext<?> context, |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
914 |
int refKind, Symbol refSym, List<JCExpression> indy_args) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
915 |
JCFunctionalExpression tree = context.tree; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
916 |
//determine the static bsm args |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15360
diff
changeset
|
917 |
MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
918 |
List<Object> staticArgs = List.<Object>of( |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
919 |
typeToMethodType(samSym.type), |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14724
diff
changeset
|
920 |
new Pool.MethodHandle(refKind, refSym, types), |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
921 |
typeToMethodType(tree.getDescriptorType(types))); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
922 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
923 |
//computed indy arg types |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
924 |
ListBuffer<Type> indy_args_types = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
925 |
for (JCExpression arg : indy_args) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
926 |
indy_args_types.append(arg.type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
927 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
928 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
929 |
//finally, compute the type of the indy call |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
930 |
MethodType indyType = new MethodType(indy_args_types.toList(), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
931 |
tree.type, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
932 |
List.<Type>nil(), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
933 |
syms.methodClass); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
934 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
935 |
Name metafactoryName = context.needsAltMetafactory() ? |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
936 |
names.altMetafactory : names.metafactory; |
16300 | 937 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
938 |
if (context.needsAltMetafactory()) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
939 |
ListBuffer<Object> markers = new ListBuffer<>(); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
940 |
for (Type t : tree.targets.tail) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
941 |
if (t.tsym != syms.serializableType.tsym) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
942 |
markers.append(t.tsym); |
16300 | 943 |
} |
944 |
} |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
945 |
int flags = context.isSerializable() ? FLAG_SERIALIZABLE : 0; |
16300 | 946 |
boolean hasMarkers = markers.nonEmpty(); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
947 |
boolean hasBridges = context.bridges.nonEmpty(); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
948 |
if (hasMarkers) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
949 |
flags |= FLAG_MARKERS; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
950 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
951 |
if (hasBridges) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
952 |
flags |= FLAG_BRIDGES; |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
953 |
} |
16300 | 954 |
staticArgs = staticArgs.append(flags); |
955 |
if (hasMarkers) { |
|
956 |
staticArgs = staticArgs.append(markers.length()); |
|
957 |
staticArgs = staticArgs.appendList(markers.toList()); |
|
958 |
} |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
959 |
if (hasBridges) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
960 |
staticArgs = staticArgs.append(context.bridges.length() - 1); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
961 |
for (Symbol s : context.bridges) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
962 |
Type s_erasure = s.erasure(types); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
963 |
if (!types.isSameType(s_erasure, samSym.erasure(types))) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
964 |
staticArgs = staticArgs.append(s.erasure(types)); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
965 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
966 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
967 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
968 |
if (context.isSerializable()) { |
16300 | 969 |
addDeserializationCase(refKind, refSym, tree.type, samSym, |
970 |
tree, staticArgs, indyType); |
|
971 |
} |
|
972 |
} |
|
973 |
||
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
974 |
return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args, samSym.name); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
975 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
976 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
977 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
978 |
* Generate an indy method call with given name, type and static bootstrap |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
979 |
* arguments types |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
980 |
*/ |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
981 |
private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName, |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
982 |
List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs, |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
983 |
Name methName) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
984 |
int prevPos = make.pos; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
985 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
986 |
make.at(pos); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
987 |
List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
988 |
syms.stringType, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
989 |
syms.methodTypeType).appendList(bsmStaticArgToTypes(staticArgs)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
990 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
991 |
Symbol bsm = rs.resolveInternalMethod(pos, attrEnv, site, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
992 |
bsmName, bsm_staticArgs, List.<Type>nil()); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
993 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
994 |
DynamicMethodSymbol dynSym = |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
995 |
new DynamicMethodSymbol(methName, |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
996 |
syms.noSymbol, |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
997 |
bsm.isStatic() ? |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
998 |
ClassFile.REF_invokeStatic : |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
999 |
ClassFile.REF_invokeVirtual, |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1000 |
(MethodSymbol)bsm, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1001 |
indyType, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1002 |
staticArgs.toArray()); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1003 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1004 |
JCFieldAccess qualifier = make.Select(make.QualIdent(site.tsym), bsmName); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1005 |
qualifier.sym = dynSym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1006 |
qualifier.type = indyType.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1007 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1008 |
JCMethodInvocation proxyCall = make.Apply(List.<JCExpression>nil(), qualifier, indyArgs); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1009 |
proxyCall.type = indyType.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1010 |
return proxyCall; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1011 |
} finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1012 |
make.at(prevPos); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1013 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1014 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1015 |
//where |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1016 |
private List<Type> bsmStaticArgToTypes(List<Object> args) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
1017 |
ListBuffer<Type> argtypes = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1018 |
for (Object arg : args) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1019 |
argtypes.append(bsmStaticArgToType(arg)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1020 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1021 |
return argtypes.toList(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1022 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1023 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1024 |
private Type bsmStaticArgToType(Object arg) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1025 |
Assert.checkNonNull(arg); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1026 |
if (arg instanceof ClassSymbol) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1027 |
return syms.classType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1028 |
} else if (arg instanceof Integer) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1029 |
return syms.intType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1030 |
} else if (arg instanceof Long) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1031 |
return syms.longType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1032 |
} else if (arg instanceof Float) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1033 |
return syms.floatType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1034 |
} else if (arg instanceof Double) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1035 |
return syms.doubleType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1036 |
} else if (arg instanceof String) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1037 |
return syms.stringType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1038 |
} else if (arg instanceof Pool.MethodHandle) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1039 |
return syms.methodHandleType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1040 |
} else if (arg instanceof MethodType) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1041 |
return syms.methodTypeType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1042 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1043 |
Assert.error("bad static arg " + arg.getClass()); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1044 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1045 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1046 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1047 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1048 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1049 |
* Get the opcode associated with this method reference |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1050 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1051 |
private int referenceKind(Symbol refSym) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1052 |
if (refSym.isConstructor()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1053 |
return ClassFile.REF_newInvokeSpecial; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1054 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1055 |
if (refSym.isStatic()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1056 |
return ClassFile.REF_invokeStatic; |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1057 |
} else if ((refSym.flags() & PRIVATE) != 0) { |
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1058 |
return ClassFile.REF_invokeSpecial; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1059 |
} else if (refSym.enclClass().isInterface()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1060 |
return ClassFile.REF_invokeInterface; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1061 |
} else { |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1062 |
return ClassFile.REF_invokeVirtual; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1063 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1064 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1065 |
} |
16300 | 1066 |
|
16564
061aa10703e8
8009649: Lambda back-end should generate invokespecial for method handles referring to private instance methods
mcimadamore
parents:
16551
diff
changeset
|
1067 |
// <editor-fold defaultstate="collapsed" desc="Lambda/reference analyzer"> |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1068 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1069 |
* This visitor collects information about translation of a lambda expression. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1070 |
* More specifically, it keeps track of the enclosing contexts and captured locals |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1071 |
* accessed by the lambda being translated (as well as other useful info). |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1072 |
* It also translates away problems for LambdaToMethod. |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1073 |
*/ |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1074 |
class LambdaAnalyzerPreprocessor extends TreeTranslator { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1075 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1076 |
/** the frame stack - used to reconstruct translation info about enclosing scopes */ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1077 |
private List<Frame> frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1078 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1079 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1080 |
* keep the count of lambda expression (used to generate unambiguous |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1081 |
* names) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1082 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1083 |
private int lambdaCount = 0; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1084 |
|
16300 | 1085 |
/** |
1086 |
* keep the count of lambda expression defined in given context (used to |
|
1087 |
* generate unambiguous names for serializable lambdas) |
|
1088 |
*/ |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1089 |
private class SyntheticMethodNameCounter { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1090 |
private Map<String, Integer> map = new HashMap<>(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1091 |
int getIndex(StringBuilder buf) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1092 |
String temp = buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1093 |
Integer count = map.get(temp); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1094 |
if (count == null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1095 |
count = 0; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1096 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1097 |
++count; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1098 |
map.put(temp, count); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1099 |
return count; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1100 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1101 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1102 |
private SyntheticMethodNameCounter syntheticMethodNameCounts = |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1103 |
new SyntheticMethodNameCounter(); |
16300 | 1104 |
|
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1105 |
private Map<Symbol, JCClassDecl> localClassDefs; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1106 |
|
16300 | 1107 |
/** |
1108 |
* maps for fake clinit symbols to be used as owners of lambda occurring in |
|
1109 |
* a static var init context |
|
1110 |
*/ |
|
1111 |
private Map<ClassSymbol, Symbol> clinits = |
|
1112 |
new HashMap<ClassSymbol, Symbol>(); |
|
1113 |
||
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1114 |
private JCClassDecl analyzeAndPreprocessClass(JCClassDecl tree) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1115 |
frameStack = List.nil(); |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1116 |
localClassDefs = new HashMap<Symbol, JCClassDecl>(); |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1117 |
return translate(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1118 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1119 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1120 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1121 |
public void visitBlock(JCBlock tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1122 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1123 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1124 |
if (frameStack.nonEmpty() && frameStack.head.tree.hasTag(CLASSDEF)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1125 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1126 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1127 |
super.visitBlock(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1128 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1129 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1130 |
frameStack = prevStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1131 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1132 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1133 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1134 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1135 |
public void visitClassDef(JCClassDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1136 |
List<Frame> prevStack = frameStack; |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1137 |
SyntheticMethodNameCounter prevSyntheticMethodNameCounts = |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1138 |
syntheticMethodNameCounts; |
16300 | 1139 |
Map<ClassSymbol, Symbol> prevClinits = clinits; |
18386 | 1140 |
DiagnosticSource prevSource = log.currentSource(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1141 |
try { |
18386 | 1142 |
log.useSource(tree.sym.sourcefile); |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1143 |
syntheticMethodNameCounts = new SyntheticMethodNameCounter(); |
16300 | 1144 |
prevClinits = new HashMap<ClassSymbol, Symbol>(); |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1145 |
if (tree.sym.owner.kind == MTH) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1146 |
localClassDefs.put(tree.sym, tree); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1147 |
} |
16300 | 1148 |
if (directlyEnclosingLambda() != null) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1149 |
tree.sym.owner = owner(); |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1150 |
if (tree.sym.hasOuterInstance()) { |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1151 |
//if a class is defined within a lambda, the lambda must capture |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1152 |
//its enclosing instance (if any) |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1153 |
TranslationContext<?> localContext = context(); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1154 |
while (localContext != null) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1155 |
if (localContext.tree.getTag() == LAMBDA) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1156 |
((LambdaTranslationContext)localContext) |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1157 |
.addSymbol(tree.sym.type.getEnclosingType().tsym, CAPTURED_THIS); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1158 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1159 |
localContext = localContext.prev; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1160 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1161 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1162 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1163 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1164 |
super.visitClassDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1165 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1166 |
finally { |
18386 | 1167 |
log.useSource(prevSource.getFile()); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1168 |
frameStack = prevStack; |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1169 |
syntheticMethodNameCounts = prevSyntheticMethodNameCounts; |
16300 | 1170 |
clinits = prevClinits; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1171 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1172 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1173 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1174 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1175 |
public void visitIdent(JCIdent tree) { |
16300 | 1176 |
if (context() != null && lambdaIdentSymbolFilter(tree.sym)) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1177 |
if (tree.sym.kind == VAR && |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1178 |
tree.sym.owner.kind == MTH && |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1179 |
tree.type.constValue() == null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1180 |
TranslationContext<?> localContext = context(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1181 |
while (localContext != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1182 |
if (localContext.tree.getTag() == LAMBDA) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1183 |
JCTree block = capturedDecl(localContext.depth, tree.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1184 |
if (block == null) break; |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1185 |
((LambdaTranslationContext)localContext) |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1186 |
.addSymbol(tree.sym, CAPTURED_VAR); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1187 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1188 |
localContext = localContext.prev; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1189 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1190 |
} else if (tree.sym.owner.kind == TYP) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1191 |
TranslationContext<?> localContext = context(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1192 |
while (localContext != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1193 |
if (localContext.tree.hasTag(LAMBDA)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1194 |
JCTree block = capturedDecl(localContext.depth, tree.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1195 |
if (block == null) break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1196 |
switch (block.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1197 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1198 |
JCClassDecl cdecl = (JCClassDecl)block; |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1199 |
((LambdaTranslationContext)localContext) |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1200 |
.addSymbol(cdecl.sym, CAPTURED_THIS); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1201 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1202 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1203 |
Assert.error("bad block kind"); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1204 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1205 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1206 |
localContext = localContext.prev; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1207 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1208 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1209 |
} |
16300 | 1210 |
super.visitIdent(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1211 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1212 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1213 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1214 |
public void visitLambda(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1215 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1216 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1217 |
LambdaTranslationContext context = (LambdaTranslationContext)makeLambdaContext(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1218 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1219 |
for (JCVariableDecl param : tree.params) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1220 |
context.addSymbol(param.sym, PARAM); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1221 |
frameStack.head.addLocal(param.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1222 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1223 |
contextMap.put(tree, context); |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1224 |
super.visitLambda(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1225 |
context.complete(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1226 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1227 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1228 |
frameStack = prevStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1229 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1230 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1231 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1232 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1233 |
public void visitMethodDef(JCMethodDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1234 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1235 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1236 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1237 |
super.visitMethodDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1238 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1239 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1240 |
frameStack = prevStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1241 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1242 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1243 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1244 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1245 |
public void visitNewClass(JCNewClass tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1246 |
if (lambdaNewClassFilter(context(), tree)) { |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1247 |
TranslationContext<?> localContext = context(); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1248 |
while (localContext != null) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1249 |
if (localContext.tree.getTag() == LAMBDA) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1250 |
((LambdaTranslationContext)localContext) |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1251 |
.addSymbol(tree.type.getEnclosingType().tsym, CAPTURED_THIS); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1252 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1253 |
localContext = localContext.prev; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1254 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1255 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1256 |
if (context() != null && tree.type.tsym.owner.kind == MTH) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1257 |
LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1258 |
captureLocalClassDefs(tree.type.tsym, lambdaContext); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1259 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1260 |
super.visitNewClass(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1261 |
} |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1262 |
//where |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1263 |
void captureLocalClassDefs(Symbol csym, final LambdaTranslationContext lambdaContext) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1264 |
JCClassDecl localCDef = localClassDefs.get(csym); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1265 |
if (localCDef != null && localCDef.pos < lambdaContext.tree.pos) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1266 |
BasicFreeVarCollector fvc = lower.new BasicFreeVarCollector() { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1267 |
@Override |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1268 |
void addFreeVars(ClassSymbol c) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1269 |
captureLocalClassDefs(c, lambdaContext); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1270 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1271 |
@Override |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1272 |
void visitSymbol(Symbol sym) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1273 |
if (sym.kind == VAR && |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1274 |
sym.owner.kind == MTH && |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1275 |
((VarSymbol)sym).getConstValue() == null) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1276 |
TranslationContext<?> localContext = context(); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1277 |
while (localContext != null) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1278 |
if (localContext.tree.getTag() == LAMBDA) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1279 |
JCTree block = capturedDecl(localContext.depth, sym); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1280 |
if (block == null) break; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1281 |
((LambdaTranslationContext)localContext).addSymbol(sym, CAPTURED_VAR); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1282 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1283 |
localContext = localContext.prev; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1284 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1285 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1286 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1287 |
}; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1288 |
fvc.scan(localCDef); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1289 |
} |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1290 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1291 |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1292 |
/** |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1293 |
* Method references to local class constructors, may, if the local |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1294 |
* class references local variables, have implicit constructor |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1295 |
* parameters added in Lower; As a result, the invokedynamic bootstrap |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1296 |
* information added in the LambdaToMethod pass will have the wrong |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1297 |
* signature. Hooks between Lower and LambdaToMethod have been added to |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1298 |
* handle normal "new" in this case. This visitor converts potentially |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1299 |
* effected method references into a lambda containing a normal "new" of |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1300 |
* the class. |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1301 |
* |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1302 |
* @param tree |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1303 |
*/ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1304 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1305 |
public void visitReference(JCMemberReference tree) { |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1306 |
if (tree.getMode() == ReferenceMode.NEW |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1307 |
&& tree.kind != ReferenceKind.ARRAY_CTOR |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1308 |
&& tree.sym.owner.isLocal()) { |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1309 |
MethodSymbol consSym = (MethodSymbol) tree.sym; |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1310 |
List<Type> ptypes = ((MethodType) consSym.type).getParameterTypes(); |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1311 |
Type classType = consSym.owner.type; |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1312 |
|
17550
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1313 |
// Build lambda parameters |
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1314 |
// partially cloned from TreeMaker.Params until 8014021 is fixed |
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1315 |
Symbol owner = owner(); |
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1316 |
ListBuffer<JCVariableDecl> paramBuff = new ListBuffer<JCVariableDecl>(); |
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1317 |
int i = 0; |
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1318 |
for (List<Type> l = ptypes; l.nonEmpty(); l = l.tail) { |
21477 | 1319 |
JCVariableDecl param = make.Param(make.paramName(i++), l.head, owner); |
1320 |
param.sym.pos = tree.pos; |
|
1321 |
paramBuff.append(param); |
|
17550
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1322 |
} |
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1323 |
List<JCVariableDecl> params = paramBuff.toList(); |
567df1379253
8014023: When a method reference to a local class constructor is contained in a method whose number of parameters matches the number of constructor parameters compilation fails
rfield
parents:
17286
diff
changeset
|
1324 |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1325 |
// Make new-class call |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1326 |
JCNewClass nc = makeNewClass(classType, make.Idents(params)); |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1327 |
nc.pos = tree.pos; |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1328 |
|
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1329 |
// Make lambda holding the new-class call |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1330 |
JCLambda slam = make.Lambda(params, nc); |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1331 |
slam.targets = tree.targets; |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1332 |
slam.type = tree.type; |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1333 |
slam.pos = tree.pos; |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1334 |
|
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1335 |
// Now it is a lambda, process as such |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1336 |
visitLambda(slam); |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1337 |
} else { |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1338 |
super.visitReference(tree); |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1339 |
contextMap.put(tree, makeReferenceContext(tree)); |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1340 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1341 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1342 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1343 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1344 |
public void visitSelect(JCFieldAccess tree) { |
17585
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1345 |
if (context() != null && tree.sym.kind == VAR && |
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1346 |
(tree.sym.name == names._this || |
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1347 |
tree.sym.name == names._super)) { |
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1348 |
// A select of this or super means, if we are in a lambda, |
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1349 |
// we much have an instance context |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1350 |
TranslationContext<?> localContext = context(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1351 |
while (localContext != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1352 |
if (localContext.tree.hasTag(LAMBDA)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1353 |
JCClassDecl clazz = (JCClassDecl)capturedDecl(localContext.depth, tree.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1354 |
if (clazz == null) break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1355 |
((LambdaTranslationContext)localContext).addSymbol(clazz.sym, CAPTURED_THIS); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1356 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1357 |
localContext = localContext.prev; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1358 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1359 |
} |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1360 |
super.visitSelect(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1361 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1362 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1363 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1364 |
public void visitVarDef(JCVariableDecl tree) { |
16300 | 1365 |
TranslationContext<?> context = context(); |
1366 |
LambdaTranslationContext ltc = (context != null && context instanceof LambdaTranslationContext)? |
|
1367 |
(LambdaTranslationContext)context : |
|
1368 |
null; |
|
1369 |
if (ltc != null) { |
|
1370 |
if (frameStack.head.tree.hasTag(LAMBDA)) { |
|
1371 |
ltc.addSymbol(tree.sym, LOCAL_VAR); |
|
1372 |
} |
|
1373 |
// Check for type variables (including as type arguments). |
|
1374 |
// If they occur within class nested in a lambda, mark for erasure |
|
1375 |
Type type = tree.sym.asType(); |
|
1376 |
if (inClassWithinLambda() && !types.isSameType(types.erasure(type), type)) { |
|
1377 |
ltc.addSymbol(tree.sym, TYPE_VAR); |
|
1378 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1379 |
} |
16300 | 1380 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1381 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1382 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1383 |
if (tree.sym.owner.kind == MTH) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1384 |
frameStack.head.addLocal(tree.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1385 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1386 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1387 |
super.visitVarDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1388 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1389 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1390 |
frameStack = prevStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1391 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1392 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1393 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1394 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1395 |
* Return a valid owner given the current declaration stack |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1396 |
* (required to skip synthetic lambda symbols) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1397 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1398 |
private Symbol owner() { |
15379
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1399 |
return owner(false); |
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1400 |
} |
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1401 |
|
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1402 |
@SuppressWarnings("fallthrough") |
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1403 |
private Symbol owner(boolean skipLambda) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1404 |
List<Frame> frameStack2 = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1405 |
while (frameStack2.nonEmpty()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1406 |
switch (frameStack2.head.tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1407 |
case VARDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1408 |
if (((JCVariableDecl)frameStack2.head.tree).sym.isLocal()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1409 |
frameStack2 = frameStack2.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1410 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1411 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1412 |
JCClassDecl cdecl = (JCClassDecl)frameStack2.tail.head.tree; |
16300 | 1413 |
return initSym(cdecl.sym, |
1414 |
((JCVariableDecl)frameStack2.head.tree).sym.flags() & STATIC); |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1415 |
case BLOCK: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1416 |
JCClassDecl cdecl2 = (JCClassDecl)frameStack2.tail.head.tree; |
16300 | 1417 |
return initSym(cdecl2.sym, |
1418 |
((JCBlock)frameStack2.head.tree).flags & STATIC); |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1419 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1420 |
return ((JCClassDecl)frameStack2.head.tree).sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1421 |
case METHODDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1422 |
return ((JCMethodDecl)frameStack2.head.tree).sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1423 |
case LAMBDA: |
15379
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1424 |
if (!skipLambda) |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1425 |
return ((LambdaTranslationContext)contextMap |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1426 |
.get(frameStack2.head.tree)).translatedSym; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1427 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1428 |
frameStack2 = frameStack2.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1429 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1430 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1431 |
Assert.error(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1432 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1433 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1434 |
|
16300 | 1435 |
private Symbol initSym(ClassSymbol csym, long flags) { |
1436 |
boolean isStatic = (flags & STATIC) != 0; |
|
1437 |
if (isStatic) { |
|
1438 |
//static clinits are generated in Gen - so we need to fake them |
|
1439 |
Symbol clinit = clinits.get(csym); |
|
1440 |
if (clinit == null) { |
|
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1441 |
clinit = makePrivateSyntheticMethod(STATIC, |
16300 | 1442 |
names.clinit, |
1443 |
new MethodType(List.<Type>nil(), syms.voidType, List.<Type>nil(), syms.methodClass), |
|
1444 |
csym); |
|
1445 |
clinits.put(csym, clinit); |
|
1446 |
} |
|
1447 |
return clinit; |
|
1448 |
} else { |
|
1449 |
//get the first constructor and treat it as the instance init sym |
|
1450 |
for (Symbol s : csym.members_field.getElementsByName(names.init)) { |
|
1451 |
return s; |
|
1452 |
} |
|
1453 |
} |
|
1454 |
Assert.error("init not found"); |
|
1455 |
return null; |
|
1456 |
} |
|
1457 |
||
1458 |
private JCTree directlyEnclosingLambda() { |
|
1459 |
if (frameStack.isEmpty()) { |
|
1460 |
return null; |
|
1461 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1462 |
List<Frame> frameStack2 = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1463 |
while (frameStack2.nonEmpty()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1464 |
switch (frameStack2.head.tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1465 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1466 |
case METHODDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1467 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1468 |
case LAMBDA: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1469 |
return frameStack2.head.tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1470 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1471 |
frameStack2 = frameStack2.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1472 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1473 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1474 |
Assert.error(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1475 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1476 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1477 |
|
16300 | 1478 |
private boolean inClassWithinLambda() { |
1479 |
if (frameStack.isEmpty()) { |
|
1480 |
return false; |
|
1481 |
} |
|
1482 |
List<Frame> frameStack2 = frameStack; |
|
1483 |
boolean classFound = false; |
|
1484 |
while (frameStack2.nonEmpty()) { |
|
1485 |
switch (frameStack2.head.tree.getTag()) { |
|
1486 |
case LAMBDA: |
|
1487 |
return classFound; |
|
1488 |
case CLASSDEF: |
|
1489 |
classFound = true; |
|
1490 |
frameStack2 = frameStack2.tail; |
|
1491 |
break; |
|
1492 |
default: |
|
1493 |
frameStack2 = frameStack2.tail; |
|
1494 |
} |
|
1495 |
} |
|
1496 |
// No lambda |
|
1497 |
return false; |
|
1498 |
} |
|
1499 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1500 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1501 |
* Return the declaration corresponding to a symbol in the enclosing |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1502 |
* scope; the depth parameter is used to filter out symbols defined |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1503 |
* in nested scopes (which do not need to undergo capture). |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1504 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1505 |
private JCTree capturedDecl(int depth, Symbol sym) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1506 |
int currentDepth = frameStack.size() - 1; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1507 |
for (Frame block : frameStack) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1508 |
switch (block.tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1509 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1510 |
ClassSymbol clazz = ((JCClassDecl)block.tree).sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1511 |
if (sym.isMemberOf(clazz, types)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1512 |
return currentDepth > depth ? null : block.tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1513 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1514 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1515 |
case VARDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1516 |
if (((JCVariableDecl)block.tree).sym == sym && |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1517 |
sym.owner.kind == MTH) { //only locals are captured |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1518 |
return currentDepth > depth ? null : block.tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1519 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1520 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1521 |
case BLOCK: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1522 |
case METHODDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1523 |
case LAMBDA: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1524 |
if (block.locals != null && block.locals.contains(sym)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1525 |
return currentDepth > depth ? null : block.tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1526 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1527 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1528 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1529 |
Assert.error("bad decl kind " + block.tree.getTag()); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1530 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1531 |
currentDepth--; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1532 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1533 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1534 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1535 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1536 |
private TranslationContext<?> context() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1537 |
for (Frame frame : frameStack) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1538 |
TranslationContext<?> context = contextMap.get(frame.tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1539 |
if (context != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1540 |
return context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1541 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1542 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1543 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1544 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1545 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1546 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1547 |
* This is used to filter out those identifiers that needs to be adjusted |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1548 |
* when translating away lambda expressions |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1549 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1550 |
private boolean lambdaIdentSymbolFilter(Symbol sym) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1551 |
return (sym.kind == VAR || sym.kind == MTH) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1552 |
&& !sym.isStatic() |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1553 |
&& sym.name != names.init; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1554 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1555 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1556 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1557 |
* This is used to filter out those new class expressions that need to |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1558 |
* be qualified with an enclosing tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1559 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1560 |
private boolean lambdaNewClassFilter(TranslationContext<?> context, JCNewClass tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1561 |
if (context != null |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1562 |
&& tree.encl == null |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1563 |
&& tree.def == null |
14537
ad188879b6fe
8003306: Compiler crash: calculation of inner class access modifier
rfield
parents:
14365
diff
changeset
|
1564 |
&& !tree.type.getEnclosingType().hasTag(NONE)) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1565 |
Type encl = tree.type.getEnclosingType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1566 |
Type current = context.owner.enclClass().type; |
14537
ad188879b6fe
8003306: Compiler crash: calculation of inner class access modifier
rfield
parents:
14365
diff
changeset
|
1567 |
while (!current.hasTag(NONE)) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1568 |
if (current.tsym.isSubClass(encl.tsym, types)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1569 |
return true; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1570 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1571 |
current = current.getEnclosingType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1572 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1573 |
return false; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1574 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1575 |
return false; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1576 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1577 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1578 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1579 |
private TranslationContext<JCLambda> makeLambdaContext(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1580 |
return new LambdaTranslationContext(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1581 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1582 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1583 |
private TranslationContext<JCMemberReference> makeReferenceContext(JCMemberReference tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1584 |
return new ReferenceTranslationContext(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1585 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1586 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1587 |
private class Frame { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1588 |
final JCTree tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1589 |
List<Symbol> locals; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1590 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1591 |
public Frame(JCTree tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1592 |
this.tree = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1593 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1594 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1595 |
void addLocal(Symbol sym) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1596 |
if (locals == null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1597 |
locals = List.nil(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1598 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1599 |
locals = locals.prepend(sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1600 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1601 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1602 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1603 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1604 |
* This class is used to store important information regarding translation of |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1605 |
* lambda expression/method references (see subclasses). |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1606 |
*/ |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15360
diff
changeset
|
1607 |
private abstract class TranslationContext<T extends JCFunctionalExpression> { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1608 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1609 |
/** the underlying (untranslated) tree */ |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1610 |
final T tree; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1611 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1612 |
/** points to the adjusted enclosing scope in which this lambda/mref expression occurs */ |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1613 |
final Symbol owner; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1614 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1615 |
/** the depth of this lambda expression in the frame stack */ |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1616 |
final int depth; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1617 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1618 |
/** the enclosing translation context (set for nested lambdas/mref) */ |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1619 |
final TranslationContext<?> prev; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1620 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1621 |
/** list of methods to be bridged by the meta-factory */ |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1622 |
final List<Symbol> bridges; |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1623 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1624 |
TranslationContext(T tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1625 |
this.tree = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1626 |
this.owner = owner(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1627 |
this.depth = frameStack.size() - 1; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1628 |
this.prev = context(); |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1629 |
ClassSymbol csym = |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1630 |
types.makeFunctionalInterfaceClass(attrEnv, names.empty, tree.targets, ABSTRACT | INTERFACE); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1631 |
this.bridges = types.functionalInterfaceBridges(csym); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1632 |
} |
16300 | 1633 |
|
1634 |
/** does this functional expression need to be created using alternate metafactory? */ |
|
1635 |
boolean needsAltMetafactory() { |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1636 |
return tree.targets.length() > 1 || |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1637 |
isSerializable() || |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1638 |
bridges.length() > 1; |
16300 | 1639 |
} |
1640 |
||
1641 |
/** does this functional expression require serialization support? */ |
|
1642 |
boolean isSerializable() { |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1643 |
for (Type target : tree.targets) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1644 |
if (types.asSuper(target, syms.serializableType.tsym) != null) { |
16300 | 1645 |
return true; |
1646 |
} |
|
1647 |
} |
|
1648 |
return false; |
|
1649 |
} |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1650 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1651 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1652 |
* @return Name of the enclosing method to be folded into synthetic |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1653 |
* method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1654 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1655 |
String enclosingMethodName() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1656 |
return syntheticMethodNameComponent(owner.name); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1657 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1658 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1659 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1660 |
* @return Method name in a form that can be folded into a |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1661 |
* component of a synthetic method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1662 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1663 |
String syntheticMethodNameComponent(Name name) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1664 |
if (name == null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1665 |
return "null"; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1666 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1667 |
String methodName = name.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1668 |
if (methodName.equals("<clinit>")) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1669 |
methodName = "static"; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1670 |
} else if (methodName.equals("<init>")) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1671 |
methodName = "new"; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1672 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1673 |
return methodName; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1674 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1675 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1676 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1677 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1678 |
* This class retains all the useful information about a lambda expression; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1679 |
* the contents of this class are filled by the LambdaAnalyzer visitor, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1680 |
* and the used by the main translation routines in order to adjust references |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1681 |
* to captured locals/members, etc. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1682 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1683 |
private class LambdaTranslationContext extends TranslationContext<JCLambda> { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1684 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1685 |
/** variable in the enclosing context to which this lambda is assigned */ |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1686 |
final Symbol self; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1687 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1688 |
/** variable in the enclosing context to which this lambda is assigned */ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1689 |
final Symbol assignedTo; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1690 |
|
21486 | 1691 |
Map<LambdaSymbolKind, Map<Symbol, Symbol>> translatedSymbols; |
16300 | 1692 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1693 |
/** the synthetic symbol for the method hoisting the translated lambda */ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1694 |
Symbol translatedSym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1695 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1696 |
List<JCVariableDecl> syntheticParams; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1697 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1698 |
LambdaTranslationContext(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1699 |
super(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1700 |
Frame frame = frameStack.head; |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1701 |
switch (frame.tree.getTag()) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1702 |
case VARDEF: |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1703 |
assignedTo = self = ((JCVariableDecl) frame.tree).sym; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1704 |
break; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1705 |
case ASSIGN: |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1706 |
self = null; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1707 |
assignedTo = TreeInfo.symbol(((JCAssign) frame.tree).getVariable()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1708 |
break; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1709 |
default: |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1710 |
assignedTo = self = null; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1711 |
break; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1712 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1713 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1714 |
// This symbol will be filled-in in complete |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1715 |
this.translatedSym = makePrivateSyntheticMethod(0, null, null, owner.enclClass()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1716 |
|
18386 | 1717 |
if (dumpLambdaToMethodStats) { |
1718 |
log.note(tree, "lambda.stat", needsAltMetafactory(), translatedSym); |
|
1719 |
} |
|
21486 | 1720 |
translatedSymbols = new EnumMap<>(LambdaSymbolKind.class); |
1721 |
||
1722 |
translatedSymbols.put(PARAM, new LinkedHashMap<Symbol, Symbol>()); |
|
1723 |
translatedSymbols.put(LOCAL_VAR, new LinkedHashMap<Symbol, Symbol>()); |
|
1724 |
translatedSymbols.put(CAPTURED_VAR, new LinkedHashMap<Symbol, Symbol>()); |
|
1725 |
translatedSymbols.put(CAPTURED_THIS, new LinkedHashMap<Symbol, Symbol>()); |
|
1726 |
translatedSymbols.put(TYPE_VAR, new LinkedHashMap<Symbol, Symbol>()); |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1727 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1728 |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1729 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1730 |
* For a serializable lambda, generate a disambiguating string |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1731 |
* which maximizes stability across deserialization. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1732 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1733 |
* @return String to differentiate synthetic lambda method names |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1734 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1735 |
private String serializedLambdaDisambiguation() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1736 |
StringBuilder buf = new StringBuilder(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1737 |
// Append the enclosing method signature to differentiate |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1738 |
// overloaded enclosing methods. For lambdas enclosed in |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1739 |
// lambdas, the generated lambda method will not have type yet, |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1740 |
// but the enclosing method's name will have been generated |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1741 |
// with this same method, so it will be unique and never be |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1742 |
// overloaded. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1743 |
Assert.check( |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1744 |
owner.type != null || |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1745 |
directlyEnclosingLambda() != null); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1746 |
if (owner.type != null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1747 |
buf.append(typeSig(owner.type)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1748 |
buf.append(":"); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1749 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1750 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1751 |
// Add target type info |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1752 |
buf.append(types.findDescriptorSymbol(tree.type.tsym).owner.flatName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1753 |
buf.append(" "); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1754 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1755 |
// Add variable assigned to |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1756 |
if (assignedTo != null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1757 |
buf.append(assignedTo.flatName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1758 |
buf.append("="); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1759 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1760 |
//add captured locals info: type, name, order |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1761 |
for (Symbol fv : getSymbolMap(CAPTURED_VAR).keySet()) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1762 |
if (fv != self) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1763 |
buf.append(typeSig(fv.type)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1764 |
buf.append(" "); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1765 |
buf.append(fv.flatName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1766 |
buf.append(","); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1767 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1768 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1769 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1770 |
return buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1771 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1772 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1773 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1774 |
* For a non-serializable lambda, generate a simple method. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1775 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1776 |
* @return Name to use for the synthetic lambda method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1777 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1778 |
private Name lambdaName() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1779 |
return names.lambda.append(names.fromString(enclosingMethodName() + "$" + lambdaCount++)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1780 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1781 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1782 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1783 |
* For a serializable lambda, generate a method name which maximizes |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1784 |
* name stability across deserialization. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1785 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1786 |
* @return Name to use for the synthetic lambda method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1787 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1788 |
private Name serializedLambdaName() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1789 |
StringBuilder buf = new StringBuilder(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1790 |
buf.append(names.lambda); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1791 |
// Append the name of the method enclosing the lambda. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1792 |
buf.append(enclosingMethodName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1793 |
buf.append('$'); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1794 |
// Append a hash of the disambiguating string : enclosing method |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1795 |
// signature, etc. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1796 |
String disam = serializedLambdaDisambiguation(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1797 |
buf.append(Integer.toHexString(disam.hashCode())); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1798 |
buf.append('$'); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1799 |
// The above appended name components may not be unique, append |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1800 |
// a count based on the above name components. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1801 |
buf.append(syntheticMethodNameCounts.getIndex(buf)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1802 |
String result = buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1803 |
//System.err.printf("serializedLambdaName: %s -- %s\n", result, disam); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1804 |
return names.fromString(result); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1805 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1806 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1807 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1808 |
* Translate a symbol of a given kind into something suitable for the |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1809 |
* synthetic lambda body |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1810 |
*/ |
16564
061aa10703e8
8009649: Lambda back-end should generate invokespecial for method handles referring to private instance methods
mcimadamore
parents:
16551
diff
changeset
|
1811 |
Symbol translate(Name name, final Symbol sym, LambdaSymbolKind skind) { |
17578 | 1812 |
Symbol ret; |
16300 | 1813 |
switch (skind) { |
1814 |
case CAPTURED_THIS: |
|
17578 | 1815 |
ret = sym; // self represented |
1816 |
break; |
|
16300 | 1817 |
case TYPE_VAR: |
1818 |
// Just erase the type var |
|
17578 | 1819 |
ret = new VarSymbol(sym.flags(), name, |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1820 |
types.erasure(sym.type), sym.owner); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
1821 |
|
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
1822 |
/* this information should also be kept for LVT generation at Gen |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
1823 |
* a Symbol with pos < startPos won't be tracked. |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
1824 |
*/ |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
1825 |
((VarSymbol)ret).pos = ((VarSymbol)sym).pos; |
17578 | 1826 |
break; |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1827 |
case CAPTURED_VAR: |
21477 | 1828 |
ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym) { |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1829 |
@Override |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1830 |
public Symbol baseSymbol() { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1831 |
//keep mapping with original captured symbol |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1832 |
return sym; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1833 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1834 |
}; |
17578 | 1835 |
break; |
21477 | 1836 |
case LOCAL_VAR: |
1837 |
ret = new VarSymbol(FINAL, name, types.erasure(sym.type), translatedSym); |
|
1838 |
((VarSymbol) ret).pos = ((VarSymbol) sym).pos; |
|
1839 |
break; |
|
1840 |
case PARAM: |
|
1841 |
ret = new VarSymbol(FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym); |
|
1842 |
((VarSymbol) ret).pos = ((VarSymbol) sym).pos; |
|
1843 |
break; |
|
16300 | 1844 |
default: |
17578 | 1845 |
ret = makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym); |
21477 | 1846 |
((VarSymbol) ret).pos = ((VarSymbol) sym).pos; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1847 |
} |
17578 | 1848 |
if (ret != sym) { |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17585
diff
changeset
|
1849 |
ret.setDeclarationAttributes(sym.getRawAttributes()); |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17585
diff
changeset
|
1850 |
ret.setTypeAttributes(sym.getRawTypeAttributes()); |
17578 | 1851 |
} |
1852 |
return ret; |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1853 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1854 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1855 |
void addSymbol(Symbol sym, LambdaSymbolKind skind) { |
21486 | 1856 |
Map<Symbol, Symbol> transMap = getSymbolMap(skind); |
16564
061aa10703e8
8009649: Lambda back-end should generate invokespecial for method handles referring to private instance methods
mcimadamore
parents:
16551
diff
changeset
|
1857 |
Name preferredName; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1858 |
switch (skind) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1859 |
case CAPTURED_THIS: |
21486 | 1860 |
preferredName = names.fromString("encl$" + transMap.size()); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1861 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1862 |
case CAPTURED_VAR: |
21486 | 1863 |
preferredName = names.fromString("cap$" + transMap.size()); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1864 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1865 |
case LOCAL_VAR: |
16564
061aa10703e8
8009649: Lambda back-end should generate invokespecial for method handles referring to private instance methods
mcimadamore
parents:
16551
diff
changeset
|
1866 |
preferredName = sym.name; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1867 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1868 |
case PARAM: |
16564
061aa10703e8
8009649: Lambda back-end should generate invokespecial for method handles referring to private instance methods
mcimadamore
parents:
16551
diff
changeset
|
1869 |
preferredName = sym.name; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1870 |
break; |
16300 | 1871 |
case TYPE_VAR: |
16564
061aa10703e8
8009649: Lambda back-end should generate invokespecial for method handles referring to private instance methods
mcimadamore
parents:
16551
diff
changeset
|
1872 |
preferredName = sym.name; |
16300 | 1873 |
break; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1874 |
default: throw new AssertionError(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1875 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1876 |
if (!transMap.containsKey(sym)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1877 |
transMap.put(sym, translate(preferredName, sym, skind)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1878 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1879 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1880 |
|
21486 | 1881 |
Map<Symbol, Symbol> getSymbolMap(LambdaSymbolKind skind) { |
1882 |
Map<Symbol, Symbol> m = translatedSymbols.get(skind); |
|
1883 |
Assert.checkNonNull(m); |
|
1884 |
return m; |
|
1885 |
} |
|
1886 |
||
1887 |
JCTree translate(JCIdent lambdaIdent) { |
|
1888 |
for (Map<Symbol, Symbol> m : translatedSymbols.values()) { |
|
1889 |
if (m.containsKey(lambdaIdent.sym)) { |
|
1890 |
Symbol tSym = m.get(lambdaIdent.sym); |
|
1891 |
JCTree t = make.Ident(tSym).setType(lambdaIdent.type); |
|
1892 |
tSym.setTypeAttributes(lambdaIdent.sym.getRawTypeAttributes()); |
|
1893 |
return t; |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1894 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1895 |
} |
21486 | 1896 |
return null; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1897 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1898 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1899 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1900 |
* The translatedSym is not complete/accurate until the analysis is |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1901 |
* finished. Once the analysis is finished, the translatedSym is |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1902 |
* "completed" -- updated with type information, access modifiers, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1903 |
* and full parameter list. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1904 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1905 |
void complete() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1906 |
if (syntheticParams != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1907 |
return; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1908 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1909 |
boolean inInterface = translatedSym.owner.isInterface(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1910 |
boolean thisReferenced = !getSymbolMap(CAPTURED_THIS).isEmpty(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1911 |
|
17575
7693e6ff0d7d
8012556: Implement lambda methods on interfaces as static
rfield
parents:
17550
diff
changeset
|
1912 |
// If instance access isn't needed, make it static. |
7693e6ff0d7d
8012556: Implement lambda methods on interfaces as static
rfield
parents:
17550
diff
changeset
|
1913 |
// Interface instance methods must be default methods. |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1914 |
// Lambda methods are private synthetic. |
21477 | 1915 |
translatedSym.flags_field = SYNTHETIC | LAMBDA_METHOD | |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1916 |
PRIVATE | |
17575
7693e6ff0d7d
8012556: Implement lambda methods on interfaces as static
rfield
parents:
17550
diff
changeset
|
1917 |
(thisReferenced? (inInterface? DEFAULT : 0) : STATIC); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1918 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1919 |
//compute synthetic params |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
1920 |
ListBuffer<JCVariableDecl> params = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1921 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1922 |
// The signature of the method is augmented with the following |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1923 |
// synthetic parameters: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1924 |
// |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1925 |
// 1) reference to enclosing contexts captured by the lambda expression |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1926 |
// 2) enclosing locals captured by the lambda expression |
21486 | 1927 |
for (Symbol thisSym : getSymbolMap(CAPTURED_VAR).values()) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1928 |
params.append(make.VarDef((VarSymbol) thisSym, null)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1929 |
} |
21486 | 1930 |
for (Symbol thisSym : getSymbolMap(PARAM).values()) { |
1931 |
params.append(make.VarDef((VarSymbol) thisSym, null)); |
|
1932 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1933 |
syntheticParams = params.toList(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1934 |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1935 |
// Compute and set the lambda name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1936 |
translatedSym.name = isSerializable() |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1937 |
? serializedLambdaName() |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1938 |
: lambdaName(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1939 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1940 |
//prepend synthetic args to translated lambda method signature |
16300 | 1941 |
translatedSym.type = types.createMethodTypeWithParameters( |
1942 |
generatedLambdaSig(), |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1943 |
TreeInfo.types(syntheticParams)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1944 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1945 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1946 |
Type generatedLambdaSig() { |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1947 |
return types.erasure(tree.getDescriptorType(types)); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1948 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1949 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1950 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1951 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1952 |
* This class retains all the useful information about a method reference; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1953 |
* the contents of this class are filled by the LambdaAnalyzer visitor, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1954 |
* and the used by the main translation routines in order to adjust method |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1955 |
* references (i.e. in case a bridge is needed) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1956 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1957 |
private class ReferenceTranslationContext extends TranslationContext<JCMemberReference> { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1958 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1959 |
final boolean isSuper; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1960 |
final Symbol bridgeSym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1961 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1962 |
ReferenceTranslationContext(JCMemberReference tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1963 |
super(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1964 |
this.isSuper = tree.hasKind(ReferenceKind.SUPER); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1965 |
this.bridgeSym = needsBridge() |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1966 |
? makePrivateSyntheticMethod(isSuper ? 0 : STATIC, |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1967 |
referenceBridgeName(), null, |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1968 |
owner.enclClass()) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1969 |
: null; |
18386 | 1970 |
if (dumpLambdaToMethodStats) { |
1971 |
String key = bridgeSym == null ? |
|
1972 |
"mref.stat" : "mref.stat.1"; |
|
1973 |
log.note(tree, key, needsAltMetafactory(), bridgeSym); |
|
1974 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1975 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1976 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1977 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1978 |
* Get the opcode associated with this method reference |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1979 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1980 |
int referenceKind() { |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1981 |
return LambdaToMethod.this.referenceKind(needsBridge() |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1982 |
? bridgeSym |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1983 |
: tree.sym); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1984 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1985 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1986 |
boolean needsVarArgsConversion() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1987 |
return tree.varargsElement != null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1988 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1989 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1990 |
/** |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1991 |
* Generate a disambiguating string to increase stability (important |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1992 |
* if serialized) |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1993 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1994 |
* @return String to differentiate synthetic lambda method names |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1995 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1996 |
private String referenceBridgeDisambiguation() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1997 |
StringBuilder buf = new StringBuilder(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1998 |
// Append the enclosing method signature to differentiate |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1999 |
// overloaded enclosing methods. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2000 |
if (owner.type != null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2001 |
buf.append(typeSig(owner.type)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2002 |
buf.append(":"); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2003 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2004 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2005 |
// Append qualifier type |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2006 |
buf.append(classSig(tree.sym.owner.type)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2007 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2008 |
// Note static/instance |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2009 |
buf.append(tree.sym.isStatic()? " S " : " I "); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2010 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2011 |
// Append referenced signature |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2012 |
buf.append(typeSig(tree.sym.erasure(types))); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2013 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2014 |
return buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2015 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2016 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2017 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2018 |
* Construct a unique stable name for the method reference bridge |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2019 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2020 |
* @return Name to use for the synthetic method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2021 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2022 |
private Name referenceBridgeName() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2023 |
StringBuilder buf = new StringBuilder(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2024 |
// Append lambda ID, this is semantically significant |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2025 |
buf.append(names.lambda); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2026 |
// Note that it is a method reference bridge |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2027 |
buf.append("MR$"); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2028 |
// Append the enclosing method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2029 |
buf.append(enclosingMethodName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2030 |
buf.append('$'); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2031 |
// Append the referenced method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2032 |
buf.append(syntheticMethodNameComponent(tree.sym.name)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2033 |
buf.append('$'); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2034 |
// Append a hash of the disambiguating string : enclosing method |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2035 |
// signature, etc. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2036 |
String disam = referenceBridgeDisambiguation(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2037 |
buf.append(Integer.toHexString(disam.hashCode())); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2038 |
buf.append('$'); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2039 |
// The above appended name components may not be unique, append |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2040 |
// a count based on the above name components. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2041 |
buf.append(syntheticMethodNameCounts.getIndex(buf)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2042 |
String result = buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2043 |
return names.fromString(result); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2044 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2045 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2046 |
/** |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2047 |
* @return Is this an array operation like clone() |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2048 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2049 |
boolean isArrayOp() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2050 |
return tree.sym.owner == syms.arrayClass; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2051 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2052 |
|
16310
af1565438e63
8005183: Missing accessor for constructor reference pointing to private inner class ctor
mcimadamore
parents:
16308
diff
changeset
|
2053 |
boolean isPrivateConstructor() { |
16328
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2054 |
//hack needed to workaround 292 bug (8005122) |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2055 |
//when 292 issue is fixed we should simply remove this |
16310
af1565438e63
8005183: Missing accessor for constructor reference pointing to private inner class ctor
mcimadamore
parents:
16308
diff
changeset
|
2056 |
return tree.sym.name == names.init && |
af1565438e63
8005183: Missing accessor for constructor reference pointing to private inner class ctor
mcimadamore
parents:
16308
diff
changeset
|
2057 |
(tree.sym.flags() & PRIVATE) != 0; |
af1565438e63
8005183: Missing accessor for constructor reference pointing to private inner class ctor
mcimadamore
parents:
16308
diff
changeset
|
2058 |
} |
af1565438e63
8005183: Missing accessor for constructor reference pointing to private inner class ctor
mcimadamore
parents:
16308
diff
changeset
|
2059 |
|
16328
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2060 |
boolean receiverAccessible() { |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2061 |
//hack needed to workaround 292 bug (7087658) |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2062 |
//when 292 issue is fixed we should remove this and change the backend |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2063 |
//code to always generate a method handle to an accessible method |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2064 |
return tree.ownerAccessible; |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2065 |
} |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2066 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2067 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2068 |
* Does this reference needs a bridge (i.e. var args need to be |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2069 |
* expanded or "super" is used) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2070 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2071 |
final boolean needsBridge() { |
16328
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2072 |
return isSuper || needsVarArgsConversion() || isArrayOp() || |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2073 |
isPrivateConstructor() || !receiverAccessible(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2074 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2075 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2076 |
Type generatedRefSig() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2077 |
return types.erasure(tree.sym.type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2078 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2079 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2080 |
Type bridgedRefSig() { |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
2081 |
return types.erasure(types.findDescriptorSymbol(tree.targets.head.tsym).type); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2082 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2083 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2084 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2085 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2086 |
|
21486 | 2087 |
/* |
2088 |
* These keys provide mappings for various translated lambda symbols |
|
2089 |
* and the prevailing order must be maintained. |
|
2090 |
*/ |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2091 |
enum LambdaSymbolKind { |
21486 | 2092 |
PARAM, // original to translated lambda parameters |
2093 |
LOCAL_VAR, // original to translated lambda locals |
|
2094 |
CAPTURED_VAR, // variables in enclosing scope to translated synthetic parameters |
|
2095 |
CAPTURED_THIS, // class symbols to translated synthetic parameters (for captured member access) |
|
2096 |
TYPE_VAR; // original to translated lambda type variables |
|
16300 | 2097 |
} |
2098 |
||
2099 |
/** |
|
2100 |
* **************************************************************** |
|
2101 |
* Signature Generation |
|
2102 |
* **************************************************************** |
|
2103 |
*/ |
|
2104 |
||
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2105 |
private String typeSig(Type type) { |
16300 | 2106 |
L2MSignatureGenerator sg = new L2MSignatureGenerator(); |
2107 |
sg.assembleSig(type); |
|
2108 |
return sg.toString(); |
|
2109 |
} |
|
2110 |
||
2111 |
private String classSig(Type type) { |
|
2112 |
L2MSignatureGenerator sg = new L2MSignatureGenerator(); |
|
2113 |
sg.assembleClassSig(type); |
|
2114 |
return sg.toString(); |
|
2115 |
} |
|
2116 |
||
2117 |
/** |
|
2118 |
* Signature Generation |
|
2119 |
*/ |
|
2120 |
private class L2MSignatureGenerator extends Types.SignatureGenerator { |
|
2121 |
||
2122 |
/** |
|
2123 |
* An output buffer for type signatures. |
|
2124 |
*/ |
|
2125 |
StringBuilder sb = new StringBuilder(); |
|
2126 |
||
2127 |
L2MSignatureGenerator() { |
|
2128 |
super(types); |
|
2129 |
} |
|
2130 |
||
2131 |
@Override |
|
2132 |
protected void append(char ch) { |
|
2133 |
sb.append(ch); |
|
2134 |
} |
|
2135 |
||
2136 |
@Override |
|
2137 |
protected void append(byte[] ba) { |
|
2138 |
sb.append(new String(ba)); |
|
2139 |
} |
|
2140 |
||
2141 |
@Override |
|
2142 |
protected void append(Name name) { |
|
2143 |
sb.append(name.toString()); |
|
2144 |
} |
|
2145 |
||
2146 |
@Override |
|
2147 |
public String toString() { |
|
2148 |
return sb.toString(); |
|
2149 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2150 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2151 |
} |