Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalRuntime.cpp @ 16270:d56a09df1a1f
implemented eager checking of Graal options (GRAAL-807)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 27 Jun 2014 19:55:54 +0200 |
parents | 66a9286203a2 |
children | d6ffc6164830 |
comparison
equal
deleted
inserted
replaced
16269:f5437f2db322 | 16270:d56a09df1a1f |
---|---|
699 stats->_standard.reset(); | 699 stats->_standard.reset(); |
700 stats->_osr.reset(); | 700 stats->_osr.reset(); |
701 JVM_END | 701 JVM_END |
702 #endif | 702 #endif |
703 | 703 |
704 jint GraalRuntime::check_arguments(TRAPS) { | |
705 KlassHandle nullHandle; | |
706 parse_arguments(nullHandle, THREAD); | |
707 if (HAS_PENDING_EXCEPTION) { | |
708 // Errors in parsing Graal arguments cause exceptions. | |
709 // We now load and initialize HotSpotOptions which in turn | |
710 // causes argument parsing to be redone with better error messages. | |
711 CLEAR_PENDING_EXCEPTION; | |
712 TempNewSymbol name = SymbolTable::new_symbol("Lcom/oracle/graal/hotspot/HotSpotOptions;", THREAD); | |
713 instanceKlassHandle hotSpotOptionsClass = SystemDictionary::resolve_or_fail(name, true, THREAD); | |
714 GUARANTEE_NO_PENDING_EXCEPTION("Error in check_arguments"); | |
715 | |
716 parse_arguments(hotSpotOptionsClass, THREAD); | |
717 assert(HAS_PENDING_EXCEPTION, "must be"); | |
718 | |
719 ResourceMark rm; | |
720 oop message = java_lang_Throwable::message(PENDING_EXCEPTION); | |
721 assert(message != NULL, "Graal argument parsing exception is expected to hava message"); | |
722 tty->print_cr("Error parsing Graal options: %s", java_lang_String::as_utf8_string(message)); | |
723 CLEAR_PENDING_EXCEPTION; | |
724 return JNI_ERR; | |
725 } | |
726 return JNI_OK; | |
727 } | |
728 | |
704 bool GraalRuntime::parse_arguments(KlassHandle hotSpotOptionsClass, TRAPS) { | 729 bool GraalRuntime::parse_arguments(KlassHandle hotSpotOptionsClass, TRAPS) { |
705 ResourceMark rm(THREAD); | 730 ResourceMark rm(THREAD); |
706 | 731 |
707 // Process option overrides from graal.options first | 732 // Process option overrides from graal.options first |
708 parse_graal_options_file(hotSpotOptionsClass, CHECK_false); | 733 parse_graal_options_file(hotSpotOptionsClass, CHECK_false); |
714 parse_argument(hotSpotOptionsClass, arg, CHECK_false); | 739 parse_argument(hotSpotOptionsClass, arg, CHECK_false); |
715 } | 740 } |
716 return CITime || CITimeEach; | 741 return CITime || CITimeEach; |
717 } | 742 } |
718 | 743 |
744 void GraalRuntime::check_required_value(const char* name, int name_len, const char* value, TRAPS) { | |
745 if (value == NULL) { | |
746 char buf[200]; | |
747 jio_snprintf(buf, sizeof(buf), "Value for option %.*s must use '-G:%.*s=<value>' format", name_len, name, name_len, name); | |
748 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); | |
749 } | |
750 } | |
751 | |
719 void GraalRuntime::parse_argument(KlassHandle hotSpotOptionsClass, char* arg, TRAPS) { | 752 void GraalRuntime::parse_argument(KlassHandle hotSpotOptionsClass, char* arg, TRAPS) { |
720 char first = arg[0]; | 753 char first = arg[0]; |
721 char* name; | 754 char* name; |
722 size_t name_len; | 755 size_t name_len; |
723 Handle name_handle; | 756 bool recognized = true; |
724 bool valid = true; | |
725 if (first == '+' || first == '-') { | 757 if (first == '+' || first == '-') { |
726 name = arg + 1; | 758 name = arg + 1; |
727 name_len = strlen(name); | 759 name_len = strlen(name); |
728 name_handle = java_lang_String::create_from_str(name, CHECK); | 760 recognized = set_option(hotSpotOptionsClass, name, (int)name_len, arg, CHECK); |
729 valid = set_option(hotSpotOptionsClass, name, (int)name_len, name_handle, arg, CHECK); | |
730 } else { | 761 } else { |
731 char* sep = strchr(arg, '='); | 762 char* sep = strchr(arg, '='); |
763 name = arg; | |
764 char* value = NULL; | |
732 if (sep != NULL) { | 765 if (sep != NULL) { |
733 name = arg; | |
734 name_len = sep - name; | 766 name_len = sep - name; |
735 // Temporarily replace '=' with NULL to create the Java string for the option name | 767 value = sep + 1; |
736 *sep = '\0'; | 768 } else { |
737 name_handle = java_lang_String::create_from_str(arg, THREAD); | 769 name_len = strlen(name); |
738 *sep = '='; | 770 } |
739 if (HAS_PENDING_EXCEPTION) { | 771 recognized = set_option(hotSpotOptionsClass, name, (int)name_len, value, CHECK); |
740 return; | 772 } |
773 | |
774 if (!recognized) { | |
775 bool throw_err = hotSpotOptionsClass.is_null(); | |
776 if (!hotSpotOptionsClass.is_null()) { | |
777 instanceKlassHandle ikh(hotSpotOptionsClass()); | |
778 if (!ikh->is_reentrant_initialization(THREAD)) { | |
779 set_option_helper(hotSpotOptionsClass, name, name_len, Handle(), ' ', Handle(), 0L); | |
780 throw_err = true; | |
741 } | 781 } |
742 valid = set_option(hotSpotOptionsClass, name, (int)name_len, name_handle, sep + 1, CHECK); | 782 } |
743 } else { | 783 |
784 if (throw_err) { | |
744 char buf[200]; | 785 char buf[200]; |
745 jio_snprintf(buf, sizeof(buf), "Value for option %s must use '-G:%s=<value>' format", arg, arg); | 786 jio_snprintf(buf, sizeof(buf), "Unrecognized Graal option %.*s", name_len, name); |
746 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); | 787 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); |
747 } | 788 } |
748 } | |
749 | |
750 if (!valid) { | |
751 set_option_helper(hotSpotOptionsClass, name_handle, Handle(), ' ', Handle(), 0L); | |
752 char buf[200]; | |
753 jio_snprintf(buf, sizeof(buf), "Invalid Graal option %s", arg); | |
754 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); | |
755 } | 789 } |
756 } | 790 } |
757 | 791 |
758 void GraalRuntime::parse_graal_options_file(KlassHandle hotSpotOptionsClass, TRAPS) { | 792 void GraalRuntime::parse_graal_options_file(KlassHandle hotSpotOptionsClass, TRAPS) { |
759 const char* home = Arguments::get_java_home(); | 793 const char* home = Arguments::get_java_home(); |
800 warning("Error opening file %s due to %s", path, strerror(errno)); | 834 warning("Error opening file %s due to %s", path, strerror(errno)); |
801 } | 835 } |
802 } | 836 } |
803 } | 837 } |
804 | 838 |
805 jlong GraalRuntime::parse_primitive_option_value(char spec, Handle name, const char* value, TRAPS) { | 839 jlong GraalRuntime::parse_primitive_option_value(char spec, const char* name, int name_len, const char* value, TRAPS) { |
840 check_required_value(name, name_len, value, CHECK_(0L)); | |
806 union { | 841 union { |
807 jint i; | 842 jint i; |
808 jlong l; | 843 jlong l; |
809 double d; | 844 double d; |
810 } uu; | 845 } uu; |
827 default: | 862 default: |
828 ShouldNotReachHere(); | 863 ShouldNotReachHere(); |
829 } | 864 } |
830 ResourceMark rm(THREAD); | 865 ResourceMark rm(THREAD); |
831 char buf[200]; | 866 char buf[200]; |
832 jio_snprintf(buf, sizeof(buf), "Invalid %s value for Graal option %s: %s", (spec == 'i' ? "numeric" : "float/double"), java_lang_String::as_utf8_string(name()), value); | 867 jio_snprintf(buf, sizeof(buf), "Invalid %s value for Graal option %.*s: %s", (spec == 'i' ? "numeric" : "float/double"), name, name_len, value); |
833 THROW_MSG_(vmSymbols::java_lang_InternalError(), buf, 0L); | 868 THROW_MSG_(vmSymbols::java_lang_InternalError(), buf, 0L); |
834 } | 869 } |
835 | 870 |
836 void GraalRuntime::set_option_helper(KlassHandle hotSpotOptionsClass, Handle name, Handle option, jchar spec, Handle stringValue, jlong primitiveValue) { | 871 void GraalRuntime::set_option_helper(KlassHandle hotSpotOptionsClass, char* name, int name_len, Handle option, jchar spec, Handle stringValue, jlong primitiveValue) { |
837 Thread* THREAD = Thread::current(); | 872 Thread* THREAD = Thread::current(); |
873 Handle name_handle; | |
874 if (name != NULL) { | |
875 if ((int) strlen(name) > name_len) { | |
876 // Temporarily replace '=' with NULL to create the Java string for the option name | |
877 char save = name[name_len]; | |
878 name[name_len] = '\0'; | |
879 name_handle = java_lang_String::create_from_str(name, THREAD); | |
880 name[name_len] = '='; | |
881 if (HAS_PENDING_EXCEPTION) { | |
882 return; | |
883 } | |
884 } else { | |
885 assert((int) strlen(name) == name_len, "must be"); | |
886 name_handle = java_lang_String::create_from_str(name, CHECK); | |
887 } | |
888 } | |
889 | |
838 TempNewSymbol setOption = SymbolTable::new_symbol("setOption", THREAD); | 890 TempNewSymbol setOption = SymbolTable::new_symbol("setOption", THREAD); |
839 TempNewSymbol sig = SymbolTable::new_symbol("(Ljava/lang/String;Lcom/oracle/graal/options/OptionValue;CLjava/lang/String;J)V", THREAD); | 891 TempNewSymbol sig = SymbolTable::new_symbol("(Ljava/lang/String;Lcom/oracle/graal/options/OptionValue;CLjava/lang/String;J)V", THREAD); |
840 JavaValue result(T_VOID); | 892 JavaValue result(T_VOID); |
841 JavaCallArguments args; | 893 JavaCallArguments args; |
842 args.push_oop(name()); | 894 args.push_oop(name_handle()); |
843 args.push_oop(option()); | 895 args.push_oop(option()); |
844 args.push_int(spec); | 896 args.push_int(spec); |
845 args.push_oop(stringValue()); | 897 args.push_oop(stringValue()); |
846 args.push_long(primitiveValue); | 898 args.push_long(primitiveValue); |
847 JavaCalls::call_static(&result, hotSpotOptionsClass, setOption, sig, &args, THREAD); | 899 JavaCalls::call_static(&result, hotSpotOptionsClass, setOption, sig, &args, CHECK); |
848 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling set_option_helper"); | |
849 } | 900 } |
850 | 901 |
851 Handle GraalRuntime::get_OptionValue(const char* declaringClass, const char* fieldName, const char* fieldSig, TRAPS) { | 902 Handle GraalRuntime::get_OptionValue(const char* declaringClass, const char* fieldName, const char* fieldSig, TRAPS) { |
852 TempNewSymbol name = SymbolTable::new_symbol(declaringClass, THREAD); | 903 TempNewSymbol name = SymbolTable::new_symbol(declaringClass, THREAD); |
853 Klass* klass = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); | 904 Klass* klass = SystemDictionary::resolve_or_fail(name, true, CHECK_NH); |
904 Thread* THREAD = Thread::current(); | 955 Thread* THREAD = Thread::current(); |
905 CLEAR_PENDING_EXCEPTION; | 956 CLEAR_PENDING_EXCEPTION; |
906 | 957 |
907 assert(exception->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected"); | 958 assert(exception->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected"); |
908 JavaValue result(T_VOID); | 959 JavaValue result(T_VOID); |
960 tty->print_cr(message); | |
909 JavaCalls::call_virtual(&result, | 961 JavaCalls::call_virtual(&result, |
910 exception, | 962 exception, |
911 KlassHandle(THREAD, | 963 KlassHandle(THREAD, |
912 SystemDictionary::Throwable_klass()), | 964 SystemDictionary::Throwable_klass()), |
913 vmSymbols::printStackTrace_name(), | 965 vmSymbols::printStackTrace_name(), |