src/cpu/ppc/vm/templateTable_ppc_64.cpp

Wed, 15 Apr 2020 11:49:55 +0800

author
aoqi
date
Wed, 15 Apr 2020 11:49:55 +0800
changeset 9852
70aa912cebe5
parent 9041
95a08233f46c
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
mdoerr@9034 2 * Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved.
mdoerr@9034 3 * Copyright 2013, 2017 SAP AG. All rights reserved.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #include "asm/macroAssembler.inline.hpp"
aoqi@0 28 #include "interpreter/interpreter.hpp"
aoqi@0 29 #include "interpreter/interpreterRuntime.hpp"
aoqi@0 30 #include "interpreter/templateInterpreter.hpp"
aoqi@0 31 #include "interpreter/templateTable.hpp"
aoqi@0 32 #include "memory/universe.inline.hpp"
aoqi@0 33 #include "oops/objArrayKlass.hpp"
aoqi@0 34 #include "oops/oop.inline.hpp"
aoqi@0 35 #include "prims/methodHandles.hpp"
aoqi@0 36 #include "runtime/sharedRuntime.hpp"
aoqi@0 37 #include "runtime/stubRoutines.hpp"
aoqi@0 38 #include "runtime/synchronizer.hpp"
aoqi@0 39 #include "utilities/macros.hpp"
aoqi@0 40
aoqi@0 41 #ifndef CC_INTERP
aoqi@0 42
aoqi@0 43 #undef __
aoqi@0 44 #define __ _masm->
aoqi@0 45
aoqi@0 46 // ============================================================================
aoqi@0 47 // Misc helpers
aoqi@0 48
aoqi@0 49 // Do an oop store like *(base + index) = val OR *(base + offset) = val
aoqi@0 50 // (only one of both variants is possible at the same time).
aoqi@0 51 // Index can be noreg.
aoqi@0 52 // Kills:
aoqi@0 53 // Rbase, Rtmp
aoqi@0 54 static void do_oop_store(InterpreterMacroAssembler* _masm,
aoqi@0 55 Register Rbase,
aoqi@0 56 RegisterOrConstant offset,
aoqi@0 57 Register Rval, // Noreg means always null.
aoqi@0 58 Register Rtmp1,
aoqi@0 59 Register Rtmp2,
aoqi@0 60 Register Rtmp3,
aoqi@0 61 BarrierSet::Name barrier,
aoqi@0 62 bool precise,
aoqi@0 63 bool check_null) {
aoqi@0 64 assert_different_registers(Rtmp1, Rtmp2, Rtmp3, Rval, Rbase);
aoqi@0 65
aoqi@0 66 switch (barrier) {
aoqi@0 67 #if INCLUDE_ALL_GCS
aoqi@0 68 case BarrierSet::G1SATBCT:
aoqi@0 69 case BarrierSet::G1SATBCTLogging:
aoqi@0 70 {
aoqi@0 71 // Load and record the previous value.
aoqi@0 72 __ g1_write_barrier_pre(Rbase, offset,
aoqi@0 73 Rtmp3, /* holder of pre_val ? */
aoqi@0 74 Rtmp1, Rtmp2, false /* frame */);
aoqi@0 75
aoqi@0 76 Label Lnull, Ldone;
aoqi@0 77 if (Rval != noreg) {
aoqi@0 78 if (check_null) {
aoqi@0 79 __ cmpdi(CCR0, Rval, 0);
aoqi@0 80 __ beq(CCR0, Lnull);
aoqi@0 81 }
aoqi@0 82 __ store_heap_oop_not_null(Rval, offset, Rbase, /*Rval must stay uncompressed.*/ Rtmp1);
aoqi@0 83 // Mark the card.
aoqi@0 84 if (!(offset.is_constant() && offset.as_constant() == 0) && precise) {
aoqi@0 85 __ add(Rbase, offset, Rbase);
aoqi@0 86 }
aoqi@0 87 __ g1_write_barrier_post(Rbase, Rval, Rtmp1, Rtmp2, Rtmp3, /*filtered (fast path)*/ &Ldone);
aoqi@0 88 if (check_null) { __ b(Ldone); }
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 if (Rval == noreg || check_null) { // Store null oop.
aoqi@0 92 Register Rnull = Rval;
aoqi@0 93 __ bind(Lnull);
aoqi@0 94 if (Rval == noreg) {
aoqi@0 95 Rnull = Rtmp1;
aoqi@0 96 __ li(Rnull, 0);
aoqi@0 97 }
aoqi@0 98 if (UseCompressedOops) {
aoqi@0 99 __ stw(Rnull, offset, Rbase);
aoqi@0 100 } else {
aoqi@0 101 __ std(Rnull, offset, Rbase);
aoqi@0 102 }
aoqi@0 103 }
aoqi@0 104 __ bind(Ldone);
aoqi@0 105 }
aoqi@0 106 break;
aoqi@0 107 #endif // INCLUDE_ALL_GCS
aoqi@0 108 case BarrierSet::CardTableModRef:
aoqi@0 109 case BarrierSet::CardTableExtension:
aoqi@0 110 {
aoqi@0 111 Label Lnull, Ldone;
aoqi@0 112 if (Rval != noreg) {
aoqi@0 113 if (check_null) {
aoqi@0 114 __ cmpdi(CCR0, Rval, 0);
aoqi@0 115 __ beq(CCR0, Lnull);
aoqi@0 116 }
aoqi@0 117 __ store_heap_oop_not_null(Rval, offset, Rbase, /*Rval should better stay uncompressed.*/ Rtmp1);
aoqi@0 118 // Mark the card.
aoqi@0 119 if (!(offset.is_constant() && offset.as_constant() == 0) && precise) {
aoqi@0 120 __ add(Rbase, offset, Rbase);
aoqi@0 121 }
aoqi@0 122 __ card_write_barrier_post(Rbase, Rval, Rtmp1);
aoqi@0 123 if (check_null) {
aoqi@0 124 __ b(Ldone);
aoqi@0 125 }
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 if (Rval == noreg || check_null) { // Store null oop.
aoqi@0 129 Register Rnull = Rval;
aoqi@0 130 __ bind(Lnull);
aoqi@0 131 if (Rval == noreg) {
aoqi@0 132 Rnull = Rtmp1;
aoqi@0 133 __ li(Rnull, 0);
aoqi@0 134 }
aoqi@0 135 if (UseCompressedOops) {
aoqi@0 136 __ stw(Rnull, offset, Rbase);
aoqi@0 137 } else {
aoqi@0 138 __ std(Rnull, offset, Rbase);
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 __ bind(Ldone);
aoqi@0 142 }
aoqi@0 143 break;
aoqi@0 144 case BarrierSet::ModRef:
aoqi@0 145 case BarrierSet::Other:
aoqi@0 146 ShouldNotReachHere();
aoqi@0 147 break;
aoqi@0 148 default:
aoqi@0 149 ShouldNotReachHere();
aoqi@0 150 }
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 // ============================================================================
aoqi@0 154 // Platform-dependent initialization
aoqi@0 155
aoqi@0 156 void TemplateTable::pd_initialize() {
aoqi@0 157 // No ppc64 specific initialization.
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 Address TemplateTable::at_bcp(int offset) {
aoqi@0 161 // Not used on ppc.
aoqi@0 162 ShouldNotReachHere();
aoqi@0 163 return Address();
aoqi@0 164 }
aoqi@0 165
aoqi@0 166 // Patches the current bytecode (ptr to it located in bcp)
aoqi@0 167 // in the bytecode stream with a new one.
aoqi@0 168 void TemplateTable::patch_bytecode(Bytecodes::Code new_bc, Register Rnew_bc, Register Rtemp, bool load_bc_into_bc_reg /*=true*/, int byte_no) {
aoqi@0 169 // With sharing on, may need to test method flag.
aoqi@0 170 if (!RewriteBytecodes) return;
aoqi@0 171 Label L_patch_done;
aoqi@0 172
aoqi@0 173 switch (new_bc) {
aoqi@0 174 case Bytecodes::_fast_aputfield:
aoqi@0 175 case Bytecodes::_fast_bputfield:
simonis@8381 176 case Bytecodes::_fast_zputfield:
aoqi@0 177 case Bytecodes::_fast_cputfield:
aoqi@0 178 case Bytecodes::_fast_dputfield:
aoqi@0 179 case Bytecodes::_fast_fputfield:
aoqi@0 180 case Bytecodes::_fast_iputfield:
aoqi@0 181 case Bytecodes::_fast_lputfield:
aoqi@0 182 case Bytecodes::_fast_sputfield:
aoqi@0 183 {
aoqi@0 184 // We skip bytecode quickening for putfield instructions when
aoqi@0 185 // the put_code written to the constant pool cache is zero.
aoqi@0 186 // This is required so that every execution of this instruction
aoqi@0 187 // calls out to InterpreterRuntime::resolve_get_put to do
aoqi@0 188 // additional, required work.
aoqi@0 189 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
aoqi@0 190 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
aoqi@0 191 __ get_cache_and_index_at_bcp(Rtemp /* dst = cache */, 1);
kvn@7132 192 // ((*(cache+indices))>>((1+byte_no)*8))&0xFF:
kvn@7132 193 #if defined(VM_LITTLE_ENDIAN)
kvn@7132 194 __ lbz(Rnew_bc, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 1 + byte_no, Rtemp);
kvn@7132 195 #else
aoqi@0 196 __ lbz(Rnew_bc, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (1 + byte_no), Rtemp);
kvn@7132 197 #endif
aoqi@0 198 __ cmpwi(CCR0, Rnew_bc, 0);
aoqi@0 199 __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc);
aoqi@0 200 __ beq(CCR0, L_patch_done);
aoqi@0 201 // __ isync(); // acquire not needed
aoqi@0 202 break;
aoqi@0 203 }
aoqi@0 204
aoqi@0 205 default:
aoqi@0 206 assert(byte_no == -1, "sanity");
aoqi@0 207 if (load_bc_into_bc_reg) {
aoqi@0 208 __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc);
aoqi@0 209 }
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 if (JvmtiExport::can_post_breakpoint()) {
aoqi@0 213 Label L_fast_patch;
aoqi@0 214 __ lbz(Rtemp, 0, R14_bcp);
aoqi@0 215 __ cmpwi(CCR0, Rtemp, (unsigned int)(unsigned char)Bytecodes::_breakpoint);
aoqi@0 216 __ bne(CCR0, L_fast_patch);
aoqi@0 217 // Perform the quickening, slowly, in the bowels of the breakpoint table.
aoqi@0 218 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), R19_method, R14_bcp, Rnew_bc);
aoqi@0 219 __ b(L_patch_done);
aoqi@0 220 __ bind(L_fast_patch);
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 // Patch bytecode.
aoqi@0 224 __ stb(Rnew_bc, 0, R14_bcp);
aoqi@0 225
aoqi@0 226 __ bind(L_patch_done);
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 // ============================================================================
aoqi@0 230 // Individual instructions
aoqi@0 231
aoqi@0 232 void TemplateTable::nop() {
aoqi@0 233 transition(vtos, vtos);
aoqi@0 234 // Nothing to do.
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 void TemplateTable::shouldnotreachhere() {
aoqi@0 238 transition(vtos, vtos);
aoqi@0 239 __ stop("shouldnotreachhere bytecode");
aoqi@0 240 }
aoqi@0 241
aoqi@0 242 void TemplateTable::aconst_null() {
aoqi@0 243 transition(vtos, atos);
aoqi@0 244 __ li(R17_tos, 0);
aoqi@0 245 }
aoqi@0 246
aoqi@0 247 void TemplateTable::iconst(int value) {
aoqi@0 248 transition(vtos, itos);
aoqi@0 249 assert(value >= -1 && value <= 5, "");
aoqi@0 250 __ li(R17_tos, value);
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 void TemplateTable::lconst(int value) {
aoqi@0 254 transition(vtos, ltos);
aoqi@0 255 assert(value >= -1 && value <= 5, "");
aoqi@0 256 __ li(R17_tos, value);
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 void TemplateTable::fconst(int value) {
aoqi@0 260 transition(vtos, ftos);
aoqi@0 261 static float zero = 0.0;
aoqi@0 262 static float one = 1.0;
aoqi@0 263 static float two = 2.0;
aoqi@0 264 switch (value) {
aoqi@0 265 default: ShouldNotReachHere();
aoqi@0 266 case 0: {
aoqi@0 267 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&zero, R0, true);
aoqi@0 268 __ lfs(F15_ftos, simm16_offset, R11_scratch1);
aoqi@0 269 break;
aoqi@0 270 }
aoqi@0 271 case 1: {
aoqi@0 272 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&one, R0, true);
aoqi@0 273 __ lfs(F15_ftos, simm16_offset, R11_scratch1);
aoqi@0 274 break;
aoqi@0 275 }
aoqi@0 276 case 2: {
aoqi@0 277 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&two, R0, true);
aoqi@0 278 __ lfs(F15_ftos, simm16_offset, R11_scratch1);
aoqi@0 279 break;
aoqi@0 280 }
aoqi@0 281 }
aoqi@0 282 }
aoqi@0 283
aoqi@0 284 void TemplateTable::dconst(int value) {
aoqi@0 285 transition(vtos, dtos);
aoqi@0 286 static double zero = 0.0;
aoqi@0 287 static double one = 1.0;
aoqi@0 288 switch (value) {
aoqi@0 289 case 0: {
aoqi@0 290 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&zero, R0, true);
aoqi@0 291 __ lfd(F15_ftos, simm16_offset, R11_scratch1);
aoqi@0 292 break;
aoqi@0 293 }
aoqi@0 294 case 1: {
aoqi@0 295 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&one, R0, true);
aoqi@0 296 __ lfd(F15_ftos, simm16_offset, R11_scratch1);
aoqi@0 297 break;
aoqi@0 298 }
aoqi@0 299 default: ShouldNotReachHere();
aoqi@0 300 }
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 void TemplateTable::bipush() {
aoqi@0 304 transition(vtos, itos);
aoqi@0 305 __ lbz(R17_tos, 1, R14_bcp);
aoqi@0 306 __ extsb(R17_tos, R17_tos);
aoqi@0 307 }
aoqi@0 308
aoqi@0 309 void TemplateTable::sipush() {
aoqi@0 310 transition(vtos, itos);
aoqi@0 311 __ get_2_byte_integer_at_bcp(1, R17_tos, InterpreterMacroAssembler::Signed);
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 void TemplateTable::ldc(bool wide) {
aoqi@0 315 Register Rscratch1 = R11_scratch1,
aoqi@0 316 Rscratch2 = R12_scratch2,
aoqi@0 317 Rcpool = R3_ARG1;
aoqi@0 318
aoqi@0 319 transition(vtos, vtos);
aoqi@0 320 Label notInt, notClass, exit;
aoqi@0 321
aoqi@0 322 __ get_cpool_and_tags(Rcpool, Rscratch2); // Set Rscratch2 = &tags.
aoqi@0 323 if (wide) { // Read index.
aoqi@0 324 __ get_2_byte_integer_at_bcp(1, Rscratch1, InterpreterMacroAssembler::Unsigned);
aoqi@0 325 } else {
aoqi@0 326 __ lbz(Rscratch1, 1, R14_bcp);
aoqi@0 327 }
aoqi@0 328
aoqi@0 329 const int base_offset = ConstantPool::header_size() * wordSize;
aoqi@0 330 const int tags_offset = Array<u1>::base_offset_in_bytes();
aoqi@0 331
aoqi@0 332 // Get type from tags.
aoqi@0 333 __ addi(Rscratch2, Rscratch2, tags_offset);
aoqi@0 334 __ lbzx(Rscratch2, Rscratch2, Rscratch1);
aoqi@0 335
aoqi@0 336 __ cmpwi(CCR0, Rscratch2, JVM_CONSTANT_UnresolvedClass); // Unresolved class?
aoqi@0 337 __ cmpwi(CCR1, Rscratch2, JVM_CONSTANT_UnresolvedClassInError); // Unresolved class in error state?
aoqi@0 338 __ cror(/*CR0 eq*/2, /*CR1 eq*/4+2, /*CR0 eq*/2);
aoqi@0 339
aoqi@0 340 // Resolved class - need to call vm to get java mirror of the class.
aoqi@0 341 __ cmpwi(CCR1, Rscratch2, JVM_CONSTANT_Class);
aoqi@0 342 __ crnor(/*CR0 eq*/2, /*CR1 eq*/4+2, /*CR0 eq*/2); // Neither resolved class nor unresolved case from above?
aoqi@0 343 __ beq(CCR0, notClass);
aoqi@0 344
aoqi@0 345 __ li(R4, wide ? 1 : 0);
aoqi@0 346 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), R4);
aoqi@0 347 __ push(atos);
aoqi@0 348 __ b(exit);
aoqi@0 349
aoqi@0 350 __ align(32, 12);
aoqi@0 351 __ bind(notClass);
aoqi@0 352 __ addi(Rcpool, Rcpool, base_offset);
aoqi@0 353 __ sldi(Rscratch1, Rscratch1, LogBytesPerWord);
aoqi@0 354 __ cmpdi(CCR0, Rscratch2, JVM_CONSTANT_Integer);
aoqi@0 355 __ bne(CCR0, notInt);
aoqi@0 356 __ lwax(R17_tos, Rcpool, Rscratch1);
aoqi@0 357 __ push(itos);
aoqi@0 358 __ b(exit);
aoqi@0 359
aoqi@0 360 __ align(32, 12);
aoqi@0 361 __ bind(notInt);
aoqi@0 362 #ifdef ASSERT
aoqi@0 363 // String and Object are rewritten to fast_aldc
aoqi@0 364 __ cmpdi(CCR0, Rscratch2, JVM_CONSTANT_Float);
aoqi@0 365 __ asm_assert_eq("unexpected type", 0x8765);
aoqi@0 366 #endif
aoqi@0 367 __ lfsx(F15_ftos, Rcpool, Rscratch1);
aoqi@0 368 __ push(ftos);
aoqi@0 369
aoqi@0 370 __ align(32, 12);
aoqi@0 371 __ bind(exit);
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 // Fast path for caching oop constants.
aoqi@0 375 void TemplateTable::fast_aldc(bool wide) {
aoqi@0 376 transition(vtos, atos);
aoqi@0 377
aoqi@0 378 int index_size = wide ? sizeof(u2) : sizeof(u1);
aoqi@0 379 const Register Rscratch = R11_scratch1;
aoqi@0 380 Label resolved;
aoqi@0 381
aoqi@0 382 // We are resolved if the resolved reference cache entry contains a
aoqi@0 383 // non-null object (CallSite, etc.)
aoqi@0 384 __ get_cache_index_at_bcp(Rscratch, 1, index_size); // Load index.
aoqi@0 385 __ load_resolved_reference_at_index(R17_tos, Rscratch);
aoqi@0 386 __ cmpdi(CCR0, R17_tos, 0);
aoqi@0 387 __ bne(CCR0, resolved);
aoqi@0 388 __ load_const_optimized(R3_ARG1, (int)bytecode());
aoqi@0 389
aoqi@0 390 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
aoqi@0 391
aoqi@0 392 // First time invocation - must resolve first.
aoqi@0 393 __ call_VM(R17_tos, entry, R3_ARG1);
aoqi@0 394
aoqi@0 395 __ align(32, 12);
aoqi@0 396 __ bind(resolved);
aoqi@0 397 __ verify_oop(R17_tos);
aoqi@0 398 }
aoqi@0 399
aoqi@0 400 void TemplateTable::ldc2_w() {
aoqi@0 401 transition(vtos, vtos);
aoqi@0 402 Label Llong, Lexit;
aoqi@0 403
aoqi@0 404 Register Rindex = R11_scratch1,
aoqi@0 405 Rcpool = R12_scratch2,
aoqi@0 406 Rtag = R3_ARG1;
aoqi@0 407 __ get_cpool_and_tags(Rcpool, Rtag);
aoqi@0 408 __ get_2_byte_integer_at_bcp(1, Rindex, InterpreterMacroAssembler::Unsigned);
aoqi@0 409
aoqi@0 410 const int base_offset = ConstantPool::header_size() * wordSize;
aoqi@0 411 const int tags_offset = Array<u1>::base_offset_in_bytes();
aoqi@0 412 // Get type from tags.
aoqi@0 413 __ addi(Rcpool, Rcpool, base_offset);
aoqi@0 414 __ addi(Rtag, Rtag, tags_offset);
aoqi@0 415
aoqi@0 416 __ lbzx(Rtag, Rtag, Rindex);
aoqi@0 417
aoqi@0 418 __ sldi(Rindex, Rindex, LogBytesPerWord);
aoqi@0 419 __ cmpdi(CCR0, Rtag, JVM_CONSTANT_Double);
aoqi@0 420 __ bne(CCR0, Llong);
aoqi@0 421 // A double can be placed at word-aligned locations in the constant pool.
aoqi@0 422 // Check out Conversions.java for an example.
aoqi@0 423 // Also ConstantPool::header_size() is 20, which makes it very difficult
aoqi@0 424 // to double-align double on the constant pool. SG, 11/7/97
aoqi@0 425 __ lfdx(F15_ftos, Rcpool, Rindex);
aoqi@0 426 __ push(dtos);
aoqi@0 427 __ b(Lexit);
aoqi@0 428
aoqi@0 429 __ bind(Llong);
aoqi@0 430 __ ldx(R17_tos, Rcpool, Rindex);
aoqi@0 431 __ push(ltos);
aoqi@0 432
aoqi@0 433 __ bind(Lexit);
aoqi@0 434 }
aoqi@0 435
aoqi@0 436 // Get the locals index located in the bytecode stream at bcp + offset.
aoqi@0 437 void TemplateTable::locals_index(Register Rdst, int offset) {
aoqi@0 438 __ lbz(Rdst, offset, R14_bcp);
aoqi@0 439 }
aoqi@0 440
aoqi@0 441 void TemplateTable::iload() {
aoqi@0 442 transition(vtos, itos);
aoqi@0 443
aoqi@0 444 // Get the local value into tos
aoqi@0 445 const Register Rindex = R22_tmp2;
aoqi@0 446 locals_index(Rindex);
aoqi@0 447
aoqi@0 448 // Rewrite iload,iload pair into fast_iload2
aoqi@0 449 // iload,caload pair into fast_icaload
aoqi@0 450 if (RewriteFrequentPairs) {
aoqi@0 451 Label Lrewrite, Ldone;
aoqi@0 452 Register Rnext_byte = R3_ARG1,
aoqi@0 453 Rrewrite_to = R6_ARG4,
aoqi@0 454 Rscratch = R11_scratch1;
aoqi@0 455
aoqi@0 456 // get next byte
aoqi@0 457 __ lbz(Rnext_byte, Bytecodes::length_for(Bytecodes::_iload), R14_bcp);
aoqi@0 458
aoqi@0 459 // if _iload, wait to rewrite to iload2. We only want to rewrite the
aoqi@0 460 // last two iloads in a pair. Comparing against fast_iload means that
aoqi@0 461 // the next bytecode is neither an iload or a caload, and therefore
aoqi@0 462 // an iload pair.
aoqi@0 463 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_iload);
aoqi@0 464 __ beq(CCR0, Ldone);
aoqi@0 465
aoqi@0 466 __ cmpwi(CCR1, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_iload);
aoqi@0 467 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_iload2);
aoqi@0 468 __ beq(CCR1, Lrewrite);
aoqi@0 469
aoqi@0 470 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_caload);
aoqi@0 471 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_icaload);
aoqi@0 472 __ beq(CCR0, Lrewrite);
aoqi@0 473
aoqi@0 474 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_iload);
aoqi@0 475
aoqi@0 476 __ bind(Lrewrite);
aoqi@0 477 patch_bytecode(Bytecodes::_iload, Rrewrite_to, Rscratch, false);
aoqi@0 478 __ bind(Ldone);
aoqi@0 479 }
aoqi@0 480
aoqi@0 481 __ load_local_int(R17_tos, Rindex, Rindex);
aoqi@0 482 }
aoqi@0 483
aoqi@0 484 // Load 2 integers in a row without dispatching
aoqi@0 485 void TemplateTable::fast_iload2() {
aoqi@0 486 transition(vtos, itos);
aoqi@0 487
aoqi@0 488 __ lbz(R3_ARG1, 1, R14_bcp);
aoqi@0 489 __ lbz(R17_tos, Bytecodes::length_for(Bytecodes::_iload) + 1, R14_bcp);
aoqi@0 490
aoqi@0 491 __ load_local_int(R3_ARG1, R11_scratch1, R3_ARG1);
aoqi@0 492 __ load_local_int(R17_tos, R12_scratch2, R17_tos);
aoqi@0 493 __ push_i(R3_ARG1);
aoqi@0 494 }
aoqi@0 495
aoqi@0 496 void TemplateTable::fast_iload() {
aoqi@0 497 transition(vtos, itos);
aoqi@0 498 // Get the local value into tos
aoqi@0 499
aoqi@0 500 const Register Rindex = R11_scratch1;
aoqi@0 501 locals_index(Rindex);
aoqi@0 502 __ load_local_int(R17_tos, Rindex, Rindex);
aoqi@0 503 }
aoqi@0 504
aoqi@0 505 // Load a local variable type long from locals area to TOS cache register.
aoqi@0 506 // Local index resides in bytecodestream.
aoqi@0 507 void TemplateTable::lload() {
aoqi@0 508 transition(vtos, ltos);
aoqi@0 509
aoqi@0 510 const Register Rindex = R11_scratch1;
aoqi@0 511 locals_index(Rindex);
aoqi@0 512 __ load_local_long(R17_tos, Rindex, Rindex);
aoqi@0 513 }
aoqi@0 514
aoqi@0 515 void TemplateTable::fload() {
aoqi@0 516 transition(vtos, ftos);
aoqi@0 517
aoqi@0 518 const Register Rindex = R11_scratch1;
aoqi@0 519 locals_index(Rindex);
aoqi@0 520 __ load_local_float(F15_ftos, Rindex, Rindex);
aoqi@0 521 }
aoqi@0 522
aoqi@0 523 void TemplateTable::dload() {
aoqi@0 524 transition(vtos, dtos);
aoqi@0 525
aoqi@0 526 const Register Rindex = R11_scratch1;
aoqi@0 527 locals_index(Rindex);
aoqi@0 528 __ load_local_double(F15_ftos, Rindex, Rindex);
aoqi@0 529 }
aoqi@0 530
aoqi@0 531 void TemplateTable::aload() {
aoqi@0 532 transition(vtos, atos);
aoqi@0 533
aoqi@0 534 const Register Rindex = R11_scratch1;
aoqi@0 535 locals_index(Rindex);
aoqi@0 536 __ load_local_ptr(R17_tos, Rindex, Rindex);
aoqi@0 537 }
aoqi@0 538
aoqi@0 539 void TemplateTable::locals_index_wide(Register Rdst) {
aoqi@0 540 // Offset is 2, not 1, because Lbcp points to wide prefix code.
aoqi@0 541 __ get_2_byte_integer_at_bcp(2, Rdst, InterpreterMacroAssembler::Unsigned);
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 void TemplateTable::wide_iload() {
aoqi@0 545 // Get the local value into tos.
aoqi@0 546
aoqi@0 547 const Register Rindex = R11_scratch1;
aoqi@0 548 locals_index_wide(Rindex);
aoqi@0 549 __ load_local_int(R17_tos, Rindex, Rindex);
aoqi@0 550 }
aoqi@0 551
aoqi@0 552 void TemplateTable::wide_lload() {
aoqi@0 553 transition(vtos, ltos);
aoqi@0 554
aoqi@0 555 const Register Rindex = R11_scratch1;
aoqi@0 556 locals_index_wide(Rindex);
aoqi@0 557 __ load_local_long(R17_tos, Rindex, Rindex);
aoqi@0 558 }
aoqi@0 559
aoqi@0 560 void TemplateTable::wide_fload() {
aoqi@0 561 transition(vtos, ftos);
aoqi@0 562
aoqi@0 563 const Register Rindex = R11_scratch1;
aoqi@0 564 locals_index_wide(Rindex);
aoqi@0 565 __ load_local_float(F15_ftos, Rindex, Rindex);
aoqi@0 566 }
aoqi@0 567
aoqi@0 568 void TemplateTable::wide_dload() {
aoqi@0 569 transition(vtos, dtos);
aoqi@0 570
aoqi@0 571 const Register Rindex = R11_scratch1;
aoqi@0 572 locals_index_wide(Rindex);
aoqi@0 573 __ load_local_double(F15_ftos, Rindex, Rindex);
aoqi@0 574 }
aoqi@0 575
aoqi@0 576 void TemplateTable::wide_aload() {
aoqi@0 577 transition(vtos, atos);
aoqi@0 578
aoqi@0 579 const Register Rindex = R11_scratch1;
aoqi@0 580 locals_index_wide(Rindex);
aoqi@0 581 __ load_local_ptr(R17_tos, Rindex, Rindex);
aoqi@0 582 }
aoqi@0 583
aoqi@0 584 void TemplateTable::iaload() {
aoqi@0 585 transition(itos, itos);
aoqi@0 586
aoqi@0 587 const Register Rload_addr = R3_ARG1,
aoqi@0 588 Rarray = R4_ARG2,
aoqi@0 589 Rtemp = R5_ARG3;
aoqi@0 590 __ index_check(Rarray, R17_tos /* index */, LogBytesPerInt, Rtemp, Rload_addr);
aoqi@0 591 __ lwa(R17_tos, arrayOopDesc::base_offset_in_bytes(T_INT), Rload_addr);
aoqi@0 592 }
aoqi@0 593
aoqi@0 594 void TemplateTable::laload() {
aoqi@0 595 transition(itos, ltos);
aoqi@0 596
aoqi@0 597 const Register Rload_addr = R3_ARG1,
aoqi@0 598 Rarray = R4_ARG2,
aoqi@0 599 Rtemp = R5_ARG3;
aoqi@0 600 __ index_check(Rarray, R17_tos /* index */, LogBytesPerLong, Rtemp, Rload_addr);
aoqi@0 601 __ ld(R17_tos, arrayOopDesc::base_offset_in_bytes(T_LONG), Rload_addr);
aoqi@0 602 }
aoqi@0 603
aoqi@0 604 void TemplateTable::faload() {
aoqi@0 605 transition(itos, ftos);
aoqi@0 606
aoqi@0 607 const Register Rload_addr = R3_ARG1,
aoqi@0 608 Rarray = R4_ARG2,
aoqi@0 609 Rtemp = R5_ARG3;
aoqi@0 610 __ index_check(Rarray, R17_tos /* index */, LogBytesPerInt, Rtemp, Rload_addr);
aoqi@0 611 __ lfs(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Rload_addr);
aoqi@0 612 }
aoqi@0 613
aoqi@0 614 void TemplateTable::daload() {
aoqi@0 615 transition(itos, dtos);
aoqi@0 616
aoqi@0 617 const Register Rload_addr = R3_ARG1,
aoqi@0 618 Rarray = R4_ARG2,
aoqi@0 619 Rtemp = R5_ARG3;
aoqi@0 620 __ index_check(Rarray, R17_tos /* index */, LogBytesPerLong, Rtemp, Rload_addr);
aoqi@0 621 __ lfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rload_addr);
aoqi@0 622 }
aoqi@0 623
aoqi@0 624 void TemplateTable::aaload() {
aoqi@0 625 transition(itos, atos);
aoqi@0 626
aoqi@0 627 // tos: index
aoqi@0 628 // result tos: array
aoqi@0 629 const Register Rload_addr = R3_ARG1,
aoqi@0 630 Rarray = R4_ARG2,
aoqi@0 631 Rtemp = R5_ARG3;
aoqi@0 632 __ index_check(Rarray, R17_tos /* index */, UseCompressedOops ? 2 : LogBytesPerWord, Rtemp, Rload_addr);
aoqi@0 633 __ load_heap_oop(R17_tos, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Rload_addr);
aoqi@0 634 __ verify_oop(R17_tos);
aoqi@0 635 //__ dcbt(R17_tos); // prefetch
aoqi@0 636 }
aoqi@0 637
aoqi@0 638 void TemplateTable::baload() {
aoqi@0 639 transition(itos, itos);
aoqi@0 640
aoqi@0 641 const Register Rload_addr = R3_ARG1,
aoqi@0 642 Rarray = R4_ARG2,
aoqi@0 643 Rtemp = R5_ARG3;
aoqi@0 644 __ index_check(Rarray, R17_tos /* index */, 0, Rtemp, Rload_addr);
aoqi@0 645 __ lbz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_BYTE), Rload_addr);
aoqi@0 646 __ extsb(R17_tos, R17_tos);
aoqi@0 647 }
aoqi@0 648
aoqi@0 649 void TemplateTable::caload() {
aoqi@0 650 transition(itos, itos);
aoqi@0 651
aoqi@0 652 const Register Rload_addr = R3_ARG1,
aoqi@0 653 Rarray = R4_ARG2,
aoqi@0 654 Rtemp = R5_ARG3;
aoqi@0 655 __ index_check(Rarray, R17_tos /* index */, LogBytesPerShort, Rtemp, Rload_addr);
aoqi@0 656 __ lhz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_CHAR), Rload_addr);
aoqi@0 657 }
aoqi@0 658
aoqi@0 659 // Iload followed by caload frequent pair.
aoqi@0 660 void TemplateTable::fast_icaload() {
aoqi@0 661 transition(vtos, itos);
aoqi@0 662
aoqi@0 663 const Register Rload_addr = R3_ARG1,
aoqi@0 664 Rarray = R4_ARG2,
aoqi@0 665 Rtemp = R11_scratch1;
aoqi@0 666
aoqi@0 667 locals_index(R17_tos);
aoqi@0 668 __ load_local_int(R17_tos, Rtemp, R17_tos);
aoqi@0 669 __ index_check(Rarray, R17_tos /* index */, LogBytesPerShort, Rtemp, Rload_addr);
aoqi@0 670 __ lhz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_CHAR), Rload_addr);
aoqi@0 671 }
aoqi@0 672
aoqi@0 673 void TemplateTable::saload() {
aoqi@0 674 transition(itos, itos);
aoqi@0 675
aoqi@0 676 const Register Rload_addr = R11_scratch1,
aoqi@0 677 Rarray = R12_scratch2,
aoqi@0 678 Rtemp = R3_ARG1;
aoqi@0 679 __ index_check(Rarray, R17_tos /* index */, LogBytesPerShort, Rtemp, Rload_addr);
aoqi@0 680 __ lha(R17_tos, arrayOopDesc::base_offset_in_bytes(T_SHORT), Rload_addr);
aoqi@0 681 }
aoqi@0 682
aoqi@0 683 void TemplateTable::iload(int n) {
aoqi@0 684 transition(vtos, itos);
aoqi@0 685
aoqi@0 686 __ lwz(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals);
aoqi@0 687 }
aoqi@0 688
aoqi@0 689 void TemplateTable::lload(int n) {
aoqi@0 690 transition(vtos, ltos);
aoqi@0 691
aoqi@0 692 __ ld(R17_tos, Interpreter::local_offset_in_bytes(n + 1), R18_locals);
aoqi@0 693 }
aoqi@0 694
aoqi@0 695 void TemplateTable::fload(int n) {
aoqi@0 696 transition(vtos, ftos);
aoqi@0 697
aoqi@0 698 __ lfs(F15_ftos, Interpreter::local_offset_in_bytes(n), R18_locals);
aoqi@0 699 }
aoqi@0 700
aoqi@0 701 void TemplateTable::dload(int n) {
aoqi@0 702 transition(vtos, dtos);
aoqi@0 703
aoqi@0 704 __ lfd(F15_ftos, Interpreter::local_offset_in_bytes(n + 1), R18_locals);
aoqi@0 705 }
aoqi@0 706
aoqi@0 707 void TemplateTable::aload(int n) {
aoqi@0 708 transition(vtos, atos);
aoqi@0 709
aoqi@0 710 __ ld(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals);
aoqi@0 711 }
aoqi@0 712
aoqi@0 713 void TemplateTable::aload_0() {
aoqi@0 714 transition(vtos, atos);
aoqi@0 715 // According to bytecode histograms, the pairs:
aoqi@0 716 //
aoqi@0 717 // _aload_0, _fast_igetfield
aoqi@0 718 // _aload_0, _fast_agetfield
aoqi@0 719 // _aload_0, _fast_fgetfield
aoqi@0 720 //
aoqi@0 721 // occur frequently. If RewriteFrequentPairs is set, the (slow)
aoqi@0 722 // _aload_0 bytecode checks if the next bytecode is either
aoqi@0 723 // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then
aoqi@0 724 // rewrites the current bytecode into a pair bytecode; otherwise it
aoqi@0 725 // rewrites the current bytecode into _0 that doesn't do
aoqi@0 726 // the pair check anymore.
aoqi@0 727 //
aoqi@0 728 // Note: If the next bytecode is _getfield, the rewrite must be
aoqi@0 729 // delayed, otherwise we may miss an opportunity for a pair.
aoqi@0 730 //
aoqi@0 731 // Also rewrite frequent pairs
aoqi@0 732 // aload_0, aload_1
aoqi@0 733 // aload_0, iload_1
aoqi@0 734 // These bytecodes with a small amount of code are most profitable
aoqi@0 735 // to rewrite.
aoqi@0 736
aoqi@0 737 if (RewriteFrequentPairs) {
aoqi@0 738
aoqi@0 739 Label Lrewrite, Ldont_rewrite;
aoqi@0 740 Register Rnext_byte = R3_ARG1,
aoqi@0 741 Rrewrite_to = R6_ARG4,
aoqi@0 742 Rscratch = R11_scratch1;
aoqi@0 743
aoqi@0 744 // Get next byte.
aoqi@0 745 __ lbz(Rnext_byte, Bytecodes::length_for(Bytecodes::_aload_0), R14_bcp);
aoqi@0 746
aoqi@0 747 // If _getfield, wait to rewrite. We only want to rewrite the last two bytecodes in a pair.
aoqi@0 748 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_getfield);
aoqi@0 749 __ beq(CCR0, Ldont_rewrite);
aoqi@0 750
aoqi@0 751 __ cmpwi(CCR1, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_igetfield);
aoqi@0 752 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_iaccess_0);
aoqi@0 753 __ beq(CCR1, Lrewrite);
aoqi@0 754
aoqi@0 755 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_agetfield);
aoqi@0 756 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_aaccess_0);
aoqi@0 757 __ beq(CCR0, Lrewrite);
aoqi@0 758
aoqi@0 759 __ cmpwi(CCR1, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_fgetfield);
aoqi@0 760 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_faccess_0);
aoqi@0 761 __ beq(CCR1, Lrewrite);
aoqi@0 762
aoqi@0 763 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_aload_0);
aoqi@0 764
aoqi@0 765 __ bind(Lrewrite);
aoqi@0 766 patch_bytecode(Bytecodes::_aload_0, Rrewrite_to, Rscratch, false);
aoqi@0 767 __ bind(Ldont_rewrite);
aoqi@0 768 }
aoqi@0 769
aoqi@0 770 // Do actual aload_0 (must do this after patch_bytecode which might call VM and GC might change oop).
aoqi@0 771 aload(0);
aoqi@0 772 }
aoqi@0 773
aoqi@0 774 void TemplateTable::istore() {
aoqi@0 775 transition(itos, vtos);
aoqi@0 776
aoqi@0 777 const Register Rindex = R11_scratch1;
aoqi@0 778 locals_index(Rindex);
aoqi@0 779 __ store_local_int(R17_tos, Rindex);
aoqi@0 780 }
aoqi@0 781
aoqi@0 782 void TemplateTable::lstore() {
aoqi@0 783 transition(ltos, vtos);
aoqi@0 784 const Register Rindex = R11_scratch1;
aoqi@0 785 locals_index(Rindex);
aoqi@0 786 __ store_local_long(R17_tos, Rindex);
aoqi@0 787 }
aoqi@0 788
aoqi@0 789 void TemplateTable::fstore() {
aoqi@0 790 transition(ftos, vtos);
aoqi@0 791
aoqi@0 792 const Register Rindex = R11_scratch1;
aoqi@0 793 locals_index(Rindex);
aoqi@0 794 __ store_local_float(F15_ftos, Rindex);
aoqi@0 795 }
aoqi@0 796
aoqi@0 797 void TemplateTable::dstore() {
aoqi@0 798 transition(dtos, vtos);
aoqi@0 799
aoqi@0 800 const Register Rindex = R11_scratch1;
aoqi@0 801 locals_index(Rindex);
aoqi@0 802 __ store_local_double(F15_ftos, Rindex);
aoqi@0 803 }
aoqi@0 804
aoqi@0 805 void TemplateTable::astore() {
aoqi@0 806 transition(vtos, vtos);
aoqi@0 807
aoqi@0 808 const Register Rindex = R11_scratch1;
aoqi@0 809 __ pop_ptr();
aoqi@0 810 __ verify_oop_or_return_address(R17_tos, Rindex);
aoqi@0 811 locals_index(Rindex);
aoqi@0 812 __ store_local_ptr(R17_tos, Rindex);
aoqi@0 813 }
aoqi@0 814
aoqi@0 815 void TemplateTable::wide_istore() {
aoqi@0 816 transition(vtos, vtos);
aoqi@0 817
aoqi@0 818 const Register Rindex = R11_scratch1;
aoqi@0 819 __ pop_i();
aoqi@0 820 locals_index_wide(Rindex);
aoqi@0 821 __ store_local_int(R17_tos, Rindex);
aoqi@0 822 }
aoqi@0 823
aoqi@0 824 void TemplateTable::wide_lstore() {
aoqi@0 825 transition(vtos, vtos);
aoqi@0 826
aoqi@0 827 const Register Rindex = R11_scratch1;
aoqi@0 828 __ pop_l();
aoqi@0 829 locals_index_wide(Rindex);
aoqi@0 830 __ store_local_long(R17_tos, Rindex);
aoqi@0 831 }
aoqi@0 832
aoqi@0 833 void TemplateTable::wide_fstore() {
aoqi@0 834 transition(vtos, vtos);
aoqi@0 835
aoqi@0 836 const Register Rindex = R11_scratch1;
aoqi@0 837 __ pop_f();
aoqi@0 838 locals_index_wide(Rindex);
aoqi@0 839 __ store_local_float(F15_ftos, Rindex);
aoqi@0 840 }
aoqi@0 841
aoqi@0 842 void TemplateTable::wide_dstore() {
aoqi@0 843 transition(vtos, vtos);
aoqi@0 844
aoqi@0 845 const Register Rindex = R11_scratch1;
aoqi@0 846 __ pop_d();
aoqi@0 847 locals_index_wide(Rindex);
aoqi@0 848 __ store_local_double(F15_ftos, Rindex);
aoqi@0 849 }
aoqi@0 850
aoqi@0 851 void TemplateTable::wide_astore() {
aoqi@0 852 transition(vtos, vtos);
aoqi@0 853
aoqi@0 854 const Register Rindex = R11_scratch1;
aoqi@0 855 __ pop_ptr();
aoqi@0 856 __ verify_oop_or_return_address(R17_tos, Rindex);
aoqi@0 857 locals_index_wide(Rindex);
aoqi@0 858 __ store_local_ptr(R17_tos, Rindex);
aoqi@0 859 }
aoqi@0 860
aoqi@0 861 void TemplateTable::iastore() {
aoqi@0 862 transition(itos, vtos);
aoqi@0 863
aoqi@0 864 const Register Rindex = R3_ARG1,
aoqi@0 865 Rstore_addr = R4_ARG2,
aoqi@0 866 Rarray = R5_ARG3,
aoqi@0 867 Rtemp = R6_ARG4;
aoqi@0 868 __ pop_i(Rindex);
aoqi@0 869 __ index_check(Rarray, Rindex, LogBytesPerInt, Rtemp, Rstore_addr);
aoqi@0 870 __ stw(R17_tos, arrayOopDesc::base_offset_in_bytes(T_INT), Rstore_addr);
aoqi@0 871 }
aoqi@0 872
aoqi@0 873 void TemplateTable::lastore() {
aoqi@0 874 transition(ltos, vtos);
aoqi@0 875
aoqi@0 876 const Register Rindex = R3_ARG1,
aoqi@0 877 Rstore_addr = R4_ARG2,
aoqi@0 878 Rarray = R5_ARG3,
aoqi@0 879 Rtemp = R6_ARG4;
aoqi@0 880 __ pop_i(Rindex);
aoqi@0 881 __ index_check(Rarray, Rindex, LogBytesPerLong, Rtemp, Rstore_addr);
aoqi@0 882 __ std(R17_tos, arrayOopDesc::base_offset_in_bytes(T_LONG), Rstore_addr);
aoqi@0 883 }
aoqi@0 884
aoqi@0 885 void TemplateTable::fastore() {
aoqi@0 886 transition(ftos, vtos);
aoqi@0 887
aoqi@0 888 const Register Rindex = R3_ARG1,
aoqi@0 889 Rstore_addr = R4_ARG2,
aoqi@0 890 Rarray = R5_ARG3,
aoqi@0 891 Rtemp = R6_ARG4;
aoqi@0 892 __ pop_i(Rindex);
aoqi@0 893 __ index_check(Rarray, Rindex, LogBytesPerInt, Rtemp, Rstore_addr);
aoqi@0 894 __ stfs(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Rstore_addr);
aoqi@0 895 }
aoqi@0 896
aoqi@0 897 void TemplateTable::dastore() {
aoqi@0 898 transition(dtos, vtos);
aoqi@0 899
aoqi@0 900 const Register Rindex = R3_ARG1,
aoqi@0 901 Rstore_addr = R4_ARG2,
aoqi@0 902 Rarray = R5_ARG3,
aoqi@0 903 Rtemp = R6_ARG4;
aoqi@0 904 __ pop_i(Rindex);
aoqi@0 905 __ index_check(Rarray, Rindex, LogBytesPerLong, Rtemp, Rstore_addr);
aoqi@0 906 __ stfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rstore_addr);
aoqi@0 907 }
aoqi@0 908
aoqi@0 909 // Pop 3 values from the stack and...
aoqi@0 910 void TemplateTable::aastore() {
aoqi@0 911 transition(vtos, vtos);
aoqi@0 912
aoqi@0 913 Label Lstore_ok, Lis_null, Ldone;
aoqi@0 914 const Register Rindex = R3_ARG1,
aoqi@0 915 Rarray = R4_ARG2,
aoqi@0 916 Rscratch = R11_scratch1,
aoqi@0 917 Rscratch2 = R12_scratch2,
aoqi@0 918 Rarray_klass = R5_ARG3,
aoqi@0 919 Rarray_element_klass = Rarray_klass,
aoqi@0 920 Rvalue_klass = R6_ARG4,
aoqi@0 921 Rstore_addr = R31; // Use register which survives VM call.
aoqi@0 922
aoqi@0 923 __ ld(R17_tos, Interpreter::expr_offset_in_bytes(0), R15_esp); // Get value to store.
aoqi@0 924 __ lwz(Rindex, Interpreter::expr_offset_in_bytes(1), R15_esp); // Get index.
aoqi@0 925 __ ld(Rarray, Interpreter::expr_offset_in_bytes(2), R15_esp); // Get array.
aoqi@0 926
aoqi@0 927 __ verify_oop(R17_tos);
aoqi@0 928 __ index_check_without_pop(Rarray, Rindex, UseCompressedOops ? 2 : LogBytesPerWord, Rscratch, Rstore_addr);
aoqi@0 929 // Rindex is dead!
aoqi@0 930 Register Rscratch3 = Rindex;
aoqi@0 931
aoqi@0 932 // Do array store check - check for NULL value first.
aoqi@0 933 __ cmpdi(CCR0, R17_tos, 0);
aoqi@0 934 __ beq(CCR0, Lis_null);
aoqi@0 935
aoqi@0 936 __ load_klass(Rarray_klass, Rarray);
aoqi@0 937 __ load_klass(Rvalue_klass, R17_tos);
aoqi@0 938
aoqi@0 939 // Do fast instanceof cache test.
aoqi@0 940 __ ld(Rarray_element_klass, in_bytes(ObjArrayKlass::element_klass_offset()), Rarray_klass);
aoqi@0 941
aoqi@0 942 // Generate a fast subtype check. Branch to store_ok if no failure. Throw if failure.
aoqi@0 943 __ gen_subtype_check(Rvalue_klass /*subklass*/, Rarray_element_klass /*superklass*/, Rscratch, Rscratch2, Rscratch3, Lstore_ok);
aoqi@0 944
aoqi@0 945 // Fell through: subtype check failed => throw an exception.
aoqi@0 946 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArrayStoreException_entry);
aoqi@0 947 __ mtctr(R11_scratch1);
aoqi@0 948 __ bctr();
aoqi@0 949
aoqi@0 950 __ bind(Lis_null);
aoqi@0 951 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), noreg /* 0 */,
aoqi@0 952 Rscratch, Rscratch2, Rscratch3, _bs->kind(), true /* precise */, false /* check_null */);
aoqi@0 953 __ profile_null_seen(Rscratch, Rscratch2);
aoqi@0 954 __ b(Ldone);
aoqi@0 955
aoqi@0 956 // Store is OK.
aoqi@0 957 __ bind(Lstore_ok);
aoqi@0 958 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos /* value */,
aoqi@0 959 Rscratch, Rscratch2, Rscratch3, _bs->kind(), true /* precise */, false /* check_null */);
aoqi@0 960
aoqi@0 961 __ bind(Ldone);
aoqi@0 962 // Adjust sp (pops array, index and value).
aoqi@0 963 __ addi(R15_esp, R15_esp, 3 * Interpreter::stackElementSize);
aoqi@0 964 }
aoqi@0 965
aoqi@0 966 void TemplateTable::bastore() {
aoqi@0 967 transition(itos, vtos);
aoqi@0 968
aoqi@0 969 const Register Rindex = R11_scratch1,
aoqi@0 970 Rarray = R12_scratch2,
aoqi@0 971 Rscratch = R3_ARG1;
aoqi@0 972 __ pop_i(Rindex);
simonis@8381 973 __ pop_ptr(Rarray);
aoqi@0 974 // tos: val
simonis@8381 975
simonis@8381 976 // Need to check whether array is boolean or byte
simonis@8381 977 // since both types share the bastore bytecode.
simonis@8381 978 __ load_klass(Rscratch, Rarray);
simonis@8381 979 __ lwz(Rscratch, in_bytes(Klass::layout_helper_offset()), Rscratch);
simonis@8381 980 int diffbit = exact_log2(Klass::layout_helper_boolean_diffbit());
simonis@8381 981 __ testbitdi(CCR0, R0, Rscratch, diffbit);
simonis@8381 982 Label L_skip;
simonis@8381 983 __ bfalse(CCR0, L_skip);
simonis@8381 984 __ andi(R17_tos, R17_tos, 1); // if it is a T_BOOLEAN array, mask the stored value to 0/1
simonis@8381 985 __ bind(L_skip);
simonis@8381 986
simonis@8381 987 __ index_check_without_pop(Rarray, Rindex, 0, Rscratch, Rarray);
aoqi@0 988 __ stb(R17_tos, arrayOopDesc::base_offset_in_bytes(T_BYTE), Rarray);
aoqi@0 989 }
aoqi@0 990
aoqi@0 991 void TemplateTable::castore() {
aoqi@0 992 transition(itos, vtos);
aoqi@0 993
aoqi@0 994 const Register Rindex = R11_scratch1,
aoqi@0 995 Rarray = R12_scratch2,
aoqi@0 996 Rscratch = R3_ARG1;
aoqi@0 997 __ pop_i(Rindex);
aoqi@0 998 // tos: val
aoqi@0 999 // Rarray: array ptr (popped by index_check)
aoqi@0 1000 __ index_check(Rarray, Rindex, LogBytesPerShort, Rscratch, Rarray);
aoqi@0 1001 __ sth(R17_tos, arrayOopDesc::base_offset_in_bytes(T_CHAR), Rarray);
aoqi@0 1002 }
aoqi@0 1003
aoqi@0 1004 void TemplateTable::sastore() {
aoqi@0 1005 castore();
aoqi@0 1006 }
aoqi@0 1007
aoqi@0 1008 void TemplateTable::istore(int n) {
aoqi@0 1009 transition(itos, vtos);
aoqi@0 1010 __ stw(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals);
aoqi@0 1011 }
aoqi@0 1012
aoqi@0 1013 void TemplateTable::lstore(int n) {
aoqi@0 1014 transition(ltos, vtos);
aoqi@0 1015 __ std(R17_tos, Interpreter::local_offset_in_bytes(n + 1), R18_locals);
aoqi@0 1016 }
aoqi@0 1017
aoqi@0 1018 void TemplateTable::fstore(int n) {
aoqi@0 1019 transition(ftos, vtos);
aoqi@0 1020 __ stfs(F15_ftos, Interpreter::local_offset_in_bytes(n), R18_locals);
aoqi@0 1021 }
aoqi@0 1022
aoqi@0 1023 void TemplateTable::dstore(int n) {
aoqi@0 1024 transition(dtos, vtos);
aoqi@0 1025 __ stfd(F15_ftos, Interpreter::local_offset_in_bytes(n + 1), R18_locals);
aoqi@0 1026 }
aoqi@0 1027
aoqi@0 1028 void TemplateTable::astore(int n) {
aoqi@0 1029 transition(vtos, vtos);
aoqi@0 1030
aoqi@0 1031 __ pop_ptr();
aoqi@0 1032 __ verify_oop_or_return_address(R17_tos, R11_scratch1);
aoqi@0 1033 __ std(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals);
aoqi@0 1034 }
aoqi@0 1035
aoqi@0 1036 void TemplateTable::pop() {
aoqi@0 1037 transition(vtos, vtos);
aoqi@0 1038
aoqi@0 1039 __ addi(R15_esp, R15_esp, Interpreter::stackElementSize);
aoqi@0 1040 }
aoqi@0 1041
aoqi@0 1042 void TemplateTable::pop2() {
aoqi@0 1043 transition(vtos, vtos);
aoqi@0 1044
aoqi@0 1045 __ addi(R15_esp, R15_esp, Interpreter::stackElementSize * 2);
aoqi@0 1046 }
aoqi@0 1047
aoqi@0 1048 void TemplateTable::dup() {
aoqi@0 1049 transition(vtos, vtos);
aoqi@0 1050
aoqi@0 1051 __ ld(R11_scratch1, Interpreter::stackElementSize, R15_esp);
aoqi@0 1052 __ push_ptr(R11_scratch1);
aoqi@0 1053 }
aoqi@0 1054
aoqi@0 1055 void TemplateTable::dup_x1() {
aoqi@0 1056 transition(vtos, vtos);
aoqi@0 1057
aoqi@0 1058 Register Ra = R11_scratch1,
aoqi@0 1059 Rb = R12_scratch2;
aoqi@0 1060 // stack: ..., a, b
aoqi@0 1061 __ ld(Rb, Interpreter::stackElementSize, R15_esp);
aoqi@0 1062 __ ld(Ra, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1063 __ std(Rb, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1064 __ std(Ra, Interpreter::stackElementSize, R15_esp);
aoqi@0 1065 __ push_ptr(Rb);
aoqi@0 1066 // stack: ..., b, a, b
aoqi@0 1067 }
aoqi@0 1068
aoqi@0 1069 void TemplateTable::dup_x2() {
aoqi@0 1070 transition(vtos, vtos);
aoqi@0 1071
aoqi@0 1072 Register Ra = R11_scratch1,
aoqi@0 1073 Rb = R12_scratch2,
aoqi@0 1074 Rc = R3_ARG1;
aoqi@0 1075
aoqi@0 1076 // stack: ..., a, b, c
aoqi@0 1077 __ ld(Rc, Interpreter::stackElementSize, R15_esp); // load c
aoqi@0 1078 __ ld(Ra, Interpreter::stackElementSize * 3, R15_esp); // load a
aoqi@0 1079 __ std(Rc, Interpreter::stackElementSize * 3, R15_esp); // store c in a
aoqi@0 1080 __ ld(Rb, Interpreter::stackElementSize * 2, R15_esp); // load b
aoqi@0 1081 // stack: ..., c, b, c
aoqi@0 1082 __ std(Ra, Interpreter::stackElementSize * 2, R15_esp); // store a in b
aoqi@0 1083 // stack: ..., c, a, c
aoqi@0 1084 __ std(Rb, Interpreter::stackElementSize, R15_esp); // store b in c
aoqi@0 1085 __ push_ptr(Rc); // push c
aoqi@0 1086 // stack: ..., c, a, b, c
aoqi@0 1087 }
aoqi@0 1088
aoqi@0 1089 void TemplateTable::dup2() {
aoqi@0 1090 transition(vtos, vtos);
aoqi@0 1091
aoqi@0 1092 Register Ra = R11_scratch1,
aoqi@0 1093 Rb = R12_scratch2;
aoqi@0 1094 // stack: ..., a, b
aoqi@0 1095 __ ld(Rb, Interpreter::stackElementSize, R15_esp);
aoqi@0 1096 __ ld(Ra, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1097 __ push_2ptrs(Ra, Rb);
aoqi@0 1098 // stack: ..., a, b, a, b
aoqi@0 1099 }
aoqi@0 1100
aoqi@0 1101 void TemplateTable::dup2_x1() {
aoqi@0 1102 transition(vtos, vtos);
aoqi@0 1103
aoqi@0 1104 Register Ra = R11_scratch1,
aoqi@0 1105 Rb = R12_scratch2,
aoqi@0 1106 Rc = R3_ARG1;
aoqi@0 1107 // stack: ..., a, b, c
aoqi@0 1108 __ ld(Rc, Interpreter::stackElementSize, R15_esp);
aoqi@0 1109 __ ld(Rb, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1110 __ std(Rc, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1111 __ ld(Ra, Interpreter::stackElementSize * 3, R15_esp);
aoqi@0 1112 __ std(Ra, Interpreter::stackElementSize, R15_esp);
aoqi@0 1113 __ std(Rb, Interpreter::stackElementSize * 3, R15_esp);
aoqi@0 1114 // stack: ..., b, c, a
aoqi@0 1115 __ push_2ptrs(Rb, Rc);
aoqi@0 1116 // stack: ..., b, c, a, b, c
aoqi@0 1117 }
aoqi@0 1118
aoqi@0 1119 void TemplateTable::dup2_x2() {
aoqi@0 1120 transition(vtos, vtos);
aoqi@0 1121
aoqi@0 1122 Register Ra = R11_scratch1,
aoqi@0 1123 Rb = R12_scratch2,
aoqi@0 1124 Rc = R3_ARG1,
aoqi@0 1125 Rd = R4_ARG2;
aoqi@0 1126 // stack: ..., a, b, c, d
aoqi@0 1127 __ ld(Rb, Interpreter::stackElementSize * 3, R15_esp);
aoqi@0 1128 __ ld(Rd, Interpreter::stackElementSize, R15_esp);
aoqi@0 1129 __ std(Rb, Interpreter::stackElementSize, R15_esp); // store b in d
aoqi@0 1130 __ std(Rd, Interpreter::stackElementSize * 3, R15_esp); // store d in b
aoqi@0 1131 __ ld(Ra, Interpreter::stackElementSize * 4, R15_esp);
aoqi@0 1132 __ ld(Rc, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1133 __ std(Ra, Interpreter::stackElementSize * 2, R15_esp); // store a in c
aoqi@0 1134 __ std(Rc, Interpreter::stackElementSize * 4, R15_esp); // store c in a
aoqi@0 1135 // stack: ..., c, d, a, b
aoqi@0 1136 __ push_2ptrs(Rc, Rd);
aoqi@0 1137 // stack: ..., c, d, a, b, c, d
aoqi@0 1138 }
aoqi@0 1139
aoqi@0 1140 void TemplateTable::swap() {
aoqi@0 1141 transition(vtos, vtos);
aoqi@0 1142 // stack: ..., a, b
aoqi@0 1143
aoqi@0 1144 Register Ra = R11_scratch1,
aoqi@0 1145 Rb = R12_scratch2;
aoqi@0 1146 // stack: ..., a, b
aoqi@0 1147 __ ld(Rb, Interpreter::stackElementSize, R15_esp);
aoqi@0 1148 __ ld(Ra, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1149 __ std(Rb, Interpreter::stackElementSize * 2, R15_esp);
aoqi@0 1150 __ std(Ra, Interpreter::stackElementSize, R15_esp);
aoqi@0 1151 // stack: ..., b, a
aoqi@0 1152 }
aoqi@0 1153
aoqi@0 1154 void TemplateTable::iop2(Operation op) {
aoqi@0 1155 transition(itos, itos);
aoqi@0 1156
aoqi@0 1157 Register Rscratch = R11_scratch1;
aoqi@0 1158
aoqi@0 1159 __ pop_i(Rscratch);
aoqi@0 1160 // tos = number of bits to shift
aoqi@0 1161 // Rscratch = value to shift
aoqi@0 1162 switch (op) {
aoqi@0 1163 case add: __ add(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1164 case sub: __ sub(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1165 case mul: __ mullw(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1166 case _and: __ andr(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1167 case _or: __ orr(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1168 case _xor: __ xorr(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1169 case shl: __ rldicl(R17_tos, R17_tos, 0, 64-5); __ slw(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1170 case shr: __ rldicl(R17_tos, R17_tos, 0, 64-5); __ sraw(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1171 case ushr: __ rldicl(R17_tos, R17_tos, 0, 64-5); __ srw(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1172 default: ShouldNotReachHere();
aoqi@0 1173 }
aoqi@0 1174 }
aoqi@0 1175
aoqi@0 1176 void TemplateTable::lop2(Operation op) {
aoqi@0 1177 transition(ltos, ltos);
aoqi@0 1178
aoqi@0 1179 Register Rscratch = R11_scratch1;
aoqi@0 1180 __ pop_l(Rscratch);
aoqi@0 1181 switch (op) {
aoqi@0 1182 case add: __ add(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1183 case sub: __ sub(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1184 case _and: __ andr(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1185 case _or: __ orr(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1186 case _xor: __ xorr(R17_tos, Rscratch, R17_tos); break;
aoqi@0 1187 default: ShouldNotReachHere();
aoqi@0 1188 }
aoqi@0 1189 }
aoqi@0 1190
aoqi@0 1191 void TemplateTable::idiv() {
aoqi@0 1192 transition(itos, itos);
aoqi@0 1193
aoqi@0 1194 Label Lnormal, Lexception, Ldone;
aoqi@0 1195 Register Rdividend = R11_scratch1; // Used by irem.
aoqi@0 1196
aoqi@0 1197 __ addi(R0, R17_tos, 1);
aoqi@0 1198 __ cmplwi(CCR0, R0, 2);
aoqi@0 1199 __ bgt(CCR0, Lnormal); // divisor <-1 or >1
aoqi@0 1200
aoqi@0 1201 __ cmpwi(CCR1, R17_tos, 0);
aoqi@0 1202 __ beq(CCR1, Lexception); // divisor == 0
aoqi@0 1203
aoqi@0 1204 __ pop_i(Rdividend);
aoqi@0 1205 __ mullw(R17_tos, Rdividend, R17_tos); // div by +/-1
aoqi@0 1206 __ b(Ldone);
aoqi@0 1207
aoqi@0 1208 __ bind(Lexception);
aoqi@0 1209 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArithmeticException_entry);
aoqi@0 1210 __ mtctr(R11_scratch1);
aoqi@0 1211 __ bctr();
aoqi@0 1212
aoqi@0 1213 __ align(32, 12);
aoqi@0 1214 __ bind(Lnormal);
aoqi@0 1215 __ pop_i(Rdividend);
aoqi@0 1216 __ divw(R17_tos, Rdividend, R17_tos); // Can't divide minint/-1.
aoqi@0 1217 __ bind(Ldone);
aoqi@0 1218 }
aoqi@0 1219
aoqi@0 1220 void TemplateTable::irem() {
aoqi@0 1221 transition(itos, itos);
aoqi@0 1222
aoqi@0 1223 __ mr(R12_scratch2, R17_tos);
aoqi@0 1224 idiv();
aoqi@0 1225 __ mullw(R17_tos, R17_tos, R12_scratch2);
aoqi@0 1226 __ subf(R17_tos, R17_tos, R11_scratch1); // Dividend set by idiv.
aoqi@0 1227 }
aoqi@0 1228
aoqi@0 1229 void TemplateTable::lmul() {
aoqi@0 1230 transition(ltos, ltos);
aoqi@0 1231
aoqi@0 1232 __ pop_l(R11_scratch1);
aoqi@0 1233 __ mulld(R17_tos, R11_scratch1, R17_tos);
aoqi@0 1234 }
aoqi@0 1235
aoqi@0 1236 void TemplateTable::ldiv() {
aoqi@0 1237 transition(ltos, ltos);
aoqi@0 1238
aoqi@0 1239 Label Lnormal, Lexception, Ldone;
aoqi@0 1240 Register Rdividend = R11_scratch1; // Used by lrem.
aoqi@0 1241
aoqi@0 1242 __ addi(R0, R17_tos, 1);
aoqi@0 1243 __ cmpldi(CCR0, R0, 2);
aoqi@0 1244 __ bgt(CCR0, Lnormal); // divisor <-1 or >1
aoqi@0 1245
aoqi@0 1246 __ cmpdi(CCR1, R17_tos, 0);
aoqi@0 1247 __ beq(CCR1, Lexception); // divisor == 0
aoqi@0 1248
aoqi@0 1249 __ pop_l(Rdividend);
aoqi@0 1250 __ mulld(R17_tos, Rdividend, R17_tos); // div by +/-1
aoqi@0 1251 __ b(Ldone);
aoqi@0 1252
aoqi@0 1253 __ bind(Lexception);
aoqi@0 1254 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArithmeticException_entry);
aoqi@0 1255 __ mtctr(R11_scratch1);
aoqi@0 1256 __ bctr();
aoqi@0 1257
aoqi@0 1258 __ align(32, 12);
aoqi@0 1259 __ bind(Lnormal);
aoqi@0 1260 __ pop_l(Rdividend);
aoqi@0 1261 __ divd(R17_tos, Rdividend, R17_tos); // Can't divide minint/-1.
aoqi@0 1262 __ bind(Ldone);
aoqi@0 1263 }
aoqi@0 1264
aoqi@0 1265 void TemplateTable::lrem() {
aoqi@0 1266 transition(ltos, ltos);
aoqi@0 1267
aoqi@0 1268 __ mr(R12_scratch2, R17_tos);
aoqi@0 1269 ldiv();
aoqi@0 1270 __ mulld(R17_tos, R17_tos, R12_scratch2);
aoqi@0 1271 __ subf(R17_tos, R17_tos, R11_scratch1); // Dividend set by ldiv.
aoqi@0 1272 }
aoqi@0 1273
aoqi@0 1274 void TemplateTable::lshl() {
aoqi@0 1275 transition(itos, ltos);
aoqi@0 1276
aoqi@0 1277 __ rldicl(R17_tos, R17_tos, 0, 64-6); // Extract least significant bits.
aoqi@0 1278 __ pop_l(R11_scratch1);
aoqi@0 1279 __ sld(R17_tos, R11_scratch1, R17_tos);
aoqi@0 1280 }
aoqi@0 1281
aoqi@0 1282 void TemplateTable::lshr() {
aoqi@0 1283 transition(itos, ltos);
aoqi@0 1284
aoqi@0 1285 __ rldicl(R17_tos, R17_tos, 0, 64-6); // Extract least significant bits.
aoqi@0 1286 __ pop_l(R11_scratch1);
aoqi@0 1287 __ srad(R17_tos, R11_scratch1, R17_tos);
aoqi@0 1288 }
aoqi@0 1289
aoqi@0 1290 void TemplateTable::lushr() {
aoqi@0 1291 transition(itos, ltos);
aoqi@0 1292
aoqi@0 1293 __ rldicl(R17_tos, R17_tos, 0, 64-6); // Extract least significant bits.
aoqi@0 1294 __ pop_l(R11_scratch1);
aoqi@0 1295 __ srd(R17_tos, R11_scratch1, R17_tos);
aoqi@0 1296 }
aoqi@0 1297
aoqi@0 1298 void TemplateTable::fop2(Operation op) {
aoqi@0 1299 transition(ftos, ftos);
aoqi@0 1300
aoqi@0 1301 switch (op) {
aoqi@0 1302 case add: __ pop_f(F0_SCRATCH); __ fadds(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1303 case sub: __ pop_f(F0_SCRATCH); __ fsubs(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1304 case mul: __ pop_f(F0_SCRATCH); __ fmuls(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1305 case div: __ pop_f(F0_SCRATCH); __ fdivs(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1306 case rem:
aoqi@0 1307 __ pop_f(F1_ARG1);
aoqi@0 1308 __ fmr(F2_ARG2, F15_ftos);
aoqi@0 1309 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::frem));
aoqi@0 1310 __ fmr(F15_ftos, F1_RET);
aoqi@0 1311 break;
aoqi@0 1312
aoqi@0 1313 default: ShouldNotReachHere();
aoqi@0 1314 }
aoqi@0 1315 }
aoqi@0 1316
aoqi@0 1317 void TemplateTable::dop2(Operation op) {
aoqi@0 1318 transition(dtos, dtos);
aoqi@0 1319
aoqi@0 1320 switch (op) {
aoqi@0 1321 case add: __ pop_d(F0_SCRATCH); __ fadd(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1322 case sub: __ pop_d(F0_SCRATCH); __ fsub(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1323 case mul: __ pop_d(F0_SCRATCH); __ fmul(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1324 case div: __ pop_d(F0_SCRATCH); __ fdiv(F15_ftos, F0_SCRATCH, F15_ftos); break;
aoqi@0 1325 case rem:
aoqi@0 1326 __ pop_d(F1_ARG1);
aoqi@0 1327 __ fmr(F2_ARG2, F15_ftos);
aoqi@0 1328 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::drem));
aoqi@0 1329 __ fmr(F15_ftos, F1_RET);
aoqi@0 1330 break;
aoqi@0 1331
aoqi@0 1332 default: ShouldNotReachHere();
aoqi@0 1333 }
aoqi@0 1334 }
aoqi@0 1335
aoqi@0 1336 // Negate the value in the TOS cache.
aoqi@0 1337 void TemplateTable::ineg() {
aoqi@0 1338 transition(itos, itos);
aoqi@0 1339
aoqi@0 1340 __ neg(R17_tos, R17_tos);
aoqi@0 1341 }
aoqi@0 1342
aoqi@0 1343 // Negate the value in the TOS cache.
aoqi@0 1344 void TemplateTable::lneg() {
aoqi@0 1345 transition(ltos, ltos);
aoqi@0 1346
aoqi@0 1347 __ neg(R17_tos, R17_tos);
aoqi@0 1348 }
aoqi@0 1349
aoqi@0 1350 void TemplateTable::fneg() {
aoqi@0 1351 transition(ftos, ftos);
aoqi@0 1352
aoqi@0 1353 __ fneg(F15_ftos, F15_ftos);
aoqi@0 1354 }
aoqi@0 1355
aoqi@0 1356 void TemplateTable::dneg() {
aoqi@0 1357 transition(dtos, dtos);
aoqi@0 1358
aoqi@0 1359 __ fneg(F15_ftos, F15_ftos);
aoqi@0 1360 }
aoqi@0 1361
aoqi@0 1362 // Increments a local variable in place.
aoqi@0 1363 void TemplateTable::iinc() {
aoqi@0 1364 transition(vtos, vtos);
aoqi@0 1365
aoqi@0 1366 const Register Rindex = R11_scratch1,
aoqi@0 1367 Rincrement = R0,
aoqi@0 1368 Rvalue = R12_scratch2;
aoqi@0 1369
aoqi@0 1370 locals_index(Rindex); // Load locals index from bytecode stream.
aoqi@0 1371 __ lbz(Rincrement, 2, R14_bcp); // Load increment from the bytecode stream.
aoqi@0 1372 __ extsb(Rincrement, Rincrement);
aoqi@0 1373
aoqi@0 1374 __ load_local_int(Rvalue, Rindex, Rindex); // Puts address of local into Rindex.
aoqi@0 1375
aoqi@0 1376 __ add(Rvalue, Rincrement, Rvalue);
aoqi@0 1377 __ stw(Rvalue, 0, Rindex);
aoqi@0 1378 }
aoqi@0 1379
aoqi@0 1380 void TemplateTable::wide_iinc() {
aoqi@0 1381 transition(vtos, vtos);
aoqi@0 1382
aoqi@0 1383 Register Rindex = R11_scratch1,
aoqi@0 1384 Rlocals_addr = Rindex,
aoqi@0 1385 Rincr = R12_scratch2;
aoqi@0 1386 locals_index_wide(Rindex);
aoqi@0 1387 __ get_2_byte_integer_at_bcp(4, Rincr, InterpreterMacroAssembler::Signed);
aoqi@0 1388 __ load_local_int(R17_tos, Rlocals_addr, Rindex);
aoqi@0 1389 __ add(R17_tos, Rincr, R17_tos);
aoqi@0 1390 __ stw(R17_tos, 0, Rlocals_addr);
aoqi@0 1391 }
aoqi@0 1392
aoqi@0 1393 void TemplateTable::convert() {
aoqi@0 1394 // %%%%% Factor this first part accross platforms
aoqi@0 1395 #ifdef ASSERT
aoqi@0 1396 TosState tos_in = ilgl;
aoqi@0 1397 TosState tos_out = ilgl;
aoqi@0 1398 switch (bytecode()) {
aoqi@0 1399 case Bytecodes::_i2l: // fall through
aoqi@0 1400 case Bytecodes::_i2f: // fall through
aoqi@0 1401 case Bytecodes::_i2d: // fall through
aoqi@0 1402 case Bytecodes::_i2b: // fall through
aoqi@0 1403 case Bytecodes::_i2c: // fall through
aoqi@0 1404 case Bytecodes::_i2s: tos_in = itos; break;
aoqi@0 1405 case Bytecodes::_l2i: // fall through
aoqi@0 1406 case Bytecodes::_l2f: // fall through
aoqi@0 1407 case Bytecodes::_l2d: tos_in = ltos; break;
aoqi@0 1408 case Bytecodes::_f2i: // fall through
aoqi@0 1409 case Bytecodes::_f2l: // fall through
aoqi@0 1410 case Bytecodes::_f2d: tos_in = ftos; break;
aoqi@0 1411 case Bytecodes::_d2i: // fall through
aoqi@0 1412 case Bytecodes::_d2l: // fall through
aoqi@0 1413 case Bytecodes::_d2f: tos_in = dtos; break;
aoqi@0 1414 default : ShouldNotReachHere();
aoqi@0 1415 }
aoqi@0 1416 switch (bytecode()) {
aoqi@0 1417 case Bytecodes::_l2i: // fall through
aoqi@0 1418 case Bytecodes::_f2i: // fall through
aoqi@0 1419 case Bytecodes::_d2i: // fall through
aoqi@0 1420 case Bytecodes::_i2b: // fall through
aoqi@0 1421 case Bytecodes::_i2c: // fall through
aoqi@0 1422 case Bytecodes::_i2s: tos_out = itos; break;
aoqi@0 1423 case Bytecodes::_i2l: // fall through
aoqi@0 1424 case Bytecodes::_f2l: // fall through
aoqi@0 1425 case Bytecodes::_d2l: tos_out = ltos; break;
aoqi@0 1426 case Bytecodes::_i2f: // fall through
aoqi@0 1427 case Bytecodes::_l2f: // fall through
aoqi@0 1428 case Bytecodes::_d2f: tos_out = ftos; break;
aoqi@0 1429 case Bytecodes::_i2d: // fall through
aoqi@0 1430 case Bytecodes::_l2d: // fall through
aoqi@0 1431 case Bytecodes::_f2d: tos_out = dtos; break;
aoqi@0 1432 default : ShouldNotReachHere();
aoqi@0 1433 }
aoqi@0 1434 transition(tos_in, tos_out);
aoqi@0 1435 #endif
aoqi@0 1436
aoqi@0 1437 // Conversion
aoqi@0 1438 Label done;
aoqi@0 1439 switch (bytecode()) {
aoqi@0 1440 case Bytecodes::_i2l:
aoqi@0 1441 __ extsw(R17_tos, R17_tos);
aoqi@0 1442 break;
aoqi@0 1443
aoqi@0 1444 case Bytecodes::_l2i:
aoqi@0 1445 // Nothing to do, we'll continue to work with the lower bits.
aoqi@0 1446 break;
aoqi@0 1447
aoqi@0 1448 case Bytecodes::_i2b:
aoqi@0 1449 __ extsb(R17_tos, R17_tos);
aoqi@0 1450 break;
aoqi@0 1451
aoqi@0 1452 case Bytecodes::_i2c:
aoqi@0 1453 __ rldicl(R17_tos, R17_tos, 0, 64-2*8);
aoqi@0 1454 break;
aoqi@0 1455
aoqi@0 1456 case Bytecodes::_i2s:
aoqi@0 1457 __ extsh(R17_tos, R17_tos);
aoqi@0 1458 break;
aoqi@0 1459
aoqi@0 1460 case Bytecodes::_i2d:
aoqi@0 1461 __ extsw(R17_tos, R17_tos);
aoqi@0 1462 case Bytecodes::_l2d:
aoqi@0 1463 __ push_l_pop_d();
aoqi@0 1464 __ fcfid(F15_ftos, F15_ftos);
aoqi@0 1465 break;
aoqi@0 1466
aoqi@0 1467 case Bytecodes::_i2f:
aoqi@0 1468 __ extsw(R17_tos, R17_tos);
aoqi@0 1469 __ push_l_pop_d();
aoqi@0 1470 if (VM_Version::has_fcfids()) { // fcfids is >= Power7 only
aoqi@0 1471 // Comment: alternatively, load with sign extend could be done by lfiwax.
aoqi@0 1472 __ fcfids(F15_ftos, F15_ftos);
aoqi@0 1473 } else {
aoqi@0 1474 __ fcfid(F15_ftos, F15_ftos);
aoqi@0 1475 __ frsp(F15_ftos, F15_ftos);
aoqi@0 1476 }
aoqi@0 1477 break;
aoqi@0 1478
aoqi@0 1479 case Bytecodes::_l2f:
aoqi@0 1480 if (VM_Version::has_fcfids()) { // fcfids is >= Power7 only
aoqi@0 1481 __ push_l_pop_d();
aoqi@0 1482 __ fcfids(F15_ftos, F15_ftos);
aoqi@0 1483 } else {
aoqi@0 1484 // Avoid rounding problem when result should be 0x3f800001: need fixup code before fcfid+frsp.
aoqi@0 1485 __ mr(R3_ARG1, R17_tos);
aoqi@0 1486 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::l2f));
aoqi@0 1487 __ fmr(F15_ftos, F1_RET);
aoqi@0 1488 }
aoqi@0 1489 break;
aoqi@0 1490
aoqi@0 1491 case Bytecodes::_f2d:
aoqi@0 1492 // empty
aoqi@0 1493 break;
aoqi@0 1494
aoqi@0 1495 case Bytecodes::_d2f:
aoqi@0 1496 __ frsp(F15_ftos, F15_ftos);
aoqi@0 1497 break;
aoqi@0 1498
aoqi@0 1499 case Bytecodes::_d2i:
aoqi@0 1500 case Bytecodes::_f2i:
aoqi@0 1501 __ fcmpu(CCR0, F15_ftos, F15_ftos);
aoqi@0 1502 __ li(R17_tos, 0); // 0 in case of NAN
aoqi@0 1503 __ bso(CCR0, done);
aoqi@0 1504 __ fctiwz(F15_ftos, F15_ftos);
aoqi@0 1505 __ push_d_pop_l();
aoqi@0 1506 break;
aoqi@0 1507
aoqi@0 1508 case Bytecodes::_d2l:
aoqi@0 1509 case Bytecodes::_f2l:
aoqi@0 1510 __ fcmpu(CCR0, F15_ftos, F15_ftos);
aoqi@0 1511 __ li(R17_tos, 0); // 0 in case of NAN
aoqi@0 1512 __ bso(CCR0, done);
aoqi@0 1513 __ fctidz(F15_ftos, F15_ftos);
aoqi@0 1514 __ push_d_pop_l();
aoqi@0 1515 break;
aoqi@0 1516
aoqi@0 1517 default: ShouldNotReachHere();
aoqi@0 1518 }
aoqi@0 1519 __ bind(done);
aoqi@0 1520 }
aoqi@0 1521
aoqi@0 1522 // Long compare
aoqi@0 1523 void TemplateTable::lcmp() {
aoqi@0 1524 transition(ltos, itos);
aoqi@0 1525
aoqi@0 1526 const Register Rscratch = R11_scratch1;
aoqi@0 1527 __ pop_l(Rscratch); // first operand, deeper in stack
aoqi@0 1528
aoqi@0 1529 __ cmpd(CCR0, Rscratch, R17_tos); // compare
aoqi@0 1530 __ mfcr(R17_tos); // set bit 32..33 as follows: <: 0b10, =: 0b00, >: 0b01
aoqi@0 1531 __ srwi(Rscratch, R17_tos, 30);
aoqi@0 1532 __ srawi(R17_tos, R17_tos, 31);
aoqi@0 1533 __ orr(R17_tos, Rscratch, R17_tos); // set result as follows: <: -1, =: 0, >: 1
aoqi@0 1534 }
aoqi@0 1535
aoqi@0 1536 // fcmpl/fcmpg and dcmpl/dcmpg bytecodes
aoqi@0 1537 // unordered_result == -1 => fcmpl or dcmpl
aoqi@0 1538 // unordered_result == 1 => fcmpg or dcmpg
aoqi@0 1539 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
aoqi@0 1540 const FloatRegister Rfirst = F0_SCRATCH,
aoqi@0 1541 Rsecond = F15_ftos;
aoqi@0 1542 const Register Rscratch = R11_scratch1;
aoqi@0 1543
aoqi@0 1544 if (is_float) {
aoqi@0 1545 __ pop_f(Rfirst);
aoqi@0 1546 } else {
aoqi@0 1547 __ pop_d(Rfirst);
aoqi@0 1548 }
aoqi@0 1549
aoqi@0 1550 Label Lunordered, Ldone;
aoqi@0 1551 __ fcmpu(CCR0, Rfirst, Rsecond); // compare
aoqi@0 1552 if (unordered_result) {
aoqi@0 1553 __ bso(CCR0, Lunordered);
aoqi@0 1554 }
aoqi@0 1555 __ mfcr(R17_tos); // set bit 32..33 as follows: <: 0b10, =: 0b00, >: 0b01
aoqi@0 1556 __ srwi(Rscratch, R17_tos, 30);
aoqi@0 1557 __ srawi(R17_tos, R17_tos, 31);
aoqi@0 1558 __ orr(R17_tos, Rscratch, R17_tos); // set result as follows: <: -1, =: 0, >: 1
aoqi@0 1559 if (unordered_result) {
aoqi@0 1560 __ b(Ldone);
aoqi@0 1561 __ bind(Lunordered);
aoqi@0 1562 __ load_const_optimized(R17_tos, unordered_result);
aoqi@0 1563 }
aoqi@0 1564 __ bind(Ldone);
aoqi@0 1565 }
aoqi@0 1566
aoqi@0 1567 // Branch_conditional which takes TemplateTable::Condition.
aoqi@0 1568 void TemplateTable::branch_conditional(ConditionRegister crx, TemplateTable::Condition cc, Label& L, bool invert) {
aoqi@0 1569 bool positive = false;
aoqi@0 1570 Assembler::Condition cond = Assembler::equal;
aoqi@0 1571 switch (cc) {
aoqi@0 1572 case TemplateTable::equal: positive = true ; cond = Assembler::equal ; break;
aoqi@0 1573 case TemplateTable::not_equal: positive = false; cond = Assembler::equal ; break;
aoqi@0 1574 case TemplateTable::less: positive = true ; cond = Assembler::less ; break;
aoqi@0 1575 case TemplateTable::less_equal: positive = false; cond = Assembler::greater; break;
aoqi@0 1576 case TemplateTable::greater: positive = true ; cond = Assembler::greater; break;
aoqi@0 1577 case TemplateTable::greater_equal: positive = false; cond = Assembler::less ; break;
aoqi@0 1578 default: ShouldNotReachHere();
aoqi@0 1579 }
aoqi@0 1580 int bo = (positive != invert) ? Assembler::bcondCRbiIs1 : Assembler::bcondCRbiIs0;
aoqi@0 1581 int bi = Assembler::bi0(crx, cond);
aoqi@0 1582 __ bc(bo, bi, L);
aoqi@0 1583 }
aoqi@0 1584
aoqi@0 1585 void TemplateTable::branch(bool is_jsr, bool is_wide) {
aoqi@0 1586
aoqi@0 1587 // Note: on SPARC, we use InterpreterMacroAssembler::if_cmp also.
aoqi@0 1588 __ verify_thread();
aoqi@0 1589
aoqi@0 1590 const Register Rscratch1 = R11_scratch1,
aoqi@0 1591 Rscratch2 = R12_scratch2,
aoqi@0 1592 Rscratch3 = R3_ARG1,
aoqi@0 1593 R4_counters = R4_ARG2,
aoqi@0 1594 bumped_count = R31,
aoqi@0 1595 Rdisp = R22_tmp2;
aoqi@0 1596
aoqi@0 1597 __ profile_taken_branch(Rscratch1, bumped_count);
aoqi@0 1598
aoqi@0 1599 // Get (wide) offset.
aoqi@0 1600 if (is_wide) {
aoqi@0 1601 __ get_4_byte_integer_at_bcp(1, Rdisp, InterpreterMacroAssembler::Signed);
aoqi@0 1602 } else {
aoqi@0 1603 __ get_2_byte_integer_at_bcp(1, Rdisp, InterpreterMacroAssembler::Signed);
aoqi@0 1604 }
aoqi@0 1605
aoqi@0 1606 // --------------------------------------------------------------------------
aoqi@0 1607 // Handle all the JSR stuff here, then exit.
aoqi@0 1608 // It's much shorter and cleaner than intermingling with the
aoqi@0 1609 // non-JSR normal-branch stuff occurring below.
aoqi@0 1610 if (is_jsr) {
aoqi@0 1611 // Compute return address as bci in Otos_i.
aoqi@0 1612 __ ld(Rscratch1, in_bytes(Method::const_offset()), R19_method);
aoqi@0 1613 __ addi(Rscratch2, R14_bcp, -in_bytes(ConstMethod::codes_offset()) + (is_wide ? 5 : 3));
aoqi@0 1614 __ subf(R17_tos, Rscratch1, Rscratch2);
aoqi@0 1615
aoqi@0 1616 // Bump bcp to target of JSR.
aoqi@0 1617 __ add(R14_bcp, Rdisp, R14_bcp);
aoqi@0 1618 // Push returnAddress for "ret" on stack.
aoqi@0 1619 __ push_ptr(R17_tos);
aoqi@0 1620 // And away we go!
aoqi@0 1621 __ dispatch_next(vtos);
aoqi@0 1622 return;
aoqi@0 1623 }
aoqi@0 1624
aoqi@0 1625 // --------------------------------------------------------------------------
aoqi@0 1626 // Normal (non-jsr) branch handling
aoqi@0 1627
aoqi@0 1628 const bool increment_invocation_counter_for_backward_branches = UseCompiler && UseLoopCounter;
aoqi@0 1629 if (increment_invocation_counter_for_backward_branches) {
aoqi@0 1630 //__ unimplemented("branch invocation counter");
aoqi@0 1631
aoqi@0 1632 Label Lforward;
aoqi@0 1633 __ add(R14_bcp, Rdisp, R14_bcp); // Add to bc addr.
aoqi@0 1634
aoqi@0 1635 // Check branch direction.
aoqi@0 1636 __ cmpdi(CCR0, Rdisp, 0);
aoqi@0 1637 __ bgt(CCR0, Lforward);
aoqi@0 1638
aoqi@0 1639 __ get_method_counters(R19_method, R4_counters, Lforward);
aoqi@0 1640
aoqi@0 1641 if (TieredCompilation) {
aoqi@0 1642 Label Lno_mdo, Loverflow;
aoqi@0 1643 const int increment = InvocationCounter::count_increment;
aoqi@0 1644 const int mask = ((1 << Tier0BackedgeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
aoqi@0 1645 if (ProfileInterpreter) {
aoqi@0 1646 Register Rmdo = Rscratch1;
aoqi@0 1647
aoqi@0 1648 // If no method data exists, go to profile_continue.
aoqi@0 1649 __ ld(Rmdo, in_bytes(Method::method_data_offset()), R19_method);
aoqi@0 1650 __ cmpdi(CCR0, Rmdo, 0);
aoqi@0 1651 __ beq(CCR0, Lno_mdo);
aoqi@0 1652
aoqi@0 1653 // Increment backedge counter in the MDO.
aoqi@0 1654 const int mdo_bc_offs = in_bytes(MethodData::backedge_counter_offset()) + in_bytes(InvocationCounter::counter_offset());
aoqi@0 1655 __ lwz(Rscratch2, mdo_bc_offs, Rmdo);
aoqi@0 1656 __ load_const_optimized(Rscratch3, mask, R0);
aoqi@0 1657 __ addi(Rscratch2, Rscratch2, increment);
aoqi@0 1658 __ stw(Rscratch2, mdo_bc_offs, Rmdo);
aoqi@0 1659 __ and_(Rscratch3, Rscratch2, Rscratch3);
aoqi@0 1660 __ bne(CCR0, Lforward);
aoqi@0 1661 __ b(Loverflow);
aoqi@0 1662 }
aoqi@0 1663
aoqi@0 1664 // If there's no MDO, increment counter in method.
aoqi@0 1665 const int mo_bc_offs = in_bytes(MethodCounters::backedge_counter_offset()) + in_bytes(InvocationCounter::counter_offset());
aoqi@0 1666 __ bind(Lno_mdo);
aoqi@0 1667 __ lwz(Rscratch2, mo_bc_offs, R4_counters);
aoqi@0 1668 __ load_const_optimized(Rscratch3, mask, R0);
aoqi@0 1669 __ addi(Rscratch2, Rscratch2, increment);
aoqi@0 1670 __ stw(Rscratch2, mo_bc_offs, R19_method);
aoqi@0 1671 __ and_(Rscratch3, Rscratch2, Rscratch3);
aoqi@0 1672 __ bne(CCR0, Lforward);
aoqi@0 1673
aoqi@0 1674 __ bind(Loverflow);
aoqi@0 1675
aoqi@0 1676 // Notify point for loop, pass branch bytecode.
aoqi@0 1677 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), R14_bcp, true);
aoqi@0 1678
aoqi@0 1679 // Was an OSR adapter generated?
aoqi@0 1680 // O0 = osr nmethod
aoqi@0 1681 __ cmpdi(CCR0, R3_RET, 0);
aoqi@0 1682 __ beq(CCR0, Lforward);
aoqi@0 1683
aoqi@0 1684 // Has the nmethod been invalidated already?
aoqi@0 1685 __ lwz(R0, nmethod::entry_bci_offset(), R3_RET);
aoqi@0 1686 __ cmpwi(CCR0, R0, InvalidOSREntryBci);
aoqi@0 1687 __ beq(CCR0, Lforward);
aoqi@0 1688
aoqi@0 1689 // Migrate the interpreter frame off of the stack.
aoqi@0 1690 // We can use all registers because we will not return to interpreter from this point.
aoqi@0 1691
aoqi@0 1692 // Save nmethod.
aoqi@0 1693 const Register osr_nmethod = R31;
aoqi@0 1694 __ mr(osr_nmethod, R3_RET);
aoqi@0 1695 __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R11_scratch1);
aoqi@0 1696 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), R16_thread);
aoqi@0 1697 __ reset_last_Java_frame();
aoqi@0 1698 // OSR buffer is in ARG1.
aoqi@0 1699
aoqi@0 1700 // Remove the interpreter frame.
aoqi@0 1701 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
aoqi@0 1702
aoqi@0 1703 // Jump to the osr code.
aoqi@0 1704 __ ld(R11_scratch1, nmethod::osr_entry_point_offset(), osr_nmethod);
aoqi@0 1705 __ mtlr(R0);
aoqi@0 1706 __ mtctr(R11_scratch1);
aoqi@0 1707 __ bctr();
aoqi@0 1708
aoqi@0 1709 } else {
aoqi@0 1710
aoqi@0 1711 const Register invoke_ctr = Rscratch1;
aoqi@0 1712 // Update Backedge branch separately from invocations.
aoqi@0 1713 __ increment_backedge_counter(R4_counters, invoke_ctr, Rscratch2, Rscratch3);
aoqi@0 1714
aoqi@0 1715 if (ProfileInterpreter) {
aoqi@0 1716 __ test_invocation_counter_for_mdp(invoke_ctr, Rscratch2, Lforward);
aoqi@0 1717 if (UseOnStackReplacement) {
aoqi@0 1718 __ test_backedge_count_for_osr(bumped_count, R14_bcp, Rscratch2);
aoqi@0 1719 }
aoqi@0 1720 } else {
aoqi@0 1721 if (UseOnStackReplacement) {
aoqi@0 1722 __ test_backedge_count_for_osr(invoke_ctr, R14_bcp, Rscratch2);
aoqi@0 1723 }
aoqi@0 1724 }
aoqi@0 1725 }
aoqi@0 1726
aoqi@0 1727 __ bind(Lforward);
aoqi@0 1728
aoqi@0 1729 } else {
aoqi@0 1730 // Bump bytecode pointer by displacement (take the branch).
aoqi@0 1731 __ add(R14_bcp, Rdisp, R14_bcp); // Add to bc addr.
aoqi@0 1732 }
aoqi@0 1733 // Continue with bytecode @ target.
aoqi@0 1734 // %%%%% Like Intel, could speed things up by moving bytecode fetch to code above,
aoqi@0 1735 // %%%%% and changing dispatch_next to dispatch_only.
aoqi@0 1736 __ dispatch_next(vtos);
aoqi@0 1737 }
aoqi@0 1738
aoqi@0 1739 // Helper function for if_cmp* methods below.
aoqi@0 1740 // Factored out common compare and branch code.
aoqi@0 1741 void TemplateTable::if_cmp_common(Register Rfirst, Register Rsecond, Register Rscratch1, Register Rscratch2, Condition cc, bool is_jint, bool cmp0) {
aoqi@0 1742 Label Lnot_taken;
aoqi@0 1743 // Note: The condition code we get is the condition under which we
aoqi@0 1744 // *fall through*! So we have to inverse the CC here.
aoqi@0 1745
aoqi@0 1746 if (is_jint) {
aoqi@0 1747 if (cmp0) {
aoqi@0 1748 __ cmpwi(CCR0, Rfirst, 0);
aoqi@0 1749 } else {
aoqi@0 1750 __ cmpw(CCR0, Rfirst, Rsecond);
aoqi@0 1751 }
aoqi@0 1752 } else {
aoqi@0 1753 if (cmp0) {
aoqi@0 1754 __ cmpdi(CCR0, Rfirst, 0);
aoqi@0 1755 } else {
aoqi@0 1756 __ cmpd(CCR0, Rfirst, Rsecond);
aoqi@0 1757 }
aoqi@0 1758 }
aoqi@0 1759 branch_conditional(CCR0, cc, Lnot_taken, /*invert*/ true);
aoqi@0 1760
aoqi@0 1761 // Conition is false => Jump!
aoqi@0 1762 branch(false, false);
aoqi@0 1763
aoqi@0 1764 // Condition is not true => Continue.
aoqi@0 1765 __ align(32, 12);
aoqi@0 1766 __ bind(Lnot_taken);
aoqi@0 1767 __ profile_not_taken_branch(Rscratch1, Rscratch2);
aoqi@0 1768 }
aoqi@0 1769
aoqi@0 1770 // Compare integer values with zero and fall through if CC holds, branch away otherwise.
aoqi@0 1771 void TemplateTable::if_0cmp(Condition cc) {
aoqi@0 1772 transition(itos, vtos);
aoqi@0 1773
aoqi@0 1774 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, true, true);
aoqi@0 1775 }
aoqi@0 1776
aoqi@0 1777 // Compare integer values and fall through if CC holds, branch away otherwise.
aoqi@0 1778 //
aoqi@0 1779 // Interface:
aoqi@0 1780 // - Rfirst: First operand (older stack value)
aoqi@0 1781 // - tos: Second operand (younger stack value)
aoqi@0 1782 void TemplateTable::if_icmp(Condition cc) {
aoqi@0 1783 transition(itos, vtos);
aoqi@0 1784
aoqi@0 1785 const Register Rfirst = R0,
aoqi@0 1786 Rsecond = R17_tos;
aoqi@0 1787
aoqi@0 1788 __ pop_i(Rfirst);
aoqi@0 1789 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, true, false);
aoqi@0 1790 }
aoqi@0 1791
aoqi@0 1792 void TemplateTable::if_nullcmp(Condition cc) {
aoqi@0 1793 transition(atos, vtos);
aoqi@0 1794
aoqi@0 1795 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, false, true);
aoqi@0 1796 }
aoqi@0 1797
aoqi@0 1798 void TemplateTable::if_acmp(Condition cc) {
aoqi@0 1799 transition(atos, vtos);
aoqi@0 1800
aoqi@0 1801 const Register Rfirst = R0,
aoqi@0 1802 Rsecond = R17_tos;
aoqi@0 1803
aoqi@0 1804 __ pop_ptr(Rfirst);
aoqi@0 1805 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, false, false);
aoqi@0 1806 }
aoqi@0 1807
aoqi@0 1808 void TemplateTable::ret() {
aoqi@0 1809 locals_index(R11_scratch1);
aoqi@0 1810 __ load_local_ptr(R17_tos, R11_scratch1, R11_scratch1);
aoqi@0 1811
aoqi@0 1812 __ profile_ret(vtos, R17_tos, R11_scratch1, R12_scratch2);
aoqi@0 1813
aoqi@0 1814 __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
aoqi@0 1815 __ add(R11_scratch1, R17_tos, R11_scratch1);
aoqi@0 1816 __ addi(R14_bcp, R11_scratch1, in_bytes(ConstMethod::codes_offset()));
aoqi@0 1817 __ dispatch_next(vtos);
aoqi@0 1818 }
aoqi@0 1819
aoqi@0 1820 void TemplateTable::wide_ret() {
aoqi@0 1821 transition(vtos, vtos);
aoqi@0 1822
aoqi@0 1823 const Register Rindex = R3_ARG1,
aoqi@0 1824 Rscratch1 = R11_scratch1,
aoqi@0 1825 Rscratch2 = R12_scratch2;
aoqi@0 1826
aoqi@0 1827 locals_index_wide(Rindex);
aoqi@0 1828 __ load_local_ptr(R17_tos, R17_tos, Rindex);
aoqi@0 1829 __ profile_ret(vtos, R17_tos, Rscratch1, R12_scratch2);
aoqi@0 1830 // Tos now contains the bci, compute the bcp from that.
aoqi@0 1831 __ ld(Rscratch1, in_bytes(Method::const_offset()), R19_method);
aoqi@0 1832 __ addi(Rscratch2, R17_tos, in_bytes(ConstMethod::codes_offset()));
aoqi@0 1833 __ add(R14_bcp, Rscratch1, Rscratch2);
aoqi@0 1834 __ dispatch_next(vtos);
aoqi@0 1835 }
aoqi@0 1836
aoqi@0 1837 void TemplateTable::tableswitch() {
aoqi@0 1838 transition(itos, vtos);
aoqi@0 1839
aoqi@0 1840 Label Ldispatch, Ldefault_case;
aoqi@0 1841 Register Rlow_byte = R3_ARG1,
aoqi@0 1842 Rindex = Rlow_byte,
aoqi@0 1843 Rhigh_byte = R4_ARG2,
aoqi@0 1844 Rdef_offset_addr = R5_ARG3, // is going to contain address of default offset
aoqi@0 1845 Rscratch1 = R11_scratch1,
aoqi@0 1846 Rscratch2 = R12_scratch2,
aoqi@0 1847 Roffset = R6_ARG4;
aoqi@0 1848
aoqi@0 1849 // Align bcp.
aoqi@0 1850 __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt);
aoqi@0 1851 __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt));
aoqi@0 1852
aoqi@0 1853 // Load lo & hi.
kvn@7132 1854 __ get_u4(Rlow_byte, Rdef_offset_addr, BytesPerInt, InterpreterMacroAssembler::Unsigned);
kvn@7132 1855 __ get_u4(Rhigh_byte, Rdef_offset_addr, 2 *BytesPerInt, InterpreterMacroAssembler::Unsigned);
aoqi@0 1856
aoqi@0 1857 // Check for default case (=index outside [low,high]).
aoqi@0 1858 __ cmpw(CCR0, R17_tos, Rlow_byte);
aoqi@0 1859 __ cmpw(CCR1, R17_tos, Rhigh_byte);
aoqi@0 1860 __ blt(CCR0, Ldefault_case);
aoqi@0 1861 __ bgt(CCR1, Ldefault_case);
aoqi@0 1862
aoqi@0 1863 // Lookup dispatch offset.
aoqi@0 1864 __ sub(Rindex, R17_tos, Rlow_byte);
aoqi@0 1865 __ extsw(Rindex, Rindex);
aoqi@0 1866 __ profile_switch_case(Rindex, Rhigh_byte /* scratch */, Rscratch1, Rscratch2);
aoqi@0 1867 __ sldi(Rindex, Rindex, LogBytesPerInt);
aoqi@0 1868 __ addi(Rindex, Rindex, 3 * BytesPerInt);
kvn@7132 1869 #if defined(VM_LITTLE_ENDIAN)
kvn@7132 1870 __ lwbrx(Roffset, Rdef_offset_addr, Rindex);
kvn@7132 1871 __ extsw(Roffset, Roffset);
kvn@7132 1872 #else
aoqi@0 1873 __ lwax(Roffset, Rdef_offset_addr, Rindex);
kvn@7132 1874 #endif
aoqi@0 1875 __ b(Ldispatch);
aoqi@0 1876
aoqi@0 1877 __ bind(Ldefault_case);
aoqi@0 1878 __ profile_switch_default(Rhigh_byte, Rscratch1);
kvn@7132 1879 __ get_u4(Roffset, Rdef_offset_addr, 0, InterpreterMacroAssembler::Signed);
aoqi@0 1880
aoqi@0 1881 __ bind(Ldispatch);
aoqi@0 1882
aoqi@0 1883 __ add(R14_bcp, Roffset, R14_bcp);
aoqi@0 1884 __ dispatch_next(vtos);
aoqi@0 1885 }
aoqi@0 1886
aoqi@0 1887 void TemplateTable::lookupswitch() {
aoqi@0 1888 transition(itos, itos);
aoqi@0 1889 __ stop("lookupswitch bytecode should have been rewritten");
aoqi@0 1890 }
aoqi@0 1891
aoqi@0 1892 // Table switch using linear search through cases.
aoqi@0 1893 // Bytecode stream format:
aoqi@0 1894 // Bytecode (1) | 4-byte padding | default offset (4) | count (4) | value/offset pair1 (8) | value/offset pair2 (8) | ...
kvn@7132 1895 // Note: Everything is big-endian format here.
aoqi@0 1896 void TemplateTable::fast_linearswitch() {
aoqi@0 1897 transition(itos, vtos);
aoqi@0 1898
kvn@7132 1899 Label Lloop_entry, Lsearch_loop, Lcontinue_execution, Ldefault_case;
aoqi@0 1900 Register Rcount = R3_ARG1,
aoqi@0 1901 Rcurrent_pair = R4_ARG2,
aoqi@0 1902 Rdef_offset_addr = R5_ARG3, // Is going to contain address of default offset.
aoqi@0 1903 Roffset = R31, // Might need to survive C call.
aoqi@0 1904 Rvalue = R12_scratch2,
aoqi@0 1905 Rscratch = R11_scratch1,
aoqi@0 1906 Rcmp_value = R17_tos;
aoqi@0 1907
aoqi@0 1908 // Align bcp.
aoqi@0 1909 __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt);
aoqi@0 1910 __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt));
aoqi@0 1911
aoqi@0 1912 // Setup loop counter and limit.
kvn@7132 1913 __ get_u4(Rcount, Rdef_offset_addr, BytesPerInt, InterpreterMacroAssembler::Unsigned);
aoqi@0 1914 __ addi(Rcurrent_pair, Rdef_offset_addr, 2 * BytesPerInt); // Rcurrent_pair now points to first pair.
aoqi@0 1915
kvn@7132 1916 __ mtctr(Rcount);
aoqi@0 1917 __ cmpwi(CCR0, Rcount, 0);
kvn@7132 1918 __ bne(CCR0, Lloop_entry);
kvn@7132 1919
kvn@7132 1920 // Default case
aoqi@0 1921 __ bind(Ldefault_case);
kvn@7132 1922 __ get_u4(Roffset, Rdef_offset_addr, 0, InterpreterMacroAssembler::Signed);
aoqi@0 1923 if (ProfileInterpreter) {
aoqi@0 1924 __ profile_switch_default(Rdef_offset_addr, Rcount/* scratch */);
aoqi@0 1925 }
kvn@7132 1926 __ b(Lcontinue_execution);
kvn@7132 1927
kvn@7132 1928 // Next iteration
kvn@7132 1929 __ bind(Lsearch_loop);
kvn@7132 1930 __ bdz(Ldefault_case);
kvn@7132 1931 __ addi(Rcurrent_pair, Rcurrent_pair, 2 * BytesPerInt);
kvn@7132 1932 __ bind(Lloop_entry);
kvn@7132 1933 __ get_u4(Rvalue, Rcurrent_pair, 0, InterpreterMacroAssembler::Unsigned);
kvn@7132 1934 __ cmpw(CCR0, Rvalue, Rcmp_value);
kvn@7132 1935 __ bne(CCR0, Lsearch_loop);
kvn@7132 1936
kvn@7132 1937 // Found, load offset.
kvn@7132 1938 __ get_u4(Roffset, Rcurrent_pair, BytesPerInt, InterpreterMacroAssembler::Signed);
kvn@7132 1939 // Calculate case index and profile
kvn@7132 1940 __ mfctr(Rcurrent_pair);
aoqi@0 1941 if (ProfileInterpreter) {
kvn@7132 1942 __ sub(Rcurrent_pair, Rcount, Rcurrent_pair);
aoqi@0 1943 __ profile_switch_case(Rcurrent_pair, Rcount /*scratch*/, Rdef_offset_addr/*scratch*/, Rscratch);
aoqi@0 1944 }
kvn@7132 1945
kvn@7132 1946 __ bind(Lcontinue_execution);
aoqi@0 1947 __ add(R14_bcp, Roffset, R14_bcp);
aoqi@0 1948 __ dispatch_next(vtos);
aoqi@0 1949 }
aoqi@0 1950
aoqi@0 1951 // Table switch using binary search (value/offset pairs are ordered).
aoqi@0 1952 // Bytecode stream format:
aoqi@0 1953 // Bytecode (1) | 4-byte padding | default offset (4) | count (4) | value/offset pair1 (8) | value/offset pair2 (8) | ...
aoqi@0 1954 // Note: Everything is big-endian format here. So on little endian machines, we have to revers offset and count and cmp value.
aoqi@0 1955 void TemplateTable::fast_binaryswitch() {
aoqi@0 1956
aoqi@0 1957 transition(itos, vtos);
aoqi@0 1958 // Implementation using the following core algorithm: (copied from Intel)
aoqi@0 1959 //
aoqi@0 1960 // int binary_search(int key, LookupswitchPair* array, int n) {
aoqi@0 1961 // // Binary search according to "Methodik des Programmierens" by
aoqi@0 1962 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
aoqi@0 1963 // int i = 0;
aoqi@0 1964 // int j = n;
aoqi@0 1965 // while (i+1 < j) {
aoqi@0 1966 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
aoqi@0 1967 // // with Q: for all i: 0 <= i < n: key < a[i]
aoqi@0 1968 // // where a stands for the array and assuming that the (inexisting)
aoqi@0 1969 // // element a[n] is infinitely big.
aoqi@0 1970 // int h = (i + j) >> 1;
aoqi@0 1971 // // i < h < j
aoqi@0 1972 // if (key < array[h].fast_match()) {
aoqi@0 1973 // j = h;
aoqi@0 1974 // } else {
aoqi@0 1975 // i = h;
aoqi@0 1976 // }
aoqi@0 1977 // }
aoqi@0 1978 // // R: a[i] <= key < a[i+1] or Q
aoqi@0 1979 // // (i.e., if key is within array, i is the correct index)
aoqi@0 1980 // return i;
aoqi@0 1981 // }
aoqi@0 1982
aoqi@0 1983 // register allocation
aoqi@0 1984 const Register Rkey = R17_tos; // already set (tosca)
aoqi@0 1985 const Register Rarray = R3_ARG1;
aoqi@0 1986 const Register Ri = R4_ARG2;
aoqi@0 1987 const Register Rj = R5_ARG3;
aoqi@0 1988 const Register Rh = R6_ARG4;
aoqi@0 1989 const Register Rscratch = R11_scratch1;
aoqi@0 1990
aoqi@0 1991 const int log_entry_size = 3;
aoqi@0 1992 const int entry_size = 1 << log_entry_size;
aoqi@0 1993
aoqi@0 1994 Label found;
aoqi@0 1995
aoqi@0 1996 // Find Array start,
aoqi@0 1997 __ addi(Rarray, R14_bcp, 3 * BytesPerInt);
aoqi@0 1998 __ clrrdi(Rarray, Rarray, log2_long((jlong)BytesPerInt));
aoqi@0 1999
aoqi@0 2000 // initialize i & j
aoqi@0 2001 __ li(Ri,0);
kvn@7132 2002 __ get_u4(Rj, Rarray, -BytesPerInt, InterpreterMacroAssembler::Unsigned);
aoqi@0 2003
aoqi@0 2004 // and start.
aoqi@0 2005 Label entry;
aoqi@0 2006 __ b(entry);
aoqi@0 2007
aoqi@0 2008 // binary search loop
aoqi@0 2009 { Label loop;
aoqi@0 2010 __ bind(loop);
aoqi@0 2011 // int h = (i + j) >> 1;
aoqi@0 2012 __ srdi(Rh, Rh, 1);
aoqi@0 2013 // if (key < array[h].fast_match()) {
aoqi@0 2014 // j = h;
aoqi@0 2015 // } else {
aoqi@0 2016 // i = h;
aoqi@0 2017 // }
aoqi@0 2018 __ sldi(Rscratch, Rh, log_entry_size);
kvn@7132 2019 #if defined(VM_LITTLE_ENDIAN)
kvn@7132 2020 __ lwbrx(Rscratch, Rscratch, Rarray);
kvn@7132 2021 #else
aoqi@0 2022 __ lwzx(Rscratch, Rscratch, Rarray);
kvn@7132 2023 #endif
aoqi@0 2024
aoqi@0 2025 // if (key < current value)
aoqi@0 2026 // Rh = Rj
aoqi@0 2027 // else
aoqi@0 2028 // Rh = Ri
aoqi@0 2029 Label Lgreater;
aoqi@0 2030 __ cmpw(CCR0, Rkey, Rscratch);
aoqi@0 2031 __ bge(CCR0, Lgreater);
aoqi@0 2032 __ mr(Rj, Rh);
aoqi@0 2033 __ b(entry);
aoqi@0 2034 __ bind(Lgreater);
aoqi@0 2035 __ mr(Ri, Rh);
aoqi@0 2036
aoqi@0 2037 // while (i+1 < j)
aoqi@0 2038 __ bind(entry);
aoqi@0 2039 __ addi(Rscratch, Ri, 1);
aoqi@0 2040 __ cmpw(CCR0, Rscratch, Rj);
aoqi@0 2041 __ add(Rh, Ri, Rj); // start h = i + j >> 1;
aoqi@0 2042
aoqi@0 2043 __ blt(CCR0, loop);
aoqi@0 2044 }
aoqi@0 2045
aoqi@0 2046 // End of binary search, result index is i (must check again!).
aoqi@0 2047 Label default_case;
aoqi@0 2048 Label continue_execution;
aoqi@0 2049 if (ProfileInterpreter) {
aoqi@0 2050 __ mr(Rh, Ri); // Save index in i for profiling.
aoqi@0 2051 }
aoqi@0 2052 // Ri = value offset
aoqi@0 2053 __ sldi(Ri, Ri, log_entry_size);
aoqi@0 2054 __ add(Ri, Ri, Rarray);
kvn@7132 2055 __ get_u4(Rscratch, Ri, 0, InterpreterMacroAssembler::Unsigned);
aoqi@0 2056
aoqi@0 2057 Label not_found;
aoqi@0 2058 // Ri = offset offset
aoqi@0 2059 __ cmpw(CCR0, Rkey, Rscratch);
aoqi@0 2060 __ beq(CCR0, not_found);
aoqi@0 2061 // entry not found -> j = default offset
kvn@7132 2062 __ get_u4(Rj, Rarray, -2 * BytesPerInt, InterpreterMacroAssembler::Unsigned);
aoqi@0 2063 __ b(default_case);
aoqi@0 2064
aoqi@0 2065 __ bind(not_found);
aoqi@0 2066 // entry found -> j = offset
aoqi@0 2067 __ profile_switch_case(Rh, Rj, Rscratch, Rkey);
kvn@7132 2068 __ get_u4(Rj, Ri, BytesPerInt, InterpreterMacroAssembler::Unsigned);
aoqi@0 2069
aoqi@0 2070 if (ProfileInterpreter) {
aoqi@0 2071 __ b(continue_execution);
aoqi@0 2072 }
aoqi@0 2073
aoqi@0 2074 __ bind(default_case); // fall through (if not profiling)
aoqi@0 2075 __ profile_switch_default(Ri, Rscratch);
aoqi@0 2076
aoqi@0 2077 __ bind(continue_execution);
aoqi@0 2078
aoqi@0 2079 __ extsw(Rj, Rj);
aoqi@0 2080 __ add(R14_bcp, Rj, R14_bcp);
aoqi@0 2081 __ dispatch_next(vtos);
aoqi@0 2082 }
aoqi@0 2083
aoqi@0 2084 void TemplateTable::_return(TosState state) {
aoqi@0 2085 transition(state, state);
aoqi@0 2086 assert(_desc->calls_vm(),
aoqi@0 2087 "inconsistent calls_vm information"); // call in remove_activation
aoqi@0 2088
aoqi@0 2089 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
aoqi@0 2090
aoqi@0 2091 Register Rscratch = R11_scratch1,
aoqi@0 2092 Rklass = R12_scratch2,
aoqi@0 2093 Rklass_flags = Rklass;
aoqi@0 2094 Label Lskip_register_finalizer;
aoqi@0 2095
aoqi@0 2096 // Check if the method has the FINALIZER flag set and call into the VM to finalize in this case.
aoqi@0 2097 assert(state == vtos, "only valid state");
aoqi@0 2098 __ ld(R17_tos, 0, R18_locals);
aoqi@0 2099
aoqi@0 2100 // Load klass of this obj.
aoqi@0 2101 __ load_klass(Rklass, R17_tos);
aoqi@0 2102 __ lwz(Rklass_flags, in_bytes(Klass::access_flags_offset()), Rklass);
aoqi@0 2103 __ testbitdi(CCR0, R0, Rklass_flags, exact_log2(JVM_ACC_HAS_FINALIZER));
aoqi@0 2104 __ bfalse(CCR0, Lskip_register_finalizer);
aoqi@0 2105
aoqi@0 2106 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), R17_tos /* obj */);
aoqi@0 2107
aoqi@0 2108 __ align(32, 12);
aoqi@0 2109 __ bind(Lskip_register_finalizer);
aoqi@0 2110 }
aoqi@0 2111
aoqi@0 2112 // Move the result value into the correct register and remove memory stack frame.
aoqi@0 2113 __ remove_activation(state, /* throw_monitor_exception */ true);
aoqi@0 2114 // Restoration of lr done by remove_activation.
aoqi@0 2115 switch (state) {
simonis@8381 2116 // Narrow result if state is itos but result type is smaller.
simonis@8381 2117 // Need to narrow in the return bytecode rather than in generate_return_entry
simonis@8381 2118 // since compiled code callers expect the result to already be narrowed.
simonis@8381 2119 case itos: __ narrow(R17_tos); /* fall through */
aoqi@0 2120 case ltos:
aoqi@0 2121 case btos:
simonis@8381 2122 case ztos:
aoqi@0 2123 case ctos:
aoqi@0 2124 case stos:
simonis@8381 2125 case atos: __ mr(R3_RET, R17_tos); break;
aoqi@0 2126 case ftos:
aoqi@0 2127 case dtos: __ fmr(F1_RET, F15_ftos); break;
aoqi@0 2128 case vtos: // This might be a constructor. Final fields (and volatile fields on PPC64) need
aoqi@0 2129 // to get visible before the reference to the object gets stored anywhere.
aoqi@0 2130 __ membar(Assembler::StoreStore); break;
aoqi@0 2131 default : ShouldNotReachHere();
aoqi@0 2132 }
aoqi@0 2133 __ blr();
aoqi@0 2134 }
aoqi@0 2135
aoqi@0 2136 // ============================================================================
aoqi@0 2137 // Constant pool cache access
aoqi@0 2138 //
aoqi@0 2139 // Memory ordering:
aoqi@0 2140 //
aoqi@0 2141 // Like done in C++ interpreter, we load the fields
aoqi@0 2142 // - _indices
aoqi@0 2143 // - _f12_oop
aoqi@0 2144 // acquired, because these are asked if the cache is already resolved. We don't
aoqi@0 2145 // want to float loads above this check.
aoqi@0 2146 // See also comments in ConstantPoolCacheEntry::bytecode_1(),
aoqi@0 2147 // ConstantPoolCacheEntry::bytecode_2() and ConstantPoolCacheEntry::f1();
aoqi@0 2148
aoqi@0 2149 // Call into the VM if call site is not yet resolved
aoqi@0 2150 //
aoqi@0 2151 // Input regs:
aoqi@0 2152 // - None, all passed regs are outputs.
aoqi@0 2153 //
aoqi@0 2154 // Returns:
aoqi@0 2155 // - Rcache: The const pool cache entry that contains the resolved result.
aoqi@0 2156 // - Rresult: Either noreg or output for f1/f2.
aoqi@0 2157 //
aoqi@0 2158 // Kills:
aoqi@0 2159 // - Rscratch
aoqi@0 2160 void TemplateTable::resolve_cache_and_index(int byte_no, Register Rcache, Register Rscratch, size_t index_size) {
aoqi@0 2161
aoqi@0 2162 __ get_cache_and_index_at_bcp(Rcache, 1, index_size);
aoqi@0 2163 Label Lresolved, Ldone;
aoqi@0 2164
aoqi@0 2165 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
aoqi@0 2166 // We are resolved if the indices offset contains the current bytecode.
kvn@7132 2167 #if defined(VM_LITTLE_ENDIAN)
kvn@7132 2168 __ lbz(Rscratch, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + byte_no + 1, Rcache);
kvn@7132 2169 #else
aoqi@0 2170 __ lbz(Rscratch, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (byte_no + 1), Rcache);
kvn@7132 2171 #endif
aoqi@0 2172 // Acquire by cmp-br-isync (see below).
aoqi@0 2173 __ cmpdi(CCR0, Rscratch, (int)bytecode());
aoqi@0 2174 __ beq(CCR0, Lresolved);
aoqi@0 2175
aoqi@0 2176 address entry = NULL;
aoqi@0 2177 switch (bytecode()) {
aoqi@0 2178 case Bytecodes::_getstatic : // fall through
aoqi@0 2179 case Bytecodes::_putstatic : // fall through
aoqi@0 2180 case Bytecodes::_getfield : // fall through
aoqi@0 2181 case Bytecodes::_putfield : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
aoqi@0 2182 case Bytecodes::_invokevirtual : // fall through
aoqi@0 2183 case Bytecodes::_invokespecial : // fall through
aoqi@0 2184 case Bytecodes::_invokestatic : // fall through
aoqi@0 2185 case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke); break;
aoqi@0 2186 case Bytecodes::_invokehandle : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle); break;
aoqi@0 2187 case Bytecodes::_invokedynamic : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic); break;
aoqi@0 2188 default : ShouldNotReachHere(); break;
aoqi@0 2189 }
aoqi@0 2190 __ li(R4_ARG2, (int)bytecode());
aoqi@0 2191 __ call_VM(noreg, entry, R4_ARG2, true);
aoqi@0 2192
aoqi@0 2193 // Update registers with resolved info.
aoqi@0 2194 __ get_cache_and_index_at_bcp(Rcache, 1, index_size);
aoqi@0 2195 __ b(Ldone);
aoqi@0 2196
aoqi@0 2197 __ bind(Lresolved);
aoqi@0 2198 __ isync(); // Order load wrt. succeeding loads.
aoqi@0 2199 __ bind(Ldone);
aoqi@0 2200 }
aoqi@0 2201
aoqi@0 2202 // Load the constant pool cache entry at field accesses into registers.
aoqi@0 2203 // The Rcache and Rindex registers must be set before call.
aoqi@0 2204 // Input:
aoqi@0 2205 // - Rcache, Rindex
aoqi@0 2206 // Output:
aoqi@0 2207 // - Robj, Roffset, Rflags
aoqi@0 2208 void TemplateTable::load_field_cp_cache_entry(Register Robj,
aoqi@0 2209 Register Rcache,
aoqi@0 2210 Register Rindex /* unused on PPC64 */,
aoqi@0 2211 Register Roffset,
aoqi@0 2212 Register Rflags,
aoqi@0 2213 bool is_static = false) {
aoqi@0 2214 assert_different_registers(Rcache, Rflags, Roffset);
aoqi@0 2215 // assert(Rindex == noreg, "parameter not used on PPC64");
aoqi@0 2216
aoqi@0 2217 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 2218 __ ld(Rflags, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::flags_offset()), Rcache);
aoqi@0 2219 __ ld(Roffset, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::f2_offset()), Rcache);
aoqi@0 2220 if (is_static) {
aoqi@0 2221 __ ld(Robj, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::f1_offset()), Rcache);
aoqi@0 2222 __ ld(Robj, in_bytes(Klass::java_mirror_offset()), Robj);
aoqi@0 2223 // Acquire not needed here. Following access has an address dependency on this value.
aoqi@0 2224 }
aoqi@0 2225 }
aoqi@0 2226
aoqi@0 2227 // Load the constant pool cache entry at invokes into registers.
aoqi@0 2228 // Resolve if necessary.
aoqi@0 2229
aoqi@0 2230 // Input Registers:
aoqi@0 2231 // - None, bcp is used, though
aoqi@0 2232 //
aoqi@0 2233 // Return registers:
aoqi@0 2234 // - Rmethod (f1 field or f2 if invokevirtual)
aoqi@0 2235 // - Ritable_index (f2 field)
aoqi@0 2236 // - Rflags (flags field)
aoqi@0 2237 //
aoqi@0 2238 // Kills:
aoqi@0 2239 // - R21
aoqi@0 2240 //
aoqi@0 2241 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
aoqi@0 2242 Register Rmethod,
aoqi@0 2243 Register Ritable_index,
aoqi@0 2244 Register Rflags,
aoqi@0 2245 bool is_invokevirtual,
aoqi@0 2246 bool is_invokevfinal,
aoqi@0 2247 bool is_invokedynamic) {
aoqi@0 2248
aoqi@0 2249 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 2250 // Determine constant pool cache field offsets.
aoqi@0 2251 assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant");
aoqi@0 2252 const int method_offset = in_bytes(cp_base_offset + (is_invokevirtual ? ConstantPoolCacheEntry::f2_offset() : ConstantPoolCacheEntry::f1_offset()));
aoqi@0 2253 const int flags_offset = in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset());
aoqi@0 2254 // Access constant pool cache fields.
aoqi@0 2255 const int index_offset = in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset());
aoqi@0 2256
aoqi@0 2257 Register Rcache = R21_tmp1; // Note: same register as R21_sender_SP.
aoqi@0 2258
aoqi@0 2259 if (is_invokevfinal) {
aoqi@0 2260 assert(Ritable_index == noreg, "register not used");
aoqi@0 2261 // Already resolved.
aoqi@0 2262 __ get_cache_and_index_at_bcp(Rcache, 1);
aoqi@0 2263 } else {
aoqi@0 2264 resolve_cache_and_index(byte_no, Rcache, R0, is_invokedynamic ? sizeof(u4) : sizeof(u2));
aoqi@0 2265 }
aoqi@0 2266
aoqi@0 2267 __ ld(Rmethod, method_offset, Rcache);
aoqi@0 2268 __ ld(Rflags, flags_offset, Rcache);
aoqi@0 2269
aoqi@0 2270 if (Ritable_index != noreg) {
aoqi@0 2271 __ ld(Ritable_index, index_offset, Rcache);
aoqi@0 2272 }
aoqi@0 2273 }
aoqi@0 2274
aoqi@0 2275 // ============================================================================
aoqi@0 2276 // Field access
aoqi@0 2277
aoqi@0 2278 // Volatile variables demand their effects be made known to all CPU's
aoqi@0 2279 // in order. Store buffers on most chips allow reads & writes to
aoqi@0 2280 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode
aoqi@0 2281 // without some kind of memory barrier (i.e., it's not sufficient that
aoqi@0 2282 // the interpreter does not reorder volatile references, the hardware
aoqi@0 2283 // also must not reorder them).
aoqi@0 2284 //
aoqi@0 2285 // According to the new Java Memory Model (JMM):
aoqi@0 2286 // (1) All volatiles are serialized wrt to each other. ALSO reads &
aoqi@0 2287 // writes act as aquire & release, so:
aoqi@0 2288 // (2) A read cannot let unrelated NON-volatile memory refs that
aoqi@0 2289 // happen after the read float up to before the read. It's OK for
aoqi@0 2290 // non-volatile memory refs that happen before the volatile read to
aoqi@0 2291 // float down below it.
aoqi@0 2292 // (3) Similar a volatile write cannot let unrelated NON-volatile
aoqi@0 2293 // memory refs that happen BEFORE the write float down to after the
aoqi@0 2294 // write. It's OK for non-volatile memory refs that happen after the
aoqi@0 2295 // volatile write to float up before it.
aoqi@0 2296 //
aoqi@0 2297 // We only put in barriers around volatile refs (they are expensive),
aoqi@0 2298 // not _between_ memory refs (that would require us to track the
aoqi@0 2299 // flavor of the previous memory refs). Requirements (2) and (3)
aoqi@0 2300 // require some barriers before volatile stores and after volatile
aoqi@0 2301 // loads. These nearly cover requirement (1) but miss the
aoqi@0 2302 // volatile-store-volatile-load case. This final case is placed after
aoqi@0 2303 // volatile-stores although it could just as well go before
aoqi@0 2304 // volatile-loads.
aoqi@0 2305
aoqi@0 2306 // The registers cache and index expected to be set before call.
aoqi@0 2307 // Correct values of the cache and index registers are preserved.
aoqi@0 2308 // Kills:
aoqi@0 2309 // Rcache (if has_tos)
aoqi@0 2310 // Rscratch
aoqi@0 2311 void TemplateTable::jvmti_post_field_access(Register Rcache, Register Rscratch, bool is_static, bool has_tos) {
aoqi@0 2312
aoqi@0 2313 assert_different_registers(Rcache, Rscratch);
aoqi@0 2314
aoqi@0 2315 if (JvmtiExport::can_post_field_access()) {
aoqi@0 2316 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 2317 Label Lno_field_access_post;
aoqi@0 2318
aoqi@0 2319 // Check if post field access in enabled.
aoqi@0 2320 int offs = __ load_const_optimized(Rscratch, JvmtiExport::get_field_access_count_addr(), R0, true);
aoqi@0 2321 __ lwz(Rscratch, offs, Rscratch);
aoqi@0 2322
aoqi@0 2323 __ cmpwi(CCR0, Rscratch, 0);
aoqi@0 2324 __ beq(CCR0, Lno_field_access_post);
aoqi@0 2325
aoqi@0 2326 // Post access enabled - do it!
aoqi@0 2327 __ addi(Rcache, Rcache, in_bytes(cp_base_offset));
aoqi@0 2328 if (is_static) {
aoqi@0 2329 __ li(R17_tos, 0);
aoqi@0 2330 } else {
aoqi@0 2331 if (has_tos) {
aoqi@0 2332 // The fast bytecode versions have obj ptr in register.
aoqi@0 2333 // Thus, save object pointer before call_VM() clobbers it
aoqi@0 2334 // put object on tos where GC wants it.
aoqi@0 2335 __ push_ptr(R17_tos);
aoqi@0 2336 } else {
aoqi@0 2337 // Load top of stack (do not pop the value off the stack).
aoqi@0 2338 __ ld(R17_tos, Interpreter::expr_offset_in_bytes(0), R15_esp);
aoqi@0 2339 }
aoqi@0 2340 __ verify_oop(R17_tos);
aoqi@0 2341 }
aoqi@0 2342 // tos: object pointer or NULL if static
aoqi@0 2343 // cache: cache entry pointer
aoqi@0 2344 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), R17_tos, Rcache);
aoqi@0 2345 if (!is_static && has_tos) {
aoqi@0 2346 // Restore object pointer.
aoqi@0 2347 __ pop_ptr(R17_tos);
aoqi@0 2348 __ verify_oop(R17_tos);
aoqi@0 2349 } else {
aoqi@0 2350 // Cache is still needed to get class or obj.
aoqi@0 2351 __ get_cache_and_index_at_bcp(Rcache, 1);
aoqi@0 2352 }
aoqi@0 2353
aoqi@0 2354 __ align(32, 12);
aoqi@0 2355 __ bind(Lno_field_access_post);
aoqi@0 2356 }
aoqi@0 2357 }
aoqi@0 2358
aoqi@0 2359 // kills R11_scratch1
aoqi@0 2360 void TemplateTable::pop_and_check_object(Register Roop) {
aoqi@0 2361 Register Rtmp = R11_scratch1;
aoqi@0 2362
aoqi@0 2363 assert_different_registers(Rtmp, Roop);
aoqi@0 2364 __ pop_ptr(Roop);
aoqi@0 2365 // For field access must check obj.
aoqi@0 2366 __ null_check_throw(Roop, -1, Rtmp);
aoqi@0 2367 __ verify_oop(Roop);
aoqi@0 2368 }
aoqi@0 2369
aoqi@0 2370 // PPC64: implement volatile loads as fence-store-acquire.
aoqi@0 2371 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
aoqi@0 2372 transition(vtos, vtos);
aoqi@0 2373
aoqi@0 2374 Label Lacquire, Lisync;
aoqi@0 2375
aoqi@0 2376 const Register Rcache = R3_ARG1,
aoqi@0 2377 Rclass_or_obj = R22_tmp2,
aoqi@0 2378 Roffset = R23_tmp3,
aoqi@0 2379 Rflags = R31,
aoqi@0 2380 Rbtable = R5_ARG3,
aoqi@0 2381 Rbc = R6_ARG4,
aoqi@0 2382 Rscratch = R12_scratch2;
aoqi@0 2383
aoqi@0 2384 static address field_branch_table[number_of_states],
aoqi@0 2385 static_branch_table[number_of_states];
aoqi@0 2386
aoqi@0 2387 address* branch_table = is_static ? static_branch_table : field_branch_table;
aoqi@0 2388
aoqi@0 2389 // Get field offset.
aoqi@0 2390 resolve_cache_and_index(byte_no, Rcache, Rscratch, sizeof(u2));
aoqi@0 2391
aoqi@0 2392 // JVMTI support
aoqi@0 2393 jvmti_post_field_access(Rcache, Rscratch, is_static, false);
aoqi@0 2394
aoqi@0 2395 // Load after possible GC.
aoqi@0 2396 load_field_cp_cache_entry(Rclass_or_obj, Rcache, noreg, Roffset, Rflags, is_static);
aoqi@0 2397
aoqi@0 2398 // Load pointer to branch table.
aoqi@0 2399 __ load_const_optimized(Rbtable, (address)branch_table, Rscratch);
aoqi@0 2400
aoqi@0 2401 // Get volatile flag.
aoqi@0 2402 __ rldicl(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit.
aoqi@0 2403 // Note: sync is needed before volatile load on PPC64.
aoqi@0 2404
aoqi@0 2405 // Check field type.
aoqi@0 2406 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
aoqi@0 2407
aoqi@0 2408 #ifdef ASSERT
aoqi@0 2409 Label LFlagInvalid;
aoqi@0 2410 __ cmpldi(CCR0, Rflags, number_of_states);
aoqi@0 2411 __ bge(CCR0, LFlagInvalid);
aoqi@0 2412 #endif
aoqi@0 2413
aoqi@0 2414 // Load from branch table and dispatch (volatile case: one instruction ahead).
aoqi@0 2415 __ sldi(Rflags, Rflags, LogBytesPerWord);
aoqi@0 2416 __ cmpwi(CCR6, Rscratch, 1); // Volatile?
aoqi@0 2417 if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2418 __ sldi(Rscratch, Rscratch, exact_log2(BytesPerInstWord)); // Volatile ? size of 1 instruction : 0.
aoqi@0 2419 }
aoqi@0 2420 __ ldx(Rbtable, Rbtable, Rflags);
aoqi@0 2421
aoqi@0 2422 // Get the obj from stack.
aoqi@0 2423 if (!is_static) {
aoqi@0 2424 pop_and_check_object(Rclass_or_obj); // Kills R11_scratch1.
aoqi@0 2425 } else {
aoqi@0 2426 __ verify_oop(Rclass_or_obj);
aoqi@0 2427 }
aoqi@0 2428
aoqi@0 2429 if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2430 __ subf(Rbtable, Rscratch, Rbtable); // Point to volatile/non-volatile entry point.
aoqi@0 2431 }
aoqi@0 2432 __ mtctr(Rbtable);
aoqi@0 2433 __ bctr();
aoqi@0 2434
aoqi@0 2435 #ifdef ASSERT
aoqi@0 2436 __ bind(LFlagInvalid);
aoqi@0 2437 __ stop("got invalid flag", 0x654);
aoqi@0 2438
aoqi@0 2439 // __ bind(Lvtos);
aoqi@0 2440 address pc_before_fence = __ pc();
aoqi@0 2441 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2442 assert(__ pc() - pc_before_fence == (ptrdiff_t)BytesPerInstWord, "must be single instruction");
aoqi@0 2443 assert(branch_table[vtos] == 0, "can't compute twice");
aoqi@0 2444 branch_table[vtos] = __ pc(); // non-volatile_entry point
aoqi@0 2445 __ stop("vtos unexpected", 0x655);
aoqi@0 2446 #endif
aoqi@0 2447
aoqi@0 2448 __ align(32, 28, 28); // Align load.
aoqi@0 2449 // __ bind(Ldtos);
aoqi@0 2450 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2451 assert(branch_table[dtos] == 0, "can't compute twice");
aoqi@0 2452 branch_table[dtos] = __ pc(); // non-volatile_entry point
aoqi@0 2453 __ lfdx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 2454 __ push(dtos);
aoqi@0 2455 if (!is_static) patch_bytecode(Bytecodes::_fast_dgetfield, Rbc, Rscratch);
aoqi@0 2456 {
aoqi@0 2457 Label acquire_double;
aoqi@0 2458 __ beq(CCR6, acquire_double); // Volatile?
aoqi@0 2459 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2460
aoqi@0 2461 __ bind(acquire_double);
aoqi@0 2462 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync.
aoqi@0 2463 __ beq_predict_taken(CCR0, Lisync);
aoqi@0 2464 __ b(Lisync); // In case of NAN.
aoqi@0 2465 }
aoqi@0 2466
aoqi@0 2467 __ align(32, 28, 28); // Align load.
aoqi@0 2468 // __ bind(Lftos);
aoqi@0 2469 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2470 assert(branch_table[ftos] == 0, "can't compute twice");
aoqi@0 2471 branch_table[ftos] = __ pc(); // non-volatile_entry point
aoqi@0 2472 __ lfsx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 2473 __ push(ftos);
aoqi@0 2474 if (!is_static) { patch_bytecode(Bytecodes::_fast_fgetfield, Rbc, Rscratch); }
aoqi@0 2475 {
aoqi@0 2476 Label acquire_float;
aoqi@0 2477 __ beq(CCR6, acquire_float); // Volatile?
aoqi@0 2478 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2479
aoqi@0 2480 __ bind(acquire_float);
aoqi@0 2481 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync.
aoqi@0 2482 __ beq_predict_taken(CCR0, Lisync);
aoqi@0 2483 __ b(Lisync); // In case of NAN.
aoqi@0 2484 }
aoqi@0 2485
aoqi@0 2486 __ align(32, 28, 28); // Align load.
aoqi@0 2487 // __ bind(Litos);
aoqi@0 2488 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2489 assert(branch_table[itos] == 0, "can't compute twice");
aoqi@0 2490 branch_table[itos] = __ pc(); // non-volatile_entry point
aoqi@0 2491 __ lwax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2492 __ push(itos);
aoqi@0 2493 if (!is_static) patch_bytecode(Bytecodes::_fast_igetfield, Rbc, Rscratch);
aoqi@0 2494 __ beq(CCR6, Lacquire); // Volatile?
aoqi@0 2495 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2496
aoqi@0 2497 __ align(32, 28, 28); // Align load.
aoqi@0 2498 // __ bind(Lltos);
aoqi@0 2499 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2500 assert(branch_table[ltos] == 0, "can't compute twice");
aoqi@0 2501 branch_table[ltos] = __ pc(); // non-volatile_entry point
aoqi@0 2502 __ ldx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2503 __ push(ltos);
aoqi@0 2504 if (!is_static) patch_bytecode(Bytecodes::_fast_lgetfield, Rbc, Rscratch);
aoqi@0 2505 __ beq(CCR6, Lacquire); // Volatile?
aoqi@0 2506 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2507
aoqi@0 2508 __ align(32, 28, 28); // Align load.
aoqi@0 2509 // __ bind(Lbtos);
aoqi@0 2510 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2511 assert(branch_table[btos] == 0, "can't compute twice");
aoqi@0 2512 branch_table[btos] = __ pc(); // non-volatile_entry point
aoqi@0 2513 __ lbzx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2514 __ extsb(R17_tos, R17_tos);
aoqi@0 2515 __ push(btos);
aoqi@0 2516 if (!is_static) patch_bytecode(Bytecodes::_fast_bgetfield, Rbc, Rscratch);
aoqi@0 2517 __ beq(CCR6, Lacquire); // Volatile?
aoqi@0 2518 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2519
aoqi@0 2520 __ align(32, 28, 28); // Align load.
simonis@8381 2521 // __ bind(Lztos); (same code as btos)
simonis@8381 2522 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
simonis@8381 2523 assert(branch_table[ztos] == 0, "can't compute twice");
simonis@8381 2524 branch_table[ztos] = __ pc(); // non-volatile_entry point
simonis@8381 2525 __ lbzx(R17_tos, Rclass_or_obj, Roffset);
simonis@8381 2526 __ extsb(R17_tos, R17_tos);
simonis@8381 2527 __ push(ztos);
simonis@8381 2528 if (!is_static) {
simonis@8381 2529 // use btos rewriting, no truncating to t/f bit is needed for getfield.
simonis@8381 2530 patch_bytecode(Bytecodes::_fast_bgetfield, Rbc, Rscratch);
simonis@8381 2531 }
simonis@8381 2532 __ beq(CCR6, Lacquire); // Volatile?
simonis@8381 2533 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
simonis@8381 2534
simonis@8381 2535 __ align(32, 28, 28); // Align load.
aoqi@0 2536 // __ bind(Lctos);
aoqi@0 2537 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2538 assert(branch_table[ctos] == 0, "can't compute twice");
aoqi@0 2539 branch_table[ctos] = __ pc(); // non-volatile_entry point
aoqi@0 2540 __ lhzx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2541 __ push(ctos);
aoqi@0 2542 if (!is_static) patch_bytecode(Bytecodes::_fast_cgetfield, Rbc, Rscratch);
aoqi@0 2543 __ beq(CCR6, Lacquire); // Volatile?
aoqi@0 2544 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2545
aoqi@0 2546 __ align(32, 28, 28); // Align load.
aoqi@0 2547 // __ bind(Lstos);
aoqi@0 2548 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2549 assert(branch_table[stos] == 0, "can't compute twice");
aoqi@0 2550 branch_table[stos] = __ pc(); // non-volatile_entry point
aoqi@0 2551 __ lhax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2552 __ push(stos);
aoqi@0 2553 if (!is_static) patch_bytecode(Bytecodes::_fast_sgetfield, Rbc, Rscratch);
aoqi@0 2554 __ beq(CCR6, Lacquire); // Volatile?
aoqi@0 2555 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2556
aoqi@0 2557 __ align(32, 28, 28); // Align load.
aoqi@0 2558 // __ bind(Latos);
aoqi@0 2559 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2560 assert(branch_table[atos] == 0, "can't compute twice");
aoqi@0 2561 branch_table[atos] = __ pc(); // non-volatile_entry point
aoqi@0 2562 __ load_heap_oop(R17_tos, (RegisterOrConstant)Roffset, Rclass_or_obj);
aoqi@0 2563 __ verify_oop(R17_tos);
aoqi@0 2564 __ push(atos);
aoqi@0 2565 //__ dcbt(R17_tos); // prefetch
aoqi@0 2566 if (!is_static) patch_bytecode(Bytecodes::_fast_agetfield, Rbc, Rscratch);
aoqi@0 2567 __ beq(CCR6, Lacquire); // Volatile?
aoqi@0 2568 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2569
aoqi@0 2570 __ align(32, 12);
aoqi@0 2571 __ bind(Lacquire);
aoqi@0 2572 __ twi_0(R17_tos);
aoqi@0 2573 __ bind(Lisync);
aoqi@0 2574 __ isync(); // acquire
aoqi@0 2575
aoqi@0 2576 #ifdef ASSERT
aoqi@0 2577 for (int i = 0; i<number_of_states; ++i) {
aoqi@0 2578 assert(branch_table[i], "get initialization");
aoqi@0 2579 //tty->print_cr("get: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)",
aoqi@0 2580 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i]));
aoqi@0 2581 }
aoqi@0 2582 #endif
aoqi@0 2583 }
aoqi@0 2584
aoqi@0 2585 void TemplateTable::getfield(int byte_no) {
aoqi@0 2586 getfield_or_static(byte_no, false);
aoqi@0 2587 }
aoqi@0 2588
aoqi@0 2589 void TemplateTable::getstatic(int byte_no) {
aoqi@0 2590 getfield_or_static(byte_no, true);
aoqi@0 2591 }
aoqi@0 2592
aoqi@0 2593 // The registers cache and index expected to be set before call.
aoqi@0 2594 // The function may destroy various registers, just not the cache and index registers.
aoqi@0 2595 void TemplateTable::jvmti_post_field_mod(Register Rcache, Register Rscratch, bool is_static) {
aoqi@0 2596
aoqi@0 2597 assert_different_registers(Rcache, Rscratch, R6_ARG4);
aoqi@0 2598
aoqi@0 2599 if (JvmtiExport::can_post_field_modification()) {
aoqi@0 2600 Label Lno_field_mod_post;
aoqi@0 2601
aoqi@0 2602 // Check if post field access in enabled.
aoqi@0 2603 int offs = __ load_const_optimized(Rscratch, JvmtiExport::get_field_modification_count_addr(), R0, true);
aoqi@0 2604 __ lwz(Rscratch, offs, Rscratch);
aoqi@0 2605
aoqi@0 2606 __ cmpwi(CCR0, Rscratch, 0);
aoqi@0 2607 __ beq(CCR0, Lno_field_mod_post);
aoqi@0 2608
aoqi@0 2609 // Do the post
aoqi@0 2610 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 2611 const Register Robj = Rscratch;
aoqi@0 2612
aoqi@0 2613 __ addi(Rcache, Rcache, in_bytes(cp_base_offset));
aoqi@0 2614 if (is_static) {
aoqi@0 2615 // Life is simple. Null out the object pointer.
aoqi@0 2616 __ li(Robj, 0);
aoqi@0 2617 } else {
aoqi@0 2618 // In case of the fast versions, value lives in registers => put it back on tos.
aoqi@0 2619 int offs = Interpreter::expr_offset_in_bytes(0);
aoqi@0 2620 Register base = R15_esp;
aoqi@0 2621 switch(bytecode()) {
aoqi@0 2622 case Bytecodes::_fast_aputfield: __ push_ptr(); offs+= Interpreter::stackElementSize; break;
aoqi@0 2623 case Bytecodes::_fast_iputfield: // Fall through
aoqi@0 2624 case Bytecodes::_fast_bputfield: // Fall through
simonis@8381 2625 case Bytecodes::_fast_zputfield: // Fall through
aoqi@0 2626 case Bytecodes::_fast_cputfield: // Fall through
aoqi@0 2627 case Bytecodes::_fast_sputfield: __ push_i(); offs+= Interpreter::stackElementSize; break;
aoqi@0 2628 case Bytecodes::_fast_lputfield: __ push_l(); offs+=2*Interpreter::stackElementSize; break;
aoqi@0 2629 case Bytecodes::_fast_fputfield: __ push_f(); offs+= Interpreter::stackElementSize; break;
aoqi@0 2630 case Bytecodes::_fast_dputfield: __ push_d(); offs+=2*Interpreter::stackElementSize; break;
aoqi@0 2631 default: {
aoqi@0 2632 offs = 0;
aoqi@0 2633 base = Robj;
aoqi@0 2634 const Register Rflags = Robj;
aoqi@0 2635 Label is_one_slot;
aoqi@0 2636 // Life is harder. The stack holds the value on top, followed by the
aoqi@0 2637 // object. We don't know the size of the value, though; it could be
aoqi@0 2638 // one or two words depending on its type. As a result, we must find
aoqi@0 2639 // the type to determine where the object is.
aoqi@0 2640 __ ld(Rflags, in_bytes(ConstantPoolCacheEntry::flags_offset()), Rcache); // Big Endian
aoqi@0 2641 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
aoqi@0 2642
aoqi@0 2643 __ cmpwi(CCR0, Rflags, ltos);
aoqi@0 2644 __ cmpwi(CCR1, Rflags, dtos);
aoqi@0 2645 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(1));
aoqi@0 2646 __ crnor(/*CR0 eq*/2, /*CR1 eq*/4+2, /*CR0 eq*/2);
aoqi@0 2647 __ beq(CCR0, is_one_slot);
aoqi@0 2648 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(2));
aoqi@0 2649 __ bind(is_one_slot);
aoqi@0 2650 break;
aoqi@0 2651 }
aoqi@0 2652 }
aoqi@0 2653 __ ld(Robj, offs, base);
aoqi@0 2654 __ verify_oop(Robj);
aoqi@0 2655 }
aoqi@0 2656
aoqi@0 2657 __ addi(R6_ARG4, R15_esp, Interpreter::expr_offset_in_bytes(0));
aoqi@0 2658 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), Robj, Rcache, R6_ARG4);
aoqi@0 2659 __ get_cache_and_index_at_bcp(Rcache, 1);
aoqi@0 2660
aoqi@0 2661 // In case of the fast versions, value lives in registers => put it back on tos.
aoqi@0 2662 switch(bytecode()) {
aoqi@0 2663 case Bytecodes::_fast_aputfield: __ pop_ptr(); break;
aoqi@0 2664 case Bytecodes::_fast_iputfield: // Fall through
aoqi@0 2665 case Bytecodes::_fast_bputfield: // Fall through
simonis@8381 2666 case Bytecodes::_fast_zputfield: // Fall through
aoqi@0 2667 case Bytecodes::_fast_cputfield: // Fall through
aoqi@0 2668 case Bytecodes::_fast_sputfield: __ pop_i(); break;
aoqi@0 2669 case Bytecodes::_fast_lputfield: __ pop_l(); break;
aoqi@0 2670 case Bytecodes::_fast_fputfield: __ pop_f(); break;
aoqi@0 2671 case Bytecodes::_fast_dputfield: __ pop_d(); break;
aoqi@0 2672 default: break; // Nothin' to do.
aoqi@0 2673 }
aoqi@0 2674
aoqi@0 2675 __ align(32, 12);
aoqi@0 2676 __ bind(Lno_field_mod_post);
aoqi@0 2677 }
aoqi@0 2678 }
aoqi@0 2679
aoqi@0 2680 // PPC64: implement volatile stores as release-store (return bytecode contains an additional release).
aoqi@0 2681 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
aoqi@0 2682 Label Lvolatile;
aoqi@0 2683
aoqi@0 2684 const Register Rcache = R5_ARG3, // Do not use ARG1/2 (causes trouble in jvmti_post_field_mod).
aoqi@0 2685 Rclass_or_obj = R31, // Needs to survive C call.
aoqi@0 2686 Roffset = R22_tmp2, // Needs to survive C call.
aoqi@0 2687 Rflags = R3_ARG1,
aoqi@0 2688 Rbtable = R4_ARG2,
aoqi@0 2689 Rscratch = R11_scratch1,
aoqi@0 2690 Rscratch2 = R12_scratch2,
aoqi@0 2691 Rscratch3 = R6_ARG4,
aoqi@0 2692 Rbc = Rscratch3;
aoqi@0 2693 const ConditionRegister CR_is_vol = CCR2; // Non-volatile condition register (survives runtime call in do_oop_store).
aoqi@0 2694
aoqi@0 2695 static address field_branch_table[number_of_states],
aoqi@0 2696 static_branch_table[number_of_states];
aoqi@0 2697
aoqi@0 2698 address* branch_table = is_static ? static_branch_table : field_branch_table;
aoqi@0 2699
aoqi@0 2700 // Stack (grows up):
aoqi@0 2701 // value
aoqi@0 2702 // obj
aoqi@0 2703
aoqi@0 2704 // Load the field offset.
aoqi@0 2705 resolve_cache_and_index(byte_no, Rcache, Rscratch, sizeof(u2));
aoqi@0 2706 jvmti_post_field_mod(Rcache, Rscratch, is_static);
aoqi@0 2707 load_field_cp_cache_entry(Rclass_or_obj, Rcache, noreg, Roffset, Rflags, is_static);
aoqi@0 2708
aoqi@0 2709 // Load pointer to branch table.
aoqi@0 2710 __ load_const_optimized(Rbtable, (address)branch_table, Rscratch);
aoqi@0 2711
aoqi@0 2712 // Get volatile flag.
aoqi@0 2713 __ rldicl(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit.
aoqi@0 2714
aoqi@0 2715 // Check the field type.
aoqi@0 2716 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
aoqi@0 2717
aoqi@0 2718 #ifdef ASSERT
aoqi@0 2719 Label LFlagInvalid;
aoqi@0 2720 __ cmpldi(CCR0, Rflags, number_of_states);
aoqi@0 2721 __ bge(CCR0, LFlagInvalid);
aoqi@0 2722 #endif
aoqi@0 2723
aoqi@0 2724 // Load from branch table and dispatch (volatile case: one instruction ahead).
aoqi@0 2725 __ sldi(Rflags, Rflags, LogBytesPerWord);
aoqi@0 2726 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { __ cmpwi(CR_is_vol, Rscratch, 1); } // Volatile?
aoqi@0 2727 __ sldi(Rscratch, Rscratch, exact_log2(BytesPerInstWord)); // Volatile? size of instruction 1 : 0.
aoqi@0 2728 __ ldx(Rbtable, Rbtable, Rflags);
aoqi@0 2729
aoqi@0 2730 __ subf(Rbtable, Rscratch, Rbtable); // Point to volatile/non-volatile entry point.
aoqi@0 2731 __ mtctr(Rbtable);
aoqi@0 2732 __ bctr();
aoqi@0 2733
aoqi@0 2734 #ifdef ASSERT
aoqi@0 2735 __ bind(LFlagInvalid);
aoqi@0 2736 __ stop("got invalid flag", 0x656);
aoqi@0 2737
aoqi@0 2738 // __ bind(Lvtos);
aoqi@0 2739 address pc_before_release = __ pc();
aoqi@0 2740 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2741 assert(__ pc() - pc_before_release == (ptrdiff_t)BytesPerInstWord, "must be single instruction");
aoqi@0 2742 assert(branch_table[vtos] == 0, "can't compute twice");
aoqi@0 2743 branch_table[vtos] = __ pc(); // non-volatile_entry point
aoqi@0 2744 __ stop("vtos unexpected", 0x657);
aoqi@0 2745 #endif
aoqi@0 2746
aoqi@0 2747 __ align(32, 28, 28); // Align pop.
aoqi@0 2748 // __ bind(Ldtos);
aoqi@0 2749 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2750 assert(branch_table[dtos] == 0, "can't compute twice");
aoqi@0 2751 branch_table[dtos] = __ pc(); // non-volatile_entry point
aoqi@0 2752 __ pop(dtos);
aoqi@0 2753 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
aoqi@0 2754 __ stfdx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 2755 if (!is_static) { patch_bytecode(Bytecodes::_fast_dputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2756 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2757 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2758 }
aoqi@0 2759 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2760
aoqi@0 2761 __ align(32, 28, 28); // Align pop.
aoqi@0 2762 // __ bind(Lftos);
aoqi@0 2763 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2764 assert(branch_table[ftos] == 0, "can't compute twice");
aoqi@0 2765 branch_table[ftos] = __ pc(); // non-volatile_entry point
aoqi@0 2766 __ pop(ftos);
aoqi@0 2767 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
aoqi@0 2768 __ stfsx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 2769 if (!is_static) { patch_bytecode(Bytecodes::_fast_fputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2770 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2771 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2772 }
aoqi@0 2773 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2774
aoqi@0 2775 __ align(32, 28, 28); // Align pop.
aoqi@0 2776 // __ bind(Litos);
aoqi@0 2777 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2778 assert(branch_table[itos] == 0, "can't compute twice");
aoqi@0 2779 branch_table[itos] = __ pc(); // non-volatile_entry point
aoqi@0 2780 __ pop(itos);
aoqi@0 2781 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
aoqi@0 2782 __ stwx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2783 if (!is_static) { patch_bytecode(Bytecodes::_fast_iputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2784 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2785 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2786 }
aoqi@0 2787 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2788
aoqi@0 2789 __ align(32, 28, 28); // Align pop.
aoqi@0 2790 // __ bind(Lltos);
aoqi@0 2791 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2792 assert(branch_table[ltos] == 0, "can't compute twice");
aoqi@0 2793 branch_table[ltos] = __ pc(); // non-volatile_entry point
aoqi@0 2794 __ pop(ltos);
aoqi@0 2795 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
aoqi@0 2796 __ stdx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2797 if (!is_static) { patch_bytecode(Bytecodes::_fast_lputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2798 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2799 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2800 }
aoqi@0 2801 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2802
aoqi@0 2803 __ align(32, 28, 28); // Align pop.
aoqi@0 2804 // __ bind(Lbtos);
aoqi@0 2805 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2806 assert(branch_table[btos] == 0, "can't compute twice");
aoqi@0 2807 branch_table[btos] = __ pc(); // non-volatile_entry point
aoqi@0 2808 __ pop(btos);
aoqi@0 2809 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
aoqi@0 2810 __ stbx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2811 if (!is_static) { patch_bytecode(Bytecodes::_fast_bputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2812 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2813 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2814 }
aoqi@0 2815 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2816
aoqi@0 2817 __ align(32, 28, 28); // Align pop.
simonis@8381 2818 // __ bind(Lztos);
simonis@8381 2819 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
simonis@8381 2820 assert(branch_table[ztos] == 0, "can't compute twice");
simonis@8381 2821 branch_table[ztos] = __ pc(); // non-volatile_entry point
simonis@8381 2822 __ pop(ztos);
simonis@8381 2823 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
simonis@8381 2824 __ andi(R17_tos, R17_tos, 0x1);
simonis@8381 2825 __ stbx(R17_tos, Rclass_or_obj, Roffset);
simonis@8381 2826 if (!is_static) { patch_bytecode(Bytecodes::_fast_zputfield, Rbc, Rscratch, true, byte_no); }
simonis@8381 2827 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
simonis@8381 2828 __ beq(CR_is_vol, Lvolatile); // Volatile?
simonis@8381 2829 }
simonis@8381 2830 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
simonis@8381 2831
simonis@8381 2832 __ align(32, 28, 28); // Align pop.
aoqi@0 2833 // __ bind(Lctos);
aoqi@0 2834 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2835 assert(branch_table[ctos] == 0, "can't compute twice");
aoqi@0 2836 branch_table[ctos] = __ pc(); // non-volatile_entry point
aoqi@0 2837 __ pop(ctos);
aoqi@0 2838 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1..
aoqi@0 2839 __ sthx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2840 if (!is_static) { patch_bytecode(Bytecodes::_fast_cputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2841 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2842 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2843 }
aoqi@0 2844 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2845
aoqi@0 2846 __ align(32, 28, 28); // Align pop.
aoqi@0 2847 // __ bind(Lstos);
aoqi@0 2848 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2849 assert(branch_table[stos] == 0, "can't compute twice");
aoqi@0 2850 branch_table[stos] = __ pc(); // non-volatile_entry point
aoqi@0 2851 __ pop(stos);
aoqi@0 2852 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.
aoqi@0 2853 __ sthx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2854 if (!is_static) { patch_bytecode(Bytecodes::_fast_sputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2855 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2856 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2857 }
aoqi@0 2858 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2859
aoqi@0 2860 __ align(32, 28, 28); // Align pop.
aoqi@0 2861 // __ bind(Latos);
aoqi@0 2862 __ release(); // Volatile entry point (one instruction before non-volatile_entry point).
aoqi@0 2863 assert(branch_table[atos] == 0, "can't compute twice");
aoqi@0 2864 branch_table[atos] = __ pc(); // non-volatile_entry point
aoqi@0 2865 __ pop(atos);
aoqi@0 2866 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // kills R11_scratch1
aoqi@0 2867 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, _bs->kind(), false /* precise */, true /* check null */);
aoqi@0 2868 if (!is_static) { patch_bytecode(Bytecodes::_fast_aputfield, Rbc, Rscratch, true, byte_no); }
aoqi@0 2869 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2870 __ beq(CR_is_vol, Lvolatile); // Volatile?
aoqi@0 2871 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2872
aoqi@0 2873 __ align(32, 12);
aoqi@0 2874 __ bind(Lvolatile);
aoqi@0 2875 __ fence();
aoqi@0 2876 }
aoqi@0 2877 // fallthru: __ b(Lexit);
aoqi@0 2878
aoqi@0 2879 #ifdef ASSERT
aoqi@0 2880 for (int i = 0; i<number_of_states; ++i) {
aoqi@0 2881 assert(branch_table[i], "put initialization");
aoqi@0 2882 //tty->print_cr("put: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)",
aoqi@0 2883 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i]));
aoqi@0 2884 }
aoqi@0 2885 #endif
aoqi@0 2886 }
aoqi@0 2887
aoqi@0 2888 void TemplateTable::putfield(int byte_no) {
aoqi@0 2889 putfield_or_static(byte_no, false);
aoqi@0 2890 }
aoqi@0 2891
aoqi@0 2892 void TemplateTable::putstatic(int byte_no) {
aoqi@0 2893 putfield_or_static(byte_no, true);
aoqi@0 2894 }
aoqi@0 2895
aoqi@0 2896 // See SPARC. On PPC64, we have a different jvmti_post_field_mod which does the job.
aoqi@0 2897 void TemplateTable::jvmti_post_fast_field_mod() {
aoqi@0 2898 __ should_not_reach_here();
aoqi@0 2899 }
aoqi@0 2900
aoqi@0 2901 void TemplateTable::fast_storefield(TosState state) {
aoqi@0 2902 transition(state, vtos);
aoqi@0 2903
aoqi@0 2904 const Register Rcache = R5_ARG3, // Do not use ARG1/2 (causes trouble in jvmti_post_field_mod).
aoqi@0 2905 Rclass_or_obj = R31, // Needs to survive C call.
aoqi@0 2906 Roffset = R22_tmp2, // Needs to survive C call.
aoqi@0 2907 Rflags = R3_ARG1,
aoqi@0 2908 Rscratch = R11_scratch1,
aoqi@0 2909 Rscratch2 = R12_scratch2,
aoqi@0 2910 Rscratch3 = R4_ARG2;
aoqi@0 2911 const ConditionRegister CR_is_vol = CCR2; // Non-volatile condition register (survives runtime call in do_oop_store).
aoqi@0 2912
aoqi@0 2913 // Constant pool already resolved => Load flags and offset of field.
aoqi@0 2914 __ get_cache_and_index_at_bcp(Rcache, 1);
aoqi@0 2915 jvmti_post_field_mod(Rcache, Rscratch, false /* not static */);
aoqi@0 2916 load_field_cp_cache_entry(noreg, Rcache, noreg, Roffset, Rflags, false);
aoqi@0 2917
aoqi@0 2918 // Get the obj and the final store addr.
aoqi@0 2919 pop_and_check_object(Rclass_or_obj); // Kills R11_scratch1.
aoqi@0 2920
aoqi@0 2921 // Get volatile flag.
aoqi@0 2922 __ rldicl_(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit.
aoqi@0 2923 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { __ cmpdi(CR_is_vol, Rscratch, 1); }
aoqi@0 2924 {
aoqi@0 2925 Label LnotVolatile;
aoqi@0 2926 __ beq(CCR0, LnotVolatile);
aoqi@0 2927 __ release();
aoqi@0 2928 __ align(32, 12);
aoqi@0 2929 __ bind(LnotVolatile);
aoqi@0 2930 }
aoqi@0 2931
aoqi@0 2932 // Do the store and fencing.
aoqi@0 2933 switch(bytecode()) {
aoqi@0 2934 case Bytecodes::_fast_aputfield:
aoqi@0 2935 // Store into the field.
aoqi@0 2936 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, _bs->kind(), false /* precise */, true /* check null */);
aoqi@0 2937 break;
aoqi@0 2938
aoqi@0 2939 case Bytecodes::_fast_iputfield:
aoqi@0 2940 __ stwx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2941 break;
aoqi@0 2942
aoqi@0 2943 case Bytecodes::_fast_lputfield:
aoqi@0 2944 __ stdx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2945 break;
aoqi@0 2946
simonis@8381 2947 case Bytecodes::_fast_zputfield:
simonis@8381 2948 __ andi(R17_tos, R17_tos, 0x1); // boolean is true if LSB is 1
simonis@8381 2949 // fall through to bputfield
aoqi@0 2950 case Bytecodes::_fast_bputfield:
aoqi@0 2951 __ stbx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2952 break;
aoqi@0 2953
aoqi@0 2954 case Bytecodes::_fast_cputfield:
aoqi@0 2955 case Bytecodes::_fast_sputfield:
aoqi@0 2956 __ sthx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 2957 break;
aoqi@0 2958
aoqi@0 2959 case Bytecodes::_fast_fputfield:
aoqi@0 2960 __ stfsx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 2961 break;
aoqi@0 2962
aoqi@0 2963 case Bytecodes::_fast_dputfield:
aoqi@0 2964 __ stfdx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 2965 break;
aoqi@0 2966
aoqi@0 2967 default: ShouldNotReachHere();
aoqi@0 2968 }
aoqi@0 2969
aoqi@0 2970 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 2971 Label LVolatile;
aoqi@0 2972 __ beq(CR_is_vol, LVolatile);
aoqi@0 2973 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode()));
aoqi@0 2974
aoqi@0 2975 __ align(32, 12);
aoqi@0 2976 __ bind(LVolatile);
aoqi@0 2977 __ fence();
aoqi@0 2978 }
aoqi@0 2979 }
aoqi@0 2980
aoqi@0 2981 void TemplateTable::fast_accessfield(TosState state) {
aoqi@0 2982 transition(atos, state);
aoqi@0 2983
aoqi@0 2984 Label LisVolatile;
aoqi@0 2985 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 2986
aoqi@0 2987 const Register Rcache = R3_ARG1,
aoqi@0 2988 Rclass_or_obj = R17_tos,
aoqi@0 2989 Roffset = R22_tmp2,
aoqi@0 2990 Rflags = R23_tmp3,
aoqi@0 2991 Rscratch = R12_scratch2;
aoqi@0 2992
aoqi@0 2993 // Constant pool already resolved. Get the field offset.
aoqi@0 2994 __ get_cache_and_index_at_bcp(Rcache, 1);
aoqi@0 2995 load_field_cp_cache_entry(noreg, Rcache, noreg, Roffset, Rflags, false);
aoqi@0 2996
aoqi@0 2997 // JVMTI support
aoqi@0 2998 jvmti_post_field_access(Rcache, Rscratch, false, true);
aoqi@0 2999
aoqi@0 3000 // Get the load address.
aoqi@0 3001 __ null_check_throw(Rclass_or_obj, -1, Rscratch);
aoqi@0 3002
aoqi@0 3003 // Get volatile flag.
aoqi@0 3004 __ rldicl_(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit.
aoqi@0 3005 __ bne(CCR0, LisVolatile);
aoqi@0 3006
aoqi@0 3007 switch(bytecode()) {
aoqi@0 3008 case Bytecodes::_fast_agetfield:
aoqi@0 3009 {
aoqi@0 3010 __ load_heap_oop(R17_tos, (RegisterOrConstant)Roffset, Rclass_or_obj);
aoqi@0 3011 __ verify_oop(R17_tos);
aoqi@0 3012 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3013
aoqi@0 3014 __ bind(LisVolatile);
aoqi@0 3015 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3016 __ load_heap_oop(R17_tos, (RegisterOrConstant)Roffset, Rclass_or_obj);
aoqi@0 3017 __ verify_oop(R17_tos);
aoqi@0 3018 __ twi_0(R17_tos);
aoqi@0 3019 __ isync();
aoqi@0 3020 break;
aoqi@0 3021 }
aoqi@0 3022 case Bytecodes::_fast_igetfield:
aoqi@0 3023 {
aoqi@0 3024 __ lwax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3025 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3026
aoqi@0 3027 __ bind(LisVolatile);
aoqi@0 3028 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3029 __ lwax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3030 __ twi_0(R17_tos);
aoqi@0 3031 __ isync();
aoqi@0 3032 break;
aoqi@0 3033 }
aoqi@0 3034 case Bytecodes::_fast_lgetfield:
aoqi@0 3035 {
aoqi@0 3036 __ ldx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3037 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3038
aoqi@0 3039 __ bind(LisVolatile);
aoqi@0 3040 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3041 __ ldx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3042 __ twi_0(R17_tos);
aoqi@0 3043 __ isync();
aoqi@0 3044 break;
aoqi@0 3045 }
aoqi@0 3046 case Bytecodes::_fast_bgetfield:
aoqi@0 3047 {
aoqi@0 3048 __ lbzx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3049 __ extsb(R17_tos, R17_tos);
aoqi@0 3050 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3051
aoqi@0 3052 __ bind(LisVolatile);
aoqi@0 3053 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3054 __ lbzx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3055 __ twi_0(R17_tos);
aoqi@0 3056 __ extsb(R17_tos, R17_tos);
aoqi@0 3057 __ isync();
aoqi@0 3058 break;
aoqi@0 3059 }
aoqi@0 3060 case Bytecodes::_fast_cgetfield:
aoqi@0 3061 {
aoqi@0 3062 __ lhzx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3063 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3064
aoqi@0 3065 __ bind(LisVolatile);
aoqi@0 3066 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3067 __ lhzx(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3068 __ twi_0(R17_tos);
aoqi@0 3069 __ isync();
aoqi@0 3070 break;
aoqi@0 3071 }
aoqi@0 3072 case Bytecodes::_fast_sgetfield:
aoqi@0 3073 {
aoqi@0 3074 __ lhax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3075 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3076
aoqi@0 3077 __ bind(LisVolatile);
aoqi@0 3078 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3079 __ lhax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3080 __ twi_0(R17_tos);
aoqi@0 3081 __ isync();
aoqi@0 3082 break;
aoqi@0 3083 }
aoqi@0 3084 case Bytecodes::_fast_fgetfield:
aoqi@0 3085 {
aoqi@0 3086 __ lfsx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 3087 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3088
aoqi@0 3089 __ bind(LisVolatile);
aoqi@0 3090 Label Ldummy;
aoqi@0 3091 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3092 __ lfsx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 3093 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync.
aoqi@0 3094 __ bne_predict_not_taken(CCR0, Ldummy);
aoqi@0 3095 __ bind(Ldummy);
aoqi@0 3096 __ isync();
aoqi@0 3097 break;
aoqi@0 3098 }
aoqi@0 3099 case Bytecodes::_fast_dgetfield:
aoqi@0 3100 {
aoqi@0 3101 __ lfdx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 3102 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()));
aoqi@0 3103
aoqi@0 3104 __ bind(LisVolatile);
aoqi@0 3105 Label Ldummy;
aoqi@0 3106 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3107 __ lfdx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 3108 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync.
aoqi@0 3109 __ bne_predict_not_taken(CCR0, Ldummy);
aoqi@0 3110 __ bind(Ldummy);
aoqi@0 3111 __ isync();
aoqi@0 3112 break;
aoqi@0 3113 }
aoqi@0 3114 default: ShouldNotReachHere();
aoqi@0 3115 }
aoqi@0 3116 }
aoqi@0 3117
aoqi@0 3118 void TemplateTable::fast_xaccess(TosState state) {
aoqi@0 3119 transition(vtos, state);
aoqi@0 3120
aoqi@0 3121 Label LisVolatile;
aoqi@0 3122 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 3123 const Register Rcache = R3_ARG1,
aoqi@0 3124 Rclass_or_obj = R17_tos,
aoqi@0 3125 Roffset = R22_tmp2,
aoqi@0 3126 Rflags = R23_tmp3,
aoqi@0 3127 Rscratch = R12_scratch2;
aoqi@0 3128
aoqi@0 3129 __ ld(Rclass_or_obj, 0, R18_locals);
aoqi@0 3130
aoqi@0 3131 // Constant pool already resolved. Get the field offset.
aoqi@0 3132 __ get_cache_and_index_at_bcp(Rcache, 2);
aoqi@0 3133 load_field_cp_cache_entry(noreg, Rcache, noreg, Roffset, Rflags, false);
aoqi@0 3134
aoqi@0 3135 // JVMTI support not needed, since we switch back to single bytecode as soon as debugger attaches.
aoqi@0 3136
aoqi@0 3137 // Needed to report exception at the correct bcp.
aoqi@0 3138 __ addi(R14_bcp, R14_bcp, 1);
aoqi@0 3139
aoqi@0 3140 // Get the load address.
aoqi@0 3141 __ null_check_throw(Rclass_or_obj, -1, Rscratch);
aoqi@0 3142
aoqi@0 3143 // Get volatile flag.
aoqi@0 3144 __ rldicl_(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit.
aoqi@0 3145 __ bne(CCR0, LisVolatile);
aoqi@0 3146
aoqi@0 3147 switch(state) {
aoqi@0 3148 case atos:
aoqi@0 3149 {
aoqi@0 3150 __ load_heap_oop(R17_tos, (RegisterOrConstant)Roffset, Rclass_or_obj);
aoqi@0 3151 __ verify_oop(R17_tos);
aoqi@0 3152 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()) - 1); // Undo bcp increment.
aoqi@0 3153
aoqi@0 3154 __ bind(LisVolatile);
aoqi@0 3155 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3156 __ load_heap_oop(R17_tos, (RegisterOrConstant)Roffset, Rclass_or_obj);
aoqi@0 3157 __ verify_oop(R17_tos);
aoqi@0 3158 __ twi_0(R17_tos);
aoqi@0 3159 __ isync();
aoqi@0 3160 break;
aoqi@0 3161 }
aoqi@0 3162 case itos:
aoqi@0 3163 {
aoqi@0 3164 __ lwax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3165 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()) - 1); // Undo bcp increment.
aoqi@0 3166
aoqi@0 3167 __ bind(LisVolatile);
aoqi@0 3168 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3169 __ lwax(R17_tos, Rclass_or_obj, Roffset);
aoqi@0 3170 __ twi_0(R17_tos);
aoqi@0 3171 __ isync();
aoqi@0 3172 break;
aoqi@0 3173 }
aoqi@0 3174 case ftos:
aoqi@0 3175 {
aoqi@0 3176 __ lfsx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 3177 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()) - 1); // Undo bcp increment.
aoqi@0 3178
aoqi@0 3179 __ bind(LisVolatile);
aoqi@0 3180 Label Ldummy;
aoqi@0 3181 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); }
aoqi@0 3182 __ lfsx(F15_ftos, Rclass_or_obj, Roffset);
aoqi@0 3183 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync.
aoqi@0 3184 __ bne_predict_not_taken(CCR0, Ldummy);
aoqi@0 3185 __ bind(Ldummy);
aoqi@0 3186 __ isync();
aoqi@0 3187 break;
aoqi@0 3188 }
aoqi@0 3189 default: ShouldNotReachHere();
aoqi@0 3190 }
aoqi@0 3191 __ addi(R14_bcp, R14_bcp, -1);
aoqi@0 3192 }
aoqi@0 3193
aoqi@0 3194 // ============================================================================
aoqi@0 3195 // Calls
aoqi@0 3196
aoqi@0 3197 // Common code for invoke
aoqi@0 3198 //
aoqi@0 3199 // Input:
aoqi@0 3200 // - byte_no
aoqi@0 3201 //
aoqi@0 3202 // Output:
aoqi@0 3203 // - Rmethod: The method to invoke next.
aoqi@0 3204 // - Rret_addr: The return address to return to.
aoqi@0 3205 // - Rindex: MethodType (invokehandle) or CallSite obj (invokedynamic)
aoqi@0 3206 // - Rrecv: Cache for "this" pointer, might be noreg if static call.
aoqi@0 3207 // - Rflags: Method flags from const pool cache.
aoqi@0 3208 //
aoqi@0 3209 // Kills:
aoqi@0 3210 // - Rscratch1
aoqi@0 3211 //
aoqi@0 3212 void TemplateTable::prepare_invoke(int byte_no,
aoqi@0 3213 Register Rmethod, // linked method (or i-klass)
aoqi@0 3214 Register Rret_addr,// return address
aoqi@0 3215 Register Rindex, // itable index, MethodType, etc.
aoqi@0 3216 Register Rrecv, // If caller wants to see it.
aoqi@0 3217 Register Rflags, // If caller wants to test it.
aoqi@0 3218 Register Rscratch
aoqi@0 3219 ) {
aoqi@0 3220 // Determine flags.
aoqi@0 3221 const Bytecodes::Code code = bytecode();
aoqi@0 3222 const bool is_invokeinterface = code == Bytecodes::_invokeinterface;
aoqi@0 3223 const bool is_invokedynamic = code == Bytecodes::_invokedynamic;
aoqi@0 3224 const bool is_invokehandle = code == Bytecodes::_invokehandle;
aoqi@0 3225 const bool is_invokevirtual = code == Bytecodes::_invokevirtual;
aoqi@0 3226 const bool is_invokespecial = code == Bytecodes::_invokespecial;
aoqi@0 3227 const bool load_receiver = (Rrecv != noreg);
aoqi@0 3228 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), "");
aoqi@0 3229
aoqi@0 3230 assert_different_registers(Rmethod, Rindex, Rflags, Rscratch);
aoqi@0 3231 assert_different_registers(Rmethod, Rrecv, Rflags, Rscratch);
aoqi@0 3232 assert_different_registers(Rret_addr, Rscratch);
aoqi@0 3233
aoqi@0 3234 load_invoke_cp_cache_entry(byte_no, Rmethod, Rindex, Rflags, is_invokevirtual, false, is_invokedynamic);
aoqi@0 3235
aoqi@0 3236 // Saving of SP done in call_from_interpreter.
aoqi@0 3237
aoqi@0 3238 // Maybe push "appendix" to arguments.
aoqi@0 3239 if (is_invokedynamic || is_invokehandle) {
aoqi@0 3240 Label Ldone;
aoqi@0 3241 __ rldicl_(R0, Rflags, 64-ConstantPoolCacheEntry::has_appendix_shift, 63);
aoqi@0 3242 __ beq(CCR0, Ldone);
aoqi@0 3243 // Push "appendix" (MethodType, CallSite, etc.).
aoqi@0 3244 // This must be done before we get the receiver,
aoqi@0 3245 // since the parameter_size includes it.
aoqi@0 3246 __ load_resolved_reference_at_index(Rscratch, Rindex);
aoqi@0 3247 __ verify_oop(Rscratch);
aoqi@0 3248 __ push_ptr(Rscratch);
aoqi@0 3249 __ bind(Ldone);
aoqi@0 3250 }
aoqi@0 3251
aoqi@0 3252 // Load receiver if needed (after appendix is pushed so parameter size is correct).
aoqi@0 3253 if (load_receiver) {
aoqi@0 3254 const Register Rparam_count = Rscratch;
aoqi@0 3255 __ andi(Rparam_count, Rflags, ConstantPoolCacheEntry::parameter_size_mask);
aoqi@0 3256 __ load_receiver(Rparam_count, Rrecv);
aoqi@0 3257 __ verify_oop(Rrecv);
aoqi@0 3258 }
aoqi@0 3259
aoqi@0 3260 // Get return address.
aoqi@0 3261 {
aoqi@0 3262 Register Rtable_addr = Rscratch;
aoqi@0 3263 Register Rret_type = Rret_addr;
aoqi@0 3264 address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
aoqi@0 3265
aoqi@0 3266 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value.
aoqi@0 3267 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
aoqi@0 3268 __ load_dispatch_table(Rtable_addr, (address*)table_addr);
aoqi@0 3269 __ sldi(Rret_type, Rret_type, LogBytesPerWord);
aoqi@0 3270 // Get return address.
aoqi@0 3271 __ ldx(Rret_addr, Rtable_addr, Rret_type);
aoqi@0 3272 }
aoqi@0 3273 }
aoqi@0 3274
aoqi@0 3275 // Helper for virtual calls. Load target out of vtable and jump off!
aoqi@0 3276 // Kills all passed registers.
aoqi@0 3277 void TemplateTable::generate_vtable_call(Register Rrecv_klass, Register Rindex, Register Rret, Register Rtemp) {
aoqi@0 3278
aoqi@0 3279 assert_different_registers(Rrecv_klass, Rtemp, Rret);
aoqi@0 3280 const Register Rtarget_method = Rindex;
aoqi@0 3281
aoqi@0 3282 // Get target method & entry point.
aoqi@0 3283 const int base = InstanceKlass::vtable_start_offset() * wordSize;
aoqi@0 3284 // Calc vtable addr scale the vtable index by 8.
aoqi@0 3285 __ sldi(Rindex, Rindex, exact_log2(vtableEntry::size() * wordSize));
aoqi@0 3286 // Load target.
aoqi@0 3287 __ addi(Rrecv_klass, Rrecv_klass, base + vtableEntry::method_offset_in_bytes());
aoqi@0 3288 __ ldx(Rtarget_method, Rindex, Rrecv_klass);
goetz@7424 3289 // Argument and return type profiling.
goetz@7424 3290 __ profile_arguments_type(Rtarget_method, Rrecv_klass /* scratch1 */, Rtemp /* scratch2 */, true);
aoqi@0 3291 __ call_from_interpreter(Rtarget_method, Rret, Rrecv_klass /* scratch1 */, Rtemp /* scratch2 */);
aoqi@0 3292 }
aoqi@0 3293
aoqi@0 3294 // Virtual or final call. Final calls are rewritten on the fly to run through "fast_finalcall" next time.
aoqi@0 3295 void TemplateTable::invokevirtual(int byte_no) {
aoqi@0 3296 transition(vtos, vtos);
aoqi@0 3297
aoqi@0 3298 Register Rtable_addr = R11_scratch1,
aoqi@0 3299 Rret_type = R12_scratch2,
aoqi@0 3300 Rret_addr = R5_ARG3,
aoqi@0 3301 Rflags = R22_tmp2, // Should survive C call.
aoqi@0 3302 Rrecv = R3_ARG1,
aoqi@0 3303 Rrecv_klass = Rrecv,
aoqi@0 3304 Rvtableindex_or_method = R31, // Should survive C call.
aoqi@0 3305 Rnum_params = R4_ARG2,
aoqi@0 3306 Rnew_bc = R6_ARG4;
aoqi@0 3307
aoqi@0 3308 Label LnotFinal;
aoqi@0 3309
aoqi@0 3310 load_invoke_cp_cache_entry(byte_no, Rvtableindex_or_method, noreg, Rflags, /*virtual*/ true, false, false);
aoqi@0 3311
aoqi@0 3312 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_vfinal_shift);
aoqi@0 3313 __ bfalse(CCR0, LnotFinal);
aoqi@0 3314
aoqi@0 3315 patch_bytecode(Bytecodes::_fast_invokevfinal, Rnew_bc, R12_scratch2);
aoqi@0 3316 invokevfinal_helper(Rvtableindex_or_method, Rflags, R11_scratch1, R12_scratch2);
aoqi@0 3317
aoqi@0 3318 __ align(32, 12);
aoqi@0 3319 __ bind(LnotFinal);
aoqi@0 3320 // Load "this" pointer (receiver).
aoqi@0 3321 __ rldicl(Rnum_params, Rflags, 64, 48);
aoqi@0 3322 __ load_receiver(Rnum_params, Rrecv);
aoqi@0 3323 __ verify_oop(Rrecv);
aoqi@0 3324
aoqi@0 3325 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value.
aoqi@0 3326 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
aoqi@0 3327 __ load_dispatch_table(Rtable_addr, Interpreter::invoke_return_entry_table());
aoqi@0 3328 __ sldi(Rret_type, Rret_type, LogBytesPerWord);
aoqi@0 3329 __ ldx(Rret_addr, Rret_type, Rtable_addr);
aoqi@0 3330 __ null_check_throw(Rrecv, oopDesc::klass_offset_in_bytes(), R11_scratch1);
aoqi@0 3331 __ load_klass(Rrecv_klass, Rrecv);
aoqi@0 3332 __ verify_klass_ptr(Rrecv_klass);
aoqi@0 3333 __ profile_virtual_call(Rrecv_klass, R11_scratch1, R12_scratch2, false);
aoqi@0 3334
aoqi@0 3335 generate_vtable_call(Rrecv_klass, Rvtableindex_or_method, Rret_addr, R11_scratch1);
aoqi@0 3336 }
aoqi@0 3337
aoqi@0 3338 void TemplateTable::fast_invokevfinal(int byte_no) {
aoqi@0 3339 transition(vtos, vtos);
aoqi@0 3340
aoqi@0 3341 assert(byte_no == f2_byte, "use this argument");
aoqi@0 3342 Register Rflags = R22_tmp2,
aoqi@0 3343 Rmethod = R31;
aoqi@0 3344 load_invoke_cp_cache_entry(byte_no, Rmethod, noreg, Rflags, /*virtual*/ true, /*is_invokevfinal*/ true, false);
aoqi@0 3345 invokevfinal_helper(Rmethod, Rflags, R11_scratch1, R12_scratch2);
aoqi@0 3346 }
aoqi@0 3347
aoqi@0 3348 void TemplateTable::invokevfinal_helper(Register Rmethod, Register Rflags, Register Rscratch1, Register Rscratch2) {
aoqi@0 3349
aoqi@0 3350 assert_different_registers(Rmethod, Rflags, Rscratch1, Rscratch2);
aoqi@0 3351
aoqi@0 3352 // Load receiver from stack slot.
aoqi@0 3353 Register Rrecv = Rscratch2;
aoqi@0 3354 Register Rnum_params = Rrecv;
aoqi@0 3355
aoqi@0 3356 __ ld(Rnum_params, in_bytes(Method::const_offset()), Rmethod);
aoqi@0 3357 __ lhz(Rnum_params /* number of params */, in_bytes(ConstMethod::size_of_parameters_offset()), Rnum_params);
aoqi@0 3358
aoqi@0 3359 // Get return address.
aoqi@0 3360 Register Rtable_addr = Rscratch1,
aoqi@0 3361 Rret_addr = Rflags,
aoqi@0 3362 Rret_type = Rret_addr;
aoqi@0 3363 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value.
aoqi@0 3364 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
aoqi@0 3365 __ load_dispatch_table(Rtable_addr, Interpreter::invoke_return_entry_table());
aoqi@0 3366 __ sldi(Rret_type, Rret_type, LogBytesPerWord);
aoqi@0 3367 __ ldx(Rret_addr, Rret_type, Rtable_addr);
aoqi@0 3368
aoqi@0 3369 // Load receiver and receiver NULL check.
aoqi@0 3370 __ load_receiver(Rnum_params, Rrecv);
aoqi@0 3371 __ null_check_throw(Rrecv, -1, Rscratch1);
aoqi@0 3372
aoqi@0 3373 __ profile_final_call(Rrecv, Rscratch1);
goetz@7424 3374 // Argument and return type profiling.
goetz@7424 3375 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, true);
aoqi@0 3376
aoqi@0 3377 // Do the call.
aoqi@0 3378 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1, Rscratch2);
aoqi@0 3379 }
aoqi@0 3380
aoqi@0 3381 void TemplateTable::invokespecial(int byte_no) {
aoqi@0 3382 assert(byte_no == f1_byte, "use this argument");
aoqi@0 3383 transition(vtos, vtos);
aoqi@0 3384
aoqi@0 3385 Register Rtable_addr = R3_ARG1,
aoqi@0 3386 Rret_addr = R4_ARG2,
aoqi@0 3387 Rflags = R5_ARG3,
aoqi@0 3388 Rreceiver = R6_ARG4,
aoqi@0 3389 Rmethod = R31;
aoqi@0 3390
aoqi@0 3391 prepare_invoke(byte_no, Rmethod, Rret_addr, noreg, Rreceiver, Rflags, R11_scratch1);
aoqi@0 3392
aoqi@0 3393 // Receiver NULL check.
aoqi@0 3394 __ null_check_throw(Rreceiver, -1, R11_scratch1);
aoqi@0 3395
aoqi@0 3396 __ profile_call(R11_scratch1, R12_scratch2);
goetz@7424 3397 // Argument and return type profiling.
goetz@7424 3398 __ profile_arguments_type(Rmethod, R11_scratch1, R12_scratch2, false);
aoqi@0 3399 __ call_from_interpreter(Rmethod, Rret_addr, R11_scratch1, R12_scratch2);
aoqi@0 3400 }
aoqi@0 3401
aoqi@0 3402 void TemplateTable::invokestatic(int byte_no) {
aoqi@0 3403 assert(byte_no == f1_byte, "use this argument");
aoqi@0 3404 transition(vtos, vtos);
aoqi@0 3405
aoqi@0 3406 Register Rtable_addr = R3_ARG1,
aoqi@0 3407 Rret_addr = R4_ARG2,
aoqi@0 3408 Rflags = R5_ARG3;
aoqi@0 3409
aoqi@0 3410 prepare_invoke(byte_no, R19_method, Rret_addr, noreg, noreg, Rflags, R11_scratch1);
aoqi@0 3411
aoqi@0 3412 __ profile_call(R11_scratch1, R12_scratch2);
goetz@7424 3413 // Argument and return type profiling.
goetz@7424 3414 __ profile_arguments_type(R19_method, R11_scratch1, R12_scratch2, false);
aoqi@0 3415 __ call_from_interpreter(R19_method, Rret_addr, R11_scratch1, R12_scratch2);
aoqi@0 3416 }
aoqi@0 3417
aoqi@0 3418 void TemplateTable::invokeinterface_object_method(Register Rrecv_klass,
aoqi@0 3419 Register Rret,
aoqi@0 3420 Register Rflags,
mdoerr@9034 3421 Register Rmethod,
aoqi@0 3422 Register Rtemp1,
aoqi@0 3423 Register Rtemp2) {
aoqi@0 3424
mdoerr@9034 3425 assert_different_registers(Rmethod, Rret, Rrecv_klass, Rflags, Rtemp1, Rtemp2);
aoqi@0 3426 Label LnotFinal;
aoqi@0 3427
aoqi@0 3428 // Check for vfinal.
aoqi@0 3429 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_vfinal_shift);
aoqi@0 3430 __ bfalse(CCR0, LnotFinal);
aoqi@0 3431
aoqi@0 3432 Register Rscratch = Rflags; // Rflags is dead now.
aoqi@0 3433
aoqi@0 3434 // Final call case.
aoqi@0 3435 __ profile_final_call(Rtemp1, Rscratch);
goetz@7424 3436 // Argument and return type profiling.
mdoerr@9034 3437 __ profile_arguments_type(Rmethod, Rscratch, Rrecv_klass /* scratch */, true);
aoqi@0 3438 // Do the final call - the index (f2) contains the method.
mdoerr@9034 3439 __ call_from_interpreter(Rmethod, Rret, Rscratch, Rrecv_klass /* scratch */);
aoqi@0 3440
aoqi@0 3441 // Non-final callc case.
aoqi@0 3442 __ bind(LnotFinal);
aoqi@0 3443 __ profile_virtual_call(Rrecv_klass, Rtemp1, Rscratch, false);
mdoerr@9034 3444 generate_vtable_call(Rrecv_klass, Rmethod, Rret, Rscratch);
aoqi@0 3445 }
aoqi@0 3446
aoqi@0 3447 void TemplateTable::invokeinterface(int byte_no) {
aoqi@0 3448 assert(byte_no == f1_byte, "use this argument");
aoqi@0 3449 transition(vtos, vtos);
aoqi@0 3450
aoqi@0 3451 const Register Rscratch1 = R11_scratch1,
aoqi@0 3452 Rscratch2 = R12_scratch2,
mdoerr@9034 3453 Rmethod = R6_ARG4,
mdoerr@9034 3454 Rmethod2 = R9_ARG7,
aoqi@0 3455 Rinterface_klass = R5_ARG3,
mdoerr@9034 3456 Rret_addr = R8_ARG6,
mdoerr@9034 3457 Rindex = R10_ARG8,
mdoerr@9034 3458 Rreceiver = R3_ARG1,
mdoerr@9034 3459 Rrecv_klass = R4_ARG2,
aoqi@0 3460 Rflags = R7_ARG5;
aoqi@0 3461
mdoerr@9034 3462 prepare_invoke(byte_no, Rinterface_klass, Rret_addr, Rmethod, Rreceiver, Rflags, Rscratch1);
aoqi@0 3463
aoqi@0 3464 // Get receiver klass.
mdoerr@9034 3465 __ null_check_throw(Rreceiver, oopDesc::klass_offset_in_bytes(), Rscratch2);
aoqi@0 3466 __ load_klass(Rrecv_klass, Rreceiver);
aoqi@0 3467
aoqi@0 3468 // Check corner case object method.
mdoerr@9034 3469 Label LobjectMethod, L_no_such_interface, Lthrow_ame;
aoqi@0 3470 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_forced_virtual_shift);
aoqi@0 3471 __ btrue(CCR0, LobjectMethod);
aoqi@0 3472
mdoerr@9034 3473 __ lookup_interface_method(Rrecv_klass, Rinterface_klass, noreg, noreg, Rscratch1, Rscratch2,
mdoerr@9034 3474 L_no_such_interface, /*return_method=*/false);
mdoerr@9034 3475
aoqi@0 3476 __ profile_virtual_call(Rrecv_klass, Rscratch1, Rscratch2, false);
aoqi@0 3477
aoqi@0 3478 // Find entry point to call.
mdoerr@9034 3479
mdoerr@9034 3480 // Get declaring interface class from method
mdoerr@9034 3481 __ ld(Rinterface_klass, in_bytes(Method::const_offset()), Rmethod);
mdoerr@9034 3482 __ ld(Rinterface_klass, in_bytes(ConstMethod::constants_offset()), Rinterface_klass);
mdoerr@9034 3483 __ ld(Rinterface_klass, ConstantPool::pool_holder_offset_in_bytes(), Rinterface_klass);
mdoerr@9034 3484
mdoerr@9034 3485 // Get itable index from method
mdoerr@9034 3486 __ lwa(Rindex, in_bytes(Method::itable_index_offset()), Rmethod);
mdoerr@9034 3487 __ subfic(Rindex, Rindex, Method::itable_index_max);
mdoerr@9034 3488
mdoerr@9034 3489 __ lookup_interface_method(Rrecv_klass, Rinterface_klass, Rindex, Rmethod2, Rscratch1, Rscratch2,
mdoerr@9034 3490 L_no_such_interface);
mdoerr@9034 3491
mdoerr@9034 3492 __ cmpdi(CCR0, Rmethod2, 0);
aoqi@0 3493 __ beq(CCR0, Lthrow_ame);
aoqi@0 3494 // Found entry. Jump off!
goetz@7424 3495 // Argument and return type profiling.
mdoerr@9034 3496 __ profile_arguments_type(Rmethod2, Rscratch1, Rscratch2, true);
mdoerr@9034 3497 //__ profile_called_method(Rindex, Rscratch1);
mdoerr@9034 3498 __ call_from_interpreter(Rmethod2, Rret_addr, Rscratch1, Rscratch2);
aoqi@0 3499
aoqi@0 3500 // Vtable entry was NULL => Throw abstract method error.
aoqi@0 3501 __ bind(Lthrow_ame);
aoqi@0 3502 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
aoqi@0 3503
aoqi@0 3504 // Interface was not found => Throw incompatible class change error.
mdoerr@9034 3505 __ bind(L_no_such_interface);
aoqi@0 3506 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
mdoerr@9034 3507 DEBUG_ONLY( __ should_not_reach_here(); )
aoqi@0 3508
aoqi@0 3509 // Special case of invokeinterface called for virtual method of
aoqi@0 3510 // java.lang.Object. See ConstantPoolCacheEntry::set_method() for details:
aoqi@0 3511 // The invokeinterface was rewritten to a invokevirtual, hence we have
aoqi@0 3512 // to handle this corner case. This code isn't produced by javac, but could
aoqi@0 3513 // be produced by another compliant java compiler.
aoqi@0 3514 __ bind(LobjectMethod);
mdoerr@9034 3515 invokeinterface_object_method(Rrecv_klass, Rret_addr, Rflags, Rmethod, Rscratch1, Rscratch2);
aoqi@0 3516 }
aoqi@0 3517
aoqi@0 3518 void TemplateTable::invokedynamic(int byte_no) {
aoqi@0 3519 transition(vtos, vtos);
aoqi@0 3520
aoqi@0 3521 const Register Rret_addr = R3_ARG1,
aoqi@0 3522 Rflags = R4_ARG2,
aoqi@0 3523 Rmethod = R22_tmp2,
aoqi@0 3524 Rscratch1 = R11_scratch1,
aoqi@0 3525 Rscratch2 = R12_scratch2;
aoqi@0 3526
aoqi@0 3527 if (!EnableInvokeDynamic) {
aoqi@0 3528 // We should not encounter this bytecode if !EnableInvokeDynamic.
aoqi@0 3529 // The verifier will stop it. However, if we get past the verifier,
aoqi@0 3530 // this will stop the thread in a reasonable way, without crashing the JVM.
aoqi@0 3531 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
aoqi@0 3532 // The call_VM checks for exception, so we should never return here.
aoqi@0 3533 __ should_not_reach_here();
aoqi@0 3534 return;
aoqi@0 3535 }
aoqi@0 3536
aoqi@0 3537 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, noreg, Rflags, Rscratch2);
aoqi@0 3538
aoqi@0 3539 // Profile this call.
aoqi@0 3540 __ profile_call(Rscratch1, Rscratch2);
aoqi@0 3541
aoqi@0 3542 // Off we go. With the new method handles, we don't jump to a method handle
aoqi@0 3543 // entry any more. Instead, we pushed an "appendix" in prepare invoke, which happens
aoqi@0 3544 // to be the callsite object the bootstrap method returned. This is passed to a
aoqi@0 3545 // "link" method which does the dispatch (Most likely just grabs the MH stored
aoqi@0 3546 // inside the callsite and does an invokehandle).
goetz@7424 3547 // Argument and return type profiling.
goetz@7424 3548 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, false);
aoqi@0 3549 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */);
aoqi@0 3550 }
aoqi@0 3551
aoqi@0 3552 void TemplateTable::invokehandle(int byte_no) {
aoqi@0 3553 transition(vtos, vtos);
aoqi@0 3554
aoqi@0 3555 const Register Rret_addr = R3_ARG1,
aoqi@0 3556 Rflags = R4_ARG2,
aoqi@0 3557 Rrecv = R5_ARG3,
aoqi@0 3558 Rmethod = R22_tmp2,
aoqi@0 3559 Rscratch1 = R11_scratch1,
aoqi@0 3560 Rscratch2 = R12_scratch2;
aoqi@0 3561
aoqi@0 3562 if (!EnableInvokeDynamic) {
aoqi@0 3563 // Rewriter does not generate this bytecode.
aoqi@0 3564 __ should_not_reach_here();
aoqi@0 3565 return;
aoqi@0 3566 }
aoqi@0 3567
aoqi@0 3568 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, Rrecv, Rflags, Rscratch2);
aoqi@0 3569 __ verify_method_ptr(Rmethod);
aoqi@0 3570 __ null_check_throw(Rrecv, -1, Rscratch2);
aoqi@0 3571
aoqi@0 3572 __ profile_final_call(Rrecv, Rscratch1);
aoqi@0 3573
aoqi@0 3574 // Still no call from handle => We call the method handle interpreter here.
goetz@7424 3575 // Argument and return type profiling.
goetz@7424 3576 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, true);
aoqi@0 3577 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */);
aoqi@0 3578 }
aoqi@0 3579
aoqi@0 3580 // =============================================================================
aoqi@0 3581 // Allocation
aoqi@0 3582
aoqi@0 3583 // Puts allocated obj ref onto the expression stack.
aoqi@0 3584 void TemplateTable::_new() {
aoqi@0 3585 transition(vtos, atos);
aoqi@0 3586
aoqi@0 3587 Label Lslow_case,
aoqi@0 3588 Ldone,
aoqi@0 3589 Linitialize_header,
aoqi@0 3590 Lallocate_shared,
aoqi@0 3591 Linitialize_object; // Including clearing the fields.
aoqi@0 3592
aoqi@0 3593 const Register RallocatedObject = R17_tos,
aoqi@0 3594 RinstanceKlass = R9_ARG7,
aoqi@0 3595 Rscratch = R11_scratch1,
aoqi@0 3596 Roffset = R8_ARG6,
aoqi@0 3597 Rinstance_size = Roffset,
aoqi@0 3598 Rcpool = R4_ARG2,
aoqi@0 3599 Rtags = R3_ARG1,
aoqi@0 3600 Rindex = R5_ARG3;
aoqi@0 3601
aoqi@0 3602 const bool allow_shared_alloc = Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
aoqi@0 3603
aoqi@0 3604 // --------------------------------------------------------------------------
aoqi@0 3605 // Check if fast case is possible.
aoqi@0 3606
aoqi@0 3607 // Load pointers to const pool and const pool's tags array.
aoqi@0 3608 __ get_cpool_and_tags(Rcpool, Rtags);
aoqi@0 3609 // Load index of constant pool entry.
aoqi@0 3610 __ get_2_byte_integer_at_bcp(1, Rindex, InterpreterMacroAssembler::Unsigned);
aoqi@0 3611
aoqi@0 3612 if (UseTLAB) {
aoqi@0 3613 // Make sure the class we're about to instantiate has been resolved
aoqi@0 3614 // This is done before loading instanceKlass to be consistent with the order
aoqi@0 3615 // how Constant Pool is updated (see ConstantPoolCache::klass_at_put).
aoqi@0 3616 __ addi(Rtags, Rtags, Array<u1>::base_offset_in_bytes());
aoqi@0 3617 __ lbzx(Rtags, Rindex, Rtags);
aoqi@0 3618
aoqi@0 3619 __ cmpdi(CCR0, Rtags, JVM_CONSTANT_Class);
aoqi@0 3620 __ bne(CCR0, Lslow_case);
aoqi@0 3621
aoqi@0 3622 // Get instanceKlass (load from Rcpool + sizeof(ConstantPool) + Rindex*BytesPerWord).
aoqi@0 3623 __ sldi(Roffset, Rindex, LogBytesPerWord);
aoqi@0 3624 __ addi(Rscratch, Rcpool, sizeof(ConstantPool));
aoqi@0 3625 __ isync(); // Order load of instance Klass wrt. tags.
aoqi@0 3626 __ ldx(RinstanceKlass, Roffset, Rscratch);
aoqi@0 3627
aoqi@0 3628 // Make sure klass is fully initialized and get instance_size.
aoqi@0 3629 __ lbz(Rscratch, in_bytes(InstanceKlass::init_state_offset()), RinstanceKlass);
aoqi@0 3630 __ lwz(Rinstance_size, in_bytes(Klass::layout_helper_offset()), RinstanceKlass);
aoqi@0 3631
aoqi@0 3632 __ cmpdi(CCR1, Rscratch, InstanceKlass::fully_initialized);
aoqi@0 3633 // Make sure klass does not have has_finalizer, or is abstract, or interface or java/lang/Class.
aoqi@0 3634 __ andi_(R0, Rinstance_size, Klass::_lh_instance_slow_path_bit); // slow path bit equals 0?
aoqi@0 3635
aoqi@0 3636 __ crnand(/*CR0 eq*/2, /*CR1 eq*/4+2, /*CR0 eq*/2); // slow path bit set or not fully initialized?
aoqi@0 3637 __ beq(CCR0, Lslow_case);
aoqi@0 3638
aoqi@0 3639 // --------------------------------------------------------------------------
aoqi@0 3640 // Fast case:
aoqi@0 3641 // Allocate the instance.
aoqi@0 3642 // 1) Try to allocate in the TLAB.
aoqi@0 3643 // 2) If fail, and the TLAB is not full enough to discard, allocate in the shared Eden.
aoqi@0 3644 // 3) If the above fails (or is not applicable), go to a slow case (creates a new TLAB, etc.).
aoqi@0 3645
aoqi@0 3646 Register RoldTopValue = RallocatedObject; // Object will be allocated here if it fits.
aoqi@0 3647 Register RnewTopValue = R6_ARG4;
aoqi@0 3648 Register RendValue = R7_ARG5;
aoqi@0 3649
aoqi@0 3650 // Check if we can allocate in the TLAB.
aoqi@0 3651 __ ld(RoldTopValue, in_bytes(JavaThread::tlab_top_offset()), R16_thread);
aoqi@0 3652 __ ld(RendValue, in_bytes(JavaThread::tlab_end_offset()), R16_thread);
aoqi@0 3653
aoqi@0 3654 __ add(RnewTopValue, Rinstance_size, RoldTopValue);
aoqi@0 3655
aoqi@0 3656 // If there is enough space, we do not CAS and do not clear.
aoqi@0 3657 __ cmpld(CCR0, RnewTopValue, RendValue);
aoqi@0 3658 __ bgt(CCR0, allow_shared_alloc ? Lallocate_shared : Lslow_case);
aoqi@0 3659
aoqi@0 3660 __ std(RnewTopValue, in_bytes(JavaThread::tlab_top_offset()), R16_thread);
aoqi@0 3661
aoqi@0 3662 if (ZeroTLAB) {
aoqi@0 3663 // The fields have already been cleared.
aoqi@0 3664 __ b(Linitialize_header);
aoqi@0 3665 } else {
aoqi@0 3666 // Initialize both the header and fields.
aoqi@0 3667 __ b(Linitialize_object);
aoqi@0 3668 }
aoqi@0 3669
aoqi@0 3670 // Fall through: TLAB was too small.
aoqi@0 3671 if (allow_shared_alloc) {
aoqi@0 3672 Register RtlabWasteLimitValue = R10_ARG8;
aoqi@0 3673 Register RfreeValue = RnewTopValue;
aoqi@0 3674
aoqi@0 3675 __ bind(Lallocate_shared);
aoqi@0 3676 // Check if tlab should be discarded (refill_waste_limit >= free).
aoqi@0 3677 __ ld(RtlabWasteLimitValue, in_bytes(JavaThread::tlab_refill_waste_limit_offset()), R16_thread);
aoqi@0 3678 __ subf(RfreeValue, RoldTopValue, RendValue);
aoqi@0 3679 __ srdi(RfreeValue, RfreeValue, LogHeapWordSize); // in dwords
aoqi@0 3680 __ cmpld(CCR0, RtlabWasteLimitValue, RfreeValue);
aoqi@0 3681 __ bge(CCR0, Lslow_case);
aoqi@0 3682
aoqi@0 3683 // Increment waste limit to prevent getting stuck on this slow path.
aoqi@0 3684 __ addi(RtlabWasteLimitValue, RtlabWasteLimitValue, (int)ThreadLocalAllocBuffer::refill_waste_limit_increment());
aoqi@0 3685 __ std(RtlabWasteLimitValue, in_bytes(JavaThread::tlab_refill_waste_limit_offset()), R16_thread);
aoqi@0 3686 }
aoqi@0 3687 // else: No allocation in the shared eden. // fallthru: __ b(Lslow_case);
aoqi@0 3688 }
aoqi@0 3689 // else: Always go the slow path.
aoqi@0 3690
aoqi@0 3691 // --------------------------------------------------------------------------
aoqi@0 3692 // slow case
aoqi@0 3693 __ bind(Lslow_case);
aoqi@0 3694 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), Rcpool, Rindex);
aoqi@0 3695
aoqi@0 3696 if (UseTLAB) {
aoqi@0 3697 __ b(Ldone);
aoqi@0 3698 // --------------------------------------------------------------------------
aoqi@0 3699 // Init1: Zero out newly allocated memory.
aoqi@0 3700
aoqi@0 3701 if (!ZeroTLAB || allow_shared_alloc) {
aoqi@0 3702 // Clear object fields.
aoqi@0 3703 __ bind(Linitialize_object);
aoqi@0 3704
aoqi@0 3705 // Initialize remaining object fields.
aoqi@0 3706 Register Rbase = Rtags;
aoqi@0 3707 __ addi(Rinstance_size, Rinstance_size, 7 - (int)sizeof(oopDesc));
aoqi@0 3708 __ addi(Rbase, RallocatedObject, sizeof(oopDesc));
aoqi@0 3709 __ srdi(Rinstance_size, Rinstance_size, 3);
aoqi@0 3710
aoqi@0 3711 // Clear out object skipping header. Takes also care of the zero length case.
aoqi@0 3712 __ clear_memory_doubleword(Rbase, Rinstance_size);
aoqi@0 3713 // fallthru: __ b(Linitialize_header);
aoqi@0 3714 }
aoqi@0 3715
aoqi@0 3716 // --------------------------------------------------------------------------
aoqi@0 3717 // Init2: Initialize the header: mark, klass
aoqi@0 3718 __ bind(Linitialize_header);
aoqi@0 3719
aoqi@0 3720 // Init mark.
aoqi@0 3721 if (UseBiasedLocking) {
aoqi@0 3722 __ ld(Rscratch, in_bytes(Klass::prototype_header_offset()), RinstanceKlass);
aoqi@0 3723 } else {
aoqi@0 3724 __ load_const_optimized(Rscratch, markOopDesc::prototype(), R0);
aoqi@0 3725 }
aoqi@0 3726 __ std(Rscratch, oopDesc::mark_offset_in_bytes(), RallocatedObject);
aoqi@0 3727
aoqi@0 3728 // Init klass.
aoqi@0 3729 __ store_klass_gap(RallocatedObject);
aoqi@0 3730 __ store_klass(RallocatedObject, RinstanceKlass, Rscratch); // klass (last for cms)
aoqi@0 3731
aoqi@0 3732 // Check and trigger dtrace event.
aoqi@0 3733 {
aoqi@0 3734 SkipIfEqualZero skip_if(_masm, Rscratch, &DTraceAllocProbes);
aoqi@0 3735 __ push(atos);
aoqi@0 3736 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc));
aoqi@0 3737 __ pop(atos);
aoqi@0 3738 }
aoqi@0 3739 }
aoqi@0 3740
aoqi@0 3741 // continue
aoqi@0 3742 __ bind(Ldone);
aoqi@0 3743
aoqi@0 3744 // Must prevent reordering of stores for object initialization with stores that publish the new object.
aoqi@0 3745 __ membar(Assembler::StoreStore);
aoqi@0 3746 }
aoqi@0 3747
aoqi@0 3748 void TemplateTable::newarray() {
aoqi@0 3749 transition(itos, atos);
aoqi@0 3750
aoqi@0 3751 __ lbz(R4, 1, R14_bcp);
aoqi@0 3752 __ extsw(R5, R17_tos);
aoqi@0 3753 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), R4, R5 /* size */);
aoqi@0 3754
aoqi@0 3755 // Must prevent reordering of stores for object initialization with stores that publish the new object.
aoqi@0 3756 __ membar(Assembler::StoreStore);
aoqi@0 3757 }
aoqi@0 3758
aoqi@0 3759 void TemplateTable::anewarray() {
aoqi@0 3760 transition(itos, atos);
aoqi@0 3761
aoqi@0 3762 __ get_constant_pool(R4);
aoqi@0 3763 __ get_2_byte_integer_at_bcp(1, R5, InterpreterMacroAssembler::Unsigned);
aoqi@0 3764 __ extsw(R6, R17_tos); // size
aoqi@0 3765 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), R4 /* pool */, R5 /* index */, R6 /* size */);
aoqi@0 3766
aoqi@0 3767 // Must prevent reordering of stores for object initialization with stores that publish the new object.
aoqi@0 3768 __ membar(Assembler::StoreStore);
aoqi@0 3769 }
aoqi@0 3770
aoqi@0 3771 // Allocate a multi dimensional array
aoqi@0 3772 void TemplateTable::multianewarray() {
aoqi@0 3773 transition(vtos, atos);
aoqi@0 3774
aoqi@0 3775 Register Rptr = R31; // Needs to survive C call.
aoqi@0 3776
aoqi@0 3777 // Put ndims * wordSize into frame temp slot
aoqi@0 3778 __ lbz(Rptr, 3, R14_bcp);
aoqi@0 3779 __ sldi(Rptr, Rptr, Interpreter::logStackElementSize);
aoqi@0 3780 // Esp points past last_dim, so set to R4 to first_dim address.
aoqi@0 3781 __ add(R4, Rptr, R15_esp);
aoqi@0 3782 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), R4 /* first_size_address */);
aoqi@0 3783 // Pop all dimensions off the stack.
aoqi@0 3784 __ add(R15_esp, Rptr, R15_esp);
aoqi@0 3785
aoqi@0 3786 // Must prevent reordering of stores for object initialization with stores that publish the new object.
aoqi@0 3787 __ membar(Assembler::StoreStore);
aoqi@0 3788 }
aoqi@0 3789
aoqi@0 3790 void TemplateTable::arraylength() {
aoqi@0 3791 transition(atos, itos);
aoqi@0 3792
aoqi@0 3793 Label LnoException;
aoqi@0 3794 __ verify_oop(R17_tos);
aoqi@0 3795 __ null_check_throw(R17_tos, arrayOopDesc::length_offset_in_bytes(), R11_scratch1);
aoqi@0 3796 __ lwa(R17_tos, arrayOopDesc::length_offset_in_bytes(), R17_tos);
aoqi@0 3797 }
aoqi@0 3798
aoqi@0 3799 // ============================================================================
aoqi@0 3800 // Typechecks
aoqi@0 3801
aoqi@0 3802 void TemplateTable::checkcast() {
aoqi@0 3803 transition(atos, atos);
aoqi@0 3804
aoqi@0 3805 Label Ldone, Lis_null, Lquicked, Lresolved;
aoqi@0 3806 Register Roffset = R6_ARG4,
aoqi@0 3807 RobjKlass = R4_ARG2,
aoqi@0 3808 RspecifiedKlass = R5_ARG3, // Generate_ClassCastException_verbose_handler will read value from this register.
aoqi@0 3809 Rcpool = R11_scratch1,
aoqi@0 3810 Rtags = R12_scratch2;
aoqi@0 3811
aoqi@0 3812 // Null does not pass.
aoqi@0 3813 __ cmpdi(CCR0, R17_tos, 0);
aoqi@0 3814 __ beq(CCR0, Lis_null);
aoqi@0 3815
aoqi@0 3816 // Get constant pool tag to find out if the bytecode has already been "quickened".
aoqi@0 3817 __ get_cpool_and_tags(Rcpool, Rtags);
aoqi@0 3818
aoqi@0 3819 __ get_2_byte_integer_at_bcp(1, Roffset, InterpreterMacroAssembler::Unsigned);
aoqi@0 3820
aoqi@0 3821 __ addi(Rtags, Rtags, Array<u1>::base_offset_in_bytes());
aoqi@0 3822 __ lbzx(Rtags, Rtags, Roffset);
aoqi@0 3823
aoqi@0 3824 __ cmpdi(CCR0, Rtags, JVM_CONSTANT_Class);
aoqi@0 3825 __ beq(CCR0, Lquicked);
aoqi@0 3826
aoqi@0 3827 // Call into the VM to "quicken" instanceof.
aoqi@0 3828 __ push_ptr(); // for GC
aoqi@0 3829 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
aoqi@0 3830 __ get_vm_result_2(RspecifiedKlass);
aoqi@0 3831 __ pop_ptr(); // Restore receiver.
aoqi@0 3832 __ b(Lresolved);
aoqi@0 3833
aoqi@0 3834 // Extract target class from constant pool.
aoqi@0 3835 __ bind(Lquicked);
aoqi@0 3836 __ sldi(Roffset, Roffset, LogBytesPerWord);
aoqi@0 3837 __ addi(Rcpool, Rcpool, sizeof(ConstantPool));
aoqi@0 3838 __ isync(); // Order load of specified Klass wrt. tags.
aoqi@0 3839 __ ldx(RspecifiedKlass, Rcpool, Roffset);
aoqi@0 3840
aoqi@0 3841 // Do the checkcast.
aoqi@0 3842 __ bind(Lresolved);
aoqi@0 3843 // Get value klass in RobjKlass.
aoqi@0 3844 __ load_klass(RobjKlass, R17_tos);
aoqi@0 3845 // Generate a fast subtype check. Branch to cast_ok if no failure. Return 0 if failure.
aoqi@0 3846 __ gen_subtype_check(RobjKlass, RspecifiedKlass, /*3 temp regs*/ Roffset, Rcpool, Rtags, /*target if subtype*/ Ldone);
aoqi@0 3847
aoqi@0 3848 // Not a subtype; so must throw exception
aoqi@0 3849 // Target class oop is in register R6_ARG4 == RspecifiedKlass by convention.
aoqi@0 3850 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ClassCastException_entry);
aoqi@0 3851 __ mtctr(R11_scratch1);
aoqi@0 3852 __ bctr();
aoqi@0 3853
aoqi@0 3854 // Profile the null case.
aoqi@0 3855 __ align(32, 12);
aoqi@0 3856 __ bind(Lis_null);
aoqi@0 3857 __ profile_null_seen(R11_scratch1, Rtags); // Rtags used as scratch.
aoqi@0 3858
aoqi@0 3859 __ align(32, 12);
aoqi@0 3860 __ bind(Ldone);
aoqi@0 3861 }
aoqi@0 3862
aoqi@0 3863 // Output:
aoqi@0 3864 // - tos == 0: Obj was null or not an instance of class.
aoqi@0 3865 // - tos == 1: Obj was an instance of class.
aoqi@0 3866 void TemplateTable::instanceof() {
aoqi@0 3867 transition(atos, itos);
aoqi@0 3868
aoqi@0 3869 Label Ldone, Lis_null, Lquicked, Lresolved;
aoqi@0 3870 Register Roffset = R5_ARG3,
aoqi@0 3871 RobjKlass = R4_ARG2,
aoqi@0 3872 RspecifiedKlass = R6_ARG4, // Generate_ClassCastException_verbose_handler will expect the value in this register.
aoqi@0 3873 Rcpool = R11_scratch1,
aoqi@0 3874 Rtags = R12_scratch2;
aoqi@0 3875
aoqi@0 3876 // Null does not pass.
aoqi@0 3877 __ cmpdi(CCR0, R17_tos, 0);
aoqi@0 3878 __ beq(CCR0, Lis_null);
aoqi@0 3879
aoqi@0 3880 // Get constant pool tag to find out if the bytecode has already been "quickened".
aoqi@0 3881 __ get_cpool_and_tags(Rcpool, Rtags);
aoqi@0 3882
aoqi@0 3883 __ get_2_byte_integer_at_bcp(1, Roffset, InterpreterMacroAssembler::Unsigned);
aoqi@0 3884
aoqi@0 3885 __ addi(Rtags, Rtags, Array<u1>::base_offset_in_bytes());
aoqi@0 3886 __ lbzx(Rtags, Rtags, Roffset);
aoqi@0 3887
aoqi@0 3888 __ cmpdi(CCR0, Rtags, JVM_CONSTANT_Class);
aoqi@0 3889 __ beq(CCR0, Lquicked);
aoqi@0 3890
aoqi@0 3891 // Call into the VM to "quicken" instanceof.
aoqi@0 3892 __ push_ptr(); // for GC
aoqi@0 3893 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
aoqi@0 3894 __ get_vm_result_2(RspecifiedKlass);
aoqi@0 3895 __ pop_ptr(); // Restore receiver.
aoqi@0 3896 __ b(Lresolved);
aoqi@0 3897
aoqi@0 3898 // Extract target class from constant pool.
aoqi@0 3899 __ bind(Lquicked);
aoqi@0 3900 __ sldi(Roffset, Roffset, LogBytesPerWord);
aoqi@0 3901 __ addi(Rcpool, Rcpool, sizeof(ConstantPool));
aoqi@0 3902 __ isync(); // Order load of specified Klass wrt. tags.
aoqi@0 3903 __ ldx(RspecifiedKlass, Rcpool, Roffset);
aoqi@0 3904
aoqi@0 3905 // Do the checkcast.
aoqi@0 3906 __ bind(Lresolved);
aoqi@0 3907 // Get value klass in RobjKlass.
aoqi@0 3908 __ load_klass(RobjKlass, R17_tos);
aoqi@0 3909 // Generate a fast subtype check. Branch to cast_ok if no failure. Return 0 if failure.
aoqi@0 3910 __ li(R17_tos, 1);
aoqi@0 3911 __ gen_subtype_check(RobjKlass, RspecifiedKlass, /*3 temp regs*/ Roffset, Rcpool, Rtags, /*target if subtype*/ Ldone);
aoqi@0 3912 __ li(R17_tos, 0);
aoqi@0 3913
aoqi@0 3914 if (ProfileInterpreter) {
aoqi@0 3915 __ b(Ldone);
aoqi@0 3916 }
aoqi@0 3917
aoqi@0 3918 // Profile the null case.
aoqi@0 3919 __ align(32, 12);
aoqi@0 3920 __ bind(Lis_null);
aoqi@0 3921 __ profile_null_seen(Rcpool, Rtags); // Rcpool and Rtags used as scratch.
aoqi@0 3922
aoqi@0 3923 __ align(32, 12);
aoqi@0 3924 __ bind(Ldone);
aoqi@0 3925 }
aoqi@0 3926
aoqi@0 3927 // =============================================================================
aoqi@0 3928 // Breakpoints
aoqi@0 3929
aoqi@0 3930 void TemplateTable::_breakpoint() {
aoqi@0 3931 transition(vtos, vtos);
aoqi@0 3932
aoqi@0 3933 // Get the unpatched byte code.
aoqi@0 3934 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), R19_method, R14_bcp);
aoqi@0 3935 __ mr(R31, R3_RET);
aoqi@0 3936
aoqi@0 3937 // Post the breakpoint event.
aoqi@0 3938 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), R19_method, R14_bcp);
aoqi@0 3939
aoqi@0 3940 // Complete the execution of original bytecode.
aoqi@0 3941 __ dispatch_Lbyte_code(vtos, R31, Interpreter::normal_table(vtos));
aoqi@0 3942 }
aoqi@0 3943
aoqi@0 3944 // =============================================================================
aoqi@0 3945 // Exceptions
aoqi@0 3946
aoqi@0 3947 void TemplateTable::athrow() {
aoqi@0 3948 transition(atos, vtos);
aoqi@0 3949
aoqi@0 3950 // Exception oop is in tos
aoqi@0 3951 __ verify_oop(R17_tos);
aoqi@0 3952
aoqi@0 3953 __ null_check_throw(R17_tos, -1, R11_scratch1);
aoqi@0 3954
aoqi@0 3955 // Throw exception interpreter entry expects exception oop to be in R3.
aoqi@0 3956 __ mr(R3_RET, R17_tos);
aoqi@0 3957 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::throw_exception_entry());
aoqi@0 3958 __ mtctr(R11_scratch1);
aoqi@0 3959 __ bctr();
aoqi@0 3960 }
aoqi@0 3961
aoqi@0 3962 // =============================================================================
aoqi@0 3963 // Synchronization
aoqi@0 3964 // Searches the basic object lock list on the stack for a free slot
aoqi@0 3965 // and uses it to lock the obect in tos.
aoqi@0 3966 //
aoqi@0 3967 // Recursive locking is enabled by exiting the search if the same
aoqi@0 3968 // object is already found in the list. Thus, a new basic lock obj lock
aoqi@0 3969 // is allocated "higher up" in the stack and thus is found first
aoqi@0 3970 // at next monitor exit.
aoqi@0 3971 void TemplateTable::monitorenter() {
aoqi@0 3972 transition(atos, vtos);
aoqi@0 3973
aoqi@0 3974 __ verify_oop(R17_tos);
aoqi@0 3975
aoqi@0 3976 Register Rcurrent_monitor = R11_scratch1,
aoqi@0 3977 Rcurrent_obj = R12_scratch2,
aoqi@0 3978 Robj_to_lock = R17_tos,
aoqi@0 3979 Rscratch1 = R3_ARG1,
aoqi@0 3980 Rscratch2 = R4_ARG2,
aoqi@0 3981 Rscratch3 = R5_ARG3,
aoqi@0 3982 Rcurrent_obj_addr = R6_ARG4;
aoqi@0 3983
aoqi@0 3984 // ------------------------------------------------------------------------------
aoqi@0 3985 // Null pointer exception.
aoqi@0 3986 __ null_check_throw(Robj_to_lock, -1, R11_scratch1);
aoqi@0 3987
aoqi@0 3988 // Try to acquire a lock on the object.
aoqi@0 3989 // Repeat until succeeded (i.e., until monitorenter returns true).
aoqi@0 3990
aoqi@0 3991 // ------------------------------------------------------------------------------
aoqi@0 3992 // Find a free slot in the monitor block.
aoqi@0 3993 Label Lfound, Lexit, Lallocate_new;
aoqi@0 3994 ConditionRegister found_free_slot = CCR0,
aoqi@0 3995 found_same_obj = CCR1,
aoqi@0 3996 reached_limit = CCR6;
aoqi@0 3997 {
aoqi@0 3998 Label Lloop, Lentry;
aoqi@0 3999 Register Rlimit = Rcurrent_monitor;
aoqi@0 4000
aoqi@0 4001 // Set up search loop - start with topmost monitor.
aoqi@0 4002 __ add(Rcurrent_obj_addr, BasicObjectLock::obj_offset_in_bytes(), R26_monitor);
aoqi@0 4003
aoqi@0 4004 __ ld(Rlimit, 0, R1_SP);
aoqi@0 4005 __ addi(Rlimit, Rlimit, - (frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes() - BasicObjectLock::obj_offset_in_bytes())); // Monitor base
aoqi@0 4006
aoqi@0 4007 // Check if any slot is present => short cut to allocation if not.
aoqi@0 4008 __ cmpld(reached_limit, Rcurrent_obj_addr, Rlimit);
aoqi@0 4009 __ bgt(reached_limit, Lallocate_new);
aoqi@0 4010
aoqi@0 4011 // Pre-load topmost slot.
aoqi@0 4012 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
aoqi@0 4013 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 4014 // The search loop.
aoqi@0 4015 __ bind(Lloop);
aoqi@0 4016 // Found free slot?
aoqi@0 4017 __ cmpdi(found_free_slot, Rcurrent_obj, 0);
aoqi@0 4018 // Is this entry for same obj? If so, stop the search and take the found
aoqi@0 4019 // free slot or allocate a new one to enable recursive locking.
aoqi@0 4020 __ cmpd(found_same_obj, Rcurrent_obj, Robj_to_lock);
aoqi@0 4021 __ cmpld(reached_limit, Rcurrent_obj_addr, Rlimit);
aoqi@0 4022 __ beq(found_free_slot, Lexit);
aoqi@0 4023 __ beq(found_same_obj, Lallocate_new);
aoqi@0 4024 __ bgt(reached_limit, Lallocate_new);
aoqi@0 4025 // Check if last allocated BasicLockObj reached.
aoqi@0 4026 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
aoqi@0 4027 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 4028 // Next iteration if unchecked BasicObjectLocks exist on the stack.
aoqi@0 4029 __ b(Lloop);
aoqi@0 4030 }
aoqi@0 4031
aoqi@0 4032 // ------------------------------------------------------------------------------
aoqi@0 4033 // Check if we found a free slot.
aoqi@0 4034 __ bind(Lexit);
aoqi@0 4035
aoqi@0 4036 __ addi(Rcurrent_monitor, Rcurrent_obj_addr, -(frame::interpreter_frame_monitor_size() * wordSize) - BasicObjectLock::obj_offset_in_bytes());
aoqi@0 4037 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, - frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 4038 __ b(Lfound);
aoqi@0 4039
aoqi@0 4040 // We didn't find a free BasicObjLock => allocate one.
aoqi@0 4041 __ align(32, 12);
aoqi@0 4042 __ bind(Lallocate_new);
aoqi@0 4043 __ add_monitor_to_stack(false, Rscratch1, Rscratch2);
aoqi@0 4044 __ mr(Rcurrent_monitor, R26_monitor);
aoqi@0 4045 __ addi(Rcurrent_obj_addr, R26_monitor, BasicObjectLock::obj_offset_in_bytes());
aoqi@0 4046
aoqi@0 4047 // ------------------------------------------------------------------------------
aoqi@0 4048 // We now have a slot to lock.
aoqi@0 4049 __ bind(Lfound);
aoqi@0 4050
aoqi@0 4051 // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
aoqi@0 4052 // The object has already been poped from the stack, so the expression stack looks correct.
aoqi@0 4053 __ addi(R14_bcp, R14_bcp, 1);
aoqi@0 4054
aoqi@0 4055 __ std(Robj_to_lock, 0, Rcurrent_obj_addr);
aoqi@0 4056 __ lock_object(Rcurrent_monitor, Robj_to_lock);
aoqi@0 4057
aoqi@0 4058 // Check if there's enough space on the stack for the monitors after locking.
aoqi@0 4059 Label Lskip_stack_check;
aoqi@0 4060 // Optimization: If the monitors stack section is less then a std page size (4K) don't run
aoqi@0 4061 // the stack check. There should be enough shadow pages to fit that in.
aoqi@0 4062 __ ld(Rscratch3, 0, R1_SP);
aoqi@0 4063 __ sub(Rscratch3, Rscratch3, R26_monitor);
aoqi@0 4064 __ cmpdi(CCR0, Rscratch3, 4*K);
aoqi@0 4065 __ blt(CCR0, Lskip_stack_check);
aoqi@0 4066
aoqi@0 4067 DEBUG_ONLY(__ untested("stack overflow check during monitor enter");)
aoqi@0 4068 __ li(Rscratch1, 0);
aoqi@0 4069 __ generate_stack_overflow_check_with_compare_and_throw(Rscratch1, Rscratch2);
aoqi@0 4070
aoqi@0 4071 __ align(32, 12);
aoqi@0 4072 __ bind(Lskip_stack_check);
aoqi@0 4073
aoqi@0 4074 // The bcp has already been incremented. Just need to dispatch to next instruction.
aoqi@0 4075 __ dispatch_next(vtos);
aoqi@0 4076 }
aoqi@0 4077
aoqi@0 4078 void TemplateTable::monitorexit() {
aoqi@0 4079 transition(atos, vtos);
aoqi@0 4080 __ verify_oop(R17_tos);
aoqi@0 4081
aoqi@0 4082 Register Rcurrent_monitor = R11_scratch1,
aoqi@0 4083 Rcurrent_obj = R12_scratch2,
aoqi@0 4084 Robj_to_lock = R17_tos,
aoqi@0 4085 Rcurrent_obj_addr = R3_ARG1,
aoqi@0 4086 Rlimit = R4_ARG2;
aoqi@0 4087 Label Lfound, Lillegal_monitor_state;
aoqi@0 4088
aoqi@0 4089 // Check corner case: unbalanced monitorEnter / Exit.
aoqi@0 4090 __ ld(Rlimit, 0, R1_SP);
aoqi@0 4091 __ addi(Rlimit, Rlimit, - (frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base
aoqi@0 4092
aoqi@0 4093 // Null pointer check.
aoqi@0 4094 __ null_check_throw(Robj_to_lock, -1, R11_scratch1);
aoqi@0 4095
aoqi@0 4096 __ cmpld(CCR0, R26_monitor, Rlimit);
aoqi@0 4097 __ bgt(CCR0, Lillegal_monitor_state);
aoqi@0 4098
aoqi@0 4099 // Find the corresponding slot in the monitors stack section.
aoqi@0 4100 {
aoqi@0 4101 Label Lloop;
aoqi@0 4102
aoqi@0 4103 // Start with topmost monitor.
aoqi@0 4104 __ addi(Rcurrent_obj_addr, R26_monitor, BasicObjectLock::obj_offset_in_bytes());
aoqi@0 4105 __ addi(Rlimit, Rlimit, BasicObjectLock::obj_offset_in_bytes());
aoqi@0 4106 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
aoqi@0 4107 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 4108
aoqi@0 4109 __ bind(Lloop);
aoqi@0 4110 // Is this entry for same obj?
aoqi@0 4111 __ cmpd(CCR0, Rcurrent_obj, Robj_to_lock);
aoqi@0 4112 __ beq(CCR0, Lfound);
aoqi@0 4113
aoqi@0 4114 // Check if last allocated BasicLockObj reached.
aoqi@0 4115
aoqi@0 4116 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
aoqi@0 4117 __ cmpld(CCR0, Rcurrent_obj_addr, Rlimit);
aoqi@0 4118 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 4119
aoqi@0 4120 // Next iteration if unchecked BasicObjectLocks exist on the stack.
aoqi@0 4121 __ ble(CCR0, Lloop);
aoqi@0 4122 }
aoqi@0 4123
aoqi@0 4124 // Fell through without finding the basic obj lock => throw up!
aoqi@0 4125 __ bind(Lillegal_monitor_state);
aoqi@0 4126 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
aoqi@0 4127 __ should_not_reach_here();
aoqi@0 4128
aoqi@0 4129 __ align(32, 12);
aoqi@0 4130 __ bind(Lfound);
aoqi@0 4131 __ addi(Rcurrent_monitor, Rcurrent_obj_addr,
aoqi@0 4132 -(frame::interpreter_frame_monitor_size() * wordSize) - BasicObjectLock::obj_offset_in_bytes());
aoqi@0 4133 __ unlock_object(Rcurrent_monitor);
aoqi@0 4134 }
aoqi@0 4135
aoqi@0 4136 // ============================================================================
aoqi@0 4137 // Wide bytecodes
aoqi@0 4138
aoqi@0 4139 // Wide instructions. Simply redirects to the wide entry point for that instruction.
aoqi@0 4140 void TemplateTable::wide() {
aoqi@0 4141 transition(vtos, vtos);
aoqi@0 4142
aoqi@0 4143 const Register Rtable = R11_scratch1,
aoqi@0 4144 Rindex = R12_scratch2,
aoqi@0 4145 Rtmp = R0;
aoqi@0 4146
aoqi@0 4147 __ lbz(Rindex, 1, R14_bcp);
aoqi@0 4148
aoqi@0 4149 __ load_dispatch_table(Rtable, Interpreter::_wentry_point);
aoqi@0 4150
aoqi@0 4151 __ slwi(Rindex, Rindex, LogBytesPerWord);
aoqi@0 4152 __ ldx(Rtmp, Rtable, Rindex);
aoqi@0 4153 __ mtctr(Rtmp);
aoqi@0 4154 __ bctr();
aoqi@0 4155 // Note: the bcp increment step is part of the individual wide bytecode implementations.
aoqi@0 4156 }
aoqi@0 4157 #endif // !CC_INTERP

mercurial