src/cpu/x86/vm/templateTable_x86_32.cpp

Thu, 15 Aug 2013 20:04:10 -0400

author
hseigel
date
Thu, 15 Aug 2013 20:04:10 -0400
changeset 5528
740e263c80c6
parent 4936
aeaca88565e6
child 5914
d13d7aba8c12
permissions
-rw-r--r--

8003424: Enable Class Data Sharing for CompressedOops
8016729: ObjectAlignmentInBytes=16 now forces the use of heap based compressed oops
8005933: The -Xshare:auto option is ignored for -server
Summary: Move klass metaspace above the heap and support CDS with compressed klass ptrs.
Reviewed-by: coleenp, kvn, mgerdin, tschatzl, stefank

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

mercurial