< prev index next >

test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java

Print this page
rev 8016 : [mq]: unique-cds
   1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  31 import com.oracle.java.testlibrary.*;
  32 
  33 import java.util.regex.Pattern;
  34 import java.util.regex.Matcher;
  35 import java.util.ArrayList;
  36 import java.lang.Integer;
  37 
  38 public class SpaceUtilizationCheck {
  39     // Minimum allowed utilization value (percent)
  40     // The goal is to have this number to be 50% for RO and RW regions
  41     // Once that feature is implemented, increase the MIN_UTILIZATION to 50
  42     private static final int MIN_UTILIZATION = 30;
  43 
  44     // Only RO and RW regions are considered for this check, since they
  45     // currently account for the bulk of the shared space
  46     private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2;
  47 
  48     public static void main(String[] args) throws Exception {
  49         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  50            "-XX:+UnlockDiagnosticVMOptions",
  51            "-XX:SharedArchiveFile=./test.jsa",
  52            "-Xshare:dump");
  53 
  54         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  55         String stdout = output.getStdout();
  56         ArrayList<String> utilization = findUtilization(stdout);
  57 
  58         if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS )
  59             throw new RuntimeException("The output format of sharing summary has changed");
  60 
  61         for(String str : utilization) {
  62             int value = Integer.parseInt(str);
  63             if (value < MIN_UTILIZATION) {
  64                 System.out.println(stdout);
  65                 throw new RuntimeException("Utilization for one of the regions" +
  66                     "is below a threshold of " + MIN_UTILIZATION + "%");
  67             }
  68         }
  69     }
  70 
  71     public static ArrayList<String> findUtilization(String input) {


   1 /*
   2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  31 import com.oracle.java.testlibrary.*;
  32 
  33 import java.util.regex.Pattern;
  34 import java.util.regex.Matcher;
  35 import java.util.ArrayList;
  36 import java.lang.Integer;
  37 
  38 public class SpaceUtilizationCheck {
  39     // Minimum allowed utilization value (percent)
  40     // The goal is to have this number to be 50% for RO and RW regions
  41     // Once that feature is implemented, increase the MIN_UTILIZATION to 50
  42     private static final int MIN_UTILIZATION = 30;
  43 
  44     // Only RO and RW regions are considered for this check, since they
  45     // currently account for the bulk of the shared space
  46     private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2;
  47 
  48     public static void main(String[] args) throws Exception {
  49         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  50            "-XX:+UnlockDiagnosticVMOptions",
  51            "-XX:SharedArchiveFile=./SpaceUtilizationCheck.jsa",
  52            "-Xshare:dump");
  53 
  54         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  55         String stdout = output.getStdout();
  56         ArrayList<String> utilization = findUtilization(stdout);
  57 
  58         if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS )
  59             throw new RuntimeException("The output format of sharing summary has changed");
  60 
  61         for(String str : utilization) {
  62             int value = Integer.parseInt(str);
  63             if (value < MIN_UTILIZATION) {
  64                 System.out.println(stdout);
  65                 throw new RuntimeException("Utilization for one of the regions" +
  66                     "is below a threshold of " + MIN_UTILIZATION + "%");
  67             }
  68         }
  69     }
  70 
  71     public static ArrayList<String> findUtilization(String input) {


< prev index next >