Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/stress/TestStressArrayCopy.java
64507 views
/*1* Copyright (c) 2021, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package compiler.arraycopy.stress;2425import java.util.ArrayList;26import java.util.List;27import java.util.Random;2829import jdk.test.lib.Platform;30import jdk.test.lib.Utils;31import jdk.test.lib.process.OutputAnalyzer;32import jdk.test.lib.process.ProcessTools;3334import jdk.test.whitebox.cpuinfo.CPUInfo;3536/**37* @test38* @key stress randomness39* @library /test/lib40* @build compiler.arraycopy.stress.AbstractStressArrayCopy41* compiler.arraycopy.stress.StressBooleanArrayCopy42* compiler.arraycopy.stress.StressByteArrayCopy43* compiler.arraycopy.stress.StressCharArrayCopy44* compiler.arraycopy.stress.StressShortArrayCopy45* compiler.arraycopy.stress.StressIntArrayCopy46* compiler.arraycopy.stress.StressFloatArrayCopy47* compiler.arraycopy.stress.StressLongArrayCopy48* compiler.arraycopy.stress.StressDoubleArrayCopy49* compiler.arraycopy.stress.StressObjectArrayCopy50* jdk.test.whitebox.WhiteBox51* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox52*53* @run main/othervm/timeout=720054* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI55* compiler.arraycopy.stress.TestStressArrayCopy56*/57public class TestStressArrayCopy {5859// These tests are remarkably memory bandwidth hungry. Running multiple60// configs in parallel makes sense only when running a single test in61// isolation, and only on machines with many memory channels. In common62// testing, or even running all arraycopy stress tests at once, overloading63// the system with many configs become counter-productive very quickly.64//65// Default to 1/4 of the CPUs, and allow users to override.66static final int MAX_PARALLELISM = Integer.getInteger("maxParallelism",67Math.max(1, Runtime.getRuntime().availableProcessors() / 4));6869private static List<String> mix(List<String> o, String... mix) {70List<String> n = new ArrayList<>(o);71for (String m : mix) {72n.add(m);73}74return n;75}7677private static List<List<String>> product(List<List<String>> list, String... mix) {78List<List<String>> newList = new ArrayList<>();79for (List<String> c : list) {80for (String m : mix) {81newList.add(mix(c, m));82}83}84return newList;85}8687private static List<List<String>> alternate(List<List<String>> list, String opt) {88return product(list, "-XX:+" + opt, "-XX:-" + opt);89}9091private static boolean containsFuzzy(List<String> list, String sub) {92for (String s : list) {93if (s.contains(sub)) return true;94}95return false;96}9798public static void main(String... args) throws Exception {99List<List<String>> configs = new ArrayList<>();100List<String> cpuFeatures = CPUInfo.getFeatures();101102if (Platform.isX64() || Platform.isX86()) {103// If CPU features were not found, provide a default config.104if (cpuFeatures.isEmpty()) {105configs.add(new ArrayList());106}107108// Otherwise, select the tests that make sense on current platform.109if (containsFuzzy(cpuFeatures, "avx512")) {110configs.add(List.of("-XX:UseAVX=3"));111}112if (containsFuzzy(cpuFeatures, "avx2")) {113configs.add(List.of("-XX:UseAVX=2"));114}115if (containsFuzzy(cpuFeatures, "avx")) {116configs.add(List.of("-XX:UseAVX=1"));117}118if (containsFuzzy(cpuFeatures, "sse4")) {119configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=4"));120}121if (containsFuzzy(cpuFeatures, "sse3")) {122configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=3"));123}124if (containsFuzzy(cpuFeatures, "sse2")) {125configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=2"));126}127128// x86_64 always has UseSSE >= 2. These lower configurations only129// make sense for x86_32.130if (Platform.isX86()) {131if (containsFuzzy(cpuFeatures, "sse")) {132configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=1"));133}134135configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=0"));136}137138// Alternate configs with other flags139if (Platform.isX64()) {140configs = alternate(configs, "UseCompressedOops");141}142configs = alternate(configs, "UseUnalignedLoadStores");143144} else if (Platform.isAArch64()) {145// AArch64.146configs.add(new ArrayList());147148// Alternate configs with other flags149configs = alternate(configs, "UseCompressedOops");150configs = alternate(configs, "UseSIMDForMemoryOps");151} else {152// Generic config.153configs.add(new ArrayList());154}155156String[] classNames = {157"compiler.arraycopy.stress.StressBooleanArrayCopy",158"compiler.arraycopy.stress.StressByteArrayCopy",159"compiler.arraycopy.stress.StressCharArrayCopy",160"compiler.arraycopy.stress.StressShortArrayCopy",161"compiler.arraycopy.stress.StressIntArrayCopy",162"compiler.arraycopy.stress.StressFloatArrayCopy",163"compiler.arraycopy.stress.StressLongArrayCopy",164"compiler.arraycopy.stress.StressDoubleArrayCopy",165"compiler.arraycopy.stress.StressObjectArrayCopy",166};167168ArrayList<Fork> forks = new ArrayList<>();169int jobs = 0;170171for (List<String> c : configs) {172for (String className : classNames) {173// Start a new job174{175ProcessBuilder pb = ProcessTools.createTestJvm(mix(c, "-Xmx256m", className));176Process p = pb.start();177OutputAnalyzer oa = new OutputAnalyzer(p);178forks.add(new Fork(p, oa));179jobs++;180}181182// Wait for the completion of other jobs183while (jobs >= MAX_PARALLELISM) {184Fork f = findDone(forks);185if (f != null) {186OutputAnalyzer oa = f.oa();187oa.shouldHaveExitValue(0);188forks.remove(f);189jobs--;190} else {191// Nothing is done, wait a little.192Thread.sleep(200);193}194}195}196}197198// Drain the rest199for (Fork f : forks) {200OutputAnalyzer oa = f.oa();201oa.shouldHaveExitValue(0);202}203}204205private static Fork findDone(List<Fork> forks) {206for (Fork f : forks) {207if (!f.p().isAlive()) {208return f;209}210}211return null;212}213214private static record Fork(Process p, OutputAnalyzer oa) {};215216}217218219