--- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatilesShenandoah.java 2018-11-30 21:07:06.381948521 +0100 @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary C2 should use ldar, stlr and ldaxr+stlxr insns for volatile operations + * @library /test/lib / + * + * @modules java.base/jdk.internal.misc + * + * @requires os.arch=="aarch64" & vm.debug == true & + * vm.flavor == "server" & !vm.graal.enabled & + * vm.gc.Shenandoah + * + * @build compiler.c2.aarch64.TestVolatiles + * compiler.c2.aarch64.TestVolatileLoad + * compiler.c2.aarch64.TestUnsafeVolatileLoad + * compiler.c2.aarch64.TestVolatileStore + * compiler.c2.aarch64.TestUnsafeVolatileStore + * compiler.c2.aarch64.TestUnsafeVolatileCAS + * compiler.c2.aarch64.TestUnsafeVolatileWeakCAS + * compiler.c2.aarch64.TestUnsafeVolatileCAE + * compiler.c2.aarch64.TestUnsafeVolatileGAS + * compiler.c2.aarch64.TestUnsafeVolatileGAA + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestVolatileLoad Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestVolatileStore Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileLoad Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileStore Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileCAS Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileWeakCAS Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileCAE Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileGAS Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileGAA Shenandoah + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestVolatileLoad ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestVolatileStore ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileLoad ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileStore ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileCAS ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileWeakCAS ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileCAE ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileGAS ShenandoahTraversal + * + * @run driver compiler.c2.aarch64.TestVolatilesShenandoah + * TestUnsafeVolatileGAA ShenandoahTraversal + * + */ + +package compiler.c2.aarch64; + +public class TestVolatilesShenandoah { + public static void main(String args[]) throws Throwable + { + // delegate work to shared code + new TestVolatiles().runtest(args[0], args[1]); + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestAllocHumongousFragment.java 2018-11-30 21:07:06.623946283 +0100 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestAllocHumongousFragment + * @summary Make sure Shenandoah can recover from humongous allocation fragmentation + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestAllocHumongousFragment + * + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestAllocHumongousFragment + * + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestAllocHumongousFragment + * + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=adaptive TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=static TestAllocHumongousFragment + * @run main/othervm -Xlog:gc -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahTargetNumRegions=2048 -XX:ShenandoahGCHeuristics=traversal TestAllocHumongousFragment + */ + +import java.util.*; +import java.util.concurrent.*; + +public class TestAllocHumongousFragment { + + static final long TARGET_MB = Long.getLong("target", 30_000); // 30 Gb allocations + static final long LIVE_MB = Long.getLong("occupancy", 700); // 700 Mb alive + + static volatile Object sink; + + static List objects; + + public static void main(String[] args) throws Exception { + final int min = 128 * 1024; + final int max = 16 * 1024 * 1024; + final long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2)); + + objects = new ArrayList<>(); + long current = 0; + + Random r = new Random(); + for (long c = 0; c < count; c++) { + while (current > LIVE_MB * 1024 * 1024) { + int idx = ThreadLocalRandom.current().nextInt(objects.size()); + int[] remove = objects.remove(idx); + current -= remove.length * 4 + 16; + } + + int[] newObj = new int[min + r.nextInt(max - min)]; + current += newObj.length * 4 + 16; + objects.add(newObj); + sink = new Object(); + + System.out.println("Allocated: " + (current / 1024 / 1024) + " Mb"); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestAllocIntArrays.java 2018-11-30 21:07:06.871943990 +0100 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestAllocIntArrays + * @summary Acceptance tests: collector can withstand allocation + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestAllocIntArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive TestAllocIntArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestAllocIntArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static TestAllocIntArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact TestAllocIntArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:-UseTLAB -XX:+ShenandoahVerify TestAllocIntArrays + */ + +import java.util.Random; + +public class TestAllocIntArrays { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + final int min = 0; + final int max = 384 * 1024; + long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2)); + + Random r = new Random(); + for (long c = 0; c < count; c++) { + sink = new int[min + r.nextInt(max - min)]; + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestAllocObjectArrays.java 2018-11-30 21:07:07.110941780 +0100 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestAllocObjectArrays + * @summary Acceptance tests: collector can withstand allocation + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestAllocObjectArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive TestAllocObjectArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestAllocObjectArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact TestAllocObjectArrays + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal TestAllocObjectArrays + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:-UseTLAB -XX:+ShenandoahVerify TestAllocObjectArrays + */ + +import java.util.Random; + +public class TestAllocObjectArrays { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + final int min = 0; + final int max = 384 * 1024; + long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2)); + + Random r = new Random(); + for (long c = 0; c < count; c++) { + sink = new Object[min + r.nextInt(max - min)]; + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestAllocObjects.java 2018-11-30 21:07:07.353939533 +0100 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestAllocObjects + * @summary Acceptance tests: collector can withstand allocation + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestAllocObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive TestAllocObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestAllocObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal TestAllocObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahSuspendibleWorkers TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static -XX:+ShenandoahSuspendibleWorkers TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact -XX:+ShenandoahSuspendibleWorkers TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahSuspendibleWorkers TestAllocObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahSuspendibleWorkers TestAllocObjects + */ + +import java.util.Random; + +public class TestAllocObjects { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 16; + for (long c = 0; c < count; c++) { + sink = new Object(); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestArrayCopyCheckCast.java 2018-11-30 21:07:07.599937259 +0100 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestArrayCopyCheckCast + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:TieredStopAtLevel=0 -Xmx16m TestArrayCopyCheckCast + */ +public class TestArrayCopyCheckCast { + + static class Foo {} + static class Bar {} + + public static void main(String[] args) throws Exception { + try { + Object[] array1 = new Object[1]; + array1[0] = new Bar(); + Foo[] array2 = new Foo[1]; + System.arraycopy(array1, 0, array2, 0, 1); + throw new RuntimeException(); + } catch (ArrayStoreException ex) { + // expected + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestArrayCopyStress.java 2018-11-30 21:07:07.842935012 +0100 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +import java.util.concurrent.*; + +/* + * @test TestArrayCopyStress + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:TieredStopAtLevel=0 -Xmx16m TestArrayCopyStress + */ +public class TestArrayCopyStress { + + private static final int ARRAY_SIZE = 1000; + private static final int ITERATIONS = 10000; + + static class Foo { + int num; + + Foo(int num) { + this.num = num; + } + } + + static class Bar {} + + public static void main(String[] args) throws Exception { + for (int i = 0; i < ITERATIONS; i++) { + testConjoint(); + } + } + + private static void testConjoint() { + Foo[] array = new Foo[ARRAY_SIZE]; + for (int i = 0; i < ARRAY_SIZE; i++) { + array[i] = new Foo(i); + } + + int src_idx = ThreadLocalRandom.current().nextInt(0, ARRAY_SIZE); + int dst_idx = ThreadLocalRandom.current().nextInt(0, ARRAY_SIZE); + int len = ThreadLocalRandom.current().nextInt(0, Math.min(ARRAY_SIZE - src_idx, ARRAY_SIZE - dst_idx)); + System.arraycopy(array, src_idx, array, dst_idx, len); + + for (int i = 0; i < ARRAY_SIZE; i++) { + if (i >= dst_idx && i < dst_idx + len) { + assertEquals(array[i].num, i - (dst_idx - src_idx)); + } else { + assertEquals(array[i].num, i); + } + } + } + + private static void assertEquals(int a, int b) { + if (a != b) throw new RuntimeException("assert failed"); + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestElasticTLAB.java 2018-11-30 21:07:08.084932775 +0100 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestElasticTLAB + * @summary Test that Shenandoah is able to work with elastic TLABs + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:-UseTLAB -XX:-ShenandoahElasticTLAB -XX:+ShenandoahVerify TestElasticTLAB + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:-UseTLAB -XX:-ShenandoahElasticTLAB TestElasticTLAB + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:-UseTLAB -XX:+ShenandoahElasticTLAB -XX:+ShenandoahVerify TestElasticTLAB + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:-UseTLAB -XX:+ShenandoahElasticTLAB TestElasticTLAB + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+UseTLAB -XX:-ShenandoahElasticTLAB -XX:+ShenandoahVerify TestElasticTLAB + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+UseTLAB -XX:-ShenandoahElasticTLAB TestElasticTLAB + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+UseTLAB -XX:+ShenandoahElasticTLAB -XX:+ShenandoahVerify TestElasticTLAB + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+UseTLAB -XX:+ShenandoahElasticTLAB TestElasticTLAB + */ + +import java.util.Random; + +public class TestElasticTLAB { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + final int min = 0; + final int max = 384 * 1024; + long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2)); + + Random r = new Random(); + for (long c = 0; c < count; c++) { + sink = new int[min + r.nextInt(max - min)]; + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestEvilSyncBug.java 2018-11-30 21:07:08.334930464 +0100 @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestEvilSyncBug + * @summary Tests for crash/assert when attaching init thread during shutdown + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @run driver/timeout=480 TestEvilSyncBug + */ + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.locks.*; + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestEvilSyncBug { + + private static final int NUM_RUNS = 100; + + static Thread[] hooks = new MyHook[10000]; + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + test(); + } else { + ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + + Future[] fs = new Future[NUM_RUNS]; + + for (int c = 0; c < NUM_RUNS; c++) { + Callable task = () -> { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xms128m", + "-Xmx128m", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=aggressive", + "-XX:+ShenandoahStoreCheck", + "TestEvilSyncBug", "test"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + return null; + }; + fs[c] = pool.submit(task); + } + + for (Future f : fs) { + f.get(); + } + + pool.shutdown(); + pool.awaitTermination(1, TimeUnit.HOURS); + } + } + + private static void test() throws Exception { + + for (int t = 0; t < hooks.length; t++) { + hooks[t] = new MyHook(); + } + + ExecutorService service = Executors.newFixedThreadPool( + 2, + r -> { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + ); + + List> futures = new ArrayList<>(); + for (int c = 0; c < 100; c++) { + Runtime.getRuntime().addShutdownHook(hooks[c]); + final Test[] tests = new Test[1000]; + for (int t = 0; t < tests.length; t++) { + tests[t] = new Test(); + } + + Future f1 = service.submit(() -> { + Runtime.getRuntime().addShutdownHook(new MyHook()); + IntResult2 r = new IntResult2(); + for (Test test : tests) { + test.RL_Us(r); + } + }); + Future f2 = service.submit(() -> { + Runtime.getRuntime().addShutdownHook(new MyHook()); + for (Test test : tests) { + test.WLI_Us(); + } + }); + + futures.add(f1); + futures.add(f2); + } + + for (Future f : futures) { + f.get(); + } + } + + public static class IntResult2 { + int r1, r2; + } + + public static class Test { + final StampedLock lock = new StampedLock(); + + int x, y; + + public void RL_Us(IntResult2 r) { + StampedLock lock = this.lock; + long stamp = lock.readLock(); + r.r1 = x; + r.r2 = y; + lock.unlock(stamp); + } + + public void WLI_Us() { + try { + StampedLock lock = this.lock; + long stamp = lock.writeLockInterruptibly(); + x = 1; + y = 2; + lock.unlock(stamp); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + private static class MyHook extends Thread { + @Override + public void run() { + try { + Thread.sleep(10); + } catch (Exception e) {} + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestGCThreadGroups.java 2018-11-30 21:07:08.577928217 +0100 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestGCThreadGroups + * @summary Test Shenandoah GC uses concurrent/parallel threads correctly + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4 -Xmx16m -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:-UseDynamicNumberOfGCThreads -Xmx16m -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+ForceDynamicNumberOfGCThreads -Xmx16m -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4 -Xmx16m -XX:ShenandoahGCHeuristics=passive -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4 -Xmx16m -XX:ShenandoahGCHeuristics=adaptive -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4 -Xmx16m -XX:ShenandoahGCHeuristics=static -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4 -Xmx16m -XX:ShenandoahGCHeuristics=compact -Dtarget=100 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4 -Xmx16m -XX:ShenandoahGCHeuristics=aggressive -Dtarget=100 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4 -Xmx16m -XX:ShenandoahGCHeuristics=traversal -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2 -Xmx16m -XX:ShenandoahGCHeuristics=passive -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2 -Xmx16m -XX:ShenandoahGCHeuristics=adaptive -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2 -Xmx16m -XX:ShenandoahGCHeuristics=static -Dtarget=1000 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2 -Xmx16m -XX:ShenandoahGCHeuristics=compact -Dtarget=100 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2 -Xmx16m -XX:ShenandoahGCHeuristics=aggressive -Dtarget=100 TestGCThreadGroups + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2 -Xmx16m -XX:ShenandoahGCHeuristics=traversal -Dtarget=1000 TestGCThreadGroups +*/ + +public class TestGCThreadGroups { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation, around 1K cycles to handle + static final long STRIDE = 100_000; + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 16; + for (long c = 0; c < count; c += STRIDE) { + for (long s = 0; s < STRIDE; s++) { + sink = new Object(); + } + Thread.sleep(1); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestHeapUncommit.java 2018-11-30 21:07:08.824925934 +0100 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestHeapUncommit + * @summary Acceptance tests: collector can withstand allocation + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestHeapUncommit + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:+ShenandoahVerify TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:+UseLargePages -XX:+ShenandoahVerify TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=static -XX:+ShenandoahVerify TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestHeapUncommit + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:-UseTLAB -XX:+ShenandoahVerify TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:-UseTLAB -XX:+UseLargePages -XX:+ShenandoahVerify TestHeapUncommit + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:+UseLargePages TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=adaptive TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=static TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=compact TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=aggressive TestHeapUncommit + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahUncommit -XX:ShenandoahUncommitDelay=0 -XX:ShenandoahGCHeuristics=traversal TestHeapUncommit + */ + +import java.util.Random; + +public class TestHeapUncommit { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + final int min = 0; + final int max = 384 * 1024; + long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2)); + + Random r = new Random(); + for (long c = 0; c < count; c++) { + sink = new int[min + r.nextInt(max - min)]; + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestHumongousThreshold.java 2018-11-30 21:07:09.074923623 +0100 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestHumongousThreshold + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:+ShenandoahVerify TestHumongousThreshold + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:ShenandoahHumongousThreshold=50 -XX:+ShenandoahVerify TestHumongousThreshold + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:ShenandoahHumongousThreshold=90 -XX:+ShenandoahVerify TestHumongousThreshold + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:ShenandoahHumongousThreshold=99 -XX:+ShenandoahVerify TestHumongousThreshold + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:ShenandoahHumongousThreshold=100 -XX:+ShenandoahVerify TestHumongousThreshold + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -XX:ShenandoahHumongousThreshold=90 -XX:ShenandoahGCHeuristics=aggressive TestHumongousThreshold + */ + +import java.util.Random; + +public class TestHumongousThreshold { + + static final long TARGET_MB = Long.getLong("target", 20_000); // 20 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + final int min = 0; + final int max = 384 * 1024; + long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2)); + + Random r = new Random(); + for (long c = 0; c < count; c++) { + sink = new int[min + r.nextInt(max - min)]; + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestLargeObjectAlignment.java 2018-11-30 21:07:09.324921311 +0100 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestLargeObjectAlignment + * @summary Shenandoah crashes with -XX:ObjectAlignmentInBytes=16 + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xint TestLargeObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -XX:-TieredCompilation TestLargeObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -XX:TieredStopAtLevel=1 TestLargeObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -XX:TieredStopAtLevel=4 TestLargeObjectAlignment + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +public class TestLargeObjectAlignment { + + static final int SLABS_COUNT = Integer.getInteger("slabs", 10000); + static final int NODE_COUNT = Integer.getInteger("nodes", 10000); + static final long TIME_NS = 1000L * 1000L * Integer.getInteger("timeMs", 5000); + + static Object[] objects; + + public static void main(String[] args) throws Exception { + objects = new Object[SLABS_COUNT]; + + long start = System.nanoTime(); + while (System.nanoTime() - start < TIME_NS) { + objects[ThreadLocalRandom.current().nextInt(SLABS_COUNT)] = createSome(); + } + } + + public static Object createSome() { + List result = new ArrayList(); + for (int c = 0; c < NODE_COUNT; c++) { + result.add(new Integer(c)); + } + return result; + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestLotsOfCycles.java 2018-11-30 21:07:09.565919083 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestLotsOfCycles + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=passive -Dtarget=10000 -XX:+ShenandoahDegeneratedGC TestLotsOfCycles + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=passive -Dtarget=10000 -XX:-ShenandoahDegeneratedGC TestLotsOfCycles + * + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=aggressive -Dtarget=1000 -XX:+ShenandoahOOMDuringEvacALot TestLotsOfCycles + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=aggressive -Dtarget=1000 -XX:+ShenandoahAllocFailureALot TestLotsOfCycles + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=aggressive -Dtarget=1000 TestLotsOfCycles + * + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=adaptive -Dtarget=10000 TestLotsOfCycles + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=traversal -Dtarget=10000 TestLotsOfCycles + * + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=static -Dtarget=10000 TestLotsOfCycles + * @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m -XX:ShenandoahGCHeuristics=compact -Dtarget=1000 TestLotsOfCycles + */ + +public class TestLotsOfCycles { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation, around 1K cycles to handle + static final long STRIDE = 100_000; + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 16; + for (long c = 0; c < count; c += STRIDE) { + for (long s = 0; s < STRIDE; s++) { + sink = new Object(); + } + Thread.sleep(1); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestParallelRefprocSanity.java 2018-11-30 21:07:09.804916873 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestParallelRefprocSanity + * @summary Test that reference processing works with both parallel and non-parallel variants. + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g TestParallelRefprocSanity + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:-ParallelRefProcEnabled TestParallelRefprocSanity + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:+ParallelRefProcEnabled TestParallelRefprocSanity + */ + +import java.lang.ref.*; + +public class TestParallelRefprocSanity { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 32; + for (long c = 0; c < count; c++) { + sink = new WeakReference(new Object()); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestPeriodicGC.java 2018-11-30 21:07:10.044914654 +0100 @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestPeriodicGC + * @summary Test that periodic GC is working + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run driver TestPeriodicGC + */ + +import java.util.*; + +import jdk.test.lib.Asserts; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestPeriodicGC { + + public static void testWith(String msg, boolean periodic, String... args) throws Exception { + String[] cmds = Arrays.copyOf(args, args.length + 2); + cmds[args.length] = TestPeriodicGC.class.getName(); + cmds[args.length + 1] = "test"; + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) { + throw new AssertionError(msg + ": Should have periodic GC in logs"); + } + if (!periodic && output.getOutput().contains("Trigger: Time since last GC")) { + throw new AssertionError(msg + ": Should not have periodic GC in logs"); + } + } + + public static void main(String[] args) throws Exception { + if (args.length > 0 && args[0].equals("test")) { + Thread.sleep(5000); // stay idle + return; + } + + String[] enabled = new String[] { + "adaptive", + "compact", + "static", + "traversal", + }; + + String[] disabled = new String[] { + "aggressive", + "passive", + }; + + for (String h : enabled) { + testWith("Short period with " + h, + true, + "-Xlog:gc", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-XX:ShenandoahGuaranteedGCInterval=1000" + ); + + testWith("Long period with " + h, + false, + "-Xlog:gc", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long + ); + } + + for (String h : disabled) { + testWith("Short period with " + h, + false, + "-Xlog:gc", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-XX:ShenandoahGuaranteedGCInterval=1000" + ); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestRefprocSanity.java 2018-11-30 21:07:10.286912416 +0100 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestRefprocSanity + * @summary Test that null references/referents work fine + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g TestRefprocSanity + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:+ShenandoahVerify TestRefprocSanity + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive TestRefprocSanity + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:+ShenandoahVerify -XX:ShenandoahGCHeuristics=traversal TestRefprocSanity + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal TestRefprocSanity + */ + +import java.lang.ref.*; + +public class TestRefprocSanity { + + static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation + static final int WINDOW = 10_000; + + static final Reference[] refs = new Reference[WINDOW]; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 32; + int rIdx = 0; + + ReferenceQueue rq = new ReferenceQueue(); + + for (int c = 0; c < WINDOW; c++) { + refs[c] = select(c, new MyObject(c), rq); + } + + for (int c = 0; c < count; c++) { + verifyRefAt(rIdx); + refs[rIdx] = select(c, new MyObject(rIdx), rq); + + rIdx++; + if (rIdx >= WINDOW) { + rIdx = 0; + } + while (rq.poll() != null); // drain + } + } + + static Reference select(int v, MyObject ext, ReferenceQueue rq) { + switch (v % 10) { + case 0: return new SoftReference(null); + case 1: return new SoftReference(null, rq); + case 2: return new SoftReference(ext); + case 3: return new SoftReference(ext, rq); + case 4: return new WeakReference(null); + case 5: return new WeakReference(null, rq); + case 6: return new WeakReference(ext); + case 7: return new WeakReference(ext, rq); + case 8: return new PhantomReference(null, rq); + case 9: return new PhantomReference(ext, rq); + default: throw new IllegalStateException(); + } + } + + static void verifyRefAt(int idx) { + Reference ref = refs[idx]; + MyObject mo = ref.get(); + if (mo != null && mo.x != idx) { + throw new IllegalStateException("Referent tag is incorrect: " + mo.x + ", should be " + idx); + } + } + + static class MyObject { + final int x; + + public MyObject(int x) { + this.x = x; + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestRegionSampling.java 2018-11-30 21:07:10.526910198 +0100 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestRegionSampling + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:+ShenandoahRegionSampling TestRegionSampling + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahRegionSampling TestRegionSampling + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahRegionSampling TestRegionSampling + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static -XX:+ShenandoahRegionSampling TestRegionSampling + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact -XX:+ShenandoahRegionSampling TestRegionSampling + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahRegionSampling TestRegionSampling + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahRegionSampling TestRegionSampling + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahRegionSampling TestRegionSampling + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahRegionSampling TestRegionSampling + */ + +public class TestRegionSampling { + + static final long TARGET_MB = Long.getLong("target", 2_000); // 2 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 16; + for (long c = 0; c < count; c++) { + sink = new Object(); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestRetainObjects.java 2018-11-30 21:07:10.765907988 +0100 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestRetainObjects + * @summary Acceptance tests: collector can deal with retained objects + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestRetainObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive TestRetainObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestRetainObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact TestRetainObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal TestRetainObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:-UseTLAB -XX:+ShenandoahVerify TestRetainObjects + */ + +public class TestRetainObjects { + + static final int COUNT = 10_000_000; + static final int WINDOW = 10_000; + + static final String[] reachable = new String[WINDOW]; + + public static void main(String[] args) throws Exception { + int rIdx = 0; + for (int c = 0; c < COUNT; c++) { + reachable[rIdx] = ("LargeString" + c); + rIdx++; + if (rIdx >= WINDOW) { + rIdx = 0; + } + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestSieveObjects.java 2018-11-30 21:07:11.003905788 +0100 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestSieveObjects + * @summary Acceptance tests: collector can deal with retained objects + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestSieveObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive TestSieveObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestSieveObjects + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact TestSieveObjects + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=traversal TestSieveObjects + * + * @run main/othervm/timeout=240 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g -XX:-UseTLAB -XX:+ShenandoahVerify TestSieveObjects + */ + +import java.util.concurrent.ThreadLocalRandom; + +public class TestSieveObjects { + + static final int COUNT = 100_000_000; + static final int WINDOW = 1_000_000; + static final int PAYLOAD = 100; + + static final MyObject[] arr = new MyObject[WINDOW]; + + public static void main(String[] args) throws Exception { + int rIdx = 0; + for (int c = 0; c < COUNT; c++) { + MyObject v = arr[rIdx]; + if (v != null) { + if (v.x != rIdx) { + throw new IllegalStateException("Illegal value at index " + rIdx + ": " + v.x); + } + if (ThreadLocalRandom.current().nextInt(1000) > 100) { + arr[rIdx] = null; + } + } else { + if (ThreadLocalRandom.current().nextInt(1000) > 500) { + arr[rIdx] = new MyObject(rIdx); + } + } + rIdx++; + if (rIdx >= WINDOW) { + rIdx = 0; + } + } + } + + public static class MyObject { + public int x; + public byte[] payload; + + public MyObject(int x) { + this.x = x; + this.payload = new byte[PAYLOAD]; + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestSmallHeap.java 2018-11-30 21:07:11.240903597 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestSmallHeap + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC TestSmallHeap + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx64m TestSmallHeap + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx32m TestSmallHeap + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx16m TestSmallHeap + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx8m TestSmallHeap + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx4m TestSmallHeap + */ + +public class TestSmallHeap { + + public static void main(String[] args) throws Exception { + System.out.println("Hello World!"); + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestStringDedup.java 2018-11-30 21:07:11.481901369 +0100 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + + /* + * @test TestStringDedup + * @summary Test Shenandoah string deduplication implementation + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc:open + * @modules java.base/java.lang:open + * java.management + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+UseStringDeduplication -Xmx256M -Xlog:gc+stats TestStringDedup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+UseStringDeduplication -Xmx256M -Xlog:gc+stats TestStringDedup + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -XX:+UseStringDeduplication -Xmx256M -Xlog:gc+stats TestStringDedup + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx256M -Xlog:gc+stats TestStringDedup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal -XX:+UseStringDeduplication -Xmx256M -Xlog:gc+stats TestStringDedup + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact -XX:+UseStringDeduplication -Xmx256M -Xlog:gc+stats TestStringDedup + */ + +import java.lang.reflect.*; +import java.util.*; + +import sun.misc.*; + +public class TestStringDedup { + private static Field valueField; + private static Unsafe unsafe; + + private static final int UniqueStrings = 20; + + static { + try { + Field field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe) field.get(null); + + valueField = String.class.getDeclaredField("value"); + valueField.setAccessible(true); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static Object getValue(String string) { + try { + return valueField.get(string); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + static class StringAndId { + private String str; + private int id; + + public StringAndId(String str, int id) { + this.str = str; + this.id = id; + } + + public String str() { + return str; + } + + public int id() { + return id; + } + } + + private static void generateStrings(ArrayList strs, int unique_strs) { + Random rn = new Random(); + for (int u = 0; u < unique_strs; u++) { + int n = rn.nextInt() % 10; + n = Math.max(n, 2); + for (int index = 0; index < n; index++) { + strs.add(new StringAndId("Unique String " + u, u)); + } + } + } + + private static int verifyDedepString(ArrayList strs) { + HashMap seen = new HashMap<>(); + int total = 0; + int dedup = 0; + + for (StringAndId item : strs) { + total++; + StringAndId existing_item = seen.get(getValue(item.str())); + if (existing_item == null) { + seen.put(getValue(item.str()), item); + } else { + if (item.id() != existing_item.id() || + !item.str().equals(existing_item.str())) { + System.out.println("StringDedup error:"); + System.out.println("String: " + item.str() + " != " + existing_item.str()); + throw new RuntimeException("StringDedup Test failed"); + } else { + dedup++; + } + } + } + System.out.println("Dedup: " + dedup + "/" + total + " unique: " + (total - dedup)); + return (total - dedup); + } + + public static void main(String[] args) { + ArrayList astrs = new ArrayList<>(); + generateStrings(astrs, UniqueStrings); + System.gc(); + System.gc(); + System.gc(); + System.gc(); + System.gc(); + + if (verifyDedepString(astrs) != UniqueStrings) { + // Can not guarantee all strings are deduplicated, there can + // still have pending items in queues. + System.out.println("Not all strings are deduplicated"); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestStringDedupStress.java 2018-11-30 21:07:11.719899168 +0100 @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + + /* + * @test TestStringDedupStress + * @summary Test Shenandoah string deduplication implementation + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc:open + * @modules java.base/java.lang:open + * java.management + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -DtargetStrings=3000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=aggressive -DtargetStrings=2000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot -DtargetStrings=2000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=static -DtargetStrings=4000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=compact + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -DtargetOverwrites=40000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -DtargetOverwrites=40000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=traversal + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahUpdateRefsEarly=off -DtargetStrings=3000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=compact -XX:ShenandoahUpdateRefsEarly=off -DtargetStrings=2000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=aggressive -XX:ShenandoahUpdateRefsEarly=off -DtargetStrings=2000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=static -XX:ShenandoahUpdateRefsEarly=off -DtargetOverwrites=4000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=aggressive -XX:ShenandoahUpdateRefsEarly=off -XX:+ShenandoahOOMDuringEvacALot -DtargetStrings=2000000 + * TestStringDedupStress + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx512M -Xlog:gc+stats + * -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahOOMDuringEvacALot -DtargetStrings=2000000 + * TestStringDedupStress + */ + +import java.lang.management.*; +import java.lang.reflect.*; +import java.util.*; + +import sun.misc.*; + +public class TestStringDedupStress { + private static Field valueField; + private static Unsafe unsafe; + + private static long TARGET_STRINGS = Long.getLong("targetStrings", 2_500_000); + private static long TARGET_OVERWRITES = Long.getLong("targetOverwrites", 600_000); + private static final long MAX_REWRITE_GC_CYCLES = 6; + + private static final int UNIQUE_STRINGS = 20; + + static { + try { + Field field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe) field.get(null); + + valueField = String.class.getDeclaredField("value"); + valueField.setAccessible(true); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static Object getValue(String string) { + try { + return valueField.get(string); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + static class StringAndId { + private String str; + private int id; + + public StringAndId(String str, int id) { + this.str = str; + this.id = id; + } + + public String str() { + return str; + } + + public int id() { + return id; + } + } + + // Generate uniqueStrings number of strings + private static void generateStrings(ArrayList strs, int uniqueStrings) { + Random rn = new Random(); + for (int u = 0; u < uniqueStrings; u++) { + int n = rn.nextInt(uniqueStrings); + strs.add(new StringAndId("Unique String " + n, n)); + } + } + + private static int verifyDedepString(ArrayList strs) { + HashMap seen = new HashMap<>(); + int total = 0; + int dedup = 0; + + for (StringAndId item : strs) { + total++; + StringAndId existingItem = seen.get(getValue(item.str())); + if (existingItem == null) { + seen.put(getValue(item.str()), item); + } else { + if (item.id() != existingItem.id() || + !item.str().equals(existingItem.str())) { + System.out.println("StringDedup error:"); + System.out.println("id: " + item.id() + " != " + existingItem.id()); + System.out.println("or String: " + item.str() + " != " + existingItem.str()); + throw new RuntimeException("StringDedup Test failed"); + } else { + dedup++; + } + } + } + System.out.println("Dedup: " + dedup + "/" + total + " unique: " + (total - dedup)); + return (total - dedup); + } + + static volatile ArrayList astrs = new ArrayList<>(); + static GarbageCollectorMXBean gcCycleMBean; + + public static void main(String[] args) { + Random rn = new Random(); + + for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { + if ("Shenandoah Cycles".equals(bean.getName())) { + gcCycleMBean = bean; + break; + } + } + + if (gcCycleMBean == null) { + throw new RuntimeException("Can not find Shenandoah GC cycle mbean"); + } + + // Generate roughly TARGET_STRINGS strings, only UNIQUE_STRINGS are unique + long genIters = TARGET_STRINGS / UNIQUE_STRINGS; + for (long index = 0; index < genIters; index++) { + generateStrings(astrs, UNIQUE_STRINGS); + } + + long cycleBeforeRewrite = gcCycleMBean.getCollectionCount(); + + for (long loop = 1; loop < TARGET_OVERWRITES; loop++) { + int arrSize = astrs.size(); + int index = rn.nextInt(arrSize); + StringAndId item = astrs.get(index); + int n = rn.nextInt(UNIQUE_STRINGS); + item.str = "Unique String " + n; + item.id = n; + + if (loop % 1000 == 0) { + // enough GC cycles for rewritten strings to be deduplicated + if (gcCycleMBean.getCollectionCount() - cycleBeforeRewrite >= MAX_REWRITE_GC_CYCLES) { + break; + } + } + } + verifyDedepString(astrs); + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestStringInternCleanup.java 2018-11-30 21:07:11.963896912 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestStringInternCleanup + * @summary Check that Shenandoah cleans up interned strings + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestStringInternCleanup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestStringInternCleanup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestStringInternCleanup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestStringInternCleanup + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=aggressive TestStringInternCleanup + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestStringInternCleanup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestStringInternCleanup + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=adaptive TestStringInternCleanup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=static TestStringInternCleanup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=compact TestStringInternCleanup + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ClassUnloadingWithConcurrentMark -Xmx64m -XX:ShenandoahGCHeuristics=traversal TestStringInternCleanup + * + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:-ClassUnloadingWithConcurrentMark -Xmx64m TestStringInternCleanup + */ + +public class TestStringInternCleanup { + + static final int COUNT = 1_000_000; + static final int WINDOW = 1_000; + + static final String[] reachable = new String[WINDOW]; + + public static void main(String[] args) throws Exception { + int rIdx = 0; + for (int c = 0; c < COUNT; c++) { + reachable[rIdx] = ("LargeInternedString" + c).intern(); + rIdx++; + if (rIdx >= WINDOW) { + rIdx = 0; + } + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestVerifyJCStress.java 2018-11-30 21:07:12.209894637 +0100 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestVerifyJCStress + * @summary Tests that we pass at least one jcstress-like test with all verification turned on + * @key gc + * @requires vm.gc.Shenandoah + * @modules java.base/jdk.internal.misc + * java.management + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions + * -XX:+UseShenandoahGC -Xmx1g -Xms1g + * -XX:+ShenandoahStoreCheck -XX:+ShenandoahVerify -XX:+VerifyObjectEquals + * -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC + * TestVerifyJCStress + * + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions + * -XX:+UseShenandoahGC -Xmx1g -Xms1g + * -XX:+ShenandoahStoreCheck -XX:+ShenandoahVerify -XX:+VerifyObjectEquals + * -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC + * TestVerifyJCStress + * + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions + * -XX:+UseShenandoahGC -Xmx1g -Xms1g + * -XX:+ShenandoahStoreCheck -XX:+ShenandoahVerify -XX:+VerifyObjectEquals -XX:+ShenandoahVerifyOptoBarriers + * -XX:ShenandoahGCHeuristics=adaptive + * TestVerifyJCStress + * + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions + * -XX:+UseShenandoahGC -Xmx1g -Xms1g + * -XX:+ShenandoahStoreCheck -XX:+ShenandoahVerify -XX:+VerifyObjectEquals -XX:+ShenandoahVerifyOptoBarriers + * -XX:ShenandoahGCHeuristics=static + * TestVerifyJCStress + * + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions + * -XX:+UseShenandoahGC -Xmx1g -Xms1g + * -XX:+ShenandoahStoreCheck -XX:+ShenandoahVerify -XX:+VerifyObjectEquals -XX:+ShenandoahVerifyOptoBarriers + * -XX:ShenandoahGCHeuristics=traversal + * TestVerifyJCStress + */ + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.locks.*; + +public class TestVerifyJCStress { + + public static void main(String[] args) throws Exception { + ExecutorService service = Executors.newFixedThreadPool( + 2, + r -> { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + ); + + for (int c = 0; c < 10000; c++) { + final Test[] tests = new Test[10000]; + for (int t = 0; t < tests.length; t++) { + tests[t] = new Test(); + } + + Future f1 = service.submit(() -> { + IntResult2 r = new IntResult2(); + for (Test test : tests) { + test.RL_Us(r); + } + }); + Future f2 = service.submit(() -> { + for (Test test : tests) { + test.WLI_Us(); + } + }); + + f1.get(); + f2.get(); + } + } + + public static class IntResult2 { + int r1, r2; + } + + public static class Test { + final StampedLock lock = new StampedLock(); + + int x, y; + + public void RL_Us(IntResult2 r) { + StampedLock lock = this.lock; + long stamp = lock.readLock(); + r.r1 = x; + r.r2 = y; + lock.unlock(stamp); + } + + public void WLI_Us() { + try { + StampedLock lock = this.lock; + long stamp = lock.writeLockInterruptibly(); + x = 1; + y = 2; + lock.unlock(stamp); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestVerifyLevels.java 2018-11-30 21:07:12.450892409 +0100 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestVerifyLevels + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -Xmx128m -XX:+ShenandoahVerify -XX:ShenandoahVerifyLevel=0 TestVerifyLevels + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -Xmx128m -XX:+ShenandoahVerify -XX:ShenandoahVerifyLevel=1 TestVerifyLevels + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -Xmx128m -XX:+ShenandoahVerify -XX:ShenandoahVerifyLevel=2 TestVerifyLevels + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -Xmx128m -XX:+ShenandoahVerify -XX:ShenandoahVerifyLevel=3 TestVerifyLevels + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -Xmx128m -XX:+ShenandoahVerify -XX:ShenandoahVerifyLevel=4 TestVerifyLevels + */ + +public class TestVerifyLevels { + + static final long TARGET_MB = Long.getLong("target", 1_000); // 1 Gb allocation + + static Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 16; + for (long c = 0; c < count; c++) { + sink = new Object(); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestWithLogLevel.java 2018-11-30 21:07:12.685890236 +0100 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + + /* + * @test TestWithLogLevel + * @summary Test Shenandoah with different log levels + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms256M -Xmx1G -Xlog:gc*=error TestWithLogLevel + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms256M -Xmx1G -Xlog:gc*=warning TestWithLogLevel + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms256M -Xmx1G -Xlog:gc*=info TestWithLogLevel + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms256M -Xmx1G -Xlog:gc*=debug TestWithLogLevel + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms256M -Xmx1G -Xlog:gc*=trace TestWithLogLevel + */ + +import java.util.*; + +public class TestWithLogLevel { + public static void main(String[] args) { + ArrayList list = new ArrayList<>(); + long count = 300 * 1024 * 1024 / 16; // 300MB allocation + for (long index = 0; index < count; index++) { + Object sink = new Object(); + list.add(sink); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/TestWrongArrayMember.java 2018-11-30 21:07:12.928887990 +0100 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestWrongArrayMember + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -Xmx128m -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC TestWrongArrayMember + * @run main/othervm -Xmx128m -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal TestWrongArrayMember + */ + +public class TestWrongArrayMember { + public static void main(String... args) throws Exception { + Object[] src = new Object[3]; + src[0] = new Integer(0); + src[1] = new Object(); + src[2] = new Object(); + Object[] dst = new Integer[3]; + dst[0] = new Integer(1); + dst[1] = new Integer(2); + dst[2] = new Integer(3); + try { + System.arraycopy(src, 0, dst, 0, 3); + throw new RuntimeException("Expected ArrayStoreException"); + } catch (ArrayStoreException e) { + if (src[0] != dst[0]) { + throw new RuntimeException("First element not copied"); + } else if (src[1] == dst[1] || src[2] == dst[2]) { + throw new RuntimeException("Second and third elements are affected"); + } else { + return; // Passed! + } + } + } +} + --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestC1ArrayCopyNPE.java 2018-11-30 21:07:13.170885752 +0100 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestC1ArrayCopyNPE + * @summary test C1 arraycopy intrinsic + * @key gc + * @requires vm.gc.Shenandoah + * @run main/othervm -XX:TieredStopAtLevel=1 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestC1ArrayCopyNPE + */ + +public class TestC1ArrayCopyNPE { + + private static final int NUM_RUNS = 10000; + private static final int ARRAY_SIZE = 10000; + private static int[] a; + private static int[] b; + + public static void main(String[] args) { + a = null; + b = new int[ARRAY_SIZE]; + for (int i = 0; i < NUM_RUNS; i++) { + test(); + } + a = new int[ARRAY_SIZE]; + b = null; + for (int i = 0; i < NUM_RUNS; i++) { + test(); + } + } + + private static void test() { + try { + System.arraycopy(a, 0, b, 0, ARRAY_SIZE); + throw new RuntimeException("test failed"); + } catch (NullPointerException ex) { + // Ok + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestC1VectorizedMismatch.java 2018-11-30 21:07:13.411883524 +0100 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestC1VectorizedMismatch + * @summary test C1 vectorized mismatch intrinsic + * @key gc + * @requires vm.gc.Shenandoah + * @run main/othervm -XX:TieredStopAtLevel=1 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestC1VectorizedMismatch + */ + +import java.util.Arrays; + +public class TestC1VectorizedMismatch { + + private static final int NUM_RUNS = 10000; + private static final int ARRAY_SIZE = 10000; + private static int[] a; + private static int[] b; + + public static void main(String[] args) { + a = new int[ARRAY_SIZE]; + b = new int[ARRAY_SIZE]; + for (int i = 0; i < NUM_RUNS; i++) { + test(); + } + } + + private static void test() { + int[] a1 = new int[ARRAY_SIZE]; + int[] b1 = new int[ARRAY_SIZE]; + fillArray(a); + System.arraycopy(a, 0, b, 0, ARRAY_SIZE); + if (!Arrays.equals(a, b)) { + throw new RuntimeException("arrays not equal"); + } + } + + private static void fillArray(int[] array) { + for (int i = 0; i < ARRAY_SIZE; i++) { + int val = (int) (Math.random() * Integer.MAX_VALUE); + array[i] = val; + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestCommonGCLoads.java 2018-11-30 21:07:13.649881323 +0100 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test TestCommonGCLoads + * @summary Test GC state load commoning works + * @key gc + * @requires vm.flavor == "server" + * @requires vm.gc.Shenandoah + * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC + * -XX:-ShenandoahCommonGCStateLoads + * TestCommonGCLoads + * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC + * -XX:+ShenandoahCommonGCStateLoads + * TestCommonGCLoads + */ + +public class TestCommonGCLoads { + + static Object d = new Object(); + + static Target t1 = new Target(); + static Target t2 = new Target(); + static Target t3 = new Target(); + static Target t4 = new Target(); + static Target t5 = new Target(); + + static void test() { + t1.field = d; + t2.field = d; + t3.field = d; + t4.field = d; + t5.field = d; + } + + static public void main(String[] args) { + for (int i = 0; i < 100_000; i++) { + test(); + } + } + + static class Target { + Object field; + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestExpandedWBLostNullCheckDep.java 2018-11-30 21:07:13.890879095 +0100 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test TestExpandedWBLostNullCheckDep + * @summary Logic that moves a null check in the expanded barrier may cause a memory access that doesn't depend on the barrier to bypass the null check + * @key gc + * @requires vm.gc.Shenandoah + * @requires vm.flavor == "server" + * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation + * -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC + * -XX:+StressGCM -XX:+StressLCM TestExpandedWBLostNullCheckDep + */ + +public class TestExpandedWBLostNullCheckDep { + + static void test(int i, int[] arr) { + // arr.length depends on a null check for arr + if (i < 0 || i >= arr.length) { + } + // The write barrier here also depends on the null check. The + // null check is moved in the barrier to enable implicit null + // checks. The null check must not be moved arr.length + arr[i] = 0x42; + } + + static public void main(String[] args) { + int[] int_arr = new int[10]; + for (int i = 0; i < 20000; i++) { + test(0, int_arr); + } + try { + test(0, null); + } catch (NullPointerException npe) {} + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestMaybeNullUnsafeAccess.java 2018-11-30 21:07:14.128876895 +0100 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test TestMaybeNullUnsafeAccess + * @summary cast before unsafe access moved in dominating null check null path causes crash + * @key gc + * @requires vm.gc.Shenandoah + * @modules java.base/jdk.internal.misc:+open + * + * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation TestMaybeNullUnsafeAccess + * + */ + +import jdk.internal.misc.Unsafe; + +import java.lang.reflect.Field; + +public class TestMaybeNullUnsafeAccess { + + static final jdk.internal.misc.Unsafe UNSAFE = Unsafe.getUnsafe(); + static final long F_OFFSET; + + static class A { + int f; + } + + static { + try { + Field fField = A.class.getDeclaredField("f"); + F_OFFSET = UNSAFE.objectFieldOffset(fField); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + static A test_helper(Object o) { + return (A) o; + } + + static int test(Object o) { + int f = 0; + for (int i = 0; i < 100; i++) { + A a = test_helper(o); + f = UNSAFE.getInt(a, F_OFFSET); + } + return f; + } + + static public void main(String[] args) { + A a = new A(); + for (int i = 0; i < 20000; i++) { + test_helper(null); + test_helper(a); + test(a); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestNullCheck.java 2018-11-30 21:07:14.373874630 +0100 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test TestNullCheck + * @summary implicit null check on brooks pointer must not cause crash + * @key gc + * @requires vm.gc.Shenandoah + * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC + * -Xmx4G -XX:HeapBaseMinAddress=0x800000000 TestNullCheck + */ + +// HeapBaseMinAddress above forces compressed oops with a base + +public class TestNullCheck { + + int f; + + static int test1(TestNullCheck o) { + return o.f; + } + + static TestNullCheck static_obj = new TestNullCheck(); + + static int test2() { + return static_obj.f; + } + + static public void main(String[] args) { + TestNullCheck o = new TestNullCheck(); + for (int i = 0; i < 20000; i++) { + test1(o); + test2(); + } + try { + test1(null); + } catch (NullPointerException npe) {} + static_obj = null; + try { + test2(); + } catch (NullPointerException npe) {} + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestReferenceCAS.java 2018-11-30 21:07:14.620872346 +0100 @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * Run standalone with: --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED + */ + +/* + * @test TestReferenceCAS + * @summary Shenandoah reference CAS test + * @key gc + * @requires vm.gc.Shenandoah + * @modules java.base/jdk.internal.misc:+open + * + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC TestReferenceCAS + * @run main/othervm -Diters=100 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -Xint TestReferenceCAS + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:-TieredCompilation TestReferenceCAS + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:TieredStopAtLevel=1 TestReferenceCAS + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:TieredStopAtLevel=4 TestReferenceCAS + * + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:-UseCompressedOops TestReferenceCAS + * @run main/othervm -Diters=100 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:-UseCompressedOops -Xint TestReferenceCAS + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:-UseCompressedOops -XX:-TieredCompilation TestReferenceCAS + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:-UseCompressedOops -XX:TieredStopAtLevel=1 TestReferenceCAS + * @run main/othervm -Diters=20000 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseShenandoahGC -XX:-UseCompressedOops -XX:TieredStopAtLevel=4 TestReferenceCAS + */ + +import java.lang.reflect.Field; + +public class TestReferenceCAS { + + static final int ITERS = Integer.getInteger("iters", 1); + static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10); + + static final jdk.internal.misc.Unsafe UNSAFE; + static final long V_OFFSET; + + static { + try { + Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + UNSAFE = (jdk.internal.misc.Unsafe) f.get(null); + } catch (Exception e) { + throw new RuntimeException("Unable to get Unsafe instance.", e); + } + + try { + Field vField = TestReferenceCAS.class.getDeclaredField("v"); + V_OFFSET = UNSAFE.objectFieldOffset(vField); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + Object v; + + private static void assertEquals(boolean a, boolean b, String msg) { + if (a != b) { + throw new RuntimeException("a (" + a + ") != b (" + b + "): " + msg); + } + } + + private static void assertEquals(Object a, Object b, String msg) { + if (!a.equals(b)) { + throw new RuntimeException("a (" + a.toString() + ") != b (" + b.toString() + "): " + msg); + } + } + + public static void main(String[] args) { + TestReferenceCAS t = new TestReferenceCAS(); + for (int c = 0; c < ITERS; c++) { + testAccess(t, V_OFFSET); + } + } + + static void testAccess(Object base, long offset) { + String foo = new String("foo"); + String bar = new String("bar"); + String baz = new String("baz"); + UNSAFE.putReference(base, offset, "foo"); + { + String newval = bar; + boolean r = UNSAFE.compareAndSetReference(base, offset, "foo", newval); + assertEquals(r, true, "success compareAndSet Object"); + assertEquals(newval, "bar", "must not destroy newval"); + Object x = UNSAFE.getReference(base, offset); + assertEquals(x, "bar", "success compareAndSet Object value"); + } + + { + String newval = baz; + boolean r = UNSAFE.compareAndSetReference(base, offset, "foo", newval); + assertEquals(r, false, "failing compareAndSet Object"); + assertEquals(newval, "baz", "must not destroy newval"); + Object x = UNSAFE.getReference(base, offset); + assertEquals(x, "bar", "failing compareAndSet Object value"); + } + + UNSAFE.putReference(base, offset, "bar"); + { + String newval = foo; + Object r = UNSAFE.compareAndExchangeReference(base, offset, "bar", newval); + assertEquals(r, "bar", "success compareAndExchange Object"); + assertEquals(newval, "foo", "must not destroy newval"); + Object x = UNSAFE.getReference(base, offset); + assertEquals(x, "foo", "success compareAndExchange Object value"); + } + + { + String newval = baz; + Object r = UNSAFE.compareAndExchangeReference(base, offset, "bar", newval); + assertEquals(r, "foo", "failing compareAndExchange Object"); + assertEquals(newval, "baz", "must not destroy newval"); + Object x = UNSAFE.getReference(base, offset); + assertEquals(x, "foo", "failing compareAndExchange Object value"); + } + + UNSAFE.putReference(base, offset, "bar"); + { + String newval = foo; + boolean success = false; + for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { + success = UNSAFE.weakCompareAndSetReference(base, offset, "bar", newval); + assertEquals(newval, "foo", "must not destroy newval"); + } + assertEquals(success, true, "weakCompareAndSet Object"); + Object x = UNSAFE.getReference(base, offset); + assertEquals(x, "foo", "weakCompareAndSet Object"); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/compiler/TestWriteBarrierClearControl.java 2018-11-30 21:07:14.861870118 +0100 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test TestWriteBarrierClearControl + * @summary Clearing control during final graph reshape causes memory barrier to loose dependency on null check + * @key gc + * @requires vm.gc.Shenandoah + * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation + * -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC + * -XX:+UnlockDiagnosticVMOptions -XX:+StressLCM -XX:+StressGCM + * TestWriteBarrierClearControl + * + */ +public class TestWriteBarrierClearControl { + + int f; + + static void test1(TestWriteBarrierClearControl o) { + o.f = 0x42; + } + + static TestWriteBarrierClearControl fo = new TestWriteBarrierClearControl(); + + static void test2() { + TestWriteBarrierClearControl o = fo; + o.f = 0x42; + } + + static public void main(String[] args) { + TestWriteBarrierClearControl o = new TestWriteBarrierClearControl(); + for (int i = 0; i < 20000; i++) { + test1(o); + test2(); + } + try { + test1(null); + } catch (NullPointerException npe) {} + fo = null; + try { + test2(); + } catch (NullPointerException npe) {} + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jni/TestJNICritical.java 2018-11-30 21:07:15.096867945 +0100 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestJNICritical + * @summary test JNI critical arrays support in Shenandoah + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ShenandoahVerify TestJNICritical + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestJNICritical + */ + +import java.util.Arrays; + +public class TestJNICritical { + static { + System.loadLibrary("TestJNICritical"); + } + + private static final int NUM_RUNS = 10000; + private static final int ARRAY_SIZE = 10000; + private static int[] a; + private static int[] b; + + private static native void copyAtoB(int[] a, int[] b); + + public static void main(String[] args) { + a = new int[ARRAY_SIZE]; + b = new int[ARRAY_SIZE]; + for (int i = 0; i < NUM_RUNS; i++) { + test(); + } + } + + private static void test() { + int[] a1 = new int[ARRAY_SIZE]; + int[] b1 = new int[ARRAY_SIZE]; + fillArray(a); + copyAtoB(a, b); + copyAtoB(a1, b1); // Don't optimize out garbage arrays. + if (!Arrays.equals(a, b)) { + throw new RuntimeException("arrays not equal"); + } + } + + private static void fillArray(int[] array) { + for (int i = 0; i < ARRAY_SIZE; i++) { + int val = (int) (Math.random() * Integer.MAX_VALUE); + array[i] = val; + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jni/TestJNIGlobalRefs.java 2018-11-30 21:07:15.341865680 +0100 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestJNIGlobalRefs + * @summary Test JNI Global Refs with Shenandoah + * @key gc + * @requires vm.gc.Shenandoah + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xlog:gc -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahVerify TestJNIGlobalRefs + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xlog:gc -XX:ShenandoahGCHeuristics=aggressive TestJNIGlobalRefs + */ + +import java.util.Arrays; +import java.util.Random; + +public class TestJNIGlobalRefs { + static { + System.loadLibrary("TestJNIGlobalRefs"); + } + + private static final int TIME_MSEC = 120000; + private static final int ARRAY_SIZE = 10000; + + private static native void makeGlobalRef(Object o); + private static native void makeWeakGlobalRef(Object o); + private static native Object readGlobalRef(); + private static native Object readWeakGlobalRef(); + + public static void main(String[] args) throws Throwable { + seedGlobalRef(); + seedWeakGlobalRef(); + long start = System.currentTimeMillis(); + long current = start; + while (current - start < TIME_MSEC) { + testGlobal(); + testWeakGlobal(); + Thread.sleep(1); + current = System.currentTimeMillis(); + } + } + + private static void seedGlobalRef() { + int[] a = new int[ARRAY_SIZE]; + fillArray(a, 1337); + makeGlobalRef(a); + } + + private static void seedWeakGlobalRef() { + int[] a = new int[ARRAY_SIZE]; + fillArray(a, 8080); + makeWeakGlobalRef(a); + } + + private static void testGlobal() { + int[] a = (int[]) readGlobalRef(); + checkArray(a, 1337); + } + + private static void testWeakGlobal() { + int[] a = (int[]) readWeakGlobalRef(); + if (a != null) { + checkArray(a, 8080); + } else { + // weak reference is cleaned, recreate: + seedWeakGlobalRef(); + } + } + + private static void fillArray(int[] array, int seed) { + Random r = new Random(seed); + for (int i = 0; i < ARRAY_SIZE; i++) { + array[i] = r.nextInt(); + } + } + + private static void checkArray(int[] array, int seed) { + Random r = new Random(seed); + if (array.length != ARRAY_SIZE) { + throw new IllegalStateException("Illegal array length: " + array.length + ", but expected " + ARRAY_SIZE); + } + for (int i = 0; i < ARRAY_SIZE; i++) { + int actual = array[i]; + int expected = r.nextInt(); + if (actual != expected) { + throw new IllegalStateException("Incorrect array data: " + actual + ", but expected " + expected); + } + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jni/TestPinnedGarbage.java 2018-11-30 21:07:15.589863387 +0100 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestPinnedGarbage + * @summary Test that garbage in the pinned region does not crash VM + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx512m -XX:+ShenandoahVerify -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestPinnedGarbage + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx512m -XX:+ShenandoahVerify -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestPinnedGarbage + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx512m -XX:ShenandoahGCHeuristics=aggressive TestPinnedGarbage + * + * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx512m -XX:+ShenandoahVerify TestPinnedGarbage + */ + +import java.util.Arrays; +import java.util.concurrent.*; + +public class TestPinnedGarbage { + static { + System.loadLibrary("TestPinnedGarbage"); + } + + private static final int NUM_RUNS = 1_000; + private static final int OBJS_COUNT = 1_000; + private static final int GARBAGE_COUNT = 1_000_000; + + private static native void pin(int[] a); + private static native void unpin(int[] a); + + public static void main(String[] args) { + for (int i = 0; i < NUM_RUNS; i++) { + test(); + } + } + + private static void test() { + Object[] objs = new Object[OBJS_COUNT]; + for (int i = 0; i < OBJS_COUNT; i++) { + objs[i] = new MyClass(); + } + + int[] cog = new int[10]; + int cogIdx = ThreadLocalRandom.current().nextInt(OBJS_COUNT); + objs[cogIdx] = cog; + pin(cog); + + for (int i = 0; i < GARBAGE_COUNT; i++) { + int rIdx = ThreadLocalRandom.current().nextInt(OBJS_COUNT); + if (rIdx != cogIdx) { + objs[rIdx] = new MyClass(); + } + } + + unpin(cog); + } + + public static class MyClass { + public Object ref = new Object(); + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jni/libTestJNICritical.c 2018-11-30 21:07:15.830861159 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include +#include + +JNIEXPORT void JNICALL +Java_TestJNICritical_copyAtoB(JNIEnv *env, jclass unused, jintArray a, jintArray b) { + jint len = (*env)->GetArrayLength(env, a); + jint* aa = (*env)->GetPrimitiveArrayCritical(env, a, 0); + jint* bb = (*env)->GetPrimitiveArrayCritical(env, b, 0); + memcpy(bb, aa, len * sizeof(jint)); + (*env)->ReleasePrimitiveArrayCritical(env, b, bb, 0); + (*env)->ReleasePrimitiveArrayCritical(env, a, aa, 0); +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jni/libTestJNIGlobalRefs.c 2018-11-30 21:07:16.074858903 +0100 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include +#include + +jobject global_ref = NULL; +jobject weak_global_ref = NULL; + +JNIEXPORT void JNICALL +Java_TestJNIGlobalRefs_makeGlobalRef(JNIEnv *env, jclass unused, jobject o) { + global_ref = (*env)->NewGlobalRef(env, o); +} + +JNIEXPORT void JNICALL +Java_TestJNIGlobalRefs_makeWeakGlobalRef(JNIEnv *env, jclass unused, jobject o) { + weak_global_ref = (*env)->NewWeakGlobalRef(env, o); +} + +JNIEXPORT jobject JNICALL +Java_TestJNIGlobalRefs_readGlobalRef(JNIEnv *env, jclass unused) { + return global_ref; +} + +JNIEXPORT jobject JNICALL +Java_TestJNIGlobalRefs_readWeakGlobalRef(JNIEnv *env, jclass unused) { + return weak_global_ref; +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jni/libTestPinnedGarbage.c 2018-11-30 21:07:16.314856684 +0100 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include +#include + +static jint* pinned; + +JNIEXPORT void JNICALL +Java_TestPinnedGarbage_pin(JNIEnv *env, jclass unused, jintArray a) { + pinned = (*env)->GetPrimitiveArrayCritical(env, a, 0); +} + +JNIEXPORT void JNICALL +Java_TestPinnedGarbage_unpin(JNIEnv *env, jclass unused, jintArray a) { + (*env)->ReleasePrimitiveArrayCritical(env, a, pinned, 0); +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jvmti/TestHeapDump.java 2018-11-30 21:07:16.556854447 +0100 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestHeapDump + * @summary Tests JVMTI heap dumps + * @key gc + * @requires vm.gc.Shenandoah + * @compile TestHeapDump.java + * @run main/othervm/native/timeout=300 -agentlib:TestHeapDump -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx128m -XX:ShenandoahGCHeuristics=aggressive -XX:+UseCompressedOops TestHeapDump + * @run main/othervm/native/timeout=300 -agentlib:TestHeapDump -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx128m -XX:ShenandoahGCHeuristics=aggressive -XX:-UseCompressedOops TestHeapDump + */ + +public class TestHeapDump { + + private static final int NUM_ITER = 10000; + + private static final int ARRAY_SIZE = 1000; + + private static final int EXPECTED_OBJECTS = + ARRAY_SIZE + // array reachable from instance field + 1 + // static field root + 1; // local field root + + static { + try { + System.loadLibrary("TestHeapDump"); + } catch (UnsatisfiedLinkError ule) { + System.err.println("Could not load TestHeapDump library"); + System.err.println("java.library.path: " + + System.getProperty("java.library.path")); + throw ule; + } + } + + native static int heapdump(Class filterClass); + + public static void main(String args[]) { + new TestHeapDump().run(); + } + + // This root needs to be discovered + static Object root = new TestObject(); + + // This field needs to be discovered + TestObject[] array; + + public void run() { + array = new TestObject[ARRAY_SIZE]; + for (int i = 0; i < ARRAY_SIZE; i++) { + array[i] = new TestObject(); + } + TestObject localRoot = new TestObject(); + for (int i = 0; i < NUM_ITER; i++) { + int numObjs = heapdump(TestObject.class); + if (numObjs != EXPECTED_OBJECTS) { + throw new RuntimeException("Expected " + EXPECTED_OBJECTS + " objects, but got " + numObjs); + } + } + } + + // We look for the instances of this class during the heap scan + public static class TestObject {} +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/jvmti/libTestHeapDump.c 2018-11-30 21:07:16.797852219 +0100 @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include +#include +#include "jvmti.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +#define TranslateError(err) "JVMTI error" + +#define PASSED 0 +#define FAILED 2 + +static const char *EXC_CNAME = "java/lang/Exception"; + +static jvmtiEnv *jvmti = NULL; +static jint result = PASSED; + +static jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved); + +JNIEXPORT +jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} + +JNIEXPORT +jint JNICALL Agent_OnAttach(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} + +JNIEXPORT +jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { + return JNI_VERSION_1_8; +} + +static +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiCapabilities capabilities; + jint res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION_9); + if (res != JNI_OK || jvmti == NULL) { + printf(" Error: wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + (void)memset(&capabilities, 0, sizeof(capabilities)); + capabilities.can_tag_objects = 1; + capabilities.can_generate_garbage_collection_events = 1; + (*jvmti)->AddCapabilities(jvmti, &capabilities); + + return JNI_OK; +} + +static +void throw_exc(JNIEnv *env, char *msg) { + jclass exc_class = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, EXC_CNAME)); + jint rt = JNI_OK; + + if (exc_class == NULL) { + printf("throw_exc: Error in FindClass(env, %s)\n", EXC_CNAME); + return; + } + rt = JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG(env, exc_class), msg); + if (rt == JNI_ERR) { + printf("throw_exc: Error in JNI ThrowNew(env, %s)\n", msg); + } +} + +static jint JNICALL heap_iter_callback(jlong class_tag, + jlong size, + jlong* tag_ptr, + jint length, + void* user_data) { + (*((jint*)(user_data)))++; + return JVMTI_VISIT_OBJECTS; +} + +JNIEXPORT jint JNICALL +Java_TestHeapDump_heapdump(JNIEnv *env, jclass cls, jclass filter_cls) { + jvmtiHeapCallbacks callbacks; + jint totalCount = 0; + if (jvmti == NULL) { + throw_exc(env, "JVMTI client was not properly loaded!\n"); + return 0; + } + + (void)memset(&callbacks, 0, sizeof(callbacks)); + callbacks.heap_iteration_callback = &heap_iter_callback; + (*jvmti)->IterateThroughHeap(jvmti, 0, filter_cls, &callbacks, (const void *)&totalCount); + return totalCount; +} + +#ifdef __cplusplus +} +#endif --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/mxbeans/TestChurnNotifications.java 2018-11-30 21:07:17.034850027 +0100 @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestChurnNotifications + * @summary Check that MX notifications are reported for all cycles + * @requires vm.gc.Shenandoah + * + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -Dprecise=true TestChurnNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -Dprecise=true TestChurnNotifications + * + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -Dprecise=false TestChurnNotifications + * + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -Dprecise=false TestChurnNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static -Dprecise=false TestChurnNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact -Dprecise=false TestChurnNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal -Dprecise=false TestChurnNotifications + */ + +import java.util.*; +import java.util.concurrent.atomic.*; +import javax.management.*; +import java.lang.management.*; +import javax.management.openmbean.*; + +import com.sun.management.GarbageCollectionNotificationInfo; + +public class TestChurnNotifications { + + static final long HEAP_MB = 128; // adjust for test configuration above + static final long TARGET_MB = Long.getLong("target", 8_000); // 8 Gb allocation + + // Should we track the churn precisely? + // Precise tracking is only reliable when GC is fully stop-the-world. Otherwise, + // we cannot tell, looking at heap used before/after, what was the GC churn. + static final boolean PRECISE = Boolean.getBoolean("precise"); + + static final long M = 1024 * 1024; + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + final AtomicLong churnBytes = new AtomicLong(); + + NotificationListener listener = new NotificationListener() { + @Override + public void handleNotification(Notification n, Object o) { + if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) { + GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData()); + Map mapBefore = info.getGcInfo().getMemoryUsageBeforeGc(); + Map mapAfter = info.getGcInfo().getMemoryUsageAfterGc(); + + MemoryUsage before = mapBefore.get("Shenandoah"); + MemoryUsage after = mapAfter.get("Shenandoah"); + + if ((before != null) && (after != null)) { + long diff = before.getUsed() - after.getUsed(); + if (diff > 0) { + churnBytes.addAndGet(diff); + } + } + } + } + }; + + for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { + ((NotificationEmitter) bean).addNotificationListener(listener, null, null); + } + + final int size = 100_000; + long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size); + + long mem = count * (16 + 4 * size); + + for (int c = 0; c < count; c++) { + sink = new int[size]; + } + + System.gc(); + + Thread.sleep(1000); + + long actual = churnBytes.get(); + + long minExpected = PRECISE ? (mem - HEAP_MB * 1024 * 1024) : 1; + long maxExpected = mem + HEAP_MB * 1024 * 1024; + + String msg = "Expected = [" + minExpected / M + "; " + maxExpected / M + "] (" + mem / M + "), actual = " + actual / M; + if (minExpected < actual && actual < maxExpected) { + System.out.println(msg); + } else { + throw new IllegalStateException(msg); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/mxbeans/TestMemoryMXBeans.java 2018-11-30 21:07:17.278847772 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestMemoryMXBeans + * @summary Test JMX memory beans + * @key gc + * @requires vm.gc.Shenandoah + * @modules java.base/jdk.internal.misc + * java.management + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g TestMemoryMXBeans -1 1024 + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms1g -Xmx1g TestMemoryMXBeans 1024 1024 + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms128m -Xmx1g TestMemoryMXBeans 128 1024 + */ + +import java.lang.management.*; +import java.util.*; + +public class TestMemoryMXBeans { + + public static void main(String[] args) throws Exception { + if (args.length < 2) { + throw new IllegalStateException("Should provide expected heap sizes"); + } + + long initSize = 1L * Integer.parseInt(args[0]) * 1024 * 1024; + long maxSize = 1L * Integer.parseInt(args[1]) * 1024 * 1024; + + testMemoryBean(initSize, maxSize); + } + + public static void testMemoryBean(long initSize, long maxSize) { + MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + long heapInit = memoryMXBean.getHeapMemoryUsage().getInit(); + long heapMax = memoryMXBean.getHeapMemoryUsage().getMax(); + long nonHeapInit = memoryMXBean.getNonHeapMemoryUsage().getInit(); + long nonHeapMax = memoryMXBean.getNonHeapMemoryUsage().getMax(); + + if (initSize > 0 && heapInit != initSize) { + throw new IllegalStateException("Init heap size is wrong: " + heapInit + " vs " + initSize); + } + if (maxSize > 0 && heapMax != maxSize) { + throw new IllegalStateException("Max heap size is wrong: " + heapMax + " vs " + maxSize); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/mxbeans/TestMemoryPools.java 2018-11-30 21:07:17.516845571 +0100 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestMemoryPools + * @summary Test JMX memory pools + * @key gc + * @requires vm.gc.Shenandoah + * @modules java.base/jdk.internal.misc + * java.management + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g -Xms1g TestMemoryPools + */ + +import java.lang.management.*; +import java.util.*; + +public class TestMemoryPools { + + public static void main(String[] args) throws Exception { + List mms = ManagementFactory.getMemoryManagerMXBeans(); + if (mms == null) { + throw new RuntimeException("getMemoryManagerMXBeans is null"); + } + if (mms.isEmpty()) { + throw new RuntimeException("getMemoryManagerMXBeans is empty"); + } + for (MemoryManagerMXBean mmBean : mms) { + String[] names = mmBean.getMemoryPoolNames(); + if (names == null) { + throw new RuntimeException("getMemoryPoolNames() is null"); + } + if (names.length == 0) { + throw new RuntimeException("getMemoryPoolNames() is empty"); + } + for (String name : names) { + if (name == null) { + throw new RuntimeException("pool name is null"); + } + if (name.length() == 0) { + throw new RuntimeException("pool name is empty"); + } + } + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/mxbeans/TestPauseNotifications.java 2018-11-30 21:07:17.758843333 +0100 @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestPauseNotifications + * @summary Check that MX notifications are reported for all cycles + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestPauseNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestPauseNotifications + * + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestPauseNotifications + * + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive TestPauseNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static TestPauseNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact TestPauseNotifications + * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal TestPauseNotifications + */ + +import java.util.*; +import java.util.concurrent.atomic.*; +import javax.management.*; +import java.lang.management.*; +import javax.management.openmbean.*; + +import com.sun.management.GarbageCollectionNotificationInfo; + +public class TestPauseNotifications { + + static final long HEAP_MB = 128; // adjust for test configuration above + static final long TARGET_MB = Long.getLong("target", 8_000); // 8 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + final AtomicLong pausesDuration = new AtomicLong(); + final AtomicLong cyclesDuration = new AtomicLong(); + + NotificationListener listener = new NotificationListener() { + @Override + public void handleNotification(Notification n, Object o) { + if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) { + GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData()); + + System.out.println(info.getGcInfo().toString()); + System.out.println(info.getGcName()); + System.out.println(); + + long d = info.getGcInfo().getDuration(); + + String name = info.getGcName(); + if (name.contains("Shenandoah")) { + if (name.equals("Shenandoah Pauses")) { + pausesDuration.addAndGet(d); + } else if (name.equals("Shenandoah Cycles")) { + cyclesDuration.addAndGet(d); + } else { + throw new IllegalStateException("Unknown name: " + name); + } + } + } + } + }; + + for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { + ((NotificationEmitter) bean).addNotificationListener(listener, null, null); + } + + final int size = 100_000; + long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size); + + for (int c = 0; c < count; c++) { + sink = new int[size]; + } + + Thread.sleep(1000); + + long pausesActual = pausesDuration.get(); + long cyclesActual = cyclesDuration.get(); + + long minExpected = 1; + long maxExpected = Long.MAX_VALUE; + + { + String msg = "Pauses expected = [" + minExpected + "; " + maxExpected + "], actual = " + pausesActual; + if (minExpected < pausesActual && pausesActual < maxExpected) { + System.out.println(msg); + } else { + throw new IllegalStateException(msg); + } + } + + { + String msg = "Cycles expected = [" + minExpected + "; " + maxExpected + "], actual = " + cyclesActual; + if (minExpected < cyclesActual && cyclesActual < maxExpected) { + System.out.println(msg); + } else { + throw new IllegalStateException(msg); + } + } + + { + String msg = "Cycle duration (" + cyclesActual + "), pause duration (" + pausesActual + ")"; + if (pausesActual < cyclesActual) { + System.out.println(msg); + } else { + throw new IllegalStateException(msg); + } + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/oom/TestAllocLargeObj.java 2018-11-30 21:07:17.997841124 +0100 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestAllocLargeObj + * @summary Test allocation of small object to result OOM, but not to crash JVM + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run main TestAllocLargeObj + */ + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestAllocLargeObj { + + static final int SIZE = 1 * 1024 * 1024; + static final int COUNT = 16; + + static volatile Object sink; + + public static void work() throws Exception { + Object[] root = new Object[COUNT]; + sink = root; + for (int c = 0; c < COUNT; c++) { + root[c] = new Object[SIZE]; + } + } + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + work(); + return; + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx16m", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestAllocLargeObj.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(1); + analyzer.shouldContain("java.lang.OutOfMemoryError: Java heap space"); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx1g", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestAllocLargeObj.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(0); + analyzer.shouldNotContain("java.lang.OutOfMemoryError: Java heap space"); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/oom/TestAllocLargerThanHeap.java 2018-11-30 21:07:18.241838868 +0100 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestAllocLargerThanHeap + * @summary Test that allocation of the object larger than heap fails predictably + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run main TestAllocLargerThanHeap + */ + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestAllocLargerThanHeap { + + static final int SIZE = 16 * 1024 * 1024; + + static volatile Object sink; + + public static void work() throws Exception { + sink = new Object[SIZE]; + } + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + work(); + return; + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx16m", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestAllocLargerThanHeap.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(1); + analyzer.shouldContain("java.lang.OutOfMemoryError: Java heap space"); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx1g", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestAllocLargerThanHeap.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(0); + analyzer.shouldNotContain("java.lang.OutOfMemoryError: Java heap space"); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/oom/TestAllocSmallObj.java 2018-11-30 21:07:18.475836705 +0100 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestAllocSmallObj + * @summary Test allocation of small object to result OOM, but not to crash JVM + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run main TestAllocSmallObj + */ + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestAllocSmallObj { + + static final int COUNT = 16 * 1024 * 1024; + + static volatile Object sink; + + public static void work() throws Exception { + Object[] root = new Object[COUNT]; + sink = root; + for (int c = 0; c < COUNT; c++) { + root[c] = new Object(); + } + } + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + work(); + return; + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx16m", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestAllocSmallObj.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(1); + analyzer.shouldContain("java.lang.OutOfMemoryError: Java heap space"); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx1g", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestAllocSmallObj.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(0); + analyzer.shouldNotContain("java.lang.OutOfMemoryError: Java heap space"); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/oom/TestClassLoaderLeak.java 2018-11-30 21:07:18.718834459 +0100 @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestClassLoaderLeak + * @summary Test OOME in due to classloader leak + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run main TestClassLoaderLeak + */ + +import java.util.*; +import java.io.*; +import java.nio.*; +import java.nio.file.*; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestClassLoaderLeak { + + static final int SIZE = 1 * 1024 * 1024; + static final int COUNT = 128; + + static volatile Object sink; + + static class Dummy { + static final int[] PAYLOAD = new int[SIZE]; + } + + static class MyClassLoader extends ClassLoader { + final String path; + + MyClassLoader(String path) { + this.path = path; + } + + public Class loadClass(String name) throws ClassNotFoundException { + try { + File f = new File(path, name + ".class"); + if (!f.exists()) { + return super.loadClass(name); + } + + Path path = Paths.get(f.getAbsolutePath()); + byte[] cls = Files.readAllBytes(path); + return defineClass(name, cls, 0, cls.length, null); + } catch (IOException e) { + throw new ClassNotFoundException(name); + } + } + } + + static void load(String path) throws Exception { + ClassLoader cl = new MyClassLoader(path); + Class c = (Class) Class.forName("TestClassLoaderLeak$Dummy", true, cl); + if (c.getClassLoader() != cl) { + throw new IllegalStateException("Should have loaded by target loader"); + } + sink = c; + } + + public static void passWith(String... args) throws Exception { + testWith(true, args); + } + + public static void failWith(String... args) throws Exception { + testWith(false, args); + } + + public static void testWith(boolean shouldPass, String... args) throws Exception { + List pbArgs = new ArrayList<>(); + pbArgs.add("-Xmx128m"); + pbArgs.add("-XX:+UnlockExperimentalVMOptions"); + pbArgs.add("-XX:+UnlockDiagnosticVMOptions"); + pbArgs.add("-XX:+UseShenandoahGC"); + pbArgs.addAll(Arrays.asList(args)); + pbArgs.add(TestClassLoaderLeak.class.getName()); + pbArgs.add("test"); + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(pbArgs.toArray(new String[0])); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + + if (shouldPass) { + analyzer.shouldHaveExitValue(0); + analyzer.shouldNotContain("java.lang.OutOfMemoryError"); + analyzer.shouldContain("All good"); + } else { + analyzer.shouldHaveExitValue(1); + analyzer.shouldContain("java.lang.OutOfMemoryError"); + analyzer.shouldNotContain("All good"); + } + } + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + String classDir = TestClassLoaderLeak.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + for (int c = 0; c < COUNT; c++) { + load(classDir); + } + System.out.println("All good"); + return; + } + + String[] heuristics = new String[] { + "adaptive", + "compact", + "static", + "traversal", + "aggressive", + "passive", + }; + + for (String h : heuristics) { + // Forceful enabling should work + passWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading"); + passWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloadingWithConcurrentMark"); + + // Even when concurrent unloading is disabled, Full GC has to recover + passWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading", "-XX:-ClassUnloadingWithConcurrentMark"); + passWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading", "-XX:-ClassUnloadingWithConcurrentMark", "-XX:ShenandoahUnloadClassesFrequency=0"); + passWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading", "-XX:+ClassUnloadingWithConcurrentMark", "-XX:ShenandoahUnloadClassesFrequency=0"); + + // Should OOME when unloading forcefully disabled, even if local flags try to enable it back + failWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading"); + failWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading", "-XX:+ClassUnloadingWithConcurrentMark"); + failWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading", "-XX:+ClassUnloadingWithConcurrentMark", "-XX:ShenandoahUnloadClassesFrequency=1"); + failWith("-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading", "-XX:-ClassUnloadingWithConcurrentMark", "-XX:ShenandoahUnloadClassesFrequency=1"); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/oom/TestThreadFailure.java 2018-11-30 21:07:18.955832268 +0100 @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test TestThreadFailure + * @summary Test OOME in separate thread is recoverable + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run main TestThreadFailure + */ + +import java.util.*; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestThreadFailure { + + static final int SIZE = 1024; + static final int COUNT = 16; + + static class NastyThread extends Thread { + @Override + public void run() { + List root = new ArrayList(); + while (true) { + root.add(new Object[SIZE]); + } + } + } + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + for (int t = 0; t < COUNT; t++) { + Thread thread = new NastyThread(); + thread.start(); + thread.join(); + } + System.out.println("All good"); + return; + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx16m", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestThreadFailure.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(0); + analyzer.shouldContain("java.lang.OutOfMemoryError"); + analyzer.shouldContain("All good"); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xmx128m", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + TestThreadFailure.class.getName(), + "test"); + + OutputAnalyzer analyzer = new OutputAnalyzer(pb.start()); + analyzer.shouldHaveExitValue(0); + analyzer.shouldContain("java.lang.OutOfMemoryError"); + analyzer.shouldContain("All good"); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestAlwaysPreTouch.java 2018-11-30 21:07:19.198830021 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestAlwaysPreTouch + * @summary Check that Shenandoah's AlwaysPreTouch does not fire asserts + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+AlwaysPreTouch -Xmx1g TestAlwaysPreTouch + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+AlwaysPreTouch -XX:ConcGCThreads=2 -Xmx1g TestAlwaysPreTouch + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+AlwaysPreTouch -XX:ParallelGCThreads=2 -Xmx1g TestAlwaysPreTouch + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+AlwaysPreTouch -Xms128m -Xmx1g TestAlwaysPreTouch + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+AlwaysPreTouch -Xms1g -Xmx1g TestAlwaysPreTouch + */ + +public class TestAlwaysPreTouch { + + public static void main(String[] args) throws Exception { + // checking the initialization before entering main() + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestArgumentRanges.java 2018-11-30 21:07:19.440827784 +0100 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestArgumentRanges + * @summary Test that Shenandoah arguments are checked for ranges where applicable + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @run driver TestArgumentRanges + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestArgumentRanges { + public static void main(String[] args) throws Exception { + testRange("ShenandoahGarbageThreshold", 0, 100); + testRange("ShenandoahFreeThreshold", 0, 100); + testRange("ShenandoahAllocationThreshold", 0, 100); + testHeuristics(); + } + + private static void testHeuristics() throws Exception { + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=aggressive", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=static", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=fluff", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Unknown -XX:ShenandoahGCHeuristics option"); + output.shouldHaveExitValue(1); + } + } + + private static void testRange(String option, int min, int max) throws Exception { + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:" + option + "=" + (max + 1), + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(1); + } + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:" + option + "=" + max, + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:" + option + "=" + (min - 1), + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(1); + } + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:" + option + "=" + min, + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestClassUnloadingArguments.java 2018-11-30 21:07:19.685825519 +0100 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestClassUnloadingArguments + * @summary Test that loop mining arguments are sane + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run driver TestClassUnloadingArguments + */ + +import java.util.*; + +import jdk.test.lib.Asserts; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestClassUnloadingArguments { + + public static void testWith(String msg, boolean cu, boolean cuConc, String... args) throws Exception { + String[] cmds = Arrays.copyOf(args, args.length + 2); + cmds[args.length] = "-XX:+PrintFlagsFinal"; + cmds[args.length + 1] = "-version"; + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + output.shouldContain("ClassUnloading"); + output.shouldContain("ClassUnloadingWithConcurrentMark"); + + Asserts.assertEQ(output.firstMatch("(.+?) ClassUnloading.+?= (.+?) (.+?)", 2), + Boolean.toString(cu), + msg + ", but got wrong ClassUnloading"); + Asserts.assertEQ(output.firstMatch("(.+?) ClassUnloadingWithConcurrentMark.+?= (.+?) (.+?)", 2), + Boolean.toString(cuConc), + msg + ", but got wrong ClassUnloadingWithConcurrentMark"); + } + + public static void main(String[] args) throws Exception { + testDefaultGC(); + testShenandoah(); + } + + public static void testDefaultGC() throws Exception { + testWith("Default GC should have class unloading enabled", + true, true); + + testWith("Default GC should disable everything", + false, false, + "-XX:-ClassUnloading"); + + testWith("Default GC should disable conc unload", + true, false, + "-XX:-ClassUnloadingWithConcurrentMark"); + + testWith("Default GC should not let conc unload to be enabled separately", + false, false, + "-XX:-ClassUnloading", + "-XX:+ClassUnloadingWithConcurrentMark"); + } + + public static void testShenandoah() throws Exception { + testWith("Shenandoah GC should have class unloading enabled", + true, false, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC"); + + testWith("Shenandoah GC should disable everything", + false, false, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:-ClassUnloading"); + + testWith("Shenandoah GC should enable conc unload", + true, true, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:+ClassUnloadingWithConcurrentMark"); + + testWith("Shenandoah GC should not let conc unload to be enabled separately", + false, false, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:-ClassUnloading", + "-XX:+ClassUnloadingWithConcurrentMark"); + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestCodeCacheRootStyles.java 2018-11-30 21:07:19.927823281 +0100 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestCodeCacheRootStyles + * @key gc + * @requires vm.gc.Shenandoah + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahCodeRootsStyle=0 TestCodeCacheRootStyles + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahCodeRootsStyle=1 TestCodeCacheRootStyles + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahCodeRootsStyle=2 TestCodeCacheRootStyles + */ + +public class TestCodeCacheRootStyles { + public static void main(String[] args) { + // Bug should crash before we get here. + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestEnabled.java 2018-11-30 21:07:20.169821044 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.lang.management.GarbageCollectorMXBean; +import java.lang.management.ManagementFactory; + +/* + * @test TestEnabled + * @key gc + * @requires vm.gc.Shenandoah & vm.gc == "null" + * @run main/othervm -Dexpected=false -Xmx64m TestEnabled + * @run main/othervm -Dexpected=true -Xmx64m -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC TestEnabled + */ + +/* + * @test TestEnabledAlready + * @key gc + * @requires vm.gc.Shenandoah & vm.gc == "Shenandoah" + * @run main/othervm -Dexpected=true -Xmx64m TestEnabled + */ +public class TestEnabled { + + public static void main(String... args) { + boolean expected = Boolean.getBoolean("expected"); + boolean actual = isEnabled(); + if (expected != actual) { + throw new IllegalStateException("Error: expected = " + expected + ", actual = " + actual); + } + } + + public static boolean isEnabled() { + for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { + if (bean.getName().contains("Shenandoah")) { + return true; + } + } + return false; + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestExplicitGC.java 2018-11-30 21:07:20.410818816 +0100 @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestExplicitGC + * @summary Test that Shenandoah reacts to explicit GC flags appropriately + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @run driver TestExplicitGC + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestExplicitGC { + + enum Mode { + PRODUCT, + DIAGNOSTIC, + EXPERIMENTAL, + } + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + System.out.println("Calling System.gc()"); + System.gc(); + return; + } + + String[] full = new String[] { + "Pause Full" + }; + + String[] concNormal = new String[] { + "Pause Init Mark", + "Pause Final Mark", + }; + + String[] concTraversal = new String[] { + "Pause Init Traversal", + "Pause Final Traversal", + }; + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xlog:gc", + TestExplicitGC.class.getName(), + "test"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + for (String p : full) { + output.shouldNotContain(p); + } + for (String p : concNormal) { + output.shouldContain(p); + } + for (String p : concTraversal) { + output.shouldNotContain(p); + } + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xlog:gc", + "-XX:+DisableExplicitGC", + TestExplicitGC.class.getName(), + "test"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + for (String p : full) { + output.shouldNotContain(p); + } + for (String p : concNormal) { + output.shouldNotContain(p); + } + for (String p : concTraversal) { + output.shouldNotContain(p); + } + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xlog:gc", + "-XX:+ExplicitGCInvokesConcurrent", + TestExplicitGC.class.getName(), + "test"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + for (String p : full) { + output.shouldNotContain(p); + } + for (String p : concNormal) { + output.shouldContain(p); + } + for (String p : concTraversal) { + output.shouldNotContain(p); + } + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xlog:gc", + "-XX:+ExplicitGCInvokesConcurrent", + "-XX:ShenandoahGCHeuristics=traversal", + TestExplicitGC.class.getName(), + "test"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + for (String p : full) { + output.shouldNotContain(p); + } + for (String p : concNormal) { + output.shouldNotContain(p); + } + for (String p : concTraversal) { + output.shouldContain(p); + } + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xlog:gc", + "-XX:-ExplicitGCInvokesConcurrent", + TestExplicitGC.class.getName(), + "test"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + for (String p : full) { + output.shouldContain(p); + } + for (String p : concNormal) { + output.shouldNotContain(p); + } + for (String p : concTraversal) { + output.shouldNotContain(p); + } + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestExplicitGCNoConcurrent.java 2018-11-30 21:07:20.650816597 +0100 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestExplicitGCNoConcurrent + * @summary Test that Shenandoah reacts to explicit GC flags appropriately + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @run driver TestExplicitGCNoConcurrent + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestExplicitGCNoConcurrent { + + public static void main(String[] args) throws Exception { + if (args.length > 0) { + System.out.println("Calling System.gc()"); + System.gc(); + return; + } + + String[] concurrent = new String[] { + "Pause Init Mark", + "Pause Final Mark", + "Pause Init Update Refs", + "Pause Final Update Refs", + "Pause Init Traversal", + "Pause Final Traversal", + }; + + String[] opts = new String[] { + "", + "-XX:-ExplicitGCInvokesConcurrent", + "-XX:+ExplicitGCInvokesConcurrent" + }; + + for (String opt : opts) { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xlog:gc", + "-XX:+UnlockDiagnosticVMOptions", + opt, + "-XX:ShenandoahGCHeuristics=passive", + TestExplicitGCNoConcurrent.class.getName(), + "test"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + for (String p : concurrent) { + output.shouldNotContain(p); + } + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestHeuristicsUnlock.java 2018-11-30 21:07:20.890814378 +0100 @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestHeuristicsUnlock + * @summary Test that Shenandoah heuristics are unlocked properly + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @run driver TestHeuristicsUnlock + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestHeuristicsUnlock { + + enum Mode { + PRODUCT, + DIAGNOSTIC, + EXPERIMENTAL, + } + + public static void main(String[] args) throws Exception { + testWith("adaptive", Mode.PRODUCT); + testWith("static", Mode.PRODUCT); + testWith("compact", Mode.PRODUCT); + + testWith("traversal", Mode.EXPERIMENTAL); + + testWith("aggressive", Mode.DIAGNOSTIC); + testWith("passive", Mode.DIAGNOSTIC); + } + + private static void testWith(String h, Mode mode) throws Exception { + if (false) { // When ShenandoahGC is experimental flag, this makes no sense to test + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:-UnlockDiagnosticVMOptions", + "-XX:-UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-version" + ); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + switch (mode) { + case PRODUCT: + output.shouldHaveExitValue(0); + break; + case DIAGNOSTIC: + case EXPERIMENTAL: + output.shouldNotHaveExitValue(0); + break; + } + } + + if (false) { // When ShenandoahGC is experimental flag, this makes no sense to test + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:-UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-version" + ); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + switch (mode) { + case PRODUCT: + case DIAGNOSTIC: + output.shouldHaveExitValue(0); + break; + case EXPERIMENTAL: + output.shouldNotHaveExitValue(0); + break; + } + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:-UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-version" + ); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + switch (mode) { + case PRODUCT: + case EXPERIMENTAL: + output.shouldHaveExitValue(0); + break; + case DIAGNOSTIC: + output.shouldNotHaveExitValue(0); + break; + } + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestHumongousThresholdArgs.java 2018-11-30 21:07:21.132812141 +0100 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestHumongousThresholdArgs + * @summary Test that Shenandoah humongous threshold args are checked + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @run driver TestHumongousThresholdArgs + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestHumongousThresholdArgs { + public static void main(String[] args) throws Exception { + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + int[] valid = new int[] {1, 10, 50, 90, 100}; + int[] invalid = new int[] {-100, -1, 0, 101, 1000}; + + for (int v : valid) { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahHumongousThreshold=" + v, + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + for (int v : invalid) { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahHumongousThreshold=" + v, + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(1); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestLoopMiningArguments.java 2018-11-30 21:07:21.379809857 +0100 @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestLoopMiningArguments + * @summary Test that loop mining arguments are sane + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run driver TestLoopMiningArguments + */ + +import java.util.*; + +import jdk.test.lib.Asserts; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestLoopMiningArguments { + + public static void testWith(String msg, boolean cls, int iters, String... args) throws Exception { + String[] cmds = Arrays.copyOf(args, args.length + 2); + cmds[args.length] = "-XX:+PrintFlagsFinal"; + cmds[args.length + 1] = "-version"; + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + output.shouldContain("UseCountedLoopSafepoints"); + output.shouldContain("LoopStripMiningIter"); + + Asserts.assertEQ(output.firstMatch("(.+?) UseCountedLoopSafepoints.+?= (.+?) (.+?)", 2), Boolean.toString(cls), msg + ", but got wrong CLS"); + Asserts.assertEQ(output.firstMatch("(.+?) LoopStripMiningIter.+?= (.+?) (.+?)", 2), String.valueOf(iters), msg + ", but got wrong LSM"); + } + + public static void main(String[] args) throws Exception { + testDefaultGC(); + testShenandoah(); + } + + public static void testDefaultGC() throws Exception { + testWith("Default GC should have CLS enabled, LSM = 1000", + true, 1000); + + testWith("Default GC with +CLS should set LSM = 1", + true, 1, + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Default GC with +CLS should not override LSM>1", + true, 10, + "-XX:LoopStripMiningIter=10", + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Default GC with +CLS should not override LSM=1", + true, 1, + "-XX:LoopStripMiningIter=1", + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Default GC with +CLS should override LSM=0 to 1", + true, 1, + "-XX:LoopStripMiningIter=0", + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Default GC with -CLS should set LSM = 0", + false, 0, + "-XX:-UseCountedLoopSafepoints" + ); + + testWith("Default GC with -CLS should override LSM to 0", + false, 0, + "-XX:LoopStripMiningIter=10", + "-XX:-UseCountedLoopSafepoints" + ); + } + + public static void testShenandoah() throws Exception { + testWith("Shenandoah should have CLS and LSM enabled", + true, 1000, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC" + ); + + testWith("Shenandoah with +CLS should set LSM = 1", + true, 1, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Shenandoah GC with +CLS should not override LSM>1", + true, 10, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:LoopStripMiningIter=10", + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Shenandoah GC with +CLS should not override LSM=1", + true, 1, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:LoopStripMiningIter=1", + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Shenandoah GC with +CLS should override LSM=0 to 1", + true, 1, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:LoopStripMiningIter=0", + "-XX:+UseCountedLoopSafepoints" + ); + + testWith("Shenandoah GC with -CLS should set LSM = 0", + false, 0, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:-UseCountedLoopSafepoints" + ); + + testWith("Shenandoah GC with -CLS should override LSM to 0", + false, 0, + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:LoopStripMiningIter=10", + "-XX:-UseCountedLoopSafepoints" + ); + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestObjectAlignment.java 2018-11-30 21:07:21.618807648 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestObjectAlignment + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 TestObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xmx16m TestObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xmx32m TestObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xmx64m TestObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xmx128m TestObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xmx256m TestObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xmx512m TestObjectAlignment + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ObjectAlignmentInBytes=16 -Xmx1g TestObjectAlignment + */ + +public class TestObjectAlignment { + + public static void main(String[] args) throws Exception { + // Testing the checking code on startup + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestPacing.java 2018-11-30 21:07:21.858805429 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestPacing + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:-ShenandoahPacing -Xmx128m TestPacing + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ShenandoahPacing -Xmx128m TestPacing + */ + +public class TestPacing { + static final long TARGET_MB = Long.getLong("target", 1000); // 1 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 16; + for (long c = 0; c < count; c++) { + sink = new Object(); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestParallelRegionStride.java 2018-11-30 21:07:22.099803200 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestParallelRegionStride + * @key gc + * @requires vm.gc.Shenandoah + * + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahParallelRegionStride=1 -Xmx128m TestParallelRegionStride + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahParallelRegionStride=10 -Xmx128m TestParallelRegionStride + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahParallelRegionStride=100 -Xmx128m TestParallelRegionStride + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahParallelRegionStride=1024 -Xmx128m TestParallelRegionStride + */ + +public class TestParallelRegionStride { + static final long TARGET_MB = Long.getLong("target", 1000); // 1 Gb allocation + + static volatile Object sink; + + public static void main(String[] args) throws Exception { + long count = TARGET_MB * 1024 * 1024 / 16; + for (long c = 0; c < count; c++) { + sink = new Object(); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestRegionSizeArgs.java 2018-11-30 21:07:22.338800990 +0100 @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestRegionSizeArgs + * @summary Test that Shenandoah region size args are checked + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @run driver TestRegionSizeArgs + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestRegionSizeArgs { + public static void main(String[] args) throws Exception { + testInvalidRegionSizes(); + testMinRegionSize(); + testMaxRegionSize(); + } + + private static void testInvalidRegionSizes() throws Exception { + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms2m", + "-Xmx1g", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Initial heap size"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms4m", + "-Xmx1g", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms8m", + "-Xmx1g", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=200m", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahHeapRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=11m", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahHeapRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=9m", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=255K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahHeapRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=260K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms1g", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=32M", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms1g", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=64M", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahHeapRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms1g", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=256K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms1g", + "-Xmx1g", + "-XX:ShenandoahHeapRegionSize=128K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahHeapRegionSize option"); + output.shouldHaveExitValue(1); + } + } + + private static void testMinRegionSize() throws Exception { + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahMinRegionSize=255K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahMinRegionSize=1M", + "-XX:ShenandoahMaxRegionSize=260K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize or -XX:ShenandoahMaxRegionSize"); + output.shouldHaveExitValue(1); + } + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahMinRegionSize=200m", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahMinRegionSize=11m", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahMinRegionSize=9m", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + + } + + private static void testMaxRegionSize() throws Exception { + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahMaxRegionSize=255K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahMaxRegionSize option"); + output.shouldHaveExitValue(1); + } + + { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-Xms100m", + "-Xmx1g", + "-XX:ShenandoahMinRegionSize=1M", + "-XX:ShenandoahMaxRegionSize=260K", + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize or -XX:ShenandoahMaxRegionSize"); + output.shouldHaveExitValue(1); + } + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestSelectiveBarrierFlags.java 2018-11-30 21:07:22.576798790 +0100 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestSelectiveBarrierFlags + * @summary Test selective barrier enabling works, by aggressively compiling HelloWorld with combinations + * of barrier flags + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run main/othervm TestSelectiveBarrierFlags -Xint + * @run main/othervm TestSelectiveBarrierFlags -Xbatch -XX:CompileThreshold=100 -XX:TieredStopAtLevel=1 + * @run main/othervm TestSelectiveBarrierFlags -Xbatch -XX:CompileThreshold=100 -XX:-TieredCompilation -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers + */ + +import java.util.*; +import java.util.concurrent.*; + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestSelectiveBarrierFlags { + + public static void main(String[] args) throws Exception { + String[][] opts = { + new String[] { "ShenandoahKeepAliveBarrier" }, + new String[] { "ShenandoahWriteBarrier" }, + new String[] { "ShenandoahReadBarrier" }, + // StoreValRead+SATB are actually compatible, but we need to protect against + // StorveValEnqueue+SATB. TODO: Make it better. + new String[] { "ShenandoahSATBBarrier", "ShenandoahStoreValReadBarrier", "ShenandoahStoreValEnqueueBarrier" }, + new String[] { "ShenandoahCASBarrier" }, + new String[] { "ShenandoahAcmpBarrier" }, + new String[] { "ShenandoahCloneBarrier" }, + }; + + int size = 1; + for (String[] l : opts) { + size *= (l.length + 1); + } + + ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + + for (int c = 0; c < size; c++) { + int t = c; + + List conf = new ArrayList<>(); + conf.addAll(Arrays.asList(args)); + conf.add("-Xmx128m"); + conf.add("-XX:+UnlockDiagnosticVMOptions"); + conf.add("-XX:+UnlockExperimentalVMOptions"); + conf.add("-XX:+UseShenandoahGC"); + conf.add("-XX:ShenandoahGCHeuristics=passive"); + + StringBuilder sb = new StringBuilder(); + for (String[] l : opts) { + // Make a choice which flag to select from the group. + // Zero means no flag is selected from the group. + int choice = t % (l.length + 1); + for (int e = 0; e < l.length; e++) { + conf.add("-XX:" + ((choice == (e + 1)) ? "+" : "-") + l[e]); + } + t = t / (l.length + 1); + } + + conf.add("TestSelectiveBarrierFlags$Test"); + + pool.submit(() -> { + try { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(conf.toArray(new String[0])); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + }); + } + + pool.shutdown(); + pool.awaitTermination(1, TimeUnit.HOURS); + } + + public static class Test { + public static void main(String... args) { + System.out.println("HelloWorld"); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestSingleThreaded.java 2018-11-30 21:07:22.819796544 +0100 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestSingleThreaded + * @summary test single worker threaded Shenandoah + * @key gc + * @requires vm.gc.Shenandoah + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive + * -XX:ParallelGCThreads=1 -XX:ConcGCThreads=1 TestSingleThreaded + */ + +public class TestSingleThreaded { + + public static void main(String[] args) { + // Bug should crash before we get here. + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/shenandoah/options/TestWrongBarrierDisable.java 2018-11-30 21:07:23.057794344 +0100 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* @test TestWrongBarrierDisable + * @summary Test that disabling wrong barriers fails early + * @key gc + * @requires vm.gc.Shenandoah + * @library /test/lib + * @run main/othervm TestWrongBarrierDisable + */ + +import java.util.*; + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestWrongBarrierDisable { + + public static void main(String[] args) throws Exception { + String[] concurrent = { + "ShenandoahReadBarrier", + "ShenandoahWriteBarrier", + "ShenandoahCASBarrier", + "ShenandoahAcmpBarrier", + "ShenandoahCloneBarrier", + "ShenandoahSATBBarrier", + "ShenandoahKeepAliveBarrier", + "ShenandoahStoreValReadBarrier", + }; + + String[] traversal = { + "ShenandoahReadBarrier", + "ShenandoahWriteBarrier", + "ShenandoahCASBarrier", + "ShenandoahAcmpBarrier", + "ShenandoahCloneBarrier", + }; + + shouldFailAll("adaptive", concurrent); + shouldFailAll("static", concurrent); + shouldFailAll("compact", concurrent); + shouldFailAll("aggressive", concurrent); + shouldFailAll("traversal", traversal); + shouldPassAll("passive", concurrent); + shouldPassAll("passive", traversal); + } + + private static void shouldFailAll(String h, String[] barriers) throws Exception { + for (String b : barriers) { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-XX:-" + b, + "-version" + ); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldNotHaveExitValue(0); + output.shouldContain("Heuristics needs "); + output.shouldContain("to work correctly"); + } + } + + private static void shouldPassAll(String h, String[] barriers) throws Exception { + for (String b : barriers) { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseShenandoahGC", + "-XX:ShenandoahGCHeuristics=" + h, + "-XX:-" + b, + "-version" + ); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + } + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/startup_warnings/TestShenandoah.java 2018-11-30 21:07:23.295792142 +0100 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* +* @test TestShenandoah +* @key gc +* @requires vm.gc.Shenandoah +* @bug 8006398 +* @summary Test that the Shenandoah collector does not print a warning message +* @library /test/lib +* @modules java.base/jdk.internal.misc +* java.management +*/ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestShenandoah { + + public static void main(String args[]) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", "-XX:+UseShenandoahGC", "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldNotContain("deprecated"); + output.shouldNotContain("error"); + output.shouldHaveExitValue(0); + } + +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/stress/gcbasher/TestGCBasherWithShenandoah.java 2018-11-30 21:07:23.535789923 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +import java.io.IOException; + +/* + * @test TestGCBasherWithShenandoah + * @key gc + * @key stress + * @requires vm.gc.Shenandoah + * @requires vm.flavor == "server" & !vm.emulatedClient & !vm.graal.enabled + * @summary Stress the Shenandoah GC by trying to make old objects more likely to be garbage than young objects. + * + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahVerify -XX:+ShenandoahDegeneratedGC TestGCBasherWithShenandoah 120000 + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahVerify -XX:-ShenandoahDegeneratedGC TestGCBasherWithShenandoah 120000 + * + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestGCBasherWithShenandoah 120000 + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestGCBasherWithShenandoah 120000 + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestGCBasherWithShenandoah 120000 + * + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestGCBasherWithShenandoah 120000 + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestGCBasherWithShenandoah 120000 + * + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive TestGCBasherWithShenandoah 120000 + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal TestGCBasherWithShenandoah 120000 + * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact TestGCBasherWithShenandoah 120000 + */ +public class TestGCBasherWithShenandoah { + public static void main(String[] args) throws IOException { + TestGCBasher.main(args); + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/stress/gclocker/TestGCLockerWithShenandoah.java 2018-11-30 21:07:23.780787658 +0100 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestGCLockerWithShenandoah + * @key gc + * @requires vm.gc.Shenandoah + * @summary Stress Shenandoah's JNI handling by calling GetPrimitiveArrayCritical while concurrently filling up old gen. + * @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xms1500m -Xmx1500m -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+ShenandoahVerify -XX:+UseShenandoahGC TestGCLockerWithShenandoah + * @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xms1500m -Xmx1500m -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC TestGCLockerWithShenandoah + * @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xms1500m -Xmx1500m -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+UseShenandoahGC -XX:+ShenandoahOOMDuringEvacALot -XX:ShenandoahGCHeuristics=aggressive TestGCLockerWithShenandoah + * @run main/native/othervm/timeout=200 -Xlog:gc*=info -Xms1500m -Xmx1500m -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+UseShenandoahGC -XX:+ShenandoahAllocFailureALot -XX:ShenandoahGCHeuristics=aggressive TestGCLockerWithShenandoah + */ +public class TestGCLockerWithShenandoah { + public static void main(String[] args) { + String[] testArgs = {"2", "Shenandoah heap"}; + TestGCLocker.main(testArgs); + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/stress/gcold/TestGCOldWithShenandoah.java 2018-11-30 21:07:24.024785402 +0100 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 only, as +* published by the Free Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* version 2 for more details (a copy is included in the LICENSE file that +* accompanied this code). +* +* You should have received a copy of the GNU General Public License version +* 2 along with this work; if not, write to the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +* +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +* or visit www.oracle.com if you need additional information or have any +* questions. +*/ + +/* + * @test TestGCOldWithShenandoah + * @key gc + * @key stress + * @requires vm.gc.Shenandoah & !vm.graal.enabled + * @summary Stress the GC by trying to make old objects more likely to be garbage than young objects. + * + * @run main/othervm/timeout=600 -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestGCOld 50 1 20 10 10000 + * @run main/othervm/timeout=600 -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify TestGCOld 50 1 20 10 10000 + * @run main/othervm/timeout=600 -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC TestGCOld 50 1 20 10 10000 + * @run main/othervm/timeout=600 -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC TestGCOld 50 1 20 10 10000 + * + * @run main/othervm -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot TestGCOld 50 1 20 10 10000 + * @run main/othervm -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot TestGCOld 50 1 20 10 10000 + * @run main/othervm -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestGCOld 50 1 20 10 10000 + * + * @run main/othervm/timeout=600 -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify TestGCOld 50 1 20 10 10000 + * @run main/othervm/timeout=600 -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal -XX:+ShenandoahVerify TestGCOld 50 1 20 10 10000 + * + * @run main/othervm -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive TestGCOld 50 1 20 10 10000 + * @run main/othervm -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static TestGCOld 50 1 20 10 10000 + * @run main/othervm -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact TestGCOld 50 1 20 10 10000 + * @run main/othervm -Xmx384M -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal TestGCOld 50 1 20 10 10000 + */ + +public class TestGCOldWithShenandoah { + + public static void main(String[] args) { + TestGCOld.main(args); + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/test/hotspot/jtreg/gc/stress/systemgc/TestSystemGCWithShenandoah.java 2018-11-30 21:07:24.261783210 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test TestSystemGCWithShenandoah + * @key gc + * @key stress + * @requires vm.gc.Shenandoah + * @summary Stress the Shenandoah GC full GC by allocating objects of different lifetimes concurrently with System.gc(). + * @run main/othervm/timeout=300 -Xlog:gc*=info -Xmx512m -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+ShenandoahVerify -XX:+UseShenandoahGC TestSystemGCWithShenandoah 270 + * @run main/othervm/timeout=300 -Xlog:gc*=info -Xmx512m -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+ShenandoahVerify -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=traversal TestSystemGCWithShenandoah 270 + * @run main/othervm/timeout=300 -Xlog:gc*=info -Xmx512m -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC TestSystemGCWithShenandoah 270 + */ +public class TestSystemGCWithShenandoah { + public static void main(String[] args) throws Exception { + TestSystemGC.main(args); + } +}