172 173 // Note: there is a safepoint safety issue here. No matter whether we enter 174 // via vanilla deopt or uncommon trap we MUST NOT stop at a safepoint once 175 // the vframeArray is created. 176 // 177 178 // Allocate our special deoptimization ResourceMark 179 DeoptResourceMark* dmark = new DeoptResourceMark(thread); 180 assert(thread->deopt_mark() == NULL, "Pending deopt!"); 181 thread->set_deopt_mark(dmark); 182 183 frame stub_frame = thread->last_frame(); // Makes stack walkable as side effect 184 RegisterMap map(thread, true); 185 RegisterMap dummy_map(thread, false); 186 // Now get the deoptee with a valid map 187 frame deoptee = stub_frame.sender(&map); 188 // Set the deoptee nmethod 189 assert(thread->deopt_nmethod() == NULL, "Pending deopt!"); 190 thread->set_deopt_nmethod(deoptee.cb()->as_nmethod_or_null()); 191 192 // Create a growable array of VFrames where each VFrame represents an inlined 193 // Java frame. This storage is allocated with the usual system arena. 194 assert(deoptee.is_compiled_frame(), "Wrong frame type"); 195 GrowableArray<compiledVFrame*>* chunk = new GrowableArray<compiledVFrame*>(10); 196 vframe* vf = vframe::new_vframe(&deoptee, &map, thread); 197 while (!vf->is_top()) { 198 assert(vf->is_compiled_frame(), "Wrong frame type"); 199 chunk->push(compiledVFrame::cast(vf)); 200 vf = vf->sender(); 201 } 202 assert(vf->is_compiled_frame(), "Wrong frame type"); 203 chunk->push(compiledVFrame::cast(vf)); 204 205 #ifdef COMPILER2 206 // Reallocate the non-escaping objects and restore their fields. Then 207 // relock objects if synchronization on them was eliminated. 208 if (DoEscapeAnalysis) { 209 if (EliminateAllocations) { 210 assert (chunk->at(0)->scope() != NULL,"expect only compiled java frames"); 211 GrowableArray<ScopeValue*>* objects = chunk->at(0)->scope()->objects(); 404 405 // Compute whether the root vframe returns a float or double value. 406 BasicType return_type; 407 { 408 HandleMark hm; 409 methodHandle method(thread, array->element(0)->method()); 410 Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci()); 411 return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL; 412 } 413 414 // Compute information for handling adapters and adjusting the frame size of the caller. 415 int caller_adjustment = 0; 416 417 // Find the current pc for sender of the deoptee. Since the sender may have been deoptimized 418 // itself since the deoptee vframeArray was created we must get a fresh value of the pc rather 419 // than simply use array->sender.pc(). This requires us to walk the current set of frames 420 // 421 frame deopt_sender = stub_frame.sender(&dummy_map); // First is the deoptee frame 422 deopt_sender = deopt_sender.sender(&dummy_map); // Now deoptee caller 423 424 // Compute the amount the oldest interpreter frame will have to adjust 425 // its caller's stack by. If the caller is a compiled frame then 426 // we pretend that the callee has no parameters so that the 427 // extension counts for the full amount of locals and not just 428 // locals-parms. This is because without a c2i adapter the parm 429 // area as created by the compiled frame will not be usable by 430 // the interpreter. (Depending on the calling convention there 431 // may not even be enough space). 432 433 // QQQ I'd rather see this pushed down into last_frame_adjust 434 // and have it take the sender (aka caller). 435 436 if (deopt_sender.is_compiled_frame()) { 437 caller_adjustment = last_frame_adjust(0, callee_locals); 438 } else if (callee_locals > callee_parameters) { 439 // The caller frame may need extending to accommodate 440 // non-parameter locals of the first unpacked interpreted frame. 441 // Compute that adjustment. 442 caller_adjustment = last_frame_adjust(callee_parameters, callee_locals); 443 } 444 445 446 // If the sender is deoptimized the we must retrieve the address of the handler 447 // since the frame will "magically" show the original pc before the deopt 448 // and we'd undo the deopt. 449 450 frame_pcs[0] = deopt_sender.raw_pc(); 451 452 #ifndef SHARK 453 assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc"); 454 #endif // SHARK 455 456 UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord, 457 caller_adjustment * BytesPerWord, 458 number_of_frames, 459 frame_sizes, 460 frame_pcs, 461 return_type); 462 // On some platforms, we need a way to pass fp to the unpacking code 463 // so the skeletal frames come out correct. 464 info->set_initial_fp((intptr_t) array->sender().fp()); 465 552 UnrollBlock* info = array->unroll_block(); 553 554 // Unpack the interpreter frames and any adapter frame (c2 only) we might create. 555 array->unpack_to_stack(stub_frame, exec_mode); 556 557 BasicType bt = info->return_type(); 558 559 // If we have an exception pending, claim that the return type is an oop 560 // so the deopt_blob does not overwrite the exception_oop. 561 562 if (exec_mode == Unpack_exception) 563 bt = T_OBJECT; 564 565 // Cleanup thread deopt data 566 cleanup_deopt_info(thread, array); 567 568 #ifndef PRODUCT 569 if (VerifyStack) { 570 ResourceMark res_mark; 571 572 // Verify that the just-unpacked frames match the interpreter's 573 // notions of expression stack and locals 574 vframeArray* cur_array = thread->vframe_array_last(); 575 RegisterMap rm(thread, false); 576 rm.set_include_argument_oops(false); 577 bool is_top_frame = true; 578 int callee_size_of_parameters = 0; 579 int callee_max_locals = 0; 580 for (int i = 0; i < cur_array->frames(); i++) { 581 vframeArrayElement* el = cur_array->element(i); 582 frame* iframe = el->iframe(); 583 guarantee(iframe->is_interpreted_frame(), "Wrong frame type"); 584 585 // Get the oop map for this bci 586 InterpreterOopMap mask; 587 int cur_invoke_parameter_size = 0; 588 bool try_next_mask = false; 589 int next_mask_expression_stack_size = -1; 590 int top_frame_expression_stack_adjustment = 0; 591 methodHandle mh(thread, iframe->interpreter_frame_method()); | 172 173 // Note: there is a safepoint safety issue here. No matter whether we enter 174 // via vanilla deopt or uncommon trap we MUST NOT stop at a safepoint once 175 // the vframeArray is created. 176 // 177 178 // Allocate our special deoptimization ResourceMark 179 DeoptResourceMark* dmark = new DeoptResourceMark(thread); 180 assert(thread->deopt_mark() == NULL, "Pending deopt!"); 181 thread->set_deopt_mark(dmark); 182 183 frame stub_frame = thread->last_frame(); // Makes stack walkable as side effect 184 RegisterMap map(thread, true); 185 RegisterMap dummy_map(thread, false); 186 // Now get the deoptee with a valid map 187 frame deoptee = stub_frame.sender(&map); 188 // Set the deoptee nmethod 189 assert(thread->deopt_nmethod() == NULL, "Pending deopt!"); 190 thread->set_deopt_nmethod(deoptee.cb()->as_nmethod_or_null()); 191 192 if (VerifyStack) { 193 thread->validate_frame_layout(); 194 } 195 196 // Create a growable array of VFrames where each VFrame represents an inlined 197 // Java frame. This storage is allocated with the usual system arena. 198 assert(deoptee.is_compiled_frame(), "Wrong frame type"); 199 GrowableArray<compiledVFrame*>* chunk = new GrowableArray<compiledVFrame*>(10); 200 vframe* vf = vframe::new_vframe(&deoptee, &map, thread); 201 while (!vf->is_top()) { 202 assert(vf->is_compiled_frame(), "Wrong frame type"); 203 chunk->push(compiledVFrame::cast(vf)); 204 vf = vf->sender(); 205 } 206 assert(vf->is_compiled_frame(), "Wrong frame type"); 207 chunk->push(compiledVFrame::cast(vf)); 208 209 #ifdef COMPILER2 210 // Reallocate the non-escaping objects and restore their fields. Then 211 // relock objects if synchronization on them was eliminated. 212 if (DoEscapeAnalysis) { 213 if (EliminateAllocations) { 214 assert (chunk->at(0)->scope() != NULL,"expect only compiled java frames"); 215 GrowableArray<ScopeValue*>* objects = chunk->at(0)->scope()->objects(); 408 409 // Compute whether the root vframe returns a float or double value. 410 BasicType return_type; 411 { 412 HandleMark hm; 413 methodHandle method(thread, array->element(0)->method()); 414 Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci()); 415 return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL; 416 } 417 418 // Compute information for handling adapters and adjusting the frame size of the caller. 419 int caller_adjustment = 0; 420 421 // Find the current pc for sender of the deoptee. Since the sender may have been deoptimized 422 // itself since the deoptee vframeArray was created we must get a fresh value of the pc rather 423 // than simply use array->sender.pc(). This requires us to walk the current set of frames 424 // 425 frame deopt_sender = stub_frame.sender(&dummy_map); // First is the deoptee frame 426 deopt_sender = deopt_sender.sender(&dummy_map); // Now deoptee caller 427 428 // It's possible that the number of paramters at the call site is 429 // different than number of arguments in the callee when method 430 // handles are used. If the caller is interpreted get the real 431 // value so that the proper amount of space can be added to it's 432 // frame. 433 int sender_callee_parameters = callee_parameters; 434 if (deopt_sender.is_interpreted_frame()) { 435 methodHandle method = deopt_sender.interpreter_frame_method(); 436 Bytecode_invoke cur = Bytecode_invoke_check(method, 437 deopt_sender.interpreter_frame_bci()); 438 Symbol* signature = method->constants()->signature_ref_at(cur.index()); 439 ArgumentSizeComputer asc(signature); 440 sender_callee_parameters = asc.size() + cur.has_receiver() ? 1 : 0; 441 } 442 443 // Compute the amount the oldest interpreter frame will have to adjust 444 // its caller's stack by. If the caller is a compiled frame then 445 // we pretend that the callee has no parameters so that the 446 // extension counts for the full amount of locals and not just 447 // locals-parms. This is because without a c2i adapter the parm 448 // area as created by the compiled frame will not be usable by 449 // the interpreter. (Depending on the calling convention there 450 // may not even be enough space). 451 452 // QQQ I'd rather see this pushed down into last_frame_adjust 453 // and have it take the sender (aka caller). 454 455 if (deopt_sender.is_compiled_frame()) { 456 caller_adjustment = last_frame_adjust(0, callee_locals); 457 } else if (callee_locals > sender_callee_parameters) { 458 // The caller frame may need extending to accommodate 459 // non-parameter locals of the first unpacked interpreted frame. 460 // Compute that adjustment. 461 caller_adjustment = last_frame_adjust(sender_callee_parameters, callee_locals); 462 } 463 464 // If the sender is deoptimized the we must retrieve the address of the handler 465 // since the frame will "magically" show the original pc before the deopt 466 // and we'd undo the deopt. 467 468 frame_pcs[0] = deopt_sender.raw_pc(); 469 470 #ifndef SHARK 471 assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc"); 472 #endif // SHARK 473 474 UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord, 475 caller_adjustment * BytesPerWord, 476 number_of_frames, 477 frame_sizes, 478 frame_pcs, 479 return_type); 480 // On some platforms, we need a way to pass fp to the unpacking code 481 // so the skeletal frames come out correct. 482 info->set_initial_fp((intptr_t) array->sender().fp()); 483 570 UnrollBlock* info = array->unroll_block(); 571 572 // Unpack the interpreter frames and any adapter frame (c2 only) we might create. 573 array->unpack_to_stack(stub_frame, exec_mode); 574 575 BasicType bt = info->return_type(); 576 577 // If we have an exception pending, claim that the return type is an oop 578 // so the deopt_blob does not overwrite the exception_oop. 579 580 if (exec_mode == Unpack_exception) 581 bt = T_OBJECT; 582 583 // Cleanup thread deopt data 584 cleanup_deopt_info(thread, array); 585 586 #ifndef PRODUCT 587 if (VerifyStack) { 588 ResourceMark res_mark; 589 590 thread->validate_frame_layout(); 591 592 // Verify that the just-unpacked frames match the interpreter's 593 // notions of expression stack and locals 594 vframeArray* cur_array = thread->vframe_array_last(); 595 RegisterMap rm(thread, false); 596 rm.set_include_argument_oops(false); 597 bool is_top_frame = true; 598 int callee_size_of_parameters = 0; 599 int callee_max_locals = 0; 600 for (int i = 0; i < cur_array->frames(); i++) { 601 vframeArrayElement* el = cur_array->element(i); 602 frame* iframe = el->iframe(); 603 guarantee(iframe->is_interpreted_frame(), "Wrong frame type"); 604 605 // Get the oop map for this bci 606 InterpreterOopMap mask; 607 int cur_invoke_parameter_size = 0; 608 bool try_next_mask = false; 609 int next_mask_expression_stack_size = -1; 610 int top_frame_expression_stack_adjustment = 0; 611 methodHandle mh(thread, iframe->interpreter_frame_method()); |