src/share/vm/runtime/arguments.cpp

Print this page




  98 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  99 int    Arguments::_sun_java_launcher_pid        = -1;
 100 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
 101 
 102 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
 103 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
 104 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
 105 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
 106 bool   Arguments::_ClipInlining                 = ClipInlining;
 107 
 108 char*  Arguments::SharedArchivePath             = NULL;
 109 
 110 AgentLibraryList Arguments::_libraryList;
 111 AgentLibraryList Arguments::_agentList;
 112 
 113 abort_hook_t     Arguments::_abort_hook         = NULL;
 114 exit_hook_t      Arguments::_exit_hook          = NULL;
 115 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
 116 
 117 
 118 SystemProperty *Arguments::_java_ext_dirs = NULL;
 119 SystemProperty *Arguments::_java_endorsed_dirs = NULL;
 120 SystemProperty *Arguments::_sun_boot_library_path = NULL;
 121 SystemProperty *Arguments::_java_library_path = NULL;
 122 SystemProperty *Arguments::_java_home = NULL;
 123 SystemProperty *Arguments::_java_class_path = NULL;
 124 SystemProperty *Arguments::_sun_boot_class_path = NULL;
 125 
 126 char* Arguments::_meta_index_path = NULL;
 127 char* Arguments::_meta_index_dir = NULL;

 128 
 129 // Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
 130 
 131 static bool match_option(const JavaVMOption *option, const char* name,
 132                          const char** tail) {
 133   int len = (int)strlen(name);
 134   if (strncmp(option->optionString, name, len) == 0) {
 135     *tail = option->optionString + len;
 136     return true;
 137   } else {
 138     return false;
 139   }
 140 }
 141 
 142 static void logOption(const char* opt) {
 143   if (PrintVMOptions) {
 144     jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
 145   }
 146 }
 147 


 167     }
 168     if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
 169       _sun_java_launcher_pid = atoi(tail);
 170       continue;
 171     }
 172   }
 173 }
 174 
 175 // Initialize system properties key and value.
 176 void Arguments::init_system_properties() {
 177 
 178   PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
 179                                                                  "Java Virtual Machine Specification",  false));
 180   PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(),  false));
 181   PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(),  false));
 182   PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(),  true));
 183 
 184   // Following are JVMTI agent writable properties.
 185   // Properties values are set to NULL and they are
 186   // os specific they are initialized in os::init_system_properties_values().
 187   _java_ext_dirs = new SystemProperty("java.ext.dirs", NULL,  true);
 188   _java_endorsed_dirs = new SystemProperty("java.endorsed.dirs", NULL,  true);
 189   _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL,  true);
 190   _java_library_path = new SystemProperty("java.library.path", NULL,  true);
 191   _java_home =  new SystemProperty("java.home", NULL,  true);
 192   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
 193 
 194   _java_class_path = new SystemProperty("java.class.path", "",  true);
 195 
 196   // Add to System Property list.
 197   PropertyList_add(&_system_properties, _java_ext_dirs);
 198   PropertyList_add(&_system_properties, _java_endorsed_dirs);
 199   PropertyList_add(&_system_properties, _sun_boot_library_path);
 200   PropertyList_add(&_system_properties, _java_library_path);
 201   PropertyList_add(&_system_properties, _java_home);
 202   PropertyList_add(&_system_properties, _java_class_path);
 203   PropertyList_add(&_system_properties, _sun_boot_class_path);
 204 
 205   // Set OS specific system properties values
 206   os::init_system_properties_values();
 207 }
 208 
 209 
 210   // Update/Initialize System properties after JDK version number is known
 211 void Arguments::init_version_specific_system_properties() {
 212   enum { bufsz = 16 };
 213   char buffer[bufsz];
 214   const char* spec_vendor = "Sun Microsystems Inc.";
 215   uint32_t spec_version = 0;
 216 
 217   spec_vendor = "Oracle Corporation";
 218   spec_version = JDK_Version::current().major_version();


 327     const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
 328     // <flag>=xxx form
 329     // [-|+]<flag> form
 330     if ((strncmp(flag_status.name, s, strlen(flag_status.name)) == 0) ||
 331         ((s[0] == '+' || s[0] == '-') &&
 332         (strncmp(flag_status.name, &s[1], strlen(flag_status.name)) == 0))) {
 333       if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
 334           *version = flag_status.obsoleted_in;
 335           return true;
 336       }
 337     }
 338     i++;
 339   }
 340   return false;
 341 }
 342 
 343 // Constructs the system class path (aka boot class path) from the following
 344 // components, in order:
 345 //
 346 //     prefix           // from -Xbootclasspath/p:...
 347 //     endorsed         // the expansion of -Djava.endorsed.dirs=...
 348 //     base             // from os::get_system_properties() or -Xbootclasspath=
 349 //     suffix           // from -Xbootclasspath/a:...
 350 //
 351 // java.endorsed.dirs is a list of directories; any jar or zip files in the
 352 // directories are added to the sysclasspath just before the base.
 353 //
 354 // This could be AllStatic, but it isn't needed after argument processing is
 355 // complete.
 356 class SysClassPath: public StackObj {
 357 public:
 358   SysClassPath(const char* base);
 359   ~SysClassPath();
 360 
 361   inline void set_base(const char* base);
 362   inline void add_prefix(const char* prefix);
 363   inline void add_suffix_to_prefix(const char* suffix);
 364   inline void add_suffix(const char* suffix);
 365   inline void reset_path(const char* base);
 366 
 367   // Expand the jar/zip files in each directory listed by the java.endorsed.dirs
 368   // property.  Must be called after all command-line arguments have been
 369   // processed (in particular, -Djava.endorsed.dirs=...) and before calling
 370   // combined_path().
 371   void expand_endorsed();
 372 
 373   inline const char* get_base()     const { return _items[_scp_base]; }
 374   inline const char* get_prefix()   const { return _items[_scp_prefix]; }
 375   inline const char* get_suffix()   const { return _items[_scp_suffix]; }
 376   inline const char* get_endorsed() const { return _items[_scp_endorsed]; }
 377 
 378   // Combine all the components into a single c-heap-allocated string; caller
 379   // must free the string if/when no longer needed.
 380   char* combined_path();
 381 
 382 private:
 383   // Utility routines.
 384   static char* add_to_path(const char* path, const char* str, bool prepend);
 385   static char* add_jars_to_path(char* path, const char* directory);
 386 
 387   inline void reset_item_at(int index);
 388 
 389   // Array indices for the items that make up the sysclasspath.  All except the
 390   // base are allocated in the C heap and freed by this class.
 391   enum {
 392     _scp_prefix,        // from -Xbootclasspath/p:...
 393     _scp_endorsed,      // the expansion of -Djava.endorsed.dirs=...
 394     _scp_base,          // the default sysclasspath
 395     _scp_suffix,        // from -Xbootclasspath/a:...
 396     _scp_nitems         // the number of items, must be last.
 397   };
 398 
 399   const char* _items[_scp_nitems];
 400   DEBUG_ONLY(bool _expansion_done;)
 401 };
 402 
 403 SysClassPath::SysClassPath(const char* base) {
 404   memset(_items, 0, sizeof(_items));
 405   _items[_scp_base] = base;
 406   DEBUG_ONLY(_expansion_done = false;)
 407 }
 408 
 409 SysClassPath::~SysClassPath() {
 410   // Free everything except the base.
 411   for (int i = 0; i < _scp_nitems; ++i) {
 412     if (i != _scp_base) reset_item_at(i);
 413   }
 414   DEBUG_ONLY(_expansion_done = false;)
 415 }
 416 
 417 inline void SysClassPath::set_base(const char* base) {
 418   _items[_scp_base] = base;
 419 }
 420 
 421 inline void SysClassPath::add_prefix(const char* prefix) {
 422   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
 423 }
 424 
 425 inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
 426   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
 427 }
 428 
 429 inline void SysClassPath::add_suffix(const char* suffix) {
 430   _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
 431 }
 432 
 433 inline void SysClassPath::reset_item_at(int index) {
 434   assert(index < _scp_nitems && index != _scp_base, "just checking");
 435   if (_items[index] != NULL) {
 436     FREE_C_HEAP_ARRAY(char, _items[index], mtInternal);
 437     _items[index] = NULL;
 438   }
 439 }
 440 
 441 inline void SysClassPath::reset_path(const char* base) {
 442   // Clear the prefix and suffix.
 443   reset_item_at(_scp_prefix);
 444   reset_item_at(_scp_suffix);
 445   set_base(base);
 446 }
 447 
 448 //------------------------------------------------------------------------------
 449 
 450 void SysClassPath::expand_endorsed() {
 451   assert(_items[_scp_endorsed] == NULL, "can only be called once.");
 452 
 453   const char* path = Arguments::get_property("java.endorsed.dirs");
 454   if (path == NULL) {
 455     path = Arguments::get_endorsed_dir();
 456     assert(path != NULL, "no default for java.endorsed.dirs");
 457   }
 458 
 459   char* expanded_path = NULL;
 460   const char separator = *os::path_separator();
 461   const char* const end = path + strlen(path);
 462   while (path < end) {
 463     const char* tmp_end = strchr(path, separator);
 464     if (tmp_end == NULL) {
 465       expanded_path = add_jars_to_path(expanded_path, path);
 466       path = end;
 467     } else {
 468       char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal);
 469       memcpy(dirpath, path, tmp_end - path);
 470       dirpath[tmp_end - path] = '\0';
 471       expanded_path = add_jars_to_path(expanded_path, dirpath);
 472       FREE_C_HEAP_ARRAY(char, dirpath, mtInternal);
 473       path = tmp_end + 1;
 474     }
 475   }
 476   _items[_scp_endorsed] = expanded_path;
 477   DEBUG_ONLY(_expansion_done = true;)
 478 }
 479 
 480 // Combine the bootclasspath elements, some of which may be null, into a single
 481 // c-heap-allocated string.
 482 char* SysClassPath::combined_path() {
 483   assert(_items[_scp_base] != NULL, "empty default sysclasspath");
 484   assert(_expansion_done, "must call expand_endorsed() first.");
 485 
 486   size_t lengths[_scp_nitems];
 487   size_t total_len = 0;
 488 
 489   const char separator = *os::path_separator();
 490 
 491   // Get the lengths.
 492   int i;
 493   for (i = 0; i < _scp_nitems; ++i) {
 494     if (_items[i] != NULL) {
 495       lengths[i] = strlen(_items[i]);
 496       // Include space for the separator char (or a NULL for the last item).
 497       total_len += lengths[i] + 1;
 498     }
 499   }
 500   assert(total_len > 0, "empty sysclasspath not allowed");
 501 
 502   // Copy the _items to a single string.
 503   char* cp = NEW_C_HEAP_ARRAY(char, total_len, mtInternal);
 504   char* cp_tmp = cp;


3067     } else if (match_option(option, "-Xconcurrentio", &tail)) {
3068       FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
3069       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
3070       FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
3071       FLAG_SET_CMDLINE(bool, UseTLAB, false);
3072       FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K);  // 20Kb per thread added to new generation
3073 
3074       // -Xinternalversion
3075     } else if (match_option(option, "-Xinternalversion", &tail)) {
3076       jio_fprintf(defaultStream::output_stream(), "%s\n",
3077                   VM_Version::internal_vm_info_string());
3078       vm_exit(0);
3079 #ifndef PRODUCT
3080     // -Xprintflags
3081     } else if (match_option(option, "-Xprintflags", &tail)) {
3082       CommandLineFlags::printFlags(tty, false);
3083       vm_exit(0);
3084 #endif
3085     // -D
3086     } else if (match_option(option, "-D", &tail)) {














3087       if (!add_property(tail)) {
3088         return JNI_ENOMEM;
3089       }
3090       // Out of the box management support
3091       if (match_option(option, "-Dcom.sun.management", &tail)) {
3092 #if INCLUDE_MANAGEMENT
3093         FLAG_SET_CMDLINE(bool, ManagementServer, true);
3094 #else
3095         jio_fprintf(defaultStream::output_stream(),
3096           "-Dcom.sun.management is not supported in this VM.\n");
3097         return JNI_ERR;
3098 #endif
3099       }
3100     // -Xint
3101     } else if (match_option(option, "-Xint", &tail)) {
3102           set_mode_flags(_int);
3103     // -Xmixed
3104     } else if (match_option(option, "-Xmixed", &tail)) {
3105           set_mode_flags(_mixed);
3106     // -Xcomp


3512     for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
3513       *tail = '\0';
3514     }
3515 
3516     char from[3] = {separator, separator, '\0'};
3517     char to  [2] = {separator, '\0'};
3518     while (StringUtils::replace_no_expand(copy, from, to) > 0) {
3519       // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
3520       // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
3521     }
3522 
3523     _java_class_path->set_value(copy);
3524     FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
3525   }
3526 
3527   if (!PrintSharedArchiveAndExit) {
3528     ClassLoader::trace_class_path("[classpath: ", _java_class_path->value());
3529   }
3530 }
3531 














































