src/cpu/x86/vm/templateTable_x86_32.cpp

Mon, 28 May 2018 10:33:52 +0800

author
aoqi
date
Mon, 28 May 2018 10:33:52 +0800
changeset 9041
95a08233f46c
parent 8997
f8a45a60bc6b
parent 8604
04d83ba48607
child 9637
eef07cd490d4
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
dbuck@8997 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "asm/macroAssembler.hpp"
aoqi@0 27 #include "interpreter/interpreter.hpp"
aoqi@0 28 #include "interpreter/interpreterRuntime.hpp"
aoqi@0 29 #include "interpreter/templateTable.hpp"
aoqi@0 30 #include "memory/universe.inline.hpp"
aoqi@0 31 #include "oops/methodData.hpp"
aoqi@0 32 #include "oops/objArrayKlass.hpp"
aoqi@0 33 #include "oops/oop.inline.hpp"
aoqi@0 34 #include "prims/methodHandles.hpp"
aoqi@0 35 #include "runtime/sharedRuntime.hpp"
aoqi@0 36 #include "runtime/stubRoutines.hpp"
aoqi@0 37 #include "runtime/synchronizer.hpp"
aoqi@0 38 #include "utilities/macros.hpp"
aoqi@0 39
aoqi@0 40 #ifndef CC_INTERP
aoqi@0 41 #define __ _masm->
aoqi@0 42
aoqi@0 43 //----------------------------------------------------------------------------------------------------
aoqi@0 44 // Platform-dependent initialization
aoqi@0 45
aoqi@0 46 void TemplateTable::pd_initialize() {
aoqi@0 47 // No i486 specific initialization
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 //----------------------------------------------------------------------------------------------------
aoqi@0 51 // Address computation
aoqi@0 52
aoqi@0 53 // local variables
aoqi@0 54 static inline Address iaddress(int n) {
aoqi@0 55 return Address(rdi, Interpreter::local_offset_in_bytes(n));
aoqi@0 56 }
aoqi@0 57
aoqi@0 58 static inline Address laddress(int n) { return iaddress(n + 1); }
aoqi@0 59 static inline Address haddress(int n) { return iaddress(n + 0); }
aoqi@0 60 static inline Address faddress(int n) { return iaddress(n); }
aoqi@0 61 static inline Address daddress(int n) { return laddress(n); }
aoqi@0 62 static inline Address aaddress(int n) { return iaddress(n); }
aoqi@0 63
aoqi@0 64 static inline Address iaddress(Register r) {
aoqi@0 65 return Address(rdi, r, Interpreter::stackElementScale());
aoqi@0 66 }
aoqi@0 67 static inline Address laddress(Register r) {
aoqi@0 68 return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(1));
aoqi@0 69 }
aoqi@0 70 static inline Address haddress(Register r) {
aoqi@0 71 return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(0));
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 static inline Address faddress(Register r) { return iaddress(r); }
aoqi@0 75 static inline Address daddress(Register r) { return laddress(r); }
aoqi@0 76 static inline Address aaddress(Register r) { return iaddress(r); }
aoqi@0 77
aoqi@0 78 // expression stack
aoqi@0 79 // (Note: Must not use symmetric equivalents at_rsp_m1/2 since they store
aoqi@0 80 // data beyond the rsp which is potentially unsafe in an MT environment;
aoqi@0 81 // an interrupt may overwrite that data.)
aoqi@0 82 static inline Address at_rsp () {
aoqi@0 83 return Address(rsp, 0);
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 // At top of Java expression stack which may be different than rsp(). It
aoqi@0 87 // isn't for category 1 objects.
aoqi@0 88 static inline Address at_tos () {
aoqi@0 89 Address tos = Address(rsp, Interpreter::expr_offset_in_bytes(0));
aoqi@0 90 return tos;
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 static inline Address at_tos_p1() {
aoqi@0 94 return Address(rsp, Interpreter::expr_offset_in_bytes(1));
aoqi@0 95 }
aoqi@0 96
aoqi@0 97 static inline Address at_tos_p2() {
aoqi@0 98 return Address(rsp, Interpreter::expr_offset_in_bytes(2));
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 // Condition conversion
aoqi@0 102 static Assembler::Condition j_not(TemplateTable::Condition cc) {
aoqi@0 103 switch (cc) {
aoqi@0 104 case TemplateTable::equal : return Assembler::notEqual;
aoqi@0 105 case TemplateTable::not_equal : return Assembler::equal;
aoqi@0 106 case TemplateTable::less : return Assembler::greaterEqual;
aoqi@0 107 case TemplateTable::less_equal : return Assembler::greater;
aoqi@0 108 case TemplateTable::greater : return Assembler::lessEqual;
aoqi@0 109 case TemplateTable::greater_equal: return Assembler::less;
aoqi@0 110 }
aoqi@0 111 ShouldNotReachHere();
aoqi@0 112 return Assembler::zero;
aoqi@0 113 }
aoqi@0 114
aoqi@0 115
aoqi@0 116 //----------------------------------------------------------------------------------------------------
aoqi@0 117 // Miscelaneous helper routines
aoqi@0 118
aoqi@0 119 // Store an oop (or NULL) at the address described by obj.
aoqi@0 120 // If val == noreg this means store a NULL
aoqi@0 121
aoqi@0 122 static void do_oop_store(InterpreterMacroAssembler* _masm,
aoqi@0 123 Address obj,
aoqi@0 124 Register val,
aoqi@0 125 BarrierSet::Name barrier,
aoqi@0 126 bool precise) {
aoqi@0 127 assert(val == noreg || val == rax, "parameter is just for looks");
aoqi@0 128 switch (barrier) {
aoqi@0 129 #if INCLUDE_ALL_GCS
aoqi@0 130 case BarrierSet::G1SATBCT:
aoqi@0 131 case BarrierSet::G1SATBCTLogging:
aoqi@0 132 {
aoqi@0 133 // flatten object address if needed
aoqi@0 134 // We do it regardless of precise because we need the registers
aoqi@0 135 if (obj.index() == noreg && obj.disp() == 0) {
aoqi@0 136 if (obj.base() != rdx) {
aoqi@0 137 __ movl(rdx, obj.base());
aoqi@0 138 }
aoqi@0 139 } else {
aoqi@0 140 __ leal(rdx, obj);
aoqi@0 141 }
aoqi@0 142 __ get_thread(rcx);
aoqi@0 143 __ save_bcp();
aoqi@0 144 __ g1_write_barrier_pre(rdx /* obj */,
aoqi@0 145 rbx /* pre_val */,
aoqi@0 146 rcx /* thread */,
aoqi@0 147 rsi /* tmp */,
aoqi@0 148 val != noreg /* tosca_live */,
aoqi@0 149 false /* expand_call */);
aoqi@0 150
aoqi@0 151 // Do the actual store
aoqi@0 152 // noreg means NULL
aoqi@0 153 if (val == noreg) {
aoqi@0 154 __ movptr(Address(rdx, 0), NULL_WORD);
aoqi@0 155 // No post barrier for NULL
aoqi@0 156 } else {
aoqi@0 157 __ movl(Address(rdx, 0), val);
aoqi@0 158 __ g1_write_barrier_post(rdx /* store_adr */,
aoqi@0 159 val /* new_val */,
aoqi@0 160 rcx /* thread */,
aoqi@0 161 rbx /* tmp */,
aoqi@0 162 rsi /* tmp2 */);
aoqi@0 163 }
aoqi@0 164 __ restore_bcp();
aoqi@0 165
aoqi@0 166 }
aoqi@0 167 break;
aoqi@0 168 #endif // INCLUDE_ALL_GCS
aoqi@0 169 case BarrierSet::CardTableModRef:
aoqi@0 170 case BarrierSet::CardTableExtension:
aoqi@0 171 {
aoqi@0 172 if (val == noreg) {
aoqi@0 173 __ movptr(obj, NULL_WORD);
aoqi@0 174 } else {
aoqi@0 175 __ movl(obj, val);
aoqi@0 176 // flatten object address if needed
aoqi@0 177 if (!precise || (obj.index() == noreg && obj.disp() == 0)) {
aoqi@0 178 __ store_check(obj.base());
aoqi@0 179 } else {
aoqi@0 180 __ leal(rdx, obj);
aoqi@0 181 __ store_check(rdx);
aoqi@0 182 }
aoqi@0 183 }
aoqi@0 184 }
aoqi@0 185 break;
aoqi@0 186 case BarrierSet::ModRef:
aoqi@0 187 case BarrierSet::Other:
aoqi@0 188 if (val == noreg) {
aoqi@0 189 __ movptr(obj, NULL_WORD);
aoqi@0 190 } else {
aoqi@0 191 __ movl(obj, val);
aoqi@0 192 }
aoqi@0 193 break;
aoqi@0 194 default :
aoqi@0 195 ShouldNotReachHere();
aoqi@0 196
aoqi@0 197 }
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 Address TemplateTable::at_bcp(int offset) {
aoqi@0 201 assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
aoqi@0 202 return Address(rsi, offset);
aoqi@0 203 }
aoqi@0 204
aoqi@0 205
aoqi@0 206 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
aoqi@0 207 Register temp_reg, bool load_bc_into_bc_reg/*=true*/,
aoqi@0 208 int byte_no) {
aoqi@0 209 if (!RewriteBytecodes) return;
aoqi@0 210 Label L_patch_done;
aoqi@0 211
aoqi@0 212 switch (bc) {
aoqi@0 213 case Bytecodes::_fast_aputfield:
aoqi@0 214 case Bytecodes::_fast_bputfield:
kevinw@8368 215 case Bytecodes::_fast_zputfield:
aoqi@0 216 case Bytecodes::_fast_cputfield:
aoqi@0 217 case Bytecodes::_fast_dputfield:
aoqi@0 218 case Bytecodes::_fast_fputfield:
aoqi@0 219 case Bytecodes::_fast_iputfield:
aoqi@0 220 case Bytecodes::_fast_lputfield:
aoqi@0 221 case Bytecodes::_fast_sputfield:
aoqi@0 222 {
aoqi@0 223 // We skip bytecode quickening for putfield instructions when
aoqi@0 224 // the put_code written to the constant pool cache is zero.
aoqi@0 225 // This is required so that every execution of this instruction
aoqi@0 226 // calls out to InterpreterRuntime::resolve_get_put to do
aoqi@0 227 // additional, required work.
aoqi@0 228 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
aoqi@0 229 assert(load_bc_into_bc_reg, "we use bc_reg as temp");
aoqi@0 230 __ get_cache_and_index_and_bytecode_at_bcp(bc_reg, temp_reg, temp_reg, byte_no, 1);
aoqi@0 231 __ movl(bc_reg, bc);
aoqi@0 232 __ cmpl(temp_reg, (int) 0);
aoqi@0 233 __ jcc(Assembler::zero, L_patch_done); // don't patch
aoqi@0 234 }
aoqi@0 235 break;
aoqi@0 236 default:
aoqi@0 237 assert(byte_no == -1, "sanity");
aoqi@0 238 // the pair bytecodes have already done the load.
aoqi@0 239 if (load_bc_into_bc_reg) {
aoqi@0 240 __ movl(bc_reg, bc);
aoqi@0 241 }
aoqi@0 242 }
aoqi@0 243
aoqi@0 244 if (JvmtiExport::can_post_breakpoint()) {
aoqi@0 245 Label L_fast_patch;
aoqi@0 246 // if a breakpoint is present we can't rewrite the stream directly
aoqi@0 247 __ movzbl(temp_reg, at_bcp(0));
aoqi@0 248 __ cmpl(temp_reg, Bytecodes::_breakpoint);
aoqi@0 249 __ jcc(Assembler::notEqual, L_fast_patch);
aoqi@0 250 __ get_method(temp_reg);
aoqi@0 251 // Let breakpoint table handling rewrite to quicker bytecode
aoqi@0 252 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), temp_reg, rsi, bc_reg);
aoqi@0 253 #ifndef ASSERT
aoqi@0 254 __ jmpb(L_patch_done);
aoqi@0 255 #else
aoqi@0 256 __ jmp(L_patch_done);
aoqi@0 257 #endif
aoqi@0 258 __ bind(L_fast_patch);
aoqi@0 259 }
aoqi@0 260
aoqi@0 261 #ifdef ASSERT
aoqi@0 262 Label L_okay;
aoqi@0 263 __ load_unsigned_byte(temp_reg, at_bcp(0));
aoqi@0 264 __ cmpl(temp_reg, (int)Bytecodes::java_code(bc));
aoqi@0 265 __ jccb(Assembler::equal, L_okay);
aoqi@0 266 __ cmpl(temp_reg, bc_reg);
aoqi@0 267 __ jcc(Assembler::equal, L_okay);
aoqi@0 268 __ stop("patching the wrong bytecode");
aoqi@0 269 __ bind(L_okay);
aoqi@0 270 #endif
aoqi@0 271
aoqi@0 272 // patch bytecode
aoqi@0 273 __ movb(at_bcp(0), bc_reg);
aoqi@0 274 __ bind(L_patch_done);
aoqi@0 275 }
aoqi@0 276
aoqi@0 277 //----------------------------------------------------------------------------------------------------
aoqi@0 278 // Individual instructions
aoqi@0 279
aoqi@0 280 void TemplateTable::nop() {
aoqi@0 281 transition(vtos, vtos);
aoqi@0 282 // nothing to do
aoqi@0 283 }
aoqi@0 284
aoqi@0 285 void TemplateTable::shouldnotreachhere() {
aoqi@0 286 transition(vtos, vtos);
aoqi@0 287 __ stop("shouldnotreachhere bytecode");
aoqi@0 288 }
aoqi@0 289
aoqi@0 290
aoqi@0 291
aoqi@0 292 void TemplateTable::aconst_null() {
aoqi@0 293 transition(vtos, atos);
aoqi@0 294 __ xorptr(rax, rax);
aoqi@0 295 }
aoqi@0 296
aoqi@0 297
aoqi@0 298 void TemplateTable::iconst(int value) {
aoqi@0 299 transition(vtos, itos);
aoqi@0 300 if (value == 0) {
aoqi@0 301 __ xorptr(rax, rax);
aoqi@0 302 } else {
aoqi@0 303 __ movptr(rax, value);
aoqi@0 304 }
aoqi@0 305 }
aoqi@0 306
aoqi@0 307
aoqi@0 308 void TemplateTable::lconst(int value) {
aoqi@0 309 transition(vtos, ltos);
aoqi@0 310 if (value == 0) {
aoqi@0 311 __ xorptr(rax, rax);
aoqi@0 312 } else {
aoqi@0 313 __ movptr(rax, value);
aoqi@0 314 }
aoqi@0 315 assert(value >= 0, "check this code");
aoqi@0 316 __ xorptr(rdx, rdx);
aoqi@0 317 }
aoqi@0 318
aoqi@0 319
aoqi@0 320 void TemplateTable::fconst(int value) {
aoqi@0 321 transition(vtos, ftos);
aoqi@0 322 if (value == 0) { __ fldz();
aoqi@0 323 } else if (value == 1) { __ fld1();
aoqi@0 324 } else if (value == 2) { __ fld1(); __ fld1(); __ faddp(); // should do a better solution here
aoqi@0 325 } else { ShouldNotReachHere();
aoqi@0 326 }
aoqi@0 327 }
aoqi@0 328
aoqi@0 329
aoqi@0 330 void TemplateTable::dconst(int value) {
aoqi@0 331 transition(vtos, dtos);
aoqi@0 332 if (value == 0) { __ fldz();
aoqi@0 333 } else if (value == 1) { __ fld1();
aoqi@0 334 } else { ShouldNotReachHere();
aoqi@0 335 }
aoqi@0 336 }
aoqi@0 337
aoqi@0 338
aoqi@0 339 void TemplateTable::bipush() {
aoqi@0 340 transition(vtos, itos);
aoqi@0 341 __ load_signed_byte(rax, at_bcp(1));
aoqi@0 342 }
aoqi@0 343
aoqi@0 344
aoqi@0 345 void TemplateTable::sipush() {
aoqi@0 346 transition(vtos, itos);
aoqi@0 347 __ load_unsigned_short(rax, at_bcp(1));
aoqi@0 348 __ bswapl(rax);
aoqi@0 349 __ sarl(rax, 16);
aoqi@0 350 }
aoqi@0 351
aoqi@0 352 void TemplateTable::ldc(bool wide) {
aoqi@0 353 transition(vtos, vtos);
aoqi@0 354 Label call_ldc, notFloat, notClass, Done;
aoqi@0 355
aoqi@0 356 if (wide) {
aoqi@0 357 __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
aoqi@0 358 } else {
aoqi@0 359 __ load_unsigned_byte(rbx, at_bcp(1));
aoqi@0 360 }
aoqi@0 361 __ get_cpool_and_tags(rcx, rax);
aoqi@0 362 const int base_offset = ConstantPool::header_size() * wordSize;
aoqi@0 363 const int tags_offset = Array<u1>::base_offset_in_bytes();
aoqi@0 364
aoqi@0 365 // get type
aoqi@0 366 __ xorptr(rdx, rdx);
aoqi@0 367 __ movb(rdx, Address(rax, rbx, Address::times_1, tags_offset));
aoqi@0 368
aoqi@0 369 // unresolved class - get the resolved class
aoqi@0 370 __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass);
aoqi@0 371 __ jccb(Assembler::equal, call_ldc);
aoqi@0 372
aoqi@0 373 // unresolved class in error (resolution failed) - call into runtime
aoqi@0 374 // so that the same error from first resolution attempt is thrown.
aoqi@0 375 __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError);
aoqi@0 376 __ jccb(Assembler::equal, call_ldc);
aoqi@0 377
aoqi@0 378 // resolved class - need to call vm to get java mirror of the class
aoqi@0 379 __ cmpl(rdx, JVM_CONSTANT_Class);
aoqi@0 380 __ jcc(Assembler::notEqual, notClass);
aoqi@0 381
aoqi@0 382 __ bind(call_ldc);
aoqi@0 383 __ movl(rcx, wide);
aoqi@0 384 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rcx);
aoqi@0 385 __ push(atos);
aoqi@0 386 __ jmp(Done);
aoqi@0 387
aoqi@0 388 __ bind(notClass);
aoqi@0 389 __ cmpl(rdx, JVM_CONSTANT_Float);
aoqi@0 390 __ jccb(Assembler::notEqual, notFloat);
aoqi@0 391 // ftos
aoqi@0 392 __ fld_s( Address(rcx, rbx, Address::times_ptr, base_offset));
aoqi@0 393 __ push(ftos);
aoqi@0 394 __ jmp(Done);
aoqi@0 395
aoqi@0 396 __ bind(notFloat);
aoqi@0 397 #ifdef ASSERT
aoqi@0 398 { Label L;
aoqi@0 399 __ cmpl(rdx, JVM_CONSTANT_Integer);
aoqi@0 400 __ jcc(Assembler::equal, L);
aoqi@0 401 // String and Object are rewritten to fast_aldc
aoqi@0 402 __ stop("unexpected tag type in ldc");
aoqi@0 403 __ bind(L);
aoqi@0 404 }
aoqi@0 405 #endif
aoqi@0 406 // itos JVM_CONSTANT_Integer only
aoqi@0 407 __ movl(rax, Address(rcx, rbx, Address::times_ptr, base_offset));
aoqi@0 408 __ push(itos);
aoqi@0 409 __ bind(Done);
aoqi@0 410 }
aoqi@0 411
aoqi@0 412 // Fast path for caching oop constants.
aoqi@0 413 void TemplateTable::fast_aldc(bool wide) {
aoqi@0 414 transition(vtos, atos);
aoqi@0 415
aoqi@0 416 Register result = rax;
aoqi@0 417 Register tmp = rdx;
aoqi@0 418 int index_size = wide ? sizeof(u2) : sizeof(u1);
aoqi@0 419
aoqi@0 420 Label resolved;
aoqi@0 421
aoqi@0 422 // We are resolved if the resolved reference cache entry contains a
aoqi@0 423 // non-null object (String, MethodType, etc.)
aoqi@0 424 assert_different_registers(result, tmp);
aoqi@0 425 __ get_cache_index_at_bcp(tmp, 1, index_size);
aoqi@0 426 __ load_resolved_reference_at_index(result, tmp);
aoqi@0 427 __ testl(result, result);
aoqi@0 428 __ jcc(Assembler::notZero, resolved);
aoqi@0 429
aoqi@0 430 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);
aoqi@0 431
aoqi@0 432 // first time invocation - must resolve first
aoqi@0 433 __ movl(tmp, (int)bytecode());
aoqi@0 434 __ call_VM(result, entry, tmp);
aoqi@0 435
aoqi@0 436 __ bind(resolved);
aoqi@0 437
aoqi@0 438 if (VerifyOops) {
aoqi@0 439 __ verify_oop(result);
aoqi@0 440 }
aoqi@0 441 }
aoqi@0 442
aoqi@0 443 void TemplateTable::ldc2_w() {
aoqi@0 444 transition(vtos, vtos);
aoqi@0 445 Label Long, Done;
aoqi@0 446 __ get_unsigned_2_byte_index_at_bcp(rbx, 1);
aoqi@0 447
aoqi@0 448 __ get_cpool_and_tags(rcx, rax);
aoqi@0 449 const int base_offset = ConstantPool::header_size() * wordSize;
aoqi@0 450 const int tags_offset = Array<u1>::base_offset_in_bytes();
aoqi@0 451
aoqi@0 452 // get type
aoqi@0 453 __ cmpb(Address(rax, rbx, Address::times_1, tags_offset), JVM_CONSTANT_Double);
aoqi@0 454 __ jccb(Assembler::notEqual, Long);
aoqi@0 455 // dtos
aoqi@0 456 __ fld_d( Address(rcx, rbx, Address::times_ptr, base_offset));
aoqi@0 457 __ push(dtos);
aoqi@0 458 __ jmpb(Done);
aoqi@0 459
aoqi@0 460 __ bind(Long);
aoqi@0 461 // ltos
aoqi@0 462 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset + 0 * wordSize));
aoqi@0 463 NOT_LP64(__ movptr(rdx, Address(rcx, rbx, Address::times_ptr, base_offset + 1 * wordSize)));
aoqi@0 464
aoqi@0 465 __ push(ltos);
aoqi@0 466
aoqi@0 467 __ bind(Done);
aoqi@0 468 }
aoqi@0 469
aoqi@0 470
aoqi@0 471 void TemplateTable::locals_index(Register reg, int offset) {
aoqi@0 472 __ load_unsigned_byte(reg, at_bcp(offset));
aoqi@0 473 __ negptr(reg);
aoqi@0 474 }
aoqi@0 475
aoqi@0 476
aoqi@0 477 void TemplateTable::iload() {
aoqi@0 478 transition(vtos, itos);
aoqi@0 479 if (RewriteFrequentPairs) {
aoqi@0 480 Label rewrite, done;
aoqi@0 481
aoqi@0 482 // get next byte
aoqi@0 483 __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_iload)));
aoqi@0 484 // if _iload, wait to rewrite to iload2. We only want to rewrite the
aoqi@0 485 // last two iloads in a pair. Comparing against fast_iload means that
aoqi@0 486 // the next bytecode is neither an iload or a caload, and therefore
aoqi@0 487 // an iload pair.
aoqi@0 488 __ cmpl(rbx, Bytecodes::_iload);
aoqi@0 489 __ jcc(Assembler::equal, done);
aoqi@0 490
aoqi@0 491 __ cmpl(rbx, Bytecodes::_fast_iload);
aoqi@0 492 __ movl(rcx, Bytecodes::_fast_iload2);
aoqi@0 493 __ jccb(Assembler::equal, rewrite);
aoqi@0 494
aoqi@0 495 // if _caload, rewrite to fast_icaload
aoqi@0 496 __ cmpl(rbx, Bytecodes::_caload);
aoqi@0 497 __ movl(rcx, Bytecodes::_fast_icaload);
aoqi@0 498 __ jccb(Assembler::equal, rewrite);
aoqi@0 499
aoqi@0 500 // rewrite so iload doesn't check again.
aoqi@0 501 __ movl(rcx, Bytecodes::_fast_iload);
aoqi@0 502
aoqi@0 503 // rewrite
aoqi@0 504 // rcx: fast bytecode
aoqi@0 505 __ bind(rewrite);
aoqi@0 506 patch_bytecode(Bytecodes::_iload, rcx, rbx, false);
aoqi@0 507 __ bind(done);
aoqi@0 508 }
aoqi@0 509
aoqi@0 510 // Get the local value into tos
aoqi@0 511 locals_index(rbx);
aoqi@0 512 __ movl(rax, iaddress(rbx));
aoqi@0 513 }
aoqi@0 514
aoqi@0 515
aoqi@0 516 void TemplateTable::fast_iload2() {
aoqi@0 517 transition(vtos, itos);
aoqi@0 518 locals_index(rbx);
aoqi@0 519 __ movl(rax, iaddress(rbx));
aoqi@0 520 __ push(itos);
aoqi@0 521 locals_index(rbx, 3);
aoqi@0 522 __ movl(rax, iaddress(rbx));
aoqi@0 523 }
aoqi@0 524
aoqi@0 525 void TemplateTable::fast_iload() {
aoqi@0 526 transition(vtos, itos);
aoqi@0 527 locals_index(rbx);
aoqi@0 528 __ movl(rax, iaddress(rbx));
aoqi@0 529 }
aoqi@0 530
aoqi@0 531
aoqi@0 532 void TemplateTable::lload() {
aoqi@0 533 transition(vtos, ltos);
aoqi@0 534 locals_index(rbx);
aoqi@0 535 __ movptr(rax, laddress(rbx));
aoqi@0 536 NOT_LP64(__ movl(rdx, haddress(rbx)));
aoqi@0 537 }
aoqi@0 538
aoqi@0 539
aoqi@0 540 void TemplateTable::fload() {
aoqi@0 541 transition(vtos, ftos);
aoqi@0 542 locals_index(rbx);
aoqi@0 543 __ fld_s(faddress(rbx));
aoqi@0 544 }
aoqi@0 545
aoqi@0 546
aoqi@0 547 void TemplateTable::dload() {
aoqi@0 548 transition(vtos, dtos);
aoqi@0 549 locals_index(rbx);
aoqi@0 550 __ fld_d(daddress(rbx));
aoqi@0 551 }
aoqi@0 552
aoqi@0 553
aoqi@0 554 void TemplateTable::aload() {
aoqi@0 555 transition(vtos, atos);
aoqi@0 556 locals_index(rbx);
aoqi@0 557 __ movptr(rax, aaddress(rbx));
aoqi@0 558 }
aoqi@0 559
aoqi@0 560
aoqi@0 561 void TemplateTable::locals_index_wide(Register reg) {
aoqi@0 562 __ load_unsigned_short(reg, at_bcp(2));
aoqi@0 563 __ bswapl(reg);
aoqi@0 564 __ shrl(reg, 16);
aoqi@0 565 __ negptr(reg);
aoqi@0 566 }
aoqi@0 567
aoqi@0 568
aoqi@0 569 void TemplateTable::wide_iload() {
aoqi@0 570 transition(vtos, itos);
aoqi@0 571 locals_index_wide(rbx);
aoqi@0 572 __ movl(rax, iaddress(rbx));
aoqi@0 573 }
aoqi@0 574
aoqi@0 575
aoqi@0 576 void TemplateTable::wide_lload() {
aoqi@0 577 transition(vtos, ltos);
aoqi@0 578 locals_index_wide(rbx);
aoqi@0 579 __ movptr(rax, laddress(rbx));
aoqi@0 580 NOT_LP64(__ movl(rdx, haddress(rbx)));
aoqi@0 581 }
aoqi@0 582
aoqi@0 583
aoqi@0 584 void TemplateTable::wide_fload() {
aoqi@0 585 transition(vtos, ftos);
aoqi@0 586 locals_index_wide(rbx);
aoqi@0 587 __ fld_s(faddress(rbx));
aoqi@0 588 }
aoqi@0 589
aoqi@0 590
aoqi@0 591 void TemplateTable::wide_dload() {
aoqi@0 592 transition(vtos, dtos);
aoqi@0 593 locals_index_wide(rbx);
aoqi@0 594 __ fld_d(daddress(rbx));
aoqi@0 595 }
aoqi@0 596
aoqi@0 597
aoqi@0 598 void TemplateTable::wide_aload() {
aoqi@0 599 transition(vtos, atos);
aoqi@0 600 locals_index_wide(rbx);
aoqi@0 601 __ movptr(rax, aaddress(rbx));
aoqi@0 602 }
aoqi@0 603
aoqi@0 604 void TemplateTable::index_check(Register array, Register index) {
aoqi@0 605 // Pop ptr into array
aoqi@0 606 __ pop_ptr(array);
aoqi@0 607 index_check_without_pop(array, index);
aoqi@0 608 }
aoqi@0 609
aoqi@0 610 void TemplateTable::index_check_without_pop(Register array, Register index) {
aoqi@0 611 // destroys rbx,
aoqi@0 612 // check array
aoqi@0 613 __ null_check(array, arrayOopDesc::length_offset_in_bytes());
aoqi@0 614 LP64_ONLY(__ movslq(index, index));
aoqi@0 615 // check index
aoqi@0 616 __ cmpl(index, Address(array, arrayOopDesc::length_offset_in_bytes()));
aoqi@0 617 if (index != rbx) {
aoqi@0 618 // ??? convention: move aberrant index into rbx, for exception message
aoqi@0 619 assert(rbx != array, "different registers");
aoqi@0 620 __ mov(rbx, index);
aoqi@0 621 }
aoqi@0 622 __ jump_cc(Assembler::aboveEqual,
aoqi@0 623 ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry));
aoqi@0 624 }
aoqi@0 625
aoqi@0 626
aoqi@0 627 void TemplateTable::iaload() {
aoqi@0 628 transition(itos, itos);
aoqi@0 629 // rdx: array
aoqi@0 630 index_check(rdx, rax); // kills rbx,
aoqi@0 631 // rax,: index
aoqi@0 632 __ movl(rax, Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)));
aoqi@0 633 }
aoqi@0 634
aoqi@0 635
aoqi@0 636 void TemplateTable::laload() {
aoqi@0 637 transition(itos, ltos);
aoqi@0 638 // rax,: index
aoqi@0 639 // rdx: array
aoqi@0 640 index_check(rdx, rax);
aoqi@0 641 __ mov(rbx, rax);
aoqi@0 642 // rbx,: index
aoqi@0 643 __ movptr(rax, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize));
aoqi@0 644 NOT_LP64(__ movl(rdx, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize)));
aoqi@0 645 }
aoqi@0 646
aoqi@0 647
aoqi@0 648 void TemplateTable::faload() {
aoqi@0 649 transition(itos, ftos);
aoqi@0 650 // rdx: array
aoqi@0 651 index_check(rdx, rax); // kills rbx,
aoqi@0 652 // rax,: index
aoqi@0 653 __ fld_s(Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
aoqi@0 654 }
aoqi@0 655
aoqi@0 656
aoqi@0 657 void TemplateTable::daload() {
aoqi@0 658 transition(itos, dtos);
aoqi@0 659 // rdx: array
aoqi@0 660 index_check(rdx, rax); // kills rbx,
aoqi@0 661 // rax,: index
aoqi@0 662 __ fld_d(Address(rdx, rax, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
aoqi@0 663 }
aoqi@0 664
aoqi@0 665
aoqi@0 666 void TemplateTable::aaload() {
aoqi@0 667 transition(itos, atos);
aoqi@0 668 // rdx: array
aoqi@0 669 index_check(rdx, rax); // kills rbx,
aoqi@0 670 // rax,: index
aoqi@0 671 __ movptr(rax, Address(rdx, rax, Address::times_ptr, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
aoqi@0 672 }
aoqi@0 673
aoqi@0 674
aoqi@0 675 void TemplateTable::baload() {
aoqi@0 676 transition(itos, itos);
aoqi@0 677 // rdx: array
aoqi@0 678 index_check(rdx, rax); // kills rbx,
aoqi@0 679 // rax,: index
aoqi@0 680 // can do better code for P5 - fix this at some point
aoqi@0 681 __ load_signed_byte(rbx, Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)));
aoqi@0 682 __ mov(rax, rbx);
aoqi@0 683 }
aoqi@0 684
aoqi@0 685
aoqi@0 686 void TemplateTable::caload() {
aoqi@0 687 transition(itos, itos);
aoqi@0 688 // rdx: array
aoqi@0 689 index_check(rdx, rax); // kills rbx,
aoqi@0 690 // rax,: index
aoqi@0 691 // can do better code for P5 - may want to improve this at some point
aoqi@0 692 __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
aoqi@0 693 __ mov(rax, rbx);
aoqi@0 694 }
aoqi@0 695
aoqi@0 696 // iload followed by caload frequent pair
aoqi@0 697 void TemplateTable::fast_icaload() {
aoqi@0 698 transition(vtos, itos);
aoqi@0 699 // load index out of locals
aoqi@0 700 locals_index(rbx);
aoqi@0 701 __ movl(rax, iaddress(rbx));
aoqi@0 702
aoqi@0 703 // rdx: array
aoqi@0 704 index_check(rdx, rax);
aoqi@0 705 // rax,: index
aoqi@0 706 __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
aoqi@0 707 __ mov(rax, rbx);
aoqi@0 708 }
aoqi@0 709
aoqi@0 710 void TemplateTable::saload() {
aoqi@0 711 transition(itos, itos);
aoqi@0 712 // rdx: array
aoqi@0 713 index_check(rdx, rax); // kills rbx,
aoqi@0 714 // rax,: index
aoqi@0 715 // can do better code for P5 - may want to improve this at some point
aoqi@0 716 __ load_signed_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_SHORT)));
aoqi@0 717 __ mov(rax, rbx);
aoqi@0 718 }
aoqi@0 719
aoqi@0 720
aoqi@0 721 void TemplateTable::iload(int n) {
aoqi@0 722 transition(vtos, itos);
aoqi@0 723 __ movl(rax, iaddress(n));
aoqi@0 724 }
aoqi@0 725
aoqi@0 726
aoqi@0 727 void TemplateTable::lload(int n) {
aoqi@0 728 transition(vtos, ltos);
aoqi@0 729 __ movptr(rax, laddress(n));
aoqi@0 730 NOT_LP64(__ movptr(rdx, haddress(n)));
aoqi@0 731 }
aoqi@0 732
aoqi@0 733
aoqi@0 734 void TemplateTable::fload(int n) {
aoqi@0 735 transition(vtos, ftos);
aoqi@0 736 __ fld_s(faddress(n));
aoqi@0 737 }
aoqi@0 738
aoqi@0 739
aoqi@0 740 void TemplateTable::dload(int n) {
aoqi@0 741 transition(vtos, dtos);
aoqi@0 742 __ fld_d(daddress(n));
aoqi@0 743 }
aoqi@0 744
aoqi@0 745
aoqi@0 746 void TemplateTable::aload(int n) {
aoqi@0 747 transition(vtos, atos);
aoqi@0 748 __ movptr(rax, aaddress(n));
aoqi@0 749 }
aoqi@0 750
aoqi@0 751
aoqi@0 752 void TemplateTable::aload_0() {
aoqi@0 753 transition(vtos, atos);
aoqi@0 754 // According to bytecode histograms, the pairs:
aoqi@0 755 //
aoqi@0 756 // _aload_0, _fast_igetfield
aoqi@0 757 // _aload_0, _fast_agetfield
aoqi@0 758 // _aload_0, _fast_fgetfield
aoqi@0 759 //
aoqi@0 760 // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
aoqi@0 761 // bytecode checks if the next bytecode is either _fast_igetfield,
aoqi@0 762 // _fast_agetfield or _fast_fgetfield and then rewrites the
aoqi@0 763 // current bytecode into a pair bytecode; otherwise it rewrites the current
aoqi@0 764 // bytecode into _fast_aload_0 that doesn't do the pair check anymore.
aoqi@0 765 //
aoqi@0 766 // Note: If the next bytecode is _getfield, the rewrite must be delayed,
aoqi@0 767 // otherwise we may miss an opportunity for a pair.
aoqi@0 768 //
aoqi@0 769 // Also rewrite frequent pairs
aoqi@0 770 // aload_0, aload_1
aoqi@0 771 // aload_0, iload_1
aoqi@0 772 // These bytecodes with a small amount of code are most profitable to rewrite
aoqi@0 773 if (RewriteFrequentPairs) {
aoqi@0 774 Label rewrite, done;
aoqi@0 775 // get next byte
aoqi@0 776 __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)));
aoqi@0 777
aoqi@0 778 // do actual aload_0
aoqi@0 779 aload(0);
aoqi@0 780
aoqi@0 781 // if _getfield then wait with rewrite
aoqi@0 782 __ cmpl(rbx, Bytecodes::_getfield);
aoqi@0 783 __ jcc(Assembler::equal, done);
aoqi@0 784
aoqi@0 785 // if _igetfield then reqrite to _fast_iaccess_0
aoqi@0 786 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
aoqi@0 787 __ cmpl(rbx, Bytecodes::_fast_igetfield);
aoqi@0 788 __ movl(rcx, Bytecodes::_fast_iaccess_0);
aoqi@0 789 __ jccb(Assembler::equal, rewrite);
aoqi@0 790
aoqi@0 791 // if _agetfield then reqrite to _fast_aaccess_0
aoqi@0 792 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
aoqi@0 793 __ cmpl(rbx, Bytecodes::_fast_agetfield);
aoqi@0 794 __ movl(rcx, Bytecodes::_fast_aaccess_0);
aoqi@0 795 __ jccb(Assembler::equal, rewrite);
aoqi@0 796
aoqi@0 797 // if _fgetfield then reqrite to _fast_faccess_0
aoqi@0 798 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition");
aoqi@0 799 __ cmpl(rbx, Bytecodes::_fast_fgetfield);
aoqi@0 800 __ movl(rcx, Bytecodes::_fast_faccess_0);
aoqi@0 801 __ jccb(Assembler::equal, rewrite);
aoqi@0 802
aoqi@0 803 // else rewrite to _fast_aload0
aoqi@0 804 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition");
aoqi@0 805 __ movl(rcx, Bytecodes::_fast_aload_0);
aoqi@0 806
aoqi@0 807 // rewrite
aoqi@0 808 // rcx: fast bytecode
aoqi@0 809 __ bind(rewrite);
aoqi@0 810 patch_bytecode(Bytecodes::_aload_0, rcx, rbx, false);
aoqi@0 811
aoqi@0 812 __ bind(done);
aoqi@0 813 } else {
aoqi@0 814 aload(0);
aoqi@0 815 }
aoqi@0 816 }
aoqi@0 817
aoqi@0 818 void TemplateTable::istore() {
aoqi@0 819 transition(itos, vtos);
aoqi@0 820 locals_index(rbx);
aoqi@0 821 __ movl(iaddress(rbx), rax);
aoqi@0 822 }
aoqi@0 823
aoqi@0 824
aoqi@0 825 void TemplateTable::lstore() {
aoqi@0 826 transition(ltos, vtos);
aoqi@0 827 locals_index(rbx);
aoqi@0 828 __ movptr(laddress(rbx), rax);
aoqi@0 829 NOT_LP64(__ movptr(haddress(rbx), rdx));
aoqi@0 830 }
aoqi@0 831
aoqi@0 832
aoqi@0 833 void TemplateTable::fstore() {
aoqi@0 834 transition(ftos, vtos);
aoqi@0 835 locals_index(rbx);
aoqi@0 836 __ fstp_s(faddress(rbx));
aoqi@0 837 }
aoqi@0 838
aoqi@0 839
aoqi@0 840 void TemplateTable::dstore() {
aoqi@0 841 transition(dtos, vtos);
aoqi@0 842 locals_index(rbx);
aoqi@0 843 __ fstp_d(daddress(rbx));
aoqi@0 844 }
aoqi@0 845
aoqi@0 846
aoqi@0 847 void TemplateTable::astore() {
aoqi@0 848 transition(vtos, vtos);
aoqi@0 849 __ pop_ptr(rax);
aoqi@0 850 locals_index(rbx);
aoqi@0 851 __ movptr(aaddress(rbx), rax);
aoqi@0 852 }
aoqi@0 853
aoqi@0 854
aoqi@0 855 void TemplateTable::wide_istore() {
aoqi@0 856 transition(vtos, vtos);
aoqi@0 857 __ pop_i(rax);
aoqi@0 858 locals_index_wide(rbx);
aoqi@0 859 __ movl(iaddress(rbx), rax);
aoqi@0 860 }
aoqi@0 861
aoqi@0 862
aoqi@0 863 void TemplateTable::wide_lstore() {
aoqi@0 864 transition(vtos, vtos);
aoqi@0 865 __ pop_l(rax, rdx);
aoqi@0 866 locals_index_wide(rbx);
aoqi@0 867 __ movptr(laddress(rbx), rax);
aoqi@0 868 NOT_LP64(__ movl(haddress(rbx), rdx));
aoqi@0 869 }
aoqi@0 870
aoqi@0 871
aoqi@0 872 void TemplateTable::wide_fstore() {
aoqi@0 873 wide_istore();
aoqi@0 874 }
aoqi@0 875
aoqi@0 876
aoqi@0 877 void TemplateTable::wide_dstore() {
aoqi@0 878 wide_lstore();
aoqi@0 879 }
aoqi@0 880
aoqi@0 881
aoqi@0 882 void TemplateTable::wide_astore() {
aoqi@0 883 transition(vtos, vtos);
aoqi@0 884 __ pop_ptr(rax);
aoqi@0 885 locals_index_wide(rbx);
aoqi@0 886 __ movptr(aaddress(rbx), rax);
aoqi@0 887 }
aoqi@0 888
aoqi@0 889
aoqi@0 890 void TemplateTable::iastore() {
aoqi@0 891 transition(itos, vtos);
aoqi@0 892 __ pop_i(rbx);
aoqi@0 893 // rax,: value
aoqi@0 894 // rdx: array
aoqi@0 895 index_check(rdx, rbx); // prefer index in rbx,
aoqi@0 896 // rbx,: index
aoqi@0 897 __ movl(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)), rax);
aoqi@0 898 }
aoqi@0 899
aoqi@0 900
aoqi@0 901 void TemplateTable::lastore() {
aoqi@0 902 transition(ltos, vtos);
aoqi@0 903 __ pop_i(rbx);
aoqi@0 904 // rax,: low(value)
aoqi@0 905 // rcx: array
aoqi@0 906 // rdx: high(value)
aoqi@0 907 index_check(rcx, rbx); // prefer index in rbx,
aoqi@0 908 // rbx,: index
aoqi@0 909 __ movptr(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize), rax);
aoqi@0 910 NOT_LP64(__ movl(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize), rdx));
aoqi@0 911 }
aoqi@0 912
aoqi@0 913
aoqi@0 914 void TemplateTable::fastore() {
aoqi@0 915 transition(ftos, vtos);
aoqi@0 916 __ pop_i(rbx);
aoqi@0 917 // rdx: array
aoqi@0 918 // st0: value
aoqi@0 919 index_check(rdx, rbx); // prefer index in rbx,
aoqi@0 920 // rbx,: index
aoqi@0 921 __ fstp_s(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT)));
aoqi@0 922 }
aoqi@0 923
aoqi@0 924
aoqi@0 925 void TemplateTable::dastore() {
aoqi@0 926 transition(dtos, vtos);
aoqi@0 927 __ pop_i(rbx);
aoqi@0 928 // rdx: array
aoqi@0 929 // st0: value
aoqi@0 930 index_check(rdx, rbx); // prefer index in rbx,
aoqi@0 931 // rbx,: index
aoqi@0 932 __ fstp_d(Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE)));
aoqi@0 933 }
aoqi@0 934
aoqi@0 935
aoqi@0 936 void TemplateTable::aastore() {
aoqi@0 937 Label is_null, ok_is_subtype, done;
aoqi@0 938 transition(vtos, vtos);
aoqi@0 939 // stack: ..., array, index, value
aoqi@0 940 __ movptr(rax, at_tos()); // Value
aoqi@0 941 __ movl(rcx, at_tos_p1()); // Index
aoqi@0 942 __ movptr(rdx, at_tos_p2()); // Array
aoqi@0 943
aoqi@0 944 Address element_address(rdx, rcx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
aoqi@0 945 index_check_without_pop(rdx, rcx); // kills rbx,
aoqi@0 946 // do array store check - check for NULL value first
aoqi@0 947 __ testptr(rax, rax);
aoqi@0 948 __ jcc(Assembler::zero, is_null);
aoqi@0 949
aoqi@0 950 // Move subklass into EBX
aoqi@0 951 __ load_klass(rbx, rax);
aoqi@0 952 // Move superklass into EAX
aoqi@0 953 __ load_klass(rax, rdx);
aoqi@0 954 __ movptr(rax, Address(rax, ObjArrayKlass::element_klass_offset()));
aoqi@0 955 // Compress array+index*wordSize+12 into a single register. Frees ECX.
aoqi@0 956 __ lea(rdx, element_address);
aoqi@0 957
aoqi@0 958 // Generate subtype check. Blows ECX. Resets EDI to locals.
aoqi@0 959 // Superklass in EAX. Subklass in EBX.
aoqi@0 960 __ gen_subtype_check( rbx, ok_is_subtype );
aoqi@0 961
aoqi@0 962 // Come here on failure
aoqi@0 963 // object is at TOS
aoqi@0 964 __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
aoqi@0 965
aoqi@0 966 // Come here on success
aoqi@0 967 __ bind(ok_is_subtype);
aoqi@0 968
aoqi@0 969 // Get the value to store
aoqi@0 970 __ movptr(rax, at_rsp());
aoqi@0 971 // and store it with appropriate barrier
aoqi@0 972 do_oop_store(_masm, Address(rdx, 0), rax, _bs->kind(), true);
aoqi@0 973
aoqi@0 974 __ jmp(done);
aoqi@0 975
aoqi@0 976 // Have a NULL in EAX, EDX=array, ECX=index. Store NULL at ary[idx]
aoqi@0 977 __ bind(is_null);
aoqi@0 978 __ profile_null_seen(rbx);
aoqi@0 979
aoqi@0 980 // Store NULL, (noreg means NULL to do_oop_store)
aoqi@0 981 do_oop_store(_masm, element_address, noreg, _bs->kind(), true);
aoqi@0 982
aoqi@0 983 // Pop stack arguments
aoqi@0 984 __ bind(done);
aoqi@0 985 __ addptr(rsp, 3 * Interpreter::stackElementSize);
aoqi@0 986 }
aoqi@0 987
aoqi@0 988
aoqi@0 989 void TemplateTable::bastore() {
aoqi@0 990 transition(itos, vtos);
aoqi@0 991 __ pop_i(rbx);
kevinw@8368 992 // rax: value
kevinw@8368 993 // rbx: index
aoqi@0 994 // rdx: array
kevinw@8368 995 index_check(rdx, rbx); // prefer index in rbx
kevinw@8368 996 // Need to check whether array is boolean or byte
kevinw@8368 997 // since both types share the bastore bytecode.
kevinw@8368 998 __ load_klass(rcx, rdx);
kevinw@8368 999 __ movl(rcx, Address(rcx, Klass::layout_helper_offset()));
kevinw@8368 1000 int diffbit = Klass::layout_helper_boolean_diffbit();
kevinw@8368 1001 __ testl(rcx, diffbit);
kevinw@8368 1002 Label L_skip;
kevinw@8368 1003 __ jccb(Assembler::zero, L_skip);
kevinw@8368 1004 __ andl(rax, 1); // if it is a T_BOOLEAN array, mask the stored value to 0/1
kevinw@8368 1005 __ bind(L_skip);
kevinw@8368 1006 __ movb(Address(rdx, rbx, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)), rax);
aoqi@0 1007 }
aoqi@0 1008
aoqi@0 1009
aoqi@0 1010 void TemplateTable::castore() {
aoqi@0 1011 transition(itos, vtos);
aoqi@0 1012 __ pop_i(rbx);
aoqi@0 1013 // rax,: value
aoqi@0 1014 // rdx: array
aoqi@0 1015 index_check(rdx, rbx); // prefer index in rbx,
aoqi@0 1016 // rbx,: index
aoqi@0 1017 __ movw(Address(rdx, rbx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)), rax);
aoqi@0 1018 }
aoqi@0 1019
aoqi@0 1020
aoqi@0 1021 void TemplateTable::sastore() {
aoqi@0 1022 castore();
aoqi@0 1023 }
aoqi@0 1024
aoqi@0 1025
aoqi@0 1026 void TemplateTable::istore(int n) {
aoqi@0 1027 transition(itos, vtos);
aoqi@0 1028 __ movl(iaddress(n), rax);
aoqi@0 1029 }
aoqi@0 1030
aoqi@0 1031
aoqi@0 1032 void TemplateTable::lstore(int n) {
aoqi@0 1033 transition(ltos, vtos);
aoqi@0 1034 __ movptr(laddress(n), rax);
aoqi@0 1035 NOT_LP64(__ movptr(haddress(n), rdx));
aoqi@0 1036 }
aoqi@0 1037
aoqi@0 1038
aoqi@0 1039 void TemplateTable::fstore(int n) {
aoqi@0 1040 transition(ftos, vtos);
aoqi@0 1041 __ fstp_s(faddress(n));
aoqi@0 1042 }
aoqi@0 1043
aoqi@0 1044
aoqi@0 1045 void TemplateTable::dstore(int n) {
aoqi@0 1046 transition(dtos, vtos);
aoqi@0 1047 __ fstp_d(daddress(n));
aoqi@0 1048 }
aoqi@0 1049
aoqi@0 1050
aoqi@0 1051 void TemplateTable::astore(int n) {
aoqi@0 1052 transition(vtos, vtos);
aoqi@0 1053 __ pop_ptr(rax);
aoqi@0 1054 __ movptr(aaddress(n), rax);
aoqi@0 1055 }
aoqi@0 1056
aoqi@0 1057
aoqi@0 1058 void TemplateTable::pop() {
aoqi@0 1059 transition(vtos, vtos);
aoqi@0 1060 __ addptr(rsp, Interpreter::stackElementSize);
aoqi@0 1061 }
aoqi@0 1062
aoqi@0 1063
aoqi@0 1064 void TemplateTable::pop2() {
aoqi@0 1065 transition(vtos, vtos);
aoqi@0 1066 __ addptr(rsp, 2*Interpreter::stackElementSize);
aoqi@0 1067 }
aoqi@0 1068
aoqi@0 1069
aoqi@0 1070 void TemplateTable::dup() {
aoqi@0 1071 transition(vtos, vtos);
aoqi@0 1072 // stack: ..., a
aoqi@0 1073 __ load_ptr(0, rax);
aoqi@0 1074 __ push_ptr(rax);
aoqi@0 1075 // stack: ..., a, a
aoqi@0 1076 }
aoqi@0 1077
aoqi@0 1078
aoqi@0 1079 void TemplateTable::dup_x1() {
aoqi@0 1080 transition(vtos, vtos);
aoqi@0 1081 // stack: ..., a, b
aoqi@0 1082 __ load_ptr( 0, rax); // load b
aoqi@0 1083 __ load_ptr( 1, rcx); // load a
aoqi@0 1084 __ store_ptr(1, rax); // store b
aoqi@0 1085 __ store_ptr(0, rcx); // store a
aoqi@0 1086 __ push_ptr(rax); // push b
aoqi@0 1087 // stack: ..., b, a, b
aoqi@0 1088 }
aoqi@0 1089
aoqi@0 1090
aoqi@0 1091 void TemplateTable::dup_x2() {
aoqi@0 1092 transition(vtos, vtos);
aoqi@0 1093 // stack: ..., a, b, c
aoqi@0 1094 __ load_ptr( 0, rax); // load c
aoqi@0 1095 __ load_ptr( 2, rcx); // load a
aoqi@0 1096 __ store_ptr(2, rax); // store c in a
aoqi@0 1097 __ push_ptr(rax); // push c
aoqi@0 1098 // stack: ..., c, b, c, c
aoqi@0 1099 __ load_ptr( 2, rax); // load b
aoqi@0 1100 __ store_ptr(2, rcx); // store a in b
aoqi@0 1101 // stack: ..., c, a, c, c
aoqi@0 1102 __ store_ptr(1, rax); // store b in c
aoqi@0 1103 // stack: ..., c, a, b, c
aoqi@0 1104 }
aoqi@0 1105
aoqi@0 1106
aoqi@0 1107 void TemplateTable::dup2() {
aoqi@0 1108 transition(vtos, vtos);
aoqi@0 1109 // stack: ..., a, b
aoqi@0 1110 __ load_ptr(1, rax); // load a
aoqi@0 1111 __ push_ptr(rax); // push a
aoqi@0 1112 __ load_ptr(1, rax); // load b
aoqi@0 1113 __ push_ptr(rax); // push b
aoqi@0 1114 // stack: ..., a, b, a, b
aoqi@0 1115 }
aoqi@0 1116
aoqi@0 1117
aoqi@0 1118 void TemplateTable::dup2_x1() {
aoqi@0 1119 transition(vtos, vtos);
aoqi@0 1120 // stack: ..., a, b, c
aoqi@0 1121 __ load_ptr( 0, rcx); // load c
aoqi@0 1122 __ load_ptr( 1, rax); // load b
aoqi@0 1123 __ push_ptr(rax); // push b
aoqi@0 1124 __ push_ptr(rcx); // push c
aoqi@0 1125 // stack: ..., a, b, c, b, c
aoqi@0 1126 __ store_ptr(3, rcx); // store c in b
aoqi@0 1127 // stack: ..., a, c, c, b, c
aoqi@0 1128 __ load_ptr( 4, rcx); // load a
aoqi@0 1129 __ store_ptr(2, rcx); // store a in 2nd c
aoqi@0 1130 // stack: ..., a, c, a, b, c
aoqi@0 1131 __ store_ptr(4, rax); // store b in a
aoqi@0 1132 // stack: ..., b, c, a, b, c
aoqi@0 1133 // stack: ..., b, c, a, b, c
aoqi@0 1134 }
aoqi@0 1135
aoqi@0 1136
aoqi@0 1137 void TemplateTable::dup2_x2() {
aoqi@0 1138 transition(vtos, vtos);
aoqi@0 1139 // stack: ..., a, b, c, d
aoqi@0 1140 __ load_ptr( 0, rcx); // load d
aoqi@0 1141 __ load_ptr( 1, rax); // load c
aoqi@0 1142 __ push_ptr(rax); // push c
aoqi@0 1143 __ push_ptr(rcx); // push d
aoqi@0 1144 // stack: ..., a, b, c, d, c, d
aoqi@0 1145 __ load_ptr( 4, rax); // load b
aoqi@0 1146 __ store_ptr(2, rax); // store b in d
aoqi@0 1147 __ store_ptr(4, rcx); // store d in b
aoqi@0 1148 // stack: ..., a, d, c, b, c, d
aoqi@0 1149 __ load_ptr( 5, rcx); // load a
aoqi@0 1150 __ load_ptr( 3, rax); // load c
aoqi@0 1151 __ store_ptr(3, rcx); // store a in c
aoqi@0 1152 __ store_ptr(5, rax); // store c in a
aoqi@0 1153 // stack: ..., c, d, a, b, c, d
aoqi@0 1154 // stack: ..., c, d, a, b, c, d
aoqi@0 1155 }
aoqi@0 1156
aoqi@0 1157
aoqi@0 1158 void TemplateTable::swap() {
aoqi@0 1159 transition(vtos, vtos);
aoqi@0 1160 // stack: ..., a, b
aoqi@0 1161 __ load_ptr( 1, rcx); // load a
aoqi@0 1162 __ load_ptr( 0, rax); // load b
aoqi@0 1163 __ store_ptr(0, rcx); // store a in b
aoqi@0 1164 __ store_ptr(1, rax); // store b in a
aoqi@0 1165 // stack: ..., b, a
aoqi@0 1166 }
aoqi@0 1167
aoqi@0 1168
aoqi@0 1169 void TemplateTable::iop2(Operation op) {
aoqi@0 1170 transition(itos, itos);
aoqi@0 1171 switch (op) {
aoqi@0 1172 case add : __ pop_i(rdx); __ addl (rax, rdx); break;
aoqi@0 1173 case sub : __ mov(rdx, rax); __ pop_i(rax); __ subl (rax, rdx); break;
aoqi@0 1174 case mul : __ pop_i(rdx); __ imull(rax, rdx); break;
aoqi@0 1175 case _and : __ pop_i(rdx); __ andl (rax, rdx); break;
aoqi@0 1176 case _or : __ pop_i(rdx); __ orl (rax, rdx); break;
aoqi@0 1177 case _xor : __ pop_i(rdx); __ xorl (rax, rdx); break;
aoqi@0 1178 case shl : __ mov(rcx, rax); __ pop_i(rax); __ shll (rax); break; // implicit masking of lower 5 bits by Intel shift instr.
aoqi@0 1179 case shr : __ mov(rcx, rax); __ pop_i(rax); __ sarl (rax); break; // implicit masking of lower 5 bits by Intel shift instr.
aoqi@0 1180 case ushr : __ mov(rcx, rax); __ pop_i(rax); __ shrl (rax); break; // implicit masking of lower 5 bits by Intel shift instr.
aoqi@0 1181 default : ShouldNotReachHere();
aoqi@0 1182 }
aoqi@0 1183 }
aoqi@0 1184
aoqi@0 1185
aoqi@0 1186 void TemplateTable::lop2(Operation op) {
aoqi@0 1187 transition(ltos, ltos);
aoqi@0 1188 __ pop_l(rbx, rcx);
aoqi@0 1189 switch (op) {
aoqi@0 1190 case add : __ addl(rax, rbx); __ adcl(rdx, rcx); break;
aoqi@0 1191 case sub : __ subl(rbx, rax); __ sbbl(rcx, rdx);
aoqi@0 1192 __ mov (rax, rbx); __ mov (rdx, rcx); break;
aoqi@0 1193 case _and : __ andl(rax, rbx); __ andl(rdx, rcx); break;
aoqi@0 1194 case _or : __ orl (rax, rbx); __ orl (rdx, rcx); break;
aoqi@0 1195 case _xor : __ xorl(rax, rbx); __ xorl(rdx, rcx); break;
aoqi@0 1196 default : ShouldNotReachHere();
aoqi@0 1197 }
aoqi@0 1198 }
aoqi@0 1199
aoqi@0 1200
aoqi@0 1201 void TemplateTable::idiv() {
aoqi@0 1202 transition(itos, itos);
aoqi@0 1203 __ mov(rcx, rax);
aoqi@0 1204 __ pop_i(rax);
aoqi@0 1205 // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
aoqi@0 1206 // they are not equal, one could do a normal division (no correction
aoqi@0 1207 // needed), which may speed up this implementation for the common case.
aoqi@0 1208 // (see also JVM spec., p.243 & p.271)
aoqi@0 1209 __ corrected_idivl(rcx);
aoqi@0 1210 }
aoqi@0 1211
aoqi@0 1212
aoqi@0 1213 void TemplateTable::irem() {
aoqi@0 1214 transition(itos, itos);
aoqi@0 1215 __ mov(rcx, rax);
aoqi@0 1216 __ pop_i(rax);
aoqi@0 1217 // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If
aoqi@0 1218 // they are not equal, one could do a normal division (no correction
aoqi@0 1219 // needed), which may speed up this implementation for the common case.
aoqi@0 1220 // (see also JVM spec., p.243 & p.271)
aoqi@0 1221 __ corrected_idivl(rcx);
aoqi@0 1222 __ mov(rax, rdx);
aoqi@0 1223 }
aoqi@0 1224
aoqi@0 1225
aoqi@0 1226 void TemplateTable::lmul() {
aoqi@0 1227 transition(ltos, ltos);
aoqi@0 1228 __ pop_l(rbx, rcx);
aoqi@0 1229 __ push(rcx); __ push(rbx);
aoqi@0 1230 __ push(rdx); __ push(rax);
aoqi@0 1231 __ lmul(2 * wordSize, 0);
aoqi@0 1232 __ addptr(rsp, 4 * wordSize); // take off temporaries
aoqi@0 1233 }
aoqi@0 1234
aoqi@0 1235
aoqi@0 1236 void TemplateTable::ldiv() {
aoqi@0 1237 transition(ltos, ltos);
aoqi@0 1238 __ pop_l(rbx, rcx);
aoqi@0 1239 __ push(rcx); __ push(rbx);
aoqi@0 1240 __ push(rdx); __ push(rax);
aoqi@0 1241 // check if y = 0
aoqi@0 1242 __ orl(rax, rdx);
aoqi@0 1243 __ jump_cc(Assembler::zero,
aoqi@0 1244 ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
aoqi@0 1245 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
aoqi@0 1246 __ addptr(rsp, 4 * wordSize); // take off temporaries
aoqi@0 1247 }
aoqi@0 1248
aoqi@0 1249
aoqi@0 1250 void TemplateTable::lrem() {
aoqi@0 1251 transition(ltos, ltos);
aoqi@0 1252 __ pop_l(rbx, rcx);
aoqi@0 1253 __ push(rcx); __ push(rbx);
aoqi@0 1254 __ push(rdx); __ push(rax);
aoqi@0 1255 // check if y = 0
aoqi@0 1256 __ orl(rax, rdx);
aoqi@0 1257 __ jump_cc(Assembler::zero,
aoqi@0 1258 ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
aoqi@0 1259 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
aoqi@0 1260 __ addptr(rsp, 4 * wordSize);
aoqi@0 1261 }
aoqi@0 1262
aoqi@0 1263
aoqi@0 1264 void TemplateTable::lshl() {
aoqi@0 1265 transition(itos, ltos);
aoqi@0 1266 __ movl(rcx, rax); // get shift count
aoqi@0 1267 __ pop_l(rax, rdx); // get shift value
aoqi@0 1268 __ lshl(rdx, rax);
aoqi@0 1269 }
aoqi@0 1270
aoqi@0 1271
aoqi@0 1272 void TemplateTable::lshr() {
aoqi@0 1273 transition(itos, ltos);
aoqi@0 1274 __ mov(rcx, rax); // get shift count
aoqi@0 1275 __ pop_l(rax, rdx); // get shift value
aoqi@0 1276 __ lshr(rdx, rax, true);
aoqi@0 1277 }
aoqi@0 1278
aoqi@0 1279
aoqi@0 1280 void TemplateTable::lushr() {
aoqi@0 1281 transition(itos, ltos);
aoqi@0 1282 __ mov(rcx, rax); // get shift count
aoqi@0 1283 __ pop_l(rax, rdx); // get shift value
aoqi@0 1284 __ lshr(rdx, rax);
aoqi@0 1285 }
aoqi@0 1286
aoqi@0 1287
aoqi@0 1288 void TemplateTable::fop2(Operation op) {
aoqi@0 1289 transition(ftos, ftos);
aoqi@0 1290 switch (op) {
aoqi@0 1291 case add: __ fadd_s (at_rsp()); break;
aoqi@0 1292 case sub: __ fsubr_s(at_rsp()); break;
aoqi@0 1293 case mul: __ fmul_s (at_rsp()); break;
aoqi@0 1294 case div: __ fdivr_s(at_rsp()); break;
aoqi@0 1295 case rem: __ fld_s (at_rsp()); __ fremr(rax); break;
aoqi@0 1296 default : ShouldNotReachHere();
aoqi@0 1297 }
aoqi@0 1298 __ f2ieee();
aoqi@0 1299 __ pop(rax); // pop float thing off
aoqi@0 1300 }
aoqi@0 1301
aoqi@0 1302
aoqi@0 1303 void TemplateTable::dop2(Operation op) {
aoqi@0 1304 transition(dtos, dtos);
aoqi@0 1305
aoqi@0 1306 switch (op) {
aoqi@0 1307 case add: __ fadd_d (at_rsp()); break;
aoqi@0 1308 case sub: __ fsubr_d(at_rsp()); break;
aoqi@0 1309 case mul: {
aoqi@0 1310 Label L_strict;
aoqi@0 1311 Label L_join;
aoqi@0 1312 const Address access_flags (rcx, Method::access_flags_offset());
aoqi@0 1313 __ get_method(rcx);
aoqi@0 1314 __ movl(rcx, access_flags);
aoqi@0 1315 __ testl(rcx, JVM_ACC_STRICT);
aoqi@0 1316 __ jccb(Assembler::notZero, L_strict);
aoqi@0 1317 __ fmul_d (at_rsp());
aoqi@0 1318 __ jmpb(L_join);
aoqi@0 1319 __ bind(L_strict);
aoqi@0 1320 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
aoqi@0 1321 __ fmulp();
aoqi@0 1322 __ fmul_d (at_rsp());
aoqi@0 1323 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
aoqi@0 1324 __ fmulp();
aoqi@0 1325 __ bind(L_join);
aoqi@0 1326 break;
aoqi@0 1327 }
aoqi@0 1328 case div: {
aoqi@0 1329 Label L_strict;
aoqi@0 1330 Label L_join;
aoqi@0 1331 const Address access_flags (rcx, Method::access_flags_offset());
aoqi@0 1332 __ get_method(rcx);
aoqi@0 1333 __ movl(rcx, access_flags);
aoqi@0 1334 __ testl(rcx, JVM_ACC_STRICT);
aoqi@0 1335 __ jccb(Assembler::notZero, L_strict);
aoqi@0 1336 __ fdivr_d(at_rsp());
aoqi@0 1337 __ jmp(L_join);
aoqi@0 1338 __ bind(L_strict);
aoqi@0 1339 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1()));
aoqi@0 1340 __ fmul_d (at_rsp());
aoqi@0 1341 __ fdivrp();
aoqi@0 1342 __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2()));
aoqi@0 1343 __ fmulp();
aoqi@0 1344 __ bind(L_join);
aoqi@0 1345 break;
aoqi@0 1346 }
aoqi@0 1347 case rem: __ fld_d (at_rsp()); __ fremr(rax); break;
aoqi@0 1348 default : ShouldNotReachHere();
aoqi@0 1349 }
aoqi@0 1350 __ d2ieee();
aoqi@0 1351 // Pop double precision number from rsp.
aoqi@0 1352 __ pop(rax);
aoqi@0 1353 __ pop(rdx);
aoqi@0 1354 }
aoqi@0 1355
aoqi@0 1356
aoqi@0 1357 void TemplateTable::ineg() {
aoqi@0 1358 transition(itos, itos);
aoqi@0 1359 __ negl(rax);
aoqi@0 1360 }
aoqi@0 1361
aoqi@0 1362
aoqi@0 1363 void TemplateTable::lneg() {
aoqi@0 1364 transition(ltos, ltos);
aoqi@0 1365 __ lneg(rdx, rax);
aoqi@0 1366 }
aoqi@0 1367
aoqi@0 1368
aoqi@0 1369 void TemplateTable::fneg() {
aoqi@0 1370 transition(ftos, ftos);
aoqi@0 1371 __ fchs();
aoqi@0 1372 }
aoqi@0 1373
aoqi@0 1374
aoqi@0 1375 void TemplateTable::dneg() {
aoqi@0 1376 transition(dtos, dtos);
aoqi@0 1377 __ fchs();
aoqi@0 1378 }
aoqi@0 1379
aoqi@0 1380
aoqi@0 1381 void TemplateTable::iinc() {
aoqi@0 1382 transition(vtos, vtos);
aoqi@0 1383 __ load_signed_byte(rdx, at_bcp(2)); // get constant
aoqi@0 1384 locals_index(rbx);
aoqi@0 1385 __ addl(iaddress(rbx), rdx);
aoqi@0 1386 }
aoqi@0 1387
aoqi@0 1388
aoqi@0 1389 void TemplateTable::wide_iinc() {
aoqi@0 1390 transition(vtos, vtos);
aoqi@0 1391 __ movl(rdx, at_bcp(4)); // get constant
aoqi@0 1392 locals_index_wide(rbx);
aoqi@0 1393 __ bswapl(rdx); // swap bytes & sign-extend constant
aoqi@0 1394 __ sarl(rdx, 16);
aoqi@0 1395 __ addl(iaddress(rbx), rdx);
aoqi@0 1396 // Note: should probably use only one movl to get both
aoqi@0 1397 // the index and the constant -> fix this
aoqi@0 1398 }
aoqi@0 1399
aoqi@0 1400
aoqi@0 1401 void TemplateTable::convert() {
aoqi@0 1402 // Checking
aoqi@0 1403 #ifdef ASSERT
aoqi@0 1404 { TosState tos_in = ilgl;
aoqi@0 1405 TosState tos_out = ilgl;
aoqi@0 1406 switch (bytecode()) {
aoqi@0 1407 case Bytecodes::_i2l: // fall through
aoqi@0 1408 case Bytecodes::_i2f: // fall through
aoqi@0 1409 case Bytecodes::_i2d: // fall through
aoqi@0 1410 case Bytecodes::_i2b: // fall through
aoqi@0 1411 case Bytecodes::_i2c: // fall through
aoqi@0 1412 case Bytecodes::_i2s: tos_in = itos; break;
aoqi@0 1413 case Bytecodes::_l2i: // fall through
aoqi@0 1414 case Bytecodes::_l2f: // fall through
aoqi@0 1415 case Bytecodes::_l2d: tos_in = ltos; break;
aoqi@0 1416 case Bytecodes::_f2i: // fall through
aoqi@0 1417 case Bytecodes::_f2l: // fall through
aoqi@0 1418 case Bytecodes::_f2d: tos_in = ftos; break;
aoqi@0 1419 case Bytecodes::_d2i: // fall through
aoqi@0 1420 case Bytecodes::_d2l: // fall through
aoqi@0 1421 case Bytecodes::_d2f: tos_in = dtos; break;
aoqi@0 1422 default : ShouldNotReachHere();
aoqi@0 1423 }
aoqi@0 1424 switch (bytecode()) {
aoqi@0 1425 case Bytecodes::_l2i: // fall through
aoqi@0 1426 case Bytecodes::_f2i: // fall through
aoqi@0 1427 case Bytecodes::_d2i: // fall through
aoqi@0 1428 case Bytecodes::_i2b: // fall through
aoqi@0 1429 case Bytecodes::_i2c: // fall through
aoqi@0 1430 case Bytecodes::_i2s: tos_out = itos; break;
aoqi@0 1431 case Bytecodes::_i2l: // fall through
aoqi@0 1432 case Bytecodes::_f2l: // fall through
aoqi@0 1433 case Bytecodes::_d2l: tos_out = ltos; break;
aoqi@0 1434 case Bytecodes::_i2f: // fall through
aoqi@0 1435 case Bytecodes::_l2f: // fall through
aoqi@0 1436 case Bytecodes::_d2f: tos_out = ftos; break;
aoqi@0 1437 case Bytecodes::_i2d: // fall through
aoqi@0 1438 case Bytecodes::_l2d: // fall through
aoqi@0 1439 case Bytecodes::_f2d: tos_out = dtos; break;
aoqi@0 1440 default : ShouldNotReachHere();
aoqi@0 1441 }
aoqi@0 1442 transition(tos_in, tos_out);
aoqi@0 1443 }
aoqi@0 1444 #endif // ASSERT
aoqi@0 1445
aoqi@0 1446 // Conversion
aoqi@0 1447 // (Note: use push(rcx)/pop(rcx) for 1/2-word stack-ptr manipulation)
aoqi@0 1448 switch (bytecode()) {
aoqi@0 1449 case Bytecodes::_i2l:
aoqi@0 1450 __ extend_sign(rdx, rax);
aoqi@0 1451 break;
aoqi@0 1452 case Bytecodes::_i2f:
aoqi@0 1453 __ push(rax); // store int on tos
aoqi@0 1454 __ fild_s(at_rsp()); // load int to ST0
aoqi@0 1455 __ f2ieee(); // truncate to float size
aoqi@0 1456 __ pop(rcx); // adjust rsp
aoqi@0 1457 break;
aoqi@0 1458 case Bytecodes::_i2d:
aoqi@0 1459 __ push(rax); // add one slot for d2ieee()
aoqi@0 1460 __ push(rax); // store int on tos
aoqi@0 1461 __ fild_s(at_rsp()); // load int to ST0
aoqi@0 1462 __ d2ieee(); // truncate to double size
aoqi@0 1463 __ pop(rcx); // adjust rsp
aoqi@0 1464 __ pop(rcx);
aoqi@0 1465 break;
aoqi@0 1466 case Bytecodes::_i2b:
aoqi@0 1467 __ shll(rax, 24); // truncate upper 24 bits
aoqi@0 1468 __ sarl(rax, 24); // and sign-extend byte
aoqi@0 1469 LP64_ONLY(__ movsbl(rax, rax));
aoqi@0 1470 break;
aoqi@0 1471 case Bytecodes::_i2c:
aoqi@0 1472 __ andl(rax, 0xFFFF); // truncate upper 16 bits
aoqi@0 1473 LP64_ONLY(__ movzwl(rax, rax));
aoqi@0 1474 break;
aoqi@0 1475 case Bytecodes::_i2s:
aoqi@0 1476 __ shll(rax, 16); // truncate upper 16 bits
aoqi@0 1477 __ sarl(rax, 16); // and sign-extend short
aoqi@0 1478 LP64_ONLY(__ movswl(rax, rax));
aoqi@0 1479 break;
aoqi@0 1480 case Bytecodes::_l2i:
aoqi@0 1481 /* nothing to do */
aoqi@0 1482 break;
aoqi@0 1483 case Bytecodes::_l2f:
aoqi@0 1484 __ push(rdx); // store long on tos
aoqi@0 1485 __ push(rax);
aoqi@0 1486 __ fild_d(at_rsp()); // load long to ST0
aoqi@0 1487 __ f2ieee(); // truncate to float size
aoqi@0 1488 __ pop(rcx); // adjust rsp
aoqi@0 1489 __ pop(rcx);
aoqi@0 1490 break;
aoqi@0 1491 case Bytecodes::_l2d:
aoqi@0 1492 __ push(rdx); // store long on tos
aoqi@0 1493 __ push(rax);
aoqi@0 1494 __ fild_d(at_rsp()); // load long to ST0
aoqi@0 1495 __ d2ieee(); // truncate to double size
aoqi@0 1496 __ pop(rcx); // adjust rsp
aoqi@0 1497 __ pop(rcx);
aoqi@0 1498 break;
aoqi@0 1499 case Bytecodes::_f2i:
aoqi@0 1500 __ push(rcx); // reserve space for argument
aoqi@0 1501 __ fstp_s(at_rsp()); // pass float argument on stack
aoqi@0 1502 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1);
aoqi@0 1503 break;
aoqi@0 1504 case Bytecodes::_f2l:
aoqi@0 1505 __ push(rcx); // reserve space for argument
aoqi@0 1506 __ fstp_s(at_rsp()); // pass float argument on stack
aoqi@0 1507 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1);
aoqi@0 1508 break;
aoqi@0 1509 case Bytecodes::_f2d:
aoqi@0 1510 /* nothing to do */
aoqi@0 1511 break;
aoqi@0 1512 case Bytecodes::_d2i:
aoqi@0 1513 __ push(rcx); // reserve space for argument
aoqi@0 1514 __ push(rcx);
aoqi@0 1515 __ fstp_d(at_rsp()); // pass double argument on stack
aoqi@0 1516 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 2);
aoqi@0 1517 break;
aoqi@0 1518 case Bytecodes::_d2l:
aoqi@0 1519 __ push(rcx); // reserve space for argument
aoqi@0 1520 __ push(rcx);
aoqi@0 1521 __ fstp_d(at_rsp()); // pass double argument on stack
aoqi@0 1522 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 2);
aoqi@0 1523 break;
aoqi@0 1524 case Bytecodes::_d2f:
aoqi@0 1525 __ push(rcx); // reserve space for f2ieee()
aoqi@0 1526 __ f2ieee(); // truncate to float size
aoqi@0 1527 __ pop(rcx); // adjust rsp
aoqi@0 1528 break;
aoqi@0 1529 default :
aoqi@0 1530 ShouldNotReachHere();
aoqi@0 1531 }
aoqi@0 1532 }
aoqi@0 1533
aoqi@0 1534
aoqi@0 1535 void TemplateTable::lcmp() {
aoqi@0 1536 transition(ltos, itos);
aoqi@0 1537 // y = rdx:rax
aoqi@0 1538 __ pop_l(rbx, rcx); // get x = rcx:rbx
aoqi@0 1539 __ lcmp2int(rcx, rbx, rdx, rax);// rcx := cmp(x, y)
aoqi@0 1540 __ mov(rax, rcx);
aoqi@0 1541 }
aoqi@0 1542
aoqi@0 1543
aoqi@0 1544 void TemplateTable::float_cmp(bool is_float, int unordered_result) {
aoqi@0 1545 if (is_float) {
aoqi@0 1546 __ fld_s(at_rsp());
aoqi@0 1547 } else {
aoqi@0 1548 __ fld_d(at_rsp());
aoqi@0 1549 __ pop(rdx);
aoqi@0 1550 }
aoqi@0 1551 __ pop(rcx);
aoqi@0 1552 __ fcmp2int(rax, unordered_result < 0);
aoqi@0 1553 }
aoqi@0 1554
aoqi@0 1555
aoqi@0 1556 void TemplateTable::branch(bool is_jsr, bool is_wide) {
aoqi@0 1557 __ get_method(rcx); // ECX holds method
aoqi@0 1558 __ profile_taken_branch(rax,rbx); // EAX holds updated MDP, EBX holds bumped taken count
aoqi@0 1559
aoqi@0 1560 const ByteSize be_offset = MethodCounters::backedge_counter_offset() +
aoqi@0 1561 InvocationCounter::counter_offset();
aoqi@0 1562 const ByteSize inv_offset = MethodCounters::invocation_counter_offset() +
aoqi@0 1563 InvocationCounter::counter_offset();
aoqi@0 1564
aoqi@0 1565 // Load up EDX with the branch displacement
aoqi@0 1566 if (is_wide) {
aoqi@0 1567 __ movl(rdx, at_bcp(1));
aoqi@0 1568 } else {
aoqi@0 1569 __ load_signed_short(rdx, at_bcp(1));
aoqi@0 1570 }
aoqi@0 1571 __ bswapl(rdx);
aoqi@0 1572 if (!is_wide) __ sarl(rdx, 16);
aoqi@0 1573 LP64_ONLY(__ movslq(rdx, rdx));
aoqi@0 1574
aoqi@0 1575
aoqi@0 1576 // Handle all the JSR stuff here, then exit.
aoqi@0 1577 // It's much shorter and cleaner than intermingling with the
aoqi@0 1578 // non-JSR normal-branch stuff occurring below.
aoqi@0 1579 if (is_jsr) {
aoqi@0 1580 // Pre-load the next target bytecode into EBX
aoqi@0 1581 __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1, 0));
aoqi@0 1582
aoqi@0 1583 // compute return address as bci in rax,
aoqi@0 1584 __ lea(rax, at_bcp((is_wide ? 5 : 3) - in_bytes(ConstMethod::codes_offset())));
aoqi@0 1585 __ subptr(rax, Address(rcx, Method::const_offset()));
aoqi@0 1586 // Adjust the bcp in RSI by the displacement in EDX
aoqi@0 1587 __ addptr(rsi, rdx);
aoqi@0 1588 // Push return address
aoqi@0 1589 __ push_i(rax);
aoqi@0 1590 // jsr returns vtos
aoqi@0 1591 __ dispatch_only_noverify(vtos);
aoqi@0 1592 return;
aoqi@0 1593 }
aoqi@0 1594
aoqi@0 1595 // Normal (non-jsr) branch handling
aoqi@0 1596
aoqi@0 1597 // Adjust the bcp in RSI by the displacement in EDX
aoqi@0 1598 __ addptr(rsi, rdx);
aoqi@0 1599
aoqi@0 1600 assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters");
aoqi@0 1601 Label backedge_counter_overflow;
aoqi@0 1602 Label profile_method;
aoqi@0 1603 Label dispatch;
aoqi@0 1604 if (UseLoopCounter) {
aoqi@0 1605 // increment backedge counter for backward branches
aoqi@0 1606 // rax,: MDO
aoqi@0 1607 // rbx,: MDO bumped taken-count
aoqi@0 1608 // rcx: method
aoqi@0 1609 // rdx: target offset
aoqi@0 1610 // rsi: target bcp
aoqi@0 1611 // rdi: locals pointer
aoqi@0 1612 __ testl(rdx, rdx); // check if forward or backward branch
aoqi@0 1613 __ jcc(Assembler::positive, dispatch); // count only if backward branch
aoqi@0 1614
aoqi@0 1615 // check if MethodCounters exists
aoqi@0 1616 Label has_counters;
aoqi@0 1617 __ movptr(rax, Address(rcx, Method::method_counters_offset()));
aoqi@0 1618 __ testptr(rax, rax);
aoqi@0 1619 __ jcc(Assembler::notZero, has_counters);
aoqi@0 1620 __ push(rdx);
aoqi@0 1621 __ push(rcx);
aoqi@0 1622 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters),
aoqi@0 1623 rcx);
aoqi@0 1624 __ pop(rcx);
aoqi@0 1625 __ pop(rdx);
aoqi@0 1626 __ movptr(rax, Address(rcx, Method::method_counters_offset()));
aoqi@0 1627 __ testptr(rax, rax);
aoqi@0 1628 __ jcc(Assembler::zero, dispatch);
aoqi@0 1629 __ bind(has_counters);
aoqi@0 1630
aoqi@0 1631 if (TieredCompilation) {
aoqi@0 1632 Label no_mdo;
aoqi@0 1633 int increment = InvocationCounter::count_increment;
aoqi@0 1634 int mask = ((1 << Tier0BackedgeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
aoqi@0 1635 if (ProfileInterpreter) {
aoqi@0 1636 // Are we profiling?
aoqi@0 1637 __ movptr(rbx, Address(rcx, in_bytes(Method::method_data_offset())));
aoqi@0 1638 __ testptr(rbx, rbx);
aoqi@0 1639 __ jccb(Assembler::zero, no_mdo);
aoqi@0 1640 // Increment the MDO backedge counter
aoqi@0 1641 const Address mdo_backedge_counter(rbx, in_bytes(MethodData::backedge_counter_offset()) +
aoqi@0 1642 in_bytes(InvocationCounter::counter_offset()));
aoqi@0 1643 __ increment_mask_and_jump(mdo_backedge_counter, increment, mask,
aoqi@0 1644 rax, false, Assembler::zero, &backedge_counter_overflow);
aoqi@0 1645 __ jmp(dispatch);
aoqi@0 1646 }
aoqi@0 1647 __ bind(no_mdo);
aoqi@0 1648 // Increment backedge counter in MethodCounters*
aoqi@0 1649 __ movptr(rcx, Address(rcx, Method::method_counters_offset()));
aoqi@0 1650 __ increment_mask_and_jump(Address(rcx, be_offset), increment, mask,
aoqi@0 1651 rax, false, Assembler::zero, &backedge_counter_overflow);
aoqi@0 1652 } else {
aoqi@0 1653 // increment counter
aoqi@0 1654 __ movptr(rcx, Address(rcx, Method::method_counters_offset()));
aoqi@0 1655 __ movl(rax, Address(rcx, be_offset)); // load backedge counter
aoqi@0 1656 __ incrementl(rax, InvocationCounter::count_increment); // increment counter
aoqi@0 1657 __ movl(Address(rcx, be_offset), rax); // store counter
aoqi@0 1658
aoqi@0 1659 __ movl(rax, Address(rcx, inv_offset)); // load invocation counter
aoqi@0 1660
aoqi@0 1661 __ andl(rax, InvocationCounter::count_mask_value); // and the status bits
aoqi@0 1662 __ addl(rax, Address(rcx, be_offset)); // add both counters
aoqi@0 1663
aoqi@0 1664 if (ProfileInterpreter) {
aoqi@0 1665 // Test to see if we should create a method data oop
aoqi@0 1666 __ cmp32(rax,
aoqi@0 1667 ExternalAddress((address) &InvocationCounter::InterpreterProfileLimit));
aoqi@0 1668 __ jcc(Assembler::less, dispatch);
aoqi@0 1669
aoqi@0 1670 // if no method data exists, go to profile method
aoqi@0 1671 __ test_method_data_pointer(rax, profile_method);
aoqi@0 1672
aoqi@0 1673 if (UseOnStackReplacement) {
aoqi@0 1674 // check for overflow against rbx, which is the MDO taken count
aoqi@0 1675 __ cmp32(rbx,
aoqi@0 1676 ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
aoqi@0 1677 __ jcc(Assembler::below, dispatch);
aoqi@0 1678
aoqi@0 1679 // When ProfileInterpreter is on, the backedge_count comes from the
aoqi@0 1680 // MethodData*, which value does not get reset on the call to
aoqi@0 1681 // frequency_counter_overflow(). To avoid excessive calls to the overflow
aoqi@0 1682 // routine while the method is being compiled, add a second test to make
aoqi@0 1683 // sure the overflow function is called only once every overflow_frequency.
aoqi@0 1684 const int overflow_frequency = 1024;
aoqi@0 1685 __ andptr(rbx, overflow_frequency-1);
aoqi@0 1686 __ jcc(Assembler::zero, backedge_counter_overflow);
aoqi@0 1687 }
aoqi@0 1688 } else {
aoqi@0 1689 if (UseOnStackReplacement) {
aoqi@0 1690 // check for overflow against rax, which is the sum of the counters
aoqi@0 1691 __ cmp32(rax,
aoqi@0 1692 ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit));
aoqi@0 1693 __ jcc(Assembler::aboveEqual, backedge_counter_overflow);
aoqi@0 1694
aoqi@0 1695 }
aoqi@0 1696 }
aoqi@0 1697 }
aoqi@0 1698 __ bind(dispatch);
aoqi@0 1699 }
aoqi@0 1700
aoqi@0 1701 // Pre-load the next target bytecode into EBX
aoqi@0 1702 __ load_unsigned_byte(rbx, Address(rsi, 0));
aoqi@0 1703
aoqi@0 1704 // continue with the bytecode @ target
aoqi@0 1705 // rax,: return bci for jsr's, unused otherwise
aoqi@0 1706 // rbx,: target bytecode
aoqi@0 1707 // rsi: target bcp
aoqi@0 1708 __ dispatch_only(vtos);
aoqi@0 1709
aoqi@0 1710 if (UseLoopCounter) {
aoqi@0 1711 if (ProfileInterpreter) {
aoqi@0 1712 // Out-of-line code to allocate method data oop.
aoqi@0 1713 __ bind(profile_method);
aoqi@0 1714 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
aoqi@0 1715 __ load_unsigned_byte(rbx, Address(rsi, 0)); // restore target bytecode
aoqi@0 1716 __ set_method_data_pointer_for_bcp();
aoqi@0 1717 __ jmp(dispatch);
aoqi@0 1718 }
aoqi@0 1719
aoqi@0 1720 if (UseOnStackReplacement) {
aoqi@0 1721
aoqi@0 1722 // invocation counter overflow
aoqi@0 1723 __ bind(backedge_counter_overflow);
aoqi@0 1724 __ negptr(rdx);
aoqi@0 1725 __ addptr(rdx, rsi); // branch bcp
aoqi@0 1726 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rdx);
aoqi@0 1727 __ load_unsigned_byte(rbx, Address(rsi, 0)); // restore target bytecode
aoqi@0 1728
aoqi@0 1729 // rax,: osr nmethod (osr ok) or NULL (osr not possible)
aoqi@0 1730 // rbx,: target bytecode
aoqi@0 1731 // rdx: scratch
aoqi@0 1732 // rdi: locals pointer
aoqi@0 1733 // rsi: bcp
aoqi@0 1734 __ testptr(rax, rax); // test result
aoqi@0 1735 __ jcc(Assembler::zero, dispatch); // no osr if null
aoqi@0 1736 // nmethod may have been invalidated (VM may block upon call_VM return)
aoqi@0 1737 __ movl(rcx, Address(rax, nmethod::entry_bci_offset()));
aoqi@0 1738 __ cmpl(rcx, InvalidOSREntryBci);
aoqi@0 1739 __ jcc(Assembler::equal, dispatch);
aoqi@0 1740
aoqi@0 1741 // We have the address of an on stack replacement routine in rax,
aoqi@0 1742 // We need to prepare to execute the OSR method. First we must
aoqi@0 1743 // migrate the locals and monitors off of the stack.
aoqi@0 1744
aoqi@0 1745 __ mov(rbx, rax); // save the nmethod
aoqi@0 1746
aoqi@0 1747 const Register thread = rcx;
aoqi@0 1748 __ get_thread(thread);
aoqi@0 1749 call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin));
aoqi@0 1750 // rax, is OSR buffer, move it to expected parameter location
aoqi@0 1751 __ mov(rcx, rax);
aoqi@0 1752
aoqi@0 1753 // pop the interpreter frame
aoqi@0 1754 __ movptr(rdx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
aoqi@0 1755 __ leave(); // remove frame anchor
aoqi@0 1756 __ pop(rdi); // get return address
aoqi@0 1757 __ mov(rsp, rdx); // set sp to sender sp
aoqi@0 1758
aoqi@0 1759 // Align stack pointer for compiled code (note that caller is
aoqi@0 1760 // responsible for undoing this fixup by remembering the old SP
aoqi@0 1761 // in an rbp,-relative location)
aoqi@0 1762 __ andptr(rsp, -(StackAlignmentInBytes));
aoqi@0 1763
aoqi@0 1764 // push the (possibly adjusted) return address
aoqi@0 1765 __ push(rdi);
aoqi@0 1766
aoqi@0 1767 // and begin the OSR nmethod
aoqi@0 1768 __ jmp(Address(rbx, nmethod::osr_entry_point_offset()));
aoqi@0 1769 }
aoqi@0 1770 }
aoqi@0 1771 }
aoqi@0 1772
aoqi@0 1773
aoqi@0 1774 void TemplateTable::if_0cmp(Condition cc) {
aoqi@0 1775 transition(itos, vtos);
aoqi@0 1776 // assume branch is more often taken than not (loops use backward branches)
aoqi@0 1777 Label not_taken;
aoqi@0 1778 __ testl(rax, rax);
aoqi@0 1779 __ jcc(j_not(cc), not_taken);
aoqi@0 1780 branch(false, false);
aoqi@0 1781 __ bind(not_taken);
aoqi@0 1782 __ profile_not_taken_branch(rax);
aoqi@0 1783 }
aoqi@0 1784
aoqi@0 1785
aoqi@0 1786 void TemplateTable::if_icmp(Condition cc) {
aoqi@0 1787 transition(itos, vtos);
aoqi@0 1788 // assume branch is more often taken than not (loops use backward branches)
aoqi@0 1789 Label not_taken;
aoqi@0 1790 __ pop_i(rdx);
aoqi@0 1791 __ cmpl(rdx, rax);
aoqi@0 1792 __ jcc(j_not(cc), not_taken);
aoqi@0 1793 branch(false, false);
aoqi@0 1794 __ bind(not_taken);
aoqi@0 1795 __ profile_not_taken_branch(rax);
aoqi@0 1796 }
aoqi@0 1797
aoqi@0 1798
aoqi@0 1799 void TemplateTable::if_nullcmp(Condition cc) {
aoqi@0 1800 transition(atos, vtos);
aoqi@0 1801 // assume branch is more often taken than not (loops use backward branches)
aoqi@0 1802 Label not_taken;
aoqi@0 1803 __ testptr(rax, rax);
aoqi@0 1804 __ jcc(j_not(cc), not_taken);
aoqi@0 1805 branch(false, false);
aoqi@0 1806 __ bind(not_taken);
aoqi@0 1807 __ profile_not_taken_branch(rax);
aoqi@0 1808 }
aoqi@0 1809
aoqi@0 1810
aoqi@0 1811 void TemplateTable::if_acmp(Condition cc) {
aoqi@0 1812 transition(atos, vtos);
aoqi@0 1813 // assume branch is more often taken than not (loops use backward branches)
aoqi@0 1814 Label not_taken;
aoqi@0 1815 __ pop_ptr(rdx);
aoqi@0 1816 __ cmpptr(rdx, rax);
aoqi@0 1817 __ jcc(j_not(cc), not_taken);
aoqi@0 1818 branch(false, false);
aoqi@0 1819 __ bind(not_taken);
aoqi@0 1820 __ profile_not_taken_branch(rax);
aoqi@0 1821 }
aoqi@0 1822
aoqi@0 1823
aoqi@0 1824 void TemplateTable::ret() {
aoqi@0 1825 transition(vtos, vtos);
aoqi@0 1826 locals_index(rbx);
aoqi@0 1827 __ movptr(rbx, iaddress(rbx)); // get return bci, compute return bcp
aoqi@0 1828 __ profile_ret(rbx, rcx);
aoqi@0 1829 __ get_method(rax);
aoqi@0 1830 __ movptr(rsi, Address(rax, Method::const_offset()));
aoqi@0 1831 __ lea(rsi, Address(rsi, rbx, Address::times_1,
aoqi@0 1832 ConstMethod::codes_offset()));
aoqi@0 1833 __ dispatch_next(vtos);
aoqi@0 1834 }
aoqi@0 1835
aoqi@0 1836
aoqi@0 1837 void TemplateTable::wide_ret() {
aoqi@0 1838 transition(vtos, vtos);
aoqi@0 1839 locals_index_wide(rbx);
aoqi@0 1840 __ movptr(rbx, iaddress(rbx)); // get return bci, compute return bcp
aoqi@0 1841 __ profile_ret(rbx, rcx);
aoqi@0 1842 __ get_method(rax);
aoqi@0 1843 __ movptr(rsi, Address(rax, Method::const_offset()));
aoqi@0 1844 __ lea(rsi, Address(rsi, rbx, Address::times_1, ConstMethod::codes_offset()));
aoqi@0 1845 __ dispatch_next(vtos);
aoqi@0 1846 }
aoqi@0 1847
aoqi@0 1848
aoqi@0 1849 void TemplateTable::tableswitch() {
aoqi@0 1850 Label default_case, continue_execution;
aoqi@0 1851 transition(itos, vtos);
aoqi@0 1852 // align rsi
aoqi@0 1853 __ lea(rbx, at_bcp(wordSize));
aoqi@0 1854 __ andptr(rbx, -wordSize);
aoqi@0 1855 // load lo & hi
aoqi@0 1856 __ movl(rcx, Address(rbx, 1 * wordSize));
aoqi@0 1857 __ movl(rdx, Address(rbx, 2 * wordSize));
aoqi@0 1858 __ bswapl(rcx);
aoqi@0 1859 __ bswapl(rdx);
aoqi@0 1860 // check against lo & hi
aoqi@0 1861 __ cmpl(rax, rcx);
aoqi@0 1862 __ jccb(Assembler::less, default_case);
aoqi@0 1863 __ cmpl(rax, rdx);
aoqi@0 1864 __ jccb(Assembler::greater, default_case);
aoqi@0 1865 // lookup dispatch offset
aoqi@0 1866 __ subl(rax, rcx);
aoqi@0 1867 __ movl(rdx, Address(rbx, rax, Address::times_4, 3 * BytesPerInt));
aoqi@0 1868 __ profile_switch_case(rax, rbx, rcx);
aoqi@0 1869 // continue execution
aoqi@0 1870 __ bind(continue_execution);
aoqi@0 1871 __ bswapl(rdx);
aoqi@0 1872 __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
aoqi@0 1873 __ addptr(rsi, rdx);
aoqi@0 1874 __ dispatch_only(vtos);
aoqi@0 1875 // handle default
aoqi@0 1876 __ bind(default_case);
aoqi@0 1877 __ profile_switch_default(rax);
aoqi@0 1878 __ movl(rdx, Address(rbx, 0));
aoqi@0 1879 __ jmp(continue_execution);
aoqi@0 1880 }
aoqi@0 1881
aoqi@0 1882
aoqi@0 1883 void TemplateTable::lookupswitch() {
aoqi@0 1884 transition(itos, itos);
aoqi@0 1885 __ stop("lookupswitch bytecode should have been rewritten");
aoqi@0 1886 }
aoqi@0 1887
aoqi@0 1888
aoqi@0 1889 void TemplateTable::fast_linearswitch() {
aoqi@0 1890 transition(itos, vtos);
aoqi@0 1891 Label loop_entry, loop, found, continue_execution;
aoqi@0 1892 // bswapl rax, so we can avoid bswapping the table entries
aoqi@0 1893 __ bswapl(rax);
aoqi@0 1894 // align rsi
aoqi@0 1895 __ lea(rbx, at_bcp(wordSize)); // btw: should be able to get rid of this instruction (change offsets below)
aoqi@0 1896 __ andptr(rbx, -wordSize);
aoqi@0 1897 // set counter
aoqi@0 1898 __ movl(rcx, Address(rbx, wordSize));
aoqi@0 1899 __ bswapl(rcx);
aoqi@0 1900 __ jmpb(loop_entry);
aoqi@0 1901 // table search
aoqi@0 1902 __ bind(loop);
aoqi@0 1903 __ cmpl(rax, Address(rbx, rcx, Address::times_8, 2 * wordSize));
aoqi@0 1904 __ jccb(Assembler::equal, found);
aoqi@0 1905 __ bind(loop_entry);
aoqi@0 1906 __ decrementl(rcx);
aoqi@0 1907 __ jcc(Assembler::greaterEqual, loop);
aoqi@0 1908 // default case
aoqi@0 1909 __ profile_switch_default(rax);
aoqi@0 1910 __ movl(rdx, Address(rbx, 0));
aoqi@0 1911 __ jmpb(continue_execution);
aoqi@0 1912 // entry found -> get offset
aoqi@0 1913 __ bind(found);
aoqi@0 1914 __ movl(rdx, Address(rbx, rcx, Address::times_8, 3 * wordSize));
aoqi@0 1915 __ profile_switch_case(rcx, rax, rbx);
aoqi@0 1916 // continue execution
aoqi@0 1917 __ bind(continue_execution);
aoqi@0 1918 __ bswapl(rdx);
aoqi@0 1919 __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1));
aoqi@0 1920 __ addptr(rsi, rdx);
aoqi@0 1921 __ dispatch_only(vtos);
aoqi@0 1922 }
aoqi@0 1923
aoqi@0 1924
aoqi@0 1925 void TemplateTable::fast_binaryswitch() {
aoqi@0 1926 transition(itos, vtos);
aoqi@0 1927 // Implementation using the following core algorithm:
aoqi@0 1928 //
aoqi@0 1929 // int binary_search(int key, LookupswitchPair* array, int n) {
aoqi@0 1930 // // Binary search according to "Methodik des Programmierens" by
aoqi@0 1931 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
aoqi@0 1932 // int i = 0;
aoqi@0 1933 // int j = n;
aoqi@0 1934 // while (i+1 < j) {
aoqi@0 1935 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
aoqi@0 1936 // // with Q: for all i: 0 <= i < n: key < a[i]
aoqi@0 1937 // // where a stands for the array and assuming that the (inexisting)
aoqi@0 1938 // // element a[n] is infinitely big.
aoqi@0 1939 // int h = (i + j) >> 1;
aoqi@0 1940 // // i < h < j
aoqi@0 1941 // if (key < array[h].fast_match()) {
aoqi@0 1942 // j = h;
aoqi@0 1943 // } else {
aoqi@0 1944 // i = h;
aoqi@0 1945 // }
aoqi@0 1946 // }
aoqi@0 1947 // // R: a[i] <= key < a[i+1] or Q
aoqi@0 1948 // // (i.e., if key is within array, i is the correct index)
aoqi@0 1949 // return i;
aoqi@0 1950 // }
aoqi@0 1951
aoqi@0 1952 // register allocation
aoqi@0 1953 const Register key = rax; // already set (tosca)
aoqi@0 1954 const Register array = rbx;
aoqi@0 1955 const Register i = rcx;
aoqi@0 1956 const Register j = rdx;
aoqi@0 1957 const Register h = rdi; // needs to be restored
aoqi@0 1958 const Register temp = rsi;
aoqi@0 1959 // setup array
aoqi@0 1960 __ save_bcp();
aoqi@0 1961
aoqi@0 1962 __ lea(array, at_bcp(3*wordSize)); // btw: should be able to get rid of this instruction (change offsets below)
aoqi@0 1963 __ andptr(array, -wordSize);
aoqi@0 1964 // initialize i & j
aoqi@0 1965 __ xorl(i, i); // i = 0;
aoqi@0 1966 __ movl(j, Address(array, -wordSize)); // j = length(array);
aoqi@0 1967 // Convert j into native byteordering
aoqi@0 1968 __ bswapl(j);
aoqi@0 1969 // and start
aoqi@0 1970 Label entry;
aoqi@0 1971 __ jmp(entry);
aoqi@0 1972
aoqi@0 1973 // binary search loop
aoqi@0 1974 { Label loop;
aoqi@0 1975 __ bind(loop);
aoqi@0 1976 // int h = (i + j) >> 1;
aoqi@0 1977 __ leal(h, Address(i, j, Address::times_1)); // h = i + j;
aoqi@0 1978 __ sarl(h, 1); // h = (i + j) >> 1;
aoqi@0 1979 // if (key < array[h].fast_match()) {
aoqi@0 1980 // j = h;
aoqi@0 1981 // } else {
aoqi@0 1982 // i = h;
aoqi@0 1983 // }
aoqi@0 1984 // Convert array[h].match to native byte-ordering before compare
aoqi@0 1985 __ movl(temp, Address(array, h, Address::times_8, 0*wordSize));
aoqi@0 1986 __ bswapl(temp);
aoqi@0 1987 __ cmpl(key, temp);
aoqi@0 1988 // j = h if (key < array[h].fast_match())
aoqi@0 1989 __ cmov32(Assembler::less , j, h);
aoqi@0 1990 // i = h if (key >= array[h].fast_match())
aoqi@0 1991 __ cmov32(Assembler::greaterEqual, i, h);
aoqi@0 1992 // while (i+1 < j)
aoqi@0 1993 __ bind(entry);
aoqi@0 1994 __ leal(h, Address(i, 1)); // i+1
aoqi@0 1995 __ cmpl(h, j); // i+1 < j
aoqi@0 1996 __ jcc(Assembler::less, loop);
aoqi@0 1997 }
aoqi@0 1998
aoqi@0 1999 // end of binary search, result index is i (must check again!)
aoqi@0 2000 Label default_case;
aoqi@0 2001 // Convert array[i].match to native byte-ordering before compare
aoqi@0 2002 __ movl(temp, Address(array, i, Address::times_8, 0*wordSize));
aoqi@0 2003 __ bswapl(temp);
aoqi@0 2004 __ cmpl(key, temp);
aoqi@0 2005 __ jcc(Assembler::notEqual, default_case);
aoqi@0 2006
aoqi@0 2007 // entry found -> j = offset
aoqi@0 2008 __ movl(j , Address(array, i, Address::times_8, 1*wordSize));
aoqi@0 2009 __ profile_switch_case(i, key, array);
aoqi@0 2010 __ bswapl(j);
aoqi@0 2011 LP64_ONLY(__ movslq(j, j));
aoqi@0 2012 __ restore_bcp();
aoqi@0 2013 __ restore_locals(); // restore rdi
aoqi@0 2014 __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
aoqi@0 2015
aoqi@0 2016 __ addptr(rsi, j);
aoqi@0 2017 __ dispatch_only(vtos);
aoqi@0 2018
aoqi@0 2019 // default case -> j = default offset
aoqi@0 2020 __ bind(default_case);
aoqi@0 2021 __ profile_switch_default(i);
aoqi@0 2022 __ movl(j, Address(array, -2*wordSize));
aoqi@0 2023 __ bswapl(j);
aoqi@0 2024 LP64_ONLY(__ movslq(j, j));
aoqi@0 2025 __ restore_bcp();
aoqi@0 2026 __ restore_locals(); // restore rdi
aoqi@0 2027 __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1));
aoqi@0 2028 __ addptr(rsi, j);
aoqi@0 2029 __ dispatch_only(vtos);
aoqi@0 2030 }
aoqi@0 2031
aoqi@0 2032
aoqi@0 2033 void TemplateTable::_return(TosState state) {
aoqi@0 2034 transition(state, state);
aoqi@0 2035 assert(_desc->calls_vm(), "inconsistent calls_vm information"); // call in remove_activation
aoqi@0 2036
aoqi@0 2037 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
aoqi@0 2038 assert(state == vtos, "only valid state");
aoqi@0 2039 __ movptr(rax, aaddress(0));
aoqi@0 2040 __ load_klass(rdi, rax);
aoqi@0 2041 __ movl(rdi, Address(rdi, Klass::access_flags_offset()));
aoqi@0 2042 __ testl(rdi, JVM_ACC_HAS_FINALIZER);
aoqi@0 2043 Label skip_register_finalizer;
aoqi@0 2044 __ jcc(Assembler::zero, skip_register_finalizer);
aoqi@0 2045
aoqi@0 2046 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), rax);
aoqi@0 2047
aoqi@0 2048 __ bind(skip_register_finalizer);
aoqi@0 2049 }
aoqi@0 2050
kevinw@8368 2051 // Narrow result if state is itos but result type is smaller.
kevinw@8368 2052 // Need to narrow in the return bytecode rather than in generate_return_entry
kevinw@8368 2053 // since compiled code callers expect the result to already be narrowed.
kevinw@8368 2054 if (state == itos) {
kevinw@8368 2055 __ narrow(rax);
kevinw@8368 2056 }
aoqi@0 2057 __ remove_activation(state, rsi);
kevinw@8368 2058
aoqi@0 2059 __ jmp(rsi);
aoqi@0 2060 }
aoqi@0 2061
aoqi@0 2062
aoqi@0 2063 // ----------------------------------------------------------------------------
aoqi@0 2064 // Volatile variables demand their effects be made known to all CPU's in
aoqi@0 2065 // order. Store buffers on most chips allow reads & writes to reorder; the
aoqi@0 2066 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
aoqi@0 2067 // memory barrier (i.e., it's not sufficient that the interpreter does not
aoqi@0 2068 // reorder volatile references, the hardware also must not reorder them).
aoqi@0 2069 //
aoqi@0 2070 // According to the new Java Memory Model (JMM):
aoqi@0 2071 // (1) All volatiles are serialized wrt to each other.
aoqi@0 2072 // ALSO reads & writes act as aquire & release, so:
aoqi@0 2073 // (2) A read cannot let unrelated NON-volatile memory refs that happen after
aoqi@0 2074 // the read float up to before the read. It's OK for non-volatile memory refs
aoqi@0 2075 // that happen before the volatile read to float down below it.
aoqi@0 2076 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
aoqi@0 2077 // that happen BEFORE the write float down to after the write. It's OK for
aoqi@0 2078 // non-volatile memory refs that happen after the volatile write to float up
aoqi@0 2079 // before it.
aoqi@0 2080 //
aoqi@0 2081 // We only put in barriers around volatile refs (they are expensive), not
aoqi@0 2082 // _between_ memory refs (that would require us to track the flavor of the
aoqi@0 2083 // previous memory refs). Requirements (2) and (3) require some barriers
aoqi@0 2084 // before volatile stores and after volatile loads. These nearly cover
aoqi@0 2085 // requirement (1) but miss the volatile-store-volatile-load case. This final
aoqi@0 2086 // case is placed after volatile-stores although it could just as well go
aoqi@0 2087 // before volatile-loads.
aoqi@0 2088 void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint ) {
aoqi@0 2089 // Helper function to insert a is-volatile test and memory barrier
aoqi@0 2090 if( !os::is_MP() ) return; // Not needed on single CPU
aoqi@0 2091 __ membar(order_constraint);
aoqi@0 2092 }
aoqi@0 2093
aoqi@0 2094 void TemplateTable::resolve_cache_and_index(int byte_no,
aoqi@0 2095 Register Rcache,
aoqi@0 2096 Register index,
aoqi@0 2097 size_t index_size) {
aoqi@0 2098 const Register temp = rbx;
aoqi@0 2099 assert_different_registers(Rcache, index, temp);
aoqi@0 2100
aoqi@0 2101 Label resolved;
aoqi@0 2102 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
aoqi@0 2103 __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size);
aoqi@0 2104 __ cmpl(temp, (int) bytecode()); // have we resolved this bytecode?
aoqi@0 2105 __ jcc(Assembler::equal, resolved);
aoqi@0 2106
aoqi@0 2107 // resolve first time through
aoqi@0 2108 address entry;
aoqi@0 2109 switch (bytecode()) {
aoqi@0 2110 case Bytecodes::_getstatic : // fall through
aoqi@0 2111 case Bytecodes::_putstatic : // fall through
aoqi@0 2112 case Bytecodes::_getfield : // fall through
aoqi@0 2113 case Bytecodes::_putfield : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
aoqi@0 2114 case Bytecodes::_invokevirtual : // fall through
aoqi@0 2115 case Bytecodes::_invokespecial : // fall through
aoqi@0 2116 case Bytecodes::_invokestatic : // fall through
aoqi@0 2117 case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke); break;
aoqi@0 2118 case Bytecodes::_invokehandle : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle); break;
aoqi@0 2119 case Bytecodes::_invokedynamic : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic); break;
aoqi@0 2120 default:
aoqi@0 2121 fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode())));
aoqi@0 2122 break;
aoqi@0 2123 }
aoqi@0 2124 __ movl(temp, (int)bytecode());
aoqi@0 2125 __ call_VM(noreg, entry, temp);
aoqi@0 2126 // Update registers with resolved info
aoqi@0 2127 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
aoqi@0 2128 __ bind(resolved);
aoqi@0 2129 }
aoqi@0 2130
aoqi@0 2131
aoqi@0 2132 // The cache and index registers must be set before call
aoqi@0 2133 void TemplateTable::load_field_cp_cache_entry(Register obj,
aoqi@0 2134 Register cache,
aoqi@0 2135 Register index,
aoqi@0 2136 Register off,
aoqi@0 2137 Register flags,
aoqi@0 2138 bool is_static = false) {
aoqi@0 2139 assert_different_registers(cache, index, flags, off);
aoqi@0 2140
aoqi@0 2141 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 2142 // Field offset
aoqi@0 2143 __ movptr(off, Address(cache, index, Address::times_ptr,
aoqi@0 2144 in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset())));
aoqi@0 2145 // Flags
aoqi@0 2146 __ movl(flags, Address(cache, index, Address::times_ptr,
aoqi@0 2147 in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset())));
aoqi@0 2148
aoqi@0 2149 // klass overwrite register
aoqi@0 2150 if (is_static) {
aoqi@0 2151 __ movptr(obj, Address(cache, index, Address::times_ptr,
aoqi@0 2152 in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset())));
aoqi@0 2153 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
aoqi@0 2154 __ movptr(obj, Address(obj, mirror_offset));
aoqi@0 2155 }
aoqi@0 2156 }
aoqi@0 2157
aoqi@0 2158 void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
aoqi@0 2159 Register method,
aoqi@0 2160 Register itable_index,
aoqi@0 2161 Register flags,
aoqi@0 2162 bool is_invokevirtual,
aoqi@0 2163 bool is_invokevfinal, /*unused*/
aoqi@0 2164 bool is_invokedynamic) {
aoqi@0 2165 // setup registers
aoqi@0 2166 const Register cache = rcx;
aoqi@0 2167 const Register index = rdx;
aoqi@0 2168 assert_different_registers(method, flags);
aoqi@0 2169 assert_different_registers(method, cache, index);
aoqi@0 2170 assert_different_registers(itable_index, flags);
aoqi@0 2171 assert_different_registers(itable_index, cache, index);
aoqi@0 2172 // determine constant pool cache field offsets
aoqi@0 2173 assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant");
aoqi@0 2174 const int method_offset = in_bytes(
aoqi@0 2175 ConstantPoolCache::base_offset() +
aoqi@0 2176 ((byte_no == f2_byte)
aoqi@0 2177 ? ConstantPoolCacheEntry::f2_offset()
aoqi@0 2178 : ConstantPoolCacheEntry::f1_offset()));
aoqi@0 2179 const int flags_offset = in_bytes(ConstantPoolCache::base_offset() +
aoqi@0 2180 ConstantPoolCacheEntry::flags_offset());
aoqi@0 2181 // access constant pool cache fields
aoqi@0 2182 const int index_offset = in_bytes(ConstantPoolCache::base_offset() +
aoqi@0 2183 ConstantPoolCacheEntry::f2_offset());
aoqi@0 2184
aoqi@0 2185 size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2));
aoqi@0 2186 resolve_cache_and_index(byte_no, cache, index, index_size);
aoqi@0 2187 __ movptr(method, Address(cache, index, Address::times_ptr, method_offset));
aoqi@0 2188
aoqi@0 2189 if (itable_index != noreg) {
aoqi@0 2190 __ movptr(itable_index, Address(cache, index, Address::times_ptr, index_offset));
aoqi@0 2191 }
aoqi@0 2192 __ movl(flags, Address(cache, index, Address::times_ptr, flags_offset));
aoqi@0 2193 }
aoqi@0 2194
aoqi@0 2195
aoqi@0 2196 // The registers cache and index expected to be set before call.
aoqi@0 2197 // Correct values of the cache and index registers are preserved.
aoqi@0 2198 void TemplateTable::jvmti_post_field_access(Register cache,
aoqi@0 2199 Register index,
aoqi@0 2200 bool is_static,
aoqi@0 2201 bool has_tos) {
aoqi@0 2202 if (JvmtiExport::can_post_field_access()) {
aoqi@0 2203 // Check to see if a field access watch has been set before we take
aoqi@0 2204 // the time to call into the VM.
aoqi@0 2205 Label L1;
aoqi@0 2206 assert_different_registers(cache, index, rax);
aoqi@0 2207 __ mov32(rax, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
aoqi@0 2208 __ testl(rax,rax);
aoqi@0 2209 __ jcc(Assembler::zero, L1);
aoqi@0 2210
aoqi@0 2211 // cache entry pointer
aoqi@0 2212 __ addptr(cache, in_bytes(ConstantPoolCache::base_offset()));
aoqi@0 2213 __ shll(index, LogBytesPerWord);
aoqi@0 2214 __ addptr(cache, index);
aoqi@0 2215 if (is_static) {
aoqi@0 2216 __ xorptr(rax, rax); // NULL object reference
aoqi@0 2217 } else {
aoqi@0 2218 __ pop(atos); // Get the object
aoqi@0 2219 __ verify_oop(rax);
aoqi@0 2220 __ push(atos); // Restore stack state
aoqi@0 2221 }
aoqi@0 2222 // rax,: object pointer or NULL
aoqi@0 2223 // cache: cache entry pointer
aoqi@0 2224 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
aoqi@0 2225 rax, cache);
aoqi@0 2226 __ get_cache_and_index_at_bcp(cache, index, 1);
aoqi@0 2227 __ bind(L1);
aoqi@0 2228 }
aoqi@0 2229 }
aoqi@0 2230
aoqi@0 2231 void TemplateTable::pop_and_check_object(Register r) {
aoqi@0 2232 __ pop_ptr(r);
aoqi@0 2233 __ null_check(r); // for field access must check obj.
aoqi@0 2234 __ verify_oop(r);
aoqi@0 2235 }
aoqi@0 2236
aoqi@0 2237 void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
aoqi@0 2238 transition(vtos, vtos);
aoqi@0 2239
aoqi@0 2240 const Register cache = rcx;
aoqi@0 2241 const Register index = rdx;
aoqi@0 2242 const Register obj = rcx;
aoqi@0 2243 const Register off = rbx;
aoqi@0 2244 const Register flags = rax;
aoqi@0 2245
aoqi@0 2246 resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
aoqi@0 2247 jvmti_post_field_access(cache, index, is_static, false);
aoqi@0 2248 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
aoqi@0 2249
aoqi@0 2250 if (!is_static) pop_and_check_object(obj);
aoqi@0 2251
aoqi@0 2252 const Address lo(obj, off, Address::times_1, 0*wordSize);
aoqi@0 2253 const Address hi(obj, off, Address::times_1, 1*wordSize);
aoqi@0 2254
kevinw@8368 2255 Label Done, notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
aoqi@0 2256
aoqi@0 2257 __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
aoqi@0 2258 assert(btos == 0, "change code, btos != 0");
aoqi@0 2259 // btos
aoqi@0 2260 __ andptr(flags, ConstantPoolCacheEntry::tos_state_mask);
aoqi@0 2261 __ jcc(Assembler::notZero, notByte);
aoqi@0 2262
aoqi@0 2263 __ load_signed_byte(rax, lo );
aoqi@0 2264 __ push(btos);
aoqi@0 2265 // Rewrite bytecode to be faster
aoqi@0 2266 if (!is_static) {
aoqi@0 2267 patch_bytecode(Bytecodes::_fast_bgetfield, rcx, rbx);
aoqi@0 2268 }
aoqi@0 2269 __ jmp(Done);
aoqi@0 2270
aoqi@0 2271 __ bind(notByte);
kevinw@8368 2272
kevinw@8368 2273 __ cmpl(flags, ztos);
kevinw@8368 2274 __ jcc(Assembler::notEqual, notBool);
kevinw@8368 2275
kevinw@8368 2276 // ztos (same code as btos)
kevinw@8368 2277 __ load_signed_byte(rax, lo);
kevinw@8368 2278 __ push(ztos);
kevinw@8368 2279 // Rewrite bytecode to be faster
kevinw@8368 2280 if (!is_static) {
kevinw@8368 2281 // use btos rewriting, no truncating to t/f bit is needed for getfield.
kevinw@8368 2282 patch_bytecode(Bytecodes::_fast_bgetfield, rcx, rbx);
kevinw@8368 2283 }
kevinw@8368 2284 __ jmp(Done);
kevinw@8368 2285
kevinw@8368 2286 __ bind(notBool);
kevinw@8368 2287
aoqi@0 2288 // itos
aoqi@0 2289 __ cmpl(flags, itos );
aoqi@0 2290 __ jcc(Assembler::notEqual, notInt);
aoqi@0 2291
aoqi@0 2292 __ movl(rax, lo );
aoqi@0 2293 __ push(itos);
aoqi@0 2294 // Rewrite bytecode to be faster
aoqi@0 2295 if (!is_static) {
aoqi@0 2296 patch_bytecode(Bytecodes::_fast_igetfield, rcx, rbx);
aoqi@0 2297 }
aoqi@0 2298 __ jmp(Done);
aoqi@0 2299
aoqi@0 2300 __ bind(notInt);
aoqi@0 2301 // atos
aoqi@0 2302 __ cmpl(flags, atos );
aoqi@0 2303 __ jcc(Assembler::notEqual, notObj);
aoqi@0 2304
aoqi@0 2305 __ movl(rax, lo );
aoqi@0 2306 __ push(atos);
aoqi@0 2307 if (!is_static) {
aoqi@0 2308 patch_bytecode(Bytecodes::_fast_agetfield, rcx, rbx);
aoqi@0 2309 }
aoqi@0 2310 __ jmp(Done);
aoqi@0 2311
aoqi@0 2312 __ bind(notObj);
aoqi@0 2313 // ctos
aoqi@0 2314 __ cmpl(flags, ctos );
aoqi@0 2315 __ jcc(Assembler::notEqual, notChar);
aoqi@0 2316
aoqi@0 2317 __ load_unsigned_short(rax, lo );
aoqi@0 2318 __ push(ctos);
aoqi@0 2319 if (!is_static) {
aoqi@0 2320 patch_bytecode(Bytecodes::_fast_cgetfield, rcx, rbx);
aoqi@0 2321 }
aoqi@0 2322 __ jmp(Done);
aoqi@0 2323
aoqi@0 2324 __ bind(notChar);
aoqi@0 2325 // stos
aoqi@0 2326 __ cmpl(flags, stos );
aoqi@0 2327 __ jcc(Assembler::notEqual, notShort);
aoqi@0 2328
aoqi@0 2329 __ load_signed_short(rax, lo );
aoqi@0 2330 __ push(stos);
aoqi@0 2331 if (!is_static) {
aoqi@0 2332 patch_bytecode(Bytecodes::_fast_sgetfield, rcx, rbx);
aoqi@0 2333 }
aoqi@0 2334 __ jmp(Done);
aoqi@0 2335
aoqi@0 2336 __ bind(notShort);
aoqi@0 2337 // ltos
aoqi@0 2338 __ cmpl(flags, ltos );
aoqi@0 2339 __ jcc(Assembler::notEqual, notLong);
aoqi@0 2340
aoqi@0 2341 // Generate code as if volatile. There just aren't enough registers to
aoqi@0 2342 // save that information and this code is faster than the test.
aoqi@0 2343 __ fild_d(lo); // Must load atomically
aoqi@0 2344 __ subptr(rsp,2*wordSize); // Make space for store
aoqi@0 2345 __ fistp_d(Address(rsp,0));
aoqi@0 2346 __ pop(rax);
aoqi@0 2347 __ pop(rdx);
aoqi@0 2348
aoqi@0 2349 __ push(ltos);
aoqi@0 2350 // Don't rewrite to _fast_lgetfield for potential volatile case.
aoqi@0 2351 __ jmp(Done);
aoqi@0 2352
aoqi@0 2353 __ bind(notLong);
aoqi@0 2354 // ftos
aoqi@0 2355 __ cmpl(flags, ftos );
aoqi@0 2356 __ jcc(Assembler::notEqual, notFloat);
aoqi@0 2357
aoqi@0 2358 __ fld_s(lo);
aoqi@0 2359 __ push(ftos);
aoqi@0 2360 if (!is_static) {
aoqi@0 2361 patch_bytecode(Bytecodes::_fast_fgetfield, rcx, rbx);
aoqi@0 2362 }
aoqi@0 2363 __ jmp(Done);
aoqi@0 2364
aoqi@0 2365 __ bind(notFloat);
aoqi@0 2366 // dtos
aoqi@0 2367 __ cmpl(flags, dtos );
aoqi@0 2368 __ jcc(Assembler::notEqual, notDouble);
aoqi@0 2369
aoqi@0 2370 __ fld_d(lo);
aoqi@0 2371 __ push(dtos);
aoqi@0 2372 if (!is_static) {
aoqi@0 2373 patch_bytecode(Bytecodes::_fast_dgetfield, rcx, rbx);
aoqi@0 2374 }
aoqi@0 2375 __ jmpb(Done);
aoqi@0 2376
aoqi@0 2377 __ bind(notDouble);
aoqi@0 2378
aoqi@0 2379 __ stop("Bad state");
aoqi@0 2380
aoqi@0 2381 __ bind(Done);
aoqi@0 2382 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
aoqi@0 2383 // volatile_barrier( );
aoqi@0 2384 }
aoqi@0 2385
aoqi@0 2386
aoqi@0 2387 void TemplateTable::getfield(int byte_no) {
aoqi@0 2388 getfield_or_static(byte_no, false);
aoqi@0 2389 }
aoqi@0 2390
aoqi@0 2391
aoqi@0 2392 void TemplateTable::getstatic(int byte_no) {
aoqi@0 2393 getfield_or_static(byte_no, true);
aoqi@0 2394 }
aoqi@0 2395
aoqi@0 2396 // The registers cache and index expected to be set before call.
aoqi@0 2397 // The function may destroy various registers, just not the cache and index registers.
aoqi@0 2398 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
aoqi@0 2399
aoqi@0 2400 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 2401
aoqi@0 2402 if (JvmtiExport::can_post_field_modification()) {
aoqi@0 2403 // Check to see if a field modification watch has been set before we take
aoqi@0 2404 // the time to call into the VM.
aoqi@0 2405 Label L1;
aoqi@0 2406 assert_different_registers(cache, index, rax);
aoqi@0 2407 __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
aoqi@0 2408 __ testl(rax, rax);
aoqi@0 2409 __ jcc(Assembler::zero, L1);
aoqi@0 2410
aoqi@0 2411 // The cache and index registers have been already set.
aoqi@0 2412 // This allows to eliminate this call but the cache and index
aoqi@0 2413 // registers have to be correspondingly used after this line.
aoqi@0 2414 __ get_cache_and_index_at_bcp(rax, rdx, 1);
aoqi@0 2415
aoqi@0 2416 if (is_static) {
aoqi@0 2417 // Life is simple. Null out the object pointer.
aoqi@0 2418 __ xorptr(rbx, rbx);
aoqi@0 2419 } else {
aoqi@0 2420 // Life is harder. The stack holds the value on top, followed by the object.
aoqi@0 2421 // We don't know the size of the value, though; it could be one or two words
aoqi@0 2422 // depending on its type. As a result, we must find the type to determine where
aoqi@0 2423 // the object is.
aoqi@0 2424 Label two_word, valsize_known;
aoqi@0 2425 __ movl(rcx, Address(rax, rdx, Address::times_ptr, in_bytes(cp_base_offset +
aoqi@0 2426 ConstantPoolCacheEntry::flags_offset())));
aoqi@0 2427 __ mov(rbx, rsp);
aoqi@0 2428 __ shrl(rcx, ConstantPoolCacheEntry::tos_state_shift);
aoqi@0 2429 // Make sure we don't need to mask rcx after the above shift
aoqi@0 2430 ConstantPoolCacheEntry::verify_tos_state_shift();
aoqi@0 2431 __ cmpl(rcx, ltos);
aoqi@0 2432 __ jccb(Assembler::equal, two_word);
aoqi@0 2433 __ cmpl(rcx, dtos);
aoqi@0 2434 __ jccb(Assembler::equal, two_word);
aoqi@0 2435 __ addptr(rbx, Interpreter::expr_offset_in_bytes(1)); // one word jvalue (not ltos, dtos)
aoqi@0 2436 __ jmpb(valsize_known);
aoqi@0 2437
aoqi@0 2438 __ bind(two_word);
aoqi@0 2439 __ addptr(rbx, Interpreter::expr_offset_in_bytes(2)); // two words jvalue
aoqi@0 2440
aoqi@0 2441 __ bind(valsize_known);
aoqi@0 2442 // setup object pointer
aoqi@0 2443 __ movptr(rbx, Address(rbx, 0));
aoqi@0 2444 }
aoqi@0 2445 // cache entry pointer
aoqi@0 2446 __ addptr(rax, in_bytes(cp_base_offset));
aoqi@0 2447 __ shll(rdx, LogBytesPerWord);
aoqi@0 2448 __ addptr(rax, rdx);
aoqi@0 2449 // object (tos)
aoqi@0 2450 __ mov(rcx, rsp);
aoqi@0 2451 // rbx,: object pointer set up above (NULL if static)
aoqi@0 2452 // rax,: cache entry pointer
aoqi@0 2453 // rcx: jvalue object on the stack
aoqi@0 2454 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
aoqi@0 2455 rbx, rax, rcx);
aoqi@0 2456 __ get_cache_and_index_at_bcp(cache, index, 1);
aoqi@0 2457 __ bind(L1);
aoqi@0 2458 }
aoqi@0 2459 }
aoqi@0 2460
aoqi@0 2461
aoqi@0 2462 void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
aoqi@0 2463 transition(vtos, vtos);
aoqi@0 2464
aoqi@0 2465 const Register cache = rcx;
aoqi@0 2466 const Register index = rdx;
aoqi@0 2467 const Register obj = rcx;
aoqi@0 2468 const Register off = rbx;
aoqi@0 2469 const Register flags = rax;
aoqi@0 2470
aoqi@0 2471 resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
aoqi@0 2472 jvmti_post_field_mod(cache, index, is_static);
aoqi@0 2473 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
aoqi@0 2474
aoqi@0 2475 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
aoqi@0 2476 // volatile_barrier( );
aoqi@0 2477
aoqi@0 2478 Label notVolatile, Done;
aoqi@0 2479 __ movl(rdx, flags);
aoqi@0 2480 __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
aoqi@0 2481 __ andl(rdx, 0x1);
aoqi@0 2482
aoqi@0 2483 // field addresses
aoqi@0 2484 const Address lo(obj, off, Address::times_1, 0*wordSize);
aoqi@0 2485 const Address hi(obj, off, Address::times_1, 1*wordSize);
aoqi@0 2486
kevinw@8368 2487 Label notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble;
aoqi@0 2488
aoqi@0 2489 __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
aoqi@0 2490 assert(btos == 0, "change code, btos != 0");
aoqi@0 2491 __ andl(flags, ConstantPoolCacheEntry::tos_state_mask);
aoqi@0 2492 __ jcc(Assembler::notZero, notByte);
aoqi@0 2493
aoqi@0 2494 // btos
aoqi@0 2495 {
aoqi@0 2496 __ pop(btos);
aoqi@0 2497 if (!is_static) pop_and_check_object(obj);
aoqi@0 2498 __ movb(lo, rax);
aoqi@0 2499 if (!is_static) {
aoqi@0 2500 patch_bytecode(Bytecodes::_fast_bputfield, rcx, rbx, true, byte_no);
aoqi@0 2501 }
aoqi@0 2502 __ jmp(Done);
aoqi@0 2503 }
aoqi@0 2504
aoqi@0 2505 __ bind(notByte);
kevinw@8368 2506 __ cmpl(flags, ztos);
kevinw@8368 2507 __ jcc(Assembler::notEqual, notBool);
kevinw@8368 2508
kevinw@8368 2509 // ztos
kevinw@8368 2510 {
kevinw@8368 2511 __ pop(ztos);
kevinw@8368 2512 if (!is_static) pop_and_check_object(obj);
kevinw@8368 2513 __ andl(rax, 0x1);
kevinw@8368 2514 __ movb(lo, rax);
kevinw@8368 2515 if (!is_static) {
kevinw@8368 2516 patch_bytecode(Bytecodes::_fast_zputfield, rcx, rbx, true, byte_no);
kevinw@8368 2517 }
kevinw@8368 2518 __ jmp(Done);
kevinw@8368 2519 }
kevinw@8368 2520
kevinw@8368 2521 __ bind(notBool);
aoqi@0 2522 __ cmpl(flags, itos);
aoqi@0 2523 __ jcc(Assembler::notEqual, notInt);
aoqi@0 2524
aoqi@0 2525 // itos
aoqi@0 2526 {
aoqi@0 2527 __ pop(itos);
aoqi@0 2528 if (!is_static) pop_and_check_object(obj);
aoqi@0 2529 __ movl(lo, rax);
aoqi@0 2530 if (!is_static) {
aoqi@0 2531 patch_bytecode(Bytecodes::_fast_iputfield, rcx, rbx, true, byte_no);
aoqi@0 2532 }
aoqi@0 2533 __ jmp(Done);
aoqi@0 2534 }
aoqi@0 2535
aoqi@0 2536 __ bind(notInt);
aoqi@0 2537 __ cmpl(flags, atos);
aoqi@0 2538 __ jcc(Assembler::notEqual, notObj);
aoqi@0 2539
aoqi@0 2540 // atos
aoqi@0 2541 {
aoqi@0 2542 __ pop(atos);
aoqi@0 2543 if (!is_static) pop_and_check_object(obj);
aoqi@0 2544 do_oop_store(_masm, lo, rax, _bs->kind(), false);
aoqi@0 2545 if (!is_static) {
aoqi@0 2546 patch_bytecode(Bytecodes::_fast_aputfield, rcx, rbx, true, byte_no);
aoqi@0 2547 }
aoqi@0 2548 __ jmp(Done);
aoqi@0 2549 }
aoqi@0 2550
aoqi@0 2551 __ bind(notObj);
aoqi@0 2552 __ cmpl(flags, ctos);
aoqi@0 2553 __ jcc(Assembler::notEqual, notChar);
aoqi@0 2554
aoqi@0 2555 // ctos
aoqi@0 2556 {
aoqi@0 2557 __ pop(ctos);
aoqi@0 2558 if (!is_static) pop_and_check_object(obj);
aoqi@0 2559 __ movw(lo, rax);
aoqi@0 2560 if (!is_static) {
aoqi@0 2561 patch_bytecode(Bytecodes::_fast_cputfield, rcx, rbx, true, byte_no);
aoqi@0 2562 }
aoqi@0 2563 __ jmp(Done);
aoqi@0 2564 }
aoqi@0 2565
aoqi@0 2566 __ bind(notChar);
aoqi@0 2567 __ cmpl(flags, stos);
aoqi@0 2568 __ jcc(Assembler::notEqual, notShort);
aoqi@0 2569
aoqi@0 2570 // stos
aoqi@0 2571 {
aoqi@0 2572 __ pop(stos);
aoqi@0 2573 if (!is_static) pop_and_check_object(obj);
aoqi@0 2574 __ movw(lo, rax);
aoqi@0 2575 if (!is_static) {
aoqi@0 2576 patch_bytecode(Bytecodes::_fast_sputfield, rcx, rbx, true, byte_no);
aoqi@0 2577 }
aoqi@0 2578 __ jmp(Done);
aoqi@0 2579 }
aoqi@0 2580
aoqi@0 2581 __ bind(notShort);
aoqi@0 2582 __ cmpl(flags, ltos);
aoqi@0 2583 __ jcc(Assembler::notEqual, notLong);
aoqi@0 2584
aoqi@0 2585 // ltos
aoqi@0 2586 {
aoqi@0 2587 Label notVolatileLong;
aoqi@0 2588 __ testl(rdx, rdx);
aoqi@0 2589 __ jcc(Assembler::zero, notVolatileLong);
aoqi@0 2590
aoqi@0 2591 __ pop(ltos); // overwrites rdx, do this after testing volatile.
aoqi@0 2592 if (!is_static) pop_and_check_object(obj);
aoqi@0 2593
aoqi@0 2594 // Replace with real volatile test
aoqi@0 2595 __ push(rdx);
aoqi@0 2596 __ push(rax); // Must update atomically with FIST
aoqi@0 2597 __ fild_d(Address(rsp,0)); // So load into FPU register
aoqi@0 2598 __ fistp_d(lo); // and put into memory atomically
aoqi@0 2599 __ addptr(rsp, 2*wordSize);
aoqi@0 2600 // volatile_barrier();
aoqi@0 2601 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
aoqi@0 2602 Assembler::StoreStore));
aoqi@0 2603 // Don't rewrite volatile version
aoqi@0 2604 __ jmp(notVolatile);
aoqi@0 2605
aoqi@0 2606 __ bind(notVolatileLong);
aoqi@0 2607
aoqi@0 2608 __ pop(ltos); // overwrites rdx
aoqi@0 2609 if (!is_static) pop_and_check_object(obj);
aoqi@0 2610 NOT_LP64(__ movptr(hi, rdx));
aoqi@0 2611 __ movptr(lo, rax);
aoqi@0 2612 if (!is_static) {
aoqi@0 2613 patch_bytecode(Bytecodes::_fast_lputfield, rcx, rbx, true, byte_no);
aoqi@0 2614 }
aoqi@0 2615 __ jmp(notVolatile);
aoqi@0 2616 }
aoqi@0 2617
aoqi@0 2618 __ bind(notLong);
aoqi@0 2619 __ cmpl(flags, ftos);
aoqi@0 2620 __ jcc(Assembler::notEqual, notFloat);
aoqi@0 2621
aoqi@0 2622 // ftos
aoqi@0 2623 {
aoqi@0 2624 __ pop(ftos);
aoqi@0 2625 if (!is_static) pop_and_check_object(obj);
aoqi@0 2626 __ fstp_s(lo);
aoqi@0 2627 if (!is_static) {
aoqi@0 2628 patch_bytecode(Bytecodes::_fast_fputfield, rcx, rbx, true, byte_no);
aoqi@0 2629 }
aoqi@0 2630 __ jmp(Done);
aoqi@0 2631 }
aoqi@0 2632
aoqi@0 2633 __ bind(notFloat);
aoqi@0 2634 #ifdef ASSERT
aoqi@0 2635 __ cmpl(flags, dtos);
aoqi@0 2636 __ jcc(Assembler::notEqual, notDouble);
aoqi@0 2637 #endif
aoqi@0 2638
aoqi@0 2639 // dtos
aoqi@0 2640 {
aoqi@0 2641 __ pop(dtos);
aoqi@0 2642 if (!is_static) pop_and_check_object(obj);
aoqi@0 2643 __ fstp_d(lo);
aoqi@0 2644 if (!is_static) {
aoqi@0 2645 patch_bytecode(Bytecodes::_fast_dputfield, rcx, rbx, true, byte_no);
aoqi@0 2646 }
aoqi@0 2647 __ jmp(Done);
aoqi@0 2648 }
aoqi@0 2649
aoqi@0 2650 #ifdef ASSERT
aoqi@0 2651 __ bind(notDouble);
aoqi@0 2652 __ stop("Bad state");
aoqi@0 2653 #endif
aoqi@0 2654
aoqi@0 2655 __ bind(Done);
aoqi@0 2656
aoqi@0 2657 // Check for volatile store
aoqi@0 2658 __ testl(rdx, rdx);
aoqi@0 2659 __ jcc(Assembler::zero, notVolatile);
aoqi@0 2660 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
aoqi@0 2661 Assembler::StoreStore));
aoqi@0 2662 __ bind(notVolatile);
aoqi@0 2663 }
aoqi@0 2664
aoqi@0 2665
aoqi@0 2666 void TemplateTable::putfield(int byte_no) {
aoqi@0 2667 putfield_or_static(byte_no, false);
aoqi@0 2668 }
aoqi@0 2669
aoqi@0 2670
aoqi@0 2671 void TemplateTable::putstatic(int byte_no) {
aoqi@0 2672 putfield_or_static(byte_no, true);
aoqi@0 2673 }
aoqi@0 2674
aoqi@0 2675 void TemplateTable::jvmti_post_fast_field_mod() {
aoqi@0 2676 if (JvmtiExport::can_post_field_modification()) {
aoqi@0 2677 // Check to see if a field modification watch has been set before we take
aoqi@0 2678 // the time to call into the VM.
aoqi@0 2679 Label L2;
aoqi@0 2680 __ mov32(rcx, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr()));
aoqi@0 2681 __ testl(rcx,rcx);
aoqi@0 2682 __ jcc(Assembler::zero, L2);
aoqi@0 2683 __ pop_ptr(rbx); // copy the object pointer from tos
aoqi@0 2684 __ verify_oop(rbx);
aoqi@0 2685 __ push_ptr(rbx); // put the object pointer back on tos
aoqi@0 2686
aoqi@0 2687 // Save tos values before call_VM() clobbers them. Since we have
aoqi@0 2688 // to do it for every data type, we use the saved values as the
aoqi@0 2689 // jvalue object.
aoqi@0 2690 switch (bytecode()) { // load values into the jvalue object
aoqi@0 2691 case Bytecodes::_fast_aputfield: __ push_ptr(rax); break;
aoqi@0 2692 case Bytecodes::_fast_bputfield: // fall through
kevinw@8368 2693 case Bytecodes::_fast_zputfield: // fall through
aoqi@0 2694 case Bytecodes::_fast_sputfield: // fall through
aoqi@0 2695 case Bytecodes::_fast_cputfield: // fall through
aoqi@0 2696 case Bytecodes::_fast_iputfield: __ push_i(rax); break;
aoqi@0 2697 case Bytecodes::_fast_dputfield: __ push_d(); break;
aoqi@0 2698 case Bytecodes::_fast_fputfield: __ push_f(); break;
aoqi@0 2699 case Bytecodes::_fast_lputfield: __ push_l(rax); break;
aoqi@0 2700
aoqi@0 2701 default:
aoqi@0 2702 ShouldNotReachHere();
aoqi@0 2703 }
aoqi@0 2704 __ mov(rcx, rsp); // points to jvalue on the stack
aoqi@0 2705 // access constant pool cache entry
aoqi@0 2706 __ get_cache_entry_pointer_at_bcp(rax, rdx, 1);
aoqi@0 2707 __ verify_oop(rbx);
aoqi@0 2708 // rbx,: object pointer copied above
aoqi@0 2709 // rax,: cache entry pointer
aoqi@0 2710 // rcx: jvalue object on the stack
aoqi@0 2711 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
aoqi@0 2712
aoqi@0 2713 switch (bytecode()) { // restore tos values
aoqi@0 2714 case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break;
aoqi@0 2715 case Bytecodes::_fast_bputfield: // fall through
kevinw@8368 2716 case Bytecodes::_fast_zputfield: // fall through
aoqi@0 2717 case Bytecodes::_fast_sputfield: // fall through
aoqi@0 2718 case Bytecodes::_fast_cputfield: // fall through
aoqi@0 2719 case Bytecodes::_fast_iputfield: __ pop_i(rax); break;
aoqi@0 2720 case Bytecodes::_fast_dputfield: __ pop_d(); break;
aoqi@0 2721 case Bytecodes::_fast_fputfield: __ pop_f(); break;
aoqi@0 2722 case Bytecodes::_fast_lputfield: __ pop_l(rax); break;
aoqi@0 2723 }
aoqi@0 2724 __ bind(L2);
aoqi@0 2725 }
aoqi@0 2726 }
aoqi@0 2727
aoqi@0 2728 void TemplateTable::fast_storefield(TosState state) {
aoqi@0 2729 transition(state, vtos);
aoqi@0 2730
aoqi@0 2731 ByteSize base = ConstantPoolCache::base_offset();
aoqi@0 2732
aoqi@0 2733 jvmti_post_fast_field_mod();
aoqi@0 2734
aoqi@0 2735 // access constant pool cache
aoqi@0 2736 __ get_cache_and_index_at_bcp(rcx, rbx, 1);
aoqi@0 2737
aoqi@0 2738 // test for volatile with rdx but rdx is tos register for lputfield.
aoqi@0 2739 if (bytecode() == Bytecodes::_fast_lputfield) __ push(rdx);
aoqi@0 2740 __ movl(rdx, Address(rcx, rbx, Address::times_ptr, in_bytes(base +
aoqi@0 2741 ConstantPoolCacheEntry::flags_offset())));
aoqi@0 2742
aoqi@0 2743 // replace index with field offset from cache entry
aoqi@0 2744 __ movptr(rbx, Address(rcx, rbx, Address::times_ptr, in_bytes(base + ConstantPoolCacheEntry::f2_offset())));
aoqi@0 2745
aoqi@0 2746 // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
aoqi@0 2747 // volatile_barrier( );
aoqi@0 2748
aoqi@0 2749 Label notVolatile, Done;
aoqi@0 2750 __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift);
aoqi@0 2751 __ andl(rdx, 0x1);
aoqi@0 2752 // Check for volatile store
aoqi@0 2753 __ testl(rdx, rdx);
aoqi@0 2754 __ jcc(Assembler::zero, notVolatile);
aoqi@0 2755
aoqi@0 2756 if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
aoqi@0 2757
aoqi@0 2758 // Get object from stack
aoqi@0 2759 pop_and_check_object(rcx);
aoqi@0 2760
aoqi@0 2761 // field addresses
aoqi@0 2762 const Address lo(rcx, rbx, Address::times_1, 0*wordSize);
aoqi@0 2763 const Address hi(rcx, rbx, Address::times_1, 1*wordSize);
aoqi@0 2764
aoqi@0 2765 // access field
aoqi@0 2766 switch (bytecode()) {
kevinw@8368 2767 case Bytecodes::_fast_zputfield: __ andl(rax, 0x1); // boolean is true if LSB is 1
kevinw@8368 2768 // fall through to bputfield
aoqi@0 2769 case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
aoqi@0 2770 case Bytecodes::_fast_sputfield: // fall through
aoqi@0 2771 case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
aoqi@0 2772 case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
aoqi@0 2773 case Bytecodes::_fast_lputfield:
aoqi@0 2774 NOT_LP64(__ movptr(hi, rdx));
aoqi@0 2775 __ movptr(lo, rax);
aoqi@0 2776 break;
aoqi@0 2777 case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
aoqi@0 2778 case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
aoqi@0 2779 case Bytecodes::_fast_aputfield: {
aoqi@0 2780 do_oop_store(_masm, lo, rax, _bs->kind(), false);
aoqi@0 2781 break;
aoqi@0 2782 }
aoqi@0 2783 default:
aoqi@0 2784 ShouldNotReachHere();
aoqi@0 2785 }
aoqi@0 2786
aoqi@0 2787 Label done;
aoqi@0 2788 volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad |
aoqi@0 2789 Assembler::StoreStore));
aoqi@0 2790 // Barriers are so large that short branch doesn't reach!
aoqi@0 2791 __ jmp(done);
aoqi@0 2792
aoqi@0 2793 // Same code as above, but don't need rdx to test for volatile.
aoqi@0 2794 __ bind(notVolatile);
aoqi@0 2795
aoqi@0 2796 if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx);
aoqi@0 2797
aoqi@0 2798 // Get object from stack
aoqi@0 2799 pop_and_check_object(rcx);
aoqi@0 2800
aoqi@0 2801 // access field
aoqi@0 2802 switch (bytecode()) {
kevinw@8368 2803 case Bytecodes::_fast_zputfield: __ andl(rax, 0x1); // boolean is true if LSB is 1
kevinw@8368 2804 // fall through to bputfield
aoqi@0 2805 case Bytecodes::_fast_bputfield: __ movb(lo, rax); break;
aoqi@0 2806 case Bytecodes::_fast_sputfield: // fall through
aoqi@0 2807 case Bytecodes::_fast_cputfield: __ movw(lo, rax); break;
aoqi@0 2808 case Bytecodes::_fast_iputfield: __ movl(lo, rax); break;
aoqi@0 2809 case Bytecodes::_fast_lputfield:
aoqi@0 2810 NOT_LP64(__ movptr(hi, rdx));
aoqi@0 2811 __ movptr(lo, rax);
aoqi@0 2812 break;
aoqi@0 2813 case Bytecodes::_fast_fputfield: __ fstp_s(lo); break;
aoqi@0 2814 case Bytecodes::_fast_dputfield: __ fstp_d(lo); break;
aoqi@0 2815 case Bytecodes::_fast_aputfield: {
aoqi@0 2816 do_oop_store(_masm, lo, rax, _bs->kind(), false);
aoqi@0 2817 break;
aoqi@0 2818 }
aoqi@0 2819 default:
aoqi@0 2820 ShouldNotReachHere();
aoqi@0 2821 }
aoqi@0 2822 __ bind(done);
aoqi@0 2823 }
aoqi@0 2824
aoqi@0 2825
aoqi@0 2826 void TemplateTable::fast_accessfield(TosState state) {
aoqi@0 2827 transition(atos, state);
aoqi@0 2828
aoqi@0 2829 // do the JVMTI work here to avoid disturbing the register state below
aoqi@0 2830 if (JvmtiExport::can_post_field_access()) {
aoqi@0 2831 // Check to see if a field access watch has been set before we take
aoqi@0 2832 // the time to call into the VM.
aoqi@0 2833 Label L1;
aoqi@0 2834 __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr()));
aoqi@0 2835 __ testl(rcx,rcx);
aoqi@0 2836 __ jcc(Assembler::zero, L1);
aoqi@0 2837 // access constant pool cache entry
aoqi@0 2838 __ get_cache_entry_pointer_at_bcp(rcx, rdx, 1);
aoqi@0 2839 __ push_ptr(rax); // save object pointer before call_VM() clobbers it
aoqi@0 2840 __ verify_oop(rax);
aoqi@0 2841 // rax,: object pointer copied above
aoqi@0 2842 // rcx: cache entry pointer
aoqi@0 2843 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
aoqi@0 2844 __ pop_ptr(rax); // restore object pointer
aoqi@0 2845 __ bind(L1);
aoqi@0 2846 }
aoqi@0 2847
aoqi@0 2848 // access constant pool cache
aoqi@0 2849 __ get_cache_and_index_at_bcp(rcx, rbx, 1);
aoqi@0 2850 // replace index with field offset from cache entry
aoqi@0 2851 __ movptr(rbx, Address(rcx,
aoqi@0 2852 rbx,
aoqi@0 2853 Address::times_ptr,
aoqi@0 2854 in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset())));
aoqi@0 2855
aoqi@0 2856
aoqi@0 2857 // rax,: object
aoqi@0 2858 __ verify_oop(rax);
aoqi@0 2859 __ null_check(rax);
aoqi@0 2860 // field addresses
aoqi@0 2861 const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
aoqi@0 2862 const Address hi = Address(rax, rbx, Address::times_1, 1*wordSize);
aoqi@0 2863
aoqi@0 2864 // access field
aoqi@0 2865 switch (bytecode()) {
aoqi@0 2866 case Bytecodes::_fast_bgetfield: __ movsbl(rax, lo ); break;
aoqi@0 2867 case Bytecodes::_fast_sgetfield: __ load_signed_short(rax, lo ); break;
aoqi@0 2868 case Bytecodes::_fast_cgetfield: __ load_unsigned_short(rax, lo ); break;
aoqi@0 2869 case Bytecodes::_fast_igetfield: __ movl(rax, lo); break;
aoqi@0 2870 case Bytecodes::_fast_lgetfield: __ stop("should not be rewritten"); break;
aoqi@0 2871 case Bytecodes::_fast_fgetfield: __ fld_s(lo); break;
aoqi@0 2872 case Bytecodes::_fast_dgetfield: __ fld_d(lo); break;
aoqi@0 2873 case Bytecodes::_fast_agetfield: __ movptr(rax, lo); __ verify_oop(rax); break;
aoqi@0 2874 default:
aoqi@0 2875 ShouldNotReachHere();
aoqi@0 2876 }
aoqi@0 2877
aoqi@0 2878 // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO)
aoqi@0 2879 // volatile_barrier( );
aoqi@0 2880 }
aoqi@0 2881
aoqi@0 2882 void TemplateTable::fast_xaccess(TosState state) {
aoqi@0 2883 transition(vtos, state);
aoqi@0 2884 // get receiver
aoqi@0 2885 __ movptr(rax, aaddress(0));
aoqi@0 2886 // access constant pool cache
aoqi@0 2887 __ get_cache_and_index_at_bcp(rcx, rdx, 2);
aoqi@0 2888 __ movptr(rbx, Address(rcx,
aoqi@0 2889 rdx,
aoqi@0 2890 Address::times_ptr,
aoqi@0 2891 in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset())));
aoqi@0 2892 // make sure exception is reported in correct bcp range (getfield is next instruction)
aoqi@0 2893 __ increment(rsi);
aoqi@0 2894 __ null_check(rax);
aoqi@0 2895 const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize);
aoqi@0 2896 if (state == itos) {
aoqi@0 2897 __ movl(rax, lo);
aoqi@0 2898 } else if (state == atos) {
aoqi@0 2899 __ movptr(rax, lo);
aoqi@0 2900 __ verify_oop(rax);
aoqi@0 2901 } else if (state == ftos) {
aoqi@0 2902 __ fld_s(lo);
aoqi@0 2903 } else {
aoqi@0 2904 ShouldNotReachHere();
aoqi@0 2905 }
aoqi@0 2906 __ decrement(rsi);
aoqi@0 2907 }
aoqi@0 2908
aoqi@0 2909
aoqi@0 2910
aoqi@0 2911 //----------------------------------------------------------------------------------------------------
aoqi@0 2912 // Calls
aoqi@0 2913
aoqi@0 2914 void TemplateTable::count_calls(Register method, Register temp) {
aoqi@0 2915 // implemented elsewhere
aoqi@0 2916 ShouldNotReachHere();
aoqi@0 2917 }
aoqi@0 2918
aoqi@0 2919
aoqi@0 2920 void TemplateTable::prepare_invoke(int byte_no,
aoqi@0 2921 Register method, // linked method (or i-klass)
aoqi@0 2922 Register index, // itable index, MethodType, etc.
aoqi@0 2923 Register recv, // if caller wants to see it
aoqi@0 2924 Register flags // if caller wants to test it
aoqi@0 2925 ) {
aoqi@0 2926 // determine flags
aoqi@0 2927 const Bytecodes::Code code = bytecode();
aoqi@0 2928 const bool is_invokeinterface = code == Bytecodes::_invokeinterface;
aoqi@0 2929 const bool is_invokedynamic = code == Bytecodes::_invokedynamic;
aoqi@0 2930 const bool is_invokehandle = code == Bytecodes::_invokehandle;
aoqi@0 2931 const bool is_invokevirtual = code == Bytecodes::_invokevirtual;
aoqi@0 2932 const bool is_invokespecial = code == Bytecodes::_invokespecial;
aoqi@0 2933 const bool load_receiver = (recv != noreg);
aoqi@0 2934 const bool save_flags = (flags != noreg);
aoqi@0 2935 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), "");
aoqi@0 2936 assert(save_flags == (is_invokeinterface || is_invokevirtual), "need flags for vfinal");
aoqi@0 2937 assert(flags == noreg || flags == rdx, "");
aoqi@0 2938 assert(recv == noreg || recv == rcx, "");
aoqi@0 2939
aoqi@0 2940 // setup registers & access constant pool cache
aoqi@0 2941 if (recv == noreg) recv = rcx;
aoqi@0 2942 if (flags == noreg) flags = rdx;
aoqi@0 2943 assert_different_registers(method, index, recv, flags);
aoqi@0 2944
aoqi@0 2945 // save 'interpreter return address'
aoqi@0 2946 __ save_bcp();
aoqi@0 2947
aoqi@0 2948 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic);
aoqi@0 2949
aoqi@0 2950 // maybe push appendix to arguments (just before return address)
aoqi@0 2951 if (is_invokedynamic || is_invokehandle) {
aoqi@0 2952 Label L_no_push;
aoqi@0 2953 __ testl(flags, (1 << ConstantPoolCacheEntry::has_appendix_shift));
aoqi@0 2954 __ jccb(Assembler::zero, L_no_push);
aoqi@0 2955 // Push the appendix as a trailing parameter.
aoqi@0 2956 // This must be done before we get the receiver,
aoqi@0 2957 // since the parameter_size includes it.
aoqi@0 2958 __ push(rbx);
aoqi@0 2959 __ mov(rbx, index);
aoqi@0 2960 assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0");
aoqi@0 2961 __ load_resolved_reference_at_index(index, rbx);
aoqi@0 2962 __ pop(rbx);
aoqi@0 2963 __ push(index); // push appendix (MethodType, CallSite, etc.)
aoqi@0 2964 __ bind(L_no_push);
aoqi@0 2965 }
aoqi@0 2966
aoqi@0 2967 // load receiver if needed (note: no return address pushed yet)
aoqi@0 2968 if (load_receiver) {
aoqi@0 2969 __ movl(recv, flags);
aoqi@0 2970 __ andl(recv, ConstantPoolCacheEntry::parameter_size_mask);
aoqi@0 2971 const int no_return_pc_pushed_yet = -1; // argument slot correction before we push return address
aoqi@0 2972 const int receiver_is_at_end = -1; // back off one slot to get receiver
aoqi@0 2973 Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end);
aoqi@0 2974 __ movptr(recv, recv_addr);
aoqi@0 2975 __ verify_oop(recv);
aoqi@0 2976 }
aoqi@0 2977
aoqi@0 2978 if (save_flags) {
aoqi@0 2979 __ mov(rsi, flags);
aoqi@0 2980 }
aoqi@0 2981
aoqi@0 2982 // compute return type
aoqi@0 2983 __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift);
aoqi@0 2984 // Make sure we don't need to mask flags after the above shift
aoqi@0 2985 ConstantPoolCacheEntry::verify_tos_state_shift();
aoqi@0 2986 // load return address
aoqi@0 2987 {
aoqi@0 2988 const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code);
aoqi@0 2989 ExternalAddress table(table_addr);
aoqi@0 2990 __ movptr(flags, ArrayAddress(table, Address(noreg, flags, Address::times_ptr)));
aoqi@0 2991 }
aoqi@0 2992
aoqi@0 2993 // push return address
aoqi@0 2994 __ push(flags);
aoqi@0 2995
aoqi@0 2996 // Restore flags value from the constant pool cache, and restore rsi
aoqi@0 2997 // for later null checks. rsi is the bytecode pointer
aoqi@0 2998 if (save_flags) {
aoqi@0 2999 __ mov(flags, rsi);
aoqi@0 3000 __ restore_bcp();
aoqi@0 3001 }
aoqi@0 3002 }
aoqi@0 3003
aoqi@0 3004
aoqi@0 3005 void TemplateTable::invokevirtual_helper(Register index,
aoqi@0 3006 Register recv,
aoqi@0 3007 Register flags) {
aoqi@0 3008 // Uses temporary registers rax, rdx
aoqi@0 3009 assert_different_registers(index, recv, rax, rdx);
aoqi@0 3010 assert(index == rbx, "");
aoqi@0 3011 assert(recv == rcx, "");
aoqi@0 3012
aoqi@0 3013 // Test for an invoke of a final method
aoqi@0 3014 Label notFinal;
aoqi@0 3015 __ movl(rax, flags);
aoqi@0 3016 __ andl(rax, (1 << ConstantPoolCacheEntry::is_vfinal_shift));
aoqi@0 3017 __ jcc(Assembler::zero, notFinal);
aoqi@0 3018
aoqi@0 3019 const Register method = index; // method must be rbx
aoqi@0 3020 assert(method == rbx,
aoqi@0 3021 "Method* must be rbx for interpreter calling convention");
aoqi@0 3022
aoqi@0 3023 // do the call - the index is actually the method to call
aoqi@0 3024 // that is, f2 is a vtable index if !is_vfinal, else f2 is a Method*
aoqi@0 3025
aoqi@0 3026 // It's final, need a null check here!
aoqi@0 3027 __ null_check(recv);
aoqi@0 3028
aoqi@0 3029 // profile this call
aoqi@0 3030 __ profile_final_call(rax);
aoqi@0 3031 __ profile_arguments_type(rax, method, rsi, true);
aoqi@0 3032
aoqi@0 3033 __ jump_from_interpreted(method, rax);
aoqi@0 3034
aoqi@0 3035 __ bind(notFinal);
aoqi@0 3036
aoqi@0 3037 // get receiver klass
aoqi@0 3038 __ null_check(recv, oopDesc::klass_offset_in_bytes());
aoqi@0 3039 __ load_klass(rax, recv);
aoqi@0 3040
aoqi@0 3041 // profile this call
aoqi@0 3042 __ profile_virtual_call(rax, rdi, rdx);
aoqi@0 3043
aoqi@0 3044 // get target Method* & entry point
aoqi@0 3045 __ lookup_virtual_method(rax, index, method);
aoqi@0 3046 __ profile_arguments_type(rdx, method, rsi, true);
aoqi@0 3047 __ jump_from_interpreted(method, rdx);
aoqi@0 3048 }
aoqi@0 3049
aoqi@0 3050
aoqi@0 3051 void TemplateTable::invokevirtual(int byte_no) {
aoqi@0 3052 transition(vtos, vtos);
aoqi@0 3053 assert(byte_no == f2_byte, "use this argument");
aoqi@0 3054 prepare_invoke(byte_no,
aoqi@0 3055 rbx, // method or vtable index
aoqi@0 3056 noreg, // unused itable index
aoqi@0 3057 rcx, rdx); // recv, flags
aoqi@0 3058
aoqi@0 3059 // rbx: index
aoqi@0 3060 // rcx: receiver
aoqi@0 3061 // rdx: flags
aoqi@0 3062
aoqi@0 3063 invokevirtual_helper(rbx, rcx, rdx);
aoqi@0 3064 }
aoqi@0 3065
aoqi@0 3066
aoqi@0 3067 void TemplateTable::invokespecial(int byte_no) {
aoqi@0 3068 transition(vtos, vtos);
aoqi@0 3069 assert(byte_no == f1_byte, "use this argument");
aoqi@0 3070 prepare_invoke(byte_no, rbx, noreg, // get f1 Method*
aoqi@0 3071 rcx); // get receiver also for null check
aoqi@0 3072 __ verify_oop(rcx);
aoqi@0 3073 __ null_check(rcx);
aoqi@0 3074 // do the call
aoqi@0 3075 __ profile_call(rax);
aoqi@0 3076 __ profile_arguments_type(rax, rbx, rsi, false);
aoqi@0 3077 __ jump_from_interpreted(rbx, rax);
aoqi@0 3078 }
aoqi@0 3079
aoqi@0 3080
aoqi@0 3081 void TemplateTable::invokestatic(int byte_no) {
aoqi@0 3082 transition(vtos, vtos);
aoqi@0 3083 assert(byte_no == f1_byte, "use this argument");
aoqi@0 3084 prepare_invoke(byte_no, rbx); // get f1 Method*
aoqi@0 3085 // do the call
aoqi@0 3086 __ profile_call(rax);
aoqi@0 3087 __ profile_arguments_type(rax, rbx, rsi, false);
aoqi@0 3088 __ jump_from_interpreted(rbx, rax);
aoqi@0 3089 }
aoqi@0 3090
aoqi@0 3091
aoqi@0 3092 void TemplateTable::fast_invokevfinal(int byte_no) {
aoqi@0 3093 transition(vtos, vtos);
aoqi@0 3094 assert(byte_no == f2_byte, "use this argument");
aoqi@0 3095 __ stop("fast_invokevfinal not used on x86");
aoqi@0 3096 }
aoqi@0 3097
aoqi@0 3098
aoqi@0 3099 void TemplateTable::invokeinterface(int byte_no) {
aoqi@0 3100 transition(vtos, vtos);
aoqi@0 3101 assert(byte_no == f1_byte, "use this argument");
dbuck@8997 3102 prepare_invoke(byte_no, rax, rbx, // get f1 Klass*, f2 Method*
aoqi@0 3103 rcx, rdx); // recv, flags
aoqi@0 3104
dbuck@8997 3105 // rax: reference klass (from f1)
dbuck@8997 3106 // rbx: method (from f2)
aoqi@0 3107 // rcx: receiver
aoqi@0 3108 // rdx: flags
aoqi@0 3109
aoqi@0 3110 // Special case of invokeinterface called for virtual method of
aoqi@0 3111 // java.lang.Object. See cpCacheOop.cpp for details.
aoqi@0 3112 // This code isn't produced by javac, but could be produced by
aoqi@0 3113 // another compliant java compiler.
aoqi@0 3114 Label notMethod;
aoqi@0 3115 __ movl(rdi, rdx);
aoqi@0 3116 __ andl(rdi, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift));
aoqi@0 3117 __ jcc(Assembler::zero, notMethod);
aoqi@0 3118
aoqi@0 3119 invokevirtual_helper(rbx, rcx, rdx);
aoqi@0 3120 __ bind(notMethod);
aoqi@0 3121
aoqi@0 3122 // Get receiver klass into rdx - also a null check
aoqi@0 3123 __ restore_locals(); // restore rdi
aoqi@0 3124 __ null_check(rcx, oopDesc::klass_offset_in_bytes());
aoqi@0 3125 __ load_klass(rdx, rcx);
aoqi@0 3126
dbuck@8997 3127 Label no_such_interface, no_such_method;
dbuck@8997 3128
dbuck@8997 3129 // Receiver subtype check against REFC.
dbuck@8997 3130 // Superklass in rax. Subklass in rdx. Blows rcx, rdi.
dbuck@8997 3131 __ lookup_interface_method(// inputs: rec. class, interface, itable index
dbuck@8997 3132 rdx, rax, noreg,
dbuck@8997 3133 // outputs: scan temp. reg, scan temp. reg
dbuck@8997 3134 rsi, rdi,
dbuck@8997 3135 no_such_interface,
dbuck@8997 3136 /*return_method=*/false);
dbuck@8997 3137
dbuck@8997 3138
aoqi@0 3139 // profile this call
dbuck@8997 3140 __ restore_bcp(); // rbcp was destroyed by receiver type check
aoqi@0 3141 __ profile_virtual_call(rdx, rsi, rdi);
aoqi@0 3142
dbuck@8997 3143 // Get declaring interface class from method, and itable index
dbuck@8997 3144 __ movptr(rax, Address(rbx, Method::const_offset()));
dbuck@8997 3145 __ movptr(rax, Address(rax, ConstMethod::constants_offset()));
dbuck@8997 3146 __ movptr(rax, Address(rax, ConstantPool::pool_holder_offset_in_bytes()));
dbuck@8997 3147 __ movl(rbx, Address(rbx, Method::itable_index_offset()));
dbuck@8997 3148 __ subl(rbx, Method::itable_index_max);
dbuck@8997 3149 __ negl(rbx);
aoqi@0 3150
aoqi@0 3151 __ lookup_interface_method(// inputs: rec. class, interface, itable index
aoqi@0 3152 rdx, rax, rbx,
aoqi@0 3153 // outputs: method, scan temp. reg
aoqi@0 3154 rbx, rsi,
aoqi@0 3155 no_such_interface);
aoqi@0 3156
aoqi@0 3157 // rbx: Method* to call
aoqi@0 3158 // rcx: receiver
aoqi@0 3159 // Check for abstract method error
aoqi@0 3160 // Note: This should be done more efficiently via a throw_abstract_method_error
aoqi@0 3161 // interpreter entry point and a conditional jump to it in case of a null
aoqi@0 3162 // method.
aoqi@0 3163 __ testptr(rbx, rbx);
aoqi@0 3164 __ jcc(Assembler::zero, no_such_method);
aoqi@0 3165
aoqi@0 3166 __ profile_arguments_type(rdx, rbx, rsi, true);
aoqi@0 3167
aoqi@0 3168 // do the call
aoqi@0 3169 // rcx: receiver
aoqi@0 3170 // rbx,: Method*
aoqi@0 3171 __ jump_from_interpreted(rbx, rdx);
aoqi@0 3172 __ should_not_reach_here();
aoqi@0 3173
aoqi@0 3174 // exception handling code follows...
aoqi@0 3175 // note: must restore interpreter registers to canonical
aoqi@0 3176 // state for exception handling to work correctly!
aoqi@0 3177
aoqi@0 3178 __ bind(no_such_method);
aoqi@0 3179 // throw exception
aoqi@0 3180 __ pop(rbx); // pop return address (pushed by prepare_invoke)
aoqi@0 3181 __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
aoqi@0 3182 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
aoqi@0 3183 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
aoqi@0 3184 // the call_VM checks for exception, so we should never return here.
aoqi@0 3185 __ should_not_reach_here();
aoqi@0 3186
aoqi@0 3187 __ bind(no_such_interface);
aoqi@0 3188 // throw exception
aoqi@0 3189 __ pop(rbx); // pop return address (pushed by prepare_invoke)
aoqi@0 3190 __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
aoqi@0 3191 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
aoqi@0 3192 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
aoqi@0 3193 InterpreterRuntime::throw_IncompatibleClassChangeError));
aoqi@0 3194 // the call_VM checks for exception, so we should never return here.
aoqi@0 3195 __ should_not_reach_here();
aoqi@0 3196 }
aoqi@0 3197
aoqi@0 3198 void TemplateTable::invokehandle(int byte_no) {
aoqi@0 3199 transition(vtos, vtos);
aoqi@0 3200 assert(byte_no == f1_byte, "use this argument");
aoqi@0 3201 const Register rbx_method = rbx;
aoqi@0 3202 const Register rax_mtype = rax;
aoqi@0 3203 const Register rcx_recv = rcx;
aoqi@0 3204 const Register rdx_flags = rdx;
aoqi@0 3205
aoqi@0 3206 if (!EnableInvokeDynamic) {
aoqi@0 3207 // rewriter does not generate this bytecode
aoqi@0 3208 __ should_not_reach_here();
aoqi@0 3209 return;
aoqi@0 3210 }
aoqi@0 3211
aoqi@0 3212 prepare_invoke(byte_no, rbx_method, rax_mtype, rcx_recv);
aoqi@0 3213 __ verify_method_ptr(rbx_method);
aoqi@0 3214 __ verify_oop(rcx_recv);
aoqi@0 3215 __ null_check(rcx_recv);
aoqi@0 3216
aoqi@0 3217 // rax: MethodType object (from cpool->resolved_references[f1], if necessary)
aoqi@0 3218 // rbx: MH.invokeExact_MT method (from f2)
aoqi@0 3219
aoqi@0 3220 // Note: rax_mtype is already pushed (if necessary) by prepare_invoke
aoqi@0 3221
aoqi@0 3222 // FIXME: profile the LambdaForm also
aoqi@0 3223 __ profile_final_call(rax);
aoqi@0 3224 __ profile_arguments_type(rdx, rbx_method, rsi, true);
aoqi@0 3225
aoqi@0 3226 __ jump_from_interpreted(rbx_method, rdx);
aoqi@0 3227 }
aoqi@0 3228
aoqi@0 3229
aoqi@0 3230 void TemplateTable::invokedynamic(int byte_no) {
aoqi@0 3231 transition(vtos, vtos);
aoqi@0 3232 assert(byte_no == f1_byte, "use this argument");
aoqi@0 3233
aoqi@0 3234 if (!EnableInvokeDynamic) {
aoqi@0 3235 // We should not encounter this bytecode if !EnableInvokeDynamic.
aoqi@0 3236 // The verifier will stop it. However, if we get past the verifier,
aoqi@0 3237 // this will stop the thread in a reasonable way, without crashing the JVM.
aoqi@0 3238 __ call_VM(noreg, CAST_FROM_FN_PTR(address,
aoqi@0 3239 InterpreterRuntime::throw_IncompatibleClassChangeError));
aoqi@0 3240 // the call_VM checks for exception, so we should never return here.
aoqi@0 3241 __ should_not_reach_here();
aoqi@0 3242 return;
aoqi@0 3243 }
aoqi@0 3244
aoqi@0 3245 const Register rbx_method = rbx;
aoqi@0 3246 const Register rax_callsite = rax;
aoqi@0 3247
aoqi@0 3248 prepare_invoke(byte_no, rbx_method, rax_callsite);
aoqi@0 3249
aoqi@0 3250 // rax: CallSite object (from cpool->resolved_references[f1])
aoqi@0 3251 // rbx: MH.linkToCallSite method (from f2)
aoqi@0 3252
aoqi@0 3253 // Note: rax_callsite is already pushed by prepare_invoke
aoqi@0 3254
aoqi@0 3255 // %%% should make a type profile for any invokedynamic that takes a ref argument
aoqi@0 3256 // profile this call
aoqi@0 3257 __ profile_call(rsi);
aoqi@0 3258 __ profile_arguments_type(rdx, rbx, rsi, false);
aoqi@0 3259
aoqi@0 3260 __ verify_oop(rax_callsite);
aoqi@0 3261
aoqi@0 3262 __ jump_from_interpreted(rbx_method, rdx);
aoqi@0 3263 }
aoqi@0 3264
aoqi@0 3265 //----------------------------------------------------------------------------------------------------
aoqi@0 3266 // Allocation
aoqi@0 3267
aoqi@0 3268 void TemplateTable::_new() {
aoqi@0 3269 transition(vtos, atos);
aoqi@0 3270 __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
aoqi@0 3271 Label slow_case;
aoqi@0 3272 Label slow_case_no_pop;
aoqi@0 3273 Label done;
aoqi@0 3274 Label initialize_header;
aoqi@0 3275 Label initialize_object; // including clearing the fields
aoqi@0 3276 Label allocate_shared;
aoqi@0 3277
aoqi@0 3278 __ get_cpool_and_tags(rcx, rax);
aoqi@0 3279
aoqi@0 3280 // Make sure the class we're about to instantiate has been resolved.
aoqi@0 3281 // This is done before loading InstanceKlass to be consistent with the order
aoqi@0 3282 // how Constant Pool is updated (see ConstantPool::klass_at_put)
aoqi@0 3283 const int tags_offset = Array<u1>::base_offset_in_bytes();
aoqi@0 3284 __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class);
aoqi@0 3285 __ jcc(Assembler::notEqual, slow_case_no_pop);
aoqi@0 3286
aoqi@0 3287 // get InstanceKlass
aoqi@0 3288 __ movptr(rcx, Address(rcx, rdx, Address::times_ptr, sizeof(ConstantPool)));
aoqi@0 3289 __ push(rcx); // save the contexts of klass for initializing the header
aoqi@0 3290
aoqi@0 3291 // make sure klass is initialized & doesn't have finalizer
aoqi@0 3292 // make sure klass is fully initialized
aoqi@0 3293 __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
aoqi@0 3294 __ jcc(Assembler::notEqual, slow_case);
aoqi@0 3295
aoqi@0 3296 // get instance_size in InstanceKlass (scaled to a count of bytes)
aoqi@0 3297 __ movl(rdx, Address(rcx, Klass::layout_helper_offset()));
aoqi@0 3298 // test to see if it has a finalizer or is malformed in some way
aoqi@0 3299 __ testl(rdx, Klass::_lh_instance_slow_path_bit);
aoqi@0 3300 __ jcc(Assembler::notZero, slow_case);
aoqi@0 3301
aoqi@0 3302 //
aoqi@0 3303 // Allocate the instance
aoqi@0 3304 // 1) Try to allocate in the TLAB
aoqi@0 3305 // 2) if fail and the object is large allocate in the shared Eden
aoqi@0 3306 // 3) if the above fails (or is not applicable), go to a slow case
aoqi@0 3307 // (creates a new TLAB, etc.)
aoqi@0 3308
aoqi@0 3309 const bool allow_shared_alloc =
aoqi@0 3310 Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;
aoqi@0 3311
aoqi@0 3312 const Register thread = rcx;
aoqi@0 3313 if (UseTLAB || allow_shared_alloc) {
aoqi@0 3314 __ get_thread(thread);
aoqi@0 3315 }
aoqi@0 3316
aoqi@0 3317 if (UseTLAB) {
aoqi@0 3318 __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset())));
aoqi@0 3319 __ lea(rbx, Address(rax, rdx, Address::times_1));
aoqi@0 3320 __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset())));
aoqi@0 3321 __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case);
aoqi@0 3322 __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx);
aoqi@0 3323 if (ZeroTLAB) {
aoqi@0 3324 // the fields have been already cleared
aoqi@0 3325 __ jmp(initialize_header);
aoqi@0 3326 } else {
aoqi@0 3327 // initialize both the header and fields
aoqi@0 3328 __ jmp(initialize_object);
aoqi@0 3329 }
aoqi@0 3330 }
aoqi@0 3331
aoqi@0 3332 // Allocation in the shared Eden, if allowed.
aoqi@0 3333 //
aoqi@0 3334 // rdx: instance size in bytes
aoqi@0 3335 if (allow_shared_alloc) {
aoqi@0 3336 __ bind(allocate_shared);
aoqi@0 3337
aoqi@0 3338 ExternalAddress heap_top((address)Universe::heap()->top_addr());
aoqi@0 3339
aoqi@0 3340 Label retry;
aoqi@0 3341 __ bind(retry);
aoqi@0 3342 __ movptr(rax, heap_top);
aoqi@0 3343 __ lea(rbx, Address(rax, rdx, Address::times_1));
aoqi@0 3344 __ cmpptr(rbx, ExternalAddress((address)Universe::heap()->end_addr()));
aoqi@0 3345 __ jcc(Assembler::above, slow_case);
aoqi@0 3346
aoqi@0 3347 // Compare rax, with the top addr, and if still equal, store the new
aoqi@0 3348 // top addr in rbx, at the address of the top addr pointer. Sets ZF if was
aoqi@0 3349 // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
aoqi@0 3350 //
aoqi@0 3351 // rax,: object begin
aoqi@0 3352 // rbx,: object end
aoqi@0 3353 // rdx: instance size in bytes
aoqi@0 3354 __ locked_cmpxchgptr(rbx, heap_top);
aoqi@0 3355
aoqi@0 3356 // if someone beat us on the allocation, try again, otherwise continue
aoqi@0 3357 __ jcc(Assembler::notEqual, retry);
aoqi@0 3358
aoqi@0 3359 __ incr_allocated_bytes(thread, rdx, 0);
aoqi@0 3360 }
aoqi@0 3361
aoqi@0 3362 if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
aoqi@0 3363 // The object is initialized before the header. If the object size is
aoqi@0 3364 // zero, go directly to the header initialization.
aoqi@0 3365 __ bind(initialize_object);
aoqi@0 3366 __ decrement(rdx, sizeof(oopDesc));
aoqi@0 3367 __ jcc(Assembler::zero, initialize_header);
aoqi@0 3368
aoqi@0 3369 // Initialize topmost object field, divide rdx by 8, check if odd and
aoqi@0 3370 // test if zero.
aoqi@0 3371 __ xorl(rcx, rcx); // use zero reg to clear memory (shorter code)
aoqi@0 3372 __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
aoqi@0 3373
aoqi@0 3374 // rdx must have been multiple of 8
aoqi@0 3375 #ifdef ASSERT
aoqi@0 3376 // make sure rdx was multiple of 8
aoqi@0 3377 Label L;
aoqi@0 3378 // Ignore partial flag stall after shrl() since it is debug VM
aoqi@0 3379 __ jccb(Assembler::carryClear, L);
aoqi@0 3380 __ stop("object size is not multiple of 2 - adjust this code");
aoqi@0 3381 __ bind(L);
aoqi@0 3382 // rdx must be > 0, no extra check needed here
aoqi@0 3383 #endif
aoqi@0 3384
aoqi@0 3385 // initialize remaining object fields: rdx was a multiple of 8
aoqi@0 3386 { Label loop;
aoqi@0 3387 __ bind(loop);
aoqi@0 3388 __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx);
aoqi@0 3389 NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx));
aoqi@0 3390 __ decrement(rdx);
aoqi@0 3391 __ jcc(Assembler::notZero, loop);
aoqi@0 3392 }
aoqi@0 3393
aoqi@0 3394 // initialize object header only.
aoqi@0 3395 __ bind(initialize_header);
aoqi@0 3396 if (UseBiasedLocking) {
aoqi@0 3397 __ pop(rcx); // get saved klass back in the register.
aoqi@0 3398 __ movptr(rbx, Address(rcx, Klass::prototype_header_offset()));
aoqi@0 3399 __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), rbx);
aoqi@0 3400 } else {
aoqi@0 3401 __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()),
aoqi@0 3402 (int32_t)markOopDesc::prototype()); // header
aoqi@0 3403 __ pop(rcx); // get saved klass back in the register.
aoqi@0 3404 }
aoqi@0 3405 __ store_klass(rax, rcx); // klass
aoqi@0 3406
aoqi@0 3407 {
aoqi@0 3408 SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0);
aoqi@0 3409 // Trigger dtrace event for fastpath
aoqi@0 3410 __ push(atos);
aoqi@0 3411 __ call_VM_leaf(
aoqi@0 3412 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), rax);
aoqi@0 3413 __ pop(atos);
aoqi@0 3414 }
aoqi@0 3415
aoqi@0 3416 __ jmp(done);
aoqi@0 3417 }
aoqi@0 3418
aoqi@0 3419 // slow case
aoqi@0 3420 __ bind(slow_case);
aoqi@0 3421 __ pop(rcx); // restore stack pointer to what it was when we came in.
aoqi@0 3422 __ bind(slow_case_no_pop);
aoqi@0 3423 __ get_constant_pool(rax);
aoqi@0 3424 __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
aoqi@0 3425 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rax, rdx);
aoqi@0 3426
aoqi@0 3427 // continue
aoqi@0 3428 __ bind(done);
aoqi@0 3429 }
aoqi@0 3430
aoqi@0 3431
aoqi@0 3432 void TemplateTable::newarray() {
aoqi@0 3433 transition(itos, atos);
aoqi@0 3434 __ push_i(rax); // make sure everything is on the stack
aoqi@0 3435 __ load_unsigned_byte(rdx, at_bcp(1));
aoqi@0 3436 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), rdx, rax);
aoqi@0 3437 __ pop_i(rdx); // discard size
aoqi@0 3438 }
aoqi@0 3439
aoqi@0 3440
aoqi@0 3441 void TemplateTable::anewarray() {
aoqi@0 3442 transition(itos, atos);
aoqi@0 3443 __ get_unsigned_2_byte_index_at_bcp(rdx, 1);
aoqi@0 3444 __ get_constant_pool(rcx);
aoqi@0 3445 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), rcx, rdx, rax);
aoqi@0 3446 }
aoqi@0 3447
aoqi@0 3448
aoqi@0 3449 void TemplateTable::arraylength() {
aoqi@0 3450 transition(atos, itos);
aoqi@0 3451 __ null_check(rax, arrayOopDesc::length_offset_in_bytes());
aoqi@0 3452 __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes()));
aoqi@0 3453 }
aoqi@0 3454
aoqi@0 3455
aoqi@0 3456 void TemplateTable::checkcast() {
aoqi@0 3457 transition(atos, atos);
aoqi@0 3458 Label done, is_null, ok_is_subtype, quicked, resolved;
aoqi@0 3459 __ testptr(rax, rax); // Object is in EAX
aoqi@0 3460 __ jcc(Assembler::zero, is_null);
aoqi@0 3461
aoqi@0 3462 // Get cpool & tags index
aoqi@0 3463 __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
aoqi@0 3464 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
aoqi@0 3465 // See if bytecode has already been quicked
aoqi@0 3466 __ cmpb(Address(rdx, rbx, Address::times_1, Array<u1>::base_offset_in_bytes()), JVM_CONSTANT_Class);
aoqi@0 3467 __ jcc(Assembler::equal, quicked);
aoqi@0 3468
aoqi@0 3469 __ push(atos);
aoqi@0 3470 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
aoqi@0 3471 // vm_result_2 has metadata result
aoqi@0 3472 // borrow rdi from locals
aoqi@0 3473 __ get_thread(rdi);
aoqi@0 3474 __ get_vm_result_2(rax, rdi);
aoqi@0 3475 __ restore_locals();
aoqi@0 3476 __ pop_ptr(rdx);
aoqi@0 3477 __ jmpb(resolved);
aoqi@0 3478
aoqi@0 3479 // Get superklass in EAX and subklass in EBX
aoqi@0 3480 __ bind(quicked);
aoqi@0 3481 __ mov(rdx, rax); // Save object in EDX; EAX needed for subtype check
aoqi@0 3482 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(ConstantPool)));
aoqi@0 3483
aoqi@0 3484 __ bind(resolved);
aoqi@0 3485 __ load_klass(rbx, rdx);
aoqi@0 3486
aoqi@0 3487 // Generate subtype check. Blows ECX. Resets EDI. Object in EDX.
aoqi@0 3488 // Superklass in EAX. Subklass in EBX.
aoqi@0 3489 __ gen_subtype_check( rbx, ok_is_subtype );
aoqi@0 3490
aoqi@0 3491 // Come here on failure
aoqi@0 3492 __ push(rdx);
aoqi@0 3493 // object is at TOS
aoqi@0 3494 __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
aoqi@0 3495
aoqi@0 3496 // Come here on success
aoqi@0 3497 __ bind(ok_is_subtype);
aoqi@0 3498 __ mov(rax,rdx); // Restore object in EDX
aoqi@0 3499
aoqi@0 3500 // Collect counts on whether this check-cast sees NULLs a lot or not.
aoqi@0 3501 if (ProfileInterpreter) {
aoqi@0 3502 __ jmp(done);
aoqi@0 3503 __ bind(is_null);
aoqi@0 3504 __ profile_null_seen(rcx);
aoqi@0 3505 } else {
aoqi@0 3506 __ bind(is_null); // same as 'done'
aoqi@0 3507 }
aoqi@0 3508 __ bind(done);
aoqi@0 3509 }
aoqi@0 3510
aoqi@0 3511
aoqi@0 3512 void TemplateTable::instanceof() {
aoqi@0 3513 transition(atos, itos);
aoqi@0 3514 Label done, is_null, ok_is_subtype, quicked, resolved;
aoqi@0 3515 __ testptr(rax, rax);
aoqi@0 3516 __ jcc(Assembler::zero, is_null);
aoqi@0 3517
aoqi@0 3518 // Get cpool & tags index
aoqi@0 3519 __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array
aoqi@0 3520 __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index
aoqi@0 3521 // See if bytecode has already been quicked
aoqi@0 3522 __ cmpb(Address(rdx, rbx, Address::times_1, Array<u1>::base_offset_in_bytes()), JVM_CONSTANT_Class);
aoqi@0 3523 __ jcc(Assembler::equal, quicked);
aoqi@0 3524
aoqi@0 3525 __ push(atos);
aoqi@0 3526 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
aoqi@0 3527 // vm_result_2 has metadata result
aoqi@0 3528 // borrow rdi from locals
aoqi@0 3529 __ get_thread(rdi);
aoqi@0 3530 __ get_vm_result_2(rax, rdi);
aoqi@0 3531 __ restore_locals();
aoqi@0 3532 __ pop_ptr(rdx);
aoqi@0 3533 __ load_klass(rdx, rdx);
aoqi@0 3534 __ jmp(resolved);
aoqi@0 3535
aoqi@0 3536 // Get superklass in EAX and subklass in EDX
aoqi@0 3537 __ bind(quicked);
aoqi@0 3538 __ load_klass(rdx, rax);
aoqi@0 3539 __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(ConstantPool)));
aoqi@0 3540
aoqi@0 3541 __ bind(resolved);
aoqi@0 3542
aoqi@0 3543 // Generate subtype check. Blows ECX. Resets EDI.
aoqi@0 3544 // Superklass in EAX. Subklass in EDX.
aoqi@0 3545 __ gen_subtype_check( rdx, ok_is_subtype );
aoqi@0 3546
aoqi@0 3547 // Come here on failure
aoqi@0 3548 __ xorl(rax,rax);
aoqi@0 3549 __ jmpb(done);
aoqi@0 3550 // Come here on success
aoqi@0 3551 __ bind(ok_is_subtype);
aoqi@0 3552 __ movl(rax, 1);
aoqi@0 3553
aoqi@0 3554 // Collect counts on whether this test sees NULLs a lot or not.
aoqi@0 3555 if (ProfileInterpreter) {
aoqi@0 3556 __ jmp(done);
aoqi@0 3557 __ bind(is_null);
aoqi@0 3558 __ profile_null_seen(rcx);
aoqi@0 3559 } else {
aoqi@0 3560 __ bind(is_null); // same as 'done'
aoqi@0 3561 }
aoqi@0 3562 __ bind(done);
aoqi@0 3563 // rax, = 0: obj == NULL or obj is not an instanceof the specified klass
aoqi@0 3564 // rax, = 1: obj != NULL and obj is an instanceof the specified klass
aoqi@0 3565 }
aoqi@0 3566
aoqi@0 3567
aoqi@0 3568 //----------------------------------------------------------------------------------------------------
aoqi@0 3569 // Breakpoints
aoqi@0 3570 void TemplateTable::_breakpoint() {
aoqi@0 3571
aoqi@0 3572 // Note: We get here even if we are single stepping..
aoqi@0 3573 // jbug inists on setting breakpoints at every bytecode
aoqi@0 3574 // even if we are in single step mode.
aoqi@0 3575
aoqi@0 3576 transition(vtos, vtos);
aoqi@0 3577
aoqi@0 3578 // get the unpatched byte code
aoqi@0 3579 __ get_method(rcx);
aoqi@0 3580 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), rcx, rsi);
aoqi@0 3581 __ mov(rbx, rax);
aoqi@0 3582
aoqi@0 3583 // post the breakpoint event
aoqi@0 3584 __ get_method(rcx);
aoqi@0 3585 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), rcx, rsi);
aoqi@0 3586
aoqi@0 3587 // complete the execution of original bytecode
aoqi@0 3588 __ dispatch_only_normal(vtos);
aoqi@0 3589 }
aoqi@0 3590
aoqi@0 3591
aoqi@0 3592 //----------------------------------------------------------------------------------------------------
aoqi@0 3593 // Exceptions
aoqi@0 3594
aoqi@0 3595 void TemplateTable::athrow() {
aoqi@0 3596 transition(atos, vtos);
aoqi@0 3597 __ null_check(rax);
aoqi@0 3598 __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
aoqi@0 3599 }
aoqi@0 3600
aoqi@0 3601
aoqi@0 3602 //----------------------------------------------------------------------------------------------------
aoqi@0 3603 // Synchronization
aoqi@0 3604 //
aoqi@0 3605 // Note: monitorenter & exit are symmetric routines; which is reflected
aoqi@0 3606 // in the assembly code structure as well
aoqi@0 3607 //
aoqi@0 3608 // Stack layout:
aoqi@0 3609 //
aoqi@0 3610 // [expressions ] <--- rsp = expression stack top
aoqi@0 3611 // ..
aoqi@0 3612 // [expressions ]
aoqi@0 3613 // [monitor entry] <--- monitor block top = expression stack bot
aoqi@0 3614 // ..
aoqi@0 3615 // [monitor entry]
aoqi@0 3616 // [frame data ] <--- monitor block bot
aoqi@0 3617 // ...
aoqi@0 3618 // [saved rbp, ] <--- rbp,
aoqi@0 3619
aoqi@0 3620
aoqi@0 3621 void TemplateTable::monitorenter() {
aoqi@0 3622 transition(atos, vtos);
aoqi@0 3623
aoqi@0 3624 // check for NULL object
aoqi@0 3625 __ null_check(rax);
aoqi@0 3626
aoqi@0 3627 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
aoqi@0 3628 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
aoqi@0 3629 const int entry_size = ( frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 3630 Label allocated;
aoqi@0 3631
aoqi@0 3632 // initialize entry pointer
aoqi@0 3633 __ xorl(rdx, rdx); // points to free slot or NULL
aoqi@0 3634
aoqi@0 3635 // find a free slot in the monitor block (result in rdx)
aoqi@0 3636 { Label entry, loop, exit;
aoqi@0 3637 __ movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry
aoqi@0 3638
aoqi@0 3639 __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block
aoqi@0 3640 __ jmpb(entry);
aoqi@0 3641
aoqi@0 3642 __ bind(loop);
aoqi@0 3643 __ cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used
aoqi@0 3644 __ cmovptr(Assembler::equal, rdx, rcx); // if not used then remember entry in rdx
aoqi@0 3645 __ cmpptr(rax, Address(rcx, BasicObjectLock::obj_offset_in_bytes())); // check if current entry is for same object
aoqi@0 3646 __ jccb(Assembler::equal, exit); // if same object then stop searching
aoqi@0 3647 __ addptr(rcx, entry_size); // otherwise advance to next entry
aoqi@0 3648 __ bind(entry);
aoqi@0 3649 __ cmpptr(rcx, rbx); // check if bottom reached
aoqi@0 3650 __ jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
aoqi@0 3651 __ bind(exit);
aoqi@0 3652 }
aoqi@0 3653
aoqi@0 3654 __ testptr(rdx, rdx); // check if a slot has been found
aoqi@0 3655 __ jccb(Assembler::notZero, allocated); // if found, continue with that one
aoqi@0 3656
aoqi@0 3657 // allocate one if there's no free slot
aoqi@0 3658 { Label entry, loop;
aoqi@0 3659 // 1. compute new pointers // rsp: old expression stack top
aoqi@0 3660 __ movptr(rdx, monitor_block_bot); // rdx: old expression stack bottom
aoqi@0 3661 __ subptr(rsp, entry_size); // move expression stack top
aoqi@0 3662 __ subptr(rdx, entry_size); // move expression stack bottom
aoqi@0 3663 __ mov(rcx, rsp); // set start value for copy loop
aoqi@0 3664 __ movptr(monitor_block_bot, rdx); // set new monitor block top
aoqi@0 3665 __ jmp(entry);
aoqi@0 3666 // 2. move expression stack contents
aoqi@0 3667 __ bind(loop);
aoqi@0 3668 __ movptr(rbx, Address(rcx, entry_size)); // load expression stack word from old location
aoqi@0 3669 __ movptr(Address(rcx, 0), rbx); // and store it at new location
aoqi@0 3670 __ addptr(rcx, wordSize); // advance to next word
aoqi@0 3671 __ bind(entry);
aoqi@0 3672 __ cmpptr(rcx, rdx); // check if bottom reached
aoqi@0 3673 __ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word
aoqi@0 3674 }
aoqi@0 3675
aoqi@0 3676 // call run-time routine
aoqi@0 3677 // rdx: points to monitor entry
aoqi@0 3678 __ bind(allocated);
aoqi@0 3679
aoqi@0 3680 // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
aoqi@0 3681 // The object has already been poped from the stack, so the expression stack looks correct.
aoqi@0 3682 __ increment(rsi);
aoqi@0 3683
aoqi@0 3684 __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), rax); // store object
aoqi@0 3685 __ lock_object(rdx);
aoqi@0 3686
aoqi@0 3687 // check to make sure this monitor doesn't cause stack overflow after locking
aoqi@0 3688 __ save_bcp(); // in case of exception
aoqi@0 3689 __ generate_stack_overflow_check(0);
aoqi@0 3690
aoqi@0 3691 // The bcp has already been incremented. Just need to dispatch to next instruction.
aoqi@0 3692 __ dispatch_next(vtos);
aoqi@0 3693 }
aoqi@0 3694
aoqi@0 3695
aoqi@0 3696 void TemplateTable::monitorexit() {
aoqi@0 3697 transition(atos, vtos);
aoqi@0 3698
aoqi@0 3699 // check for NULL object
aoqi@0 3700 __ null_check(rax);
aoqi@0 3701
aoqi@0 3702 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
aoqi@0 3703 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
aoqi@0 3704 const int entry_size = ( frame::interpreter_frame_monitor_size() * wordSize);
aoqi@0 3705 Label found;
aoqi@0 3706
aoqi@0 3707 // find matching slot
aoqi@0 3708 { Label entry, loop;
aoqi@0 3709 __ movptr(rdx, monitor_block_top); // points to current entry, starting with top-most entry
aoqi@0 3710 __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block
aoqi@0 3711 __ jmpb(entry);
aoqi@0 3712
aoqi@0 3713 __ bind(loop);
aoqi@0 3714 __ cmpptr(rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); // check if current entry is for same object
aoqi@0 3715 __ jcc(Assembler::equal, found); // if same object then stop searching
aoqi@0 3716 __ addptr(rdx, entry_size); // otherwise advance to next entry
aoqi@0 3717 __ bind(entry);
aoqi@0 3718 __ cmpptr(rdx, rbx); // check if bottom reached
aoqi@0 3719 __ jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
aoqi@0 3720 }
aoqi@0 3721
aoqi@0 3722 // error handling. Unlocking was not block-structured
aoqi@0 3723 Label end;
aoqi@0 3724 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
aoqi@0 3725 __ should_not_reach_here();
aoqi@0 3726
aoqi@0 3727 // call run-time routine
aoqi@0 3728 // rcx: points to monitor entry
aoqi@0 3729 __ bind(found);
aoqi@0 3730 __ push_ptr(rax); // make sure object is on stack (contract with oopMaps)
aoqi@0 3731 __ unlock_object(rdx);
aoqi@0 3732 __ pop_ptr(rax); // discard object
aoqi@0 3733 __ bind(end);
aoqi@0 3734 }
aoqi@0 3735
aoqi@0 3736
aoqi@0 3737 //----------------------------------------------------------------------------------------------------
aoqi@0 3738 // Wide instructions
aoqi@0 3739
aoqi@0 3740 void TemplateTable::wide() {
aoqi@0 3741 transition(vtos, vtos);
aoqi@0 3742 __ load_unsigned_byte(rbx, at_bcp(1));
aoqi@0 3743 ExternalAddress wtable((address)Interpreter::_wentry_point);
aoqi@0 3744 __ jump(ArrayAddress(wtable, Address(noreg, rbx, Address::times_ptr)));
aoqi@0 3745 // Note: the rsi increment step is part of the individual wide bytecode implementations
aoqi@0 3746 }
aoqi@0 3747
aoqi@0 3748
aoqi@0 3749 //----------------------------------------------------------------------------------------------------
aoqi@0 3750 // Multi arrays
aoqi@0 3751
aoqi@0 3752 void TemplateTable::multianewarray() {
aoqi@0 3753 transition(vtos, atos);
aoqi@0 3754 __ load_unsigned_byte(rax, at_bcp(3)); // get number of dimensions
aoqi@0 3755 // last dim is on top of stack; we want address of first one:
aoqi@0 3756 // first_addr = last_addr + (ndims - 1) * stackElementSize - 1*wordsize
aoqi@0 3757 // the latter wordSize to point to the beginning of the array.
aoqi@0 3758 __ lea( rax, Address(rsp, rax, Interpreter::stackElementScale(), -wordSize));
aoqi@0 3759 call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), rax); // pass in rax,
aoqi@0 3760 __ load_unsigned_byte(rbx, at_bcp(3));
aoqi@0 3761 __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale())); // get rid of counts
aoqi@0 3762 }
aoqi@0 3763
aoqi@0 3764 #endif /* !CC_INTERP */

mercurial