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