Print this page
rev 1022 : 6829192: JSR 292 needs to support 64-bit x86
Summary: changes for method handles and invokedynamic
Reviewed-by: ?, ?
Split |
Close |
Expand all |
Collapse all |
--- old/src/cpu/x86/vm/interpreter_x86_64.cpp
+++ new/src/cpu/x86/vm/interpreter_x86_64.cpp
1 1 /*
2 2 * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 #include "incls/_precompiled.incl"
26 26 #include "incls/_interpreter_x86_64.cpp.incl"
27 27
28 28 #define __ _masm->
29 29
30 30
31 31 #ifdef _WIN64
32 32 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
33 33 address entry = __ pc();
34 34
35 35 // rbx: method
36 36 // r14: pointer to locals
37 37 // c_rarg3: first stack arg - wordSize
38 38 __ mov(c_rarg3, rsp);
39 39 // adjust rsp
40 40 __ subptr(rsp, 4 * wordSize);
41 41 __ call_VM(noreg,
42 42 CAST_FROM_FN_PTR(address,
43 43 InterpreterRuntime::slow_signature_handler),
44 44 rbx, r14, c_rarg3);
45 45
46 46 // rax: result handler
47 47
48 48 // Stack layout:
49 49 // rsp: 3 integer or float args (if static first is unused)
50 50 // 1 float/double identifiers
51 51 // return address
52 52 // stack args
53 53 // garbage
54 54 // expression stack bottom
55 55 // bcp (NULL)
56 56 // ...
57 57
58 58 // Do FP first so we can use c_rarg3 as temp
59 59 __ movl(c_rarg3, Address(rsp, 3 * wordSize)); // float/double identifiers
60 60
61 61 for ( int i= 0; i < Argument::n_int_register_parameters_c-1; i++ ) {
62 62 XMMRegister floatreg = as_XMMRegister(i+1);
63 63 Label isfloatordouble, isdouble, next;
64 64
65 65 __ testl(c_rarg3, 1 << (i*2)); // Float or Double?
66 66 __ jcc(Assembler::notZero, isfloatordouble);
67 67
68 68 // Do Int register here
69 69 switch ( i ) {
70 70 case 0:
71 71 __ movl(rscratch1, Address(rbx, methodOopDesc::access_flags_offset()));
72 72 __ testl(rscratch1, JVM_ACC_STATIC);
73 73 __ cmovptr(Assembler::zero, c_rarg1, Address(rsp, 0));
74 74 break;
75 75 case 1:
76 76 __ movptr(c_rarg2, Address(rsp, wordSize));
77 77 break;
78 78 case 2:
79 79 __ movptr(c_rarg3, Address(rsp, 2 * wordSize));
80 80 break;
81 81 default:
82 82 break;
83 83 }
84 84
85 85 __ jmp (next);
86 86
87 87 __ bind(isfloatordouble);
88 88 __ testl(c_rarg3, 1 << ((i*2)+1)); // Double?
89 89 __ jcc(Assembler::notZero, isdouble);
90 90
91 91 // Do Float Here
92 92 __ movflt(floatreg, Address(rsp, i * wordSize));
93 93 __ jmp(next);
94 94
95 95 // Do Double here
96 96 __ bind(isdouble);
97 97 __ movdbl(floatreg, Address(rsp, i * wordSize));
98 98
99 99 __ bind(next);
100 100 }
101 101
102 102
103 103 // restore rsp
104 104 __ addptr(rsp, 4 * wordSize);
105 105
106 106 __ ret(0);
107 107
108 108 return entry;
109 109 }
110 110 #else
111 111 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
112 112 address entry = __ pc();
113 113
114 114 // rbx: method
115 115 // r14: pointer to locals
116 116 // c_rarg3: first stack arg - wordSize
117 117 __ mov(c_rarg3, rsp);
118 118 // adjust rsp
119 119 __ subptr(rsp, 14 * wordSize);
120 120 __ call_VM(noreg,
121 121 CAST_FROM_FN_PTR(address,
122 122 InterpreterRuntime::slow_signature_handler),
123 123 rbx, r14, c_rarg3);
124 124
125 125 // rax: result handler
126 126
127 127 // Stack layout:
128 128 // rsp: 5 integer args (if static first is unused)
129 129 // 1 float/double identifiers
130 130 // 8 double args
131 131 // return address
132 132 // stack args
133 133 // garbage
134 134 // expression stack bottom
135 135 // bcp (NULL)
136 136 // ...
137 137
138 138 // Do FP first so we can use c_rarg3 as temp
139 139 __ movl(c_rarg3, Address(rsp, 5 * wordSize)); // float/double identifiers
140 140
141 141 for (int i = 0; i < Argument::n_float_register_parameters_c; i++) {
142 142 const XMMRegister r = as_XMMRegister(i);
143 143
144 144 Label d, done;
145 145
146 146 __ testl(c_rarg3, 1 << i);
147 147 __ jcc(Assembler::notZero, d);
148 148 __ movflt(r, Address(rsp, (6 + i) * wordSize));
149 149 __ jmp(done);
150 150 __ bind(d);
151 151 __ movdbl(r, Address(rsp, (6 + i) * wordSize));
152 152 __ bind(done);
153 153 }
154 154
155 155 // Now handle integrals. Only do c_rarg1 if not static.
156 156 __ movl(c_rarg3, Address(rbx, methodOopDesc::access_flags_offset()));
157 157 __ testl(c_rarg3, JVM_ACC_STATIC);
158 158 __ cmovptr(Assembler::zero, c_rarg1, Address(rsp, 0));
159 159
160 160 __ movptr(c_rarg2, Address(rsp, wordSize));
161 161 __ movptr(c_rarg3, Address(rsp, 2 * wordSize));
162 162 __ movptr(c_rarg4, Address(rsp, 3 * wordSize));
163 163 __ movptr(c_rarg5, Address(rsp, 4 * wordSize));
164 164
165 165 // restore rsp
166 166 __ addptr(rsp, 14 * wordSize);
167 167
168 168 __ ret(0);
169 169
170 170 return entry;
171 171 }
172 172 #endif
173 173
174 174
175 175 //
176 176 // Various method entries
177 177 //
178 178
179 179 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
180 180
181 181 // rbx,: methodOop
182 182 // rcx: scratrch
183 183 // r13: sender sp
184 184
185 185 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
186 186
187 187 address entry_point = __ pc();
188 188
189 189 // These don't need a safepoint check because they aren't virtually
190 190 // callable. We won't enter these intrinsics from compiled code.
191 191 // If in the future we added an intrinsic which was virtually callable
192 192 // we'd have to worry about how to safepoint so that this code is used.
193 193
194 194 // mathematical functions inlined by compiler
195 195 // (interpreter must provide identical implementation
196 196 // in order to avoid monotonicity bugs when switching
197 197 // from interpreter to compiler in the middle of some
198 198 // computation)
199 199 //
200 200 // stack: [ ret adr ] <-- rsp
201 201 // [ lo(arg) ]
202 202 // [ hi(arg) ]
203 203 //
204 204
205 205 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
206 206 // native methods. Interpreter::method_kind(...) does a check for
207 207 // native methods first before checking for intrinsic methods and
208 208 // thus will never select this entry point. Make sure it is not
209 209 // called accidentally since the SharedRuntime entry points will
210 210 // not work for JDK 1.2.
211 211 //
212 212 // We no longer need to check for JDK 1.2 since it's EOL'ed.
213 213 // The following check existed in pre 1.6 implementation,
214 214 // if (Universe::is_jdk12x_version()) {
215 215 // __ should_not_reach_here();
216 216 // }
217 217 // Universe::is_jdk12x_version() always returns false since
218 218 // the JDK version is not yet determined when this method is called.
219 219 // This method is called during interpreter_init() whereas
220 220 // JDK version is only determined when universe2_init() is called.
221 221
222 222 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
223 223 // java methods. Interpreter::method_kind(...) will select
224 224 // this entry point for the corresponding methods in JDK 1.3.
225 225 // get argument
226 226
227 227 if (kind == Interpreter::java_lang_math_sqrt) {
228 228 __ sqrtsd(xmm0, Address(rsp, wordSize));
229 229 } else {
230 230 __ fld_d(Address(rsp, wordSize));
231 231 switch (kind) {
232 232 case Interpreter::java_lang_math_sin :
233 233 __ trigfunc('s');
234 234 break;
235 235 case Interpreter::java_lang_math_cos :
236 236 __ trigfunc('c');
237 237 break;
238 238 case Interpreter::java_lang_math_tan :
239 239 __ trigfunc('t');
240 240 break;
241 241 case Interpreter::java_lang_math_abs:
242 242 __ fabs();
243 243 break;
244 244 case Interpreter::java_lang_math_log:
245 245 __ flog();
246 246 break;
247 247 case Interpreter::java_lang_math_log10:
248 248 __ flog10();
249 249 break;
250 250 default :
251 251 ShouldNotReachHere();
252 252 }
253 253
254 254 // return double result in xmm0 for interpreter and compilers.
255 255 __ subptr(rsp, 2*wordSize);
256 256 // Round to 64bit precision
257 257 __ fstp_d(Address(rsp, 0));
258 258 __ movdbl(xmm0, Address(rsp, 0));
259 259 __ addptr(rsp, 2*wordSize);
260 260 }
261 261
262 262
263 263 __ pop(rax);
264 264 __ mov(rsp, r13);
265 265 __ jmp(rax);
266 266
267 267 return entry_point;
268 268 }
269 269
↓ open down ↓ |
269 lines elided |
↑ open up ↑ |
270 270
271 271 // Abstract method entry
272 272 // Attempt to execute abstract method. Throw exception
273 273 address InterpreterGenerator::generate_abstract_entry(void) {
274 274 // rbx: methodOop
275 275 // r13: sender SP
276 276
277 277 address entry_point = __ pc();
278 278
279 279 // abstract method entry
280 - // remove return address. Not really needed, since exception
281 - // handling throws away expression stack
282 - __ pop(rbx);
283 280
284 - // adjust stack to what a normal return would do
285 - __ mov(rsp, r13);
281 + // pop return address, reset last_sp to NULL
282 + __ empty_expression_stack();
283 + __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
284 + __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
286 285
287 286 // throw exception
288 287 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
289 288 InterpreterRuntime::throw_AbstractMethodError));
290 289 // the call_VM checks for exception, so we should never return here.
291 290 __ should_not_reach_here();
292 291
293 292 return entry_point;
294 293 }
295 294
296 295
297 296 // Method handle invoker
298 297 // Dispatch a method of the form java.dyn.MethodHandles::invoke(...)
299 298 address InterpreterGenerator::generate_method_handle_entry(void) {
300 299 if (!EnableMethodHandles) {
301 300 return generate_abstract_entry();
302 301 }
303 - return generate_abstract_entry(); //6815692//
302 +
303 + address entry_point = MethodHandles::generate_method_handle_interpreter_entry(_masm);
304 +
305 + return entry_point;
304 306 }
305 307
306 308
307 309 // Empty method, generate a very fast return.
308 310
309 311 address InterpreterGenerator::generate_empty_entry(void) {
310 312 // rbx: methodOop
311 313 // r13: sender sp must set sp to this value on return
312 314
313 315 if (!UseFastEmptyMethods) {
314 316 return NULL;
315 317 }
316 318
317 319 address entry_point = __ pc();
318 320
319 321 // If we need a safepoint check, generate full interpreter entry.
320 322 Label slow_path;
321 323 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
322 324 SafepointSynchronize::_not_synchronized);
323 325 __ jcc(Assembler::notEqual, slow_path);
324 326
325 327 // do nothing for empty methods (do not even increment invocation counter)
326 328 // Code: _return
327 329 // _return
328 330 // return w/o popping parameters
329 331 __ pop(rax);
330 332 __ mov(rsp, r13);
331 333 __ jmp(rax);
332 334
333 335 __ bind(slow_path);
334 336 (void) generate_normal_entry(false);
335 337 return entry_point;
336 338
337 339 }
338 340
339 341 // This method tells the deoptimizer how big an interpreted frame must be:
340 342 int AbstractInterpreter::size_activation(methodOop method,
341 343 int tempcount,
342 344 int popframe_extra_args,
343 345 int moncount,
344 346 int callee_param_count,
345 347 int callee_locals,
346 348 bool is_top_frame) {
347 349 return layout_activation(method,
348 350 tempcount, popframe_extra_args, moncount,
349 351 callee_param_count, callee_locals,
350 352 (frame*) NULL, (frame*) NULL, is_top_frame);
351 353 }
352 354
353 355 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
354 356
355 357 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
356 358 // the days we had adapter frames. When we deoptimize a situation where a
357 359 // compiled caller calls a compiled caller will have registers it expects
358 360 // to survive the call to the callee. If we deoptimize the callee the only
359 361 // way we can restore these registers is to have the oldest interpreter
360 362 // frame that we create restore these values. That is what this routine
361 363 // will accomplish.
362 364
363 365 // At the moment we have modified c2 to not have any callee save registers
364 366 // so this problem does not exist and this routine is just a place holder.
365 367
366 368 assert(f->is_interpreted_frame(), "must be interpreted");
367 369 }
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX