From eef506df5a1b93af8f23ab5b491d37e3c7984fd6 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Sat, 4 Apr 2026 01:33:50 -0400 Subject: [PATCH 1/3] 8380322: [lworld] Identity records use preview feature --- .../com/sun/tools/javac/comp/Check.java | 1 + .../InitializationWarningTester.java | 2 ++ .../tools/javac/SuperInit/SuperInitFails.out | 2 ++ .../tools/javac/patterns/DominationWithPP.out | 2 ++ .../javac/preview/PreviewAutoSuppress.java | 3 +- .../ValueObjectCompilationTests.java | 33 +++++++++++++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index be933ab1ce4..6a6c66c86c9 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -1183,6 +1183,7 @@ else if ((sym.owner.flags_field & INTERFACE) != 0) if (allowValueClasses && (isInstanceFieldOfValueClass || isRecordField)) { implicit |= FINAL | STRICT; mask = ValueFieldFlags; + preview.checkSourceLevel(pos, Feature.VALUE_CLASSES); } else { mask = VarFlags; } diff --git a/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java b/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java index 101f35f5b20..8ede50c9c2a 100644 --- a/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java +++ b/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java @@ -121,6 +121,8 @@ void test(Path baseDir, String className, String warningsGoldenFileName) throws // compile javaCompiler.compile(com.sun.tools.javac.util.List.of(javacFileManager.getJavaFileObject(javaFile))); if (goldenFile != null) { + // lets remove preview related messages from the compilation output + compilationOutput.removeIf(msg -> msg.contains("preview")); java.util.List goldenFileContent = Files.readAllLines(goldenFile); if (goldenFileContent.size() != compilationOutput.size()) { System.err.println("compilation output length mismatch"); diff --git a/test/langtools/tools/javac/SuperInit/SuperInitFails.out b/test/langtools/tools/javac/SuperInit/SuperInitFails.out index 65887a39954..21f2f2e0242 100644 --- a/test/langtools/tools/javac/SuperInit/SuperInitFails.out +++ b/test/langtools/tools/javac/SuperInit/SuperInitFails.out @@ -40,4 +40,6 @@ SuperInitFails.java:55:32: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:85:18: compiler.err.ctor.calls.not.allowed.here SuperInitFails.java:91:13: compiler.err.return.before.superclass.initialized SuperInitFails.java:152:18: compiler.err.call.must.only.appear.in.ctor +- compiler.note.preview.filename: SuperInitFails.java, DEFAULT +- compiler.note.preview.recompile 42 errors diff --git a/test/langtools/tools/javac/patterns/DominationWithPP.out b/test/langtools/tools/javac/patterns/DominationWithPP.out index 119cc003d07..9a1c17a5cdd 100644 --- a/test/langtools/tools/javac/patterns/DominationWithPP.out +++ b/test/langtools/tools/javac/patterns/DominationWithPP.out @@ -11,4 +11,6 @@ Domination.java:193:18: compiler.err.pattern.dominated Domination.java:202:18: compiler.err.pattern.dominated Domination.java:211:18: compiler.err.pattern.dominated Domination.java:228:18: compiler.err.pattern.dominated +- compiler.note.preview.filename: Domination.java, DEFAULT +- compiler.note.preview.recompile 13 errors diff --git a/test/langtools/tools/javac/preview/PreviewAutoSuppress.java b/test/langtools/tools/javac/preview/PreviewAutoSuppress.java index 6550a08e348..c66a1e18531 100644 --- a/test/langtools/tools/javac/preview/PreviewAutoSuppress.java +++ b/test/langtools/tools/javac/preview/PreviewAutoSuppress.java @@ -99,7 +99,8 @@ public class Use { List.of("- compiler.warn.preview.feature.use.classfile: Record.class, " + FEATURE_VERSION, "Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)", "Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)", - "3 warnings"); + "Outer.java:3:18: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.value.classes)", + "4 warnings"); if (!log.equals(expected)) throw new Exception("expected output not found" + log); checkPreviewClassfile(classes.resolve("test").resolve("Outer.class"), true); //TODO: correct? diff --git a/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java b/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java index 2f11e840684..4aca90046cb 100644 --- a/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java +++ b/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java @@ -1483,4 +1483,37 @@ value class Test { "aconst_null,putstatic,getstatic,astore_2,aload_0,aload_2,putfield,aload_0,aload_2," + "putfield,aload_0,invokespecial,return"); } + + @Test + void testIdentityRecordUsesPreview() throws Exception { + String source_withComponents = + """ + record IdentityRecord(int i) {} + """; + String source_noComponents = + """ + record IdentityRecord() {} + """; + String[] previousOptions = getCompileOptions(); + try { + setCompileOptions("--enable-preview", + "-source", Integer.toString(Runtime.version().feature()), + "-Xlint:preview"); + assertOKWithWarning("compiler.warn.preview.feature.use.plural", 1, source_withComponents); + + File dir = assertOK(true, source_withComponents); + File classFile = new File(dir, "IdentityRecord.class"); + Assert.check(classFile.exists(), "missing class file"); + Assert.check(ClassFile.of().parse(classFile.toPath()).minorVersion() == ClassFile.PREVIEW_MINOR_VERSION, + "identity records should produce preview class files when compiled with preview enabled"); + + dir = assertOK(true, source_noComponents); + classFile = new File(dir, "IdentityRecord.class"); + Assert.check(classFile.exists(), "missing class file"); + Assert.check(ClassFile.of().parse(classFile.toPath()).minorVersion() == 0, + "identity records with no components should not produce preview class files even with preview enabled"); + } finally { + setCompileOptions(previousOptions); + } + } } From 2f40c114a98a9c95fd38ba153f1d609ca785a440 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Mon, 6 Apr 2026 18:15:10 -0400 Subject: [PATCH 2/3] minor change --- .../tools/javac/SuperInit/InitializationWarningTester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java b/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java index 8ede50c9c2a..0a065ff1e89 100644 --- a/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java +++ b/test/langtools/tools/javac/SuperInit/InitializationWarningTester.java @@ -122,7 +122,7 @@ void test(Path baseDir, String className, String warningsGoldenFileName) throws javaCompiler.compile(com.sun.tools.javac.util.List.of(javacFileManager.getJavaFileObject(javaFile))); if (goldenFile != null) { // lets remove preview related messages from the compilation output - compilationOutput.removeIf(msg -> msg.contains("preview")); + compilationOutput.removeIf(msg -> msg.contains("compiler.note.preview")); java.util.List goldenFileContent = Files.readAllLines(goldenFile); if (goldenFileContent.size() != compilationOutput.size()) { System.err.println("compilation output length mismatch"); From 84d2a92dc28461724875ad45cdf3c4457aa89512 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Tue, 7 Apr 2026 21:50:05 -0400 Subject: [PATCH 3/3] fixing tests failing --- .../inlinetypes/TestFieldNullMarkers.java | 28 +++++++++---------- .../inlinetypes/TestStrictFieldBarriers.java | 2 +- .../field_layout/StrictFinalTest.java | 2 +- .../verifier/RedefineStrictFieldsTest.java | 2 +- .../verifier/StrictInstanceFieldsTest.java | 2 +- .../verifier/StrictStaticFieldsTest.java | 2 +- .../test/lib/StrictProcessorSuperTest.java | 2 +- .../jdk/test/lib/StrictProcessorTest.java | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestFieldNullMarkers.java b/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestFieldNullMarkers.java index 90e631e30a5..d572d5250df 100644 --- a/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestFieldNullMarkers.java +++ b/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestFieldNullMarkers.java @@ -39,7 +39,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/timeout=300 compiler.valhalla.inlinetypes.TestFieldNullMarkers */ @@ -54,7 +54,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -73,7 +73,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -92,7 +92,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -111,7 +111,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -130,7 +130,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -149,7 +149,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -168,7 +168,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -187,7 +187,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -206,7 +206,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -226,7 +226,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -246,7 +246,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -266,7 +266,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions @@ -286,7 +286,7 @@ * @modules java.base/jdk.internal.value * java.base/jdk.internal.vm.annotation * @compile TestFieldNullMarkers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestFieldNullMarkers$StrictFieldHolder * @run main/othervm/timeout=300 -Xbatch * -XX:+UnlockDiagnosticVMOptions diff --git a/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestStrictFieldBarriers.java b/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestStrictFieldBarriers.java index 9c918b8c2b2..f9d8ab1980f 100644 --- a/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestStrictFieldBarriers.java +++ b/test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestStrictFieldBarriers.java @@ -28,7 +28,7 @@ * @library /test/lib * @enablePreview * @compile TestStrictFieldBarriers.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * compiler.valhalla.inlinetypes.TestStrictFieldBarriers$A1 * compiler.valhalla.inlinetypes.TestStrictFieldBarriers$B1 * compiler.valhalla.inlinetypes.TestStrictFieldBarriers$C1 diff --git a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/field_layout/StrictFinalTest.java b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/field_layout/StrictFinalTest.java index bceef0695b9..0467f21581a 100644 --- a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/field_layout/StrictFinalTest.java +++ b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/field_layout/StrictFinalTest.java @@ -29,7 +29,7 @@ * @enablePreview * @compile FieldLayoutAnalyzer.java StrictFinalTest.java * @compile StrictFinalTest.java - * @run driver jdk.test.lib.helpers.StrictProcessor StrictFinalTest + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor StrictFinalTest * StrictFinalTest$Container5 StrictFinalTest$Container6 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UseNullableNonAtomicValueFlattening StrictFinalTest */ diff --git a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/RedefineStrictFieldsTest.java b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/RedefineStrictFieldsTest.java index ff920bf90ff..345d807602a 100644 --- a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/RedefineStrictFieldsTest.java +++ b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/RedefineStrictFieldsTest.java @@ -28,7 +28,7 @@ * @library /test/lib * @run main RedefineClassHelper * @compile StrictFieldsOld.java StrictFieldsNew.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * StrictFieldsOld StrictFieldsNew * @run main/othervm -Xverify:remote -javaagent:redefineagent.jar RedefineStrictFieldsTest */ diff --git a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictInstanceFieldsTest.java b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictInstanceFieldsTest.java index b74fcc90676..51e5560b6bd 100644 --- a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictInstanceFieldsTest.java +++ b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictInstanceFieldsTest.java @@ -37,7 +37,7 @@ * EarlyLarvalNotSubset.jcod * InvalidIndexInEarlyLarval.jcod * @compile StrictInstanceFieldsTest.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * StrictInstanceFieldsTest * Child ControlFlowChild TryCatchChild AssignedInConditionalChild * SwitchCaseChild NestedConstructorChild FinalChild diff --git a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictStaticFieldsTest.java b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictStaticFieldsTest.java index b6112b2e6ae..923316259a8 100644 --- a/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictStaticFieldsTest.java +++ b/test/hotspot/jtreg/runtime/valhalla/inlinetypes/verifier/StrictStaticFieldsTest.java @@ -34,7 +34,7 @@ * Creflbefore_BAD.jasm * WriteAfterReadRefl.jasm * @compile StrictStaticFieldsTest.java - * @run driver jdk.test.lib.helpers.StrictProcessor + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor * StrictStaticFieldsTest * Aregular_OK * Anulls_OK diff --git a/test/lib-test/jdk/test/lib/StrictProcessorSuperTest.java b/test/lib-test/jdk/test/lib/StrictProcessorSuperTest.java index 26b3e81b5f3..c42d1341f59 100644 --- a/test/lib-test/jdk/test/lib/StrictProcessorSuperTest.java +++ b/test/lib-test/jdk/test/lib/StrictProcessorSuperTest.java @@ -27,7 +27,7 @@ * @enablePreview * @library /test/lib * @compile StrictProcessorSuperTest.java - * @run driver jdk.test.lib.helpers.StrictProcessor --deferSuperCall + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor --deferSuperCall * StrictProcessorSuperTest$Rec StrictProcessorSuperTest$Exp * StrictProcessorSuperTest$Inner * @run junit StrictProcessorSuperTest diff --git a/test/lib-test/jdk/test/lib/StrictProcessorTest.java b/test/lib-test/jdk/test/lib/StrictProcessorTest.java index 6a842f2fc98..93a1b3f9a36 100644 --- a/test/lib-test/jdk/test/lib/StrictProcessorTest.java +++ b/test/lib-test/jdk/test/lib/StrictProcessorTest.java @@ -27,7 +27,7 @@ * @enablePreview * @library /test/lib * @build StrictProcessorTest - * @run driver jdk.test.lib.helpers.StrictProcessor StrictProcessorTest$StrictTarget + * @run main/othervm --enable-preview jdk.test.lib.helpers.StrictProcessor StrictProcessorTest$StrictTarget * @run junit StrictProcessorTest */