< prev index next >

test/hotspot/jtreg/runtime/cds/SpaceUtilizationCheck.java

Print this page


  27  * @requires vm.cds
  28  * @library /test/lib
  29  * @build sun.hotspot.WhiteBox
  30  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  31  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  32  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SpaceUtilizationCheck
  33  */
  34 
  35 import jdk.test.lib.cds.CDSTestUtils;
  36 import jdk.test.lib.cds.CDSOptions;
  37 import jdk.test.lib.process.OutputAnalyzer;
  38 import sun.hotspot.WhiteBox;
  39 
  40 import java.util.regex.Pattern;
  41 import java.util.regex.Matcher;
  42 import java.util.ArrayList;
  43 import java.util.Hashtable;
  44 import java.lang.Integer;
  45 
  46 public class SpaceUtilizationCheck {

  47     // [1] Each region must have strictly less than
  48     //     WhiteBox.metaspaceReserveAlignment() bytes of unused space.
  49     // [2] There must be no gap between two consecutive regions.
  50 
  51     public static void main(String[] args) throws Exception {
  52         // (1) Default VM arguments
  53         test("-Xlog:cds=debug");
  54 
  55         // (2) Use the now deprecated VM arguments. They should have no effect.
  56         test("-Xlog:cds=debug",
  57              "-XX:SharedReadWriteSize=128M",
  58              "-XX:SharedReadOnlySize=128M",
  59              "-XX:SharedMiscDataSize=128M",
  60              "-XX:SharedMiscCodeSize=128M");
  61     }
  62 
  63     static void test(String... extra_options) throws Exception {
  64         CDSOptions opts = new CDSOptions();
  65         opts.addSuffix(extra_options);
  66         OutputAnalyzer output = CDSTestUtils.createArchive(opts);
  67         CDSTestUtils.checkDump(output);
  68         Pattern pattern = Pattern.compile("(..) *space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
  69         WhiteBox wb = WhiteBox.getWhiteBox();
  70         long reserve_alignment = wb.metaspaceReserveAlignment();
  71         System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment);
  72 










  73         long last_region = -1;
  74         Hashtable<String,String> checked = new Hashtable<>();
  75         for (String line : output.getStdout().split("\n")) {
  76             if (line.contains(" space:") && !line.contains("st space:")) {
  77                 Matcher matcher = pattern.matcher(line);
  78                 if (matcher.find()) {
  79                     String name = matcher.group(1);
  80                     if (name.equals("bm")) {
  81                       // Bitmap space does not have a requested address.
  82                       break;
  83                     } else {
  84                       System.out.println("Checking " + name + " in : " + line);
  85                       checked.put(name, name);
  86                     }
  87                     long used = Long.parseLong(matcher.group(2));
  88                     long capacity = Long.parseLong(matcher.group(3));
  89                     long address = Long.parseLong(matcher.group(4), 16);
  90                     long unused = capacity - used;
  91                     if (unused < 0) {
  92                         throw new RuntimeException("Unused space (" + unused + ") less than 0");
  93                     }
  94                     if (unused > reserve_alignment) {
  95                         // [1] Check for unused space
  96                         throw new RuntimeException("Unused space (" + unused + ") must be smaller than Metaspace::reserve_alignment() (" +
  97                                                    reserve_alignment + ")");
  98                     }
  99                     if (last_region >= 0 && address != last_region) {
 100                         // [2] Check for no-gap
 101                         throw new RuntimeException("Region 0x" + address + " should have started at 0x" + Long.toString(last_region, 16));
 102                     }
 103                     last_region = address + capacity;
 104                 }
 105             }
 106         }


  27  * @requires vm.cds
  28  * @library /test/lib
  29  * @build sun.hotspot.WhiteBox
  30  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  31  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  32  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SpaceUtilizationCheck
  33  */
  34 
  35 import jdk.test.lib.cds.CDSTestUtils;
  36 import jdk.test.lib.cds.CDSOptions;
  37 import jdk.test.lib.process.OutputAnalyzer;
  38 import sun.hotspot.WhiteBox;
  39 
  40 import java.util.regex.Pattern;
  41 import java.util.regex.Matcher;
  42 import java.util.ArrayList;
  43 import java.util.Hashtable;
  44 import java.lang.Integer;
  45 
  46 public class SpaceUtilizationCheck {
  47     // For the MC/RW/RO regions:
  48     // [1] Each region must have strictly less than
  49     //     WhiteBox.metaspaceReserveAlignment() bytes of unused space.
  50     // [2] There must be no gap between two consecutive regions.
  51 
  52     public static void main(String[] args) throws Exception {
  53         // (1) Default VM arguments
  54         test("-Xlog:cds=debug");
  55 
  56         // (2) Use the now deprecated VM arguments. They should have no effect.
  57         test("-Xlog:cds=debug",
  58              "-XX:SharedReadWriteSize=128M",
  59              "-XX:SharedReadOnlySize=128M",
  60              "-XX:SharedMiscDataSize=128M",
  61              "-XX:SharedMiscCodeSize=128M");
  62     }
  63 
  64     static void test(String... extra_options) throws Exception {
  65         CDSOptions opts = new CDSOptions();
  66         opts.addSuffix(extra_options);
  67         OutputAnalyzer output = CDSTestUtils.createArchive(opts);
  68         CDSTestUtils.checkDump(output);
  69         Pattern pattern = Pattern.compile("(..)  space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)");
  70         WhiteBox wb = WhiteBox.getWhiteBox();
  71         long reserve_alignment = wb.metaspaceReserveAlignment();
  72         System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment);
  73 
  74         // Look for output like this. The pattern will only match the first 3 regions, which is what we need to check
  75         //
  76         // [4.682s][debug][cds] mc  space:     24912 [  0.2% of total] out of     28672 bytes [ 86.9% used] at 0x0000000800000000
  77         // [4.682s][debug][cds] rw  space:   4391632 [ 33.7% of total] out of   4395008 bytes [ 99.9% used] at 0x0000000800007000
  78         // [4.682s][debug][cds] ro  space:   7570632 [ 58.0% of total] out of   7573504 bytes [100.0% used] at 0x0000000800438000
  79         // [4.682s][debug][cds] bm  space:    213528 [  1.6% of total] out of    213528 bytes [100.0% used]
  80         // [4.682s][debug][cds] ca0 space:    507904 [  3.9% of total] out of    507904 bytes [100.0% used] at 0x00000000fff00000
  81         // [4.682s][debug][cds] oa0 space:    327680 [  2.5% of total] out of    327680 bytes [100.0% used] at 0x00000000ffe00000
  82         // [4.682s][debug][cds] total    :  13036288 [100.0% of total] out of  13049856 bytes [ 99.9% used]
  83 
  84         long last_region = -1;
  85         Hashtable<String,String> checked = new Hashtable<>();
  86         for (String line : output.getStdout().split("\n")) {
  87             if (line.contains(" space:") && !line.contains("st space:")) {
  88                 Matcher matcher = pattern.matcher(line);
  89                 if (matcher.find()) {
  90                     String name = matcher.group(1);




  91                     System.out.println("Checking " + name + " in : " + line);
  92                     checked.put(name, name);

  93                     long used = Long.parseLong(matcher.group(2));
  94                     long capacity = Long.parseLong(matcher.group(3));
  95                     long address = Long.parseLong(matcher.group(4), 16);
  96                     long unused = capacity - used;
  97                     if (unused < 0) {
  98                         throw new RuntimeException("Unused space (" + unused + ") less than 0");
  99                     }
 100                     if (unused > reserve_alignment) {
 101                         // [1] Check for unused space
 102                         throw new RuntimeException("Unused space (" + unused + ") must be smaller than Metaspace::reserve_alignment() (" +
 103                                                    reserve_alignment + ")");
 104                     }
 105                     if (last_region >= 0 && address != last_region) {
 106                         // [2] Check for no-gap
 107                         throw new RuntimeException("Region 0x" + address + " should have started at 0x" + Long.toString(last_region, 16));
 108                     }
 109                     last_region = address + capacity;
 110                 }
 111             }
 112         }
< prev index next >