src/cpu/sparc/vm/sharedRuntime_sparc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 7063628 Sdiff src/cpu/sparc/vm

src/cpu/sparc/vm/sharedRuntime_sparc.cpp

Print this page




 583   void gen_c2i_adapter(int total_args_passed,
 584                               // VMReg max_arg,
 585                               int comp_args_on_stack, // VMRegStackSlots
 586                               const BasicType *sig_bt,
 587                               const VMRegPair *regs,
 588                               Label& skip_fixup);
 589   void gen_i2c_adapter(int total_args_passed,
 590                               // VMReg max_arg,
 591                               int comp_args_on_stack, // VMRegStackSlots
 592                               const BasicType *sig_bt,
 593                               const VMRegPair *regs);
 594 
 595   AdapterGenerator(MacroAssembler *_masm) : masm(_masm) {}
 596 };
 597 
 598 
 599 // Patch the callers callsite with entry to compiled code if it exists.
 600 void AdapterGenerator::patch_callers_callsite() {
 601   Label L;
 602   __ ld_ptr(G5_method, in_bytes(methodOopDesc::code_offset()), G3_scratch);
 603   __ br_null(G3_scratch, false, __ pt, L);
 604   // Schedule the branch target address early.
 605   __ delayed()->ld_ptr(G5_method, in_bytes(methodOopDesc::interpreter_entry_offset()), G3_scratch);
 606   // Call into the VM to patch the caller, then jump to compiled callee
 607   __ save_frame(4);     // Args in compiled layout; do not blow them
 608 
 609   // Must save all the live Gregs the list is:
 610   // G1: 1st Long arg (32bit build)
 611   // G2: global allocated to TLS
 612   // G3: used in inline cache check (scratch)
 613   // G4: 2nd Long arg (32bit build);
 614   // G5: used in inline cache check (methodOop)
 615 
 616   // The longs must go to the stack by hand since in the 32 bit build they can be trashed by window ops.
 617 
 618 #ifdef _LP64
 619   // mov(s,d)
 620   __ mov(G1, L1);
 621   __ mov(G4, L4);
 622   __ mov(G5_method, L5);
 623   __ mov(G5_method, O0);         // VM needs target method


1110 
1111     // 6243940 We might end up in handle_wrong_method if
1112     // the callee is deoptimized as we race thru here. If that
1113     // happens we don't want to take a safepoint because the
1114     // caller frame will look interpreted and arguments are now
1115     // "compiled" so it is much better to make this transition
1116     // invisible to the stack walking code. Unfortunately if
1117     // we try and find the callee by normal means a safepoint
1118     // is possible. So we stash the desired callee in the thread
1119     // and the vm will find there should this case occur.
1120     Address callee_target_addr(G2_thread, JavaThread::callee_target_offset());
1121     __ st_ptr(G5_method, callee_target_addr);
1122 
1123     if (StressNonEntrant) {
1124       // Open a big window for deopt failure
1125       __ save_frame(0);
1126       __ mov(G0, L0);
1127       Label loop;
1128       __ bind(loop);
1129       __ sub(L0, 1, L0);
1130       __ br_null(L0, false, Assembler::pt, loop);
1131       __ delayed()->nop();
1132 
1133       __ restore();
1134     }
1135 
1136 
1137     __ jmpl(G3, 0, G0);
1138     __ delayed()->nop();
1139 }
1140 
1141 // ---------------------------------------------------------------
1142 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1143                                                             int total_args_passed,
1144                                                             // VMReg max_arg,
1145                                                             int comp_args_on_stack, // VMRegStackSlots
1146                                                             const BasicType *sig_bt,
1147                                                             const VMRegPair *regs,
1148                                                             AdapterFingerPrint* fingerprint) {
1149   address i2c_entry = __ pc();
1150 
1151   AdapterGenerator agen(masm);


1185     __ cmp(G3_scratch, R_temp);
1186     __ restore();
1187 #else
1188     __ ld_ptr(G5_method, compiledICHolderOopDesc::holder_klass_offset(), R_temp);
1189     __ verify_oop(R_temp);
1190     __ cmp(G3_scratch, R_temp);
1191 #endif
1192 
1193     Label ok, ok2;
1194     __ brx(Assembler::equal, false, Assembler::pt, ok);
1195     __ delayed()->ld_ptr(G5_method, compiledICHolderOopDesc::holder_method_offset(), G5_method);
1196     __ jump_to(ic_miss, G3_scratch);
1197     __ delayed()->nop();
1198 
1199     __ bind(ok);
1200     // Method might have been compiled since the call site was patched to
1201     // interpreted if that is the case treat it as a miss so we can get
1202     // the call site corrected.
1203     __ ld_ptr(G5_method, in_bytes(methodOopDesc::code_offset()), G3_scratch);
1204     __ bind(ok2);
1205     __ br_null(G3_scratch, false, __ pt, skip_fixup);
1206     __ delayed()->ld_ptr(G5_method, in_bytes(methodOopDesc::interpreter_entry_offset()), G3_scratch);
1207     __ jump_to(ic_miss, G3_scratch);
1208     __ delayed()->nop();
1209 
1210   }
1211 
1212   address c2i_entry = __ pc();
1213 
1214   agen.gen_c2i_adapter(total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
1215 
1216   __ flush();
1217   return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
1218 
1219 }
1220 
1221 // Helper function for native calling conventions
1222 static VMReg int_stk_helper( int i ) {
1223   // Bias any stack based VMReg we get by ignoring the window area
1224   // but not the register parameter save area.
1225   //


1762                                                 int comp_args_on_stack, // in VMRegStackSlots
1763                                                 BasicType *in_sig_bt,
1764                                                 VMRegPair *in_regs,
1765                                                 BasicType ret_type) {
1766 
1767   // Native nmethod wrappers never take possesion of the oop arguments.
1768   // So the caller will gc the arguments. The only thing we need an
1769   // oopMap for is if the call is static
1770   //
1771   // An OopMap for lock (and class if static), and one for the VM call itself
1772   OopMapSet *oop_maps = new OopMapSet();
1773   intptr_t start = (intptr_t)__ pc();
1774 
1775   // First thing make an ic check to see if we should even be here
1776   {
1777     Label L;
1778     const Register temp_reg = G3_scratch;
1779     AddressLiteral ic_miss(SharedRuntime::get_ic_miss_stub());
1780     __ verify_oop(O0);
1781     __ load_klass(O0, temp_reg);
1782     __ cmp(temp_reg, G5_inline_cache_reg);
1783     __ brx(Assembler::equal, true, Assembler::pt, L);
1784     __ delayed()->nop();
1785 
1786     __ jump_to(ic_miss, temp_reg);
1787     __ delayed()->nop();
1788     __ align(CodeEntryAlignment);
1789     __ bind(L);
1790   }
1791 
1792   int vep_offset = ((intptr_t)__ pc()) - start;
1793 
1794 #ifdef COMPILER1
1795   if (InlineObjectHash && method->intrinsic_id() == vmIntrinsics::_hashCode) {
1796     // Object.hashCode can pull the hashCode from the header word
1797     // instead of doing a full VM transition once it's been computed.
1798     // Since hashCode is usually polymorphic at call sites we can't do
1799     // this optimization at the call site without a lot of work.
1800     Label slowCase;
1801     Register receiver             = O0;
1802     Register result               = O0;
1803     Register header               = G3_scratch;
1804     Register hash                 = G3_scratch; // overwrite header value with hash value


2165     // None of the above fast optimizations worked so we have to get into the
2166     // slow case of monitor enter.  Inline a special case of call_VM that
2167     // disallows any pending_exception.
2168     __ mov(Roop, O0);            // Need oop in O0
2169     __ mov(L3_box, O1);
2170 
2171     // Record last_Java_sp, in case the VM code releases the JVM lock.
2172 
2173     __ set_last_Java_frame(FP, I7);
2174 
2175     // do the call
2176     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), relocInfo::runtime_call_type);
2177     __ delayed()->mov(L7_thread_cache, O2);
2178 
2179     __ restore_thread(L7_thread_cache); // restore G2_thread
2180     __ reset_last_Java_frame();
2181 
2182 #ifdef ASSERT
2183     { Label L;
2184     __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O0);
2185     __ br_null(O0, false, Assembler::pt, L);
2186     __ delayed()->nop();
2187     __ stop("no pending exception allowed on exit from IR::monitorenter");
2188     __ bind(L);
2189     }
2190 #endif
2191     __ bind(done);
2192   }
2193 
2194 
2195   // Finally just about ready to make the JNI call
2196 
2197   __ flush_windows();
2198   if (inner_frame_created) {
2199     __ restore();
2200   } else {
2201     // Store only what we need from this frame
2202     // QQQ I think that non-v9 (like we care) we don't need these saves
2203     // either as the flush traps and the current window goes too.
2204     __ st_ptr(FP, SP, FP->sp_offset_in_saved_window()*wordSize + STACK_BIAS);
2205     __ st_ptr(I7, SP, I7->sp_offset_in_saved_window()*wordSize + STACK_BIAS);
2206   }


