src/share/vm/jvmci/jvmciRuntime.cpp

Print this page




  33 #include "jvmci/jvmciEnv.hpp"
  34 #include "memory/oopFactory.hpp"
  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(Handle kind, TRAPS) {
  63   if (kind.is_null()) {
  64     THROW_(vmSymbols::java_lang_NullPointerException(), T_ILLEGAL);
  65   }
  66   jchar ch = JavaKind::typeChar(kind);
  67   switch(ch) {
  68     case 'z': return T_BOOLEAN;
  69     case 'b': return T_BYTE;
  70     case 's': return T_SHORT;
  71     case 'c': return T_CHAR;
  72     case 'i': return T_INT;
  73     case 'f': return T_FLOAT;
  74     case 'j': return T_LONG;
  75     case 'd': return T_DOUBLE;
  76     case 'a': return T_OBJECT;
  77     case '-': return T_ILLEGAL;
  78     default:
  79       JVMCI_ERROR_(T_ILLEGAL, "unexpected Kind: %c", ch);
  80   }
  81 }


 614   jobject ret = JVMCIRuntime::get_HotSpotJVMCIRuntime_jobject(CHECK_NULL);
 615   return ret;
 616 JVM_END
 617 
 618 Handle JVMCIRuntime::callStatic(const char* className, const char* methodName, const char* signature, JavaCallArguments* args, TRAPS) {
 619   guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
 620 
 621   TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_(Handle()));
 622   KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle()));
 623   TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_(Handle()));
 624   TempNewSymbol sig = SymbolTable::new_symbol(signature, CHECK_(Handle()));
 625   JavaValue result(T_OBJECT);
 626   if (args == NULL) {
 627     JavaCalls::call_static(&result, klass, runtime, sig, CHECK_(Handle()));
 628   } else {
 629     JavaCalls::call_static(&result, klass, runtime, sig, args, CHECK_(Handle()));
 630   }
 631   return Handle((oop)result.get_jobject());
 632 }
 633 
 634 static bool jvmci_options_file_exists() {
 635   const char* home = Arguments::get_java_home();
 636   size_t path_len = strlen(home) + strlen("/lib/jvmci.options") + 1;
 637   char path[JVM_MAXPATHLEN];
 638   char sep = os::file_separator()[0];
 639   jio_snprintf(path, JVM_MAXPATHLEN, "%s%clib%cjvmci.options", home, sep, sep);
 640   struct stat st;
 641   return os::stat(path, &st) == 0;
 642 }
 643 
 644 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
 645   if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) {
 646 #ifdef ASSERT
 647     // This should only be called in the context of the JVMCI class being initialized
 648     TempNewSymbol name = SymbolTable::new_symbol("jdk/vm/ci/runtime/JVMCI", CHECK);
 649     Klass* k = SystemDictionary::resolve_or_null(name, CHECK);
 650     instanceKlassHandle klass = InstanceKlass::cast(k);
 651     assert(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD),
 652            "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
 653 #endif
 654 
 655     bool parseOptionsFile = jvmci_options_file_exists();
 656     if (_options != NULL || parseOptionsFile) {
 657       JavaCallArguments args;
 658       objArrayOop options;
 659       if (_options != NULL) {
 660         options = oopFactory::new_objArray(SystemDictionary::String_klass(), _options_count * 2, CHECK);
 661         for (int i = 0; i < _options_count; i++) {
 662           SystemProperty* prop = _options[i];
 663           oop name = java_lang_String::create_oop_from_str(prop->key() + OPTION_PREFIX_LEN, CHECK);
 664           const char* prop_value = prop->value() != NULL ? prop->value() : "";
 665           oop value = java_lang_String::create_oop_from_str(prop_value, CHECK);
 666           options->obj_at_put(i * 2, name);
 667           options->obj_at_put((i * 2) + 1, value);
 668         }
 669       } else {
 670         options = NULL;
 671       }
 672       args.push_oop(options);
 673       args.push_int(parseOptionsFile);
 674       callStatic("jdk/vm/ci/options/OptionsParser",
 675                  "parseOptionsFromVM",
 676                  "([Ljava/lang/String;Z)Ljava/lang/Boolean;", &args, CHECK);
 677     }
 678 
 679     if (_compiler != NULL) {
 680       JavaCallArguments args;
 681       oop compiler = java_lang_String::create_oop_from_str(_compiler, CHECK);
 682       args.push_oop(compiler);
 683       callStatic("jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig",
 684                  "selectCompiler",
 685                  "(Ljava/lang/String;)Ljava/lang/Boolean;", &args, CHECK);
 686     }
 687 
 688     Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
 689                                "runtime",
 690                                "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
 691     objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
 692     if (trivial_prefixes != NULL) {
 693       char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
 694       for (int i = 0; i < trivial_prefixes->length(); i++) {
 695         oop str = trivial_prefixes->obj_at(i);
 696         if (str == NULL) {
 697           THROW(vmSymbols::java_lang_NullPointerException());
 698         } else {


 876     os::closedir(dir);
 877   }
 878 }
 879 
 880 #define CHECK_WARN_ABORT_(message) THREAD); \
 881   if (HAS_PENDING_EXCEPTION) { \
 882     warning(message); \
 883     char buf[512]; \
 884     jio_snprintf(buf, 512, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
 885     JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \
 886     return; \
 887   } \
 888   (void)(0
 889 
 890 void JVMCIRuntime::save_compiler(const char* compiler) {
 891   assert(compiler != NULL, "npe");
 892   assert(_compiler == NULL, "cannot reassign JVMCI compiler");
 893   _compiler = compiler;
 894 }
 895 
 896 void JVMCIRuntime::maybe_print_flags(TRAPS) {
 897   if (_options != NULL) {
 898     for (int i = 0; i < _options_count; i++) {
 899       SystemProperty* p = _options[i];
 900       const char* name = p->key() + OPTION_PREFIX_LEN;
 901       if (strcmp(name, "PrintFlags") == 0 || strcmp(name, "ShowFlags") == 0) {
 902         JVMCIRuntime::initialize_well_known_classes(CHECK);
 903         HandleMark hm;
 904         ResourceMark rm;
 905         JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK);
 906         return;
 907       }
 908     }
 909   }
 910 }
 911 
 912 void JVMCIRuntime::save_options(SystemProperty* props) {
 913   int count = 0;
 914   SystemProperty* first = NULL;
 915   for (SystemProperty* p = props; p != NULL; p = p->next()) {
 916     if (strncmp(p->key(), OPTION_PREFIX, OPTION_PREFIX_LEN) == 0) {
 917       if (first == NULL) {
 918         first = p;
 919       }
 920       count++;
 921     }
 922   }
 923   if (count != 0) {
 924     _options_count = count;
 925     _options = NEW_C_HEAP_ARRAY(SystemProperty*, count, mtCompiler);
 926     _options[0] = first;
 927     SystemProperty** insert_pos = _options + 1;
 928     for (SystemProperty* p = first->next(); p != NULL; p = p->next()) {
 929       if (strncmp(p->key(), OPTION_PREFIX, OPTION_PREFIX_LEN) == 0) {
 930         *insert_pos = p;
 931         insert_pos++;
 932       }
 933     }
 934     assert (insert_pos - _options == count, "must be");
 935   }
 936 }
 937 
 938 void JVMCIRuntime::shutdown() {
 939   if (_HotSpotJVMCIRuntime_instance != NULL) {
 940     _shutdown_called = true;
 941     JavaThread* THREAD = JavaThread::current();
 942     HandleMark hm(THREAD);
 943     Handle receiver = get_HotSpotJVMCIRuntime(CHECK_ABORT);
 944     JavaValue result(T_VOID);
 945     JavaCallArguments args;
 946     args.push_oop(receiver);
 947     JavaCalls::call_special(&result, receiver->klass(), vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, CHECK_ABORT);
 948   }
 949 }
 950 
 951 bool JVMCIRuntime::treat_as_trivial(Method* method) {
 952   if (_HotSpotJVMCIRuntime_initialized) {
 953     oop loader = method->method_holder()->class_loader();
 954     if (loader == NULL) {
 955       for (int i = 0; i < _trivial_prefixes_count; i++) {
 956         if (method->method_holder()->name()->starts_with(_trivial_prefixes[i])) {
 957           return true;




  33 #include "jvmci/jvmciEnv.hpp"
  34 #include "memory/oopFactory.hpp"
  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::_trivial_prefixes_count = 0;
  54 char** JVMCIRuntime::_trivial_prefixes = NULL;
  55 bool JVMCIRuntime::_shutdown_called = false;
  56 



  57 BasicType JVMCIRuntime::kindToBasicType(Handle kind, TRAPS) {
  58   if (kind.is_null()) {
  59     THROW_(vmSymbols::java_lang_NullPointerException(), T_ILLEGAL);
  60   }
  61   jchar ch = JavaKind::typeChar(kind);
  62   switch(ch) {
  63     case 'z': return T_BOOLEAN;
  64     case 'b': return T_BYTE;
  65     case 's': return T_SHORT;
  66     case 'c': return T_CHAR;
  67     case 'i': return T_INT;
  68     case 'f': return T_FLOAT;
  69     case 'j': return T_LONG;
  70     case 'd': return T_DOUBLE;
  71     case 'a': return T_OBJECT;
  72     case '-': return T_ILLEGAL;
  73     default:
  74       JVMCI_ERROR_(T_ILLEGAL, "unexpected Kind: %c", ch);
  75   }
  76 }


 609   jobject ret = JVMCIRuntime::get_HotSpotJVMCIRuntime_jobject(CHECK_NULL);
 610   return ret;
 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 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
 630   if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) {
 631 #ifdef ASSERT
 632     // This should only be called in the context of the JVMCI class being initialized
 633     TempNewSymbol name = SymbolTable::new_symbol("jdk/vm/ci/runtime/JVMCI", CHECK);
 634     Klass* k = SystemDictionary::resolve_or_null(name, CHECK);
 635     instanceKlassHandle klass = InstanceKlass::cast(k);
 636     assert(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD),
 637            "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
 638 #endif
 639 
























 640     if (_compiler != NULL) {
 641       JavaCallArguments args;
 642       oop compiler = java_lang_String::create_oop_from_str(_compiler, CHECK);
 643       args.push_oop(compiler);
 644       callStatic("jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig",
 645                  "selectCompiler",
 646                  "(Ljava/lang/String;)Ljava/lang/Boolean;", &args, CHECK);
 647     }
 648 
 649     Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
 650                                "runtime",
 651                                "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
 652     objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
 653     if (trivial_prefixes != NULL) {
 654       char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
 655       for (int i = 0; i < trivial_prefixes->length(); i++) {
 656         oop str = trivial_prefixes->obj_at(i);
 657         if (str == NULL) {
 658           THROW(vmSymbols::java_lang_NullPointerException());
 659         } else {


 837     os::closedir(dir);
 838   }
 839 }
 840 
 841 #define CHECK_WARN_ABORT_(message) THREAD); \
 842   if (HAS_PENDING_EXCEPTION) { \
 843     warning(message); \
 844     char buf[512]; \
 845     jio_snprintf(buf, 512, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
 846     JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \
 847     return; \
 848   } \
 849   (void)(0
 850 
 851 void JVMCIRuntime::save_compiler(const char* compiler) {
 852   assert(compiler != NULL, "npe");
 853   assert(_compiler == NULL, "cannot reassign JVMCI compiler");
 854   _compiler = compiler;
 855 }
 856 










































 857 void JVMCIRuntime::shutdown() {
 858   if (_HotSpotJVMCIRuntime_instance != NULL) {
 859     _shutdown_called = true;
 860     JavaThread* THREAD = JavaThread::current();
 861     HandleMark hm(THREAD);
 862     Handle receiver = get_HotSpotJVMCIRuntime(CHECK_ABORT);
 863     JavaValue result(T_VOID);
 864     JavaCallArguments args;
 865     args.push_oop(receiver);
 866     JavaCalls::call_special(&result, receiver->klass(), vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, CHECK_ABORT);
 867   }
 868 }
 869 
 870 bool JVMCIRuntime::treat_as_trivial(Method* method) {
 871   if (_HotSpotJVMCIRuntime_initialized) {
 872     oop loader = method->method_holder()->class_loader();
 873     if (loader == NULL) {
 874       for (int i = 0; i < _trivial_prefixes_count; i++) {
 875         if (method->method_holder()->name()->starts_with(_trivial_prefixes[i])) {
 876           return true;