sharedRuntime_x86_32.cpp revision 4010
0N/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. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A enum {
FPU_regs_live =
8 /*for the FPU stack*/+
8/*eight more for XMM registers*/ };
0N/A // Capture info about frame layout 0N/A // The frame sender code expects that rbp will be in the "natural" place and 0N/A // will override any oopMap setting for it. We must therefore force the layout 0N/A // so that it agrees with the frame sender code. 0N/A // Offsets into the register save area 0N/A // Used by deoptimization when it is managing result register 0N/A // values on its own 0N/A // This really returns a slot in the fp save area, which one is not important 0N/A // During deoptimization only the result register need to be restored 0N/A // all the other values have already been extracted. 0N/A // save registers, fpu state, and flags 0N/A // We assume caller has already has return address slot on the stack 0N/A // We push epb twice in this sequence because we want the real rbp, // to be under the return like a normal enter and we want to use pusha // We push by hand instead of pusing push // Some stubs may have non standard FPU control word settings so // only check and reset the value when it required to be the // standard value. The safepoint blob in particular can be used // in methods which are using the 24 bit control word for // Make sure the control word has the expected value __ stop(
"corrupted control word detected");
// Reset the control word to guard against exceptions being unmasked // since fstp_d can cause FPU stack underflow exceptions. Write it // into the on stack copy and then reload that to make sure that the // current and future values are correct. // Set the control word so that exceptions are masked for the // Save the FPU registers in de-opt-able form if(
UseSSE ==
1 ) {
// Save the XMM state // 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. // rbp, location is known implicitly, no oopMap // %%% This is really a waste but we'll keep things as they were for now // Recover XMM & FPU state // Get the rbp, described implicitly by the frame sender code (no oopMap) // Just restore result register. Only used by deoptimization. By // now any callee save register that needs to be restore to a c2 // caller of the deoptee has been extracted into the vframeArray // and will be stuffed into the c2i adapter we create for later // restoration so only result registers need to be restored here. // Recover XMM & FPU state // Pop all of the register save are off the stack except the return address // The java_calling_convention describes stack locations as ideal slots on // a frame with no abi restrictions. Since we must observe abi restrictions // (like the placement of the register window) the slots must be biased by // Account for saved rbp, and return address // This should really be in_preserve_stack_slots // --------------------------------------------------------------------------- // Read the array of BasicTypes from a signature, and compute where the // arguments should go. Values in the VMRegPair regs array refer to 4-byte // quantities. Values less than SharedInfo::stack0 are registers, those above // refer to 4-byte stack slots. All stack slots are based off of the stack pointer // as framesizes are fixed. // VMRegImpl::stack0 refers to the first slot 0(sp). // and VMRegImpl::stack0+1 refers to the memory word 4-byes higher. Register // up to RegisterImpl::number_of_registers) are the 32-bit // Pass first two oop/int args in registers ECX and EDX. // Pass first two float/double args in registers XMM0 and XMM1. // Doubles have precedence, so if you pass a mix of floats and doubles // the doubles will grab the registers before the floats will. // Note: the INPUTS in sig_bt are in units of Java argument words, which are // either 32-bit or 64-bit depending on the build. The OUTPUTS are in 32-bit // units regardless of build. Of course for i486 there is no 64 bit build // --------------------------------------------------------------------------- // The compiled Java calling convention. // Pass first two oop/int args in registers ECX and EDX. // Pass first two float/double args in registers XMM0 and XMM1. // Doubles have precedence, so if you pass a mix of floats and doubles // the doubles will grab the registers before the floats will. uint stack = 0;
// Starting stack position for args on stack // Pass first two oop/int args in registers ECX and EDX. // Pass first two float/double args in registers XMM0 and XMM1. // Doubles have precedence, so if you pass a mix of floats and doubles // the doubles will grab the registers before the floats will. // CNC - TURNED OFF FOR non-SSE. // On Intel we have to round all doubles (and most floats) at // call sites by storing to the stack in any case. // UseSSE=0 ==> Don't Use ==> 9999+0 // UseSSE=1 ==> Floats only ==> 9999+1 // UseSSE>=2 ==> Floats or doubles ==> 9999+2 // Pass doubles & longs aligned on the stack. First count stack slots for doubles // first 2 doubles go in registers else // Else double is passed low on the stack to be aligned. int dstack = 0;
// Separate counter for placing doubles // Now pick where all else goes. // From the type and the argument number (count) compute the location // return value can be odd number of VMRegImpl stack slots make multiple of 2 // Patch the callers callsite with entry to compiled code if it exists. // Schedule the branch target address early. // Call into the VM to patch the caller, then jump to compiled callee // rax, isn't live so capture return address while we easily can // C2 may leave the stack dirty if not in SSE2+ mode __ verify_FPU(0,
"c2i transition should have clean FPU stack");
// VM needs caller's callsite // VM needs target method // 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. // C2 may leave the stack dirty if not in SSE2+ mode __ verify_FPU(0,
"c2i transition should have clean FPU stack");
// Since all args are passed on the stack, total_args_passed * interpreter_ // stack_element_size is the // Now write the args into the outgoing interpreter space // st_off points to lowest address on stack. // memory to memory use fpu stack top // ld_off == LSW, ld_off+VMRegImpl::stack_slot_size == MSW // st_off == MSW, st_off-wordSize == LSW // Overwrite the unused slot with known junk // Two VMRegs 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 // Schedule the branch target address early. // And repush original return address // Note: rsi 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. // Adapters can be frameless because they do not require the caller // to perform additional cleanup work, such as correcting the stack pointer. // An i2c adapter is frameless because the *caller* frame, which is interpreted, // routinely repairs its own stack pointer (from interpreter_frame_last_sp), // even if a callee has modified the stack pointer. // A c2i adapter is frameless because the *callee* frame, which is interpreted, // routinely repairs its caller's stack pointer (from sender_sp, which is set // up via the senderSP register). // In other words, if *either* the caller or callee is interpreted, we can // get the stack pointer repaired after a call. // This is why c2i and i2c adapters cannot be indefinitely composed. // In particular, if a c2i adapter were to somehow call an i2c adapter, // both caller and callee would be compiled methods, and neither would // clean up the stack pointer changes performed by the two adapters. // If this happens, control eventually transfers back to the compiled // caller, but with an uncorrected stack, causing delayed havoc. // Pick up the return address // So, let's test for cascading c2i/i2c adapters right now. // assert(Interpreter::contains($return_addr) || // StubRoutines::contains($return_addr), // "i2c adapter must return to an interpreter frame"); const char*
msg =
"i2c adapter must return to an interpreter frame";
// 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. // int comp_args_on_stack = VMRegImpl::reg2stack(max_arg); // Convert 4-byte stack slots to words. // Round up to miminum stack alignment, in wordSize // push the return address on the stack (note that pushing, rather // than storing it, yields the correct frame alignment for the callee) // 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 rsi as a temp here because compiled code doesn't need rsi as an input // and if we end up going thru a c2i because of a miss a reasonable value of rsi // __ fld_s(Address(saved_sp, ld_off)); // __ fstp_s(Address(rsp, st_off)); // 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()) // __ fld_d(Address(saved_sp, next_off)); // __ fstp_d(Address(rsp, st_off)); // 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. // 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 // 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 // Remember r_1 is low address (and LSB on x86) // So r_2 gets loaded from high address regardless of the platform // 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. // move methodOop to rax, in case we end up in an c2i adapter. // the c2i adapters expect methodOop in rax, (c2) because c2's // resolve stubs return the result (the method) in rax,. // --------------------------------------------------------------- // ------------------------------------------------------------------------- // 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 EBP, 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. // From the type and the argument number (count) compute the location case T_DOUBLE:
// The stack numbering is reversed from Java // Since C arguments do not get reversed, the ordering for // doubles on the stack must be opposite the Java convention // A simple move of integer like type // __ ld(FP, reg2offset(src.first()) + STACK_BIAS, L5); // __ st(L5, SP, reg2offset(dst.first()) + STACK_BIAS); // no need to sign extend on 64bit // An oop arg. Must pass a handle not the oop itself // Because of the calling conventions we know that src can be a // register or a stack location. dst can only be a stack location. // must pass a handle. First figure out the location we use as a handle // Oop is already on the stack as an argument // Oop is in an a register we must store it to the space we reserve // on the stack for oop_handles // Store the handle parameter // A float arg may have to do float reg int reg conversion // Because of the calling convention we know that src is either a stack location // or an xmm register. dst can only be a stack location. // The only legal possibility for a long_move VMRegPair is: // 1: two stack slots (possibly unaligned) // as neither the java or C calling convention will use registers // The only legal possibilities for a double_move VMRegPair are: // The painful thing here is that like long_move a VMRegPair might be // Because of the calling convention we know that src is either // 1: a single physical register (xmm registers only) // 2: two stack slots (possibly unaligned) // dst can only be a pair of stack slots. // No worries about stack alignment // 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 // if map is non-NULL then the code should store the values, // otherwise it should load them. // Save down double word first // Save or restore single word registers // Value is in an input register pass we must flush it to the stack // Check GC_locker::needs_gc and enter the runtime if it's true. This // keeps a new JNI critical region from starting until a GC has been // forced. Save down any oops in registers and describe them in an // Save down any incoming oops and call into the runtime to halt for a GC // Stress register saving // Destroy argument registers // Unpack an array argument into a pointer to the body and the length // if the array is non-null, otherwise pass 0 for both. // Pass the length, ptr pair // Load the arg up from the stack // load the length relative to the body. // Now write the args into the outgoing interpreter space // Load the member_arg into register, if necessary. // no data motion is needed // Make sure the receiver is loaded into a register. // Porting note: This assumes that compiled calling conventions always // pass the receiver oop in a register. If this is not true on some // platform, pick a temp and load the receiver from stack. fatal(
"receiver always in a register");
// no data motion is needed // Figure out which address we are really jumping to: // --------------------------------------------------------------------------- // 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 // Critical native functions are a shorthand for the use of // GetPrimtiveArrayCritical and disallow the use of any other JNI // functions. The wrapper is expected to unpack the arguments before // passing them to the callee and perform checks before and after the // native call to ensure that they GC_locker // parts of JNI setup are skipped like the tear down of the JNI handle // block and the check for pending exceptions it's impossible for them // They are roughly structured like this: // if (GC_locker::needs_gc()) // SharedRuntime::block_for_jni_critical(); // tranistion to thread_in_native // unpack arrray arguments and call native entry point // check for safepoint in progress // check if any thread suspend flags are set // call into JVM and possible unlock the JNI critical // if a GC was suppressed while in the critical native. // transition back to thread_in_Java // 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) // Arrays are passed as int, elem* pair // 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 // registers a max of 2 on x86. // 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 // Critical natives may have to call out so they need a save area // for register arguments. case T_ARRAY:
// critical array (uses 2 slots on LP64) // Now any space we need for handlizing a klass if static method // Now a place (+2) to save return values or temp during shuffling // + 2 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 (-lock_slot_rbp_offset) // |---------------------| <- klass_slot_offset // |---------------------| <- oop_handle_offset (a max of 2 registers) // |---------------------| // SP-> | out_preserved_slots | // **************************************************************************** // WARNING - on Windows Java Natives use pascal calling convention and pop the // arguments off of the stack after the jni call. Before the call we can use // instructions that are SP relative. After the jni call we switch to FP // relative instructions instead of re-adjusting the stack on windows. // **************************************************************************** // 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 // Object.hashCode can pull the hashCode from the header word // instead of doing a full VM transition once it's been computed. // Since hashCode is usually polymorphic at call sites we can't do // this optimization at the call site without a lot of work. // Check if biased and fall through to runtime if so // test if hashCode exists // 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. // Calculate the difference between rsp and rbp,. We need to know it // after the native call because on windows Java Natives will pop // the arguments and it is painful to do rsp relative addressing // in a platform independent way. So after the call we switch to // rbp, relative addressing. // C2 may leave the stack dirty if not in SSE2+ mode __ verify_FPU(0,
"c2i transition should have clean FPU stack");
// Compute the rbp, offset for any slots used after the jni call // We use rdi as a thread pointer because it is callee save and // if we load it once it is usable thru the entire wrapper // 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 // Natives require 1 or 2 extra arguments over the normal ones: the JNIEnv* // and, if static, the class mirror instead of a receiver. This pretty much // guarantees that register layout will not match (and x86 doesn't use reg // parms though amd does). Since the native abi doesn't use register args // and the java conventions does we don't have to worry about collisions. // All of our moved are reg->stack or stack->stack. // We ignore the extra arguments during the shuffle and handle them at the // last moment. The shuffle is described by the two calling convention // vectors we have in our possession. We simply walk the java vector to // get the source locations and the c vector to get the destinations. // Record rsp-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 // map->set_callee_saved(VMRegImpl::stack2reg( stack_slots - 2), stack_slots * 2, 0, rbp->as_VMReg()); // We know that we only have args in at most two integer registers (rcx, rdx). So rax, rbx // Are free to temporaries if we have to do stack to steck moves. // All inbound args are referenced based on rbp, and all outbound args via rsp. // Pre-load a static method's oop into rsi. Used both by locking code and // the normal JNI call code. // load opp into a register // Now handlize the static class mirror it's known not-null. // store the klass handle as second argument // 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? // RedefineClasses() tracing support for obsolete method entry // Lock a synchronized method // Get the handle (the 2nd argument) // Get address of the box // Load the oop from the handle // Note that oop_handle_reg is trashed during this call // 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 // *obj_reg = lock_reg iff *obj_reg == rax, else rax, = *(obj_reg) // 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 // Re-fetch oop_handle_reg as we trashed it above // Finally just about ready to make the JNI call // get JNIEnv* which is first argument to native // Now set thread in native // WARNING - on Windows Java Natives use pascal calling convention and pop the // arguments off of the stack. We could just re-adjust the stack pointer here // and continue to do SP relative addressing but we instead switch to FP // Unpack native results. case T_INT :
/* nothing to do */ break;
// Result is in st0 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. // Make sure the control word is correct. // 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 // The call above performed the transition to thread_in_Java so // skip the transition logic below. // slow path reguard re-enters here // Handle possible exception (will unlock if necessary) // 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 old displaced header // get address of the stack lock // Atomic swap old header if oop still contains the stack lock // src -> dest iff dest == rax, else rax, <- dest // *obj_reg = rbx, iff *obj_reg == rax, else rax, = *(obj_reg) // slow path re-enters here // Tell dtrace about this method exit // We can finally stop using that last_Java_frame we setup ages ago // Any exception pending? // no exception, we're almost done // check that only result value is on FPU stack // Fixup floating pointer results so that result looks like a return from a compiled method // Pop st0 and store as float and reload into xmm register // Pop st0 and store as double and reload into xmm register // Unexpected paths are out of line and go here // 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) __ stop(
"no pending exception allowed on exit from monitorenter");
// BEGIN Slow path unlock // Save pending exception around call to VM (which contains an EXCEPTION_MARK) // +wordSize because of the push above __ stop(
"no pending exception allowed on exit complete_monitor_unlocking_C");
// SLOW PATH Reguard the stack if needed // BEGIN EXCEPTION PROCESSING // remove possible return value from FPU register stack // and forward the exception // --------------------------------------------------------------------------- // 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). // 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 // 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). // 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 // + 2 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. // -2 because return address is already present and so is saved rbp, // Frame is now completed as far a size and linkage. // First thing we do store all the args as if we are doing the call. // Since the C calling convention is stack based that ensures that // all the Java register args are stored before we need to convert any "stack based abi assumed");
// Any register based arg for a java string after the first // will be destroyed by the call to get_utf so we store // the original value in the location the utf string address // will eventually be stored. // need to unbox a one-word value "value(s) must go into stack slots");
// Convert the arg to NULL ++
c_arg;
// Move over the T_VOID To keep the loop indices in sync // Now we must convert any string we have to utf8 // The first string we find might still be in the original java arg // This is where the argument will eventually reside // Get the copy of the jls object // arg is still in the original location // Now we can store the address of the utf string as the argument ++
c_arg;
// Move over the 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 // Account for the extra args we place on the stack // by the time we call fetch_unroll_info // 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 to it looks like we have the original return // address on the stack (like when we eagerly deoptimized). // In the case of an exception pending with deoptimized then 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: // 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. // 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. // No need to update map as each call to save_live_registers will produce identical oopmap // Now it is safe to overwrite any register // store the correct deoptimization type // 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");
// Compiled code leaves the floating point stack dirty, empty it. // Call C code. Need thread and this frame, but NOT official VM entry // crud. We cannot block on this call, no GC can happen. // fetch_unroll_info needs to call last_java_frame() // Need to have an oopmap that tells fetch_unroll_info where to // find any register it might need. // Discard arg to fetch_unroll_info // Load UnrollBlock into EDI // Move the unpack kind to a safe place in the UnrollBlock because // we are very short of registers // retrieve the deopt kind from where we left it. // Overwrite the result registers with the exception results. // Stack is back to only having register save data on the stack. // Now restore the result registers. Everything else is either dead or captured // Non standard control word may be leaked out through a safepoint blob, and we can // deopt at a poll point with the non standard control word. However, we should make // sure the control word is correct after restore_result_registers. // 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. // sp 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 array of frame pcs into ECX // Load array of frame sizes into ESI // 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 rbp, rbx);
// Make it walkable // This value is corrected by layout_activation_impl __ enter();
// save old & set new rbp, // Return address and rbp, are in place // We'll push additional args later. Just allocate a full sized // Restore frame locals after moving the frame // Set up the args to unpack_frame // set last_Java_sp, last_Java_fp // 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. // Set an oopmap for the call site // rax, contains the return result type // Clear floating point stack before returning to interpreter // Check if we should push the float or double return value. // return float value as expected by interpreter // return double value as expected by interpreter // make sure all code is generated //------------------------------generate_uncommon_trap_blob-------------------- // allocate space for the code // setup code generation tools arg0_off,
// thread sp + 0 // Arg location for arg1_off,
// unloaded_class_index sp + 1 // calling C // The frame sender code expects that rbp will be in the "natural" place and // will override any oopMap setting for it. We must therefore force the layout // so that it agrees with the frame sender code. rbp_off,
// callee saved register sp + 2 // 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. // Clear the floating point exception stack // 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. // argument already in ECX // Set an oopmap for the call site // No oopMap for rbp, it is known implicitly // Load UnrollBlock into EDI // 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 EAX and ESP. // sp 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 array of frame pcs into ECX // Load array of frame sizes into ESI // 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 __ push(
0xDEADDEAD);
// (parm to RecursiveInterpreter...) __ enter();
// save old & set new rbp, rbx);
// Make it walkable // This value is corrected by layout_activation_impl __ enter();
// save old & set new rbp, // set last_Java_sp, last_Java_fp // 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. // 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, // setup oopmap, and calls safepoint code to stop the compiled code for // Account for thread arg in our frame // allocate space for the code // setup code generation tools // If cause_return is true we are at a poll_return and there is // the return address on the stack to the caller on the nmethod // that is safepoint. We can leave this return on the stack and // effectively complete the return and safepoint in the caller. // Otherwise we push space for a return address that the safepoint // handler will install later to make the stack walking sensible. __ push(
rbx);
// Make room for return address (or push it again) // 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 // Push thread argument and setup last_Java_sp // if this was not a poll_return then we need to correct the return address now. // 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. // Clear last_Java_sp again // Normal exit, register restoring 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??