2281     __ st(G3_scratch, G2_thread, JavaThread::thread_state_offset());
2282     if(os::is_MP()) {
2283       if (UseMembar) {
2284         // Force this write out before the read below
2285         __ membar(Assembler::StoreLoad);
2286       } else {
2287         // Write serialization page so VM thread can do a pseudo remote membar.
2288         // We use the current thread pointer to calculate a thread specific
2289         // offset to write to within the page. This minimizes bus traffic
2290         // due to cache line collision.
2291         __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
2292       }
2293     }
2294     __ load_contents(sync_state, G3_scratch);
2295     __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
2296 
2297     Label L;
2298     Address suspend_state(G2_thread, JavaThread::suspend_flags_offset());
2299     __ br(Assembler::notEqual, false, Assembler::pn, L);
2300     __ delayed()->ld(suspend_state, G3_scratch);
2301     __ cmp(G3_scratch, 0);
2302     __ br(Assembler::equal, false, Assembler::pt, no_block);
2303     __ delayed()->nop();
2304     __ bind(L);
2305 
2306     // Block.  Save any potential method result value before the operation and
2307     // use a leaf call to leave the last_Java_frame setup undisturbed. Doing this
2308     // lets us share the oopMap we used when we went native rather the create
2309     // a distinct one for this pc
2310     //
2311     save_native_result(masm, ret_type, stack_slots);
2312     __ call_VM_leaf(L7_thread_cache,
2313                     CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
2314                     G2_thread);
2315 
2316     // Restore any method result value
2317     restore_native_result(masm, ret_type, stack_slots);
2318     __ bind(no_block);
2319   }
2320 
2321   // thread state is thread_in_native_trans. Any safepoint blocking has already
2322   // happened so we can now change state to _thread_in_Java.
2323 
2324 
2325   __ set(_thread_in_Java, G3_scratch);
2326   __ st(G3_scratch, G2_thread, JavaThread::thread_state_offset());
2327 
2328 
2329   Label no_reguard;
2330   __ ld(G2_thread, JavaThread::stack_guard_state_offset(), G3_scratch);
2331   __ cmp(G3_scratch, JavaThread::stack_guard_yellow_disabled);
2332   __ br(Assembler::notEqual, false, Assembler::pt, no_reguard);
2333   __ delayed()->nop();
2334 
2335     save_native_result(masm, ret_type, stack_slots);
2336   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages));
2337   __ delayed()->nop();
2338 
2339   __ restore_thread(L7_thread_cache); // restore G2_thread
2340     restore_native_result(masm, ret_type, stack_slots);
2341 
2342   __ bind(no_reguard);
2343 
2344   // Handle possible exception (will unlock if necessary)
2345 
2346   // native result if any is live in freg or I0 (and I1 if long and 32bit vm)
2347 
2348   // Unlock
2349   if (method->is_synchronized()) {
2350     Label done;
2351     Register I2_ex_oop = I2;
2352     const Register L3_box = L3;
2353     // Get locked oop from the handle we passed to jni


2365     // save and restore any potential method result value around the unlocking
2366     // operation.  Will save in I0 (or stack for FP returns).
2367     save_native_result(masm, ret_type, stack_slots);
2368 
2369     // Must clear pending-exception before re-entering the VM.  Since this is
2370     // a leaf call, pending-exception-oop can be safely kept in a register.
2371     __ st_ptr(G0, G2_thread, in_bytes(Thread::pending_exception_offset()));
2372 
2373     // slow case of monitor enter.  Inline a special case of call_VM that
2374     // disallows any pending_exception.
2375     __ mov(L3_box, O1);
2376 
2377     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C), relocInfo::runtime_call_type);
2378     __ delayed()->mov(L4, O0);              // Need oop in O0
2379 
2380     __ restore_thread(L7_thread_cache); // restore G2_thread
2381 
2382 #ifdef ASSERT
2383     { Label L;
2384     __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O0);
2385     __ br_null(O0, false, Assembler::pt, L);
2386     __ delayed()->nop();
2387     __ stop("no pending exception allowed on exit from IR::monitorexit");
2388     __ bind(L);
2389     }
2390 #endif
2391     restore_native_result(masm, ret_type, stack_slots);
2392     // check_forward_pending_exception jump to forward_exception if any pending
2393     // exception is set.  The forward_exception routine expects to see the
2394     // exception in pending_exception and not in a register.  Kind of clumsy,
2395     // since all folks who branch to forward_exception must have tested
2396     // pending_exception first and hence have it in a register already.
2397     __ st_ptr(I2_ex_oop, G2_thread, in_bytes(Thread::pending_exception_offset()));
2398     __ bind(done);
2399   }
2400 
2401   // Tell dtrace about this method exit
2402   {
2403     SkipIfEqual skip_if(
2404       masm, G3_scratch, &DTraceMethodProbes, Assembler::zero);
2405     save_native_result(masm, ret_type, stack_slots);
2406     __ set_oop_constant(JNIHandles::make_local(method()), O1);


2622   // SP-> | out_preserved_slots |
2623   //
2624   //
2625 
2626   // Now compute actual number of stack words we need rounding to make
2627   // stack properly aligned.
2628   stack_slots = round_to(stack_slots, 4 * VMRegImpl::slots_per_word);
2629 
2630   int stack_size = stack_slots * VMRegImpl::stack_slot_size;
2631 
2632   intptr_t start = (intptr_t)__ pc();
2633 
2634   // First thing make an ic check to see if we should even be here
2635 
2636   {
2637     Label L;
2638     const Register temp_reg = G3_scratch;
2639     AddressLiteral ic_miss(SharedRuntime::get_ic_miss_stub());
2640     __ verify_oop(O0);
2641     __ ld_ptr(O0, oopDesc::klass_offset_in_bytes(), temp_reg);
2642     __ cmp(temp_reg, G5_inline_cache_reg);
2643     __ brx(Assembler::equal, true, Assembler::pt, L);
2644     __ delayed()->nop();
2645 
2646     __ jump_to(ic_miss, temp_reg);
2647     __ delayed()->nop();
2648     __ align(CodeEntryAlignment);
2649     __ bind(L);
2650   }
2651 
2652   int vep_offset = ((intptr_t)__ pc()) - start;
2653 
2654 
2655   // The instruction at the verified entry point must be 5 bytes or longer
2656   // because it can be patched on the fly by make_non_entrant. The stack bang
2657   // instruction fits that requirement.
2658 
2659   // Generate stack overflow check before creating frame
2660   __ generate_stack_overflow_check(stack_size);
2661 
2662   assert(((intptr_t)__ pc() - start - vep_offset) >= 5,
2663          "valid size for make_non_entrant");
2664 


3126   // for each frame we create and keep up the illusion every where.
3127   //
3128 
3129   __ ld(O2UnrollBlock, Deoptimization::UnrollBlock::caller_adjustment_offset_in_bytes(), O7);
3130   __ mov(SP, O5_savedSP);       // remember initial sender's original sp before adjustment
3131   __ sub(SP, O7, SP);
3132 
3133 #ifdef ASSERT
3134   // make sure that there is at least one entry in the array
3135   __ tst(O4array_size);
3136   __ breakpoint_trap(Assembler::zero);
3137 #endif
3138 
3139   // Now push the new interpreter frames
3140   __ bind(loop);
3141 
3142   // allocate a new frame, filling the registers
3143 
3144   gen_new_frame(masm, deopt);        // allocate an interpreter frame
3145 
3146   __ tst(O4array_size);
3147   __ br(Assembler::notZero, false, Assembler::pn, loop);
3148   __ delayed()->add(O3array, wordSize, O3array);
3149   __ ld_ptr(G3pcs, 0, O7);                      // load final frame new pc
3150 
3151 }
3152 
3153 //------------------------------generate_deopt_blob----------------------------
3154 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
3155 // instead.
3156 void SharedRuntime::generate_deopt_blob() {
3157   // allocate space for the code
3158   ResourceMark rm;
3159   // setup code generation tools
3160   int pad = VerifyThread ? 512 : 0;// Extra slop space for more verify code
3161 #ifdef _LP64
3162   CodeBuffer buffer("deopt_blob", 2100+pad, 512);
3163 #else
3164   // Measured 8/7/03 at 1212 in 32bit debug build (no VerifyThread)
3165   // Measured 8/7/03 at 1396 in 32bit debug build (VerifyThread)
3166   CodeBuffer buffer("deopt_blob", 1600+pad, 512);
3167 #endif /* _LP64 */


3204   //   - deallocate the dummy unpack_frame
3205   //   - ensure that all the return values are correctly set and then do
3206   //     a return to the interpreter entry point
3207   //
3208   // Refer to the following methods for more information:
3209   //   - Deoptimization::fetch_unroll_info
3210   //   - Deoptimization::unpack_frames
3211 
3212   OopMap* map = NULL;
3213 
3214   int start = __ offset();
3215 
3216   // restore G2, the trampoline destroyed it
3217   __ get_thread();
3218 
3219   // On entry we have been called by the deoptimized nmethod with a call that
3220   // replaced the original call (or safepoint polling location) so the deoptimizing
3221   // pc is now in O7. Return values are still in the expected places
3222 
3223   map = RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3224   __ ba(false, cont);
3225   __ delayed()->mov(Deoptimization::Unpack_deopt, L0deopt_mode);
3226 
3227   int exception_offset = __ offset() - start;
3228 
3229   // restore G2, the trampoline destroyed it
3230   __ get_thread();
3231 
3232   // On entry we have been jumped to by the exception handler (or exception_blob
3233   // for server).  O0 contains the exception oop and O7 contains the original
3234   // exception pc.  So if we push a frame here it will look to the
3235   // stack walking code (fetch_unroll_info) just like a normal call so
3236   // state will be extracted normally.
3237 
3238   // save exception oop in JavaThread and fall through into the
3239   // exception_in_tls case since they are handled in same way except
3240   // for where the pending exception is kept.
3241   __ st_ptr(Oexception, G2_thread, JavaThread::exception_oop_offset());
3242 
3243   //
3244   // Vanilla deoptimization with an exception pending in exception_oop
3245   //
3246   int exception_in_tls_offset = __ offset() - start;
3247 
3248   // No need to update oop_map  as each call to save_live_registers will produce identical oopmap
3249   (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3250 
3251   // Restore G2_thread
3252   __ get_thread();
3253 
3254 #ifdef ASSERT
3255   {
3256     // verify that there is really an exception oop in exception_oop
3257     Label has_exception;
3258     __ ld_ptr(G2_thread, JavaThread::exception_oop_offset(), Oexception);
3259     __ br_notnull(Oexception, false, Assembler::pt, has_exception);
3260     __ delayed()-> nop();
3261     __ stop("no exception in thread");
3262     __ bind(has_exception);
3263 
3264     // verify that there is no pending exception
3265     Label no_pending_exception;
3266     Address exception_addr(G2_thread, Thread::pending_exception_offset());
3267     __ ld_ptr(exception_addr, Oexception);
3268     __ br_null(Oexception, false, Assembler::pt, no_pending_exception);
3269     __ delayed()->nop();
3270     __ stop("must not have pending exception here");
3271     __ bind(no_pending_exception);
3272   }
3273 #endif
3274 
3275   __ ba(false, cont);
3276   __ delayed()->mov(Deoptimization::Unpack_exception, L0deopt_mode);;
3277 
3278   //
3279   // Reexecute entry, similar to c2 uncommon trap
3280   //
3281   int reexecute_offset = __ offset() - start;
3282 
3283   // No need to update oop_map  as each call to save_live_registers will produce identical oopmap
3284   (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3285 
3286   __ mov(Deoptimization::Unpack_reexecute, L0deopt_mode);
3287 
3288   __ bind(cont);
3289 
3290   __ set_last_Java_frame(SP, noreg);
3291 
3292   // do the call by hand so we can get the oopmap
3293 
3294   __ mov(G2_thread, L7_thread_cache);
3295   __ call(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info), relocInfo::runtime_call_type);
3296   __ delayed()->mov(G2_thread, O0);
3297 
3298   // Set an oopmap for the call site this describes all our saved volatile registers
3299 
3300   oop_maps->add_gc_map( __ offset()-start, map);
3301 
3302   __ mov(L7_thread_cache, G2_thread);
3303 
3304   __ reset_last_Java_frame();
3305 
3306   // NOTE: we know that only O0/O1 will be reloaded by restore_result_registers
3307   // so this move will survive
3308 
3309   __ mov(L0deopt_mode, G4deopt_mode);
3310 
3311   __ mov(O0, O2UnrollBlock->after_save());
3312 
3313   RegisterSaver::restore_result_registers(masm);
3314 
3315   Label noException;
3316   __ cmp(G4deopt_mode, Deoptimization::Unpack_exception);   // Was exception pending?
3317   __ br(Assembler::notEqual, false, Assembler::pt, noException);
3318   __ delayed()->nop();
3319 
3320   // Move the pending exception from exception_oop to Oexception so
3321   // the pending exception will be picked up the interpreter.
3322   __ ld_ptr(G2_thread, in_bytes(JavaThread::exception_oop_offset()), Oexception);
3323   __ st_ptr(G0, G2_thread, in_bytes(JavaThread::exception_oop_offset()));
3324   __ bind(noException);
3325 
3326   // deallocate the deoptimization frame taking care to preserve the return values
3327   __ mov(Oreturn0,     Oreturn0->after_save());
3328   __ mov(Oreturn1,     Oreturn1->after_save());
3329   __ mov(O2UnrollBlock, O2UnrollBlock->after_save());
3330   __ restore();
3331 
3332   // Allocate new interpreter frame(s) and possible c2i adapter frame
3333 
3334   make_new_frames(masm, true);
3335 
3336   // push a dummy "unpack_frame" taking care of float return values and
3337   // call Deoptimization::unpack_frames to have the unpacker layout
3338   // information in the interpreter frames just created and then return


3342 #if !defined(_LP64)
3343 #if defined(COMPILER2)
3344   // 32-bit 1-register longs return longs in G1
3345   __ stx(Greturn1, saved_Greturn1_addr);
3346 #endif
3347   __ set_last_Java_frame(SP, noreg);
3348   __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), G2_thread, G4deopt_mode);
3349 #else
3350   // LP64 uses g4 in set_last_Java_frame
3351   __ mov(G4deopt_mode, O1);
3352   __ set_last_Java_frame(SP, G0);
3353   __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), G2_thread, O1);
3354 #endif
3355   __ reset_last_Java_frame();
3356   __ ldf(FloatRegisterImpl::D, saved_Freturn0_addr, Freturn0);
3357 
3358 #if !defined(_LP64) && defined(COMPILER2)
3359   // In 32 bit, C2 returns longs in G1 so restore the saved G1 into
3360   // I0/I1 if the return value is long.
3361   Label not_long;
3362   __ cmp(O0,T_LONG);
3363   __ br(Assembler::notEqual, false, Assembler::pt, not_long);
3364   __ delayed()->nop();
3365   __ ldd(saved_Greturn1_addr,I0);
3366   __ bind(not_long);
3367 #endif
3368   __ ret();
3369   __ delayed()->restore();
3370 
3371   masm->flush();
3372   _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, reexecute_offset, frame_size_words);
3373   _deopt_blob->set_unpack_with_exception_in_tls_offset(exception_in_tls_offset);
3374 }
3375 
3376 #ifdef COMPILER2
3377 
3378 //------------------------------generate_uncommon_trap_blob--------------------
3379 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
3380 // instead.
3381 void SharedRuntime::generate_uncommon_trap_blob() {
3382   // allocate space for the code
3383   ResourceMark rm;
3384   // setup code generation tools


3517   // Do not use call_VM_leaf, because we need to make a GC map at this call site.
3518   __ mov(G2_thread, O0);
3519   __ save_thread(L7_thread_cache);
3520   __ call(call_ptr);
3521   __ delayed()->nop();
3522 
3523   // Set an oopmap for the call site.
3524   // We need this not only for callee-saved registers, but also for volatile
3525   // registers that the compiler might be keeping live across a safepoint.
3526 
3527   oop_maps->add_gc_map( __ offset() - start, map);
3528 
3529   __ restore_thread(L7_thread_cache);
3530   // clear last_Java_sp
3531   __ reset_last_Java_frame();
3532 
3533   // Check for exceptions
3534   Label pending;
3535 
3536   __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O1);
3537   __ tst(O1);
3538   __ brx(Assembler::notEqual, true, Assembler::pn, pending);
3539   __ delayed()->nop();
3540 
3541   RegisterSaver::restore_live_registers(masm);
3542 
3543   // We are back the the original state on entry and ready to go.
3544 
3545   __ retl();
3546   __ delayed()->nop();
3547 
3548   // Pending exception after the safepoint
3549 
3550   __ bind(pending);
3551 
3552   RegisterSaver::restore_live_registers(masm);
3553 
3554   // We are back the the original state on entry.
3555 
3556   // Tail-call forward_exception_entry, with the issuing PC in O7,
3557   // so it looks like the original nmethod called forward_exception_entry.
3558   __ set((intptr_t)StubRoutines::forward_exception_entry(), O0);
3559   __ JMP(O0, 0);


