1 /*
2 * Copyright (c) 2002, 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2012, 2026 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_PPC_INTERP_MASM_PPC_HPP
27 #define CPU_PPC_INTERP_MASM_PPC_HPP
28
29 #include "asm/macroAssembler.hpp"
30 #include "interpreter/invocationCounter.hpp"
31
32 // This file specializes the assembler with interpreter-specific macros.
33
34
35 class InterpreterMacroAssembler: public MacroAssembler {
36
37 public:
38 InterpreterMacroAssembler(CodeBuffer* code) : MacroAssembler(code) {}
39
40 void null_check_throw(Register a, int offset, Register temp_reg);
41 void load_klass_check_null_throw(Register dst, Register src, Register temp_reg);
42
43 void jump_to_entry(address entry, Register Rscratch);
44
45 // Handy address generation macros.
46 #define thread_(field_name) in_bytes(JavaThread::field_name ## _offset()), R16_thread
47 #define method_(field_name) in_bytes(Method::field_name ## _offset()), R19_method
48
49 virtual void check_and_handle_popframe(Register scratch_reg);
50 virtual void check_and_handle_earlyret(Register scratch_reg);
51
52 // Use for vthread preemption
53 void call_VM_preemptable(Register oop_result, address entry_point, Register arg_1, bool check_exceptions = true);
54 void call_VM_preemptable(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true);
55 void restore_after_resume(Register fp);
56 // R22 and R31 are preserved when a vthread gets preempted in the interpreter.
57 // The interpreter already assumes that these registers are nonvolatile across native calls.
58 bool nonvolatile_accross_vthread_preemtion(Register r) const {
59 return r->is_nonvolatile() && ((r == R24) || (r == R31));
60 }
61
62 // Base routine for all dispatches.
63 void dispatch_base(TosState state, address* table);
64
65 void load_earlyret_value(TosState state, Register Rscratch1);
66
67 static const Address l_tmp;
68 static const Address d_tmp;
69
70 // dispatch routines
71 void dispatch_next(TosState state, int step = 0, bool generate_poll = false);
72 void dispatch_via (TosState state, address* table);
73 void load_dispatch_table(Register dst, address* table);
74 void dispatch_Lbyte_code(TosState state, Register bytecode, address* table, bool generate_poll = false);
75
76 // Called by shared interpreter generator.
77 void dispatch_prolog(TosState state, int step = 0);
78 void dispatch_epilog(TosState state, int step = 0);
79
80 // Super call_VM calls - correspond to MacroAssembler::call_VM(_leaf) calls.
81 void super_call_VM_leaf(Register thread_cache, address entry_point, Register arg_1);
82 void super_call_VM(Register thread_cache, Register oop_result, Register last_java_sp,
83 address entry_point, Register arg_1, Register arg_2, bool check_exception = true);
84
85 // Generate a subtype check: branch to ok_is_subtype if sub_klass is
86 // a subtype of super_klass. Blows registers tmp1, tmp2 and tmp3.
87 void gen_subtype_check(Register sub_klass, Register super_klass,
88 Register tmp1, Register tmp2, Register tmp3, Label &ok_is_subtype, bool profile = true);
89
90 // Load object from cpool->resolved_references(index).
91 void load_resolved_reference_at_index(Register result, Register index, Register tmp1, Register tmp2,
92 Label *L_handle_null = nullptr);
93
94 // load cpool->resolved_klass_at(index)
95 void load_resolved_klass_at_offset(Register Rcpool, Register Roffset, Register Rklass);
96
97 void load_receiver(Register Rparam_count, Register Rrecv_dst);
98
99 // helpers for expression stack
100 void pop_i( Register r = R17_tos);
101 void pop_ptr( Register r = R17_tos);
102 void pop_l( Register r = R17_tos);
103 void pop_f(FloatRegister f = F15_ftos);
104 void pop_d(FloatRegister f = F15_ftos );
105
106 void push_i( Register r = R17_tos);
107 void push_ptr( Register r = R17_tos);
108 void push_l( Register r = R17_tos);
109 void push_f(FloatRegister f = F15_ftos );
110 void push_d(FloatRegister f = F15_ftos);
111
112 void push_2ptrs(Register first, Register second);
113
114 void move_l_to_d(Register l = R17_tos, FloatRegister d = F15_ftos);
115 void move_d_to_l(FloatRegister d = F15_ftos, Register l = R17_tos);
116
117 void pop (TosState state); // transition vtos -> state
118 void push(TosState state); // transition state -> vtos
119 void empty_expression_stack(); // Resets both Lesp and SP.
120
121 public:
122 // Load values from bytecode stream:
123
124 enum signedOrNot { Signed, Unsigned };
125 enum setCCOrNot { set_CC, dont_set_CC };
126
127 void get_2_byte_integer_at_bcp(int bcp_offset,
128 Register Rdst,
129 signedOrNot is_signed);
130
131 void get_4_byte_integer_at_bcp(int bcp_offset,
132 Register Rdst,
133 signedOrNot is_signed = Unsigned);
134
135 void get_cache_index_at_bcp(Register Rdst, int bcp_offset, size_t index_size);
136
137 void load_resolved_indy_entry(Register cache, Register index);
138 void load_field_or_method_entry(bool is_method, Register cache, Register index, int bcp_offset, bool for_fast_bytecode);
139 void load_field_entry(Register cache, Register index, int bcp_offset = 1, bool for_fast_bytecode = false) {
140 load_field_or_method_entry(false, cache, index, bcp_offset, for_fast_bytecode);
141 }
142 void load_method_entry(Register cache, Register index, int bcp_offset = 1, bool for_fast_bytecode = false) {
143 load_field_or_method_entry(true, cache, index, bcp_offset, for_fast_bytecode);
144 }
145
146 void get_u4(Register Rdst, Register Rsrc, int offset, signedOrNot is_signed);
147
148 // common code
149
150 void field_offset_at(int n, Register tmp, Register dest, Register base);
151 int field_offset_at(Register object, address bcp, int offset);
152 void fast_iaaccess(int n, address bcp);
153 void fast_iaputfield(address bcp, bool do_store_check);
154
155 void index_check(Register array, Register index, int index_shift, Register tmp, Register res);
156 void index_check_without_pop(Register array, Register index, int index_shift, Register tmp, Register res);
157
158 void get_const(Register Rdst);
159 void get_constant_pool(Register Rdst);
160 void get_constant_pool_cache(Register Rdst);
161 void get_cpool_and_tags(Register Rcpool, Register Rtags);
162 void is_a(Label& L);
163
164 void narrow(Register result);
165
166 // Java Call Helpers
167 void call_from_interpreter(Register Rtarget_method, Register Rret_addr, Register Rscratch1, Register Rscratch2);
168
169 // --------------------------------------------------
170
171 void unlock_if_synchronized_method(TosState state, bool throw_monitor_exception = true,
172 bool install_monitor_exception = true);
173
174 // Removes the current activation (incl. unlocking of monitors).
175 // Additionally this code is used for earlyReturn in which case we
176 // want to skip throwing an exception and installing an exception.
177 void remove_activation(TosState state,
178 bool throw_monitor_exception = true,
179 bool install_monitor_exception = true);
180 JFR_ONLY(void enter_jfr_critical_section();)
181 JFR_ONLY(void leave_jfr_critical_section();)
182 void load_fp(Register fp);
183 void remove_top_frame_given_fp(Register fp, Register sender_sp, Register sender_fp, Register return_pc, Register temp);
184 void merge_frames(Register sender_sp, Register return_pc, Register temp1, Register temp2); // merge top frames
185
186 void add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2);
187
188 // Local variable access helpers
189 void load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex);
190 void load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex);
191 void load_local_ptr(Register Rdst_value, Register Rdst_address, Register Rindex);
192 void load_local_float(FloatRegister Rdst_value, Register Rdst_address, Register Rindex);
193 void load_local_double(FloatRegister Rdst_value, Register Rdst_address, Register Rindex);
194 void store_local_int(Register Rvalue, Register Rindex);
195 void store_local_long(Register Rvalue, Register Rindex);
196 void store_local_ptr(Register Rvalue, Register Rindex);
197 void store_local_float(FloatRegister Rvalue, Register Rindex);
198 void store_local_double(FloatRegister Rvalue, Register Rindex);
199
200 // Call VM for std frames
201 // Special call VM versions that check for exceptions and forward exception
202 // via short cut (not via expensive forward exception stub).
203 void check_and_forward_exception(Register Rscratch1, Register Rscratch2);
204 void call_VM(Register oop_result, address entry_point, bool check_exceptions = true, Label* last_java_pc = nullptr);
205 void call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions = true);
206 void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true);
207 void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true);
208 // Should not be used:
209 void call_VM(Register oop_result, Register last_java_sp, address entry_point, bool check_exceptions = true) {ShouldNotReachHere();}
210 void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions = true) {ShouldNotReachHere();}
211 void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true) {ShouldNotReachHere();}
212 void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true) {ShouldNotReachHere();}
213
214 Address first_local_in_stack();
215
216 enum LoadOrStore { load, store };
217 void static_iload_or_store(int which_local, LoadOrStore direction, Register Rtmp);
218 void static_aload_or_store(int which_local, LoadOrStore direction, Register Rtmp);
219 void static_dload_or_store(int which_local, LoadOrStore direction);
220
221 void save_interpreter_state(Register scratch);
222 void restore_interpreter_state(Register scratch, bool bcp_and_mdx_only = false, bool restore_top_frame_sp = false);
223
224 void increment_backedge_counter(const Register Rcounters, Register Rtmp, Register Rtmp2, Register Rscratch);
225
226 void record_static_call_in_profile(Register Rentry, Register Rtmp);
227 void record_receiver_call_in_profile(Register Rklass, Register Rentry, Register Rtmp);
228
229 void get_method_counters(Register method, Register Rcounters, Label& skip);
230 void increment_invocation_counter(Register iv_be_count, Register Rtmp1, Register Rtmp2_r0);
231
232 // Object locking
233 void lock_object (Register lock_reg, Register obj_reg);
234 void unlock_object(Register lock_reg);
235
236 // Interpreter profiling operations
237 void set_method_data_pointer_for_bcp();
238 void test_method_data_pointer(Label& zero_continue);
239 void verify_method_data_pointer();
240
241 void set_mdp_data_at(int constant, Register value);
242
243 void increment_mdp_data_at(int constant, Register counter_addr, Register Rbumped_count, bool decrement = false);
244
245 void increment_mdp_data_at(Register counter_addr, Register Rbumped_count, bool decrement = false);
246 void increment_mdp_data_at(Register reg, int constant, Register scratch, Register Rbumped_count, bool decrement = false);
247
248 void set_mdp_flag_at(int flag_constant, Register scratch);
249 void test_mdp_data_at(int offset, Register value, Label& not_equal_continue, Register test_out);
250
251 void update_mdp_by_offset(int offset_of_disp, Register scratch);
252 void update_mdp_by_offset(Register reg, int offset_of_disp,
253 Register scratch);
254 void update_mdp_by_constant(int constant);
255 void update_mdp_for_ret(TosState state, Register return_bci);
256
257 void profile_taken_branch(Register scratch, Register bumped_count);
258 void profile_not_taken_branch(Register scratch1, Register scratch2, bool acmp = false);
259 void profile_call(Register scratch1, Register scratch2);
260 void profile_final_call(Register scratch1, Register scratch2);
261 void profile_virtual_call(Register Rreceiver, Register Rscratch1, Register Rscratch2);
262 void profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2);
263 void profile_ret(TosState state, Register return_bci, Register scratch1, Register scratch2);
264 void profile_switch_default(Register scratch1, Register scratch2);
265 void profile_switch_case(Register index, Register scratch1,Register scratch2, Register scratch3);
266 void profile_null_seen(Register Rscratch1, Register Rscratch2);
267
268 template <class ArrayData> void profile_array_type(Register array, Register tmp1, Register tmp2);
269
270 void profile_multiple_element_types(Register element, Register tmp1, Register tmp2, Register tmp3);
271 void profile_element_type(Register element, Register tmp1, Register tmp2);
272 void profile_acmp(Register left, Register right, Register tmp1, Register tmp2);
273
274 // Argument and return type profiling.
275 void profile_obj_type(Register obj, Register mdo_addr_base, RegisterOrConstant mdo_addr_offs, Register tmp, Register tmp2);
276 void profile_arguments_type(Register callee, Register tmp1, Register tmp2, bool is_virtual);
277 void profile_return_type(Register ret, Register tmp1, Register tmp2);
278 void profile_parameters_type(Register tmp1, Register tmp2, Register tmp3, Register tmp4);
279
280 // Debugging
281 void verify_oop(Register reg, TosState state = atos); // only if +VerifyOops && state == atos
282 void verify_oop_or_return_address(Register reg, Register rtmp); // for astore
283
284 typedef enum { NotifyJVMTI, SkipNotifyJVMTI } NotifyMethodExitMode;
285
286 // Support for jvmdi/jvmpi.
287 void notify_method_entry();
288 void notify_method_exit(bool is_native_method, TosState state,
289 NotifyMethodExitMode mode, bool check_exceptions);
290
291 // Allocate instance in "obj" and read in the content of the inline field
292 // NOTES:
293 // - input holder object via "obj", which must be r0,
294 // will return new instance via the same reg
295 void read_flat_field(Register entry, Register obj);
296 void write_flat_field(Register entry, Register tmp1, Register tmp2, Register obj, Register field_offset, Register value);
297 };
298
299 #endif // CPU_PPC_INTERP_MASM_PPC_HPP