3790N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A//----------------------------------------------------------------------------- 0N/A // Restore bcp under the assumption that the current frame is still 0N/A // expression stack must be empty before entering the VM if an 0N/A // exception happened 0N/A // expression stack must be empty before entering the VM if an 0N/A // exception happened 0N/A // ??? convention: expect aberrant index in register ebx 0N/A // expression stack must be empty before entering the VM if an 0N/A // exception happened 0N/A // expression stack must be empty before entering the VM if an 0N/A // exception happened 0N/A // kind of lame ExternalAddress can't take NULL because 0N/A // external_word_Relocation will assert. 0N/A // NULL last_sp until next java call 0N/A // Restore stack bottom in case i2c adjusted stack 0N/A // and NULL it as marker that esp is now tos until next java call 1108N/A // out of the main line of code... 0N/A // NULL last_sp until next java call 0N/A // handle exceptions 0N/A "index out of bounds");
0N/A // retrieve result from frame 0N/A __ ret(0);
// return from result handler 0N/A// Helpers for commoning out cases in the various type of method entries. 0N/A// increment invocation count & check for overflow 0N/A// Note: checking for negative value instead of overflow 0N/A// so we have a 'sticky' overflow test 0N/A// ecx: invocation counter 1703N/A // Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not. 1703N/A // Increment counter in the MDO 1703N/A // Increment counter in methodOop (we don't need to load it, it's in ecx). 1703N/A // Update standard invocation counters 1703N/A // profile_method is non-null only for interpreted method so 1703N/A // profile_method != NULL == !native_call 1703N/A // Test to see if we should create a method data oop 1703N/A // if no method data exists, go to profile_method 0N/A // Asm interpreter on entry 0N/A // edx - cpool --- DOES NOT APPEAR TO BE TRUE 0N/A // rbp - interpreter frame 0N/A // On return (i.e. jump to entry_point) [ back to invocation of interpreter ] 0N/A // Everything as it was on entry 0N/A // rdx is not restored. Doesn't appear to really be set. 0N/A // InterpreterRuntime::frequency_counter_overflow takes two 0N/A // arguments, the first (thread) is passed by call_VM, the second 0N/A // indicates if the counter overflow occurs at a backwards branch 0N/A // (NULL bcp). We pass zero for it. The call returns the address 0N/A // of the verified entry point for the method or NULL if the 0N/A // compilation did not complete (either went background or bailed 0N/A // and jump to the interpreted entry. 0N/A// See if we've got enough room on the stack for locals plus overhead. 0N/A// The expression stack grows down incrementally, so the normal guard 0N/A// page mechanism will work for that. 0N/A// NOTE: Since the additional locals are also always pushed (wasn't 0N/A// obvious in generate_method_entry) so the guard should work for them 0N/A// rdx: number of additional locals this frame needs (what we must check) 0N/A // monitor entry size: see picture of stack set 0N/A // total overhead size: entry_size + (saved rbp through expr stack 0N/A // see if the frame is greater than one page in size. If so, 0N/A // then we need to verify there is enough stack space remaining 0N/A // for the additional locals. 0N/A // compute rsp as if this were going to be the last frame on 0N/A // the stack before the red zone 0N/A // locals + overhead, in bytes 0N/A // verify that thread stack base is non-zero 0N/A // verify that thread stack size is non-zero 0N/A // Add stack base to locals and subtract stack size 1135N/A // Use the maximum number of pages we might bang. 0N/A // add in the red and yellow zone sizes 0N/A // check against the current stack bottom 3023N/A // Restore sender's sp as SP. This is necessary if the sender's 3023N/A // frame is an extended compiled frame (see gen_c2i_adapter()) 3023N/A // and safer anyway in case of JSR292 adaptations. 3023N/A // Note: the restored frame is not necessarily interpreted. 3023N/A // Use the shared runtime version of the StackOverflowError. 0N/A // all done with frame size check 0N/A// Allocate monitor and lock method (asm interpreter) 0N/A// c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs) 0N/A// rscratch1, rscratch2 (scratch regs) 0N/A // synchronize method 0N/A __ stop(
"method doesn't need synchronization");
0N/A // get synchronization object 0N/A // get receiver (assume this is frequent case) 0N/A // add space for monitor & lock 0N/A// Generate a fixed interpreter frame. This is identical setup for 0N/A// interpreted methods and for native methods hence the shared code. 0N/A// rax: return address 0N/A// r14: pointer to locals 0N/A // initialize fixed part of activation frame 304N/A __ push(0);
// reserve word for pointer to expression stack bottom 304N/A// Various method entries 304N/A//------------------------------------------------------------------------------------------------------------------------ 304N/A// Call an accessor method (assuming it is resolved, otherwise drop 304N/A// into vanilla (slow path) entry 304N/A // r13: senderSP must preserver for slow path, set SP to it on fast path 304N/A // do fastpath for resolved accessor methods 304N/A // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites 304N/A // thereof; parameter size = 1 304N/A // Note: We can only use this code if the getfield has been resolved 304N/A // and if we don't have a null-pointer exception => check for 304N/A // these conditions first and use slow path if necessary. 304N/A // If we need a safepoint check, generate full interpreter entry. 304N/A // check if local 0 != NULL and read field 304N/A // read first instruction word and extract bytecode @ 1 and index @ 2 304N/A // Shift codes right to get the index on the right. 304N/A // The bytecode fetched looks like <index><0xb4><0x2a> 304N/A // rdx: constant pool cache index 304N/A // rdi: constant pool cache 304N/A // check if getfield has been resolved and read constant pool cache entry 304N/A // check the validity of the cache entry by testing whether _indices field 304N/A // contains Bytecode::_getfield in b1 byte. 304N/A // Note: constant pool entry is not valid before bytecode is resolved 304N/A // Need to differentiate between igetfield, agetfield, bgetfield etc. 304N/A // because they are different sizes. 304N/A // Use the type from the constant pool cache 3932N/A // Make sure we don't need to mask edx after the above shift 304N/A // generate a vanilla interpreter entry as the slow path 2346N/A// Method entry for java.lang.ref.Reference.get. 2346N/A // Code: _aload_0, _getfield, _areturn 2346N/A // The code that gets generated by this routine is split into 2 parts: 2346N/A // 1. The "intrinsified" code for G1 (or any SATB based GC), 2346N/A // 2. The slow path - which is an expansion of the regular method entry. 2346N/A // * In the G1 code we do not check whether we need to block for 2346N/A // a safepoint. If G1 is enabled then we must execute the specialized 2346N/A // code for Reference.get (except when the Reference object is null) 2346N/A // so that we can log the value in the referent field with an SATB 2346N/A // If the code for the getfield template is modified so that the 2346N/A // G1 pre-barrier code is executed when the current method is 2346N/A // Reference.get() then going through the normal method entry 2346N/A // * The G1 code can, however, check the receiver object (the instance 2346N/A // of java.lang.Reference) and jump to the slow path if null. If the 2346N/A // Reference object is null then we obviously cannot fetch the referent 2346N/A // and so we don't need to call the G1 pre-barrier. Thus we can use the 2346N/A // regular method entry code to generate the NPE. 2346N/A // This code is based on generate_accessor_enty. 2346N/A // r13: senderSP must preserve for slow path, set SP to it on fast path 2346N/A // Check if local 0 != NULL 2346N/A // If the receiver is null then it is OK to jump to the slow path. 2346N/A // rbx: method (but can be used as scratch now) 2346N/A // Generate the G1 pre-barrier code to log the value of 2346N/A // the referent field in an SATB buffer. 2346N/A // Load the value of the referent field. 2346N/A // Generate the G1 pre-barrier code to log the value of 2346N/A // the referent field in an SATB buffer. 2346N/A // generate a vanilla interpreter entry as the slow path 2346N/A // If G1 is not enabled then attempt to go through the accessor entry point 2346N/A // Reference.get is an accessor 0N/A// Interpreter stub for calling a native method. (asm interpreter) 0N/A// This sets up a somewhat different looking stack for calling the 0N/A// native method than the typical interpreter frame setup. 0N/A // determine code generation flags 0N/A // get parameter size (always needed) 0N/A // native calls don't need the stack size check since they have no 0N/A // expression stack and the arguments are already on the stack and 0N/A // we only add a handful of words to the stack 0N/A // rcx: size of parameters 0N/A // for natives the size of locals is zero 0N/A // compute beginning of parameters (r14) 0N/A // add 2 zero-initialized slots for native calls 0N/A // initialize result_handler slot 0N/A // slot for oop temp 0N/A // initialize fixed part of activation frame 0N/A // make sure method is native & not abstract 0N/A __ stop(
"tried to execute non-native method as native");
0N/A __ stop(
"tried to execute abstract method in interpreter");
0N/A // Since at this point in the method invocation the exception handler 0N/A // would try to exit the monitor of synchronized methods which hasn't 0N/A // been entered yet, we set the thread local variable 0N/A // _do_not_unlock_if_synchronized to true. The remove_activation will 0N/A // increment invocation count & check for overflow 0N/A // reset the _do_not_unlock_if_synchronized flag 0N/A // check for synchronized methods 0N/A // Must happen AFTER invocation_counter check and stack overflow check, 0N/A // so method is not locked if overflows. 0N/A // no synchronization necessary 0N/A __ stop(
"broken stack frame setup in interpreter");
0N/A // allocate space for parameters 0N/A // get signature handler 0N/A // call signature handler 0N/A "adjust this code");
0N/A "adjust this code");
0N/A "adjust this code");
0N/A // The generated handlers do not touch RBX (the method oop). 0N/A // However, large signatures cannot be cached and are generated 0N/A // each time here. The slow-path generator can do a GC on return, 0N/A // so we must reload it after the call. 0N/A // result handler is in rax 0N/A // set result handler 0N/A // pass mirror handle if static call 0N/A // copy mirror into activation frame 0N/A // pass handle to mirror 0N/A // get native function entry point 0N/A // It is enough that the pc() points into the right code 0N/A // segment. It does not have to be the correct return pc. 0N/A // change thread state 0N/A __ stop(
"Wrong thread state in native stub");
0N/A // Change state to native 0N/A // Call the native method. 0N/A // result potentially in rax or xmm0 4442N/A // Verify or restore cpu control state after JNI call 0N/A // NOTE: The order of these pushes is known to frame::interpreter_frame_result 0N/A // in order to extract the result of a method call. If the order of these 0N/A // pushes change or anything else is added to the stack then the code in 0N/A // interpreter_frame_result must also change. 0N/A // change thread state 0N/A // Force this write out before the read below 0N/A // Write serialization page so VM thread can do a pseudo remote membar. 0N/A // We use the current thread pointer to calculate a thread specific 0N/A // offset to write to within the page. This minimizes bus traffic 0N/A // due to cache line collision. 0N/A // check for safepoint operation in progress and/or pending suspend requests 0N/A // Don't use call_VM as it will see a possible pending exception 0N/A // and forward it and never return here preventing us from 0N/A // clearing _last_native_pc down below. Also can't use 0N/A // call_VM_leaf either as it will check to see if r13 & r14 are 0N/A // preserved and correspond to the bcp/locals pointers. So we do a 0N/A // runtime call by hand. 0N/A // change thread state 0N/A // reset_last_Java_frame 0N/A // reset handle block 0N/A // If result is an oop unbox and store it in frame where gc will see it 0N/A // and result handler will pick it up 0N/A // keep stack depth as expected by pushing oop which will eventually be discarde 0N/A // The method register is junk from after the thread_in_native transition 0N/A // until here. Also can't call_VM until the bcp has been 0N/A // restored. Need bcp for throwing exception below so get it now. 0N/A // restore r13 to have legal interpreter frame, i.e., bci == 0 <=> 0N/A // r13 == code_base() 0N/A // handle exceptions (exception handling will handle unlocking!) 0N/A // Note: At some point we may want to unify this with the code 0N/A // used in call_VM_base(); i.e., we should use the 0N/A // StubRoutines::forward_exception code. For now this doesn't work 0N/A // here because the rsp is not correctly set at this point. 0N/A // do unlocking if necessary 0N/A // the code below should be shared with interpreter macro 0N/A // assembler implementation 0N/A // BasicObjectLock will be first in list, since this is a 0N/A // synchronized method. However, need to check that the object 0N/A // has not been unlocked by an explicit monitorexit bytecode. 0N/A // monitor expect in c_rarg1 for slow unlock path 0N/A // Entry already unlocked, need to throw exception 0N/A // the exception handler code notifies the runtime of method exits 0N/A // too. If this happens before, method entry/exit notifications are 0N/A // not properly paired (was bug - gri 11/22/99). 0N/A // restore potential result in edx:eax, call result handler to 0N/A // restore potential result in ST0 & handle result 0N/A // remove activation 0N/A // Handle overflow of counter and compile method 0N/A// Generic interpreted method entry to (asm) interpreter 0N/A // determine code generation flags 0N/A // get parameter size (always needed) 0N/A // rcx: size of parameters 0N/A // r13: sender_sp (could differ from sp+wordSize if we were called via c2i ) 0N/A// __ incrementl(rdx); 0N/A // see if we've got enough room on the stack for locals plus overhead. 0N/A // get return address 0N/A // compute beginning of parameters (r14) 0N/A // rdx - # of additional locals 0N/A // allocate space for locals 0N/A // explicitly initialize locals 0N/A // (pre-)fetch invocation count 0N/A // initialize fixed part of activation frame 0N/A // make sure method is not native & not abstract 0N/A __ stop(
"tried to execute native method as non-native");
0N/A __ stop(
"tried to execute abstract method in interpreter");
0N/A // Since at this point in the method invocation the exception 0N/A // handler would try to exit the monitor of synchronized methods 0N/A // which hasn't been entered yet, we set the thread local variable 0N/A // _do_not_unlock_if_synchronized to true. The remove_activation 0N/A // will check this flag. 0N/A // increment invocation count & check for overflow 0N/A // check for synchronized interpreted methods 0N/A // reset the _do_not_unlock_if_synchronized flag 0N/A // check for synchronized methods 0N/A // Must happen AFTER invocation_counter check and stack overflow check, 0N/A // so method is not locked if overflows. 0N/A // Allocate monitor and lock method 0N/A // no synchronization necessary 0N/A __ stop(
"broken stack frame setup in interpreter");
0N/A // invocation counter overflow 0N/A // We have decided to profile this method in the interpreter 0N/A // Handle overflow of counter and compile method 0N/A// Here we generate the various kind of entries into the interpreter. 0N/A// The two main entry type are generic bytecode methods and native 0N/A// call method. These both come in synchronized and non-synchronized 0N/A// versions but the frame layout they create is very similar. The 0N/A// other method entry types are really just special purpose entries 0N/A// that are really entry and interpretation all in one. These are for 0N/A// trivial methods like accessor, empty, or special math methods. 0N/A// When control flow reaches any of the entry types for the interpreter 0N/A// the following holds -> 0N/A// Stack layout immediately at entry 0N/A// [ return address ] <--- rsp 0N/A// [ expression stack ] (caller's java expression stack) 0N/A// Assuming that we don't go to one of the trivial specialized entries 0N/A// the stack will look like below when we are ready to execute the 0N/A// first bytecode (or call the native routine). The register usage 0N/A// will be as the template based interpreter expects (see 0N/A// local variables follow incoming parameters immediately; i.e. 0N/A// the return address is moved to the end of the locals). 0N/A// [ monitor entry ] <--- rsp 0N/A// [ expr. stack bottom ] 0N/A// [ saved ebp ] <--- rbp 0N/A// [ return address ] 0N/A// [ local variable m ] 0N/A// [ local variable 1 ] 0N/A// [ parameter 1 ] <--- r14 0N/A // determine code generation flags 1174N/A// These should never be compiled since the interpreter will prefer 1174N/A// the compiled version to the intrinsic version. 0N/A// How much stack a method activation needs in words. 0N/A // total overhead size: entry_size + (saved rbp thru expr stack 0N/A // Note: This calculation must exactly parallel the frame setup 0N/A // in AbstractInterpreterGenerator::generate_method_entry. 0N/A // If interpreter_frame!=NULL, set up the method, locals, and monitors. 0N/A // The frame interpreter_frame, if not NULL, is guaranteed to be the 0N/A // right size, as determined by a previous call to this method. 0N/A // It is also guaranteed to be walkable even though it is in a skeletal state 0N/A // fixed size of an interpreter frame: 0N/A // Our locals were accounted for by the caller (or last_frame_adjust 0N/A // on the transistion) Since the callee parameters already account 0N/A // for the callee's params we only need to account for the extra 1135N/A // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences? 1135N/A // Probably, since deoptimization doesn't work yet. 0N/A // NOTE the difference in using sender_sp and 0N/A // interpreter_frame_sender_sp interpreter_frame_sender_sp is 0N/A // the original sp of the caller (the unextended_sp) and 0N/A // sender_sp is fp+16 XXX 0N/A // All frames but the initial (oldest) interpreter frame we fill in have 0N/A // a value for sender_sp that allows walking the stack but isn't 0N/A // truly correct. Correct the value here. 0N/A//----------------------------------------------------------------------------- 0N/A // Entry point in previous activation (i.e., if the caller was 0N/A // Restore sp to interpreter_frame_last_sp even though we are going 0N/A // to empty the expression stack for the exception processing. 0N/A // Entry point for exceptions thrown within interpreter code 0N/A // expression stack is undefined here 0N/A // r13: exception bcp 0N/A // expression stack must be empty before entering the VM in case of 0N/A // find exception handler address and preserve exception oop 0N/A // rax: exception handler entry point 0N/A // rdx: preserved exception oop 0N/A // r13: bcp for exception handler 0N/A __ jmp(
rax);
// jump to exception handler (may be _remove_activation_entry!) 0N/A // If the exception is not handled in the current frame the frame is 0N/A // removed and the exception is rethrown (i.e. exception 0N/A // continuation is _rethrow_exception). 0N/A // Note: At this point the bci is still the bxi for the instruction 0N/A // which caused the exception and the expression stack is 0N/A // empty. Thus, for any VM calls at this point, GC will find a legal 0N/A // oop map (with empty expression stack). 0N/A // In current activation 0N/A // esi: exception bcp 0N/A // JVMTI PopFrame support 0N/A // Set the popframe_processing bit in pending_popframe_condition 0N/A // indicating that we are currently handling popframe, so that 0N/A // call_VMs that may happen later do not trigger new popframe 0N/A // Check to see whether we are returning to a deoptimized frame. 0N/A // (The PopFrame call ensures that the caller of the popped frame is 0N/A // either interpreted or compiled and deoptimizes it if compiled.) 0N/A // In this case, we can't call dispatch_next() after the frame is 0N/A // popped, but instead must save the incoming arguments and restore 0N/A // them after deoptimization has occurred. 0N/A // Note that we don't compare the return PC against the 0N/A // deoptimization blob's unpack entry because of the presence of 0N/A // adapter frames in C2. 0N/A // Compute size of arguments for saving when returning to 0N/A // deoptimized caller 0N/A // Save these arguments 0N/A /* throw_monitor_exception */ false,
0N/A /* install_monitor_exception */ false,
0N/A /* notify_jvmdi */ false);
0N/A // Inform deoptimization that it is responsible for restoring 0N/A // Continue in deoptimization handler 0N/A /* throw_monitor_exception */ false,
0N/A /* install_monitor_exception */ false,
0N/A /* notify_jvmdi */ false);
0N/A // Finish with popframe handling 0N/A // A previous I2C followed by a deoptimization might have moved the 0N/A // outgoing arguments further up the stack. PopFrame expects the 0N/A // mutations to those outgoing arguments to be preserved and other 0N/A // constraints basically require this frame to look exactly as 0N/A // though it had previously invoked an interpreted activation with 0N/A // no space between the top of the expression stack (current 0N/A // last_sp) and the top of stack. Rather than force deopt to 0N/A // maintain this kind of invariant all the time we call a small 0N/A // fixup routine to move the mutated arguments onto the top of our 0N/A // expression stack if necessary. 0N/A // PC must point into interpreter here 0N/A // Restore the last_sp and null it out 0N/A // The method data pointer was incremented already during 0N/A // call profiling. We have to restore the mdp for the current bcp. 0N/A // Clear the popframe condition flag 0N/A // end of PopFrame support 0N/A // preserve exception over this code sequence 0N/A // remove the activation (without doing throws on illegalMonitorExceptions) 0N/A // restore exception 0N/A // In between activations - previous activation type unknown yet 0N/A // compute continuation point - the continuation point expects the 0N/A // following registers set up: 0N/A // rsp: expression stack of caller 0N/A // rbp: ebp of caller 0N/A // Note that an "issuing PC" is actually the next PC after the call 0N/A // handler of caller 0N/A// JVMTI ForceEarlyReturn support 0N/A // Clear the earlyret state 0N/A false,
/* throw_monitor_exception */ 0N/A false,
/* install_monitor_exception */ 0N/A true);
/* notify_jvmdi */ 0N/A}
// end of ForceEarlyReturn support 0N/A//----------------------------------------------------------------------------- 0N/A// Helper for vtos entry point generation 0N/A//----------------------------------------------------------------------------- 0N/A// Generation of individual instructions 0N/A// helpers for generate_and_dispatch 0N/A//----------------------------------------------------------------------------- 0N/A __ ret(0);
// return from result handler 0N/A // Call a little run-time stub to avoid blow-up for each bytecode. 0N/A // The run-time runtime saves the right registers, depending on 0N/A // the tosca in-state for the given template. 0N/A "entry must have been generated");