2
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
25
#include "precompiled.hpp"
26
#include "asm/assembler.inline.hpp"
27
#include "asm/macroAssembler.hpp"
28
#include "code/codeBlob.hpp"
29
#include "memory/resourceArea.hpp"
30
#include "prims/jniFastGetField.hpp"
31
#include "prims/jvm_misc.hpp"
32
#include "prims/jvmtiExport.hpp"
33
#include "runtime/jniHandles.hpp"
34
#include "runtime/safepoint.hpp"
38
#define BUFFER_SIZE 120
40
address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
41
const char* name = nullptr;
42
address slow_case_addr = nullptr;
45
name = "jni_fast_GetBooleanField";
46
slow_case_addr = jni_GetBooleanField_addr();
49
name = "jni_fast_GetByteField";
50
slow_case_addr = jni_GetByteField_addr();
53
name = "jni_fast_GetCharField";
54
slow_case_addr = jni_GetCharField_addr();
57
name = "jni_fast_GetShortField";
58
slow_case_addr = jni_GetShortField_addr();
61
name = "jni_fast_GetIntField";
62
slow_case_addr = jni_GetIntField_addr();
65
name = "jni_fast_GetLongField";
66
slow_case_addr = jni_GetLongField_addr();
69
name = "jni_fast_GetFloatField";
70
slow_case_addr = jni_GetFloatField_addr();
73
name = "jni_fast_GetDoubleField";
74
slow_case_addr = jni_GetDoubleField_addr();
84
const Register Rsafepoint_counter_addr = R3;
85
const Register Robj = R1;
86
const Register Rres = R0;
87
const Register Rres_hi = R1;
88
const Register Rsafept_cnt = Rtemp;
89
const Register Rsafept_cnt2 = Rsafepoint_counter_addr;
90
const Register Rtmp1 = R3; // same as Rsafepoint_counter_addr
91
const Register Rtmp2 = R2; // same as jfieldID
93
assert_different_registers(Rsafepoint_counter_addr, Rsafept_cnt, Robj, Rres, LR);
94
assert_different_registers(Rsafept_cnt, R1, R2, Rtmp1, LR);
95
assert_different_registers(Rsafepoint_counter_addr, Rsafept_cnt, Rres, Rres_hi, Rtmp2, LR);
96
assert_different_registers(Rsafept_cnt2, Rsafept_cnt, Rres, Rres_hi, LR);
101
BufferBlob* blob = BufferBlob::create(name, BUFFER_SIZE);
102
CodeBuffer cbuf(blob);
103
MacroAssembler* masm = new MacroAssembler(&cbuf);
104
fast_entry = __ pc();
108
InlinedAddress safepoint_counter_addr(SafepointSynchronize::safepoint_counter_addr());
109
__ ldr_literal(Rsafepoint_counter_addr, safepoint_counter_addr);
111
__ push(RegisterSet(R0, R3)); // save incoming arguments for slow case
113
__ ldr_s32(Rsafept_cnt, Address(Rsafepoint_counter_addr));
114
__ tbnz(Rsafept_cnt, 0, slow_case);
116
__ bic(R1, R1, JNIHandles::tag_mask);
118
if (JvmtiExport::can_post_field_access()) {
119
// Using barrier to order wrt. JVMTI check and load of result.
120
__ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::LoadLoad), Rtmp1);
122
// Check to see if a field access watch has been set before we
123
// take the fast path.
124
__ ldr_global_s32(Rtmp1, (address)JvmtiExport::get_field_access_count_addr());
125
__ cbnz(Rtmp1, slow_case);
127
__ ldr(Robj, Address(R1));
129
// Address dependency restricts memory access ordering. It's cheaper than explicit LoadLoad barrier
130
__ andr(Rtmp1, Rsafept_cnt, (unsigned)1);
131
__ ldr(Robj, Address(R1, Rtmp1));
135
if (type != T_BOOLEAN
139
#endif // !__ABI_HARD__
141
// Only ldr and ldrb support embedded shift, other loads do not
142
__ add(Robj, Robj, AsmOperand(R2, lsr, 2));
143
field_addr = Address(Robj);
145
field_addr = Address(Robj, R2, lsr, 2);
147
assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
148
speculative_load_pclist[count] = __ pc();
152
__ ldrb(Rres, field_addr);
155
__ ldrsb(Rres, field_addr);
158
__ ldrh(Rres, field_addr);
161
__ ldrsh(Rres, field_addr);
167
__ ldr_s32(Rres, field_addr);
173
// Safe to use ldrd since long and double fields are 8-byte aligned
174
__ ldrd(Rres, field_addr);
178
__ ldr_float(S0, field_addr);
181
__ ldr_double(D0, field_addr);
183
#endif // __ABI_HARD__
185
ShouldNotReachHere();
188
__ ldr_literal(Rsafepoint_counter_addr, safepoint_counter_addr);
190
if (type == T_FLOAT || type == T_DOUBLE) {
191
__ fmrrd(Rres, Rres_hi, D0);
193
#endif // __ABI_HARD__
195
// Order JVMTI check and load of result wrt. succeeding check
196
// (LoadStore for volatile field).
197
__ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::LoadLoad | MacroAssembler::LoadStore), Rtmp2);
199
__ ldr_s32(Rsafept_cnt2, Address(Rsafepoint_counter_addr));
200
__ cmp(Rsafept_cnt2, Rsafept_cnt);
201
// discards saved R0 R1 R2 R3
202
__ add(SP, SP, 4 * wordSize, eq);
205
slowcase_entry_pclist[count++] = __ pc();
208
__ pop(RegisterSet(R0, R3));
209
// thumb mode switch handled by MacroAssembler::jump if needed
210
__ jump(slow_case_addr, relocInfo::none, Rtemp);
212
__ bind_literal(safepoint_counter_addr);
216
guarantee((__ pc() - fast_entry) <= BUFFER_SIZE, "BUFFER_SIZE too small");
221
address JNI_FastGetField::generate_fast_get_float_field0(BasicType type) {
222
ShouldNotReachHere();
226
address JNI_FastGetField::generate_fast_get_boolean_field() {
227
return generate_fast_get_int_field0(T_BOOLEAN);
230
address JNI_FastGetField::generate_fast_get_byte_field() {
231
return generate_fast_get_int_field0(T_BYTE);
234
address JNI_FastGetField::generate_fast_get_char_field() {
235
return generate_fast_get_int_field0(T_CHAR);
238
address JNI_FastGetField::generate_fast_get_short_field() {
239
return generate_fast_get_int_field0(T_SHORT);
242
address JNI_FastGetField::generate_fast_get_int_field() {
243
return generate_fast_get_int_field0(T_INT);
246
address JNI_FastGetField::generate_fast_get_long_field() {
247
return generate_fast_get_int_field0(T_LONG);
250
address JNI_FastGetField::generate_fast_get_float_field() {
251
return generate_fast_get_int_field0(T_FLOAT);
254
address JNI_FastGetField::generate_fast_get_double_field() {
255
return generate_fast_get_int_field0(T_DOUBLE);