sharedRuntime_x86_64.cpp revision 2117
5053N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 5053N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5053N/A * This code is free software; you can redistribute it and/or modify it 5053N/A * under the terms of the GNU General Public License version 2 only, as 5053N/A * published by the Free Software Foundation. 5053N/A * This code is distributed in the hope that it will be useful, but WITHOUT 5053N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5053N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5053N/A * version 2 for more details (a copy is included in the LICENSE file that 5053N/A * You should have received a copy of the GNU General Public License version 5053N/A * 2 along with this work; if not, write to the Free Software Foundation, 5053N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5053N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5053N/A // Most of the runtime stubs have this simple frame layout. 5232N/A // This class exists to make the layout shared in one place. 5232N/A // Offsets are for compiler stack slots, which are jints. 5232N/A // The frame sender code expects that rbp will be in the "natural" place and 5232N/A // will override any oopMap setting for it. We must therefore force the layout 5053N/A // so that it agrees with the frame sender code. 5053N/A // Capture info about frame layout. Layout offsets are in jint 5232N/A // units because compiler frame slots are jints. 5232N/A // The frame sender code expects that rbp will be in the "natural" place and 5232N/A // will override any oopMap setting for it. We must therefore force the layout 5232N/A // so that it agrees with the frame sender code. 5232N/A // Offsets into the register save area 5232N/A // Used by deoptimization when it is managing result register 5053N/A // During deoptimization only the result registers need to be restored, 5232N/A // all the other values have already been extracted. 5053N/A // Always make the frame size 16-byte aligned 5053N/A // OopMap frame size is in compiler stack slots (jint's) not bytes or words 5271N/A // The caller will allocate additional_frame_words 5053N/A // CodeBlob frame size is in words. 5232N/A // Save registers, fpu state, and flags. 5232N/A // We assume caller has already pushed the return address onto the 5232N/A // stack, so rsp is 8-byte aligned here. 5053N/A // We push rpb twice in this sequence because we want the real rbp 5053N/A // to be under the return like a normal enter. 5232N/A // Allocate argument register save area 5053N/A // Set an oopmap for the call site. This oopmap will map all 5053N/A // oop-registers and debug-info registers as callee-saved. This 5232N/A // will allow deoptimization at this safepoint to find all possible 5232N/A // debug-info recordings, as well as let GC find all oops. 5053N/A // rbp location is known implicitly by the frame sender code, needs no oopmap 5232N/A // and the location where rbp was saved by is ignored 5232N/A // %%% These should all be a waste but we'll keep things as they were for now 5232N/A // rbp location is known implicitly by the frame sender code, needs no oopmap 5053N/A // Pop arg register save area 5053N/A // Get the rbp described implicitly by the calling convention (no oopMap) 5232N/A // Just restore result register. Only used by deoptimization. By 5053N/A // now any callee save register that needs to be restored to a c2 5053N/A // caller of the deoptee has been extracted into the vframeArray 5232N/A // and will be stuffed into the c2i adapter we create for later 5232N/A // restoration so only result registers need to be restored here. 5053N/A // Restore fp result register 5232N/A // Restore integer result register 5053N/A // Pop all of the register save are off the stack except the return address 5232N/A// The java_calling_convention describes stack locations as ideal slots on 5232N/A// a frame with no abi restrictions. Since we must observe abi restrictions 5232N/A// (like the placement of the register window) the slots must be biased by 5232N/A // Account for saved rbp and return address 5232N/A // This should really be in_preserve_stack_slots 5232N/A// --------------------------------------------------------------------------- 5053N/A// Read the array of BasicTypes from a signature, and compute where the 5053N/A// arguments should go. Values in the VMRegPair regs array refer to 4-byte 5232N/A// quantities. Values less than VMRegImpl::stack0 are registers, those above 5232N/A// refer to 4-byte stack slots. All stack slots are based off of the stack pointer 5053N/A// VMRegImpl::stack0 refers to the first slot 0(sp). 5053N/A// and VMRegImpl::stack0+1 refers to the memory word 4-byes higher. Register 5232N/A// up to RegisterImpl::number_of_registers) are the 64-bit 5232N/A// Note: the INPUTS in sig_bt are in units of Java argument words, which are 5232N/A// either 32-bit or 64-bit depending on the build. The OUTPUTS are in 32-bit 5232N/A// units regardless of build. Of course for i486 there is no 64 bit build 5053N/A// The Java calling convention is a "shifted" version of the C ABI. 5232N/A// By skipping the first C ABI register we can call non-static jni methods 5232N/A// with small numbers of arguments without having to shuffle the arguments 5232N/A// at all. Since we control the java ABI we ought to at least get some 5053N/A // Create the mapping between argument positions and 5053N/A // halves of T_LONG or T_DOUBLE 5053N/A// Patch the callers callsite with entry to compiled code if it exists. 5232N/A // Save the current stack pointer 5232N/A // Schedule the branch target address early. 5232N/A // Call into the VM to patch the caller, then jump to compiled callee 5232N/A // rax isn't live so capture return address while we easily can 5232N/A // align stack so push_CPU_state doesn't fault 5053N/A // VM needs caller's callsite 5232N/A // This needs to be a long call since we will relocate this adapter to 5232N/A // the codeBuffer and it may not reach 5053N/A // Allocate argument register save area 5232N/A // De-allocate argument register save area // Before we get into the guts of the C2I adapter, see if we should be here // at all. We've come from compiled code and are attempting to jump to the // interpreter, which means the caller made a static call to get here // (vcalls always get a compiled target if there is one). Check for a // compiled target. If there is one, we need to patch the caller's call. // Since all args are passed on the stack, total_args_passed * // Interpreter::stackElementSize is the space we need. Plus 1 because // we also account for the return address location since // we store it first rather than hold it in rax across all the shuffling // stack is aligned, keep it that way // Store the return address in the expected location // Now write the args into the outgoing interpreter space // offset to start parameters // However to make thing extra confusing. Because we can fit a long/double in // a single slot on a 64 bt vm and it would be silly to break them up, the interpreter // leaves one slot empty and only stores to a single slot. In this case the // slot that is occupied is the T_VOID slot. See I said it was confusing. // memory to memory use rax // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG // T_DOUBLE and T_LONG use two slots in the interpreter // ld_off == LSW, ld_off+wordSize == MSW // st_off == MSW, next_off == LSW // Overwrite the unused slot with known junk // must be only an int (or less ) so move only 32bits to slot // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG // T_DOUBLE and T_LONG use two slots in the interpreter // Overwrite the unused slot with known junk // only a float use just part of the slot // Overwrite the unused slot with known junk // Schedule the branch target address early. // Note: r13 contains the senderSP on entry. We must preserve it since // we may do a i2c -> c2i transition if we lose a race where compiled // code goes non-entrant while we get args ready. // In addition we use r13 to locate all the interpreter args as // we must align the stack to 16 bytes on an i2c entry else we // lose alignment we expect in all compiled code and register // save code can segv when fxsave instructions find improperly // aligned stack pointer. // Pick up the return address // Must preserve original SP for loading incoming arguments because // we need to align the outgoing SP for compiled code. // Cut-out for having no stack args. Since up to 2 int/oop args are passed // in registers, we will occasionally have no stack args. // Sig words on the stack are greater-than VMRegImpl::stack0. Those in // registers are below. By subtracting stack0, we either get a negative // number (all values in registers) or the maximum stack slot accessed. // Convert 4-byte c2 stack slots to words. // Round up to miminum stack alignment, in wordSize // Ensure compiled code always sees stack at proper alignment // push the return address and misalign the stack that youngest frame always sees // as far as the placement of the call instruction // Put saved SP in another register // Will jump to the compiled code just as if compiled code was doing it. // Pre-load the register-jump target early, to schedule it better. // Now generate the shuffle code. Pick up all register args and move the // rest through the floating point stack top. // Longs and doubles are passed in native word order, but misaligned // Pick up 0, 1 or 2 words from SP+offset. "scrambled load targets?");
// Load in argument order going down. // Point to interpreter value (vs. tag) // Convert stack slot to an SP offset (+ wordSize to account for return address ) // We can use r13 as a temp here because compiled code doesn't need r13 as an input // and if we end up going thru a c2i because of a miss a reasonable value of r13 // We are using two optoregs. This can be either T_OBJECT, T_ADDRESS, T_LONG, or T_DOUBLE // the interpreter allocates two slots but only uses one for thr T_LONG or T_DOUBLE case // So we must adjust where to pick up the data to match the interpreter. // Interpreter local[n] == MSW, local[n+1] == LSW however locals // are accessed as negative so LSW is at LOW address // ld_off is MSW so get LSW // st_off is LSW (i.e. reg.first()) // We are using two VMRegs. This can be either T_OBJECT, T_ADDRESS, T_LONG, or T_DOUBLE // the interpreter allocates two slots but only uses one for thr T_LONG or T_DOUBLE case // So we must adjust where to pick up the data to match the interpreter. // this can be a misaligned move // sign extend and use a full word? // 6243940 We might end up in handle_wrong_method if // the callee is deoptimized as we race thru here. If that // happens we don't want to take a safepoint because the // caller frame will look interpreted and arguments are now // "compiled" so it is much better to make this transition // invisible to the stack walking code. Unfortunately if // we try and find the callee by normal means a safepoint // is possible. So we stash the desired callee in the thread // and the vm will find there should this case occur. // put methodOop where a c2i would expect should we end up there // only needed becaus eof c2 resolve stubs return methodOop as a result in // --------------------------------------------------------------- // ------------------------------------------------------------------------- // Generate a C2I adapter. On entry we know rbx holds the methodOop during calls // to the interpreter. The args start out packed in the compiled layout. They // need to be unpacked into the interpreter layout. This will almost always // require some stack space. We grow the current (compiled) stack, then repack // the args. We finally end in a jump to the generic interpreter entry point. // On exit from the interpreter, the interpreter will restore our SP (lest the // compiled code, which relys solely on SP and not RBP, get sick). // Method might have been compiled since the call site was patched to // interpreted if that is the case treat it as a miss so we can get // the call site corrected. // We return the amount of VMRegImpl stack slots we need to reserve for all // the arguments NOT counting out_preserve_stack_slots. // NOTE: These arrays will have to change when c1 is ported // Allocate slots for callee to stuff register args the stack. // Allocate slots for callee to stuff register args the stack. // Allocate slots for callee to stuff register args the stack. case T_VOID:
// Halves of longs and doubles // windows abi requires that we always allocate enough stack space // for 4 64bit registers to be stored down. // On 64 bit we will store integer like items to the stack as // 64 bits items (sparc abi) even though java would only store // 32bits for a parameter. On 32bit it will simply be 32 bits // So this routine will do 32->32 on 32bit and 32->64 on 64bit // Do we really have to sign extend??? // __ movslq(src.first()->as_Register(), src.first()->as_Register()); // Do we really have to sign extend??? // __ movslq(dst.first()->as_Register(), src.first()->as_Register()); // An oop arg. Must pass a handle not the oop itself // must pass a handle. First figure out the location we use as a handle // See if oop is NULL if it is we need no handle // Oop is already on the stack as an argument // conditionally move a NULL // Oop is in an a register we must store it to the space we reserve // on the stack for oop_handles and pass a handle if oop is non-NULL // Store oop in handle area, may be NULL // conditionally move a NULL from the handle area where it was just stored // If arg is on the stack then place it otherwise it is already in correct reg. // A float arg may have to do float reg int reg conversion // The calling conventions assures us that each VMregpair is either // all really one physical register or adjacent stack slots. // This greatly simplifies the cases here compared to sparc. // In theory these overlap but the ordering is such that this is likely a nop // The calling conventions assures us that each VMregpair is either // all really one physical register or adjacent stack slots. // This greatly simplifies the cases here compared to sparc. // The calling conventions assures us that each VMregpair is either // all really one physical register or adjacent stack slots. // This greatly simplifies the cases here compared to sparc. // In theory these overlap but the ordering is such that this is likely a nop // We always ignore the frame_slots arg and just use the space just below frame pointer // which by this time is free to use // We always ignore the frame_slots arg and just use the space just below frame pointer // which by this time is free to use // --------------------------------------------------------------------------- // Generate a native wrapper for a given method. The method takes arguments // in the Java compiled code convention, marshals them to the native // convention (handlizes oops, etc), transitions to native, makes the call, // returns to java state (possibly blocking), unhandlizes any result and // Native nmethod wrappers never take possesion of the oop arguments. // So the caller will gc the arguments. The only thing we need an // oopMap for is if the call is static // An OopMap for lock (and class if static) // We have received a description of where all the java arg are located // on entry to the wrapper. We need to convert these args to where // the jni function will expect them. To figure out where they go // we convert the java signature to a C signature by inserting // the hidden arguments as arg[0] and possibly arg[1] (static method) // Now figure out where the args must be stored and how much stack space // Compute framesize for the wrapper. We need to handlize all oops in // Calculate the total number of stack slots we will need. // First count the abi requirement plus all of the outgoing args // Now the space for the inbound oop handle area // Now any space we need for handlizing a klass if static method // Now a place (+2) to save return values or temp during shuffling // + 4 for return address (which we own) and saved rbp // Ok The space we have allocated will look like: // |---------------------| // |---------------------| // | lock box (if sync) | // |---------------------| <- lock_slot_offset // |---------------------| <- klass_slot_offset // |---------------------| <- oop_handle_offset (6 java arg registers) // |---------------------| // SP-> | out_preserved_slots | // Now compute actual number of stack words we need rounding to make // stack properly aligned. // First thing make an ic check to see if we should even be here // We are free to use all registers as temps without saving them and // restoring them except rbp. rbp is the only callee save register // as far as the interpreter and the compiler(s) are concerned. // Verified entry point must be aligned // The instruction at the verified entry point must be 5 bytes or longer // because it can be patched on the fly by make_non_entrant. The stack bang // instruction fits that requirement. // Generate stack overflow check // need a 5 byte instruction to allow MT safe patching to non-entrant // Generate a new frame for the wrapper. // -2 because return address is already present and so is saved rbp // Frame is now completed as far as size and linkage. __ andptr(
rax, -
16);
// must be 16 byte boundary (see amd64 ABI) __ stop(
"improperly aligned stack");
// It is callee save so it survives the call to native // We immediately shuffle the arguments so that any vm call we have to // make from here on out (sync slow path, jvmti, etc.) we will have // captured the oops from our caller and have a valid oopMap for // The Java calling convention is either equal (linux) or denser (win64) than the // c calling convention. However the because of the jni_env argument the c calling // convention always has at least one more (and two for static) arguments than Java. // Therefore if we move the args from java -> c backwards then we will never have // a register->register conflict and we don't have to build a dependency graph // and figure out how to break any cycles. // Record esp-based slot for receiver on stack for non-static methods // This is a trick. We double the stack slots so we can claim // the oops in the caller's frame. Since we are sure to have // more args than the caller doubling is enough to make // sure we can capture all the incoming oop args from the // Mark location of rbp (someday) // map->set_callee_saved(VMRegImpl::stack2reg( stack_slots - 2), stack_slots * 2, 0, vmreg(rbp)); // Use eax, ebx as temporaries during any memory-memory moves we have to do // All inbound args are referenced based on rbp and all outbound args via rsp. // point c_arg at the first arg that is already loaded in case we // need to spill before we call out // Pre-load a static method's oop into r14. Used both by locking code and // the normal JNI call code. // load oop into a register // Now handlize the static class mirror it's known not-null. // store the klass handle as second argument // and protect the arg if we must spill // Change state to native (we save the return address in the thread, since it might not // be pushed on the stack when we do a a stack traversal). It is enough that the pc() // points into the right code segment. It does not have to be the correct return pc. // We use the same pc/oopMap repeatedly when we call out // We have all of the arguments setup at this point. We must not touch any register // argument registers at this point (what if we save/restore them there are no oop? // protect the args we've loaded // RedefineClasses() tracing support for obsolete method entry // protect the args we've loaded // Lock a synchronized method // Register definitions used by locking and unlocking // Get the handle (the 2nd argument) // Get address of the box // Load the oop from the handle // Load immediate 1 into swap_reg %rax // Load (object->mark() | 1) into swap_reg %rax // Save (object->mark() | 1) into BasicLock's displaced header // src -> dest iff dest == rax else rax <- dest // Hmm should this move to the slow path code area??? // Test if the oopMark is an obvious stack pointer, i.e., // 1) (mark & 3) == 0, and // 2) rsp <= mark < mark + os::pagesize() // These 3 tests can be done by evaluating the following // expression: ((mark - rsp) & (3 - os::vm_page_size())), // assuming both stack pointer and pagesize have their // least significant 2 bits clear. // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg // Save the test result, for recursive case, the result is zero // Slow path will re-enter here // Finally just about ready to make the JNI call // get JNIEnv* which is first argument to native // Now set thread in native // Either restore the MXCSR register after returning from the JNI Call // or verify that it wasn't changed. // Unpack native results. case T_INT :
/* nothing to do */ break;
// Result is in xmm0 we'll save as needed break;
// can't de-handlize until after safepoint check // Switch thread to "native transition" state before reading the synchronization state. // This additional state is necessary because reading and testing the synchronization // state is not atomic w.r.t. GC, as this scenario demonstrates: // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted. // VM thread changes sync state to synchronizing and suspends threads for GC. // Thread A is resumed to finish this native method, but doesn't block here since it // didn't see any synchronization is progress, and escapes. // Force this write out before the read below // Write serialization page so VM thread can do a pseudo remote membar. // We use the current thread pointer to calculate a thread specific // offset to write to within the page. This minimizes bus traffic // due to cache line collision. // check for safepoint operation in progress and/or pending suspend requests // Don't use call_VM as it will see a possible pending exception and forward it // and never return here preventing us from clearing _last_native_pc down below. // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are // preserved and correspond to the bcp/locals pointers. So we do a runtime call // Restore any method result value // native result if any is live // Get locked oop from the handle we passed to jni // Simple recursive lock? // Must save rax if if it is live now because cmpxchg must use it // get address of the stack lock // get old displaced header // Atomic swap old header if oop still contains the stack lock // slow path re-enters here // Any exception pending? // Unexpected paths are out of line and go here // and forward the exception // Slow path locking & unlocking // has last_Java_frame setup. No exceptions so do vanilla call not call_VM // args are (oop obj, BasicLock* lock, JavaThread* thread) // protect the args we've loaded // Not a leaf but we have last_Java_frame setup as we want __ stop(
"no pending exception allowed on exit from monitorenter");
// BEGIN Slow path unlock // If we haven't already saved the native result we must save it now as xmm registers // Save pending exception around call to VM (which contains an EXCEPTION_MARK) // NOTE that obj_reg == rbx currently __ stop(
"no pending exception allowed on exit complete_monitor_unlocking_C");
// SLOW PATH Reguard the stack if needed // --------------------------------------------------------------------------- // Generate a dtrace nmethod for a given signature. The method takes arguments // in the Java compiled code convention, marshals them to the native // abi and then leaves nops at the position you would expect to call a native // function. When the probe is enabled the nops are replaced with a trap // instruction that dtrace inserts and the trace will cause a notification // The probes are only able to take primitive types and java/lang/String as // arguments. No other java types are allowed. Strings are converted to utf8 // strings so that from dtrace point of view java strings are converted to C // strings. There is an arbitrary fixed limit on the total space that a method // can use for converting the strings. (256 chars per string in the signature). // So any java string larger then this is truncated. // generate_dtrace_nmethod is guarded by a mutex so we are sure to // be single threaded in this method. // Fill in the signature array, for the calling-convention call. // The signature we are going to use for the trap that dtrace will see // is converted to NULL. (A one-slot java/lang/Long object reference // is converted to a two-slot long, which is why we double the allocation). // Skip the receiver as dtrace doesn't want to see it // We need to convert the java args to where a native (non-jni) function // would expect them. To figure out where they go we convert the java // signature to a C signature. in_sig_bt[i++] =
bt;
// Collect remaining bits of signature // We convert double to long // We convert float to int // Now get the compiled-Java layout as input arguments // Now figure out where the args must be stored and how much stack space // they require (neglecting out_preserve_stack_slots but space for storing // the 1st six register arguments). It's weird see int_stk_helper. // Calculate the total number of stack slots we will need. // First count the abi requirement plus all of the outgoing args // Now space for the string(s) we must convert // Plus the temps we might need to juggle register args // regs take two slots each // + 4 for return address (which we own) and saved rbp, // Ok The space we have allocated will look like: // |---------------------| // |---------------------| <- string_locs[n] // |---------------------| <- string_locs[n-1] // |---------------------| <- string_locs[1] // |---------------------| <- string_locs[0] // |---------------------| // SP-> | out_preserved_slots | // Now compute actual number of stack words we need rounding to make // stack properly aligned. // First thing make an ic check to see if we should even be here // We are free to use all registers as temps without saving them and // restoring them except rbp. rbp, is the only callee save register // as far as the interpreter and the compiler(s) are concerned. // verified entry must be aligned for code patching. // and the first 5 bytes must be in the same cache line // if we align at 8 then we will be sure 5 bytes are in the same line // The instruction at the verified entry point must be 5 bytes or longer // because it can be patched on the fly by make_non_entrant. The stack bang // instruction fits that requirement. // Generate stack overflow check // need a 5 byte instruction to allow MT safe patching to non-entrant "valid size for make_non_entrant");
// Generate a new frame for the wrapper. // -4 because return address is already present and so is saved rbp, // Frame is now completed as far a size and linkage. // State of input register args // All args (except strings) destined for the stack are moved first // Get the real reg value or a dummy (rsp) // Even though a string arg in a register is still live after this loop // after the string conversion loop (next) it will be dead so we take // advantage of that now for simpler code to manage live. // need to unbox a one-word value ++
c_arg;
// skip over T_VOID to keep the loop indices in sync // Convert the arg to NULL // This does the right thing since we know it is destined for the // This does the right thing since we know it is destined for the // If we have any strings we must store any register based arg to the stack // This includes any still live xmm registers too. // string oops were left untouched by the previous loop even if the // eventual (converted) arg is destined for the stack so park them // away now (except for first) // The first string arg won't be killed until after the utf8 // Convert the xmm register to an int and store it in the reserved // location for the eventual c register arg // If the arg is an oop type we don't support don't bother to store // it remember string was handled above. ++
c_arg;
// skip over T_VOID to keep the loop indices in sync // Now that the volatile registers are safe, convert all the strings // The first string we find might still be in the original java arg // We will need to eventually save the final argument to the trap // in the von-volatile location dedicated to src. This is the offset // This is where the argument will eventually reside // arg is still in the original location // see if the oop is NULL // Save the ptr to utf string in the origina src loc or the tmp ++
c_arg;
// skip over T_VOID to keep the loop indices in sync // The get_utf call killed all the c_arg registers // Now we can finally move the register args to their desired locations // Only need to look for args destined for the interger registers (since we // Check if the java arg is unsupported and thereofre useless // If we're going to kill an existing arg save it first // you can't kill yourself // If the arg is an oop type we don't support don't bother to store // full sized move even for int should be ok // At this point r has the original java arg in the final location // (assuming it wasn't useless). If the java arg was an oop // we have a bit more to do // need to unbox a one-word value // Convert the arg to NULL // dst can longer be holding an input value ++
c_arg;
// skip over T_VOID to keep the loop indices in sync // Ok now we are done. Need to place the nop that dtrace wants in order to // this function returns the adjust size (in number of words) to a c2i adapter // activation for use during deoptimization //------------------------------generate_deopt_blob---------------------------- // Allocate space for the code // Setup code generation tools // This code enters when returning to a de-optimized nmethod. A return // address has been pushed on the the stack, and return values are in // If we are doing a normal deopt then we were called from the patched // nmethod from the point we returned to the nmethod. So the return // address on the stack is wrong by NativeCall::instruction_size // We will adjust the value so it looks like we have the original return // address on the stack (like when we eagerly deoptimized). // In the case of an exception pending when deoptimizing, we enter // with a return address on the stack that points after the call we patched // into the exception handler. We have the following register state from, // rbx: exception handler // So in this case we simply jam rdx into the useless return address and // the stack looks just like we want. // At this point we need to de-opt. We save the argument return // registers. We call the first C routine, fetch_unroll_info(). This // routine captures the return values and returns a structure which // describes the current frame size and the sizes of all replacement frames. // The current frame is compiled code and may contain many inlined // functions, each with their own JVM state. We pop the current frame, then // push all the new frames. Then we call the C routine unpack_frames() to // populate these frames. Finally unpack_frames() returns us the new target // address. Notice that callee-save registers are BLOWN here; they have // already been captured in the vframeArray at the time the return PC was // Prolog for non exception case! // Save everything in sight. // Normal deoptimization. Save exec mode for unpack_frames. // return address is the pc describes what bci to do re-execute at // No need to update map as each call to save_live_registers will produce identical oopmap // Prolog for exception case // all registers are dead at this entry point, except for rax, and // rdx which contain the exception oop and exception pc // respectively. Set them in TLS and fall thru to the // unpack_with_exception_in_tls entry point. // new implementation because exception oop is now passed in JavaThread // Prolog for exception case // All registers must be preserved because they might be used by LinearScan // Exceptiop oop and throwing PC are passed in JavaThread // tos: stack at point of call to method that threw the exception (i.e. only // args are on the stack, no return address) // make room on stack for the return address // It will be patched later with the throwing pc. The correct value is not // available now because loading it from memory would destroy registers. // Save everything in sight. // Now it is safe to overwrite any register // Deopt during an exception. Save exec mode for unpack_frames. // load throwing pc from JavaThread and patch it as the return address // of the current frame. Then clear the field in JavaThread // verify that there is really an exception oop in JavaThread // verify that there is no pending exception __ stop(
"must not have pending exception here");
// Call C code. Need thread and this frame, but NOT official VM entry // crud. We cannot block on this call, no GC can happen. // UnrollBlock* fetch_unroll_info(JavaThread* thread) // fetch_unroll_info needs to call last_java_frame(). __ stop(
"SharedRuntime::generate_deopt_blob: last_Java_fp not cleared");
// Need to have an oopmap that tells fetch_unroll_info where to // find any register it might need. // Load UnrollBlock* into rdi // QQQ this is useless it was NULL above // Overwrite the result registers with the exception results. // I think this is useless // Only register save data is on the stack. // Now restore the result registers. Everything else is either dead // or captured in the vframeArray. // All of the register save area has been popped of the stack. Only the // return address remains. // Frame picture (youngest to oldest) // 1: self-frame (no frame link) // 2: deopting frame (no frame link) // Note: by leaving the return address of self-frame on the stack // and using the size of frame 2 to adjust the stack // when we are done the return to frame 3 will still be on the stack. // rsp should be pointing at the return address to the caller (3) // Stack bang to make sure there's enough room for these interpreter frames. // Load address of array of frame pcs into rcx // Load address of array of frame sizes into rsi // Pick up the initial fp we should save // Now adjust the caller's stack to make up for the extra locals // but record the original sp so that we can save it in the skeletal interpreter // frame and the stack walking of interpreter_sender will get the unextended sp // value and not the "real" sp value. // Push interpreter frames in a loop __ push(
0xDEADDEAD);
// Make a recognizable pattern __ enter();
// Save old & set new ebp // This value is corrected by layout_activation_impl __ enter();
// Save old & set new ebp // Allocate a full sized register save area. // Return address and rbp are in place, so we allocate two less words. // Restore frame locals after moving the frame // Call C code. Need thread but NOT official VM entry // crud. We cannot block on this call, no GC can happen. Call should // restore return values to their stack-slots with the new SP. // void Deoptimization::unpack_frames(JavaThread* thread, int exec_mode) // Use rbp because the frames look interpreted now // Set an oopmap for the call site // I think this is useless (throwing pc?) // Make sure all code is generated //------------------------------generate_uncommon_trap_blob-------------------- // Allocate space for the code // Setup code generation tools // Push self-frame. We get here with a return address on the // stack, so rsp is 8-byte aligned until we allocate our frame. // No callee saved registers. rbp is assumed implicitly saved // compiler left unloaded_class_index in j_rarg0 move to where the // Call C code. Need thread but NOT official VM entry // crud. We cannot block on this call, no GC can happen. Call should // capture callee-saved registers as well as return values. // Thread is in rdi already. // UnrollBlock* uncommon_trap(JavaThread* thread, jint unloaded_class_index); // Set an oopmap for the call site // location of rbp is known implicitly by the frame sender code // Load UnrollBlock* into rdi // Frame picture (youngest to oldest) // 1: self-frame (no frame link) // 2: deopting frame (no frame link) // Pop self-frame. We have no frame, and must rely only on rax and rsp. // Pop deoptimized frame (int) // rsp should be pointing at the return address to the caller (3) // Stack bang to make sure there's enough room for these interpreter frames. // Load address of array of frame pcs into rcx (address*) // Load address of array of frame sizes into rsi (intptr_t*) // Pick up the initial fp we should save // Now adjust the caller's stack to make up for the extra locals but // record the original sp so that we can save it in the skeletal // interpreter frame and the stack walking of interpreter_sender // will get the unextended sp value and not the "real" sp value. // Push interpreter frames in a loop __ enter();
// Save old & set new rbp // This value is corrected by layout_activation_impl __ enter();
// Save old & set new rbp // Use rbp because the frames look interpreted now // Call C code. Need thread but NOT official VM entry // crud. We cannot block on this call, no GC can happen. Call should // restore return values to their stack-slots with the new SP. // Thread is in rdi already. // BasicType unpack_frames(JavaThread* thread, int exec_mode); // Set an oopmap for the call site // Make sure all code is generated //------------------------------generate_handler_blob------ // Generate a special Compile2Runtime blob that saves all registers, "must be generated before");
// Allocate space for the code. Setup code generation tools. // Make room for return address (or push it again) // Save registers, fpu state, and flags // The following is basically a call_VM. However, we need the precise // address of the call in order to generate an oopmap. Hence, we do all the // The return address must always be correct so that frame constructor never // overwrite the dummy value we pushed on entry // Set an oopmap for the call site. This oopmap will map all // oop-registers and debug-info registers as callee-saved. This // will allow deoptimization at this safepoint to find all possible // debug-info recordings, as well as let GC find all oops. // Normal exit, restore registers and exit. // Make sure all code is generated // Fill-out other meta info // Generate a stub that calls into vm to find out the proper destination // of a java call. All the argument registers are live at this point // but since this is generic code we don't know what they are and the caller // must do any gc of the args. // allocate space for the code // Set an oopmap for the call site. // We need this not only for callee-saved registers, but also for volatile // registers that the compiler might be keeping live across a safepoint. // rax contains the address we are going to jump to assuming no exception got installed // check for pending exceptions // get the returned methodOop // We are back the the original state on entry and ready to go. // Pending exception after the safepoint // exception pending => remove activation and forward to exception handler // make sure all code is generated // frame_size_words or bytes?? "resolve_opt_virtual_call");
//------------------------------generate_exception_blob--------------------------- // creates exception blob at the end // Using exception blob, this code is jumped from a compiled method. // (see emit_exception_handler in x86_64.ad file) // Given an exception pc at a call we call into the runtime for the // handler in this method. This handler might merely restore state // (i.e. callee save registers) unwind the frame and jump to the // exception handler for the nmethod if there is no Java level handler // This code is entered with a jmp. // rdx: exception pc in caller or ??? // destination: exception handler of caller // Note: the exception pc MUST be at a call (precise debug information) // Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved. // Allocate space for the code // Setup code generation tools // Exception pc is 'return address' for stack walker // Save callee-saved registers. See x86_64.ad. // rbp is an implicitly saved callee saved register (i.e. the calling // convention will save restore it in prolog/epilog) Other than that // there are no callee save registers now that adapter frames are gone. // Store exception in Thread object. We cannot pass any arguments to the // handle_exception call, since we do not want to make any assumption // about the size of the frame where the exception happened in. // c_rarg0 is either rdi (Linux) or rcx (Windows). // This call does all the hard work. It checks if an exception handler // If so, it returns the handler address. // If not, it prepares for stack-unwinding, restoring the callee-save // registers of the frame being removed. // address OptoRuntime::handle_exception_C(JavaThread* thread) // Set an oopmap for the call site. This oopmap will only be used if we // are unwinding the stack. Hence, all locations will be dead. // Callee-saved registers will be the same as the frame above (i.e., // handle_exception_stub), since they were restored when we got the // Restore callee-saved registers // rbp is an implicitly saved callee saved register (i.e. the calling // convention will save restore it in prolog/epilog) Other than that // there are no callee save registers no that adapter frames are gone. __ pop(
rdx);
// No need for exception pc anymore // rax: exception handler // Restore SP from BP if the exception PC is a MethodHandle call site. // We have a handler in rax (could be deopt blob). // Get the exception pc in case we are deoptimized // Clear the exception oop so GC no longer processes it as a root. // Make sure all code is generated