author | jlahoda |
Thu, 15 Jun 2017 13:44:42 +0200 | |
changeset 45504 | ea7475564d07 |
parent 44230 | 6f46f350a21b |
child 45604 | 2460d6aeca6e |
permissions | -rw-r--r-- |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1 |
/* |
44230
6f46f350a21b
8175191: dead code removal at package com.sun.tools.javac.comp
vromero
parents:
43148
diff
changeset
|
2 |
* Copyright (c) 2010, 2017, 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 |
*/ |
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
34568
diff
changeset
|
25 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.comp; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
27 |
|
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.*; |
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.*; |
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.JCTree.JCMemberReference.ReferenceKind; |
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.TreeMaker; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
32 |
import com.sun.tools.javac.tree.TreeTranslator; |
17578 | 33 |
import com.sun.tools.javac.code.Attribute; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25281
diff
changeset
|
34 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
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; |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
39 |
import com.sun.tools.javac.code.Symbol.TypeSymbol; |
14365
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.Symbol.VarSymbol; |
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.Symtab; |
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; |
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.Type.MethodType; |
27855
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
44 |
import com.sun.tools.javac.code.Type.TypeVar; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
45 |
import com.sun.tools.javac.code.Types; |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
46 |
import com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzerPreprocessor.*; |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
47 |
import com.sun.tools.javac.comp.Lower.BasicFreeVarCollector; |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44230
diff
changeset
|
48 |
import com.sun.tools.javac.resources.CompilerProperties.Notes; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
49 |
import com.sun.tools.javac.jvm.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
50 |
import com.sun.tools.javac.util.*; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
|
21486 | 54 |
import java.util.EnumMap; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
55 |
import java.util.HashMap; |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
56 |
import java.util.HashSet; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
57 |
import java.util.LinkedHashMap; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
58 |
import java.util.Map; |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
59 |
import java.util.Set; |
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
60 |
import java.util.function.Consumer; |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
61 |
import java.util.function.Supplier; |
14365
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 |
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
|
64 |
import static com.sun.tools.javac.code.Flags.*; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26990
diff
changeset
|
65 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
16300 | 66 |
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
|
67 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
68 |
|
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
69 |
import javax.lang.model.element.ElementKind; |
27855
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
70 |
import javax.lang.model.type.TypeKind; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
71 |
|
39599 | 72 |
import com.sun.tools.javac.main.Option; |
73 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
74 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
75 |
* 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
|
76 |
* |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
77 |
* <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
|
78 |
* 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
|
79 |
* 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
|
80 |
* deletion without notice.</b> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
81 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
82 |
public class LambdaToMethod extends TreeTranslator { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
83 |
|
21486 | 84 |
private Attr attr; |
18386 | 85 |
private JCDiagnostic.Factory diags; |
86 |
private Log log; |
|
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
87 |
private Lower lower; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
88 |
private Names names; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
89 |
private Symtab syms; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
90 |
private Resolve rs; |
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
91 |
private Operators operators; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
92 |
private TreeMaker make; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
93 |
private Types types; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
94 |
private TransTypes transTypes; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
95 |
private Env<AttrContext> attrEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
96 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
97 |
/** the analyzer scanner */ |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
98 |
private LambdaAnalyzerPreprocessor analyzer; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
99 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
100 |
/** 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
|
101 |
private Map<JCTree, TranslationContext<?>> contextMap; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
102 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
103 |
/** current translation context (visitor argument) */ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
104 |
private TranslationContext<?> context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
105 |
|
16300 | 106 |
/** info about the current class being processed */ |
107 |
private KlassInfo kInfo; |
|
108 |
||
18386 | 109 |
/** dump statistics about lambda code generation */ |
39599 | 110 |
private final boolean dumpLambdaToMethodStats; |
18386 | 111 |
|
39588
a30039aaca6c
8160915: javac, option forceSerializable should be restored
vromero
parents:
39587
diff
changeset
|
112 |
/** force serializable representation, for stress testing **/ |
a30039aaca6c
8160915: javac, option forceSerializable should be restored
vromero
parents:
39587
diff
changeset
|
113 |
private final boolean forceSerializable; |
a30039aaca6c
8160915: javac, option forceSerializable should be restored
vromero
parents:
39587
diff
changeset
|
114 |
|
16300 | 115 |
/** Flag for alternate metafactories indicating the lambda object is intended to be serializable */ |
116 |
public static final int FLAG_SERIALIZABLE = 1 << 0; |
|
117 |
||
118 |
/** Flag for alternate metafactories indicating the lambda object has multiple targets */ |
|
119 |
public static final int FLAG_MARKERS = 1 << 1; |
|
120 |
||
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
121 |
/** 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
|
122 |
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
|
123 |
|
21486 | 124 |
// <editor-fold defaultstate="collapsed" desc="Instantiating"> |
22163 | 125 |
protected static final Context.Key<LambdaToMethod> unlambdaKey = new Context.Key<>(); |
21486 | 126 |
|
127 |
public static LambdaToMethod instance(Context context) { |
|
128 |
LambdaToMethod instance = context.get(unlambdaKey); |
|
129 |
if (instance == null) { |
|
130 |
instance = new LambdaToMethod(context); |
|
131 |
} |
|
132 |
return instance; |
|
133 |
} |
|
134 |
private LambdaToMethod(Context context) { |
|
135 |
context.put(unlambdaKey, this); |
|
136 |
diags = JCDiagnostic.Factory.instance(context); |
|
137 |
log = Log.instance(context); |
|
138 |
lower = Lower.instance(context); |
|
139 |
names = Names.instance(context); |
|
140 |
syms = Symtab.instance(context); |
|
141 |
rs = Resolve.instance(context); |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
142 |
operators = Operators.instance(context); |
21486 | 143 |
make = TreeMaker.instance(context); |
144 |
types = Types.instance(context); |
|
145 |
transTypes = TransTypes.instance(context); |
|
146 |
analyzer = new LambdaAnalyzerPreprocessor(); |
|
147 |
Options options = Options.instance(context); |
|
39599 | 148 |
dumpLambdaToMethodStats = options.isSet("debug.dumpLambdaToMethodStats"); |
21486 | 149 |
attr = Attr.instance(context); |
39588
a30039aaca6c
8160915: javac, option forceSerializable should be restored
vromero
parents:
39587
diff
changeset
|
150 |
forceSerializable = options.isSet("forceSerializable"); |
21486 | 151 |
} |
152 |
// </editor-fold> |
|
153 |
||
16300 | 154 |
private class KlassInfo { |
155 |
||
156 |
/** |
|
157 |
* list of methods to append |
|
158 |
*/ |
|
159 |
private ListBuffer<JCTree> appendedMethodList; |
|
160 |
||
161 |
/** |
|
162 |
* list of deserialization cases |
|
163 |
*/ |
|
164 |
private final Map<String, ListBuffer<JCStatement>> deserializeCases; |
|
165 |
||
166 |
/** |
|
167 |
* deserialize method symbol |
|
168 |
*/ |
|
169 |
private final MethodSymbol deserMethodSym; |
|
170 |
||
171 |
/** |
|
172 |
* deserialize method parameter symbol |
|
173 |
*/ |
|
174 |
private final VarSymbol deserParamSym; |
|
175 |
||
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
176 |
private final JCClassDecl clazz; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
177 |
|
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
178 |
private KlassInfo(JCClassDecl clazz) { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
179 |
this.clazz = clazz; |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
180 |
appendedMethodList = new ListBuffer<>(); |
22163 | 181 |
deserializeCases = new HashMap<>(); |
16300 | 182 |
MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
183 |
List.nil(), syms.methodClass); |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
184 |
deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, clazz.sym); |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
185 |
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
|
186 |
syms.serializedLambdaType, deserMethodSym); |
16300 | 187 |
} |
188 |
||
189 |
private void addMethod(JCTree decl) { |
|
190 |
appendedMethodList = appendedMethodList.prepend(decl); |
|
191 |
} |
|
192 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
193 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
194 |
// <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
|
195 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
196 |
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
|
197 |
TranslationContext<?> newContext = contextMap.get(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
198 |
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
|
199 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
200 |
|
17585
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
201 |
<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
|
202 |
TranslationContext<?> prevContext = context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
203 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
204 |
context = newContext; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
205 |
return super.translate(tree); |
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 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
208 |
context = prevContext; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
209 |
} |
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 |
|
17585
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
212 |
<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
|
213 |
ListBuffer<T> buf = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
214 |
for (T tree : trees) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
215 |
buf.append(translate(tree, newContext)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
216 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
217 |
return buf.toList(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
218 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
219 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
220 |
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
|
221 |
this.make = make; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
222 |
this.attrEnv = env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
223 |
this.context = null; |
22163 | 224 |
this.contextMap = new HashMap<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
225 |
return translate(cdef); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
226 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
227 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
228 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
229 |
// <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
|
230 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
231 |
* Visit a class. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
232 |
* Maintain the translatedMethodList across nested classes. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
233 |
* 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
|
234 |
* @param tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
235 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
236 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
237 |
public void visitClassDef(JCClassDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
238 |
if (tree.sym.owner.kind == PCK) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
239 |
//analyze class |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
240 |
tree = analyzer.analyzeAndPreprocessClass(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
241 |
} |
16300 | 242 |
KlassInfo prevKlassInfo = kInfo; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
243 |
try { |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
244 |
kInfo = new KlassInfo(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
245 |
super.visitClassDef(tree); |
16300 | 246 |
if (!kInfo.deserializeCases.isEmpty()) { |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
247 |
int prevPos = make.pos; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
248 |
try { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
249 |
make.at(tree); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
250 |
kInfo.addMethod(makeDeserializeMethod(tree.sym)); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
251 |
} finally { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
252 |
make.at(prevPos); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
253 |
} |
16300 | 254 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
255 |
//add all translated instance methods here |
16300 | 256 |
List<JCTree> newMethods = kInfo.appendedMethodList.toList(); |
257 |
tree.defs = tree.defs.appendList(newMethods); |
|
258 |
for (JCTree lambda : newMethods) { |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
259 |
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
|
260 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
261 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
262 |
} finally { |
16300 | 263 |
kInfo = prevKlassInfo; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
264 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
265 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
266 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
267 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
268 |
* 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
|
269 |
* 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
|
270 |
* 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
|
271 |
* @param tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
272 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
273 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
274 |
public void visitLambda(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
275 |
LambdaTranslationContext localContext = (LambdaTranslationContext)context; |
28452
6afa05455443
8037546: javac -parameters does not emit parameter names for lambda expressions
jlahoda
parents:
28145
diff
changeset
|
276 |
MethodSymbol sym = localContext.translatedSym; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
277 |
MethodType lambdaType = (MethodType) sym.type; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
278 |
|
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
279 |
{ /* Type annotation management: Based on where the lambda features, type annotations that |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
280 |
are interior to it, may at this point be attached to the enclosing method, or the first |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
281 |
constructor in the class, or in the enclosing class symbol or in the field whose |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
282 |
initializer is the lambda. In any event, gather up the annotations that belong to the |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
283 |
lambda and attach it to the implementation method. |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
284 |
*/ |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
285 |
|
19651 | 286 |
Symbol owner = localContext.owner; |
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
287 |
apportionTypeAnnotations(tree, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
288 |
owner::getRawTypeAttributes, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
289 |
owner::setTypeAttributes, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
290 |
sym::setTypeAttributes); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
291 |
|
17578 | 292 |
|
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
293 |
boolean init; |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
294 |
if ((init = (owner.name == names.init)) || owner.name == names.clinit) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
295 |
owner = owner.owner; |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
296 |
apportionTypeAnnotations(tree, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
297 |
init ? owner::getInitTypeAttributes : owner::getClassInitTypeAttributes, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
298 |
init ? owner::setInitTypeAttributes : owner::setClassInitTypeAttributes, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
299 |
sym::appendUniqueTypeAttributes); |
17578 | 300 |
} |
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
301 |
if (localContext.self != null && localContext.self.getKind() == ElementKind.FIELD) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
302 |
owner = localContext.self; |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
303 |
apportionTypeAnnotations(tree, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
304 |
owner::getRawTypeAttributes, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
305 |
owner::setTypeAttributes, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
306 |
sym::appendUniqueTypeAttributes); |
17578 | 307 |
} |
308 |
} |
|
309 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
310 |
//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
|
311 |
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
|
312 |
sym.name, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
313 |
make.QualIdent(lambdaType.getReturnType().tsym), |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
314 |
List.nil(), |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
315 |
localContext.syntheticParams, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
316 |
lambdaType.getThrownTypes() == null ? |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
317 |
List.nil() : |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
318 |
make.Types(lambdaType.getThrownTypes()), |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
319 |
null, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
320 |
null); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
321 |
lambdaDecl.sym = sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
322 |
lambdaDecl.type = lambdaType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
323 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
324 |
//translate lambda body |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
325 |
//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
|
326 |
//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
|
327 |
//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
|
328 |
//captured members directly). |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
329 |
lambdaDecl.body = translate(makeLambdaBody(tree, lambdaDecl)); |
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 |
//Add the method to the list of methods to be added to this class. |
16300 | 332 |
kInfo.addMethod(lambdaDecl); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
333 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
334 |
//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
|
335 |
//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
|
336 |
//created method. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
337 |
// |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
338 |
//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
|
339 |
//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
|
340 |
//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
|
341 |
// |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
342 |
// * 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
|
343 |
// * 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
|
344 |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
345 |
ListBuffer<JCExpression> syntheticInits = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
346 |
|
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
347 |
if (localContext.methodReferenceReceiver != null) { |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
348 |
syntheticInits.append(localContext.methodReferenceReceiver); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
349 |
} else if (!sym.isStatic()) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
350 |
syntheticInits.append(makeThis( |
16300 | 351 |
sym.owner.enclClass().asType(), |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
352 |
localContext.owner.enclClass())); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
353 |
} |
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 |
//add captured locals |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
356 |
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
|
357 |
if (fv != localContext.self) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
358 |
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
|
359 |
syntheticInits.append((JCExpression) captured_local); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
360 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
361 |
} |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
362 |
// add captured outer this instances (used only when `this' capture itself is illegal) |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
363 |
for (Symbol fv : localContext.getSymbolMap(CAPTURED_OUTER_THIS).keySet()) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
364 |
JCTree captured_local = make.QualThis(fv.type); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
365 |
syntheticInits.append((JCExpression) captured_local); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
366 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
367 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
368 |
//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
|
369 |
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
|
370 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
371 |
//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
|
372 |
int refKind = referenceKind(sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
373 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
374 |
//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
|
375 |
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
|
376 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
377 |
|
33712
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
378 |
// where |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
379 |
// Reassign type annotations from the source that should really belong to the lambda |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
380 |
private void apportionTypeAnnotations(JCLambda tree, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
381 |
Supplier<List<Attribute.TypeCompound>> source, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
382 |
Consumer<List<Attribute.TypeCompound>> owner, |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
383 |
Consumer<List<Attribute.TypeCompound>> lambda) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
384 |
|
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
385 |
ListBuffer<Attribute.TypeCompound> ownerTypeAnnos = new ListBuffer<>(); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
386 |
ListBuffer<Attribute.TypeCompound> lambdaTypeAnnos = new ListBuffer<>(); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
387 |
|
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
388 |
for (Attribute.TypeCompound tc : source.get()) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
389 |
if (tc.position.onLambda == tree) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
390 |
lambdaTypeAnnos.append(tc); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
391 |
} else { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
392 |
ownerTypeAnnos.append(tc); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
393 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
394 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
395 |
if (lambdaTypeAnnos.nonEmpty()) { |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
396 |
owner.accept(ownerTypeAnnos.toList()); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
397 |
lambda.accept(lambdaTypeAnnos.toList()); |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
398 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
399 |
} |
fd1ce6d7ac63
8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents:
33710
diff
changeset
|
400 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
401 |
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
|
402 |
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
|
403 |
names._this, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
404 |
type, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
405 |
owner); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
406 |
return make.Ident(_this); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
407 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
408 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
409 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
410 |
* 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
|
411 |
* meta-factory. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
412 |
* @param tree |
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 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
415 |
public void visitReference(JCMemberReference tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
416 |
ReferenceTranslationContext localContext = (ReferenceTranslationContext)context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
417 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
418 |
//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
|
419 |
//this is either the method reference symbol, or the bridged reference symbol |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
420 |
Symbol refSym = localContext.isSignaturePolymorphic() |
21892
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
421 |
? localContext.sigPolySym |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
422 |
: tree.sym; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
423 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
424 |
//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
|
425 |
JCExpression init; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
426 |
switch(tree.kind) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
427 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
428 |
case IMPLICIT_INNER: /** Inner :: new */ |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
429 |
case SUPER: /** super :: instMethod */ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
430 |
init = makeThis( |
16300 | 431 |
localContext.owner.enclClass().asType(), |
432 |
localContext.owner.enclClass()); |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
433 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
434 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
435 |
case BOUND: /** Expr :: instMethod */ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
436 |
init = tree.getQualifierExpression(); |
20245
c351f524fbc6
8024696: Missing null check in bound method reference capture
vromero
parents:
19941
diff
changeset
|
437 |
init = attr.makeNullCheck(init); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
438 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
439 |
|
14724
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
440 |
case UNBOUND: /** Type :: instMethod */ |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
441 |
case STATIC: /** Type :: staticMethod */ |
b542db73539a
8004101: Add checks for method reference well-formedness
mcimadamore
parents:
14537
diff
changeset
|
442 |
case TOPLEVEL: /** Top level :: new */ |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
443 |
case ARRAY_CTOR: /** ArrayType :: new */ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
444 |
init = null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
445 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
446 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
447 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
448 |
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
|
449 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
450 |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
451 |
List<JCExpression> indy_args = init==null? List.nil() : translate(List.of(init), localContext.prev); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
452 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
453 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
454 |
//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
|
455 |
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
|
456 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
457 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
458 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
459 |
* 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
|
460 |
* @param tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
461 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
462 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
463 |
public void visitIdent(JCIdent tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
464 |
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
|
465 |
super.visitIdent(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
466 |
} else { |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
467 |
int prevPos = make.pos; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
468 |
try { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
469 |
make.at(tree); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
470 |
|
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
471 |
LambdaTranslationContext lambdaContext = (LambdaTranslationContext) context; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
472 |
JCTree ltree = lambdaContext.translate(tree); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
473 |
if (ltree != null) { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
474 |
result = ltree; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
475 |
} else { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
476 |
//access to untranslated symbols (i.e. compile-time constants, |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
477 |
//members defined inside the lambda body, etc.) ) |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
478 |
super.visitIdent(tree); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
479 |
} |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
480 |
} finally { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
481 |
make.at(prevPos); |
14365
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 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
485 |
|
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
486 |
/** |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
487 |
* Translate qualified `this' references within a lambda to the mapped identifier |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
488 |
* @param tree |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
489 |
*/ |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
490 |
@Override |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
491 |
public void visitSelect(JCFieldAccess tree) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
492 |
if (context == null || !analyzer.lambdaFieldAccessFilter(tree)) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
493 |
super.visitSelect(tree); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
494 |
} else { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
495 |
int prevPos = make.pos; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
496 |
try { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
497 |
make.at(tree); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
498 |
|
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
499 |
LambdaTranslationContext lambdaContext = (LambdaTranslationContext) context; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
500 |
JCTree ltree = lambdaContext.translate(tree); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
501 |
if (ltree != null) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
502 |
result = ltree; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
503 |
} else { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
504 |
super.visitSelect(tree); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
505 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
506 |
} finally { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
507 |
make.at(prevPos); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
508 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
509 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
510 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
511 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
512 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
513 |
public void visitVarDef(JCVariableDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
514 |
LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
515 |
if (context != null && lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) { |
24224
b31b4a230595
8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
23970
diff
changeset
|
516 |
tree.init = translate(tree.init); |
b31b4a230595
8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
23970
diff
changeset
|
517 |
tree.sym = (VarSymbol) lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym); |
b31b4a230595
8036942: javac generates incorrect exception table for multi-catch statements inside a lambda
rfield
parents:
23970
diff
changeset
|
518 |
result = tree; |
16300 | 519 |
} else if (context != null && lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) { |
520 |
JCExpression init = translate(tree.init); |
|
521 |
VarSymbol xsym = (VarSymbol)lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym); |
|
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
522 |
int prevPos = make.pos; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
523 |
try { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
524 |
result = make.at(tree).VarDef(xsym, init); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
525 |
} finally { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
526 |
make.at(prevPos); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
527 |
} |
16300 | 528 |
// Replace the entered symbol for this variable |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25281
diff
changeset
|
529 |
WriteableScope sc = tree.sym.owner.members(); |
16300 | 530 |
if (sc != null) { |
531 |
sc.remove(tree.sym); |
|
532 |
sc.enter(xsym); |
|
533 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
534 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
535 |
super.visitVarDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
536 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
537 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
538 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
539 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
540 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
541 |
// <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
|
542 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
543 |
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
|
544 |
return tree.getBodyKind() == JCLambda.BodyKind.EXPRESSION ? |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
545 |
makeLambdaExpressionBody((JCExpression)tree.body, lambdaMethodDecl) : |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
546 |
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
|
547 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
548 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
549 |
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
|
550 |
Type restype = lambdaMethodDecl.type.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
551 |
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
|
552 |
boolean isTarget_void = restype.hasTag(VOID); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
553 |
boolean isTarget_Void = types.isSameType(restype, types.boxedClass(syms.voidType).type); |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
554 |
int prevPos = make.pos; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
555 |
try { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
556 |
if (isTarget_void) { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
557 |
//target is void: |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
558 |
// BODY; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
559 |
JCStatement stat = make.at(expr).Exec(expr); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
560 |
return make.Block(0, List.of(stat)); |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
561 |
} else if (isLambda_void && isTarget_Void) { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
562 |
//void to Void conversion: |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
563 |
// BODY; return null; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
564 |
ListBuffer<JCStatement> stats = new ListBuffer<>(); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
565 |
stats.append(make.at(expr).Exec(expr)); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
566 |
stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType))); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
567 |
return make.Block(0, stats.toList()); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
568 |
} else { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
569 |
//non-void to non-void conversion: |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
570 |
// return (TYPE)BODY; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
571 |
JCExpression retExpr = transTypes.coerce(attrEnv, expr, restype); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
572 |
return make.at(retExpr).Block(0, List.of(make.Return(retExpr))); |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
573 |
} |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
574 |
} finally { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
575 |
make.at(prevPos); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
576 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
577 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
578 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
579 |
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
|
580 |
final Type restype = lambdaMethodDecl.type.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
581 |
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
|
582 |
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
|
583 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
584 |
class LambdaBodyTranslator extends TreeTranslator { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
585 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
586 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
587 |
public void visitClassDef(JCClassDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
588 |
//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
|
589 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
590 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
591 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
592 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
593 |
public void visitLambda(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
594 |
//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
|
595 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
596 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
597 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
598 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
599 |
public void visitReturn(JCReturn tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
600 |
boolean isLambda_void = tree.expr == null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
601 |
if (isTarget_void && !isLambda_void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
602 |
//Void to void conversion: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
603 |
// { TYPE $loc = RET-EXPR; return; } |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
604 |
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
|
605 |
JCVariableDecl varDef = make.VarDef(loc, tree.expr); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
606 |
result = make.Block(0, List.of(varDef, make.Return(null))); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
607 |
} else if (!isTarget_void || !isLambda_void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
608 |
//non-void to non-void conversion: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
609 |
// return (TYPE)RET-EXPR; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
610 |
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
|
611 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
612 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
613 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
614 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
615 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
616 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
617 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
618 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
619 |
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
|
620 |
if (completeNormally && isTarget_Void) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
621 |
//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
|
622 |
//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
|
623 |
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
|
624 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
625 |
return trans_block; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
626 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
627 |
|
16300 | 628 |
private JCMethodDecl makeDeserializeMethod(Symbol kSym) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
629 |
ListBuffer<JCCase> cases = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
630 |
ListBuffer<JCBreak> breaks = new ListBuffer<>(); |
16300 | 631 |
for (Map.Entry<String, ListBuffer<JCStatement>> entry : kInfo.deserializeCases.entrySet()) { |
632 |
JCBreak br = make.Break(null); |
|
633 |
breaks.add(br); |
|
634 |
List<JCStatement> stmts = entry.getValue().append(br).toList(); |
|
635 |
cases.add(make.Case(make.Literal(entry.getKey()), stmts)); |
|
636 |
} |
|
637 |
JCSwitch sw = make.Switch(deserGetter("getImplMethodName", syms.stringType), cases.toList()); |
|
638 |
for (JCBreak br : breaks) { |
|
639 |
br.target = sw; |
|
640 |
} |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
641 |
JCBlock body = make.Block(0L, List.of( |
16300 | 642 |
sw, |
643 |
make.Throw(makeNewClass( |
|
644 |
syms.illegalArgumentExceptionType, |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
645 |
List.of(make.Literal("Invalid lambda deserialization")))))); |
16300 | 646 |
JCMethodDecl deser = make.MethodDef(make.Modifiers(kInfo.deserMethodSym.flags()), |
647 |
names.deserializeLambda, |
|
648 |
make.QualIdent(kInfo.deserMethodSym.getReturnType().tsym), |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
649 |
List.nil(), |
16300 | 650 |
List.of(make.VarDef(kInfo.deserParamSym, null)), |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
651 |
List.nil(), |
16300 | 652 |
body, |
653 |
null); |
|
654 |
deser.sym = kInfo.deserMethodSym; |
|
655 |
deser.type = kInfo.deserMethodSym.type; |
|
656 |
//System.err.printf("DESER: '%s'\n", deser); |
|
657 |
return deser; |
|
658 |
} |
|
659 |
||
660 |
/** Make an attributed class instance creation expression. |
|
661 |
* @param ctype The class type. |
|
662 |
* @param args The constructor arguments. |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
663 |
* @param cons The constructor symbol |
16300 | 664 |
*/ |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
665 |
JCNewClass makeNewClass(Type ctype, List<JCExpression> args, Symbol cons) { |
16300 | 666 |
JCNewClass tree = make.NewClass(null, |
667 |
null, make.QualIdent(ctype.tsym), args, null); |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
668 |
tree.constructor = cons; |
16300 | 669 |
tree.type = ctype; |
670 |
return tree; |
|
671 |
} |
|
672 |
||
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
673 |
/** Make an attributed class instance creation expression. |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
674 |
* @param ctype The class type. |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
675 |
* @param args The constructor arguments. |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
676 |
*/ |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
677 |
JCNewClass makeNewClass(Type ctype, List<JCExpression> args) { |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
678 |
return makeNewClass(ctype, args, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
679 |
rs.resolveConstructor(null, attrEnv, ctype, TreeInfo.types(args), List.nil())); |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
680 |
} |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
681 |
|
16300 | 682 |
private void addDeserializationCase(int implMethodKind, Symbol refSym, Type targetType, MethodSymbol samSym, |
683 |
DiagnosticPosition pos, List<Object> staticArgs, MethodType indyType) { |
|
684 |
String functionalInterfaceClass = classSig(targetType); |
|
685 |
String functionalInterfaceMethodName = samSym.getSimpleName().toString(); |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
686 |
String functionalInterfaceMethodSignature = typeSig(types.erasure(samSym.type)); |
16335
4f7fe060522f
8009582: Method reference generic constructor gives: IllegalArgumentException: Invalid lambda deserialization
rfield
parents:
16332
diff
changeset
|
687 |
String implClass = classSig(types.erasure(refSym.owner.type)); |
16300 | 688 |
String implMethodName = refSym.getQualifiedName().toString(); |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
689 |
String implMethodSignature = typeSig(types.erasure(refSym.type)); |
16300 | 690 |
|
691 |
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
|
692 |
ListBuffer<JCExpression> serArgs = new ListBuffer<>(); |
16300 | 693 |
int i = 0; |
694 |
for (Type t : indyType.getParameterTypes()) { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
695 |
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
|
696 |
List<Type> argTypes = new ListBuffer<Type>().append(syms.intType).toList(); |
16300 | 697 |
serArgs.add(make.TypeCast(types.erasure(t), deserGetter("getCapturedArg", syms.objectType, argTypes, indexAsArg))); |
698 |
++i; |
|
699 |
} |
|
700 |
JCStatement stmt = make.If( |
|
701 |
deserTest(deserTest(deserTest(deserTest(deserTest( |
|
702 |
kindTest, |
|
703 |
"getFunctionalInterfaceClass", functionalInterfaceClass), |
|
704 |
"getFunctionalInterfaceMethodName", functionalInterfaceMethodName), |
|
705 |
"getFunctionalInterfaceMethodSignature", functionalInterfaceMethodSignature), |
|
706 |
"getImplClass", implClass), |
|
707 |
"getImplMethodSignature", implMethodSignature), |
|
708 |
make.Return(makeIndyCall( |
|
709 |
pos, |
|
710 |
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
|
711 |
names.altMetafactory, |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
712 |
staticArgs, indyType, serArgs.toList(), samSym.name)), |
16300 | 713 |
null); |
714 |
ListBuffer<JCStatement> stmts = kInfo.deserializeCases.get(implMethodName); |
|
715 |
if (stmts == null) { |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
716 |
stmts = new ListBuffer<>(); |
16300 | 717 |
kInfo.deserializeCases.put(implMethodName, stmts); |
718 |
} |
|
719 |
/**** |
|
720 |
System.err.printf("+++++++++++++++++\n"); |
|
721 |
System.err.printf("*functionalInterfaceClass: '%s'\n", functionalInterfaceClass); |
|
722 |
System.err.printf("*functionalInterfaceMethodName: '%s'\n", functionalInterfaceMethodName); |
|
723 |
System.err.printf("*functionalInterfaceMethodSignature: '%s'\n", functionalInterfaceMethodSignature); |
|
724 |
System.err.printf("*implMethodKind: %d\n", implMethodKind); |
|
725 |
System.err.printf("*implClass: '%s'\n", implClass); |
|
726 |
System.err.printf("*implMethodName: '%s'\n", implMethodName); |
|
727 |
System.err.printf("*implMethodSignature: '%s'\n", implMethodSignature); |
|
728 |
****/ |
|
729 |
stmts.append(stmt); |
|
730 |
} |
|
731 |
||
732 |
private JCExpression eqTest(Type argType, JCExpression arg1, JCExpression arg2) { |
|
733 |
JCBinary testExpr = make.Binary(JCTree.Tag.EQ, arg1, arg2); |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
734 |
testExpr.operator = operators.resolveBinary(testExpr, JCTree.Tag.EQ, argType, argType); |
16300 | 735 |
testExpr.setType(syms.booleanType); |
736 |
return testExpr; |
|
737 |
} |
|
738 |
||
739 |
private JCExpression deserTest(JCExpression prev, String func, String lit) { |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
740 |
MethodType eqmt = new MethodType(List.of(syms.objectType), syms.booleanType, List.nil(), syms.methodClass); |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
741 |
Symbol eqsym = rs.resolveQualifiedMethod(null, attrEnv, syms.objectType, names.equals, List.of(syms.objectType), List.nil()); |
16300 | 742 |
JCMethodInvocation eqtest = make.Apply( |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
743 |
List.nil(), |
16300 | 744 |
make.Select(deserGetter(func, syms.stringType), eqsym).setType(eqmt), |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
745 |
List.of(make.Literal(lit))); |
16300 | 746 |
eqtest.setType(syms.booleanType); |
747 |
JCBinary compound = make.Binary(JCTree.Tag.AND, prev, eqtest); |
|
29051
7244db2ab176
8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents:
28591
diff
changeset
|
748 |
compound.operator = operators.resolveBinary(compound, JCTree.Tag.AND, syms.booleanType, syms.booleanType); |
16300 | 749 |
compound.setType(syms.booleanType); |
750 |
return compound; |
|
751 |
} |
|
752 |
||
753 |
private JCExpression deserGetter(String func, Type type) { |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
754 |
return deserGetter(func, type, List.nil(), List.nil()); |
16300 | 755 |
} |
756 |
||
757 |
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) { |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
758 |
MethodType getmt = new MethodType(argTypes, type, List.nil(), syms.methodClass); |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
759 |
Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.nil()); |
16300 | 760 |
return make.Apply( |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
761 |
List.nil(), |
16300 | 762 |
make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), |
763 |
args).setType(type); |
|
764 |
} |
|
765 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
766 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
767 |
* 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
|
768 |
*/ |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
769 |
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
|
770 |
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
|
771 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
772 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
773 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
774 |
* 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
|
775 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
776 |
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
|
777 |
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
|
778 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
779 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
780 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
781 |
* 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
|
782 |
* or a method call tree) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
783 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
784 |
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
|
785 |
if (varargsElement != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
786 |
switch (tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
787 |
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
|
788 |
case NEWCLASS: ((JCNewClass)tree).varargsElement = varargsElement; break; |
43148
9d11c46bd7bf
8171993: AssertionError when compiling method reference with generic code and varargs.
sadayapalam
parents:
42828
diff
changeset
|
789 |
case TYPECAST: setVarargsIfNeeded(((JCTypeCast) tree).expr, varargsElement); break; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
790 |
default: throw new AssertionError(); |
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 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
793 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
794 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
795 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
796 |
* 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
|
797 |
* 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
|
798 |
* 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
|
799 |
* with the generated signature. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
800 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
801 |
private List<JCExpression> convertArgs(Symbol meth, List<JCExpression> args, Type varargsElement) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26990
diff
changeset
|
802 |
Assert.check(meth.kind == MTH); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
803 |
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
|
804 |
if (varargsElement != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
805 |
Assert.check((meth.flags() & VARARGS) != 0); |
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 |
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
|
808 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
809 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
810 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
811 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
812 |
/** |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
813 |
* Converts a method reference which cannot be used directly into a lambda |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
814 |
*/ |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
815 |
private class MemberReferenceToLambda { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
816 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
817 |
private final JCMemberReference tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
818 |
private final ReferenceTranslationContext localContext; |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
819 |
private final Symbol owner; |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
820 |
private final ListBuffer<JCExpression> args = new ListBuffer<>(); |
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
821 |
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
|
822 |
|
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
823 |
private JCExpression receiverExpression = null; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
824 |
|
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
825 |
MemberReferenceToLambda(JCMemberReference tree, ReferenceTranslationContext localContext, Symbol owner) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
826 |
this.tree = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
827 |
this.localContext = localContext; |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
828 |
this.owner = owner; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
829 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
830 |
|
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
831 |
JCLambda lambda() { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
832 |
int prevPos = make.pos; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
833 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
834 |
make.at(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
835 |
|
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
836 |
//body generation - this can be either a method call or a |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
837 |
//new instance creation expression, depending on the member reference kind |
27855
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
838 |
VarSymbol rcvr = addParametersReturnReceiver(); |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
839 |
JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE) |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
840 |
? expressionInvoke(rcvr) |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
841 |
: expressionNew(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
842 |
|
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
843 |
JCLambda slam = make.Lambda(params.toList(), expr); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
844 |
slam.targets = tree.targets; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
845 |
slam.type = tree.type; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
846 |
slam.pos = tree.pos; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
847 |
return slam; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
848 |
} finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
849 |
make.at(prevPos); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
850 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
851 |
} |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
852 |
|
27855
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
853 |
/** |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
854 |
* Generate the parameter list for the converted member reference. |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
855 |
* |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
856 |
* @return The receiver variable symbol, if any |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
857 |
*/ |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
858 |
VarSymbol addParametersReturnReceiver() { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
859 |
Type samDesc = localContext.bridgedRefSig(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
860 |
List<Type> samPTypes = samDesc.getParameterTypes(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
861 |
List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
862 |
|
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
863 |
// Determine the receiver, if any |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
864 |
VarSymbol rcvr; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
865 |
switch (tree.kind) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
866 |
case BOUND: |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
867 |
// The receiver is explicit in the method reference |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
868 |
rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
869 |
receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
870 |
break; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
871 |
case UNBOUND: |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
872 |
// The receiver is the first parameter, extract it and |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
873 |
// adjust the SAM and unerased type lists accordingly |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
874 |
rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
875 |
samPTypes = samPTypes.tail; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
876 |
descPTypes = descPTypes.tail; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
877 |
break; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
878 |
default: |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
879 |
rcvr = null; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
880 |
break; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
881 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
882 |
List<Type> implPTypes = tree.sym.type.getParameterTypes(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
883 |
int implSize = implPTypes.size(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
884 |
int samSize = samPTypes.size(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
885 |
// Last parameter to copy from referenced method, exclude final var args |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
886 |
int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
887 |
|
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
888 |
// Failsafe -- assure match-up |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
889 |
boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
890 |
|
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
891 |
// Use parameter types of the implementation method unless the unerased |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
892 |
// SAM parameter type is an intersection type, in that case use the |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
893 |
// erased SAM parameter type so that the supertype relationship |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
894 |
// the implementation method parameters is not obscured. |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
895 |
// Note: in this loop, the lists implPTypes, samPTypes, and descPTypes |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
896 |
// are used as pointers to the current parameter type information |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
897 |
// and are thus not usable afterwards. |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
898 |
for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
899 |
// By default use the implementation method parmeter type |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
900 |
Type parmType = implPTypes.head; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
901 |
// If the unerased parameter type is a type variable whose |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
902 |
// bound is an intersection (eg. <T extends A & B>) then |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
903 |
// use the SAM parameter type |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
904 |
if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
905 |
TypeVar tv = (TypeVar) descPTypes.head; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
906 |
if (tv.bound.getKind() == TypeKind.INTERSECTION) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
907 |
parmType = samPTypes.head; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
908 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
909 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
910 |
addParameter("x$" + i, parmType, true); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
911 |
|
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
912 |
// Advance to the next parameter |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
913 |
implPTypes = implPTypes.tail; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
914 |
samPTypes = samPTypes.tail; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
915 |
descPTypes = descPTypes.tail; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
916 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
917 |
// Flatten out the var args |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
918 |
for (int i = last; i < samSize; ++i) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
919 |
addParameter("xva$" + i, tree.varargsElement, true); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
920 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
921 |
|
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
922 |
return rcvr; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
923 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
924 |
|
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
925 |
JCExpression getReceiverExpression() { |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
926 |
return receiverExpression; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
927 |
} |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
928 |
|
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
929 |
private JCExpression makeReceiver(VarSymbol rcvr) { |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
930 |
if (rcvr == null) return null; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
931 |
JCExpression rcvrExpr = make.Ident(rcvr); |
34472
ac6e7be35ea8
8143647: Javac compiles method reference that allows results in an IllegalAccessError
sadayapalam
parents:
33916
diff
changeset
|
932 |
Type rcvrType = tree.ownerAccessible ? tree.sym.enclClass().type : tree.expr.type; |
26990
e3fd4b46d39d
8056051: int[]::clone causes "java.lang.NoClassDefFoundError: Array"
rfield
parents:
25874
diff
changeset
|
933 |
if (rcvrType == syms.arrayClass.type) { |
e3fd4b46d39d
8056051: int[]::clone causes "java.lang.NoClassDefFoundError: Array"
rfield
parents:
25874
diff
changeset
|
934 |
// Map the receiver type to the actually type, not just "array" |
e3fd4b46d39d
8056051: int[]::clone causes "java.lang.NoClassDefFoundError: Array"
rfield
parents:
25874
diff
changeset
|
935 |
rcvrType = tree.getQualifierExpression().type; |
e3fd4b46d39d
8056051: int[]::clone causes "java.lang.NoClassDefFoundError: Array"
rfield
parents:
25874
diff
changeset
|
936 |
} |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
937 |
if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) { |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
938 |
rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType); |
16327
01a0c0cb811c
8009154: Missing cast in method reference bridge leads to NoSuchMethodError
mcimadamore
parents:
16325
diff
changeset
|
939 |
} |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
940 |
return rcvrExpr; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
941 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
942 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
943 |
/** |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
944 |
* determine the receiver of the method call - the receiver can |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
945 |
* be a type qualifier, the synthetic receiver parameter or 'super'. |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
946 |
*/ |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
947 |
private JCExpression expressionInvoke(VarSymbol rcvr) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
948 |
JCExpression qualifier = |
28453
9b94e84322e4
8068254: Method reference uses wrong qualifying type
jlahoda
parents:
28452
diff
changeset
|
949 |
(rcvr != null) ? |
9b94e84322e4
8068254: Method reference uses wrong qualifying type
jlahoda
parents:
28452
diff
changeset
|
950 |
makeReceiver(rcvr) : |
9b94e84322e4
8068254: Method reference uses wrong qualifying type
jlahoda
parents:
28452
diff
changeset
|
951 |
tree.getQualifierExpression(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
952 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
953 |
//create the qualifier expression |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
954 |
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
|
955 |
select.sym = tree.sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
956 |
select.type = tree.sym.erasure(types); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
957 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
958 |
//create the method call expression |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
959 |
JCExpression apply = make.Apply(List.nil(), select, |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
960 |
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
|
961 |
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
|
962 |
|
28591
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28453
diff
changeset
|
963 |
apply = transTypes.coerce(attrEnv, apply, |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28453
diff
changeset
|
964 |
types.erasure(localContext.tree.referentType.getReturnType())); |
25f1384324ae
8046977: ClassCastException: typing information needed for method reference bridging not preserved
jfranck
parents:
28453
diff
changeset
|
965 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
966 |
setVarargsIfNeeded(apply, tree.varargsElement); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
967 |
return apply; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
968 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
969 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
970 |
/** |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
971 |
* Lambda body to use for a 'new'. |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
972 |
*/ |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
973 |
private JCExpression expressionNew() { |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
974 |
if (tree.kind == ReferenceKind.ARRAY_CTOR) { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
975 |
//create the array creation expression |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
976 |
JCNewArray newArr = make.NewArray( |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
977 |
make.Type(types.elemtype(tree.getQualifierExpression().type)), |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
978 |
List.of(make.Ident(params.first())), |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
979 |
null); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
980 |
newArr.type = tree.getQualifierExpression().type; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
981 |
return newArr; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
982 |
} else { |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
983 |
//create the instance creation expression |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
984 |
//note that method reference syntax does not allow an explicit |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
985 |
//enclosing class (so the enclosing class is null) |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
986 |
JCNewClass newClass = make.NewClass(null, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
987 |
List.nil(), |
15360
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
988 |
make.Type(tree.getQualifierExpression().type), |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
989 |
convertArgs(tree.sym, args.toList(), tree.varargsElement), |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
990 |
null); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
991 |
newClass.constructor = tree.sym; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
992 |
newClass.constructorType = tree.sym.erasure(types); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
993 |
newClass.type = tree.getQualifierExpression().type; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
994 |
setVarargsIfNeeded(newClass, tree.varargsElement); |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
995 |
return newClass; |
450af2a9e3c9
8005854: Add support for array constructor references
mcimadamore
parents:
14949
diff
changeset
|
996 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
997 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
998 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
999 |
private VarSymbol addParameter(String name, Type p, boolean genArg) { |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1000 |
VarSymbol vsym = new VarSymbol(PARAMETER | SYNTHETIC, names.fromString(name), p, owner); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1001 |
vsym.pos = tree.pos; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1002 |
params.append(make.VarDef(vsym, null)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1003 |
if (genArg) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1004 |
args.append(make.Ident(vsym)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1005 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1006 |
return vsym; |
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 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1009 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1010 |
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
|
1011 |
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
|
1012 |
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
|
1013 |
type.getReturnType(), |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1014 |
type.getThrownTypes(), |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1015 |
syms.methodClass); |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1016 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1017 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1018 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1019 |
* 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
|
1020 |
*/ |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1021 |
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
|
1022 |
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
|
1023 |
JCFunctionalExpression tree = context.tree; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1024 |
//determine the static bsm args |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15360
diff
changeset
|
1025 |
MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym); |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
1026 |
List<Object> staticArgs = List.of( |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1027 |
typeToMethodType(samSym.type), |
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14724
diff
changeset
|
1028 |
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
|
1029 |
typeToMethodType(tree.getDescriptorType(types))); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1030 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1031 |
//computed indy arg types |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
1032 |
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
|
1033 |
for (JCExpression arg : indy_args) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1034 |
indy_args_types.append(arg.type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1035 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1036 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1037 |
//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
|
1038 |
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
|
1039 |
tree.type, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
1040 |
List.nil(), |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1041 |
syms.methodClass); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1042 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1043 |
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
|
1044 |
names.altMetafactory : names.metafactory; |
16300 | 1045 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1046 |
if (context.needsAltMetafactory()) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
1047 |
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
|
1048 |
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
|
1049 |
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
|
1050 |
markers.append(t.tsym); |
16300 | 1051 |
} |
1052 |
} |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1053 |
int flags = context.isSerializable() ? FLAG_SERIALIZABLE : 0; |
16300 | 1054 |
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
|
1055 |
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
|
1056 |
if (hasMarkers) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1057 |
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
|
1058 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1059 |
if (hasBridges) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1060 |
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
|
1061 |
} |
16300 | 1062 |
staticArgs = staticArgs.append(flags); |
1063 |
if (hasMarkers) { |
|
1064 |
staticArgs = staticArgs.append(markers.length()); |
|
1065 |
staticArgs = staticArgs.appendList(markers.toList()); |
|
1066 |
} |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1067 |
if (hasBridges) { |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1068 |
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
|
1069 |
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
|
1070 |
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
|
1071 |
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
|
1072 |
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
|
1073 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1074 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1075 |
} |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1076 |
if (context.isSerializable()) { |
21496
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1077 |
int prevPos = make.pos; |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1078 |
try { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1079 |
make.at(kInfo.clazz); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1080 |
addDeserializationCase(refKind, refSym, tree.type, samSym, |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1081 |
tree, staticArgs, indyType); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1082 |
} finally { |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1083 |
make.at(prevPos); |
2eb1bb11add1
8026861: Wrong LineNumberTable for variable declarations in lambdas
jlahoda
parents:
21495
diff
changeset
|
1084 |
} |
16300 | 1085 |
} |
1086 |
} |
|
1087 |
||
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1088 |
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
|
1089 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1090 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1091 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1092 |
* 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
|
1093 |
* arguments types |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1094 |
*/ |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1095 |
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
|
1096 |
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
|
1097 |
Name methName) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1098 |
int prevPos = make.pos; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1099 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1100 |
make.at(pos); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1101 |
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
|
1102 |
syms.stringType, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1103 |
syms.methodTypeType).appendList(bsmStaticArgToTypes(staticArgs)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1104 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1105 |
Symbol bsm = rs.resolveInternalMethod(pos, attrEnv, site, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
1106 |
bsmName, bsm_staticArgs, List.nil()); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1107 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1108 |
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
|
1109 |
new DynamicMethodSymbol(methName, |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1110 |
syms.noSymbol, |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1111 |
bsm.isStatic() ? |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1112 |
ClassFile.REF_invokeStatic : |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1113 |
ClassFile.REF_invokeVirtual, |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1114 |
(MethodSymbol)bsm, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1115 |
indyType, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1116 |
staticArgs.toArray()); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1117 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1118 |
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
|
1119 |
qualifier.sym = dynSym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1120 |
qualifier.type = indyType.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1121 |
|
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
1122 |
JCMethodInvocation proxyCall = make.Apply(List.nil(), qualifier, indyArgs); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1123 |
proxyCall.type = indyType.getReturnType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1124 |
return proxyCall; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1125 |
} finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1126 |
make.at(prevPos); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1127 |
} |
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 |
//where |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1130 |
private List<Type> bsmStaticArgToTypes(List<Object> args) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
1131 |
ListBuffer<Type> argtypes = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1132 |
for (Object arg : args) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1133 |
argtypes.append(bsmStaticArgToType(arg)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1134 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1135 |
return argtypes.toList(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1136 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1137 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1138 |
private Type bsmStaticArgToType(Object arg) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1139 |
Assert.checkNonNull(arg); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1140 |
if (arg instanceof ClassSymbol) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1141 |
return syms.classType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1142 |
} else if (arg instanceof Integer) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1143 |
return syms.intType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1144 |
} else if (arg instanceof Long) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1145 |
return syms.longType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1146 |
} else if (arg instanceof Float) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1147 |
return syms.floatType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1148 |
} else if (arg instanceof Double) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1149 |
return syms.doubleType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1150 |
} else if (arg instanceof String) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1151 |
return syms.stringType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1152 |
} else if (arg instanceof Pool.MethodHandle) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1153 |
return syms.methodHandleType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1154 |
} else if (arg instanceof MethodType) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1155 |
return syms.methodTypeType; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1156 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1157 |
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
|
1158 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1159 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1160 |
} |
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 |
* 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
|
1164 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1165 |
private int referenceKind(Symbol refSym) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1166 |
if (refSym.isConstructor()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1167 |
return ClassFile.REF_newInvokeSpecial; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1168 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1169 |
if (refSym.isStatic()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1170 |
return ClassFile.REF_invokeStatic; |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1171 |
} else if ((refSym.flags() & PRIVATE) != 0) { |
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1172 |
return ClassFile.REF_invokeSpecial; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1173 |
} else if (refSym.enclClass().isInterface()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1174 |
return ClassFile.REF_invokeInterface; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1175 |
} else { |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1176 |
return ClassFile.REF_invokeVirtual; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1177 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1178 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1179 |
} |
16300 | 1180 |
|
16564
061aa10703e8
8009649: Lambda back-end should generate invokespecial for method handles referring to private instance methods
mcimadamore
parents:
16551
diff
changeset
|
1181 |
// <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
|
1182 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1183 |
* 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
|
1184 |
* 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
|
1185 |
* 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
|
1186 |
* 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
|
1187 |
*/ |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1188 |
class LambdaAnalyzerPreprocessor extends TreeTranslator { |
14365
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 |
/** 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
|
1191 |
private List<Frame> frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1192 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1193 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1194 |
* 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
|
1195 |
* names) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1196 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1197 |
private int lambdaCount = 0; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1198 |
|
16300 | 1199 |
/** |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1200 |
* List of types undergoing construction via explicit constructor chaining. |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1201 |
*/ |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1202 |
private List<ClassSymbol> typesUnderConstruction; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1203 |
|
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1204 |
/** |
16300 | 1205 |
* keep the count of lambda expression defined in given context (used to |
1206 |
* generate unambiguous names for serializable lambdas) |
|
1207 |
*/ |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1208 |
private class SyntheticMethodNameCounter { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1209 |
private Map<String, Integer> map = new HashMap<>(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1210 |
int getIndex(StringBuilder buf) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1211 |
String temp = buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1212 |
Integer count = map.get(temp); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1213 |
if (count == null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1214 |
count = 0; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1215 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1216 |
++count; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1217 |
map.put(temp, count); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1218 |
return count; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1219 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1220 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1221 |
private SyntheticMethodNameCounter syntheticMethodNameCounts = |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1222 |
new SyntheticMethodNameCounter(); |
16300 | 1223 |
|
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1224 |
private Map<Symbol, JCClassDecl> localClassDefs; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1225 |
|
16300 | 1226 |
/** |
1227 |
* maps for fake clinit symbols to be used as owners of lambda occurring in |
|
1228 |
* a static var init context |
|
1229 |
*/ |
|
22163 | 1230 |
private Map<ClassSymbol, Symbol> clinits = new HashMap<>(); |
16300 | 1231 |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1232 |
private JCClassDecl analyzeAndPreprocessClass(JCClassDecl tree) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1233 |
frameStack = List.nil(); |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1234 |
typesUnderConstruction = List.nil(); |
22163 | 1235 |
localClassDefs = new HashMap<>(); |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1236 |
return translate(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1237 |
} |
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 |
@Override |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1240 |
public void visitApply(JCMethodInvocation tree) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1241 |
List<ClassSymbol> previousNascentTypes = typesUnderConstruction; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1242 |
try { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1243 |
Name methName = TreeInfo.name(tree.meth); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1244 |
if (methName == names._this || methName == names._super) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1245 |
typesUnderConstruction = typesUnderConstruction.prepend(currentClass()); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1246 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1247 |
super.visitApply(tree); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1248 |
} finally { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1249 |
typesUnderConstruction = previousNascentTypes; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1250 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1251 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1252 |
// where |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1253 |
private ClassSymbol currentClass() { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1254 |
for (Frame frame : frameStack) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1255 |
if (frame.tree.hasTag(JCTree.Tag.CLASSDEF)) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1256 |
JCClassDecl cdef = (JCClassDecl) frame.tree; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1257 |
return cdef.sym; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1258 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1259 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1260 |
return null; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1261 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1262 |
|
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1263 |
@Override |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1264 |
public void visitBlock(JCBlock tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1265 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1266 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1267 |
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
|
1268 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1269 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1270 |
super.visitBlock(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1271 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1272 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1273 |
frameStack = prevStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1274 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1275 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1276 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1277 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1278 |
public void visitClassDef(JCClassDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1279 |
List<Frame> prevStack = frameStack; |
28145
365419055307
8067422: Lambda method names are unnecessarily unstable
jlahoda
parents:
27855
diff
changeset
|
1280 |
int prevLambdaCount = lambdaCount; |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1281 |
SyntheticMethodNameCounter prevSyntheticMethodNameCounts = |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1282 |
syntheticMethodNameCounts; |
16300 | 1283 |
Map<ClassSymbol, Symbol> prevClinits = clinits; |
18386 | 1284 |
DiagnosticSource prevSource = log.currentSource(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1285 |
try { |
18386 | 1286 |
log.useSource(tree.sym.sourcefile); |
28145
365419055307
8067422: Lambda method names are unnecessarily unstable
jlahoda
parents:
27855
diff
changeset
|
1287 |
lambdaCount = 0; |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1288 |
syntheticMethodNameCounts = new SyntheticMethodNameCounter(); |
22163 | 1289 |
prevClinits = new HashMap<>(); |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1290 |
if (tree.sym.owner.kind == MTH) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1291 |
localClassDefs.put(tree.sym, tree); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1292 |
} |
16300 | 1293 |
if (directlyEnclosingLambda() != null) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1294 |
tree.sym.owner = owner(); |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1295 |
if (tree.sym.hasOuterInstance()) { |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1296 |
//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
|
1297 |
//its enclosing instance (if any) |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1298 |
TranslationContext<?> localContext = context(); |
31296
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1299 |
final TypeSymbol outerInstanceSymbol = tree.sym.type.getEnclosingType().tsym; |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1300 |
while (localContext != null && !localContext.owner.isStatic()) { |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1301 |
if (localContext.tree.hasTag(LAMBDA)) { |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1302 |
JCTree block = capturedDecl(localContext.depth, outerInstanceSymbol); |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1303 |
if (block == null) break; |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1304 |
((LambdaTranslationContext)localContext) |
31296
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1305 |
.addSymbol(outerInstanceSymbol, CAPTURED_THIS); |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1306 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1307 |
localContext = localContext.prev; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1308 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1309 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1310 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1311 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1312 |
super.visitClassDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1313 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1314 |
finally { |
18386 | 1315 |
log.useSource(prevSource.getFile()); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1316 |
frameStack = prevStack; |
28145
365419055307
8067422: Lambda method names are unnecessarily unstable
jlahoda
parents:
27855
diff
changeset
|
1317 |
lambdaCount = prevLambdaCount; |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1318 |
syntheticMethodNameCounts = prevSyntheticMethodNameCounts; |
16300 | 1319 |
clinits = prevClinits; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1320 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1321 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1322 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1323 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1324 |
public void visitIdent(JCIdent tree) { |
16300 | 1325 |
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
|
1326 |
if (tree.sym.kind == VAR && |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1327 |
tree.sym.owner.kind == MTH && |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1328 |
tree.type.constValue() == null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1329 |
TranslationContext<?> localContext = context(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1330 |
while (localContext != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1331 |
if (localContext.tree.getTag() == LAMBDA) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1332 |
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
|
1333 |
if (block == null) break; |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1334 |
((LambdaTranslationContext)localContext) |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1335 |
.addSymbol(tree.sym, CAPTURED_VAR); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1336 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1337 |
localContext = localContext.prev; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1338 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1339 |
} 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
|
1340 |
TranslationContext<?> localContext = context(); |
31296
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1341 |
while (localContext != null && !localContext.owner.isStatic()) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1342 |
if (localContext.tree.hasTag(LAMBDA)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1343 |
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
|
1344 |
if (block == null) break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1345 |
switch (block.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1346 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1347 |
JCClassDecl cdecl = (JCClassDecl)block; |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1348 |
((LambdaTranslationContext)localContext) |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1349 |
.addSymbol(cdecl.sym, CAPTURED_THIS); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1350 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1351 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1352 |
Assert.error("bad block kind"); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1353 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1354 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1355 |
localContext = localContext.prev; |
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 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1358 |
} |
16300 | 1359 |
super.visitIdent(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1360 |
} |
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 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1363 |
public void visitLambda(JCLambda tree) { |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1364 |
analyzeLambda(tree, "lambda.stat"); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1365 |
} |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1366 |
|
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1367 |
private void analyzeLambda(JCLambda tree, JCExpression methodReferenceReceiver) { |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1368 |
// Translation of the receiver expression must occur first |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1369 |
JCExpression rcvr = translate(methodReferenceReceiver); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1370 |
LambdaTranslationContext context = analyzeLambda(tree, "mref.stat.1"); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1371 |
if (rcvr != null) { |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1372 |
context.methodReferenceReceiver = rcvr; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1373 |
} |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1374 |
} |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1375 |
|
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1376 |
private LambdaTranslationContext analyzeLambda(JCLambda tree, String statKey) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1377 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1378 |
try { |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1379 |
LambdaTranslationContext context = new LambdaTranslationContext(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1380 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1381 |
for (JCVariableDecl param : tree.params) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1382 |
context.addSymbol(param.sym, PARAM); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1383 |
frameStack.head.addLocal(param.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1384 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1385 |
contextMap.put(tree, context); |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1386 |
super.visitLambda(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1387 |
context.complete(); |
33916
9b8030e8e0d9
8143217: javac throws NPE when printing diagnostics for Lambda expressions
sadayapalam
parents:
33712
diff
changeset
|
1388 |
if (dumpLambdaToMethodStats) { |
9b8030e8e0d9
8143217: javac throws NPE when printing diagnostics for Lambda expressions
sadayapalam
parents:
33712
diff
changeset
|
1389 |
log.note(tree, statKey, context.needsAltMetafactory(), context.translatedSym); |
9b8030e8e0d9
8143217: javac throws NPE when printing diagnostics for Lambda expressions
sadayapalam
parents:
33712
diff
changeset
|
1390 |
} |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1391 |
return context; |
14365
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 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1394 |
frameStack = prevStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1395 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1396 |
} |
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 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1399 |
public void visitMethodDef(JCMethodDecl tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1400 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1401 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1402 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1403 |
super.visitMethodDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1404 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1405 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1406 |
frameStack = prevStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1407 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1408 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1409 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1410 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1411 |
public void visitNewClass(JCNewClass tree) { |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1412 |
TypeSymbol def = tree.type.tsym; |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1413 |
boolean inReferencedClass = currentlyInClass(def); |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1414 |
boolean isLocal = def.isLocal(); |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1415 |
if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) { |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1416 |
TranslationContext<?> localContext = context(); |
31296
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1417 |
final TypeSymbol outerInstanceSymbol = tree.type.getEnclosingType().tsym; |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1418 |
while (localContext != null && !localContext.owner.isStatic()) { |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1419 |
if (localContext.tree.hasTag(LAMBDA)) { |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1420 |
if (outerInstanceSymbol != null) { |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1421 |
JCTree block = capturedDecl(localContext.depth, outerInstanceSymbol); |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1422 |
if (block == null) break; |
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1423 |
} |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1424 |
((LambdaTranslationContext)localContext) |
31296
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1425 |
.addSymbol(outerInstanceSymbol, CAPTURED_THIS); |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1426 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1427 |
localContext = localContext.prev; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1428 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1429 |
} |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1430 |
if (context() != null && !inReferencedClass && isLocal) { |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1431 |
LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1432 |
captureLocalClassDefs(def, lambdaContext); |
14365
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 |
super.visitNewClass(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1435 |
} |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1436 |
//where |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1437 |
void captureLocalClassDefs(Symbol csym, final LambdaTranslationContext lambdaContext) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1438 |
JCClassDecl localCDef = localClassDefs.get(csym); |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1439 |
if (localCDef != null && lambdaContext.freeVarProcessedLocalClasses.add(csym)) { |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1440 |
BasicFreeVarCollector fvc = lower.new BasicFreeVarCollector() { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1441 |
@Override |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1442 |
void addFreeVars(ClassSymbol c) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1443 |
captureLocalClassDefs(c, lambdaContext); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1444 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1445 |
@Override |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1446 |
void visitSymbol(Symbol sym) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1447 |
if (sym.kind == VAR && |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1448 |
sym.owner.kind == MTH && |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1449 |
((VarSymbol)sym).getConstValue() == null) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1450 |
TranslationContext<?> localContext = context(); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1451 |
while (localContext != null) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1452 |
if (localContext.tree.getTag() == LAMBDA) { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1453 |
JCTree block = capturedDecl(localContext.depth, sym); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1454 |
if (block == null) break; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1455 |
((LambdaTranslationContext)localContext).addSymbol(sym, CAPTURED_VAR); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1456 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1457 |
localContext = localContext.prev; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1458 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1459 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1460 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1461 |
}; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1462 |
fvc.scan(localCDef); |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
1463 |
} |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1464 |
} |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1465 |
//where |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1466 |
boolean currentlyInClass(Symbol csym) { |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1467 |
for (Frame frame : frameStack) { |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1468 |
if (frame.tree.hasTag(JCTree.Tag.CLASSDEF)) { |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1469 |
JCClassDecl cdef = (JCClassDecl) frame.tree; |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1470 |
if (cdef.sym == csym) { |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1471 |
return true; |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1472 |
} |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1473 |
} |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1474 |
} |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1475 |
return false; |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1476 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1477 |
|
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1478 |
/** |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1479 |
* 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
|
1480 |
* class references local variables, have implicit constructor |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1481 |
* 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
|
1482 |
* 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
|
1483 |
* 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
|
1484 |
* handle normal "new" in this case. This visitor converts potentially |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1485 |
* affected method references into a lambda containing a normal |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1486 |
* expression. |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1487 |
* |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1488 |
* @param tree |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1489 |
*/ |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1490 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1491 |
public void visitReference(JCMemberReference tree) { |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1492 |
ReferenceTranslationContext rcontext = new ReferenceTranslationContext(tree); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1493 |
contextMap.put(tree, rcontext); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1494 |
if (rcontext.needsConversionToLambda()) { |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1495 |
// Convert to a lambda, and process as such |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1496 |
MemberReferenceToLambda conv = new MemberReferenceToLambda(tree, rcontext, owner()); |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1497 |
analyzeLambda(conv.lambda(), conv.getReceiverExpression()); |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1498 |
} else { |
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1499 |
super.visitReference(tree); |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1500 |
if (dumpLambdaToMethodStats) { |
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
44230
diff
changeset
|
1501 |
log.note(tree, Notes.MrefStat(rcontext.needsAltMetafactory(), null)); |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1502 |
} |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1503 |
} |
14365
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 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1506 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1507 |
public void visitSelect(JCFieldAccess tree) { |
17585
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1508 |
if (context() != null && tree.sym.kind == VAR && |
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1509 |
(tree.sym.name == names._this || |
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1510 |
tree.sym.name == names._super)) { |
bf56a85f3897
8010006: NPE in javac with interface super in lambda
rfield
parents:
17578
diff
changeset
|
1511 |
// 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
|
1512 |
// 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
|
1513 |
TranslationContext<?> localContext = context(); |
31296
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1514 |
while (localContext != null && !localContext.owner.isStatic()) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1515 |
if (localContext.tree.hasTag(LAMBDA)) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1516 |
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
|
1517 |
if (clazz == null) break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1518 |
((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
|
1519 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1520 |
localContext = localContext.prev; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1521 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1522 |
} |
17286
fec581c36de4
8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
16798
diff
changeset
|
1523 |
super.visitSelect(tree); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1524 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1525 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1526 |
@Override |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1527 |
public void visitVarDef(JCVariableDecl tree) { |
16300 | 1528 |
TranslationContext<?> context = context(); |
1529 |
LambdaTranslationContext ltc = (context != null && context instanceof LambdaTranslationContext)? |
|
1530 |
(LambdaTranslationContext)context : |
|
1531 |
null; |
|
1532 |
if (ltc != null) { |
|
1533 |
if (frameStack.head.tree.hasTag(LAMBDA)) { |
|
1534 |
ltc.addSymbol(tree.sym, LOCAL_VAR); |
|
1535 |
} |
|
1536 |
// Check for type variables (including as type arguments). |
|
1537 |
// If they occur within class nested in a lambda, mark for erasure |
|
1538 |
Type type = tree.sym.asType(); |
|
1539 |
if (inClassWithinLambda() && !types.isSameType(types.erasure(type), type)) { |
|
1540 |
ltc.addSymbol(tree.sym, TYPE_VAR); |
|
1541 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1542 |
} |
16300 | 1543 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1544 |
List<Frame> prevStack = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1545 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1546 |
if (tree.sym.owner.kind == MTH) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1547 |
frameStack.head.addLocal(tree.sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1548 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1549 |
frameStack = frameStack.prepend(new Frame(tree)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1550 |
super.visitVarDef(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1551 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1552 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1553 |
frameStack = prevStack; |
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 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1558 |
* 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
|
1559 |
* (required to skip synthetic lambda symbols) |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1560 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1561 |
private Symbol owner() { |
15379
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1562 |
return owner(false); |
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1563 |
} |
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1564 |
|
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1565 |
@SuppressWarnings("fallthrough") |
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1566 |
private Symbol owner(boolean skipLambda) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1567 |
List<Frame> frameStack2 = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1568 |
while (frameStack2.nonEmpty()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1569 |
switch (frameStack2.head.tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1570 |
case VARDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1571 |
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
|
1572 |
frameStack2 = frameStack2.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1573 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1574 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1575 |
JCClassDecl cdecl = (JCClassDecl)frameStack2.tail.head.tree; |
16300 | 1576 |
return initSym(cdecl.sym, |
1577 |
((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
|
1578 |
case BLOCK: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1579 |
JCClassDecl cdecl2 = (JCClassDecl)frameStack2.tail.head.tree; |
16300 | 1580 |
return initSym(cdecl2.sym, |
1581 |
((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
|
1582 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1583 |
return ((JCClassDecl)frameStack2.head.tree).sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1584 |
case METHODDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1585 |
return ((JCMethodDecl)frameStack2.head.tree).sym; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1586 |
case LAMBDA: |
15379
c483442d0939
8006684: Compiler produces java.lang.VerifyError: Bad type on operand stack
mcimadamore
parents:
15374
diff
changeset
|
1587 |
if (!skipLambda) |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1588 |
return ((LambdaTranslationContext)contextMap |
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
1589 |
.get(frameStack2.head.tree)).translatedSym; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1590 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1591 |
frameStack2 = frameStack2.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1592 |
} |
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 |
Assert.error(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1595 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1596 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1597 |
|
16300 | 1598 |
private Symbol initSym(ClassSymbol csym, long flags) { |
1599 |
boolean isStatic = (flags & STATIC) != 0; |
|
1600 |
if (isStatic) { |
|
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1601 |
/* static clinits are generated in Gen, so we need to use a fake |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1602 |
* one. Attr creates a fake clinit method while attributing |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1603 |
* lambda expressions used as initializers of static fields, so |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1604 |
* let's use that one. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1605 |
*/ |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1606 |
MethodSymbol clinit = attr.removeClinit(csym); |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1607 |
if (clinit != null) { |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1608 |
clinits.put(csym, clinit); |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1609 |
return clinit; |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1610 |
} |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1611 |
|
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1612 |
/* if no clinit is found at Attr, then let's try at clinits. |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1613 |
*/ |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1614 |
clinit = (MethodSymbol)clinits.get(csym); |
16300 | 1615 |
if (clinit == null) { |
22162
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1616 |
/* no luck, let's create a new one |
3b3e23e67329
8029721: javac crash for annotated parameter type of lambda in a field
vromero
parents:
21892
diff
changeset
|
1617 |
*/ |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
1618 |
clinit = makePrivateSyntheticMethod(STATIC, |
16300 | 1619 |
names.clinit, |
42828
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
1620 |
new MethodType(List.nil(), syms.voidType, |
cce89649f958
8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents:
41028
diff
changeset
|
1621 |
List.nil(), syms.methodClass), |
16300 | 1622 |
csym); |
1623 |
clinits.put(csym, clinit); |
|
1624 |
} |
|
1625 |
return clinit; |
|
1626 |
} else { |
|
1627 |
//get the first constructor and treat it as the instance init sym |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25281
diff
changeset
|
1628 |
for (Symbol s : csym.members_field.getSymbolsByName(names.init)) { |
16300 | 1629 |
return s; |
1630 |
} |
|
1631 |
} |
|
1632 |
Assert.error("init not found"); |
|
1633 |
return null; |
|
1634 |
} |
|
1635 |
||
1636 |
private JCTree directlyEnclosingLambda() { |
|
1637 |
if (frameStack.isEmpty()) { |
|
1638 |
return null; |
|
1639 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1640 |
List<Frame> frameStack2 = frameStack; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1641 |
while (frameStack2.nonEmpty()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1642 |
switch (frameStack2.head.tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1643 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1644 |
case METHODDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1645 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1646 |
case LAMBDA: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1647 |
return frameStack2.head.tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1648 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1649 |
frameStack2 = frameStack2.tail; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1650 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1651 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1652 |
Assert.error(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1653 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1654 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1655 |
|
16300 | 1656 |
private boolean inClassWithinLambda() { |
1657 |
if (frameStack.isEmpty()) { |
|
1658 |
return false; |
|
1659 |
} |
|
1660 |
List<Frame> frameStack2 = frameStack; |
|
1661 |
boolean classFound = false; |
|
1662 |
while (frameStack2.nonEmpty()) { |
|
1663 |
switch (frameStack2.head.tree.getTag()) { |
|
1664 |
case LAMBDA: |
|
1665 |
return classFound; |
|
1666 |
case CLASSDEF: |
|
1667 |
classFound = true; |
|
1668 |
frameStack2 = frameStack2.tail; |
|
1669 |
break; |
|
1670 |
default: |
|
1671 |
frameStack2 = frameStack2.tail; |
|
1672 |
} |
|
1673 |
} |
|
1674 |
// No lambda |
|
1675 |
return false; |
|
1676 |
} |
|
1677 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1678 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1679 |
* 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
|
1680 |
* 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
|
1681 |
* 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
|
1682 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1683 |
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
|
1684 |
int currentDepth = frameStack.size() - 1; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1685 |
for (Frame block : frameStack) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1686 |
switch (block.tree.getTag()) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1687 |
case CLASSDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1688 |
ClassSymbol clazz = ((JCClassDecl)block.tree).sym; |
31296
9a8e44b62c77
8076538: Verify error at runtime due to incorrect classification of a lambda as being instance capturing
sadayapalam
parents:
29772
diff
changeset
|
1689 |
if (clazz.isSubClass(sym, types) || sym.isMemberOf(clazz, types)) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1690 |
return currentDepth > depth ? null : block.tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1691 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1692 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1693 |
case VARDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1694 |
if (((JCVariableDecl)block.tree).sym == sym && |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1695 |
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
|
1696 |
return currentDepth > depth ? null : block.tree; |
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 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1699 |
case BLOCK: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1700 |
case METHODDEF: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1701 |
case LAMBDA: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1702 |
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
|
1703 |
return currentDepth > depth ? null : block.tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1704 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1705 |
break; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1706 |
default: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1707 |
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
|
1708 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1709 |
currentDepth--; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1710 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1711 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1712 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1713 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1714 |
private TranslationContext<?> context() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1715 |
for (Frame frame : frameStack) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1716 |
TranslationContext<?> context = contextMap.get(frame.tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1717 |
if (context != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1718 |
return context; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1719 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1720 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1721 |
return null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1722 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1723 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1724 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1725 |
* 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
|
1726 |
* when translating away lambda expressions |
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 |
private boolean lambdaIdentSymbolFilter(Symbol sym) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1729 |
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
|
1730 |
&& !sym.isStatic() |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1731 |
&& sym.name != names.init; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1732 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1733 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1734 |
/** |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1735 |
* This is used to filter out those select nodes that need to be adjusted |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1736 |
* when translating away lambda expressions - at the moment, this is the |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1737 |
* set of nodes that select `this' (qualified this) |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1738 |
*/ |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1739 |
private boolean lambdaFieldAccessFilter(JCFieldAccess fAccess) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1740 |
LambdaTranslationContext lambdaContext = |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1741 |
context instanceof LambdaTranslationContext ? |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1742 |
(LambdaTranslationContext) context : null; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1743 |
return lambdaContext != null |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1744 |
&& !fAccess.sym.isStatic() |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1745 |
&& fAccess.name == names._this |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1746 |
&& (fAccess.sym.owner.kind == TYP) |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1747 |
&& !lambdaContext.translatedSymbols.get(CAPTURED_OUTER_THIS).isEmpty(); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1748 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1749 |
|
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1750 |
/** |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1751 |
* 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
|
1752 |
* be qualified with an enclosing tree |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1753 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1754 |
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
|
1755 |
if (context != null |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1756 |
&& tree.encl == null |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1757 |
&& tree.def == null |
14537
ad188879b6fe
8003306: Compiler crash: calculation of inner class access modifier
rfield
parents:
14365
diff
changeset
|
1758 |
&& !tree.type.getEnclosingType().hasTag(NONE)) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1759 |
Type encl = tree.type.getEnclosingType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1760 |
Type current = context.owner.enclClass().type; |
14537
ad188879b6fe
8003306: Compiler crash: calculation of inner class access modifier
rfield
parents:
14365
diff
changeset
|
1761 |
while (!current.hasTag(NONE)) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1762 |
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
|
1763 |
return true; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1764 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1765 |
current = current.getEnclosingType(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1766 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1767 |
return false; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1768 |
} else { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1769 |
return false; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1770 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1771 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1772 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1773 |
private class Frame { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1774 |
final JCTree tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1775 |
List<Symbol> locals; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1776 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1777 |
public Frame(JCTree tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1778 |
this.tree = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1779 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1780 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1781 |
void addLocal(Symbol sym) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1782 |
if (locals == null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1783 |
locals = List.nil(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1784 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1785 |
locals = locals.prepend(sym); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1786 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1787 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1788 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1789 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1790 |
* 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
|
1791 |
* lambda expression/method references (see subclasses). |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1792 |
*/ |
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
29051
diff
changeset
|
1793 |
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
|
1794 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1795 |
/** the underlying (untranslated) tree */ |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1796 |
final T tree; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1797 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1798 |
/** 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
|
1799 |
final Symbol owner; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1800 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1801 |
/** 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
|
1802 |
final int depth; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1803 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1804 |
/** 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
|
1805 |
final TranslationContext<?> prev; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1806 |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1807 |
/** 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
|
1808 |
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
|
1809 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1810 |
TranslationContext(T tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1811 |
this.tree = tree; |
35418
8681d57fc3f8
8144168: No type annotations generated for nested lambdas
sadayapalam
parents:
34752
diff
changeset
|
1812 |
this.owner = owner(true); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1813 |
this.depth = frameStack.size() - 1; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1814 |
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
|
1815 |
ClassSymbol csym = |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1816 |
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
|
1817 |
this.bridges = types.functionalInterfaceBridges(csym); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1818 |
} |
16300 | 1819 |
|
1820 |
/** does this functional expression need to be created using alternate metafactory? */ |
|
1821 |
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
|
1822 |
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
|
1823 |
isSerializable() || |
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1824 |
bridges.length() > 1; |
16300 | 1825 |
} |
1826 |
||
1827 |
/** does this functional expression require serialization support? */ |
|
1828 |
boolean isSerializable() { |
|
39588
a30039aaca6c
8160915: javac, option forceSerializable should be restored
vromero
parents:
39587
diff
changeset
|
1829 |
if (forceSerializable) { |
a30039aaca6c
8160915: javac, option forceSerializable should be restored
vromero
parents:
39587
diff
changeset
|
1830 |
return true; |
a30039aaca6c
8160915: javac, option forceSerializable should be restored
vromero
parents:
39587
diff
changeset
|
1831 |
} |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
1832 |
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
|
1833 |
if (types.asSuper(target, syms.serializableType.tsym) != null) { |
16300 | 1834 |
return true; |
1835 |
} |
|
1836 |
} |
|
1837 |
return false; |
|
1838 |
} |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1839 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1840 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1841 |
* @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
|
1842 |
* method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1843 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1844 |
String enclosingMethodName() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1845 |
return syntheticMethodNameComponent(owner.name); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1846 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1847 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1848 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1849 |
* @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
|
1850 |
* component of a synthetic method name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1851 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1852 |
String syntheticMethodNameComponent(Name name) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1853 |
if (name == null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1854 |
return "null"; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1855 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1856 |
String methodName = name.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1857 |
if (methodName.equals("<clinit>")) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1858 |
methodName = "static"; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1859 |
} else if (methodName.equals("<init>")) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1860 |
methodName = "new"; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1861 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1862 |
return methodName; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1863 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1864 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1865 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1866 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1867 |
* 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
|
1868 |
* 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
|
1869 |
* 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
|
1870 |
* to captured locals/members, etc. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1871 |
*/ |
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
29051
diff
changeset
|
1872 |
class LambdaTranslationContext extends TranslationContext<JCLambda> { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1873 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1874 |
/** 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
|
1875 |
final Symbol self; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1876 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1877 |
/** 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
|
1878 |
final Symbol assignedTo; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1879 |
|
21486 | 1880 |
Map<LambdaSymbolKind, Map<Symbol, Symbol>> translatedSymbols; |
16300 | 1881 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1882 |
/** the synthetic symbol for the method hoisting the translated lambda */ |
28452
6afa05455443
8037546: javac -parameters does not emit parameter names for lambda expressions
jlahoda
parents:
28145
diff
changeset
|
1883 |
MethodSymbol translatedSym; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1884 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1885 |
List<JCVariableDecl> syntheticParams; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1886 |
|
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1887 |
/** |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1888 |
* to prevent recursion, track local classes processed |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1889 |
*/ |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1890 |
final Set<Symbol> freeVarProcessedLocalClasses; |
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1891 |
|
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1892 |
/** |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1893 |
* For method references converted to lambdas. The method |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1894 |
* reference receiver expression. Must be treated like a captured |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1895 |
* variable. |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1896 |
*/ |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1897 |
JCExpression methodReferenceReceiver; |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
1898 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1899 |
LambdaTranslationContext(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1900 |
super(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1901 |
Frame frame = frameStack.head; |
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1902 |
switch (frame.tree.getTag()) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1903 |
case VARDEF: |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1904 |
assignedTo = self = ((JCVariableDecl) frame.tree).sym; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1905 |
break; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1906 |
case ASSIGN: |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1907 |
self = null; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1908 |
assignedTo = TreeInfo.symbol(((JCAssign) frame.tree).getVariable()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1909 |
break; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1910 |
default: |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1911 |
assignedTo = self = null; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1912 |
break; |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1913 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1914 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1915 |
// This symbol will be filled-in in complete |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1916 |
this.translatedSym = makePrivateSyntheticMethod(0, null, null, owner.enclClass()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1917 |
|
21486 | 1918 |
translatedSymbols = new EnumMap<>(LambdaSymbolKind.class); |
1919 |
||
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
1920 |
translatedSymbols.put(PARAM, new LinkedHashMap<Symbol, Symbol>()); |
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
1921 |
translatedSymbols.put(LOCAL_VAR, new LinkedHashMap<Symbol, Symbol>()); |
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
1922 |
translatedSymbols.put(CAPTURED_VAR, new LinkedHashMap<Symbol, Symbol>()); |
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
1923 |
translatedSymbols.put(CAPTURED_THIS, new LinkedHashMap<Symbol, Symbol>()); |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
1924 |
translatedSymbols.put(CAPTURED_OUTER_THIS, new LinkedHashMap<Symbol, Symbol>()); |
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
1925 |
translatedSymbols.put(TYPE_VAR, new LinkedHashMap<Symbol, Symbol>()); |
24225
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1926 |
|
44f3a7b2ac71
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
24224
diff
changeset
|
1927 |
freeVarProcessedLocalClasses = new HashSet<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1928 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
1929 |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1930 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1931 |
* For a serializable lambda, generate a disambiguating string |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1932 |
* which maximizes stability across deserialization. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1933 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1934 |
* @return String to differentiate synthetic lambda method names |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1935 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1936 |
private String serializedLambdaDisambiguation() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1937 |
StringBuilder buf = new StringBuilder(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1938 |
// Append the enclosing method signature to differentiate |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1939 |
// overloaded enclosing methods. For lambdas enclosed in |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1940 |
// 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
|
1941 |
// 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
|
1942 |
// 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
|
1943 |
// overloaded. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1944 |
Assert.check( |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1945 |
owner.type != null || |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1946 |
directlyEnclosingLambda() != null); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1947 |
if (owner.type != null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1948 |
buf.append(typeSig(owner.type)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1949 |
buf.append(":"); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1950 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1951 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1952 |
// Add target type info |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1953 |
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
|
1954 |
buf.append(" "); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1955 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1956 |
// Add variable assigned to |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1957 |
if (assignedTo != null) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1958 |
buf.append(assignedTo.flatName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1959 |
buf.append("="); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1960 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1961 |
//add captured locals info: type, name, order |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1962 |
for (Symbol fv : getSymbolMap(CAPTURED_VAR).keySet()) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1963 |
if (fv != self) { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1964 |
buf.append(typeSig(fv.type)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1965 |
buf.append(" "); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1966 |
buf.append(fv.flatName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1967 |
buf.append(","); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1968 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1969 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1970 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1971 |
return buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1972 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1973 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1974 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1975 |
* 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
|
1976 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1977 |
* @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
|
1978 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1979 |
private Name lambdaName() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1980 |
return names.lambda.append(names.fromString(enclosingMethodName() + "$" + lambdaCount++)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1981 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1982 |
|
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1983 |
/** |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1984 |
* 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
|
1985 |
* name stability across deserialization. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1986 |
* |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1987 |
* @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
|
1988 |
*/ |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1989 |
private Name serializedLambdaName() { |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1990 |
StringBuilder buf = new StringBuilder(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1991 |
buf.append(names.lambda); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1992 |
// 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
|
1993 |
buf.append(enclosingMethodName()); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1994 |
buf.append('$'); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1995 |
// 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
|
1996 |
// signature, etc. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1997 |
String disam = serializedLambdaDisambiguation(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1998 |
buf.append(Integer.toHexString(disam.hashCode())); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
1999 |
buf.append('$'); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2000 |
// 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
|
2001 |
// a count based on the above name components. |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2002 |
buf.append(syntheticMethodNameCounts.getIndex(buf)); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2003 |
String result = buf.toString(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2004 |
//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
|
2005 |
return names.fromString(result); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2006 |
} |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2007 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2008 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2009 |
* 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
|
2010 |
* synthetic lambda body |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2011 |
*/ |
29772
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2012 |
Symbol translate(final Symbol sym, LambdaSymbolKind skind) { |
17578 | 2013 |
Symbol ret; |
16300 | 2014 |
switch (skind) { |
2015 |
case CAPTURED_THIS: |
|
17578 | 2016 |
ret = sym; // self represented |
2017 |
break; |
|
16300 | 2018 |
case TYPE_VAR: |
2019 |
// Just erase the type var |
|
29772
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2020 |
ret = new VarSymbol(sym.flags(), sym.name, |
16308
a0658c36f717
8008227: Mixing lambdas with anonymous classes leads to NPE thrown by compiler
mcimadamore
parents:
16300
diff
changeset
|
2021 |
types.erasure(sym.type), sym.owner); |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
2022 |
|
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
2023 |
/* 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
|
2024 |
* 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
|
2025 |
*/ |
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19651
diff
changeset
|
2026 |
((VarSymbol)ret).pos = ((VarSymbol)sym).pos; |
17578 | 2027 |
break; |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
2028 |
case CAPTURED_VAR: |
29772
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2029 |
ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, sym.name, types.erasure(sym.type), translatedSym) { |
16325
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
2030 |
@Override |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
2031 |
public Symbol baseSymbol() { |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
2032 |
//keep mapping with original captured symbol |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
2033 |
return sym; |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
2034 |
} |
088a91896245
8004962: Code generation crash with lambda and local classes
mcimadamore
parents:
16310
diff
changeset
|
2035 |
}; |
17578 | 2036 |
break; |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2037 |
case CAPTURED_OUTER_THIS: |
34568
afc0330fa0d4
8145051: Wrong parameter name in synthetic lambda method leads to verifier error
sadayapalam
parents:
34472
diff
changeset
|
2038 |
Name name = names.fromString(new String(sym.flatName().toString().replace('.', '$') + names.dollarThis)); |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2039 |
ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2040 |
@Override |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2041 |
public Symbol baseSymbol() { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2042 |
//keep mapping with original captured symbol |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2043 |
return sym; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2044 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2045 |
}; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2046 |
break; |
21477 | 2047 |
case LOCAL_VAR: |
29772
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2048 |
ret = new VarSymbol(sym.flags() & FINAL, sym.name, sym.type, translatedSym); |
21477 | 2049 |
((VarSymbol) ret).pos = ((VarSymbol) sym).pos; |
2050 |
break; |
|
2051 |
case PARAM: |
|
29772
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2052 |
ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, sym.name, types.erasure(sym.type), translatedSym); |
21477 | 2053 |
((VarSymbol) ret).pos = ((VarSymbol) sym).pos; |
2054 |
break; |
|
16300 | 2055 |
default: |
29772
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2056 |
Assert.error(skind.name()); |
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2057 |
throw new AssertionError(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2058 |
} |
17578 | 2059 |
if (ret != sym) { |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17585
diff
changeset
|
2060 |
ret.setDeclarationAttributes(sym.getRawAttributes()); |
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17585
diff
changeset
|
2061 |
ret.setTypeAttributes(sym.getRawTypeAttributes()); |
17578 | 2062 |
} |
2063 |
return ret; |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2064 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2065 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2066 |
void addSymbol(Symbol sym, LambdaSymbolKind skind) { |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2067 |
if (skind == CAPTURED_THIS && sym != null && sym.kind == TYP && !typesUnderConstruction.isEmpty()) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2068 |
ClassSymbol currentClass = currentClass(); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2069 |
if (currentClass != null && typesUnderConstruction.contains(currentClass)) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2070 |
// reference must be to enclosing outer instance, mutate capture kind. |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2071 |
Assert.check(sym != currentClass); // should have been caught right in Attr |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2072 |
skind = CAPTURED_OUTER_THIS; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2073 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2074 |
} |
21486 | 2075 |
Map<Symbol, Symbol> transMap = getSymbolMap(skind); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2076 |
if (!transMap.containsKey(sym)) { |
29772
4e4e74b99d27
8054220: Debugger doesn't show variables *outside* lambda
jlahoda
parents:
29149
diff
changeset
|
2077 |
transMap.put(sym, translate(sym, skind)); |
14365
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 |
|
21486 | 2081 |
Map<Symbol, Symbol> getSymbolMap(LambdaSymbolKind skind) { |
2082 |
Map<Symbol, Symbol> m = translatedSymbols.get(skind); |
|
2083 |
Assert.checkNonNull(m); |
|
2084 |
return m; |
|
2085 |
} |
|
2086 |
||
2087 |
JCTree translate(JCIdent lambdaIdent) { |
|
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2088 |
for (LambdaSymbolKind kind : LambdaSymbolKind.values()) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2089 |
Map<Symbol, Symbol> m = getSymbolMap(kind); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2090 |
switch(kind) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2091 |
default: |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2092 |
if (m.containsKey(lambdaIdent.sym)) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2093 |
Symbol tSym = m.get(lambdaIdent.sym); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2094 |
JCTree t = make.Ident(tSym).setType(lambdaIdent.type); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2095 |
tSym.setTypeAttributes(lambdaIdent.sym.getRawTypeAttributes()); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2096 |
return t; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2097 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2098 |
break; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2099 |
case CAPTURED_OUTER_THIS: |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2100 |
if (lambdaIdent.sym.owner.kind == TYP && m.containsKey(lambdaIdent.sym.owner)) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2101 |
// Transform outer instance variable references anchoring them to the captured synthetic. |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2102 |
Symbol tSym = m.get(lambdaIdent.sym.owner); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2103 |
JCExpression t = make.Ident(tSym).setType(lambdaIdent.sym.owner.type); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2104 |
tSym.setTypeAttributes(lambdaIdent.sym.owner.getRawTypeAttributes()); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2105 |
t = make.Select(t, lambdaIdent.name); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2106 |
t.setType(lambdaIdent.type); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2107 |
TreeInfo.setSymbol(t, lambdaIdent.sym); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2108 |
return t; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2109 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2110 |
break; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2111 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2112 |
} |
21486 | 2113 |
return null; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2114 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2115 |
|
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2116 |
/* Translate away qualified this expressions, anchoring them to synthetic parameters that |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2117 |
capture the qualified this handle. `fieldAccess' is guaranteed to one such. |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2118 |
*/ |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2119 |
public JCTree translate(JCFieldAccess fieldAccess) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2120 |
Assert.check(fieldAccess.name == names._this); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2121 |
Map<Symbol, Symbol> m = translatedSymbols.get(LambdaSymbolKind.CAPTURED_OUTER_THIS); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2122 |
if (m.containsKey(fieldAccess.sym.owner)) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2123 |
Symbol tSym = m.get(fieldAccess.sym.owner); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2124 |
JCExpression t = make.Ident(tSym).setType(fieldAccess.sym.owner.type); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2125 |
tSym.setTypeAttributes(fieldAccess.sym.owner.getRawTypeAttributes()); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2126 |
return t; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2127 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2128 |
return null; |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2129 |
} |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2130 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2131 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2132 |
* 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
|
2133 |
* 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
|
2134 |
* "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
|
2135 |
* and full parameter list. |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2136 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2137 |
void complete() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2138 |
if (syntheticParams != null) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2139 |
return; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2140 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2141 |
boolean inInterface = translatedSym.owner.isInterface(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2142 |
boolean thisReferenced = !getSymbolMap(CAPTURED_THIS).isEmpty(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2143 |
|
17575
7693e6ff0d7d
8012556: Implement lambda methods on interfaces as static
rfield
parents:
17550
diff
changeset
|
2144 |
// If instance access isn't needed, make it static. |
7693e6ff0d7d
8012556: Implement lambda methods on interfaces as static
rfield
parents:
17550
diff
changeset
|
2145 |
// Interface instance methods must be default methods. |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
2146 |
// Lambda methods are private synthetic. |
25278
8a326edaf411
8046060: Different results of floating point multiplication for lambda code block
rfield
parents:
24225
diff
changeset
|
2147 |
// Inherit ACC_STRICT from the enclosing method, or, for clinit, |
8a326edaf411
8046060: Different results of floating point multiplication for lambda code block
rfield
parents:
24225
diff
changeset
|
2148 |
// from the class. |
21477 | 2149 |
translatedSym.flags_field = SYNTHETIC | LAMBDA_METHOD | |
25278
8a326edaf411
8046060: Different results of floating point multiplication for lambda code block
rfield
parents:
24225
diff
changeset
|
2150 |
owner.flags_field & STRICTFP | |
8a326edaf411
8046060: Different results of floating point multiplication for lambda code block
rfield
parents:
24225
diff
changeset
|
2151 |
owner.owner.flags_field & STRICTFP | |
21014
57913337d634
8012557: Implement lambda methods on interfaces as private
rfield
parents:
20249
diff
changeset
|
2152 |
PRIVATE | |
17575
7693e6ff0d7d
8012556: Implement lambda methods on interfaces as static
rfield
parents:
17550
diff
changeset
|
2153 |
(thisReferenced? (inInterface? DEFAULT : 0) : STATIC); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2154 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2155 |
//compute synthetic params |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
20245
diff
changeset
|
2156 |
ListBuffer<JCVariableDecl> params = new ListBuffer<>(); |
28452
6afa05455443
8037546: javac -parameters does not emit parameter names for lambda expressions
jlahoda
parents:
28145
diff
changeset
|
2157 |
ListBuffer<VarSymbol> parameterSymbols = new ListBuffer<>(); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2158 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2159 |
// 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
|
2160 |
// synthetic parameters: |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2161 |
// |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2162 |
// 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
|
2163 |
// 2) enclosing locals captured by the lambda expression |
21486 | 2164 |
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
|
2165 |
params.append(make.VarDef((VarSymbol) thisSym, null)); |
28452
6afa05455443
8037546: javac -parameters does not emit parameter names for lambda expressions
jlahoda
parents:
28145
diff
changeset
|
2166 |
parameterSymbols.append((VarSymbol) thisSym); |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2167 |
} |
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2168 |
for (Symbol thisSym : getSymbolMap(CAPTURED_OUTER_THIS).values()) { |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2169 |
params.append(make.VarDef((VarSymbol) thisSym, null)); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2170 |
parameterSymbols.append((VarSymbol) thisSym); |
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2171 |
} |
21486 | 2172 |
for (Symbol thisSym : getSymbolMap(PARAM).values()) { |
2173 |
params.append(make.VarDef((VarSymbol) thisSym, null)); |
|
28452
6afa05455443
8037546: javac -parameters does not emit parameter names for lambda expressions
jlahoda
parents:
28145
diff
changeset
|
2174 |
parameterSymbols.append((VarSymbol) thisSym); |
21486 | 2175 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2176 |
syntheticParams = params.toList(); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2177 |
|
28452
6afa05455443
8037546: javac -parameters does not emit parameter names for lambda expressions
jlahoda
parents:
28145
diff
changeset
|
2178 |
translatedSym.params = parameterSymbols.toList(); |
6afa05455443
8037546: javac -parameters does not emit parameter names for lambda expressions
jlahoda
parents:
28145
diff
changeset
|
2179 |
|
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2180 |
// Compute and set the lambda name |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2181 |
translatedSym.name = isSerializable() |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2182 |
? serializedLambdaName() |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2183 |
: lambdaName(); |
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2184 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2185 |
//prepend synthetic args to translated lambda method signature |
16300 | 2186 |
translatedSym.type = types.createMethodTypeWithParameters( |
2187 |
generatedLambdaSig(), |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2188 |
TreeInfo.types(syntheticParams)); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2189 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2190 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2191 |
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
|
2192 |
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
|
2193 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2194 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2195 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2196 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2197 |
* 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
|
2198 |
* 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
|
2199 |
* 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
|
2200 |
* 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
|
2201 |
*/ |
29149
3fa94aad0264
8067886: Inaccessible nested classes can be incorrectly imported
jlahoda
parents:
29051
diff
changeset
|
2202 |
final class ReferenceTranslationContext extends TranslationContext<JCMemberReference> { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2203 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2204 |
final boolean isSuper; |
21892
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2205 |
final Symbol sigPolySym; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2206 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2207 |
ReferenceTranslationContext(JCMemberReference tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2208 |
super(tree); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2209 |
this.isSuper = tree.hasKind(ReferenceKind.SUPER); |
21892
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2210 |
this.sigPolySym = isSignaturePolymorphic() |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2211 |
? makePrivateSyntheticMethod(tree.sym.flags(), |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2212 |
tree.sym.name, |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2213 |
bridgedRefSig(), |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2214 |
tree.sym.enclClass()) |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2215 |
: null; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2216 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2217 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2218 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2219 |
* 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
|
2220 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2221 |
int referenceKind() { |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2222 |
return LambdaToMethod.this.referenceKind(tree.sym); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2223 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2224 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2225 |
boolean needsVarArgsConversion() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2226 |
return tree.varargsElement != null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2227 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2228 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2229 |
/** |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2230 |
* @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
|
2231 |
*/ |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2232 |
boolean isArrayOp() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2233 |
return tree.sym.owner == syms.arrayClass; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2234 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2235 |
|
16328
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2236 |
boolean receiverAccessible() { |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2237 |
//hack needed to workaround 292 bug (7087658) |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2238 |
//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
|
2239 |
//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
|
2240 |
return tree.ownerAccessible; |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2241 |
} |
8b9eb42167f6
8009129: Illegal access error when calling method reference
mcimadamore
parents:
16327
diff
changeset
|
2242 |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2243 |
/** |
21493
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2244 |
* The VM does not support access across nested classes (8010319). |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2245 |
* Were that ever to change, this should be removed. |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2246 |
*/ |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2247 |
boolean isPrivateInOtherClass() { |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2248 |
return (tree.sym.flags() & PRIVATE) != 0 && |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2249 |
!types.isSameType( |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2250 |
types.erasure(tree.sym.enclClass().asType()), |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2251 |
types.erasure(owner.enclClass().asType())); |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2252 |
} |
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2253 |
|
41028
5164e92730d9
8138667: java.lang.IllegalAccessError: tried to access method (for a protected method)
sadayapalam
parents:
39599
diff
changeset
|
2254 |
boolean isProtectedInSuperClassOfEnclosingClassInOtherPackage() { |
5164e92730d9
8138667: java.lang.IllegalAccessError: tried to access method (for a protected method)
sadayapalam
parents:
39599
diff
changeset
|
2255 |
return ((tree.sym.flags() & PROTECTED) != 0 && |
5164e92730d9
8138667: java.lang.IllegalAccessError: tried to access method (for a protected method)
sadayapalam
parents:
39599
diff
changeset
|
2256 |
tree.sym.packge() != owner.packge() && |
5164e92730d9
8138667: java.lang.IllegalAccessError: tried to access method (for a protected method)
sadayapalam
parents:
39599
diff
changeset
|
2257 |
!owner.enclClass().isSubClass(tree.sym.owner, types)); |
5164e92730d9
8138667: java.lang.IllegalAccessError: tried to access method (for a protected method)
sadayapalam
parents:
39599
diff
changeset
|
2258 |
} |
5164e92730d9
8138667: java.lang.IllegalAccessError: tried to access method (for a protected method)
sadayapalam
parents:
39599
diff
changeset
|
2259 |
|
21493
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2260 |
/** |
21892
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2261 |
* Signature polymorphic methods need special handling. |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2262 |
* e.g. MethodHandle.invoke() MethodHandle.invokeExact() |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2263 |
*/ |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2264 |
final boolean isSignaturePolymorphic() { |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2265 |
return tree.sym.kind == MTH && |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2266 |
types.isSignaturePolymorphic((MethodSymbol)tree.sym); |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2267 |
} |
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2268 |
|
8ab5aa58a900
8028739: javac generates incorrect descriptor for MethodHandle::invoke
rfield
parents:
21496
diff
changeset
|
2269 |
/** |
27855
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2270 |
* Erasure destroys the implementation parameter subtype |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2271 |
* relationship for intersection types |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2272 |
*/ |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2273 |
boolean interfaceParameterIsIntersectionType() { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2274 |
List<Type> tl = tree.getDescriptorType(types).getParameterTypes(); |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2275 |
for (; tl.nonEmpty(); tl = tl.tail) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2276 |
Type pt = tl.head; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2277 |
if (pt.getKind() == TypeKind.TYPEVAR) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2278 |
TypeVar tv = (TypeVar) pt; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2279 |
if (tv.bound.getKind() == TypeKind.INTERSECTION) { |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2280 |
return true; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2281 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2282 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2283 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2284 |
return false; |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2285 |
} |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2286 |
|
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2287 |
/** |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2288 |
* Does this reference need to be converted to a lambda |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2289 |
* (i.e. var args need to be expanded or "super" is used) |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2290 |
*/ |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2291 |
final boolean needsConversionToLambda() { |
27855
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2292 |
return interfaceParameterIsIntersectionType() || |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2293 |
isSuper || |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2294 |
needsVarArgsConversion() || |
7afea3897f9b
8058112: Invalid BootstrapMethod for constructor/method reference
rfield
parents:
27224
diff
changeset
|
2295 |
isArrayOp() || |
21493
d3f44b144a76
8022720: Method refeerences - private method should be accessible (nested classes)
rfield
parents:
21492
diff
changeset
|
2296 |
isPrivateInOtherClass() || |
41028
5164e92730d9
8138667: java.lang.IllegalAccessError: tried to access method (for a protected method)
sadayapalam
parents:
39599
diff
changeset
|
2297 |
isProtectedInSuperClassOfEnclosingClassInOtherPackage() || |
25281
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2298 |
!receiverAccessible() || |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2299 |
(tree.getMode() == ReferenceMode.NEW && |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2300 |
tree.kind != ReferenceKind.ARRAY_CTOR && |
0babd05cbcd3
8037404: javac NPE or VerifyError for code with constructor reference of inner class
rfield
parents:
25278
diff
changeset
|
2301 |
(tree.sym.owner.isLocal() || tree.sym.owner.isInner())); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2302 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2303 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2304 |
Type generatedRefSig() { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2305 |
return types.erasure(tree.sym.type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2306 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2307 |
|
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2308 |
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
|
2309 |
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
|
2310 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2311 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2312 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2313 |
// </editor-fold> |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2314 |
|
21486 | 2315 |
/* |
2316 |
* These keys provide mappings for various translated lambda symbols |
|
2317 |
* and the prevailing order must be maintained. |
|
2318 |
*/ |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2319 |
enum LambdaSymbolKind { |
21486 | 2320 |
PARAM, // original to translated lambda parameters |
2321 |
LOCAL_VAR, // original to translated lambda locals |
|
2322 |
CAPTURED_VAR, // variables in enclosing scope to translated synthetic parameters |
|
2323 |
CAPTURED_THIS, // class symbols to translated synthetic parameters (for captured member access) |
|
33706
0d21ecb55e6a
8129740: Incorrect class file created when passing lambda in inner class constructor
sadayapalam
parents:
31296
diff
changeset
|
2324 |
CAPTURED_OUTER_THIS, // used when `this' capture is illegal, but outer this capture is legit (JDK-8129740) |
22163 | 2325 |
TYPE_VAR // original to translated lambda type variables |
16300 | 2326 |
} |
2327 |
||
2328 |
/** |
|
2329 |
* **************************************************************** |
|
2330 |
* Signature Generation |
|
2331 |
* **************************************************************** |
|
2332 |
*/ |
|
2333 |
||
21489
018e34d4045f
8023668: Desugar serializable lambda bodies using more robust naming scheme
rfield
parents:
21486
diff
changeset
|
2334 |
private String typeSig(Type type) { |
16300 | 2335 |
L2MSignatureGenerator sg = new L2MSignatureGenerator(); |
2336 |
sg.assembleSig(type); |
|
2337 |
return sg.toString(); |
|
2338 |
} |
|
2339 |
||
2340 |
private String classSig(Type type) { |
|
2341 |
L2MSignatureGenerator sg = new L2MSignatureGenerator(); |
|
2342 |
sg.assembleClassSig(type); |
|
2343 |
return sg.toString(); |
|
2344 |
} |
|
2345 |
||
2346 |
/** |
|
2347 |
* Signature Generation |
|
2348 |
*/ |
|
2349 |
private class L2MSignatureGenerator extends Types.SignatureGenerator { |
|
2350 |
||
2351 |
/** |
|
2352 |
* An output buffer for type signatures. |
|
2353 |
*/ |
|
2354 |
StringBuilder sb = new StringBuilder(); |
|
2355 |
||
2356 |
L2MSignatureGenerator() { |
|
2357 |
super(types); |
|
2358 |
} |
|
2359 |
||
2360 |
@Override |
|
2361 |
protected void append(char ch) { |
|
2362 |
sb.append(ch); |
|
2363 |
} |
|
2364 |
||
2365 |
@Override |
|
2366 |
protected void append(byte[] ba) { |
|
2367 |
sb.append(new String(ba)); |
|
2368 |
} |
|
2369 |
||
2370 |
@Override |
|
2371 |
protected void append(Name name) { |
|
2372 |
sb.append(name.toString()); |
|
2373 |
} |
|
2374 |
||
2375 |
@Override |
|
2376 |
public String toString() { |
|
2377 |
return sb.toString(); |
|
2378 |
} |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2379 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
diff
changeset
|
2380 |
} |