Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit 7fcd5ca

Browse files
committed
8266036: class file for sun.misc.Contended not found
8258421: (jdeprscan) tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java failed with "error: cannot access jdk.internal.ValueBased" Reviewed-by: darcy
1 parent a49b1dc commit 7fcd5ca

File tree

15 files changed

+309
-110
lines changed

15 files changed

+309
-110
lines changed

make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -229,6 +229,7 @@ public void createSymbols(String ctDescriptionFileExtra, String ctDescriptionFil
229229
: null,
230230
Paths.get(ctDescriptionFile));
231231

232+
stripNonExistentAnnotations(data);
232233
splitHeaders(data.classes);
233234

234235
Map<String, Map<Character, String>> package2Version2Module = new HashMap<>();
@@ -301,6 +302,50 @@ public void createSymbols(String ctDescriptionFileExtra, String ctDescriptionFil
301302
}
302303
}
303304

305+
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
306+
"Ljdk/internal/PreviewFeature;";
307+
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
308+
"Ljdk/internal/javac/PreviewFeature;";
309+
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
310+
"Ljdk/internal/PreviewFeature+Annotation;";
311+
private static final String VALUE_BASED_ANNOTATION =
312+
"Ljdk/internal/ValueBased;";
313+
private static final String VALUE_BASED_ANNOTATION_INTERNAL =
314+
"Ljdk/internal/ValueBased+Annotation;";
315+
public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
316+
List.of("Ljdk/Profile+Annotation;",
317+
"Lsun/Proprietary+Annotation;",
318+
PREVIEW_FEATURE_ANNOTATION_OLD,
319+
PREVIEW_FEATURE_ANNOTATION_NEW,
320+
VALUE_BASED_ANNOTATION));
321+
322+
private void stripNonExistentAnnotations(LoadDescriptions data) {
323+
Set<String> allClasses = data.classes.name2Class.keySet();
324+
data.modules.values().forEach(mod -> {
325+
stripNonExistentAnnotations(allClasses, mod.header);
326+
});
327+
data.classes.classes.forEach(clazz -> {
328+
stripNonExistentAnnotations(allClasses, clazz.header);
329+
stripNonExistentAnnotations(allClasses, clazz.fields);
330+
stripNonExistentAnnotations(allClasses, clazz.methods);
331+
});
332+
}
333+
334+
private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
335+
descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
336+
}
337+
338+
private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
339+
stripNonExistentAnnotations(allClasses, d.classAnnotations);
340+
stripNonExistentAnnotations(allClasses, d.runtimeAnnotations);
341+
}
342+
343+
private void stripNonExistentAnnotations(Set<String> allClasses, List<AnnotationDescription> annotations) {
344+
if (annotations != null)
345+
annotations.removeIf(ann -> !HARDCODED_ANNOTATIONS.contains(ann.annotationType) &&
346+
!allClasses.contains(ann.annotationType.substring(1, ann.annotationType.length() - 1)));
347+
}
348+
304349
private ZipEntry createZipEntry(String name, long timestamp) {
305350
ZipEntry ze = new ZipEntry(name);
306351

@@ -1140,17 +1185,16 @@ private Annotation createAnnotation(List<CPInfo> constantPool, AnnotationDescrip
11401185
values.put("reflective", essentialAPI != null && !essentialAPI);
11411186
}
11421187

1188+
if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
1189+
//the non-public ValueBased annotation will not be available in ct.sym,
1190+
//replace with purely synthetic javac-internal annotation:
1191+
annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
1192+
}
1193+
11431194
return new Annotation(null,
11441195
addString(constantPool, annotationType),
11451196
createElementPairs(constantPool, values));
11461197
}
1147-
//where:
1148-
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
1149-
"Ljdk/internal/PreviewFeature;";
1150-
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
1151-
"Ljdk/internal/javac/PreviewFeature;";
1152-
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
1153-
"Ljdk/internal/PreviewFeature+Annotation;";
11541198

11551199
private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) {
11561200
element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()];

