Tue, 12 Jun 2018 13:58:17 +0800
#7157 Fix all forgot saying delayed() when filling delay slot issues
Summary: enable check_delay and guarantee delay_state is at_delay_slot when filling delay slot
Reviewed-by: aoqi
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"
38 #define __ _masm->
40 // Implementation of SignatureHandlerGenerator
42 void InterpreterRuntime::SignatureHandlerGenerator::move(int from_offset, int to_offset) {
43 __ ld(temp(), from(), Interpreter::local_offset_in_bytes(from_offset));
44 __ sd(temp(), to(), to_offset * longSize);
45 }
47 void InterpreterRuntime::SignatureHandlerGenerator::box(int from_offset, int to_offset) {
48 __ addi(temp(), from(),Interpreter::local_offset_in_bytes(from_offset) );
49 __ lw(AT, from(), Interpreter::local_offset_in_bytes(from_offset) );
51 Label L;
52 __ bne(AT, R0, L);
53 __ delayed()->nop();
54 __ move(temp(), R0);
55 __ bind(L);
56 __ sw(temp(), to(), to_offset * wordSize);
57 }
59 void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) {
60 // generate code to handle arguments
61 iterate(fingerprint);
62 // return result handler
63 __ li(V0, AbstractInterpreter::result_handler(method()->result_type()));
64 // return
65 __ jr(RA);
66 __ delayed()->nop();
68 __ flush();
69 }
71 void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
72 Argument jni_arg(jni_offset());
73 __ lw(temp(), from(), Interpreter::local_offset_in_bytes(offset()));
74 __ store_int_argument(temp(), jni_arg);
75 }
77 void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
78 Argument jni_arg(jni_offset());
80 Register Rtmp1 = temp();
82 // the handle for a receiver will never be null
83 bool do_NULL_check = offset() != 0 || is_static();
84 __ ld(Rtmp1, from(), Interpreter::local_offset_in_bytes(offset()));
86 Label L;
87 __ bne(Rtmp1, R0, L);
88 __ delayed()->daddiu(Rtmp1, from(), Interpreter::local_offset_in_bytes(offset()));
89 __ move(Rtmp1, R0);
90 __ bind(L);
92 __ store_ptr_argument(Rtmp1, jni_arg);
93 }
95 //the jvm specifies that long type takes 2 stack spaces, so in do_long(), _offset += 2.
96 void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
97 Argument jni_arg(jni_offset());
98 __ ld(temp(), from(), Interpreter::local_offset_in_bytes(offset() + 1));
99 if(jni_arg.is_Register()) {
100 __ move(jni_arg.as_Register(), temp());
101 } else {
102 __ sd(temp(), jni_arg.as_caller_address());
103 }
104 }
106 #if (defined _LP64) || (defined N32)
107 void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
108 Argument jni_arg(jni_offset());
109 __ lwc1(F4, from(), Interpreter::local_offset_in_bytes(offset()));
110 __ store_float_argument(F4, jni_arg);
111 }
114 //the jvm specifies that double type takes 2 stack spaces, so in do_double(), _offset += 2.
115 void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
116 Argument jni_arg(jni_offset());
117 __ ldc1(F4, from(), Interpreter::local_offset_in_bytes(offset() + 1));
118 __ store_double_argument(F4, jni_arg);
119 }
120 #endif
123 Register InterpreterRuntime::SignatureHandlerGenerator::from() { return LVP; }
124 Register InterpreterRuntime::SignatureHandlerGenerator::to() { return SP; }
125 Register InterpreterRuntime::SignatureHandlerGenerator::temp() { return RT4; }
127 // Implementation of SignatureHandlerLibrary
129 void SignatureHandlerLibrary::pd_set_handler(address handler) {}
132 class SlowSignatureHandler
133 : public NativeSignatureIterator {
134 private:
135 address _from;
136 intptr_t* _to;
137 intptr_t* _reg_args;
138 intptr_t* _fp_identifiers;
139 unsigned int _num_args;
141 virtual void pass_int()
142 {
143 jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
144 _from -= Interpreter::stackElementSize;
146 if (_num_args < Argument::n_register_parameters) {
147 *_reg_args++ = from_obj;
148 _num_args++;
149 } else {
150 *_to++ = from_obj;
151 }
152 }
154 virtual void pass_long()
155 {
156 intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
157 _from -= 2 * Interpreter::stackElementSize;
159 if (_num_args < Argument::n_register_parameters) {
160 *_reg_args++ = from_obj;
161 _num_args++;
162 } else {
163 *_to++ = from_obj;
164 }
165 }
167 virtual void pass_object()
168 {
169 intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0));
170 _from -= Interpreter::stackElementSize;
171 if (_num_args < Argument::n_register_parameters) {
172 *_reg_args++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr;
173 _num_args++;
174 } else {
175 *_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr;
176 }
177 }
179 virtual void pass_float()
180 {
181 jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
182 _from -= Interpreter::stackElementSize;
184 if (_num_args < Argument::n_float_register_parameters) {
185 *_reg_args++ = from_obj;
186 *_fp_identifiers |= (0x01 << (_num_args*2)); // mark as float
187 _num_args++;
188 } else {
189 *_to++ = from_obj;
190 }
191 }
193 virtual void pass_double()
194 {
195 intptr_t from_obj = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
196 _from -= 2*Interpreter::stackElementSize;
198 if (_num_args < Argument::n_float_register_parameters) {
199 *_reg_args++ = from_obj;
200 *_fp_identifiers |= (0x3 << (_num_args*2)); // mark as double
201 _num_args++;
202 } else {
203 *_to++ = from_obj;
204 }
205 }
207 public:
208 SlowSignatureHandler(methodHandle method, address from, intptr_t* to)
209 : NativeSignatureIterator(method)
210 {
211 _from = from;
212 _to = to;
214 _reg_args = to - Argument::n_register_parameters + jni_offset() - 1;
215 _fp_identifiers = to - 1;
216 *(int*) _fp_identifiers = 0;
217 _num_args = jni_offset();
218 }
219 };
222 IRT_ENTRY(address,
223 InterpreterRuntime::slow_signature_handler(JavaThread* thread,
224 Method* method,
225 intptr_t* from,
226 intptr_t* to))
227 methodHandle m(thread, (Method*)method);
228 assert(m->is_native(), "sanity check");
230 // handle arguments
231 SlowSignatureHandler(m, (address)from, to).iterate(UCONST64(-1));
233 // return result handler
234 return Interpreter::result_handler(m->result_type());
235 IRT_END