3606   __ save_thread(L7_thread_cache);
3607   __ call(destination, relocInfo::runtime_call_type);
3608   __ delayed()->nop();
3609 
3610   // O0 contains the address we are going to jump to assuming no exception got installed
3611 
3612   // Set an oopmap for the call site.
3613   // We need this not only for callee-saved registers, but also for volatile
3614   // registers that the compiler might be keeping live across a safepoint.
3615 
3616   oop_maps->add_gc_map( __ offset() - start, map);
3617 
3618   __ restore_thread(L7_thread_cache);
3619   // clear last_Java_sp
3620   __ reset_last_Java_frame();
3621 
3622   // Check for exceptions
3623   Label pending;
3624 
3625   __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O1);
3626   __ tst(O1);
3627   __ brx(Assembler::notEqual, true, Assembler::pn, pending);
3628   __ delayed()->nop();
3629 
3630   // get the returned methodOop
3631 
3632   __ get_vm_result(G5_method);
3633   __ stx(G5_method, SP, RegisterSaver::G5_offset()+STACK_BIAS);
3634 
3635   // O0 is where we want to jump, overwrite G3 which is saved and scratch
3636 
3637   __ stx(O0, SP, RegisterSaver::G3_offset()+STACK_BIAS);
3638 
3639   RegisterSaver::restore_live_registers(masm);
3640 
3641   // We are back the the original state on entry and ready to go.
3642 
3643   __ JMP(G3, 0);
3644   __ delayed()->nop();
3645 
3646   // Pending exception after the safepoint
3647 
3648   __ bind(pending);


 583   void gen_c2i_adapter(int total_args_passed,
 584                               // VMReg max_arg,
 585                               int comp_args_on_stack, // VMRegStackSlots
 586                               const BasicType *sig_bt,
 587                               const VMRegPair *regs,
 588                               Label& skip_fixup);
 589   void gen_i2c_adapter(int total_args_passed,
 590                               // VMReg max_arg,
 591                               int comp_args_on_stack, // VMRegStackSlots
 592                               const BasicType *sig_bt,
 593                               const VMRegPair *regs);
 594 
 595   AdapterGenerator(MacroAssembler *_masm) : masm(_masm) {}
 596 };
 597 
 598 
 599 // Patch the callers callsite with entry to compiled code if it exists.
 600 void AdapterGenerator::patch_callers_callsite() {
 601   Label L;
 602   __ ld_ptr(G5_method, in_bytes(methodOopDesc::code_offset()), G3_scratch);
 603   __ br_null(G3_scratch, false, Assembler::pt, L);
 604   // Schedule the branch target address early.
 605   __ delayed()->ld_ptr(G5_method, in_bytes(methodOopDesc::interpreter_entry_offset()), G3_scratch);
 606   // Call into the VM to patch the caller, then jump to compiled callee
 607   __ save_frame(4);     // Args in compiled layout; do not blow them
 608 
 609   // Must save all the live Gregs the list is:
 610   // G1: 1st Long arg (32bit build)
 611   // G2: global allocated to TLS
 612   // G3: used in inline cache check (scratch)
 613   // G4: 2nd Long arg (32bit build);
 614   // G5: used in inline cache check (methodOop)
 615 
 616   // The longs must go to the stack by hand since in the 32 bit build they can be trashed by window ops.
 617 
 618 #ifdef _LP64
 619   // mov(s,d)
 620   __ mov(G1, L1);
 621   __ mov(G4, L4);
 622   __ mov(G5_method, L5);
 623   __ mov(G5_method, O0);         // VM needs target method


1110 
1111     // 6243940 We might end up in handle_wrong_method if
1112     // the callee is deoptimized as we race thru here. If that
1113     // happens we don't want to take a safepoint because the
1114     // caller frame will look interpreted and arguments are now
1115     // "compiled" so it is much better to make this transition
1116     // invisible to the stack walking code. Unfortunately if
1117     // we try and find the callee by normal means a safepoint
1118     // is possible. So we stash the desired callee in the thread
1119     // and the vm will find there should this case occur.
1120     Address callee_target_addr(G2_thread, JavaThread::callee_target_offset());
1121     __ st_ptr(G5_method, callee_target_addr);
1122 
1123     if (StressNonEntrant) {
1124       // Open a big window for deopt failure
1125       __ save_frame(0);
1126       __ mov(G0, L0);
1127       Label loop;
1128       __ bind(loop);
1129       __ sub(L0, 1, L0);
1130       __ br_null_short(L0, Assembler::pt, loop);

1131 
1132       __ restore();
1133     }
1134 
1135 
1136     __ jmpl(G3, 0, G0);
1137     __ delayed()->nop();
1138 }
1139 
1140 // ---------------------------------------------------------------
1141 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
1142                                                             int total_args_passed,
1143                                                             // VMReg max_arg,
1144                                                             int comp_args_on_stack, // VMRegStackSlots
1145                                                             const BasicType *sig_bt,
1146                                                             const VMRegPair *regs,
1147                                                             AdapterFingerPrint* fingerprint) {
1148   address i2c_entry = __ pc();
1149 
1150   AdapterGenerator agen(masm);


1184     __ cmp(G3_scratch, R_temp);
1185     __ restore();
1186 #else
1187     __ ld_ptr(G5_method, compiledICHolderOopDesc::holder_klass_offset(), R_temp);
1188     __ verify_oop(R_temp);
1189     __ cmp(G3_scratch, R_temp);
1190 #endif
1191 
1192     Label ok, ok2;
1193     __ brx(Assembler::equal, false, Assembler::pt, ok);
1194     __ delayed()->ld_ptr(G5_method, compiledICHolderOopDesc::holder_method_offset(), G5_method);
1195     __ jump_to(ic_miss, G3_scratch);
1196     __ delayed()->nop();
1197 
1198     __ bind(ok);
1199     // Method might have been compiled since the call site was patched to
1200     // interpreted if that is the case treat it as a miss so we can get
1201     // the call site corrected.
1202     __ ld_ptr(G5_method, in_bytes(methodOopDesc::code_offset()), G3_scratch);
1203     __ bind(ok2);
1204     __ br_null(G3_scratch, false, Assembler::pt, skip_fixup);
1205     __ delayed()->ld_ptr(G5_method, in_bytes(methodOopDesc::interpreter_entry_offset()), G3_scratch);
1206     __ jump_to(ic_miss, G3_scratch);
1207     __ delayed()->nop();
1208 
1209   }
1210 
1211   address c2i_entry = __ pc();
1212 
1213   agen.gen_c2i_adapter(total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
1214 
1215   __ flush();
1216   return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
1217 
1218 }
1219 
1220 // Helper function for native calling conventions
1221 static VMReg int_stk_helper( int i ) {
1222   // Bias any stack based VMReg we get by ignoring the window area
1223   // but not the register parameter save area.
1224   //


1761                                                 int comp_args_on_stack, // in VMRegStackSlots
1762                                                 BasicType *in_sig_bt,
1763                                                 VMRegPair *in_regs,
1764                                                 BasicType ret_type) {
1765 
1766   // Native nmethod wrappers never take possesion of the oop arguments.
1767   // So the caller will gc the arguments. The only thing we need an
1768   // oopMap for is if the call is static
1769   //
1770   // An OopMap for lock (and class if static), and one for the VM call itself
1771   OopMapSet *oop_maps = new OopMapSet();
1772   intptr_t start = (intptr_t)__ pc();
1773 
1774   // First thing make an ic check to see if we should even be here
1775   {
1776     Label L;
1777     const Register temp_reg = G3_scratch;
1778     AddressLiteral ic_miss(SharedRuntime::get_ic_miss_stub());
1779     __ verify_oop(O0);
1780     __ load_klass(O0, temp_reg);
1781     __ cmp_and_brx_short(temp_reg, G5_inline_cache_reg, Assembler::equal, Assembler::pt, L);


1782 
1783     __ jump_to(ic_miss, temp_reg);
1784     __ delayed()->nop();
1785     __ align(CodeEntryAlignment);
1786     __ bind(L);
1787   }
1788 
1789   int vep_offset = ((intptr_t)__ pc()) - start;
1790 
1791 #ifdef COMPILER1
1792   if (InlineObjectHash && method->intrinsic_id() == vmIntrinsics::_hashCode) {
1793     // Object.hashCode can pull the hashCode from the header word
1794     // instead of doing a full VM transition once it's been computed.
1795     // Since hashCode is usually polymorphic at call sites we can't do
1796     // this optimization at the call site without a lot of work.
1797     Label slowCase;
1798     Register receiver             = O0;
1799     Register result               = O0;
1800     Register header               = G3_scratch;
1801     Register hash                 = G3_scratch; // overwrite header value with hash value


2162     // None of the above fast optimizations worked so we have to get into the
2163     // slow case of monitor enter.  Inline a special case of call_VM that
2164     // disallows any pending_exception.
2165     __ mov(Roop, O0);            // Need oop in O0
2166     __ mov(L3_box, O1);
2167 
2168     // Record last_Java_sp, in case the VM code releases the JVM lock.
2169 
2170     __ set_last_Java_frame(FP, I7);
2171 
2172     // do the call
2173     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), relocInfo::runtime_call_type);
2174     __ delayed()->mov(L7_thread_cache, O2);
2175 
2176     __ restore_thread(L7_thread_cache); // restore G2_thread
2177     __ reset_last_Java_frame();
2178 
2179 #ifdef ASSERT
2180     { Label L;
2181     __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O0);
2182     __ br_null_short(O0, Assembler::pt, L);

