Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.
/ jdk20 Public archive

Commit a3ed7e9

Browse files
committedJan 24, 2023
8300623: Lambda deserialization regression involving Enum method reference
Reviewed-by: mcimadamore, vromero
1 parent fd75217 commit a3ed7e9

File tree

6 files changed

+51
-329
lines changed

6 files changed

+51
-329
lines changed
 

‎src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java

-51
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ protected Types(Context context) {
119119
messages = JavacMessages.instance(context);
120120
diags = JCDiagnostic.Factory.instance(context);
121121
noWarnings = new Warner(null);
122-
qualifiedSymbolCache = new HashMap<>();
123122
}
124123
// </editor-fold>
125124

@@ -3618,56 +3617,6 @@ public int rank(Type t) {
36183617
}
36193618
// </editor-fold>
36203619

3621-
/** Cache the symbol to reflect the qualifying type.
3622-
* key: corresponding type
3623-
* value: qualified symbol
3624-
*/
3625-
private Map<Type, Symbol> qualifiedSymbolCache;
3626-
3627-
public void clearQualifiedSymbolCache() {
3628-
qualifiedSymbolCache.clear();
3629-
}
3630-
3631-
/** Construct a symbol to reflect the qualifying type that should
3632-
* appear in the byte code as per JLS 13.1.
3633-
*
3634-
* For {@literal target >= 1.2}: Clone a method with the qualifier as owner (except
3635-
* for those cases where we need to work around VM bugs).
3636-
*
3637-
* For {@literal target <= 1.1}: If qualified variable or method is defined in a
3638-
* non-accessible class, clone it with the qualifier class as owner.
3639-
*
3640-
* @param sym The accessed symbol
3641-
* @param site The qualifier's type.
3642-
*/
3643-
public Symbol binaryQualifier(Symbol sym, Type site) {
3644-
3645-
if (site.hasTag(ARRAY)) {
3646-
if (sym == syms.lengthVar ||
3647-
sym.owner != syms.arrayClass)
3648-
return sym;
3649-
// array clone can be qualified by the array type in later targets
3650-
Symbol qualifier;
3651-
if ((qualifier = qualifiedSymbolCache.get(site)) == null) {
3652-
qualifier = new ClassSymbol(Flags.PUBLIC, site.tsym.name, site, syms.noSymbol);
3653-
qualifiedSymbolCache.put(site, qualifier);
3654-
}
3655-
return sym.clone(qualifier);
3656-
}
3657-
3658-
if (sym.owner == site.tsym ||
3659-
(sym.flags() & (STATIC | SYNTHETIC)) == (STATIC | SYNTHETIC)) {
3660-
return sym;
3661-
}
3662-
3663-
// leave alone methods inherited from Object
3664-
// JLS 13.1.
3665-
if (sym.owner == syms.objectType.tsym)
3666-
return sym;
3667-
3668-
return sym.clone(site.tsym);
3669-
}
3670-
36713620
/**
36723621
* Helper method for generating a string representation of a given type
36733622
* accordingly to a given locale

‎src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java

-3
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,6 @@ public void visitReference(JCMemberReference tree) {
518518
throw new InternalError("Should not have an invalid kind");
519519
}
520520

521-
if (init != null) {
522-
refSym = (MethodSymbol) types.binaryQualifier(refSym, init.type);
523-
}
524521
List<JCExpression> indy_args = init==null? List.nil() : translate(List.of(init), localContext.prev);
525522

526523

‎src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java

+51-4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ protected Gen(Context context) {
131131
// ignore cldc because we cannot have both stackmap formats
132132
this.stackMap = StackMapFormat.JSR202;
133133
annotate = Annotate.instance(context);
134+
qualifiedSymbolCache = new HashMap<>();
134135
}
135136

136137
/** Switches
@@ -174,6 +175,12 @@ protected Gen(Context context) {
174175
Set<JCMethodInvocation> invocationsWithPatternMatchingCatch = Set.of();
175176
ListBuffer<int[]> patternMatchingInvocationRanges;
176177

178+
/** Cache the symbol to reflect the qualifying type.
179+
* key: corresponding type
180+
* value: qualified symbol
181+
*/
182+
Map<Type, Symbol> qualifiedSymbolCache;
183+
177184
/** Generate code to load an integer constant.
178185
* @param n The integer to be loaded.
179186
*/
@@ -217,6 +224,46 @@ void emitMinusOne(int tc) {
217224
}
218225
}
219226

