25
#include "precompiled.hpp"
26
#include "asm/macroAssembler.inline.hpp"
27
#include "interpreter/interp_masm.hpp"
28
#include "interpreter/interpreter.hpp"
29
#include "interpreter/interpreterRuntime.hpp"
30
#include "memory/allocation.inline.hpp"
31
#include "oops/method.hpp"
32
#include "oops/oop.inline.hpp"
33
#include "runtime/handles.inline.hpp"
34
#include "runtime/icache.hpp"
35
#include "runtime/interfaceSupport.inline.hpp"
36
#include "runtime/signature.hpp"
40
InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(
41
const methodHandle& method, CodeBuffer* buffer) : NativeSignatureIterator(method) {
42
_masm = new MacroAssembler(buffer);
44
_ireg = is_static() ? 2 : 1;
51
#ifdef SHARING_FAST_NATIVE_FINGERPRINTS
53
static const BasicType shared_type[] = {
71
uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {
72
if (fingerprint == UCONST64(-1)) {
76
int shift = SignatureIterator::fp_static_feature_size;
77
SignatureIterator::fingerprint_t result = fingerprint & ((1 << shift) - 1);
79
BasicType ret_type = SignatureIterator::fp_return_type(fingerprint);
85
if (is_reference_type(ret_type)) {
87
} else if (ret_type != T_BOOLEAN) {
90
result |= ((SignatureIterator::fingerprint_t) ret_type) << shift;
91
shift += SignatureIterator::fp_result_feature_size;
93
SignatureIterator::fingerprint_t unaccumulator = SignatureIterator::fp_start_parameters(fingerprint);
95
BasicType type = SignatureIterator::fp_next_parameter(unaccumulator);
96
if (type == (BasicType)SignatureIterator::fp_parameters_done) {
99
assert(SignatureIterator::fp_is_valid_type(type), "garbled fingerprint");
100
BasicType shared = shared_type[type - T_BOOLEAN];
101
result |= ((SignatureIterator::fingerprint_t) shared) << shift;
102
shift += SignatureIterator::fp_parameter_feature_size;
108
void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
109
if (_ireg < GPR_PARAMS) {
110
Register dst = as_Register(_ireg);
111
__ ldr_s32(dst, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
114
__ ldr_s32(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
115
__ str_32(Rtemp, Address(SP, _abi_offset * wordSize));
120
void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
122
#if (ALIGN_WIDE_ARGUMENTS == 1)
123
if ((_ireg & 1) != 0) {
128
Register dst1 = as_Register(_ireg);
129
Register dst2 = as_Register(_ireg+1);
130
__ ldr(dst1, Address(Rlocals, Interpreter::local_offset_in_bytes(offset()+1)));
131
__ ldr(dst2, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
133
#if (ALIGN_WIDE_ARGUMENTS == 0)
134
} else if (_ireg == 3) {
136
Register dst1 = as_Register(_ireg);
137
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
138
__ ldr(dst1, Address(Rlocals, Interpreter::local_offset_in_bytes(offset()+1)));
139
__ str(Rtemp, Address(SP, _abi_offset * wordSize));
144
#if (ALIGN_WIDE_ARGUMENTS == 1)
145
if(_abi_offset & 1) _abi_offset++;
147
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset()+1)));
148
__ str(Rtemp, Address(SP, (_abi_offset) * wordSize));
149
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
150
__ str(Rtemp, Address(SP, (_abi_offset+1) * wordSize));
156
void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
158
Register dst = as_Register(_ireg);
159
__ ldr(dst, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
161
__ sub(dst, Rlocals, -Interpreter::local_offset_in_bytes(offset()), ne);
164
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
166
__ sub(Rtemp, Rlocals, -Interpreter::local_offset_in_bytes(offset()), ne);
167
__ str(Rtemp, Address(SP, _abi_offset * wordSize));
173
void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
175
Register dst = as_Register(_ireg);
176
__ ldr(dst, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
179
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
180
__ str(Rtemp, Address(SP, _abi_offset * wordSize));
187
void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
188
if((_fp_slot < 16) || (_single_fpr_slot & 1)) {
189
if ((_single_fpr_slot & 1) == 0) {
190
_single_fpr_slot = _fp_slot;
193
__ flds(as_FloatRegister(_single_fpr_slot), Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
196
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
197
__ str(Rtemp, Address(SP, _abi_offset * wordSize));
202
void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
204
__ fldd(as_FloatRegister(_fp_slot), Address(Rlocals, Interpreter::local_offset_in_bytes(offset()+1)));
207
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset()+1)));
208
__ str(Rtemp, Address(SP, (_abi_offset) * wordSize));
209
__ ldr(Rtemp, Address(Rlocals, Interpreter::local_offset_in_bytes(offset())));
210
__ str(Rtemp, Address(SP, (_abi_offset+1) * wordSize));
212
_single_fpr_slot = 16;
218
void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) {
219
iterate(fingerprint);
221
BasicType result_type = SignatureIterator::fp_return_type(fingerprint);
223
address result_handler = Interpreter::result_handler(result_type);
225
__ mov_slow(R0, (intptr_t)result_handler);
233
void SignatureHandlerLibrary::pd_set_handler(address handler) {}
235
class SlowSignatureHandler: public NativeSignatureIterator {
241
virtual void pass_int() {
242
*_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
243
_from -= Interpreter::stackElementSize;
246
virtual void pass_float() {
247
*_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
248
_from -= Interpreter::stackElementSize;
251
virtual void pass_long() {
252
#if (ALIGN_WIDE_ARGUMENTS == 1)
253
if (((intptr_t)_to & 7) != 0) {
258
_to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
259
_to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0));
261
_from -= 2*Interpreter::stackElementSize;
264
virtual void pass_object() {
265
intptr_t from_addr = (intptr_t)(_from + Interpreter::local_offset_in_bytes(0));
266
*_to++ = (*(intptr_t*)from_addr == 0) ? 0 : from_addr;
267
_from -= Interpreter::stackElementSize;
278
virtual void pass_int() {
279
if(_last_gp < GPR_PARAMS) {
280
_toGP[_last_gp++] = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
282
*_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
284
_from -= Interpreter::stackElementSize;
287
virtual void pass_long() {
288
assert(ALIGN_WIDE_ARGUMENTS == 1, "ABI_HARD not supported with unaligned wide arguments");
290
if(_last_gp & 1) _last_gp++;
291
_toGP[_last_gp++] = *(jint *)(_from+Interpreter::local_offset_in_bytes(1));
292
_toGP[_last_gp++] = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
294
if (((intptr_t)_to & 7) != 0) {
298
_to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
299
_to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0));
303
_from -= 2*Interpreter::stackElementSize;
306
virtual void pass_object() {
307
intptr_t from_addr = (intptr_t)(_from + Interpreter::local_offset_in_bytes(0));
308
if(_last_gp < GPR_PARAMS) {
309
_toGP[_last_gp++] = (*(intptr_t*)from_addr == 0) ? 0 : from_addr;
311
*_to++ = (*(intptr_t*)from_addr == 0) ? 0 : from_addr;
313
_from -= Interpreter::stackElementSize;
316
virtual void pass_float() {
317
if((_last_fp < 16) || (_last_single_fp & 1)) {
318
if ((_last_single_fp & 1) == 0) {
319
_last_single_fp = _last_fp;
323
_toFP[_last_single_fp++] = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
325
*_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
327
_from -= Interpreter::stackElementSize;
330
virtual void pass_double() {
331
assert(ALIGN_WIDE_ARGUMENTS == 1, "ABI_HARD not supported with unaligned wide arguments");
333
_toFP[_last_fp++] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
334
_toFP[_last_fp++] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0));
336
if (((intptr_t)_to & 7) != 0) {
339
_to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
340
_to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0));
342
_last_single_fp = 16;
344
_from -= 2*Interpreter::stackElementSize;
350
SlowSignatureHandler(const methodHandle& method, address from, intptr_t* to) :
351
NativeSignatureIterator(method) {
356
_toFP = _toGP + GPR_PARAMS;
358
_last_gp = (is_static() ? 2 : 1);
362
_to = to + (is_static() ? 2 : 1);
367
JRT_ENTRY(address, InterpreterRuntime::slow_signature_handler(JavaThread* current, Method* method, intptr_t* from, intptr_t* to))
368
methodHandle m(current, (Method*)method);
369
assert(m->is_native(), "sanity check");
370
SlowSignatureHandler(m, (address)from, to).iterate(UCONST64(-1));
371
return Interpreter::result_handler(m->result_type());