comparison src/share/vm/graal/graalRuntime.cpp @ 18614:c307546c7b0a

made initialization of the Graal class loader and well known Graal classes lazy
author Doug Simon <doug.simon@oracle.com>
date Thu, 04 Dec 2014 13:42:56 +0100
parents ab47ef2f2207
children 0aec14bcf006
comparison
equal deleted inserted replaced
18613:8c3a85077f84 18614:c307546c7b0a
47 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end(); 47 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end();
48 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024; 48 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024;
49 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)")); 49 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)"));
50 NOT_LP64(error("check TLAB allocation code for address space conflicts")); 50 NOT_LP64(error("check TLAB allocation code for address space conflicts"));
51 51
52 ensure_graal_class_loader_is_initialized();
53
52 JavaThread* THREAD = JavaThread::current(); 54 JavaThread* THREAD = JavaThread::current();
53 { 55 {
54 ThreadToNativeFromVM trans(THREAD); 56 ThreadToNativeFromVM trans(THREAD);
55 57
56 ResourceMark rm; 58 ResourceMark rm;
654 JRT_ENTRY(jint, GraalRuntime::test_deoptimize_call_int(JavaThread* thread, int value)) 656 JRT_ENTRY(jint, GraalRuntime::test_deoptimize_call_int(JavaThread* thread, int value))
655 deopt_caller(); 657 deopt_caller();
656 return value; 658 return value;
657 JRT_END 659 JRT_END
658 660
661 // private static void Factory.init()
662 JVM_ENTRY(void, JVM_InitGraalClassLoader(JNIEnv *env, jclass c, jobject loader_handle))
663 SystemDictionary::init_graal_loader(JNIHandles::resolve(loader_handle));
664 SystemDictionary::WKID scan = SystemDictionary::FIRST_GRAAL_WKID;
665 SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_GRAAL_WKID, scan, CHECK);
666 JVM_END
667
659 // private static GraalRuntime Graal.initializeRuntime() 668 // private static GraalRuntime Graal.initializeRuntime()
660 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c)) 669 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c))
661 return GraalRuntime::get_HotSpotGraalRuntime_jobject(); 670 return GraalRuntime::get_HotSpotGraalRuntime_jobject();
662 JVM_END 671 JVM_END
663 672
746 KlassHandle hotSpotOptionsClass(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(c))); 755 KlassHandle hotSpotOptionsClass(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(c)));
747 bool result = GraalRuntime::parse_arguments(hotSpotOptionsClass, CHECK_false); 756 bool result = GraalRuntime::parse_arguments(hotSpotOptionsClass, CHECK_false);
748 return result; 757 return result;
749 JVM_END 758 JVM_END
750 759
760
761 void GraalRuntime::ensure_graal_class_loader_is_initialized() {
762 // This initialization code is guarded by a static pointer to the Factory class.
763 // Once it is non-null, the Graal class loader and well know Graal classes are
764 // guaranteed to have been initialized. By going through the static
765 // initializer of Factory, we can rely on class initialization semantics to
766 // synchronize threads racing to do the initialization.
767 static Klass* _FactoryKlass = NULL;
768 if (_FactoryKlass == NULL) {
769 Thread* THREAD = Thread::current();
770 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/loader/Factory", CHECK_ABORT);
771 KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, THREAD);
772 if (HAS_PENDING_EXCEPTION) {
773 abort_on_pending_exception(PENDING_EXCEPTION, "Graal classes are not available");
774 }
775 TempNewSymbol field_name = SymbolTable::new_symbol("useGraalClassLoader", CHECK_ABORT);
776
777 fieldDescriptor field_desc;
778 if (klass->find_field(field_name, vmSymbols::bool_signature(), &field_desc) == NULL) {
779 ResourceMark rm;
780 fatal(err_msg("Invalid layout of %s at %s", field_name->as_C_string(), klass->external_name()));
781 }
782 InstanceKlass* ik = InstanceKlass::cast(klass());
783 address addr = ik->static_field_addr(field_desc.offset() - InstanceMirrorKlass::offset_of_static_fields());
784 *((jboolean *) addr) = (jboolean) UseGraalClassLoader;
785 klass->initialize(CHECK_ABORT);
786 _FactoryKlass = klass();
787 }
788 }
789
751 jint GraalRuntime::check_arguments(TRAPS) { 790 jint GraalRuntime::check_arguments(TRAPS) {
752 KlassHandle nullHandle; 791 KlassHandle nullHandle;
753 parse_arguments(nullHandle, THREAD); 792 parse_arguments(nullHandle, THREAD);
754 if (HAS_PENDING_EXCEPTION) { 793 if (HAS_PENDING_EXCEPTION) {
755 // Errors in parsing Graal arguments cause exceptions. 794 // Errors in parsing Graal arguments cause exceptions.
798 THROW_MSG(vmSymbols::java_lang_InternalError(), buf); 837 THROW_MSG(vmSymbols::java_lang_InternalError(), buf);
799 } 838 }
800 } 839 }
801 840
802 void GraalRuntime::parse_argument(KlassHandle hotSpotOptionsClass, char* arg, TRAPS) { 841 void GraalRuntime::parse_argument(KlassHandle hotSpotOptionsClass, char* arg, TRAPS) {
842 ensure_graal_class_loader_is_initialized();
803 char first = arg[0]; 843 char first = arg[0];
804 char* name; 844 char* name;
805 size_t name_len; 845 size_t name_len;
806 bool recognized = true; 846 bool recognized = true;
807 if (first == '+' || first == '-') { 847 if (first == '+' || first == '-') {
1015 vmSymbols::printStackTrace_name(), 1055 vmSymbols::printStackTrace_name(),
1016 vmSymbols::void_method_signature(), 1056 vmSymbols::void_method_signature(),
1017 thread); 1057 thread);
1018 } 1058 }
1019 1059
1020 oop GraalRuntime::compute_graal_class_loader(TRAPS) {
1021 assert(UseGraalClassLoader, "must be");
1022 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/loader/Factory", CHECK_NULL);
1023 KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, CHECK_NULL);
1024
1025 TempNewSymbol getClassLoader = SymbolTable::new_symbol("newClassLoader", CHECK_NULL);
1026 JavaValue result(T_OBJECT);
1027 JavaCalls::call_static(&result, klass, getClassLoader, vmSymbols::void_classloader_signature(), CHECK_NULL);
1028 return (oop) result.get_jobject();
1029 }
1030
1031 void GraalRuntime::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) { 1060 void GraalRuntime::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) {
1032 Thread* THREAD = Thread::current(); 1061 Thread* THREAD = Thread::current();
1033 CLEAR_PENDING_EXCEPTION; 1062 CLEAR_PENDING_EXCEPTION;
1034 tty->print_raw_cr(message); 1063 tty->print_raw_cr(message);
1035 call_printStackTrace(exception, THREAD); 1064 call_printStackTrace(exception, THREAD);