1 /*
2 * Copyright (c) 2026, 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.
49 import jdk.test.lib.Platform;
50 import jdk.test.lib.cds.CDSAppTester;
51 import jdk.test.lib.process.ProcessTools;
52 import jdk.test.lib.process.OutputAnalyzer;
53
54 import jdk.test.whitebox.WhiteBox;
55 import jdk.test.whitebox.cpuinfo.CPUInfo;
56
57 public class AOTCodeCPUFeatureIncompatibilityTest {
58 public static void main(String... args) throws Exception {
59 List<String> cpuFeatures = CPUInfo.getFeatures();
60 if (Platform.isX64()) {
61 // Minimum value of UseSSE required by JVM is 2. So the production run has to be executed with UseSSE=2.
62 // To simulate the case of incmpatible SSE feature, we can run this test only on system with higher SSE level (sse3 or above).
63 if (isSSE3Supported(cpuFeatures)) {
64 testIncompatibleFeature("-XX:UseSSE=2", "sse3");
65 }
66 if (isAVXSupported(cpuFeatures)) {
67 testIncompatibleFeature("-XX:UseAVX=0", "avx");
68 }
69 }
70 }
71
72 // vmOption = command line option to disable CPU feature
73 // featureName = name of the CPU feature used by the JVM in the log messages
74 public static void testIncompatibleFeature(String vmOption, String featureName) throws Exception {
75 new CDSAppTester("AOTCodeCPUFeatureIncompatibilityTest") {
76 @Override
77 public String[] vmArgs(RunMode runMode) {
78 if (runMode == RunMode.PRODUCTION) {
79 return new String[] {vmOption, "-Xlog:aot+codecache+init=debug"};
80 }
81 return new String[] {};
82 }
83 @Override
84 public void checkExecution(OutputAnalyzer out, RunMode runMode) throws Exception {
85 if (runMode == RunMode.ASSEMBLY) {
86 out.shouldMatch("CPU features recorded in AOTCodeCache:.*" + featureName + ".*");
87 } else if (runMode == RunMode.PRODUCTION) {
88 out.shouldMatch("AOT Code Cache disabled: required cpu features are missing:.*" + featureName + ".*");
94 return "app.jar";
95 }
96 @Override
97 public String[] appCommandLine(RunMode runMode) {
98 return new String[] {
99 "JavacBenchApp", "10"
100 };
101 }
102 }.runAOTWorkflow("--two-step-training");
103 }
104
105 // Only used on x86-64 platform
106 static boolean isSSE3Supported(List<String> cpuFeatures) {
107 return cpuFeatures.contains("sse3");
108 }
109
110 // Only used on x86-64 platform
111 static boolean isAVXSupported(List<String> cpuFeatures) {
112 return cpuFeatures.contains("avx");
113 }
114 }
|
1 /*
2 * Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
50 import jdk.test.lib.Platform;
51 import jdk.test.lib.cds.CDSAppTester;
52 import jdk.test.lib.process.ProcessTools;
53 import jdk.test.lib.process.OutputAnalyzer;
54
55 import jdk.test.whitebox.WhiteBox;
56 import jdk.test.whitebox.cpuinfo.CPUInfo;
57
58 public class AOTCodeCPUFeatureIncompatibilityTest {
59 public static void main(String... args) throws Exception {
60 List<String> cpuFeatures = CPUInfo.getFeatures();
61 if (Platform.isX64()) {
62 // Minimum value of UseSSE required by JVM is 2. So the production run has to be executed with UseSSE=2.
63 // To simulate the case of incmpatible SSE feature, we can run this test only on system with higher SSE level (sse3 or above).
64 if (isSSE3Supported(cpuFeatures)) {
65 testIncompatibleFeature("-XX:UseSSE=2", "sse3");
66 }
67 if (isAVXSupported(cpuFeatures)) {
68 testIncompatibleFeature("-XX:UseAVX=0", "avx");
69 }
70
71 /*
72 * Unfortunately -XX:-UseCRC32 does not clear the feature bit in VM_Version::_features!
73 * Disable this test until it is fixed
74 } else if (Platform.isAArch64()) {
75 if (isCRC32Supported(cpuFeatures)) {
76 testIncompatibleFeature("-XX:-UseCRC32", "crc32");
77 }
78 */
79 }
80 }
81
82 // vmOption = command line option to disable CPU feature
83 // featureName = name of the CPU feature used by the JVM in the log messages
84 public static void testIncompatibleFeature(String vmOption, String featureName) throws Exception {
85 new CDSAppTester("AOTCodeCPUFeatureIncompatibilityTest") {
86 @Override
87 public String[] vmArgs(RunMode runMode) {
88 if (runMode == RunMode.PRODUCTION) {
89 return new String[] {vmOption, "-Xlog:aot+codecache+init=debug"};
90 }
91 return new String[] {};
92 }
93 @Override
94 public void checkExecution(OutputAnalyzer out, RunMode runMode) throws Exception {
95 if (runMode == RunMode.ASSEMBLY) {
96 out.shouldMatch("CPU features recorded in AOTCodeCache:.*" + featureName + ".*");
97 } else if (runMode == RunMode.PRODUCTION) {
98 out.shouldMatch("AOT Code Cache disabled: required cpu features are missing:.*" + featureName + ".*");
104 return "app.jar";
105 }
106 @Override
107 public String[] appCommandLine(RunMode runMode) {
108 return new String[] {
109 "JavacBenchApp", "10"
110 };
111 }
112 }.runAOTWorkflow("--two-step-training");
113 }
114
115 // Only used on x86-64 platform
116 static boolean isSSE3Supported(List<String> cpuFeatures) {
117 return cpuFeatures.contains("sse3");
118 }
119
120 // Only used on x86-64 platform
121 static boolean isAVXSupported(List<String> cpuFeatures) {
122 return cpuFeatures.contains("avx");
123 }
124
125 // Only used on aarch64 platofrm
126 static boolean isCRC32Supported(List<String> cpuFeatures) {
127 return cpuFeatures.contains("crc32");
128 }
129 }
|