duke@435: /* duke@435: * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_interpreter_x86_64.cpp.incl" duke@435: duke@435: #define __ _masm-> duke@435: duke@435: duke@435: #ifdef _WIN64 duke@435: address AbstractInterpreterGenerator::generate_slow_signature_handler() { duke@435: address entry = __ pc(); duke@435: duke@435: // rbx: method duke@435: // r14: pointer to locals duke@435: // c_rarg3: first stack arg - wordSize duke@435: __ movq(c_rarg3, rsp); duke@435: // adjust rsp duke@435: __ subq(rsp, 4 * wordSize); duke@435: __ call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime::slow_signature_handler), duke@435: rbx, r14, c_rarg3); duke@435: duke@435: // rax: result handler duke@435: duke@435: // Stack layout: duke@435: // rsp: 3 integer or float args (if static first is unused) duke@435: // 1 float/double identifiers duke@435: // return address duke@435: // stack args duke@435: // garbage duke@435: // expression stack bottom duke@435: // bcp (NULL) duke@435: // ... duke@435: duke@435: // Do FP first so we can use c_rarg3 as temp duke@435: __ movl(c_rarg3, Address(rsp, 3 * wordSize)); // float/double identifiers duke@435: duke@435: for ( int i= 0; i < Argument::n_int_register_parameters_c-1; i++ ) { duke@435: XMMRegister floatreg = as_XMMRegister(i+1); duke@435: Label isfloatordouble, isdouble, next; duke@435: duke@435: __ testl(c_rarg3, 1 << (i*2)); // Float or Double? duke@435: __ jcc(Assembler::notZero, isfloatordouble); duke@435: duke@435: // Do Int register here duke@435: switch ( i ) { duke@435: case 0: duke@435: __ movl(rscratch1, Address(rbx, methodOopDesc::access_flags_offset())); duke@435: __ testl(rscratch1, JVM_ACC_STATIC); duke@435: __ cmovq(Assembler::zero, c_rarg1, Address(rsp, 0)); duke@435: break; duke@435: case 1: duke@435: __ movq(c_rarg2, Address(rsp, wordSize)); duke@435: break; duke@435: case 2: duke@435: __ movq(c_rarg3, Address(rsp, 2 * wordSize)); duke@435: break; duke@435: default: duke@435: break; duke@435: } duke@435: duke@435: __ jmp (next); duke@435: duke@435: __ bind(isfloatordouble); duke@435: __ testl(c_rarg3, 1 << ((i*2)+1)); // Double? duke@435: __ jcc(Assembler::notZero, isdouble); duke@435: duke@435: // Do Float Here duke@435: __ movflt(floatreg, Address(rsp, i * wordSize)); duke@435: __ jmp(next); duke@435: duke@435: // Do Double here duke@435: __ bind(isdouble); duke@435: __ movdbl(floatreg, Address(rsp, i * wordSize)); duke@435: duke@435: __ bind(next); duke@435: } duke@435: duke@435: duke@435: // restore rsp duke@435: __ addq(rsp, 4 * wordSize); duke@435: duke@435: __ ret(0); duke@435: duke@435: return entry; duke@435: } duke@435: #else duke@435: address AbstractInterpreterGenerator::generate_slow_signature_handler() { duke@435: address entry = __ pc(); duke@435: duke@435: // rbx: method duke@435: // r14: pointer to locals duke@435: // c_rarg3: first stack arg - wordSize duke@435: __ movq(c_rarg3, rsp); duke@435: // adjust rsp duke@435: __ subq(rsp, 14 * wordSize); duke@435: __ call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime::slow_signature_handler), duke@435: rbx, r14, c_rarg3); duke@435: duke@435: // rax: result handler duke@435: duke@435: // Stack layout: duke@435: // rsp: 5 integer args (if static first is unused) duke@435: // 1 float/double identifiers duke@435: // 8 double args duke@435: // return address duke@435: // stack args duke@435: // garbage duke@435: // expression stack bottom duke@435: // bcp (NULL) duke@435: // ... duke@435: duke@435: // Do FP first so we can use c_rarg3 as temp duke@435: __ movl(c_rarg3, Address(rsp, 5 * wordSize)); // float/double identifiers duke@435: duke@435: for (int i = 0; i < Argument::n_float_register_parameters_c; i++) { duke@435: const XMMRegister r = as_XMMRegister(i); duke@435: duke@435: Label d, done; duke@435: duke@435: __ testl(c_rarg3, 1 << i); duke@435: __ jcc(Assembler::notZero, d); duke@435: __ movflt(r, Address(rsp, (6 + i) * wordSize)); duke@435: __ jmp(done); duke@435: __ bind(d); duke@435: __ movdbl(r, Address(rsp, (6 + i) * wordSize)); duke@435: __ bind(done); duke@435: } duke@435: duke@435: // Now handle integrals. Only do c_rarg1 if not static. duke@435: __ movl(c_rarg3, Address(rbx, methodOopDesc::access_flags_offset())); duke@435: __ testl(c_rarg3, JVM_ACC_STATIC); duke@435: __ cmovq(Assembler::zero, c_rarg1, Address(rsp, 0)); duke@435: duke@435: __ movq(c_rarg2, Address(rsp, wordSize)); duke@435: __ movq(c_rarg3, Address(rsp, 2 * wordSize)); duke@435: __ movq(c_rarg4, Address(rsp, 3 * wordSize)); duke@435: __ movq(c_rarg5, Address(rsp, 4 * wordSize)); duke@435: duke@435: // restore rsp duke@435: __ addq(rsp, 14 * wordSize); duke@435: duke@435: __ ret(0); duke@435: duke@435: return entry; duke@435: } duke@435: #endif duke@435: duke@435: duke@435: // duke@435: // Various method entries duke@435: // duke@435: duke@435: address InterpreterGenerator::generate_math_entry( duke@435: AbstractInterpreter::MethodKind kind) { duke@435: // rbx: methodOop duke@435: duke@435: if (!InlineIntrinsics) return NULL; // Generate a vanilla entry duke@435: duke@435: assert(kind == Interpreter::java_lang_math_sqrt, duke@435: "Other intrinsics are not special"); duke@435: duke@435: address entry_point = __ pc(); duke@435: duke@435: // These don't need a safepoint check because they aren't virtually duke@435: // callable. We won't enter these intrinsics from compiled code. duke@435: // If in the future we added an intrinsic which was virtually callable duke@435: // we'd have to worry about how to safepoint so that this code is used. duke@435: duke@435: // mathematical functions inlined by compiler duke@435: // (interpreter must provide identical implementation duke@435: // in order to avoid monotonicity bugs when switching duke@435: // from interpreter to compiler in the middle of some duke@435: // computation) duke@435: duke@435: // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are duke@435: // native methods. Interpreter::method_kind(...) does a check for duke@435: // native methods first before checking for intrinsic methods and duke@435: // thus will never select this entry point. Make sure it is not duke@435: // called accidentally since the SharedRuntime entry points will duke@435: // not work for JDK 1.2. duke@435: // duke@435: // We no longer need to check for JDK 1.2 since it's EOL'ed. duke@435: // The following check existed in pre 1.6 implementation, duke@435: // if (Universe::is_jdk12x_version()) { duke@435: // __ should_not_reach_here(); duke@435: // } duke@435: // Universe::is_jdk12x_version() always returns false since duke@435: // the JDK version is not yet determined when this method is called. duke@435: // This method is called during interpreter_init() whereas duke@435: // JDK version is only determined when universe2_init() is called. duke@435: duke@435: // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are duke@435: // java methods. Interpreter::method_kind(...) will select duke@435: // this entry point for the corresponding methods in JDK 1.3. duke@435: __ sqrtsd(xmm0, Address(rsp, wordSize)); duke@435: duke@435: __ popq(rax); duke@435: __ movq(rsp, r13); duke@435: __ jmp(rax); duke@435: duke@435: return entry_point; duke@435: } duke@435: duke@435: duke@435: // Abstract method entry duke@435: // Attempt to execute abstract method. Throw exception duke@435: address InterpreterGenerator::generate_abstract_entry(void) { duke@435: // rbx: methodOop duke@435: // r13: sender SP duke@435: duke@435: address entry_point = __ pc(); duke@435: duke@435: // abstract method entry duke@435: // remove return address. Not really needed, since exception duke@435: // handling throws away expression stack duke@435: __ popq(rbx); duke@435: duke@435: // adjust stack to what a normal return would do duke@435: __ movq(rsp, r13); duke@435: duke@435: // throw exception duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime::throw_AbstractMethodError)); duke@435: // the call_VM checks for exception, so we should never return here. duke@435: __ should_not_reach_here(); duke@435: duke@435: return entry_point; duke@435: } duke@435: duke@435: duke@435: // Empty method, generate a very fast return. duke@435: duke@435: address InterpreterGenerator::generate_empty_entry(void) { duke@435: // rbx: methodOop duke@435: // r13: sender sp must set sp to this value on return duke@435: duke@435: if (!UseFastEmptyMethods) { duke@435: return NULL; duke@435: } duke@435: duke@435: address entry_point = __ pc(); duke@435: duke@435: // If we need a safepoint check, generate full interpreter entry. duke@435: Label slow_path; duke@435: __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), duke@435: SafepointSynchronize::_not_synchronized); duke@435: __ jcc(Assembler::notEqual, slow_path); duke@435: duke@435: // do nothing for empty methods (do not even increment invocation counter) duke@435: // Code: _return duke@435: // _return duke@435: // return w/o popping parameters duke@435: __ popq(rax); duke@435: __ movq(rsp, r13); duke@435: __ jmp(rax); duke@435: duke@435: __ bind(slow_path); duke@435: (void) generate_normal_entry(false); duke@435: return entry_point; duke@435: duke@435: } duke@435: duke@435: // Call an accessor method (assuming it is resolved, otherwise drop duke@435: // into vanilla (slow path) entry duke@435: address InterpreterGenerator::generate_accessor_entry(void) { duke@435: // rbx: methodOop duke@435: duke@435: // r13: senderSP must preserver for slow path, set SP to it on fast path duke@435: duke@435: address entry_point = __ pc(); duke@435: Label xreturn_path; duke@435: duke@435: // do fastpath for resolved accessor methods duke@435: if (UseFastAccessorMethods) { duke@435: // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites duke@435: // thereof; parameter size = 1 duke@435: // Note: We can only use this code if the getfield has been resolved duke@435: // and if we don't have a null-pointer exception => check for duke@435: // these conditions first and use slow path if necessary. duke@435: Label slow_path; duke@435: // If we need a safepoint check, generate full interpreter entry. duke@435: __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), duke@435: SafepointSynchronize::_not_synchronized); duke@435: duke@435: __ jcc(Assembler::notEqual, slow_path); duke@435: // rbx: method duke@435: __ movq(rax, Address(rsp, wordSize)); duke@435: duke@435: // check if local 0 != NULL and read field duke@435: __ testq(rax, rax); duke@435: __ jcc(Assembler::zero, slow_path); duke@435: duke@435: __ movq(rdi, Address(rbx, methodOopDesc::constants_offset())); duke@435: // read first instruction word and extract bytecode @ 1 and index @ 2 duke@435: __ movq(rdx, Address(rbx, methodOopDesc::const_offset())); duke@435: __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset())); duke@435: // Shift codes right to get the index on the right. duke@435: // The bytecode fetched looks like <0xb4><0x2a> duke@435: __ shrl(rdx, 2 * BitsPerByte); duke@435: __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size()))); duke@435: __ movq(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes())); duke@435: duke@435: // rax: local 0 duke@435: // rbx: method duke@435: // rdx: constant pool cache index duke@435: // rdi: constant pool cache duke@435: duke@435: // check if getfield has been resolved and read constant pool cache entry duke@435: // check the validity of the cache entry by testing whether _indices field duke@435: // contains Bytecode::_getfield in b1 byte. duke@435: assert(in_words(ConstantPoolCacheEntry::size()) == 4, duke@435: "adjust shift below"); duke@435: __ movl(rcx, duke@435: Address(rdi, duke@435: rdx, duke@435: Address::times_8, duke@435: constantPoolCacheOopDesc::base_offset() + duke@435: ConstantPoolCacheEntry::indices_offset())); duke@435: __ shrl(rcx, 2 * BitsPerByte); duke@435: __ andl(rcx, 0xFF); duke@435: __ cmpl(rcx, Bytecodes::_getfield); duke@435: __ jcc(Assembler::notEqual, slow_path); duke@435: duke@435: // Note: constant pool entry is not valid before bytecode is resolved duke@435: __ movq(rcx, duke@435: Address(rdi, duke@435: rdx, duke@435: Address::times_8, duke@435: constantPoolCacheOopDesc::base_offset() + duke@435: ConstantPoolCacheEntry::f2_offset())); duke@435: // edx: flags duke@435: __ movl(rdx, duke@435: Address(rdi, duke@435: rdx, duke@435: Address::times_8, duke@435: constantPoolCacheOopDesc::base_offset() + duke@435: ConstantPoolCacheEntry::flags_offset())); duke@435: duke@435: Label notObj, notInt, notByte, notShort; duke@435: const Address field_address(rax, rcx, Address::times_1); duke@435: duke@435: // Need to differentiate between igetfield, agetfield, bgetfield etc. duke@435: // because they are different sizes. duke@435: // Use the type from the constant pool cache duke@435: __ shrl(rdx, ConstantPoolCacheEntry::tosBits); duke@435: // Make sure we don't need to mask edx for tosBits after the above shift duke@435: ConstantPoolCacheEntry::verify_tosBits(); duke@435: duke@435: __ cmpl(rdx, atos); duke@435: __ jcc(Assembler::notEqual, notObj); duke@435: // atos coleenp@548: __ load_heap_oop(rax, field_address); duke@435: __ jmp(xreturn_path); duke@435: duke@435: __ bind(notObj); duke@435: __ cmpl(rdx, itos); duke@435: __ jcc(Assembler::notEqual, notInt); duke@435: // itos duke@435: __ movl(rax, field_address); duke@435: __ jmp(xreturn_path); duke@435: duke@435: __ bind(notInt); duke@435: __ cmpl(rdx, btos); duke@435: __ jcc(Assembler::notEqual, notByte); duke@435: // btos duke@435: __ load_signed_byte(rax, field_address); duke@435: __ jmp(xreturn_path); duke@435: duke@435: __ bind(notByte); duke@435: __ cmpl(rdx, stos); duke@435: __ jcc(Assembler::notEqual, notShort); duke@435: // stos duke@435: __ load_signed_word(rax, field_address); duke@435: __ jmp(xreturn_path); duke@435: duke@435: __ bind(notShort); duke@435: #ifdef ASSERT duke@435: Label okay; duke@435: __ cmpl(rdx, ctos); duke@435: __ jcc(Assembler::equal, okay); duke@435: __ stop("what type is this?"); duke@435: __ bind(okay); duke@435: #endif duke@435: // ctos duke@435: __ load_unsigned_word(rax, field_address); duke@435: duke@435: __ bind(xreturn_path); duke@435: duke@435: // _ireturn/_areturn duke@435: __ popq(rdi); duke@435: __ movq(rsp, r13); duke@435: __ jmp(rdi); duke@435: __ ret(0); duke@435: duke@435: // generate a vanilla interpreter entry as the slow path duke@435: __ bind(slow_path); duke@435: (void) generate_normal_entry(false); duke@435: } else { duke@435: (void) generate_normal_entry(false); duke@435: } duke@435: duke@435: return entry_point; duke@435: } duke@435: duke@435: // This method tells the deoptimizer how big an interpreted frame must be: duke@435: int AbstractInterpreter::size_activation(methodOop method, duke@435: int tempcount, duke@435: int popframe_extra_args, duke@435: int moncount, duke@435: int callee_param_count, duke@435: int callee_locals, duke@435: bool is_top_frame) { duke@435: return layout_activation(method, duke@435: tempcount, popframe_extra_args, moncount, duke@435: callee_param_count, callee_locals, duke@435: (frame*) NULL, (frame*) NULL, is_top_frame); duke@435: } duke@435: duke@435: void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) { duke@435: duke@435: // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in duke@435: // the days we had adapter frames. When we deoptimize a situation where a duke@435: // compiled caller calls a compiled caller will have registers it expects duke@435: // to survive the call to the callee. If we deoptimize the callee the only duke@435: // way we can restore these registers is to have the oldest interpreter duke@435: // frame that we create restore these values. That is what this routine duke@435: // will accomplish. duke@435: duke@435: // At the moment we have modified c2 to not have any callee save registers duke@435: // so this problem does not exist and this routine is just a place holder. duke@435: duke@435: assert(f->is_interpreted_frame(), "must be interpreted"); duke@435: }