1 /*
  2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef CPU_AARCH64_FRAME_AARCH64_INLINE_HPP
 27 #define CPU_AARCH64_FRAME_AARCH64_INLINE_HPP
 28 
 29 #include "code/codeCache.hpp"
 30 #include "code/vmreg.inline.hpp"



 31 #include "pauth_aarch64.hpp"
 32 
 33 // Inline functions for AArch64 frames:
 34 
 35 // Constructors:
 36 
 37 inline frame::frame() {
 38   _pc = NULL;
 39   _sp = NULL;
 40   _unextended_sp = NULL;
 41   _fp = NULL;
 42   _cb = NULL;
 43   _deopt_state = unknown;
 44 }
 45 
 46 static int spin;
 47 
 48 inline void frame::init(intptr_t* sp, intptr_t* fp, address pc) {
 49   assert(pauth_ptr_is_raw(pc), "cannot be signed");
 50   intptr_t a = intptr_t(sp);
 51   intptr_t b = intptr_t(fp);
 52   _sp = sp;
 53   _unextended_sp = sp;
 54   _fp = fp;
 55   _pc = pc;
 56   assert(pc != NULL, "no pc?");
 57   _cb = CodeCache::find_blob(pc);







 58   adjust_unextended_sp();
 59 
 60   address original_pc = CompiledMethod::get_deopt_original_pc(this);
 61   if (original_pc != NULL) {
 62     _pc = original_pc;
 63     _deopt_state = is_deoptimized;


 64   } else {
 65     _deopt_state = not_deoptimized;




 66   }
 67 }
 68 
 69 inline frame::frame(intptr_t* sp, intptr_t* fp, address pc) {
 70   init(sp, fp, pc);
 71 }
 72 
 73 inline frame::frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc) {
 74   assert(pauth_ptr_is_raw(pc), "cannot be signed");
 75   intptr_t a = intptr_t(sp);
 76   intptr_t b = intptr_t(fp);
 77   _sp = sp;
 78   _unextended_sp = unextended_sp;
 79   _fp = fp;
 80   _pc = pc;
 81   assert(pc != NULL, "no pc?");
 82   _cb = CodeCache::find_blob(pc);
 83   adjust_unextended_sp();

 84 
 85   address original_pc = CompiledMethod::get_deopt_original_pc(this);
 86   if (original_pc != NULL) {
 87     _pc = original_pc;
 88     assert(_cb->as_compiled_method()->insts_contains_inclusive(_pc),
 89            "original PC must be in the main code section of the the compiled method (or must be immediately following it)");
 90     _deopt_state = is_deoptimized;
 91   } else {
 92     _deopt_state = not_deoptimized;






















 93   }

 94 }
 95 
















 96 inline frame::frame(intptr_t* sp, intptr_t* fp) {
 97   intptr_t a = intptr_t(sp);
 98   intptr_t b = intptr_t(fp);
 99   _sp = sp;
100   _unextended_sp = sp;
101   _fp = fp;
102   _pc = (address)(sp[-1]);
103 
104   // Here's a sticky one. This constructor can be called via AsyncGetCallTrace
105   // when last_Java_sp is non-null but the pc fetched is junk. If we are truly
106   // unlucky the junk value could be to a zombied method and we'll die on the
107   // find_blob call. This is also why we can have no asserts on the validity
108   // of the pc we find here. AsyncGetCallTrace -> pd_get_top_frame_for_signal_handler
109   // -> pd_last_frame should use a specialized version of pd_last_frame which could
110   // call a specilaized frame constructor instead of this one.
111   // Then we could use the assert below. However this assert is of somewhat dubious
112   // value.
113   // assert(_pc != NULL, "no pc?");
114 
115   _cb = CodeCache::find_blob(_pc);
116   adjust_unextended_sp();
117 
118   address original_pc = CompiledMethod::get_deopt_original_pc(this);
119   if (original_pc != NULL) {
120     _pc = original_pc;
121     _deopt_state = is_deoptimized;
122   } else {
123     _deopt_state = not_deoptimized;
124   }
125 }
126 
127 // Accessors
128 
129 inline bool frame::equal(frame other) const {
130   bool ret =  sp() == other.sp()
131               && unextended_sp() == other.unextended_sp()
132               && fp() == other.fp()
133               && pc() == other.pc();
134   assert(!ret || ret && cb() == other.cb() && _deopt_state == other._deopt_state, "inconsistent construction");
135   return ret;
136 }
137 
138 // Return unique id for this frame. The id must have a value where we can distinguish
139 // identity and younger/older relationship. NULL represents an invalid (incomparable)
140 // frame.
141 inline intptr_t* frame::id(void) const { return unextended_sp(); }
142 
143 // Return true if the frame is older (less recent activation) than the frame represented by id
144 inline bool frame::is_older(intptr_t* id) const   { assert(this->id() != NULL && id != NULL, "NULL frame id");
145                                                     return this->id() > id ; }
146 
147 
148 
149 inline intptr_t* frame::link() const              { return (intptr_t*) *(intptr_t **)addr_at(link_offset); }
150 
151 
152 inline intptr_t* frame::unextended_sp() const     { return _unextended_sp; }
153 













































































154 // Return address:
155 
156 inline address* frame::sender_pc_addr()         const { return (address*) addr_at( return_addr_offset); }
157 inline address  frame::sender_pc_maybe_signed() const { return *sender_pc_addr(); }
158 inline address  frame::sender_pc()              const { return pauth_strip_pointer(sender_pc_maybe_signed()); }
159 
160 inline intptr_t*    frame::sender_sp()        const { return            addr_at(   sender_sp_offset); }
161 
162 inline intptr_t** frame::interpreter_frame_locals_addr() const {
163   return (intptr_t**)addr_at(interpreter_frame_locals_offset);
164 }
165 

166 inline intptr_t* frame::interpreter_frame_last_sp() const {
167   return *(intptr_t**)addr_at(interpreter_frame_last_sp_offset);
168 }
169 
170 inline intptr_t* frame::interpreter_frame_bcp_addr() const {
171   return (intptr_t*)addr_at(interpreter_frame_bcp_offset);
172 }
173 
174 inline intptr_t* frame::interpreter_frame_mdp_addr() const {
175   return (intptr_t*)addr_at(interpreter_frame_mdp_offset);
176 }
177 
178 
179 // Constant pool cache
180 
181 inline ConstantPoolCache** frame::interpreter_frame_cache_addr() const {
182   return (ConstantPoolCache**)addr_at(interpreter_frame_cache_offset);
183 }
184 
185 // Method
186 
187 inline Method** frame::interpreter_frame_method_addr() const {
188   return (Method**)addr_at(interpreter_frame_method_offset);
189 }
190 
191 // Mirror
192 
193 inline oop* frame::interpreter_frame_mirror_addr() const {
194   return (oop*)addr_at(interpreter_frame_mirror_offset);
195 }
196 
197 // top of expression stack

198 inline intptr_t* frame::interpreter_frame_tos_address() const {
199   intptr_t* last_sp = interpreter_frame_last_sp();
200   if (last_sp == NULL) {
201     return sp();
202   } else {
203     // sp() may have been extended or shrunk by an adapter.  At least
204     // check that we don't fall behind the legal region.
205     // For top deoptimized frame last_sp == interpreter_frame_monitor_end.
206     assert(last_sp <= (intptr_t*) interpreter_frame_monitor_end(), "bad tos");
207     return last_sp;
208   }
209 }
210 
211 inline oop* frame::interpreter_frame_temp_oop_addr() const {
212   return (oop *)(fp() + interpreter_frame_oop_temp_offset);
213 }
214 
215 inline int frame::interpreter_frame_monitor_size() {
216   return BasicObjectLock::size();
217 }
218 
219 
220 // expression stack
221 // (the max_stack arguments are used by the GC; see class FrameClosure)
222 

223 inline intptr_t* frame::interpreter_frame_expression_stack() const {
224   intptr_t* monitor_end = (intptr_t*) interpreter_frame_monitor_end();
225   return monitor_end-1;
226 }
227 
228 
229 // Entry frames
230 
231 inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const {
232  return (JavaCallWrapper**)addr_at(entry_frame_call_wrapper_offset);
233 }
234 
235 
236 // Compiled frames
237 
238 inline oop frame::saved_oop_result(RegisterMap* map) const {
239   PRAGMA_DIAG_PUSH
240   PRAGMA_NONNULL_IGNORED
241   oop* result_adr = (oop *)map->location(r0->as_VMReg());
242   PRAGMA_DIAG_POP
243   guarantee(result_adr != NULL, "bad register save location");

244 
245   return (*result_adr);



246 }
247 
248 inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) {
249   PRAGMA_DIAG_PUSH
250   PRAGMA_NONNULL_IGNORED
251   oop* result_adr = (oop *)map->location(r0->as_VMReg());
252   PRAGMA_DIAG_POP
253   guarantee(result_adr != NULL, "bad register save location");
254 
255   *result_adr = obj;
256 }
257 


































































































258 #endif // CPU_AARCH64_FRAME_AARCH64_INLINE_HPP
--- EOF ---