test/hotspot/jtreg/gc/shenandoah/options/TestSelectiveBarrierFlags.java
author rkennke
Mon, 10 Dec 2018 15:47:44 +0100
changeset 52925 9c18c9d839d3
child 54423 6c0ab8bd8da5
permissions -rw-r--r--
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental) Reviewed-by: kvn, roland, shade, coleenp, lmesnik, pliden, jgeorge, ihse, erikj Contributed-by: Christine Flood <chf@redhat.com>, Aleksey Shipilev <shade@redhat.com>, Roland Westrelin <rwestrel@redhat.com>, Zhenygu Gu <zgu@redhat.com>, Andrew Haley <aph@redhat.com>, Andrew Dinn <adinn@redhat.com>, Mario Torre <mtorre@redhat.com>, Roman Kennke <rkennke@redhat.com>

/*
 * 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<String> 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");
        }
    }

}