1 /*
  2  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2016 SAP SE. 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_S390_FRAME_S390_INLINE_HPP
 27 #define CPU_S390_FRAME_S390_INLINE_HPP
 28 
 29 #include "code/codeCache.hpp"
 30 #include "code/vmreg.inline.hpp"
 31 #include "utilities/align.hpp"
 32 
 33 // Inline functions for z/Architecture frames:
 34 
 35 inline void frame::find_codeblob_and_set_pc_and_deopt_state(address pc) {
 36   assert(pc != NULL, "precondition: must have PC");
 37 
 38   _cb = CodeCache::find_blob(pc);
 39   _pc = pc;   // Must be set for get_deopt_original_pc().
 40 
 41   _fp = (intptr_t *) own_abi()->callers_sp;
 42 
 43   address original_pc = CompiledMethod::get_deopt_original_pc(this);
 44   if (original_pc != NULL) {
 45     _pc = original_pc;
 46     _deopt_state = is_deoptimized;
 47   } else {
 48     _deopt_state = not_deoptimized;
 49   }
 50 
 51   assert(((uint64_t)_sp & 0x7) == 0, "SP must be 8-byte aligned");
 52 }
 53 
 54 // Constructors
 55 
 56 // Initialize all fields, _unextended_sp will be adjusted in find_codeblob_and_set_pc_and_deopt_state.
 57 inline frame::frame() : _sp(NULL), _pc(NULL), _cb(NULL), _deopt_state(unknown), _unextended_sp(NULL), _fp(NULL) {}
 58 
 59 inline frame::frame(intptr_t* sp) : _sp(sp), _unextended_sp(sp) {
 60   find_codeblob_and_set_pc_and_deopt_state((address)own_abi()->return_pc);
 61 }
 62 
 63 inline frame::frame(intptr_t* sp, address pc) : _sp(sp), _unextended_sp(sp) {
 64   find_codeblob_and_set_pc_and_deopt_state(pc); // Also sets _fp and adjusts _unextended_sp.
 65 }
 66 
 67 inline frame::frame(intptr_t* sp, address pc, intptr_t* unextended_sp) : _sp(sp), _unextended_sp(unextended_sp) {
 68   find_codeblob_and_set_pc_and_deopt_state(pc); // Also sets _fp and adjusts _unextended_sp.
 69 }
 70 
 71 // Generic constructor. Used by pns() in debug.cpp only
 72 #ifndef PRODUCT
 73 inline frame::frame(void* sp, void* pc, void* unextended_sp) :
 74   _sp((intptr_t*)sp), _pc(NULL), _cb(NULL), _unextended_sp((intptr_t*)unextended_sp) {
 75   find_codeblob_and_set_pc_and_deopt_state((address)pc); // Also sets _fp and adjusts _unextended_sp.
 76 }
 77 #endif
 78 
 79 // template interpreter state
 80 inline frame::z_ijava_state* frame::ijava_state_unchecked() const {
 81   z_ijava_state* state = (z_ijava_state*) ((uintptr_t)fp() - z_ijava_state_size);
 82   return state;
 83 }
 84 
 85 inline frame::z_ijava_state* frame::ijava_state() const {
 86   z_ijava_state* state = ijava_state_unchecked();
 87   assert(state->magic == (intptr_t) frame::z_istate_magic_number,
 88          "wrong z_ijava_state in interpreter frame (no magic found)");
 89   return state;
 90 }
 91 
 92 inline BasicObjectLock** frame::interpreter_frame_monitors_addr() const {
 93   return (BasicObjectLock**) &(ijava_state()->monitors);
 94 }
 95 
 96 // The next two funcions read and write z_ijava_state.monitors.
 97 inline BasicObjectLock* frame::interpreter_frame_monitors() const {
 98   return *interpreter_frame_monitors_addr();
 99 }
100 inline void frame::interpreter_frame_set_monitors(BasicObjectLock* monitors) {
101   *interpreter_frame_monitors_addr() = monitors;
102 }
103 
104 // Accessors
105 
106 // Return unique id for this frame. The id must have a value where we
107 // can distinguish identity and younger/older relationship. NULL
108 // represents an invalid (incomparable) frame.
109 inline intptr_t* frame::id(void) const {
110   // Use _fp. _sp or _unextended_sp wouldn't be correct due to resizing.
111   return _fp;
112 }
113 
114 // Return true if this frame is older (less recent activation) than
115 // the frame represented by id.
116 inline bool frame::is_older(intptr_t* id) const {
117   assert(this->id() != NULL && id != NULL, "NULL frame id");
118   // Stack grows towards smaller addresses on z/Architecture.
119   return this->id() > id;
120 }
121 
122 inline int frame::frame_size() const {
123   // Stack grows towards smaller addresses on z/Linux: sender is at a higher address.
124   return sender_sp() - sp();
125 }
126 
127 // Ignore c2i adapter frames.
128 inline intptr_t* frame::unextended_sp() const {
129   return _unextended_sp;
130 }
131 
132 inline address frame::sender_pc() const {
133   return (address) callers_abi()->return_pc;
134 }
135 
136 // Get caller pc, if caller is native from stack slot of gpr14.
137 inline address frame::native_sender_pc() const {
138   return (address) callers_abi()->gpr14;
139 }
140 
141 // Get caller pc from stack slot of gpr10.
142 inline address frame::callstub_sender_pc() const {
143   return (address) callers_abi()->gpr10;
144 }
145 
146 inline address* frame::sender_pc_addr() const {
147   return (address*) &(callers_abi()->return_pc);
148 }
149 
150 inline intptr_t* frame::sender_sp() const {
151   return (intptr_t*) callers_abi();
152 }
153 
154 inline intptr_t* frame::link() const {
155   return (intptr_t*) callers_abi()->callers_sp;
156 }
157 
158 inline intptr_t** frame::interpreter_frame_locals_addr() const {
159   return (intptr_t**) &(ijava_state()->locals);
160 }
161 
162 inline intptr_t* frame::interpreter_frame_bcp_addr() const {
163   return (intptr_t*) &(ijava_state()->bcp);
164 }
165 
166 inline intptr_t* frame::interpreter_frame_mdp_addr() const {
167   return (intptr_t*) &(ijava_state()->mdx);
168 }
169 
170 // Bottom(base) of the expression stack (highest address).
171 template <bool relative>
172 inline intptr_t* frame::interpreter_frame_expression_stack() const {
173   return (intptr_t*)interpreter_frame_monitor_end() - 1;
174 }
175 





176 // monitor elements
177 
178 // End is lower in memory than begin, and beginning element is oldest element.
179 // Also begin is one past last monitor.
180 
181 inline intptr_t* frame::interpreter_frame_top_frame_sp() {
182   return (intptr_t*)ijava_state()->top_frame_sp;
183 }
184 
185 inline void frame::interpreter_frame_set_top_frame_sp(intptr_t* top_frame_sp) {
186   ijava_state()->top_frame_sp = (intptr_t) top_frame_sp;
187 }
188 
189 inline void frame::interpreter_frame_set_sender_sp(intptr_t* sender_sp) {
190   ijava_state()->sender_sp = (intptr_t) sender_sp;
191 }
192 
193 #ifdef ASSERT
194 inline void frame::interpreter_frame_set_magic() {
195   ijava_state()->magic = (intptr_t) frame::z_istate_magic_number;
196 }
197 #endif
198 
199 // Where z_ijava_state.esp is saved.
200 inline intptr_t** frame::interpreter_frame_esp_addr() const {
201   return (intptr_t**) &(ijava_state()->esp);
202 }
203 
204 // top of expression stack (lowest address)
205 template <bool relative>
206 inline intptr_t* frame::interpreter_frame_tos_address() const {
207   return *interpreter_frame_esp_addr() + 1;
208 }
209 
210 inline void frame::interpreter_frame_set_tos_address(intptr_t* x) {
211   *interpreter_frame_esp_addr() = x - 1;
212 }
213 
214 // Stack slot needed for native calls and GC.
215 inline oop * frame::interpreter_frame_temp_oop_addr() const {
216   return (oop *) ((address) _fp + _z_ijava_state_neg(oop_tmp));
217 }
218 
219 // In keeping with Intel side: end is lower in memory than begin.
220 // Beginning element is oldest element. Also begin is one past last monitor.
221 inline BasicObjectLock * frame::interpreter_frame_monitor_begin() const {
222   return (BasicObjectLock*)ijava_state();
223 }
224 




225 inline void frame::interpreter_frame_set_monitor_end(BasicObjectLock* monitors) {
226   interpreter_frame_set_monitors((BasicObjectLock *)monitors);
227 }
228 
229 inline int frame::interpreter_frame_monitor_size() {
230   // Number of stack slots for a monitor
231   return align_up(BasicObjectLock::size() /* number of stack slots */,
232                   WordsPerLong /* Number of stack slots for a Java long. */);
233 }
234 
235 inline int frame::interpreter_frame_monitor_size_in_bytes() {
236   // Number of bytes for a monitor.
237   return frame::interpreter_frame_monitor_size() * wordSize;
238 }
239 
240 inline int frame::interpreter_frame_interpreterstate_size_in_bytes() {
241   return z_ijava_state_size;
242 }
243 
244 inline Method** frame::interpreter_frame_method_addr() const {
245   return (Method**)&(ijava_state()->method);
246 }
247 
248 inline oop* frame::interpreter_frame_mirror_addr() const {
249   return (oop*)&(ijava_state()->mirror);
250 }
251 
252 // Constant pool cache
253 
254 inline ConstantPoolCache** frame::interpreter_frame_cache_addr() const {
255   return (ConstantPoolCache**)&(ijava_state()->cpoolCache);
256 }
257 
258 // entry frames
259 
260 inline intptr_t* frame::entry_frame_argument_at(int offset) const {
261   // Since an entry frame always calls the interpreter first,
262   // the parameters are on the stack and relative to known register in the
263   // entry frame.
264   intptr_t* tos = (intptr_t*) entry_frame_locals()->arguments_tos_address;
265   return &tos[offset + 1]; // prepushed tos
266 }
267 
268 inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const {
269   return (JavaCallWrapper**) &entry_frame_locals()->call_wrapper_address;
270 }
271 
272 inline oop frame::saved_oop_result(RegisterMap* map) const {
273   return *((oop*) map->location(Z_R2->as_VMReg(), (intptr_t*) NULL));  // R2 is return register.
274 }
275 
276 inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) {
277   *((oop*) map->location(Z_R2->as_VMReg(), (intptr_t*) NULL)) = obj;  // R2 is return register.
278 }
279 
280 inline intptr_t* frame::real_fp() const {
281   return fp();
282 }
283 
284 inline const ImmutableOopMap* frame::get_oop_map() const {
285   Unimplemented();
286   return NULL;
287 }
288 
289 inline int frame::compiled_frame_stack_argsize() const {
290   Unimplemented();
291   return 0;
292 }
293 
294 inline void frame::interpreted_frame_oop_map(InterpreterOopMap* mask) const {
295   Unimplemented();
296 }
297 
298 inline int frame::interpreted_frame_num_oops(InterpreterOopMap* mask) const {
299   Unimplemented();
300   return 0;
301 }
302 
303 template <bool relative>
304 inline intptr_t* frame::interpreter_frame_last_sp() const {
305   Unimplemented();
306   return NULL;
307 }
308 
309 inline int frame::sender_sp_ret_address_offset() {
310   Unimplemented();
311   return 0;
312 }
313 
314 template <typename RegisterMapT>
315 void frame::update_map_with_saved_link(RegisterMapT* map, intptr_t** link_addr) {
316   Unimplemented();
317 }
318 
319 inline void frame::set_unextended_sp(intptr_t* value) {
320   Unimplemented();
321 }
322 
323 inline int frame::offset_unextended_sp() const {
324   Unimplemented();
325   return 0;
326 }
327 
328 inline void frame::set_offset_unextended_sp(int value) {
329   Unimplemented();
330 }
331 
332 #endif // CPU_S390_FRAME_S390_INLINE_HPP
--- EOF ---