hotspot/test/gc/concurrent_phase_control/CheckUnsupported.java
changeset 46384 dacebddcdea0
equal deleted inserted replaced
46383:24999171edf9 46384:dacebddcdea0
       
     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 package gc.concurrent_phase_control;
       
    25 
       
    26 /*
       
    27  * Utility class that provides verification of expected behavior of
       
    28  * the Concurrent GC Phase Control WB API when the current GC does not
       
    29  * support phase control.  The invoking test must provide WhiteBox access.
       
    30  */
       
    31 
       
    32 import sun.hotspot.WhiteBox;
       
    33 
       
    34 public class CheckUnsupported {
       
    35 
       
    36     private static final WhiteBox WB = WhiteBox.getWhiteBox();
       
    37 
       
    38     public static void check(String gcName) throws Exception {
       
    39         // Verify unsupported.
       
    40         if (WB.supportsConcurrentGCPhaseControl()) {
       
    41             throw new RuntimeException(
       
    42                 gcName + " unexpectedly supports phase control");
       
    43         }
       
    44 
       
    45         // Verify phase sequence is empty.
       
    46         String[] phases = WB.getConcurrentGCPhases();
       
    47         if (phases.length > 0) {
       
    48             throw new RuntimeException(
       
    49                 gcName + " unexpectedly has non-empty phases");
       
    50         }
       
    51 
       
    52         // Verify IllegalStateException thrown by request attempt.
       
    53         boolean illegalStateThrown = false;
       
    54         try {
       
    55             WB.requestConcurrentGCPhase("UNKNOWN PHASE");
       
    56         } catch (IllegalStateException e) {
       
    57             // Expected.
       
    58             illegalStateThrown = true;
       
    59         } catch (Exception e) {
       
    60             throw new RuntimeException(
       
    61                 gcName + ": Unexpected exception when requesting phase: "
       
    62                 + e.toString());
       
    63         }
       
    64         if (!illegalStateThrown) {
       
    65             throw new RuntimeException(
       
    66                 gcName + ": No exception when requesting phase");
       
    67         }
       
    68     }
       
    69 }
       
    70