test/hotspot/jtreg/runtime/appcds/TestCommon.java
changeset 48516 7d286141598c
parent 48155 551de50b4ff7
child 48979 514c73a1955b
--- a/test/hotspot/jtreg/runtime/appcds/TestCommon.java	Thu Jan 11 15:38:57 2018 -0800
+++ b/test/hotspot/jtreg/runtime/appcds/TestCommon.java	Thu Jan 11 16:40:10 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
  */
 
 import jdk.test.lib.Utils;
+import jdk.test.lib.BuildHelper;
 import jdk.test.lib.JDKToolFinder;
 import jdk.test.lib.Platform;
 import jdk.test.lib.cds.CDSOptions;
@@ -107,6 +108,19 @@
         return createArchive(opts);
     }
 
+    // If you use -XX:+UseAppCDS or -XX:-UseAppCDS in your JVM command-line, call this method
+    // to wrap the arguments. On commercial builds, -XX:+UnlockCommercialFeatures will be
+    // prepended to the command-line. See JDK-8193664.
+    public static String[] makeCommandLineForAppCDS(String... args) throws Exception {
+        if (BuildHelper.isCommercialBuild()) {
+            String[] newArgs = new String[args.length + 1];
+            newArgs[0] = "-XX:+UnlockCommercialFeatures";
+            System.arraycopy(args, 0, newArgs, 1, args.length);
+            return newArgs;
+        } else {
+            return args;
+        }
+    }
 
     // Create AppCDS archive using appcds options
     public static OutputAnalyzer createArchive(AppCDSOptions opts)
@@ -139,7 +153,7 @@
         for (String s : opts.suffix) cmd.add(s);
 
         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, makeCommandLineForAppCDS(cmdLine));
         return executeAndLog(pb, "dump");
     }
 
@@ -166,7 +180,7 @@
         for (String s : opts.suffix) cmd.add(s);
 
         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
-        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, makeCommandLineForAppCDS(cmdLine));
         return executeAndLog(pb, "exec");
     }