1 /*
2 * Copyright (c) 1997, 2024, 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_HPP
27 #define CPU_AARCH64_FRAME_AARCH64_HPP
28
29 // A frame represents a physical stack frame (an activation). Frames can be
30 // C or Java frames, and the Java frames can be interpreted or compiled.
31 // In contrast, vframes represent source-level activations, so that one physical frame
32 // can correspond to multiple source level frames because of inlining.
33 // A frame is comprised of {pc, fp, sp}
34 // ------------------------------ Asm interpreter ----------------------------------------
35 // Layout of asm interpreter frame:
36 // [expression stack ] * <- sp
37
38 // [monitors[0] ] \
39 // ... | monitor block size = k
40 // [monitors[k-1] ] /
41 // [frame initial esp ] ( == &monitors[0], initially here) initial_sp_offset
42 // [byte code index/pointr] = bcx() bcx_offset
43
44 // [pointer to locals ] = locals() locals_offset
45 // [constant pool cache ] = cache() cache_offset
46
47 // [klass of method ] = mirror() mirror_offset
48 // [extended SP ] extended_sp offset
49
50 // [methodData ] = mdp() mdx_offset
51 // [Method ] = method() method_offset
52
53 // [last esp ] = last_sp() last_sp_offset
54 // [sender's SP ] (sender_sp) sender_sp_offset
55
56 // [old frame pointer ] <- fp = link()
57 // [return pc ]
58
59 // [last sp ]
60 // [oop temp ] (only for native calls)
61
62 // [padding ] (to preserve machine SP alignment)
63 // [locals and parameters ]
64 // <- sender sp
65 // ------------------------------ Asm interpreter ----------------------------------------
66
67 public:
68 enum {
69 pc_return_offset = 0,
70 // All frames
71 link_offset = 0,
72 return_addr_offset = 1,
73 sender_sp_offset = 2,
74
75 // Interpreter frames
76 interpreter_frame_oop_temp_offset = 3, // for native calls only
77
78 interpreter_frame_sender_sp_offset = -1,
79 // outgoing sp before a call to an invoked method
80 interpreter_frame_last_sp_offset = interpreter_frame_sender_sp_offset - 1,
81 interpreter_frame_method_offset = interpreter_frame_last_sp_offset - 1,
82 interpreter_frame_mdp_offset = interpreter_frame_method_offset - 1,
83 interpreter_frame_extended_sp_offset = interpreter_frame_mdp_offset - 1,
84 interpreter_frame_mirror_offset = interpreter_frame_extended_sp_offset - 1,
85 interpreter_frame_cache_offset = interpreter_frame_mirror_offset - 1,
86 interpreter_frame_locals_offset = interpreter_frame_cache_offset - 1,
87 interpreter_frame_bcp_offset = interpreter_frame_locals_offset - 1,
88 interpreter_frame_initial_sp_offset = interpreter_frame_bcp_offset - 1,
89
90 interpreter_frame_monitor_block_top_offset = interpreter_frame_initial_sp_offset,
91 interpreter_frame_monitor_block_bottom_offset = interpreter_frame_initial_sp_offset,
92
93 // Entry frames
94 // n.b. these values are determined by the layout defined in
95 // stubGenerator for the Java call stub
96 entry_frame_after_call_words = 29,
97 entry_frame_call_wrapper_offset = -8,
98
99 // we don't need a save area
100 arg_reg_save_area_bytes = 0,
101
102 // size, in words, of frame metadata (e.g. pc and link)
103 metadata_words = sender_sp_offset,
104 // size, in words, of metadata at frame bottom, i.e. it is not part of the
105 // caller/callee overlap
106 metadata_words_at_bottom = metadata_words,
107 // size, in words, of frame metadata at the frame top, i.e. it is located
108 // between a callee frame and its stack arguments, where it is part
109 // of the caller/callee overlap
110 metadata_words_at_top = 0,
111 // in bytes
112 frame_alignment = 16,
113 // size, in words, of maximum shift in frame position due to alignment
114 align_wiggle = 1
115 };
116
117 intptr_t ptr_at(int offset) const {
118 return *ptr_at_addr(offset);
119 }
120
121 void ptr_at_put(int offset, intptr_t value) {
122 *ptr_at_addr(offset) = value;
123 }
124
125 private:
126 // an additional field beyond _sp and _pc:
127 union {
128 intptr_t* _fp; // frame pointer
129 int _offset_fp; // relative frame pointer for use in stack-chunk frames
130 };
131 // The interpreter and adapters will extend the frame of the caller.
132 // Since oopMaps are based on the sp of the caller before extension
133 // we need to know that value. However in order to compute the address
134 // of the return address we need the real "raw" sp. Since sparc already
135 // uses sp() to mean "raw" sp and unextended_sp() to mean the caller's
136 // original sp we use that convention.
137
138 union {
139 intptr_t* _unextended_sp;
140 int _offset_unextended_sp; // for use in stack-chunk frames
141 };
142
143 void adjust_unextended_sp() NOT_DEBUG_RETURN;
144
145 // true means _sp value is correct and we can use it to get the sender's sp
146 // of the compiled frame, otherwise, _sp value may be invalid and we can use
147 // _fp to get the sender's sp if PreserveFramePointer is enabled.
148 bool _sp_is_trusted;
149
150 intptr_t* ptr_at_addr(int offset) const {
151 return (intptr_t*) addr_at(offset);
152 }
153
154 #ifdef ASSERT
155 // Used in frame::sender_for_{interpreter,compiled}_frame
156 static void verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp);
157 #endif
158
159 public:
160 // Constructors
161
162 frame(intptr_t* sp, intptr_t* fp, address pc);
163
164 frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc);
165
166 frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc, CodeBlob* cb, bool allow_cb_null = false);
167 // used for fast frame construction by continuations
168 frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc, CodeBlob* cb, const ImmutableOopMap* oop_map, bool on_heap);
169
170 frame(intptr_t* sp, intptr_t* fp);
171
172 void init(intptr_t* sp, intptr_t* fp, address pc);
173 void setup(address pc);
174
175 // accessors for the instance variables
176 // Note: not necessarily the real 'frame pointer' (see real_fp)
177 intptr_t* fp() const { assert_absolute(); return _fp; }
178 void set_fp(intptr_t* newfp) { _fp = newfp; }
179 int offset_fp() const { assert_offset(); return _offset_fp; }
180 void set_offset_fp(int value) { assert_on_heap(); _offset_fp = value; }
181
182 inline address* sender_pc_addr() const;
183 inline address sender_pc_maybe_signed() const;
184
185 // expression stack tos if we are nested in a java call
186 intptr_t* interpreter_frame_last_sp() const;
187
188 void interpreter_frame_set_extended_sp(intptr_t* sp);
189
190 template <typename RegisterMapT>
191 static void update_map_with_saved_link(RegisterMapT* map, intptr_t** link_addr);
192
193 // deoptimization support
194 void interpreter_frame_set_last_sp(intptr_t* sp);
195
196 static jint interpreter_frame_expression_stack_direction() { return -1; }
197
198 // returns the sending frame, without applying any barriers
199 inline frame sender_raw(RegisterMap* map) const;
200
201 void set_sp_is_trusted() { _sp_is_trusted = true; }
202
203 #endif // CPU_AARCH64_FRAME_AARCH64_HPP
--- EOF ---