src/cpu/x86/vm/templateTable_x86_64.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial