test/hotspot/jtreg/runtime/appcds/TestCommon.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff test/hotspot/jtreg/runtime/appcds

test/hotspot/jtreg/runtime/appcds/TestCommon.java

Print this page




  93     }
  94 
  95 
  96     // Create AppCDS archive using most common args - convenience method
  97     // Legacy name preserved for compatibility
  98     public static OutputAnalyzer dump(String appJar, String appClasses[],
  99                                                String... suffix) throws Exception {
 100         return createArchive(appJar, appClasses, suffix);
 101     }
 102 
 103 
 104     // Create AppCDS archive using most common args - convenience method
 105     public static OutputAnalyzer createArchive(String appJar, String appClasses[],
 106                                                String... suffix) throws Exception {
 107         AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar)
 108             .setAppClasses(appClasses);
 109         opts.addSuffix(suffix);
 110         return createArchive(opts);
 111     }
 112 
 113     public static String[] makeCommandLineForAppCDS(String... args) throws Exception {
 114         return args;
 115     }
 116 
 117     // Create AppCDS archive using appcds options
 118     public static OutputAnalyzer createArchive(AppCDSOptions opts)
 119         throws Exception {
 120 
 121         ArrayList<String> cmd = new ArrayList<String>();
 122         File classList = makeClassList(opts.appClasses);
 123         startNewArchiveName();
 124 
 125         for (String p : opts.prefix) cmd.add(p);
 126 
 127         if (opts.appJar != null) {
 128             cmd.add("-cp");
 129             cmd.add(opts.appJar);
 130         } else {
 131             cmd.add("-cp");
 132             cmd.add("\"\"");
 133         }
 134 
 135         cmd.add("-Xshare:dump");
 136         cmd.add("-XX:ExtraSharedClassListFile=" + classList.getPath());
 137 
 138         if (opts.archiveName == null)
 139             opts.archiveName = getCurrentArchiveName();
 140 
 141         cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
 142 
 143         for (String s : opts.suffix) cmd.add(s);
 144 
 145         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 146         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, makeCommandLineForAppCDS(cmdLine));
 147         return executeAndLog(pb, "dump");
 148     }
 149 
 150 
 151     // Execute JVM using AppCDS archive with specified AppCDSOptions
 152     public static OutputAnalyzer runWithArchive(AppCDSOptions opts)
 153         throws Exception {
 154 
 155         ArrayList<String> cmd = new ArrayList<String>();
 156 
 157         for (String p : opts.prefix) cmd.add(p);
 158 
 159         cmd.add("-Xshare:" + opts.xShareMode);
 160         cmd.add("-showversion");
 161         cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName());
 162         cmd.add("-Dtest.timeout.factor=" + timeoutFactor);
 163 
 164         if (opts.appJar != null) {
 165             cmd.add("-cp");
 166             cmd.add(opts.appJar);
 167         }
 168 
 169         for (String s : opts.suffix) cmd.add(s);
 170 
 171         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 172         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, makeCommandLineForAppCDS(cmdLine));
 173         return executeAndLog(pb, "exec");
 174     }
 175 
 176 
 177     public static OutputAnalyzer execCommon(String... suffix) throws Exception {
 178         AppCDSOptions opts = (new AppCDSOptions());
 179         opts.addSuffix(suffix);
 180         return runWithArchive(opts);
 181     }
 182 
 183     // This is the new API for running a Java process with CDS enabled.
 184     // See comments in the CDSTestUtils.Result class for how to use this method.
 185     public static Result run(String... suffix) throws Exception {
 186         AppCDSOptions opts = (new AppCDSOptions());
 187         opts.addSuffix(suffix);
 188         return new Result(opts, runWithArchive(opts));
 189     }
 190 
 191     public static OutputAnalyzer exec(String appJar, String... suffix) throws Exception {
 192         AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar);




  93     }
  94 
  95 
  96     // Create AppCDS archive using most common args - convenience method
  97     // Legacy name preserved for compatibility
  98     public static OutputAnalyzer dump(String appJar, String appClasses[],
  99                                                String... suffix) throws Exception {
 100         return createArchive(appJar, appClasses, suffix);
 101     }
 102 
 103 
 104     // Create AppCDS archive using most common args - convenience method
 105     public static OutputAnalyzer createArchive(String appJar, String appClasses[],
 106                                                String... suffix) throws Exception {
 107         AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar)
 108             .setAppClasses(appClasses);
 109         opts.addSuffix(suffix);
 110         return createArchive(opts);
 111     }
 112 




 113     // Create AppCDS archive using appcds options
 114     public static OutputAnalyzer createArchive(AppCDSOptions opts)
 115         throws Exception {
 116 
 117         ArrayList<String> cmd = new ArrayList<String>();
 118         File classList = makeClassList(opts.appClasses);
 119         startNewArchiveName();
 120 
 121         for (String p : opts.prefix) cmd.add(p);
 122 
 123         if (opts.appJar != null) {
 124             cmd.add("-cp");
 125             cmd.add(opts.appJar);
 126         } else {
 127             cmd.add("-cp");
 128             cmd.add("\"\"");
 129         }
 130 
 131         cmd.add("-Xshare:dump");
 132         cmd.add("-XX:ExtraSharedClassListFile=" + classList.getPath());
 133 
 134         if (opts.archiveName == null)
 135             opts.archiveName = getCurrentArchiveName();
 136 
 137         cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
 138 
 139         for (String s : opts.suffix) cmd.add(s);
 140 
 141         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 142         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
 143         return executeAndLog(pb, "dump");
 144     }
 145 
 146 
 147     // Execute JVM using AppCDS archive with specified AppCDSOptions
 148     public static OutputAnalyzer runWithArchive(AppCDSOptions opts)
 149         throws Exception {
 150 
 151         ArrayList<String> cmd = new ArrayList<String>();
 152 
 153         for (String p : opts.prefix) cmd.add(p);
 154 
 155         cmd.add("-Xshare:" + opts.xShareMode);
 156         cmd.add("-showversion");
 157         cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName());
 158         cmd.add("-Dtest.timeout.factor=" + timeoutFactor);
 159 
 160         if (opts.appJar != null) {
 161             cmd.add("-cp");
 162             cmd.add(opts.appJar);
 163         }
 164 
 165         for (String s : opts.suffix) cmd.add(s);
 166 
 167         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 168         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
 169         return executeAndLog(pb, "exec");
 170     }
 171 
 172 
 173     public static OutputAnalyzer execCommon(String... suffix) throws Exception {
 174         AppCDSOptions opts = (new AppCDSOptions());
 175         opts.addSuffix(suffix);
 176         return runWithArchive(opts);
 177     }
 178 
 179     // This is the new API for running a Java process with CDS enabled.
 180     // See comments in the CDSTestUtils.Result class for how to use this method.
 181     public static Result run(String... suffix) throws Exception {
 182         AppCDSOptions opts = (new AppCDSOptions());
 183         opts.addSuffix(suffix);
 184         return new Result(opts, runWithArchive(opts));
 185     }
 186 
 187     public static OutputAnalyzer exec(String appJar, String... suffix) throws Exception {
 188         AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar);


test/hotspot/jtreg/runtime/appcds/TestCommon.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File