1 /*
2  * Copyright (c) 2019, 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  */
23 
24 package gc.arguments;
25 
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
29 import jdk.test.lib.Platform;
30 import jdk.test.lib.process.ProcessTools;
31 
32 /**
33  * Helper class for adding options to child processes that should be
34  * used by all of the argument tests in this package.  The default
35  * options are added at the front, to allow them to be overridden by
36  * explicit options from any particular test.
37  */
38 
39 public final class GCArguments {
40 
41     // Avoid excessive execution time.
disableZapUnusedHeapArea(List<String> arguments)42     static private void disableZapUnusedHeapArea(List<String> arguments) {
43         // Develop option, only available in debug builds.
44         if (Platform.isDebugBuild()) {
45             arguments.add("-XX:-ZapUnusedHeapArea");
46         }
47     }
48 
49     // Avoid excessive execution time.
disableVerifyBeforeExit(List<String> arguments)50     static private void disableVerifyBeforeExit(List<String> arguments) {
51         // Diagnostic option, default enabled in debug builds.
52         if (Platform.isDebugBuild()) {
53             arguments.add("-XX:-VerifyBeforeExit");
54         }
55     }
56 
addDefaults(List<String> arguments)57     static private void addDefaults(List<String> arguments) {
58         disableZapUnusedHeapArea(arguments);
59         disableVerifyBeforeExit(arguments);
60     }
61 
withDefaults(String[] arguments)62     static private String[] withDefaults(String[] arguments) {
63         List<String> augmented = new ArrayList<String>();
64         addDefaults(augmented);
65         Collections.addAll(augmented, arguments);
66         return augmented.toArray(new String[augmented.size()]);
67     }
68 
createJavaProcessBuilder(String... arguments)69     static public ProcessBuilder createJavaProcessBuilder(String... arguments) {
70         return createJavaProcessBuilder(false, arguments);
71     }
72 
createJavaProcessBuilder(boolean addTestVmAndJavaOptions, String... arguments)73     static public ProcessBuilder createJavaProcessBuilder(boolean addTestVmAndJavaOptions,
74                                                           String... arguments) {
75         return ProcessTools.createJavaProcessBuilder(addTestVmAndJavaOptions,
76                                                      withDefaults(arguments));
77     }
78 
79 }
80