PageRenderTime 53ms CodeModel.GetById 19ms 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

Large files files are truncated, but you can click here to view the full file

  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_s

Large files files are truncated, but you can click here to view the full file