PageRenderTime 40ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/java-1.7.0-openjdk/openjdk/hotspot/src/share/vm/runtime/arguments.cpp

#
C++ | 3380 lines | 3053 code | 158 blank | 169 comment | 338 complexity | 1ff331024371cf94ab0164bb2a74ac73 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, LGPL-3.0, LGPL-2.0
  1. /*
  2. * Copyright (c) 1997, 2012, 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. #include "precompiled.hpp"
  25. #include "classfile/javaAssertions.hpp"
  26. #include "compiler/compilerOracle.hpp"
  27. #include "memory/allocation.inline.hpp"
  28. #include "memory/cardTableRS.hpp"
  29. #include "memory/referenceProcessor.hpp"
  30. #include "memory/universe.inline.hpp"
  31. #include "oops/oop.inline.hpp"
  32. #include "prims/jvmtiExport.hpp"
  33. #include "runtime/arguments.hpp"
  34. #include "runtime/globals_extension.hpp"
  35. #include "runtime/java.hpp"
  36. #include "services/management.hpp"
  37. #include "utilities/defaultStream.hpp"
  38. #include "utilities/taskqueue.hpp"
  39. #ifdef TARGET_OS_FAMILY_linux
  40. # include "os_linux.inline.hpp"
  41. #endif
  42. #ifdef TARGET_OS_FAMILY_solaris
  43. # include "os_solaris.inline.hpp"
  44. #endif
  45. #ifdef TARGET_OS_FAMILY_windows
  46. # include "os_windows.inline.hpp"
  47. #endif
  48. #ifdef TARGET_OS_FAMILY_bsd
  49. # include "os_bsd.inline.hpp"
  50. #endif
  51. #ifndef SERIALGC
  52. #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
  53. #endif
  54. #define DEFAULT_VENDOR_URL_BUG "http://icedtea.classpath.org/bugzilla"
  55. #define DEFAULT_JAVA_LAUNCHER "generic"
  56. char** Arguments::_jvm_flags_array = NULL;
  57. int Arguments::_num_jvm_flags = 0;
  58. char** Arguments::_jvm_args_array = NULL;
  59. int Arguments::_num_jvm_args = 0;
  60. char* Arguments::_java_command = NULL;
  61. SystemProperty* Arguments::_system_properties = NULL;
  62. const char* Arguments::_gc_log_filename = NULL;
  63. bool Arguments::_has_profile = false;
  64. bool Arguments::_has_alloc_profile = false;
  65. uintx Arguments::_min_heap_size = 0;
  66. Arguments::Mode Arguments::_mode = _mixed;
  67. bool Arguments::_java_compiler = false;
  68. bool Arguments::_xdebug_mode = false;
  69. const char* Arguments::_java_vendor_url_bug = DEFAULT_VENDOR_URL_BUG;
  70. const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
  71. int Arguments::_sun_java_launcher_pid = -1;
  72. bool Arguments::_created_by_gamma_launcher = false;
  73. // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
  74. bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
  75. bool Arguments::_UseOnStackReplacement = UseOnStackReplacement;
  76. bool Arguments::_BackgroundCompilation = BackgroundCompilation;
  77. bool Arguments::_ClipInlining = ClipInlining;
  78. char* Arguments::SharedArchivePath = NULL;
  79. AgentLibraryList Arguments::_libraryList;
  80. AgentLibraryList Arguments::_agentList;
  81. abort_hook_t Arguments::_abort_hook = NULL;
  82. exit_hook_t Arguments::_exit_hook = NULL;
  83. vfprintf_hook_t Arguments::_vfprintf_hook = NULL;
  84. SystemProperty *Arguments::_java_ext_dirs = NULL;
  85. SystemProperty *Arguments::_java_endorsed_dirs = NULL;
  86. SystemProperty *Arguments::_sun_boot_library_path = NULL;
  87. SystemProperty *Arguments::_java_library_path = NULL;
  88. SystemProperty *Arguments::_java_home = NULL;
  89. SystemProperty *Arguments::_java_class_path = NULL;
  90. SystemProperty *Arguments::_sun_boot_class_path = NULL;
  91. char* Arguments::_meta_index_path = NULL;
  92. char* Arguments::_meta_index_dir = NULL;
  93. // Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
  94. static bool match_option(const JavaVMOption *option, const char* name,
  95. const char** tail) {
  96. int len = (int)strlen(name);
  97. if (strncmp(option->optionString, name, len) == 0) {
  98. *tail = option->optionString + len;
  99. return true;
  100. } else {
  101. return false;
  102. }
  103. }
  104. static void logOption(const char* opt) {
  105. if (PrintVMOptions) {
  106. jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
  107. }
  108. }
  109. // Process java launcher properties.
  110. void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
  111. // See if sun.java.launcher or sun.java.launcher.pid is defined.
  112. // Must do this before setting up other system properties,
  113. // as some of them may depend on launcher type.
  114. for (int index = 0; index < args->nOptions; index++) {
  115. const JavaVMOption* option = args->options + index;
  116. const char* tail;
  117. if (match_option(option, "-Dsun.java.launcher=", &tail)) {
  118. process_java_launcher_argument(tail, option->extraInfo);
  119. continue;
  120. }
  121. if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
  122. _sun_java_launcher_pid = atoi(tail);
  123. continue;
  124. }
  125. }
  126. }
  127. // Initialize system properties key and value.
  128. void Arguments::init_system_properties() {
  129. PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
  130. "Java Virtual Machine Specification", false));
  131. PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false));
  132. PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false));
  133. PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true));
  134. // following are JVMTI agent writeable properties.
  135. // Properties values are set to NULL and they are
  136. // os specific they are initialized in os::init_system_properties_values().
  137. _java_ext_dirs = new SystemProperty("java.ext.dirs", NULL, true);
  138. _java_endorsed_dirs = new SystemProperty("java.endorsed.dirs", NULL, true);
  139. _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL, true);
  140. _java_library_path = new SystemProperty("java.library.path", NULL, true);
  141. _java_home = new SystemProperty("java.home", NULL, true);
  142. _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL, true);
  143. _java_class_path = new SystemProperty("java.class.path", "", true);
  144. // Add to System Property list.
  145. PropertyList_add(&_system_properties, _java_ext_dirs);
  146. PropertyList_add(&_system_properties, _java_endorsed_dirs);
  147. PropertyList_add(&_system_properties, _sun_boot_library_path);
  148. PropertyList_add(&_system_properties, _java_library_path);
  149. PropertyList_add(&_system_properties, _java_home);
  150. PropertyList_add(&_system_properties, _java_class_path);
  151. PropertyList_add(&_system_properties, _sun_boot_class_path);
  152. // Set OS specific system properties values
  153. os::init_system_properties_values();
  154. }
  155. // Update/Initialize System properties after JDK version number is known
  156. void Arguments::init_version_specific_system_properties() {
  157. enum { bufsz = 16 };
  158. char buffer[bufsz];
  159. const char* spec_vendor = "Sun Microsystems Inc.";
  160. uint32_t spec_version = 0;
  161. if (JDK_Version::is_gte_jdk17x_version()) {
  162. spec_vendor = "Oracle Corporation";
  163. spec_version = JDK_Version::current().major_version();
  164. }
  165. jio_snprintf(buffer, bufsz, "1." UINT32_FORMAT, spec_version);
  166. PropertyList_add(&_system_properties,
  167. new SystemProperty("java.vm.specification.vendor", spec_vendor, false));
  168. PropertyList_add(&_system_properties,
  169. new SystemProperty("java.vm.specification.version", buffer, false));
  170. PropertyList_add(&_system_properties,
  171. new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false));
  172. }
  173. /**
  174. * Provide a slightly more user-friendly way of eliminating -XX flags.
  175. * When a flag is eliminated, it can be added to this list in order to
  176. * continue accepting this flag on the command-line, while issuing a warning
  177. * and ignoring the value. Once the JDK version reaches the 'accept_until'
  178. * limit, we flatly refuse to admit the existence of the flag. This allows
  179. * a flag to die correctly over JDK releases using HSX.
  180. */
  181. typedef struct {
  182. const char* name;
  183. JDK_Version obsoleted_in; // when the flag went away
  184. JDK_Version accept_until; // which version to start denying the existence
  185. } ObsoleteFlag;
  186. static ObsoleteFlag obsolete_jvm_flags[] = {
  187. { "UseTrainGC", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  188. { "UseSpecialLargeObjectHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  189. { "UseOversizedCarHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  190. { "TraceCarAllocation", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  191. { "PrintTrainGCProcessingStats", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  192. { "LogOfCarSpaceSize", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  193. { "OversizedCarThreshold", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  194. { "MinTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  195. { "DefaultTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  196. { "MaxTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  197. { "DelayTickAdjustment", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  198. { "ProcessingToTenuringRatio", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  199. { "MinTrainLength", JDK_Version::jdk(5), JDK_Version::jdk(7) },
  200. { "AppendRatio", JDK_Version::jdk_update(6,10), JDK_Version::jdk(7) },
  201. { "DefaultMaxRAM", JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
  202. { "DefaultInitialRAMFraction",
  203. JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
  204. { "UseDepthFirstScavengeOrder",
  205. JDK_Version::jdk_update(6,22), JDK_Version::jdk(7) },
  206. { "HandlePromotionFailure",
  207. JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
  208. { "MaxLiveObjectEvacuationRatio",
  209. JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
  210. { "ForceSharedSpaces", JDK_Version::jdk_update(6,25), JDK_Version::jdk(8) },
  211. { "UseParallelOldGCCompacting",
  212. JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
  213. { "UseParallelDensePrefixUpdate",
  214. JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
  215. { "UseParallelOldGCDensePrefix",
  216. JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
  217. { "AllowTransitionalJSR292", JDK_Version::jdk(7), JDK_Version::jdk(8) },
  218. { "UseCompressedStrings", JDK_Version::jdk(7), JDK_Version::jdk(8) },
  219. #ifdef PRODUCT
  220. { "DesiredMethodLimit",
  221. JDK_Version::jdk_update(7, 2), JDK_Version::jdk(8) },
  222. #endif // PRODUCT
  223. { NULL, JDK_Version(0), JDK_Version(0) }
  224. };
  225. // Returns true if the flag is obsolete and fits into the range specified
  226. // for being ignored. In the case that the flag is ignored, the 'version'
  227. // value is filled in with the version number when the flag became
  228. // obsolete so that that value can be displayed to the user.
  229. bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) {
  230. int i = 0;
  231. assert(version != NULL, "Must provide a version buffer");
  232. while (obsolete_jvm_flags[i].name != NULL) {
  233. const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
  234. // <flag>=xxx form
  235. // [-|+]<flag> form
  236. if ((strncmp(flag_status.name, s, strlen(flag_status.name)) == 0) ||
  237. ((s[0] == '+' || s[0] == '-') &&
  238. (strncmp(flag_status.name, &s[1], strlen(flag_status.name)) == 0))) {
  239. if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
  240. *version = flag_status.obsoleted_in;
  241. return true;
  242. }
  243. }
  244. i++;
  245. }
  246. return false;
  247. }
  248. // Constructs the system class path (aka boot class path) from the following
  249. // components, in order:
  250. //
  251. // prefix // from -Xbootclasspath/p:...
  252. // endorsed // the expansion of -Djava.endorsed.dirs=...
  253. // base // from os::get_system_properties() or -Xbootclasspath=
  254. // suffix // from -Xbootclasspath/a:...
  255. //
  256. // java.endorsed.dirs is a list of directories; any jar or zip files in the
  257. // directories are added to the sysclasspath just before the base.
  258. //
  259. // This could be AllStatic, but it isn't needed after argument processing is
  260. // complete.
  261. class SysClassPath: public StackObj {
  262. public:
  263. SysClassPath(const char* base);
  264. ~SysClassPath();
  265. inline void set_base(const char* base);
  266. inline void add_prefix(const char* prefix);
  267. inline void add_suffix_to_prefix(const char* suffix);
  268. inline void add_suffix(const char* suffix);
  269. inline void reset_path(const char* base);
  270. // Expand the jar/zip files in each directory listed by the java.endorsed.dirs
  271. // property. Must be called after all command-line arguments have been
  272. // processed (in particular, -Djava.endorsed.dirs=...) and before calling
  273. // combined_path().
  274. void expand_endorsed();
  275. inline const char* get_base() const { return _items[_scp_base]; }
  276. inline const char* get_prefix() const { return _items[_scp_prefix]; }
  277. inline const char* get_suffix() const { return _items[_scp_suffix]; }
  278. inline const char* get_endorsed() const { return _items[_scp_endorsed]; }
  279. // Combine all the components into a single c-heap-allocated string; caller
  280. // must free the string if/when no longer needed.
  281. char* combined_path();
  282. private:
  283. // Utility routines.
  284. static char* add_to_path(const char* path, const char* str, bool prepend);
  285. static char* add_jars_to_path(char* path, const char* directory);
  286. inline void reset_item_at(int index);
  287. // Array indices for the items that make up the sysclasspath. All except the
  288. // base are allocated in the C heap and freed by this class.
  289. enum {
  290. _scp_prefix, // from -Xbootclasspath/p:...
  291. _scp_endorsed, // the expansion of -Djava.endorsed.dirs=...
  292. _scp_base, // the default sysclasspath
  293. _scp_suffix, // from -Xbootclasspath/a:...
  294. _scp_nitems // the number of items, must be last.
  295. };
  296. const char* _items[_scp_nitems];
  297. DEBUG_ONLY(bool _expansion_done;)
  298. };
  299. SysClassPath::SysClassPath(const char* base) {
  300. memset(_items, 0, sizeof(_items));
  301. _items[_scp_base] = base;
  302. DEBUG_ONLY(_expansion_done = false;)
  303. }
  304. SysClassPath::~SysClassPath() {
  305. // Free everything except the base.
  306. for (int i = 0; i < _scp_nitems; ++i) {
  307. if (i != _scp_base) reset_item_at(i);
  308. }
  309. DEBUG_ONLY(_expansion_done = false;)
  310. }
  311. inline void SysClassPath::set_base(const char* base) {
  312. _items[_scp_base] = base;
  313. }
  314. inline void SysClassPath::add_prefix(const char* prefix) {
  315. _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
  316. }
  317. inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
  318. _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
  319. }
  320. inline void SysClassPath::add_suffix(const char* suffix) {
  321. _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
  322. }
  323. inline void SysClassPath::reset_item_at(int index) {
  324. assert(index < _scp_nitems && index != _scp_base, "just checking");
  325. if (_items[index] != NULL) {
  326. FREE_C_HEAP_ARRAY(char, _items[index]);
  327. _items[index] = NULL;
  328. }
  329. }
  330. inline void SysClassPath::reset_path(const char* base) {
  331. // Clear the prefix and suffix.
  332. reset_item_at(_scp_prefix);
  333. reset_item_at(_scp_suffix);
  334. set_base(base);
  335. }
  336. //------------------------------------------------------------------------------
  337. void SysClassPath::expand_endorsed() {
  338. assert(_items[_scp_endorsed] == NULL, "can only be called once.");
  339. const char* path = Arguments::get_property("java.endorsed.dirs");
  340. if (path == NULL) {
  341. path = Arguments::get_endorsed_dir();
  342. assert(path != NULL, "no default for java.endorsed.dirs");
  343. }
  344. char* expanded_path = NULL;
  345. const char separator = *os::path_separator();
  346. const char* const end = path + strlen(path);
  347. while (path < end) {
  348. const char* tmp_end = strchr(path, separator);
  349. if (tmp_end == NULL) {
  350. expanded_path = add_jars_to_path(expanded_path, path);
  351. path = end;
  352. } else {
  353. char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1);
  354. memcpy(dirpath, path, tmp_end - path);
  355. dirpath[tmp_end - path] = '\0';
  356. expanded_path = add_jars_to_path(expanded_path, dirpath);
  357. FREE_C_HEAP_ARRAY(char, dirpath);
  358. path = tmp_end + 1;
  359. }
  360. }
  361. _items[_scp_endorsed] = expanded_path;
  362. DEBUG_ONLY(_expansion_done = true;)
  363. }
  364. // Combine the bootclasspath elements, some of which may be null, into a single
  365. // c-heap-allocated string.
  366. char* SysClassPath::combined_path() {
  367. assert(_items[_scp_base] != NULL, "empty default sysclasspath");
  368. assert(_expansion_done, "must call expand_endorsed() first.");
  369. size_t lengths[_scp_nitems];
  370. size_t total_len = 0;
  371. const char separator = *os::path_separator();
  372. // Get the lengths.
  373. int i;
  374. for (i = 0; i < _scp_nitems; ++i) {
  375. if (_items[i] != NULL) {
  376. lengths[i] = strlen(_items[i]);
  377. // Include space for the separator char (or a NULL for the last item).
  378. total_len += lengths[i] + 1;
  379. }
  380. }
  381. assert(total_len > 0, "empty sysclasspath not allowed");
  382. // Copy the _items to a single string.
  383. char* cp = NEW_C_HEAP_ARRAY(char, total_len);
  384. char* cp_tmp = cp;
  385. for (i = 0; i < _scp_nitems; ++i) {
  386. if (_items[i] != NULL) {
  387. memcpy(cp_tmp, _items[i], lengths[i]);
  388. cp_tmp += lengths[i];
  389. *cp_tmp++ = separator;
  390. }
  391. }
  392. *--cp_tmp = '\0'; // Replace the extra separator.
  393. return cp;
  394. }
  395. // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
  396. char*
  397. SysClassPath::add_to_path(const char* path, const char* str, bool prepend) {
  398. char *cp;
  399. assert(str != NULL, "just checking");
  400. if (path == NULL) {
  401. size_t len = strlen(str) + 1;
  402. cp = NEW_C_HEAP_ARRAY(char, len);
  403. memcpy(cp, str, len); // copy the trailing null
  404. } else {
  405. const char separator = *os::path_separator();
  406. size_t old_len = strlen(path);
  407. size_t str_len = strlen(str);
  408. size_t len = old_len + str_len + 2;
  409. if (prepend) {
  410. cp = NEW_C_HEAP_ARRAY(char, len);
  411. char* cp_tmp = cp;
  412. memcpy(cp_tmp, str, str_len);
  413. cp_tmp += str_len;
  414. *cp_tmp = separator;
  415. memcpy(++cp_tmp, path, old_len + 1); // copy the trailing null
  416. FREE_C_HEAP_ARRAY(char, path);
  417. } else {
  418. cp = REALLOC_C_HEAP_ARRAY(char, path, len);
  419. char* cp_tmp = cp + old_len;
  420. *cp_tmp = separator;
  421. memcpy(++cp_tmp, str, str_len + 1); // copy the trailing null
  422. }
  423. }
  424. return cp;
  425. }
  426. // Scan the directory and append any jar or zip files found to path.
  427. // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
  428. char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
  429. DIR* dir = os::opendir(directory);
  430. if (dir == NULL) return path;
  431. char dir_sep[2] = { '\0', '\0' };
  432. size_t directory_len = strlen(directory);
  433. const char fileSep = *os::file_separator();
  434. if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
  435. /* Scan the directory for jars/zips, appending them to path. */
  436. struct dirent *entry;
  437. char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory));
  438. while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
  439. const char* name = entry->d_name;
  440. const char* ext = name + strlen(name) - 4;
  441. bool isJarOrZip = ext > name &&
  442. (os::file_name_strcmp(ext, ".jar") == 0 ||
  443. os::file_name_strcmp(ext, ".zip") == 0);
  444. if (isJarOrZip) {
  445. char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name));
  446. sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
  447. path = add_to_path(path, jarpath, false);
  448. FREE_C_HEAP_ARRAY(char, jarpath);
  449. }
  450. }
  451. FREE_C_HEAP_ARRAY(char, dbuf);
  452. os::closedir(dir);
  453. return path;
  454. }
  455. // Parses a memory size specification string.
  456. static bool atomull(const char *s, julong* result) {
  457. julong n = 0;
  458. int args_read = sscanf(s, os::julong_format_specifier(), &n);
  459. if (args_read != 1) {
  460. return false;
  461. }
  462. while (*s != '\0' && isdigit(*s)) {
  463. s++;
  464. }
  465. // 4705540: illegal if more characters are found after the first non-digit
  466. if (strlen(s) > 1) {
  467. return false;
  468. }
  469. switch (*s) {
  470. case 'T': case 't':
  471. *result = n * G * K;
  472. // Check for overflow.
  473. if (*result/((julong)G * K) != n) return false;
  474. return true;
  475. case 'G': case 'g':
  476. *result = n * G;
  477. if (*result/G != n) return false;
  478. return true;
  479. case 'M': case 'm':
  480. *result = n * M;
  481. if (*result/M != n) return false;
  482. return true;
  483. case 'K': case 'k':
  484. *result = n * K;
  485. if (*result/K != n) return false;
  486. return true;
  487. case '\0':
  488. *result = n;
  489. return true;
  490. default:
  491. return false;
  492. }
  493. }
  494. Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) {
  495. if (size < min_size) return arg_too_small;
  496. // Check that size will fit in a size_t (only relevant on 32-bit)
  497. if (size > max_uintx) return arg_too_big;
  498. return arg_in_range;
  499. }
  500. // Describe an argument out of range error
  501. void Arguments::describe_range_error(ArgsRange errcode) {
  502. switch(errcode) {
  503. case arg_too_big:
  504. jio_fprintf(defaultStream::error_stream(),
  505. "The specified size exceeds the maximum "
  506. "representable size.\n");
  507. break;
  508. case arg_too_small:
  509. case arg_unreadable:
  510. case arg_in_range:
  511. // do nothing for now
  512. break;
  513. default:
  514. ShouldNotReachHere();
  515. }
  516. }
  517. static bool set_bool_flag(char* name, bool value, FlagValueOrigin origin) {
  518. return CommandLineFlags::boolAtPut(name, &value, origin);
  519. }
  520. static bool set_fp_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
  521. double v;
  522. if (sscanf(value, "%lf", &v) != 1) {
  523. return false;
  524. }
  525. if (CommandLineFlags::doubleAtPut(name, &v, origin)) {
  526. return true;
  527. }
  528. return false;
  529. }
  530. static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
  531. julong v;
  532. intx intx_v;
  533. bool is_neg = false;
  534. // Check the sign first since atomull() parses only unsigned values.
  535. if (*value == '-') {
  536. if (!CommandLineFlags::intxAt(name, &intx_v)) {
  537. return false;
  538. }
  539. value++;
  540. is_neg = true;
  541. }
  542. if (!atomull(value, &v)) {
  543. return false;
  544. }
  545. intx_v = (intx) v;
  546. if (is_neg) {
  547. intx_v = -intx_v;
  548. }
  549. if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) {
  550. return true;
  551. }
  552. uintx uintx_v = (uintx) v;
  553. if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) {
  554. return true;
  555. }
  556. uint64_t uint64_t_v = (uint64_t) v;
  557. if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) {
  558. return true;
  559. }
  560. return false;
  561. }
  562. static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
  563. if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false;
  564. // Contract: CommandLineFlags always returns a pointer that needs freeing.
  565. FREE_C_HEAP_ARRAY(char, value);
  566. return true;
  567. }
  568. static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
  569. const char* old_value = "";
  570. if (!CommandLineFlags::ccstrAt(name, &old_value)) return false;
  571. size_t old_len = old_value != NULL ? strlen(old_value) : 0;
  572. size_t new_len = strlen(new_value);
  573. const char* value;
  574. char* free_this_too = NULL;
  575. if (old_len == 0) {
  576. value = new_value;
  577. } else if (new_len == 0) {
  578. value = old_value;
  579. } else {
  580. char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1);
  581. // each new setting adds another LINE to the switch:
  582. sprintf(buf, "%s\n%s", old_value, new_value);
  583. value = buf;
  584. free_this_too = buf;
  585. }
  586. (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
  587. // CommandLineFlags always returns a pointer that needs freeing.
  588. FREE_C_HEAP_ARRAY(char, value);
  589. if (free_this_too != NULL) {
  590. // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
  591. FREE_C_HEAP_ARRAY(char, free_this_too);
  592. }
  593. return true;
  594. }
  595. bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
  596. // range of acceptable characters spelled out for portability reasons
  597. #define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
  598. #define BUFLEN 255
  599. char name[BUFLEN+1];
  600. char dummy;
  601. if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
  602. return set_bool_flag(name, false, origin);
  603. }
  604. if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
  605. return set_bool_flag(name, true, origin);
  606. }
  607. char punct;
  608. if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
  609. const char* value = strchr(arg, '=') + 1;
  610. Flag* flag = Flag::find_flag(name, strlen(name));
  611. if (flag != NULL && flag->is_ccstr()) {
  612. if (flag->ccstr_accumulates()) {
  613. return append_to_string_flag(name, value, origin);
  614. } else {
  615. if (value[0] == '\0') {
  616. value = NULL;
  617. }
  618. return set_string_flag(name, value, origin);
  619. }
  620. }
  621. }
  622. if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
  623. const char* value = strchr(arg, '=') + 1;
  624. // -XX:Foo:=xxx will reset the string flag to the given value.
  625. if (value[0] == '\0') {
  626. value = NULL;
  627. }
  628. return set_string_flag(name, value, origin);
  629. }
  630. #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
  631. #define SIGNED_NUMBER_RANGE "[-0123456789]"
  632. #define NUMBER_RANGE "[0123456789]"
  633. char value[BUFLEN + 1];
  634. char value2[BUFLEN + 1];
  635. if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
  636. // Looks like a floating-point number -- try again with more lenient format string
  637. if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
  638. return set_fp_numeric_flag(name, value, origin);
  639. }
  640. }
  641. #define VALUE_RANGE "[-kmgtKMGT0123456789]"
  642. if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
  643. return set_numeric_flag(name, value, origin);
  644. }
  645. return false;
  646. }
  647. void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
  648. assert(bldarray != NULL, "illegal argument");
  649. if (arg == NULL) {
  650. return;
  651. }
  652. int index = *count;
  653. // expand the array and add arg to the last element
  654. (*count)++;
  655. if (*bldarray == NULL) {
  656. *bldarray = NEW_C_HEAP_ARRAY(char*, *count);
  657. } else {
  658. *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, *count);
  659. }
  660. (*bldarray)[index] = strdup(arg);
  661. }
  662. void Arguments::build_jvm_args(const char* arg) {
  663. add_string(&_jvm_args_array, &_num_jvm_args, arg);
  664. }
  665. void Arguments::build_jvm_flags(const char* arg) {
  666. add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
  667. }
  668. // utility function to return a string that concatenates all
  669. // strings in a given char** array
  670. const char* Arguments::build_resource_string(char** args, int count) {
  671. if (args == NULL || count == 0) {
  672. return NULL;
  673. }
  674. size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
  675. for (int i = 1; i < count; i++) {
  676. length += strlen(args[i]) + 1; // add 1 for a space
  677. }
  678. char* s = NEW_RESOURCE_ARRAY(char, length);
  679. strcpy(s, args[0]);
  680. for (int j = 1; j < count; j++) {
  681. strcat(s, " ");
  682. strcat(s, args[j]);
  683. }
  684. return (const char*) s;
  685. }
  686. void Arguments::print_on(outputStream* st) {
  687. st->print_cr("VM Arguments:");
  688. if (num_jvm_flags() > 0) {
  689. st->print("jvm_flags: "); print_jvm_flags_on(st);
  690. }
  691. if (num_jvm_args() > 0) {
  692. st->print("jvm_args: "); print_jvm_args_on(st);
  693. }
  694. st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
  695. st->print_cr("Launcher Type: %s", _sun_java_launcher);
  696. }
  697. void Arguments::print_jvm_flags_on(outputStream* st) {
  698. if (_num_jvm_flags > 0) {
  699. for (int i=0; i < _num_jvm_flags; i++) {
  700. st->print("%s ", _jvm_flags_array[i]);
  701. }
  702. st->print_cr("");
  703. }
  704. }
  705. void Arguments::print_jvm_args_on(outputStream* st) {
  706. if (_num_jvm_args > 0) {
  707. for (int i=0; i < _num_jvm_args; i++) {
  708. st->print("%s ", _jvm_args_array[i]);
  709. }
  710. st->print_cr("");
  711. }
  712. }
  713. bool Arguments::process_argument(const char* arg,
  714. jboolean ignore_unrecognized, FlagValueOrigin origin) {
  715. JDK_Version since = JDK_Version();
  716. if (parse_argument(arg, origin) || ignore_unrecognized) {
  717. return true;
  718. }
  719. const char * const argname = *arg == '+' || *arg == '-' ? arg + 1 : arg;
  720. if (is_newly_obsolete(arg, &since)) {
  721. char version[256];
  722. since.to_string(version, sizeof(version));
  723. warning("ignoring option %s; support was removed in %s", argname, version);
  724. return true;
  725. }
  726. // For locked flags, report a custom error message if available.
  727. // Otherwise, report the standard unrecognized VM option.
  728. Flag* locked_flag = Flag::find_flag((char*)argname, strlen(argname), true);
  729. if (locked_flag != NULL) {
  730. char locked_message_buf[BUFLEN];
  731. locked_flag->get_locked_message(locked_message_buf, BUFLEN);
  732. if (strlen(locked_message_buf) == 0) {
  733. jio_fprintf(defaultStream::error_stream(),
  734. "Unrecognized VM option '%s'\n", argname);
  735. } else {
  736. jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
  737. }
  738. }
  739. // allow for commandline "commenting out" options like -XX:#+Verbose
  740. return arg[0] == '#';
  741. }
  742. bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
  743. FILE* stream = fopen(file_name, "rb");
  744. if (stream == NULL) {
  745. if (should_exist) {
  746. jio_fprintf(defaultStream::error_stream(),
  747. "Could not open settings file %s\n", file_name);
  748. return false;
  749. } else {
  750. return true;
  751. }
  752. }
  753. char token[1024];
  754. int pos = 0;
  755. bool in_white_space = true;
  756. bool in_comment = false;
  757. bool in_quote = false;
  758. char quote_c = 0;
  759. bool result = true;
  760. int c = getc(stream);
  761. while(c != EOF) {
  762. if (in_white_space) {
  763. if (in_comment) {
  764. if (c == '\n') in_comment = false;
  765. } else {
  766. if (c == '#') in_comment = true;
  767. else if (!isspace(c)) {
  768. in_white_space = false;
  769. token[pos++] = c;
  770. }
  771. }
  772. } else {
  773. if (c == '\n' || (!in_quote && isspace(c))) {
  774. // token ends at newline, or at unquoted whitespace
  775. // this allows a way to include spaces in string-valued options
  776. token[pos] = '\0';
  777. logOption(token);
  778. result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
  779. build_jvm_flags(token);
  780. pos = 0;
  781. in_white_space = true;
  782. in_quote = false;
  783. } else if (!in_quote && (c == '\'' || c == '"')) {
  784. in_quote = true;
  785. quote_c = c;
  786. } else if (in_quote && (c == quote_c)) {
  787. in_quote = false;
  788. } else {
  789. token[pos++] = c;
  790. }
  791. }
  792. c = getc(stream);
  793. }
  794. if (pos > 0) {
  795. token[pos] = '\0';
  796. result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
  797. build_jvm_flags(token);
  798. }
  799. fclose(stream);
  800. return result;
  801. }
  802. //=============================================================================================================
  803. // Parsing of properties (-D)
  804. const char* Arguments::get_property(const char* key) {
  805. return PropertyList_get_value(system_properties(), key);
  806. }
  807. bool Arguments::add_property(const char* prop) {
  808. const char* eq = strchr(prop, '=');
  809. char* key;
  810. // ns must be static--its address may be stored in a SystemProperty object.
  811. const static char ns[1] = {0};
  812. char* value = (char *)ns;
  813. size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop);
  814. key = AllocateHeap(key_len + 1, "add_property");
  815. strncpy(key, prop, key_len);
  816. key[key_len] = '\0';
  817. if (eq != NULL) {
  818. size_t value_len = strlen(prop) - key_len - 1;
  819. value = AllocateHeap(value_len + 1, "add_property");
  820. strncpy(value, &prop[key_len + 1], value_len + 1);
  821. }
  822. if (strcmp(key, "java.compiler") == 0) {
  823. process_java_compiler_argument(value);
  824. FreeHeap(key);
  825. if (eq != NULL) {
  826. FreeHeap(value);
  827. }
  828. return true;
  829. } else if (strcmp(key, "sun.java.command") == 0) {
  830. _java_command = value;
  831. // Record value in Arguments, but let it get passed to Java.
  832. } else if (strcmp(key, "sun.java.launcher.pid") == 0) {
  833. // launcher.pid property is private and is processed
  834. // in process_sun_java_launcher_properties();
  835. // the sun.java.launcher property is passed on to the java application
  836. FreeHeap(key);
  837. if (eq != NULL) {
  838. FreeHeap(value);
  839. }
  840. return true;
  841. } else if (strcmp(key, "java.vendor.url.bug") == 0) {
  842. // save it in _java_vendor_url_bug, so JVM fatal error handler can access
  843. // its value without going through the property list or making a Java call.
  844. _java_vendor_url_bug = value;
  845. } else if (strcmp(key, "sun.boot.library.path") == 0) {
  846. PropertyList_unique_add(&_system_properties, key, value, true);
  847. return true;
  848. }
  849. // Create new property and add at the end of the list
  850. PropertyList_unique_add(&_system_properties, key, value);
  851. return true;
  852. }
  853. //===========================================================================================================
  854. // Setting int/mixed/comp mode flags
  855. void Arguments::set_mode_flags(Mode mode) {
  856. // Set up default values for all flags.
  857. // If you add a flag to any of the branches below,
  858. // add a default value for it here.
  859. set_java_compiler(false);
  860. _mode = mode;
  861. // Ensure Agent_OnLoad has the correct initial values.
  862. // This may not be the final mode; mode may change later in onload phase.
  863. PropertyList_unique_add(&_system_properties, "java.vm.info",
  864. (char*)VM_Version::vm_info_string(), false);
  865. UseInterpreter = true;
  866. UseCompiler = true;
  867. UseLoopCounter = true;
  868. #ifndef ZERO
  869. // Turn these off for mixed and comp. Leave them on for Zero.
  870. if (FLAG_IS_DEFAULT(UseFastAccessorMethods)) {
  871. UseFastAccessorMethods = (mode == _int);
  872. }
  873. if (FLAG_IS_DEFAULT(UseFastEmptyMethods)) {
  874. UseFastEmptyMethods = (mode == _int);
  875. }
  876. #endif
  877. // Default values may be platform/compiler dependent -
  878. // use the saved values
  879. ClipInlining = Arguments::_ClipInlining;
  880. AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods;
  881. UseOnStackReplacement = Arguments::_UseOnStackReplacement;
  882. BackgroundCompilation = Arguments::_BackgroundCompilation;
  883. // Change from defaults based on mode
  884. switch (mode) {
  885. default:
  886. ShouldNotReachHere();
  887. break;
  888. case _int:
  889. UseCompiler = false;
  890. UseLoopCounter = false;
  891. AlwaysCompileLoopMethods = false;
  892. UseOnStackReplacement = false;
  893. break;
  894. case _mixed:
  895. // same as default
  896. break;
  897. case _comp:
  898. UseInterpreter = false;
  899. BackgroundCompilation = false;
  900. ClipInlining = false;
  901. // Be much more aggressive in tiered mode with -Xcomp and exercise C2 more.
  902. // We will first compile a level 3 version (C1 with full profiling), then do one invocation of it and
  903. // compile a level 4 (C2) and then continue executing it.
  904. if (TieredCompilation) {
  905. Tier3InvokeNotifyFreqLog = 0;
  906. Tier4InvocationThreshold = 0;
  907. }
  908. break;
  909. }
  910. }
  911. // Conflict: required to use shared spaces (-Xshare:on), but
  912. // incompatible command line options were chosen.
  913. static void no_shared_spaces() {
  914. if (RequireSharedSpaces) {
  915. jio_fprintf(defaultStream::error_stream(),
  916. "Class data sharing is inconsistent with other specified options.\n");
  917. vm_exit_during_initialization("Unable to use shared archive.", NULL);
  918. } else {
  919. FLAG_SET_DEFAULT(UseSharedSpaces, false);
  920. }
  921. }
  922. void Arguments::set_tiered_flags() {
  923. // With tiered, set default policy to AdvancedThresholdPolicy, which is 3.
  924. if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
  925. FLAG_SET_DEFAULT(CompilationPolicyChoice, 3);
  926. }
  927. if (CompilationPolicyChoice < 2) {
  928. vm_exit_during_initialization(
  929. "Incompatible compilation policy selected", NULL);
  930. }
  931. // Increase the code cache size - tiered compiles a lot more.
  932. if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
  933. FLAG_SET_DEFAULT(ReservedCodeCacheSize, ReservedCodeCacheSize * 2);
  934. }
  935. }
  936. #ifndef KERNEL
  937. static void disable_adaptive_size_policy(const char* collector_name) {
  938. if (UseAdaptiveSizePolicy) {
  939. if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) {
  940. warning("disabling UseAdaptiveSizePolicy; it is incompatible with %s.",
  941. collector_name);
  942. }
  943. FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
  944. }
  945. }
  946. // If the user has chosen ParallelGCThreads > 0, we set UseParNewGC
  947. // if it's not explictly set or unset. If the user has chosen
  948. // UseParNewGC and not explicitly set ParallelGCThreads we
  949. // set it, unless this is a single cpu machine.
  950. void Arguments::set_parnew_gc_flags() {
  951. assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
  952. "control point invariant");
  953. assert(UseParNewGC, "Error");
  954. // Turn off AdaptiveSizePolicy for parnew until it is complete.
  955. disable_adaptive_size_policy("UseParNewGC");
  956. if (ParallelGCThreads == 0) {
  957. FLAG_SET_DEFAULT(ParallelGCThreads,
  958. Abstract_VM_Version::parallel_worker_threads());
  959. if (ParallelGCThreads == 1) {
  960. FLAG_SET_DEFAULT(UseParNewGC, false);
  961. FLAG_SET_DEFAULT(ParallelGCThreads, 0);
  962. }
  963. }
  964. if (UseParNewGC) {
  965. // CDS doesn't work with ParNew yet
  966. no_shared_spaces();
  967. // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively,
  968. // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration
  969. // we set them to 1024 and 1024.
  970. // See CR 6362902.
  971. if (FLAG_IS_DEFAULT(YoungPLABSize)) {
  972. FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024);
  973. }
  974. if (FLAG_IS_DEFAULT(OldPLABSize)) {
  975. FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
  976. }
  977. // AlwaysTenure flag should make ParNew promote all at first collection.
  978. // See CR 6362902.
  979. if (AlwaysTenure) {
  980. FLAG_SET_CMDLINE(intx, MaxTenuringThreshold, 0);
  981. }
  982. // When using compressed oops, we use local overflow stacks,
  983. // rather than using a global overflow list chained through
  984. // the klass word of the object's pre-image.
  985. if (UseCompressedOops && !ParGCUseLocalOverflow) {
  986. if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) {
  987. warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references");
  988. }
  989. FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true);
  990. }
  991. assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error");
  992. }
  993. }
  994. // Adjust some sizes to suit CMS and/or ParNew needs; these work well on
  995. // sparc/solaris for certain applications, but would gain from
  996. // further optimization and tuning efforts, and would almost
  997. // certainly gain from analysis of platform and environment.
  998. void Arguments::set_cms_and_parnew_gc_flags() {
  999. assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
  1000. assert(UseConcMarkSweepGC, "CMS is expected to be on here");
  1001. // If we are using CMS, we prefer to UseParNewGC,
  1002. // unless explicitly forbidden.
  1003. if (FLAG_IS_DEFAULT(UseParNewGC)) {
  1004. FLAG_SET_ERGO(bool, UseParNewGC, true);
  1005. }
  1006. // Turn off AdaptiveSizePolicy for CMS until it is complete.
  1007. disable_adaptive_size_policy("UseConcMarkSweepGC");
  1008. // In either case, adjust ParallelGCThreads and/or UseParNewGC
  1009. // as needed.
  1010. if (UseParNewGC) {
  1011. set_parnew_gc_flags();
  1012. }
  1013. // MaxHeapSize is aligned down in collectorPolicy
  1014. size_t max_heap = align_size_down(MaxHeapSize,
  1015. CardTableRS::ct_max_alignment_constraint());
  1016. // Now make adjustments for CMS
  1017. intx tenuring_default = (intx)6;
  1018. size_t young_gen_per_worker = CMSYoungGenPerWorker;
  1019. // Preferred young gen size for "short" pauses:
  1020. // upper bound depends on # of threads and NewRatio.
  1021. const uintx parallel_gc_threads =
  1022. (ParallelGCThreads == 0 ? 1 : ParallelGCThreads);
  1023. const size_t preferred_max_new_size_unaligned =
  1024. MIN2(max_heap/(NewRatio+1), ScaleForWordSize(young_gen_per_worker * parallel_gc_threads));
  1025. size_t preferred_max_new_size =
  1026. align_size_up(preferred_max_new_size_unaligned, os::vm_page_size());
  1027. // Unless explicitly requested otherwise, size young gen
  1028. // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads
  1029. // If either MaxNewSize or NewRatio is set on the command line,
  1030. // assume the user is trying to set the size of the young gen.
  1031. if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) {
  1032. // Set MaxNewSize to our calculated preferred_max_new_size unless
  1033. // NewSize was set on the command line and it is larger than
  1034. // preferred_max_new_size.
  1035. if (!FLAG_IS_DEFAULT(NewSize)) { // NewSize explicitly set at command-line
  1036. FLAG_SET_ERGO(uintx, MaxNewSize, MAX2((size_t) NewSize, preferred_max_new_size));
  1037. } else {
  1038. FLAG_SET_ERGO(uintx, MaxNewSize, preferred_max_new_size);
  1039. }
  1040. if (PrintGCDetails && Verbose) {
  1041. // Too early to use gclog_or_tty
  1042. tty->print_cr("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);
  1043. }
  1044. // Code along this path potentially sets NewSize and OldSize
  1045. assert(max_heap >= InitialHeapSize, "Error");
  1046. assert(max_heap >= NewSize, "Error");
  1047. if (PrintGCDetails && Verbose) {
  1048. // Too early to use gclog_or_tty
  1049. tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT
  1050. " initial_heap_size: " SIZE_FORMAT
  1051. " max_heap: " SIZE_FORMAT,
  1052. min_heap_size(), InitialHeapSize, max_heap);
  1053. }
  1054. size_t min_new = preferred_max_new_size;
  1055. if (FLAG_IS_CMDLINE(NewSize)) {
  1056. min_new = NewSize;
  1057. }
  1058. if (max_heap > min_new && min_heap_size() > min_new) {
  1059. // Unless explicitly requested otherwise, make young gen
  1060. // at least min_new, and at most preferred_max_new_size.
  1061. if (FLAG_IS_DEFAULT(NewSize)) {
  1062. FLAG_SET_ERGO(uintx, NewSize, MAX2((size_t) NewSize, min_new));
  1063. FLAG_SET_ERGO(uintx, NewSize, MIN2(preferred_max_new_size, (size_t) NewSize));
  1064. if (PrintGCDetails && Verbose) {
  1065. // Too early to use gclog_or_tty
  1066. tty->print_cr("CMS ergo set NewSize: " SIZE_FORMAT, NewSize);
  1067. }
  1068. }
  1069. // Unless explicitly requested otherwise, size old gen
  1070. // so it's NewRatio x of NewSize.
  1071. if (FLAG_IS_DEFAULT(OldSize)) {
  1072. if (max_heap > NewSize) {
  1073. FLAG_SET_ERGO(uintx, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize));
  1074. if (PrintGCDetails && Verbose) {
  1075. // Too early to use gclog_or_tty
  1076. tty->print_cr("CMS ergo set OldSize: " SIZE_FORMAT, OldSize);
  1077. }
  1078. }
  1079. }
  1080. }
  1081. }
  1082. // Unless explicitly requested otherwise, definitely
  1083. // promote all objects surviving "tenuring_default" scavenges.
  1084. if (FLAG_IS_DEFAULT(MaxTenuringThreshold) &&
  1085. FLAG_IS_DEFAULT(SurvivorRatio)) {
  1086. FLAG_SET_ERGO(intx, MaxTenuringThreshold, tenuring_default);
  1087. }
  1088. // If we decided above (or user explicitly requested)
  1089. // `promote all' (via MaxTenuringThreshold := 0),
  1090. // prefer minuscule survivor spaces so as not to waste
  1091. // space for (non-existent) survivors
  1092. if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) {
  1093. FLAG_SET_ERGO(intx, SurvivorRatio, MAX2((intx)1024, SurvivorRatio));
  1094. }
  1095. // If OldPLABSize is set and CMSParPromoteBlocksToClaim is not,
  1096. // set CMSParPromoteBlocksToClaim equal to OldPLABSize.
  1097. // This is done in order to make ParNew+CMS configuration to work
  1098. // with YoungPLABSize and OldPLABSize options.
  1099. // See CR 6362902.
  1100. if (!FLAG_IS_DEFAULT(OldPLABSize)) {
  1101. if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
  1102. // OldPLABSize is not the default value but CMSParPromoteBlocksToClaim
  1103. // is. In this situtation let CMSParPromoteBlocksToClaim follow
  1104. // the value (either from the command line or ergonomics) of
  1105. // OldPLABSize. Following OldPLABSize is an ergonomics decision.
  1106. FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, OldPLABSize);
  1107. } else {
  1108. // OldPLABSize and CMSParPromoteBlocksToClaim are both set.
  1109. // CMSParPromoteBlocksToClaim is a collector-specific flag, so
  1110. // we'll let it to take precedence.
  1111. jio_fprintf(defaultStream::error_stream(),
  1112. "Both OldPLABSize and CMSParPromoteBlocksToClaim"
  1113. " options are specified for the CMS collector."
  1114. " CMSParPromoteBlocksToClaim will take precedence.\n");
  1115. }
  1116. }
  1117. if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) {
  1118. // OldPLAB sizing manually turned off: Use a larger default setting,
  1119. // unless it was manually specified. This is because a too-low value
  1120. // will slow down scavenges.
  1121. if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
  1122. FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, 50); // default value before 6631166
  1123. }
  1124. }
  1125. // Overwrite OldPLABSize which is the variable we will internally use everywhere.
  1126. FLAG_SET_ERGO(uintx, OldPLABSize, CMSParPromoteBlocksToClaim);
  1127. // If either of the static initialization defaults have changed, note this
  1128. // modification.
  1129. if (!FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim) || !FLAG_IS_DEFAULT(OldPLABWeight)) {
  1130. CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight);
  1131. }
  1132. if (PrintGCDetails && Verbose) {
  1133. tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk",
  1134. MarkStackSize / K, MarkStackSizeMax / K);
  1135. tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
  1136. }
  1137. }
  1138. #endif // KERNEL
  1139. void set_object_alignment() {
  1140. // Object alignment.
  1141. assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2");
  1142. MinObjAlignmentInBytes = ObjectAlignmentInBytes;
  1143. assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small");
  1144. MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize;
  1145. assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect");
  1146. MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1;
  1147. LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes);
  1148. LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize;
  1149. // Oop encoding heap max
  1150. OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes;
  1151. #ifndef KERNEL
  1152. // Set CMS global values
  1153. CompactibleFreeListSpace::set_cms_values();
  1154. #endif // KERNEL
  1155. }
  1156. bool verify_object_alignment() {
  1157. // Object alignment.
  1158. if (!is_power_of_2(ObjectAlignmentInBytes)) {
  1159. jio_fprintf(defaultStream::error_stream(),
  1160. "error: ObjectAlignmentInBytes=%d must be power of 2\n",
  1161. (int)ObjectAlignmentInBytes);
  1162. return false;
  1163. }
  1164. if ((int)ObjectAlignmentInBytes < BytesPerLong) {
  1165. jio_fprintf(defaultStream::error_stream(),
  1166. "error: ObjectAlignmentInBytes=%d must be greater or equal %d\n",
  1167. (int)ObjectAlignmentInBytes, BytesPerLong);
  1168. return false;
  1169. }
  1170. // It does not make sense to have big object alignment
  1171. // since a space lost due to alignment will be greater
  1172. // then a saved space from compressed oops.
  1173. if ((int)ObjectAlignmentInBytes > 256) {
  1174. jio_fprintf(defaultStream::error_stream(),
  1175. "error: ObjectAlignmentInBytes=%d must not be greater then 256\n",
  1176. (int)ObjectAlignmentInBytes);
  1177. return false;
  1178. }
  1179. // In case page size is very small.
  1180. if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) {
  1181. jio_fprintf(defaultStream::error_stream(),
  1182. "error: ObjectAlignmentInBytes=%d must be less then page size %d\n",
  1183. (int)ObjectAlignmentInBytes, os::vm_page_size());
  1184. return false;
  1185. }
  1186. return true;
  1187. }
  1188. inline uintx max_heap_for_compressed_oops() {
  1189. // Avoid sign flip.
  1190. if (OopEncodingHeapMax < MaxPermSize + os::vm_page_size()) {
  1191. return 0;
  1192. }
  1193. LP64_ONLY(return OopEncodingHeapMax - MaxPermSize - os::vm_page_size());
  1194. NOT_LP64(ShouldNotReachHere(); return 0);
  1195. }
  1196. bool Arguments::should_auto_select_low_pause_collector() {
  1197. if (UseAutoGCSelectPolicy &&
  1198. !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
  1199. (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
  1200. if (PrintGCDetails) {
  1201. // Cannot use gclog_or_tty yet.
  1202. tty->print_cr("Automatic selection of the low pause collector"
  1203. " based on pause goal of %d (ms)", MaxGCPauseMillis);
  1204. }
  1205. return true;
  1206. }
  1207. return false;
  1208. }
  1209. void Arguments::set_ergonomics_flags() {
  1210. // Parallel GC is not compatible with sharing. If one specifies
  1211. // that they want sharing explicitly, do not set ergonomics flags.
  1212. if (DumpSharedSpaces || RequireSharedSpaces) {
  1213. return;
  1214. }
  1215. if (os::is_server_class_machine()) {
  1216. // If no other collector is requested explicitly,
  1217. // let the VM select the collector based on
  1218. // machine class and automatic selection policy.
  1219. if (!UseSerialGC &&
  1220. !UseConcMarkSweepGC &&
  1221. !UseG1GC &&
  1222. !UseParNewGC &&
  1223. !DumpSharedSpaces &&
  1224. FLAG_IS_DEFAULT(UseParallelGC)) {
  1225. if (should_auto_select_low_pause_collector()) {
  1226. FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
  1227. } else {
  1228. FLAG_SET_ERGO(bool, UseParallelGC, true);
  1229. }
  1230. no_shared_spaces();
  1231. }
  1232. }
  1233. #ifndef ZERO
  1234. #ifdef _LP64
  1235. // Check that UseCompressedOops can be set with the max heap size allocated
  1236. // by ergonomics.
  1237. if (MaxHeapSize <= max_heap_for_compressed_oops()) {
  1238. #if !defined(COMPILER1) || defined(TIERED)
  1239. if (FLAG_IS_DEFAULT(UseCompressedOops)) {
  1240. FLAG_SET_ERGO(bool, UseCompressedOops, true);
  1241. }
  1242. #endif
  1243. #ifdef _WIN64
  1244. if (UseLargePages && UseCompressedOops) {
  1245. // Cannot allocate guard pages for implicit checks in indexed addressing
  1246. // mode, when large pages are specified on windows.
  1247. // This flag could be switched ON if narrow oop base address is set to 0,
  1248. // see code in Universe::initialize_heap().
  1249. Universe::set_narrow_oop_use_implicit_null_checks(false);
  1250. }
  1251. #endif // _WIN64
  1252. } else {
  1253. if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
  1254. warning("Max heap size too large for Compressed Oops");
  1255. FLAG_SET_DEFAULT(UseCompressedOops, false);
  1256. }
  1257. }
  1258. // Also checks that certain machines are slower with compressed oops
  1259. // in vm_version initialization code.
  1260. #endif // _LP64
  1261. #endif // !ZERO
  1262. }
  1263. void Arguments::set_parallel_gc_flags() {
  1264. assert(UseParallelGC || UseParallelOldGC, "Error");
  1265. // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file).
  1266. if (FLAG_IS_DEFAULT(UseParallelOldGC)) {
  1267. FLAG_SET_DEFAULT(UseParallelOldGC, true);
  1268. }
  1269. FLAG_SET_DEFAULT(UseParallelGC, true);
  1270. // If no heap maximum was requested explicitly, use some reasonable fraction
  1271. // of the physical memory, up to a maximum of 1GB.
  1272. if (UseParallelGC) {
  1273. FLAG_SET_DEFAULT(ParallelGCThreads,
  1274. Abstract_VM_Version::parallel_worker_threads());
  1275. // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the
  1276. // SurvivorRatio has been set, reset their default values to SurvivorRatio +
  1277. // 2. By doing this we make SurvivorRatio also work for Parallel Scavenger.
  1278. // See CR 6362902 for details.
  1279. if (!FLAG_IS_DEFAULT(SurvivorRatio)) {
  1280. if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {
  1281. FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);
  1282. }
  1283. if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {
  1284. FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);
  1285. }
  1286. }
  1287. if (UseParallelOldGC) {
  1288. // Par compact uses lower default values since they are treated as
  1289. // minimums. These are different defaults because of the different
  1290. // interpretation and are not ergonomically set.
  1291. if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {
  1292. FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);
  1293. }
  1294. if (FLAG_IS_DEFAULT(PermMarkSweepDeadRatio)) {
  1295. FLAG_SET_DEFAULT(PermMarkSweepDeadRatio, 5);
  1296. }
  1297. }
  1298. }
  1299. if (UseNUMA) {
  1300. if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) {
  1301. FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M);
  1302. }
  1303. // For those collectors or operating systems (eg, Windows) that do
  1304. // not support full UseNUMA, we will map to UseNUMAInterleaving for now
  1305. UseNUMAInterleaving = true;
  1306. }
  1307. }
  1308. void Arguments::set_g1_gc_flags() {
  1309. assert(UseG1GC, "Error");
  1310. #ifdef COMPILER1
  1311. FastTLABRefill = false;
  1312. #endif
  1313. FLAG_SET_DEFAULT(ParallelGCThreads,
  1314. Abstract_VM_Version::parallel_worker_threads());
  1315. if (ParallelGCThreads == 0) {
  1316. FLAG_SET_DEFAULT(ParallelGCThreads,
  1317. Abstract_VM_Version::parallel_worker_threads());
  1318. }
  1319. no_shared_spaces();
  1320. if (FLAG_IS_DEFAULT(MarkStackSize)) {
  1321. FLAG_SET_DEFAULT(MarkStackSize, 128 * TASKQUEUE_SIZE);
  1322. }
  1323. if (PrintGCDetails && Verbose) {
  1324. tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk",
  1325. MarkStackSize / K, MarkStackSizeMax / K);
  1326. tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
  1327. }
  1328. if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
  1329. // In G1, we want the default GC overhead goal to be higher than
  1330. // say in PS. So we set it here to 10%. Otherwise the heap might
  1331. // be expanded more aggressively than we would like it to. In
  1332. // fact, even 10% seems to not be high enough in some cases
  1333. // (especially small GC stress tests that the main thing they do
  1334. // is allocation). We might consider increase it further.
  1335. FLAG_SET_DEFAULT(GCTimeRatio, 9);
  1336. }
  1337. }
  1338. void Arguments::set_heap_size() {
  1339. if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
  1340. // Deprecated flag
  1341. FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
  1342. }
  1343. const julong phys_mem =
  1344. FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
  1345. : (julong)MaxRAM;
  1346. // If the maximum heap size has not been set with -Xmx,
  1347. // then set it as fraction of the size of physical memory,
  1348. // respecting the maximum and minimum sizes of the heap.
  1349. if (FLAG_IS_DEFAULT(MaxHeapSize)) {
  1350. julong reasonable_max = phys_mem / MaxRAMFraction;
  1351. if (phys_mem <= MaxHeapSize * MinRAMFraction) {
  1352. // Small physical memory, so use a minimum fraction of it for the heap
  1353. reasonable_max = phys_mem / MinRAMFraction;
  1354. } else {
  1355. // Not-small physical memory, so require a heap at least
  1356. // as large as MaxHeapSize
  1357. reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
  1358. }
  1359. if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
  1360. // Limit the heap size to ErgoHeapSizeLimit
  1361. reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
  1362. }
  1363. if (UseCompressedOops) {
  1364. // Limit the heap size to the maximum possible when using compressed oops
  1365. julong max_coop_heap = (julong)max_heap_for_compressed_oops();
  1366. if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) {
  1367. // Heap should be above HeapBaseMinAddress to get zero based compressed oops
  1368. // but it should be not less than default MaxHeapSize.
  1369. max_coop_heap -= HeapBaseMinAddress;
  1370. }
  1371. reasonable_max = MIN2(reasonable_max, max_coop_heap);
  1372. }
  1373. reasonable_max = os::allocatable_physical_memory(reasonable_max);
  1374. if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
  1375. // An initial heap size was specified on the command line,
  1376. // so be sure that the maximum size is consistent. Done
  1377. // after call to allocatable_physical_memory because that
  1378. // method might reduce the allocation size.
  1379. reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
  1380. }
  1381. if (PrintGCDetails && Verbose) {
  1382. // Cannot use gclog_or_tty yet.
  1383. tty->print_cr(" Maximum heap size " SIZE_FORMAT, reasonable_max);
  1384. }
  1385. FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx)reasonable_max);
  1386. }
  1387. // If the initial_heap_size has not been set with InitialHeapSize
  1388. // or -Xms, then set it as fraction of the size of physical memory,
  1389. // respecting the maximum and minimum sizes of the heap.
  1390. if (FLAG_IS_DEFAULT(InitialHeapSize)) {
  1391. julong reasonable_minimum = (julong)(OldSize + NewSize);
  1392. reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
  1393. reasonable_minimum = os::allocatable_physical_memory(reasonable_minimum);
  1394. julong reasonable_initial = phys_mem / InitialRAMFraction;
  1395. reasonable_initial = MAX2(reasonable_initial, reasonable_minimum);
  1396. reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
  1397. reasonable_initial = os::allocatable_physical_memory(reasonable_initial);
  1398. if (PrintGCDetails && Verbose) {
  1399. // Cannot use gclog_or_tty yet.
  1400. tty->print_cr(" Initial heap size " SIZE_FORMAT, (uintx)reasonable_initial);
  1401. tty->print_cr(" Minimum heap size " SIZE_FORMAT, (uintx)reasonable_minimum);
  1402. }
  1403. FLAG_SET_ERGO(uintx, InitialHeapSize, (uintx)reasonable_initial);
  1404. set_min_heap_size((uintx)reasonable_minimum);
  1405. }
  1406. }
  1407. // This must be called after ergonomics because we want bytecode rewriting
  1408. // if the server compiler is used, or if UseSharedSpaces is disabled.
  1409. void Arguments::set_bytecode_flags() {
  1410. // Better not attempt to store into a read-only space.
  1411. if (UseSharedSpaces) {
  1412. FLAG_SET_DEFAULT(RewriteBytecodes, false);
  1413. FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
  1414. }
  1415. if (!RewriteBytecodes) {
  1416. FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
  1417. }
  1418. }
  1419. // Aggressive optimization flags -XX:+AggressiveOpts
  1420. void Arguments::set_aggressive_opts_flags() {
  1421. #ifdef COMPILER2
  1422. if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
  1423. if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
  1424. FLAG_SET_DEFAULT(EliminateAutoBox, true);
  1425. }
  1426. if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
  1427. FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
  1428. }
  1429. // Feed the cache size setting into the JDK
  1430. char buffer[1024];
  1431. sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
  1432. add_property(buffer);
  1433. }
  1434. if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
  1435. FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
  1436. }
  1437. #endif
  1438. if (AggressiveOpts) {
  1439. // Sample flag setting code
  1440. // if (FLAG_IS_DEFAULT(EliminateZeroing)) {
  1441. // FLAG_SET_DEFAULT(EliminateZeroing, true);
  1442. // }
  1443. }
  1444. }
  1445. //===========================================================================================================
  1446. // Parsing of java.compiler property
  1447. void Arguments::process_java_compiler_argument(char* arg) {
  1448. // For backwards compatibility, Djava.compiler=NONE or ""
  1449. // causes us to switch to -Xint mode UNLESS -Xdebug
  1450. // is also specified.
  1451. if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) {
  1452. set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen.
  1453. }
  1454. }
  1455. void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
  1456. _sun_java_launcher = strdup(launcher);
  1457. if (strcmp("gamma", _sun_java_launcher) == 0) {
  1458. _created_by_gamma_launcher = true;
  1459. }
  1460. }
  1461. bool Arguments::created_by_java_launcher() {
  1462. assert(_sun_java_launcher != NULL, "property must have value");
  1463. return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
  1464. }
  1465. bool Arguments::created_by_gamma_launcher() {
  1466. return _created_by_gamma_launcher;
  1467. }
  1468. //===========================================================================================================
  1469. // Parsing of main arguments
  1470. bool Arguments::verify_interval(uintx val, uintx min,
  1471. uintx max, const char* name) {
  1472. // Returns true iff value is in the inclusive interval [min..max]
  1473. // false, otherwise.
  1474. if (val >= min && val <= max) {
  1475. return true;
  1476. }
  1477. jio_fprintf(defaultStream::error_stream(),
  1478. "%s of " UINTX_FORMAT " is invalid; must be between " UINTX_FORMAT
  1479. " and " UINTX_FORMAT "\n",
  1480. name, val, min, max);
  1481. return false;
  1482. }
  1483. bool Arguments::verify_min_value(intx val, intx min, const char* name) {
  1484. // Returns true if given value is at least specified min threshold
  1485. // false, otherwise.
  1486. if (val >= min ) {
  1487. return true;
  1488. }
  1489. jio_fprintf(defaultStream::error_stream(),
  1490. "%s of " INTX_FORMAT " is invalid; must be at least " INTX_FORMAT "\n",
  1491. name, val, min);
  1492. return false;
  1493. }
  1494. bool Arguments::verify_percentage(uintx value, const char* name) {
  1495. if (value <= 100) {
  1496. return true;
  1497. }
  1498. jio_fprintf(defaultStream::error_stream(),
  1499. "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n",
  1500. name, value);
  1501. return false;
  1502. }
  1503. static void force_serial_gc() {
  1504. FLAG_SET_DEFAULT(UseSerialGC, true);
  1505. FLAG_SET_DEFAULT(UseParNewGC, false);
  1506. FLAG_SET_DEFAULT(UseConcMarkSweepGC, false);
  1507. FLAG_SET_DEFAULT(CMSIncrementalMode, false); // special CMS suboption
  1508. FLAG_SET_DEFAULT(UseParallelGC, false);
  1509. FLAG_SET_DEFAULT(UseParallelOldGC, false);
  1510. FLAG_SET_DEFAULT(UseG1GC, false);
  1511. }
  1512. static bool verify_serial_gc_flags() {
  1513. return (UseSerialGC &&
  1514. !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC ||
  1515. UseParallelGC || UseParallelOldGC));
  1516. }
  1517. // check if do gclog rotation
  1518. // +UseGCLogFileRotation is a must,
  1519. // no gc log rotation when log file not supplied or
  1520. // NumberOfGCLogFiles is 0, or GCLogFileSize is 0
  1521. void check_gclog_consistency() {
  1522. if (UseGCLogFileRotation) {
  1523. if ((Arguments::gc_log_filename() == NULL) ||
  1524. (NumberOfGCLogFiles == 0) ||
  1525. (GCLogFileSize == 0)) {
  1526. jio_fprintf(defaultStream::output_stream(),
  1527. "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files> -XX:GCLogFileSize=<num_of_size>\n"
  1528. "where num_of_file > 0 and num_of_size > 0\n"
  1529. "GC log rotation is turned off\n");
  1530. UseGCLogFileRotation = false;
  1531. }
  1532. }
  1533. if (UseGCLogFileRotation && GCLogFileSize < 8*K) {
  1534. FLAG_SET_CMDLINE(uintx, GCLogFileSize, 8*K);
  1535. jio_fprintf(defaultStream::output_stream(),
  1536. "GCLogFileSize changed to minimum 8K\n");
  1537. }
  1538. }
  1539. // Check consistency of GC selection
  1540. bool Arguments::check_gc_consistency() {
  1541. check_gclog_consistency();
  1542. bool status = true;
  1543. // Ensure that the user has not selected conflicting sets
  1544. // of collectors. [Note: this check is merely a user convenience;
  1545. // collectors over-ride each other so that only a non-conflicting
  1546. // set is selected; however what the user gets is not what they
  1547. // may have expected from the combination they asked for. It's
  1548. // better to reduce user confusion by not allowing them to
  1549. // select conflicting combinations.
  1550. uint i = 0;
  1551. if (UseSerialGC) i++;
  1552. if (UseConcMarkSweepGC || UseParNewGC) i++;
  1553. if (UseParallelGC || UseParallelOldGC) i++;
  1554. if (UseG1GC) i++;
  1555. if (i > 1) {
  1556. jio_fprintf(defaultStream::error_stream(),
  1557. "Conflicting collector combinations in option list; "
  1558. "please refer to the release notes for the combinations "
  1559. "allowed\n");
  1560. status = false;
  1561. }
  1562. return status;
  1563. }
  1564. // Check stack pages settings
  1565. bool Arguments::check_stack_pages()
  1566. {
  1567. bool status = true;
  1568. status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages");
  1569. status = status && verify_min_value(StackRedPages, 1, "StackRedPages");
  1570. // greater stack shadow pages can't generate instruction to bang stack
  1571. status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages");
  1572. return status;
  1573. }
  1574. // Check the consistency of vm_init_args
  1575. bool Arguments::check_vm_args_consistency() {
  1576. // Method for adding checks for flag consistency.
  1577. // The intent is to warn the user of all possible conflicts,
  1578. // before returning an error.
  1579. // Note: Needs platform-dependent factoring.
  1580. bool status = true;
  1581. #if ( (defined(COMPILER2) && defined(SPARC)))
  1582. // NOTE: The call to VM_Version_init depends on the fact that VM_Version_init
  1583. // on sparc doesn't require generation of a stub as is the case on, e.g.,
  1584. // x86. Normally, VM_Version_init must be called from init_globals in
  1585. // init.cpp, which is called by the initial java thread *after* arguments
  1586. // have been parsed. VM_Version_init gets called twice on sparc.
  1587. extern void VM_Version_init();
  1588. VM_Version_init();
  1589. if (!VM_Version::has_v9()) {
  1590. jio_fprintf(defaultStream::error_stream(),
  1591. "V8 Machine detected, Server requires V9\n");
  1592. status = false;
  1593. }
  1594. #endif /* COMPILER2 && SPARC */
  1595. // Allow both -XX:-UseStackBanging and -XX:-UseBoundThreads in non-product
  1596. // builds so the cost of stack banging can be measured.
  1597. #if (defined(PRODUCT) && defined(SOLARIS))
  1598. if (!UseBoundThreads && !UseStackBanging) {
  1599. jio_fprintf(defaultStream::error_stream(),
  1600. "-UseStackBanging conflicts with -UseBoundThreads\n");
  1601. status = false;
  1602. }
  1603. #endif
  1604. if (TLABRefillWasteFraction == 0) {
  1605. jio_fprintf(defaultStream::error_stream(),
  1606. "TLABRefillWasteFraction should be a denominator, "
  1607. "not " SIZE_FORMAT "\n",
  1608. TLABRefillWasteFraction);
  1609. status = false;
  1610. }
  1611. status = status && verify_percentage(AdaptiveSizePolicyWeight,
  1612. "AdaptiveSizePolicyWeight");
  1613. status = status && verify_percentage(AdaptivePermSizeWeight, "AdaptivePermSizeWeight");
  1614. status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance");
  1615. status = status && verify_percentage(MinHeapFreeRatio, "MinHeapFreeRatio");
  1616. status = status && verify_percentage(MaxHeapFreeRatio, "MaxHeapFreeRatio");
  1617. if (MinHeapFreeRatio > MaxHeapFreeRatio) {
  1618. jio_fprintf(defaultStream::error_stream(),
  1619. "MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
  1620. "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
  1621. MinHeapFreeRatio, MaxHeapFreeRatio);
  1622. status = false;
  1623. }
  1624. // Keeping the heap 100% free is hard ;-) so limit it to 99%.
  1625. MinHeapFreeRatio = MIN2(MinHeapFreeRatio, (uintx) 99);
  1626. if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
  1627. MarkSweepAlwaysCompactCount = 1; // Move objects every gc.
  1628. }
  1629. if (UseParallelOldGC && ParallelOldGCSplitALot) {
  1630. // Settings to encourage splitting.
  1631. if (!FLAG_IS_CMDLINE(NewRatio)) {
  1632. FLAG_SET_CMDLINE(intx, NewRatio, 2);
  1633. }
  1634. if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) {
  1635. FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  1636. }
  1637. }
  1638. status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
  1639. status = status && verify_percentage(GCTimeLimit, "GCTimeLimit");
  1640. if (GCTimeLimit == 100) {
  1641. // Turn off gc-overhead-limit-exceeded checks
  1642. FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
  1643. }
  1644. status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
  1645. status = status && check_gc_consistency();
  1646. status = status && check_stack_pages();
  1647. if (_has_alloc_profile) {
  1648. if (UseParallelGC || UseParallelOldGC) {
  1649. jio_fprintf(defaultStream::error_stream(),
  1650. "error: invalid argument combination.\n"
  1651. "Allocation profiling (-Xaprof) cannot be used together with "
  1652. "Parallel GC (-XX:+UseParallelGC or -XX:+UseParallelOldGC).\n");
  1653. status = false;
  1654. }
  1655. if (UseConcMarkSweepGC) {
  1656. jio_fprintf(defaultStream::error_stream(),
  1657. "error: invalid argument combination.\n"
  1658. "Allocation profiling (-Xaprof) cannot be used together with "
  1659. "the CMS collector (-XX:+UseConcMarkSweepGC).\n");
  1660. status = false;
  1661. }
  1662. }
  1663. if (CMSIncrementalMode) {
  1664. if (!UseConcMarkSweepGC) {
  1665. jio_fprintf(defaultStream::error_stream(),
  1666. "error: invalid argument combination.\n"
  1667. "The CMS collector (-XX:+UseConcMarkSweepGC) must be "
  1668. "selected in order\nto use CMSIncrementalMode.\n");
  1669. status = false;
  1670. } else {
  1671. status = status && verify_percentage(CMSIncrementalDutyCycle,
  1672. "CMSIncrementalDutyCycle");
  1673. status = status && verify_percentage(CMSIncrementalDutyCycleMin,
  1674. "CMSIncrementalDutyCycleMin");
  1675. status = status && verify_percentage(CMSIncrementalSafetyFactor,
  1676. "CMSIncrementalSafetyFactor");
  1677. status = status && verify_percentage(CMSIncrementalOffset,
  1678. "CMSIncrementalOffset");
  1679. status = status && verify_percentage(CMSExpAvgFactor,
  1680. "CMSExpAvgFactor");
  1681. // If it was not set on the command line, set
  1682. // CMSInitiatingOccupancyFraction to 1 so icms can initiate cycles early.
  1683. if (CMSInitiatingOccupancyFraction < 0) {
  1684. FLAG_SET_DEFAULT(CMSInitiatingOccupancyFraction, 1);
  1685. }
  1686. }
  1687. }
  1688. // CMS space iteration, which FLSVerifyAllHeapreferences entails,
  1689. // insists that we hold the requisite locks so that the iteration is
  1690. // MT-safe. For the verification at start-up and shut-down, we don't
  1691. // yet have a good way of acquiring and releasing these locks,
  1692. // which are not visible at the CollectedHeap level. We want to
  1693. // be able to acquire these locks and then do the iteration rather
  1694. // than just disable the lock verification. This will be fixed under
  1695. // bug 4788986.
  1696. if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) {
  1697. if (VerifyGCStartAt == 0) {
  1698. warning("Heap verification at start-up disabled "
  1699. "(due to current incompatibility with FLSVerifyAllHeapReferences)");
  1700. VerifyGCStartAt = 1; // Disable verification at start-up
  1701. }
  1702. if (VerifyBeforeExit) {
  1703. warning("Heap verification at shutdown disabled "
  1704. "(due to current incompatibility with FLSVerifyAllHeapReferences)");
  1705. VerifyBeforeExit = false; // Disable verification at shutdown
  1706. }
  1707. }
  1708. // Note: only executed in non-PRODUCT mode
  1709. if (!UseAsyncConcMarkSweepGC &&
  1710. (ExplicitGCInvokesConcurrent ||
  1711. ExplicitGCInvokesConcurrentAndUnloadsClasses)) {
  1712. jio_fprintf(defaultStream::error_stream(),
  1713. "error: +ExplictGCInvokesConcurrent[AndUnloadsClasses] conflicts"
  1714. " with -UseAsyncConcMarkSweepGC");
  1715. status = false;
  1716. }
  1717. status = status && verify_min_value(ParGCArrayScanChunk, 1, "ParGCArrayScanChunk");
  1718. #ifndef SERIALGC
  1719. if (UseG1GC) {
  1720. status = status && verify_percentage(InitiatingHeapOccupancyPercent,
  1721. "InitiatingHeapOccupancyPercent");
  1722. status = status && verify_min_value(G1RefProcDrainInterval, 1,
  1723. "G1RefProcDrainInterval");
  1724. status = status && verify_min_value((intx)G1ConcMarkStepDurationMillis, 1,
  1725. "G1ConcMarkStepDurationMillis");
  1726. }
  1727. #endif
  1728. status = status && verify_interval(RefDiscoveryPolicy,
  1729. ReferenceProcessor::DiscoveryPolicyMin,
  1730. ReferenceProcessor::DiscoveryPolicyMax,
  1731. "RefDiscoveryPolicy");
  1732. // Limit the lower bound of this flag to 1 as it is used in a division
  1733. // expression.
  1734. status = status && verify_interval(TLABWasteTargetPercent,
  1735. 1, 100, "TLABWasteTargetPercent");
  1736. status = status && verify_object_alignment();
  1737. return status;
  1738. }
  1739. bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore,
  1740. const char* option_type) {
  1741. if (ignore) return false;
  1742. const char* spacer = " ";
  1743. if (option_type == NULL) {
  1744. option_type = ++spacer; // Set both to the empty string.
  1745. }
  1746. if (os::obsolete_option(option)) {
  1747. jio_fprintf(defaultStream::error_stream(),
  1748. "Obsolete %s%soption: %s\n", option_type, spacer,
  1749. option->optionString);
  1750. return false;
  1751. } else {
  1752. jio_fprintf(defaultStream::error_stream(),
  1753. "Unrecognized %s%soption: %s\n", option_type, spacer,
  1754. option->optionString);
  1755. return true;
  1756. }
  1757. }
  1758. static const char* user_assertion_options[] = {
  1759. "-da", "-ea", "-disableassertions", "-enableassertions", 0
  1760. };
  1761. static const char* system_assertion_options[] = {
  1762. "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
  1763. };
  1764. // Return true if any of the strings in null-terminated array 'names' matches.
  1765. // If tail_allowed is true, then the tail must begin with a colon; otherwise,
  1766. // the option must match exactly.
  1767. static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
  1768. bool tail_allowed) {
  1769. for (/* empty */; *names != NULL; ++names) {
  1770. if (match_option(option, *names, tail)) {
  1771. if (**tail == '\0' || tail_allowed && **tail == ':') {
  1772. return true;
  1773. }
  1774. }
  1775. }
  1776. return false;
  1777. }
  1778. bool Arguments::parse_uintx(const char* value,
  1779. uintx* uintx_arg,
  1780. uintx min_size) {
  1781. // Check the sign first since atomull() parses only unsigned values.
  1782. bool value_is_positive = !(*value == '-');
  1783. if (value_is_positive) {
  1784. julong n;
  1785. bool good_return = atomull(value, &n);
  1786. if (good_return) {
  1787. bool above_minimum = n >= min_size;
  1788. bool value_is_too_large = n > max_uintx;
  1789. if (above_minimum && !value_is_too_large) {
  1790. *uintx_arg = n;
  1791. return true;
  1792. }
  1793. }
  1794. }
  1795. return false;
  1796. }
  1797. Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
  1798. julong* long_arg,
  1799. julong min_size) {
  1800. if (!atomull(s, long_arg)) return arg_unreadable;
  1801. return check_memory_size(*long_arg, min_size);
  1802. }
  1803. // Parse JavaVMInitArgs structure
  1804. jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
  1805. // For components of the system classpath.
  1806. SysClassPath scp(Arguments::get_sysclasspath());
  1807. bool scp_assembly_required = false;
  1808. // Save default settings for some mode flags
  1809. Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
  1810. Arguments::_UseOnStackReplacement = UseOnStackReplacement;
  1811. Arguments::_ClipInlining = ClipInlining;
  1812. Arguments::_BackgroundCompilation = BackgroundCompilation;
  1813. // Setup flags for mixed which is the default
  1814. set_mode_flags(_mixed);
  1815. // Parse JAVA_TOOL_OPTIONS environment variable (if present)
  1816. jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required);
  1817. if (result != JNI_OK) {
  1818. return result;
  1819. }
  1820. // Parse JavaVMInitArgs structure passed in
  1821. result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, COMMAND_LINE);
  1822. if (result != JNI_OK) {
  1823. return result;
  1824. }
  1825. if (AggressiveOpts) {
  1826. // Insert alt-rt.jar between user-specified bootclasspath
  1827. // prefix and the default bootclasspath. os::set_boot_path()
  1828. // uses meta_index_dir as the default bootclasspath directory.
  1829. const char* altclasses_jar = "alt-rt.jar";
  1830. size_t altclasses_path_len = strlen(get_meta_index_dir()) + 1 +
  1831. strlen(altclasses_jar);
  1832. char* altclasses_path = NEW_C_HEAP_ARRAY(char, altclasses_path_len);
  1833. strcpy(altclasses_path, get_meta_index_dir());
  1834. strcat(altclasses_path, altclasses_jar);
  1835. scp.add_suffix_to_prefix(altclasses_path);
  1836. scp_assembly_required = true;
  1837. FREE_C_HEAP_ARRAY(char, altclasses_path);
  1838. }
  1839. // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM)
  1840. result = parse_java_options_environment_variable(&scp, &scp_assembly_required);
  1841. if (result != JNI_OK) {
  1842. return result;
  1843. }
  1844. // Do final processing now that all arguments have been parsed
  1845. result = finalize_vm_init_args(&scp, scp_assembly_required);
  1846. if (result != JNI_OK) {
  1847. return result;
  1848. }
  1849. return JNI_OK;
  1850. }
  1851. jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
  1852. SysClassPath* scp_p,
  1853. bool* scp_assembly_required_p,
  1854. FlagValueOrigin origin) {
  1855. // Remaining part of option string
  1856. const char* tail;
  1857. // iterate over arguments
  1858. for (int index = 0; index < args->nOptions; index++) {
  1859. bool is_absolute_path = false; // for -agentpath vs -agentlib
  1860. const JavaVMOption* option = args->options + index;
  1861. if (!match_option(option, "-Djava.class.path", &tail) &&
  1862. !match_option(option, "-Dsun.java.command", &tail) &&
  1863. !match_option(option, "-Dsun.java.launcher", &tail)) {
  1864. // add all jvm options to the jvm_args string. This string
  1865. // is used later to set the java.vm.args PerfData string constant.
  1866. // the -Djava.class.path and the -Dsun.java.command options are
  1867. // omitted from jvm_args string as each have their own PerfData
  1868. // string constant object.
  1869. build_jvm_args(option->optionString);
  1870. }
  1871. // -verbose:[class/gc/jni]
  1872. if (match_option(option, "-verbose", &tail)) {
  1873. if (!strcmp(tail, ":class") || !strcmp(tail, "")) {
  1874. FLAG_SET_CMDLINE(bool, TraceClassLoading, true);
  1875. FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
  1876. } else if (!strcmp(tail, ":gc")) {
  1877. FLAG_SET_CMDLINE(bool, PrintGC, true);
  1878. } else if (!strcmp(tail, ":jni")) {
  1879. FLAG_SET_CMDLINE(bool, PrintJNIResolving, true);
  1880. }
  1881. // -da / -ea / -disableassertions / -enableassertions
  1882. // These accept an optional class/package name separated by a colon, e.g.,
  1883. // -da:java.lang.Thread.
  1884. } else if (match_option(option, user_assertion_options, &tail, true)) {
  1885. bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
  1886. if (*tail == '\0') {
  1887. JavaAssertions::setUserClassDefault(enable);
  1888. } else {
  1889. assert(*tail == ':', "bogus match by match_option()");
  1890. JavaAssertions::addOption(tail + 1, enable);
  1891. }
  1892. // -dsa / -esa / -disablesystemassertions / -enablesystemassertions
  1893. } else if (match_option(option, system_assertion_options, &tail, false)) {
  1894. bool enable = option->optionString[1] == 'e'; // char after '-' is 'e'
  1895. JavaAssertions::setSystemClassDefault(enable);
  1896. // -bootclasspath:
  1897. } else if (match_option(option, "-Xbootclasspath:", &tail)) {
  1898. scp_p->reset_path(tail);
  1899. *scp_assembly_required_p = true;
  1900. // -bootclasspath/a:
  1901. } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
  1902. scp_p->add_suffix(tail);
  1903. *scp_assembly_required_p = true;
  1904. // -bootclasspath/p:
  1905. } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
  1906. scp_p->add_prefix(tail);
  1907. *scp_assembly_required_p = true;
  1908. // -Xrun
  1909. } else if (match_option(option, "-Xrun", &tail)) {
  1910. if (tail != NULL) {
  1911. const char* pos = strchr(tail, ':');
  1912. size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
  1913. char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
  1914. name[len] = '\0';
  1915. char *options = NULL;
  1916. if(pos != NULL) {
  1917. size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied.
  1918. options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2), pos+1, len2);
  1919. }
  1920. #ifdef JVMTI_KERNEL
  1921. if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
  1922. warning("profiling and debugging agents are not supported with Kernel VM");
  1923. } else
  1924. #endif // JVMTI_KERNEL
  1925. add_init_library(name, options);
  1926. }
  1927. // -agentlib and -agentpath
  1928. } else if (match_option(option, "-agentlib:", &tail) ||
  1929. (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
  1930. if(tail != NULL) {
  1931. const char* pos = strchr(tail, '=');
  1932. size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
  1933. char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
  1934. name[len] = '\0';
  1935. char *options = NULL;
  1936. if(pos != NULL) {
  1937. options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1), pos + 1);
  1938. }
  1939. #ifdef JVMTI_KERNEL
  1940. if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
  1941. warning("profiling and debugging agents are not supported with Kernel VM");
  1942. } else
  1943. #endif // JVMTI_KERNEL
  1944. add_init_agent(name, options, is_absolute_path);
  1945. }
  1946. // -javaagent
  1947. } else if (match_option(option, "-javaagent:", &tail)) {
  1948. if(tail != NULL) {
  1949. char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1), tail);
  1950. add_init_agent("instrument", options, false);
  1951. }
  1952. // -Xnoclassgc
  1953. } else if (match_option(option, "-Xnoclassgc", &tail)) {
  1954. FLAG_SET_CMDLINE(bool, ClassUnloading, false);
  1955. // -Xincgc: i-CMS
  1956. } else if (match_option(option, "-Xincgc", &tail)) {
  1957. FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
  1958. FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true);
  1959. // -Xnoincgc: no i-CMS
  1960. } else if (match_option(option, "-Xnoincgc", &tail)) {
  1961. FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
  1962. FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false);
  1963. // -Xconcgc
  1964. } else if (match_option(option, "-Xconcgc", &tail)) {
  1965. FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
  1966. // -Xnoconcgc
  1967. } else if (match_option(option, "-Xnoconcgc", &tail)) {
  1968. FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
  1969. // -Xbatch
  1970. } else if (match_option(option, "-Xbatch", &tail)) {
  1971. FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
  1972. // -Xmn for compatibility with other JVM vendors
  1973. } else if (match_option(option, "-Xmn", &tail)) {
  1974. julong long_initial_eden_size = 0;
  1975. ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
  1976. if (errcode != arg_in_range) {
  1977. jio_fprintf(defaultStream::error_stream(),
  1978. "Invalid initial eden size: %s\n", option->optionString);
  1979. describe_range_error(errcode);
  1980. return JNI_EINVAL;
  1981. }
  1982. FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx)long_initial_eden_size);
  1983. FLAG_SET_CMDLINE(uintx, NewSize, (uintx)long_initial_eden_size);
  1984. // -Xms
  1985. } else if (match_option(option, "-Xms", &tail)) {
  1986. julong long_initial_heap_size = 0;
  1987. ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 1);
  1988. if (errcode != arg_in_range) {
  1989. jio_fprintf(defaultStream::error_stream(),
  1990. "Invalid initial heap size: %s\n", option->optionString);
  1991. describe_range_error(errcode);
  1992. return JNI_EINVAL;
  1993. }
  1994. FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx)long_initial_heap_size);
  1995. // Currently the minimum size and the initial heap sizes are the same.
  1996. set_min_heap_size(InitialHeapSize);
  1997. // -Xmx
  1998. } else if (match_option(option, "-Xmx", &tail)) {
  1999. julong long_max_heap_size = 0;
  2000. ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
  2001. if (errcode != arg_in_range) {
  2002. jio_fprintf(defaultStream::error_stream(),
  2003. "Invalid maximum heap size: %s\n", option->optionString);
  2004. describe_range_error(errcode);
  2005. return JNI_EINVAL;
  2006. }
  2007. FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size);
  2008. // Xmaxf
  2009. } else if (match_option(option, "-Xmaxf", &tail)) {
  2010. int maxf = (int)(atof(tail) * 100);
  2011. if (maxf < 0 || maxf > 100) {
  2012. jio_fprintf(defaultStream::error_stream(),
  2013. "Bad max heap free percentage size: %s\n",
  2014. option->optionString);
  2015. return JNI_EINVAL;
  2016. } else {
  2017. FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
  2018. }
  2019. // Xminf
  2020. } else if (match_option(option, "-Xminf", &tail)) {
  2021. int minf = (int)(atof(tail) * 100);
  2022. if (minf < 0 || minf > 100) {
  2023. jio_fprintf(defaultStream::error_stream(),
  2024. "Bad min heap free percentage size: %s\n",
  2025. option->optionString);
  2026. return JNI_EINVAL;
  2027. } else {
  2028. FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf);
  2029. }
  2030. // -Xss
  2031. } else if (match_option(option, "-Xss", &tail)) {
  2032. julong long_ThreadStackSize = 0;
  2033. ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
  2034. if (errcode != arg_in_range) {
  2035. jio_fprintf(defaultStream::error_stream(),
  2036. "Invalid thread stack size: %s\n", option->optionString);
  2037. describe_range_error(errcode);
  2038. return JNI_EINVAL;
  2039. }
  2040. // Internally track ThreadStackSize in units of 1024 bytes.
  2041. FLAG_SET_CMDLINE(intx, ThreadStackSize,
  2042. round_to((int)long_ThreadStackSize, K) / K);
  2043. // -Xoss
  2044. } else if (match_option(option, "-Xoss", &tail)) {
  2045. // HotSpot does not have separate native and Java stacks, ignore silently for compatibility
  2046. // -Xmaxjitcodesize
  2047. } else if (match_option(option, "-Xmaxjitcodesize", &tail) ||
  2048. match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) {
  2049. julong long_ReservedCodeCacheSize = 0;
  2050. ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize,
  2051. (size_t)InitialCodeCacheSize);
  2052. if (errcode != arg_in_range) {
  2053. jio_fprintf(defaultStream::error_stream(),
  2054. "Invalid maximum code cache size: %s. Should be greater than InitialCodeCacheSize=%dK\n",
  2055. option->optionString, InitialCodeCacheSize/K);
  2056. describe_range_error(errcode);
  2057. return JNI_EINVAL;
  2058. }
  2059. FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize);
  2060. // -green
  2061. } else if (match_option(option, "-green", &tail)) {
  2062. jio_fprintf(defaultStream::error_stream(),
  2063. "Green threads support not available\n");
  2064. return JNI_EINVAL;
  2065. // -native
  2066. } else if (match_option(option, "-native", &tail)) {
  2067. // HotSpot always uses native threads, ignore silently for compatibility
  2068. // -Xsqnopause
  2069. } else if (match_option(option, "-Xsqnopause", &tail)) {
  2070. // EVM option, ignore silently for compatibility
  2071. // -Xrs
  2072. } else if (match_option(option, "-Xrs", &tail)) {
  2073. // Classic/EVM option, new functionality
  2074. FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true);
  2075. } else if (match_option(option, "-Xusealtsigs", &tail)) {
  2076. // change default internal VM signals used - lower case for back compat
  2077. FLAG_SET_CMDLINE(bool, UseAltSigs, true);
  2078. // -Xoptimize
  2079. } else if (match_option(option, "-Xoptimize", &tail)) {
  2080. // EVM option, ignore silently for compatibility
  2081. // -Xprof
  2082. } else if (match_option(option, "-Xprof", &tail)) {
  2083. #ifndef FPROF_KERNEL
  2084. _has_profile = true;
  2085. #else // FPROF_KERNEL
  2086. // do we have to exit?
  2087. warning("Kernel VM does not support flat profiling.");
  2088. #endif // FPROF_KERNEL
  2089. // -Xaprof
  2090. } else if (match_option(option, "-Xaprof", &tail)) {
  2091. _has_alloc_profile = true;
  2092. // -Xconcurrentio
  2093. } else if (match_option(option, "-Xconcurrentio", &tail)) {
  2094. FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
  2095. FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
  2096. FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
  2097. FLAG_SET_CMDLINE(bool, UseTLAB, false);
  2098. FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation
  2099. // -Xinternalversion
  2100. } else if (match_option(option, "-Xinternalversion", &tail)) {
  2101. jio_fprintf(defaultStream::output_stream(), "%s\n",
  2102. VM_Version::internal_vm_info_string());
  2103. vm_exit(0);
  2104. #ifndef PRODUCT
  2105. // -Xprintflags
  2106. } else if (match_option(option, "-Xprintflags", &tail)) {
  2107. CommandLineFlags::printFlags(tty, false);
  2108. vm_exit(0);
  2109. #endif
  2110. // -D
  2111. } else if (match_option(option, "-D", &tail)) {
  2112. if (!add_property(tail)) {
  2113. return JNI_ENOMEM;
  2114. }
  2115. // Out of the box management support
  2116. if (match_option(option, "-Dcom.sun.management", &tail)) {
  2117. FLAG_SET_CMDLINE(bool, ManagementServer, true);
  2118. }
  2119. // -Xint
  2120. } else if (match_option(option, "-Xint", &tail)) {
  2121. set_mode_flags(_int);
  2122. // -Xmixed
  2123. } else if (match_option(option, "-Xmixed", &tail)) {
  2124. set_mode_flags(_mixed);
  2125. // -Xcomp
  2126. } else if (match_option(option, "-Xcomp", &tail)) {
  2127. // for testing the compiler; turn off all flags that inhibit compilation
  2128. set_mode_flags(_comp);
  2129. // -Xshare:dump
  2130. } else if (match_option(option, "-Xshare:dump", &tail)) {
  2131. #ifdef TIERED
  2132. FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
  2133. set_mode_flags(_int); // Prevent compilation, which creates objects
  2134. #elif defined(COMPILER2)
  2135. vm_exit_during_initialization(
  2136. "Dumping a shared archive is not supported on the Server JVM.", NULL);
  2137. #elif defined(KERNEL)
  2138. vm_exit_during_initialization(
  2139. "Dumping a shared archive is not supported on the Kernel JVM.", NULL);
  2140. #else
  2141. FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
  2142. set_mode_flags(_int); // Prevent compilation, which creates objects
  2143. #endif
  2144. // -Xshare:on
  2145. } else if (match_option(option, "-Xshare:on", &tail)) {
  2146. FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
  2147. FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
  2148. // -Xshare:auto
  2149. } else if (match_option(option, "-Xshare:auto", &tail)) {
  2150. FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
  2151. FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
  2152. // -Xshare:off
  2153. } else if (match_option(option, "-Xshare:off", &tail)) {
  2154. FLAG_SET_CMDLINE(bool, UseSharedSpaces, false);
  2155. FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
  2156. // -Xverify
  2157. } else if (match_option(option, "-Xverify", &tail)) {
  2158. if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) {
  2159. FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true);
  2160. FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
  2161. } else if (strcmp(tail, ":remote") == 0) {
  2162. FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
  2163. FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
  2164. } else if (strcmp(tail, ":none") == 0) {
  2165. FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
  2166. FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false);
  2167. } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) {
  2168. return JNI_EINVAL;
  2169. }
  2170. // -Xdebug
  2171. } else if (match_option(option, "-Xdebug", &tail)) {
  2172. // note this flag has been used, then ignore
  2173. set_xdebug_mode(true);
  2174. // -Xnoagent
  2175. } else if (match_option(option, "-Xnoagent", &tail)) {
  2176. // For compatibility with classic. HotSpot refuses to load the old style agent.dll.
  2177. } else if (match_option(option, "-Xboundthreads", &tail)) {
  2178. // Bind user level threads to kernel threads (Solaris only)
  2179. FLAG_SET_CMDLINE(bool, UseBoundThreads, true);
  2180. } else if (match_option(option, "-Xloggc:", &tail)) {
  2181. // Redirect GC output to the file. -Xloggc:<filename>
  2182. // ostream_init_log(), when called will use this filename
  2183. // to initialize a fileStream.
  2184. _gc_log_filename = strdup(tail);
  2185. FLAG_SET_CMDLINE(bool, PrintGC, true);
  2186. FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true);
  2187. // JNI hooks
  2188. } else if (match_option(option, "-Xcheck", &tail)) {
  2189. if (!strcmp(tail, ":jni")) {
  2190. CheckJNICalls = true;
  2191. } else if (is_bad_option(option, args->ignoreUnrecognized,
  2192. "check")) {
  2193. return JNI_EINVAL;
  2194. }
  2195. } else if (match_option(option, "vfprintf", &tail)) {
  2196. _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
  2197. } else if (match_option(option, "exit", &tail)) {
  2198. _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
  2199. } else if (match_option(option, "abort", &tail)) {
  2200. _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
  2201. // -XX:+AggressiveHeap
  2202. } else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
  2203. // This option inspects the machine and attempts to set various
  2204. // parameters to be optimal for long-running, memory allocation
  2205. // intensive jobs. It is intended for machines with large
  2206. // amounts of cpu and memory.
  2207. // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
  2208. // VM, but we may not be able to represent the total physical memory
  2209. // available (like having 8gb of memory on a box but using a 32bit VM).
  2210. // Thus, we need to make sure we're using a julong for intermediate
  2211. // calculations.
  2212. julong initHeapSize;
  2213. julong total_memory = os::physical_memory();
  2214. if (total_memory < (julong)256*M) {
  2215. jio_fprintf(defaultStream::error_stream(),
  2216. "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
  2217. vm_exit(1);
  2218. }
  2219. // The heap size is half of available memory, or (at most)
  2220. // all of possible memory less 160mb (leaving room for the OS
  2221. // when using ISM). This is the maximum; because adaptive sizing
  2222. // is turned on below, the actual space used may be smaller.
  2223. initHeapSize = MIN2(total_memory / (julong)2,
  2224. total_memory - (julong)160*M);
  2225. // Make sure that if we have a lot of memory we cap the 32 bit
  2226. // process space. The 64bit VM version of this function is a nop.
  2227. initHeapSize = os::allocatable_physical_memory(initHeapSize);
  2228. // The perm gen is separate but contiguous with the
  2229. // object heap (and is reserved with it) so subtract it
  2230. // from the heap size.
  2231. if (initHeapSize > MaxPermSize) {
  2232. initHeapSize = initHeapSize - MaxPermSize;
  2233. } else {
  2234. warning("AggressiveHeap and MaxPermSize values may conflict");
  2235. }
  2236. if (FLAG_IS_DEFAULT(MaxHeapSize)) {
  2237. FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
  2238. FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
  2239. // Currently the minimum size and the initial heap sizes are the same.
  2240. set_min_heap_size(initHeapSize);
  2241. }
  2242. if (FLAG_IS_DEFAULT(NewSize)) {
  2243. // Make the young generation 3/8ths of the total heap.
  2244. FLAG_SET_CMDLINE(uintx, NewSize,
  2245. ((julong)MaxHeapSize / (julong)8) * (julong)3);
  2246. FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
  2247. }
  2248. FLAG_SET_DEFAULT(UseLargePages, true);
  2249. // Increase some data structure sizes for efficiency
  2250. FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
  2251. FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
  2252. FLAG_SET_CMDLINE(uintx, TLABSize, 256*K);
  2253. // See the OldPLABSize comment below, but replace 'after promotion'
  2254. // with 'after copying'. YoungPLABSize is the size of the survivor
  2255. // space per-gc-thread buffers. The default is 4kw.
  2256. FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K); // Note: this is in words
  2257. // OldPLABSize is the size of the buffers in the old gen that
  2258. // UseParallelGC uses to promote live data that doesn't fit in the
  2259. // survivor spaces. At any given time, there's one for each gc thread.
  2260. // The default size is 1kw. These buffers are rarely used, since the
  2261. // survivor spaces are usually big enough. For specjbb, however, there
  2262. // are occasions when there's lots of live data in the young gen
  2263. // and we end up promoting some of it. We don't have a definite
  2264. // explanation for why bumping OldPLABSize helps, but the theory
  2265. // is that a bigger PLAB results in retaining something like the
  2266. // original allocation order after promotion, which improves mutator
  2267. // locality. A minor effect may be that larger PLABs reduce the
  2268. // number of PLAB allocation events during gc. The value of 8kw
  2269. // was arrived at by experimenting with specjbb.
  2270. FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K); // Note: this is in words
  2271. // Enable parallel GC and adaptive generation sizing
  2272. FLAG_SET_CMDLINE(bool, UseParallelGC, true);
  2273. FLAG_SET_DEFAULT(ParallelGCThreads,
  2274. Abstract_VM_Version::parallel_worker_threads());
  2275. // Encourage steady state memory management
  2276. FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
  2277. // This appears to improve mutator locality
  2278. FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  2279. // Get around early Solaris scheduling bug
  2280. // (affinity vs other jobs on system)
  2281. // but disallow DR and offlining (5008695).
  2282. FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
  2283. } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
  2284. // The last option must always win.
  2285. FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
  2286. FLAG_SET_CMDLINE(bool, NeverTenure, true);
  2287. } else if (match_option(option, "-XX:+AlwaysTenure", &tail)) {
  2288. // The last option must always win.
  2289. FLAG_SET_CMDLINE(bool, NeverTenure, false);
  2290. FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
  2291. } else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) ||
  2292. match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) {
  2293. jio_fprintf(defaultStream::error_stream(),
  2294. "Please use CMSClassUnloadingEnabled in place of "
  2295. "CMSPermGenSweepingEnabled in the future\n");
  2296. } else if (match_option(option, "-XX:+UseGCTimeLimit", &tail)) {
  2297. FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, true);
  2298. jio_fprintf(defaultStream::error_stream(),
  2299. "Please use -XX:+UseGCOverheadLimit in place of "
  2300. "-XX:+UseGCTimeLimit in the future\n");
  2301. } else if (match_option(option, "-XX:-UseGCTimeLimit", &tail)) {
  2302. FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, false);
  2303. jio_fprintf(defaultStream::error_stream(),
  2304. "Please use -XX:-UseGCOverheadLimit in place of "
  2305. "-XX:-UseGCTimeLimit in the future\n");
  2306. // The TLE options are for compatibility with 1.3 and will be
  2307. // removed without notice in a future release. These options
  2308. // are not to be documented.
  2309. } else if (match_option(option, "-XX:MaxTLERatio=", &tail)) {
  2310. // No longer used.
  2311. } else if (match_option(option, "-XX:+ResizeTLE", &tail)) {
  2312. FLAG_SET_CMDLINE(bool, ResizeTLAB, true);
  2313. } else if (match_option(option, "-XX:-ResizeTLE", &tail)) {
  2314. FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
  2315. } else if (match_option(option, "-XX:+PrintTLE", &tail)) {
  2316. FLAG_SET_CMDLINE(bool, PrintTLAB, true);
  2317. } else if (match_option(option, "-XX:-PrintTLE", &tail)) {
  2318. FLAG_SET_CMDLINE(bool, PrintTLAB, false);
  2319. } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) {
  2320. // No longer used.
  2321. } else if (match_option(option, "-XX:TLESize=", &tail)) {
  2322. julong long_tlab_size = 0;
  2323. ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1);
  2324. if (errcode != arg_in_range) {
  2325. jio_fprintf(defaultStream::error_stream(),
  2326. "Invalid TLAB size: %s\n", option->optionString);
  2327. describe_range_error(errcode);
  2328. return JNI_EINVAL;
  2329. }
  2330. FLAG_SET_CMDLINE(uintx, TLABSize, long_tlab_size);
  2331. } else if (match_option(option, "-XX:TLEThreadRatio=", &tail)) {
  2332. // No longer used.
  2333. } else if (match_option(option, "-XX:+UseTLE", &tail)) {
  2334. FLAG_SET_CMDLINE(bool, UseTLAB, true);
  2335. } else if (match_option(option, "-XX:-UseTLE", &tail)) {
  2336. FLAG_SET_CMDLINE(bool, UseTLAB, false);
  2337. SOLARIS_ONLY(
  2338. } else if (match_option(option, "-XX:+UsePermISM", &tail)) {
  2339. warning("-XX:+UsePermISM is obsolete.");
  2340. FLAG_SET_CMDLINE(bool, UseISM, true);
  2341. } else if (match_option(option, "-XX:-UsePermISM", &tail)) {
  2342. FLAG_SET_CMDLINE(bool, UseISM, false);
  2343. )
  2344. } else if (match_option(option, "-XX:+DisplayVMOutputToStderr", &tail)) {
  2345. FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false);
  2346. FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true);
  2347. } else if (match_option(option, "-XX:+DisplayVMOutputToStdout", &tail)) {
  2348. FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
  2349. FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
  2350. } else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) {
  2351. #if defined(DTRACE_ENABLED)
  2352. FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
  2353. FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
  2354. FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true);
  2355. FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true);
  2356. #else // defined(DTRACE_ENABLED)
  2357. jio_fprintf(defaultStream::error_stream(),
  2358. "ExtendedDTraceProbes flag is not applicable for this configuration\n");
  2359. return JNI_EINVAL;
  2360. #endif // defined(DTRACE_ENABLED)
  2361. #ifdef ASSERT
  2362. } else if (match_option(option, "-XX:+FullGCALot", &tail)) {
  2363. FLAG_SET_CMDLINE(bool, FullGCALot, true);
  2364. // disable scavenge before parallel mark-compact
  2365. FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  2366. #endif
  2367. } else if (match_option(option, "-XX:CMSParPromoteBlocksToClaim=", &tail)) {
  2368. julong cms_blocks_to_claim = (julong)atol(tail);
  2369. FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
  2370. jio_fprintf(defaultStream::error_stream(),
  2371. "Please use -XX:OldPLABSize in place of "
  2372. "-XX:CMSParPromoteBlocksToClaim in the future\n");
  2373. } else if (match_option(option, "-XX:ParCMSPromoteBlocksToClaim=", &tail)) {
  2374. julong cms_blocks_to_claim = (julong)atol(tail);
  2375. FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
  2376. jio_fprintf(defaultStream::error_stream(),
  2377. "Please use -XX:OldPLABSize in place of "
  2378. "-XX:ParCMSPromoteBlocksToClaim in the future\n");
  2379. } else if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) {
  2380. julong old_plab_size = 0;
  2381. ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1);
  2382. if (errcode != arg_in_range) {
  2383. jio_fprintf(defaultStream::error_stream(),
  2384. "Invalid old PLAB size: %s\n", option->optionString);
  2385. describe_range_error(errcode);
  2386. return JNI_EINVAL;
  2387. }
  2388. FLAG_SET_CMDLINE(uintx, OldPLABSize, old_plab_size);
  2389. jio_fprintf(defaultStream::error_stream(),
  2390. "Please use -XX:OldPLABSize in place of "
  2391. "-XX:ParallelGCOldGenAllocBufferSize in the future\n");
  2392. } else if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) {
  2393. julong young_plab_size = 0;
  2394. ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1);
  2395. if (errcode != arg_in_range) {
  2396. jio_fprintf(defaultStream::error_stream(),
  2397. "Invalid young PLAB size: %s\n", option->optionString);
  2398. describe_range_error(errcode);
  2399. return JNI_EINVAL;
  2400. }
  2401. FLAG_SET_CMDLINE(uintx, YoungPLABSize, young_plab_size);
  2402. jio_fprintf(defaultStream::error_stream(),
  2403. "Please use -XX:YoungPLABSize in place of "
  2404. "-XX:ParallelGCToSpaceAllocBufferSize in the future\n");
  2405. } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) ||
  2406. match_option(option, "-XX:G1MarkStackSize=", &tail)) {
  2407. julong stack_size = 0;
  2408. ArgsRange errcode = parse_memory_size(tail, &stack_size, 1);
  2409. if (errcode != arg_in_range) {
  2410. jio_fprintf(defaultStream::error_stream(),
  2411. "Invalid mark stack size: %s\n", option->optionString);
  2412. describe_range_error(errcode);
  2413. return JNI_EINVAL;
  2414. }
  2415. FLAG_SET_CMDLINE(uintx, MarkStackSize, stack_size);
  2416. } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) {
  2417. julong max_stack_size = 0;
  2418. ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1);
  2419. if (errcode != arg_in_range) {
  2420. jio_fprintf(defaultStream::error_stream(),
  2421. "Invalid maximum mark stack size: %s\n",
  2422. option->optionString);
  2423. describe_range_error(errcode);
  2424. return JNI_EINVAL;
  2425. }
  2426. FLAG_SET_CMDLINE(uintx, MarkStackSizeMax, max_stack_size);
  2427. } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) ||
  2428. match_option(option, "-XX:ParallelCMSThreads=", &tail)) {
  2429. uintx conc_threads = 0;
  2430. if (!parse_uintx(tail, &conc_threads, 1)) {
  2431. jio_fprintf(defaultStream::error_stream(),
  2432. "Invalid concurrent threads: %s\n", option->optionString);
  2433. return JNI_EINVAL;
  2434. }
  2435. FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads);
  2436. } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
  2437. // Skip -XX:Flags= since that case has already been handled
  2438. if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
  2439. if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
  2440. return JNI_EINVAL;
  2441. }
  2442. }
  2443. // Unknown option
  2444. } else if (is_bad_option(option, args->ignoreUnrecognized)) {
  2445. return JNI_ERR;
  2446. }
  2447. }
  2448. // Change the default value for flags which have different default values
  2449. // when working with older JDKs.
  2450. if (JDK_Version::current().compare_major(6) <= 0 &&
  2451. FLAG_IS_DEFAULT(UseVMInterruptibleIO)) {
  2452. FLAG_SET_DEFAULT(UseVMInterruptibleIO, true);
  2453. }
  2454. #ifdef LINUX
  2455. if (JDK_Version::current().compare_major(6) <= 0 &&
  2456. FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) {
  2457. FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false);
  2458. }
  2459. #endif // LINUX
  2460. return JNI_OK;
  2461. }
  2462. jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
  2463. // This must be done after all -D arguments have been processed.
  2464. scp_p->expand_endorsed();
  2465. if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
  2466. // Assemble the bootclasspath elements into the final path.
  2467. Arguments::set_sysclasspath(scp_p->combined_path());
  2468. }
  2469. // This must be done after all arguments have been processed.
  2470. // java_compiler() true means set to "NONE" or empty.
  2471. if (java_compiler() && !xdebug_mode()) {
  2472. // For backwards compatibility, we switch to interpreted mode if
  2473. // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
  2474. // not specified.
  2475. set_mode_flags(_int);
  2476. }
  2477. if (CompileThreshold == 0) {
  2478. set_mode_flags(_int);
  2479. }
  2480. #ifndef COMPILER2
  2481. // Don't degrade server performance for footprint
  2482. if (FLAG_IS_DEFAULT(UseLargePages) &&
  2483. MaxHeapSize < LargePageHeapSizeThreshold) {
  2484. // No need for large granularity pages w/small heaps.
  2485. // Note that large pages are enabled/disabled for both the
  2486. // Java heap and the code cache.
  2487. FLAG_SET_DEFAULT(UseLargePages, false);
  2488. SOLARIS_ONLY(FLAG_SET_DEFAULT(UseMPSS, false));
  2489. SOLARIS_ONLY(FLAG_SET_DEFAULT(UseISM, false));
  2490. }
  2491. // Tiered compilation is undefined with C1.
  2492. TieredCompilation = false;
  2493. #else
  2494. if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
  2495. FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
  2496. }
  2497. #endif
  2498. // If we are running in a headless jre, force java.awt.headless property
  2499. // to be true unless the property has already been set.
  2500. // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
  2501. if (os::is_headless_jre()) {
  2502. const char* headless = Arguments::get_property("java.awt.headless");
  2503. if (headless == NULL) {
  2504. char envbuffer[128];
  2505. if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) {
  2506. if (!add_property("java.awt.headless=true")) {
  2507. return JNI_ENOMEM;
  2508. }
  2509. } else {
  2510. char buffer[256];
  2511. strcpy(buffer, "java.awt.headless=");
  2512. strcat(buffer, envbuffer);
  2513. if (!add_property(buffer)) {
  2514. return JNI_ENOMEM;
  2515. }
  2516. }
  2517. }
  2518. }
  2519. if (!check_vm_args_consistency()) {
  2520. return JNI_ERR;
  2521. }
  2522. return JNI_OK;
  2523. }
  2524. jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
  2525. return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
  2526. scp_assembly_required_p);
  2527. }
  2528. jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
  2529. return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
  2530. scp_assembly_required_p);
  2531. }
  2532. jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
  2533. const int N_MAX_OPTIONS = 64;
  2534. const int OPTION_BUFFER_SIZE = 1024;
  2535. char buffer[OPTION_BUFFER_SIZE];
  2536. // The variable will be ignored if it exceeds the length of the buffer.
  2537. // Don't check this variable if user has special privileges
  2538. // (e.g. unix su command).
  2539. if (os::getenv(name, buffer, sizeof(buffer)) &&
  2540. !os::have_special_privileges()) {
  2541. JavaVMOption options[N_MAX_OPTIONS]; // Construct option array
  2542. jio_fprintf(defaultStream::error_stream(),
  2543. "Picked up %s: %s\n", name, buffer);
  2544. char* rd = buffer; // pointer to the input string (rd)
  2545. int i;
  2546. for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string
  2547. while (isspace(*rd)) rd++; // skip whitespace
  2548. if (*rd == 0) break; // we re done when the input string is read completely
  2549. // The output, option string, overwrites the input string.
  2550. // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
  2551. // input string (rd).
  2552. char* wrt = rd;
  2553. options[i++].optionString = wrt; // Fill in option
  2554. while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL
  2555. if (*rd == '\'' || *rd == '"') { // handle a quoted string
  2556. int quote = *rd; // matching quote to look for
  2557. rd++; // don't copy open quote
  2558. while (*rd != quote) { // include everything (even spaces) up until quote
  2559. if (*rd == 0) { // string termination means unmatched string
  2560. jio_fprintf(defaultStream::error_stream(),
  2561. "Unmatched quote in %s\n", name);
  2562. return JNI_ERR;
  2563. }
  2564. *wrt++ = *rd++; // copy to option string
  2565. }
  2566. rd++; // don't copy close quote
  2567. } else {
  2568. *wrt++ = *rd++; // copy to option string
  2569. }
  2570. }
  2571. // Need to check if we're done before writing a NULL,
  2572. // because the write could be to the byte that rd is pointing to.
  2573. if (*rd++ == 0) {
  2574. *wrt = 0;
  2575. break;
  2576. }
  2577. *wrt = 0; // Zero terminate option
  2578. }
  2579. // Construct JavaVMInitArgs structure and parse as if it was part of the command line
  2580. JavaVMInitArgs vm_args;
  2581. vm_args.version = JNI_VERSION_1_2;
  2582. vm_args.options = options;
  2583. vm_args.nOptions = i;
  2584. vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
  2585. if (PrintVMOptions) {
  2586. const char* tail;
  2587. for (int i = 0; i < vm_args.nOptions; i++) {
  2588. const JavaVMOption *option = vm_args.options + i;
  2589. if (match_option(option, "-XX:", &tail)) {
  2590. logOption(tail);
  2591. }
  2592. }
  2593. }
  2594. return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, ENVIRON_VAR));
  2595. }
  2596. return JNI_OK;
  2597. }
  2598. void Arguments::set_shared_spaces_flags() {
  2599. const bool must_share = DumpSharedSpaces || RequireSharedSpaces;
  2600. const bool might_share = must_share || UseSharedSpaces;
  2601. // The string table is part of the shared archive so the size must match.
  2602. if (!FLAG_IS_DEFAULT(StringTableSize)) {
  2603. // Disable sharing.
  2604. if (must_share) {
  2605. warning("disabling shared archive %s because of non-default "
  2606. "StringTableSize", DumpSharedSpaces ? "creation" : "use");
  2607. }
  2608. if (might_share) {
  2609. FLAG_SET_DEFAULT(DumpSharedSpaces, false);
  2610. FLAG_SET_DEFAULT(RequireSharedSpaces, false);
  2611. FLAG_SET_DEFAULT(UseSharedSpaces, false);
  2612. }
  2613. return;
  2614. }
  2615. // Check whether class data sharing settings conflict with GC, compressed oops
  2616. // or page size, and fix them up. Explicit sharing options override other
  2617. // settings.
  2618. const bool cannot_share = UseConcMarkSweepGC || CMSIncrementalMode ||
  2619. UseG1GC || UseParNewGC || UseParallelGC || UseParallelOldGC ||
  2620. UseCompressedOops || UseLargePages && FLAG_IS_CMDLINE(UseLargePages);
  2621. if (cannot_share) {
  2622. if (must_share) {
  2623. warning("selecting serial gc and disabling large pages %s"
  2624. "because of %s", "" LP64_ONLY("and compressed oops "),
  2625. DumpSharedSpaces ? "-Xshare:dump" : "-Xshare:on");
  2626. force_serial_gc();
  2627. FLAG_SET_CMDLINE(bool, UseLargePages, false);
  2628. LP64_ONLY(FLAG_SET_CMDLINE(bool, UseCompressedOops, false));
  2629. } else {
  2630. if (UseSharedSpaces && Verbose) {
  2631. warning("turning off use of shared archive because of "
  2632. "choice of garbage collector or large pages");
  2633. }
  2634. no_shared_spaces();
  2635. }
  2636. } else if (UseLargePages && might_share) {
  2637. // Disable large pages to allow shared spaces. This is sub-optimal, since
  2638. // there may not even be a shared archive to use.
  2639. FLAG_SET_DEFAULT(UseLargePages, false);
  2640. }
  2641. }
  2642. // Disable options not supported in this release, with a warning if they
  2643. // were explicitly requested on the command-line
  2644. #define UNSUPPORTED_OPTION(opt, description) \
  2645. do { \
  2646. if (opt) { \
  2647. if (FLAG_IS_CMDLINE(opt)) { \
  2648. warning(description " is disabled in this release."); \
  2649. } \
  2650. FLAG_SET_DEFAULT(opt, false); \
  2651. } \
  2652. } while(0)
  2653. // Parse entry point called from JNI_CreateJavaVM
  2654. jint Arguments::parse(const JavaVMInitArgs* args) {
  2655. // Sharing support
  2656. // Construct the path to the archive
  2657. char jvm_path[JVM_MAXPATHLEN];
  2658. os::jvm_path(jvm_path, sizeof(jvm_path));
  2659. char *end = strrchr(jvm_path, *os::file_separator());
  2660. if (end != NULL) *end = '\0';
  2661. char *shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(jvm_path) +
  2662. strlen(os::file_separator()) + 20);
  2663. if (shared_archive_path == NULL) return JNI_ENOMEM;
  2664. strcpy(shared_archive_path, jvm_path);
  2665. strcat(shared_archive_path, os::file_separator());
  2666. strcat(shared_archive_path, "classes");
  2667. DEBUG_ONLY(strcat(shared_archive_path, "_g");)
  2668. strcat(shared_archive_path, ".jsa");
  2669. SharedArchivePath = shared_archive_path;
  2670. // Remaining part of option string
  2671. const char* tail;
  2672. // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
  2673. bool settings_file_specified = false;
  2674. const char* flags_file;
  2675. int index;
  2676. for (index = 0; index < args->nOptions; index++) {
  2677. const JavaVMOption *option = args->options + index;
  2678. if (match_option(option, "-XX:Flags=", &tail)) {
  2679. flags_file = tail;
  2680. settings_file_specified = true;
  2681. }
  2682. if (match_option(option, "-XX:+PrintVMOptions", &tail)) {
  2683. PrintVMOptions = true;
  2684. }
  2685. if (match_option(option, "-XX:-PrintVMOptions", &tail)) {
  2686. PrintVMOptions = false;
  2687. }
  2688. if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions", &tail)) {
  2689. IgnoreUnrecognizedVMOptions = true;
  2690. }
  2691. if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions", &tail)) {
  2692. IgnoreUnrecognizedVMOptions = false;
  2693. }
  2694. if (match_option(option, "-XX:+PrintFlagsInitial", &tail)) {
  2695. CommandLineFlags::printFlags(tty, false);
  2696. vm_exit(0);
  2697. }
  2698. #ifndef PRODUCT
  2699. if (match_option(option, "-XX:+PrintFlagsWithComments", &tail)) {
  2700. CommandLineFlags::printFlags(tty, true);
  2701. vm_exit(0);
  2702. }
  2703. #endif
  2704. }
  2705. if (IgnoreUnrecognizedVMOptions) {
  2706. // uncast const to modify the flag args->ignoreUnrecognized
  2707. *(jboolean*)(&args->ignoreUnrecognized) = true;
  2708. }
  2709. // Parse specified settings file
  2710. if (settings_file_specified) {
  2711. if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
  2712. return JNI_EINVAL;
  2713. }
  2714. }
  2715. #ifdef ASSERT
  2716. // Parse default .hotspotrc settings file
  2717. if (!settings_file_specified) {
  2718. if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
  2719. return JNI_EINVAL;
  2720. }
  2721. }
  2722. #endif
  2723. if (PrintVMOptions) {
  2724. for (index = 0; index < args->nOptions; index++) {
  2725. const JavaVMOption *option = args->options + index;
  2726. if (match_option(option, "-XX:", &tail)) {
  2727. logOption(tail);
  2728. }
  2729. }
  2730. }
  2731. // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
  2732. jint result = parse_vm_init_args(args);
  2733. if (result != JNI_OK) {
  2734. return result;
  2735. }
  2736. #ifdef JAVASE_EMBEDDED
  2737. UNSUPPORTED_OPTION(UseG1GC, "G1 GC");
  2738. #endif
  2739. #ifndef PRODUCT
  2740. if (TraceBytecodesAt != 0) {
  2741. TraceBytecodes = true;
  2742. }
  2743. if (CountCompiledCalls) {
  2744. if (UseCounterDecay) {
  2745. warning("UseCounterDecay disabled because CountCalls is set");
  2746. UseCounterDecay = false;
  2747. }
  2748. }
  2749. #endif // PRODUCT
  2750. // Transitional
  2751. if (EnableMethodHandles || AnonymousClasses) {
  2752. if (!EnableInvokeDynamic && !FLAG_IS_DEFAULT(EnableInvokeDynamic)) {
  2753. warning("EnableMethodHandles and AnonymousClasses are obsolete. Keeping EnableInvokeDynamic disabled.");
  2754. } else {
  2755. EnableInvokeDynamic = true;
  2756. }
  2757. }
  2758. // JSR 292 is not supported before 1.7
  2759. if (!JDK_Version::is_gte_jdk17x_version()) {
  2760. if (EnableInvokeDynamic) {
  2761. if (!FLAG_IS_DEFAULT(EnableInvokeDynamic)) {
  2762. warning("JSR 292 is not supported before 1.7. Disabling support.");
  2763. }
  2764. EnableInvokeDynamic = false;
  2765. }
  2766. }
  2767. if (EnableInvokeDynamic && ScavengeRootsInCode == 0) {
  2768. if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
  2769. warning("forcing ScavengeRootsInCode non-zero because EnableInvokeDynamic is true");
  2770. }
  2771. ScavengeRootsInCode = 1;
  2772. }
  2773. if (!JavaObjectsInPerm && ScavengeRootsInCode == 0) {
  2774. if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
  2775. warning("forcing ScavengeRootsInCode non-zero because JavaObjectsInPerm is false");
  2776. }
  2777. ScavengeRootsInCode = 1;
  2778. }
  2779. if (PrintGCDetails) {
  2780. // Turn on -verbose:gc options as well
  2781. PrintGC = true;
  2782. }
  2783. // Set object alignment values.
  2784. set_object_alignment();
  2785. #ifdef SERIALGC
  2786. force_serial_gc();
  2787. #endif // SERIALGC
  2788. #ifdef KERNEL
  2789. no_shared_spaces();
  2790. #endif // KERNEL
  2791. // Set flags based on ergonomics.
  2792. set_ergonomics_flags();
  2793. set_shared_spaces_flags();
  2794. // Check the GC selections again.
  2795. if (!check_gc_consistency()) {
  2796. return JNI_EINVAL;
  2797. }
  2798. if (TieredCompilation) {
  2799. set_tiered_flags();
  2800. } else {
  2801. // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup.
  2802. if (CompilationPolicyChoice >= 2) {
  2803. vm_exit_during_initialization(
  2804. "Incompatible compilation policy selected", NULL);
  2805. }
  2806. }
  2807. #ifndef KERNEL
  2808. // Set heap size based on available physical memory
  2809. set_heap_size();
  2810. // Set per-collector flags
  2811. if (UseParallelGC || UseParallelOldGC) {
  2812. set_parallel_gc_flags();
  2813. } else if (UseConcMarkSweepGC) { // should be done before ParNew check below
  2814. set_cms_and_parnew_gc_flags();
  2815. } else if (UseParNewGC) { // skipped if CMS is set above
  2816. set_parnew_gc_flags();
  2817. } else if (UseG1GC) {
  2818. set_g1_gc_flags();
  2819. }
  2820. #endif // KERNEL
  2821. #ifdef SERIALGC
  2822. assert(verify_serial_gc_flags(), "SerialGC unset");
  2823. #endif // SERIALGC
  2824. // Set bytecode rewriting flags
  2825. set_bytecode_flags();
  2826. // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
  2827. set_aggressive_opts_flags();
  2828. // Turn off biased locking for locking debug mode flags,
  2829. // which are subtlely different from each other but neither works with
  2830. // biased locking.
  2831. if (UseHeavyMonitors
  2832. #ifdef COMPILER1
  2833. || !UseFastLocking
  2834. #endif // COMPILER1
  2835. ) {
  2836. if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) {
  2837. // flag set to true on command line; warn the user that they
  2838. // can't enable biased locking here
  2839. warning("Biased Locking is not supported with locking debug flags"
  2840. "; ignoring UseBiasedLocking flag." );
  2841. }
  2842. UseBiasedLocking = false;
  2843. }
  2844. #ifdef CC_INTERP
  2845. // Clear flags not supported by the C++ interpreter
  2846. FLAG_SET_DEFAULT(ProfileInterpreter, false);
  2847. FLAG_SET_DEFAULT(UseBiasedLocking, false);
  2848. LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false));
  2849. #endif // CC_INTERP
  2850. #ifdef COMPILER2
  2851. if (!UseBiasedLocking || EmitSync != 0) {
  2852. UseOptoBiasInlining = false;
  2853. }
  2854. if (!EliminateLocks) {
  2855. EliminateNestedLocks = false;
  2856. }
  2857. #endif
  2858. if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
  2859. warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
  2860. DebugNonSafepoints = true;
  2861. }
  2862. #ifndef PRODUCT
  2863. if (CompileTheWorld) {
  2864. // Force NmethodSweeper to sweep whole CodeCache each time.
  2865. if (FLAG_IS_DEFAULT(NmethodSweepFraction)) {
  2866. NmethodSweepFraction = 1;
  2867. }
  2868. }
  2869. #endif
  2870. if (PrintCommandLineFlags) {
  2871. CommandLineFlags::printSetFlags(tty);
  2872. }
  2873. // Apply CPU specific policy for the BiasedLocking
  2874. if (UseBiasedLocking) {
  2875. if (!VM_Version::use_biased_locking() &&
  2876. !(FLAG_IS_CMDLINE(UseBiasedLocking))) {
  2877. UseBiasedLocking = false;
  2878. }
  2879. }
  2880. // set PauseAtExit if the gamma launcher was used and a debugger is attached
  2881. // but only if not already set on the commandline
  2882. if (Arguments::created_by_gamma_launcher() && os::is_debugger_attached()) {
  2883. bool set = false;
  2884. CommandLineFlags::wasSetOnCmdline("PauseAtExit", &set);
  2885. if (!set) {
  2886. FLAG_SET_DEFAULT(PauseAtExit, true);
  2887. }
  2888. }
  2889. return JNI_OK;
  2890. }
  2891. int Arguments::PropertyList_count(SystemProperty* pl) {
  2892. int count = 0;
  2893. while(pl != NULL) {
  2894. count++;
  2895. pl = pl->next();
  2896. }
  2897. return count;
  2898. }
  2899. const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) {
  2900. assert(key != NULL, "just checking");
  2901. SystemProperty* prop;
  2902. for (prop = pl; prop != NULL; prop = prop->next()) {
  2903. if (strcmp(key, prop->key()) == 0) return prop->value();
  2904. }
  2905. return NULL;
  2906. }
  2907. const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) {
  2908. int count = 0;
  2909. const char* ret_val = NULL;
  2910. while(pl != NULL) {
  2911. if(count >= index) {
  2912. ret_val = pl->key();
  2913. break;
  2914. }
  2915. count++;
  2916. pl = pl->next();
  2917. }
  2918. return ret_val;
  2919. }
  2920. char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) {
  2921. int count = 0;
  2922. char* ret_val = NULL;
  2923. while(pl != NULL) {
  2924. if(count >= index) {
  2925. ret_val = pl->value();
  2926. break;
  2927. }
  2928. count++;
  2929. pl = pl->next();
  2930. }
  2931. return ret_val;
  2932. }
  2933. void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) {
  2934. SystemProperty* p = *plist;
  2935. if (p == NULL) {
  2936. *plist = new_p;
  2937. } else {
  2938. while (p->next() != NULL) {
  2939. p = p->next();
  2940. }
  2941. p->set_next(new_p);
  2942. }
  2943. }
  2944. void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) {
  2945. if (plist == NULL)
  2946. return;
  2947. SystemProperty* new_p = new SystemProperty(k, v, true);
  2948. PropertyList_add(plist, new_p);
  2949. }
  2950. // This add maintains unique property key in the list.
  2951. void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) {
  2952. if (plist == NULL)
  2953. return;
  2954. // If property key exist then update with new value.
  2955. SystemProperty* prop;
  2956. for (prop = *plist; prop != NULL; prop = prop->next()) {
  2957. if (strcmp(k, prop->key()) == 0) {
  2958. if (append) {
  2959. prop->append_value(v);
  2960. } else {
  2961. prop->set_value(v);
  2962. }
  2963. return;
  2964. }
  2965. }
  2966. PropertyList_add(plist, k, v);
  2967. }
  2968. #ifdef KERNEL
  2969. char *Arguments::get_kernel_properties() {
  2970. // Find properties starting with kernel and append them to string
  2971. // We need to find out how long they are first because the URL's that they
  2972. // might point to could get long.
  2973. int length = 0;
  2974. SystemProperty* prop;
  2975. for (prop = _system_properties; prop != NULL; prop = prop->next()) {
  2976. if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
  2977. length += (strlen(prop->key()) + strlen(prop->value()) + 5); // "-D ="
  2978. }
  2979. }
  2980. // Add one for null terminator.
  2981. char *props = AllocateHeap(length + 1, "get_kernel_properties");
  2982. if (length != 0) {
  2983. int pos = 0;
  2984. for (prop = _system_properties; prop != NULL; prop = prop->next()) {
  2985. if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
  2986. jio_snprintf(&props[pos], length-pos,
  2987. "-D%s=%s ", prop->key(), prop->value());
  2988. pos = strlen(props);
  2989. }
  2990. }
  2991. }
  2992. // null terminate props in case of null
  2993. props[length] = '\0';
  2994. return props;
  2995. }
  2996. #endif // KERNEL
  2997. // Copies src into buf, replacing "%%" with "%" and "%p" with pid
  2998. // Returns true if all of the source pointed by src has been copied over to
  2999. // the destination buffer pointed by buf. Otherwise, returns false.
  3000. // Notes:
  3001. // 1. If the length (buflen) of the destination buffer excluding the
  3002. // NULL terminator character is not long enough for holding the expanded
  3003. // pid characters, it also returns false instead of returning the partially
  3004. // expanded one.
  3005. // 2. The passed in "buflen" should be large enough to hold the null terminator.
  3006. bool Arguments::copy_expand_pid(const char* src, size_t srclen,
  3007. char* buf, size_t buflen) {
  3008. const char* p = src;
  3009. char* b = buf;
  3010. const char* src_end = &src[srclen];
  3011. char* buf_end = &buf[buflen - 1];
  3012. while (p < src_end && b < buf_end) {
  3013. if (*p == '%') {
  3014. switch (*(++p)) {
  3015. case '%': // "%%" ==> "%"
  3016. *b++ = *p++;
  3017. break;
  3018. case 'p': { // "%p" ==> current process id
  3019. // buf_end points to the character before the last character so
  3020. // that we could write '\0' to the end of the buffer.
  3021. size_t buf_sz = buf_end - b + 1;
  3022. int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id());
  3023. // if jio_snprintf fails or the buffer is not long enough to hold
  3024. // the expanded pid, returns false.
  3025. if (ret < 0 || ret >= (int)buf_sz) {
  3026. return false;
  3027. } else {
  3028. b += ret;
  3029. assert(*b == '\0', "fail in copy_expand_pid");
  3030. if (p == src_end && b == buf_end + 1) {
  3031. // reach the end of the buffer.
  3032. return true;
  3033. }
  3034. }
  3035. p++;
  3036. break;
  3037. }
  3038. default :
  3039. *b++ = '%';
  3040. }
  3041. } else {
  3042. *b++ = *p++;
  3043. }
  3044. }
  3045. *b = '\0';
  3046. return (p == src_end); // return false if not all of the source was copied
  3047. }