Tue, 31 May 2016 00:22:06 -0400
[Code Reorganization] load_two_bytes_from_at_bcp -> get_2_byte_integer_at_bcp
remove useless MacroAssembler::store_two_byts_to_at_bcp
change MacroAssembler::load_two_bytes_from_at_bcp to InterpreterMacroAssembler::get_2_byte_integer_at_bcp
change MacroAssembler::get_4_byte_integer_at_bcp to InterpreterMacroAssembler::get_4_byte_integer_at_bcp
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2016, Loongson Technology. 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 */
26 #include "precompiled.hpp"
27 #include "interpreter/interpreter.hpp"
28 #include "interpreter/interpreterRuntime.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "memory/universe.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.hpp"
36 #include "runtime/signature.hpp"
39 #define __ _masm->
41 // Implementation of SignatureHandlerGenerator
43 //#define aoqi_test
44 void InterpreterRuntime::SignatureHandlerGenerator::move(int from_offset, int to_offset) {
45 __ ld(temp(), from(), Interpreter::local_offset_in_bytes(from_offset));
46 __ sd(temp(), to(), to_offset * longSize);
47 }
49 void InterpreterRuntime::SignatureHandlerGenerator::box(int from_offset, int to_offset) {
50 __ addi(temp(), from(),Interpreter::local_offset_in_bytes(from_offset) );
51 __ lw(AT, from(), Interpreter::local_offset_in_bytes(from_offset) );
53 Label L;
54 __ bne(AT, R0, L);
55 __ delayed()->nop();
56 __ move(temp(), R0);
57 __ bind(L);
58 __ sw(temp(), to(), to_offset * wordSize);
59 }
61 void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) {
62 // generate code to handle arguments
63 iterate(fingerprint);
64 // return result handler
65 __ li(V0, AbstractInterpreter::result_handler(method()->result_type()));
66 // return
67 __ jr(RA);
68 __ delayed()->nop();
70 __ flush();
71 }
73 void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
74 Argument jni_arg(jni_offset());
75 __ lw(temp(), from(), Interpreter::local_offset_in_bytes(offset()));
76 __ store_int_argument(temp(), jni_arg);
77 }
79 void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
80 Argument jni_arg(jni_offset());
82 Register Rtmp1 = temp();
84 // the handle for a receiver will never be null
85 bool do_NULL_check = offset() != 0 || is_static();
86 __ ld(Rtmp1, from(), Interpreter::local_offset_in_bytes(offset()));
88 Label L;
89 __ bne(Rtmp1, R0, L);
90 __ addu_long(Rtmp1, from(), Interpreter::local_offset_in_bytes(offset()));
91 __ move(Rtmp1, R0);
92 __ bind(L);
94 __ store_ptr_argument(Rtmp1, jni_arg);
95 }
97 //the jvm specifies that long type takes 2 stack spaces, so in do_long(), _offset += 2.
98 void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
99 Argument jni_arg(jni_offset());
100 /*
101 __ lw(temp(), from(), Interpreter::local_offset_in_bytes(offset()));
102 __ dsll32(temp(), temp(), 0);
103 __ lw(AT, from(), Interpreter::local_offset_in_bytes(offset() + 1));
104 __ daddu(temp(), temp(), AT);
105 __ sd(temp(), to(), jni_offset() * longSize);
106 */
107 __ ld(temp(), from(), Interpreter::local_offset_in_bytes(offset() + 1));
108 //__ store_long_argument(temp(), jni_arg);
109 if(jni_arg.is_Register()) {
110 __ move(jni_arg.as_Register(), temp());
111 } else {
112 __ sd(temp(), jni_arg.as_caller_address());
113 }
114 }
116 #if (defined _LP64) || (defined N32)
117 void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
118 Argument jni_arg(jni_offset());
119 __ lwc1(F4, from(), Interpreter::local_offset_in_bytes(offset()));
120 // __ sdc1(F4, to(), jni_offset() * longSize);
121 __ store_float_argument(F4, jni_arg);
122 }
125 //the jvm specifies that double type takes 2 stack spaces, so in do_double(), _offset += 2.
126 void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
127 Argument jni_arg(jni_offset());
128 __ ldc1(F4, from(), Interpreter::local_offset_in_bytes(offset() + 1));
129 __ store_double_argument(F4, jni_arg);
130 }
131 #endif
134 inline Register InterpreterRuntime::SignatureHandlerGenerator::from() { return LVP; }
135 inline Register InterpreterRuntime::SignatureHandlerGenerator::to() { return SP; }
136 inline Register InterpreterRuntime::SignatureHandlerGenerator::temp() { return RT4; }
138 // Implementation of SignatureHandlerLibrary
140 void SignatureHandlerLibrary::pd_set_handler(address handler) {}
143 class SlowSignatureHandler
144 : public NativeSignatureIterator {
145 private:
146 address _from;
147 intptr_t* _to;
148 intptr_t* _reg_args;
149 intptr_t* _fp_identifiers;
150 unsigned int _num_args;
151 //bool _align;
153 virtual void pass_int()
154 {
155 jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
156 _from -= Interpreter::stackElementSize;
158 if (_num_args < Argument::n_register_parameters) {
159 *_reg_args++ = from_obj;
160 _num_args++;
161 } else {
162 *_to++ = from_obj;
163 }
164 }
166 virtual void pass_long()
167 {
168 intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
169 _from -= 2 * Interpreter::stackElementSize;
171 if (_num_args < Argument::n_register_parameters) {
172 *_reg_args++ = from_obj;
173 _num_args++;
174 } else {
175 *_to++ = from_obj;
176 }
177 }
179 virtual void pass_object()
180 {
181 intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0));
182 _from -= Interpreter::stackElementSize;
183 if (_num_args < Argument::n_register_parameters) {
184 *_reg_args++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr;
185 _num_args++;
186 } else {
187 *_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr;
188 }
189 }
191 virtual void pass_float()
192 {
193 jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
194 _from -= Interpreter::stackElementSize;
196 if (_num_args < Argument::n_float_register_parameters) {
197 *_reg_args++ = from_obj;
198 *_fp_identifiers |= (0x01 << (_num_args*2)); // mark as float
199 _num_args++;
200 } else {
201 *_to++ = from_obj;
202 }
203 }
205 virtual void pass_double()
206 {
207 intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
208 _from -= 2*Interpreter::stackElementSize;
210 if (_num_args < Argument::n_float_register_parameters) {
211 *_reg_args++ = from_obj;
212 *_fp_identifiers |= (0x3 << (_num_args*2)); // mark as double
213 _num_args++;
214 } else {
215 *_to++ = from_obj;
216 }
217 }
219 public:
220 SlowSignatureHandler(methodHandle method, address from, intptr_t* to)
221 : NativeSignatureIterator(method)
222 {
223 _from = from;
224 _to = to;
226 //_reg_args = to - (method->is_static() ? 8 : 9);
227 _reg_args = to - Argument::n_register_parameters + jni_offset() - 1;
228 _fp_identifiers = to - 1;
229 // _to = _to + 4; // Windows reserves stack space for register arguments
230 *(int*) _fp_identifiers = 0;
231 //_num_args = (method->is_static() ? 1 : 0);
232 _num_args = jni_offset();
233 }
234 };
237 IRT_ENTRY(address,
238 InterpreterRuntime::slow_signature_handler(JavaThread* thread,
239 Method* method,
240 intptr_t* from,
241 intptr_t* to))
242 methodHandle m(thread, (Method*)method);
243 assert(m->is_native(), "sanity check");
245 // handle arguments
246 SlowSignatureHandler(m, (address)from, to).iterate(UCONST64(-1));
248 // return result handler
249 return Interpreter::result_handler(m->result_type());
250 IRT_END