src/cpu/x86/vm/interp_masm_x86_32.cpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8368
32b682649973
parent 6876
710a3c8b516e
child 9637
eef07cd490d4
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
kevinw@8368 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "interp_masm_x86.hpp"
aoqi@0 27 #include "interpreter/interpreter.hpp"
aoqi@0 28 #include "interpreter/interpreterRuntime.hpp"
aoqi@0 29 #include "oops/arrayOop.hpp"
aoqi@0 30 #include "oops/markOop.hpp"
aoqi@0 31 #include "oops/methodData.hpp"
aoqi@0 32 #include "oops/method.hpp"
aoqi@0 33 #include "prims/jvmtiExport.hpp"
aoqi@0 34 #include "prims/jvmtiRedefineClassesTrace.hpp"
aoqi@0 35 #include "prims/jvmtiThreadState.hpp"
aoqi@0 36 #include "runtime/basicLock.hpp"
aoqi@0 37 #include "runtime/biasedLocking.hpp"
aoqi@0 38 #include "runtime/sharedRuntime.hpp"
aoqi@0 39 #include "runtime/thread.inline.hpp"
aoqi@0 40
aoqi@0 41
aoqi@0 42 // Implementation of InterpreterMacroAssembler
aoqi@0 43 #ifdef CC_INTERP
aoqi@0 44 void InterpreterMacroAssembler::get_method(Register reg) {
aoqi@0 45 movptr(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize)));
aoqi@0 46 movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
aoqi@0 47 }
aoqi@0 48 #endif // CC_INTERP
aoqi@0 49
aoqi@0 50
aoqi@0 51 #ifndef CC_INTERP
aoqi@0 52 void InterpreterMacroAssembler::call_VM_leaf_base(
aoqi@0 53 address entry_point,
aoqi@0 54 int number_of_arguments
aoqi@0 55 ) {
aoqi@0 56 // interpreter specific
aoqi@0 57 //
aoqi@0 58 // Note: No need to save/restore bcp & locals (rsi & rdi) pointer
aoqi@0 59 // since these are callee saved registers and no blocking/
aoqi@0 60 // GC can happen in leaf calls.
aoqi@0 61 // Further Note: DO NOT save/restore bcp/locals. If a caller has
aoqi@0 62 // already saved them so that it can use rsi/rdi as temporaries
aoqi@0 63 // then a save/restore here will DESTROY the copy the caller
aoqi@0 64 // saved! There used to be a save_bcp() that only happened in
aoqi@0 65 // the ASSERT path (no restore_bcp). Which caused bizarre failures
aoqi@0 66 // when jvm built with ASSERTs.
aoqi@0 67 #ifdef ASSERT
aoqi@0 68 { Label L;
aoqi@0 69 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
aoqi@0 70 jcc(Assembler::equal, L);
aoqi@0 71 stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL");
aoqi@0 72 bind(L);
aoqi@0 73 }
aoqi@0 74 #endif
aoqi@0 75 // super call
aoqi@0 76 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
aoqi@0 77 // interpreter specific
aoqi@0 78
aoqi@0 79 // Used to ASSERT that rsi/rdi were equal to frame's bcp/locals
aoqi@0 80 // but since they may not have been saved (and we don't want to
aoqi@0 81 // save them here (see note above) the assert is invalid.
aoqi@0 82 }
aoqi@0 83
aoqi@0 84
aoqi@0 85 void InterpreterMacroAssembler::call_VM_base(
aoqi@0 86 Register oop_result,
aoqi@0 87 Register java_thread,
aoqi@0 88 Register last_java_sp,
aoqi@0 89 address entry_point,
aoqi@0 90 int number_of_arguments,
aoqi@0 91 bool check_exceptions
aoqi@0 92 ) {
aoqi@0 93 #ifdef ASSERT
aoqi@0 94 { Label L;
aoqi@0 95 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
aoqi@0 96 jcc(Assembler::equal, L);
aoqi@0 97 stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
aoqi@0 98 bind(L);
aoqi@0 99 }
aoqi@0 100 #endif /* ASSERT */
aoqi@0 101 // interpreter specific
aoqi@0 102 //
aoqi@0 103 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
aoqi@0 104 // really make a difference for these runtime calls, since they are
aoqi@0 105 // slow anyway. Btw., bcp must be saved/restored since it may change
aoqi@0 106 // due to GC.
aoqi@0 107 assert(java_thread == noreg , "not expecting a precomputed java thread");
aoqi@0 108 save_bcp();
aoqi@0 109 // super call
aoqi@0 110 MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
aoqi@0 111 // interpreter specific
aoqi@0 112 restore_bcp();
aoqi@0 113 restore_locals();
aoqi@0 114 }
aoqi@0 115
aoqi@0 116
aoqi@0 117 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
aoqi@0 118 if (JvmtiExport::can_pop_frame()) {
aoqi@0 119 Label L;
aoqi@0 120 // Initiate popframe handling only if it is not already being processed. If the flag
aoqi@0 121 // has the popframe_processing bit set, it means that this code is called *during* popframe
aoqi@0 122 // handling - we don't want to reenter.
aoqi@0 123 Register pop_cond = java_thread; // Not clear if any other register is available...
aoqi@0 124 movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset()));
aoqi@0 125 testl(pop_cond, JavaThread::popframe_pending_bit);
aoqi@0 126 jcc(Assembler::zero, L);
aoqi@0 127 testl(pop_cond, JavaThread::popframe_processing_bit);
aoqi@0 128 jcc(Assembler::notZero, L);
aoqi@0 129 // Call Interpreter::remove_activation_preserving_args_entry() to get the
aoqi@0 130 // address of the same-named entrypoint in the generated interpreter code.
aoqi@0 131 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
aoqi@0 132 jmp(rax);
aoqi@0 133 bind(L);
aoqi@0 134 get_thread(java_thread);
aoqi@0 135 }
aoqi@0 136 }
aoqi@0 137
aoqi@0 138
aoqi@0 139 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
aoqi@0 140 get_thread(rcx);
aoqi@0 141 movl(rcx, Address(rcx, JavaThread::jvmti_thread_state_offset()));
aoqi@0 142 const Address tos_addr (rcx, JvmtiThreadState::earlyret_tos_offset());
aoqi@0 143 const Address oop_addr (rcx, JvmtiThreadState::earlyret_oop_offset());
aoqi@0 144 const Address val_addr (rcx, JvmtiThreadState::earlyret_value_offset());
aoqi@0 145 const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset()
aoqi@0 146 + in_ByteSize(wordSize));
aoqi@0 147 switch (state) {
aoqi@0 148 case atos: movptr(rax, oop_addr);
aoqi@0 149 movptr(oop_addr, NULL_WORD);
aoqi@0 150 verify_oop(rax, state); break;
aoqi@0 151 case ltos:
aoqi@0 152 movl(rdx, val_addr1); // fall through
aoqi@0 153 case btos: // fall through
kevinw@8368 154 case ztos: // fall through
aoqi@0 155 case ctos: // fall through
aoqi@0 156 case stos: // fall through
aoqi@0 157 case itos: movl(rax, val_addr); break;
aoqi@0 158 case ftos: fld_s(val_addr); break;
aoqi@0 159 case dtos: fld_d(val_addr); break;
aoqi@0 160 case vtos: /* nothing to do */ break;
aoqi@0 161 default : ShouldNotReachHere();
aoqi@0 162 }
aoqi@0 163 // Clean up tos value in the thread object
aoqi@0 164 movl(tos_addr, (int32_t) ilgl);
aoqi@0 165 movptr(val_addr, NULL_WORD);
aoqi@0 166 NOT_LP64(movptr(val_addr1, NULL_WORD));
aoqi@0 167 }
aoqi@0 168
aoqi@0 169
aoqi@0 170 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
aoqi@0 171 if (JvmtiExport::can_force_early_return()) {
aoqi@0 172 Label L;
aoqi@0 173 Register tmp = java_thread;
aoqi@0 174 movptr(tmp, Address(tmp, JavaThread::jvmti_thread_state_offset()));
aoqi@0 175 testptr(tmp, tmp);
aoqi@0 176 jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
aoqi@0 177
aoqi@0 178 // Initiate earlyret handling only if it is not already being processed.
aoqi@0 179 // If the flag has the earlyret_processing bit set, it means that this code
aoqi@0 180 // is called *during* earlyret handling - we don't want to reenter.
aoqi@0 181 movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset()));
aoqi@0 182 cmpl(tmp, JvmtiThreadState::earlyret_pending);
aoqi@0 183 jcc(Assembler::notEqual, L);
aoqi@0 184
aoqi@0 185 // Call Interpreter::remove_activation_early_entry() to get the address of the
aoqi@0 186 // same-named entrypoint in the generated interpreter code.
aoqi@0 187 get_thread(java_thread);
aoqi@0 188 movptr(tmp, Address(java_thread, JavaThread::jvmti_thread_state_offset()));
aoqi@0 189 pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
aoqi@0 190 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1);
aoqi@0 191 jmp(rax);
aoqi@0 192 bind(L);
aoqi@0 193 get_thread(java_thread);
aoqi@0 194 }
aoqi@0 195 }
aoqi@0 196
aoqi@0 197
aoqi@0 198 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) {
aoqi@0 199 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
aoqi@0 200 load_unsigned_short(reg, Address(rsi, bcp_offset));
aoqi@0 201 bswapl(reg);
aoqi@0 202 shrl(reg, 16);
aoqi@0 203 }
aoqi@0 204
aoqi@0 205
aoqi@0 206 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register reg, int bcp_offset, size_t index_size) {
aoqi@0 207 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
aoqi@0 208 if (index_size == sizeof(u2)) {
aoqi@0 209 load_unsigned_short(reg, Address(rsi, bcp_offset));
aoqi@0 210 } else if (index_size == sizeof(u4)) {
aoqi@0 211 assert(EnableInvokeDynamic, "giant index used only for JSR 292");
aoqi@0 212 movl(reg, Address(rsi, bcp_offset));
aoqi@0 213 // Check if the secondary index definition is still ~x, otherwise
aoqi@0 214 // we have to change the following assembler code to calculate the
aoqi@0 215 // plain index.
aoqi@0 216 assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
aoqi@0 217 notl(reg); // convert to plain index
aoqi@0 218 } else if (index_size == sizeof(u1)) {
aoqi@0 219 load_unsigned_byte(reg, Address(rsi, bcp_offset));
aoqi@0 220 } else {
aoqi@0 221 ShouldNotReachHere();
aoqi@0 222 }
aoqi@0 223 }
aoqi@0 224
aoqi@0 225
aoqi@0 226 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register index,
aoqi@0 227 int bcp_offset, size_t index_size) {
aoqi@0 228 assert_different_registers(cache, index);
aoqi@0 229 get_cache_index_at_bcp(index, bcp_offset, index_size);
aoqi@0 230 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
aoqi@0 231 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
aoqi@0 232 assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
aoqi@0 233 shlptr(index, 2); // convert from field index to ConstantPoolCacheEntry index
aoqi@0 234 }
aoqi@0 235
aoqi@0 236
aoqi@0 237 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
aoqi@0 238 Register index,
aoqi@0 239 Register bytecode,
aoqi@0 240 int byte_no,
aoqi@0 241 int bcp_offset,
aoqi@0 242 size_t index_size) {
aoqi@0 243 get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
aoqi@0 244 movptr(bytecode, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
aoqi@0 245 const int shift_count = (1 + byte_no) * BitsPerByte;
aoqi@0 246 assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
aoqi@0 247 (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
aoqi@0 248 "correct shift count");
aoqi@0 249 shrptr(bytecode, shift_count);
aoqi@0 250 assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
aoqi@0 251 andptr(bytecode, ConstantPoolCacheEntry::bytecode_1_mask);
aoqi@0 252 }
aoqi@0 253
aoqi@0 254
aoqi@0 255 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp,
aoqi@0 256 int bcp_offset, size_t index_size) {
aoqi@0 257 assert(cache != tmp, "must use different register");
aoqi@0 258 get_cache_index_at_bcp(tmp, bcp_offset, index_size);
aoqi@0 259 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
aoqi@0 260 // convert from field index to ConstantPoolCacheEntry index
aoqi@0 261 // and from word offset to byte offset
aoqi@0 262 assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
aoqi@0 263 shll(tmp, 2 + LogBytesPerWord);
aoqi@0 264 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
aoqi@0 265 // skip past the header
aoqi@0 266 addptr(cache, in_bytes(ConstantPoolCache::base_offset()));
aoqi@0 267 addptr(cache, tmp); // construct pointer to cache entry
aoqi@0 268 }
aoqi@0 269
aoqi@0 270 void InterpreterMacroAssembler::get_method_counters(Register method,
aoqi@0 271 Register mcs, Label& skip) {
aoqi@0 272 Label has_counters;
aoqi@0 273 movptr(mcs, Address(method, Method::method_counters_offset()));
aoqi@0 274 testptr(mcs, mcs);
aoqi@0 275 jcc(Assembler::notZero, has_counters);
aoqi@0 276 call_VM(noreg, CAST_FROM_FN_PTR(address,
aoqi@0 277 InterpreterRuntime::build_method_counters), method);
aoqi@0 278 movptr(mcs, Address(method,Method::method_counters_offset()));
aoqi@0 279 testptr(mcs, mcs);
aoqi@0 280 jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
aoqi@0 281 bind(has_counters);
aoqi@0 282 }
aoqi@0 283
aoqi@0 284 // Load object from cpool->resolved_references(index)
aoqi@0 285 void InterpreterMacroAssembler::load_resolved_reference_at_index(
aoqi@0 286 Register result, Register index) {
aoqi@0 287 assert_different_registers(result, index);
aoqi@0 288 // convert from field index to resolved_references() index and from
aoqi@0 289 // word index to byte offset. Since this is a java object, it can be compressed
aoqi@0 290 Register tmp = index; // reuse
aoqi@0 291 shll(tmp, LogBytesPerHeapOop);
aoqi@0 292
aoqi@0 293 get_constant_pool(result);
aoqi@0 294 // load pointer for resolved_references[] objArray
aoqi@0 295 movptr(result, Address(result, ConstantPool::resolved_references_offset_in_bytes()));
aoqi@0 296 // JNIHandles::resolve(obj);
aoqi@0 297 movptr(result, Address(result, 0));
aoqi@0 298 // Add in the index
aoqi@0 299 addptr(result, tmp);
aoqi@0 300 load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 // Generate a subtype check: branch to ok_is_subtype if sub_klass is
aoqi@0 304 // a subtype of super_klass. EAX holds the super_klass. Blows ECX.
aoqi@0 305 // Resets EDI to locals. Register sub_klass cannot be any of the above.
aoqi@0 306 void InterpreterMacroAssembler::gen_subtype_check( Register Rsub_klass, Label &ok_is_subtype ) {
aoqi@0 307 assert( Rsub_klass != rax, "rax, holds superklass" );
aoqi@0 308 assert( Rsub_klass != rcx, "used as a temp" );
aoqi@0 309 assert( Rsub_klass != rdi, "used as a temp, restored from locals" );
aoqi@0 310
aoqi@0 311 // Profile the not-null value's klass.
aoqi@0 312 profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
aoqi@0 313
aoqi@0 314 // Do the check.
aoqi@0 315 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
aoqi@0 316
aoqi@0 317 // Profile the failure of the check.
aoqi@0 318 profile_typecheck_failed(rcx); // blows rcx
aoqi@0 319 }
aoqi@0 320
aoqi@0 321 void InterpreterMacroAssembler::f2ieee() {
aoqi@0 322 if (IEEEPrecision) {
aoqi@0 323 fstp_s(Address(rsp, 0));
aoqi@0 324 fld_s(Address(rsp, 0));
aoqi@0 325 }
aoqi@0 326 }
aoqi@0 327
aoqi@0 328
aoqi@0 329 void InterpreterMacroAssembler::d2ieee() {
aoqi@0 330 if (IEEEPrecision) {
aoqi@0 331 fstp_d(Address(rsp, 0));
aoqi@0 332 fld_d(Address(rsp, 0));
aoqi@0 333 }
aoqi@0 334 }
aoqi@0 335
aoqi@0 336 // Java Expression Stack
aoqi@0 337
aoqi@0 338 void InterpreterMacroAssembler::pop_ptr(Register r) {
aoqi@0 339 pop(r);
aoqi@0 340 }
aoqi@0 341
aoqi@0 342 void InterpreterMacroAssembler::pop_i(Register r) {
aoqi@0 343 pop(r);
aoqi@0 344 }
aoqi@0 345
aoqi@0 346 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
aoqi@0 347 pop(lo);
aoqi@0 348 pop(hi);
aoqi@0 349 }
aoqi@0 350
aoqi@0 351 void InterpreterMacroAssembler::pop_f() {
aoqi@0 352 fld_s(Address(rsp, 0));
aoqi@0 353 addptr(rsp, 1 * wordSize);
aoqi@0 354 }
aoqi@0 355
aoqi@0 356 void InterpreterMacroAssembler::pop_d() {
aoqi@0 357 fld_d(Address(rsp, 0));
aoqi@0 358 addptr(rsp, 2 * wordSize);
aoqi@0 359 }
aoqi@0 360
aoqi@0 361
aoqi@0 362 void InterpreterMacroAssembler::pop(TosState state) {
aoqi@0 363 switch (state) {
aoqi@0 364 case atos: pop_ptr(rax); break;
aoqi@0 365 case btos: // fall through
kevinw@8368 366 case ztos: // fall through
aoqi@0 367 case ctos: // fall through
aoqi@0 368 case stos: // fall through
aoqi@0 369 case itos: pop_i(rax); break;
aoqi@0 370 case ltos: pop_l(rax, rdx); break;
aoqi@0 371 case ftos: pop_f(); break;
aoqi@0 372 case dtos: pop_d(); break;
aoqi@0 373 case vtos: /* nothing to do */ break;
aoqi@0 374 default : ShouldNotReachHere();
aoqi@0 375 }
aoqi@0 376 verify_oop(rax, state);
aoqi@0 377 }
aoqi@0 378
aoqi@0 379 void InterpreterMacroAssembler::push_ptr(Register r) {
aoqi@0 380 push(r);
aoqi@0 381 }
aoqi@0 382
aoqi@0 383 void InterpreterMacroAssembler::push_i(Register r) {
aoqi@0 384 push(r);
aoqi@0 385 }
aoqi@0 386
aoqi@0 387 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
aoqi@0 388 push(hi);
aoqi@0 389 push(lo);
aoqi@0 390 }
aoqi@0 391
aoqi@0 392 void InterpreterMacroAssembler::push_f() {
aoqi@0 393 // Do not schedule for no AGI! Never write beyond rsp!
aoqi@0 394 subptr(rsp, 1 * wordSize);
aoqi@0 395 fstp_s(Address(rsp, 0));
aoqi@0 396 }
aoqi@0 397
aoqi@0 398 void InterpreterMacroAssembler::push_d(Register r) {
aoqi@0 399 // Do not schedule for no AGI! Never write beyond rsp!
aoqi@0 400 subptr(rsp, 2 * wordSize);
aoqi@0 401 fstp_d(Address(rsp, 0));
aoqi@0 402 }
aoqi@0 403
aoqi@0 404
aoqi@0 405 void InterpreterMacroAssembler::push(TosState state) {
aoqi@0 406 verify_oop(rax, state);
aoqi@0 407 switch (state) {
aoqi@0 408 case atos: push_ptr(rax); break;
aoqi@0 409 case btos: // fall through
kevinw@8368 410 case ztos: // fall through
aoqi@0 411 case ctos: // fall through
aoqi@0 412 case stos: // fall through
aoqi@0 413 case itos: push_i(rax); break;
aoqi@0 414 case ltos: push_l(rax, rdx); break;
aoqi@0 415 case ftos: push_f(); break;
aoqi@0 416 case dtos: push_d(rax); break;
aoqi@0 417 case vtos: /* nothing to do */ break;
aoqi@0 418 default : ShouldNotReachHere();
aoqi@0 419 }
aoqi@0 420 }
aoqi@0 421
aoqi@0 422
aoqi@0 423 // Helpers for swap and dup
aoqi@0 424 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
aoqi@0 425 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
aoqi@0 429 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
aoqi@0 430 }
aoqi@0 431
aoqi@0 432 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
aoqi@0 433 // set sender sp
aoqi@0 434 lea(rsi, Address(rsp, wordSize));
aoqi@0 435 // record last_sp
aoqi@0 436 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rsi);
aoqi@0 437 }
aoqi@0 438
aoqi@0 439
aoqi@0 440 // Jump to from_interpreted entry of a call unless single stepping is possible
aoqi@0 441 // in this thread in which case we must call the i2i entry
aoqi@0 442 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
aoqi@0 443 prepare_to_jump_from_interpreted();
aoqi@0 444
aoqi@0 445 if (JvmtiExport::can_post_interpreter_events()) {
aoqi@0 446 Label run_compiled_code;
aoqi@0 447 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
aoqi@0 448 // compiled code in threads for which the event is enabled. Check here for
aoqi@0 449 // interp_only_mode if these events CAN be enabled.
aoqi@0 450 get_thread(temp);
aoqi@0 451 // interp_only is an int, on little endian it is sufficient to test the byte only
aoqi@0 452 // Is a cmpl faster?
aoqi@0 453 cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
aoqi@0 454 jccb(Assembler::zero, run_compiled_code);
aoqi@0 455 jmp(Address(method, Method::interpreter_entry_offset()));
aoqi@0 456 bind(run_compiled_code);
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 jmp(Address(method, Method::from_interpreted_offset()));
aoqi@0 460
aoqi@0 461 }
aoqi@0 462
aoqi@0 463
aoqi@0 464 // The following two routines provide a hook so that an implementation
aoqi@0 465 // can schedule the dispatch in two parts. Intel does not do this.
aoqi@0 466 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
aoqi@0 467 // Nothing Intel-specific to be done here.
aoqi@0 468 }
aoqi@0 469
aoqi@0 470 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
aoqi@0 471 dispatch_next(state, step);
aoqi@0 472 }
aoqi@0 473
aoqi@0 474 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table,
aoqi@0 475 bool verifyoop) {
aoqi@0 476 verify_FPU(1, state);
aoqi@0 477 if (VerifyActivationFrameSize) {
aoqi@0 478 Label L;
aoqi@0 479 mov(rcx, rbp);
aoqi@0 480 subptr(rcx, rsp);
aoqi@0 481 int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize;
aoqi@0 482 cmpptr(rcx, min_frame_size);
aoqi@0 483 jcc(Assembler::greaterEqual, L);
aoqi@0 484 stop("broken stack frame");
aoqi@0 485 bind(L);
aoqi@0 486 }
aoqi@0 487 if (verifyoop) verify_oop(rax, state);
aoqi@0 488 Address index(noreg, rbx, Address::times_ptr);
aoqi@0 489 ExternalAddress tbl((address)table);
aoqi@0 490 ArrayAddress dispatch(tbl, index);
aoqi@0 491 jump(dispatch);
aoqi@0 492 }
aoqi@0 493
aoqi@0 494
aoqi@0 495 void InterpreterMacroAssembler::dispatch_only(TosState state) {
aoqi@0 496 dispatch_base(state, Interpreter::dispatch_table(state));
aoqi@0 497 }
aoqi@0 498
aoqi@0 499
aoqi@0 500 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
aoqi@0 501 dispatch_base(state, Interpreter::normal_table(state));
aoqi@0 502 }
aoqi@0 503
aoqi@0 504 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
aoqi@0 505 dispatch_base(state, Interpreter::normal_table(state), false);
aoqi@0 506 }
aoqi@0 507
aoqi@0 508
aoqi@0 509 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
aoqi@0 510 // load next bytecode (load before advancing rsi to prevent AGI)
aoqi@0 511 load_unsigned_byte(rbx, Address(rsi, step));
aoqi@0 512 // advance rsi
aoqi@0 513 increment(rsi, step);
aoqi@0 514 dispatch_base(state, Interpreter::dispatch_table(state));
aoqi@0 515 }
aoqi@0 516
aoqi@0 517
aoqi@0 518 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
aoqi@0 519 // load current bytecode
aoqi@0 520 load_unsigned_byte(rbx, Address(rsi, 0));
aoqi@0 521 dispatch_base(state, table);
aoqi@0 522 }
aoqi@0 523
aoqi@0 524 // remove activation
aoqi@0 525 //
aoqi@0 526 // Unlock the receiver if this is a synchronized method.
aoqi@0 527 // Unlock any Java monitors from syncronized blocks.
aoqi@0 528 // Remove the activation from the stack.
aoqi@0 529 //
aoqi@0 530 // If there are locked Java monitors
aoqi@0 531 // If throw_monitor_exception
aoqi@0 532 // throws IllegalMonitorStateException
aoqi@0 533 // Else if install_monitor_exception
aoqi@0 534 // installs IllegalMonitorStateException
aoqi@0 535 // Else
aoqi@0 536 // no error processing
aoqi@0 537 void InterpreterMacroAssembler::remove_activation(TosState state, Register ret_addr,
aoqi@0 538 bool throw_monitor_exception,
aoqi@0 539 bool install_monitor_exception,
aoqi@0 540 bool notify_jvmdi) {
aoqi@0 541 // Note: Registers rax, rdx and FPU ST(0) may be in use for the result
aoqi@0 542 // check if synchronized method
aoqi@0 543 Label unlocked, unlock, no_unlock;
aoqi@0 544
aoqi@0 545 get_thread(rcx);
aoqi@0 546 const Address do_not_unlock_if_synchronized(rcx,
aoqi@0 547 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
aoqi@0 548
aoqi@0 549 movbool(rbx, do_not_unlock_if_synchronized);
aoqi@0 550 mov(rdi,rbx);
aoqi@0 551 movbool(do_not_unlock_if_synchronized, false); // reset the flag
aoqi@0 552
aoqi@0 553 movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); // get method access flags
aoqi@0 554 movl(rcx, Address(rbx, Method::access_flags_offset()));
aoqi@0 555
aoqi@0 556 testl(rcx, JVM_ACC_SYNCHRONIZED);
aoqi@0 557 jcc(Assembler::zero, unlocked);
aoqi@0 558
aoqi@0 559 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
aoqi@0 560 // is set.
aoqi@0 561 mov(rcx,rdi);
aoqi@0 562 testbool(rcx);
aoqi@0 563 jcc(Assembler::notZero, no_unlock);
aoqi@0 564
aoqi@0 565 // unlock monitor
aoqi@0 566 push(state); // save result
aoqi@0 567
aoqi@0 568 // BasicObjectLock will be first in list, since this is a synchronized method. However, need
aoqi@0 569 // to check that the object has not been unlocked by an explicit monitorexit bytecode.
aoqi@0 570 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
aoqi@0 571 lea (rdx, monitor); // address of first monitor
aoqi@0 572
aoqi@0 573 movptr (rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
aoqi@0 574 testptr(rax, rax);
aoqi@0 575 jcc (Assembler::notZero, unlock);
aoqi@0 576
aoqi@0 577 pop(state);
aoqi@0 578 if (throw_monitor_exception) {
aoqi@0 579 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
aoqi@0 580
aoqi@0 581 // Entry already unlocked, need to throw exception
aoqi@0 582 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
aoqi@0 583 should_not_reach_here();
aoqi@0 584 } else {
aoqi@0 585 // Monitor already unlocked during a stack unroll.
aoqi@0 586 // If requested, install an illegal_monitor_state_exception.
aoqi@0 587 // Continue with stack unrolling.
aoqi@0 588 if (install_monitor_exception) {
aoqi@0 589 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
aoqi@0 590 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
aoqi@0 591 }
aoqi@0 592 jmp(unlocked);
aoqi@0 593 }
aoqi@0 594
aoqi@0 595 bind(unlock);
aoqi@0 596 unlock_object(rdx);
aoqi@0 597 pop(state);
aoqi@0 598
aoqi@0 599 // Check that for block-structured locking (i.e., that all locked objects has been unlocked)
aoqi@0 600 bind(unlocked);
aoqi@0 601
aoqi@0 602 // rax, rdx: Might contain return value
aoqi@0 603
aoqi@0 604 // Check that all monitors are unlocked
aoqi@0 605 {
aoqi@0 606 Label loop, exception, entry, restart;
aoqi@0 607 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
aoqi@0 608 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
aoqi@0 609 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
aoqi@0 610
aoqi@0 611 bind(restart);
aoqi@0 612 movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry
aoqi@0 613 lea(rbx, monitor_block_bot); // points to word before bottom of monitor block
aoqi@0 614 jmp(entry);
aoqi@0 615
aoqi@0 616 // Entry already locked, need to throw exception
aoqi@0 617 bind(exception);
aoqi@0 618
aoqi@0 619 if (throw_monitor_exception) {
aoqi@0 620 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
aoqi@0 621
aoqi@0 622 // Throw exception
aoqi@0 623 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
aoqi@0 624 should_not_reach_here();
aoqi@0 625 } else {
aoqi@0 626 // Stack unrolling. Unlock object and install illegal_monitor_exception
aoqi@0 627 // Unlock does not block, so don't have to worry about the frame
aoqi@0 628
aoqi@0 629 push(state);
aoqi@0 630 mov(rdx, rcx);
aoqi@0 631 unlock_object(rdx);
aoqi@0 632 pop(state);
aoqi@0 633
aoqi@0 634 if (install_monitor_exception) {
aoqi@0 635 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow
aoqi@0 636 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
aoqi@0 637 }
aoqi@0 638
aoqi@0 639 jmp(restart);
aoqi@0 640 }
aoqi@0 641
aoqi@0 642 bind(loop);
aoqi@0 643 cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used
aoqi@0 644 jcc(Assembler::notEqual, exception);
aoqi@0 645
aoqi@0 646 addptr(rcx, entry_size); // otherwise advance to next entry
aoqi@0 647 bind(entry);
aoqi@0 648 cmpptr(rcx, rbx); // check if bottom reached
aoqi@0 649 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
aoqi@0 650 }
aoqi@0 651
aoqi@0 652 bind(no_unlock);
aoqi@0 653
aoqi@0 654 // jvmti support
aoqi@0 655 if (notify_jvmdi) {
aoqi@0 656 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
aoqi@0 657 } else {
aoqi@0 658 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
aoqi@0 659 }
aoqi@0 660
aoqi@0 661 // remove activation
aoqi@0 662 movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
aoqi@0 663 leave(); // remove frame anchor
aoqi@0 664 pop(ret_addr); // get return address
aoqi@0 665 mov(rsp, rbx); // set sp to sender sp
aoqi@0 666 if (UseSSE) {
aoqi@0 667 // float and double are returned in xmm register in SSE-mode
aoqi@0 668 if (state == ftos && UseSSE >= 1) {
aoqi@0 669 subptr(rsp, wordSize);
aoqi@0 670 fstp_s(Address(rsp, 0));
aoqi@0 671 movflt(xmm0, Address(rsp, 0));
aoqi@0 672 addptr(rsp, wordSize);
aoqi@0 673 } else if (state == dtos && UseSSE >= 2) {
aoqi@0 674 subptr(rsp, 2*wordSize);
aoqi@0 675 fstp_d(Address(rsp, 0));
aoqi@0 676 movdbl(xmm0, Address(rsp, 0));
aoqi@0 677 addptr(rsp, 2*wordSize);
aoqi@0 678 }
aoqi@0 679 }
aoqi@0 680 }
aoqi@0 681
aoqi@0 682 #endif /* !CC_INTERP */
aoqi@0 683
aoqi@0 684
aoqi@0 685 // Lock object
aoqi@0 686 //
aoqi@0 687 // Argument: rdx : Points to BasicObjectLock to be used for locking. Must
aoqi@0 688 // be initialized with object to lock
aoqi@0 689 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
aoqi@0 690 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
aoqi@0 691
aoqi@0 692 if (UseHeavyMonitors) {
aoqi@0 693 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
aoqi@0 694 } else {
aoqi@0 695
aoqi@0 696 Label done;
aoqi@0 697
aoqi@0 698 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction
aoqi@0 699 const Register obj_reg = rcx; // Will contain the oop
aoqi@0 700
aoqi@0 701 const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
aoqi@0 702 const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
aoqi@0 703 const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes();
aoqi@0 704
aoqi@0 705 Label slow_case;
aoqi@0 706
aoqi@0 707 // Load object pointer into obj_reg %rcx
aoqi@0 708 movptr(obj_reg, Address(lock_reg, obj_offset));
aoqi@0 709
aoqi@0 710 if (UseBiasedLocking) {
aoqi@0 711 // Note: we use noreg for the temporary register since it's hard
aoqi@0 712 // to come up with a free register on all incoming code paths
aoqi@0 713 biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
aoqi@0 714 }
aoqi@0 715
aoqi@0 716 // Load immediate 1 into swap_reg %rax,
aoqi@0 717 movptr(swap_reg, (int32_t)1);
aoqi@0 718
aoqi@0 719 // Load (object->mark() | 1) into swap_reg %rax,
aoqi@0 720 orptr(swap_reg, Address(obj_reg, 0));
aoqi@0 721
aoqi@0 722 // Save (object->mark() | 1) into BasicLock's displaced header
aoqi@0 723 movptr(Address(lock_reg, mark_offset), swap_reg);
aoqi@0 724
aoqi@0 725 assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
aoqi@0 726 if (os::is_MP()) {
aoqi@0 727 lock();
aoqi@0 728 }
aoqi@0 729 cmpxchgptr(lock_reg, Address(obj_reg, 0));
aoqi@0 730 if (PrintBiasedLockingStatistics) {
aoqi@0 731 cond_inc32(Assembler::zero,
aoqi@0 732 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
aoqi@0 733 }
aoqi@0 734 jcc(Assembler::zero, done);
aoqi@0 735
aoqi@0 736 // Test if the oopMark is an obvious stack pointer, i.e.,
aoqi@0 737 // 1) (mark & 3) == 0, and
aoqi@0 738 // 2) rsp <= mark < mark + os::pagesize()
aoqi@0 739 //
aoqi@0 740 // These 3 tests can be done by evaluating the following
aoqi@0 741 // expression: ((mark - rsp) & (3 - os::vm_page_size())),
aoqi@0 742 // assuming both stack pointer and pagesize have their
aoqi@0 743 // least significant 2 bits clear.
aoqi@0 744 // NOTE: the oopMark is in swap_reg %rax, as the result of cmpxchg
aoqi@0 745 subptr(swap_reg, rsp);
aoqi@0 746 andptr(swap_reg, 3 - os::vm_page_size());
aoqi@0 747
aoqi@0 748 // Save the test result, for recursive case, the result is zero
aoqi@0 749 movptr(Address(lock_reg, mark_offset), swap_reg);
aoqi@0 750
aoqi@0 751 if (PrintBiasedLockingStatistics) {
aoqi@0 752 cond_inc32(Assembler::zero,
aoqi@0 753 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
aoqi@0 754 }
aoqi@0 755 jcc(Assembler::zero, done);
aoqi@0 756
aoqi@0 757 bind(slow_case);
aoqi@0 758
aoqi@0 759 // Call the runtime routine for slow case
aoqi@0 760 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
aoqi@0 761
aoqi@0 762 bind(done);
aoqi@0 763 }
aoqi@0 764 }
aoqi@0 765
aoqi@0 766
aoqi@0 767 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
aoqi@0 768 //
aoqi@0 769 // Argument: rdx : Points to BasicObjectLock structure for lock
aoqi@0 770 // Throw an IllegalMonitorException if object is not locked by current thread
aoqi@0 771 //
aoqi@0 772 // Uses: rax, rbx, rcx, rdx
aoqi@0 773 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
aoqi@0 774 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
aoqi@0 775
aoqi@0 776 if (UseHeavyMonitors) {
aoqi@0 777 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
aoqi@0 778 } else {
aoqi@0 779 Label done;
aoqi@0 780
aoqi@0 781 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction
aoqi@0 782 const Register header_reg = rbx; // Will contain the old oopMark
aoqi@0 783 const Register obj_reg = rcx; // Will contain the oop
aoqi@0 784
aoqi@0 785 save_bcp(); // Save in case of exception
aoqi@0 786
aoqi@0 787 // Convert from BasicObjectLock structure to object and BasicLock structure
aoqi@0 788 // Store the BasicLock address into %rax,
aoqi@0 789 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
aoqi@0 790
aoqi@0 791 // Load oop into obj_reg(%rcx)
aoqi@0 792 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes ()));
aoqi@0 793
aoqi@0 794 // Free entry
aoqi@0 795 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD);
aoqi@0 796
aoqi@0 797 if (UseBiasedLocking) {
aoqi@0 798 biased_locking_exit(obj_reg, header_reg, done);
aoqi@0 799 }
aoqi@0 800
aoqi@0 801 // Load the old header from BasicLock structure
aoqi@0 802 movptr(header_reg, Address(swap_reg, BasicLock::displaced_header_offset_in_bytes()));
aoqi@0 803
aoqi@0 804 // Test for recursion
aoqi@0 805 testptr(header_reg, header_reg);
aoqi@0 806
aoqi@0 807 // zero for recursive case
aoqi@0 808 jcc(Assembler::zero, done);
aoqi@0 809
aoqi@0 810 // Atomic swap back the old header
aoqi@0 811 if (os::is_MP()) lock();
aoqi@0 812 cmpxchgptr(header_reg, Address(obj_reg, 0));
aoqi@0 813
aoqi@0 814 // zero for recursive case
aoqi@0 815 jcc(Assembler::zero, done);
aoqi@0 816
aoqi@0 817 // Call the runtime routine for slow case.
aoqi@0 818 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj
aoqi@0 819 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
aoqi@0 820
aoqi@0 821 bind(done);
aoqi@0 822
aoqi@0 823 restore_bcp();
aoqi@0 824 }
aoqi@0 825 }
aoqi@0 826
aoqi@0 827
aoqi@0 828 #ifndef CC_INTERP
aoqi@0 829
aoqi@0 830 // Test ImethodDataPtr. If it is null, continue at the specified label
aoqi@0 831 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) {
aoqi@0 832 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 833 movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
aoqi@0 834 testptr(mdp, mdp);
aoqi@0 835 jcc(Assembler::zero, zero_continue);
aoqi@0 836 }
aoqi@0 837
aoqi@0 838
aoqi@0 839 // Set the method data pointer for the current bcp.
aoqi@0 840 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
aoqi@0 841 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 842 Label set_mdp;
aoqi@0 843 push(rax);
aoqi@0 844 push(rbx);
aoqi@0 845
aoqi@0 846 get_method(rbx);
aoqi@0 847 // Test MDO to avoid the call if it is NULL.
aoqi@0 848 movptr(rax, Address(rbx, in_bytes(Method::method_data_offset())));
aoqi@0 849 testptr(rax, rax);
aoqi@0 850 jcc(Assembler::zero, set_mdp);
aoqi@0 851 // rbx,: method
aoqi@0 852 // rsi: bcp
aoqi@0 853 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, rsi);
aoqi@0 854 // rax,: mdi
aoqi@0 855 // mdo is guaranteed to be non-zero here, we checked for it before the call.
aoqi@0 856 movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset())));
aoqi@0 857 addptr(rbx, in_bytes(MethodData::data_offset()));
aoqi@0 858 addptr(rax, rbx);
aoqi@0 859 bind(set_mdp);
aoqi@0 860 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rax);
aoqi@0 861 pop(rbx);
aoqi@0 862 pop(rax);
aoqi@0 863 }
aoqi@0 864
aoqi@0 865 void InterpreterMacroAssembler::verify_method_data_pointer() {
aoqi@0 866 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 867 #ifdef ASSERT
aoqi@0 868 Label verify_continue;
aoqi@0 869 push(rax);
aoqi@0 870 push(rbx);
aoqi@0 871 push(rcx);
aoqi@0 872 push(rdx);
aoqi@0 873 test_method_data_pointer(rcx, verify_continue); // If mdp is zero, continue
aoqi@0 874 get_method(rbx);
aoqi@0 875
aoqi@0 876 // If the mdp is valid, it will point to a DataLayout header which is
aoqi@0 877 // consistent with the bcp. The converse is highly probable also.
aoqi@0 878 load_unsigned_short(rdx, Address(rcx, in_bytes(DataLayout::bci_offset())));
aoqi@0 879 addptr(rdx, Address(rbx, Method::const_offset()));
aoqi@0 880 lea(rdx, Address(rdx, ConstMethod::codes_offset()));
aoqi@0 881 cmpptr(rdx, rsi);
aoqi@0 882 jcc(Assembler::equal, verify_continue);
aoqi@0 883 // rbx,: method
aoqi@0 884 // rsi: bcp
aoqi@0 885 // rcx: mdp
aoqi@0 886 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), rbx, rsi, rcx);
aoqi@0 887 bind(verify_continue);
aoqi@0 888 pop(rdx);
aoqi@0 889 pop(rcx);
aoqi@0 890 pop(rbx);
aoqi@0 891 pop(rax);
aoqi@0 892 #endif // ASSERT
aoqi@0 893 }
aoqi@0 894
aoqi@0 895
aoqi@0 896 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) {
aoqi@0 897 // %%% this seems to be used to store counter data which is surely 32bits
aoqi@0 898 // however 64bit side stores 64 bits which seems wrong
aoqi@0 899 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 900 Address data(mdp_in, constant);
aoqi@0 901 movptr(data, value);
aoqi@0 902 }
aoqi@0 903
aoqi@0 904
aoqi@0 905 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
aoqi@0 906 int constant,
aoqi@0 907 bool decrement) {
aoqi@0 908 // Counter address
aoqi@0 909 Address data(mdp_in, constant);
aoqi@0 910
aoqi@0 911 increment_mdp_data_at(data, decrement);
aoqi@0 912 }
aoqi@0 913
aoqi@0 914
aoqi@0 915 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
aoqi@0 916 bool decrement) {
aoqi@0 917
aoqi@0 918 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
aoqi@0 919 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 920
aoqi@0 921 // %%% 64bit treats this as 64 bit which seems unlikely
aoqi@0 922 if (decrement) {
aoqi@0 923 // Decrement the register. Set condition codes.
aoqi@0 924 addl(data, -DataLayout::counter_increment);
aoqi@0 925 // If the decrement causes the counter to overflow, stay negative
aoqi@0 926 Label L;
aoqi@0 927 jcc(Assembler::negative, L);
aoqi@0 928 addl(data, DataLayout::counter_increment);
aoqi@0 929 bind(L);
aoqi@0 930 } else {
aoqi@0 931 assert(DataLayout::counter_increment == 1,
aoqi@0 932 "flow-free idiom only works with 1");
aoqi@0 933 // Increment the register. Set carry flag.
aoqi@0 934 addl(data, DataLayout::counter_increment);
aoqi@0 935 // If the increment causes the counter to overflow, pull back by 1.
aoqi@0 936 sbbl(data, 0);
aoqi@0 937 }
aoqi@0 938 }
aoqi@0 939
aoqi@0 940
aoqi@0 941 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
aoqi@0 942 Register reg,
aoqi@0 943 int constant,
aoqi@0 944 bool decrement) {
aoqi@0 945 Address data(mdp_in, reg, Address::times_1, constant);
aoqi@0 946
aoqi@0 947 increment_mdp_data_at(data, decrement);
aoqi@0 948 }
aoqi@0 949
aoqi@0 950
aoqi@0 951 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, int flag_byte_constant) {
aoqi@0 952 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 953 int header_offset = in_bytes(DataLayout::header_offset());
aoqi@0 954 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
aoqi@0 955 // Set the flag
aoqi@0 956 orl(Address(mdp_in, header_offset), header_bits);
aoqi@0 957 }
aoqi@0 958
aoqi@0 959
aoqi@0 960
aoqi@0 961 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
aoqi@0 962 int offset,
aoqi@0 963 Register value,
aoqi@0 964 Register test_value_out,
aoqi@0 965 Label& not_equal_continue) {
aoqi@0 966 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 967 if (test_value_out == noreg) {
aoqi@0 968 cmpptr(value, Address(mdp_in, offset));
aoqi@0 969 } else {
aoqi@0 970 // Put the test value into a register, so caller can use it:
aoqi@0 971 movptr(test_value_out, Address(mdp_in, offset));
aoqi@0 972 cmpptr(test_value_out, value);
aoqi@0 973 }
aoqi@0 974 jcc(Assembler::notEqual, not_equal_continue);
aoqi@0 975 }
aoqi@0 976
aoqi@0 977
aoqi@0 978 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) {
aoqi@0 979 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 980 Address disp_address(mdp_in, offset_of_disp);
aoqi@0 981 addptr(mdp_in,disp_address);
aoqi@0 982 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
aoqi@0 983 }
aoqi@0 984
aoqi@0 985
aoqi@0 986 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp) {
aoqi@0 987 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 988 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
aoqi@0 989 addptr(mdp_in, disp_address);
aoqi@0 990 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
aoqi@0 991 }
aoqi@0 992
aoqi@0 993
aoqi@0 994 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) {
aoqi@0 995 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 996 addptr(mdp_in, constant);
aoqi@0 997 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
aoqi@0 998 }
aoqi@0 999
aoqi@0 1000
aoqi@0 1001 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
aoqi@0 1002 assert(ProfileInterpreter, "must be profiling interpreter");
aoqi@0 1003 push(return_bci); // save/restore across call_VM
aoqi@0 1004 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
aoqi@0 1005 pop(return_bci);
aoqi@0 1006 }
aoqi@0 1007
aoqi@0 1008
aoqi@0 1009 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) {
aoqi@0 1010 if (ProfileInterpreter) {
aoqi@0 1011 Label profile_continue;
aoqi@0 1012
aoqi@0 1013 // If no method data exists, go to profile_continue.
aoqi@0 1014 // Otherwise, assign to mdp
aoqi@0 1015 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1016
aoqi@0 1017 // We are taking a branch. Increment the taken count.
aoqi@0 1018 // We inline increment_mdp_data_at to return bumped_count in a register
aoqi@0 1019 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
aoqi@0 1020 Address data(mdp, in_bytes(JumpData::taken_offset()));
aoqi@0 1021
aoqi@0 1022 // %%% 64bit treats these cells as 64 bit but they seem to be 32 bit
aoqi@0 1023 movl(bumped_count,data);
aoqi@0 1024 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
aoqi@0 1025 addl(bumped_count, DataLayout::counter_increment);
aoqi@0 1026 sbbl(bumped_count, 0);
aoqi@0 1027 movl(data,bumped_count); // Store back out
aoqi@0 1028
aoqi@0 1029 // The method data pointer needs to be updated to reflect the new target.
aoqi@0 1030 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
aoqi@0 1031 bind (profile_continue);
aoqi@0 1032 }
aoqi@0 1033 }
aoqi@0 1034
aoqi@0 1035
aoqi@0 1036 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
aoqi@0 1037 if (ProfileInterpreter) {
aoqi@0 1038 Label profile_continue;
aoqi@0 1039
aoqi@0 1040 // If no method data exists, go to profile_continue.
aoqi@0 1041 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1042
aoqi@0 1043 // We are taking a branch. Increment the not taken count.
aoqi@0 1044 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
aoqi@0 1045
aoqi@0 1046 // The method data pointer needs to be updated to correspond to the next bytecode
aoqi@0 1047 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
aoqi@0 1048 bind (profile_continue);
aoqi@0 1049 }
aoqi@0 1050 }
aoqi@0 1051
aoqi@0 1052 void InterpreterMacroAssembler::profile_call(Register mdp) {
aoqi@0 1053 if (ProfileInterpreter) {
aoqi@0 1054 Label profile_continue;
aoqi@0 1055
aoqi@0 1056 // If no method data exists, go to profile_continue.
aoqi@0 1057 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1058
aoqi@0 1059 // We are making a call. Increment the count.
aoqi@0 1060 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
aoqi@0 1061
aoqi@0 1062 // The method data pointer needs to be updated to reflect the new target.
aoqi@0 1063 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
aoqi@0 1064 bind (profile_continue);
aoqi@0 1065 }
aoqi@0 1066 }
aoqi@0 1067
aoqi@0 1068
aoqi@0 1069 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
aoqi@0 1070 if (ProfileInterpreter) {
aoqi@0 1071 Label profile_continue;
aoqi@0 1072
aoqi@0 1073 // If no method data exists, go to profile_continue.
aoqi@0 1074 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1075
aoqi@0 1076 // We are making a call. Increment the count.
aoqi@0 1077 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
aoqi@0 1078
aoqi@0 1079 // The method data pointer needs to be updated to reflect the new target.
aoqi@0 1080 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
aoqi@0 1081 bind (profile_continue);
aoqi@0 1082 }
aoqi@0 1083 }
aoqi@0 1084
aoqi@0 1085
aoqi@0 1086 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, Register mdp,
aoqi@0 1087 Register reg2,
aoqi@0 1088 bool receiver_can_be_null) {
aoqi@0 1089 if (ProfileInterpreter) {
aoqi@0 1090 Label profile_continue;
aoqi@0 1091
aoqi@0 1092 // If no method data exists, go to profile_continue.
aoqi@0 1093 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1094
aoqi@0 1095 Label skip_receiver_profile;
aoqi@0 1096 if (receiver_can_be_null) {
aoqi@0 1097 Label not_null;
aoqi@0 1098 testptr(receiver, receiver);
aoqi@0 1099 jccb(Assembler::notZero, not_null);
aoqi@0 1100 // We are making a call. Increment the count for null receiver.
aoqi@0 1101 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
aoqi@0 1102 jmp(skip_receiver_profile);
aoqi@0 1103 bind(not_null);
aoqi@0 1104 }
aoqi@0 1105
aoqi@0 1106 // Record the receiver type.
aoqi@0 1107 record_klass_in_profile(receiver, mdp, reg2, true);
aoqi@0 1108 bind(skip_receiver_profile);
aoqi@0 1109
aoqi@0 1110 // The method data pointer needs to be updated to reflect the new target.
aoqi@0 1111 update_mdp_by_constant(mdp,
aoqi@0 1112 in_bytes(VirtualCallData::
aoqi@0 1113 virtual_call_data_size()));
aoqi@0 1114 bind(profile_continue);
aoqi@0 1115 }
aoqi@0 1116 }
aoqi@0 1117
aoqi@0 1118
aoqi@0 1119 void InterpreterMacroAssembler::record_klass_in_profile_helper(
aoqi@0 1120 Register receiver, Register mdp,
aoqi@0 1121 Register reg2, int start_row,
aoqi@0 1122 Label& done, bool is_virtual_call) {
aoqi@0 1123 if (TypeProfileWidth == 0) {
aoqi@0 1124 if (is_virtual_call) {
aoqi@0 1125 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
aoqi@0 1126 }
aoqi@0 1127 return;
aoqi@0 1128 }
aoqi@0 1129
aoqi@0 1130 int last_row = VirtualCallData::row_limit() - 1;
aoqi@0 1131 assert(start_row <= last_row, "must be work left to do");
aoqi@0 1132 // Test this row for both the receiver and for null.
aoqi@0 1133 // Take any of three different outcomes:
aoqi@0 1134 // 1. found receiver => increment count and goto done
aoqi@0 1135 // 2. found null => keep looking for case 1, maybe allocate this cell
aoqi@0 1136 // 3. found something else => keep looking for cases 1 and 2
aoqi@0 1137 // Case 3 is handled by a recursive call.
aoqi@0 1138 for (int row = start_row; row <= last_row; row++) {
aoqi@0 1139 Label next_test;
aoqi@0 1140 bool test_for_null_also = (row == start_row);
aoqi@0 1141
aoqi@0 1142 // See if the receiver is receiver[n].
aoqi@0 1143 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
aoqi@0 1144 test_mdp_data_at(mdp, recvr_offset, receiver,
aoqi@0 1145 (test_for_null_also ? reg2 : noreg),
aoqi@0 1146 next_test);
aoqi@0 1147 // (Reg2 now contains the receiver from the CallData.)
aoqi@0 1148
aoqi@0 1149 // The receiver is receiver[n]. Increment count[n].
aoqi@0 1150 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
aoqi@0 1151 increment_mdp_data_at(mdp, count_offset);
aoqi@0 1152 jmp(done);
aoqi@0 1153 bind(next_test);
aoqi@0 1154
aoqi@0 1155 if (row == start_row) {
aoqi@0 1156 Label found_null;
aoqi@0 1157 // Failed the equality check on receiver[n]... Test for null.
aoqi@0 1158 testptr(reg2, reg2);
aoqi@0 1159 if (start_row == last_row) {
aoqi@0 1160 // The only thing left to do is handle the null case.
aoqi@0 1161 if (is_virtual_call) {
aoqi@0 1162 jccb(Assembler::zero, found_null);
aoqi@0 1163 // Receiver did not match any saved receiver and there is no empty row for it.
aoqi@0 1164 // Increment total counter to indicate polymorphic case.
aoqi@0 1165 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
aoqi@0 1166 jmp(done);
aoqi@0 1167 bind(found_null);
aoqi@0 1168 } else {
aoqi@0 1169 jcc(Assembler::notZero, done);
aoqi@0 1170 }
aoqi@0 1171 break;
aoqi@0 1172 }
aoqi@0 1173 // Since null is rare, make it be the branch-taken case.
aoqi@0 1174 jcc(Assembler::zero, found_null);
aoqi@0 1175
aoqi@0 1176 // Put all the "Case 3" tests here.
aoqi@0 1177 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
aoqi@0 1178
aoqi@0 1179 // Found a null. Keep searching for a matching receiver,
aoqi@0 1180 // but remember that this is an empty (unused) slot.
aoqi@0 1181 bind(found_null);
aoqi@0 1182 }
aoqi@0 1183 }
aoqi@0 1184
aoqi@0 1185 // In the fall-through case, we found no matching receiver, but we
aoqi@0 1186 // observed the receiver[start_row] is NULL.
aoqi@0 1187
aoqi@0 1188 // Fill in the receiver field and increment the count.
aoqi@0 1189 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
aoqi@0 1190 set_mdp_data_at(mdp, recvr_offset, receiver);
aoqi@0 1191 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
aoqi@0 1192 movptr(reg2, (intptr_t)DataLayout::counter_increment);
aoqi@0 1193 set_mdp_data_at(mdp, count_offset, reg2);
aoqi@0 1194 if (start_row > 0) {
aoqi@0 1195 jmp(done);
aoqi@0 1196 }
aoqi@0 1197 }
aoqi@0 1198
aoqi@0 1199 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
aoqi@0 1200 Register mdp, Register reg2,
aoqi@0 1201 bool is_virtual_call) {
aoqi@0 1202 assert(ProfileInterpreter, "must be profiling");
aoqi@0 1203 Label done;
aoqi@0 1204
aoqi@0 1205 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
aoqi@0 1206
aoqi@0 1207 bind (done);
aoqi@0 1208 }
aoqi@0 1209
aoqi@0 1210 void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) {
aoqi@0 1211 if (ProfileInterpreter) {
aoqi@0 1212 Label profile_continue;
aoqi@0 1213 uint row;
aoqi@0 1214
aoqi@0 1215 // If no method data exists, go to profile_continue.
aoqi@0 1216 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1217
aoqi@0 1218 // Update the total ret count.
aoqi@0 1219 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
aoqi@0 1220
aoqi@0 1221 for (row = 0; row < RetData::row_limit(); row++) {
aoqi@0 1222 Label next_test;
aoqi@0 1223
aoqi@0 1224 // See if return_bci is equal to bci[n]:
aoqi@0 1225 test_mdp_data_at(mdp, in_bytes(RetData::bci_offset(row)), return_bci,
aoqi@0 1226 noreg, next_test);
aoqi@0 1227
aoqi@0 1228 // return_bci is equal to bci[n]. Increment the count.
aoqi@0 1229 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
aoqi@0 1230
aoqi@0 1231 // The method data pointer needs to be updated to reflect the new target.
aoqi@0 1232 update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row)));
aoqi@0 1233 jmp(profile_continue);
aoqi@0 1234 bind(next_test);
aoqi@0 1235 }
aoqi@0 1236
aoqi@0 1237 update_mdp_for_ret(return_bci);
aoqi@0 1238
aoqi@0 1239 bind (profile_continue);
aoqi@0 1240 }
aoqi@0 1241 }
aoqi@0 1242
aoqi@0 1243
aoqi@0 1244 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
aoqi@0 1245 if (ProfileInterpreter) {
aoqi@0 1246 Label profile_continue;
aoqi@0 1247
aoqi@0 1248 // If no method data exists, go to profile_continue.
aoqi@0 1249 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1250
aoqi@0 1251 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
aoqi@0 1252
aoqi@0 1253 // The method data pointer needs to be updated.
aoqi@0 1254 int mdp_delta = in_bytes(BitData::bit_data_size());
aoqi@0 1255 if (TypeProfileCasts) {
aoqi@0 1256 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
aoqi@0 1257 }
aoqi@0 1258 update_mdp_by_constant(mdp, mdp_delta);
aoqi@0 1259
aoqi@0 1260 bind (profile_continue);
aoqi@0 1261 }
aoqi@0 1262 }
aoqi@0 1263
aoqi@0 1264
aoqi@0 1265 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
aoqi@0 1266 if (ProfileInterpreter && TypeProfileCasts) {
aoqi@0 1267 Label profile_continue;
aoqi@0 1268
aoqi@0 1269 // If no method data exists, go to profile_continue.
aoqi@0 1270 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1271
aoqi@0 1272 int count_offset = in_bytes(CounterData::count_offset());
aoqi@0 1273 // Back up the address, since we have already bumped the mdp.
aoqi@0 1274 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
aoqi@0 1275
aoqi@0 1276 // *Decrement* the counter. We expect to see zero or small negatives.
aoqi@0 1277 increment_mdp_data_at(mdp, count_offset, true);
aoqi@0 1278
aoqi@0 1279 bind (profile_continue);
aoqi@0 1280 }
aoqi@0 1281 }
aoqi@0 1282
aoqi@0 1283
aoqi@0 1284 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2)
aoqi@0 1285 {
aoqi@0 1286 if (ProfileInterpreter) {
aoqi@0 1287 Label profile_continue;
aoqi@0 1288
aoqi@0 1289 // If no method data exists, go to profile_continue.
aoqi@0 1290 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1291
aoqi@0 1292 // The method data pointer needs to be updated.
aoqi@0 1293 int mdp_delta = in_bytes(BitData::bit_data_size());
aoqi@0 1294 if (TypeProfileCasts) {
aoqi@0 1295 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
aoqi@0 1296
aoqi@0 1297 // Record the object type.
aoqi@0 1298 record_klass_in_profile(klass, mdp, reg2, false);
aoqi@0 1299 assert(reg2 == rdi, "we know how to fix this blown reg");
aoqi@0 1300 restore_locals(); // Restore EDI
aoqi@0 1301 }
aoqi@0 1302 update_mdp_by_constant(mdp, mdp_delta);
aoqi@0 1303
aoqi@0 1304 bind(profile_continue);
aoqi@0 1305 }
aoqi@0 1306 }
aoqi@0 1307
aoqi@0 1308
aoqi@0 1309 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
aoqi@0 1310 if (ProfileInterpreter) {
aoqi@0 1311 Label profile_continue;
aoqi@0 1312
aoqi@0 1313 // If no method data exists, go to profile_continue.
aoqi@0 1314 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1315
aoqi@0 1316 // Update the default case count
aoqi@0 1317 increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));
aoqi@0 1318
aoqi@0 1319 // The method data pointer needs to be updated.
aoqi@0 1320 update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset()));
aoqi@0 1321
aoqi@0 1322 bind (profile_continue);
aoqi@0 1323 }
aoqi@0 1324 }
aoqi@0 1325
aoqi@0 1326
aoqi@0 1327 void InterpreterMacroAssembler::profile_switch_case(Register index, Register mdp, Register reg2) {
aoqi@0 1328 if (ProfileInterpreter) {
aoqi@0 1329 Label profile_continue;
aoqi@0 1330
aoqi@0 1331 // If no method data exists, go to profile_continue.
aoqi@0 1332 test_method_data_pointer(mdp, profile_continue);
aoqi@0 1333
aoqi@0 1334 // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
aoqi@0 1335 movptr(reg2, (intptr_t)in_bytes(MultiBranchData::per_case_size()));
aoqi@0 1336 // index is positive and so should have correct value if this code were
aoqi@0 1337 // used on 64bits
aoqi@0 1338 imulptr(index, reg2);
aoqi@0 1339 addptr(index, in_bytes(MultiBranchData::case_array_offset()));
aoqi@0 1340
aoqi@0 1341 // Update the case count
aoqi@0 1342 increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset()));
aoqi@0 1343
aoqi@0 1344 // The method data pointer needs to be updated.
aoqi@0 1345 update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData::relative_displacement_offset()));
aoqi@0 1346
aoqi@0 1347 bind (profile_continue);
aoqi@0 1348 }
aoqi@0 1349 }
aoqi@0 1350
aoqi@0 1351 #endif // !CC_INTERP
aoqi@0 1352
aoqi@0 1353
aoqi@0 1354
aoqi@0 1355 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
aoqi@0 1356 if (state == atos) MacroAssembler::verify_oop(reg);
aoqi@0 1357 }
aoqi@0 1358
aoqi@0 1359
aoqi@0 1360 #ifndef CC_INTERP
aoqi@0 1361 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
aoqi@0 1362 if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth);
aoqi@0 1363 }
aoqi@0 1364
aoqi@0 1365 #endif /* CC_INTERP */
aoqi@0 1366
aoqi@0 1367
aoqi@0 1368 void InterpreterMacroAssembler::notify_method_entry() {
aoqi@0 1369 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
aoqi@0 1370 // track stack depth. If it is possible to enter interp_only_mode we add
aoqi@0 1371 // the code to check if the event should be sent.
aoqi@0 1372 if (JvmtiExport::can_post_interpreter_events()) {
aoqi@0 1373 Label L;
aoqi@0 1374 get_thread(rcx);
aoqi@0 1375 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
aoqi@0 1376 testl(rcx,rcx);
aoqi@0 1377 jcc(Assembler::zero, L);
aoqi@0 1378 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
aoqi@0 1379 bind(L);
aoqi@0 1380 }
aoqi@0 1381
aoqi@0 1382 {
aoqi@0 1383 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
aoqi@0 1384 get_thread(rcx);
aoqi@0 1385 get_method(rbx);
aoqi@0 1386 call_VM_leaf(
aoqi@0 1387 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), rcx, rbx);
aoqi@0 1388 }
aoqi@0 1389
aoqi@0 1390 // RedefineClasses() tracing support for obsolete method entry
aoqi@0 1391 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
aoqi@0 1392 get_thread(rcx);
aoqi@0 1393 get_method(rbx);
aoqi@0 1394 call_VM_leaf(
aoqi@0 1395 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
aoqi@0 1396 rcx, rbx);
aoqi@0 1397 }
aoqi@0 1398 }
aoqi@0 1399
aoqi@0 1400
aoqi@0 1401 void InterpreterMacroAssembler::notify_method_exit(
aoqi@0 1402 TosState state, NotifyMethodExitMode mode) {
aoqi@0 1403 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
aoqi@0 1404 // track stack depth. If it is possible to enter interp_only_mode we add
aoqi@0 1405 // the code to check if the event should be sent.
aoqi@0 1406 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
aoqi@0 1407 Label L;
aoqi@0 1408 // Note: frame::interpreter_frame_result has a dependency on how the
aoqi@0 1409 // method result is saved across the call to post_method_exit. If this
aoqi@0 1410 // is changed then the interpreter_frame_result implementation will
aoqi@0 1411 // need to be updated too.
aoqi@0 1412
aoqi@0 1413 // For c++ interpreter the result is always stored at a known location in the frame
aoqi@0 1414 // template interpreter will leave it on the top of the stack.
aoqi@0 1415 NOT_CC_INTERP(push(state);)
aoqi@0 1416 get_thread(rcx);
aoqi@0 1417 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
aoqi@0 1418 testl(rcx,rcx);
aoqi@0 1419 jcc(Assembler::zero, L);
aoqi@0 1420 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
aoqi@0 1421 bind(L);
aoqi@0 1422 NOT_CC_INTERP(pop(state);)
aoqi@0 1423 }
aoqi@0 1424
aoqi@0 1425 {
aoqi@0 1426 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
aoqi@0 1427 NOT_CC_INTERP(push(state));
aoqi@0 1428 get_thread(rbx);
aoqi@0 1429 get_method(rcx);
aoqi@0 1430 call_VM_leaf(
aoqi@0 1431 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
aoqi@0 1432 rbx, rcx);
aoqi@0 1433 NOT_CC_INTERP(pop(state));
aoqi@0 1434 }
aoqi@0 1435 }
aoqi@0 1436
aoqi@0 1437 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
aoqi@0 1438 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
aoqi@0 1439 int increment, int mask,
aoqi@0 1440 Register scratch, bool preloaded,
aoqi@0 1441 Condition cond, Label* where) {
aoqi@0 1442 if (!preloaded) {
aoqi@0 1443 movl(scratch, counter_addr);
aoqi@0 1444 }
aoqi@0 1445 incrementl(scratch, increment);
aoqi@0 1446 movl(counter_addr, scratch);
aoqi@0 1447 andl(scratch, mask);
aoqi@0 1448 jcc(cond, *where);
aoqi@0 1449 }

mercurial