2
* Copyright (c) 2003, 2022, 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 "interpreter/interp_masm.hpp"
27
#include "interpreter/interpreter.hpp"
28
#include "interpreter/interpreterRuntime.hpp"
29
#include "memory/allocation.inline.hpp"
30
#include "oops/method.hpp"
31
#include "oops/oop.inline.hpp"
32
#include "runtime/handles.inline.hpp"
33
#include "runtime/icache.hpp"
34
#include "runtime/interfaceSupport.inline.hpp"
35
#include "runtime/signature.hpp"
39
// Implementation of SignatureHandlerGenerator
41
InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(const methodHandle& method, CodeBuffer* buffer) :
42
NativeSignatureIterator(method) {
43
_masm = new MacroAssembler(buffer);
46
_num_args = (method->is_static() ? 1 : 0);
47
_stack_offset = (Argument::n_int_register_parameters_c+1)* wordSize; // don't overwrite return address
49
_num_int_args = (method->is_static() ? 1 : 0);
51
_stack_offset = wordSize; // don't overwrite return address
56
Register InterpreterRuntime::SignatureHandlerGenerator::from() { return r14; }
57
Register InterpreterRuntime::SignatureHandlerGenerator::to() { return rsp; }
58
Register InterpreterRuntime::SignatureHandlerGenerator::temp() { return rscratch1; }
60
void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
61
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));
66
__ movl(c_rarg1, src);
70
__ movl(c_rarg2, src);
74
__ movl(c_rarg3, src);
79
__ movl(Address(to(), _stack_offset), rax);
80
_stack_offset += wordSize;
84
switch (_num_int_args) {
86
__ movl(c_rarg1, src);
90
__ movl(c_rarg2, src);
94
__ movl(c_rarg3, src);
98
__ movl(c_rarg4, src);
102
__ movl(c_rarg5, src);
107
__ movl(Address(to(), _stack_offset), rax);
108
_stack_offset += wordSize;
114
void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
115
const Address src(from(), Interpreter::local_offset_in_bytes(offset() + 1));
120
__ movptr(c_rarg1, src);
124
__ movptr(c_rarg2, src);
128
__ movptr(c_rarg3, src);
134
__ movptr(Address(to(), _stack_offset), rax);
135
_stack_offset += wordSize;
139
switch (_num_int_args) {
141
__ movptr(c_rarg1, src);
145
__ movptr(c_rarg2, src);
149
__ movptr(c_rarg3, src);
153
__ movptr(c_rarg4, src);
157
__ movptr(c_rarg5, src);
162
__ movptr(Address(to(), _stack_offset), rax);
163
_stack_offset += wordSize;
169
void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
170
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));
173
if (_num_args < Argument::n_float_register_parameters_c-1) {
174
__ movflt(as_XMMRegister(++_num_args), src);
177
__ movl(Address(to(), _stack_offset), rax);
178
_stack_offset += wordSize;
181
if (_num_fp_args < Argument::n_float_register_parameters_c) {
182
__ movflt(as_XMMRegister(_num_fp_args++), src);
185
__ movl(Address(to(), _stack_offset), rax);
186
_stack_offset += wordSize;
191
void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
192
const Address src(from(), Interpreter::local_offset_in_bytes(offset() + 1));
195
if (_num_args < Argument::n_float_register_parameters_c-1) {
196
__ movdbl(as_XMMRegister(++_num_args), src);
199
__ movptr(Address(to(), _stack_offset), rax);
200
_stack_offset += wordSize;
203
if (_num_fp_args < Argument::n_float_register_parameters_c) {
204
__ movdbl(as_XMMRegister(_num_fp_args++), src);
207
__ movptr(Address(to(), _stack_offset), rax);
208
_stack_offset += wordSize;
213
void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
214
const Address src(from(), Interpreter::local_offset_in_bytes(offset()));
219
assert(offset() == 0, "argument register 1 can only be (non-null) receiver");
220
__ lea(c_rarg1, src);
225
__ xorl(c_rarg2, c_rarg2);
227
__ cmov(Assembler::notEqual, c_rarg2, rax);
232
__ xorl(c_rarg3, c_rarg3);
234
__ cmov(Assembler::notEqual, c_rarg3, rax);
239
__ xorl(temp(), temp());
241
__ cmov(Assembler::notEqual, temp(), rax);
242
__ movptr(Address(to(), _stack_offset), temp());
243
_stack_offset += wordSize;
247
switch (_num_int_args) {
249
assert(offset() == 0, "argument register 1 can only be (non-null) receiver");
250
__ lea(c_rarg1, src);
255
__ xorl(c_rarg2, c_rarg2);
257
__ cmov(Assembler::notEqual, c_rarg2, rax);
262
__ xorl(c_rarg3, c_rarg3);
264
__ cmov(Assembler::notEqual, c_rarg3, rax);
269
__ xorl(c_rarg4, c_rarg4);
271
__ cmov(Assembler::notEqual, c_rarg4, rax);
276
__ xorl(c_rarg5, c_rarg5);
278
__ cmov(Assembler::notEqual, c_rarg5, rax);
283
__ xorl(temp(), temp());
285
__ cmov(Assembler::notEqual, temp(), rax);
286
__ movptr(Address(to(), _stack_offset), temp());
287
_stack_offset += wordSize;
293
void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) {
294
// generate code to handle arguments
295
iterate(fingerprint);
297
// return result handler
298
__ lea(rax, ExternalAddress(Interpreter::result_handler(method()->result_type())));
305
// Implementation of SignatureHandlerLibrary
307
void SignatureHandlerLibrary::pd_set_handler(address handler) {}
311
class SlowSignatureHandler
312
: public NativeSignatureIterator {
317
intptr_t* _fp_identifiers;
318
unsigned int _num_args;
320
virtual void pass_int()
322
jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
323
_from -= Interpreter::stackElementSize;
325
if (_num_args < Argument::n_int_register_parameters_c-1) {
326
*_reg_args++ = from_obj;
333
virtual void pass_long()
335
intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
336
_from -= 2*Interpreter::stackElementSize;
338
if (_num_args < Argument::n_int_register_parameters_c-1) {
339
*_reg_args++ = from_obj;
346
virtual void pass_object()
348
intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0));
349
_from -= Interpreter::stackElementSize;
350
if (_num_args < Argument::n_int_register_parameters_c-1) {
351
*_reg_args++ = (*from_addr == 0) ? NULL_WORD : (intptr_t) from_addr;
354
*_to++ = (*from_addr == 0) ? NULL_WORD : (intptr_t) from_addr;
358
virtual void pass_float()
360
jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
361
_from -= Interpreter::stackElementSize;
363
if (_num_args < Argument::n_float_register_parameters_c-1) {
364
assert((_num_args*2) < BitsPerWord, "_num_args*2 is out of range");
365
*_reg_args++ = from_obj;
366
*_fp_identifiers |= ((intptr_t)0x01 << (_num_args*2)); // mark as float
373
virtual void pass_double()
375
intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
376
_from -= 2*Interpreter::stackElementSize;
378
if (_num_args < Argument::n_float_register_parameters_c-1) {
379
assert((_num_args*2) < BitsPerWord, "_num_args*2 is out of range");
380
*_reg_args++ = from_obj;
381
*_fp_identifiers |= ((intptr_t)0x3 << (_num_args*2)); // mark as double
389
SlowSignatureHandler(const methodHandle& method, address from, intptr_t* to)
390
: NativeSignatureIterator(method)
395
_reg_args = to - (method->is_static() ? 4 : 5);
396
_fp_identifiers = to - 2;
397
_to = _to + 4; // Windows reserves stack space for register arguments
398
*(int*) _fp_identifiers = 0;
399
_num_args = (method->is_static() ? 1 : 0);
403
class SlowSignatureHandler
404
: public NativeSignatureIterator {
410
intptr_t* _fp_identifiers;
411
unsigned int _num_int_args;
412
unsigned int _num_fp_args;
414
virtual void pass_int()
416
jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
417
_from -= Interpreter::stackElementSize;
419
if (_num_int_args < Argument::n_int_register_parameters_c-1) {
420
*_int_args++ = from_obj;
427
virtual void pass_long()
429
intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
430
_from -= 2*Interpreter::stackElementSize;
432
if (_num_int_args < Argument::n_int_register_parameters_c-1) {
433
*_int_args++ = from_obj;
440
virtual void pass_object()
442
intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0));
443
_from -= Interpreter::stackElementSize;
445
if (_num_int_args < Argument::n_int_register_parameters_c-1) {
446
*_int_args++ = (*from_addr == 0) ? NULL_WORD : (intptr_t)from_addr;
449
*_to++ = (*from_addr == 0) ? NULL_WORD : (intptr_t) from_addr;
453
virtual void pass_float()
455
jint from_obj = *(jint*)(_from+Interpreter::local_offset_in_bytes(0));
456
_from -= Interpreter::stackElementSize;
458
if (_num_fp_args < Argument::n_float_register_parameters_c) {
459
*_fp_args++ = from_obj;
466
virtual void pass_double()
468
intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
469
_from -= 2*Interpreter::stackElementSize;
471
if (_num_fp_args < Argument::n_float_register_parameters_c) {
472
*_fp_args++ = from_obj;
473
*_fp_identifiers |= (1 << _num_fp_args); // mark as double
481
SlowSignatureHandler(const methodHandle& method, address from, intptr_t* to)
482
: NativeSignatureIterator(method)
487
_int_args = to - (method->is_static() ? 14 : 15);
489
_fp_identifiers = to - 10;
490
*(int*) _fp_identifiers = 0;
491
_num_int_args = (method->is_static() ? 1 : 0);
499
InterpreterRuntime::slow_signature_handler(JavaThread* current,
503
methodHandle m(current, (Method*)method);
504
assert(m->is_native(), "sanity check");
507
SlowSignatureHandler(m, (address)from, to + 1).iterate((uint64_t)CONST64(-1));
509
// return result handler
510
return Interpreter::result_handler(m->result_type());