comparison src/share/vm/graal/graalRuntime.cpp @ 15582:063ec2920d21

made Graal runtime initialization in hosted mode lazy
author Doug Simon <doug.simon@oracle.com>
date Fri, 09 May 2014 18:46:41 +0200
parents 0cb5c4d276d4
children ddb3ef30fcd2
comparison
equal deleted inserted replaced
15581:0dc0926cf0d8 15582:063ec2920d21
23 23
24 #include "precompiled.hpp" 24 #include "precompiled.hpp"
25 #include "asm/codeBuffer.hpp" 25 #include "asm/codeBuffer.hpp"
26 #include "graal/graalRuntime.hpp" 26 #include "graal/graalRuntime.hpp"
27 #include "graal/graalVMToCompiler.hpp" 27 #include "graal/graalVMToCompiler.hpp"
28 #include "graal/graalCompilerToVM.hpp"
29 #include "graal/graalJavaAccess.hpp"
30 #include "graal/graalEnv.hpp"
28 #include "memory/oopFactory.hpp" 31 #include "memory/oopFactory.hpp"
29 #include "prims/jvm.h" 32 #include "prims/jvm.h"
30 #include "runtime/biasedLocking.hpp" 33 #include "runtime/biasedLocking.hpp"
31 #include "runtime/interfaceSupport.hpp" 34 #include "runtime/interfaceSupport.hpp"
35 #include "runtime/arguments.hpp"
32 #include "runtime/reflection.hpp" 36 #include "runtime/reflection.hpp"
33 #include "utilities/debug.hpp" 37 #include "utilities/debug.hpp"
38
39 address GraalRuntime::_external_deopt_i2c_entry = NULL;
40 volatile int GraalRuntime::_state = uninitialized;
41
42 void GraalRuntime::initialize() {
43 {
44 MutexLocker locker(GraalInitialization_lock);
45 if (_state == uninitialized) {
46 _state = initializing;
47 } else {
48 while (_state == initializing) {
49 GraalInitialization_lock->wait();
50 }
51 return;
52 }
53 }
54
55 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end();
56 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024;
57 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)"));
58 NOT_LP64(error("check TLAB allocation code for address space conflicts"));
59
60 ThreadToNativeFromVM trans(JavaThread::current());
61 JavaThread* THREAD = JavaThread::current();
62 TRACE_graal_1("GraalRuntime::initialize");
63
64 JNIEnv *env = ((JavaThread *) Thread::current())->jni_environment();
65 jclass klass = env->FindClass("com/oracle/graal/hotspot/bridge/CompilerToVMImpl");
66 if (klass == NULL) {
67 tty->print_cr("graal CompilerToVMImpl class not found");
68 vm_abort(false);
69 }
70 env->RegisterNatives(klass, CompilerToVM_methods, CompilerToVM_methods_count());
71
72 ResourceMark rm;
73 HandleMark hm;
74 {
75 GRAAL_VM_ENTRY_MARK;
76 check_pending_exception("Could not register natives");
77 }
78
79 graal_compute_offsets();
80
81 // Ensure _non_oop_bits is initialized
82 Universe::non_oop_word();
83
84 {
85 GRAAL_VM_ENTRY_MARK;
86 HandleMark hm;
87 VMToCompiler::initOptions();
88 for (int i = 0; i < Arguments::num_graal_args(); ++i) {
89 const char* arg = Arguments::graal_args_array()[i];
90 Handle option = java_lang_String::create_from_str(arg, THREAD);
91 jboolean result = VMToCompiler::setOption(option);
92 if (!result) {
93 tty->print_cr("Invalid option for graal: -G:%s", arg);
94 vm_abort(false);
95 }
96 }
97 VMToCompiler::finalizeOptions(CITime || CITimeEach);
98
99 _external_deopt_i2c_entry = create_external_deopt_i2c();
100
101 VMToCompiler::startRuntime();
102
103 {
104 MutexLocker locker(GraalInitialization_lock);
105 _state = initialized;
106 }
107
108 #if !defined(PRODUCT) && !defined(COMPILERGRAAL)
109 // In COMPILERGRAAL, we want to allow GraalBootstrap
110 // to happen first so GraalCompiler::initialize()
111 // duplicates the following code.
112 if (CompileTheWorld) {
113 VMToCompiler::compileTheWorld();
114 }
115 #endif
116 }
117 }
118
119 BufferBlob* GraalRuntime::initialize_buffer_blob() {
120 JavaThread* THREAD = JavaThread::current();
121 BufferBlob* buffer_blob = THREAD->get_buffer_blob();
122 if (buffer_blob == NULL) {
123 buffer_blob = BufferBlob::create("Graal thread-local CodeBuffer", GraalNMethodSizeLimit);
124 if (buffer_blob != NULL) {
125 THREAD->set_buffer_blob(buffer_blob);
126 }
127 }
128 return buffer_blob;
129 }
130
131 address GraalRuntime::create_external_deopt_i2c() {
132 ResourceMark rm;
133 BufferBlob* buffer = BufferBlob::create("externalDeopt", 1*K);
134 CodeBuffer cb(buffer);
135 short buffer_locs[20];
136 cb.insts()->initialize_shared_locs((relocInfo*)buffer_locs, sizeof(buffer_locs)/sizeof(relocInfo));
137 MacroAssembler masm(&cb);
138
139 int total_args_passed = 5;
140
141 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
142 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
143 int i = 0;
144 sig_bt[i++] = T_INT;
145 sig_bt[i++] = T_LONG;
146 sig_bt[i++] = T_VOID; // long stakes 2 slots
147 sig_bt[i++] = T_INT;
148 sig_bt[i++] = T_OBJECT;
149
150 int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
151
152 SharedRuntime::gen_i2c_adapter(&masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
153 masm.flush();
154
155 return AdapterBlob::create(&cb)->content_begin();
156 }
157
158 BasicType GraalRuntime::kindToBasicType(jchar ch) {
159 switch(ch) {
160 case 'z': return T_BOOLEAN;
161 case 'b': return T_BYTE;
162 case 's': return T_SHORT;
163 case 'c': return T_CHAR;
164 case 'i': return T_INT;
165 case 'f': return T_FLOAT;
166 case 'j': return T_LONG;
167 case 'd': return T_DOUBLE;
168 case 'a': return T_OBJECT;
169 case 'r': return T_ADDRESS;
170 case '-': return T_ILLEGAL;
171 default:
172 fatal(err_msg("unexpected Kind: %c", ch));
173 break;
174 }
175 return T_ILLEGAL;
176 }
34 177
35 // Simple helper to see if the caller of a runtime stub which 178 // Simple helper to see if the caller of a runtime stub which
36 // entered the VM has been deoptimized 179 // entered the VM has been deoptimized
37 180
38 static bool caller_is_deopted() { 181 static bool caller_is_deopted() {
546 } 689 }
547 JRT_END 690 JRT_END
548 691
549 // JVM_InitializeGraalRuntime 692 // JVM_InitializeGraalRuntime
550 JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass)) 693 JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass))
551 return VMToCompiler::graalRuntimePermObject(); 694 GraalRuntime::initialize();
695 return VMToCompiler::get_HotSpotGraalRuntime_jobject();
552 JVM_END 696 JVM_END
553 697
554 // JVM_InitializeTruffleRuntime 698 // JVM_InitializeTruffleRuntime
555 JVM_ENTRY(jobject, JVM_InitializeTruffleRuntime(JNIEnv *env, jclass graalclass)) 699 JVM_ENTRY(jobject, JVM_InitializeTruffleRuntime(JNIEnv *env, jclass graalclass))
556 return JNIHandles::make_local(VMToCompiler::truffleRuntime()()); 700 GraalRuntime::initialize();
701 return JNIHandles::make_local(VMToCompiler::create_HotSpotTruffleRuntime()());
557 JVM_END 702 JVM_END