hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java
author mseledtsov
Mon, 02 Jun 2014 21:36:59 -0400
changeset 24840 96be34dfc72a
child 29678 dd2f3932c21e
child 30123 7a8b6bd85e24
permissions -rw-r--r--
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address Summary: Added new tests to cover missing CDS basic funtions Reviewed-by: coleenp, ctornqvi
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
/*
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    24
/*
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
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    27
 * @library /testlibrary
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    28
 * @run main SpaceUtilizationCheck
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    29
 */
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    30
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    31
import com.oracle.java.testlibrary.*;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    32
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    33
import java.util.regex.Pattern;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    34
import java.util.regex.Matcher;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    35
import java.util.ArrayList;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    36
import java.lang.Integer;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    37
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    38
public class SpaceUtilizationCheck {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    39
    // Minimum allowed utilization value (percent)
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    40
    // The goal is to have this number to be 50% for RO and RW regions
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    41
    // Once that feature is implemented, increase the MIN_UTILIZATION to 50
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    42
    private static final int MIN_UTILIZATION = 30;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    43
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    44
    // Only RO and RW regions are considered for this check, since they
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    45
    // currently account for the bulk of the shared space
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    46
    private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    47
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    48
    public static void main(String[] args) throws Exception {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    49
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    50
           "-XX:+UnlockDiagnosticVMOptions",
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    51
           "-XX:SharedArchiveFile=./test.jsa",
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    52
           "-Xshare:dump");
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    53
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    54
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    55
        String stdout = output.getStdout();
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    56
        ArrayList<String> utilization = findUtilization(stdout);
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    57
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    58
        if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS )
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    59
            throw new RuntimeException("The output format of sharing summary has changed");
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    60
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    61
        for(String str : utilization) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    62
            int value = Integer.parseInt(str);
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    63
            if (value < MIN_UTILIZATION) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    64
                System.out.println(stdout);
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    65
                throw new RuntimeException("Utilization for one of the regions" +
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    66
                    "is below a threshold of " + MIN_UTILIZATION + "%");
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    67
            }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    68
        }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    69
    }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    70
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    71
    public static ArrayList<String> findUtilization(String input) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    72
        ArrayList<String> regions = filterRegionsOfInterest(input.split("\n"));
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    73
        return filterByPattern(filterByPattern(regions, "bytes \\[.*% used\\]"), "\\d+");
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    74
    }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    75
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    76
    private static ArrayList<String> filterByPattern(Iterable<String> input, String pattern) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    77
        ArrayList<String> result = new ArrayList<String>();
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    78
        for (String str : input) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    79
            Matcher matcher = Pattern.compile(pattern).matcher(str);
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    80
            if (matcher.find()) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    81
                result.add(matcher.group());
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    82
            }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    83
        }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    84
        return result;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    85
    }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    86
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    87
    private static ArrayList<String> filterRegionsOfInterest(String[] inputLines) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    88
        ArrayList<String> result = new ArrayList<String>();
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    89
        for (String str : inputLines) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    90
            if (str.contains("ro space:") || str.contains("rw space:")) {
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    91
                result.add(str);
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    92
            }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    93
        }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    94
        return result;
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    95
    }
96be34dfc72a 8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff changeset
    96
}