test/hotspot/jtreg/runtime/cds/SpaceUtilizationCheck.java
author iklam
Wed, 13 Nov 2019 16:36:54 -0800
changeset 59070 22ee476cc664
parent 57705 7cf02b2c1455
permissions -rw-r--r--
8231610: Relocate the CDS archive if it cannot be mapped to the requested address Reviewed-by: jiangli, coleenp, ccheung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     1
/*
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 49008
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     4
 *
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     8
 *
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    13
 * accompanied this code).
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    14
 *
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    18
 *
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    21
 * questions.
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    22
 */
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    23
46779
d80ca591ae48 8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents: 46746
diff changeset
    24
/**
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    25
 * @test SpaceUtilizationCheck
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    26
 * @summary Check if the space utilization for shared spaces is adequate
48469
7312ae4465d6 8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents: 47574
diff changeset
    27
 * @requires vm.cds
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    28
 * @library /test/lib
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    29
 * @build sun.hotspot.WhiteBox
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 48469
diff changeset
    30
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    31
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SpaceUtilizationCheck
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    33
 */
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    34
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    35
import jdk.test.lib.cds.CDSTestUtils;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    37
import sun.hotspot.WhiteBox;
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    38
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    39
import java.util.regex.Pattern;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    40
import java.util.regex.Matcher;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    41
import java.util.ArrayList;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    42
import java.util.Hashtable;
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    43
import java.lang.Integer;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    44
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    45
public class SpaceUtilizationCheck {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    46
    // [1] Each region must have strictly less than
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    47
    //     WhiteBox.metaspaceReserveAlignment() bytes of unused space.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    48
    // [2] There must be no gap between two consecutive regions.
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    49
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    50
    public static void main(String[] args) throws Exception {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    51
        // (1) Default VM arguments
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    52
        test();
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    53
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    54
        // (2) Use the now deprecated VM arguments. They should have no effect.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    55
        test("-XX:SharedReadWriteSize=128M",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    56
             "-XX:SharedReadOnlySize=128M",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    57
             "-XX:SharedMiscDataSize=128M",
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    58
             "-XX:SharedMiscCodeSize=128M");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    59
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    60
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    61
    static void test(String... extra_options) throws Exception {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    62
        OutputAnalyzer output = CDSTestUtils.createArchive(extra_options);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    63
        CDSTestUtils.checkDump(output);
47574
15294343ba19 8187979: Clean up info printing at CDS dump time
iklam
parents: 47216
diff changeset
    64
        Pattern pattern = Pattern.compile("^(..) *space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    65
        WhiteBox wb = WhiteBox.getWhiteBox();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    66
        long reserve_alignment = wb.metaspaceReserveAlignment();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    67
        System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment);
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    68
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    69
        long last_region = -1;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    70
        Hashtable<String,String> checked = new Hashtable<>();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    71
        for (String line : output.getStdout().split("\n")) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    72
            if (line.contains(" space:") && !line.contains("st space:")) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    73
                Matcher matcher = pattern.matcher(line);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    74
                if (matcher.find()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    75
                    String name = matcher.group(1);
59070
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents: 57705
diff changeset
    76
                    if (name.equals("bm")) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents: 57705
diff changeset
    77
                      // Bitmap space does not have a requested address.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    78
                      break;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    79
                    } else {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    80
                      System.out.println("Checking " + name + " in : " + line);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    81
                      checked.put(name, name);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    82
                    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    83
                    long used = Long.parseLong(matcher.group(2));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    84
                    long capacity = Long.parseLong(matcher.group(3));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    85
                    long address = Long.parseLong(matcher.group(4), 16);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    86
                    long unused = capacity - used;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    87
                    if (unused < 0) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    88
                        throw new RuntimeException("Unused space (" + unused + ") less than 0");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    89
                    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    90
                    if (unused > reserve_alignment) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    91
                        // [1] Check for unused space
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    92
                        throw new RuntimeException("Unused space (" + unused + ") must be smaller than Metaspace::reserve_alignment() (" +
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    93
                                                   reserve_alignment + ")");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    94
                    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    95
                    if (last_region >= 0 && address != last_region) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    96
                        // [2] Check for no-gap
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    97
                        throw new RuntimeException("Region 0x" + address + " should have started at 0x" + Long.toString(last_region, 16));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    98
                    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
    99
                    last_region = address + capacity;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
   100
                }
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
   101
            }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
   102
        }
53884
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 49008
diff changeset
   103
        if (checked.size() != 4) {
1a7b57d02107 8218751: Do not store original classfiles inside the CDS archive
iklam
parents: 49008
diff changeset
   104
          throw new RuntimeException("Must have 4 consecutive, fully utilized regions");
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46417
diff changeset
   105
        }
24840
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
   106
    }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
   107
}