345 intptr_t* unpack_sp = stub_frame.sender(&dummy_map).unextended_sp(); 346 #endif // !SHARK 347 348 // This is a guarantee instead of an assert because if vframe doesn't match 349 // we will unpack the wrong deoptimized frame and wind up in strange places 350 // where it will be very difficult to figure out what went wrong. Better 351 // to die an early death here than some very obscure death later when the 352 // trail is cold. 353 // Note: on ia64 this guarantee can be fooled by frames with no memory stack 354 // in that it will fail to detect a problem when there is one. This needs 355 // more work in tiger timeframe. 356 guarantee(array->unextended_sp() == unpack_sp, "vframe_array_head must contain the vframeArray to unpack"); 357 358 int number_of_frames = array->frames(); 359 360 // Compute the vframes' sizes. Note that frame_sizes[] entries are ordered from outermost to innermost 361 // virtual activation, which is the reverse of the elements in the vframes array. 362 intptr_t* frame_sizes = NEW_C_HEAP_ARRAY(intptr_t, number_of_frames); 363 // +1 because we always have an interpreter return address for the final slot. 364 address* frame_pcs = NEW_C_HEAP_ARRAY(address, number_of_frames + 1); 365 int callee_parameters = 0; 366 int callee_locals = 0; 367 int popframe_extra_args = 0; 368 // Create an interpreter return address for the stub to use as its return 369 // address so the skeletal frames are perfectly walkable 370 frame_pcs[number_of_frames] = Interpreter::deopt_entry(vtos, 0); 371 372 // PopFrame requires that the preserved incoming arguments from the recently-popped topmost 373 // activation be put back on the expression stack of the caller for reexecution 374 if (JvmtiExport::can_pop_frame() && thread->popframe_forcing_deopt_reexecution()) { 375 popframe_extra_args = in_words(thread->popframe_preserved_args_size_in_words()); 376 } 377 378 // Find the current pc for sender of the deoptee. Since the sender may have been deoptimized 379 // itself since the deoptee vframeArray was created we must get a fresh value of the pc rather 380 // than simply use array->sender.pc(). This requires us to walk the current set of frames 381 // 382 frame deopt_sender = stub_frame.sender(&dummy_map); // First is the deoptee frame 383 deopt_sender = deopt_sender.sender(&dummy_map); // Now deoptee caller 384 385 // It's possible that the number of paramters at the call site is 386 // different than number of arguments in the callee when method 387 // handles are used. If the caller is interpreted get the real 388 // value so that the proper amount of space can be added to it's 389 // frame. 390 int caller_actual_parameters = callee_parameters; 391 if (deopt_sender.is_interpreted_frame()) { 392 methodHandle method = deopt_sender.interpreter_frame_method(); 393 Bytecode_invoke cur = Bytecode_invoke_check(method, 394 deopt_sender.interpreter_frame_bci()); 395 Symbol* signature = method->constants()->signature_ref_at(cur.index()); 396 ArgumentSizeComputer asc(signature); 397 caller_actual_parameters = asc.size() + (cur.has_receiver() ? 1 : 0); 398 } 399 400 // 401 // frame_sizes/frame_pcs[0] oldest frame (int or c2i) 402 // frame_sizes/frame_pcs[1] next oldest frame (int) 403 // frame_sizes/frame_pcs[n] youngest frame (int) 404 // 405 // Now a pc in frame_pcs is actually the return address to the frame's caller (a frame 406 // owns the space for the return address to it's caller). Confusing ain't it. 407 // 408 // The vframe array can address vframes with indices running from 409 // 0.._frames-1. Index 0 is the youngest frame and _frame - 1 is the oldest (root) frame. 410 // When we create the skeletal frames we need the oldest frame to be in the zero slot 411 // in the frame_sizes/frame_pcs so the assembly code can do a trivial walk. 412 // so things look a little strange in this loop. 413 // 414 for (int index = 0; index < array->frames(); index++ ) { 415 // frame[number_of_frames - 1 ] = on_stack_size(youngest) 416 // frame[number_of_frames - 2 ] = on_stack_size(sender(youngest)) 417 // frame[number_of_frames - 3 ] = on_stack_size(sender(sender(youngest))) 418 int caller_parms = callee_parameters; 419 if (index == array->frames() - 1) { 420 // Use the value from the interpreted caller 421 caller_parms = caller_actual_parameters; 422 } 423 frame_sizes[number_of_frames - 1 - index] = BytesPerWord * array->element(index)->on_stack_size(caller_parms, 424 callee_parameters, 425 callee_locals, 426 index == 0, 427 popframe_extra_args); 428 // This pc doesn't have to be perfect just good enough to identify the frame 429 // as interpreted so the skeleton frame will be walkable 430 // The correct pc will be set when the skeleton frame is completely filled out 431 // The final pc we store in the loop is wrong and will be overwritten below 432 frame_pcs[number_of_frames - 1 - index ] = Interpreter::deopt_entry(vtos, 0) - frame::pc_return_offset; 433 434 callee_parameters = array->element(index)->method()->size_of_parameters(); 435 callee_locals = array->element(index)->method()->max_locals(); 436 popframe_extra_args = 0; 437 } 438 439 // Compute whether the root vframe returns a float or double value. 440 BasicType return_type; 441 { 443 methodHandle method(thread, array->element(0)->method()); 444 Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci()); 445 return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL; 446 } 447 448 // Compute information for handling adapters and adjusting the frame size of the caller. 449 int caller_adjustment = 0; 450 451 // Compute the amount the oldest interpreter frame will have to adjust 452 // its caller's stack by. If the caller is a compiled frame then 453 // we pretend that the callee has no parameters so that the 454 // extension counts for the full amount of locals and not just 455 // locals-parms. This is because without a c2i adapter the parm 456 // area as created by the compiled frame will not be usable by 457 // the interpreter. (Depending on the calling convention there 458 // may not even be enough space). 459 460 // QQQ I'd rather see this pushed down into last_frame_adjust 461 // and have it take the sender (aka caller). 462 463 if (deopt_sender.is_compiled_frame()) { 464 caller_adjustment = last_frame_adjust(0, callee_locals); 465 } else if (callee_locals > caller_actual_parameters) { 466 // The caller frame may need extending to accommodate 467 // non-parameter locals of the first unpacked interpreted frame. 468 // Compute that adjustment. 469 caller_adjustment = last_frame_adjust(caller_actual_parameters, callee_locals); 470 } 471 472 // If the sender is deoptimized the we must retrieve the address of the handler 473 // since the frame will "magically" show the original pc before the deopt 474 // and we'd undo the deopt. 475 476 frame_pcs[0] = deopt_sender.raw_pc(); 477 478 #ifndef SHARK 479 assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc"); 480 #endif // SHARK 481 482 UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord, 483 caller_adjustment * BytesPerWord, 484 caller_actual_parameters, 485 number_of_frames, 486 frame_sizes, 487 frame_pcs, 488 return_type); 489 // On some platforms, we need a way to pass some platform dependent 490 // information to the unpacking code so the skeletal frames come out 491 // correct (initial fp value, unextended sp, ...) 492 info->set_initial_info((intptr_t) array->sender().initial_deoptimization_info()); 493 494 if (array->frames() > 1) { 495 if (VerifyStack && TraceDeoptimization) { 496 tty->print_cr("Deoptimizing method containing inlining"); 497 } 498 } 499 500 array->set_unroll_block(info); 501 return info; 502 } 503 504 // Called to cleanup deoptimization data structures in normal case | 345 intptr_t* unpack_sp = stub_frame.sender(&dummy_map).unextended_sp(); 346 #endif // !SHARK 347 348 // This is a guarantee instead of an assert because if vframe doesn't match 349 // we will unpack the wrong deoptimized frame and wind up in strange places 350 // where it will be very difficult to figure out what went wrong. Better 351 // to die an early death here than some very obscure death later when the 352 // trail is cold. 353 // Note: on ia64 this guarantee can be fooled by frames with no memory stack 354 // in that it will fail to detect a problem when there is one. This needs 355 // more work in tiger timeframe. 356 guarantee(array->unextended_sp() == unpack_sp, "vframe_array_head must contain the vframeArray to unpack"); 357 358 int number_of_frames = array->frames(); 359 360 // Compute the vframes' sizes. Note that frame_sizes[] entries are ordered from outermost to innermost 361 // virtual activation, which is the reverse of the elements in the vframes array. 362 intptr_t* frame_sizes = NEW_C_HEAP_ARRAY(intptr_t, number_of_frames); 363 // +1 because we always have an interpreter return address for the final slot. 364 address* frame_pcs = NEW_C_HEAP_ARRAY(address, number_of_frames + 1); 365 int popframe_extra_args = 0; 366 // Create an interpreter return address for the stub to use as its return 367 // address so the skeletal frames are perfectly walkable 368 frame_pcs[number_of_frames] = Interpreter::deopt_entry(vtos, 0); 369 370 // PopFrame requires that the preserved incoming arguments from the recently-popped topmost 371 // activation be put back on the expression stack of the caller for reexecution 372 if (JvmtiExport::can_pop_frame() && thread->popframe_forcing_deopt_reexecution()) { 373 popframe_extra_args = in_words(thread->popframe_preserved_args_size_in_words()); 374 } 375 376 // Find the current pc for sender of the deoptee. Since the sender may have been deoptimized 377 // itself since the deoptee vframeArray was created we must get a fresh value of the pc rather 378 // than simply use array->sender.pc(). This requires us to walk the current set of frames 379 // 380 frame deopt_sender = stub_frame.sender(&dummy_map); // First is the deoptee frame 381 deopt_sender = deopt_sender.sender(&dummy_map); // Now deoptee caller 382 383 // It's possible that the number of paramters at the call site is 384 // different than number of arguments in the callee when method 385 // handles are used. If the caller is interpreted get the real 386 // value so that the proper amount of space can be added to it's 387 // frame. 388 bool caller_was_method_handle = false; 389 if (deopt_sender.is_interpreted_frame()) { 390 methodHandle method = deopt_sender.interpreter_frame_method(); 391 Bytecode_invoke cur = Bytecode_invoke_check(method, 392 deopt_sender.interpreter_frame_bci()); 393 if (cur.code() == Bytecodes::_invokedynamic || 394 (cur.code() == Bytecodes::_invokevirtual && 395 method->constants()->klass_ref_at_noresolve(cur.index()) == vmSymbols::java_lang_invoke_MethodHandle() && 396 methodOopDesc::is_method_handle_invoke_name(cur.name()))) { 397 // Method handle invokes may involve fairly arbitrary chains of 398 // calls so it's impossible to know how much actual space the 399 // caller has for locals. 400 caller_was_method_handle = true; 401 } 402 } 403 404 // 405 // frame_sizes/frame_pcs[0] oldest frame (int or c2i) 406 // frame_sizes/frame_pcs[1] next oldest frame (int) 407 // frame_sizes/frame_pcs[n] youngest frame (int) 408 // 409 // Now a pc in frame_pcs is actually the return address to the frame's caller (a frame 410 // owns the space for the return address to it's caller). Confusing ain't it. 411 // 412 // The vframe array can address vframes with indices running from 413 // 0.._frames-1. Index 0 is the youngest frame and _frame - 1 is the oldest (root) frame. 414 // When we create the skeletal frames we need the oldest frame to be in the zero slot 415 // in the frame_sizes/frame_pcs so the assembly code can do a trivial walk. 416 // so things look a little strange in this loop. 417 // 418 int callee_parameters = 0; 419 int callee_locals = 0; 420 for (int index = 0; index < array->frames(); index++ ) { 421 // frame[number_of_frames - 1 ] = on_stack_size(youngest) 422 // frame[number_of_frames - 2 ] = on_stack_size(sender(youngest)) 423 // frame[number_of_frames - 3 ] = on_stack_size(sender(sender(youngest))) 424 int caller_parms = callee_parameters; 425 if ((index == array->frames() - 1) && caller_was_method_handle) { 426 caller_parms = 0; 427 } 428 frame_sizes[number_of_frames - 1 - index] = BytesPerWord * array->element(index)->on_stack_size(caller_parms, 429 callee_parameters, 430 callee_locals, 431 index == 0, 432 popframe_extra_args); 433 // This pc doesn't have to be perfect just good enough to identify the frame 434 // as interpreted so the skeleton frame will be walkable 435 // The correct pc will be set when the skeleton frame is completely filled out 436 // The final pc we store in the loop is wrong and will be overwritten below 437 frame_pcs[number_of_frames - 1 - index ] = Interpreter::deopt_entry(vtos, 0) - frame::pc_return_offset; 438 439 callee_parameters = array->element(index)->method()->size_of_parameters(); 440 callee_locals = array->element(index)->method()->max_locals(); 441 popframe_extra_args = 0; 442 } 443 444 // Compute whether the root vframe returns a float or double value. 445 BasicType return_type; 446 { 448 methodHandle method(thread, array->element(0)->method()); 449 Bytecode_invoke invoke = Bytecode_invoke_check(method, array->element(0)->bci()); 450 return_type = invoke.is_valid() ? invoke.result_type() : T_ILLEGAL; 451 } 452 453 // Compute information for handling adapters and adjusting the frame size of the caller. 454 int caller_adjustment = 0; 455 456 // Compute the amount the oldest interpreter frame will have to adjust 457 // its caller's stack by. If the caller is a compiled frame then 458 // we pretend that the callee has no parameters so that the 459 // extension counts for the full amount of locals and not just 460 // locals-parms. This is because without a c2i adapter the parm 461 // area as created by the compiled frame will not be usable by 462 // the interpreter. (Depending on the calling convention there 463 // may not even be enough space). 464 465 // QQQ I'd rather see this pushed down into last_frame_adjust 466 // and have it take the sender (aka caller). 467 468 if (deopt_sender.is_compiled_frame() || caller_was_method_handle) { 469 caller_adjustment = last_frame_adjust(0, callee_locals); 470 } else if (callee_locals > callee_parameters) { 471 // The caller frame may need extending to accommodate 472 // non-parameter locals of the first unpacked interpreted frame. 473 // Compute that adjustment. 474 caller_adjustment = last_frame_adjust(callee_parameters, callee_locals); 475 } 476 477 // If the sender is deoptimized the we must retrieve the address of the handler 478 // since the frame will "magically" show the original pc before the deopt 479 // and we'd undo the deopt. 480 481 frame_pcs[0] = deopt_sender.raw_pc(); 482 483 #ifndef SHARK 484 assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc"); 485 #endif // SHARK 486 487 UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord, 488 caller_adjustment * BytesPerWord, 489 caller_was_method_handle ? 0 : callee_parameters, 490 number_of_frames, 491 frame_sizes, 492 frame_pcs, 493 return_type); 494 // On some platforms, we need a way to pass some platform dependent 495 // information to the unpacking code so the skeletal frames come out 496 // correct (initial fp value, unextended sp, ...) 497 info->set_initial_info((intptr_t) array->sender().initial_deoptimization_info()); 498 499 if (array->frames() > 1) { 500 if (VerifyStack && TraceDeoptimization) { 501 tty->print_cr("Deoptimizing method containing inlining"); 502 } 503 } 504 505 array->set_unroll_block(info); 506 return info; 507 } 508 509 // Called to cleanup deoptimization data structures in normal case |