486 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
487 char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
488 DIR* dir = os::opendir(directory);
489 if (dir == NULL) return path;
490
491 char dir_sep[2] = { '\0', '\0' };
492 size_t directory_len = strlen(directory);
493 const char fileSep = *os::file_separator();
494 if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
495
496 /* Scan the directory for jars/zips, appending them to path. */
497 struct dirent *entry;
498 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory));
499 while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
500 const char* name = entry->d_name;
501 const char* ext = name + strlen(name) - 4;
502 bool isJarOrZip = ext > name &&
503 (os::file_name_strcmp(ext, ".jar") == 0 ||
504 os::file_name_strcmp(ext, ".zip") == 0);
505 if (isJarOrZip) {
506 char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name));
507 sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
508 path = add_to_path(path, jarpath, false);
509 FREE_C_HEAP_ARRAY(char, jarpath);
510 }
511 }
512 FREE_C_HEAP_ARRAY(char, dbuf);
513 os::closedir(dir);
514 return path;
515 }
516
517 // Parses a memory size specification string.
518 static bool atomull(const char *s, julong* result) {
519 julong n = 0;
520 int args_read = sscanf(s, os::julong_format_specifier(), &n);
521 if (args_read != 1) {
522 return false;
523 }
524 while (*s != '\0' && isdigit(*s)) {
525 s++;
526 }
527 // 4705540: illegal if more characters are found after the first non-digit
630
631 static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
632 if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false;
633 // Contract: CommandLineFlags always returns a pointer that needs freeing.
634 FREE_C_HEAP_ARRAY(char, value);
635 return true;
636 }
637
638 static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
639 const char* old_value = "";
640 if (!CommandLineFlags::ccstrAt(name, &old_value)) return false;
641 size_t old_len = old_value != NULL ? strlen(old_value) : 0;
642 size_t new_len = strlen(new_value);
643 const char* value;
644 char* free_this_too = NULL;
645 if (old_len == 0) {
646 value = new_value;
647 } else if (new_len == 0) {
648 value = old_value;
649 } else {
650 char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1);
651 // each new setting adds another LINE to the switch:
652 sprintf(buf, "%s\n%s", old_value, new_value);
653 value = buf;
654 free_this_too = buf;
655 }
656 (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
657 // CommandLineFlags always returns a pointer that needs freeing.
658 FREE_C_HEAP_ARRAY(char, value);
659 if (free_this_too != NULL) {
660 // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
661 FREE_C_HEAP_ARRAY(char, free_this_too);
662 }
663 return true;
664 }
665
666 bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
667
668 // range of acceptable characters spelled out for portability reasons
669 #define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
670 #define BUFLEN 255
671 char name[BUFLEN+1];
672 char dummy;
739 } else {
740 *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, *count);
741 }
742 (*bldarray)[index] = strdup(arg);
743 }
744
745 void Arguments::build_jvm_args(const char* arg) {
746 add_string(&_jvm_args_array, &_num_jvm_args, arg);
747 }
748
749 void Arguments::build_jvm_flags(const char* arg) {
750 add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
751 }
752
753 // utility function to return a string that concatenates all
754 // strings in a given char** array
755 const char* Arguments::build_resource_string(char** args, int count) {
756 if (args == NULL || count == 0) {
757 return NULL;
758 }
759 size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
760 for (int i = 1; i < count; i++) {
761 length += strlen(args[i]) + 1; // add 1 for a space
762 }
763 char* s = NEW_RESOURCE_ARRAY(char, length);
764 strcpy(s, args[0]);
765 for (int j = 1; j < count; j++) {
766 strcat(s, " ");
767 strcat(s, args[j]);
768 }
769 return (const char*) s;
770 }
771
772 void Arguments::print_on(outputStream* st) {
773 st->print_cr("VM Arguments:");
774 if (num_jvm_flags() > 0) {
775 st->print("jvm_flags: "); print_jvm_flags_on(st);
776 }
777 if (num_jvm_args() > 0) {
778 st->print("jvm_args: "); print_jvm_args_on(st);
779 }
780 st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
781 st->print_cr("Launcher Type: %s", _sun_java_launcher);
782 }
783
784 void Arguments::print_jvm_flags_on(outputStream* st) {
785 if (_num_jvm_flags > 0) {
786 for (int i=0; i < _num_jvm_flags; i++) {
787 st->print("%s ", _jvm_flags_array[i]);
1583 }
1584
1585 if (!RewriteBytecodes) {
1586 FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1587 }
1588 }
1589
1590 // Aggressive optimization flags -XX:+AggressiveOpts
1591 void Arguments::set_aggressive_opts_flags() {
1592 #ifdef COMPILER2
1593 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1594 if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
1595 FLAG_SET_DEFAULT(EliminateAutoBox, true);
1596 }
1597 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1598 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
1599 }
1600
1601 // Feed the cache size setting into the JDK
1602 char buffer[1024];
1603 sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
1604 add_property(buffer);
1605 }
1606 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
1607 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
1608 }
1609 #endif
1610
1611 if (AggressiveOpts) {
1612 // Sample flag setting code
1613 // if (FLAG_IS_DEFAULT(EliminateZeroing)) {
1614 // FLAG_SET_DEFAULT(EliminateZeroing, true);
1615 // }
1616 }
1617 }
1618
1619 //===========================================================================================================
1620 // Parsing of java.compiler property
1621
1622 void Arguments::process_java_compiler_argument(char* arg) {
1623 // For backwards compatibility, Djava.compiler=NONE or ""
2165 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2), pos+1, len2);
2166 }
2167 #ifdef JVMTI_KERNEL
2168 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
2169 warning("profiling and debugging agents are not supported with Kernel VM");
2170 } else
2171 #endif // JVMTI_KERNEL
2172 add_init_library(name, options);
2173 }
2174 // -agentlib and -agentpath
2175 } else if (match_option(option, "-agentlib:", &tail) ||
2176 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2177 if(tail != NULL) {
2178 const char* pos = strchr(tail, '=');
2179 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
2180 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
2181 name[len] = '\0';
2182
2183 char *options = NULL;
2184 if(pos != NULL) {
2185 options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1), pos + 1);
2186 }
2187 #ifdef JVMTI_KERNEL
2188 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
2189 warning("profiling and debugging agents are not supported with Kernel VM");
2190 } else
2191 #endif // JVMTI_KERNEL
2192 add_init_agent(name, options, is_absolute_path);
2193
2194 }
2195 // -javaagent
2196 } else if (match_option(option, "-javaagent:", &tail)) {
2197 if(tail != NULL) {
2198 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1), tail);
2199 add_init_agent("instrument", options, false);
2200 }
2201 // -Xnoclassgc
2202 } else if (match_option(option, "-Xnoclassgc", &tail)) {
2203 FLAG_SET_CMDLINE(bool, ClassUnloading, false);
2204 // -Xincgc: i-CMS
2205 } else if (match_option(option, "-Xincgc", &tail)) {
2206 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
2207 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true);
2208 // -Xnoincgc: no i-CMS
2209 } else if (match_option(option, "-Xnoincgc", &tail)) {
2210 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2211 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false);
2212 // -Xconcgc
2213 } else if (match_option(option, "-Xconcgc", &tail)) {
2214 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
2215 // -Xnoconcgc
2216 } else if (match_option(option, "-Xnoconcgc", &tail)) {
2217 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2218 // -Xbatch
2768 TieredCompilation = false;
2769 #else
2770 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
2771 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
2772 }
2773 #endif
2774
2775 // If we are running in a headless jre, force java.awt.headless property
2776 // to be true unless the property has already been set.
2777 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
2778 if (os::is_headless_jre()) {
2779 const char* headless = Arguments::get_property("java.awt.headless");
2780 if (headless == NULL) {
2781 char envbuffer[128];
2782 if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) {
2783 if (!add_property("java.awt.headless=true")) {
2784 return JNI_ENOMEM;
2785 }
2786 } else {
2787 char buffer[256];
2788 strcpy(buffer, "java.awt.headless=");
2789 strcat(buffer, envbuffer);
2790 if (!add_property(buffer)) {
2791 return JNI_ENOMEM;
2792 }
2793 }
2794 }
2795 }
2796
2797 if (!check_vm_args_consistency()) {
2798 return JNI_ERR;
2799 }
2800
2801 return JNI_OK;
2802 }
2803
2804 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
2805 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
2806 scp_assembly_required_p);
2807 }
2808
2809 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
|
486 // Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
487 char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
488 DIR* dir = os::opendir(directory);
489 if (dir == NULL) return path;
490
491 char dir_sep[2] = { '\0', '\0' };
492 size_t directory_len = strlen(directory);
493 const char fileSep = *os::file_separator();
494 if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
495
496 /* Scan the directory for jars/zips, appending them to path. */
497 struct dirent *entry;
498 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory));
499 while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
500 const char* name = entry->d_name;
501 const char* ext = name + strlen(name) - 4;
502 bool isJarOrZip = ext > name &&
503 (os::file_name_strcmp(ext, ".jar") == 0 ||
504 os::file_name_strcmp(ext, ".zip") == 0);
505 if (isJarOrZip) {
506 size_t length = directory_len + 2 + strlen(name);
507 char* jarpath = NEW_C_HEAP_ARRAY(char, length);
508 jio_snprintf(jarpath, length, "%s%s%s", directory, dir_sep, name);
509 path = add_to_path(path, jarpath, false);
510 FREE_C_HEAP_ARRAY(char, jarpath);
511 }
512 }
513 FREE_C_HEAP_ARRAY(char, dbuf);
514 os::closedir(dir);
515 return path;
516 }
517
518 // Parses a memory size specification string.
519 static bool atomull(const char *s, julong* result) {
520 julong n = 0;
521 int args_read = sscanf(s, os::julong_format_specifier(), &n);
522 if (args_read != 1) {
523 return false;
524 }
525 while (*s != '\0' && isdigit(*s)) {
526 s++;
527 }
528 // 4705540: illegal if more characters are found after the first non-digit
631
632 static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
633 if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false;
634 // Contract: CommandLineFlags always returns a pointer that needs freeing.
635 FREE_C_HEAP_ARRAY(char, value);
636 return true;
637 }
638
639 static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
640 const char* old_value = "";
641 if (!CommandLineFlags::ccstrAt(name, &old_value)) return false;
642 size_t old_len = old_value != NULL ? strlen(old_value) : 0;
643 size_t new_len = strlen(new_value);
644 const char* value;
645 char* free_this_too = NULL;
646 if (old_len == 0) {
647 value = new_value;
648 } else if (new_len == 0) {
649 value = old_value;
650 } else {
651 size_t length = old_len + 1 + new_len + 1;
652 char* buf = NEW_C_HEAP_ARRAY(char, length);
653 // each new setting adds another LINE to the switch:
654 jio_snprintf(buf, length, "%s\n%s", old_value, new_value);
655 value = buf;
656 free_this_too = buf;
657 }
658 (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
659 // CommandLineFlags always returns a pointer that needs freeing.
660 FREE_C_HEAP_ARRAY(char, value);
661 if (free_this_too != NULL) {
662 // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
663 FREE_C_HEAP_ARRAY(char, free_this_too);
664 }
665 return true;
666 }
667
668 bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
669
670 // range of acceptable characters spelled out for portability reasons
671 #define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
672 #define BUFLEN 255
673 char name[BUFLEN+1];
674 char dummy;
741 } else {
742 *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, *count);
743 }
744 (*bldarray)[index] = strdup(arg);
745 }
746
747 void Arguments::build_jvm_args(const char* arg) {
748 add_string(&_jvm_args_array, &_num_jvm_args, arg);
749 }
750
751 void Arguments::build_jvm_flags(const char* arg) {
752 add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
753 }
754
755 // utility function to return a string that concatenates all
756 // strings in a given char** array
757 const char* Arguments::build_resource_string(char** args, int count) {
758 if (args == NULL || count == 0) {
759 return NULL;
760 }
761 size_t length = 0;
762 for (int i = 0; i < count; i++) {
763 length += strlen(args[i]) + 1; // add 1 for a space or NULL terminating character
764 }
765 char* s = NEW_RESOURCE_ARRAY(char, length);
766 char* dst = s;
767 for (int j = 0; j < count; j++) {
768 size_t offset = strlen(args[j]) + 1; // add 1 for a space or NULL terminating character
769 jio_snprintf(dst, length, "%s ", args[j]); // jio_snprintf will replace the last space character with NULL character
770 dst += offset;
771 length -= offset;
772 }
773 return (const char*) s;
774 }
775
776 void Arguments::print_on(outputStream* st) {
777 st->print_cr("VM Arguments:");
778 if (num_jvm_flags() > 0) {
779 st->print("jvm_flags: "); print_jvm_flags_on(st);
780 }
781 if (num_jvm_args() > 0) {
782 st->print("jvm_args: "); print_jvm_args_on(st);
783 }
784 st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
785 st->print_cr("Launcher Type: %s", _sun_java_launcher);
786 }
787
788 void Arguments::print_jvm_flags_on(outputStream* st) {
789 if (_num_jvm_flags > 0) {
790 for (int i=0; i < _num_jvm_flags; i++) {
791 st->print("%s ", _jvm_flags_array[i]);
1587 }
1588
1589 if (!RewriteBytecodes) {
1590 FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1591 }
1592 }
1593
1594 // Aggressive optimization flags -XX:+AggressiveOpts
1595 void Arguments::set_aggressive_opts_flags() {
1596 #ifdef COMPILER2
1597 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1598 if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
1599 FLAG_SET_DEFAULT(EliminateAutoBox, true);
1600 }
1601 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
1602 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
1603 }
1604
1605 // Feed the cache size setting into the JDK
1606 char buffer[1024];
1607 jio_snprintf(buffer, 1024, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
1608 add_property(buffer);
1609 }
1610 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
1611 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
1612 }
1613 #endif
1614
1615 if (AggressiveOpts) {
1616 // Sample flag setting code
1617 // if (FLAG_IS_DEFAULT(EliminateZeroing)) {
1618 // FLAG_SET_DEFAULT(EliminateZeroing, true);
1619 // }
1620 }
1621 }
1622
1623 //===========================================================================================================
1624 // Parsing of java.compiler property
1625
1626 void Arguments::process_java_compiler_argument(char* arg) {
1627 // For backwards compatibility, Djava.compiler=NONE or ""
2169 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2), pos+1, len2);
2170 }
2171 #ifdef JVMTI_KERNEL
2172 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
2173 warning("profiling and debugging agents are not supported with Kernel VM");
2174 } else
2175 #endif // JVMTI_KERNEL
2176 add_init_library(name, options);
2177 }
2178 // -agentlib and -agentpath
2179 } else if (match_option(option, "-agentlib:", &tail) ||
2180 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2181 if(tail != NULL) {
2182 const char* pos = strchr(tail, '=');
2183 size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
2184 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
2185 name[len] = '\0';
2186
2187 char *options = NULL;
2188 if(pos != NULL) {
2189 size_t length = strlen(pos + 1) + 1;
2190 options = NEW_C_HEAP_ARRAY(char, length);
2191 jio_snprintf(options, length, "%s", pos + 1);
2192 }
2193 #ifdef JVMTI_KERNEL
2194 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
2195 warning("profiling and debugging agents are not supported with Kernel VM");
2196 } else
2197 #endif // JVMTI_KERNEL
2198 add_init_agent(name, options, is_absolute_path);
2199
2200 }
2201 // -javaagent
2202 } else if (match_option(option, "-javaagent:", &tail)) {
2203 if(tail != NULL) {
2204 size_t length = strlen(tail) + 1;
2205 char *options = NEW_C_HEAP_ARRAY(char, length);
2206 jio_snprintf(options, length, "%s", tail);
2207 add_init_agent("instrument", options, false);
2208 }
2209 // -Xnoclassgc
2210 } else if (match_option(option, "-Xnoclassgc", &tail)) {
2211 FLAG_SET_CMDLINE(bool, ClassUnloading, false);
2212 // -Xincgc: i-CMS
2213 } else if (match_option(option, "-Xincgc", &tail)) {
2214 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
2215 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true);
2216 // -Xnoincgc: no i-CMS
2217 } else if (match_option(option, "-Xnoincgc", &tail)) {
2218 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2219 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false);
2220 // -Xconcgc
2221 } else if (match_option(option, "-Xconcgc", &tail)) {
2222 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
2223 // -Xnoconcgc
2224 } else if (match_option(option, "-Xnoconcgc", &tail)) {
2225 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
2226 // -Xbatch
2776 TieredCompilation = false;
2777 #else
2778 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
2779 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
2780 }
2781 #endif
2782
2783 // If we are running in a headless jre, force java.awt.headless property
2784 // to be true unless the property has already been set.
2785 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
2786 if (os::is_headless_jre()) {
2787 const char* headless = Arguments::get_property("java.awt.headless");
2788 if (headless == NULL) {
2789 char envbuffer[128];
2790 if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) {
2791 if (!add_property("java.awt.headless=true")) {
2792 return JNI_ENOMEM;
2793 }
2794 } else {
2795 char buffer[256];
2796 jio_snprintf(buffer, 256, "java.awt.headless=%s", envbuffer);
2797 if (!add_property(buffer)) {
2798 return JNI_ENOMEM;
2799 }
2800 }
2801 }
2802 }
2803
2804 if (!check_vm_args_consistency()) {
2805 return JNI_ERR;
2806 }
2807
2808 return JNI_OK;
2809 }
2810
2811 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
2812 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
2813 scp_assembly_required_p);
2814 }
2815
2816 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
|