2183     __ stop("no pending exception allowed on exit from IR::monitorenter");
2184     __ bind(L);
2185     }
2186 #endif
2187     __ bind(done);
2188   }
2189 
2190 
2191   // Finally just about ready to make the JNI call
2192 
2193   __ flush_windows();
2194   if (inner_frame_created) {
2195     __ restore();
2196   } else {
2197     // Store only what we need from this frame
2198     // QQQ I think that non-v9 (like we care) we don't need these saves
2199     // either as the flush traps and the current window goes too.
2200     __ st_ptr(FP, SP, FP->sp_offset_in_saved_window()*wordSize + STACK_BIAS);
2201     __ st_ptr(I7, SP, I7->sp_offset_in_saved_window()*wordSize + STACK_BIAS);
2202   }


2277     __ st(G3_scratch, G2_thread, JavaThread::thread_state_offset());
2278     if(os::is_MP()) {
2279       if (UseMembar) {
2280         // Force this write out before the read below
2281         __ membar(Assembler::StoreLoad);
2282       } else {
2283         // Write serialization page so VM thread can do a pseudo remote membar.
2284         // We use the current thread pointer to calculate a thread specific
2285         // offset to write to within the page. This minimizes bus traffic
2286         // due to cache line collision.
2287         __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
2288       }
2289     }
2290     __ load_contents(sync_state, G3_scratch);
2291     __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
2292 
2293     Label L;
2294     Address suspend_state(G2_thread, JavaThread::suspend_flags_offset());
2295     __ br(Assembler::notEqual, false, Assembler::pn, L);
2296     __ delayed()->ld(suspend_state, G3_scratch);
2297     __ cmp_and_br_short(G3_scratch, 0, Assembler::equal, Assembler::pt, no_block);


