Mercurial > hg > graal-jvmci-8
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 3670:f198b24093f3
put back in thread transitions.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 18 Nov 2011 16:23:26 +0100 |
parents | 53636e2c9d03 |
children | 5e331d5f760e |
comparison
equal
deleted
inserted
replaced
3669:53636e2c9d03 | 3670:f198b24093f3 |
---|---|
227 } | 227 } |
228 ShouldNotReachHere(); | 228 ShouldNotReachHere(); |
229 return NULL; | 229 return NULL; |
230 } | 230 } |
231 | 231 |
232 void CodeInstaller::initialize_assumptions(Handle& target_method) { | 232 void CodeInstaller::initialize_assumptions(oop target_method) { |
233 _oop_recorder = new OopRecorder(_env->arena()); | 233 _oop_recorder = new OopRecorder(_env->arena()); |
234 _env->set_oop_recorder(_oop_recorder); | 234 _env->set_oop_recorder(_oop_recorder); |
235 _env->set_dependencies(_dependencies); | 235 _env->set_dependencies(_dependencies); |
236 _dependencies = new Dependencies(_env); | 236 _dependencies = new Dependencies(_env); |
237 Handle assumptions_handle = CiTargetMethod::assumptions(HotSpotTargetMethod::targetMethod(target_method)); | 237 Handle assumptions_handle = CiTargetMethod::assumptions(HotSpotTargetMethod::targetMethod(target_method)); |
238 if (!assumptions_handle.is_null()) { | 238 if (!assumptions_handle.is_null()) { |
239 objArrayHandle assumptions = (objArrayOop)CiAssumptions::list(assumptions_handle()); | 239 objArrayHandle assumptions(Thread::current(), (objArrayOop)CiAssumptions::list(assumptions_handle())); |
240 for (int i = 0; i < assumptions->length(); ++i) { | 240 int length = assumptions->length(); |
241 Handle assumption = assumptions->obj_at(i); | 241 jobject assumptions_handle = JNIHandles::make_local(assumptions()); |
242 if (!assumption.is_null()) { | 242 for (int i = 0; i < length; ++i) { |
243 if (assumption->is_a(CiAssumptions_ConcreteSubtype::klass())) { | 243 oop assumption = assumptions->obj_at(i); |
244 assumption_ConcreteSubtype(assumption); | 244 if (assumption != NULL) { |
245 } else if (assumption->is_a(CiAssumptions_ConcreteMethod::klass())) { | 245 if (assumption->klass() == CiAssumptions_ConcreteSubtype::klass()) { |
246 assumption_ConcreteMethod(assumption); | 246 assumption_ConcreteSubtype(JNIHandles::make_local(assumption)); |
247 } else if (assumption->klass() == CiAssumptions_ConcreteMethod::klass()) { | |
248 assumption_ConcreteMethod(JNIHandles::make_local(assumption)); | |
247 } else { | 249 } else { |
248 assumption->print(); | 250 assumption->print(); |
249 fatal("unexpected Assumption subclass"); | 251 fatal("unexpected Assumption subclass"); |
250 } | 252 } |
251 } | 253 } |
256 // constructor used to create a method | 258 // constructor used to create a method |
257 CodeInstaller::CodeInstaller(Handle& target_method, nmethod*& nm, bool install_code) { | 259 CodeInstaller::CodeInstaller(Handle& target_method, nmethod*& nm, bool install_code) { |
258 _env = CURRENT_ENV; | 260 _env = CURRENT_ENV; |
259 GraalCompiler::initialize_buffer_blob(); | 261 GraalCompiler::initialize_buffer_blob(); |
260 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | 262 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); |
261 initialize_assumptions(target_method); | 263 jobject target_method_obj = JNIHandles::make_local(target_method()); |
264 initialize_assumptions(JNIHandles::resolve(target_method_obj)); | |
262 | 265 |
263 { | 266 { |
264 No_Safepoint_Verifier no_safepoint; | 267 No_Safepoint_Verifier no_safepoint; |
265 initialize_fields(target_method); | 268 initialize_fields(JNIHandles::resolve(target_method_obj)); |
266 initialize_buffer(buffer); | 269 initialize_buffer(buffer); |
267 process_exception_handlers(); | 270 process_exception_handlers(); |
268 } | 271 } |
269 | 272 |
270 int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer | 273 int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer |
271 methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(target_method)); | 274 methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(JNIHandles::resolve(target_method_obj))); |
272 { | 275 { |
273 nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, | 276 nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, |
274 &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, false, install_code); | 277 &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, false, install_code); |
275 } | 278 } |
276 method->clear_queued_for_compilation(); | 279 method->clear_queued_for_compilation(); |
281 No_Safepoint_Verifier no_safepoint; | 284 No_Safepoint_Verifier no_safepoint; |
282 _env = CURRENT_ENV; | 285 _env = CURRENT_ENV; |
283 | 286 |
284 _oop_recorder = new OopRecorder(_env->arena()); | 287 _oop_recorder = new OopRecorder(_env->arena()); |
285 _env->set_oop_recorder(_oop_recorder); | 288 _env->set_oop_recorder(_oop_recorder); |
286 initialize_fields(target_method); | 289 initialize_fields(target_method()); |
287 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method"); | 290 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method"); |
288 | 291 |
289 // (very) conservative estimate: each site needs a relocation | 292 // (very) conservative estimate: each site needs a relocation |
290 GraalCompiler::initialize_buffer_blob(); | 293 GraalCompiler::initialize_buffer_blob(); |
291 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | 294 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); |
295 BufferBlob* blob = BufferBlob::create(strdup(cname), &buffer); // this is leaking strings... but only a limited number of stubs will be created | 298 BufferBlob* blob = BufferBlob::create(strdup(cname), &buffer); // this is leaking strings... but only a limited number of stubs will be created |
296 IF_TRACE_graal_3 Disassembler::decode((CodeBlob*) blob); | 299 IF_TRACE_graal_3 Disassembler::decode((CodeBlob*) blob); |
297 id = VmIds::addStub(blob->code_begin()); | 300 id = VmIds::addStub(blob->code_begin()); |
298 } | 301 } |
299 | 302 |
300 void CodeInstaller::initialize_fields(Handle& target_method) { | 303 void CodeInstaller::initialize_fields(oop target_method) { |
301 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); | 304 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); |
302 _hotspot_method = HotSpotTargetMethod::method(target_method); | 305 _hotspot_method = HotSpotTargetMethod::method(target_method); |
303 if (_hotspot_method != NULL) { | 306 if (_hotspot_method != NULL) { |
304 _parameter_count = getMethodFromHotSpotMethod(_hotspot_method)->size_of_parameters(); | 307 _parameter_count = getMethodFromHotSpotMethod(_hotspot_method)->size_of_parameters(); |
305 } | 308 } |
362 fatal("unexpected Site subclass"); | 365 fatal("unexpected Site subclass"); |
363 } | 366 } |
364 } | 367 } |
365 } | 368 } |
366 | 369 |
367 void CodeInstaller::assumption_ConcreteSubtype(Handle assumption) { | 370 void CodeInstaller::assumption_ConcreteSubtype(jobject assumption) { |
368 Handle context_handle = CiAssumptions_ConcreteSubtype::context(assumption); | 371 Handle context_handle = CiAssumptions_ConcreteSubtype::context(JNIHandles::resolve(assumption)); |
369 Handle type_handle = CiAssumptions_ConcreteSubtype::subtype(assumption); | |
370 | |
371 ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_handle))); | 372 ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_handle))); |
373 | |
374 Handle type_handle = CiAssumptions_ConcreteSubtype::subtype(JNIHandles::resolve(assumption)); | |
372 ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_handle))); | 375 ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_handle))); |
373 | 376 |
374 _dependencies->assert_leaf_type(type); | 377 _dependencies->assert_leaf_type(type); |
375 if (context != type) { | 378 if (context != type) { |
379 // Once you removed the transition to native here | |
380 // and have realized what a terrible mistake that was, | |
381 // please increment the following counter as a warning | |
382 // to the next guy: | |
383 // | |
384 // total_hours_wasted_here = 8 | |
385 ThreadToNativeFromVM trans(JavaThread::current()); | |
376 assert(context->is_abstract(), ""); | 386 assert(context->is_abstract(), ""); |
377 _dependencies->assert_abstract_with_unique_concrete_subtype(context, type); | 387 _dependencies->assert_abstract_with_unique_concrete_subtype(context, type); |
378 } | 388 } |
379 } | 389 } |
380 | 390 |
381 void CodeInstaller::assumption_ConcreteMethod(Handle assumption) { | 391 void CodeInstaller::assumption_ConcreteMethod(jobject assumption) { |
382 Handle context_handle = CiAssumptions_ConcreteMethod::context(assumption); | 392 Handle method_handle = CiAssumptions_ConcreteMethod::method(JNIHandles::resolve(assumption)); |
383 Handle method_handle = CiAssumptions_ConcreteMethod::method(assumption); | |
384 methodHandle method = getMethodFromHotSpotMethod(method_handle()); | 393 methodHandle method = getMethodFromHotSpotMethod(method_handle()); |
394 ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method()); | |
395 | |
396 Handle context_handle = CiAssumptions_ConcreteMethod::context(JNIHandles::resolve(assumption)); | |
385 methodHandle context = getMethodFromHotSpotMethod(context_handle()); | 397 methodHandle context = getMethodFromHotSpotMethod(context_handle()); |
386 | |
387 ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method()); | |
388 ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context()); | 398 ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context()); |
389 ciKlass* context_klass = c->holder(); | 399 ciKlass* context_klass = c->holder(); |
390 _dependencies->assert_unique_concrete_method(context_klass, m); | 400 { |
401 // Once you removed the transition to native here | |
402 // and have realized what a terrible mistake that was, | |
403 // please increment the following counter as a warning | |
404 // to the next guy: | |
405 // | |
406 // total_hours_wasted_here = 8 | |
407 ThreadToNativeFromVM trans(JavaThread::current()); | |
408 _dependencies->assert_unique_concrete_method(context_klass, m); | |
409 } | |
391 } | 410 } |
392 | 411 |
393 void CodeInstaller::process_exception_handlers() { | 412 void CodeInstaller::process_exception_handlers() { |
394 // allocate some arrays for use by the collection code. | 413 // allocate some arrays for use by the collection code. |
395 const int num_handlers = 5; | 414 const int num_handlers = 5; |