src/java.base/share/classes/jdk/internal/ValueBased.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
* References to <a href="../lang/doc-files/ValueBased.html">value-based classes</a>
3636
* should produce warnings about behavior that is inconsistent with value based semantics.
3737
*
38+
* Note this internal annotation is handled specially by the javac compiler.
39+
* To work properly with {@code --release older-release}, it requires special
40+
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
41+
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
42+
*
3843
* @since 16
3944
*/
4045
@Retention(RetentionPolicy.RUNTIME)

src/java.base/share/classes/jdk/internal/javac/NoPreview.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
/**
3333
* The element annotated with this annotation should not be marked as a preview element.
34+
*
35+
* Note this internal annotation is handled specially by the javac compiler.
36+
* To work properly with {@code --release older-release}, it requires special
37+
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
38+
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
39+
*
3440
*/
3541
@Target({ElementType.METHOD,
3642
ElementType.CONSTRUCTOR,

src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
* Indicates the API declaration in question is associated with a
3232
* <em>preview feature</em>. See JEP 12: "Preview Language and VM
3333
* Features" (http://openjdk.java.net/jeps/12).
34+
*
35+
* Note this internal annotation is handled specially by the javac compiler.
36+
* To work properly with {@code --release older-release}, it requires special
37+
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
38+
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
39+
*
3440
* @since 14
3541
*/
3642
// Match the meaningful targets of java.lang.Deprecated, omit local

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@ public static EnumSet<Flag> asFlagSet(long flags) {
311311
/**
312312
* Flag to indicate the given ModuleSymbol is a system module.
313313
*/
314-
public static final long SYSTEM_MODULE = 1L<<53;
314+
public static final long SYSTEM_MODULE = 1L<<53; //ModuleSymbols only
315+
316+
/**
317+
* Flag to indicate the given ClassSymbol is a value based.
318+
*/
319+
public static final long VALUE_BASED = 1L<<53; //ClassSymbols only
315320

316321
/**
317322
* Flag to indicate the given symbol has a @Deprecated annotation.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public static Symtab instance(Context context) {
222222
public final Type recordType;
223223
public final Type switchBootstrapsType;
224224
public final Type valueBasedType;
225+
public final Type valueBasedInternalType;
225226

226227
/** The symbol representing the length field of an array.
227228
*/
@@ -588,6 +589,7 @@ public <R, P> R accept(ElementVisitor<R, P> v, P p) {
588589
recordType = enterClass("java.lang.Record");
589590
switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");
590591
valueBasedType = enterClass("jdk.internal.ValueBased");
592+
valueBasedInternalType = enterSyntheticAnnotation("jdk.internal.ValueBased+Annotation");
591593

592594
synthesizeEmptyInterfaceIfMissing(autoCloseableType);
593595
synthesizeEmptyInterfaceIfMissing(cloneableType);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import static com.sun.tools.javac.code.Kinds.Kind.MDL;
5454
import static com.sun.tools.javac.code.Kinds.Kind.MTH;
5555
import static com.sun.tools.javac.code.Kinds.Kind.PCK;
56+
import static com.sun.tools.javac.code.Kinds.Kind.TYP;
5657
import static com.sun.tools.javac.code.Kinds.Kind.VAR;
5758
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
5859
import static com.sun.tools.javac.code.TypeTag.ARRAY;
@@ -369,14 +370,19 @@ private <T extends Attribute.Compound> void annotateNow(Symbol toAnnotate,
369370
}
370371
}
371372

372-
// Note: @Deprecated has no effect on local variables and parameters
373373
if (!c.type.isErroneous()
374374
&& types.isSameType(c.type, syms.previewFeatureType)) {
375375
toAnnotate.flags_field |= Flags.PREVIEW_API;
376376
if (isAttributeTrue(c.member(names.reflective))) {
377377
toAnnotate.flags_field |= Flags.PREVIEW_REFLECTIVE;
378378
}
379379
}
380+
381+
if (!c.type.isErroneous()
382+
&& toAnnotate.kind == TYP
383+
&& types.isSameType(c.type, syms.valueBasedType)) {
384+
toAnnotate.flags_field |= Flags.VALUE_BASED;
385+
}
380386
}
381387

382388
List<T> buf = List.nil();

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,14 +1871,7 @@ public void visitSynchronized(JCSynchronized tree) {
18711871
}
18721872
// where
18731873
private boolean isValueBased(Type t) {
1874-
if (t != null && t.tsym != null) {
1875-
for (Attribute.Compound a: t.tsym.getDeclarationAttributes()) {
1876-
if (a.type.tsym == syms.valueBasedType.tsym) {
1877-
return true;
1878-
}
1879-
}
1880-
}
1881-
return false;
1874+
return t != null && t.tsym != null && (t.tsym.flags() & VALUE_BASED) != 0;
18821875
}
18831876

18841877

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,9 @@ else if (proxy.type.tsym.flatName() == syms.profileType.tsym.flatName()) {
14461446
} else if (proxy.type.tsym.flatName() == syms.previewFeatureInternalType.tsym.flatName()) {
14471447
sym.flags_field |= PREVIEW_API;
14481448
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
1449+
} else if (proxy.type.tsym.flatName() == syms.valueBasedInternalType.tsym.flatName()) {
1450+
Assert.check(sym.kind == TYP);
1451+
sym.flags_field |= VALUE_BASED;
14491452
} else {
14501453
if (proxy.type.tsym == syms.annotationTargetType.tsym) {
14511454
target = proxy;
@@ -1457,6 +1460,8 @@ else if (proxy.type.tsym.flatName() == syms.profileType.tsym.flatName()) {
14571460
} else if (proxy.type.tsym == syms.previewFeatureType.tsym) {
14581461
sym.flags_field |= PREVIEW_API;
14591462
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
1463+
} else if (proxy.type.tsym == syms.valueBasedType.tsym && sym.kind == TYP) {
1464+
sym.flags_field |= VALUE_BASED;
14601465
}
14611466
proxies.append(proxy);
14621467
}

test/langtools/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,3 @@ tools/sjavac/ClasspathDependencies.java
7272
#
7373
# jdeps
7474

75-
tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java 8258421 generic-all Deprecation vs JDK-private annotation class

test/langtools/tools/javac/lint/ExternalAbuseOfVbc.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
22
* @test /nodynamiccopyright/
3-
* @bug 8254274
3+
* @bug 8254274 8258421
44
* @summary lint should warn when an instance of a value based class is synchronized upon
55
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint ExternalAbuseOfVbc.java
66
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:all ExternalAbuseOfVbc.java
77
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
8+
* @compile/fail/ref=ExternalAbuseOfVbc.out --release 16 -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
89
* @compile/ref=LintModeOffAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:-synchronization ExternalAbuseOfVbc.java
910
*/
1011

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ExternalAbuseOfVbc.java:18:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class
1+
ExternalAbuseOfVbc.java:19:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class
22
- compiler.err.warnings.and.werror
33
1 error
44
1 warning
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8266036 8258421
27+
* @summary Verify no error is reported for extended ForkJoinPool with --release 8.
28+
* @modules jdk.compiler
29+
* @build NonPublicAnnotations
30+
* @compile -processor NonPublicAnnotations --release 8 NonPublicAnnotations.java
31+
*/
32+
33+
import java.util.Set;
34+
import java.util.concurrent.ForkJoinPool;
35+
36+
import javax.annotation.processing.AbstractProcessor;
37+
import javax.annotation.processing.RoundEnvironment;
38+
import javax.annotation.processing.SupportedAnnotationTypes;
39+
import javax.lang.model.SourceVersion;
40+
import javax.lang.model.element.TypeElement;
41+
42+
@SupportedAnnotationTypes("*")
43+
public class NonPublicAnnotations extends AbstractProcessor {
44+
45+
@Override
46+
public boolean process(Set<? extends TypeElement> roots, RoundEnvironment roundEnv) {
47+
return false;
48+
}
49+
50+
@Override
51+
public SourceVersion getSupportedSourceVersion() {
52+
return SourceVersion.latestSupported();
53+
}
54+
55+
}
56+
57+
class TestForkJoinPool extends ForkJoinPool {}

0 commit comments

Comments
 (0)