< prev index next >

src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp

Print this page

 50   // copy the spilled fp from the heap to the stack
 51   *(frame_sp - frame::sender_sp_offset) = *(heap_sp - frame::sender_sp_offset);
 52 }
 53 
 54 // Slow path
 55 
 56 template<typename FKind>
 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   intptr_t** link_addr = link_address<FKind>(f);
 63 
 64   intptr_t* sender_sp = (intptr_t*)(link_addr + frame::sender_sp_offset); //  f.unextended_sp() + (fsize/wordSize); //
 65   address sender_pc = ContinuationHelper::return_address_at(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>
 78 frame FreezeBase::new_heap_frame(frame& f, frame& caller) {
 79   assert(FKind::is_instance(f), "");
 80   assert(!caller.is_interpreted_frame()
 81     || caller.unextended_sp() == (intptr_t*)caller.at(frame::interpreter_frame_last_sp_offset), "");
 82 
 83   intptr_t *sp, *fp; // sp is really our unextended_sp
 84   if (FKind::interpreted) {
 85     assert((intptr_t*)f.at(frame::interpreter_frame_last_sp_offset) == nullptr
 86       || f.unextended_sp() == (intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset), "");
 87     intptr_t locals_offset = *f.addr_at(frame::interpreter_frame_locals_offset);
 88     // If the caller.is_empty(), i.e. we're freezing into an empty chunk, then we set
 89     // the chunk's argsize in finalize_freeze and make room for it above the unextended_sp
 90     bool overlap_caller = caller.is_interpreted_frame() || caller.is_empty();
 91     fp = caller.unextended_sp() - 1 - locals_offset + (overlap_caller ? ContinuationHelper::InterpretedFrame::stack_argsize(f) : 0);
 92     sp = fp - (f.fp() - f.unextended_sp());
 93     assert(sp <= fp, "");
 94     assert(fp <= caller.unextended_sp(), "");
 95     caller.set_sp(fp + frame::sender_sp_offset);
 96 
 97     assert(_cont.tail()->is_in_chunk(sp), "");
 98 
 99     frame hf(sp, sp, fp, f.pc(), nullptr, nullptr, true /* on_heap */);
100     // copy relativized locals from the stack frame
101     *hf.addr_at(frame::interpreter_frame_locals_offset) = locals_offset;
102     return hf;
103   } else {
104     // We need to re-read fp out of the frame because it may be an oop and we might have
105     // had a safepoint in finalize_freeze, after constructing f.
106     fp = *(intptr_t**)(f.sp() - frame::sender_sp_offset);
107 
108     int fsize = FKind::size(f);
109     sp = caller.unextended_sp() - fsize;
110     if (caller.is_interpreted_frame()) {
111       // If the caller is interpreted, our stackargs are not supposed to overlap with it
112       // so we make more room by moving sp down by argsize
113       int argsize = FKind::stack_argsize(f);
114       sp -= argsize;
115     }
116     caller.set_sp(sp + fsize);
117 
118     assert(_cont.tail()->is_in_chunk(sp), "");
119 
120     return frame(sp, sp, fp, f.pc(), nullptr, nullptr, true /* on_heap */);
121   }
122 }
123 
124 void FreezeBase::adjust_interpreted_frame_unextended_sp(frame& f) {
125   assert((f.at(frame::interpreter_frame_last_sp_offset) != 0) || (f.unextended_sp() == f.sp()), "");
126   intptr_t* real_unextended_sp = (intptr_t*)f.at_relative_or_null(frame::interpreter_frame_last_sp_offset);
127   if (real_unextended_sp != nullptr) {
128     f.set_unextended_sp(real_unextended_sp); // can be null at a safepoint
129   }
130 }

163   assert((hf.fp() - hf.unextended_sp()) == (f.fp() - f.unextended_sp()), "");
164   assert(hf.unextended_sp() == (intptr_t*)hf.at(frame::interpreter_frame_last_sp_offset), "");
165   assert(hf.unextended_sp() <= (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
166   assert(hf.unextended_sp() + extra_space >  (intptr_t*)hf.at(frame::interpreter_frame_extended_sp_offset), "");
167   assert(hf.fp()            >  (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
168   assert(hf.fp()            <= (intptr_t*)hf.at(frame::interpreter_frame_locals_offset), "");
169 }
170 
171 inline void FreezeBase::set_top_frame_metadata_pd(const frame& hf) {
172   stackChunkOop chunk = _cont.tail();
173   assert(chunk->is_in_chunk(hf.sp() - 1), "");
174   assert(chunk->is_in_chunk(hf.sp() - frame::sender_sp_offset), "");
175 
176   *(hf.sp() - 1) = (intptr_t)hf.pc();
177 
178   intptr_t* fp_addr = hf.sp() - frame::sender_sp_offset;
179   *fp_addr = hf.is_interpreted_frame() ? (intptr_t)(hf.fp() - fp_addr)
180                                        : (intptr_t)hf.fp();
181 }
182 
183 inline void FreezeBase::patch_pd(frame& hf, const frame& caller) {
184   if (caller.is_interpreted_frame()) {
185     assert(!caller.is_empty(), "");
186     patch_callee_link_relative(caller, caller.fp());
187   } else {

188     // If we're the bottom-most frame frozen in this freeze, the caller might have stayed frozen in the chunk,
189     // and its oop-containing fp fixed. We've now just overwritten it, so we must patch it back to its value
190     // as read from the chunk.
191     patch_callee_link(caller, caller.fp());
192   }
193 }
194 
195 //////// Thaw
196 
197 // Fast path
198 
199 inline void ThawBase::prefetch_chunk_pd(void* start, int size) {
200   size <<= LogBytesPerWord;
201   Prefetch::read(start, size);
202   Prefetch::read(start, size - 64);
203 }
204 
205 template <typename ConfigT>
206 inline void Thaw<ConfigT>::patch_caller_links(intptr_t* sp, intptr_t* bottom) {
207   // Fast path depends on !PreserveFramePointer. See can_thaw_fast().
208   assert(!PreserveFramePointer, "Frame pointers need to be fixed");
209 }
210 
211 // Slow path
212 
213 inline frame ThawBase::new_entry_frame() {
214   intptr_t* sp = _cont.entrySP();
215   return frame(sp, sp, _cont.entryFP(), _cont.entryPC()); // TODO PERF: This finds code blob and computes deopt state
216 }
217 
218 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom) {
219   assert(FKind::is_instance(hf), "");
220   // The values in the returned frame object will be written into the callee's stack in patch.
221 
222   if (FKind::interpreted) {
223     intptr_t* heap_sp = hf.unextended_sp();
224     // If caller is interpreted it already made room for the callee arguments
225     int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0;
226     const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap);
227     intptr_t* frame_sp = caller.unextended_sp() - fsize;
228     intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
229     if ((intptr_t)fp % frame::frame_alignment != 0) {
230       fp--;
231       frame_sp--;
232       log_develop_trace(continuations)("Adding internal interpreted frame alignment");
233     }
234     DEBUG_ONLY(intptr_t* unextended_sp = fp + *hf.addr_at(frame::interpreter_frame_last_sp_offset);)
235     assert(frame_sp == unextended_sp, "");
236     caller.set_sp(fp + frame::sender_sp_offset);
237     frame f(frame_sp, frame_sp, fp, hf.pc());
238     // we need to set the locals so that the caller of new_stack_frame() can call
239     // ContinuationHelper::InterpretedFrame::frame_bottom
240     // copy relativized locals from the heap frame
241     *f.addr_at(frame::interpreter_frame_locals_offset) = *hf.addr_at(frame::interpreter_frame_locals_offset);
242     assert((intptr_t)f.fp() % frame::frame_alignment == 0, "");
243     return f;
244   } else {
245     int fsize = FKind::size(hf);
246     intptr_t* frame_sp = caller.unextended_sp() - fsize;
247     if (bottom || caller.is_interpreted_frame()) {
248       int argsize = FKind::stack_argsize(hf);
249 
250       fsize += argsize;
251       frame_sp   -= argsize;
252       caller.set_sp(caller.sp() - argsize);
253       assert(caller.sp() == frame_sp + (fsize-argsize), "");
254 
255       frame_sp = align(hf, frame_sp, caller, bottom);
256     }


257 
258     assert(hf.cb() != nullptr, "");
259     assert(hf.oop_map() != nullptr, "");
260     intptr_t* fp;
261     if (PreserveFramePointer) {
262       // we need to recreate a "real" frame pointer, pointing into the stack
263       fp = frame_sp + FKind::size(hf) - frame::sender_sp_offset;
264     } else {
265       fp = FKind::stub || FKind::native
266         ? frame_sp + fsize - frame::sender_sp_offset // fp always points to the address below the pushed return pc. We need correct address.
267         : *(intptr_t**)(hf.sp() - frame::sender_sp_offset); // we need to re-read fp because it may be an oop and we might have fixed the frame.
268     }
269     return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false); // TODO PERF : this computes deopt state; is it necessary?
270   }
271 }
272 
273 inline intptr_t* ThawBase::align(const frame& hf, intptr_t* frame_sp, frame& caller, bool bottom) {
274 #ifdef _LP64
275   if (((intptr_t)frame_sp & 0xf) != 0) {
276     assert(caller.is_interpreted_frame() || (bottom && hf.compiled_frame_stack_argsize() % 2 != 0), "");
277     frame_sp--;
278     caller.set_sp(caller.sp() - 1);
279   }
280   assert(is_aligned(frame_sp, frame::frame_alignment), "");
281 #endif
282 
283   return frame_sp;
284 }
285 
286 inline void ThawBase::patch_pd(frame& f, const frame& caller) {
287   patch_callee_link(caller, caller.fp());


288 }
289 
290 inline void ThawBase::patch_pd(frame& f, intptr_t* caller_sp) {
291   intptr_t* fp = caller_sp - frame::sender_sp_offset;
292   patch_callee_link(f, fp);
293 }
294 
295 inline intptr_t* ThawBase::push_cleanup_continuation() {
296   frame enterSpecial = new_entry_frame();
297   intptr_t* sp = enterSpecial.sp();
298 
299   sp[-1] = (intptr_t)ContinuationEntry::cleanup_pc();
300   sp[-2] = (intptr_t)enterSpecial.fp();
301 
302   log_develop_trace(continuations, preempt)("push_cleanup_continuation initial sp: " INTPTR_FORMAT " final sp: " INTPTR_FORMAT, p2i(sp + 2 * frame::metadata_words), p2i(sp));
303   return sp;
304 }
305 
306 inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, const frame& f) {
307   // Make sure that last_sp is kept relativized.

 50   // copy the spilled fp from the heap to the stack
 51   *(frame_sp - frame::sender_sp_offset) = *(heap_sp - frame::sender_sp_offset);
 52 }
 53 
 54 // Slow path
 55 
 56 template<typename FKind>
 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   intptr_t** link_addr = link_address<FKind>(f);
 63 
 64   intptr_t* sender_sp = (intptr_t*)(link_addr + frame::sender_sp_offset); //  f.unextended_sp() + (fsize/wordSize); //
 65   address sender_pc = ContinuationHelper::return_address_at(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 
 71   // Repair the sender sp if the frame has been extended
 72   if (sender_cb->is_nmethod()) {
 73     sender_sp = f.repair_sender_sp(sender_sp, link_addr);
 74   }
 75 
 76   return sender_cb != nullptr
 77     ? frame(sender_sp, sender_sp, *link_addr, sender_pc, sender_cb,
 78             slot == -1 ? nullptr : sender_cb->oop_map_for_slot(slot, sender_pc),
 79             false /* on_heap ? */)
 80     : frame(sender_sp, sender_sp, *link_addr, sender_pc);
 81 }
 82 
 83 template<typename FKind>
 84 frame FreezeBase::new_heap_frame(frame& f, frame& caller, int size_adjust) {
 85   assert(FKind::is_instance(f), "");
 86   assert(!caller.is_interpreted_frame()
 87     || caller.unextended_sp() == (intptr_t*)caller.at(frame::interpreter_frame_last_sp_offset), "");
 88 
 89   intptr_t *sp, *fp; // sp is really our unextended_sp
 90   if (FKind::interpreted) {
 91     assert((intptr_t*)f.at(frame::interpreter_frame_last_sp_offset) == nullptr
 92       || f.unextended_sp() == (intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset), "");
 93     intptr_t locals_offset = *f.addr_at(frame::interpreter_frame_locals_offset);
 94     // If the caller.is_empty(), i.e. we're freezing into an empty chunk, then we set
 95     // the chunk's argsize in finalize_freeze and make room for it above the unextended_sp
 96     bool overlap_caller = caller.is_interpreted_frame() || caller.is_empty();
 97     fp = caller.unextended_sp() - 1 - locals_offset + (overlap_caller ? ContinuationHelper::InterpretedFrame::stack_argsize(f) : 0);
 98     sp = fp - (f.fp() - f.unextended_sp());
 99     assert(sp <= fp, "");
100     assert(fp <= caller.unextended_sp(), "");
101     caller.set_sp(fp + frame::sender_sp_offset);
102 
103     assert(_cont.tail()->is_in_chunk(sp), "");
104 
105     frame hf(sp, sp, fp, f.pc(), nullptr, nullptr, true /* on_heap */);
106     // copy relativized locals from the stack frame
107     *hf.addr_at(frame::interpreter_frame_locals_offset) = locals_offset;
108     return hf;
109   } else {
110     // We need to re-read fp out of the frame because it may be an oop and we might have
111     // had a safepoint in finalize_freeze, after constructing f.
112     fp = *(intptr_t**)(f.sp() - frame::sender_sp_offset);
113 
114     int fsize = FKind::size(f);
115     sp = caller.unextended_sp() - fsize - size_adjust;
116     if (caller.is_interpreted_frame() && size_adjust == 0) {
117       // If the caller is interpreted, our stackargs are not supposed to overlap with it
118       // so we make more room by moving sp down by argsize
119       int argsize = FKind::stack_argsize(f);
120       sp -= argsize;
121     }
122     caller.set_sp(sp + fsize);
123 
124     assert(_cont.tail()->is_in_chunk(sp), "");
125 
126     return frame(sp, sp, fp, f.pc(), nullptr, nullptr, true /* on_heap */);
127   }
128 }
129 
130 void FreezeBase::adjust_interpreted_frame_unextended_sp(frame& f) {
131   assert((f.at(frame::interpreter_frame_last_sp_offset) != 0) || (f.unextended_sp() == f.sp()), "");
132   intptr_t* real_unextended_sp = (intptr_t*)f.at_relative_or_null(frame::interpreter_frame_last_sp_offset);
133   if (real_unextended_sp != nullptr) {
134     f.set_unextended_sp(real_unextended_sp); // can be null at a safepoint
135   }
136 }

