jdk

Форк
0
/
jniFastGetField_arm.cpp 
256 строк · 7.6 Кб
1
/*
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.
4
 *
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.
8
 *
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).
14
 *
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.
18
 *
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
21
 * questions.
22
 *
23
 */
24

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"
35

36
#define __ masm->
37

38
#define BUFFER_SIZE 120
39

40
address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
41
  const char* name = nullptr;
42
  address slow_case_addr = nullptr;
43
  switch (type) {
44
    case T_BOOLEAN:
45
      name = "jni_fast_GetBooleanField";
46
      slow_case_addr = jni_GetBooleanField_addr();
47
      break;
48
    case T_BYTE:
49
      name = "jni_fast_GetByteField";
50
      slow_case_addr = jni_GetByteField_addr();
51
      break;
52
    case T_CHAR:
53
      name = "jni_fast_GetCharField";
54
      slow_case_addr = jni_GetCharField_addr();
55
      break;
56
    case T_SHORT:
57
      name = "jni_fast_GetShortField";
58
      slow_case_addr = jni_GetShortField_addr();
59
      break;
60
    case T_INT:
61
      name = "jni_fast_GetIntField";
62
      slow_case_addr = jni_GetIntField_addr();
63
      break;
64
    case T_LONG:
65
      name = "jni_fast_GetLongField";
66
      slow_case_addr = jni_GetLongField_addr();
67
      break;
68
    case T_FLOAT:
69
      name = "jni_fast_GetFloatField";
70
      slow_case_addr = jni_GetFloatField_addr();
71
      break;
72
    case T_DOUBLE:
73
      name = "jni_fast_GetDoubleField";
74
      slow_case_addr = jni_GetDoubleField_addr();
75
      break;
76
    default:
77
      ShouldNotReachHere();
78
  }
79

80
  // R0 - jni env
81
  // R1 - object handle
82
  // R2 - jfieldID
83

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
92

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);
97

98
  address fast_entry;
99

100
  ResourceMark rm;
101
  BufferBlob* blob = BufferBlob::create(name, BUFFER_SIZE);
102
  CodeBuffer cbuf(blob);
103
  MacroAssembler* masm = new MacroAssembler(&cbuf);
104
  fast_entry = __ pc();
105
  Label slow_case;
106

107
  // Safepoint check
108
  InlinedAddress safepoint_counter_addr(SafepointSynchronize::safepoint_counter_addr());
109
  __ ldr_literal(Rsafepoint_counter_addr, safepoint_counter_addr);
110

111
  __ push(RegisterSet(R0, R3));  // save incoming arguments for slow case
112

113
  __ ldr_s32(Rsafept_cnt, Address(Rsafepoint_counter_addr));
114
  __ tbnz(Rsafept_cnt, 0, slow_case);
115

116
  __ bic(R1, R1, JNIHandles::tag_mask);
117

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);
121

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);
126

127
    __ ldr(Robj, Address(R1));
128
  } else {
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));
132
  }
133

134
  Address field_addr;
135
  if (type != T_BOOLEAN
136
      && type != T_INT
137
#ifndef __ABI_HARD__
138
      && type != T_FLOAT
139
#endif // !__ABI_HARD__
140
      ) {
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);
144
  } else {
145
    field_addr = Address(Robj, R2, lsr, 2);
146
  }
147
  assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
148
  speculative_load_pclist[count] = __ pc();
149

150
  switch (type) {
151
    case T_BOOLEAN:
152
      __ ldrb(Rres, field_addr);
153
      break;
154
    case T_BYTE:
155
      __ ldrsb(Rres, field_addr);
156
      break;
157
    case T_CHAR:
158
      __ ldrh(Rres, field_addr);
159
      break;
160
    case T_SHORT:
161
      __ ldrsh(Rres, field_addr);
162
      break;
163
    case T_INT:
164
#ifndef __ABI_HARD__
165
    case T_FLOAT:
166
#endif
167
      __ ldr_s32(Rres, field_addr);
168
      break;
169
    case T_LONG:
170
#ifndef __ABI_HARD__
171
    case T_DOUBLE:
172
#endif
173
      // Safe to use ldrd since long and double fields are 8-byte aligned
174
      __ ldrd(Rres, field_addr);
175
      break;
176
#ifdef __ABI_HARD__
177
    case T_FLOAT:
178
      __ ldr_float(S0, field_addr);
179
      break;
180
    case T_DOUBLE:
181
      __ ldr_double(D0, field_addr);
182
      break;
183
#endif // __ABI_HARD__
184
    default:
185
      ShouldNotReachHere();
186
  }
187

188
  __ ldr_literal(Rsafepoint_counter_addr, safepoint_counter_addr);
189
#ifdef __ABI_HARD__
190
  if (type == T_FLOAT || type == T_DOUBLE) {
191
    __ fmrrd(Rres, Rres_hi, D0);
192
  }
193
#endif // __ABI_HARD__
194

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);
198

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);
203
  __ bx(LR, eq);
204

205
  slowcase_entry_pclist[count++] = __ pc();
206

207
  __ bind(slow_case);
208
  __ pop(RegisterSet(R0, R3));
209
  // thumb mode switch handled by MacroAssembler::jump if needed
210
  __ jump(slow_case_addr, relocInfo::none, Rtemp);
211

212
  __ bind_literal(safepoint_counter_addr);
213

214
  __ flush();
215

216
  guarantee((__ pc() - fast_entry) <= BUFFER_SIZE, "BUFFER_SIZE too small");
217

218
  return fast_entry;
219
}
220

221
address JNI_FastGetField::generate_fast_get_float_field0(BasicType type) {
222
  ShouldNotReachHere();
223
  return nullptr;
224
}
225

226
address JNI_FastGetField::generate_fast_get_boolean_field() {
227
  return generate_fast_get_int_field0(T_BOOLEAN);
228
}
229

230
address JNI_FastGetField::generate_fast_get_byte_field() {
231
  return generate_fast_get_int_field0(T_BYTE);
232
}
233

234
address JNI_FastGetField::generate_fast_get_char_field() {
235
  return generate_fast_get_int_field0(T_CHAR);
236
}
237

238
address JNI_FastGetField::generate_fast_get_short_field() {
239
  return generate_fast_get_int_field0(T_SHORT);
240
}
241

242
address JNI_FastGetField::generate_fast_get_int_field() {
243
  return generate_fast_get_int_field0(T_INT);
244
}
245

246
address JNI_FastGetField::generate_fast_get_long_field() {
247
  return generate_fast_get_int_field0(T_LONG);
248
}
249

250
address JNI_FastGetField::generate_fast_get_float_field() {
251
  return generate_fast_get_int_field0(T_FLOAT);
252
}
253

254
address JNI_FastGetField::generate_fast_get_double_field() {
255
  return generate_fast_get_int_field0(T_DOUBLE);
256
}
257

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.