annotate src/cpu/x86/vm/templateTable_x86_64.cpp @ 844:bd02caa94611

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