35 #include "oops/oop.inline.hpp" 36 #include "oops/objArrayOop.inline.hpp" 37 #include "prims/jvm.h" 38 #include "runtime/biasedLocking.hpp" 39 #include "runtime/interfaceSupport.hpp" 40 #include "runtime/reflection.hpp" 41 #include "runtime/sharedRuntime.hpp" 42 #include "utilities/debug.hpp" 43 #include "utilities/defaultStream.hpp" 44 45 #if defined(_MSC_VER) 46 #define strtoll _strtoi64 47 #endif 48 49 jobject JVMCIRuntime::_HotSpotJVMCIRuntime_instance = NULL; 50 bool JVMCIRuntime::_HotSpotJVMCIRuntime_initialized = false; 51 bool JVMCIRuntime::_well_known_classes_initialized = false; 52 const char* JVMCIRuntime::_compiler = NULL; 53 int JVMCIRuntime::_options_count = 0; 54 SystemProperty** JVMCIRuntime::_options = NULL; 55 bool JVMCIRuntime::_shutdown_called = false; 56 57 static const char* OPTION_PREFIX = "jvmci.option."; 58 static const size_t OPTION_PREFIX_LEN = strlen(OPTION_PREFIX); 59 60 BasicType JVMCIRuntime::kindToBasicType(jchar ch) { 61 switch(ch) { 62 case 'z': return T_BOOLEAN; 63 case 'b': return T_BYTE; 64 case 's': return T_SHORT; 65 case 'c': return T_CHAR; 66 case 'i': return T_INT; 67 case 'f': return T_FLOAT; 68 case 'j': return T_LONG; 69 case 'd': return T_DOUBLE; 70 case 'a': return T_OBJECT; 71 case '-': return T_ILLEGAL; 72 default: 73 fatal("unexpected Kind: %c", ch); 74 break; 416 } 417 thread->print_stack_on(tty); 418 assert(false, "invalid lock object pointer dected"); 419 } 420 #endif 421 422 if (JVMCIUseFastLocking) { 423 // When using fast locking, the compiled code has already tried the fast case 424 ObjectSynchronizer::slow_exit(obj, lock, THREAD); 425 } else { 426 ObjectSynchronizer::fast_exit(obj, lock, THREAD); 427 } 428 IF_TRACE_jvmci_3 { 429 char type[O_BUFLEN]; 430 obj->klass()->name()->as_C_string(type, O_BUFLEN); 431 TRACE_jvmci_3("%s: exited locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), p2i(obj), type, p2i(obj->mark()), p2i(lock)); 432 tty->flush(); 433 } 434 JRT_END 435 436 JRT_LEAF(void, JVMCIRuntime::log_object(JavaThread* thread, oopDesc* obj, jint flags)) 437 bool string = mask_bits_are_true(flags, LOG_OBJECT_STRING); 438 bool addr = mask_bits_are_true(flags, LOG_OBJECT_ADDRESS); 439 bool newline = mask_bits_are_true(flags, LOG_OBJECT_NEWLINE); 440 if (!string) { 441 if (!addr && obj->is_oop_or_null(true)) { 442 char buf[O_BUFLEN]; 443 tty->print("%s@" INTPTR_FORMAT, obj->klass()->name()->as_C_string(buf, O_BUFLEN), p2i(obj)); 444 } else { 445 tty->print(INTPTR_FORMAT, p2i(obj)); 446 } 447 } else { 448 ResourceMark rm; 449 assert(obj != NULL && java_lang_String::is_instance(obj), "must be"); 450 char *buf = java_lang_String::as_utf8_string(obj); 451 tty->print_raw(buf); 452 } 453 if (newline) { 454 tty->cr(); 455 } 456 JRT_END 457 458 JRT_LEAF(void, JVMCIRuntime::write_barrier_pre(JavaThread* thread, oopDesc* obj)) 459 thread->satb_mark_queue().enqueue(obj); 460 JRT_END 461 611 JVM_END 612 613 Handle JVMCIRuntime::callStatic(const char* className, const char* methodName, const char* signature, JavaCallArguments* args, TRAPS) { 614 guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime"); 615 616 TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_(Handle())); 617 KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle())); 618 TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_(Handle())); 619 TempNewSymbol sig = SymbolTable::new_symbol(signature, CHECK_(Handle())); 620 JavaValue result(T_OBJECT); 621 if (args == NULL) { 622 JavaCalls::call_static(&result, klass, runtime, sig, CHECK_(Handle())); 623 } else { 624 JavaCalls::call_static(&result, klass, runtime, sig, args, CHECK_(Handle())); 625 } 626 return Handle((oop)result.get_jobject()); 627 } 628 629 static bool jvmci_options_file_exists() { 630 const char* home = Arguments::get_java_home(); 631 size_t path_len = strlen(home) + strlen("/lib/jvmci/options") + 1; 632 char path[JVM_MAXPATHLEN]; 633 char sep = os::file_separator()[0]; 634 jio_snprintf(path, JVM_MAXPATHLEN, "%s%clib%cjvmci%coptions", home, sep, sep, sep); 635 struct stat st; 636 return os::stat(path, &st) == 0; 637 } 638 639 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) { 640 if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) { 641 #ifdef ASSERT 642 // This should only be called in the context of the JVMCI class being initialized 643 TempNewSymbol name = SymbolTable::new_symbol("jdk/vm/ci/runtime/JVMCI", CHECK); 644 Klass* k = SystemDictionary::resolve_or_null(name, CHECK); 645 instanceKlassHandle klass = InstanceKlass::cast(k); 646 assert(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD), 647 "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization"); 648 #endif 649 650 bool parseOptionsFile = jvmci_options_file_exists(); 651 if (_options != NULL || parseOptionsFile) { 652 JavaCallArguments args; 653 objArrayOop options; 654 if (_options != NULL) { 655 options = oopFactory::new_objArray(SystemDictionary::String_klass(), _options_count * 2, CHECK); 656 for (int i = 0; i < _options_count; i++) { 657 SystemProperty* prop = _options[i]; 658 oop name = java_lang_String::create_oop_from_str(prop->key() + OPTION_PREFIX_LEN, CHECK); 659 oop value = java_lang_String::create_oop_from_str(prop->value(), CHECK); 660 options->obj_at_put(i * 2, name); 661 options->obj_at_put((i * 2) + 1, value); 662 } 663 } else { 664 options = NULL; 665 } 666 args.push_oop(options); 667 args.push_int(parseOptionsFile); 668 callStatic("jdk/vm/ci/options/OptionsParser", 669 "parseOptionsFromVM", 670 "([Ljava/lang/String;Z)Ljava/lang/Boolean;", &args, CHECK); 671 } 672 673 if (_compiler != NULL) { 674 JavaCallArguments args; 675 oop compiler = java_lang_String::create_oop_from_str(_compiler, CHECK); 676 args.push_oop(compiler); 677 callStatic("jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig", 678 "selectCompiler", 679 "(Ljava/lang/String;)Ljava/lang/Boolean;", &args, CHECK); 680 } 681 682 Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime", 683 "runtime", 684 "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK); 685 _HotSpotJVMCIRuntime_initialized = true; 686 _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result()); 687 } 688 } 689 690 void JVMCIRuntime::initialize_JVMCI(TRAPS) { 691 if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) { 692 callStatic("jdk/vm/ci/runtime/JVMCI", 693 "getRuntime", 694 "()Ljdk/vm/ci/runtime/JVMCIRuntime;", NULL, CHECK); 695 } 696 assert(_HotSpotJVMCIRuntime_initialized == true, "what?"); 697 } 698 699 void JVMCIRuntime::initialize_well_known_classes(TRAPS) { 700 if (JVMCIRuntime::_well_known_classes_initialized == false) { 701 SystemDictionary::WKID scan = SystemDictionary::FIRST_JVMCI_WKID; 702 SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_JVMCI_WKID, scan, CHECK); 703 JVMCIJavaClasses::compute_offsets(); 704 JVMCIRuntime::_well_known_classes_initialized = true; 860 os::closedir(dir); 861 } 862 } 863 864 #define CHECK_WARN_ABORT_(message) THREAD); \ 865 if (HAS_PENDING_EXCEPTION) { \ 866 warning(message); \ 867 char buf[512]; \ 868 jio_snprintf(buf, 512, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ 869 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \ 870 return; \ 871 } \ 872 (void)(0 873 874 void JVMCIRuntime::save_compiler(const char* compiler) { 875 assert(compiler != NULL, "npe"); 876 assert(_compiler == NULL, "cannot reassign JVMCI compiler"); 877 _compiler = compiler; 878 } 879 880 jint JVMCIRuntime::save_options(SystemProperty* props) { 881 int count = 0; 882 SystemProperty* first = NULL; 883 for (SystemProperty* p = props; p != NULL; p = p->next()) { 884 if (strncmp(p->key(), OPTION_PREFIX, OPTION_PREFIX_LEN) == 0) { 885 if (p->value() == NULL || strlen(p->value()) == 0) { 886 jio_fprintf(defaultStream::output_stream(), "JVMCI option %s must have non-zero length value\n", p->key()); 887 return JNI_ERR; 888 } 889 if (first == NULL) { 890 first = p; 891 } 892 count++; 893 } 894 } 895 if (count != 0) { 896 _options_count = count; 897 _options = NEW_C_HEAP_ARRAY(SystemProperty*, count, mtCompiler); 898 _options[0] = first; 899 SystemProperty** insert_pos = _options + 1; 900 for (SystemProperty* p = first->next(); p != NULL; p = p->next()) { 901 if (strncmp(p->key(), OPTION_PREFIX, OPTION_PREFIX_LEN) == 0) { 902 *insert_pos = p; 903 insert_pos++; 904 } 905 } 906 assert (insert_pos - _options == count, "must be"); 907 } 908 return JNI_OK; 909 } 910 911 void JVMCIRuntime::shutdown() { 912 if (_HotSpotJVMCIRuntime_instance != NULL) { 913 _shutdown_called = true; 914 JavaThread* THREAD = JavaThread::current(); 915 HandleMark hm(THREAD); 916 Handle receiver = get_HotSpotJVMCIRuntime(CHECK_ABORT); 917 JavaValue result(T_VOID); 918 JavaCallArguments args; 919 args.push_oop(receiver); 920 JavaCalls::call_special(&result, receiver->klass(), vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, CHECK_ABORT); 921 } 922 } 923 924 void JVMCIRuntime::call_printStackTrace(Handle exception, Thread* thread) { 925 assert(exception->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected"); 926 JavaValue result(T_VOID); 927 JavaCalls::call_virtual(&result, 928 exception, 929 KlassHandle(thread, 930 SystemDictionary::Throwable_klass()), 931 vmSymbols::printStackTrace_name(), 932 vmSymbols::void_method_signature(), 933 thread); 934 } 935 936 void JVMCIRuntime::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) { 937 Thread* THREAD = Thread::current(); 938 CLEAR_PENDING_EXCEPTION; 939 tty->print_raw_cr(message); 940 call_printStackTrace(exception, THREAD); 941 942 // Give other aborting threads to also print their stack traces. 943 // This can be very useful when debugging class initialization 944 // failures. 945 os::sleep(THREAD, 200, false); 946 947 vm_abort(dump_core); 948 } 949 950 void JVMCIRuntime::parse_lines(char* path, ParseClosure* closure, bool warnStatFailure) { 951 struct stat st; 952 if (os::stat(path, &st) == 0 && (st.st_mode & S_IFREG) == S_IFREG) { // exists & is regular file 953 int file_handle = os::open(path, 0, 0); 954 if (file_handle != -1) { 955 char* buffer = NEW_C_HEAP_ARRAY(char, st.st_size + 1, mtInternal); 956 int num_read; 957 num_read = (int) os::read(file_handle, (char*) buffer, st.st_size); 958 if (num_read == -1) { 959 warning("Error reading file %s due to %s", path, strerror(errno)); 960 } else if (num_read != st.st_size) { 961 warning("Only read %d of " SIZE_FORMAT " bytes from %s", num_read, (size_t) st.st_size, path); 962 } 963 os::close(file_handle); 964 closure->set_filename(path); 965 if (num_read == st.st_size) { 966 buffer[num_read] = '\0'; 967 968 char* line = buffer; 969 while (line - buffer < num_read && !closure->is_aborted()) { 970 // find line end (\r, \n or \r\n) 971 char* nextline = NULL; 972 char* cr = strchr(line, '\r'); 973 char* lf = strchr(line, '\n'); 974 if (cr != NULL && lf != NULL) { 975 char* min = MIN2(cr, lf); 976 *min = '\0'; 977 if (lf == cr + 1) { 978 nextline = lf + 1; 979 } else { 980 nextline = min + 1; 981 } 982 } else if (cr != NULL) { 983 *cr = '\0'; | 35 #include "oops/oop.inline.hpp" 36 #include "oops/objArrayOop.inline.hpp" 37 #include "prims/jvm.h" 38 #include "runtime/biasedLocking.hpp" 39 #include "runtime/interfaceSupport.hpp" 40 #include "runtime/reflection.hpp" 41 #include "runtime/sharedRuntime.hpp" 42 #include "utilities/debug.hpp" 43 #include "utilities/defaultStream.hpp" 44 45 #if defined(_MSC_VER) 46 #define strtoll _strtoi64 47 #endif 48 49 jobject JVMCIRuntime::_HotSpotJVMCIRuntime_instance = NULL; 50 bool JVMCIRuntime::_HotSpotJVMCIRuntime_initialized = false; 51 bool JVMCIRuntime::_well_known_classes_initialized = false; 52 const char* JVMCIRuntime::_compiler = NULL; 53 int JVMCIRuntime::_options_count = 0; 54 SystemProperty** JVMCIRuntime::_options = NULL; 55 int JVMCIRuntime::_trivial_prefixes_count = 0; 56 char** JVMCIRuntime::_trivial_prefixes = NULL; 57 bool JVMCIRuntime::_shutdown_called = false; 58 59 static const char* OPTION_PREFIX = "jvmci.option."; 60 static const size_t OPTION_PREFIX_LEN = strlen(OPTION_PREFIX); 61 62 BasicType JVMCIRuntime::kindToBasicType(jchar ch) { 63 switch(ch) { 64 case 'z': return T_BOOLEAN; 65 case 'b': return T_BYTE; 66 case 's': return T_SHORT; 67 case 'c': return T_CHAR; 68 case 'i': return T_INT; 69 case 'f': return T_FLOAT; 70 case 'j': return T_LONG; 71 case 'd': return T_DOUBLE; 72 case 'a': return T_OBJECT; 73 case '-': return T_ILLEGAL; 74 default: 75 fatal("unexpected Kind: %c", ch); 76 break; 418 } 419 thread->print_stack_on(tty); 420 assert(false, "invalid lock object pointer dected"); 421 } 422 #endif 423 424 if (JVMCIUseFastLocking) { 425 // When using fast locking, the compiled code has already tried the fast case 426 ObjectSynchronizer::slow_exit(obj, lock, THREAD); 427 } else { 428 ObjectSynchronizer::fast_exit(obj, lock, THREAD); 429 } 430 IF_TRACE_jvmci_3 { 431 char type[O_BUFLEN]; 432 obj->klass()->name()->as_C_string(type, O_BUFLEN); 433 TRACE_jvmci_3("%s: exited locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), p2i(obj), type, p2i(obj->mark()), p2i(lock)); 434 tty->flush(); 435 } 436 JRT_END 437 438 JRT_LEAF(void, JVMCIRuntime::log_object(JavaThread* thread, oopDesc* obj, bool as_string, bool newline)) 439 ttyLocker ttyl; 440 441 if (obj == NULL) { 442 tty->print("NULL"); 443 } else if (obj->is_oop_or_null(true) && (!as_string || !java_lang_String::is_instance(obj))) { 444 if (obj->is_oop_or_null(true)) { 445 char buf[O_BUFLEN]; 446 tty->print("%s@" INTPTR_FORMAT, obj->klass()->name()->as_C_string(buf, O_BUFLEN), p2i(obj)); 447 } else { 448 tty->print(INTPTR_FORMAT, p2i(obj)); 449 } 450 } else { 451 ResourceMark rm; 452 assert(obj != NULL && java_lang_String::is_instance(obj), "must be"); 453 char *buf = java_lang_String::as_utf8_string(obj); 454 tty->print_raw(buf); 455 } 456 if (newline) { 457 tty->cr(); 458 } 459 JRT_END 460 461 JRT_LEAF(void, JVMCIRuntime::write_barrier_pre(JavaThread* thread, oopDesc* obj)) 462 thread->satb_mark_queue().enqueue(obj); 463 JRT_END 464 614 JVM_END 615 616 Handle JVMCIRuntime::callStatic(const char* className, const char* methodName, const char* signature, JavaCallArguments* args, TRAPS) { 617 guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime"); 618 619 TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_(Handle())); 620 KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle())); 621 TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_(Handle())); 622 TempNewSymbol sig = SymbolTable::new_symbol(signature, CHECK_(Handle())); 623 JavaValue result(T_OBJECT); 624 if (args == NULL) { 625 JavaCalls::call_static(&result, klass, runtime, sig, CHECK_(Handle())); 626 } else { 627 JavaCalls::call_static(&result, klass, runtime, sig, args, CHECK_(Handle())); 628 } 629 return Handle((oop)result.get_jobject()); 630 } 631 632 static bool jvmci_options_file_exists() { 633 const char* home = Arguments::get_java_home(); 634 size_t path_len = strlen(home) + strlen("/lib/jvmci.options") + 1; 635 char path[JVM_MAXPATHLEN]; 636 char sep = os::file_separator()[0]; 637 jio_snprintf(path, JVM_MAXPATHLEN, "%s%clib%cjvmci.options", home, sep, sep); 638 struct stat st; 639 return os::stat(path, &st) == 0; 640 } 641 642 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) { 643 if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) { 644 #ifdef ASSERT 645 // This should only be called in the context of the JVMCI class being initialized 646 TempNewSymbol name = SymbolTable::new_symbol("jdk/vm/ci/runtime/JVMCI", CHECK); 647 Klass* k = SystemDictionary::resolve_or_null(name, CHECK); 648 instanceKlassHandle klass = InstanceKlass::cast(k); 649 assert(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD), 650 "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization"); 651 #endif 652 653 bool parseOptionsFile = jvmci_options_file_exists(); 654 if (_options != NULL || parseOptionsFile) { 655 JavaCallArguments args; 656 objArrayOop options; 657 if (_options != NULL) { 658 options = oopFactory::new_objArray(SystemDictionary::String_klass(), _options_count * 2, CHECK); 659 for (int i = 0; i < _options_count; i++) { 660 SystemProperty* prop = _options[i]; 661 oop name = java_lang_String::create_oop_from_str(prop->key() + OPTION_PREFIX_LEN, CHECK); 662 const char* prop_value = prop->value() != NULL ? prop->value() : ""; 663 oop value = java_lang_String::create_oop_from_str(prop_value, CHECK); 664 options->obj_at_put(i * 2, name); 665 options->obj_at_put((i * 2) + 1, value); 666 } 667 } else { 668 options = NULL; 669 } 670 args.push_oop(options); 671 args.push_int(parseOptionsFile); 672 callStatic("jdk/vm/ci/options/OptionsParser", 673 "parseOptionsFromVM", 674 "([Ljava/lang/String;Z)Ljava/lang/Boolean;", &args, CHECK); 675 } 676 677 if (_compiler != NULL) { 678 JavaCallArguments args; 679 oop compiler = java_lang_String::create_oop_from_str(_compiler, CHECK); 680 args.push_oop(compiler); 681 callStatic("jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig", 682 "selectCompiler", 683 "(Ljava/lang/String;)Ljava/lang/Boolean;", &args, CHECK); 684 } 685 686 Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime", 687 "runtime", 688 "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK); 689 objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result); 690 if (trivial_prefixes != NULL) { 691 char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler); 692 for (int i = 0; i < trivial_prefixes->length(); i++) { 693 oop str = trivial_prefixes->obj_at(i); 694 if (str == NULL) { 695 THROW(vmSymbols::java_lang_NullPointerException()); 696 } else { 697 prefixes[i] = strdup(java_lang_String::as_utf8_string(str)); 698 } 699 } 700 _trivial_prefixes = prefixes; 701 _trivial_prefixes_count = trivial_prefixes->length(); 702 } 703 _HotSpotJVMCIRuntime_initialized = true; 704 _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result()); 705 } 706 } 707 708 void JVMCIRuntime::initialize_JVMCI(TRAPS) { 709 if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) { 710 callStatic("jdk/vm/ci/runtime/JVMCI", 711 "getRuntime", 712 "()Ljdk/vm/ci/runtime/JVMCIRuntime;", NULL, CHECK); 713 } 714 assert(_HotSpotJVMCIRuntime_initialized == true, "what?"); 715 } 716 717 void JVMCIRuntime::initialize_well_known_classes(TRAPS) { 718 if (JVMCIRuntime::_well_known_classes_initialized == false) { 719 SystemDictionary::WKID scan = SystemDictionary::FIRST_JVMCI_WKID; 720 SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_JVMCI_WKID, scan, CHECK); 721 JVMCIJavaClasses::compute_offsets(); 722 JVMCIRuntime::_well_known_classes_initialized = true; 878 os::closedir(dir); 879 } 880 } 881 882 #define CHECK_WARN_ABORT_(message) THREAD); \ 883 if (HAS_PENDING_EXCEPTION) { \ 884 warning(message); \ 885 char buf[512]; \ 886 jio_snprintf(buf, 512, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ 887 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \ 888 return; \ 889 } \ 890 (void)(0 891 892 void JVMCIRuntime::save_compiler(const char* compiler) { 893 assert(compiler != NULL, "npe"); 894 assert(_compiler == NULL, "cannot reassign JVMCI compiler"); 895 _compiler = compiler; 896 } 897 898 void JVMCIRuntime::maybe_print_flags(TRAPS) { 899 if (_options != NULL) { 900 for (int i = 0; i < _options_count; i++) { 901 SystemProperty* p = _options[i]; 902 const char* name = p->key() + OPTION_PREFIX_LEN; 903 if (strcmp(name, "PrintFlags") == 0 || strcmp(name, "ShowFlags") == 0) { 904 JVMCIRuntime::initialize_well_known_classes(CHECK); 905 HandleMark hm; 906 ResourceMark rm; 907 JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK); 908 return; 909 } 910 } 911 } 912 } 913 914 void JVMCIRuntime::save_options(SystemProperty* props) { 915 int count = 0; 916 SystemProperty* first = NULL; 917 for (SystemProperty* p = props; p != NULL; p = p->next()) { 918 if (strncmp(p->key(), OPTION_PREFIX, OPTION_PREFIX_LEN) == 0) { 919 if (first == NULL) { 920 first = p; 921 } 922 count++; 923 } 924 } 925 if (count != 0) { 926 _options_count = count; 927 _options = NEW_C_HEAP_ARRAY(SystemProperty*, count, mtCompiler); 928 _options[0] = first; 929 SystemProperty** insert_pos = _options + 1; 930 for (SystemProperty* p = first->next(); p != NULL; p = p->next()) { 931 if (strncmp(p->key(), OPTION_PREFIX, OPTION_PREFIX_LEN) == 0) { 932 *insert_pos = p; 933 insert_pos++; 934 } 935 } 936 assert (insert_pos - _options == count, "must be"); 937 } 938 } 939 940 void JVMCIRuntime::shutdown() { 941 if (_HotSpotJVMCIRuntime_instance != NULL) { 942 _shutdown_called = true; 943 JavaThread* THREAD = JavaThread::current(); 944 HandleMark hm(THREAD); 945 Handle receiver = get_HotSpotJVMCIRuntime(CHECK_ABORT); 946 JavaValue result(T_VOID); 947 JavaCallArguments args; 948 args.push_oop(receiver); 949 JavaCalls::call_special(&result, receiver->klass(), vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, CHECK_ABORT); 950 } 951 } 952 953 bool JVMCIRuntime::treat_as_trivial(Method* method) { 954 if (_HotSpotJVMCIRuntime_initialized) { 955 oop loader = method->method_holder()->class_loader(); 956 if (loader == NULL) { 957 for (int i = 0; i < _trivial_prefixes_count; i++) { 958 if (method->method_holder()->name()->starts_with(_trivial_prefixes[i])) { 959 return true; 960 } 961 } 962 } 963 } 964 return false; 965 } 966 967 void JVMCIRuntime::call_printStackTrace(Handle exception, Thread* thread) { 968 assert(exception->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected"); 969 JavaValue result(T_VOID); 970 JavaCalls::call_virtual(&result, 971 exception, 972 KlassHandle(thread, 973 SystemDictionary::Throwable_klass()), 974 vmSymbols::printStackTrace_name(), 975 vmSymbols::void_method_signature(), 976 thread); 977 } 978 979 void JVMCIRuntime::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) { 980 Thread* THREAD = Thread::current(); 981 CLEAR_PENDING_EXCEPTION; 982 tty->print_raw_cr(message); 983 call_printStackTrace(exception, THREAD); 984 985 // Give other aborting threads to also print their stack traces. 986 // This can be very useful when debugging class initialization 987 // failures. 988 os::sleep(THREAD, 200, false); 989 990 vm_abort(dump_core); 991 } 992 993 void JVMCIRuntime::parse_lines(char* path, ParseClosure* closure, bool warnStatFailure) { 994 struct stat st; 995 if (::stat(path, &st) == 0 && (st.st_mode & S_IFREG) == S_IFREG) { // exists & is regular file 996 int file_handle = ::open(path, os::default_file_open_flags(), 0); 997 if (file_handle != -1) { 998 char* buffer = NEW_C_HEAP_ARRAY(char, st.st_size + 1, mtInternal); 999 int num_read; 1000 num_read = (int) ::read(file_handle, (char*) buffer, st.st_size); 1001 if (num_read == -1) { 1002 warning("Error reading file %s due to %s", path, strerror(errno)); 1003 } else if (num_read != st.st_size) { 1004 warning("Only read %d of " SIZE_FORMAT " bytes from %s", num_read, (size_t) st.st_size, path); 1005 } 1006 ::close(file_handle); 1007 closure->set_filename(path); 1008 if (num_read == st.st_size) { 1009 buffer[num_read] = '\0'; 1010 1011 char* line = buffer; 1012 while (line - buffer < num_read && !closure->is_aborted()) { 1013 // find line end (\r, \n or \r\n) 1014 char* nextline = NULL; 1015 char* cr = strchr(line, '\r'); 1016 char* lf = strchr(line, '\n'); 1017 if (cr != NULL && lf != NULL) { 1018 char* min = MIN2(cr, lf); 1019 *min = '\0'; 1020 if (lf == cr + 1) { 1021 nextline = lf + 1; 1022 } else { 1023 nextline = min + 1; 1024 } 1025 } else if (cr != NULL) { 1026 *cr = '\0'; |