< prev index next >

test/com/sun/management/HotSpotDiagnosticMXBean/CheckOrigin.java

Print this page




  45 import jdk.testlibrary.ProcessTools;
  46 import sun.tools.attach.HotSpotVirtualMachine;
  47 
  48 public class CheckOrigin {
  49 
  50     private static HotSpotDiagnosticMXBean mbean;
  51 
  52     public static void main(String... args) throws Exception {
  53         if (args.length == 0) {
  54             // start a process that has options set in a number of different ways
  55 
  56             File flagsFile = File.createTempFile("CheckOriginFlags", null);
  57             try (PrintWriter pw =
  58                    new PrintWriter(new FileWriter(flagsFile))) {
  59                 pw.println("+PrintSafepointStatistics");
  60             }
  61 
  62             ProcessBuilder pb = ProcessTools.
  63                 createJavaProcessBuilder(
  64                     "-XX:+UseConcMarkSweepGC",  // this will cause UseParNewGC to be FLAG_SET_ERGO
  65                     "-XX:+PrintGCDetails",
  66                     "-XX:+UseCerealGC",         // Should be ignored.
  67                     "-XX:Flags=" + flagsFile.getAbsolutePath(),
  68                     "-cp", System.getProperty("test.class.path"),
  69                     "CheckOrigin",
  70                     "-runtests");
  71 
  72             Map<String, String> env = pb.environment();
  73             // "UseCMSGC" should be ignored.
  74             env.put("_JAVA_OPTIONS", "-XX:+TraceExceptions -XX:+UseCMSGC");
  75             // "UseGOneGC" should be ignored.
  76             env.put("JAVA_TOOL_OPTIONS", "-XX:+IgnoreUnrecognizedVMOptions "
  77                 + "-XX:+PrintVMOptions -XX:+UseGOneGC");
  78 
  79             pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
  80             pb.redirectError(ProcessBuilder.Redirect.INHERIT);
  81             Process p = pb.start();
  82             int exit = p.waitFor();
  83             System.out.println("sub process exit == " + exit);
  84             if (exit != 0) {
  85                 throw new Exception("Unexpected exit code from subprocess == " + exit);
  86             }
  87         } else {
  88             mbean =
  89                 ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
  90 
  91             // set a few more options
  92             mbean.setVMOption("HeapDumpOnOutOfMemoryError", "true");
  93             setOptionUsingAttach("HeapDumpPath", "/a/sample/path");
  94 
  95             // check the origin field for all the options we set
  96 
  97             // Not set, so should be default
  98             checkOrigin("ManagementServer", Origin.DEFAULT);
  99             // Set on the command line
 100             checkOrigin("PrintGCDetails", Origin.VM_CREATION);
 101             // Set in _JAVA_OPTIONS
 102             checkOrigin("TraceExceptions", Origin.ENVIRON_VAR);
 103             // Set in JAVA_TOOL_OPTIONS
 104             checkOrigin("IgnoreUnrecognizedVMOptions", Origin.ENVIRON_VAR);
 105             checkOrigin("PrintVMOptions", Origin.ENVIRON_VAR);
 106             // Set in -XX:Flags file
 107             checkOrigin("PrintSafepointStatistics", Origin.CONFIG_FILE);
 108             // Set through j.l.m
 109             checkOrigin("HeapDumpOnOutOfMemoryError", Origin.MANAGEMENT);
 110             // Should be set by the VM, when we set UseConcMarkSweepGC
 111             checkOrigin("UseParNewGC", Origin.ERGONOMIC);
 112             // Set using attach
 113             checkOrigin("HeapDumpPath", Origin.ATTACH_ON_DEMAND);
 114         }
 115     }
 116 
 117     private static void checkOrigin(String option, Origin origin) throws Exception
 118     {
 119         Origin o = mbean.getVMOption(option).getOrigin();
 120         if (!o.equals(origin)) {




  45 import jdk.testlibrary.ProcessTools;
  46 import sun.tools.attach.HotSpotVirtualMachine;
  47 
  48 public class CheckOrigin {
  49 
  50     private static HotSpotDiagnosticMXBean mbean;
  51 
  52     public static void main(String... args) throws Exception {
  53         if (args.length == 0) {
  54             // start a process that has options set in a number of different ways
  55 
  56             File flagsFile = File.createTempFile("CheckOriginFlags", null);
  57             try (PrintWriter pw =
  58                    new PrintWriter(new FileWriter(flagsFile))) {
  59                 pw.println("+PrintSafepointStatistics");
  60             }
  61 
  62             ProcessBuilder pb = ProcessTools.
  63                 createJavaProcessBuilder(
  64                     "-XX:+UseConcMarkSweepGC",  // this will cause UseParNewGC to be FLAG_SET_ERGO
  65                     "-XX:+UseCodeAging",
  66                     "-XX:+UseCerealGC",         // Should be ignored.
  67                     "-XX:Flags=" + flagsFile.getAbsolutePath(),
  68                     "-cp", System.getProperty("test.class.path"),
  69                     "CheckOrigin",
  70                     "-runtests");
  71 
  72             Map<String, String> env = pb.environment();
  73             // "UseCMSGC" should be ignored.
  74             env.put("_JAVA_OPTIONS", "-XX:+TraceExceptions -XX:+UseCMSGC");
  75             // "UseGOneGC" should be ignored.
  76             env.put("JAVA_TOOL_OPTIONS", "-XX:+IgnoreUnrecognizedVMOptions "
  77                 + "-XX:+PrintVMOptions -XX:+UseGOneGC");
  78 
  79             pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
  80             pb.redirectError(ProcessBuilder.Redirect.INHERIT);
  81             Process p = pb.start();
  82             int exit = p.waitFor();
  83             System.out.println("sub process exit == " + exit);
  84             if (exit != 0) {
  85                 throw new Exception("Unexpected exit code from subprocess == " + exit);
  86             }
  87         } else {
  88             mbean =
  89                 ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
  90 
  91             // set a few more options
  92             mbean.setVMOption("HeapDumpOnOutOfMemoryError", "true");
  93             setOptionUsingAttach("HeapDumpPath", "/a/sample/path");
  94 
  95             // check the origin field for all the options we set
  96 
  97             // Not set, so should be default
  98             checkOrigin("ManagementServer", Origin.DEFAULT);
  99             // Set on the command line
 100             checkOrigin("UseCodeAging", Origin.VM_CREATION);
 101             // Set in _JAVA_OPTIONS
 102             checkOrigin("TraceExceptions", Origin.ENVIRON_VAR);
 103             // Set in JAVA_TOOL_OPTIONS
 104             checkOrigin("IgnoreUnrecognizedVMOptions", Origin.ENVIRON_VAR);
 105             checkOrigin("PrintVMOptions", Origin.ENVIRON_VAR);
 106             // Set in -XX:Flags file
 107             checkOrigin("PrintSafepointStatistics", Origin.CONFIG_FILE);
 108             // Set through j.l.m
 109             checkOrigin("HeapDumpOnOutOfMemoryError", Origin.MANAGEMENT);
 110             // Should be set by the VM, when we set UseConcMarkSweepGC
 111             checkOrigin("UseParNewGC", Origin.ERGONOMIC);
 112             // Set using attach
 113             checkOrigin("HeapDumpPath", Origin.ATTACH_ON_DEMAND);
 114         }
 115     }
 116 
 117     private static void checkOrigin(String option, Origin origin) throws Exception
 118     {
 119         Origin o = mbean.getVMOption(option).getOrigin();
 120         if (!o.equals(origin)) {


< prev index next >