1 /*
2 * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
57 inline frame FreezeBase::sender(const frame& f) {
58 assert(FKind::is_instance(f), "");
59 if (FKind::interpreted) {
60 return frame(f.sender_sp(), f.interpreter_frame_sender_sp(), f.link(), f.sender_pc());
61 }
62
63 intptr_t** link_addr = link_address<FKind>(f);
64 intptr_t* sender_sp = (intptr_t*)(link_addr + 2); // f.unextended_sp() + (fsize/wordSize); //
65 address sender_pc = (address) *(sender_sp - 1);
66 assert(sender_sp != f.sp(), "must have changed");
67
68 int slot = 0;
69 CodeBlob* sender_cb = CodeCache::find_blob_and_oopmap(sender_pc, slot);
70 return sender_cb != nullptr
71 ? frame(sender_sp, sender_sp, *link_addr, sender_pc, sender_cb,
72 slot == -1 ? nullptr : sender_cb->oop_map_for_slot(slot, sender_pc),
73 false /* on_heap ? */)
74 : frame(sender_sp, sender_sp, *link_addr, sender_pc);
75 }
76
77 template<typename FKind> frame FreezeBase::new_heap_frame(frame& f, frame& caller) {
78 assert(FKind::is_instance(f), "");
79 assert(!caller.is_interpreted_frame()
80 || caller.unextended_sp() == (intptr_t*)caller.at(frame::interpreter_frame_last_sp_offset), "");
81
82 intptr_t *sp, *fp; // sp is really our unextended_sp
83 if (FKind::interpreted) {
84 assert((intptr_t*)f.at(frame::interpreter_frame_last_sp_offset) == nullptr
85 || f.unextended_sp() == (intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset), "");
86 intptr_t locals_offset = *f.addr_at(frame::interpreter_frame_locals_offset);
87 // If the caller.is_empty(), i.e. we're freezing into an empty chunk, then we set
88 // the chunk's argsize in finalize_freeze and make room for it above the unextended_sp
89 bool overlap_caller = caller.is_interpreted_frame() || caller.is_empty();
90 fp = caller.unextended_sp() - 1 - locals_offset + (overlap_caller ? ContinuationHelper::InterpretedFrame::stack_argsize(f) : 0);
91 sp = fp - (f.fp() - f.unextended_sp());
92 assert(sp <= fp, "");
93 assert(fp <= caller.unextended_sp(), "");
94 caller.set_sp(fp + frame::sender_sp_offset);
95
96 assert(_cont.tail()->is_in_chunk(sp), "");
97
165 assert(hf.fp() > (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
166 #ifdef ASSERT
167 if (f.interpreter_frame_method()->max_locals() > 0) {
168 assert(hf.fp() <= (intptr_t*)hf.at(frame::interpreter_frame_locals_offset), "");
169 }
170 #endif
171 }
172
173 inline void FreezeBase::set_top_frame_metadata_pd(const frame& hf) {
174 stackChunkOop chunk = _cont.tail();
175 assert(chunk->is_in_chunk(hf.sp() - 1), "");
176 assert(chunk->is_in_chunk(hf.sp() - 2), "");
177
178 *(hf.sp() - 1) = (intptr_t)hf.pc();
179
180 intptr_t* fp_addr = hf.sp() - 2;
181 *fp_addr = hf.is_interpreted_frame() ? (intptr_t)(hf.fp() - fp_addr)
182 : (intptr_t)hf.fp();
183 }
184
185 inline void FreezeBase::patch_pd(frame& hf, const frame& caller) {
186 if (caller.is_interpreted_frame()) {
187 assert(!caller.is_empty(), "");
188 patch_callee_link_relative(caller, caller.fp());
189 } else {
190 // If we're the bottom-most frame frozen in this freeze, the caller might have stayed frozen in the chunk,
191 // and its oop-containing fp fixed. We've now just overwritten it, so we must patch it back to its value
192 // as read from the chunk.
193 patch_callee_link(caller, caller.fp());
194 }
195 }
196
197 inline void FreezeBase::patch_pd_unused(intptr_t* sp) {
198 }
199
200 //////// Thaw
201
202 // Fast path
203
204 inline void ThawBase::prefetch_chunk_pd(void* start, int size) {
205 size <<= LogBytesPerWord;
239 if (sp != _last_sp_from_frame) {
240 sp[-1] = (intptr_t)_top_frame.pc();
241 }
242 }
243 }
244
245 template <typename ConfigT>
246 inline void Thaw<ConfigT>::patch_caller_links(intptr_t* sp, intptr_t* bottom) {
247 // Fast path depends on !PreserveFramePointer. See can_thaw_fast().
248 assert(!PreserveFramePointer, "Frame pointers need to be fixed");
249 }
250
251 // Slow path
252
253 inline frame ThawBase::new_entry_frame() {
254 intptr_t* sp = _cont.entrySP();
255 // TODO PERF: This finds code blob and computes deopt state
256 return frame(sp, sp, _cont.entryFP(), _cont.entryPC());
257 }
258
259 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom) {
260 assert(FKind::is_instance(hf), "");
261 // The values in the returned frame object will be written into the callee's stack in patch.
262
263 if (FKind::interpreted) {
264 intptr_t* heap_sp = hf.unextended_sp();
265 // If caller is interpreted it already made room for the callee arguments
266 int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0;
267 const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap);
268 intptr_t* frame_sp = caller.unextended_sp() - fsize;
269 intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
270 if ((intptr_t)fp % frame::frame_alignment != 0) {
271 fp--;
272 frame_sp--;
273 log_develop_trace(continuations)("Adding internal interpreted frame alignment");
274 }
275 DEBUG_ONLY(intptr_t* unextended_sp = fp + *hf.addr_at(frame::interpreter_frame_last_sp_offset);)
276 assert(frame_sp == unextended_sp, "");
277 caller.set_sp(fp + frame::sender_sp_offset);
278 frame f(frame_sp, frame_sp, fp, hf.pc());
279 // we need to set the locals so that the caller of new_stack_frame() can call
|
1 /*
2 * Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
57 inline frame FreezeBase::sender(const frame& f) {
58 assert(FKind::is_instance(f), "");
59 if (FKind::interpreted) {
60 return frame(f.sender_sp(), f.interpreter_frame_sender_sp(), f.link(), f.sender_pc());
61 }
62
63 intptr_t** link_addr = link_address<FKind>(f);
64 intptr_t* sender_sp = (intptr_t*)(link_addr + 2); // f.unextended_sp() + (fsize/wordSize); //
65 address sender_pc = (address) *(sender_sp - 1);
66 assert(sender_sp != f.sp(), "must have changed");
67
68 int slot = 0;
69 CodeBlob* sender_cb = CodeCache::find_blob_and_oopmap(sender_pc, slot);
70 return sender_cb != nullptr
71 ? frame(sender_sp, sender_sp, *link_addr, sender_pc, sender_cb,
72 slot == -1 ? nullptr : sender_cb->oop_map_for_slot(slot, sender_pc),
73 false /* on_heap ? */)
74 : frame(sender_sp, sender_sp, *link_addr, sender_pc);
75 }
76
77 template<typename FKind> frame FreezeBase::new_heap_frame(frame& f, frame& caller, int size_adjust) {
78 assert(FKind::is_instance(f), "");
79 assert(!caller.is_interpreted_frame()
80 || caller.unextended_sp() == (intptr_t*)caller.at(frame::interpreter_frame_last_sp_offset), "");
81
82 intptr_t *sp, *fp; // sp is really our unextended_sp
83 if (FKind::interpreted) {
84 assert((intptr_t*)f.at(frame::interpreter_frame_last_sp_offset) == nullptr
85 || f.unextended_sp() == (intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset), "");
86 intptr_t locals_offset = *f.addr_at(frame::interpreter_frame_locals_offset);
87 // If the caller.is_empty(), i.e. we're freezing into an empty chunk, then we set
88 // the chunk's argsize in finalize_freeze and make room for it above the unextended_sp
89 bool overlap_caller = caller.is_interpreted_frame() || caller.is_empty();
90 fp = caller.unextended_sp() - 1 - locals_offset + (overlap_caller ? ContinuationHelper::InterpretedFrame::stack_argsize(f) : 0);
91 sp = fp - (f.fp() - f.unextended_sp());
92 assert(sp <= fp, "");
93 assert(fp <= caller.unextended_sp(), "");
94 caller.set_sp(fp + frame::sender_sp_offset);
95
96 assert(_cont.tail()->is_in_chunk(sp), "");
97
165 assert(hf.fp() > (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
166 #ifdef ASSERT
167 if (f.interpreter_frame_method()->max_locals() > 0) {
168 assert(hf.fp() <= (intptr_t*)hf.at(frame::interpreter_frame_locals_offset), "");
169 }
170 #endif
171 }
172
173 inline void FreezeBase::set_top_frame_metadata_pd(const frame& hf) {
174 stackChunkOop chunk = _cont.tail();
175 assert(chunk->is_in_chunk(hf.sp() - 1), "");
176 assert(chunk->is_in_chunk(hf.sp() - 2), "");
177
178 *(hf.sp() - 1) = (intptr_t)hf.pc();
179
180 intptr_t* fp_addr = hf.sp() - 2;
181 *fp_addr = hf.is_interpreted_frame() ? (intptr_t)(hf.fp() - fp_addr)
182 : (intptr_t)hf.fp();
183 }
184
185 inline void FreezeBase::patch_pd(frame& hf, const frame& caller, bool is_bottom_frame) {
186 if (caller.is_interpreted_frame()) {
187 assert(!caller.is_empty(), "");
188 patch_callee_link_relative(caller, caller.fp());
189 } else {
190 // If we're the bottom-most frame frozen in this freeze, the caller might have stayed frozen in the chunk,
191 // and its oop-containing fp fixed. We've now just overwritten it, so we must patch it back to its value
192 // as read from the chunk.
193 patch_callee_link(caller, caller.fp());
194 }
195 }
196
197 inline void FreezeBase::patch_pd_unused(intptr_t* sp) {
198 }
199
200 //////// Thaw
201
202 // Fast path
203
204 inline void ThawBase::prefetch_chunk_pd(void* start, int size) {
205 size <<= LogBytesPerWord;
239 if (sp != _last_sp_from_frame) {
240 sp[-1] = (intptr_t)_top_frame.pc();
241 }
242 }
243 }
244
245 template <typename ConfigT>
246 inline void Thaw<ConfigT>::patch_caller_links(intptr_t* sp, intptr_t* bottom) {
247 // Fast path depends on !PreserveFramePointer. See can_thaw_fast().
248 assert(!PreserveFramePointer, "Frame pointers need to be fixed");
249 }
250
251 // Slow path
252
253 inline frame ThawBase::new_entry_frame() {
254 intptr_t* sp = _cont.entrySP();
255 // TODO PERF: This finds code blob and computes deopt state
256 return frame(sp, sp, _cont.entryFP(), _cont.entryPC());
257 }
258
259 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom, int size_adjust) {
260 assert(FKind::is_instance(hf), "");
261 // The values in the returned frame object will be written into the callee's stack in patch.
262
263 if (FKind::interpreted) {
264 intptr_t* heap_sp = hf.unextended_sp();
265 // If caller is interpreted it already made room for the callee arguments
266 int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0;
267 const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap);
268 intptr_t* frame_sp = caller.unextended_sp() - fsize;
269 intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
270 if ((intptr_t)fp % frame::frame_alignment != 0) {
271 fp--;
272 frame_sp--;
273 log_develop_trace(continuations)("Adding internal interpreted frame alignment");
274 }
275 DEBUG_ONLY(intptr_t* unextended_sp = fp + *hf.addr_at(frame::interpreter_frame_last_sp_offset);)
276 assert(frame_sp == unextended_sp, "");
277 caller.set_sp(fp + frame::sender_sp_offset);
278 frame f(frame_sp, frame_sp, fp, hf.pc());
279 // we need to set the locals so that the caller of new_stack_frame() can call
|