Mercurial > hg > truffle
comparison src/share/vm/graal/graalRuntime.cpp @ 15603:b7fb36e57da8
made Graal initialization be driven from Java to simplify sequencing and synchronization
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 12 May 2014 23:27:07 +0200 |
parents | ddb3ef30fcd2 |
children | fe608a56e3f7 |
comparison
equal
deleted
inserted
replaced
15602:c73df62cbaee | 15603:b7fb36e57da8 |
---|---|
35 #include "runtime/arguments.hpp" | 35 #include "runtime/arguments.hpp" |
36 #include "runtime/reflection.hpp" | 36 #include "runtime/reflection.hpp" |
37 #include "utilities/debug.hpp" | 37 #include "utilities/debug.hpp" |
38 | 38 |
39 address GraalRuntime::_external_deopt_i2c_entry = NULL; | 39 address GraalRuntime::_external_deopt_i2c_entry = NULL; |
40 volatile GraalRuntime::State GraalRuntime::_state = uninitialized; | 40 |
41 Thread* GraalRuntime::_initializingThread = NULL; | 41 void GraalRuntime::initialize_natives(JNIEnv *env, jclass c2vmClass) { |
42 | |
43 bool GraalRuntime::should_perform_init() { | |
44 JavaThread* THREAD = JavaThread::current(); | |
45 if (_state != initialized) { | |
46 if (THREAD == _initializingThread) { | |
47 return false; | |
48 } | |
49 MutexLocker locker(GraalInitialization_lock); | |
50 if (_state == uninitialized) { | |
51 _state = initializing; | |
52 _initializingThread = THREAD; | |
53 return true; | |
54 } else { | |
55 while (_state == initializing) { | |
56 GraalInitialization_lock->wait(); | |
57 } | |
58 } | |
59 } | |
60 return false; | |
61 } | |
62 | |
63 void GraalRuntime::initialize() { | |
64 if (!should_perform_init()) { | |
65 return; | |
66 } | |
67 | |
68 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end(); | 42 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end(); |
69 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024; | 43 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024; |
70 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)")); | 44 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)")); |
71 NOT_LP64(error("check TLAB allocation code for address space conflicts")); | 45 NOT_LP64(error("check TLAB allocation code for address space conflicts")); |
72 | 46 |
73 JavaThread* THREAD = JavaThread::current(); | 47 JavaThread* THREAD = JavaThread::current(); |
74 ThreadToNativeFromVM trans(THREAD); | |
75 TRACE_graal_1("GraalRuntime::initialize"); | |
76 | |
77 JNIEnv *env = ((JavaThread *) Thread::current())->jni_environment(); | |
78 jclass klass = env->FindClass("com/oracle/graal/hotspot/bridge/CompilerToVMImpl"); | |
79 if (klass == NULL) { | |
80 tty->print_cr("graal CompilerToVMImpl class not found"); | |
81 vm_abort(false); | |
82 } | |
83 env->RegisterNatives(klass, CompilerToVM_methods, CompilerToVM_methods_count()); | |
84 | |
85 ResourceMark rm; | |
86 HandleMark hm; | |
87 { | 48 { |
88 GRAAL_VM_ENTRY_MARK; | 49 ThreadToNativeFromVM trans(THREAD); |
89 check_pending_exception("Could not register natives"); | 50 |
90 } | 51 ResourceMark rm; |
91 | |
92 graal_compute_offsets(); | |
93 | |
94 // Ensure _non_oop_bits is initialized | |
95 Universe::non_oop_word(); | |
96 | |
97 { | |
98 GRAAL_VM_ENTRY_MARK; | |
99 HandleMark hm; | 52 HandleMark hm; |
100 VMToCompiler::initOptions(); | 53 |
101 for (int i = 0; i < Arguments::num_graal_args(); ++i) { | 54 graal_compute_offsets(); |
102 const char* arg = Arguments::graal_args_array()[i]; | |
103 Handle option = java_lang_String::create_from_str(arg, THREAD); | |
104 jboolean result = VMToCompiler::setOption(option); | |
105 if (!result) { | |
106 tty->print_cr("Invalid option for graal: -G:%s", arg); | |
107 vm_abort(false); | |
108 } | |
109 } | |
110 VMToCompiler::finalizeOptions(CITime || CITimeEach); | |
111 | 55 |
112 _external_deopt_i2c_entry = create_external_deopt_i2c(); | 56 _external_deopt_i2c_entry = create_external_deopt_i2c(); |
113 | 57 |
114 VMToCompiler::startRuntime(); | 58 // Ensure _non_oop_bits is initialized |
115 | 59 Universe::non_oop_word(); |
116 { | 60 |
117 MutexLocker locker(GraalInitialization_lock); | 61 env->RegisterNatives(c2vmClass, CompilerToVM_methods, CompilerToVM_methods_count()); |
118 _state = initialized; | 62 } |
119 _initializingThread = NULL; | 63 check_pending_exception("Could not register natives"); |
120 } | |
121 | |
122 #if !defined(PRODUCT) && !defined(COMPILERGRAAL) | |
123 // In COMPILERGRAAL, we want to allow GraalBootstrap | |
124 // to happen first so GraalCompiler::initialize() | |
125 // duplicates the following code. | |
126 if (CompileTheWorld) { | |
127 VMToCompiler::compileTheWorld(); | |
128 } | |
129 #endif | |
130 } | |
131 } | 64 } |
132 | 65 |
133 BufferBlob* GraalRuntime::initialize_buffer_blob() { | 66 BufferBlob* GraalRuntime::initialize_buffer_blob() { |
134 JavaThread* THREAD = JavaThread::current(); | 67 JavaThread* THREAD = JavaThread::current(); |
135 BufferBlob* buffer_blob = THREAD->get_buffer_blob(); | 68 BufferBlob* buffer_blob = THREAD->get_buffer_blob(); |
701 } else { | 634 } else { |
702 return (jint) Thread::is_interrupted(receiverThread, clear_interrupted != 0); | 635 return (jint) Thread::is_interrupted(receiverThread, clear_interrupted != 0); |
703 } | 636 } |
704 JRT_END | 637 JRT_END |
705 | 638 |
706 // JVM_InitializeGraalRuntime | 639 // private static GraalRuntime Graal.initializeRuntime() |
707 JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass)) | 640 JVM_ENTRY(jobject, JVM_GetGraalRuntime(JNIEnv *env, jclass c)) |
708 GraalRuntime::initialize(); | |
709 return VMToCompiler::get_HotSpotGraalRuntime_jobject(); | 641 return VMToCompiler::get_HotSpotGraalRuntime_jobject(); |
710 JVM_END | 642 JVM_END |
711 | 643 |
712 // JVM_InitializeTruffleRuntime | 644 // private static TruffleRuntime Truffle.createRuntime() |
713 JVM_ENTRY(jobject, JVM_InitializeTruffleRuntime(JNIEnv *env, jclass graalclass)) | 645 JVM_ENTRY(jobject, JVM_CreateTruffleRuntime(JNIEnv *env, jclass c)) |
714 GraalRuntime::initialize(); | |
715 return JNIHandles::make_local(VMToCompiler::create_HotSpotTruffleRuntime()()); | 646 return JNIHandles::make_local(VMToCompiler::create_HotSpotTruffleRuntime()()); |
716 JVM_END | 647 JVM_END |
648 | |
649 // private static void HotSpotGraalRuntime.init(Class compilerToVMClass) | |
650 JVM_ENTRY(void, JVM_InitializeGraalNatives(JNIEnv *env, jclass c, jclass c2vmClass)) | |
651 GraalRuntime::initialize_natives(env, c2vmClass); | |
652 JVM_END | |
653 | |
654 // private static String[] HotSpotOptions.getVMOptions(boolean[] timeCompilations) | |
655 JVM_ENTRY(jobject, JVM_GetGraalOptions(JNIEnv *env, jclass c, jobject timeCompilations)) | |
656 HandleMark hm; | |
657 int numOptions = Arguments::num_graal_args(); | |
658 objArrayOop options = oopFactory::new_objArray(SystemDictionary::String_klass(), | |
659 numOptions, CHECK_NULL); | |
660 objArrayHandle optionsHandle(THREAD, options); | |
661 for (int i = 0; i < numOptions; i++) { | |
662 Handle option = java_lang_String::create_from_str(Arguments::graal_args_array()[i], CHECK_NULL); | |
663 optionsHandle->obj_at_put(i, option()); | |
664 } | |
665 ((typeArrayOop) JNIHandles::resolve(timeCompilations))->bool_at_put(0, CITime || CITimeEach); | |
666 return JNIHandles::make_local(THREAD, optionsHandle()); | |
667 JVM_END |