2298     __ bind(L);
2299 
2300     // Block.  Save any potential method result value before the operation and
2301     // use a leaf call to leave the last_Java_frame setup undisturbed. Doing this
2302     // lets us share the oopMap we used when we went native rather the create
2303     // a distinct one for this pc
2304     //
2305     save_native_result(masm, ret_type, stack_slots);
2306     __ call_VM_leaf(L7_thread_cache,
2307                     CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
2308                     G2_thread);
2309 
2310     // Restore any method result value
2311     restore_native_result(masm, ret_type, stack_slots);
2312     __ bind(no_block);
2313   }
2314 
2315   // thread state is thread_in_native_trans. Any safepoint blocking has already
2316   // happened so we can now change state to _thread_in_Java.
2317 
2318 
2319   __ set(_thread_in_Java, G3_scratch);
2320   __ st(G3_scratch, G2_thread, JavaThread::thread_state_offset());
2321 
2322 
2323   Label no_reguard;
2324   __ ld(G2_thread, JavaThread::stack_guard_state_offset(), G3_scratch);
2325   __ cmp_and_br_short(G3_scratch, JavaThread::stack_guard_yellow_disabled, Assembler::notEqual, Assembler::pt, no_reguard);


2326 
2327     save_native_result(masm, ret_type, stack_slots);
2328   __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages));
2329   __ delayed()->nop();
2330 
2331   __ restore_thread(L7_thread_cache); // restore G2_thread
2332     restore_native_result(masm, ret_type, stack_slots);
2333 
2334   __ bind(no_reguard);
2335 
2336   // Handle possible exception (will unlock if necessary)
2337 
2338   // native result if any is live in freg or I0 (and I1 if long and 32bit vm)
2339 
2340   // Unlock
2341   if (method->is_synchronized()) {
2342     Label done;
2343     Register I2_ex_oop = I2;
2344     const Register L3_box = L3;
2345     // Get locked oop from the handle we passed to jni


2357     // save and restore any potential method result value around the unlocking
2358     // operation.  Will save in I0 (or stack for FP returns).
2359     save_native_result(masm, ret_type, stack_slots);
2360 
2361     // Must clear pending-exception before re-entering the VM.  Since this is
2362     // a leaf call, pending-exception-oop can be safely kept in a register.
2363     __ st_ptr(G0, G2_thread, in_bytes(Thread::pending_exception_offset()));
2364 
2365     // slow case of monitor enter.  Inline a special case of call_VM that
2366     // disallows any pending_exception.
2367     __ mov(L3_box, O1);
2368 
2369     __ call(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C), relocInfo::runtime_call_type);
2370     __ delayed()->mov(L4, O0);              // Need oop in O0
2371 
2372     __ restore_thread(L7_thread_cache); // restore G2_thread
2373 
2374 #ifdef ASSERT
2375     { Label L;
2376     __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O0);
2377     __ br_null_short(O0, Assembler::pt, L);