227+
/** Construct a symbol to reflect the qualifying type that should
228+
* appear in the byte code as per JLS 13.1.
229+
*
230+
* For {@literal target >= 1.2}: Clone a method with the qualifier as owner (except
231+
* for those cases where we need to work around VM bugs).
232+
*
233+
* For {@literal target <= 1.1}: If qualified variable or method is defined in a
234+
* non-accessible class, clone it with the qualifier class as owner.
235+
*
236+
* @param sym The accessed symbol
237+
* @param site The qualifier's type.
238+
*/
239+
Symbol binaryQualifier(Symbol sym, Type site) {
240+
241+
if (site.hasTag(ARRAY)) {
242+
if (sym == syms.lengthVar ||
243+
sym.owner != syms.arrayClass)
244+
return sym;
245+
// array clone can be qualified by the array type in later targets
246+
Symbol qualifier;
247+
if ((qualifier = qualifiedSymbolCache.get(site)) == null) {
248+
qualifier = new ClassSymbol(Flags.PUBLIC, site.tsym.name, site, syms.noSymbol);
249+
qualifiedSymbolCache.put(site, qualifier);
250+
}
251+
return sym.clone(qualifier);
252+
}
253+
254+
if (sym.owner == site.tsym ||
255+
(sym.flags() & (STATIC | SYNTHETIC)) == (STATIC | SYNTHETIC)) {
256+
return sym;
257+
}
258+
259+
// leave alone methods inherited from Object
260+
// JLS 13.1.
261+
if (sym.owner == syms.objectType.tsym)
262+
return sym;
263+
264+
return sym.clone(site.tsym);
265+
}
266+
220267
/** Insert a reference to given type in the constant pool,
221268
* checking for an array with too many dimensions;
222269
* return the reference's index.
@@ -2280,11 +2327,11 @@ public void visitIdent(JCIdent tree) {
22802327
result = items.makeLocalItem((VarSymbol)sym);
22812328
} else if ((sym.flags() & STATIC) != 0) {
22822329
if (!isAccessSuper(env.enclMethod))
2283-
sym = types.binaryQualifier(sym, env.enclClass.type);
2330+
sym = binaryQualifier(sym, env.enclClass.type);
22842331
result = items.makeStaticItem(sym);
22852332
} else {
22862333
items.makeThisItem().load();
2287-
sym = types.binaryQualifier(sym, env.enclClass.type);
2334+
sym = binaryQualifier(sym, env.enclClass.type);
22882335
result = items.makeMemberItem(sym, nonVirtualForPrivateAccess(sym));
22892336
}
22902337
}
@@ -2337,7 +2384,7 @@ public void visitSelect(JCFieldAccess tree) {
23372384
result = items.makeDynamicItem(sym);
23382385
return;
23392386
} else {
2340-
sym = types.binaryQualifier(sym, tree.selected.type);
2387+
sym = binaryQualifier(sym, tree.selected.type);
23412388
}
23422389
if ((sym.flags() & STATIC) != 0) {
23432390
if (!selectSuper && (ssym == null || ssym.kind != TYP))
@@ -2443,7 +2490,7 @@ public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) {
24432490
toplevel = null;
24442491
endPosTable = null;
24452492
nerrs = 0;
2446-
types.clearQualifiedSymbolCache();
2493+
qualifiedSymbolCache.clear();
24472494
}
24482495
}
24492496

‎test/langtools/tools/javac/lambda/methodReference/8059632/MethodRefQualifyingTypeTest.java

-77
This file was deleted.

‎test/langtools/tools/javac/lambda/methodReference/8059632/MethodSupplierImpl.java

-26
This file was deleted.

‎test/langtools/tools/javac/lambda/methodReference/8059632/TestBootstrapInvocation.java

-168
This file was deleted.

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jan 24, 2023

@openjdk-notifier[bot]
This repository has been archived.