3532 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
3533   // This must be done after all -D arguments have been processed.
3534   scp_p->expand_endorsed();
































3535 
3536   if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
3537     // Assemble the bootclasspath elements into the final path.
3538     Arguments::set_sysclasspath(scp_p->combined_path());
3539   }
3540 
3541   // This must be done after all arguments have been processed.
3542   // java_compiler() true means set to "NONE" or empty.
3543   if (java_compiler() && !xdebug_mode()) {
3544     // For backwards compatibility, we switch to interpreted mode if
3545     // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
3546     // not specified.
3547     set_mode_flags(_int);
3548   }
3549 
3550   if ((TieredCompilation && CompileThresholdScaling == 0)
3551       || (!TieredCompilation && get_scaled_compile_threshold(CompileThreshold) == 0)) {
3552     set_mode_flags(_int);
3553   }
3554 
3555   // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set
3556   if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) {




  98 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  99 int    Arguments::_sun_java_launcher_pid        = -1;
 100 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
 101 
 102 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
 103 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
 104 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
 105 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
 106 bool   Arguments::_ClipInlining                 = ClipInlining;
 107 
 108 char*  Arguments::SharedArchivePath             = NULL;
 109 
 110 AgentLibraryList Arguments::_libraryList;
 111 AgentLibraryList Arguments::_agentList;
 112 
 113 abort_hook_t     Arguments::_abort_hook         = NULL;
 114 exit_hook_t      Arguments::_exit_hook          = NULL;
 115 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
 116 
 117 


 118 SystemProperty *Arguments::_sun_boot_library_path = NULL;
 119 SystemProperty *Arguments::_java_library_path = NULL;
 120 SystemProperty *Arguments::_java_home = NULL;
 121 SystemProperty *Arguments::_java_class_path = NULL;
 122 SystemProperty *Arguments::_sun_boot_class_path = NULL;
 123 
 124 char* Arguments::_meta_index_path = NULL;
 125 char* Arguments::_meta_index_dir = NULL;
 126 char* Arguments::_ext_dirs = NULL;
 127 
 128 // Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
 129 
 130 static bool match_option(const JavaVMOption *option, const char* name,
 131                          const char** tail) {
 132   int len = (int)strlen(name);
 133   if (strncmp(option->optionString, name, len) == 0) {
 134     *tail = option->optionString + len;
 135     return true;
 136   } else {
 137     return false;
 138   }
 139 }
 140 
 141 static void logOption(const char* opt) {
 142   if (PrintVMOptions) {
 143     jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
 144   }
 145 }
 146 


 166     }
 167     if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
 168       _sun_java_launcher_pid = atoi(tail);
 169       continue;
 170     }
 171   }
 172 }
 173 
 174 // Initialize system properties key and value.
 175 void Arguments::init_system_properties() {
 176 
 177   PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
 178                                                                  "Java Virtual Machine Specification",  false));
 179   PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(),  false));
 180   PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(),  false));
 181   PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(),  true));
 182 
 183   // Following are JVMTI agent writable properties.
 184   // Properties values are set to NULL and they are
 185   // os specific they are initialized in os::init_system_properties_values().


 186   _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL,  true);
 187   _java_library_path = new SystemProperty("java.library.path", NULL,  true);
 188   _java_home =  new SystemProperty("java.home", NULL,  true);
 189   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
 190 
 191   _java_class_path = new SystemProperty("java.class.path", "",  true);
 192 
 193   // Add to System Property list.


 194   PropertyList_add(&_system_properties, _sun_boot_library_path);
 195   PropertyList_add(&_system_properties, _java_library_path);
 196   PropertyList_add(&_system_properties, _java_home);
 197   PropertyList_add(&_system_properties, _java_class_path);
 198   PropertyList_add(&_system_properties, _sun_boot_class_path);
 199 
 200   // Set OS specific system properties values
 201   os::init_system_properties_values();
 202 }
 203 
 204 
 205   // Update/Initialize System properties after JDK version number is known
 206 void Arguments::init_version_specific_system_properties() {
 207   enum { bufsz = 16 };
 208   char buffer[bufsz];
 209   const char* spec_vendor = "Sun Microsystems Inc.";
 210   uint32_t spec_version = 0;
 211 
 212   spec_vendor = "Oracle Corporation";
 213   spec_version = JDK_Version::current().major_version();


 322     const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
 323     // <flag>=xxx form
 324     // [-|+]<flag> form
 325     if ((strncmp(flag_status.name, s, strlen(flag_status.name)) == 0) ||
 326         ((s[0] == '+' || s[0] == '-') &&
 327         (strncmp(flag_status.name, &s[1], strlen(flag_status.name)) == 0))) {
 328       if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
 329           *version = flag_status.obsoleted_in;
 330           return true;
 331       }
 332     }
 333     i++;
 334   }
 335   return false;
 336 }
 337 
 338 // Constructs the system class path (aka boot class path) from the following
 339 // components, in order:
 340 //
 341 //     prefix           // from -Xbootclasspath/p:...

 342 //     base             // from os::get_system_properties() or -Xbootclasspath=
 343 //     suffix           // from -Xbootclasspath/a:...
 344 //



 345 // This could be AllStatic, but it isn't needed after argument processing is
 346 // complete.
 347 class SysClassPath: public StackObj {
 348 public:
 349   SysClassPath(const char* base);
 350   ~SysClassPath();
 351 
 352   inline void set_base(const char* base);
 353   inline void add_prefix(const char* prefix);
 354   inline void add_suffix_to_prefix(const char* suffix);
 355   inline void add_suffix(const char* suffix);
 356   inline void reset_path(const char* base);
 357 






 358   inline const char* get_base()     const { return _items[_scp_base]; }
 359   inline const char* get_prefix()   const { return _items[_scp_prefix]; }
 360   inline const char* get_suffix()   const { return _items[_scp_suffix]; }

 361 
 362   // Combine all the components into a single c-heap-allocated string; caller
 363   // must free the string if/when no longer needed.
 364   char* combined_path();
 365 
 366 private:
 367   // Utility routines.
 368   static char* add_to_path(const char* path, const char* str, bool prepend);
 369   static char* add_jars_to_path(char* path, const char* directory);
 370 
 371   inline void reset_item_at(int index);
 372 
 373   // Array indices for the items that make up the sysclasspath.  All except the
 374   // base are allocated in the C heap and freed by this class.
 375   enum {
 376     _scp_prefix,        // from -Xbootclasspath/p:...

 377     _scp_base,          // the default sysclasspath
 378     _scp_suffix,        // from -Xbootclasspath/a:...
 379     _scp_nitems         // the number of items, must be last.
 380   };
 381 
 382   const char* _items[_scp_nitems];

 383 };
 384 
 385 SysClassPath::SysClassPath(const char* base) {
 386   memset(_items, 0, sizeof(_items));
 387   _items[_scp_base] = base;

 388 }
 389 
 390 SysClassPath::~SysClassPath() {
 391   // Free everything except the base.
 392   for (int i = 0; i < _scp_nitems; ++i) {
 393     if (i != _scp_base) reset_item_at(i);
 394   }

 395 }
 396 
 397 inline void SysClassPath::set_base(const char* base) {
 398   _items[_scp_base] = base;
 399 }
 400 
 401 inline void SysClassPath::add_prefix(const char* prefix) {
 402   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
 403 }
 404 
 405 inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
 406   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
 407 }
 408 
 409 inline void SysClassPath::add_suffix(const char* suffix) {
 410   _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
 411 }
 412 
 413 inline void SysClassPath::reset_item_at(int index) {
 414   assert(index < _scp_nitems && index != _scp_base, "just checking");
 415   if (_items[index] != NULL) {
 416     FREE_C_HEAP_ARRAY(char, _items[index], mtInternal);
 417     _items[index] = NULL;
 418   }
 419 }
 420 
 421 inline void SysClassPath::reset_path(const char* base) {
 422   // Clear the prefix and suffix.
 423   reset_item_at(_scp_prefix);
 424   reset_item_at(_scp_suffix);
 425   set_base(base);
 426 }
 427 
 428 //------------------------------------------------------------------------------
 429 





























 430 
 431 // Combine the bootclasspath elements, some of which may be null, into a single
 432 // c-heap-allocated string.
 433 char* SysClassPath::combined_path() {
 434   assert(_items[_scp_base] != NULL, "empty default sysclasspath");

 435 
 436   size_t lengths[_scp_nitems];
 437   size_t total_len = 0;
 438 
 439   const char separator = *os::path_separator();
 440 
 441   // Get the lengths.
 442   int i;
 443   for (i = 0; i < _scp_nitems; ++i) {
 444     if (_items[i] != NULL) {
 445       lengths[i] = strlen(_items[i]);
 446       // Include space for the separator char (or a NULL for the last item).
 447       total_len += lengths[i] + 1;
 448     }
 449   }
 450   assert(total_len > 0, "empty sysclasspath not allowed");
 451 
 452   // Copy the _items to a single string.
 453   char* cp = NEW_C_HEAP_ARRAY(char, total_len, mtInternal);
 454   char* cp_tmp = cp;


3017     } else if (match_option(option, "-Xconcurrentio", &tail)) {
3018       FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
3019       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
3020       FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
3021       FLAG_SET_CMDLINE(bool, UseTLAB, false);
3022       FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K);  // 20Kb per thread added to new generation
3023 
3024       // -Xinternalversion
3025     } else if (match_option(option, "-Xinternalversion", &tail)) {
3026       jio_fprintf(defaultStream::output_stream(), "%s\n",
3027                   VM_Version::internal_vm_info_string());
3028       vm_exit(0);
3029 #ifndef PRODUCT
3030     // -Xprintflags
3031     } else if (match_option(option, "-Xprintflags", &tail)) {
3032       CommandLineFlags::printFlags(tty, false);
3033       vm_exit(0);
3034 #endif
3035     // -D
3036     } else if (match_option(option, "-D", &tail)) {
3037       if (match_option(option, "-Djava.endorsed.dirs=", &tail)) {
3038         // abort if -Djava.endorsed.dirs is set
3039         jio_fprintf(defaultStream::output_stream(),
3040           "-Djava.endorsed.dirs is not supported. Endorsed standards and standalone APIs\n"
3041           "in modular form will be supported via the concept of upgradeable modules.\n");
3042         return JNI_EINVAL;
3043       }
3044       if (match_option(option, "-Djava.ext.dirs=", &tail)) {
3045         // abort if -Djava.ext.dirs is set
3046         jio_fprintf(defaultStream::output_stream(),
3047           "-Djava.ext.dirs is not supported.  Use -classpath instead.\n");
3048         return JNI_EINVAL;
3049       }
3050 
3051       if (!add_property(tail)) {
3052         return JNI_ENOMEM;
3053       }
3054       // Out of the box management support
3055       if (match_option(option, "-Dcom.sun.management", &tail)) {
3056 #if INCLUDE_MANAGEMENT
3057         FLAG_SET_CMDLINE(bool, ManagementServer, true);
3058 #else
3059         jio_fprintf(defaultStream::output_stream(),
3060           "-Dcom.sun.management is not supported in this VM.\n");
3061         return JNI_ERR;
3062 #endif
3063       }
3064     // -Xint
3065     } else if (match_option(option, "-Xint", &tail)) {
3066           set_mode_flags(_int);
3067     // -Xmixed
3068     } else if (match_option(option, "-Xmixed", &tail)) {
3069           set_mode_flags(_mixed);
3070     // -Xcomp


3476     for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
3477       *tail = '\0';
3478     }
3479 
3480     char from[3] = {separator, separator, '\0'};
3481     char to  [2] = {separator, '\0'};
3482     while (StringUtils::replace_no_expand(copy, from, to) > 0) {
3483       // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
3484       // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
3485     }
3486 
3487     _java_class_path->set_value(copy);
3488     FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
3489   }
3490 
3491   if (!PrintSharedArchiveAndExit) {
3492     ClassLoader::trace_class_path("[classpath: ", _java_class_path->value());
3493   }
3494 }
3495 
3496 static bool has_jar_files(const char* directory) {
3497   DIR* dir = os::opendir(directory);
3498   if (dir == NULL) return false;
3499 
3500   struct dirent *entry;
3501   char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal);
3502   bool hasJarFile = false;
3503   while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
3504     const char* name = entry->d_name;
3505     const char* ext = name + strlen(name) - 4;
3506     hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0);
3507   }
3508   FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
3509   os::closedir(dir);
3510   return hasJarFile ;
3511 }
3512 
3513 static int check_non_empty_dirs(const char* path) {
3514   const char separator = *os::path_separator();
3515   const char* const end = path + strlen(path);
3516   int nonEmptyDirs = 0;
3517   while (path < end) {
3518     const char* tmp_end = strchr(path, separator);
3519     if (tmp_end == NULL) {
3520       if (has_jar_files(path)) {
3521         nonEmptyDirs++;
3522         jio_fprintf(defaultStream::output_stream(),
3523           "Non-empty directory: %s\n", path);
3524       }
3525       path = end;
3526     } else {
3527       char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal);
3528       memcpy(dirpath, path, tmp_end - path);
3529       dirpath[tmp_end - path] = '\0';
3530       if (has_jar_files(dirpath)) {
3531         nonEmptyDirs++;
3532         jio_fprintf(defaultStream::output_stream(),
3533           "Non-empty directory: %s\n", dirpath);
3534       }
3535       FREE_C_HEAP_ARRAY(char, dirpath, mtInternal);
3536       path = tmp_end + 1;
3537     }
3538   }
3539   return nonEmptyDirs;
3540 }
3541 
3542 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
3543   // check if the default lib/endorsed directory exists; if so, error
3544   char path[JVM_MAXPATHLEN];
3545   const char* fileSep = os::file_separator();
3546   sprintf(path, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
3547 
3548   if (CheckEndorsedAndExtDirs) {
3549     int nonEmptyDirs = 0;
3550     // check endorsed directory
3551     nonEmptyDirs += check_non_empty_dirs(path);
3552     // check the extension directories
3553     nonEmptyDirs += check_non_empty_dirs(Arguments::get_ext_dirs());
3554     if (nonEmptyDirs > 0) {
3555       return JNI_ERR;
3556     }
3557   }
3558 
3559   DIR* dir = os::opendir(path);
3560   if (dir != NULL) {
3561     jio_fprintf(defaultStream::output_stream(),
3562       "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
3563       "in modular form will be supported via the concept of upgradeable modules.\n");
3564     os::closedir(dir);
3565     return JNI_ERR;
3566   }
3567 
3568   sprintf(path, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
3569   dir = os::opendir(path);
3570   if (dir != NULL) {
3571     jio_fprintf(defaultStream::output_stream(),
3572       "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
3573       "Use -classpath instead.\n.");
3574     os::closedir(dir);
3575     return JNI_ERR;
3576   }
3577 
3578   if (scp_assembly_required) {
3579     // Assemble the bootclasspath elements into the final path.
3580     Arguments::set_sysclasspath(scp_p->combined_path());
3581   }
3582 
3583   // This must be done after all arguments have been processed.
3584   // java_compiler() true means set to "NONE" or empty.
3585   if (java_compiler() && !xdebug_mode()) {
3586     // For backwards compatibility, we switch to interpreted mode if
3587     // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
3588     // not specified.
3589     set_mode_flags(_int);
3590   }
3591 
3592   if ((TieredCompilation && CompileThresholdScaling == 0)
3593       || (!TieredCompilation && get_scaled_compile_threshold(CompileThreshold) == 0)) {
3594     set_mode_flags(_int);
3595   }
3596 
3597   // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set
3598   if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) {