54 assert(FKind::is_instance(f), "");
55 if (FKind::interpreted) {
56 return frame(f.sender_sp(), f.sender_pc(), f.interpreter_frame_sender_sp());
57 }
58
59 intptr_t* sender_sp = f.sender_sp();
60 address sender_pc = f.sender_pc();
61 assert(sender_sp != f.sp(), "must have changed");
62
63 int slot = 0;
64 CodeBlob* sender_cb = CodeCache::find_blob_and_oopmap(sender_pc, slot);
65 return sender_cb != nullptr
66 ? frame(sender_sp, sender_sp, nullptr, sender_pc, sender_cb, slot == -1 ? nullptr : sender_cb->oop_map_for_slot(slot, sender_pc))
67 : frame(sender_sp, sender_pc, sender_sp);
68 }
69
70 void FreezeBase::adjust_interpreted_frame_unextended_sp(frame& f) {
71 // nothing to do
72 }
73
74 inline void FreezeBase::relativize_interpreted_frame_metadata(const frame& f, const frame& hf) {
75 intptr_t* vfp = f.fp();
76 intptr_t* hfp = hf.fp();
77 assert(f.fp() > (intptr_t*)f.interpreter_frame_esp(), "");
78
79 // There is alignment padding between vfp and f's locals array in the original
80 // frame, because we freeze the padding (see recurse_freeze_interpreted_frame)
81 // in order to keep the same relativized locals pointer, we don't need to change it here.
82
83 // Make sure that monitors is already relativized.
84 assert(hf.at_absolute(ijava_idx(monitors)) <= -(frame::ijava_state_size / wordSize), "");
85
86 // Make sure that esp is already relativized.
87 assert(hf.at_absolute(ijava_idx(esp)) <= hf.at_absolute(ijava_idx(monitors)), "");
88
89 // top_frame_sp is already relativized
90
91 // hfp == hf.sp() + (f.fp() - f.sp()) is not true on ppc because the stack frame has room for
92 // the maximal expression stack and the expression stack in the heap frame is trimmed.
93 assert(hf.fp() == hf.interpreter_frame_esp() + (f.fp() - f.interpreter_frame_esp()), "");
333 // Fast path
334
335 inline void ThawBase::prefetch_chunk_pd(void* start, int size) {
336 size <<= LogBytesPerWord;
337 Prefetch::read(start, size);
338 Prefetch::read(start, size - 64);
339 }
340
341 // Set back chain links of fast thawed frames such that *sp == callers_sp.
342 // See https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#STACK
343 template <typename ConfigT>
344 inline void Thaw<ConfigT>::patch_caller_links(intptr_t* sp, intptr_t* bottom) {
345 for (intptr_t* callers_sp; sp < bottom; sp = callers_sp) {
346 address pc = (address)((frame::java_abi*) sp)->lr;
347 assert(pc != nullptr, "");
348 // see ThawBase::patch_return() which gets called just before
349 bool is_entry_frame = pc == StubRoutines::cont_returnBarrier() || pc == _cont.entryPC();
350 if (is_entry_frame) {
351 callers_sp = _cont.entryFP();
352 } else {
353 CodeBlob* cb = CodeCache::find_blob_fast(pc);
354 callers_sp = sp + cb->frame_size();
355 }
356 // set the back link
357 ((frame::java_abi*) sp)->callers_sp = (intptr_t) callers_sp;
358 }
359 }
360
361 // Slow path
362
363 inline frame ThawBase::new_entry_frame() {
364 intptr_t* sp = _cont.entrySP();
365 return frame(sp, _cont.entryPC(), sp, _cont.entryFP());
366 }
367
368 // === New Interpreted Frame ================================================================================================================
369 //
370 // ### Non-Interpreted Caller (compiled, enterSpecial): No Overlap
371 //
372 // Heap Frame `hf` `hf` gets copied to stack _without_ overlapping the caller
463 // e | | |----------------------|
464 // w |----------------------| | Stack Args |
465 // | frame::java_abi |<- unext. SP / SP | (if any) |
466 // F ======================== |----------------------|
467 // r | frame::java_abi |<- caller's SP
468 // a ======================== / new frame's FP
469 // m | | (aligned)
470 // e | |
471 // |----------------------|
472 // | frame::java_abi |<- unext. SP / SP
473 // ========================
474 //
475 // If the new frame is at the bottom just above the ContinuationEntry frame then the stackargs
476 // don't overlap the caller either even though it is compiled because the size is not
477 // limited/known. In contrast to the interpreted caller case the abi overlaps with the caller
478 // if there are no stackargs. This is to comply with shared code (see e.g. StackChunkFrameStream::frame_size())
479 //
480 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom) {
481 assert(FKind::is_instance(hf), "");
482
483 assert(is_aligned(caller.fp(), frame::frame_alignment), "");
484 assert(is_aligned(caller.sp(), frame::frame_alignment), "");
485 if (FKind::interpreted) {
486 // Note: we have to overlap with the caller, at least if it is interpreted, to match the
487 // max_thawing_size calculation during freeze. See also comment above.
488 intptr_t* heap_sp = hf.unextended_sp();
489 const int fsize = ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp();
490 const int overlap = !caller.is_interpreted_frame() ? 0
491 : ContinuationHelper::InterpretedFrame::stack_argsize(hf) + frame::metadata_words_at_top;
492 intptr_t* frame_sp = caller.unextended_sp() + overlap - fsize;
493 intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
494 // align fp
495 int padding = fp - align_down(fp, frame::frame_alignment);
496 fp -= padding;
497 // alignment of sp is done by callee or in finish_thaw()
498 frame_sp -= padding;
499
500 // On ppc esp points to the next free slot on the expression stack and sp + metadata points to the last parameter
501 DEBUG_ONLY(intptr_t* esp = fp + *hf.addr_at(ijava_idx(esp));)
502 assert(frame_sp + frame::metadata_words_at_top == esp+1, " frame_sp=" PTR_FORMAT " esp=" PTR_FORMAT, p2i(frame_sp), p2i(esp));
503 caller.set_sp(fp);
504 frame f(frame_sp, hf.pc(), frame_sp, fp);
505 // we need to set the locals so that the caller of new_stack_frame() can call
506 // ContinuationHelper::InterpretedFrame::frame_bottom
507 // copy relativized locals from the heap frame
508 *f.addr_at(ijava_idx(locals)) = *hf.addr_at(ijava_idx(locals));
509
510 return f;
511 } else {
512 int fsize = FKind::size(hf);
513 int argsize = hf.compiled_frame_stack_argsize();
514 intptr_t* frame_sp = caller.sp() - fsize;
515
516 if ((bottom && argsize > 0) || caller.is_interpreted_frame()) {
517 frame_sp -= argsize + frame::metadata_words_at_top;
518 frame_sp = align_down(frame_sp, frame::alignment_in_bytes);
519 caller.set_sp(frame_sp + fsize);
520 }
521
522 assert(hf.cb() != nullptr, "");
523 assert(hf.oop_map() != nullptr, "");
524 intptr_t* fp = frame_sp + fsize;
525 return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false);
526 }
527 }
528
529 inline intptr_t* ThawBase::align(const frame& hf, intptr_t* frame_sp, frame& caller, bool bottom) {
530 // Unused. Alignment is done directly in new_stack_frame() / finish_thaw().
531 return nullptr;
532 }
533
534 inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, const frame& f) {
535 intptr_t* vfp = f.fp();
536
537 // Make sure that monitors is still relativized.
538 assert(f.at_absolute(ijava_idx(monitors)) <= -(frame::ijava_state_size / wordSize), "");
539
540 // Make sure that esp is still relativized.
541 assert(f.at_absolute(ijava_idx(esp)) <= f.at_absolute(ijava_idx(monitors)), "");
542
543 // Keep top_frame_sp relativized.
544 }
545
546 inline void ThawBase::patch_pd(frame& f, const frame& caller) {
547 patch_callee_link(caller, caller.fp());
548 // Prevent assertion if f gets deoptimized right away before it's fully initialized
549 f.mark_not_fully_initialized();
550 }
551
552 //
553 // Interpreter Calling Procedure on PPC
554 //
555 // Caller Resized Caller before the Call New Callee Frame
556 //
557 // - SP/FP are 16 byte aligned. - The unused part of the expression stack - The caller's original SP is passed as
558 // Padding is added as necessary. is removed sender SP (in R21_sender_SP) also by
559 // - SP is _not_ used as esp - Slots for the callee's nonparameter locals compiled callers. It is saved in the
560 // (expression stack pointer) are added. ijava_state::sender_sp slot and
561 // - Has reserved slots for the - The large ABI is replaced with a minimal restored when returning.
562 // maximal expression stack ABI. This removes a c2i extension if there
563 // - Has a larger ABI section on - The original SP was saved in is one.
564 // top that is required to call ijava_state::top_frame_sp slot. - ijava_state::sender_sp will be set
565 // C++ code From there it is restored as SP _after_ as the caller's unextended sp when
566 // returning from a call. This reverts the iterating stack frames
567 // resizing described above. It is also (see frame::unextended_sp() and
568 // required to undo potential i2c extensions frame::sender_for_interpreter_frame())
569 // if the calle should be compiled.
570 // - Note that unextended SP < SP
571 // is possible on ppc.
|
54 assert(FKind::is_instance(f), "");
55 if (FKind::interpreted) {
56 return frame(f.sender_sp(), f.sender_pc(), f.interpreter_frame_sender_sp());
57 }
58
59 intptr_t* sender_sp = f.sender_sp();
60 address sender_pc = f.sender_pc();
61 assert(sender_sp != f.sp(), "must have changed");
62
63 int slot = 0;
64 CodeBlob* sender_cb = CodeCache::find_blob_and_oopmap(sender_pc, slot);
65 return sender_cb != nullptr
66 ? frame(sender_sp, sender_sp, nullptr, sender_pc, sender_cb, slot == -1 ? nullptr : sender_cb->oop_map_for_slot(slot, sender_pc))
67 : frame(sender_sp, sender_pc, sender_sp);
68 }
69
70 void FreezeBase::adjust_interpreted_frame_unextended_sp(frame& f) {
71 // nothing to do
72 }
73
74 inline void FreezeBase::prepare_freeze_interpreted_top_frame(frame& f) {
75 // nothing to do
76 DEBUG_ONLY( intptr_t* lspp = (intptr_t*) &(f.get_ijava_state()->top_frame_sp); )
77 assert(*lspp == f.unextended_sp() - f.fp(), "should be " INTPTR_FORMAT " usp:" INTPTR_FORMAT " fp:" INTPTR_FORMAT, *lspp, p2i(f.unextended_sp()), p2i(f.fp()));
78 }
79
80 inline void FreezeBase::relativize_interpreted_frame_metadata(const frame& f, const frame& hf) {
81 intptr_t* vfp = f.fp();
82 intptr_t* hfp = hf.fp();
83 assert(f.fp() > (intptr_t*)f.interpreter_frame_esp(), "");
84
85 // There is alignment padding between vfp and f's locals array in the original
86 // frame, because we freeze the padding (see recurse_freeze_interpreted_frame)
87 // in order to keep the same relativized locals pointer, we don't need to change it here.
88
89 // Make sure that monitors is already relativized.
90 assert(hf.at_absolute(ijava_idx(monitors)) <= -(frame::ijava_state_size / wordSize), "");
91
92 // Make sure that esp is already relativized.
93 assert(hf.at_absolute(ijava_idx(esp)) <= hf.at_absolute(ijava_idx(monitors)), "");
94
95 // top_frame_sp is already relativized
96
97 // hfp == hf.sp() + (f.fp() - f.sp()) is not true on ppc because the stack frame has room for
98 // the maximal expression stack and the expression stack in the heap frame is trimmed.
99 assert(hf.fp() == hf.interpreter_frame_esp() + (f.fp() - f.interpreter_frame_esp()), "");
339 // Fast path
340
341 inline void ThawBase::prefetch_chunk_pd(void* start, int size) {
342 size <<= LogBytesPerWord;
343 Prefetch::read(start, size);
344 Prefetch::read(start, size - 64);
345 }
346
347 // Set back chain links of fast thawed frames such that *sp == callers_sp.
348 // See https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html#STACK
349 template <typename ConfigT>
350 inline void Thaw<ConfigT>::patch_caller_links(intptr_t* sp, intptr_t* bottom) {
351 for (intptr_t* callers_sp; sp < bottom; sp = callers_sp) {
352 address pc = (address)((frame::java_abi*) sp)->lr;
353 assert(pc != nullptr, "");
354 // see ThawBase::patch_return() which gets called just before
355 bool is_entry_frame = pc == StubRoutines::cont_returnBarrier() || pc == _cont.entryPC();
356 if (is_entry_frame) {
357 callers_sp = _cont.entryFP();
358 } else {
359 assert(!Interpreter::contains(pc), "sp:" PTR_FORMAT " pc:" PTR_FORMAT, p2i(sp), p2i(pc));
360 CodeBlob* cb = CodeCache::find_blob_fast(pc);
361 callers_sp = sp + cb->frame_size();
362 }
363 // set the back link
364 ((frame::java_abi*) sp)->callers_sp = (intptr_t) callers_sp;
365 }
366 }
367
368 // Slow path
369
370 inline frame ThawBase::new_entry_frame() {
371 intptr_t* sp = _cont.entrySP();
372 return frame(sp, _cont.entryPC(), sp, _cont.entryFP());
373 }
374
375 // === New Interpreted Frame ================================================================================================================
376 //
377 // ### Non-Interpreted Caller (compiled, enterSpecial): No Overlap
378 //
379 // Heap Frame `hf` `hf` gets copied to stack _without_ overlapping the caller
470 // e | | |----------------------|
471 // w |----------------------| | Stack Args |
472 // | frame::java_abi |<- unext. SP / SP | (if any) |
473 // F ======================== |----------------------|
474 // r | frame::java_abi |<- caller's SP
475 // a ======================== / new frame's FP
476 // m | | (aligned)
477 // e | |
478 // |----------------------|
479 // | frame::java_abi |<- unext. SP / SP
480 // ========================
481 //
482 // If the new frame is at the bottom just above the ContinuationEntry frame then the stackargs
483 // don't overlap the caller either even though it is compiled because the size is not
484 // limited/known. In contrast to the interpreted caller case the abi overlaps with the caller
485 // if there are no stackargs. This is to comply with shared code (see e.g. StackChunkFrameStream::frame_size())
486 //
487 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom) {
488 assert(FKind::is_instance(hf), "");
489
490 assert(is_aligned(caller.fp(), frame::frame_alignment), PTR_FORMAT, p2i(caller.fp()));
491 // caller.sp() can be unaligned. This is fixed below.
492 if (FKind::interpreted) {
493 // Note: we have to overlap with the caller, at least if it is interpreted, to match the
494 // max_thawing_size calculation during freeze. See also comment above.
495 intptr_t* heap_sp = hf.unextended_sp();
496 const int fsize = ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp();
497 const int overlap = !caller.is_interpreted_frame() ? 0
498 : ContinuationHelper::InterpretedFrame::stack_argsize(hf) + frame::metadata_words_at_top;
499 intptr_t* frame_sp = caller.unextended_sp() + overlap - fsize;
500 intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
501 // align fp
502 int padding = fp - align_down(fp, frame::frame_alignment);
503 fp -= padding;
504 // alignment of sp is done by callee or in finish_thaw()
505 frame_sp -= padding;
506
507 // On ppc esp points to the next free slot on the expression stack and sp + metadata points to the last parameter
508 DEBUG_ONLY(intptr_t* esp = fp + *hf.addr_at(ijava_idx(esp));)
509 assert(frame_sp + frame::metadata_words_at_top == esp+1, " frame_sp=" PTR_FORMAT " esp=" PTR_FORMAT, p2i(frame_sp), p2i(esp));
510 caller.set_sp(fp);
511 frame f(frame_sp, hf.pc(), frame_sp, fp);
512 // we need to set the locals so that the caller of new_stack_frame() can call
513 // ContinuationHelper::InterpretedFrame::frame_bottom
514 // copy relativized locals from the heap frame
515 *f.addr_at(ijava_idx(locals)) = *hf.addr_at(ijava_idx(locals));
516
517 return f;
518 } else {
519 int fsize = FKind::size(hf);
520 int argsize = FKind::stack_argsize(hf);
521 intptr_t* frame_sp = caller.sp() - fsize;
522
523 if ((bottom && argsize > 0) || caller.is_interpreted_frame()) {
524 frame_sp -= argsize + frame::metadata_words_at_top;
525 frame_sp = align_down(frame_sp, frame::alignment_in_bytes);
526 caller.set_sp(frame_sp + fsize);
527 }
528
529 assert(hf.cb() != nullptr, "");
530 assert(hf.oop_map() != nullptr, "");
531 intptr_t* fp = frame_sp + fsize;
532 return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false);
533 }
534 }
535
536 inline intptr_t* ThawBase::align(const frame& hf, intptr_t* frame_sp, frame& caller, bool bottom) {
537 // Unused. Alignment is done directly in new_stack_frame() / finish_thaw().
538 return nullptr;
539 }
540
541 inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, const frame& f) {
542 intptr_t* vfp = f.fp();
543
544 // Make sure that monitors is still relativized.
545 assert(f.at_absolute(ijava_idx(monitors)) <= -(frame::ijava_state_size / wordSize), "");
546
547 // Make sure that esp is still relativized.
548 assert(f.at_absolute(ijava_idx(esp)) <= f.at_absolute(ijava_idx(monitors)), "");
549
550 // Keep top_frame_sp relativized.
551 }
552
553 inline intptr_t* ThawBase::push_cleanup_continuation() {
554 frame enterSpecial = new_entry_frame();
555 frame::common_abi* enterSpecial_abi = (frame::common_abi*)enterSpecial.sp();
556
557 enterSpecial_abi->lr = (intptr_t)ContinuationEntry::cleanup_pc();
558
559 log_develop_trace(continuations, preempt)("push_cleanup_continuation enterSpecial sp: " INTPTR_FORMAT " cleanup pc: " INTPTR_FORMAT,
560 p2i(enterSpecial_abi),
561 p2i(ContinuationEntry::cleanup_pc()));
562
563 return enterSpecial.sp();
564 }
565
566 inline void ThawBase::patch_pd(frame& f, const frame& caller) {
567 patch_callee_link(caller, caller.fp());
568 // Prevent assertion if f gets deoptimized right away before it's fully initialized
569 f.mark_not_fully_initialized();
570 }
571
572 inline void ThawBase::patch_pd(frame& f, intptr_t* caller_sp) {
573 assert(f.own_abi()->callers_sp == (uint64_t)caller_sp, "should have been fixed by patch_caller_links");
574 }
575
576 //
577 // Interpreter Calling Procedure on PPC
578 //
579 // Caller Resized Caller before the Call New Callee Frame
580 //
581 // - SP/FP are 16 byte aligned. - The unused part of the expression stack - The caller's original SP is passed as
582 // Padding is added as necessary. is removed sender SP (in R21_sender_SP) also by
583 // - SP is _not_ used as esp - Slots for the callee's nonparameter locals compiled callers. It is saved in the
584 // (expression stack pointer) are added. ijava_state::sender_sp slot and
585 // - Has reserved slots for the - The large ABI is replaced with a minimal restored when returning.
586 // maximal expression stack ABI. This removes a c2i extension if there
587 // - Has a larger ABI section on - The original SP was saved in is one.
588 // top that is required to call ijava_state::top_frame_sp slot. - ijava_state::sender_sp will be set
589 // C++ code From there it is restored as SP _after_ as the caller's unextended sp when
590 // returning from a call. This reverts the iterating stack frames
591 // resizing described above. It is also (see frame::unextended_sp() and
592 // required to undo potential i2c extensions frame::sender_for_interpreter_frame())
593 // if the calle should be compiled.
594 // - Note that unextended SP < SP
595 // is possible on ppc.
|