2014-06-02 21:36:59 -04:00
|
|
|
/*
|
2018-02-15 11:39:42 -08:00
|
|
|
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
2014-06-02 21:36:59 -04:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
2017-08-03 10:24:34 +02:00
|
|
|
/**
|
2014-06-02 21:36:59 -04:00
|
|
|
* @test SpaceUtilizationCheck
|
|
|
|
* @summary Check if the space utilization for shared spaces is adequate
|
2017-12-04 08:59:47 -08:00
|
|
|
* @requires vm.cds
|
2016-08-19 10:06:30 -04:00
|
|
|
* @library /test/lib
|
2016-04-09 23:03:39 +01:00
|
|
|
* @modules java.base/jdk.internal.misc
|
2015-03-26 16:36:56 +01:00
|
|
|
* java.management
|
2017-08-02 18:06:38 -07:00
|
|
|
* @build sun.hotspot.WhiteBox
|
2018-01-17 21:44:44 -08:00
|
|
|
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
|
2017-08-02 18:06:38 -07:00
|
|
|
* sun.hotspot.WhiteBox$WhiteBoxPermission
|
|
|
|
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SpaceUtilizationCheck
|
2014-06-02 21:36:59 -04:00
|
|
|
*/
|
|
|
|
|
2017-04-18 14:18:43 -07:00
|
|
|
import jdk.test.lib.cds.CDSTestUtils;
|
2016-08-19 10:06:30 -04:00
|
|
|
import jdk.test.lib.process.OutputAnalyzer;
|
2017-08-02 18:06:38 -07:00
|
|
|
import sun.hotspot.WhiteBox;
|
2014-06-02 21:36:59 -04:00
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.ArrayList;
|
2017-08-02 18:06:38 -07:00
|
|
|
import java.util.Hashtable;
|
2014-06-02 21:36:59 -04:00
|
|
|
import java.lang.Integer;
|
|
|
|
|
|
|
|
public class SpaceUtilizationCheck {
|
2017-08-02 18:06:38 -07:00
|
|
|
// [1] Each region must have strictly less than
|
|
|
|
// WhiteBox.metaspaceReserveAlignment() bytes of unused space.
|
|
|
|
// [2] There must be no gap between two consecutive regions.
|
2014-06-02 21:36:59 -04:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2017-08-02 18:06:38 -07:00
|
|
|
// (1) Default VM arguments
|
|
|
|
test();
|
2014-06-02 21:36:59 -04:00
|
|
|
|
2017-08-02 18:06:38 -07:00
|
|
|
// (2) Use the now deprecated VM arguments. They should have no effect.
|
|
|
|
test("-XX:SharedReadWriteSize=128M",
|
|
|
|
"-XX:SharedReadOnlySize=128M",
|
|
|
|
"-XX:SharedMiscDataSize=128M",
|
|
|
|
"-XX:SharedMiscCodeSize=128M");
|
2014-06-02 21:36:59 -04:00
|
|
|
}
|
|
|
|
|
2017-08-02 18:06:38 -07:00
|
|
|
static void test(String... extra_options) throws Exception {
|
|
|
|
OutputAnalyzer output = CDSTestUtils.createArchive(extra_options);
|
|
|
|
CDSTestUtils.checkDump(output);
|
2017-10-02 16:00:42 -07:00
|
|
|
Pattern pattern = Pattern.compile("^(..) *space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
|
2017-08-02 18:06:38 -07:00
|
|
|
WhiteBox wb = WhiteBox.getWhiteBox();
|
|
|
|
long reserve_alignment = wb.metaspaceReserveAlignment();
|
|
|
|
System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment);
|
2014-06-02 21:36:59 -04:00
|
|
|
|
2017-08-02 18:06:38 -07:00
|
|
|
long last_region = -1;
|
|
|
|
Hashtable<String,String> checked = new Hashtable<>();
|
|
|
|
for (String line : output.getStdout().split("\n")) {
|
|
|
|
if (line.contains(" space:") && !line.contains("st space:")) {
|
|
|
|
Matcher matcher = pattern.matcher(line);
|
|
|
|
if (matcher.find()) {
|
|
|
|
String name = matcher.group(1);
|
|
|
|
if (name.equals("s0") || name.equals("s1")) {
|
|
|
|
// String regions are listed at the end and they may not be fully occupied.
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
System.out.println("Checking " + name + " in : " + line);
|
|
|
|
checked.put(name, name);
|
|
|
|
}
|
|
|
|
long used = Long.parseLong(matcher.group(2));
|
|
|
|
long capacity = Long.parseLong(matcher.group(3));
|
|
|
|
long address = Long.parseLong(matcher.group(4), 16);
|
|
|
|
long unused = capacity - used;
|
|
|
|
if (unused < 0) {
|
|
|
|
throw new RuntimeException("Unused space (" + unused + ") less than 0");
|
|
|
|
}
|
|
|
|
if (unused > reserve_alignment) {
|
|
|
|
// [1] Check for unused space
|
|
|
|
throw new RuntimeException("Unused space (" + unused + ") must be smaller than Metaspace::reserve_alignment() (" +
|
|
|
|
reserve_alignment + ")");
|
|
|
|
}
|
|
|
|
if (last_region >= 0 && address != last_region) {
|
|
|
|
// [2] Check for no-gap
|
|
|
|
throw new RuntimeException("Region 0x" + address + " should have started at 0x" + Long.toString(last_region, 16));
|
|
|
|
}
|
|
|
|
last_region = address + capacity;
|
|
|
|
}
|
2014-06-02 21:36:59 -04:00
|
|
|
}
|
|
|
|
}
|
2017-08-02 18:06:38 -07:00
|
|
|
if (checked.size() != 5) {
|
|
|
|
throw new RuntimeException("Must have 5 consecutive, fully utilized regions");
|
2014-06-02 21:36:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|