2378     __ stop("no pending exception allowed on exit from IR::monitorexit");
2379     __ bind(L);
2380     }
2381 #endif
2382     restore_native_result(masm, ret_type, stack_slots);
2383     // check_forward_pending_exception jump to forward_exception if any pending
2384     // exception is set.  The forward_exception routine expects to see the
2385     // exception in pending_exception and not in a register.  Kind of clumsy,
2386     // since all folks who branch to forward_exception must have tested
2387     // pending_exception first and hence have it in a register already.
2388     __ st_ptr(I2_ex_oop, G2_thread, in_bytes(Thread::pending_exception_offset()));
2389     __ bind(done);
2390   }
2391 
2392   // Tell dtrace about this method exit
2393   {
2394     SkipIfEqual skip_if(
2395       masm, G3_scratch, &DTraceMethodProbes, Assembler::zero);
2396     save_native_result(masm, ret_type, stack_slots);
2397     __ set_oop_constant(JNIHandles::make_local(method()), O1);


2613   // SP-> | out_preserved_slots |
2614   //
2615   //
2616 
2617   // Now compute actual number of stack words we need rounding to make
2618   // stack properly aligned.
2619   stack_slots = round_to(stack_slots, 4 * VMRegImpl::slots_per_word);
2620 
2621   int stack_size = stack_slots * VMRegImpl::stack_slot_size;
2622 
2623   intptr_t start = (intptr_t)__ pc();
2624 
2625   // First thing make an ic check to see if we should even be here
2626 
2627   {
2628     Label L;
2629     const Register temp_reg = G3_scratch;
2630     AddressLiteral ic_miss(SharedRuntime::get_ic_miss_stub());
2631     __ verify_oop(O0);
2632     __ ld_ptr(O0, oopDesc::klass_offset_in_bytes(), temp_reg);
2633     __ cmp_and_brx_short(temp_reg, G5_inline_cache_reg, Assembler::equal, Assembler::pt, L);


2634 
2635     __ jump_to(ic_miss, temp_reg);
2636     __ delayed()->nop();
2637     __ align(CodeEntryAlignment);
2638     __ bind(L);
2639   }
2640 
2641   int vep_offset = ((intptr_t)__ pc()) - start;
2642 
2643 
2644   // The instruction at the verified entry point must be 5 bytes or longer
2645   // because it can be patched on the fly by make_non_entrant. The stack bang
2646   // instruction fits that requirement.
2647 
2648   // Generate stack overflow check before creating frame
2649   __ generate_stack_overflow_check(stack_size);
2650 
2651   assert(((intptr_t)__ pc() - start - vep_offset) >= 5,
2652          "valid size for make_non_entrant");
2653 


3115   // for each frame we create and keep up the illusion every where.
3116   //
3117 
3118   __ ld(O2UnrollBlock, Deoptimization::UnrollBlock::caller_adjustment_offset_in_bytes(), O7);
3119   __ mov(SP, O5_savedSP);       // remember initial sender's original sp before adjustment
3120   __ sub(SP, O7, SP);
3121 
3122 #ifdef ASSERT
3123   // make sure that there is at least one entry in the array
3124   __ tst(O4array_size);
3125   __ breakpoint_trap(Assembler::zero);
3126 #endif
3127 
3128   // Now push the new interpreter frames
3129   __ bind(loop);
3130 
3131   // allocate a new frame, filling the registers
3132 
3133   gen_new_frame(masm, deopt);        // allocate an interpreter frame
3134 
3135   __ cmp_zero_and_br(Assembler::notZero, O4array_size, loop);

3136   __ delayed()->add(O3array, wordSize, O3array);
3137   __ ld_ptr(G3pcs, 0, O7);                      // load final frame new pc
3138 
3139 }
3140 
3141 //------------------------------generate_deopt_blob----------------------------
3142 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
3143 // instead.
3144 void SharedRuntime::generate_deopt_blob() {
3145   // allocate space for the code
3146   ResourceMark rm;
3147   // setup code generation tools
3148   int pad = VerifyThread ? 512 : 0;// Extra slop space for more verify code
3149 #ifdef _LP64
3150   CodeBuffer buffer("deopt_blob", 2100+pad, 512);
3151 #else
3152   // Measured 8/7/03 at 1212 in 32bit debug build (no VerifyThread)
3153   // Measured 8/7/03 at 1396 in 32bit debug build (VerifyThread)
3154   CodeBuffer buffer("deopt_blob", 1600+pad, 512);
3155 #endif /* _LP64 */


3192   //   - deallocate the dummy unpack_frame
3193   //   - ensure that all the return values are correctly set and then do
3194   //     a return to the interpreter entry point
3195   //
3196   // Refer to the following methods for more information:
3197   //   - Deoptimization::fetch_unroll_info
3198   //   - Deoptimization::unpack_frames
3199 
3200   OopMap* map = NULL;
3201 
3202   int start = __ offset();
3203 
3204   // restore G2, the trampoline destroyed it
3205   __ get_thread();
3206 
3207   // On entry we have been called by the deoptimized nmethod with a call that
3208   // replaced the original call (or safepoint polling location) so the deoptimizing
3209   // pc is now in O7. Return values are still in the expected places
3210 
3211   map = RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3212   __ ba(cont);
3213   __ delayed()->mov(Deoptimization::Unpack_deopt, L0deopt_mode);
3214 
3215   int exception_offset = __ offset() - start;
3216 
3217   // restore G2, the trampoline destroyed it
3218   __ get_thread();
3219 
3220   // On entry we have been jumped to by the exception handler (or exception_blob
3221   // for server).  O0 contains the exception oop and O7 contains the original
3222   // exception pc.  So if we push a frame here it will look to the
3223   // stack walking code (fetch_unroll_info) just like a normal call so
3224   // state will be extracted normally.
3225 
3226   // save exception oop in JavaThread and fall through into the
3227   // exception_in_tls case since they are handled in same way except
3228   // for where the pending exception is kept.
3229   __ st_ptr(Oexception, G2_thread, JavaThread::exception_oop_offset());
3230 
3231   //
3232   // Vanilla deoptimization with an exception pending in exception_oop
3233   //
3234   int exception_in_tls_offset = __ offset() - start;
3235 
3236   // No need to update oop_map  as each call to save_live_registers will produce identical oopmap
3237   (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3238 
3239   // Restore G2_thread
3240   __ get_thread();
3241 
3242 #ifdef ASSERT
3243   {
3244     // verify that there is really an exception oop in exception_oop
3245     Label has_exception;
3246     __ ld_ptr(G2_thread, JavaThread::exception_oop_offset(), Oexception);
3247     __ br_notnull_short(Oexception, Assembler::pt, has_exception);

3248     __ stop("no exception in thread");
3249     __ bind(has_exception);
3250 
3251     // verify that there is no pending exception
3252     Label no_pending_exception;
3253     Address exception_addr(G2_thread, Thread::pending_exception_offset());
3254     __ ld_ptr(exception_addr, Oexception);
3255     __ br_null_short(Oexception, Assembler::pt, no_pending_exception);

3256     __ stop("must not have pending exception here");
3257     __ bind(no_pending_exception);
3258   }
3259 #endif
3260 
3261   __ ba(cont);
3262   __ delayed()->mov(Deoptimization::Unpack_exception, L0deopt_mode);;
3263 
3264   //
3265   // Reexecute entry, similar to c2 uncommon trap
3266   //
3267   int reexecute_offset = __ offset() - start;
3268 
3269   // No need to update oop_map  as each call to save_live_registers will produce identical oopmap
3270   (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3271 
3272   __ mov(Deoptimization::Unpack_reexecute, L0deopt_mode);
3273 
3274   __ bind(cont);
3275 
3276   __ set_last_Java_frame(SP, noreg);
3277 
3278   // do the call by hand so we can get the oopmap
3279 
3280   __ mov(G2_thread, L7_thread_cache);
3281   __ call(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info), relocInfo::runtime_call_type);
3282   __ delayed()->mov(G2_thread, O0);
3283 
3284   // Set an oopmap for the call site this describes all our saved volatile registers
3285 
3286   oop_maps->add_gc_map( __ offset()-start, map);
3287 
3288   __ mov(L7_thread_cache, G2_thread);
3289 
3290   __ reset_last_Java_frame();
3291 
3292   // NOTE: we know that only O0/O1 will be reloaded by restore_result_registers
3293   // so this move will survive
3294 
3295   __ mov(L0deopt_mode, G4deopt_mode);
3296 
3297   __ mov(O0, O2UnrollBlock->after_save());
3298 
3299   RegisterSaver::restore_result_registers(masm);
3300 
3301   Label noException;
3302   __ cmp_and_br_short(G4deopt_mode, Deoptimization::Unpack_exception, Assembler::notEqual, Assembler::pt, noException);


3303 
3304   // Move the pending exception from exception_oop to Oexception so
3305   // the pending exception will be picked up the interpreter.
3306   __ ld_ptr(G2_thread, in_bytes(JavaThread::exception_oop_offset()), Oexception);
3307   __ st_ptr(G0, G2_thread, in_bytes(JavaThread::exception_oop_offset()));
3308   __ bind(noException);
3309 
3310   // deallocate the deoptimization frame taking care to preserve the return values
3311   __ mov(Oreturn0,     Oreturn0->after_save());
3312   __ mov(Oreturn1,     Oreturn1->after_save());
3313   __ mov(O2UnrollBlock, O2UnrollBlock->after_save());
3314   __ restore();
3315 
3316   // Allocate new interpreter frame(s) and possible c2i adapter frame
3317 
3318   make_new_frames(masm, true);
3319 
3320   // push a dummy "unpack_frame" taking care of float return values and
3321   // call Deoptimization::unpack_frames to have the unpacker layout
3322   // information in the interpreter frames just created and then return


3326 #if !defined(_LP64)
3327 #if defined(COMPILER2)
3328   // 32-bit 1-register longs return longs in G1
3329   __ stx(Greturn1, saved_Greturn1_addr);
3330 #endif
3331   __ set_last_Java_frame(SP, noreg);
3332   __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), G2_thread, G4deopt_mode);
3333 #else
3334   // LP64 uses g4 in set_last_Java_frame
3335   __ mov(G4deopt_mode, O1);
3336   __ set_last_Java_frame(SP, G0);
3337   __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), G2_thread, O1);
3338 #endif
3339   __ reset_last_Java_frame();
3340   __ ldf(FloatRegisterImpl::D, saved_Freturn0_addr, Freturn0);
3341 
3342 #if !defined(_LP64) && defined(COMPILER2)
3343   // In 32 bit, C2 returns longs in G1 so restore the saved G1 into
3344   // I0/I1 if the return value is long.
3345   Label not_long;
3346   __ cmp_and_br_short(O0,T_LONG, Assembler::notEqual, Assembler::pt, not_long);