169   assert((hf.fp() - hf.unextended_sp()) == (f.fp() - f.unextended_sp()), "");
170   assert(hf.unextended_sp() == (intptr_t*)hf.at(frame::interpreter_frame_last_sp_offset), "");
171   assert(hf.unextended_sp() <= (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
172   assert(hf.unextended_sp() + extra_space >  (intptr_t*)hf.at(frame::interpreter_frame_extended_sp_offset), "");
173   assert(hf.fp()            >  (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
174   assert(hf.fp()            <= (intptr_t*)hf.at(frame::interpreter_frame_locals_offset), "");
175 }
176 
177 inline void FreezeBase::set_top_frame_metadata_pd(const frame& hf) {
178   stackChunkOop chunk = _cont.tail();
179   assert(chunk->is_in_chunk(hf.sp() - 1), "");
180   assert(chunk->is_in_chunk(hf.sp() - frame::sender_sp_offset), "");
181 
182   *(hf.sp() - 1) = (intptr_t)hf.pc();
183 
184   intptr_t* fp_addr = hf.sp() - frame::sender_sp_offset;
185   *fp_addr = hf.is_interpreted_frame() ? (intptr_t)(hf.fp() - fp_addr)
186                                        : (intptr_t)hf.fp();
187 }
188 
189 inline void FreezeBase::patch_pd(frame& hf, const frame& caller, bool is_bottom_frame) {
190   if (caller.is_interpreted_frame()) {
191     assert(!caller.is_empty(), "");
192     patch_callee_link_relative(caller, caller.fp());
193   } else if (is_bottom_frame && caller.pc() != nullptr) {
194     assert(caller.is_compiled_frame(), "");
195     // If we're the bottom-most frame frozen in this freeze, the caller might have stayed frozen in the chunk,
196     // and its oop-containing fp fixed. We've now just overwritten it, so we must patch it back to its value
197     // as read from the chunk.
198     patch_callee_link(caller, caller.fp());
199   }
200 }
201 
202 //////// Thaw
203 
204 // Fast path
205 
206 inline void ThawBase::prefetch_chunk_pd(void* start, int size) {
207   size <<= LogBytesPerWord;
208   Prefetch::read(start, size);
209   Prefetch::read(start, size - 64);
210 }
211 
212 template <typename ConfigT>
213 inline void Thaw<ConfigT>::patch_caller_links(intptr_t* sp, intptr_t* bottom) {
214   // Fast path depends on !PreserveFramePointer. See can_thaw_fast().
215   assert(!PreserveFramePointer, "Frame pointers need to be fixed");
216 }
217 
218 // Slow path
219 
220 inline frame ThawBase::new_entry_frame() {
221   intptr_t* sp = _cont.entrySP();
222   return frame(sp, sp, _cont.entryFP(), _cont.entryPC()); // TODO PERF: This finds code blob and computes deopt state
223 }
224 
225 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom, int size_adjust) {
226   assert(FKind::is_instance(hf), "");
227   // The values in the returned frame object will be written into the callee's stack in patch.
228 
229   if (FKind::interpreted) {
230     intptr_t* heap_sp = hf.unextended_sp();
231     // If caller is interpreted it already made room for the callee arguments
232     int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0;
233     const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap);
234     intptr_t* frame_sp = caller.unextended_sp() - fsize;
235     intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
236     if ((intptr_t)fp % frame::frame_alignment != 0) {
237       fp--;
238       frame_sp--;
239       log_develop_trace(continuations)("Adding internal interpreted frame alignment");
240     }
241     DEBUG_ONLY(intptr_t* unextended_sp = fp + *hf.addr_at(frame::interpreter_frame_last_sp_offset);)
242     assert(frame_sp == unextended_sp, "");
243     caller.set_sp(fp + frame::sender_sp_offset);
244     frame f(frame_sp, frame_sp, fp, hf.pc());
245     // we need to set the locals so that the caller of new_stack_frame() can call
246     // ContinuationHelper::InterpretedFrame::frame_bottom
247     // copy relativized locals from the heap frame
248     *f.addr_at(frame::interpreter_frame_locals_offset) = *hf.addr_at(frame::interpreter_frame_locals_offset);
249     assert((intptr_t)f.fp() % frame::frame_alignment == 0, "");
250     return f;
251   } else {
252     int fsize = FKind::size(hf);
253     intptr_t* frame_sp = caller.unextended_sp() - fsize - size_adjust;
254     if (bottom || caller.is_interpreted_frame()) {
255       if (size_adjust == 0) {
256         int argsize = FKind::stack_argsize(hf);
257         frame_sp -= argsize;
258       }



259       frame_sp = align(hf, frame_sp, caller, bottom);
260     }
261     caller.set_sp(frame_sp + fsize);
262     assert(is_aligned(frame_sp, frame::frame_alignment), "");
263 
264     assert(hf.cb() != nullptr, "");
265     assert(hf.oop_map() != nullptr, "");
266     intptr_t* fp;
267     if (PreserveFramePointer) {
268       // we need to recreate a "real" frame pointer, pointing into the stack
269       fp = frame_sp + fsize - frame::sender_sp_offset;
270     } else {
271       fp = FKind::stub || FKind::native
272         ? frame_sp + fsize - frame::sender_sp_offset // fp always points to the address below the pushed return pc. We need correct address.
273         : *(intptr_t**)(hf.sp() - frame::sender_sp_offset); // we need to re-read fp because it may be an oop and we might have fixed the frame.
274     }
275     return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false); // TODO PERF : this computes deopt state; is it necessary?
276   }
277 }
278 
279 inline intptr_t* ThawBase::align(const frame& hf, intptr_t* frame_sp, frame& caller, bool bottom) {
280 #ifdef _LP64
281   if (((intptr_t)frame_sp & 0xf) != 0) {
282     assert(caller.is_interpreted_frame() || (bottom && hf.compiled_frame_stack_argsize() % 2 != 0), "");
283     frame_sp--;

284   }
285   assert(is_aligned(frame_sp, frame::frame_alignment), "");
286 #endif

287   return frame_sp;
288 }
289 
290 inline void ThawBase::patch_pd(frame& f, const frame& caller) {
291   if (caller.is_interpreted_frame() || PreserveFramePointer) {
292     patch_callee_link(caller, caller.fp());
293   }
294 }
295 
296 inline void ThawBase::patch_pd(frame& f, intptr_t* caller_sp) {
297   intptr_t* fp = caller_sp - frame::sender_sp_offset;
298   patch_callee_link(f, fp);
299 }
300 
301 inline intptr_t* ThawBase::push_cleanup_continuation() {
302   frame enterSpecial = new_entry_frame();
303   intptr_t* sp = enterSpecial.sp();
304 
305   sp[-1] = (intptr_t)ContinuationEntry::cleanup_pc();
306   sp[-2] = (intptr_t)enterSpecial.fp();
307 
308   log_develop_trace(continuations, preempt)("push_cleanup_continuation initial sp: " INTPTR_FORMAT " final sp: " INTPTR_FORMAT, p2i(sp + 2 * frame::metadata_words), p2i(sp));
309   return sp;
310 }
311 
312 inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, const frame& f) {
313   // Make sure that last_sp is kept relativized.
< prev index next >