1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,2046 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "asm/macroAssembler.hpp" 1.30 +#include "interpreter/bytecodeHistogram.hpp" 1.31 +#include "interpreter/interpreter.hpp" 1.32 +#include "interpreter/interpreterGenerator.hpp" 1.33 +#include "interpreter/interpreterRuntime.hpp" 1.34 +#include "interpreter/templateTable.hpp" 1.35 +#include "oops/arrayOop.hpp" 1.36 +#include "oops/methodData.hpp" 1.37 +#include "oops/method.hpp" 1.38 +#include "oops/oop.inline.hpp" 1.39 +#include "prims/jvmtiExport.hpp" 1.40 +#include "prims/jvmtiThreadState.hpp" 1.41 +#include "runtime/arguments.hpp" 1.42 +#include "runtime/deoptimization.hpp" 1.43 +#include "runtime/frame.inline.hpp" 1.44 +#include "runtime/sharedRuntime.hpp" 1.45 +#include "runtime/stubRoutines.hpp" 1.46 +#include "runtime/synchronizer.hpp" 1.47 +#include "runtime/timer.hpp" 1.48 +#include "runtime/vframeArray.hpp" 1.49 +#include "utilities/debug.hpp" 1.50 +#include "utilities/macros.hpp" 1.51 + 1.52 +#define __ _masm-> 1.53 + 1.54 +#ifndef CC_INTERP 1.55 + 1.56 +const int method_offset = frame::interpreter_frame_method_offset * wordSize; 1.57 +const int bci_offset = frame::interpreter_frame_bcx_offset * wordSize; 1.58 +const int locals_offset = frame::interpreter_frame_locals_offset * wordSize; 1.59 + 1.60 +//----------------------------------------------------------------------------- 1.61 + 1.62 +address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { 1.63 + address entry = __ pc(); 1.64 + 1.65 +#ifdef ASSERT 1.66 + { 1.67 + Label L; 1.68 + __ lea(rax, Address(rbp, 1.69 + frame::interpreter_frame_monitor_block_top_offset * 1.70 + wordSize)); 1.71 + __ cmpptr(rax, rsp); // rax = maximal rsp for current rbp (stack 1.72 + // grows negative) 1.73 + __ jcc(Assembler::aboveEqual, L); // check if frame is complete 1.74 + __ stop ("interpreter frame not set up"); 1.75 + __ bind(L); 1.76 + } 1.77 +#endif // ASSERT 1.78 + // Restore bcp under the assumption that the current frame is still 1.79 + // interpreted 1.80 + __ restore_bcp(); 1.81 + 1.82 + // expression stack must be empty before entering the VM if an 1.83 + // exception happened 1.84 + __ empty_expression_stack(); 1.85 + // throw exception 1.86 + __ call_VM(noreg, 1.87 + CAST_FROM_FN_PTR(address, 1.88 + InterpreterRuntime::throw_StackOverflowError)); 1.89 + return entry; 1.90 +} 1.91 + 1.92 +address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler( 1.93 + const char* name) { 1.94 + address entry = __ pc(); 1.95 + // expression stack must be empty before entering the VM if an 1.96 + // exception happened 1.97 + __ empty_expression_stack(); 1.98 + // setup parameters 1.99 + // ??? convention: expect aberrant index in register ebx 1.100 + __ lea(c_rarg1, ExternalAddress((address)name)); 1.101 + __ call_VM(noreg, 1.102 + CAST_FROM_FN_PTR(address, 1.103 + InterpreterRuntime:: 1.104 + throw_ArrayIndexOutOfBoundsException), 1.105 + c_rarg1, rbx); 1.106 + return entry; 1.107 +} 1.108 + 1.109 +address TemplateInterpreterGenerator::generate_ClassCastException_handler() { 1.110 + address entry = __ pc(); 1.111 + 1.112 + // object is at TOS 1.113 + __ pop(c_rarg1); 1.114 + 1.115 + // expression stack must be empty before entering the VM if an 1.116 + // exception happened 1.117 + __ empty_expression_stack(); 1.118 + 1.119 + __ call_VM(noreg, 1.120 + CAST_FROM_FN_PTR(address, 1.121 + InterpreterRuntime:: 1.122 + throw_ClassCastException), 1.123 + c_rarg1); 1.124 + return entry; 1.125 +} 1.126 + 1.127 +address TemplateInterpreterGenerator::generate_exception_handler_common( 1.128 + const char* name, const char* message, bool pass_oop) { 1.129 + assert(!pass_oop || message == NULL, "either oop or message but not both"); 1.130 + address entry = __ pc(); 1.131 + if (pass_oop) { 1.132 + // object is at TOS 1.133 + __ pop(c_rarg2); 1.134 + } 1.135 + // expression stack must be empty before entering the VM if an 1.136 + // exception happened 1.137 + __ empty_expression_stack(); 1.138 + // setup parameters 1.139 + __ lea(c_rarg1, ExternalAddress((address)name)); 1.140 + if (pass_oop) { 1.141 + __ call_VM(rax, CAST_FROM_FN_PTR(address, 1.142 + InterpreterRuntime:: 1.143 + create_klass_exception), 1.144 + c_rarg1, c_rarg2); 1.145 + } else { 1.146 + // kind of lame ExternalAddress can't take NULL because 1.147 + // external_word_Relocation will assert. 1.148 + if (message != NULL) { 1.149 + __ lea(c_rarg2, ExternalAddress((address)message)); 1.150 + } else { 1.151 + __ movptr(c_rarg2, NULL_WORD); 1.152 + } 1.153 + __ call_VM(rax, 1.154 + CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), 1.155 + c_rarg1, c_rarg2); 1.156 + } 1.157 + // throw exception 1.158 + __ jump(ExternalAddress(Interpreter::throw_exception_entry())); 1.159 + return entry; 1.160 +} 1.161 + 1.162 + 1.163 +address TemplateInterpreterGenerator::generate_continuation_for(TosState state) { 1.164 + address entry = __ pc(); 1.165 + // NULL last_sp until next java call 1.166 + __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 1.167 + __ dispatch_next(state); 1.168 + return entry; 1.169 +} 1.170 + 1.171 + 1.172 +address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) { 1.173 + address entry = __ pc(); 1.174 + 1.175 + // Restore stack bottom in case i2c adjusted stack 1.176 + __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize)); 1.177 + // and NULL it as marker that esp is now tos until next java call 1.178 + __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 1.179 + 1.180 + __ restore_bcp(); 1.181 + __ restore_locals(); 1.182 + 1.183 + if (state == atos) { 1.184 + Register mdp = rbx; 1.185 + Register tmp = rcx; 1.186 + __ profile_return_type(mdp, rax, tmp); 1.187 + } 1.188 + 1.189 + const Register cache = rbx; 1.190 + const Register index = rcx; 1.191 + __ get_cache_and_index_at_bcp(cache, index, 1, index_size); 1.192 + 1.193 + const Register flags = cache; 1.194 + __ movl(flags, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset())); 1.195 + __ andl(flags, ConstantPoolCacheEntry::parameter_size_mask); 1.196 + __ lea(rsp, Address(rsp, flags, Interpreter::stackElementScale())); 1.197 + __ dispatch_next(state, step); 1.198 + 1.199 + return entry; 1.200 +} 1.201 + 1.202 + 1.203 +address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, 1.204 + int step) { 1.205 + address entry = __ pc(); 1.206 + // NULL last_sp until next java call 1.207 + __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 1.208 + __ restore_bcp(); 1.209 + __ restore_locals(); 1.210 + // handle exceptions 1.211 + { 1.212 + Label L; 1.213 + __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD); 1.214 + __ jcc(Assembler::zero, L); 1.215 + __ call_VM(noreg, 1.216 + CAST_FROM_FN_PTR(address, 1.217 + InterpreterRuntime::throw_pending_exception)); 1.218 + __ should_not_reach_here(); 1.219 + __ bind(L); 1.220 + } 1.221 + __ dispatch_next(state, step); 1.222 + return entry; 1.223 +} 1.224 + 1.225 +int AbstractInterpreter::BasicType_as_index(BasicType type) { 1.226 + int i = 0; 1.227 + switch (type) { 1.228 + case T_BOOLEAN: i = 0; break; 1.229 + case T_CHAR : i = 1; break; 1.230 + case T_BYTE : i = 2; break; 1.231 + case T_SHORT : i = 3; break; 1.232 + case T_INT : i = 4; break; 1.233 + case T_LONG : i = 5; break; 1.234 + case T_VOID : i = 6; break; 1.235 + case T_FLOAT : i = 7; break; 1.236 + case T_DOUBLE : i = 8; break; 1.237 + case T_OBJECT : i = 9; break; 1.238 + case T_ARRAY : i = 9; break; 1.239 + default : ShouldNotReachHere(); 1.240 + } 1.241 + assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, 1.242 + "index out of bounds"); 1.243 + return i; 1.244 +} 1.245 + 1.246 + 1.247 +address TemplateInterpreterGenerator::generate_result_handler_for( 1.248 + BasicType type) { 1.249 + address entry = __ pc(); 1.250 + switch (type) { 1.251 + case T_BOOLEAN: __ c2bool(rax); break; 1.252 + case T_CHAR : __ movzwl(rax, rax); break; 1.253 + case T_BYTE : __ sign_extend_byte(rax); break; 1.254 + case T_SHORT : __ sign_extend_short(rax); break; 1.255 + case T_INT : /* nothing to do */ break; 1.256 + case T_LONG : /* nothing to do */ break; 1.257 + case T_VOID : /* nothing to do */ break; 1.258 + case T_FLOAT : /* nothing to do */ break; 1.259 + case T_DOUBLE : /* nothing to do */ break; 1.260 + case T_OBJECT : 1.261 + // retrieve result from frame 1.262 + __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize)); 1.263 + // and verify it 1.264 + __ verify_oop(rax); 1.265 + break; 1.266 + default : ShouldNotReachHere(); 1.267 + } 1.268 + __ ret(0); // return from result handler 1.269 + return entry; 1.270 +} 1.271 + 1.272 +address TemplateInterpreterGenerator::generate_safept_entry_for( 1.273 + TosState state, 1.274 + address runtime_entry) { 1.275 + address entry = __ pc(); 1.276 + __ push(state); 1.277 + __ call_VM(noreg, runtime_entry); 1.278 + __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos)); 1.279 + return entry; 1.280 +} 1.281 + 1.282 + 1.283 + 1.284 +// Helpers for commoning out cases in the various type of method entries. 1.285 +// 1.286 + 1.287 + 1.288 +// increment invocation count & check for overflow 1.289 +// 1.290 +// Note: checking for negative value instead of overflow 1.291 +// so we have a 'sticky' overflow test 1.292 +// 1.293 +// rbx: method 1.294 +// ecx: invocation counter 1.295 +// 1.296 +void InterpreterGenerator::generate_counter_incr( 1.297 + Label* overflow, 1.298 + Label* profile_method, 1.299 + Label* profile_method_continue) { 1.300 + Label done; 1.301 + // Note: In tiered we increment either counters in Method* or in MDO depending if we're profiling or not. 1.302 + if (TieredCompilation) { 1.303 + int increment = InvocationCounter::count_increment; 1.304 + int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift; 1.305 + Label no_mdo; 1.306 + if (ProfileInterpreter) { 1.307 + // Are we profiling? 1.308 + __ movptr(rax, Address(rbx, Method::method_data_offset())); 1.309 + __ testptr(rax, rax); 1.310 + __ jccb(Assembler::zero, no_mdo); 1.311 + // Increment counter in the MDO 1.312 + const Address mdo_invocation_counter(rax, in_bytes(MethodData::invocation_counter_offset()) + 1.313 + in_bytes(InvocationCounter::counter_offset())); 1.314 + __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rcx, false, Assembler::zero, overflow); 1.315 + __ jmp(done); 1.316 + } 1.317 + __ bind(no_mdo); 1.318 + // Increment counter in MethodCounters 1.319 + const Address invocation_counter(rax, 1.320 + MethodCounters::invocation_counter_offset() + 1.321 + InvocationCounter::counter_offset()); 1.322 + __ get_method_counters(rbx, rax, done); 1.323 + __ increment_mask_and_jump(invocation_counter, increment, mask, rcx, 1.324 + false, Assembler::zero, overflow); 1.325 + __ bind(done); 1.326 + } else { 1.327 + const Address backedge_counter(rax, 1.328 + MethodCounters::backedge_counter_offset() + 1.329 + InvocationCounter::counter_offset()); 1.330 + const Address invocation_counter(rax, 1.331 + MethodCounters::invocation_counter_offset() + 1.332 + InvocationCounter::counter_offset()); 1.333 + 1.334 + __ get_method_counters(rbx, rax, done); 1.335 + 1.336 + if (ProfileInterpreter) { 1.337 + __ incrementl(Address(rax, 1.338 + MethodCounters::interpreter_invocation_counter_offset())); 1.339 + } 1.340 + // Update standard invocation counters 1.341 + __ movl(rcx, invocation_counter); 1.342 + __ incrementl(rcx, InvocationCounter::count_increment); 1.343 + __ movl(invocation_counter, rcx); // save invocation count 1.344 + 1.345 + __ movl(rax, backedge_counter); // load backedge counter 1.346 + __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits 1.347 + 1.348 + __ addl(rcx, rax); // add both counters 1.349 + 1.350 + // profile_method is non-null only for interpreted method so 1.351 + // profile_method != NULL == !native_call 1.352 + 1.353 + if (ProfileInterpreter && profile_method != NULL) { 1.354 + // Test to see if we should create a method data oop 1.355 + __ cmp32(rcx, ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit)); 1.356 + __ jcc(Assembler::less, *profile_method_continue); 1.357 + 1.358 + // if no method data exists, go to profile_method 1.359 + __ test_method_data_pointer(rax, *profile_method); 1.360 + } 1.361 + 1.362 + __ cmp32(rcx, ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit)); 1.363 + __ jcc(Assembler::aboveEqual, *overflow); 1.364 + __ bind(done); 1.365 + } 1.366 +} 1.367 + 1.368 +void InterpreterGenerator::generate_counter_overflow(Label* do_continue) { 1.369 + 1.370 + // Asm interpreter on entry 1.371 + // r14 - locals 1.372 + // r13 - bcp 1.373 + // rbx - method 1.374 + // edx - cpool --- DOES NOT APPEAR TO BE TRUE 1.375 + // rbp - interpreter frame 1.376 + 1.377 + // On return (i.e. jump to entry_point) [ back to invocation of interpreter ] 1.378 + // Everything as it was on entry 1.379 + // rdx is not restored. Doesn't appear to really be set. 1.380 + 1.381 + // InterpreterRuntime::frequency_counter_overflow takes two 1.382 + // arguments, the first (thread) is passed by call_VM, the second 1.383 + // indicates if the counter overflow occurs at a backwards branch 1.384 + // (NULL bcp). We pass zero for it. The call returns the address 1.385 + // of the verified entry point for the method or NULL if the 1.386 + // compilation did not complete (either went background or bailed 1.387 + // out). 1.388 + __ movl(c_rarg1, 0); 1.389 + __ call_VM(noreg, 1.390 + CAST_FROM_FN_PTR(address, 1.391 + InterpreterRuntime::frequency_counter_overflow), 1.392 + c_rarg1); 1.393 + 1.394 + __ movptr(rbx, Address(rbp, method_offset)); // restore Method* 1.395 + // Preserve invariant that r13/r14 contain bcp/locals of sender frame 1.396 + // and jump to the interpreted entry. 1.397 + __ jmp(*do_continue, relocInfo::none); 1.398 +} 1.399 + 1.400 +// See if we've got enough room on the stack for locals plus overhead. 1.401 +// The expression stack grows down incrementally, so the normal guard 1.402 +// page mechanism will work for that. 1.403 +// 1.404 +// NOTE: Since the additional locals are also always pushed (wasn't 1.405 +// obvious in generate_method_entry) so the guard should work for them 1.406 +// too. 1.407 +// 1.408 +// Args: 1.409 +// rdx: number of additional locals this frame needs (what we must check) 1.410 +// rbx: Method* 1.411 +// 1.412 +// Kills: 1.413 +// rax 1.414 +void InterpreterGenerator::generate_stack_overflow_check(void) { 1.415 + 1.416 + // monitor entry size: see picture of stack set 1.417 + // (generate_method_entry) and frame_amd64.hpp 1.418 + const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 1.419 + 1.420 + // total overhead size: entry_size + (saved rbp through expr stack 1.421 + // bottom). be sure to change this if you add/subtract anything 1.422 + // to/from the overhead area 1.423 + const int overhead_size = 1.424 + -(frame::interpreter_frame_initial_sp_offset * wordSize) + entry_size; 1.425 + 1.426 + const int page_size = os::vm_page_size(); 1.427 + 1.428 + Label after_frame_check; 1.429 + 1.430 + // see if the frame is greater than one page in size. If so, 1.431 + // then we need to verify there is enough stack space remaining 1.432 + // for the additional locals. 1.433 + __ cmpl(rdx, (page_size - overhead_size) / Interpreter::stackElementSize); 1.434 + __ jcc(Assembler::belowEqual, after_frame_check); 1.435 + 1.436 + // compute rsp as if this were going to be the last frame on 1.437 + // the stack before the red zone 1.438 + 1.439 + const Address stack_base(r15_thread, Thread::stack_base_offset()); 1.440 + const Address stack_size(r15_thread, Thread::stack_size_offset()); 1.441 + 1.442 + // locals + overhead, in bytes 1.443 + __ mov(rax, rdx); 1.444 + __ shlptr(rax, Interpreter::logStackElementSize); // 2 slots per parameter. 1.445 + __ addptr(rax, overhead_size); 1.446 + 1.447 +#ifdef ASSERT 1.448 + Label stack_base_okay, stack_size_okay; 1.449 + // verify that thread stack base is non-zero 1.450 + __ cmpptr(stack_base, (int32_t)NULL_WORD); 1.451 + __ jcc(Assembler::notEqual, stack_base_okay); 1.452 + __ stop("stack base is zero"); 1.453 + __ bind(stack_base_okay); 1.454 + // verify that thread stack size is non-zero 1.455 + __ cmpptr(stack_size, 0); 1.456 + __ jcc(Assembler::notEqual, stack_size_okay); 1.457 + __ stop("stack size is zero"); 1.458 + __ bind(stack_size_okay); 1.459 +#endif 1.460 + 1.461 + // Add stack base to locals and subtract stack size 1.462 + __ addptr(rax, stack_base); 1.463 + __ subptr(rax, stack_size); 1.464 + 1.465 + // Use the maximum number of pages we might bang. 1.466 + const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages : 1.467 + (StackRedPages+StackYellowPages); 1.468 + 1.469 + // add in the red and yellow zone sizes 1.470 + __ addptr(rax, max_pages * page_size); 1.471 + 1.472 + // check against the current stack bottom 1.473 + __ cmpptr(rsp, rax); 1.474 + __ jcc(Assembler::above, after_frame_check); 1.475 + 1.476 + // Restore sender's sp as SP. This is necessary if the sender's 1.477 + // frame is an extended compiled frame (see gen_c2i_adapter()) 1.478 + // and safer anyway in case of JSR292 adaptations. 1.479 + 1.480 + __ pop(rax); // return address must be moved if SP is changed 1.481 + __ mov(rsp, r13); 1.482 + __ push(rax); 1.483 + 1.484 + // Note: the restored frame is not necessarily interpreted. 1.485 + // Use the shared runtime version of the StackOverflowError. 1.486 + assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated"); 1.487 + __ jump(ExternalAddress(StubRoutines::throw_StackOverflowError_entry())); 1.488 + 1.489 + // all done with frame size check 1.490 + __ bind(after_frame_check); 1.491 +} 1.492 + 1.493 +// Allocate monitor and lock method (asm interpreter) 1.494 +// 1.495 +// Args: 1.496 +// rbx: Method* 1.497 +// r14: locals 1.498 +// 1.499 +// Kills: 1.500 +// rax 1.501 +// c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs) 1.502 +// rscratch1, rscratch2 (scratch regs) 1.503 +void InterpreterGenerator::lock_method(void) { 1.504 + // synchronize method 1.505 + const Address access_flags(rbx, Method::access_flags_offset()); 1.506 + const Address monitor_block_top( 1.507 + rbp, 1.508 + frame::interpreter_frame_monitor_block_top_offset * wordSize); 1.509 + const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 1.510 + 1.511 +#ifdef ASSERT 1.512 + { 1.513 + Label L; 1.514 + __ movl(rax, access_flags); 1.515 + __ testl(rax, JVM_ACC_SYNCHRONIZED); 1.516 + __ jcc(Assembler::notZero, L); 1.517 + __ stop("method doesn't need synchronization"); 1.518 + __ bind(L); 1.519 + } 1.520 +#endif // ASSERT 1.521 + 1.522 + // get synchronization object 1.523 + { 1.524 + const int mirror_offset = in_bytes(Klass::java_mirror_offset()); 1.525 + Label done; 1.526 + __ movl(rax, access_flags); 1.527 + __ testl(rax, JVM_ACC_STATIC); 1.528 + // get receiver (assume this is frequent case) 1.529 + __ movptr(rax, Address(r14, Interpreter::local_offset_in_bytes(0))); 1.530 + __ jcc(Assembler::zero, done); 1.531 + __ movptr(rax, Address(rbx, Method::const_offset())); 1.532 + __ movptr(rax, Address(rax, ConstMethod::constants_offset())); 1.533 + __ movptr(rax, Address(rax, 1.534 + ConstantPool::pool_holder_offset_in_bytes())); 1.535 + __ movptr(rax, Address(rax, mirror_offset)); 1.536 + 1.537 +#ifdef ASSERT 1.538 + { 1.539 + Label L; 1.540 + __ testptr(rax, rax); 1.541 + __ jcc(Assembler::notZero, L); 1.542 + __ stop("synchronization object is NULL"); 1.543 + __ bind(L); 1.544 + } 1.545 +#endif // ASSERT 1.546 + 1.547 + __ bind(done); 1.548 + } 1.549 + 1.550 + // add space for monitor & lock 1.551 + __ subptr(rsp, entry_size); // add space for a monitor entry 1.552 + __ movptr(monitor_block_top, rsp); // set new monitor block top 1.553 + // store object 1.554 + __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); 1.555 + __ movptr(c_rarg1, rsp); // object address 1.556 + __ lock_object(c_rarg1); 1.557 +} 1.558 + 1.559 +// Generate a fixed interpreter frame. This is identical setup for 1.560 +// interpreted methods and for native methods hence the shared code. 1.561 +// 1.562 +// Args: 1.563 +// rax: return address 1.564 +// rbx: Method* 1.565 +// r14: pointer to locals 1.566 +// r13: sender sp 1.567 +// rdx: cp cache 1.568 +void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { 1.569 + // initialize fixed part of activation frame 1.570 + __ push(rax); // save return address 1.571 + __ enter(); // save old & set new rbp 1.572 + __ push(r13); // set sender sp 1.573 + __ push((int)NULL_WORD); // leave last_sp as null 1.574 + __ movptr(r13, Address(rbx, Method::const_offset())); // get ConstMethod* 1.575 + __ lea(r13, Address(r13, ConstMethod::codes_offset())); // get codebase 1.576 + __ push(rbx); // save Method* 1.577 + if (ProfileInterpreter) { 1.578 + Label method_data_continue; 1.579 + __ movptr(rdx, Address(rbx, in_bytes(Method::method_data_offset()))); 1.580 + __ testptr(rdx, rdx); 1.581 + __ jcc(Assembler::zero, method_data_continue); 1.582 + __ addptr(rdx, in_bytes(MethodData::data_offset())); 1.583 + __ bind(method_data_continue); 1.584 + __ push(rdx); // set the mdp (method data pointer) 1.585 + } else { 1.586 + __ push(0); 1.587 + } 1.588 + 1.589 + __ movptr(rdx, Address(rbx, Method::const_offset())); 1.590 + __ movptr(rdx, Address(rdx, ConstMethod::constants_offset())); 1.591 + __ movptr(rdx, Address(rdx, ConstantPool::cache_offset_in_bytes())); 1.592 + __ push(rdx); // set constant pool cache 1.593 + __ push(r14); // set locals pointer 1.594 + if (native_call) { 1.595 + __ push(0); // no bcp 1.596 + } else { 1.597 + __ push(r13); // set bcp 1.598 + } 1.599 + __ push(0); // reserve word for pointer to expression stack bottom 1.600 + __ movptr(Address(rsp, 0), rsp); // set expression stack bottom 1.601 +} 1.602 + 1.603 +// End of helpers 1.604 + 1.605 +// Various method entries 1.606 +//------------------------------------------------------------------------------------------------------------------------ 1.607 +// 1.608 +// 1.609 + 1.610 +// Call an accessor method (assuming it is resolved, otherwise drop 1.611 +// into vanilla (slow path) entry 1.612 +address InterpreterGenerator::generate_accessor_entry(void) { 1.613 + // rbx: Method* 1.614 + 1.615 + // r13: senderSP must preserver for slow path, set SP to it on fast path 1.616 + 1.617 + address entry_point = __ pc(); 1.618 + Label xreturn_path; 1.619 + 1.620 + // do fastpath for resolved accessor methods 1.621 + if (UseFastAccessorMethods) { 1.622 + // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites 1.623 + // thereof; parameter size = 1 1.624 + // Note: We can only use this code if the getfield has been resolved 1.625 + // and if we don't have a null-pointer exception => check for 1.626 + // these conditions first and use slow path if necessary. 1.627 + Label slow_path; 1.628 + // If we need a safepoint check, generate full interpreter entry. 1.629 + __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), 1.630 + SafepointSynchronize::_not_synchronized); 1.631 + 1.632 + __ jcc(Assembler::notEqual, slow_path); 1.633 + // rbx: method 1.634 + __ movptr(rax, Address(rsp, wordSize)); 1.635 + 1.636 + // check if local 0 != NULL and read field 1.637 + __ testptr(rax, rax); 1.638 + __ jcc(Assembler::zero, slow_path); 1.639 + 1.640 + // read first instruction word and extract bytecode @ 1 and index @ 2 1.641 + __ movptr(rdx, Address(rbx, Method::const_offset())); 1.642 + __ movptr(rdi, Address(rdx, ConstMethod::constants_offset())); 1.643 + __ movl(rdx, Address(rdx, ConstMethod::codes_offset())); 1.644 + // Shift codes right to get the index on the right. 1.645 + // The bytecode fetched looks like <index><0xb4><0x2a> 1.646 + __ shrl(rdx, 2 * BitsPerByte); 1.647 + __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size()))); 1.648 + __ movptr(rdi, Address(rdi, ConstantPool::cache_offset_in_bytes())); 1.649 + 1.650 + // rax: local 0 1.651 + // rbx: method 1.652 + // rdx: constant pool cache index 1.653 + // rdi: constant pool cache 1.654 + 1.655 + // check if getfield has been resolved and read constant pool cache entry 1.656 + // check the validity of the cache entry by testing whether _indices field 1.657 + // contains Bytecode::_getfield in b1 byte. 1.658 + assert(in_words(ConstantPoolCacheEntry::size()) == 4, 1.659 + "adjust shift below"); 1.660 + __ movl(rcx, 1.661 + Address(rdi, 1.662 + rdx, 1.663 + Address::times_8, 1.664 + ConstantPoolCache::base_offset() + 1.665 + ConstantPoolCacheEntry::indices_offset())); 1.666 + __ shrl(rcx, 2 * BitsPerByte); 1.667 + __ andl(rcx, 0xFF); 1.668 + __ cmpl(rcx, Bytecodes::_getfield); 1.669 + __ jcc(Assembler::notEqual, slow_path); 1.670 + 1.671 + // Note: constant pool entry is not valid before bytecode is resolved 1.672 + __ movptr(rcx, 1.673 + Address(rdi, 1.674 + rdx, 1.675 + Address::times_8, 1.676 + ConstantPoolCache::base_offset() + 1.677 + ConstantPoolCacheEntry::f2_offset())); 1.678 + // edx: flags 1.679 + __ movl(rdx, 1.680 + Address(rdi, 1.681 + rdx, 1.682 + Address::times_8, 1.683 + ConstantPoolCache::base_offset() + 1.684 + ConstantPoolCacheEntry::flags_offset())); 1.685 + 1.686 + Label notObj, notInt, notByte, notShort; 1.687 + const Address field_address(rax, rcx, Address::times_1); 1.688 + 1.689 + // Need to differentiate between igetfield, agetfield, bgetfield etc. 1.690 + // because they are different sizes. 1.691 + // Use the type from the constant pool cache 1.692 + __ shrl(rdx, ConstantPoolCacheEntry::tos_state_shift); 1.693 + // Make sure we don't need to mask edx after the above shift 1.694 + ConstantPoolCacheEntry::verify_tos_state_shift(); 1.695 + 1.696 + __ cmpl(rdx, atos); 1.697 + __ jcc(Assembler::notEqual, notObj); 1.698 + // atos 1.699 + __ load_heap_oop(rax, field_address); 1.700 + __ jmp(xreturn_path); 1.701 + 1.702 + __ bind(notObj); 1.703 + __ cmpl(rdx, itos); 1.704 + __ jcc(Assembler::notEqual, notInt); 1.705 + // itos 1.706 + __ movl(rax, field_address); 1.707 + __ jmp(xreturn_path); 1.708 + 1.709 + __ bind(notInt); 1.710 + __ cmpl(rdx, btos); 1.711 + __ jcc(Assembler::notEqual, notByte); 1.712 + // btos 1.713 + __ load_signed_byte(rax, field_address); 1.714 + __ jmp(xreturn_path); 1.715 + 1.716 + __ bind(notByte); 1.717 + __ cmpl(rdx, stos); 1.718 + __ jcc(Assembler::notEqual, notShort); 1.719 + // stos 1.720 + __ load_signed_short(rax, field_address); 1.721 + __ jmp(xreturn_path); 1.722 + 1.723 + __ bind(notShort); 1.724 +#ifdef ASSERT 1.725 + Label okay; 1.726 + __ cmpl(rdx, ctos); 1.727 + __ jcc(Assembler::equal, okay); 1.728 + __ stop("what type is this?"); 1.729 + __ bind(okay); 1.730 +#endif 1.731 + // ctos 1.732 + __ load_unsigned_short(rax, field_address); 1.733 + 1.734 + __ bind(xreturn_path); 1.735 + 1.736 + // _ireturn/_areturn 1.737 + __ pop(rdi); 1.738 + __ mov(rsp, r13); 1.739 + __ jmp(rdi); 1.740 + __ ret(0); 1.741 + 1.742 + // generate a vanilla interpreter entry as the slow path 1.743 + __ bind(slow_path); 1.744 + (void) generate_normal_entry(false); 1.745 + } else { 1.746 + (void) generate_normal_entry(false); 1.747 + } 1.748 + 1.749 + return entry_point; 1.750 +} 1.751 + 1.752 +// Method entry for java.lang.ref.Reference.get. 1.753 +address InterpreterGenerator::generate_Reference_get_entry(void) { 1.754 +#if INCLUDE_ALL_GCS 1.755 + // Code: _aload_0, _getfield, _areturn 1.756 + // parameter size = 1 1.757 + // 1.758 + // The code that gets generated by this routine is split into 2 parts: 1.759 + // 1. The "intrinsified" code for G1 (or any SATB based GC), 1.760 + // 2. The slow path - which is an expansion of the regular method entry. 1.761 + // 1.762 + // Notes:- 1.763 + // * In the G1 code we do not check whether we need to block for 1.764 + // a safepoint. If G1 is enabled then we must execute the specialized 1.765 + // code for Reference.get (except when the Reference object is null) 1.766 + // so that we can log the value in the referent field with an SATB 1.767 + // update buffer. 1.768 + // If the code for the getfield template is modified so that the 1.769 + // G1 pre-barrier code is executed when the current method is 1.770 + // Reference.get() then going through the normal method entry 1.771 + // will be fine. 1.772 + // * The G1 code can, however, check the receiver object (the instance 1.773 + // of java.lang.Reference) and jump to the slow path if null. If the 1.774 + // Reference object is null then we obviously cannot fetch the referent 1.775 + // and so we don't need to call the G1 pre-barrier. Thus we can use the 1.776 + // regular method entry code to generate the NPE. 1.777 + // 1.778 + // This code is based on generate_accessor_enty. 1.779 + // 1.780 + // rbx: Method* 1.781 + 1.782 + // r13: senderSP must preserve for slow path, set SP to it on fast path 1.783 + 1.784 + address entry = __ pc(); 1.785 + 1.786 + const int referent_offset = java_lang_ref_Reference::referent_offset; 1.787 + guarantee(referent_offset > 0, "referent offset not initialized"); 1.788 + 1.789 + if (UseG1GC) { 1.790 + Label slow_path; 1.791 + // rbx: method 1.792 + 1.793 + // Check if local 0 != NULL 1.794 + // If the receiver is null then it is OK to jump to the slow path. 1.795 + __ movptr(rax, Address(rsp, wordSize)); 1.796 + 1.797 + __ testptr(rax, rax); 1.798 + __ jcc(Assembler::zero, slow_path); 1.799 + 1.800 + // rax: local 0 1.801 + // rbx: method (but can be used as scratch now) 1.802 + // rdx: scratch 1.803 + // rdi: scratch 1.804 + 1.805 + // Generate the G1 pre-barrier code to log the value of 1.806 + // the referent field in an SATB buffer. 1.807 + 1.808 + // Load the value of the referent field. 1.809 + const Address field_address(rax, referent_offset); 1.810 + __ load_heap_oop(rax, field_address); 1.811 + 1.812 + // Generate the G1 pre-barrier code to log the value of 1.813 + // the referent field in an SATB buffer. 1.814 + __ g1_write_barrier_pre(noreg /* obj */, 1.815 + rax /* pre_val */, 1.816 + r15_thread /* thread */, 1.817 + rbx /* tmp */, 1.818 + true /* tosca_live */, 1.819 + true /* expand_call */); 1.820 + 1.821 + // _areturn 1.822 + __ pop(rdi); // get return address 1.823 + __ mov(rsp, r13); // set sp to sender sp 1.824 + __ jmp(rdi); 1.825 + __ ret(0); 1.826 + 1.827 + // generate a vanilla interpreter entry as the slow path 1.828 + __ bind(slow_path); 1.829 + (void) generate_normal_entry(false); 1.830 + 1.831 + return entry; 1.832 + } 1.833 +#endif // INCLUDE_ALL_GCS 1.834 + 1.835 + // If G1 is not enabled then attempt to go through the accessor entry point 1.836 + // Reference.get is an accessor 1.837 + return generate_accessor_entry(); 1.838 +} 1.839 + 1.840 +/** 1.841 + * Method entry for static native methods: 1.842 + * int java.util.zip.CRC32.update(int crc, int b) 1.843 + */ 1.844 +address InterpreterGenerator::generate_CRC32_update_entry() { 1.845 + if (UseCRC32Intrinsics) { 1.846 + address entry = __ pc(); 1.847 + 1.848 + // rbx,: Method* 1.849 + // r13: senderSP must preserved for slow path, set SP to it on fast path 1.850 + // c_rarg0: scratch (rdi on non-Win64, rcx on Win64) 1.851 + // c_rarg1: scratch (rsi on non-Win64, rdx on Win64) 1.852 + 1.853 + Label slow_path; 1.854 + // If we need a safepoint check, generate full interpreter entry. 1.855 + ExternalAddress state(SafepointSynchronize::address_of_state()); 1.856 + __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), 1.857 + SafepointSynchronize::_not_synchronized); 1.858 + __ jcc(Assembler::notEqual, slow_path); 1.859 + 1.860 + // We don't generate local frame and don't align stack because 1.861 + // we call stub code and there is no safepoint on this path. 1.862 + 1.863 + // Load parameters 1.864 + const Register crc = rax; // crc 1.865 + const Register val = c_rarg0; // source java byte value 1.866 + const Register tbl = c_rarg1; // scratch 1.867 + 1.868 + // Arguments are reversed on java expression stack 1.869 + __ movl(val, Address(rsp, wordSize)); // byte value 1.870 + __ movl(crc, Address(rsp, 2*wordSize)); // Initial CRC 1.871 + 1.872 + __ lea(tbl, ExternalAddress(StubRoutines::crc_table_addr())); 1.873 + __ notl(crc); // ~crc 1.874 + __ update_byte_crc32(crc, val, tbl); 1.875 + __ notl(crc); // ~crc 1.876 + // result in rax 1.877 + 1.878 + // _areturn 1.879 + __ pop(rdi); // get return address 1.880 + __ mov(rsp, r13); // set sp to sender sp 1.881 + __ jmp(rdi); 1.882 + 1.883 + // generate a vanilla native entry as the slow path 1.884 + __ bind(slow_path); 1.885 + 1.886 + (void) generate_native_entry(false); 1.887 + 1.888 + return entry; 1.889 + } 1.890 + return generate_native_entry(false); 1.891 +} 1.892 + 1.893 +/** 1.894 + * Method entry for static native methods: 1.895 + * int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len) 1.896 + * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 1.897 + */ 1.898 +address InterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { 1.899 + if (UseCRC32Intrinsics) { 1.900 + address entry = __ pc(); 1.901 + 1.902 + // rbx,: Method* 1.903 + // r13: senderSP must preserved for slow path, set SP to it on fast path 1.904 + 1.905 + Label slow_path; 1.906 + // If we need a safepoint check, generate full interpreter entry. 1.907 + ExternalAddress state(SafepointSynchronize::address_of_state()); 1.908 + __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), 1.909 + SafepointSynchronize::_not_synchronized); 1.910 + __ jcc(Assembler::notEqual, slow_path); 1.911 + 1.912 + // We don't generate local frame and don't align stack because 1.913 + // we call stub code and there is no safepoint on this path. 1.914 + 1.915 + // Load parameters 1.916 + const Register crc = c_rarg0; // crc 1.917 + const Register buf = c_rarg1; // source java byte array address 1.918 + const Register len = c_rarg2; // length 1.919 + const Register off = len; // offset (never overlaps with 'len') 1.920 + 1.921 + // Arguments are reversed on java expression stack 1.922 + // Calculate address of start element 1.923 + if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { 1.924 + __ movptr(buf, Address(rsp, 3*wordSize)); // long buf 1.925 + __ movl2ptr(off, Address(rsp, 2*wordSize)); // offset 1.926 + __ addq(buf, off); // + offset 1.927 + __ movl(crc, Address(rsp, 5*wordSize)); // Initial CRC 1.928 + } else { 1.929 + __ movptr(buf, Address(rsp, 3*wordSize)); // byte[] array 1.930 + __ addptr(buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size 1.931 + __ movl2ptr(off, Address(rsp, 2*wordSize)); // offset 1.932 + __ addq(buf, off); // + offset 1.933 + __ movl(crc, Address(rsp, 4*wordSize)); // Initial CRC 1.934 + } 1.935 + // Can now load 'len' since we're finished with 'off' 1.936 + __ movl(len, Address(rsp, wordSize)); // Length 1.937 + 1.938 + __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32()), crc, buf, len); 1.939 + // result in rax 1.940 + 1.941 + // _areturn 1.942 + __ pop(rdi); // get return address 1.943 + __ mov(rsp, r13); // set sp to sender sp 1.944 + __ jmp(rdi); 1.945 + 1.946 + // generate a vanilla native entry as the slow path 1.947 + __ bind(slow_path); 1.948 + 1.949 + (void) generate_native_entry(false); 1.950 + 1.951 + return entry; 1.952 + } 1.953 + return generate_native_entry(false); 1.954 +} 1.955 + 1.956 +// Interpreter stub for calling a native method. (asm interpreter) 1.957 +// This sets up a somewhat different looking stack for calling the 1.958 +// native method than the typical interpreter frame setup. 1.959 +address InterpreterGenerator::generate_native_entry(bool synchronized) { 1.960 + // determine code generation flags 1.961 + bool inc_counter = UseCompiler || CountCompiledCalls; 1.962 + 1.963 + // rbx: Method* 1.964 + // r13: sender sp 1.965 + 1.966 + address entry_point = __ pc(); 1.967 + 1.968 + const Address constMethod (rbx, Method::const_offset()); 1.969 + const Address access_flags (rbx, Method::access_flags_offset()); 1.970 + const Address size_of_parameters(rcx, ConstMethod:: 1.971 + size_of_parameters_offset()); 1.972 + 1.973 + 1.974 + // get parameter size (always needed) 1.975 + __ movptr(rcx, constMethod); 1.976 + __ load_unsigned_short(rcx, size_of_parameters); 1.977 + 1.978 + // native calls don't need the stack size check since they have no 1.979 + // expression stack and the arguments are already on the stack and 1.980 + // we only add a handful of words to the stack 1.981 + 1.982 + // rbx: Method* 1.983 + // rcx: size of parameters 1.984 + // r13: sender sp 1.985 + __ pop(rax); // get return address 1.986 + 1.987 + // for natives the size of locals is zero 1.988 + 1.989 + // compute beginning of parameters (r14) 1.990 + __ lea(r14, Address(rsp, rcx, Address::times_8, -wordSize)); 1.991 + 1.992 + // add 2 zero-initialized slots for native calls 1.993 + // initialize result_handler slot 1.994 + __ push((int) NULL_WORD); 1.995 + // slot for oop temp 1.996 + // (static native method holder mirror/jni oop result) 1.997 + __ push((int) NULL_WORD); 1.998 + 1.999 + // initialize fixed part of activation frame 1.1000 + generate_fixed_frame(true); 1.1001 + 1.1002 + // make sure method is native & not abstract 1.1003 +#ifdef ASSERT 1.1004 + __ movl(rax, access_flags); 1.1005 + { 1.1006 + Label L; 1.1007 + __ testl(rax, JVM_ACC_NATIVE); 1.1008 + __ jcc(Assembler::notZero, L); 1.1009 + __ stop("tried to execute non-native method as native"); 1.1010 + __ bind(L); 1.1011 + } 1.1012 + { 1.1013 + Label L; 1.1014 + __ testl(rax, JVM_ACC_ABSTRACT); 1.1015 + __ jcc(Assembler::zero, L); 1.1016 + __ stop("tried to execute abstract method in interpreter"); 1.1017 + __ bind(L); 1.1018 + } 1.1019 +#endif 1.1020 + 1.1021 + // Since at this point in the method invocation the exception handler 1.1022 + // would try to exit the monitor of synchronized methods which hasn't 1.1023 + // been entered yet, we set the thread local variable 1.1024 + // _do_not_unlock_if_synchronized to true. The remove_activation will 1.1025 + // check this flag. 1.1026 + 1.1027 + const Address do_not_unlock_if_synchronized(r15_thread, 1.1028 + in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 1.1029 + __ movbool(do_not_unlock_if_synchronized, true); 1.1030 + 1.1031 + // increment invocation count & check for overflow 1.1032 + Label invocation_counter_overflow; 1.1033 + if (inc_counter) { 1.1034 + generate_counter_incr(&invocation_counter_overflow, NULL, NULL); 1.1035 + } 1.1036 + 1.1037 + Label continue_after_compile; 1.1038 + __ bind(continue_after_compile); 1.1039 + 1.1040 + bang_stack_shadow_pages(true); 1.1041 + 1.1042 + // reset the _do_not_unlock_if_synchronized flag 1.1043 + __ movbool(do_not_unlock_if_synchronized, false); 1.1044 + 1.1045 + // check for synchronized methods 1.1046 + // Must happen AFTER invocation_counter check and stack overflow check, 1.1047 + // so method is not locked if overflows. 1.1048 + if (synchronized) { 1.1049 + lock_method(); 1.1050 + } else { 1.1051 + // no synchronization necessary 1.1052 +#ifdef ASSERT 1.1053 + { 1.1054 + Label L; 1.1055 + __ movl(rax, access_flags); 1.1056 + __ testl(rax, JVM_ACC_SYNCHRONIZED); 1.1057 + __ jcc(Assembler::zero, L); 1.1058 + __ stop("method needs synchronization"); 1.1059 + __ bind(L); 1.1060 + } 1.1061 +#endif 1.1062 + } 1.1063 + 1.1064 + // start execution 1.1065 +#ifdef ASSERT 1.1066 + { 1.1067 + Label L; 1.1068 + const Address monitor_block_top(rbp, 1.1069 + frame::interpreter_frame_monitor_block_top_offset * wordSize); 1.1070 + __ movptr(rax, monitor_block_top); 1.1071 + __ cmpptr(rax, rsp); 1.1072 + __ jcc(Assembler::equal, L); 1.1073 + __ stop("broken stack frame setup in interpreter"); 1.1074 + __ bind(L); 1.1075 + } 1.1076 +#endif 1.1077 + 1.1078 + // jvmti support 1.1079 + __ notify_method_entry(); 1.1080 + 1.1081 + // work registers 1.1082 + const Register method = rbx; 1.1083 + const Register t = r11; 1.1084 + 1.1085 + // allocate space for parameters 1.1086 + __ get_method(method); 1.1087 + __ movptr(t, Address(method, Method::const_offset())); 1.1088 + __ load_unsigned_short(t, Address(t, ConstMethod::size_of_parameters_offset())); 1.1089 + __ shll(t, Interpreter::logStackElementSize); 1.1090 + 1.1091 + __ subptr(rsp, t); 1.1092 + __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows 1.1093 + __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI) 1.1094 + 1.1095 + // get signature handler 1.1096 + { 1.1097 + Label L; 1.1098 + __ movptr(t, Address(method, Method::signature_handler_offset())); 1.1099 + __ testptr(t, t); 1.1100 + __ jcc(Assembler::notZero, L); 1.1101 + __ call_VM(noreg, 1.1102 + CAST_FROM_FN_PTR(address, 1.1103 + InterpreterRuntime::prepare_native_call), 1.1104 + method); 1.1105 + __ get_method(method); 1.1106 + __ movptr(t, Address(method, Method::signature_handler_offset())); 1.1107 + __ bind(L); 1.1108 + } 1.1109 + 1.1110 + // call signature handler 1.1111 + assert(InterpreterRuntime::SignatureHandlerGenerator::from() == r14, 1.1112 + "adjust this code"); 1.1113 + assert(InterpreterRuntime::SignatureHandlerGenerator::to() == rsp, 1.1114 + "adjust this code"); 1.1115 + assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == rscratch1, 1.1116 + "adjust this code"); 1.1117 + 1.1118 + // The generated handlers do not touch RBX (the method oop). 1.1119 + // However, large signatures cannot be cached and are generated 1.1120 + // each time here. The slow-path generator can do a GC on return, 1.1121 + // so we must reload it after the call. 1.1122 + __ call(t); 1.1123 + __ get_method(method); // slow path can do a GC, reload RBX 1.1124 + 1.1125 + 1.1126 + // result handler is in rax 1.1127 + // set result handler 1.1128 + __ movptr(Address(rbp, 1.1129 + (frame::interpreter_frame_result_handler_offset) * wordSize), 1.1130 + rax); 1.1131 + 1.1132 + // pass mirror handle if static call 1.1133 + { 1.1134 + Label L; 1.1135 + const int mirror_offset = in_bytes(Klass::java_mirror_offset()); 1.1136 + __ movl(t, Address(method, Method::access_flags_offset())); 1.1137 + __ testl(t, JVM_ACC_STATIC); 1.1138 + __ jcc(Assembler::zero, L); 1.1139 + // get mirror 1.1140 + __ movptr(t, Address(method, Method::const_offset())); 1.1141 + __ movptr(t, Address(t, ConstMethod::constants_offset())); 1.1142 + __ movptr(t, Address(t, ConstantPool::pool_holder_offset_in_bytes())); 1.1143 + __ movptr(t, Address(t, mirror_offset)); 1.1144 + // copy mirror into activation frame 1.1145 + __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize), 1.1146 + t); 1.1147 + // pass handle to mirror 1.1148 + __ lea(c_rarg1, 1.1149 + Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize)); 1.1150 + __ bind(L); 1.1151 + } 1.1152 + 1.1153 + // get native function entry point 1.1154 + { 1.1155 + Label L; 1.1156 + __ movptr(rax, Address(method, Method::native_function_offset())); 1.1157 + ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); 1.1158 + __ movptr(rscratch2, unsatisfied.addr()); 1.1159 + __ cmpptr(rax, rscratch2); 1.1160 + __ jcc(Assembler::notEqual, L); 1.1161 + __ call_VM(noreg, 1.1162 + CAST_FROM_FN_PTR(address, 1.1163 + InterpreterRuntime::prepare_native_call), 1.1164 + method); 1.1165 + __ get_method(method); 1.1166 + __ movptr(rax, Address(method, Method::native_function_offset())); 1.1167 + __ bind(L); 1.1168 + } 1.1169 + 1.1170 + // pass JNIEnv 1.1171 + __ lea(c_rarg0, Address(r15_thread, JavaThread::jni_environment_offset())); 1.1172 + 1.1173 + // It is enough that the pc() points into the right code 1.1174 + // segment. It does not have to be the correct return pc. 1.1175 + __ set_last_Java_frame(rsp, rbp, (address) __ pc()); 1.1176 + 1.1177 + // change thread state 1.1178 +#ifdef ASSERT 1.1179 + { 1.1180 + Label L; 1.1181 + __ movl(t, Address(r15_thread, JavaThread::thread_state_offset())); 1.1182 + __ cmpl(t, _thread_in_Java); 1.1183 + __ jcc(Assembler::equal, L); 1.1184 + __ stop("Wrong thread state in native stub"); 1.1185 + __ bind(L); 1.1186 + } 1.1187 +#endif 1.1188 + 1.1189 + // Change state to native 1.1190 + 1.1191 + __ movl(Address(r15_thread, JavaThread::thread_state_offset()), 1.1192 + _thread_in_native); 1.1193 + 1.1194 + // Call the native method. 1.1195 + __ call(rax); 1.1196 + // result potentially in rax or xmm0 1.1197 + 1.1198 + // Verify or restore cpu control state after JNI call 1.1199 + __ restore_cpu_control_state_after_jni(); 1.1200 + 1.1201 + // NOTE: The order of these pushes is known to frame::interpreter_frame_result 1.1202 + // in order to extract the result of a method call. If the order of these 1.1203 + // pushes change or anything else is added to the stack then the code in 1.1204 + // interpreter_frame_result must also change. 1.1205 + 1.1206 + __ push(dtos); 1.1207 + __ push(ltos); 1.1208 + 1.1209 + // change thread state 1.1210 + __ movl(Address(r15_thread, JavaThread::thread_state_offset()), 1.1211 + _thread_in_native_trans); 1.1212 + 1.1213 + if (os::is_MP()) { 1.1214 + if (UseMembar) { 1.1215 + // Force this write out before the read below 1.1216 + __ membar(Assembler::Membar_mask_bits( 1.1217 + Assembler::LoadLoad | Assembler::LoadStore | 1.1218 + Assembler::StoreLoad | Assembler::StoreStore)); 1.1219 + } else { 1.1220 + // Write serialization page so VM thread can do a pseudo remote membar. 1.1221 + // We use the current thread pointer to calculate a thread specific 1.1222 + // offset to write to within the page. This minimizes bus traffic 1.1223 + // due to cache line collision. 1.1224 + __ serialize_memory(r15_thread, rscratch2); 1.1225 + } 1.1226 + } 1.1227 + 1.1228 + // check for safepoint operation in progress and/or pending suspend requests 1.1229 + { 1.1230 + Label Continue; 1.1231 + __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), 1.1232 + SafepointSynchronize::_not_synchronized); 1.1233 + 1.1234 + Label L; 1.1235 + __ jcc(Assembler::notEqual, L); 1.1236 + __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0); 1.1237 + __ jcc(Assembler::equal, Continue); 1.1238 + __ bind(L); 1.1239 + 1.1240 + // Don't use call_VM as it will see a possible pending exception 1.1241 + // and forward it and never return here preventing us from 1.1242 + // clearing _last_native_pc down below. Also can't use 1.1243 + // call_VM_leaf either as it will check to see if r13 & r14 are 1.1244 + // preserved and correspond to the bcp/locals pointers. So we do a 1.1245 + // runtime call by hand. 1.1246 + // 1.1247 + __ mov(c_rarg0, r15_thread); 1.1248 + __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM) 1.1249 + __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows 1.1250 + __ andptr(rsp, -16); // align stack as required by ABI 1.1251 + __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans))); 1.1252 + __ mov(rsp, r12); // restore sp 1.1253 + __ reinit_heapbase(); 1.1254 + __ bind(Continue); 1.1255 + } 1.1256 + 1.1257 + // change thread state 1.1258 + __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_Java); 1.1259 + 1.1260 + // reset_last_Java_frame 1.1261 + __ reset_last_Java_frame(true, true); 1.1262 + 1.1263 + // reset handle block 1.1264 + __ movptr(t, Address(r15_thread, JavaThread::active_handles_offset())); 1.1265 + __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD); 1.1266 + 1.1267 + // If result is an oop unbox and store it in frame where gc will see it 1.1268 + // and result handler will pick it up 1.1269 + 1.1270 + { 1.1271 + Label no_oop, store_result; 1.1272 + __ lea(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT))); 1.1273 + __ cmpptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize)); 1.1274 + __ jcc(Assembler::notEqual, no_oop); 1.1275 + // retrieve result 1.1276 + __ pop(ltos); 1.1277 + __ testptr(rax, rax); 1.1278 + __ jcc(Assembler::zero, store_result); 1.1279 + __ movptr(rax, Address(rax, 0)); 1.1280 + __ bind(store_result); 1.1281 + __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize), rax); 1.1282 + // keep stack depth as expected by pushing oop which will eventually be discarde 1.1283 + __ push(ltos); 1.1284 + __ bind(no_oop); 1.1285 + } 1.1286 + 1.1287 + 1.1288 + { 1.1289 + Label no_reguard; 1.1290 + __ cmpl(Address(r15_thread, JavaThread::stack_guard_state_offset()), 1.1291 + JavaThread::stack_guard_yellow_disabled); 1.1292 + __ jcc(Assembler::notEqual, no_reguard); 1.1293 + 1.1294 + __ pusha(); // XXX only save smashed registers 1.1295 + __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM) 1.1296 + __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows 1.1297 + __ andptr(rsp, -16); // align stack as required by ABI 1.1298 + __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages))); 1.1299 + __ mov(rsp, r12); // restore sp 1.1300 + __ popa(); // XXX only restore smashed registers 1.1301 + __ reinit_heapbase(); 1.1302 + 1.1303 + __ bind(no_reguard); 1.1304 + } 1.1305 + 1.1306 + 1.1307 + // The method register is junk from after the thread_in_native transition 1.1308 + // until here. Also can't call_VM until the bcp has been 1.1309 + // restored. Need bcp for throwing exception below so get it now. 1.1310 + __ get_method(method); 1.1311 + 1.1312 + // restore r13 to have legal interpreter frame, i.e., bci == 0 <=> 1.1313 + // r13 == code_base() 1.1314 + __ movptr(r13, Address(method, Method::const_offset())); // get ConstMethod* 1.1315 + __ lea(r13, Address(r13, ConstMethod::codes_offset())); // get codebase 1.1316 + // handle exceptions (exception handling will handle unlocking!) 1.1317 + { 1.1318 + Label L; 1.1319 + __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD); 1.1320 + __ jcc(Assembler::zero, L); 1.1321 + // Note: At some point we may want to unify this with the code 1.1322 + // used in call_VM_base(); i.e., we should use the 1.1323 + // StubRoutines::forward_exception code. For now this doesn't work 1.1324 + // here because the rsp is not correctly set at this point. 1.1325 + __ MacroAssembler::call_VM(noreg, 1.1326 + CAST_FROM_FN_PTR(address, 1.1327 + InterpreterRuntime::throw_pending_exception)); 1.1328 + __ should_not_reach_here(); 1.1329 + __ bind(L); 1.1330 + } 1.1331 + 1.1332 + // do unlocking if necessary 1.1333 + { 1.1334 + Label L; 1.1335 + __ movl(t, Address(method, Method::access_flags_offset())); 1.1336 + __ testl(t, JVM_ACC_SYNCHRONIZED); 1.1337 + __ jcc(Assembler::zero, L); 1.1338 + // the code below should be shared with interpreter macro 1.1339 + // assembler implementation 1.1340 + { 1.1341 + Label unlock; 1.1342 + // BasicObjectLock will be first in list, since this is a 1.1343 + // synchronized method. However, need to check that the object 1.1344 + // has not been unlocked by an explicit monitorexit bytecode. 1.1345 + const Address monitor(rbp, 1.1346 + (intptr_t)(frame::interpreter_frame_initial_sp_offset * 1.1347 + wordSize - sizeof(BasicObjectLock))); 1.1348 + 1.1349 + // monitor expect in c_rarg1 for slow unlock path 1.1350 + __ lea(c_rarg1, monitor); // address of first monitor 1.1351 + 1.1352 + __ movptr(t, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes())); 1.1353 + __ testptr(t, t); 1.1354 + __ jcc(Assembler::notZero, unlock); 1.1355 + 1.1356 + // Entry already unlocked, need to throw exception 1.1357 + __ MacroAssembler::call_VM(noreg, 1.1358 + CAST_FROM_FN_PTR(address, 1.1359 + InterpreterRuntime::throw_illegal_monitor_state_exception)); 1.1360 + __ should_not_reach_here(); 1.1361 + 1.1362 + __ bind(unlock); 1.1363 + __ unlock_object(c_rarg1); 1.1364 + } 1.1365 + __ bind(L); 1.1366 + } 1.1367 + 1.1368 + // jvmti support 1.1369 + // Note: This must happen _after_ handling/throwing any exceptions since 1.1370 + // the exception handler code notifies the runtime of method exits 1.1371 + // too. If this happens before, method entry/exit notifications are 1.1372 + // not properly paired (was bug - gri 11/22/99). 1.1373 + __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI); 1.1374 + 1.1375 + // restore potential result in edx:eax, call result handler to 1.1376 + // restore potential result in ST0 & handle result 1.1377 + 1.1378 + __ pop(ltos); 1.1379 + __ pop(dtos); 1.1380 + 1.1381 + __ movptr(t, Address(rbp, 1.1382 + (frame::interpreter_frame_result_handler_offset) * wordSize)); 1.1383 + __ call(t); 1.1384 + 1.1385 + // remove activation 1.1386 + __ movptr(t, Address(rbp, 1.1387 + frame::interpreter_frame_sender_sp_offset * 1.1388 + wordSize)); // get sender sp 1.1389 + __ leave(); // remove frame anchor 1.1390 + __ pop(rdi); // get return address 1.1391 + __ mov(rsp, t); // set sp to sender sp 1.1392 + __ jmp(rdi); 1.1393 + 1.1394 + if (inc_counter) { 1.1395 + // Handle overflow of counter and compile method 1.1396 + __ bind(invocation_counter_overflow); 1.1397 + generate_counter_overflow(&continue_after_compile); 1.1398 + } 1.1399 + 1.1400 + return entry_point; 1.1401 +} 1.1402 + 1.1403 +// 1.1404 +// Generic interpreted method entry to (asm) interpreter 1.1405 +// 1.1406 +address InterpreterGenerator::generate_normal_entry(bool synchronized) { 1.1407 + // determine code generation flags 1.1408 + bool inc_counter = UseCompiler || CountCompiledCalls; 1.1409 + 1.1410 + // ebx: Method* 1.1411 + // r13: sender sp 1.1412 + address entry_point = __ pc(); 1.1413 + 1.1414 + const Address constMethod(rbx, Method::const_offset()); 1.1415 + const Address access_flags(rbx, Method::access_flags_offset()); 1.1416 + const Address size_of_parameters(rdx, 1.1417 + ConstMethod::size_of_parameters_offset()); 1.1418 + const Address size_of_locals(rdx, ConstMethod::size_of_locals_offset()); 1.1419 + 1.1420 + 1.1421 + // get parameter size (always needed) 1.1422 + __ movptr(rdx, constMethod); 1.1423 + __ load_unsigned_short(rcx, size_of_parameters); 1.1424 + 1.1425 + // rbx: Method* 1.1426 + // rcx: size of parameters 1.1427 + // r13: sender_sp (could differ from sp+wordSize if we were called via c2i ) 1.1428 + 1.1429 + __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words 1.1430 + __ subl(rdx, rcx); // rdx = no. of additional locals 1.1431 + 1.1432 + // YYY 1.1433 +// __ incrementl(rdx); 1.1434 +// __ andl(rdx, -2); 1.1435 + 1.1436 + // see if we've got enough room on the stack for locals plus overhead. 1.1437 + generate_stack_overflow_check(); 1.1438 + 1.1439 + // get return address 1.1440 + __ pop(rax); 1.1441 + 1.1442 + // compute beginning of parameters (r14) 1.1443 + __ lea(r14, Address(rsp, rcx, Address::times_8, -wordSize)); 1.1444 + 1.1445 + // rdx - # of additional locals 1.1446 + // allocate space for locals 1.1447 + // explicitly initialize locals 1.1448 + { 1.1449 + Label exit, loop; 1.1450 + __ testl(rdx, rdx); 1.1451 + __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0 1.1452 + __ bind(loop); 1.1453 + __ push((int) NULL_WORD); // initialize local variables 1.1454 + __ decrementl(rdx); // until everything initialized 1.1455 + __ jcc(Assembler::greater, loop); 1.1456 + __ bind(exit); 1.1457 + } 1.1458 + 1.1459 + // initialize fixed part of activation frame 1.1460 + generate_fixed_frame(false); 1.1461 + 1.1462 + // make sure method is not native & not abstract 1.1463 +#ifdef ASSERT 1.1464 + __ movl(rax, access_flags); 1.1465 + { 1.1466 + Label L; 1.1467 + __ testl(rax, JVM_ACC_NATIVE); 1.1468 + __ jcc(Assembler::zero, L); 1.1469 + __ stop("tried to execute native method as non-native"); 1.1470 + __ bind(L); 1.1471 + } 1.1472 + { 1.1473 + Label L; 1.1474 + __ testl(rax, JVM_ACC_ABSTRACT); 1.1475 + __ jcc(Assembler::zero, L); 1.1476 + __ stop("tried to execute abstract method in interpreter"); 1.1477 + __ bind(L); 1.1478 + } 1.1479 +#endif 1.1480 + 1.1481 + // Since at this point in the method invocation the exception 1.1482 + // handler would try to exit the monitor of synchronized methods 1.1483 + // which hasn't been entered yet, we set the thread local variable 1.1484 + // _do_not_unlock_if_synchronized to true. The remove_activation 1.1485 + // will check this flag. 1.1486 + 1.1487 + const Address do_not_unlock_if_synchronized(r15_thread, 1.1488 + in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 1.1489 + __ movbool(do_not_unlock_if_synchronized, true); 1.1490 + 1.1491 + __ profile_parameters_type(rax, rcx, rdx); 1.1492 + // increment invocation count & check for overflow 1.1493 + Label invocation_counter_overflow; 1.1494 + Label profile_method; 1.1495 + Label profile_method_continue; 1.1496 + if (inc_counter) { 1.1497 + generate_counter_incr(&invocation_counter_overflow, 1.1498 + &profile_method, 1.1499 + &profile_method_continue); 1.1500 + if (ProfileInterpreter) { 1.1501 + __ bind(profile_method_continue); 1.1502 + } 1.1503 + } 1.1504 + 1.1505 + Label continue_after_compile; 1.1506 + __ bind(continue_after_compile); 1.1507 + 1.1508 + // check for synchronized interpreted methods 1.1509 + bang_stack_shadow_pages(false); 1.1510 + 1.1511 + // reset the _do_not_unlock_if_synchronized flag 1.1512 + __ movbool(do_not_unlock_if_synchronized, false); 1.1513 + 1.1514 + // check for synchronized methods 1.1515 + // Must happen AFTER invocation_counter check and stack overflow check, 1.1516 + // so method is not locked if overflows. 1.1517 + if (synchronized) { 1.1518 + // Allocate monitor and lock method 1.1519 + lock_method(); 1.1520 + } else { 1.1521 + // no synchronization necessary 1.1522 +#ifdef ASSERT 1.1523 + { 1.1524 + Label L; 1.1525 + __ movl(rax, access_flags); 1.1526 + __ testl(rax, JVM_ACC_SYNCHRONIZED); 1.1527 + __ jcc(Assembler::zero, L); 1.1528 + __ stop("method needs synchronization"); 1.1529 + __ bind(L); 1.1530 + } 1.1531 +#endif 1.1532 + } 1.1533 + 1.1534 + // start execution 1.1535 +#ifdef ASSERT 1.1536 + { 1.1537 + Label L; 1.1538 + const Address monitor_block_top (rbp, 1.1539 + frame::interpreter_frame_monitor_block_top_offset * wordSize); 1.1540 + __ movptr(rax, monitor_block_top); 1.1541 + __ cmpptr(rax, rsp); 1.1542 + __ jcc(Assembler::equal, L); 1.1543 + __ stop("broken stack frame setup in interpreter"); 1.1544 + __ bind(L); 1.1545 + } 1.1546 +#endif 1.1547 + 1.1548 + // jvmti support 1.1549 + __ notify_method_entry(); 1.1550 + 1.1551 + __ dispatch_next(vtos); 1.1552 + 1.1553 + // invocation counter overflow 1.1554 + if (inc_counter) { 1.1555 + if (ProfileInterpreter) { 1.1556 + // We have decided to profile this method in the interpreter 1.1557 + __ bind(profile_method); 1.1558 + __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 1.1559 + __ set_method_data_pointer_for_bcp(); 1.1560 + __ get_method(rbx); 1.1561 + __ jmp(profile_method_continue); 1.1562 + } 1.1563 + // Handle overflow of counter and compile method 1.1564 + __ bind(invocation_counter_overflow); 1.1565 + generate_counter_overflow(&continue_after_compile); 1.1566 + } 1.1567 + 1.1568 + return entry_point; 1.1569 +} 1.1570 + 1.1571 +// Entry points 1.1572 +// 1.1573 +// Here we generate the various kind of entries into the interpreter. 1.1574 +// The two main entry type are generic bytecode methods and native 1.1575 +// call method. These both come in synchronized and non-synchronized 1.1576 +// versions but the frame layout they create is very similar. The 1.1577 +// other method entry types are really just special purpose entries 1.1578 +// that are really entry and interpretation all in one. These are for 1.1579 +// trivial methods like accessor, empty, or special math methods. 1.1580 +// 1.1581 +// When control flow reaches any of the entry types for the interpreter 1.1582 +// the following holds -> 1.1583 +// 1.1584 +// Arguments: 1.1585 +// 1.1586 +// rbx: Method* 1.1587 +// 1.1588 +// Stack layout immediately at entry 1.1589 +// 1.1590 +// [ return address ] <--- rsp 1.1591 +// [ parameter n ] 1.1592 +// ... 1.1593 +// [ parameter 1 ] 1.1594 +// [ expression stack ] (caller's java expression stack) 1.1595 + 1.1596 +// Assuming that we don't go to one of the trivial specialized entries 1.1597 +// the stack will look like below when we are ready to execute the 1.1598 +// first bytecode (or call the native routine). The register usage 1.1599 +// will be as the template based interpreter expects (see 1.1600 +// interpreter_amd64.hpp). 1.1601 +// 1.1602 +// local variables follow incoming parameters immediately; i.e. 1.1603 +// the return address is moved to the end of the locals). 1.1604 +// 1.1605 +// [ monitor entry ] <--- rsp 1.1606 +// ... 1.1607 +// [ monitor entry ] 1.1608 +// [ expr. stack bottom ] 1.1609 +// [ saved r13 ] 1.1610 +// [ current r14 ] 1.1611 +// [ Method* ] 1.1612 +// [ saved ebp ] <--- rbp 1.1613 +// [ return address ] 1.1614 +// [ local variable m ] 1.1615 +// ... 1.1616 +// [ local variable 1 ] 1.1617 +// [ parameter n ] 1.1618 +// ... 1.1619 +// [ parameter 1 ] <--- r14 1.1620 + 1.1621 +address AbstractInterpreterGenerator::generate_method_entry( 1.1622 + AbstractInterpreter::MethodKind kind) { 1.1623 + // determine code generation flags 1.1624 + bool synchronized = false; 1.1625 + address entry_point = NULL; 1.1626 + InterpreterGenerator* ig_this = (InterpreterGenerator*)this; 1.1627 + 1.1628 + switch (kind) { 1.1629 + case Interpreter::zerolocals : break; 1.1630 + case Interpreter::zerolocals_synchronized: synchronized = true; break; 1.1631 + case Interpreter::native : entry_point = ig_this->generate_native_entry(false); break; 1.1632 + case Interpreter::native_synchronized : entry_point = ig_this->generate_native_entry(true); break; 1.1633 + case Interpreter::empty : entry_point = ig_this->generate_empty_entry(); break; 1.1634 + case Interpreter::accessor : entry_point = ig_this->generate_accessor_entry(); break; 1.1635 + case Interpreter::abstract : entry_point = ig_this->generate_abstract_entry(); break; 1.1636 + 1.1637 + case Interpreter::java_lang_math_sin : // fall thru 1.1638 + case Interpreter::java_lang_math_cos : // fall thru 1.1639 + case Interpreter::java_lang_math_tan : // fall thru 1.1640 + case Interpreter::java_lang_math_abs : // fall thru 1.1641 + case Interpreter::java_lang_math_log : // fall thru 1.1642 + case Interpreter::java_lang_math_log10 : // fall thru 1.1643 + case Interpreter::java_lang_math_sqrt : // fall thru 1.1644 + case Interpreter::java_lang_math_pow : // fall thru 1.1645 + case Interpreter::java_lang_math_exp : entry_point = ig_this->generate_math_entry(kind); break; 1.1646 + case Interpreter::java_lang_ref_reference_get 1.1647 + : entry_point = ig_this->generate_Reference_get_entry(); break; 1.1648 + case Interpreter::java_util_zip_CRC32_update 1.1649 + : entry_point = ig_this->generate_CRC32_update_entry(); break; 1.1650 + case Interpreter::java_util_zip_CRC32_updateBytes 1.1651 + : // fall thru 1.1652 + case Interpreter::java_util_zip_CRC32_updateByteBuffer 1.1653 + : entry_point = ig_this->generate_CRC32_updateBytes_entry(kind); break; 1.1654 + default: 1.1655 + fatal(err_msg("unexpected method kind: %d", kind)); 1.1656 + break; 1.1657 + } 1.1658 + 1.1659 + if (entry_point) { 1.1660 + return entry_point; 1.1661 + } 1.1662 + 1.1663 + return ig_this->generate_normal_entry(synchronized); 1.1664 +} 1.1665 + 1.1666 +// These should never be compiled since the interpreter will prefer 1.1667 +// the compiled version to the intrinsic version. 1.1668 +bool AbstractInterpreter::can_be_compiled(methodHandle m) { 1.1669 + switch (method_kind(m)) { 1.1670 + case Interpreter::java_lang_math_sin : // fall thru 1.1671 + case Interpreter::java_lang_math_cos : // fall thru 1.1672 + case Interpreter::java_lang_math_tan : // fall thru 1.1673 + case Interpreter::java_lang_math_abs : // fall thru 1.1674 + case Interpreter::java_lang_math_log : // fall thru 1.1675 + case Interpreter::java_lang_math_log10 : // fall thru 1.1676 + case Interpreter::java_lang_math_sqrt : // fall thru 1.1677 + case Interpreter::java_lang_math_pow : // fall thru 1.1678 + case Interpreter::java_lang_math_exp : 1.1679 + return false; 1.1680 + default: 1.1681 + return true; 1.1682 + } 1.1683 +} 1.1684 + 1.1685 +// How much stack a method activation needs in words. 1.1686 +int AbstractInterpreter::size_top_interpreter_activation(Method* method) { 1.1687 + const int entry_size = frame::interpreter_frame_monitor_size(); 1.1688 + 1.1689 + // total overhead size: entry_size + (saved rbp thru expr stack 1.1690 + // bottom). be sure to change this if you add/subtract anything 1.1691 + // to/from the overhead area 1.1692 + const int overhead_size = 1.1693 + -(frame::interpreter_frame_initial_sp_offset) + entry_size; 1.1694 + 1.1695 + const int stub_code = frame::entry_frame_after_call_words; 1.1696 + const int method_stack = (method->max_locals() + method->max_stack()) * 1.1697 + Interpreter::stackElementWords; 1.1698 + return (overhead_size + method_stack + stub_code); 1.1699 +} 1.1700 + 1.1701 +//----------------------------------------------------------------------------- 1.1702 +// Exceptions 1.1703 + 1.1704 +void TemplateInterpreterGenerator::generate_throw_exception() { 1.1705 + // Entry point in previous activation (i.e., if the caller was 1.1706 + // interpreted) 1.1707 + Interpreter::_rethrow_exception_entry = __ pc(); 1.1708 + // Restore sp to interpreter_frame_last_sp even though we are going 1.1709 + // to empty the expression stack for the exception processing. 1.1710 + __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 1.1711 + // rax: exception 1.1712 + // rdx: return address/pc that threw exception 1.1713 + __ restore_bcp(); // r13 points to call/send 1.1714 + __ restore_locals(); 1.1715 + __ reinit_heapbase(); // restore r12 as heapbase. 1.1716 + // Entry point for exceptions thrown within interpreter code 1.1717 + Interpreter::_throw_exception_entry = __ pc(); 1.1718 + // expression stack is undefined here 1.1719 + // rax: exception 1.1720 + // r13: exception bcp 1.1721 + __ verify_oop(rax); 1.1722 + __ mov(c_rarg1, rax); 1.1723 + 1.1724 + // expression stack must be empty before entering the VM in case of 1.1725 + // an exception 1.1726 + __ empty_expression_stack(); 1.1727 + // find exception handler address and preserve exception oop 1.1728 + __ call_VM(rdx, 1.1729 + CAST_FROM_FN_PTR(address, 1.1730 + InterpreterRuntime::exception_handler_for_exception), 1.1731 + c_rarg1); 1.1732 + // rax: exception handler entry point 1.1733 + // rdx: preserved exception oop 1.1734 + // r13: bcp for exception handler 1.1735 + __ push_ptr(rdx); // push exception which is now the only value on the stack 1.1736 + __ jmp(rax); // jump to exception handler (may be _remove_activation_entry!) 1.1737 + 1.1738 + // If the exception is not handled in the current frame the frame is 1.1739 + // removed and the exception is rethrown (i.e. exception 1.1740 + // continuation is _rethrow_exception). 1.1741 + // 1.1742 + // Note: At this point the bci is still the bxi for the instruction 1.1743 + // which caused the exception and the expression stack is 1.1744 + // empty. Thus, for any VM calls at this point, GC will find a legal 1.1745 + // oop map (with empty expression stack). 1.1746 + 1.1747 + // In current activation 1.1748 + // tos: exception 1.1749 + // esi: exception bcp 1.1750 + 1.1751 + // 1.1752 + // JVMTI PopFrame support 1.1753 + // 1.1754 + 1.1755 + Interpreter::_remove_activation_preserving_args_entry = __ pc(); 1.1756 + __ empty_expression_stack(); 1.1757 + // Set the popframe_processing bit in pending_popframe_condition 1.1758 + // indicating that we are currently handling popframe, so that 1.1759 + // call_VMs that may happen later do not trigger new popframe 1.1760 + // handling cycles. 1.1761 + __ movl(rdx, Address(r15_thread, JavaThread::popframe_condition_offset())); 1.1762 + __ orl(rdx, JavaThread::popframe_processing_bit); 1.1763 + __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()), rdx); 1.1764 + 1.1765 + { 1.1766 + // Check to see whether we are returning to a deoptimized frame. 1.1767 + // (The PopFrame call ensures that the caller of the popped frame is 1.1768 + // either interpreted or compiled and deoptimizes it if compiled.) 1.1769 + // In this case, we can't call dispatch_next() after the frame is 1.1770 + // popped, but instead must save the incoming arguments and restore 1.1771 + // them after deoptimization has occurred. 1.1772 + // 1.1773 + // Note that we don't compare the return PC against the 1.1774 + // deoptimization blob's unpack entry because of the presence of 1.1775 + // adapter frames in C2. 1.1776 + Label caller_not_deoptimized; 1.1777 + __ movptr(c_rarg1, Address(rbp, frame::return_addr_offset * wordSize)); 1.1778 + __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1.1779 + InterpreterRuntime::interpreter_contains), c_rarg1); 1.1780 + __ testl(rax, rax); 1.1781 + __ jcc(Assembler::notZero, caller_not_deoptimized); 1.1782 + 1.1783 + // Compute size of arguments for saving when returning to 1.1784 + // deoptimized caller 1.1785 + __ get_method(rax); 1.1786 + __ movptr(rax, Address(rax, Method::const_offset())); 1.1787 + __ load_unsigned_short(rax, Address(rax, in_bytes(ConstMethod:: 1.1788 + size_of_parameters_offset()))); 1.1789 + __ shll(rax, Interpreter::logStackElementSize); 1.1790 + __ restore_locals(); // XXX do we need this? 1.1791 + __ subptr(r14, rax); 1.1792 + __ addptr(r14, wordSize); 1.1793 + // Save these arguments 1.1794 + __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1.1795 + Deoptimization:: 1.1796 + popframe_preserve_args), 1.1797 + r15_thread, rax, r14); 1.1798 + 1.1799 + __ remove_activation(vtos, rdx, 1.1800 + /* throw_monitor_exception */ false, 1.1801 + /* install_monitor_exception */ false, 1.1802 + /* notify_jvmdi */ false); 1.1803 + 1.1804 + // Inform deoptimization that it is responsible for restoring 1.1805 + // these arguments 1.1806 + __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()), 1.1807 + JavaThread::popframe_force_deopt_reexecution_bit); 1.1808 + 1.1809 + // Continue in deoptimization handler 1.1810 + __ jmp(rdx); 1.1811 + 1.1812 + __ bind(caller_not_deoptimized); 1.1813 + } 1.1814 + 1.1815 + __ remove_activation(vtos, rdx, /* rdx result (retaddr) is not used */ 1.1816 + /* throw_monitor_exception */ false, 1.1817 + /* install_monitor_exception */ false, 1.1818 + /* notify_jvmdi */ false); 1.1819 + 1.1820 + // Finish with popframe handling 1.1821 + // A previous I2C followed by a deoptimization might have moved the 1.1822 + // outgoing arguments further up the stack. PopFrame expects the 1.1823 + // mutations to those outgoing arguments to be preserved and other 1.1824 + // constraints basically require this frame to look exactly as 1.1825 + // though it had previously invoked an interpreted activation with 1.1826 + // no space between the top of the expression stack (current 1.1827 + // last_sp) and the top of stack. Rather than force deopt to 1.1828 + // maintain this kind of invariant all the time we call a small 1.1829 + // fixup routine to move the mutated arguments onto the top of our 1.1830 + // expression stack if necessary. 1.1831 + __ mov(c_rarg1, rsp); 1.1832 + __ movptr(c_rarg2, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize)); 1.1833 + // PC must point into interpreter here 1.1834 + __ set_last_Java_frame(noreg, rbp, __ pc()); 1.1835 + __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), r15_thread, c_rarg1, c_rarg2); 1.1836 + __ reset_last_Java_frame(true, true); 1.1837 + // Restore the last_sp and null it out 1.1838 + __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize)); 1.1839 + __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 1.1840 + 1.1841 + __ restore_bcp(); // XXX do we need this? 1.1842 + __ restore_locals(); // XXX do we need this? 1.1843 + // The method data pointer was incremented already during 1.1844 + // call profiling. We have to restore the mdp for the current bcp. 1.1845 + if (ProfileInterpreter) { 1.1846 + __ set_method_data_pointer_for_bcp(); 1.1847 + } 1.1848 + 1.1849 + // Clear the popframe condition flag 1.1850 + __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()), 1.1851 + JavaThread::popframe_inactive); 1.1852 + 1.1853 +#if INCLUDE_JVMTI 1.1854 + if (EnableInvokeDynamic) { 1.1855 + Label L_done; 1.1856 + const Register local0 = r14; 1.1857 + 1.1858 + __ cmpb(Address(r13, 0), Bytecodes::_invokestatic); 1.1859 + __ jcc(Assembler::notEqual, L_done); 1.1860 + 1.1861 + // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. 1.1862 + // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL. 1.1863 + 1.1864 + __ get_method(rdx); 1.1865 + __ movptr(rax, Address(local0, 0)); 1.1866 + __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), rax, rdx, r13); 1.1867 + 1.1868 + __ testptr(rax, rax); 1.1869 + __ jcc(Assembler::zero, L_done); 1.1870 + 1.1871 + __ movptr(Address(rbx, 0), rax); 1.1872 + __ bind(L_done); 1.1873 + } 1.1874 +#endif // INCLUDE_JVMTI 1.1875 + 1.1876 + __ dispatch_next(vtos); 1.1877 + // end of PopFrame support 1.1878 + 1.1879 + Interpreter::_remove_activation_entry = __ pc(); 1.1880 + 1.1881 + // preserve exception over this code sequence 1.1882 + __ pop_ptr(rax); 1.1883 + __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), rax); 1.1884 + // remove the activation (without doing throws on illegalMonitorExceptions) 1.1885 + __ remove_activation(vtos, rdx, false, true, false); 1.1886 + // restore exception 1.1887 + __ get_vm_result(rax, r15_thread); 1.1888 + 1.1889 + // In between activations - previous activation type unknown yet 1.1890 + // compute continuation point - the continuation point expects the 1.1891 + // following registers set up: 1.1892 + // 1.1893 + // rax: exception 1.1894 + // rdx: return address/pc that threw exception 1.1895 + // rsp: expression stack of caller 1.1896 + // rbp: ebp of caller 1.1897 + __ push(rax); // save exception 1.1898 + __ push(rdx); // save return address 1.1899 + __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1.1900 + SharedRuntime::exception_handler_for_return_address), 1.1901 + r15_thread, rdx); 1.1902 + __ mov(rbx, rax); // save exception handler 1.1903 + __ pop(rdx); // restore return address 1.1904 + __ pop(rax); // restore exception 1.1905 + // Note that an "issuing PC" is actually the next PC after the call 1.1906 + __ jmp(rbx); // jump to exception 1.1907 + // handler of caller 1.1908 +} 1.1909 + 1.1910 + 1.1911 +// 1.1912 +// JVMTI ForceEarlyReturn support 1.1913 +// 1.1914 +address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) { 1.1915 + address entry = __ pc(); 1.1916 + 1.1917 + __ restore_bcp(); 1.1918 + __ restore_locals(); 1.1919 + __ empty_expression_stack(); 1.1920 + __ load_earlyret_value(state); 1.1921 + 1.1922 + __ movptr(rdx, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); 1.1923 + Address cond_addr(rdx, JvmtiThreadState::earlyret_state_offset()); 1.1924 + 1.1925 + // Clear the earlyret state 1.1926 + __ movl(cond_addr, JvmtiThreadState::earlyret_inactive); 1.1927 + 1.1928 + __ remove_activation(state, rsi, 1.1929 + false, /* throw_monitor_exception */ 1.1930 + false, /* install_monitor_exception */ 1.1931 + true); /* notify_jvmdi */ 1.1932 + __ jmp(rsi); 1.1933 + 1.1934 + return entry; 1.1935 +} // end of ForceEarlyReturn support 1.1936 + 1.1937 + 1.1938 +//----------------------------------------------------------------------------- 1.1939 +// Helper for vtos entry point generation 1.1940 + 1.1941 +void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, 1.1942 + address& bep, 1.1943 + address& cep, 1.1944 + address& sep, 1.1945 + address& aep, 1.1946 + address& iep, 1.1947 + address& lep, 1.1948 + address& fep, 1.1949 + address& dep, 1.1950 + address& vep) { 1.1951 + assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); 1.1952 + Label L; 1.1953 + aep = __ pc(); __ push_ptr(); __ jmp(L); 1.1954 + fep = __ pc(); __ push_f(); __ jmp(L); 1.1955 + dep = __ pc(); __ push_d(); __ jmp(L); 1.1956 + lep = __ pc(); __ push_l(); __ jmp(L); 1.1957 + bep = cep = sep = 1.1958 + iep = __ pc(); __ push_i(); 1.1959 + vep = __ pc(); 1.1960 + __ bind(L); 1.1961 + generate_and_dispatch(t); 1.1962 +} 1.1963 + 1.1964 + 1.1965 +//----------------------------------------------------------------------------- 1.1966 +// Generation of individual instructions 1.1967 + 1.1968 +// helpers for generate_and_dispatch 1.1969 + 1.1970 + 1.1971 +InterpreterGenerator::InterpreterGenerator(StubQueue* code) 1.1972 + : TemplateInterpreterGenerator(code) { 1.1973 + generate_all(); // down here so it can be "virtual" 1.1974 +} 1.1975 + 1.1976 +//----------------------------------------------------------------------------- 1.1977 + 1.1978 +// Non-product code 1.1979 +#ifndef PRODUCT 1.1980 +address TemplateInterpreterGenerator::generate_trace_code(TosState state) { 1.1981 + address entry = __ pc(); 1.1982 + 1.1983 + __ push(state); 1.1984 + __ push(c_rarg0); 1.1985 + __ push(c_rarg1); 1.1986 + __ push(c_rarg2); 1.1987 + __ push(c_rarg3); 1.1988 + __ mov(c_rarg2, rax); // Pass itos 1.1989 +#ifdef _WIN64 1.1990 + __ movflt(xmm3, xmm0); // Pass ftos 1.1991 +#endif 1.1992 + __ call_VM(noreg, 1.1993 + CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), 1.1994 + c_rarg1, c_rarg2, c_rarg3); 1.1995 + __ pop(c_rarg3); 1.1996 + __ pop(c_rarg2); 1.1997 + __ pop(c_rarg1); 1.1998 + __ pop(c_rarg0); 1.1999 + __ pop(state); 1.2000 + __ ret(0); // return from result handler 1.2001 + 1.2002 + return entry; 1.2003 +} 1.2004 + 1.2005 +void TemplateInterpreterGenerator::count_bytecode() { 1.2006 + __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value)); 1.2007 +} 1.2008 + 1.2009 +void TemplateInterpreterGenerator::histogram_bytecode(Template* t) { 1.2010 + __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()])); 1.2011 +} 1.2012 + 1.2013 +void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) { 1.2014 + __ mov32(rbx, ExternalAddress((address) &BytecodePairHistogram::_index)); 1.2015 + __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes); 1.2016 + __ orl(rbx, 1.2017 + ((int) t->bytecode()) << 1.2018 + BytecodePairHistogram::log2_number_of_codes); 1.2019 + __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx); 1.2020 + __ lea(rscratch1, ExternalAddress((address) BytecodePairHistogram::_counters)); 1.2021 + __ incrementl(Address(rscratch1, rbx, Address::times_4)); 1.2022 +} 1.2023 + 1.2024 + 1.2025 +void TemplateInterpreterGenerator::trace_bytecode(Template* t) { 1.2026 + // Call a little run-time stub to avoid blow-up for each bytecode. 1.2027 + // The run-time runtime saves the right registers, depending on 1.2028 + // the tosca in-state for the given template. 1.2029 + 1.2030 + assert(Interpreter::trace_code(t->tos_in()) != NULL, 1.2031 + "entry must have been generated"); 1.2032 + __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM) 1.2033 + __ andptr(rsp, -16); // align stack as required by ABI 1.2034 + __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in()))); 1.2035 + __ mov(rsp, r12); // restore sp 1.2036 + __ reinit_heapbase(); 1.2037 +} 1.2038 + 1.2039 + 1.2040 +void TemplateInterpreterGenerator::stop_interpreter_at() { 1.2041 + Label L; 1.2042 + __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value), 1.2043 + StopInterpreterAt); 1.2044 + __ jcc(Assembler::notEqual, L); 1.2045 + __ int3(); 1.2046 + __ bind(L); 1.2047 +} 1.2048 +#endif // !PRODUCT 1.2049 +#endif // ! CC_INTERP