< prev index next >

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

Print this page

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 }
131 






132 inline void FreezeBase::relativize_interpreted_frame_metadata(const frame& f, const frame& hf) {
133   assert(hf.fp() == hf.unextended_sp() + (f.fp() - f.unextended_sp()), "");
134   assert((f.at(frame::interpreter_frame_last_sp_offset) != 0)
135     || (f.unextended_sp() == f.sp()), "");
136   assert(f.fp() > (intptr_t*)f.at_relative(frame::interpreter_frame_initial_sp_offset), "");
137 
138   // on AARCH64, we may insert padding between the locals and the rest of the frame
139   // (see TemplateInterpreterGenerator::generate_normal_entry, and AbstractInterpreter::layout_activation)
140   // because we freeze the padding word (see recurse_freeze_interpreted_frame) in order to keep the same relativized
141   // locals value, we don't need to change the locals value here.
142 
143   // Make sure that last_sp is already relativized.
144   assert((intptr_t*)hf.at_relative(frame::interpreter_frame_last_sp_offset) == hf.unextended_sp(), "");
145 
146   // Make sure that monitor_block_top is already relativized.
147   assert(hf.at_absolute(frame::interpreter_frame_monitor_block_top_offset) <= frame::interpreter_frame_initial_sp_offset, "");
148 
149   // extended_sp is already relativized by TemplateInterpreterGenerator::generate_normal_entry or
150   // AbstractInterpreter::layout_activation
151 






152   assert((hf.fp() - hf.unextended_sp()) == (f.fp() - f.unextended_sp()), "");
153   assert(hf.unextended_sp() == (intptr_t*)hf.at(frame::interpreter_frame_last_sp_offset), "");
154   assert(hf.unextended_sp() <= (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
155   assert(hf.unextended_sp() >  (intptr_t*)hf.at(frame::interpreter_frame_extended_sp_offset), "");
156   assert(hf.fp()            >  (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
157   assert(hf.fp()            <= (intptr_t*)hf.at(frame::interpreter_frame_locals_offset), "");
158 }
159 
160 inline void FreezeBase::set_top_frame_metadata_pd(const frame& hf) {
161   stackChunkOop chunk = _cont.tail();
162   assert(chunk->is_in_chunk(hf.sp() - 1), "");
163   assert(chunk->is_in_chunk(hf.sp() - frame::sender_sp_offset), "");
164 
165   *(hf.sp() - 1) = (intptr_t)hf.pc();
166 
167   intptr_t* fp_addr = hf.sp() - frame::sender_sp_offset;
168   *fp_addr = hf.is_interpreted_frame() ? (intptr_t)(hf.fp() - fp_addr)
169                                        : (intptr_t)hf.fp();
170 }
171 
172 inline void FreezeBase::patch_pd(frame& hf, const frame& caller) {
173   if (caller.is_interpreted_frame()) {
174     assert(!caller.is_empty(), "");
175     patch_callee_link_relative(caller, caller.fp());

196   // Fast path depends on !PreserveFramePointer. See can_thaw_fast().
197   assert(!PreserveFramePointer, "Frame pointers need to be fixed");
198 }
199 
200 // Slow path
201 
202 inline frame ThawBase::new_entry_frame() {
203   intptr_t* sp = _cont.entrySP();
204   return frame(sp, sp, _cont.entryFP(), _cont.entryPC()); // TODO PERF: This finds code blob and computes deopt state
205 }
206 
207 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom) {
208   assert(FKind::is_instance(hf), "");
209   // The values in the returned frame object will be written into the callee's stack in patch.
210 
211   if (FKind::interpreted) {
212     intptr_t* heap_sp = hf.unextended_sp();
213     // If caller is interpreted it already made room for the callee arguments
214     int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0;
215     const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap);
216     const int locals = hf.interpreter_frame_method()->max_locals();
217     intptr_t* frame_sp = caller.unextended_sp() - fsize;
218     intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
219     if ((intptr_t)fp % frame::frame_alignment != 0) {
220       fp--;
221       frame_sp--;
222       log_develop_trace(continuations)("Adding internal interpreted frame alignment");
223     }
224     DEBUG_ONLY(intptr_t* unextended_sp = fp + *hf.addr_at(frame::interpreter_frame_last_sp_offset);)
225     assert(frame_sp == unextended_sp, "");
226     caller.set_sp(fp + frame::sender_sp_offset);
227     frame f(frame_sp, frame_sp, fp, hf.pc());
228     // we need to set the locals so that the caller of new_stack_frame() can call
229     // ContinuationHelper::InterpretedFrame::frame_bottom
230     // copy relativized locals from the heap frame
231     *f.addr_at(frame::interpreter_frame_locals_offset) = *hf.addr_at(frame::interpreter_frame_locals_offset);
232     assert((intptr_t)f.fp() % frame::frame_alignment == 0, "");
233     return f;
234   } else {
235     int fsize = FKind::size(hf);
236     intptr_t* frame_sp = caller.unextended_sp() - fsize;
237     if (bottom || caller.is_interpreted_frame()) {
238       int argsize = hf.compiled_frame_stack_argsize();
239 
240       fsize += argsize;
241       frame_sp   -= argsize;
242       caller.set_sp(caller.sp() - argsize);
243       assert(caller.sp() == frame_sp + (fsize-argsize), "");
244 
245       frame_sp = align(hf, frame_sp, caller, bottom);
246     }
247 
248     assert(hf.cb() != nullptr, "");
249     assert(hf.oop_map() != nullptr, "");
250     intptr_t* fp;
251     if (PreserveFramePointer) {
252       // we need to recreate a "real" frame pointer, pointing into the stack
253       fp = frame_sp + FKind::size(hf) - frame::sender_sp_offset;
254     } else {
255       fp = FKind::stub
256         ? frame_sp + fsize - frame::sender_sp_offset // on AArch64, this value is used for the safepoint stub
257         : *(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.
258     }
259     return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false); // TODO PERF : this computes deopt state; is it necessary?
260   }
261 }
262 
263 inline intptr_t* ThawBase::align(const frame& hf, intptr_t* frame_sp, frame& caller, bool bottom) {
264 #ifdef _LP64
265   if (((intptr_t)frame_sp & 0xf) != 0) {
266     assert(caller.is_interpreted_frame() || (bottom && hf.compiled_frame_stack_argsize() % 2 != 0), "");
267     frame_sp--;
268     caller.set_sp(caller.sp() - 1);
269   }
270   assert(is_aligned(frame_sp, frame::frame_alignment), "");
271 #endif
272 
273   return frame_sp;
274 }
275 
276 inline void ThawBase::patch_pd(frame& f, const frame& caller) {
277   patch_callee_link(caller, caller.fp());
278 }
279 














































































280 inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, const frame& f) {
281   // Make sure that last_sp is kept relativized.
282   assert((intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset) == f.unextended_sp(), "");
283 
284   // Make sure that monitor_block_top is still relativized.
285   assert(f.at_absolute(frame::interpreter_frame_monitor_block_top_offset) <= frame::interpreter_frame_initial_sp_offset, "");
286 
287   // Make sure that extended_sp is kept relativized.
288   assert((intptr_t*)f.at_relative(frame::interpreter_frame_extended_sp_offset) < f.unextended_sp(), "");


289 }
290 
291 #endif // CPU_AARCH64_CONTINUATIONFREEZETHAW_AARCH64_INLINE_HPP

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 }
131 
132 inline void FreezeBase::prepare_freeze_interpreted_top_frame(const frame& f) {
133   assert(*f.addr_at(frame::interpreter_frame_last_sp_offset) == 0, "should be null for top frame");
134   intptr_t* lspp = f.addr_at(frame::interpreter_frame_last_sp_offset);
135   *lspp = f.unextended_sp() - f.fp();
136 }
137 
138 inline void FreezeBase::relativize_interpreted_frame_metadata(const frame& f, const frame& hf) {
139   assert(hf.fp() == hf.unextended_sp() + (f.fp() - f.unextended_sp()), "");
140   assert((f.at(frame::interpreter_frame_last_sp_offset) != 0)
141     || (f.unextended_sp() == f.sp()), "");
142   assert(f.fp() > (intptr_t*)f.at_relative(frame::interpreter_frame_initial_sp_offset), "");
143 
144   // on AARCH64, we may insert padding between the locals and the rest of the frame
145   // (see TemplateInterpreterGenerator::generate_normal_entry, and AbstractInterpreter::layout_activation)
146   // because we freeze the padding word (see recurse_freeze_interpreted_frame) in order to keep the same relativized
147   // locals value, we don't need to change the locals value here.
148 
149   // Make sure that last_sp is already relativized.
150   assert((intptr_t*)hf.at_relative(frame::interpreter_frame_last_sp_offset) == hf.unextended_sp(), "");
151 
152   // Make sure that monitor_block_top is already relativized.
153   assert(hf.at_absolute(frame::interpreter_frame_monitor_block_top_offset) <= frame::interpreter_frame_initial_sp_offset, "");
154 
155   // extended_sp is already relativized by TemplateInterpreterGenerator::generate_normal_entry or
156   // AbstractInterpreter::layout_activation
157 
158   // The interpreter native wrapper code adds space in the stack equal to size_of_parameters()
159   // after the fixed part of the frame. For wait0 this is equal to 3 words (this + long parameter).
160   // We adjust by this size since otherwise the saved last sp will be less than the extended_sp.
161   DEBUG_ONLY(Method* m = hf.interpreter_frame_method();)
162   DEBUG_ONLY(int extra_space = m->is_object_wait0() ? m->size_of_parameters() : 0;)
163 
164   assert((hf.fp() - hf.unextended_sp()) == (f.fp() - f.unextended_sp()), "");
165   assert(hf.unextended_sp() == (intptr_t*)hf.at(frame::interpreter_frame_last_sp_offset), "");
166   assert(hf.unextended_sp() <= (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
167   assert(hf.unextended_sp() + extra_space >  (intptr_t*)hf.at(frame::interpreter_frame_extended_sp_offset), "");
168   assert(hf.fp()            >  (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), "");
169   assert(hf.fp()            <= (intptr_t*)hf.at(frame::interpreter_frame_locals_offset), "");
170 }
171 
172 inline void FreezeBase::set_top_frame_metadata_pd(const frame& hf) {
173   stackChunkOop chunk = _cont.tail();
174   assert(chunk->is_in_chunk(hf.sp() - 1), "");
175   assert(chunk->is_in_chunk(hf.sp() - frame::sender_sp_offset), "");
176 
177   *(hf.sp() - 1) = (intptr_t)hf.pc();
178 
179   intptr_t* fp_addr = hf.sp() - frame::sender_sp_offset;
180   *fp_addr = hf.is_interpreted_frame() ? (intptr_t)(hf.fp() - fp_addr)
181                                        : (intptr_t)hf.fp();
182 }
183 
184 inline void FreezeBase::patch_pd(frame& hf, const frame& caller) {
185   if (caller.is_interpreted_frame()) {
186     assert(!caller.is_empty(), "");
187     patch_callee_link_relative(caller, caller.fp());

208   // Fast path depends on !PreserveFramePointer. See can_thaw_fast().
209   assert(!PreserveFramePointer, "Frame pointers need to be fixed");
210 }
211 
212 // Slow path
213 
214 inline frame ThawBase::new_entry_frame() {
215   intptr_t* sp = _cont.entrySP();
216   return frame(sp, sp, _cont.entryFP(), _cont.entryPC()); // TODO PERF: This finds code blob and computes deopt state
217 }
218 
219 template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame& caller, bool bottom) {
220   assert(FKind::is_instance(hf), "");
221   // The values in the returned frame object will be written into the callee's stack in patch.
222 
223   if (FKind::interpreted) {
224     intptr_t* heap_sp = hf.unextended_sp();
225     // If caller is interpreted it already made room for the callee arguments
226     int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0;
227     const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap);

228     intptr_t* frame_sp = caller.unextended_sp() - fsize;
229     intptr_t* fp = frame_sp + (hf.fp() - heap_sp);
230     if ((intptr_t)fp % frame::frame_alignment != 0) {
231       fp--;
232       frame_sp--;
233       log_develop_trace(continuations)("Adding internal interpreted frame alignment");
234     }
235     DEBUG_ONLY(intptr_t* unextended_sp = fp + *hf.addr_at(frame::interpreter_frame_last_sp_offset);)
236     assert(frame_sp == unextended_sp, "");
237     caller.set_sp(fp + frame::sender_sp_offset);
238     frame f(frame_sp, frame_sp, fp, hf.pc());
239     // we need to set the locals so that the caller of new_stack_frame() can call
240     // ContinuationHelper::InterpretedFrame::frame_bottom
241     // copy relativized locals from the heap frame
242     *f.addr_at(frame::interpreter_frame_locals_offset) = *hf.addr_at(frame::interpreter_frame_locals_offset);
243     assert((intptr_t)f.fp() % frame::frame_alignment == 0, "");
244     return f;
245   } else {
246     int fsize = FKind::size(hf);
247     intptr_t* frame_sp = caller.unextended_sp() - fsize;
248     if (bottom || caller.is_interpreted_frame()) {
249       int argsize = FKind::stack_argsize(hf);
250 
251       fsize += argsize;
252       frame_sp   -= argsize;
253       caller.set_sp(caller.sp() - argsize);
254       assert(caller.sp() == frame_sp + (fsize-argsize), "");
255 
256       frame_sp = align(hf, frame_sp, caller, bottom);
257     }
258 
259     assert(hf.cb() != nullptr, "");
260     assert(hf.oop_map() != nullptr, "");
261     intptr_t* fp;
262     if (PreserveFramePointer) {
263       // we need to recreate a "real" frame pointer, pointing into the stack
264       fp = frame_sp + FKind::size(hf) - frame::sender_sp_offset;
265     } else {
266       fp = FKind::stub || FKind::native
267         ? frame_sp + fsize - frame::sender_sp_offset // fp always points to the address below the pushed return pc. We need correct address.
268         : *(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.
269     }
270     return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false); // TODO PERF : this computes deopt state; is it necessary?
271   }
272 }
273 
274 inline intptr_t* ThawBase::align(const frame& hf, intptr_t* frame_sp, frame& caller, bool bottom) {
275 #ifdef _LP64
276   if (((intptr_t)frame_sp & 0xf) != 0) {
277     assert(caller.is_interpreted_frame() || (bottom && hf.compiled_frame_stack_argsize() % 2 != 0), "");
278     frame_sp--;
279     caller.set_sp(caller.sp() - 1);
280   }
281   assert(is_aligned(frame_sp, frame::frame_alignment), "");
282 #endif
283 
284   return frame_sp;
285 }
286 
287 inline void ThawBase::patch_pd(frame& f, const frame& caller) {
288   patch_callee_link(caller, caller.fp());
289 }
290 
291 inline void ThawBase::patch_pd(frame& f, intptr_t* caller_sp) {
292   Unimplemented();
293 }
294 
295 inline void ThawBase::fix_native_return_pc_pd(frame& top) {
296   // Nothing to do since the last pc saved before making the call to
297   // JVM_MonitorWait() was already set to the correct resume pc. Just
298   // do some sanity check.
299 #ifdef ASSERT
300   Method* method = top.is_interpreted_frame() ? top.interpreter_frame_method() : CodeCache::find_blob(top.pc())->as_nmethod()->method();
301   assert(method->is_object_wait0(), "");
302 #endif
303 }
304 
305 inline intptr_t* ThawBase::push_resume_adapter(frame& top) {
306   intptr_t* sp = top.sp();
307   CodeBlob* cb = top.cb();
308 
309 #ifdef ASSERT
310   RegisterMap map(JavaThread::current(),
311                   RegisterMap::UpdateMap::skip,
312                   RegisterMap::ProcessFrames::skip,
313                   RegisterMap::WalkContinuation::skip);
314   frame caller = top.sender(&map);
315   intptr_t link_addr = (intptr_t)ContinuationHelper::Frame::callee_link_address(caller);
316   assert(sp[-2] == link_addr, "wrong link address: " INTPTR_FORMAT " != " INTPTR_FORMAT, sp[-2], link_addr);
317 #endif
318 
319   bool interpreted = top.is_interpreted_frame();
320   if (!interpreted && cb->frame_size() == 2) {
321     // C2 runtime stub case. For aarch64 the real size of the c2 runtime stub is 2 words bigger
322     // than what we think, i.e. size is 4. This is because the _last_Java_sp is not set to the
323     // sp right before making the call to the VM, but rather it is artificially set 2 words above
324     // this real sp so that we can store the return address at last_Java_sp[-1], and keep this
325     // property where we can retrieve the last_Java_pc from the last_Java_sp. But that means that
326     // once we return to the runtime stub, the code will adjust sp according to this real size.
327     // So we must adjust the frame size back here. We just copy lr/rfp again. These 2 top words
328     // will be the ones popped in generate_cont_preempt_rerun_compiler_adapter(). The other 2 words
329     // will just be discarded once back in the runtime stub (add sp, sp, #0x10).
330     sp -= 2;
331     sp[-2] = sp[0];
332     sp[-1] = sp[1];
333   }
334 
335   intptr_t* fp = sp - frame::sender_sp_offset;
336   address pc = interpreted ? Interpreter::cont_resume_interpreter_adapter()
337                            : StubRoutines::cont_resume_compiler_adapter();
338 
339   sp -= frame::metadata_words;
340   *(address*)(sp - frame::sender_sp_ret_address_offset()) = pc;
341   *(intptr_t**)(sp - frame::sender_sp_offset) = fp;
342 
343   log_develop_trace(continuations, preempt)("push_resume_%s_adapter() initial sp: " INTPTR_FORMAT " final sp: " INTPTR_FORMAT " fp: " INTPTR_FORMAT,
344     interpreted ? "interpreter" : "compiler", p2i(sp + frame::metadata_words), p2i(sp), p2i(fp));
345   return sp;
346 }
347 
348 inline intptr_t* ThawBase::push_resume_monitor_operation(stackChunkOop chunk) {
349   frame enterSpecial = new_entry_frame();
350   intptr_t* sp = enterSpecial.sp();
351 
352   // First push the return barrier frame
353   sp -= frame::metadata_words;
354   sp[1] = (intptr_t)StubRoutines::cont_returnBarrier();
355   sp[0] = (intptr_t)enterSpecial.fp();
356 
357   // Now push the ObjectWaiter*
358   sp -= frame::metadata_words;
359   sp[1] = (intptr_t)chunk->object_waiter(); // alignment
360   sp[0] = (intptr_t)chunk->object_waiter();
361 
362   // Finally arrange to return to the resume_monitor_operation stub
363   sp[-1] = (intptr_t)StubRoutines::cont_resume_monitor_operation();
364   sp[-2] = (intptr_t)enterSpecial.fp();
365   log_develop_trace(continuations, preempt)("push_resume_monitor_operation initial sp: " INTPTR_FORMAT " final sp: " INTPTR_FORMAT, p2i(sp + 2 * frame::metadata_words), p2i(sp));
366   return sp;
367 }
368 
369 inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, const frame& f) {
370   // Make sure that last_sp is kept relativized.
371   assert((intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset) == f.unextended_sp(), "");
372 
373   // Make sure that monitor_block_top is still relativized.
374   assert(f.at_absolute(frame::interpreter_frame_monitor_block_top_offset) <= frame::interpreter_frame_initial_sp_offset, "");
375 
376   // Make sure that extended_sp is kept relativized.
377   DEBUG_ONLY(Method* m = hf.interpreter_frame_method();)
378   DEBUG_ONLY(int extra_space = m->is_object_wait0() ? m->size_of_parameters() : 0;) // see comment in relativize_interpreted_frame_metadata()
379   assert((intptr_t*)f.at_relative(frame::interpreter_frame_extended_sp_offset) < f.unextended_sp() + extra_space, "");
380 }
381 
382 #endif // CPU_AARCH64_CONTINUATIONFREEZETHAW_AARCH64_INLINE_HPP
< prev index next >