1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test TestConcurrentPhaseControl
  26  * @bug 8169517
  27  * @requires vm.gc.G1
  28  * @summary Test of WhiteBox concurrent GC phase control.
  29  * @key gc
  30  * @modules java.base
  31  * @library /test/lib
  32  * @build sun.hotspot.WhiteBox
  33  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  34  * @run driver TestConcurrentPhaseControlG1
  35  */
  36 
  37 import jdk.test.lib.gc.TestConcurrentPhaseControlSupport;
  38 
  39 public class TestConcurrentPhaseControlG1
  40     extends TestConcurrentPhaseControlSupport
  41 {
  42     // Pairs of phase name and regex to match log string.
  43     private static final String[][] g1Phases = {
  44         // Step through the phases in order.
  45         {"IDLE", null},
  46         {"CONCURRENT_CYCLE", "Concurrent Cycle"},
  47         {"IDLE", null},  // Resume IDLE before testing subphases
  48         {"CLEAR_CLAIMED_MARKS", "Concurrent Clear Claimed Marks"},
  49         {"SCAN_ROOT_REGIONS", "Concurrent Scan Root Regions"},
  50         // ^F so not "From Roots", ^R so not "Restart"
  51         {"CONCURRENT_MARK", "Concurrent Mark [^FR]"},
  52         {"IDLE", null},  // Resume IDLE before testing subphases
  53         {"MARK_FROM_ROOTS", "Concurrent Mark From Roots"},
  54         {"BEFORE_REMARK", null},
  55         {"CREATE_LIVE_DATA", "Concurrent Create Live Data"},
  56         // "COMPLETE_CLEANUP",  -- optional phase, not reached by this test
  57         {"CLEANUP_FOR_NEXT_MARK", "Concurrent Cleanup for Next Mark"},
  58         // Clear request
  59         {"IDLE", null},
  60         {"ANY", null},
  61         // Request a phase.
  62         {"MARK_FROM_ROOTS", "Concurrent Mark From Roots"},
  63         // Request an earlier phase, to ensure loop rather than stuck at idle.
  64         {"SCAN_ROOT_REGIONS", "Concurrent Scan Root Regions"},
  65         // Clear request, to unblock service.
  66         {"IDLE", null},
  67         {"ANY", null},
  68     };
  69 
  70     protected String[][] gcPhases() {
  71         return g1Phases;
  72     }
  73 
  74     protected String[] gcOptions() {
  75         return new String[]{"-XX:+UseG1GC",  "-Xlog:gc,gc+marking"};
  76     }
  77 
  78     protected String executorClassName() {
  79         return G1Test.class.getName();
  80     }
  81 
  82     protected String gcName() {
  83         return "G1";
  84     }
  85 
  86     public static void main(String[] args) throws Exception {
  87         TestConcurrentPhaseControlG1 test = new TestConcurrentPhaseControlG1();
  88         test.run();
  89     }
  90 
  91     static class G1Test extends TestConcurrentPhaseControlSupport.Executor
  92     {
  93         protected String[][] gcPhases() {
  94             return g1Phases;
  95         }
  96 
  97         public static void main(String[] args) throws Exception {
  98             G1Test test = new G1Test();
  99             test.run();
 100         }
 101     }
 102 }