3347   __ ldd(saved_Greturn1_addr,I0);
3348   __ bind(not_long);
3349 #endif
3350   __ ret();
3351   __ delayed()->restore();
3352 
3353   masm->flush();
3354   _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, reexecute_offset, frame_size_words);
3355   _deopt_blob->set_unpack_with_exception_in_tls_offset(exception_in_tls_offset);
3356 }
3357 
3358 #ifdef COMPILER2
3359 
3360 //------------------------------generate_uncommon_trap_blob--------------------
3361 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
3362 // instead.
3363 void SharedRuntime::generate_uncommon_trap_blob() {
3364   // allocate space for the code
3365   ResourceMark rm;
3366   // setup code generation tools


3499   // Do not use call_VM_leaf, because we need to make a GC map at this call site.
3500   __ mov(G2_thread, O0);
3501   __ save_thread(L7_thread_cache);
3502   __ call(call_ptr);
3503   __ delayed()->nop();
3504 
3505   // Set an oopmap for the call site.
3506   // We need this not only for callee-saved registers, but also for volatile
3507   // registers that the compiler might be keeping live across a safepoint.
3508 
3509   oop_maps->add_gc_map( __ offset() - start, map);
3510 
3511   __ restore_thread(L7_thread_cache);
3512   // clear last_Java_sp
3513   __ reset_last_Java_frame();
3514 
3515   // Check for exceptions
3516   Label pending;
3517 
3518   __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O1);
3519   __ br_notnull_short(O1, Assembler::pn, pending);


