Print this page
Split |
Split |
Close |
Expand all |
Collapse all |
--- old/src/cpu/sparc/vm/templateTable_sparc.cpp
+++ new/src/cpu/sparc/vm/templateTable_sparc.cpp
1 1 /*
2 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "interpreter/interpreter.hpp"
27 27 #include "interpreter/interpreterRuntime.hpp"
28 28 #include "interpreter/templateTable.hpp"
29 29 #include "memory/universe.inline.hpp"
30 30 #include "oops/methodDataOop.hpp"
31 31 #include "oops/objArrayKlass.hpp"
32 32 #include "oops/oop.inline.hpp"
33 33 #include "prims/methodHandles.hpp"
34 34 #include "runtime/sharedRuntime.hpp"
35 35 #include "runtime/stubRoutines.hpp"
36 36 #include "runtime/synchronizer.hpp"
37 37
38 38 #ifndef CC_INTERP
39 39 #define __ _masm->
40 40
41 41 // Misc helpers
42 42
43 43 // Do an oop store like *(base + index + offset) = val
44 44 // index can be noreg,
45 45 static void do_oop_store(InterpreterMacroAssembler* _masm,
46 46 Register base,
47 47 Register index,
48 48 int offset,
49 49 Register val,
50 50 Register tmp,
51 51 BarrierSet::Name barrier,
52 52 bool precise) {
53 53 assert(tmp != val && tmp != base && tmp != index, "register collision");
54 54 assert(index == noreg || offset == 0, "only one offset");
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
55 55 switch (barrier) {
56 56 #ifndef SERIALGC
57 57 case BarrierSet::G1SATBCT:
58 58 case BarrierSet::G1SATBCTLogging:
59 59 {
60 60 // Load and record the previous value.
61 61 __ g1_write_barrier_pre(base, index, offset,
62 62 noreg /* pre_val */,
63 63 tmp, true /*preserve_o_regs*/);
64 64
65 + // G1 barrier needs uncompressed oop for region cross check.
66 + Register new_val = val;
67 + if (UseCompressedOops && val != G0) {
68 + new_val = tmp;
69 + __ mov(val, new_val);
70 + }
71 +
65 72 if (index == noreg ) {
66 73 assert(Assembler::is_simm13(offset), "fix this code");
67 74 __ store_heap_oop(val, base, offset);
68 75 } else {
69 76 __ store_heap_oop(val, base, index);
70 77 }
71 78
72 79 // No need for post barrier if storing NULL
73 80 if (val != G0) {
74 81 if (precise) {
75 82 if (index == noreg) {
76 83 __ add(base, offset, base);
77 84 } else {
78 85 __ add(base, index, base);
79 86 }
80 87 }
81 - __ g1_write_barrier_post(base, val, tmp);
88 + __ g1_write_barrier_post(base, new_val, tmp);
82 89 }
83 90 }
84 91 break;
85 92 #endif // SERIALGC
86 93 case BarrierSet::CardTableModRef:
87 94 case BarrierSet::CardTableExtension:
88 95 {
89 96 if (index == noreg ) {
90 97 assert(Assembler::is_simm13(offset), "fix this code");
91 98 __ store_heap_oop(val, base, offset);
92 99 } else {
93 100 __ store_heap_oop(val, base, index);
94 101 }
95 102 // No need for post barrier if storing NULL
96 103 if (val != G0) {
97 104 if (precise) {
98 105 if (index == noreg) {
99 106 __ add(base, offset, base);
100 107 } else {
101 108 __ add(base, index, base);
102 109 }
103 110 }
104 111 __ card_write_barrier_post(base, val, tmp);
105 112 }
106 113 }
107 114 break;
108 115 case BarrierSet::ModRef:
109 116 case BarrierSet::Other:
110 117 ShouldNotReachHere();
111 118 break;
112 119 default :
113 120 ShouldNotReachHere();
114 121
115 122 }
116 123 }
117 124
118 125
119 126 //----------------------------------------------------------------------------------------------------
120 127 // Platform-dependent initialization
121 128
122 129 void TemplateTable::pd_initialize() {
123 130 // (none)
124 131 }
125 132
126 133
127 134 //----------------------------------------------------------------------------------------------------
128 135 // Condition conversion
129 136 Assembler::Condition ccNot(TemplateTable::Condition cc) {
130 137 switch (cc) {
131 138 case TemplateTable::equal : return Assembler::notEqual;
132 139 case TemplateTable::not_equal : return Assembler::equal;
133 140 case TemplateTable::less : return Assembler::greaterEqual;
134 141 case TemplateTable::less_equal : return Assembler::greater;
135 142 case TemplateTable::greater : return Assembler::lessEqual;
136 143 case TemplateTable::greater_equal: return Assembler::less;
137 144 }
138 145 ShouldNotReachHere();
139 146 return Assembler::zero;
140 147 }
141 148
142 149 //----------------------------------------------------------------------------------------------------
143 150 // Miscelaneous helper routines
144 151
145 152
146 153 Address TemplateTable::at_bcp(int offset) {
147 154 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
148 155 return Address(Lbcp, offset);
149 156 }
150 157
151 158
152 159 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
153 160 Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
154 161 int byte_no) {
155 162 // With sharing on, may need to test methodOop flag.
156 163 if (!RewriteBytecodes) return;
157 164 Label L_patch_done;
158 165
159 166 switch (bc) {
160 167 case Bytecodes::_fast_aputfield:
161 168 case Bytecodes::_fast_bputfield:
162 169 case Bytecodes::_fast_cputfield:
163 170 case Bytecodes::_fast_dputfield:
164 171 case Bytecodes::_fast_fputfield:
165 172 case Bytecodes::_fast_iputfield:
166 173 case Bytecodes::_fast_lputfield:
167 174 case Bytecodes::_fast_sputfield:
168 175 {
169 176 // We skip bytecode quickening for putfield instructions when
170 177 // the put_code written to the constant pool cache is zero.
171 178 // This is required so that every execution of this instruction
172 179 // calls out to InterpreterRuntime::resolve_get_put to do
173 180 // additional, required work.
174 181 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
175 182 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
176 183 __ get_cache_and_index_and_bytecode_at_bcp(bc_reg, temp_reg, temp_reg, byte_no, 1);
177 184 __ set(bc, bc_reg);
178 185 __ cmp_and_br_short(temp_reg, 0, Assembler::equal, Assembler::pn, L_patch_done); // don't patch
179 186 }
180 187 break;
181 188 default:
182 189 assert(byte_no == -1, "sanity");
183 190 if (load_bc_into_bc_reg) {
184 191 __ set(bc, bc_reg);
185 192 }
186 193 }
187 194
188 195 if (JvmtiExport::can_post_breakpoint()) {
189 196 Label L_fast_patch;
190 197 __ ldub(at_bcp(0), temp_reg);
191 198 __ cmp_and_br_short(temp_reg, Bytecodes::_breakpoint, Assembler::notEqual, Assembler::pt, L_fast_patch);
192 199 // perform the quickening, slowly, in the bowels of the breakpoint table
193 200 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), Lmethod, Lbcp, bc_reg);
194 201 __ ba_short(L_patch_done);
195 202 __ bind(L_fast_patch);
196 203 }
197 204
198 205 #ifdef ASSERT
199 206 Bytecodes::Code orig_bytecode = Bytecodes::java_code(bc);
200 207 Label L_okay;
201 208 __ ldub(at_bcp(0), temp_reg);
202 209 __ cmp(temp_reg, orig_bytecode);
203 210 __ br(Assembler::equal, false, Assembler::pt, L_okay);
204 211 __ delayed()->cmp(temp_reg, bc_reg);
205 212 __ br(Assembler::equal, false, Assembler::pt, L_okay);
206 213 __ delayed()->nop();
207 214 __ stop("patching the wrong bytecode");
208 215 __ bind(L_okay);
209 216 #endif
210 217
211 218 // patch bytecode
212 219 __ stb(bc_reg, at_bcp(0));
213 220 __ bind(L_patch_done);
214 221 }
215 222
216 223 //----------------------------------------------------------------------------------------------------
217 224 // Individual instructions
218 225
219 226 void TemplateTable::nop() {
220 227 transition(vtos, vtos);
221 228 // nothing to do
222 229 }
223 230
224 231 void TemplateTable::shouldnotreachhere() {
225 232 transition(vtos, vtos);
226 233 __ stop("shouldnotreachhere bytecode");
227 234 }
228 235
229 236 void TemplateTable::aconst_null() {
230 237 transition(vtos, atos);
231 238 __ clr(Otos_i);
232 239 }
233 240
234 241
235 242 void TemplateTable::iconst(int value) {
236 243 transition(vtos, itos);
237 244 __ set(value, Otos_i);
238 245 }
239 246
240 247
241 248 void TemplateTable::lconst(int value) {
242 249 transition(vtos, ltos);
243 250 assert(value >= 0, "check this code");
244 251 #ifdef _LP64
245 252 __ set(value, Otos_l);
246 253 #else
247 254 __ set(value, Otos_l2);
248 255 __ clr( Otos_l1);
249 256 #endif
250 257 }
251 258
252 259
253 260 void TemplateTable::fconst(int value) {
254 261 transition(vtos, ftos);
255 262 static float zero = 0.0, one = 1.0, two = 2.0;
256 263 float* p;
257 264 switch( value ) {
258 265 default: ShouldNotReachHere();
259 266 case 0: p = &zero; break;
260 267 case 1: p = &one; break;
261 268 case 2: p = &two; break;
262 269 }
263 270 AddressLiteral a(p);
264 271 __ sethi(a, G3_scratch);
265 272 __ ldf(FloatRegisterImpl::S, G3_scratch, a.low10(), Ftos_f);
266 273 }
267 274
268 275
269 276 void TemplateTable::dconst(int value) {
270 277 transition(vtos, dtos);
271 278 static double zero = 0.0, one = 1.0;
272 279 double* p;
273 280 switch( value ) {
274 281 default: ShouldNotReachHere();
275 282 case 0: p = &zero; break;
276 283 case 1: p = &one; break;
277 284 }
278 285 AddressLiteral a(p);
279 286 __ sethi(a, G3_scratch);
280 287 __ ldf(FloatRegisterImpl::D, G3_scratch, a.low10(), Ftos_d);
281 288 }
282 289
283 290
284 291 // %%%%% Should factore most snippet templates across platforms
285 292
286 293 void TemplateTable::bipush() {
287 294 transition(vtos, itos);
288 295 __ ldsb( at_bcp(1), Otos_i );
289 296 }
290 297
291 298 void TemplateTable::sipush() {
292 299 transition(vtos, itos);
293 300 __ get_2_byte_integer_at_bcp(1, G3_scratch, Otos_i, InterpreterMacroAssembler::Signed);
294 301 }
295 302
296 303 void TemplateTable::ldc(bool wide) {
297 304 transition(vtos, vtos);
298 305 Label call_ldc, notInt, isString, notString, notClass, exit;
299 306
300 307 if (wide) {
301 308 __ get_2_byte_integer_at_bcp(1, G3_scratch, O1, InterpreterMacroAssembler::Unsigned);
302 309 } else {
303 310 __ ldub(Lbcp, 1, O1);
304 311 }
305 312 __ get_cpool_and_tags(O0, O2);
306 313
307 314 const int base_offset = constantPoolOopDesc::header_size() * wordSize;
308 315 const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
309 316
310 317 // get type from tags
311 318 __ add(O2, tags_offset, O2);
312 319 __ ldub(O2, O1, O2);
313 320 // unresolved string? If so, must resolve
314 321 __ cmp_and_brx_short(O2, JVM_CONSTANT_UnresolvedString, Assembler::equal, Assembler::pt, call_ldc);
315 322
316 323 // unresolved class? If so, must resolve
317 324 __ cmp_and_brx_short(O2, JVM_CONSTANT_UnresolvedClass, Assembler::equal, Assembler::pt, call_ldc);
318 325
319 326 // unresolved class in error state
320 327 __ cmp_and_brx_short(O2, JVM_CONSTANT_UnresolvedClassInError, Assembler::equal, Assembler::pn, call_ldc);
321 328
322 329 __ cmp(O2, JVM_CONSTANT_Class); // need to call vm to get java mirror of the class
323 330 __ brx(Assembler::notEqual, true, Assembler::pt, notClass);
324 331 __ delayed()->add(O0, base_offset, O0);
325 332
326 333 __ bind(call_ldc);
327 334 __ set(wide, O1);
328 335 call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), O1);
329 336 __ push(atos);
330 337 __ ba_short(exit);
331 338
332 339 __ bind(notClass);
333 340 // __ add(O0, base_offset, O0);
334 341 __ sll(O1, LogBytesPerWord, O1);
335 342 __ cmp(O2, JVM_CONSTANT_Integer);
336 343 __ brx(Assembler::notEqual, true, Assembler::pt, notInt);
337 344 __ delayed()->cmp(O2, JVM_CONSTANT_String);
338 345 __ ld(O0, O1, Otos_i);
339 346 __ push(itos);
340 347 __ ba_short(exit);
341 348
342 349 __ bind(notInt);
343 350 // __ cmp(O2, JVM_CONSTANT_String);
344 351 __ brx(Assembler::equal, true, Assembler::pt, isString);
345 352 __ delayed()->cmp(O2, JVM_CONSTANT_Object);
346 353 __ brx(Assembler::notEqual, true, Assembler::pt, notString);
347 354 __ delayed()->ldf(FloatRegisterImpl::S, O0, O1, Ftos_f);
348 355 __ bind(isString);
349 356 __ ld_ptr(O0, O1, Otos_i);
350 357 __ verify_oop(Otos_i);
351 358 __ push(atos);
352 359 __ ba_short(exit);
353 360
354 361 __ bind(notString);
355 362 // __ ldf(FloatRegisterImpl::S, O0, O1, Ftos_f);
356 363 __ push(ftos);
357 364
358 365 __ bind(exit);
359 366 }
360 367
361 368 // Fast path for caching oop constants.
362 369 // %%% We should use this to handle Class and String constants also.
363 370 // %%% It will simplify the ldc/primitive path considerably.
364 371 void TemplateTable::fast_aldc(bool wide) {
365 372 transition(vtos, atos);
366 373
367 374 if (!EnableInvokeDynamic) {
368 375 // We should not encounter this bytecode if !EnableInvokeDynamic.
369 376 // The verifier will stop it. However, if we get past the verifier,
370 377 // this will stop the thread in a reasonable way, without crashing the JVM.
371 378 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
372 379 InterpreterRuntime::throw_IncompatibleClassChangeError));
373 380 // the call_VM checks for exception, so we should never return here.
374 381 __ should_not_reach_here();
375 382 return;
376 383 }
377 384
378 385 Register Rcache = G3_scratch;
379 386 Register Rscratch = G4_scratch;
380 387
381 388 resolve_cache_and_index(f12_oop, Otos_i, Rcache, Rscratch, wide ? sizeof(u2) : sizeof(u1));
382 389
383 390 __ verify_oop(Otos_i);
384 391
385 392 Label L_done;
386 393 const Register Rcon_klass = G3_scratch; // same as Rcache
387 394 const Register Rarray_klass = G4_scratch; // same as Rscratch
388 395 __ load_klass(Otos_i, Rcon_klass);
389 396 AddressLiteral array_klass_addr((address)Universe::systemObjArrayKlassObj_addr());
390 397 __ load_contents(array_klass_addr, Rarray_klass);
391 398 __ cmp_and_brx_short(Rarray_klass, Rcon_klass, Assembler::notEqual, Assembler::pt, L_done);
392 399 __ ld(Address(Otos_i, arrayOopDesc::length_offset_in_bytes()), Rcon_klass);
393 400 __ tst(Rcon_klass);
394 401 __ brx(Assembler::zero, true, Assembler::pt, L_done);
395 402 __ delayed()->clr(Otos_i); // executed only if branch is taken
396 403
397 404 // Load the exception from the system-array which wraps it:
398 405 __ load_heap_oop(Otos_i, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Otos_i);
399 406 __ throw_if_not_x(Assembler::never, Interpreter::throw_exception_entry(), G3_scratch);
400 407
401 408 __ bind(L_done);
402 409 }
403 410
404 411 void TemplateTable::ldc2_w() {
405 412 transition(vtos, vtos);
406 413 Label retry, resolved, Long, exit;
407 414
408 415 __ bind(retry);
409 416 __ get_2_byte_integer_at_bcp(1, G3_scratch, O1, InterpreterMacroAssembler::Unsigned);
410 417 __ get_cpool_and_tags(O0, O2);
411 418
412 419 const int base_offset = constantPoolOopDesc::header_size() * wordSize;
413 420 const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
414 421 // get type from tags
415 422 __ add(O2, tags_offset, O2);
416 423 __ ldub(O2, O1, O2);
417 424
418 425 __ sll(O1, LogBytesPerWord, O1);
419 426 __ add(O0, O1, G3_scratch);
420 427
421 428 __ cmp_and_brx_short(O2, JVM_CONSTANT_Double, Assembler::notEqual, Assembler::pt, Long);
422 429 // A double can be placed at word-aligned locations in the constant pool.
423 430 // Check out Conversions.java for an example.
424 431 // Also constantPoolOopDesc::header_size() is 20, which makes it very difficult
425 432 // to double-align double on the constant pool. SG, 11/7/97
426 433 #ifdef _LP64
427 434 __ ldf(FloatRegisterImpl::D, G3_scratch, base_offset, Ftos_d);
428 435 #else
429 436 FloatRegister f = Ftos_d;
430 437 __ ldf(FloatRegisterImpl::S, G3_scratch, base_offset, f);
431 438 __ ldf(FloatRegisterImpl::S, G3_scratch, base_offset + sizeof(jdouble)/2,
432 439 f->successor());
433 440 #endif
434 441 __ push(dtos);
435 442 __ ba_short(exit);
436 443
437 444 __ bind(Long);
438 445 #ifdef _LP64
439 446 __ ldx(G3_scratch, base_offset, Otos_l);
440 447 #else
441 448 __ ld(G3_scratch, base_offset, Otos_l);
442 449 __ ld(G3_scratch, base_offset + sizeof(jlong)/2, Otos_l->successor());
443 450 #endif
444 451 __ push(ltos);
445 452
446 453 __ bind(exit);
447 454 }
448 455
449 456
450 457 void TemplateTable::locals_index(Register reg, int offset) {
451 458 __ ldub( at_bcp(offset), reg );
452 459 }
453 460
454 461
455 462 void TemplateTable::locals_index_wide(Register reg) {
456 463 // offset is 2, not 1, because Lbcp points to wide prefix code
457 464 __ get_2_byte_integer_at_bcp(2, G4_scratch, reg, InterpreterMacroAssembler::Unsigned);
458 465 }
459 466
460 467 void TemplateTable::iload() {
461 468 transition(vtos, itos);
462 469 // Rewrite iload,iload pair into fast_iload2
463 470 // iload,caload pair into fast_icaload
464 471 if (RewriteFrequentPairs) {
465 472 Label rewrite, done;
466 473
467 474 // get next byte
468 475 __ ldub(at_bcp(Bytecodes::length_for(Bytecodes::_iload)), G3_scratch);
469 476
470 477 // if _iload, wait to rewrite to iload2. We only want to rewrite the
471 478 // last two iloads in a pair. Comparing against fast_iload means that
472 479 // the next bytecode is neither an iload or a caload, and therefore
473 480 // an iload pair.
474 481 __ cmp_and_br_short(G3_scratch, (int)Bytecodes::_iload, Assembler::equal, Assembler::pn, done);
475 482
476 483 __ cmp(G3_scratch, (int)Bytecodes::_fast_iload);
477 484 __ br(Assembler::equal, false, Assembler::pn, rewrite);
478 485 __ delayed()->set(Bytecodes::_fast_iload2, G4_scratch);
479 486
480 487 __ cmp(G3_scratch, (int)Bytecodes::_caload);
481 488 __ br(Assembler::equal, false, Assembler::pn, rewrite);
482 489 __ delayed()->set(Bytecodes::_fast_icaload, G4_scratch);
483 490
484 491 __ set(Bytecodes::_fast_iload, G4_scratch); // don't check again
485 492 // rewrite
486 493 // G4_scratch: fast bytecode
487 494 __ bind(rewrite);
488 495 patch_bytecode(Bytecodes::_iload, G4_scratch, G3_scratch, false);
489 496 __ bind(done);
490 497 }
491 498
492 499 // Get the local value into tos
493 500 locals_index(G3_scratch);
494 501 __ access_local_int( G3_scratch, Otos_i );
495 502 }
496 503
497 504 void TemplateTable::fast_iload2() {
498 505 transition(vtos, itos);
499 506 locals_index(G3_scratch);
500 507 __ access_local_int( G3_scratch, Otos_i );
501 508 __ push_i();
502 509 locals_index(G3_scratch, 3); // get next bytecode's local index.
503 510 __ access_local_int( G3_scratch, Otos_i );
504 511 }
505 512
506 513 void TemplateTable::fast_iload() {
507 514 transition(vtos, itos);
508 515 locals_index(G3_scratch);
509 516 __ access_local_int( G3_scratch, Otos_i );
510 517 }
511 518
512 519 void TemplateTable::lload() {
513 520 transition(vtos, ltos);
514 521 locals_index(G3_scratch);
515 522 __ access_local_long( G3_scratch, Otos_l );
516 523 }
517 524
518 525
519 526 void TemplateTable::fload() {
520 527 transition(vtos, ftos);
521 528 locals_index(G3_scratch);
522 529 __ access_local_float( G3_scratch, Ftos_f );
523 530 }
524 531
525 532
526 533 void TemplateTable::dload() {
527 534 transition(vtos, dtos);
528 535 locals_index(G3_scratch);
529 536 __ access_local_double( G3_scratch, Ftos_d );
530 537 }
531 538
532 539
533 540 void TemplateTable::aload() {
534 541 transition(vtos, atos);
535 542 locals_index(G3_scratch);
536 543 __ access_local_ptr( G3_scratch, Otos_i);
537 544 }
538 545
539 546
540 547 void TemplateTable::wide_iload() {
541 548 transition(vtos, itos);
542 549 locals_index_wide(G3_scratch);
543 550 __ access_local_int( G3_scratch, Otos_i );
544 551 }
545 552
546 553
547 554 void TemplateTable::wide_lload() {
548 555 transition(vtos, ltos);
549 556 locals_index_wide(G3_scratch);
550 557 __ access_local_long( G3_scratch, Otos_l );
551 558 }
552 559
553 560
554 561 void TemplateTable::wide_fload() {
555 562 transition(vtos, ftos);
556 563 locals_index_wide(G3_scratch);
557 564 __ access_local_float( G3_scratch, Ftos_f );
558 565 }
559 566
560 567
561 568 void TemplateTable::wide_dload() {
562 569 transition(vtos, dtos);
563 570 locals_index_wide(G3_scratch);
564 571 __ access_local_double( G3_scratch, Ftos_d );
565 572 }
566 573
567 574
568 575 void TemplateTable::wide_aload() {
569 576 transition(vtos, atos);
570 577 locals_index_wide(G3_scratch);
571 578 __ access_local_ptr( G3_scratch, Otos_i );
572 579 __ verify_oop(Otos_i);
573 580 }
574 581
575 582
576 583 void TemplateTable::iaload() {
577 584 transition(itos, itos);
578 585 // Otos_i: index
579 586 // tos: array
580 587 __ index_check(O2, Otos_i, LogBytesPerInt, G3_scratch, O3);
581 588 __ ld(O3, arrayOopDesc::base_offset_in_bytes(T_INT), Otos_i);
582 589 }
583 590
584 591
585 592 void TemplateTable::laload() {
586 593 transition(itos, ltos);
587 594 // Otos_i: index
588 595 // O2: array
589 596 __ index_check(O2, Otos_i, LogBytesPerLong, G3_scratch, O3);
590 597 __ ld_long(O3, arrayOopDesc::base_offset_in_bytes(T_LONG), Otos_l);
591 598 }
592 599
593 600
594 601 void TemplateTable::faload() {
595 602 transition(itos, ftos);
596 603 // Otos_i: index
597 604 // O2: array
598 605 __ index_check(O2, Otos_i, LogBytesPerInt, G3_scratch, O3);
599 606 __ ldf(FloatRegisterImpl::S, O3, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Ftos_f);
600 607 }
601 608
602 609
603 610 void TemplateTable::daload() {
604 611 transition(itos, dtos);
605 612 // Otos_i: index
606 613 // O2: array
607 614 __ index_check(O2, Otos_i, LogBytesPerLong, G3_scratch, O3);
608 615 __ ldf(FloatRegisterImpl::D, O3, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Ftos_d);
609 616 }
610 617
611 618
612 619 void TemplateTable::aaload() {
613 620 transition(itos, atos);
614 621 // Otos_i: index
615 622 // tos: array
616 623 __ index_check(O2, Otos_i, UseCompressedOops ? 2 : LogBytesPerWord, G3_scratch, O3);
617 624 __ load_heap_oop(O3, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Otos_i);
618 625 __ verify_oop(Otos_i);
619 626 }
620 627
621 628
622 629 void TemplateTable::baload() {
623 630 transition(itos, itos);
624 631 // Otos_i: index
625 632 // tos: array
626 633 __ index_check(O2, Otos_i, 0, G3_scratch, O3);
627 634 __ ldsb(O3, arrayOopDesc::base_offset_in_bytes(T_BYTE), Otos_i);
628 635 }
629 636
630 637
631 638 void TemplateTable::caload() {
632 639 transition(itos, itos);
633 640 // Otos_i: index
634 641 // tos: array
635 642 __ index_check(O2, Otos_i, LogBytesPerShort, G3_scratch, O3);
636 643 __ lduh(O3, arrayOopDesc::base_offset_in_bytes(T_CHAR), Otos_i);
637 644 }
638 645
639 646 void TemplateTable::fast_icaload() {
640 647 transition(vtos, itos);
641 648 // Otos_i: index
642 649 // tos: array
643 650 locals_index(G3_scratch);
644 651 __ access_local_int( G3_scratch, Otos_i );
645 652 __ index_check(O2, Otos_i, LogBytesPerShort, G3_scratch, O3);
646 653 __ lduh(O3, arrayOopDesc::base_offset_in_bytes(T_CHAR), Otos_i);
647 654 }
648 655
649 656
650 657 void TemplateTable::saload() {
651 658 transition(itos, itos);
652 659 // Otos_i: index
653 660 // tos: array
654 661 __ index_check(O2, Otos_i, LogBytesPerShort, G3_scratch, O3);
655 662 __ ldsh(O3, arrayOopDesc::base_offset_in_bytes(T_SHORT), Otos_i);
656 663 }
657 664
658 665
659 666 void TemplateTable::iload(int n) {
660 667 transition(vtos, itos);
661 668 __ ld( Llocals, Interpreter::local_offset_in_bytes(n), Otos_i );
662 669 }
663 670
664 671
665 672 void TemplateTable::lload(int n) {
666 673 transition(vtos, ltos);
667 674 assert(n+1 < Argument::n_register_parameters, "would need more code");
668 675 __ load_unaligned_long(Llocals, Interpreter::local_offset_in_bytes(n+1), Otos_l);
669 676 }
670 677
671 678
672 679 void TemplateTable::fload(int n) {
673 680 transition(vtos, ftos);
674 681 assert(n < Argument::n_register_parameters, "would need more code");
675 682 __ ldf( FloatRegisterImpl::S, Llocals, Interpreter::local_offset_in_bytes(n), Ftos_f );
676 683 }
677 684
678 685
679 686 void TemplateTable::dload(int n) {
680 687 transition(vtos, dtos);
681 688 FloatRegister dst = Ftos_d;
682 689 __ load_unaligned_double(Llocals, Interpreter::local_offset_in_bytes(n+1), dst);
683 690 }
684 691
685 692
686 693 void TemplateTable::aload(int n) {
687 694 transition(vtos, atos);
688 695 __ ld_ptr( Llocals, Interpreter::local_offset_in_bytes(n), Otos_i );
689 696 }
690 697
691 698
692 699 void TemplateTable::aload_0() {
693 700 transition(vtos, atos);
694 701
695 702 // According to bytecode histograms, the pairs:
696 703 //
697 704 // _aload_0, _fast_igetfield (itos)
698 705 // _aload_0, _fast_agetfield (atos)
699 706 // _aload_0, _fast_fgetfield (ftos)
700 707 //
701 708 // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
702 709 // bytecode checks the next bytecode and then rewrites the current
703 710 // bytecode into a pair bytecode; otherwise it rewrites the current
704 711 // bytecode into _fast_aload_0 that doesn't do the pair check anymore.
705 712 //
706 713 if (RewriteFrequentPairs) {
707 714 Label rewrite, done;
708 715
709 716 // get next byte
710 717 __ ldub(at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)), G3_scratch);
711 718
712 719 // do actual aload_0
713 720 aload(0);
714 721
715 722 // if _getfield then wait with rewrite
716 723 __ cmp_and_br_short(G3_scratch, (int)Bytecodes::_getfield, Assembler::equal, Assembler::pn, done);
717 724
718 725 // if _igetfield then rewrite to _fast_iaccess_0
719 726 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
720 727 __ cmp(G3_scratch, (int)Bytecodes::_fast_igetfield);
721 728 __ br(Assembler::equal, false, Assembler::pn, rewrite);
722 729 __ delayed()->set(Bytecodes::_fast_iaccess_0, G4_scratch);
723 730
724 731 // if _agetfield then rewrite to _fast_aaccess_0
725 732 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
726 733 __ cmp(G3_scratch, (int)Bytecodes::_fast_agetfield);
727 734 __ br(Assembler::equal, false, Assembler::pn, rewrite);
728 735 __ delayed()->set(Bytecodes::_fast_aaccess_0, G4_scratch);
729 736
730 737 // if _fgetfield then rewrite to _fast_faccess_0
731 738 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
732 739 __ cmp(G3_scratch, (int)Bytecodes::_fast_fgetfield);
733 740 __ br(Assembler::equal, false, Assembler::pn, rewrite);
734 741 __ delayed()->set(Bytecodes::_fast_faccess_0, G4_scratch);
735 742
736 743 // else rewrite to _fast_aload0
737 744 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
738 745 __ set(Bytecodes::_fast_aload_0, G4_scratch);
739 746
740 747 // rewrite
741 748 // G4_scratch: fast bytecode
742 749 __ bind(rewrite);
743 750 patch_bytecode(Bytecodes::_aload_0, G4_scratch, G3_scratch, false);
744 751 __ bind(done);
745 752 } else {
746 753 aload(0);
747 754 }
748 755 }
749 756
750 757
751 758 void TemplateTable::istore() {
752 759 transition(itos, vtos);
753 760 locals_index(G3_scratch);
754 761 __ store_local_int( G3_scratch, Otos_i );
755 762 }
756 763
757 764
758 765 void TemplateTable::lstore() {
759 766 transition(ltos, vtos);
760 767 locals_index(G3_scratch);
761 768 __ store_local_long( G3_scratch, Otos_l );
762 769 }
763 770
764 771
765 772 void TemplateTable::fstore() {
766 773 transition(ftos, vtos);
767 774 locals_index(G3_scratch);
768 775 __ store_local_float( G3_scratch, Ftos_f );
769 776 }
770 777
771 778
772 779 void TemplateTable::dstore() {
773 780 transition(dtos, vtos);
774 781 locals_index(G3_scratch);
775 782 __ store_local_double( G3_scratch, Ftos_d );
776 783 }
777 784
778 785
779 786 void TemplateTable::astore() {
780 787 transition(vtos, vtos);
781 788 __ load_ptr(0, Otos_i);
782 789 __ inc(Lesp, Interpreter::stackElementSize);
783 790 __ verify_oop_or_return_address(Otos_i, G3_scratch);
784 791 locals_index(G3_scratch);
785 792 __ store_local_ptr(G3_scratch, Otos_i);
786 793 }
787 794
788 795
789 796 void TemplateTable::wide_istore() {
790 797 transition(vtos, vtos);
791 798 __ pop_i();
792 799 locals_index_wide(G3_scratch);
793 800 __ store_local_int( G3_scratch, Otos_i );
794 801 }
795 802
796 803
797 804 void TemplateTable::wide_lstore() {
798 805 transition(vtos, vtos);
799 806 __ pop_l();
800 807 locals_index_wide(G3_scratch);
801 808 __ store_local_long( G3_scratch, Otos_l );
802 809 }
803 810
804 811
805 812 void TemplateTable::wide_fstore() {
806 813 transition(vtos, vtos);
807 814 __ pop_f();
808 815 locals_index_wide(G3_scratch);
809 816 __ store_local_float( G3_scratch, Ftos_f );
810 817 }
811 818
812 819
813 820 void TemplateTable::wide_dstore() {
814 821 transition(vtos, vtos);
815 822 __ pop_d();
816 823 locals_index_wide(G3_scratch);
817 824 __ store_local_double( G3_scratch, Ftos_d );
818 825 }
819 826
820 827
821 828 void TemplateTable::wide_astore() {
822 829 transition(vtos, vtos);
823 830 __ load_ptr(0, Otos_i);
824 831 __ inc(Lesp, Interpreter::stackElementSize);
825 832 __ verify_oop_or_return_address(Otos_i, G3_scratch);
826 833 locals_index_wide(G3_scratch);
827 834 __ store_local_ptr(G3_scratch, Otos_i);
828 835 }
829 836
830 837
831 838 void TemplateTable::iastore() {
832 839 transition(itos, vtos);
833 840 __ pop_i(O2); // index
834 841 // Otos_i: val
835 842 // O3: array
836 843 __ index_check(O3, O2, LogBytesPerInt, G3_scratch, O2);
837 844 __ st(Otos_i, O2, arrayOopDesc::base_offset_in_bytes(T_INT));
838 845 }
839 846
840 847
841 848 void TemplateTable::lastore() {
842 849 transition(ltos, vtos);
843 850 __ pop_i(O2); // index
844 851 // Otos_l: val
845 852 // O3: array
846 853 __ index_check(O3, O2, LogBytesPerLong, G3_scratch, O2);
847 854 __ st_long(Otos_l, O2, arrayOopDesc::base_offset_in_bytes(T_LONG));
848 855 }
849 856
850 857
851 858 void TemplateTable::fastore() {
852 859 transition(ftos, vtos);
853 860 __ pop_i(O2); // index
854 861 // Ftos_f: val
855 862 // O3: array
856 863 __ index_check(O3, O2, LogBytesPerInt, G3_scratch, O2);
857 864 __ stf(FloatRegisterImpl::S, Ftos_f, O2, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
858 865 }
859 866
860 867
861 868 void TemplateTable::dastore() {
862 869 transition(dtos, vtos);
863 870 __ pop_i(O2); // index
864 871 // Fos_d: val
865 872 // O3: array
866 873 __ index_check(O3, O2, LogBytesPerLong, G3_scratch, O2);
867 874 __ stf(FloatRegisterImpl::D, Ftos_d, O2, arrayOopDesc::base_offset_in_bytes(T_DOUBLE));
868 875 }
869 876
870 877
871 878 void TemplateTable::aastore() {
872 879 Label store_ok, is_null, done;
873 880 transition(vtos, vtos);
874 881 __ ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(0), Otos_i);
875 882 __ ld(Lesp, Interpreter::expr_offset_in_bytes(1), O2); // get index
876 883 __ ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(2), O3); // get array
877 884 // Otos_i: val
878 885 // O2: index
879 886 // O3: array
880 887 __ verify_oop(Otos_i);
881 888 __ index_check_without_pop(O3, O2, UseCompressedOops ? 2 : LogBytesPerWord, G3_scratch, O1);
882 889
883 890 // do array store check - check for NULL value first
884 891 __ br_null_short( Otos_i, Assembler::pn, is_null );
885 892
886 893 __ load_klass(O3, O4); // get array klass
887 894 __ load_klass(Otos_i, O5); // get value klass
888 895
889 896 // do fast instanceof cache test
890 897
891 898 __ ld_ptr(O4, in_bytes(objArrayKlass::element_klass_offset()), O4);
892 899
893 900 assert(Otos_i == O0, "just checking");
894 901
895 902 // Otos_i: value
896 903 // O1: addr - offset
897 904 // O2: index
898 905 // O3: array
899 906 // O4: array element klass
900 907 // O5: value klass
901 908
902 909 // Address element(O1, 0, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
903 910
904 911 // Generate a fast subtype check. Branch to store_ok if no
905 912 // failure. Throw if failure.
906 913 __ gen_subtype_check( O5, O4, G3_scratch, G4_scratch, G1_scratch, store_ok );
907 914
908 915 // Not a subtype; so must throw exception
909 916 __ throw_if_not_x( Assembler::never, Interpreter::_throw_ArrayStoreException_entry, G3_scratch );
910 917
911 918 // Store is OK.
912 919 __ bind(store_ok);
913 920 do_oop_store(_masm, O1, noreg, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Otos_i, G3_scratch, _bs->kind(), true);
914 921
915 922 __ ba(done);
916 923 __ delayed()->inc(Lesp, 3* Interpreter::stackElementSize); // adj sp (pops array, index and value)
917 924
918 925 __ bind(is_null);
919 926 do_oop_store(_masm, O1, noreg, arrayOopDesc::base_offset_in_bytes(T_OBJECT), G0, G4_scratch, _bs->kind(), true);
920 927
921 928 __ profile_null_seen(G3_scratch);
922 929 __ inc(Lesp, 3* Interpreter::stackElementSize); // adj sp (pops array, index and value)
923 930 __ bind(done);
924 931 }
925 932
926 933
927 934 void TemplateTable::bastore() {
928 935 transition(itos, vtos);
929 936 __ pop_i(O2); // index
930 937 // Otos_i: val
931 938 // O3: array
932 939 __ index_check(O3, O2, 0, G3_scratch, O2);
933 940 __ stb(Otos_i, O2, arrayOopDesc::base_offset_in_bytes(T_BYTE));
934 941 }
935 942
936 943
937 944 void TemplateTable::castore() {
938 945 transition(itos, vtos);
939 946 __ pop_i(O2); // index
940 947 // Otos_i: val
941 948 // O3: array
942 949 __ index_check(O3, O2, LogBytesPerShort, G3_scratch, O2);
943 950 __ sth(Otos_i, O2, arrayOopDesc::base_offset_in_bytes(T_CHAR));
944 951 }
945 952
946 953
947 954 void TemplateTable::sastore() {
948 955 // %%%%% Factor across platform
949 956 castore();
950 957 }
951 958
952 959
953 960 void TemplateTable::istore(int n) {
954 961 transition(itos, vtos);
955 962 __ st(Otos_i, Llocals, Interpreter::local_offset_in_bytes(n));
956 963 }
957 964
958 965
959 966 void TemplateTable::lstore(int n) {
960 967 transition(ltos, vtos);
961 968 assert(n+1 < Argument::n_register_parameters, "only handle register cases");
962 969 __ store_unaligned_long(Otos_l, Llocals, Interpreter::local_offset_in_bytes(n+1));
963 970
964 971 }
965 972
966 973
967 974 void TemplateTable::fstore(int n) {
968 975 transition(ftos, vtos);
969 976 assert(n < Argument::n_register_parameters, "only handle register cases");
970 977 __ stf(FloatRegisterImpl::S, Ftos_f, Llocals, Interpreter::local_offset_in_bytes(n));
971 978 }
972 979
973 980
974 981 void TemplateTable::dstore(int n) {
975 982 transition(dtos, vtos);
976 983 FloatRegister src = Ftos_d;
977 984 __ store_unaligned_double(src, Llocals, Interpreter::local_offset_in_bytes(n+1));
978 985 }
979 986
980 987
981 988 void TemplateTable::astore(int n) {
982 989 transition(vtos, vtos);
983 990 __ load_ptr(0, Otos_i);
984 991 __ inc(Lesp, Interpreter::stackElementSize);
985 992 __ verify_oop_or_return_address(Otos_i, G3_scratch);
986 993 __ store_local_ptr(n, Otos_i);
987 994 }
988 995
989 996
990 997 void TemplateTable::pop() {
991 998 transition(vtos, vtos);
992 999 __ inc(Lesp, Interpreter::stackElementSize);
993 1000 }
994 1001
995 1002
996 1003 void TemplateTable::pop2() {
997 1004 transition(vtos, vtos);
998 1005 __ inc(Lesp, 2 * Interpreter::stackElementSize);
999 1006 }
1000 1007
1001 1008
1002 1009 void TemplateTable::dup() {
1003 1010 transition(vtos, vtos);
1004 1011 // stack: ..., a
1005 1012 // load a and tag
1006 1013 __ load_ptr(0, Otos_i);
1007 1014 __ push_ptr(Otos_i);
1008 1015 // stack: ..., a, a
1009 1016 }
1010 1017
1011 1018
1012 1019 void TemplateTable::dup_x1() {
1013 1020 transition(vtos, vtos);
1014 1021 // stack: ..., a, b
1015 1022 __ load_ptr( 1, G3_scratch); // get a
1016 1023 __ load_ptr( 0, Otos_l1); // get b
1017 1024 __ store_ptr(1, Otos_l1); // put b
1018 1025 __ store_ptr(0, G3_scratch); // put a - like swap
1019 1026 __ push_ptr(Otos_l1); // push b
1020 1027 // stack: ..., b, a, b
1021 1028 }
1022 1029
1023 1030
1024 1031 void TemplateTable::dup_x2() {
1025 1032 transition(vtos, vtos);
1026 1033 // stack: ..., a, b, c
1027 1034 // get c and push on stack, reuse registers
1028 1035 __ load_ptr( 0, G3_scratch); // get c
1029 1036 __ push_ptr(G3_scratch); // push c with tag
1030 1037 // stack: ..., a, b, c, c (c in reg) (Lesp - 4)
1031 1038 // (stack offsets n+1 now)
1032 1039 __ load_ptr( 3, Otos_l1); // get a
1033 1040 __ store_ptr(3, G3_scratch); // put c at 3
1034 1041 // stack: ..., c, b, c, c (a in reg)
1035 1042 __ load_ptr( 2, G3_scratch); // get b
1036 1043 __ store_ptr(2, Otos_l1); // put a at 2
1037 1044 // stack: ..., c, a, c, c (b in reg)
1038 1045 __ store_ptr(1, G3_scratch); // put b at 1
1039 1046 // stack: ..., c, a, b, c
1040 1047 }
1041 1048
1042 1049
1043 1050 void TemplateTable::dup2() {
1044 1051 transition(vtos, vtos);
1045 1052 __ load_ptr(1, G3_scratch); // get a
1046 1053 __ load_ptr(0, Otos_l1); // get b
1047 1054 __ push_ptr(G3_scratch); // push a
1048 1055 __ push_ptr(Otos_l1); // push b
1049 1056 // stack: ..., a, b, a, b
1050 1057 }
1051 1058
1052 1059
1053 1060 void TemplateTable::dup2_x1() {
1054 1061 transition(vtos, vtos);
1055 1062 // stack: ..., a, b, c
1056 1063 __ load_ptr( 1, Lscratch); // get b
1057 1064 __ load_ptr( 2, Otos_l1); // get a
1058 1065 __ store_ptr(2, Lscratch); // put b at a
1059 1066 // stack: ..., b, b, c
1060 1067 __ load_ptr( 0, G3_scratch); // get c
1061 1068 __ store_ptr(1, G3_scratch); // put c at b
1062 1069 // stack: ..., b, c, c
1063 1070 __ store_ptr(0, Otos_l1); // put a at c
1064 1071 // stack: ..., b, c, a
1065 1072 __ push_ptr(Lscratch); // push b
1066 1073 __ push_ptr(G3_scratch); // push c
1067 1074 // stack: ..., b, c, a, b, c
1068 1075 }
1069 1076
1070 1077
1071 1078 // The spec says that these types can be a mixture of category 1 (1 word)
1072 1079 // types and/or category 2 types (long and doubles)
1073 1080 void TemplateTable::dup2_x2() {
1074 1081 transition(vtos, vtos);
1075 1082 // stack: ..., a, b, c, d
1076 1083 __ load_ptr( 1, Lscratch); // get c
1077 1084 __ load_ptr( 3, Otos_l1); // get a
1078 1085 __ store_ptr(3, Lscratch); // put c at 3
1079 1086 __ store_ptr(1, Otos_l1); // put a at 1
1080 1087 // stack: ..., c, b, a, d
1081 1088 __ load_ptr( 2, G3_scratch); // get b
1082 1089 __ load_ptr( 0, Otos_l1); // get d
1083 1090 __ store_ptr(0, G3_scratch); // put b at 0
1084 1091 __ store_ptr(2, Otos_l1); // put d at 2
1085 1092 // stack: ..., c, d, a, b
1086 1093 __ push_ptr(Lscratch); // push c
1087 1094 __ push_ptr(Otos_l1); // push d
1088 1095 // stack: ..., c, d, a, b, c, d
1089 1096 }
1090 1097
1091 1098
1092 1099 void TemplateTable::swap() {
1093 1100 transition(vtos, vtos);
1094 1101 // stack: ..., a, b
1095 1102 __ load_ptr( 1, G3_scratch); // get a
1096 1103 __ load_ptr( 0, Otos_l1); // get b
1097 1104 __ store_ptr(0, G3_scratch); // put b
1098 1105 __ store_ptr(1, Otos_l1); // put a
1099 1106 // stack: ..., b, a
1100 1107 }
1101 1108
1102 1109
1103 1110 void TemplateTable::iop2(Operation op) {
1104 1111 transition(itos, itos);
1105 1112 __ pop_i(O1);
1106 1113 switch (op) {
1107 1114 case add: __ add(O1, Otos_i, Otos_i); break;
1108 1115 case sub: __ sub(O1, Otos_i, Otos_i); break;
1109 1116 // %%%%% Mul may not exist: better to call .mul?
1110 1117 case mul: __ smul(O1, Otos_i, Otos_i); break;
1111 1118 case _and: __ and3(O1, Otos_i, Otos_i); break;
1112 1119 case _or: __ or3(O1, Otos_i, Otos_i); break;
1113 1120 case _xor: __ xor3(O1, Otos_i, Otos_i); break;
1114 1121 case shl: __ sll(O1, Otos_i, Otos_i); break;
1115 1122 case shr: __ sra(O1, Otos_i, Otos_i); break;
1116 1123 case ushr: __ srl(O1, Otos_i, Otos_i); break;
1117 1124 default: ShouldNotReachHere();
1118 1125 }
1119 1126 }
1120 1127
1121 1128
1122 1129 void TemplateTable::lop2(Operation op) {
1123 1130 transition(ltos, ltos);
1124 1131 __ pop_l(O2);
1125 1132 switch (op) {
1126 1133 #ifdef _LP64
1127 1134 case add: __ add(O2, Otos_l, Otos_l); break;
1128 1135 case sub: __ sub(O2, Otos_l, Otos_l); break;
1129 1136 case _and: __ and3(O2, Otos_l, Otos_l); break;
1130 1137 case _or: __ or3(O2, Otos_l, Otos_l); break;
1131 1138 case _xor: __ xor3(O2, Otos_l, Otos_l); break;
1132 1139 #else
1133 1140 case add: __ addcc(O3, Otos_l2, Otos_l2); __ addc(O2, Otos_l1, Otos_l1); break;
1134 1141 case sub: __ subcc(O3, Otos_l2, Otos_l2); __ subc(O2, Otos_l1, Otos_l1); break;
1135 1142 case _and: __ and3(O3, Otos_l2, Otos_l2); __ and3(O2, Otos_l1, Otos_l1); break;
1136 1143 case _or: __ or3(O3, Otos_l2, Otos_l2); __ or3(O2, Otos_l1, Otos_l1); break;
1137 1144 case _xor: __ xor3(O3, Otos_l2, Otos_l2); __ xor3(O2, Otos_l1, Otos_l1); break;
1138 1145 #endif
1139 1146 default: ShouldNotReachHere();
1140 1147 }
1141 1148 }
1142 1149
1143 1150
1144 1151 void TemplateTable::idiv() {
1145 1152 // %%%%% Later: ForSPARC/V7 call .sdiv library routine,
1146 1153 // %%%%% Use ldsw...sdivx on pure V9 ABI. 64 bit safe.
1147 1154
1148 1155 transition(itos, itos);
1149 1156 __ pop_i(O1); // get 1st op
1150 1157
1151 1158 // Y contains upper 32 bits of result, set it to 0 or all ones
1152 1159 __ wry(G0);
1153 1160 __ mov(~0, G3_scratch);
1154 1161
1155 1162 __ tst(O1);
1156 1163 Label neg;
1157 1164 __ br(Assembler::negative, true, Assembler::pn, neg);
1158 1165 __ delayed()->wry(G3_scratch);
1159 1166 __ bind(neg);
1160 1167
1161 1168 Label ok;
1162 1169 __ tst(Otos_i);
1163 1170 __ throw_if_not_icc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch );
1164 1171
1165 1172 const int min_int = 0x80000000;
1166 1173 Label regular;
1167 1174 __ cmp(Otos_i, -1);
1168 1175 __ br(Assembler::notEqual, false, Assembler::pt, regular);
1169 1176 #ifdef _LP64
1170 1177 // Don't put set in delay slot
1171 1178 // Set will turn into multiple instructions in 64 bit mode
1172 1179 __ delayed()->nop();
1173 1180 __ set(min_int, G4_scratch);
1174 1181 #else
1175 1182 __ delayed()->set(min_int, G4_scratch);
1176 1183 #endif
1177 1184 Label done;
1178 1185 __ cmp(O1, G4_scratch);
1179 1186 __ br(Assembler::equal, true, Assembler::pt, done);
1180 1187 __ delayed()->mov(O1, Otos_i); // (mov only executed if branch taken)
1181 1188
1182 1189 __ bind(regular);
1183 1190 __ sdiv(O1, Otos_i, Otos_i); // note: irem uses O1 after this instruction!
1184 1191 __ bind(done);
1185 1192 }
1186 1193
1187 1194
1188 1195 void TemplateTable::irem() {
1189 1196 transition(itos, itos);
1190 1197 __ mov(Otos_i, O2); // save divisor
1191 1198 idiv(); // %%%% Hack: exploits fact that idiv leaves dividend in O1
1192 1199 __ smul(Otos_i, O2, Otos_i);
1193 1200 __ sub(O1, Otos_i, Otos_i);
1194 1201 }
1195 1202
1196 1203
1197 1204 void TemplateTable::lmul() {
1198 1205 transition(ltos, ltos);
1199 1206 __ pop_l(O2);
1200 1207 #ifdef _LP64
1201 1208 __ mulx(Otos_l, O2, Otos_l);
1202 1209 #else
1203 1210 __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::lmul));
1204 1211 #endif
1205 1212
1206 1213 }
1207 1214
1208 1215
1209 1216 void TemplateTable::ldiv() {
1210 1217 transition(ltos, ltos);
1211 1218
1212 1219 // check for zero
1213 1220 __ pop_l(O2);
1214 1221 #ifdef _LP64
1215 1222 __ tst(Otos_l);
1216 1223 __ throw_if_not_xcc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
1217 1224 __ sdivx(O2, Otos_l, Otos_l);
1218 1225 #else
1219 1226 __ orcc(Otos_l1, Otos_l2, G0);
1220 1227 __ throw_if_not_icc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
1221 1228 __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
1222 1229 #endif
1223 1230 }
1224 1231
1225 1232
1226 1233 void TemplateTable::lrem() {
1227 1234 transition(ltos, ltos);
1228 1235
1229 1236 // check for zero
1230 1237 __ pop_l(O2);
1231 1238 #ifdef _LP64
1232 1239 __ tst(Otos_l);
1233 1240 __ throw_if_not_xcc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
1234 1241 __ sdivx(O2, Otos_l, Otos_l2);
1235 1242 __ mulx (Otos_l2, Otos_l, Otos_l2);
1236 1243 __ sub (O2, Otos_l2, Otos_l);
1237 1244 #else
1238 1245 __ orcc(Otos_l1, Otos_l2, G0);
1239 1246 __ throw_if_not_icc(Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
1240 1247 __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
1241 1248 #endif
1242 1249 }
1243 1250
1244 1251
1245 1252 void TemplateTable::lshl() {
1246 1253 transition(itos, ltos); // %%%% could optimize, fill delay slot or opt for ultra
1247 1254
1248 1255 __ pop_l(O2); // shift value in O2, O3
1249 1256 #ifdef _LP64
1250 1257 __ sllx(O2, Otos_i, Otos_l);
1251 1258 #else
1252 1259 __ lshl(O2, O3, Otos_i, Otos_l1, Otos_l2, O4);
1253 1260 #endif
1254 1261 }
1255 1262
1256 1263
1257 1264 void TemplateTable::lshr() {
1258 1265 transition(itos, ltos); // %%%% see lshl comment
1259 1266
1260 1267 __ pop_l(O2); // shift value in O2, O3
1261 1268 #ifdef _LP64
1262 1269 __ srax(O2, Otos_i, Otos_l);
1263 1270 #else
1264 1271 __ lshr(O2, O3, Otos_i, Otos_l1, Otos_l2, O4);
1265 1272 #endif
1266 1273 }
1267 1274
1268 1275
1269 1276
1270 1277 void TemplateTable::lushr() {
1271 1278 transition(itos, ltos); // %%%% see lshl comment
1272 1279
1273 1280 __ pop_l(O2); // shift value in O2, O3
1274 1281 #ifdef _LP64
1275 1282 __ srlx(O2, Otos_i, Otos_l);
1276 1283 #else
1277 1284 __ lushr(O2, O3, Otos_i, Otos_l1, Otos_l2, O4);
1278 1285 #endif
1279 1286 }
1280 1287
1281 1288
1282 1289 void TemplateTable::fop2(Operation op) {
1283 1290 transition(ftos, ftos);
1284 1291 switch (op) {
1285 1292 case add: __ pop_f(F4); __ fadd(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f); break;
1286 1293 case sub: __ pop_f(F4); __ fsub(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f); break;
1287 1294 case mul: __ pop_f(F4); __ fmul(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f); break;
1288 1295 case div: __ pop_f(F4); __ fdiv(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f); break;
1289 1296 case rem:
1290 1297 assert(Ftos_f == F0, "just checking");
1291 1298 #ifdef _LP64
1292 1299 // LP64 calling conventions use F1, F3 for passing 2 floats
1293 1300 __ pop_f(F1);
1294 1301 __ fmov(FloatRegisterImpl::S, Ftos_f, F3);
1295 1302 #else
1296 1303 __ pop_i(O0);
1297 1304 __ stf(FloatRegisterImpl::S, Ftos_f, __ d_tmp);
1298 1305 __ ld( __ d_tmp, O1 );
1299 1306 #endif
1300 1307 __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::frem));
1301 1308 assert( Ftos_f == F0, "fix this code" );
1302 1309 break;
1303 1310
1304 1311 default: ShouldNotReachHere();
1305 1312 }
1306 1313 }
1307 1314
1308 1315
1309 1316 void TemplateTable::dop2(Operation op) {
1310 1317 transition(dtos, dtos);
1311 1318 switch (op) {
1312 1319 case add: __ pop_d(F4); __ fadd(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d); break;
1313 1320 case sub: __ pop_d(F4); __ fsub(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d); break;
1314 1321 case mul: __ pop_d(F4); __ fmul(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d); break;
1315 1322 case div: __ pop_d(F4); __ fdiv(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d); break;
1316 1323 case rem:
1317 1324 #ifdef _LP64
1318 1325 // Pass arguments in D0, D2
1319 1326 __ fmov(FloatRegisterImpl::D, Ftos_f, F2 );
1320 1327 __ pop_d( F0 );
1321 1328 #else
1322 1329 // Pass arguments in O0O1, O2O3
1323 1330 __ stf(FloatRegisterImpl::D, Ftos_f, __ d_tmp);
1324 1331 __ ldd( __ d_tmp, O2 );
1325 1332 __ pop_d(Ftos_f);
1326 1333 __ stf(FloatRegisterImpl::D, Ftos_f, __ d_tmp);
1327 1334 __ ldd( __ d_tmp, O0 );
1328 1335 #endif
1329 1336 __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::drem));
1330 1337 assert( Ftos_d == F0, "fix this code" );
1331 1338 break;
1332 1339
1333 1340 default: ShouldNotReachHere();
1334 1341 }
1335 1342 }
1336 1343
1337 1344
1338 1345 void TemplateTable::ineg() {
1339 1346 transition(itos, itos);
1340 1347 __ neg(Otos_i);
1341 1348 }
1342 1349
1343 1350
1344 1351 void TemplateTable::lneg() {
1345 1352 transition(ltos, ltos);
1346 1353 #ifdef _LP64
1347 1354 __ sub(G0, Otos_l, Otos_l);
1348 1355 #else
1349 1356 __ lneg(Otos_l1, Otos_l2);
1350 1357 #endif
1351 1358 }
1352 1359
1353 1360
1354 1361 void TemplateTable::fneg() {
1355 1362 transition(ftos, ftos);
1356 1363 __ fneg(FloatRegisterImpl::S, Ftos_f);
1357 1364 }
1358 1365
1359 1366
1360 1367 void TemplateTable::dneg() {
1361 1368 transition(dtos, dtos);
1362 1369 // v8 has fnegd if source and dest are the same
1363 1370 __ fneg(FloatRegisterImpl::D, Ftos_f);
1364 1371 }
1365 1372
1366 1373
1367 1374 void TemplateTable::iinc() {
1368 1375 transition(vtos, vtos);
1369 1376 locals_index(G3_scratch);
1370 1377 __ ldsb(Lbcp, 2, O2); // load constant
1371 1378 __ access_local_int(G3_scratch, Otos_i);
1372 1379 __ add(Otos_i, O2, Otos_i);
1373 1380 __ st(Otos_i, G3_scratch, 0); // access_local_int puts E.A. in G3_scratch
1374 1381 }
1375 1382
1376 1383
1377 1384 void TemplateTable::wide_iinc() {
1378 1385 transition(vtos, vtos);
1379 1386 locals_index_wide(G3_scratch);
1380 1387 __ get_2_byte_integer_at_bcp( 4, O2, O3, InterpreterMacroAssembler::Signed);
1381 1388 __ access_local_int(G3_scratch, Otos_i);
1382 1389 __ add(Otos_i, O3, Otos_i);
1383 1390 __ st(Otos_i, G3_scratch, 0); // access_local_int puts E.A. in G3_scratch
1384 1391 }
1385 1392
1386 1393
1387 1394 void TemplateTable::convert() {
1388 1395 // %%%%% Factor this first part accross platforms
1389 1396 #ifdef ASSERT
1390 1397 TosState tos_in = ilgl;
1391 1398 TosState tos_out = ilgl;
1392 1399 switch (bytecode()) {
1393 1400 case Bytecodes::_i2l: // fall through
1394 1401 case Bytecodes::_i2f: // fall through
1395 1402 case Bytecodes::_i2d: // fall through
1396 1403 case Bytecodes::_i2b: // fall through
1397 1404 case Bytecodes::_i2c: // fall through
1398 1405 case Bytecodes::_i2s: tos_in = itos; break;
1399 1406 case Bytecodes::_l2i: // fall through
1400 1407 case Bytecodes::_l2f: // fall through
1401 1408 case Bytecodes::_l2d: tos_in = ltos; break;
1402 1409 case Bytecodes::_f2i: // fall through
1403 1410 case Bytecodes::_f2l: // fall through
1404 1411 case Bytecodes::_f2d: tos_in = ftos; break;
1405 1412 case Bytecodes::_d2i: // fall through
1406 1413 case Bytecodes::_d2l: // fall through
1407 1414 case Bytecodes::_d2f: tos_in = dtos; break;
1408 1415 default : ShouldNotReachHere();
1409 1416 }
1410 1417 switch (bytecode()) {
1411 1418 case Bytecodes::_l2i: // fall through
1412 1419 case Bytecodes::_f2i: // fall through
1413 1420 case Bytecodes::_d2i: // fall through
1414 1421 case Bytecodes::_i2b: // fall through
1415 1422 case Bytecodes::_i2c: // fall through
1416 1423 case Bytecodes::_i2s: tos_out = itos; break;
1417 1424 case Bytecodes::_i2l: // fall through
1418 1425 case Bytecodes::_f2l: // fall through
1419 1426 case Bytecodes::_d2l: tos_out = ltos; break;
1420 1427 case Bytecodes::_i2f: // fall through
1421 1428 case Bytecodes::_l2f: // fall through
1422 1429 case Bytecodes::_d2f: tos_out = ftos; break;
1423 1430 case Bytecodes::_i2d: // fall through
1424 1431 case Bytecodes::_l2d: // fall through
1425 1432 case Bytecodes::_f2d: tos_out = dtos; break;
1426 1433 default : ShouldNotReachHere();
1427 1434 }
1428 1435 transition(tos_in, tos_out);
1429 1436 #endif
1430 1437
1431 1438
1432 1439 // Conversion
1433 1440 Label done;
1434 1441 switch (bytecode()) {
1435 1442 case Bytecodes::_i2l:
1436 1443 #ifdef _LP64
1437 1444 // Sign extend the 32 bits
1438 1445 __ sra ( Otos_i, 0, Otos_l );
1439 1446 #else
1440 1447 __ addcc(Otos_i, 0, Otos_l2);
1441 1448 __ br(Assembler::greaterEqual, true, Assembler::pt, done);
1442 1449 __ delayed()->clr(Otos_l1);
1443 1450 __ set(~0, Otos_l1);
1444 1451 #endif
1445 1452 break;
1446 1453
1447 1454 case Bytecodes::_i2f:
1448 1455 __ st(Otos_i, __ d_tmp );
1449 1456 __ ldf(FloatRegisterImpl::S, __ d_tmp, F0);
1450 1457 __ fitof(FloatRegisterImpl::S, F0, Ftos_f);
1451 1458 break;
1452 1459
1453 1460 case Bytecodes::_i2d:
1454 1461 __ st(Otos_i, __ d_tmp);
1455 1462 __ ldf(FloatRegisterImpl::S, __ d_tmp, F0);
1456 1463 __ fitof(FloatRegisterImpl::D, F0, Ftos_f);
1457 1464 break;
1458 1465
1459 1466 case Bytecodes::_i2b:
1460 1467 __ sll(Otos_i, 24, Otos_i);
1461 1468 __ sra(Otos_i, 24, Otos_i);
1462 1469 break;
1463 1470
1464 1471 case Bytecodes::_i2c:
1465 1472 __ sll(Otos_i, 16, Otos_i);
1466 1473 __ srl(Otos_i, 16, Otos_i);
1467 1474 break;
1468 1475
1469 1476 case Bytecodes::_i2s:
1470 1477 __ sll(Otos_i, 16, Otos_i);
1471 1478 __ sra(Otos_i, 16, Otos_i);
1472 1479 break;
1473 1480
1474 1481 case Bytecodes::_l2i:
1475 1482 #ifndef _LP64
1476 1483 __ mov(Otos_l2, Otos_i);
1477 1484 #else
1478 1485 // Sign-extend into the high 32 bits
1479 1486 __ sra(Otos_l, 0, Otos_i);
1480 1487 #endif
1481 1488 break;
1482 1489
1483 1490 case Bytecodes::_l2f:
1484 1491 case Bytecodes::_l2d:
1485 1492 __ st_long(Otos_l, __ d_tmp);
1486 1493 __ ldf(FloatRegisterImpl::D, __ d_tmp, Ftos_d);
1487 1494
1488 1495 if (VM_Version::v9_instructions_work()) {
1489 1496 if (bytecode() == Bytecodes::_l2f) {
1490 1497 __ fxtof(FloatRegisterImpl::S, Ftos_d, Ftos_f);
1491 1498 } else {
1492 1499 __ fxtof(FloatRegisterImpl::D, Ftos_d, Ftos_d);
1493 1500 }
1494 1501 } else {
1495 1502 __ call_VM_leaf(
1496 1503 Lscratch,
1497 1504 bytecode() == Bytecodes::_l2f
1498 1505 ? CAST_FROM_FN_PTR(address, SharedRuntime::l2f)
1499 1506 : CAST_FROM_FN_PTR(address, SharedRuntime::l2d)
1500 1507 );
1501 1508 }
1502 1509 break;
1503 1510
1504 1511 case Bytecodes::_f2i: {
1505 1512 Label isNaN;
1506 1513 // result must be 0 if value is NaN; test by comparing value to itself
1507 1514 __ fcmp(FloatRegisterImpl::S, Assembler::fcc0, Ftos_f, Ftos_f);
1508 1515 // According to the v8 manual, you have to have a non-fp instruction
1509 1516 // between fcmp and fb.
1510 1517 if (!VM_Version::v9_instructions_work()) {
1511 1518 __ nop();
1512 1519 }
1513 1520 __ fb(Assembler::f_unordered, true, Assembler::pn, isNaN);
1514 1521 __ delayed()->clr(Otos_i); // NaN
1515 1522 __ ftoi(FloatRegisterImpl::S, Ftos_f, F30);
1516 1523 __ stf(FloatRegisterImpl::S, F30, __ d_tmp);
1517 1524 __ ld(__ d_tmp, Otos_i);
1518 1525 __ bind(isNaN);
1519 1526 }
1520 1527 break;
1521 1528
1522 1529 case Bytecodes::_f2l:
1523 1530 // must uncache tos
1524 1531 __ push_f();
1525 1532 #ifdef _LP64
1526 1533 __ pop_f(F1);
1527 1534 #else
1528 1535 __ pop_i(O0);
1529 1536 #endif
1530 1537 __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::f2l));
1531 1538 break;
1532 1539
1533 1540 case Bytecodes::_f2d:
1534 1541 __ ftof( FloatRegisterImpl::S, FloatRegisterImpl::D, Ftos_f, Ftos_f);
1535 1542 break;
1536 1543
1537 1544 case Bytecodes::_d2i:
1538 1545 case Bytecodes::_d2l:
1539 1546 // must uncache tos
1540 1547 __ push_d();
1541 1548 #ifdef _LP64
1542 1549 // LP64 calling conventions pass first double arg in D0
1543 1550 __ pop_d( Ftos_d );
1544 1551 #else
1545 1552 __ pop_i( O0 );
1546 1553 __ pop_i( O1 );
1547 1554 #endif
1548 1555 __ call_VM_leaf(Lscratch,
1549 1556 bytecode() == Bytecodes::_d2i
1550 1557 ? CAST_FROM_FN_PTR(address, SharedRuntime::d2i)
1551 1558 : CAST_FROM_FN_PTR(address, SharedRuntime::d2l));
1552 1559 break;
1553 1560
1554 1561 case Bytecodes::_d2f:
1555 1562 if (VM_Version::v9_instructions_work()) {
1556 1563 __ ftof( FloatRegisterImpl::D, FloatRegisterImpl::S, Ftos_d, Ftos_f);
1557 1564 }
1558 1565 else {
1559 1566 // must uncache tos
1560 1567 __ push_d();
1561 1568 __ pop_i(O0);
1562 1569 __ pop_i(O1);
1563 1570 __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::d2f));
1564 1571 }
1565 1572 break;
1566 1573
1567 1574 default: ShouldNotReachHere();
1568 1575 }
1569 1576 __ bind(done);
1570 1577 }
1571 1578
1572 1579
1573 1580 void TemplateTable::lcmp() {
1574 1581 transition(ltos, itos);
1575 1582
1576 1583 #ifdef _LP64
1577 1584 __ pop_l(O1); // pop off value 1, value 2 is in O0
1578 1585 __ lcmp( O1, Otos_l, Otos_i );
1579 1586 #else
1580 1587 __ pop_l(O2); // cmp O2,3 to O0,1
1581 1588 __ lcmp( O2, O3, Otos_l1, Otos_l2, Otos_i );
1582 1589 #endif
1583 1590 }
1584 1591
1585 1592
1586 1593 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
1587 1594
1588 1595 if (is_float) __ pop_f(F2);
1589 1596 else __ pop_d(F2);
1590 1597
1591 1598 assert(Ftos_f == F0 && Ftos_d == F0, "alias checking:");
1592 1599
1593 1600 __ float_cmp( is_float, unordered_result, F2, F0, Otos_i );
1594 1601 }
1595 1602
1596 1603 void TemplateTable::branch(bool is_jsr, bool is_wide) {
1597 1604 // Note: on SPARC, we use InterpreterMacroAssembler::if_cmp also.
1598 1605 __ verify_oop(Lmethod);
1599 1606 __ verify_thread();
1600 1607
1601 1608 const Register O2_bumped_count = O2;
1602 1609 __ profile_taken_branch(G3_scratch, O2_bumped_count);
1603 1610
1604 1611 // get (wide) offset to O1_disp
1605 1612 const Register O1_disp = O1;
1606 1613 if (is_wide) __ get_4_byte_integer_at_bcp( 1, G4_scratch, O1_disp, InterpreterMacroAssembler::set_CC);
1607 1614 else __ get_2_byte_integer_at_bcp( 1, G4_scratch, O1_disp, InterpreterMacroAssembler::Signed, InterpreterMacroAssembler::set_CC);
1608 1615
1609 1616 // Handle all the JSR stuff here, then exit.
1610 1617 // It's much shorter and cleaner than intermingling with the
1611 1618 // non-JSR normal-branch stuff occurring below.
1612 1619 if( is_jsr ) {
1613 1620 // compute return address as bci in Otos_i
1614 1621 __ ld_ptr(Lmethod, methodOopDesc::const_offset(), G3_scratch);
1615 1622 __ sub(Lbcp, G3_scratch, G3_scratch);
1616 1623 __ sub(G3_scratch, in_bytes(constMethodOopDesc::codes_offset()) - (is_wide ? 5 : 3), Otos_i);
1617 1624
1618 1625 // Bump Lbcp to target of JSR
1619 1626 __ add(Lbcp, O1_disp, Lbcp);
1620 1627 // Push returnAddress for "ret" on stack
1621 1628 __ push_ptr(Otos_i);
1622 1629 // And away we go!
1623 1630 __ dispatch_next(vtos);
1624 1631 return;
1625 1632 }
1626 1633
1627 1634 // Normal (non-jsr) branch handling
1628 1635
1629 1636 // Save the current Lbcp
1630 1637 const Register O0_cur_bcp = O0;
1631 1638 __ mov( Lbcp, O0_cur_bcp );
1632 1639
1633 1640
1634 1641 bool increment_invocation_counter_for_backward_branches = UseCompiler && UseLoopCounter;
1635 1642 if ( increment_invocation_counter_for_backward_branches ) {
1636 1643 Label Lforward;
1637 1644 // check branch direction
1638 1645 __ br( Assembler::positive, false, Assembler::pn, Lforward );
1639 1646 // Bump bytecode pointer by displacement (take the branch)
1640 1647 __ delayed()->add( O1_disp, Lbcp, Lbcp ); // add to bc addr
1641 1648
1642 1649 if (TieredCompilation) {
1643 1650 Label Lno_mdo, Loverflow;
1644 1651 int increment = InvocationCounter::count_increment;
1645 1652 int mask = ((1 << Tier0BackedgeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
1646 1653 if (ProfileInterpreter) {
1647 1654 // If no method data exists, go to profile_continue.
1648 1655 __ ld_ptr(Lmethod, methodOopDesc::method_data_offset(), G4_scratch);
1649 1656 __ br_null_short(G4_scratch, Assembler::pn, Lno_mdo);
1650 1657
1651 1658 // Increment backedge counter in the MDO
1652 1659 Address mdo_backedge_counter(G4_scratch, in_bytes(methodDataOopDesc::backedge_counter_offset()) +
1653 1660 in_bytes(InvocationCounter::counter_offset()));
1654 1661 __ increment_mask_and_jump(mdo_backedge_counter, increment, mask, G3_scratch, Lscratch,
1655 1662 Assembler::notZero, &Lforward);
1656 1663 __ ba_short(Loverflow);
1657 1664 }
1658 1665
1659 1666 // If there's no MDO, increment counter in methodOop
1660 1667 __ bind(Lno_mdo);
1661 1668 Address backedge_counter(Lmethod, in_bytes(methodOopDesc::backedge_counter_offset()) +
1662 1669 in_bytes(InvocationCounter::counter_offset()));
1663 1670 __ increment_mask_and_jump(backedge_counter, increment, mask, G3_scratch, Lscratch,
1664 1671 Assembler::notZero, &Lforward);
1665 1672 __ bind(Loverflow);
1666 1673
1667 1674 // notify point for loop, pass branch bytecode
1668 1675 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), O0_cur_bcp);
1669 1676
1670 1677 // Was an OSR adapter generated?
1671 1678 // O0 = osr nmethod
1672 1679 __ br_null_short(O0, Assembler::pn, Lforward);
1673 1680
1674 1681 // Has the nmethod been invalidated already?
1675 1682 __ ld(O0, nmethod::entry_bci_offset(), O2);
1676 1683 __ cmp_and_br_short(O2, InvalidOSREntryBci, Assembler::equal, Assembler::pn, Lforward);
1677 1684
1678 1685 // migrate the interpreter frame off of the stack
1679 1686
1680 1687 __ mov(G2_thread, L7);
1681 1688 // save nmethod
1682 1689 __ mov(O0, L6);
1683 1690 __ set_last_Java_frame(SP, noreg);
1684 1691 __ call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), L7);
1685 1692 __ reset_last_Java_frame();
1686 1693 __ mov(L7, G2_thread);
1687 1694
1688 1695 // move OSR nmethod to I1
1689 1696 __ mov(L6, I1);
1690 1697
1691 1698 // OSR buffer to I0
1692 1699 __ mov(O0, I0);
1693 1700
1694 1701 // remove the interpreter frame
1695 1702 __ restore(I5_savedSP, 0, SP);
1696 1703
1697 1704 // Jump to the osr code.
1698 1705 __ ld_ptr(O1, nmethod::osr_entry_point_offset(), O2);
1699 1706 __ jmp(O2, G0);
1700 1707 __ delayed()->nop();
1701 1708
1702 1709 } else {
1703 1710 // Update Backedge branch separately from invocations
1704 1711 const Register G4_invoke_ctr = G4;
1705 1712 __ increment_backedge_counter(G4_invoke_ctr, G1_scratch);
1706 1713 if (ProfileInterpreter) {
1707 1714 __ test_invocation_counter_for_mdp(G4_invoke_ctr, G3_scratch, Lforward);
1708 1715 if (UseOnStackReplacement) {
1709 1716 __ test_backedge_count_for_osr(O2_bumped_count, O0_cur_bcp, G3_scratch);
1710 1717 }
1711 1718 } else {
1712 1719 if (UseOnStackReplacement) {
1713 1720 __ test_backedge_count_for_osr(G4_invoke_ctr, O0_cur_bcp, G3_scratch);
1714 1721 }
1715 1722 }
1716 1723 }
1717 1724
1718 1725 __ bind(Lforward);
1719 1726 } else
1720 1727 // Bump bytecode pointer by displacement (take the branch)
1721 1728 __ add( O1_disp, Lbcp, Lbcp );// add to bc addr
1722 1729
1723 1730 // continue with bytecode @ target
1724 1731 // %%%%% Like Intel, could speed things up by moving bytecode fetch to code above,
1725 1732 // %%%%% and changing dispatch_next to dispatch_only
1726 1733 __ dispatch_next(vtos);
1727 1734 }
1728 1735
1729 1736
1730 1737 // Note Condition in argument is TemplateTable::Condition
1731 1738 // arg scope is within class scope
1732 1739
1733 1740 void TemplateTable::if_0cmp(Condition cc) {
1734 1741 // no pointers, integer only!
1735 1742 transition(itos, vtos);
1736 1743 // assume branch is more often taken than not (loops use backward branches)
1737 1744 __ cmp( Otos_i, 0);
1738 1745 __ if_cmp(ccNot(cc), false);
1739 1746 }
1740 1747
1741 1748
1742 1749 void TemplateTable::if_icmp(Condition cc) {
1743 1750 transition(itos, vtos);
1744 1751 __ pop_i(O1);
1745 1752 __ cmp(O1, Otos_i);
1746 1753 __ if_cmp(ccNot(cc), false);
1747 1754 }
1748 1755
1749 1756
1750 1757 void TemplateTable::if_nullcmp(Condition cc) {
1751 1758 transition(atos, vtos);
1752 1759 __ tst(Otos_i);
1753 1760 __ if_cmp(ccNot(cc), true);
1754 1761 }
1755 1762
1756 1763
1757 1764 void TemplateTable::if_acmp(Condition cc) {
1758 1765 transition(atos, vtos);
1759 1766 __ pop_ptr(O1);
1760 1767 __ verify_oop(O1);
1761 1768 __ verify_oop(Otos_i);
1762 1769 __ cmp(O1, Otos_i);
1763 1770 __ if_cmp(ccNot(cc), true);
1764 1771 }
1765 1772
1766 1773
1767 1774
1768 1775 void TemplateTable::ret() {
1769 1776 transition(vtos, vtos);
1770 1777 locals_index(G3_scratch);
1771 1778 __ access_local_returnAddress(G3_scratch, Otos_i);
1772 1779 // Otos_i contains the bci, compute the bcp from that
1773 1780
1774 1781 #ifdef _LP64
1775 1782 #ifdef ASSERT
1776 1783 // jsr result was labeled as an 'itos' not an 'atos' because we cannot GC
1777 1784 // the result. The return address (really a BCI) was stored with an
1778 1785 // 'astore' because JVM specs claim it's a pointer-sized thing. Hence in
1779 1786 // the 64-bit build the 32-bit BCI is actually in the low bits of a 64-bit
1780 1787 // loaded value.
1781 1788 { Label zzz ;
1782 1789 __ set (65536, G3_scratch) ;
1783 1790 __ cmp (Otos_i, G3_scratch) ;
1784 1791 __ bp( Assembler::lessEqualUnsigned, false, Assembler::xcc, Assembler::pn, zzz);
1785 1792 __ delayed()->nop();
1786 1793 __ stop("BCI is in the wrong register half?");
1787 1794 __ bind (zzz) ;
1788 1795 }
1789 1796 #endif
1790 1797 #endif
1791 1798
1792 1799 __ profile_ret(vtos, Otos_i, G4_scratch);
1793 1800
1794 1801 __ ld_ptr(Lmethod, methodOopDesc::const_offset(), G3_scratch);
1795 1802 __ add(G3_scratch, Otos_i, G3_scratch);
1796 1803 __ add(G3_scratch, in_bytes(constMethodOopDesc::codes_offset()), Lbcp);
1797 1804 __ dispatch_next(vtos);
1798 1805 }
1799 1806
1800 1807
1801 1808 void TemplateTable::wide_ret() {
1802 1809 transition(vtos, vtos);
1803 1810 locals_index_wide(G3_scratch);
1804 1811 __ access_local_returnAddress(G3_scratch, Otos_i);
1805 1812 // Otos_i contains the bci, compute the bcp from that
1806 1813
1807 1814 __ profile_ret(vtos, Otos_i, G4_scratch);
1808 1815
1809 1816 __ ld_ptr(Lmethod, methodOopDesc::const_offset(), G3_scratch);
1810 1817 __ add(G3_scratch, Otos_i, G3_scratch);
1811 1818 __ add(G3_scratch, in_bytes(constMethodOopDesc::codes_offset()), Lbcp);
1812 1819 __ dispatch_next(vtos);
1813 1820 }
1814 1821
1815 1822
1816 1823 void TemplateTable::tableswitch() {
1817 1824 transition(itos, vtos);
1818 1825 Label default_case, continue_execution;
1819 1826
1820 1827 // align bcp
1821 1828 __ add(Lbcp, BytesPerInt, O1);
1822 1829 __ and3(O1, -BytesPerInt, O1);
1823 1830 // load lo, hi
1824 1831 __ ld(O1, 1 * BytesPerInt, O2); // Low Byte
1825 1832 __ ld(O1, 2 * BytesPerInt, O3); // High Byte
1826 1833 #ifdef _LP64
1827 1834 // Sign extend the 32 bits
1828 1835 __ sra ( Otos_i, 0, Otos_i );
1829 1836 #endif /* _LP64 */
1830 1837
1831 1838 // check against lo & hi
1832 1839 __ cmp( Otos_i, O2);
1833 1840 __ br( Assembler::less, false, Assembler::pn, default_case);
1834 1841 __ delayed()->cmp( Otos_i, O3 );
1835 1842 __ br( Assembler::greater, false, Assembler::pn, default_case);
1836 1843 // lookup dispatch offset
1837 1844 __ delayed()->sub(Otos_i, O2, O2);
1838 1845 __ profile_switch_case(O2, O3, G3_scratch, G4_scratch);
1839 1846 __ sll(O2, LogBytesPerInt, O2);
1840 1847 __ add(O2, 3 * BytesPerInt, O2);
1841 1848 __ ba(continue_execution);
1842 1849 __ delayed()->ld(O1, O2, O2);
1843 1850 // handle default
1844 1851 __ bind(default_case);
1845 1852 __ profile_switch_default(O3);
1846 1853 __ ld(O1, 0, O2); // get default offset
1847 1854 // continue execution
1848 1855 __ bind(continue_execution);
1849 1856 __ add(Lbcp, O2, Lbcp);
1850 1857 __ dispatch_next(vtos);
1851 1858 }
1852 1859
1853 1860
1854 1861 void TemplateTable::lookupswitch() {
1855 1862 transition(itos, itos);
1856 1863 __ stop("lookupswitch bytecode should have been rewritten");
1857 1864 }
1858 1865
1859 1866 void TemplateTable::fast_linearswitch() {
1860 1867 transition(itos, vtos);
1861 1868 Label loop_entry, loop, found, continue_execution;
1862 1869 // align bcp
1863 1870 __ add(Lbcp, BytesPerInt, O1);
1864 1871 __ and3(O1, -BytesPerInt, O1);
1865 1872 // set counter
1866 1873 __ ld(O1, BytesPerInt, O2);
1867 1874 __ sll(O2, LogBytesPerInt + 1, O2); // in word-pairs
1868 1875 __ add(O1, 2 * BytesPerInt, O3); // set first pair addr
1869 1876 __ ba(loop_entry);
1870 1877 __ delayed()->add(O3, O2, O2); // counter now points past last pair
1871 1878
1872 1879 // table search
1873 1880 __ bind(loop);
1874 1881 __ cmp(O4, Otos_i);
1875 1882 __ br(Assembler::equal, true, Assembler::pn, found);
1876 1883 __ delayed()->ld(O3, BytesPerInt, O4); // offset -> O4
1877 1884 __ inc(O3, 2 * BytesPerInt);
1878 1885
1879 1886 __ bind(loop_entry);
1880 1887 __ cmp(O2, O3);
1881 1888 __ brx(Assembler::greaterUnsigned, true, Assembler::pt, loop);
1882 1889 __ delayed()->ld(O3, 0, O4);
1883 1890
1884 1891 // default case
1885 1892 __ ld(O1, 0, O4); // get default offset
1886 1893 if (ProfileInterpreter) {
1887 1894 __ profile_switch_default(O3);
1888 1895 __ ba_short(continue_execution);
1889 1896 }
1890 1897
1891 1898 // entry found -> get offset
1892 1899 __ bind(found);
1893 1900 if (ProfileInterpreter) {
1894 1901 __ sub(O3, O1, O3);
1895 1902 __ sub(O3, 2*BytesPerInt, O3);
1896 1903 __ srl(O3, LogBytesPerInt + 1, O3); // in word-pairs
1897 1904 __ profile_switch_case(O3, O1, O2, G3_scratch);
1898 1905
1899 1906 __ bind(continue_execution);
1900 1907 }
1901 1908 __ add(Lbcp, O4, Lbcp);
1902 1909 __ dispatch_next(vtos);
1903 1910 }
1904 1911
1905 1912
1906 1913 void TemplateTable::fast_binaryswitch() {
1907 1914 transition(itos, vtos);
1908 1915 // Implementation using the following core algorithm: (copied from Intel)
1909 1916 //
1910 1917 // int binary_search(int key, LookupswitchPair* array, int n) {
1911 1918 // // Binary search according to "Methodik des Programmierens" by
1912 1919 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
1913 1920 // int i = 0;
1914 1921 // int j = n;
1915 1922 // while (i+1 < j) {
1916 1923 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
1917 1924 // // with Q: for all i: 0 <= i < n: key < a[i]
1918 1925 // // where a stands for the array and assuming that the (inexisting)
1919 1926 // // element a[n] is infinitely big.
1920 1927 // int h = (i + j) >> 1;
1921 1928 // // i < h < j
1922 1929 // if (key < array[h].fast_match()) {
1923 1930 // j = h;
1924 1931 // } else {
1925 1932 // i = h;
1926 1933 // }
1927 1934 // }
1928 1935 // // R: a[i] <= key < a[i+1] or Q
1929 1936 // // (i.e., if key is within array, i is the correct index)
1930 1937 // return i;
1931 1938 // }
1932 1939
1933 1940 // register allocation
1934 1941 assert(Otos_i == O0, "alias checking");
1935 1942 const Register Rkey = Otos_i; // already set (tosca)
1936 1943 const Register Rarray = O1;
1937 1944 const Register Ri = O2;
1938 1945 const Register Rj = O3;
1939 1946 const Register Rh = O4;
1940 1947 const Register Rscratch = O5;
1941 1948
1942 1949 const int log_entry_size = 3;
1943 1950 const int entry_size = 1 << log_entry_size;
1944 1951
1945 1952 Label found;
1946 1953 // Find Array start
1947 1954 __ add(Lbcp, 3 * BytesPerInt, Rarray);
1948 1955 __ and3(Rarray, -BytesPerInt, Rarray);
1949 1956 // initialize i & j (in delay slot)
1950 1957 __ clr( Ri );
1951 1958
1952 1959 // and start
1953 1960 Label entry;
1954 1961 __ ba(entry);
1955 1962 __ delayed()->ld( Rarray, -BytesPerInt, Rj);
1956 1963 // (Rj is already in the native byte-ordering.)
1957 1964
1958 1965 // binary search loop
1959 1966 { Label loop;
1960 1967 __ bind( loop );
1961 1968 // int h = (i + j) >> 1;
1962 1969 __ sra( Rh, 1, Rh );
1963 1970 // if (key < array[h].fast_match()) {
1964 1971 // j = h;
1965 1972 // } else {
1966 1973 // i = h;
1967 1974 // }
1968 1975 __ sll( Rh, log_entry_size, Rscratch );
1969 1976 __ ld( Rarray, Rscratch, Rscratch );
1970 1977 // (Rscratch is already in the native byte-ordering.)
1971 1978 __ cmp( Rkey, Rscratch );
1972 1979 if ( VM_Version::v9_instructions_work() ) {
1973 1980 __ movcc( Assembler::less, false, Assembler::icc, Rh, Rj ); // j = h if (key < array[h].fast_match())
1974 1981 __ movcc( Assembler::greaterEqual, false, Assembler::icc, Rh, Ri ); // i = h if (key >= array[h].fast_match())
1975 1982 }
1976 1983 else {
1977 1984 Label end_of_if;
1978 1985 __ br( Assembler::less, true, Assembler::pt, end_of_if );
1979 1986 __ delayed()->mov( Rh, Rj ); // if (<) Rj = Rh
1980 1987 __ mov( Rh, Ri ); // else i = h
1981 1988 __ bind(end_of_if); // }
1982 1989 }
1983 1990
1984 1991 // while (i+1 < j)
1985 1992 __ bind( entry );
1986 1993 __ add( Ri, 1, Rscratch );
1987 1994 __ cmp(Rscratch, Rj);
1988 1995 __ br( Assembler::less, true, Assembler::pt, loop );
1989 1996 __ delayed()->add( Ri, Rj, Rh ); // start h = i + j >> 1;
1990 1997 }
1991 1998
1992 1999 // end of binary search, result index is i (must check again!)
1993 2000 Label default_case;
1994 2001 Label continue_execution;
1995 2002 if (ProfileInterpreter) {
1996 2003 __ mov( Ri, Rh ); // Save index in i for profiling
1997 2004 }
1998 2005 __ sll( Ri, log_entry_size, Ri );
1999 2006 __ ld( Rarray, Ri, Rscratch );
2000 2007 // (Rscratch is already in the native byte-ordering.)
2001 2008 __ cmp( Rkey, Rscratch );
2002 2009 __ br( Assembler::notEqual, true, Assembler::pn, default_case );
2003 2010 __ delayed()->ld( Rarray, -2 * BytesPerInt, Rj ); // load default offset -> j
2004 2011
2005 2012 // entry found -> j = offset
2006 2013 __ inc( Ri, BytesPerInt );
2007 2014 __ profile_switch_case(Rh, Rj, Rscratch, Rkey);
2008 2015 __ ld( Rarray, Ri, Rj );
2009 2016 // (Rj is already in the native byte-ordering.)
2010 2017
2011 2018 if (ProfileInterpreter) {
2012 2019 __ ba_short(continue_execution);
2013 2020 }
2014 2021
2015 2022 __ bind(default_case); // fall through (if not profiling)
2016 2023 __ profile_switch_default(Ri);
2017 2024
2018 2025 __ bind(continue_execution);
2019 2026 __ add( Lbcp, Rj, Lbcp );
2020 2027 __ dispatch_next( vtos );
2021 2028 }
2022 2029
2023 2030
2024 2031 void TemplateTable::_return(TosState state) {
2025 2032 transition(state, state);
2026 2033 assert(_desc->calls_vm(), "inconsistent calls_vm information");
2027 2034
2028 2035 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
2029 2036 assert(state == vtos, "only valid state");
2030 2037 __ mov(G0, G3_scratch);
2031 2038 __ access_local_ptr(G3_scratch, Otos_i);
2032 2039 __ load_klass(Otos_i, O2);
2033 2040 __ set(JVM_ACC_HAS_FINALIZER, G3);
2034 2041 __ ld(O2, in_bytes(Klass::access_flags_offset()), O2);
2035 2042 __ andcc(G3, O2, G0);
2036 2043 Label skip_register_finalizer;
2037 2044 __ br(Assembler::zero, false, Assembler::pn, skip_register_finalizer);
2038 2045 __ delayed()->nop();
2039 2046
2040 2047 // Call out to do finalizer registration
2041 2048 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), Otos_i);
2042 2049
2043 2050 __ bind(skip_register_finalizer);
2044 2051 }
2045 2052
2046 2053 __ remove_activation(state, /* throw_monitor_exception */ true);
2047 2054
2048 2055 // The caller's SP was adjusted upon method entry to accomodate
2049 2056 // the callee's non-argument locals. Undo that adjustment.
2050 2057 __ ret(); // return to caller
2051 2058 __ delayed()->restore(I5_savedSP, G0, SP);
2052 2059 }
2053 2060
2054 2061
2055 2062 // ----------------------------------------------------------------------------
2056 2063 // Volatile variables demand their effects be made known to all CPU's in
2057 2064 // order. Store buffers on most chips allow reads & writes to reorder; the
2058 2065 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
2059 2066 // memory barrier (i.e., it's not sufficient that the interpreter does not
2060 2067 // reorder volatile references, the hardware also must not reorder them).
2061 2068 //
2062 2069 // According to the new Java Memory Model (JMM):
2063 2070 // (1) All volatiles are serialized wrt to each other.
2064 2071 // ALSO reads & writes act as aquire & release, so:
2065 2072 // (2) A read cannot let unrelated NON-volatile memory refs that happen after
2066 2073 // the read float up to before the read. It's OK for non-volatile memory refs
2067 2074 // that happen before the volatile read to float down below it.
2068 2075 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
2069 2076 // that happen BEFORE the write float down to after the write. It's OK for
2070 2077 // non-volatile memory refs that happen after the volatile write to float up
2071 2078 // before it.
2072 2079 //
2073 2080 // We only put in barriers around volatile refs (they are expensive), not
2074 2081 // _between_ memory refs (that would require us to track the flavor of the
2075 2082 // previous memory refs). Requirements (2) and (3) require some barriers
2076 2083 // before volatile stores and after volatile loads. These nearly cover
2077 2084 // requirement (1) but miss the volatile-store-volatile-load case. This final
2078 2085 // case is placed after volatile-stores although it could just as well go
2079 2086 // before volatile-loads.
2080 2087 void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint) {
2081 2088 // Helper function to insert a is-volatile test and memory barrier
2082 2089 // All current sparc implementations run in TSO, needing only StoreLoad
2083 2090 if ((order_constraint & Assembler::StoreLoad) == 0) return;
2084 2091 __ membar( order_constraint );
2085 2092 }
2086 2093
2087 2094 // ----------------------------------------------------------------------------
2088 2095 void TemplateTable::resolve_cache_and_index(int byte_no,
2089 2096 Register result,
2090 2097 Register Rcache,
2091 2098 Register index,
2092 2099 size_t index_size) {
2093 2100 // Depends on cpCacheOop layout!
2094 2101 Label resolved;
2095 2102
2096 2103 if (byte_no == f12_oop) {
2097 2104 // We are resolved if the f1 field contains a non-null object (CallSite, MethodType, etc.)
2098 2105 // This kind of CP cache entry does not need to match bytecode_1 or bytecode_2, because
2099 2106 // there is a 1-1 relation between bytecode type and CP entry type.
2100 2107 // The caller will also load a methodOop from f2.
2101 2108 assert(result != noreg, "");
2102 2109 assert_different_registers(result, Rcache);
2103 2110 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
2104 2111 __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() +
2105 2112 ConstantPoolCacheEntry::f1_offset(), result);
2106 2113 __ tst(result);
2107 2114 __ br(Assembler::notEqual, false, Assembler::pt, resolved);
2108 2115 __ delayed()->set((int)bytecode(), O1);
2109 2116 } else {
2110 2117 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
2111 2118 assert(result == noreg, ""); //else change code for setting result
2112 2119 __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, Lbyte_code, byte_no, 1, index_size);
2113 2120 __ cmp(Lbyte_code, (int) bytecode()); // have we resolved this bytecode?
2114 2121 __ br(Assembler::equal, false, Assembler::pt, resolved);
2115 2122 __ delayed()->set((int)bytecode(), O1);
2116 2123 }
2117 2124
2118 2125 address entry;
2119 2126 switch (bytecode()) {
2120 2127 case Bytecodes::_getstatic : // fall through
2121 2128 case Bytecodes::_putstatic : // fall through
2122 2129 case Bytecodes::_getfield : // fall through
2123 2130 case Bytecodes::_putfield : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
2124 2131 case Bytecodes::_invokevirtual : // fall through
2125 2132 case Bytecodes::_invokespecial : // fall through
2126 2133 case Bytecodes::_invokestatic : // fall through
2127 2134 case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke); break;
2128 2135 case Bytecodes::_invokehandle : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle); break;
2129 2136 case Bytecodes::_invokedynamic : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic); break;
2130 2137 case Bytecodes::_fast_aldc : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); break;
2131 2138 case Bytecodes::_fast_aldc_w : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); break;
2132 2139 default:
2133 2140 fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode())));
2134 2141 break;
2135 2142 }
2136 2143 // first time invocation - must resolve first
2137 2144 __ call_VM(noreg, entry, O1);
2138 2145 // Update registers with resolved info
2139 2146 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
2140 2147 if (result != noreg)
2141 2148 __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() +
2142 2149 ConstantPoolCacheEntry::f1_offset(), result);
2143 2150 __ bind(resolved);
2144 2151 }
2145 2152
2146 2153 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
2147 2154 Register method,
2148 2155 Register itable_index,
2149 2156 Register flags,
2150 2157 bool is_invokevirtual,
2151 2158 bool is_invokevfinal,
2152 2159 bool is_invokedynamic) {
2153 2160 // Uses both G3_scratch and G4_scratch
2154 2161 Register cache = G3_scratch;
2155 2162 Register index = G4_scratch;
2156 2163 assert_different_registers(cache, method, itable_index);
2157 2164
2158 2165 // determine constant pool cache field offsets
2159 2166 assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant");
2160 2167 const int method_offset = in_bytes(
2161 2168 constantPoolCacheOopDesc::base_offset() +
2162 2169 ((byte_no == f2_byte)
2163 2170 ? ConstantPoolCacheEntry::f2_offset()
2164 2171 : ConstantPoolCacheEntry::f1_offset()
2165 2172 )
2166 2173 );
2167 2174 const int flags_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
2168 2175 ConstantPoolCacheEntry::flags_offset());
2169 2176 // access constant pool cache fields
2170 2177 const int index_offset = in_bytes(constantPoolCacheOopDesc::base_offset() +
2171 2178 ConstantPoolCacheEntry::f2_offset());
2172 2179
2173 2180 if (is_invokevfinal) {
2174 2181 __ get_cache_and_index_at_bcp(cache, index, 1);
2175 2182 __ ld_ptr(Address(cache, method_offset), method);
2176 2183 } else if (byte_no == f12_oop) {
2177 2184 // Resolved f1_oop (CallSite, MethodType, etc.) goes into 'itable_index'.
2178 2185 // Resolved f2_oop (methodOop invoker) will go into 'method' (at index_offset).
2179 2186 // See ConstantPoolCacheEntry::set_dynamic_call and set_method_handle.
2180 2187 size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2));
2181 2188 resolve_cache_and_index(byte_no, itable_index, cache, index, index_size);
2182 2189 __ ld_ptr(Address(cache, index_offset), method);
2183 2190 itable_index = noreg; // hack to disable load below
2184 2191 } else {
2185 2192 resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
2186 2193 __ ld_ptr(Address(cache, method_offset), method);
2187 2194 }
2188 2195
2189 2196 if (itable_index != noreg) {
2190 2197 // pick up itable index from f2 also:
2191 2198 assert(byte_no == f1_byte, "already picked up f1");
2192 2199 __ ld_ptr(Address(cache, index_offset), itable_index);
2193 2200 }
2194 2201 __ ld_ptr(Address(cache, flags_offset), flags);
2195 2202 }
2196 2203
2197 2204 // The Rcache register must be set before call
2198 2205 void TemplateTable::load_field_cp_cache_entry(Register Robj,
2199 2206 Register Rcache,
2200 2207 Register index,
2201 2208 Register Roffset,
2202 2209 Register Rflags,
2203 2210 bool is_static) {
2204 2211 assert_different_registers(Rcache, Rflags, Roffset);
2205 2212
2206 2213 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2207 2214
2208 2215 __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), Rflags);
2209 2216 __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Roffset);
2210 2217 if (is_static) {
2211 2218 __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f1_offset(), Robj);
2212 2219 }
2213 2220 }
2214 2221
2215 2222 // The registers Rcache and index expected to be set before call.
2216 2223 // Correct values of the Rcache and index registers are preserved.
2217 2224 void TemplateTable::jvmti_post_field_access(Register Rcache,
2218 2225 Register index,
2219 2226 bool is_static,
2220 2227 bool has_tos) {
2221 2228 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2222 2229
2223 2230 if (JvmtiExport::can_post_field_access()) {
2224 2231 // Check to see if a field access watch has been set before we take
2225 2232 // the time to call into the VM.
2226 2233 Label Label1;
2227 2234 assert_different_registers(Rcache, index, G1_scratch);
2228 2235 AddressLiteral get_field_access_count_addr(JvmtiExport::get_field_access_count_addr());
2229 2236 __ load_contents(get_field_access_count_addr, G1_scratch);
2230 2237 __ cmp_and_br_short(G1_scratch, 0, Assembler::equal, Assembler::pt, Label1);
2231 2238
2232 2239 __ add(Rcache, in_bytes(cp_base_offset), Rcache);
2233 2240
2234 2241 if (is_static) {
2235 2242 __ clr(Otos_i);
2236 2243 } else {
2237 2244 if (has_tos) {
2238 2245 // save object pointer before call_VM() clobbers it
2239 2246 __ push_ptr(Otos_i); // put object on tos where GC wants it.
2240 2247 } else {
2241 2248 // Load top of stack (do not pop the value off the stack);
2242 2249 __ ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(0), Otos_i);
2243 2250 }
2244 2251 __ verify_oop(Otos_i);
2245 2252 }
2246 2253 // Otos_i: object pointer or NULL if static
2247 2254 // Rcache: cache entry pointer
2248 2255 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
2249 2256 Otos_i, Rcache);
2250 2257 if (!is_static && has_tos) {
2251 2258 __ pop_ptr(Otos_i); // restore object pointer
2252 2259 __ verify_oop(Otos_i);
2253 2260 }
2254 2261 __ get_cache_and_index_at_bcp(Rcache, index, 1);
2255 2262 __ bind(Label1);
2256 2263 }
2257 2264 }
2258 2265
2259 2266 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
2260 2267 transition(vtos, vtos);
2261 2268
2262 2269 Register Rcache = G3_scratch;
2263 2270 Register index = G4_scratch;
2264 2271 Register Rclass = Rcache;
2265 2272 Register Roffset= G4_scratch;
2266 2273 Register Rflags = G1_scratch;
2267 2274 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2268 2275
2269 2276 resolve_cache_and_index(byte_no, noreg, Rcache, index, sizeof(u2));
2270 2277 jvmti_post_field_access(Rcache, index, is_static, false);
2271 2278 load_field_cp_cache_entry(Rclass, Rcache, index, Roffset, Rflags, is_static);
2272 2279
2273 2280 if (!is_static) {
2274 2281 pop_and_check_object(Rclass);
2275 2282 } else {
2276 2283 __ verify_oop(Rclass);
2277 2284 }
2278 2285
2279 2286 Label exit;
2280 2287
2281 2288 Assembler::Membar_mask_bits membar_bits =
2282 2289 Assembler::Membar_mask_bits(Assembler::LoadLoad | Assembler::LoadStore);
2283 2290
2284 2291 if (__ membar_has_effect(membar_bits)) {
2285 2292 // Get volatile flag
2286 2293 __ set((1 << ConstantPoolCacheEntry::is_volatile_shift), Lscratch);
2287 2294 __ and3(Rflags, Lscratch, Lscratch);
2288 2295 }
2289 2296
2290 2297 Label checkVolatile;
2291 2298
2292 2299 // compute field type
2293 2300 Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj;
2294 2301 __ srl(Rflags, ConstantPoolCacheEntry::tos_state_shift, Rflags);
2295 2302 // Make sure we don't need to mask Rflags after the above shift
2296 2303 ConstantPoolCacheEntry::verify_tos_state_shift();
2297 2304
2298 2305 // Check atos before itos for getstatic, more likely (in Queens at least)
2299 2306 __ cmp(Rflags, atos);
2300 2307 __ br(Assembler::notEqual, false, Assembler::pt, notObj);
2301 2308 __ delayed() ->cmp(Rflags, itos);
2302 2309
2303 2310 // atos
2304 2311 __ load_heap_oop(Rclass, Roffset, Otos_i);
2305 2312 __ verify_oop(Otos_i);
2306 2313 __ push(atos);
2307 2314 if (!is_static) {
2308 2315 patch_bytecode(Bytecodes::_fast_agetfield, G3_scratch, G4_scratch);
2309 2316 }
2310 2317 __ ba(checkVolatile);
2311 2318 __ delayed()->tst(Lscratch);
2312 2319
2313 2320 __ bind(notObj);
2314 2321
2315 2322 // cmp(Rflags, itos);
2316 2323 __ br(Assembler::notEqual, false, Assembler::pt, notInt);
2317 2324 __ delayed() ->cmp(Rflags, ltos);
2318 2325
2319 2326 // itos
2320 2327 __ ld(Rclass, Roffset, Otos_i);
2321 2328 __ push(itos);
2322 2329 if (!is_static) {
2323 2330 patch_bytecode(Bytecodes::_fast_igetfield, G3_scratch, G4_scratch);
2324 2331 }
2325 2332 __ ba(checkVolatile);
2326 2333 __ delayed()->tst(Lscratch);
2327 2334
2328 2335 __ bind(notInt);
2329 2336
2330 2337 // cmp(Rflags, ltos);
2331 2338 __ br(Assembler::notEqual, false, Assembler::pt, notLong);
2332 2339 __ delayed() ->cmp(Rflags, btos);
2333 2340
2334 2341 // ltos
2335 2342 // load must be atomic
2336 2343 __ ld_long(Rclass, Roffset, Otos_l);
2337 2344 __ push(ltos);
2338 2345 if (!is_static) {
2339 2346 patch_bytecode(Bytecodes::_fast_lgetfield, G3_scratch, G4_scratch);
2340 2347 }
2341 2348 __ ba(checkVolatile);
2342 2349 __ delayed()->tst(Lscratch);
2343 2350
2344 2351 __ bind(notLong);
2345 2352
2346 2353 // cmp(Rflags, btos);
2347 2354 __ br(Assembler::notEqual, false, Assembler::pt, notByte);
2348 2355 __ delayed() ->cmp(Rflags, ctos);
2349 2356
2350 2357 // btos
2351 2358 __ ldsb(Rclass, Roffset, Otos_i);
2352 2359 __ push(itos);
2353 2360 if (!is_static) {
2354 2361 patch_bytecode(Bytecodes::_fast_bgetfield, G3_scratch, G4_scratch);
2355 2362 }
2356 2363 __ ba(checkVolatile);
2357 2364 __ delayed()->tst(Lscratch);
2358 2365
2359 2366 __ bind(notByte);
2360 2367
2361 2368 // cmp(Rflags, ctos);
2362 2369 __ br(Assembler::notEqual, false, Assembler::pt, notChar);
2363 2370 __ delayed() ->cmp(Rflags, stos);
2364 2371
2365 2372 // ctos
2366 2373 __ lduh(Rclass, Roffset, Otos_i);
2367 2374 __ push(itos);
2368 2375 if (!is_static) {
2369 2376 patch_bytecode(Bytecodes::_fast_cgetfield, G3_scratch, G4_scratch);
2370 2377 }
2371 2378 __ ba(checkVolatile);
2372 2379 __ delayed()->tst(Lscratch);
2373 2380
2374 2381 __ bind(notChar);
2375 2382
2376 2383 // cmp(Rflags, stos);
2377 2384 __ br(Assembler::notEqual, false, Assembler::pt, notShort);
2378 2385 __ delayed() ->cmp(Rflags, ftos);
2379 2386
2380 2387 // stos
2381 2388 __ ldsh(Rclass, Roffset, Otos_i);
2382 2389 __ push(itos);
2383 2390 if (!is_static) {
2384 2391 patch_bytecode(Bytecodes::_fast_sgetfield, G3_scratch, G4_scratch);
2385 2392 }
2386 2393 __ ba(checkVolatile);
2387 2394 __ delayed()->tst(Lscratch);
2388 2395
2389 2396 __ bind(notShort);
2390 2397
2391 2398
2392 2399 // cmp(Rflags, ftos);
2393 2400 __ br(Assembler::notEqual, false, Assembler::pt, notFloat);
2394 2401 __ delayed() ->tst(Lscratch);
2395 2402
2396 2403 // ftos
2397 2404 __ ldf(FloatRegisterImpl::S, Rclass, Roffset, Ftos_f);
2398 2405 __ push(ftos);
2399 2406 if (!is_static) {
2400 2407 patch_bytecode(Bytecodes::_fast_fgetfield, G3_scratch, G4_scratch);
2401 2408 }
2402 2409 __ ba(checkVolatile);
2403 2410 __ delayed()->tst(Lscratch);
2404 2411
2405 2412 __ bind(notFloat);
2406 2413
2407 2414
2408 2415 // dtos
2409 2416 __ ldf(FloatRegisterImpl::D, Rclass, Roffset, Ftos_d);
2410 2417 __ push(dtos);
2411 2418 if (!is_static) {
2412 2419 patch_bytecode(Bytecodes::_fast_dgetfield, G3_scratch, G4_scratch);
2413 2420 }
2414 2421
2415 2422 __ bind(checkVolatile);
2416 2423 if (__ membar_has_effect(membar_bits)) {
2417 2424 // __ tst(Lscratch); executed in delay slot
2418 2425 __ br(Assembler::zero, false, Assembler::pt, exit);
2419 2426 __ delayed()->nop();
2420 2427 volatile_barrier(membar_bits);
2421 2428 }
2422 2429
2423 2430 __ bind(exit);
2424 2431 }
2425 2432
2426 2433
2427 2434 void TemplateTable::getfield(int byte_no) {
2428 2435 getfield_or_static(byte_no, false);
2429 2436 }
2430 2437
2431 2438 void TemplateTable::getstatic(int byte_no) {
2432 2439 getfield_or_static(byte_no, true);
2433 2440 }
2434 2441
2435 2442
2436 2443 void TemplateTable::fast_accessfield(TosState state) {
2437 2444 transition(atos, state);
2438 2445 Register Rcache = G3_scratch;
2439 2446 Register index = G4_scratch;
2440 2447 Register Roffset = G4_scratch;
2441 2448 Register Rflags = Rcache;
2442 2449 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2443 2450
2444 2451 __ get_cache_and_index_at_bcp(Rcache, index, 1);
2445 2452 jvmti_post_field_access(Rcache, index, /*is_static*/false, /*has_tos*/true);
2446 2453
2447 2454 __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Roffset);
2448 2455
2449 2456 __ null_check(Otos_i);
2450 2457 __ verify_oop(Otos_i);
2451 2458
2452 2459 Label exit;
2453 2460
2454 2461 Assembler::Membar_mask_bits membar_bits =
2455 2462 Assembler::Membar_mask_bits(Assembler::LoadLoad | Assembler::LoadStore);
2456 2463 if (__ membar_has_effect(membar_bits)) {
2457 2464 // Get volatile flag
2458 2465 __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Rflags);
2459 2466 __ set((1 << ConstantPoolCacheEntry::is_volatile_shift), Lscratch);
2460 2467 }
2461 2468
2462 2469 switch (bytecode()) {
2463 2470 case Bytecodes::_fast_bgetfield:
2464 2471 __ ldsb(Otos_i, Roffset, Otos_i);
2465 2472 break;
2466 2473 case Bytecodes::_fast_cgetfield:
2467 2474 __ lduh(Otos_i, Roffset, Otos_i);
2468 2475 break;
2469 2476 case Bytecodes::_fast_sgetfield:
2470 2477 __ ldsh(Otos_i, Roffset, Otos_i);
2471 2478 break;
2472 2479 case Bytecodes::_fast_igetfield:
2473 2480 __ ld(Otos_i, Roffset, Otos_i);
2474 2481 break;
2475 2482 case Bytecodes::_fast_lgetfield:
2476 2483 __ ld_long(Otos_i, Roffset, Otos_l);
2477 2484 break;
2478 2485 case Bytecodes::_fast_fgetfield:
2479 2486 __ ldf(FloatRegisterImpl::S, Otos_i, Roffset, Ftos_f);
2480 2487 break;
2481 2488 case Bytecodes::_fast_dgetfield:
2482 2489 __ ldf(FloatRegisterImpl::D, Otos_i, Roffset, Ftos_d);
2483 2490 break;
2484 2491 case Bytecodes::_fast_agetfield:
2485 2492 __ load_heap_oop(Otos_i, Roffset, Otos_i);
2486 2493 break;
2487 2494 default:
2488 2495 ShouldNotReachHere();
2489 2496 }
2490 2497
2491 2498 if (__ membar_has_effect(membar_bits)) {
2492 2499 __ btst(Lscratch, Rflags);
2493 2500 __ br(Assembler::zero, false, Assembler::pt, exit);
2494 2501 __ delayed()->nop();
2495 2502 volatile_barrier(membar_bits);
2496 2503 __ bind(exit);
2497 2504 }
2498 2505
2499 2506 if (state == atos) {
2500 2507 __ verify_oop(Otos_i); // does not blow flags!
2501 2508 }
2502 2509 }
2503 2510
2504 2511 void TemplateTable::jvmti_post_fast_field_mod() {
2505 2512 if (JvmtiExport::can_post_field_modification()) {
2506 2513 // Check to see if a field modification watch has been set before we take
2507 2514 // the time to call into the VM.
2508 2515 Label done;
2509 2516 AddressLiteral get_field_modification_count_addr(JvmtiExport::get_field_modification_count_addr());
2510 2517 __ load_contents(get_field_modification_count_addr, G4_scratch);
2511 2518 __ cmp_and_br_short(G4_scratch, 0, Assembler::equal, Assembler::pt, done);
2512 2519 __ pop_ptr(G4_scratch); // copy the object pointer from tos
2513 2520 __ verify_oop(G4_scratch);
2514 2521 __ push_ptr(G4_scratch); // put the object pointer back on tos
2515 2522 __ get_cache_entry_pointer_at_bcp(G1_scratch, G3_scratch, 1);
2516 2523 // Save tos values before call_VM() clobbers them. Since we have
2517 2524 // to do it for every data type, we use the saved values as the
2518 2525 // jvalue object.
2519 2526 switch (bytecode()) { // save tos values before call_VM() clobbers them
2520 2527 case Bytecodes::_fast_aputfield: __ push_ptr(Otos_i); break;
2521 2528 case Bytecodes::_fast_bputfield: // fall through
2522 2529 case Bytecodes::_fast_sputfield: // fall through
2523 2530 case Bytecodes::_fast_cputfield: // fall through
2524 2531 case Bytecodes::_fast_iputfield: __ push_i(Otos_i); break;
2525 2532 case Bytecodes::_fast_dputfield: __ push_d(Ftos_d); break;
2526 2533 case Bytecodes::_fast_fputfield: __ push_f(Ftos_f); break;
2527 2534 // get words in right order for use as jvalue object
2528 2535 case Bytecodes::_fast_lputfield: __ push_l(Otos_l); break;
2529 2536 }
2530 2537 // setup pointer to jvalue object
2531 2538 __ mov(Lesp, G3_scratch); __ inc(G3_scratch, wordSize);
2532 2539 // G4_scratch: object pointer
2533 2540 // G1_scratch: cache entry pointer
2534 2541 // G3_scratch: jvalue object on the stack
2535 2542 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), G4_scratch, G1_scratch, G3_scratch);
2536 2543 switch (bytecode()) { // restore tos values
2537 2544 case Bytecodes::_fast_aputfield: __ pop_ptr(Otos_i); break;
2538 2545 case Bytecodes::_fast_bputfield: // fall through
2539 2546 case Bytecodes::_fast_sputfield: // fall through
2540 2547 case Bytecodes::_fast_cputfield: // fall through
2541 2548 case Bytecodes::_fast_iputfield: __ pop_i(Otos_i); break;
2542 2549 case Bytecodes::_fast_dputfield: __ pop_d(Ftos_d); break;
2543 2550 case Bytecodes::_fast_fputfield: __ pop_f(Ftos_f); break;
2544 2551 case Bytecodes::_fast_lputfield: __ pop_l(Otos_l); break;
2545 2552 }
2546 2553 __ bind(done);
2547 2554 }
2548 2555 }
2549 2556
2550 2557 // The registers Rcache and index expected to be set before call.
2551 2558 // The function may destroy various registers, just not the Rcache and index registers.
2552 2559 void TemplateTable::jvmti_post_field_mod(Register Rcache, Register index, bool is_static) {
2553 2560 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2554 2561
2555 2562 if (JvmtiExport::can_post_field_modification()) {
2556 2563 // Check to see if a field modification watch has been set before we take
2557 2564 // the time to call into the VM.
2558 2565 Label Label1;
2559 2566 assert_different_registers(Rcache, index, G1_scratch);
2560 2567 AddressLiteral get_field_modification_count_addr(JvmtiExport::get_field_modification_count_addr());
2561 2568 __ load_contents(get_field_modification_count_addr, G1_scratch);
2562 2569 __ cmp_and_br_short(G1_scratch, 0, Assembler::zero, Assembler::pt, Label1);
2563 2570
2564 2571 // The Rcache and index registers have been already set.
2565 2572 // This allows to eliminate this call but the Rcache and index
2566 2573 // registers must be correspondingly used after this line.
2567 2574 __ get_cache_and_index_at_bcp(G1_scratch, G4_scratch, 1);
2568 2575
2569 2576 __ add(G1_scratch, in_bytes(cp_base_offset), G3_scratch);
2570 2577 if (is_static) {
2571 2578 // Life is simple. Null out the object pointer.
2572 2579 __ clr(G4_scratch);
2573 2580 } else {
2574 2581 Register Rflags = G1_scratch;
2575 2582 // Life is harder. The stack holds the value on top, followed by the
2576 2583 // object. We don't know the size of the value, though; it could be
2577 2584 // one or two words depending on its type. As a result, we must find
2578 2585 // the type to determine where the object is.
2579 2586
2580 2587 Label two_word, valsizeknown;
2581 2588 __ ld_ptr(G1_scratch, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), Rflags);
2582 2589 __ mov(Lesp, G4_scratch);
2583 2590 __ srl(Rflags, ConstantPoolCacheEntry::tos_state_shift, Rflags);
2584 2591 // Make sure we don't need to mask Rflags after the above shift
2585 2592 ConstantPoolCacheEntry::verify_tos_state_shift();
2586 2593 __ cmp(Rflags, ltos);
2587 2594 __ br(Assembler::equal, false, Assembler::pt, two_word);
2588 2595 __ delayed()->cmp(Rflags, dtos);
2589 2596 __ br(Assembler::equal, false, Assembler::pt, two_word);
2590 2597 __ delayed()->nop();
2591 2598 __ inc(G4_scratch, Interpreter::expr_offset_in_bytes(1));
2592 2599 __ ba_short(valsizeknown);
2593 2600 __ bind(two_word);
2594 2601
2595 2602 __ inc(G4_scratch, Interpreter::expr_offset_in_bytes(2));
2596 2603
2597 2604 __ bind(valsizeknown);
2598 2605 // setup object pointer
2599 2606 __ ld_ptr(G4_scratch, 0, G4_scratch);
2600 2607 __ verify_oop(G4_scratch);
2601 2608 }
2602 2609 // setup pointer to jvalue object
2603 2610 __ mov(Lesp, G1_scratch); __ inc(G1_scratch, wordSize);
2604 2611 // G4_scratch: object pointer or NULL if static
2605 2612 // G3_scratch: cache entry pointer
2606 2613 // G1_scratch: jvalue object on the stack
2607 2614 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
2608 2615 G4_scratch, G3_scratch, G1_scratch);
2609 2616 __ get_cache_and_index_at_bcp(Rcache, index, 1);
2610 2617 __ bind(Label1);
2611 2618 }
2612 2619 }
2613 2620
2614 2621 void TemplateTable::pop_and_check_object(Register r) {
2615 2622 __ pop_ptr(r);
2616 2623 __ null_check(r); // for field access must check obj.
2617 2624 __ verify_oop(r);
2618 2625 }
2619 2626
2620 2627 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
2621 2628 transition(vtos, vtos);
2622 2629 Register Rcache = G3_scratch;
2623 2630 Register index = G4_scratch;
2624 2631 Register Rclass = Rcache;
2625 2632 Register Roffset= G4_scratch;
2626 2633 Register Rflags = G1_scratch;
2627 2634 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2628 2635
2629 2636 resolve_cache_and_index(byte_no, noreg, Rcache, index, sizeof(u2));
2630 2637 jvmti_post_field_mod(Rcache, index, is_static);
2631 2638 load_field_cp_cache_entry(Rclass, Rcache, index, Roffset, Rflags, is_static);
2632 2639
2633 2640 Assembler::Membar_mask_bits read_bits =
2634 2641 Assembler::Membar_mask_bits(Assembler::LoadStore | Assembler::StoreStore);
2635 2642 Assembler::Membar_mask_bits write_bits = Assembler::StoreLoad;
2636 2643
2637 2644 Label notVolatile, checkVolatile, exit;
2638 2645 if (__ membar_has_effect(read_bits) || __ membar_has_effect(write_bits)) {
2639 2646 __ set((1 << ConstantPoolCacheEntry::is_volatile_shift), Lscratch);
2640 2647 __ and3(Rflags, Lscratch, Lscratch);
2641 2648
2642 2649 if (__ membar_has_effect(read_bits)) {
2643 2650 __ cmp_and_br_short(Lscratch, 0, Assembler::equal, Assembler::pt, notVolatile);
2644 2651 volatile_barrier(read_bits);
2645 2652 __ bind(notVolatile);
2646 2653 }
2647 2654 }
2648 2655
2649 2656 __ srl(Rflags, ConstantPoolCacheEntry::tos_state_shift, Rflags);
2650 2657 // Make sure we don't need to mask Rflags after the above shift
2651 2658 ConstantPoolCacheEntry::verify_tos_state_shift();
2652 2659
2653 2660 // compute field type
2654 2661 Label notInt, notShort, notChar, notObj, notByte, notLong, notFloat;
2655 2662
2656 2663 if (is_static) {
2657 2664 // putstatic with object type most likely, check that first
2658 2665 __ cmp(Rflags, atos);
2659 2666 __ br(Assembler::notEqual, false, Assembler::pt, notObj);
2660 2667 __ delayed()->cmp(Rflags, itos);
2661 2668
2662 2669 // atos
2663 2670 {
2664 2671 __ pop_ptr();
2665 2672 __ verify_oop(Otos_i);
2666 2673 do_oop_store(_masm, Rclass, Roffset, 0, Otos_i, G1_scratch, _bs->kind(), false);
2667 2674 __ ba(checkVolatile);
2668 2675 __ delayed()->tst(Lscratch);
2669 2676 }
2670 2677
2671 2678 __ bind(notObj);
2672 2679 // cmp(Rflags, itos);
2673 2680 __ br(Assembler::notEqual, false, Assembler::pt, notInt);
2674 2681 __ delayed()->cmp(Rflags, btos);
2675 2682
2676 2683 // itos
2677 2684 {
2678 2685 __ pop_i();
2679 2686 __ st(Otos_i, Rclass, Roffset);
2680 2687 __ ba(checkVolatile);
2681 2688 __ delayed()->tst(Lscratch);
2682 2689 }
2683 2690
2684 2691 __ bind(notInt);
2685 2692 } else {
2686 2693 // putfield with int type most likely, check that first
2687 2694 __ cmp(Rflags, itos);
2688 2695 __ br(Assembler::notEqual, false, Assembler::pt, notInt);
2689 2696 __ delayed()->cmp(Rflags, atos);
2690 2697
2691 2698 // itos
2692 2699 {
2693 2700 __ pop_i();
2694 2701 pop_and_check_object(Rclass);
2695 2702 __ st(Otos_i, Rclass, Roffset);
2696 2703 patch_bytecode(Bytecodes::_fast_iputfield, G3_scratch, G4_scratch, true, byte_no);
2697 2704 __ ba(checkVolatile);
2698 2705 __ delayed()->tst(Lscratch);
2699 2706 }
2700 2707
2701 2708 __ bind(notInt);
2702 2709 // cmp(Rflags, atos);
2703 2710 __ br(Assembler::notEqual, false, Assembler::pt, notObj);
2704 2711 __ delayed()->cmp(Rflags, btos);
2705 2712
2706 2713 // atos
2707 2714 {
2708 2715 __ pop_ptr();
2709 2716 pop_and_check_object(Rclass);
2710 2717 __ verify_oop(Otos_i);
2711 2718 do_oop_store(_masm, Rclass, Roffset, 0, Otos_i, G1_scratch, _bs->kind(), false);
2712 2719 patch_bytecode(Bytecodes::_fast_aputfield, G3_scratch, G4_scratch, true, byte_no);
2713 2720 __ ba(checkVolatile);
2714 2721 __ delayed()->tst(Lscratch);
2715 2722 }
2716 2723
2717 2724 __ bind(notObj);
2718 2725 }
2719 2726
2720 2727 // cmp(Rflags, btos);
2721 2728 __ br(Assembler::notEqual, false, Assembler::pt, notByte);
2722 2729 __ delayed()->cmp(Rflags, ltos);
2723 2730
2724 2731 // btos
2725 2732 {
2726 2733 __ pop_i();
2727 2734 if (!is_static) pop_and_check_object(Rclass);
2728 2735 __ stb(Otos_i, Rclass, Roffset);
2729 2736 if (!is_static) {
2730 2737 patch_bytecode(Bytecodes::_fast_bputfield, G3_scratch, G4_scratch, true, byte_no);
2731 2738 }
2732 2739 __ ba(checkVolatile);
2733 2740 __ delayed()->tst(Lscratch);
2734 2741 }
2735 2742
2736 2743 __ bind(notByte);
2737 2744 // cmp(Rflags, ltos);
2738 2745 __ br(Assembler::notEqual, false, Assembler::pt, notLong);
2739 2746 __ delayed()->cmp(Rflags, ctos);
2740 2747
2741 2748 // ltos
2742 2749 {
2743 2750 __ pop_l();
2744 2751 if (!is_static) pop_and_check_object(Rclass);
2745 2752 __ st_long(Otos_l, Rclass, Roffset);
2746 2753 if (!is_static) {
2747 2754 patch_bytecode(Bytecodes::_fast_lputfield, G3_scratch, G4_scratch, true, byte_no);
2748 2755 }
2749 2756 __ ba(checkVolatile);
2750 2757 __ delayed()->tst(Lscratch);
2751 2758 }
2752 2759
2753 2760 __ bind(notLong);
2754 2761 // cmp(Rflags, ctos);
2755 2762 __ br(Assembler::notEqual, false, Assembler::pt, notChar);
2756 2763 __ delayed()->cmp(Rflags, stos);
2757 2764
2758 2765 // ctos (char)
2759 2766 {
2760 2767 __ pop_i();
2761 2768 if (!is_static) pop_and_check_object(Rclass);
2762 2769 __ sth(Otos_i, Rclass, Roffset);
2763 2770 if (!is_static) {
2764 2771 patch_bytecode(Bytecodes::_fast_cputfield, G3_scratch, G4_scratch, true, byte_no);
2765 2772 }
2766 2773 __ ba(checkVolatile);
2767 2774 __ delayed()->tst(Lscratch);
2768 2775 }
2769 2776
2770 2777 __ bind(notChar);
2771 2778 // cmp(Rflags, stos);
2772 2779 __ br(Assembler::notEqual, false, Assembler::pt, notShort);
2773 2780 __ delayed()->cmp(Rflags, ftos);
2774 2781
2775 2782 // stos (short)
2776 2783 {
2777 2784 __ pop_i();
2778 2785 if (!is_static) pop_and_check_object(Rclass);
2779 2786 __ sth(Otos_i, Rclass, Roffset);
2780 2787 if (!is_static) {
2781 2788 patch_bytecode(Bytecodes::_fast_sputfield, G3_scratch, G4_scratch, true, byte_no);
2782 2789 }
2783 2790 __ ba(checkVolatile);
2784 2791 __ delayed()->tst(Lscratch);
2785 2792 }
2786 2793
2787 2794 __ bind(notShort);
2788 2795 // cmp(Rflags, ftos);
2789 2796 __ br(Assembler::notZero, false, Assembler::pt, notFloat);
2790 2797 __ delayed()->nop();
2791 2798
2792 2799 // ftos
2793 2800 {
2794 2801 __ pop_f();
2795 2802 if (!is_static) pop_and_check_object(Rclass);
2796 2803 __ stf(FloatRegisterImpl::S, Ftos_f, Rclass, Roffset);
2797 2804 if (!is_static) {
2798 2805 patch_bytecode(Bytecodes::_fast_fputfield, G3_scratch, G4_scratch, true, byte_no);
2799 2806 }
2800 2807 __ ba(checkVolatile);
2801 2808 __ delayed()->tst(Lscratch);
2802 2809 }
2803 2810
2804 2811 __ bind(notFloat);
2805 2812
2806 2813 // dtos
2807 2814 {
2808 2815 __ pop_d();
2809 2816 if (!is_static) pop_and_check_object(Rclass);
2810 2817 __ stf(FloatRegisterImpl::D, Ftos_d, Rclass, Roffset);
2811 2818 if (!is_static) {
2812 2819 patch_bytecode(Bytecodes::_fast_dputfield, G3_scratch, G4_scratch, true, byte_no);
2813 2820 }
2814 2821 }
2815 2822
2816 2823 __ bind(checkVolatile);
2817 2824 __ tst(Lscratch);
2818 2825
2819 2826 if (__ membar_has_effect(write_bits)) {
2820 2827 // __ tst(Lscratch); in delay slot
2821 2828 __ br(Assembler::zero, false, Assembler::pt, exit);
2822 2829 __ delayed()->nop();
2823 2830 volatile_barrier(Assembler::StoreLoad);
2824 2831 __ bind(exit);
2825 2832 }
2826 2833 }
2827 2834
2828 2835 void TemplateTable::fast_storefield(TosState state) {
2829 2836 transition(state, vtos);
2830 2837 Register Rcache = G3_scratch;
2831 2838 Register Rclass = Rcache;
2832 2839 Register Roffset= G4_scratch;
2833 2840 Register Rflags = G1_scratch;
2834 2841 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
2835 2842
2836 2843 jvmti_post_fast_field_mod();
2837 2844
2838 2845 __ get_cache_and_index_at_bcp(Rcache, G4_scratch, 1);
2839 2846
2840 2847 Assembler::Membar_mask_bits read_bits =
2841 2848 Assembler::Membar_mask_bits(Assembler::LoadStore | Assembler::StoreStore);
2842 2849 Assembler::Membar_mask_bits write_bits = Assembler::StoreLoad;
2843 2850
2844 2851 Label notVolatile, checkVolatile, exit;
2845 2852 if (__ membar_has_effect(read_bits) || __ membar_has_effect(write_bits)) {
2846 2853 __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), Rflags);
2847 2854 __ set((1 << ConstantPoolCacheEntry::is_volatile_shift), Lscratch);
2848 2855 __ and3(Rflags, Lscratch, Lscratch);
2849 2856 if (__ membar_has_effect(read_bits)) {
2850 2857 __ cmp_and_br_short(Lscratch, 0, Assembler::equal, Assembler::pt, notVolatile);
2851 2858 volatile_barrier(read_bits);
2852 2859 __ bind(notVolatile);
2853 2860 }
2854 2861 }
2855 2862
2856 2863 __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Roffset);
2857 2864 pop_and_check_object(Rclass);
2858 2865
2859 2866 switch (bytecode()) {
2860 2867 case Bytecodes::_fast_bputfield: __ stb(Otos_i, Rclass, Roffset); break;
2861 2868 case Bytecodes::_fast_cputfield: /* fall through */
2862 2869 case Bytecodes::_fast_sputfield: __ sth(Otos_i, Rclass, Roffset); break;
2863 2870 case Bytecodes::_fast_iputfield: __ st(Otos_i, Rclass, Roffset); break;
2864 2871 case Bytecodes::_fast_lputfield: __ st_long(Otos_l, Rclass, Roffset); break;
2865 2872 case Bytecodes::_fast_fputfield:
2866 2873 __ stf(FloatRegisterImpl::S, Ftos_f, Rclass, Roffset);
2867 2874 break;
2868 2875 case Bytecodes::_fast_dputfield:
2869 2876 __ stf(FloatRegisterImpl::D, Ftos_d, Rclass, Roffset);
2870 2877 break;
2871 2878 case Bytecodes::_fast_aputfield:
2872 2879 do_oop_store(_masm, Rclass, Roffset, 0, Otos_i, G1_scratch, _bs->kind(), false);
2873 2880 break;
2874 2881 default:
2875 2882 ShouldNotReachHere();
2876 2883 }
2877 2884
2878 2885 if (__ membar_has_effect(write_bits)) {
2879 2886 __ cmp_and_br_short(Lscratch, 0, Assembler::equal, Assembler::pt, exit);
2880 2887 volatile_barrier(Assembler::StoreLoad);
2881 2888 __ bind(exit);
2882 2889 }
2883 2890 }
2884 2891
2885 2892
2886 2893 void TemplateTable::putfield(int byte_no) {
2887 2894 putfield_or_static(byte_no, false);
2888 2895 }
2889 2896
2890 2897 void TemplateTable::putstatic(int byte_no) {
2891 2898 putfield_or_static(byte_no, true);
2892 2899 }
2893 2900
2894 2901
2895 2902 void TemplateTable::fast_xaccess(TosState state) {
2896 2903 transition(vtos, state);
2897 2904 Register Rcache = G3_scratch;
2898 2905 Register Roffset = G4_scratch;
2899 2906 Register Rflags = G4_scratch;
2900 2907 Register Rreceiver = Lscratch;
2901 2908
2902 2909 __ ld_ptr(Llocals, 0, Rreceiver);
2903 2910
2904 2911 // access constant pool cache (is resolved)
2905 2912 __ get_cache_and_index_at_bcp(Rcache, G4_scratch, 2);
2906 2913 __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset(), Roffset);
2907 2914 __ add(Lbcp, 1, Lbcp); // needed to report exception at the correct bcp
2908 2915
2909 2916 __ verify_oop(Rreceiver);
2910 2917 __ null_check(Rreceiver);
2911 2918 if (state == atos) {
2912 2919 __ load_heap_oop(Rreceiver, Roffset, Otos_i);
2913 2920 } else if (state == itos) {
2914 2921 __ ld (Rreceiver, Roffset, Otos_i) ;
2915 2922 } else if (state == ftos) {
2916 2923 __ ldf(FloatRegisterImpl::S, Rreceiver, Roffset, Ftos_f);
2917 2924 } else {
2918 2925 ShouldNotReachHere();
2919 2926 }
2920 2927
2921 2928 Assembler::Membar_mask_bits membar_bits =
2922 2929 Assembler::Membar_mask_bits(Assembler::LoadLoad | Assembler::LoadStore);
2923 2930 if (__ membar_has_effect(membar_bits)) {
2924 2931
2925 2932 // Get is_volatile value in Rflags and check if membar is needed
2926 2933 __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset(), Rflags);
2927 2934
2928 2935 // Test volatile
2929 2936 Label notVolatile;
2930 2937 __ set((1 << ConstantPoolCacheEntry::is_volatile_shift), Lscratch);
2931 2938 __ btst(Rflags, Lscratch);
2932 2939 __ br(Assembler::zero, false, Assembler::pt, notVolatile);
2933 2940 __ delayed()->nop();
2934 2941 volatile_barrier(membar_bits);
2935 2942 __ bind(notVolatile);
2936 2943 }
2937 2944
2938 2945 __ interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
2939 2946 __ sub(Lbcp, 1, Lbcp);
2940 2947 }
2941 2948
2942 2949 //----------------------------------------------------------------------------------------------------
2943 2950 // Calls
2944 2951
2945 2952 void TemplateTable::count_calls(Register method, Register temp) {
2946 2953 // implemented elsewhere
2947 2954 ShouldNotReachHere();
2948 2955 }
2949 2956
2950 2957
2951 2958 void TemplateTable::prepare_invoke(int byte_no,
2952 2959 Register method, // linked method (or i-klass)
2953 2960 Register ra, // return address
2954 2961 Register index, // itable index, MethodType, etc.
2955 2962 Register recv, // if caller wants to see it
2956 2963 Register flags // if caller wants to test it
2957 2964 ) {
2958 2965 // determine flags
2959 2966 const Bytecodes::Code code = bytecode();
2960 2967 const bool is_invokeinterface = code == Bytecodes::_invokeinterface;
2961 2968 const bool is_invokedynamic = code == Bytecodes::_invokedynamic;
2962 2969 const bool is_invokehandle = code == Bytecodes::_invokehandle;
2963 2970 const bool is_invokevirtual = code == Bytecodes::_invokevirtual;
2964 2971 const bool is_invokespecial = code == Bytecodes::_invokespecial;
2965 2972 const bool load_receiver = (recv != noreg);
2966 2973 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), "");
2967 2974 assert(recv == noreg || recv == O0, "");
2968 2975 assert(flags == noreg || flags == O1, "");
2969 2976
2970 2977 // setup registers & access constant pool cache
2971 2978 if (recv == noreg) recv = O0;
2972 2979 if (flags == noreg) flags = O1;
2973 2980 const Register temp = O2;
2974 2981 assert_different_registers(method, ra, index, recv, flags, temp);
2975 2982
2976 2983 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
2977 2984
2978 2985 __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore
2979 2986
2980 2987 // maybe push appendix to arguments
2981 2988 if (is_invokedynamic || is_invokehandle) {
2982 2989 Label L_no_push;
2983 2990 __ verify_oop(index);
2984 2991 __ set((1 << ConstantPoolCacheEntry::has_appendix_shift), temp);
2985 2992 __ btst(flags, temp);
2986 2993 __ br(Assembler::zero, false, Assembler::pt, L_no_push);
2987 2994 __ delayed()->nop();
2988 2995 // Push the appendix as a trailing parameter.
2989 2996 // This must be done before we get the receiver,
2990 2997 // since the parameter_size includes it.
2991 2998 __ push_ptr(index); // push appendix (MethodType, CallSite, etc.)
2992 2999 __ bind(L_no_push);
2993 3000 }
2994 3001
2995 3002 // load receiver if needed (after appendix is pushed so parameter size is correct)
2996 3003 if (load_receiver) {
2997 3004 __ and3(flags, ConstantPoolCacheEntry::parameter_size_mask, temp); // get parameter size
2998 3005 __ load_receiver(temp, recv); // __ argument_address uses Gargs but we need Lesp
2999 3006 __ verify_oop(recv);
3000 3007 }
3001 3008
3002 3009 // compute return type
3003 3010 __ srl(flags, ConstantPoolCacheEntry::tos_state_shift, ra);
3004 3011 // Make sure we don't need to mask flags after the above shift
3005 3012 ConstantPoolCacheEntry::verify_tos_state_shift();
3006 3013 // load return address
3007 3014 {
3008 3015 const address table_addr = (is_invokeinterface || is_invokedynamic) ?
3009 3016 (address)Interpreter::return_5_addrs_by_index_table() :
3010 3017 (address)Interpreter::return_3_addrs_by_index_table();
3011 3018 AddressLiteral table(table_addr);
3012 3019 __ set(table, temp);
3013 3020 __ sll(ra, LogBytesPerWord, ra);
3014 3021 __ ld_ptr(Address(temp, ra), ra);
3015 3022 }
3016 3023 }
3017 3024
3018 3025
3019 3026 void TemplateTable::generate_vtable_call(Register Rrecv, Register Rindex, Register Rret) {
3020 3027 Register Rtemp = G4_scratch;
3021 3028 Register Rcall = Rindex;
3022 3029 assert_different_registers(Rcall, G5_method, Gargs, Rret);
3023 3030
3024 3031 // get target methodOop & entry point
3025 3032 __ lookup_virtual_method(Rrecv, Rindex, G5_method);
3026 3033 __ call_from_interpreter(Rcall, Gargs, Rret);
3027 3034 }
3028 3035
3029 3036 void TemplateTable::invokevirtual(int byte_no) {
3030 3037 transition(vtos, vtos);
3031 3038 assert(byte_no == f2_byte, "use this argument");
3032 3039
3033 3040 Register Rscratch = G3_scratch;
3034 3041 Register Rtemp = G4_scratch;
3035 3042 Register Rret = Lscratch;
3036 3043 Register O0_recv = O0;
3037 3044 Label notFinal;
3038 3045
3039 3046 load_invoke_cp_cache_entry(byte_no, G5_method, noreg, Rret, true, false, false);
3040 3047 __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore
3041 3048
3042 3049 // Check for vfinal
3043 3050 __ set((1 << ConstantPoolCacheEntry::is_vfinal_shift), G4_scratch);
3044 3051 __ btst(Rret, G4_scratch);
3045 3052 __ br(Assembler::zero, false, Assembler::pt, notFinal);
3046 3053 __ delayed()->and3(Rret, 0xFF, G4_scratch); // gets number of parameters
3047 3054
3048 3055 patch_bytecode(Bytecodes::_fast_invokevfinal, Rscratch, Rtemp);
3049 3056
3050 3057 invokevfinal_helper(Rscratch, Rret);
3051 3058
3052 3059 __ bind(notFinal);
3053 3060
3054 3061 __ mov(G5_method, Rscratch); // better scratch register
3055 3062 __ load_receiver(G4_scratch, O0_recv); // gets receiverOop
3056 3063 // receiver is in O0_recv
3057 3064 __ verify_oop(O0_recv);
3058 3065
3059 3066 // get return address
3060 3067 AddressLiteral table(Interpreter::return_3_addrs_by_index_table());
3061 3068 __ set(table, Rtemp);
3062 3069 __ srl(Rret, ConstantPoolCacheEntry::tos_state_shift, Rret); // get return type
3063 3070 // Make sure we don't need to mask Rret after the above shift
3064 3071 ConstantPoolCacheEntry::verify_tos_state_shift();
3065 3072 __ sll(Rret, LogBytesPerWord, Rret);
3066 3073 __ ld_ptr(Rtemp, Rret, Rret); // get return address
3067 3074
3068 3075 // get receiver klass
3069 3076 __ null_check(O0_recv, oopDesc::klass_offset_in_bytes());
3070 3077 __ load_klass(O0_recv, O0_recv);
3071 3078 __ verify_oop(O0_recv);
3072 3079
3073 3080 __ profile_virtual_call(O0_recv, O4);
3074 3081
3075 3082 generate_vtable_call(O0_recv, Rscratch, Rret);
3076 3083 }
3077 3084
3078 3085 void TemplateTable::fast_invokevfinal(int byte_no) {
3079 3086 transition(vtos, vtos);
3080 3087 assert(byte_no == f2_byte, "use this argument");
3081 3088
3082 3089 load_invoke_cp_cache_entry(byte_no, G5_method, noreg, Lscratch, true,
3083 3090 /*is_invokevfinal*/true, false);
3084 3091 __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore
3085 3092 invokevfinal_helper(G3_scratch, Lscratch);
3086 3093 }
3087 3094
3088 3095 void TemplateTable::invokevfinal_helper(Register Rscratch, Register Rret) {
3089 3096 Register Rtemp = G4_scratch;
3090 3097
3091 3098 __ verify_oop(G5_method);
3092 3099
3093 3100 // Load receiver from stack slot
3094 3101 __ lduh(G5_method, in_bytes(methodOopDesc::size_of_parameters_offset()), G4_scratch);
3095 3102 __ load_receiver(G4_scratch, O0);
3096 3103
3097 3104 // receiver NULL check
3098 3105 __ null_check(O0);
3099 3106
3100 3107 __ profile_final_call(O4);
3101 3108
3102 3109 // get return address
3103 3110 AddressLiteral table(Interpreter::return_3_addrs_by_index_table());
3104 3111 __ set(table, Rtemp);
3105 3112 __ srl(Rret, ConstantPoolCacheEntry::tos_state_shift, Rret); // get return type
3106 3113 // Make sure we don't need to mask Rret after the above shift
3107 3114 ConstantPoolCacheEntry::verify_tos_state_shift();
3108 3115 __ sll(Rret, LogBytesPerWord, Rret);
3109 3116 __ ld_ptr(Rtemp, Rret, Rret); // get return address
3110 3117
3111 3118
3112 3119 // do the call
3113 3120 __ call_from_interpreter(Rscratch, Gargs, Rret);
3114 3121 }
3115 3122
3116 3123
3117 3124 void TemplateTable::invokespecial(int byte_no) {
3118 3125 transition(vtos, vtos);
3119 3126 assert(byte_no == f1_byte, "use this argument");
3120 3127
3121 3128 const Register Rret = Lscratch;
3122 3129 const Register O0_recv = O0;
3123 3130 const Register Rscratch = G3_scratch;
3124 3131
3125 3132 prepare_invoke(byte_no, G5_method, Rret, noreg, O0_recv); // get receiver also for null check
3126 3133 __ null_check(O0_recv);
3127 3134
3128 3135 // do the call
3129 3136 __ verify_oop(G5_method);
3130 3137 __ profile_call(O4);
3131 3138 __ call_from_interpreter(Rscratch, Gargs, Rret);
3132 3139 }
3133 3140
3134 3141
3135 3142 void TemplateTable::invokestatic(int byte_no) {
3136 3143 transition(vtos, vtos);
3137 3144 assert(byte_no == f1_byte, "use this argument");
3138 3145
3139 3146 const Register Rret = Lscratch;
3140 3147 const Register Rscratch = G3_scratch;
3141 3148
3142 3149 prepare_invoke(byte_no, G5_method, Rret); // get f1 methodOop
3143 3150
3144 3151 // do the call
3145 3152 __ verify_oop(G5_method);
3146 3153 __ profile_call(O4);
3147 3154 __ call_from_interpreter(Rscratch, Gargs, Rret);
3148 3155 }
3149 3156
3150 3157
3151 3158 void TemplateTable::invokeinterface_object_method(Register RklassOop,
3152 3159 Register Rcall,
3153 3160 Register Rret,
3154 3161 Register Rflags) {
3155 3162 Register Rscratch = G4_scratch;
3156 3163 Register Rindex = Lscratch;
3157 3164
3158 3165 assert_different_registers(Rscratch, Rindex, Rret);
3159 3166
3160 3167 Label notFinal;
3161 3168
3162 3169 // Check for vfinal
3163 3170 __ set((1 << ConstantPoolCacheEntry::is_vfinal_shift), Rscratch);
3164 3171 __ btst(Rflags, Rscratch);
3165 3172 __ br(Assembler::zero, false, Assembler::pt, notFinal);
3166 3173 __ delayed()->nop();
3167 3174
3168 3175 __ profile_final_call(O4);
3169 3176
3170 3177 // do the call - the index (f2) contains the methodOop
3171 3178 assert_different_registers(G5_method, Gargs, Rcall);
3172 3179 __ mov(Rindex, G5_method);
3173 3180 __ call_from_interpreter(Rcall, Gargs, Rret);
3174 3181 __ bind(notFinal);
3175 3182
3176 3183 __ profile_virtual_call(RklassOop, O4);
3177 3184 generate_vtable_call(RklassOop, Rindex, Rret);
3178 3185 }
3179 3186
3180 3187
3181 3188 void TemplateTable::invokeinterface(int byte_no) {
3182 3189 transition(vtos, vtos);
3183 3190 assert(byte_no == f1_byte, "use this argument");
3184 3191
3185 3192 const Register Rinterface = G1_scratch;
3186 3193 const Register Rret = G3_scratch;
3187 3194 const Register Rindex = Lscratch;
3188 3195 const Register O0_recv = O0;
3189 3196 const Register O1_flags = O1;
3190 3197 const Register O2_klassOop = O2;
3191 3198 const Register Rscratch = G4_scratch;
3192 3199 assert_different_registers(Rscratch, G5_method);
3193 3200
3194 3201 prepare_invoke(byte_no, Rinterface, Rret, Rindex, O0_recv, O1_flags);
3195 3202
3196 3203 // get receiver klass
3197 3204 __ null_check(O0_recv, oopDesc::klass_offset_in_bytes());
3198 3205 __ load_klass(O0_recv, O2_klassOop);
3199 3206 __ verify_oop(O2_klassOop);
3200 3207
3201 3208 // Special case of invokeinterface called for virtual method of
3202 3209 // java.lang.Object. See cpCacheOop.cpp for details.
3203 3210 // This code isn't produced by javac, but could be produced by
3204 3211 // another compliant java compiler.
3205 3212 Label notMethod;
3206 3213 __ set((1 << ConstantPoolCacheEntry::is_forced_virtual_shift), Rscratch);
3207 3214 __ btst(O1_flags, Rscratch);
3208 3215 __ br(Assembler::zero, false, Assembler::pt, notMethod);
3209 3216 __ delayed()->nop();
3210 3217
3211 3218 invokeinterface_object_method(O2_klassOop, Rinterface, Rret, O1_flags);
3212 3219
3213 3220 __ bind(notMethod);
3214 3221
3215 3222 __ profile_virtual_call(O2_klassOop, O4);
3216 3223
3217 3224 //
3218 3225 // find entry point to call
3219 3226 //
3220 3227
3221 3228 // compute start of first itableOffsetEntry (which is at end of vtable)
3222 3229 const int base = instanceKlass::vtable_start_offset() * wordSize;
3223 3230 Label search;
3224 3231 Register Rtemp = O1_flags;
3225 3232
3226 3233 __ ld(O2_klassOop, instanceKlass::vtable_length_offset() * wordSize, Rtemp);
3227 3234 if (align_object_offset(1) > 1) {
3228 3235 __ round_to(Rtemp, align_object_offset(1));
3229 3236 }
3230 3237 __ sll(Rtemp, LogBytesPerWord, Rtemp); // Rscratch *= 4;
3231 3238 if (Assembler::is_simm13(base)) {
3232 3239 __ add(Rtemp, base, Rtemp);
3233 3240 } else {
3234 3241 __ set(base, Rscratch);
3235 3242 __ add(Rscratch, Rtemp, Rtemp);
3236 3243 }
3237 3244 __ add(O2_klassOop, Rtemp, Rscratch);
3238 3245
3239 3246 __ bind(search);
3240 3247
3241 3248 __ ld_ptr(Rscratch, itableOffsetEntry::interface_offset_in_bytes(), Rtemp);
3242 3249 {
3243 3250 Label ok;
3244 3251
3245 3252 // Check that entry is non-null. Null entries are probably a bytecode
3246 3253 // problem. If the interface isn't implemented by the receiver class,
3247 3254 // the VM should throw IncompatibleClassChangeError. linkResolver checks
3248 3255 // this too but that's only if the entry isn't already resolved, so we
3249 3256 // need to check again.
3250 3257 __ br_notnull_short( Rtemp, Assembler::pt, ok);
3251 3258 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
3252 3259 __ should_not_reach_here();
3253 3260 __ bind(ok);
3254 3261 __ verify_oop(Rtemp);
3255 3262 }
3256 3263
3257 3264 __ verify_oop(Rinterface);
3258 3265
3259 3266 __ cmp(Rinterface, Rtemp);
3260 3267 __ brx(Assembler::notEqual, true, Assembler::pn, search);
3261 3268 __ delayed()->add(Rscratch, itableOffsetEntry::size() * wordSize, Rscratch);
3262 3269
3263 3270 // entry found and Rscratch points to it
3264 3271 __ ld(Rscratch, itableOffsetEntry::offset_offset_in_bytes(), Rscratch);
3265 3272
3266 3273 assert(itableMethodEntry::method_offset_in_bytes() == 0, "adjust instruction below");
3267 3274 __ sll(Rindex, exact_log2(itableMethodEntry::size() * wordSize), Rindex); // Rindex *= 8;
3268 3275 __ add(Rscratch, Rindex, Rscratch);
3269 3276 __ ld_ptr(O2_klassOop, Rscratch, G5_method);
3270 3277
3271 3278 // Check for abstract method error.
3272 3279 {
3273 3280 Label ok;
3274 3281 __ br_notnull_short(G5_method, Assembler::pt, ok);
3275 3282 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
3276 3283 __ should_not_reach_here();
3277 3284 __ bind(ok);
3278 3285 }
3279 3286
3280 3287 Register Rcall = Rinterface;
3281 3288 assert_different_registers(Rcall, G5_method, Gargs, Rret);
3282 3289
3283 3290 __ verify_oop(G5_method);
3284 3291 __ call_from_interpreter(Rcall, Gargs, Rret);
3285 3292 }
3286 3293
3287 3294
3288 3295 void TemplateTable::invokehandle(int byte_no) {
3289 3296 transition(vtos, vtos);
3290 3297 assert(byte_no == f12_oop, "use this argument");
3291 3298
3292 3299 if (!EnableInvokeDynamic) {
3293 3300 // rewriter does not generate this bytecode
3294 3301 __ should_not_reach_here();
3295 3302 return;
3296 3303 }
3297 3304
3298 3305 const Register Rret = Lscratch;
3299 3306 const Register G4_mtype = G4_scratch; // f1
3300 3307 const Register O0_recv = O0;
3301 3308 const Register Rscratch = G3_scratch;
3302 3309
3303 3310 prepare_invoke(byte_no, G5_method, Rret, G4_mtype, O0_recv);
3304 3311 __ null_check(O0_recv);
3305 3312
3306 3313 // G4: MethodType object (from f1)
3307 3314 // G5: MH.linkToCallSite method (from f2)
3308 3315
3309 3316 // Note: G4_mtype is already pushed (if necessary) by prepare_invoke
3310 3317
3311 3318 // do the call
3312 3319 __ verify_oop(G5_method);
3313 3320 __ profile_final_call(O4); // FIXME: profile the LambdaForm also
3314 3321 __ call_from_interpreter(Rscratch, Gargs, Rret);
3315 3322 }
3316 3323
3317 3324
3318 3325 void TemplateTable::invokedynamic(int byte_no) {
3319 3326 transition(vtos, vtos);
3320 3327 assert(byte_no == f12_oop, "use this argument");
3321 3328
3322 3329 if (!EnableInvokeDynamic) {
3323 3330 // We should not encounter this bytecode if !EnableInvokeDynamic.
3324 3331 // The verifier will stop it. However, if we get past the verifier,
3325 3332 // this will stop the thread in a reasonable way, without crashing the JVM.
3326 3333 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
3327 3334 InterpreterRuntime::throw_IncompatibleClassChangeError));
3328 3335 // the call_VM checks for exception, so we should never return here.
3329 3336 __ should_not_reach_here();
3330 3337 return;
3331 3338 }
3332 3339
3333 3340 const Register Rret = Lscratch;
3334 3341 const Register G4_callsite = G4_scratch;
3335 3342 const Register Rscratch = G3_scratch;
3336 3343
3337 3344 prepare_invoke(byte_no, G5_method, Rret, G4_callsite);
3338 3345
3339 3346 // G4: CallSite object (from f1)
3340 3347 // G5: MH.linkToCallSite method (from f2)
3341 3348
3342 3349 // Note: G4_callsite is already pushed by prepare_invoke
3343 3350
3344 3351 // %%% should make a type profile for any invokedynamic that takes a ref argument
3345 3352 // profile this call
3346 3353 __ profile_call(O4);
3347 3354
3348 3355 // do the call
3349 3356 __ verify_oop(G5_method);
3350 3357 __ call_from_interpreter(Rscratch, Gargs, Rret);
3351 3358 }
3352 3359
3353 3360
3354 3361 //----------------------------------------------------------------------------------------------------
3355 3362 // Allocation
3356 3363
3357 3364 void TemplateTable::_new() {
3358 3365 transition(vtos, atos);
3359 3366
3360 3367 Label slow_case;
3361 3368 Label done;
3362 3369 Label initialize_header;
3363 3370 Label initialize_object; // including clearing the fields
3364 3371
3365 3372 Register RallocatedObject = Otos_i;
3366 3373 Register RinstanceKlass = O1;
3367 3374 Register Roffset = O3;
3368 3375 Register Rscratch = O4;
3369 3376
3370 3377 __ get_2_byte_integer_at_bcp(1, Rscratch, Roffset, InterpreterMacroAssembler::Unsigned);
3371 3378 __ get_cpool_and_tags(Rscratch, G3_scratch);
3372 3379 // make sure the class we're about to instantiate has been resolved
3373 3380 // This is done before loading instanceKlass to be consistent with the order
3374 3381 // how Constant Pool is updated (see constantPoolOopDesc::klass_at_put)
3375 3382 __ add(G3_scratch, typeArrayOopDesc::header_size(T_BYTE) * wordSize, G3_scratch);
3376 3383 __ ldub(G3_scratch, Roffset, G3_scratch);
3377 3384 __ cmp(G3_scratch, JVM_CONSTANT_Class);
3378 3385 __ br(Assembler::notEqual, false, Assembler::pn, slow_case);
3379 3386 __ delayed()->sll(Roffset, LogBytesPerWord, Roffset);
3380 3387 // get instanceKlass
3381 3388 //__ sll(Roffset, LogBytesPerWord, Roffset); // executed in delay slot
3382 3389 __ add(Roffset, sizeof(constantPoolOopDesc), Roffset);
3383 3390 __ ld_ptr(Rscratch, Roffset, RinstanceKlass);
3384 3391
3385 3392 // make sure klass is fully initialized:
3386 3393 __ ldub(RinstanceKlass, in_bytes(instanceKlass::init_state_offset()), G3_scratch);
3387 3394 __ cmp(G3_scratch, instanceKlass::fully_initialized);
3388 3395 __ br(Assembler::notEqual, false, Assembler::pn, slow_case);
3389 3396 __ delayed()->ld(RinstanceKlass, in_bytes(Klass::layout_helper_offset()), Roffset);
3390 3397
3391 3398 // get instance_size in instanceKlass (already aligned)
3392 3399 //__ ld(RinstanceKlass, in_bytes(Klass::layout_helper_offset()), Roffset);
3393 3400
3394 3401 // make sure klass does not have has_finalizer, or is abstract, or interface or java/lang/Class
3395 3402 __ btst(Klass::_lh_instance_slow_path_bit, Roffset);
3396 3403 __ br(Assembler::notZero, false, Assembler::pn, slow_case);
3397 3404 __ delayed()->nop();
3398 3405
3399 3406 // allocate the instance
3400 3407 // 1) Try to allocate in the TLAB
3401 3408 // 2) if fail, and the TLAB is not full enough to discard, allocate in the shared Eden
3402 3409 // 3) if the above fails (or is not applicable), go to a slow case
3403 3410 // (creates a new TLAB, etc.)
3404 3411
3405 3412 const bool allow_shared_alloc =
3406 3413 Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
3407 3414
3408 3415 if(UseTLAB) {
3409 3416 Register RoldTopValue = RallocatedObject;
3410 3417 Register RtlabWasteLimitValue = G3_scratch;
3411 3418 Register RnewTopValue = G1_scratch;
3412 3419 Register RendValue = Rscratch;
3413 3420 Register RfreeValue = RnewTopValue;
3414 3421
3415 3422 // check if we can allocate in the TLAB
3416 3423 __ ld_ptr(G2_thread, in_bytes(JavaThread::tlab_top_offset()), RoldTopValue); // sets up RalocatedObject
3417 3424 __ ld_ptr(G2_thread, in_bytes(JavaThread::tlab_end_offset()), RendValue);
3418 3425 __ add(RoldTopValue, Roffset, RnewTopValue);
3419 3426
3420 3427 // if there is enough space, we do not CAS and do not clear
3421 3428 __ cmp(RnewTopValue, RendValue);
3422 3429 if(ZeroTLAB) {
3423 3430 // the fields have already been cleared
3424 3431 __ brx(Assembler::lessEqualUnsigned, true, Assembler::pt, initialize_header);
3425 3432 } else {
3426 3433 // initialize both the header and fields
3427 3434 __ brx(Assembler::lessEqualUnsigned, true, Assembler::pt, initialize_object);
3428 3435 }
3429 3436 __ delayed()->st_ptr(RnewTopValue, G2_thread, in_bytes(JavaThread::tlab_top_offset()));
3430 3437
3431 3438 if (allow_shared_alloc) {
3432 3439 // Check if tlab should be discarded (refill_waste_limit >= free)
3433 3440 __ ld_ptr(G2_thread, in_bytes(JavaThread::tlab_refill_waste_limit_offset()), RtlabWasteLimitValue);
3434 3441 __ sub(RendValue, RoldTopValue, RfreeValue);
3435 3442 #ifdef _LP64
3436 3443 __ srlx(RfreeValue, LogHeapWordSize, RfreeValue);
3437 3444 #else
3438 3445 __ srl(RfreeValue, LogHeapWordSize, RfreeValue);
3439 3446 #endif
3440 3447 __ cmp_and_brx_short(RtlabWasteLimitValue, RfreeValue, Assembler::greaterEqualUnsigned, Assembler::pt, slow_case); // tlab waste is small
3441 3448
3442 3449 // increment waste limit to prevent getting stuck on this slow path
3443 3450 __ add(RtlabWasteLimitValue, ThreadLocalAllocBuffer::refill_waste_limit_increment(), RtlabWasteLimitValue);
3444 3451 __ st_ptr(RtlabWasteLimitValue, G2_thread, in_bytes(JavaThread::tlab_refill_waste_limit_offset()));
3445 3452 } else {
3446 3453 // No allocation in the shared eden.
3447 3454 __ ba_short(slow_case);
3448 3455 }
3449 3456 }
3450 3457
3451 3458 // Allocation in the shared Eden
3452 3459 if (allow_shared_alloc) {
3453 3460 Register RoldTopValue = G1_scratch;
3454 3461 Register RtopAddr = G3_scratch;
3455 3462 Register RnewTopValue = RallocatedObject;
3456 3463 Register RendValue = Rscratch;
3457 3464
3458 3465 __ set((intptr_t)Universe::heap()->top_addr(), RtopAddr);
3459 3466
3460 3467 Label retry;
3461 3468 __ bind(retry);
3462 3469 __ set((intptr_t)Universe::heap()->end_addr(), RendValue);
3463 3470 __ ld_ptr(RendValue, 0, RendValue);
3464 3471 __ ld_ptr(RtopAddr, 0, RoldTopValue);
3465 3472 __ add(RoldTopValue, Roffset, RnewTopValue);
3466 3473
3467 3474 // RnewTopValue contains the top address after the new object
3468 3475 // has been allocated.
3469 3476 __ cmp_and_brx_short(RnewTopValue, RendValue, Assembler::greaterUnsigned, Assembler::pn, slow_case);
3470 3477
3471 3478 __ casx_under_lock(RtopAddr, RoldTopValue, RnewTopValue,
3472 3479 VM_Version::v9_instructions_work() ? NULL :
3473 3480 (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr());
3474 3481
3475 3482 // if someone beat us on the allocation, try again, otherwise continue
3476 3483 __ cmp_and_brx_short(RoldTopValue, RnewTopValue, Assembler::notEqual, Assembler::pn, retry);
3477 3484
3478 3485 // bump total bytes allocated by this thread
3479 3486 // RoldTopValue and RtopAddr are dead, so can use G1 and G3
3480 3487 __ incr_allocated_bytes(Roffset, G1_scratch, G3_scratch);
3481 3488 }
3482 3489
3483 3490 if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
3484 3491 // clear object fields
3485 3492 __ bind(initialize_object);
3486 3493 __ deccc(Roffset, sizeof(oopDesc));
3487 3494 __ br(Assembler::zero, false, Assembler::pt, initialize_header);
3488 3495 __ delayed()->add(RallocatedObject, sizeof(oopDesc), G3_scratch);
3489 3496
3490 3497 // initialize remaining object fields
3491 3498 if (UseBlockZeroing) {
3492 3499 // Use BIS for zeroing
3493 3500 __ bis_zeroing(G3_scratch, Roffset, G1_scratch, initialize_header);
3494 3501 } else {
3495 3502 Label loop;
3496 3503 __ subcc(Roffset, wordSize, Roffset);
3497 3504 __ bind(loop);
3498 3505 //__ subcc(Roffset, wordSize, Roffset); // executed above loop or in delay slot
3499 3506 __ st_ptr(G0, G3_scratch, Roffset);
3500 3507 __ br(Assembler::notEqual, false, Assembler::pt, loop);
3501 3508 __ delayed()->subcc(Roffset, wordSize, Roffset);
3502 3509 }
3503 3510 __ ba_short(initialize_header);
3504 3511 }
3505 3512
3506 3513 // slow case
3507 3514 __ bind(slow_case);
3508 3515 __ get_2_byte_integer_at_bcp(1, G3_scratch, O2, InterpreterMacroAssembler::Unsigned);
3509 3516 __ get_constant_pool(O1);
3510 3517
3511 3518 call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), O1, O2);
3512 3519
3513 3520 __ ba_short(done);
3514 3521
3515 3522 // Initialize the header: mark, klass
3516 3523 __ bind(initialize_header);
3517 3524
3518 3525 if (UseBiasedLocking) {
3519 3526 __ ld_ptr(RinstanceKlass, in_bytes(Klass::prototype_header_offset()), G4_scratch);
3520 3527 } else {
3521 3528 __ set((intptr_t)markOopDesc::prototype(), G4_scratch);
3522 3529 }
3523 3530 __ st_ptr(G4_scratch, RallocatedObject, oopDesc::mark_offset_in_bytes()); // mark
3524 3531 __ store_klass_gap(G0, RallocatedObject); // klass gap if compressed
3525 3532 __ store_klass(RinstanceKlass, RallocatedObject); // klass (last for cms)
3526 3533
3527 3534 {
3528 3535 SkipIfEqual skip_if(
3529 3536 _masm, G4_scratch, &DTraceAllocProbes, Assembler::zero);
3530 3537 // Trigger dtrace event
3531 3538 __ push(atos);
3532 3539 __ call_VM_leaf(noreg,
3533 3540 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), O0);
3534 3541 __ pop(atos);
3535 3542 }
3536 3543
3537 3544 // continue
3538 3545 __ bind(done);
3539 3546 }
3540 3547
3541 3548
3542 3549
3543 3550 void TemplateTable::newarray() {
3544 3551 transition(itos, atos);
3545 3552 __ ldub(Lbcp, 1, O1);
3546 3553 call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), O1, Otos_i);
3547 3554 }
3548 3555
3549 3556
3550 3557 void TemplateTable::anewarray() {
3551 3558 transition(itos, atos);
3552 3559 __ get_constant_pool(O1);
3553 3560 __ get_2_byte_integer_at_bcp(1, G4_scratch, O2, InterpreterMacroAssembler::Unsigned);
3554 3561 call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), O1, O2, Otos_i);
3555 3562 }
3556 3563
3557 3564
3558 3565 void TemplateTable::arraylength() {
3559 3566 transition(atos, itos);
3560 3567 Label ok;
3561 3568 __ verify_oop(Otos_i);
3562 3569 __ tst(Otos_i);
3563 3570 __ throw_if_not_1_x( Assembler::notZero, ok );
3564 3571 __ delayed()->ld(Otos_i, arrayOopDesc::length_offset_in_bytes(), Otos_i);
3565 3572 __ throw_if_not_2( Interpreter::_throw_NullPointerException_entry, G3_scratch, ok);
3566 3573 }
3567 3574
3568 3575
3569 3576 void TemplateTable::checkcast() {
3570 3577 transition(atos, atos);
3571 3578 Label done, is_null, quicked, cast_ok, resolved;
3572 3579 Register Roffset = G1_scratch;
3573 3580 Register RobjKlass = O5;
3574 3581 Register RspecifiedKlass = O4;
3575 3582
3576 3583 // Check for casting a NULL
3577 3584 __ br_null_short(Otos_i, Assembler::pn, is_null);
3578 3585
3579 3586 // Get value klass in RobjKlass
3580 3587 __ load_klass(Otos_i, RobjKlass); // get value klass
3581 3588
3582 3589 // Get constant pool tag
3583 3590 __ get_2_byte_integer_at_bcp(1, Lscratch, Roffset, InterpreterMacroAssembler::Unsigned);
3584 3591
3585 3592 // See if the checkcast has been quickened
3586 3593 __ get_cpool_and_tags(Lscratch, G3_scratch);
3587 3594 __ add(G3_scratch, typeArrayOopDesc::header_size(T_BYTE) * wordSize, G3_scratch);
3588 3595 __ ldub(G3_scratch, Roffset, G3_scratch);
3589 3596 __ cmp(G3_scratch, JVM_CONSTANT_Class);
3590 3597 __ br(Assembler::equal, true, Assembler::pt, quicked);
3591 3598 __ delayed()->sll(Roffset, LogBytesPerWord, Roffset);
3592 3599
3593 3600 __ push_ptr(); // save receiver for result, and for GC
3594 3601 call_VM(RspecifiedKlass, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
3595 3602 __ pop_ptr(Otos_i, G3_scratch); // restore receiver
3596 3603
3597 3604 __ ba_short(resolved);
3598 3605
3599 3606 // Extract target class from constant pool
3600 3607 __ bind(quicked);
3601 3608 __ add(Roffset, sizeof(constantPoolOopDesc), Roffset);
3602 3609 __ ld_ptr(Lscratch, Roffset, RspecifiedKlass);
3603 3610 __ bind(resolved);
3604 3611 __ load_klass(Otos_i, RobjKlass); // get value klass
3605 3612
3606 3613 // Generate a fast subtype check. Branch to cast_ok if no
3607 3614 // failure. Throw exception if failure.
3608 3615 __ gen_subtype_check( RobjKlass, RspecifiedKlass, G3_scratch, G4_scratch, G1_scratch, cast_ok );
3609 3616
3610 3617 // Not a subtype; so must throw exception
3611 3618 __ throw_if_not_x( Assembler::never, Interpreter::_throw_ClassCastException_entry, G3_scratch );
3612 3619
3613 3620 __ bind(cast_ok);
3614 3621
3615 3622 if (ProfileInterpreter) {
3616 3623 __ ba_short(done);
3617 3624 }
3618 3625 __ bind(is_null);
3619 3626 __ profile_null_seen(G3_scratch);
3620 3627 __ bind(done);
3621 3628 }
3622 3629
3623 3630
3624 3631 void TemplateTable::instanceof() {
3625 3632 Label done, is_null, quicked, resolved;
3626 3633 transition(atos, itos);
3627 3634 Register Roffset = G1_scratch;
3628 3635 Register RobjKlass = O5;
3629 3636 Register RspecifiedKlass = O4;
3630 3637
3631 3638 // Check for casting a NULL
3632 3639 __ br_null_short(Otos_i, Assembler::pt, is_null);
3633 3640
3634 3641 // Get value klass in RobjKlass
3635 3642 __ load_klass(Otos_i, RobjKlass); // get value klass
3636 3643
3637 3644 // Get constant pool tag
3638 3645 __ get_2_byte_integer_at_bcp(1, Lscratch, Roffset, InterpreterMacroAssembler::Unsigned);
3639 3646
3640 3647 // See if the checkcast has been quickened
3641 3648 __ get_cpool_and_tags(Lscratch, G3_scratch);
3642 3649 __ add(G3_scratch, typeArrayOopDesc::header_size(T_BYTE) * wordSize, G3_scratch);
3643 3650 __ ldub(G3_scratch, Roffset, G3_scratch);
3644 3651 __ cmp(G3_scratch, JVM_CONSTANT_Class);
3645 3652 __ br(Assembler::equal, true, Assembler::pt, quicked);
3646 3653 __ delayed()->sll(Roffset, LogBytesPerWord, Roffset);
3647 3654
3648 3655 __ push_ptr(); // save receiver for result, and for GC
3649 3656 call_VM(RspecifiedKlass, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
3650 3657 __ pop_ptr(Otos_i, G3_scratch); // restore receiver
3651 3658
3652 3659 __ ba_short(resolved);
3653 3660
3654 3661 // Extract target class from constant pool
3655 3662 __ bind(quicked);
3656 3663 __ add(Roffset, sizeof(constantPoolOopDesc), Roffset);
3657 3664 __ get_constant_pool(Lscratch);
3658 3665 __ ld_ptr(Lscratch, Roffset, RspecifiedKlass);
3659 3666 __ bind(resolved);
3660 3667 __ load_klass(Otos_i, RobjKlass); // get value klass
3661 3668
3662 3669 // Generate a fast subtype check. Branch to cast_ok if no
3663 3670 // failure. Return 0 if failure.
3664 3671 __ or3(G0, 1, Otos_i); // set result assuming quick tests succeed
3665 3672 __ gen_subtype_check( RobjKlass, RspecifiedKlass, G3_scratch, G4_scratch, G1_scratch, done );
3666 3673 // Not a subtype; return 0;
3667 3674 __ clr( Otos_i );
3668 3675
3669 3676 if (ProfileInterpreter) {
3670 3677 __ ba_short(done);
3671 3678 }
3672 3679 __ bind(is_null);
3673 3680 __ profile_null_seen(G3_scratch);
3674 3681 __ bind(done);
3675 3682 }
3676 3683
3677 3684 void TemplateTable::_breakpoint() {
3678 3685
3679 3686 // Note: We get here even if we are single stepping..
3680 3687 // jbug inists on setting breakpoints at every bytecode
3681 3688 // even if we are in single step mode.
3682 3689
3683 3690 transition(vtos, vtos);
3684 3691 // get the unpatched byte code
3685 3692 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), Lmethod, Lbcp);
3686 3693 __ mov(O0, Lbyte_code);
3687 3694
3688 3695 // post the breakpoint event
3689 3696 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), Lmethod, Lbcp);
3690 3697
3691 3698 // complete the execution of original bytecode
3692 3699 __ dispatch_normal(vtos);
3693 3700 }
3694 3701
3695 3702
3696 3703 //----------------------------------------------------------------------------------------------------
3697 3704 // Exceptions
3698 3705
3699 3706 void TemplateTable::athrow() {
3700 3707 transition(atos, vtos);
3701 3708
3702 3709 // This works because exception is cached in Otos_i which is same as O0,
3703 3710 // which is same as what throw_exception_entry_expects
3704 3711 assert(Otos_i == Oexception, "see explanation above");
3705 3712
3706 3713 __ verify_oop(Otos_i);
3707 3714 __ null_check(Otos_i);
3708 3715 __ throw_if_not_x(Assembler::never, Interpreter::throw_exception_entry(), G3_scratch);
3709 3716 }
3710 3717
3711 3718
3712 3719 //----------------------------------------------------------------------------------------------------
3713 3720 // Synchronization
3714 3721
3715 3722
3716 3723 // See frame_sparc.hpp for monitor block layout.
3717 3724 // Monitor elements are dynamically allocated by growing stack as needed.
3718 3725
3719 3726 void TemplateTable::monitorenter() {
3720 3727 transition(atos, vtos);
3721 3728 __ verify_oop(Otos_i);
3722 3729 // Try to acquire a lock on the object
3723 3730 // Repeat until succeeded (i.e., until
3724 3731 // monitorenter returns true).
3725 3732
3726 3733 { Label ok;
3727 3734 __ tst(Otos_i);
3728 3735 __ throw_if_not_1_x( Assembler::notZero, ok);
3729 3736 __ delayed()->mov(Otos_i, Lscratch); // save obj
3730 3737 __ throw_if_not_2( Interpreter::_throw_NullPointerException_entry, G3_scratch, ok);
3731 3738 }
3732 3739
3733 3740 assert(O0 == Otos_i, "Be sure where the object to lock is");
3734 3741
3735 3742 // find a free slot in the monitor block
3736 3743
3737 3744
3738 3745 // initialize entry pointer
3739 3746 __ clr(O1); // points to free slot or NULL
3740 3747
3741 3748 {
3742 3749 Label entry, loop, exit;
3743 3750 __ add( __ top_most_monitor(), O2 ); // last one to check
3744 3751 __ ba( entry );
3745 3752 __ delayed()->mov( Lmonitors, O3 ); // first one to check
3746 3753
3747 3754
3748 3755 __ bind( loop );
3749 3756
3750 3757 __ verify_oop(O4); // verify each monitor's oop
3751 3758 __ tst(O4); // is this entry unused?
3752 3759 if (VM_Version::v9_instructions_work())
3753 3760 __ movcc( Assembler::zero, false, Assembler::ptr_cc, O3, O1);
3754 3761 else {
3755 3762 Label L;
3756 3763 __ br( Assembler::zero, true, Assembler::pn, L );
3757 3764 __ delayed()->mov(O3, O1); // rememeber this one if match
3758 3765 __ bind(L);
3759 3766 }
3760 3767
3761 3768 __ cmp(O4, O0); // check if current entry is for same object
3762 3769 __ brx( Assembler::equal, false, Assembler::pn, exit );
3763 3770 __ delayed()->inc( O3, frame::interpreter_frame_monitor_size() * wordSize ); // check next one
3764 3771
3765 3772 __ bind( entry );
3766 3773
3767 3774 __ cmp( O3, O2 );
3768 3775 __ brx( Assembler::lessEqualUnsigned, true, Assembler::pt, loop );
3769 3776 __ delayed()->ld_ptr(O3, BasicObjectLock::obj_offset_in_bytes(), O4);
3770 3777
3771 3778 __ bind( exit );
3772 3779 }
3773 3780
3774 3781 { Label allocated;
3775 3782
3776 3783 // found free slot?
3777 3784 __ br_notnull_short(O1, Assembler::pn, allocated);
3778 3785
3779 3786 __ add_monitor_to_stack( false, O2, O3 );
3780 3787 __ mov(Lmonitors, O1);
3781 3788
3782 3789 __ bind(allocated);
3783 3790 }
3784 3791
3785 3792 // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
3786 3793 // The object has already been poped from the stack, so the expression stack looks correct.
3787 3794 __ inc(Lbcp);
3788 3795
3789 3796 __ st_ptr(O0, O1, BasicObjectLock::obj_offset_in_bytes()); // store object
3790 3797 __ lock_object(O1, O0);
3791 3798
3792 3799 // check if there's enough space on the stack for the monitors after locking
3793 3800 __ generate_stack_overflow_check(0);
3794 3801
3795 3802 // The bcp has already been incremented. Just need to dispatch to next instruction.
3796 3803 __ dispatch_next(vtos);
3797 3804 }
3798 3805
3799 3806
3800 3807 void TemplateTable::monitorexit() {
3801 3808 transition(atos, vtos);
3802 3809 __ verify_oop(Otos_i);
3803 3810 __ tst(Otos_i);
3804 3811 __ throw_if_not_x( Assembler::notZero, Interpreter::_throw_NullPointerException_entry, G3_scratch );
3805 3812
3806 3813 assert(O0 == Otos_i, "just checking");
3807 3814
3808 3815 { Label entry, loop, found;
3809 3816 __ add( __ top_most_monitor(), O2 ); // last one to check
3810 3817 __ ba(entry);
3811 3818 // use Lscratch to hold monitor elem to check, start with most recent monitor,
3812 3819 // By using a local it survives the call to the C routine.
3813 3820 __ delayed()->mov( Lmonitors, Lscratch );
3814 3821
3815 3822 __ bind( loop );
3816 3823
3817 3824 __ verify_oop(O4); // verify each monitor's oop
3818 3825 __ cmp(O4, O0); // check if current entry is for desired object
3819 3826 __ brx( Assembler::equal, true, Assembler::pt, found );
3820 3827 __ delayed()->mov(Lscratch, O1); // pass found entry as argument to monitorexit
3821 3828
3822 3829 __ inc( Lscratch, frame::interpreter_frame_monitor_size() * wordSize ); // advance to next
3823 3830
3824 3831 __ bind( entry );
3825 3832
3826 3833 __ cmp( Lscratch, O2 );
3827 3834 __ brx( Assembler::lessEqualUnsigned, true, Assembler::pt, loop );
3828 3835 __ delayed()->ld_ptr(Lscratch, BasicObjectLock::obj_offset_in_bytes(), O4);
3829 3836
3830 3837 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
3831 3838 __ should_not_reach_here();
3832 3839
3833 3840 __ bind(found);
3834 3841 }
3835 3842 __ unlock_object(O1);
3836 3843 }
3837 3844
3838 3845
3839 3846 //----------------------------------------------------------------------------------------------------
3840 3847 // Wide instructions
3841 3848
3842 3849 void TemplateTable::wide() {
3843 3850 transition(vtos, vtos);
3844 3851 __ ldub(Lbcp, 1, G3_scratch);// get next bc
3845 3852 __ sll(G3_scratch, LogBytesPerWord, G3_scratch);
3846 3853 AddressLiteral ep(Interpreter::_wentry_point);
3847 3854 __ set(ep, G4_scratch);
3848 3855 __ ld_ptr(G4_scratch, G3_scratch, G3_scratch);
3849 3856 __ jmp(G3_scratch, G0);
3850 3857 __ delayed()->nop();
3851 3858 // Note: the Lbcp increment step is part of the individual wide bytecode implementations
3852 3859 }
3853 3860
3854 3861
3855 3862 //----------------------------------------------------------------------------------------------------
3856 3863 // Multi arrays
3857 3864
3858 3865 void TemplateTable::multianewarray() {
3859 3866 transition(vtos, atos);
3860 3867 // put ndims * wordSize into Lscratch
3861 3868 __ ldub( Lbcp, 3, Lscratch);
3862 3869 __ sll( Lscratch, Interpreter::logStackElementSize, Lscratch);
3863 3870 // Lesp points past last_dim, so set to O1 to first_dim address
3864 3871 __ add( Lesp, Lscratch, O1);
3865 3872 call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), O1);
3866 3873 __ add( Lesp, Lscratch, Lesp); // pop all dimensions off the stack
3867 3874 }
3868 3875 #endif /* !CC_INTERP */
↓ open down ↓ |
3777 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX