< prev index next >

src/share/vm/runtime/arguments.cpp

Print this page




 760   struct dirent *entry;
 761   char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtArguments);
 762   while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
 763     const char* name = entry->d_name;
 764     const char* ext = name + strlen(name) - 4;
 765     bool isJarOrZip = ext > name &&
 766       (os::file_name_strcmp(ext, ".jar") == 0 ||
 767        os::file_name_strcmp(ext, ".zip") == 0);
 768     if (isJarOrZip) {
 769       char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name), mtArguments);
 770       sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
 771       path = add_to_path(path, jarpath, false);
 772       FREE_C_HEAP_ARRAY(char, jarpath);
 773     }
 774   }
 775   FREE_C_HEAP_ARRAY(char, dbuf);
 776   os::closedir(dir);
 777   return path;
 778 }
 779 
 780 // Parses a memory size specification string.
 781 static bool atomull(const char *s, julong* result) {
 782   julong n = 0;
 783   int args_read = 0;
 784   bool is_hex = false;
 785   // Skip leading 0[xX] for hexadecimal
 786   if (*s =='0' && (*(s+1) == 'x' || *(s+1) == 'X')) {
 787     s += 2;
 788     is_hex = true;
 789     args_read = sscanf(s, JULONG_FORMAT_X, &n);
 790   } else {
 791     args_read = sscanf(s, JULONG_FORMAT, &n);
 792   }
 793   if (args_read != 1) {
 794     return false;
 795   }
 796   while (*s != '\0' && (isdigit(*s) || (is_hex && isxdigit(*s)))) {
 797     s++;
 798   }
 799   // 4705540: illegal if more characters are found after the first non-digit
 800   if (strlen(s) > 1) {
 801     return false;


 867     return false;
 868   }
 869 
 870   if (CommandLineFlags::doubleAtPut(name, &v, origin) == Flag::SUCCESS) {
 871     return true;
 872   }
 873   return false;
 874 }
 875 
 876 static bool set_numeric_flag(const char* name, char* value, Flag::Flags origin) {
 877   julong v;
 878   int int_v;
 879   intx intx_v;
 880   bool is_neg = false;
 881   Flag* result = Flag::find_flag(name, strlen(name));
 882 
 883   if (result == NULL) {
 884     return false;
 885   }
 886 
 887   // Check the sign first since atomull() parses only unsigned values.
 888   if (*value == '-') {
 889     if (!result->is_intx() && !result->is_int()) {
 890       return false;
 891     }
 892     value++;
 893     is_neg = true;
 894   }
 895   if (!atomull(value, &v)) {
 896     return false;
 897   }
 898   if (result->is_int()) {
 899     int_v = (int) v;
 900     if (is_neg) {
 901       int_v = -int_v;
 902     }
 903     return CommandLineFlags::intAtPut(result, &int_v, origin) == Flag::SUCCESS;
 904   } else if (result->is_uint()) {
 905     uint uint_v = (uint) v;
 906     return CommandLineFlags::uintAtPut(result, &uint_v, origin) == Flag::SUCCESS;
 907   } else if (result->is_intx()) {
 908     intx_v = (intx) v;
 909     if (is_neg) {
 910       intx_v = -intx_v;
 911     }
 912     return CommandLineFlags::intxAtPut(result, &intx_v, origin) == Flag::SUCCESS;
 913   } else if (result->is_uintx()) {
 914     uintx uintx_v = (uintx) v;
 915     return CommandLineFlags::uintxAtPut(result, &uintx_v, origin) == Flag::SUCCESS;


2639   } else {
2640     jio_fprintf(defaultStream::error_stream(),
2641                 "Unrecognized %s%soption: %s\n", option_type, spacer,
2642       option->optionString);
2643     return true;
2644   }
2645 }
2646 
2647 static const char* user_assertion_options[] = {
2648   "-da", "-ea", "-disableassertions", "-enableassertions", 0
2649 };
2650 
2651 static const char* system_assertion_options[] = {
2652   "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
2653 };
2654 
2655 bool Arguments::parse_uintx(const char* value,
2656                             uintx* uintx_arg,
2657                             uintx min_size) {
2658 
2659   // Check the sign first since atomull() parses only unsigned values.
2660   bool value_is_positive = !(*value == '-');
2661 
2662   if (value_is_positive) {
2663     julong n;
2664     bool good_return = atomull(value, &n);
2665     if (good_return) {
2666       bool above_minimum = n >= min_size;
2667       bool value_is_too_large = n > max_uintx;
2668 
2669       if (above_minimum && !value_is_too_large) {
2670         *uintx_arg = n;
2671         return true;
2672       }
2673     }
2674   }
2675   return false;
2676 }
2677 
2678 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2679                                                   julong* long_arg,
2680                                                   julong min_size) {
2681   if (!atomull(s, long_arg)) return arg_unreadable;
2682   return check_memory_size(*long_arg, min_size);
2683 }
2684 
2685 // Parse JavaVMInitArgs structure
2686 
2687 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args,
2688                                    const JavaVMInitArgs *java_options_args,
2689                                    const JavaVMInitArgs *cmd_line_args) {
2690   // For components of the system classpath.
2691   ArgumentBootClassPath bcp(Arguments::get_sysclasspath());
2692   bool bcp_assembly_required = false;
2693 
2694   // Save default settings for some mode flags
2695   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2696   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
2697   Arguments::_ClipInlining             = ClipInlining;
2698   Arguments::_BackgroundCompilation    = BackgroundCompilation;
2699   if (TieredCompilation) {
2700     Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog;
2701     Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold;




 760   struct dirent *entry;
 761   char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtArguments);
 762   while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
 763     const char* name = entry->d_name;
 764     const char* ext = name + strlen(name) - 4;
 765     bool isJarOrZip = ext > name &&
 766       (os::file_name_strcmp(ext, ".jar") == 0 ||
 767        os::file_name_strcmp(ext, ".zip") == 0);
 768     if (isJarOrZip) {
 769       char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name), mtArguments);
 770       sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
 771       path = add_to_path(path, jarpath, false);
 772       FREE_C_HEAP_ARRAY(char, jarpath);
 773     }
 774   }
 775   FREE_C_HEAP_ARRAY(char, dbuf);
 776   os::closedir(dir);
 777   return path;
 778 }
 779 
 780 // Parses a size specification string.
 781 bool Arguments::atojulong(const char *s, julong* result) {
 782   julong n = 0;
 783   int args_read = 0;
 784   bool is_hex = false;
 785   // Skip leading 0[xX] for hexadecimal
 786   if (*s =='0' && (*(s+1) == 'x' || *(s+1) == 'X')) {
 787     s += 2;
 788     is_hex = true;
 789     args_read = sscanf(s, JULONG_FORMAT_X, &n);
 790   } else {
 791     args_read = sscanf(s, JULONG_FORMAT, &n);
 792   }
 793   if (args_read != 1) {
 794     return false;
 795   }
 796   while (*s != '\0' && (isdigit(*s) || (is_hex && isxdigit(*s)))) {
 797     s++;
 798   }
 799   // 4705540: illegal if more characters are found after the first non-digit
 800   if (strlen(s) > 1) {
 801     return false;


 867     return false;
 868   }
 869 
 870   if (CommandLineFlags::doubleAtPut(name, &v, origin) == Flag::SUCCESS) {
 871     return true;
 872   }
 873   return false;
 874 }
 875 
 876 static bool set_numeric_flag(const char* name, char* value, Flag::Flags origin) {
 877   julong v;
 878   int int_v;
 879   intx intx_v;
 880   bool is_neg = false;
 881   Flag* result = Flag::find_flag(name, strlen(name));
 882 
 883   if (result == NULL) {
 884     return false;
 885   }
 886 
 887   // Check the sign first since atojulong() parses only unsigned values.
 888   if (*value == '-') {
 889     if (!result->is_intx() && !result->is_int()) {
 890       return false;
 891     }
 892     value++;
 893     is_neg = true;
 894   }
 895   if (!Arguments::atojulong(value, &v)) {
 896     return false;
 897   }
 898   if (result->is_int()) {
 899     int_v = (int) v;
 900     if (is_neg) {
 901       int_v = -int_v;
 902     }
 903     return CommandLineFlags::intAtPut(result, &int_v, origin) == Flag::SUCCESS;
 904   } else if (result->is_uint()) {
 905     uint uint_v = (uint) v;
 906     return CommandLineFlags::uintAtPut(result, &uint_v, origin) == Flag::SUCCESS;
 907   } else if (result->is_intx()) {
 908     intx_v = (intx) v;
 909     if (is_neg) {
 910       intx_v = -intx_v;
 911     }
 912     return CommandLineFlags::intxAtPut(result, &intx_v, origin) == Flag::SUCCESS;
 913   } else if (result->is_uintx()) {
 914     uintx uintx_v = (uintx) v;
 915     return CommandLineFlags::uintxAtPut(result, &uintx_v, origin) == Flag::SUCCESS;


2639   } else {
2640     jio_fprintf(defaultStream::error_stream(),
2641                 "Unrecognized %s%soption: %s\n", option_type, spacer,
2642       option->optionString);
2643     return true;
2644   }
2645 }
2646 
2647 static const char* user_assertion_options[] = {
2648   "-da", "-ea", "-disableassertions", "-enableassertions", 0
2649 };
2650 
2651 static const char* system_assertion_options[] = {
2652   "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
2653 };
2654 
2655 bool Arguments::parse_uintx(const char* value,
2656                             uintx* uintx_arg,
2657                             uintx min_size) {
2658 
2659   // Check the sign first since atojulong() parses only unsigned values.
2660   bool value_is_positive = !(*value == '-');
2661 
2662   if (value_is_positive) {
2663     julong n;
2664     bool good_return = atojulong(value, &n);
2665     if (good_return) {
2666       bool above_minimum = n >= min_size;
2667       bool value_is_too_large = n > max_uintx;
2668 
2669       if (above_minimum && !value_is_too_large) {
2670         *uintx_arg = n;
2671         return true;
2672       }
2673     }
2674   }
2675   return false;
2676 }
2677 
2678 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2679                                                   julong* long_arg,
2680                                                   julong min_size) {
2681   if (!atojulong(s, long_arg)) return arg_unreadable;
2682   return check_memory_size(*long_arg, min_size);
2683 }
2684 
2685 // Parse JavaVMInitArgs structure
2686 
2687 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args,
2688                                    const JavaVMInitArgs *java_options_args,
2689                                    const JavaVMInitArgs *cmd_line_args) {
2690   // For components of the system classpath.
2691   ArgumentBootClassPath bcp(Arguments::get_sysclasspath());
2692   bool bcp_assembly_required = false;
2693 
2694   // Save default settings for some mode flags
2695   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2696   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
2697   Arguments::_ClipInlining             = ClipInlining;
2698   Arguments::_BackgroundCompilation    = BackgroundCompilation;
2699   if (TieredCompilation) {
2700     Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog;
2701     Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold;


< prev index next >