test/lib/sun/hotspot/gc/GC.java
author stefank
Wed, 10 Apr 2019 15:41:03 +0200
changeset 54510 c97a91097f9f
parent 52925 9c18c9d839d3
child 59053 ba6c248cae19
permissions -rw-r--r--
8221913: Add GC.selected() jtreg-ext function Reviewed-by: kbarrett, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     1
/*
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     4
 *
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     8
 *
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    13
 * accompanied this code).
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    14
 *
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    18
 *
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    21
 * questions.
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    22
 */
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    23
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    24
package sun.hotspot.gc;
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    25
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    26
import sun.hotspot.WhiteBox;
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    27
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    28
/**
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    29
 * API to obtain information about selected and supported Garbage Collectors
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    30
 * retrieved from the VM with the WhiteBox API.
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    31
 */
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    32
public enum GC {
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    33
    /*
51616
b071f4fff1f1 8210259: [testbug] IncompatibleOptions.java fails if VM configured without ZGC
goetz
parents: 50525
diff changeset
    34
     * Enum values must match CollectedHeap::Name
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    35
     */
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    36
    Serial(1),
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    37
    Parallel(2),
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    38
    ConcMarkSweep(3),
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 49630
diff changeset
    39
    G1(4),
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50523
diff changeset
    40
    Epsilon(5),
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 51616
diff changeset
    41
    Z(6),
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 51616
diff changeset
    42
    Shenandoah(7);
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    43
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    44
    private static final WhiteBox WB = WhiteBox.getWhiteBox();
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    45
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    46
    private final int name;
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    47
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    48
    private GC(int name) {
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    49
        this.name = name;
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    50
    }
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    51
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    52
    /**
51616
b071f4fff1f1 8210259: [testbug] IncompatibleOptions.java fails if VM configured without ZGC
goetz
parents: 50525
diff changeset
    53
     * @return true if this GC is supported by the VM, i.e., it is built into the VM.
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    54
     */
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    55
    public boolean isSupported() {
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    56
        return WB.isGCSupported(name);
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    57
    }
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    58
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    59
    /**
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    60
     * @return true if this GC is currently selected/used
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    61
     */
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    62
    public boolean isSelected() {
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    63
        return WB.isGCSelected(name);
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    64
    }
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    65
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    66
    /**
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    67
     * @return true if GC was selected ergonomically, as opposed
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    68
     *         to being explicitly specified on the command line
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    69
     */
49630
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    70
    public static boolean isSelectedErgonomically() {
2f1b308b4469 8199927: Make WhiteBox more GC agnostic
pliden
parents: 41533
diff changeset
    71
        return WB.isGCSelectedErgonomically();
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    72
    }
54510
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    73
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    74
    /**
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    75
     * @return the selected GC.
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    76
     */
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    77
    public static GC selected() {
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    78
      for (GC gc : values()) {
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    79
        if (gc.isSelected()) {
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    80
          return gc;
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    81
        }
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    82
      }
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    83
      throw new IllegalStateException("No selected GC found");
c97a91097f9f 8221913: Add GC.selected() jtreg-ext function
stefank
parents: 52925
diff changeset
    84
    }
38629
0602da3f94c9 8154096: Extend WhiteBox API with methods which retrieve from VM information about available GC
dfazunen
parents:
diff changeset
    85
}