src/cpu/x86/vm/templateTable_x86_32.cpp

Thu, 08 Sep 2011 10:12:25 +0200

author
bdelsart
date
Thu, 08 Sep 2011 10:12:25 +0200
changeset 3130
5432047c7db7
parent 3050
fdb992d83a87
child 3368
52b5d32fbfaf
child 3391
069ab3f976d3
permissions
-rw-r--r--

7087445: Improve platform independence of JSR292 shared code
Summary: changes necessary for some JSR292 ports
Reviewed-by: jrose, dholmes

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

mercurial