3520 
3521   RegisterSaver::restore_live_registers(masm);
3522 
3523   // We are back the the original state on entry and ready to go.
3524 
3525   __ retl();
3526   __ delayed()->nop();
3527 
3528   // Pending exception after the safepoint
3529 
3530   __ bind(pending);
3531 
3532   RegisterSaver::restore_live_registers(masm);
3533 
3534   // We are back the the original state on entry.
3535 
3536   // Tail-call forward_exception_entry, with the issuing PC in O7,
3537   // so it looks like the original nmethod called forward_exception_entry.
3538   __ set((intptr_t)StubRoutines::forward_exception_entry(), O0);
3539   __ JMP(O0, 0);


3586   __ save_thread(L7_thread_cache);
3587   __ call(destination, relocInfo::runtime_call_type);
3588   __ delayed()->nop();
3589 
3590   // O0 contains the address we are going to jump to assuming no exception got installed
3591 
3592   // Set an oopmap for the call site.
3593   // We need this not only for callee-saved registers, but also for volatile
3594   // registers that the compiler might be keeping live across a safepoint.
3595 
3596   oop_maps->add_gc_map( __ offset() - start, map);
3597 
3598   __ restore_thread(L7_thread_cache);
3599   // clear last_Java_sp
3600   __ reset_last_Java_frame();
3601 
3602   // Check for exceptions
3603   Label pending;
3604 
3605   __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O1);
3606   __ br_notnull_short(O1, Assembler::pn, pending);


3607 
3608   // get the returned methodOop
3609 
3610   __ get_vm_result(G5_method);
3611   __ stx(G5_method, SP, RegisterSaver::G5_offset()+STACK_BIAS);
3612 
3613   // O0 is where we want to jump, overwrite G3 which is saved and scratch
3614 
3615   __ stx(O0, SP, RegisterSaver::G3_offset()+STACK_BIAS);
3616 
3617   RegisterSaver::restore_live_registers(masm);
3618 
3619   // We are back the the original state on entry and ready to go.
3620 
3621   __ JMP(G3, 0);
3622   __ delayed()->nop();
3623 
3624   // Pending exception after the safepoint
3625 
3626   __ bind(pending);
src/cpu/sparc/vm/sharedRuntime_sparc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File