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, false);
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
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, __ pt, skip_fixup, false);
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(temp_reg, G5_inline_cache_reg, Assembler::equal, true, 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(O0, false, 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 __ br_zero(G3_scratch, 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(G3_scratch, JavaThread::stack_guard_yellow_disabled, Assembler::notEqual, false, 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(O0, false, 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(temp_reg, G5_inline_cache_reg, Assembler::equal, true, 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 __ tst(O4array_size);
3136 __ br(Assembler::notZero, false, Assembler::pn, loop);
3137 __ delayed()->add(O3array, wordSize, O3array);
3138 __ ld_ptr(G3pcs, 0, O7); // load final frame new pc
3139
3140 }
3141
3142 //------------------------------generate_deopt_blob----------------------------
3143 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
3144 // instead.
3145 void SharedRuntime::generate_deopt_blob() {
3146 // allocate space for the code
3147 ResourceMark rm;
3148 // setup code generation tools
3149 int pad = VerifyThread ? 512 : 0;// Extra slop space for more verify code
3150 #ifdef _LP64
3151 CodeBuffer buffer("deopt_blob", 2100+pad, 512);
3152 #else
3153 // Measured 8/7/03 at 1212 in 32bit debug build (no VerifyThread)
3154 // Measured 8/7/03 at 1396 in 32bit debug build (VerifyThread)
3155 CodeBuffer buffer("deopt_blob", 1600+pad, 512);
3156 #endif /* _LP64 */
3193 // - deallocate the dummy unpack_frame
3194 // - ensure that all the return values are correctly set and then do
3195 // a return to the interpreter entry point
3196 //
3197 // Refer to the following methods for more information:
3198 // - Deoptimization::fetch_unroll_info
3199 // - Deoptimization::unpack_frames
3200
3201 OopMap* map = NULL;
3202
3203 int start = __ offset();
3204
3205 // restore G2, the trampoline destroyed it
3206 __ get_thread();
3207
3208 // On entry we have been called by the deoptimized nmethod with a call that
3209 // replaced the original call (or safepoint polling location) so the deoptimizing
3210 // pc is now in O7. Return values are still in the expected places
3211
3212 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3213 __ ba(cont, false);
3214 __ delayed()->mov(Deoptimization::Unpack_deopt, L0deopt_mode);
3215
3216 int exception_offset = __ offset() - start;
3217
3218 // restore G2, the trampoline destroyed it
3219 __ get_thread();
3220
3221 // On entry we have been jumped to by the exception handler (or exception_blob
3222 // for server). O0 contains the exception oop and O7 contains the original
3223 // exception pc. So if we push a frame here it will look to the
3224 // stack walking code (fetch_unroll_info) just like a normal call so
3225 // state will be extracted normally.
3226
3227 // save exception oop in JavaThread and fall through into the
3228 // exception_in_tls case since they are handled in same way except
3229 // for where the pending exception is kept.
3230 __ st_ptr(Oexception, G2_thread, JavaThread::exception_oop_offset());
3231
3232 //
3233 // Vanilla deoptimization with an exception pending in exception_oop
3234 //
3235 int exception_in_tls_offset = __ offset() - start;
3236
3237 // No need to update oop_map as each call to save_live_registers will produce identical oopmap
3238 (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3239
3240 // Restore G2_thread
3241 __ get_thread();
3242
3243 #ifdef ASSERT
3244 {
3245 // verify that there is really an exception oop in exception_oop
3246 Label has_exception;
3247 __ ld_ptr(G2_thread, JavaThread::exception_oop_offset(), Oexception);
3248 __ br_notnull(Oexception, false, Assembler::pt, has_exception);
3249 __ stop("no exception in thread");
3250 __ bind(has_exception);
3251
3252 // verify that there is no pending exception
3253 Label no_pending_exception;
3254 Address exception_addr(G2_thread, Thread::pending_exception_offset());
3255 __ ld_ptr(exception_addr, Oexception);
3256 __ br_null(Oexception, false, Assembler::pt, no_pending_exception);
3257 __ stop("must not have pending exception here");
3258 __ bind(no_pending_exception);
3259 }
3260 #endif
3261
3262 __ ba(cont, false);
3263 __ delayed()->mov(Deoptimization::Unpack_exception, L0deopt_mode);;
3264
3265 //
3266 // Reexecute entry, similar to c2 uncommon trap
3267 //
3268 int reexecute_offset = __ offset() - start;
3269
3270 // No need to update oop_map as each call to save_live_registers will produce identical oopmap
3271 (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_words);
3272
3273 __ mov(Deoptimization::Unpack_reexecute, L0deopt_mode);
3274
3275 __ bind(cont);
3276
3277 __ set_last_Java_frame(SP, noreg);
3278
3279 // do the call by hand so we can get the oopmap
3280
3281 __ mov(G2_thread, L7_thread_cache);
3282 __ call(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info), relocInfo::runtime_call_type);
3283 __ delayed()->mov(G2_thread, O0);
3284
3285 // Set an oopmap for the call site this describes all our saved volatile registers
3286
3287 oop_maps->add_gc_map( __ offset()-start, map);
3288
3289 __ mov(L7_thread_cache, G2_thread);
3290
3291 __ reset_last_Java_frame();
3292
3293 // NOTE: we know that only O0/O1 will be reloaded by restore_result_registers
3294 // so this move will survive
3295
3296 __ mov(L0deopt_mode, G4deopt_mode);
3297
3298 __ mov(O0, O2UnrollBlock->after_save());
3299
3300 RegisterSaver::restore_result_registers(masm);
3301
3302 Label noException;
3303 __ cmp_and_br(G4deopt_mode, Deoptimization::Unpack_exception, Assembler::notEqual, false, Assembler::pt, noException);
3304
3305 // Move the pending exception from exception_oop to Oexception so
3306 // the pending exception will be picked up the interpreter.
3307 __ ld_ptr(G2_thread, in_bytes(JavaThread::exception_oop_offset()), Oexception);
3308 __ st_ptr(G0, G2_thread, in_bytes(JavaThread::exception_oop_offset()));
3309 __ bind(noException);
3310
3311 // deallocate the deoptimization frame taking care to preserve the return values
3312 __ mov(Oreturn0, Oreturn0->after_save());
3313 __ mov(Oreturn1, Oreturn1->after_save());
3314 __ mov(O2UnrollBlock, O2UnrollBlock->after_save());
3315 __ restore();
3316
3317 // Allocate new interpreter frame(s) and possible c2i adapter frame
3318
3319 make_new_frames(masm, true);
3320
3321 // push a dummy "unpack_frame" taking care of float return values and
3322 // call Deoptimization::unpack_frames to have the unpacker layout
3323 // information in the interpreter frames just created and then return
3327 #if !defined(_LP64)
3328 #if defined(COMPILER2)
3329 // 32-bit 1-register longs return longs in G1
3330 __ stx(Greturn1, saved_Greturn1_addr);
3331 #endif
3332 __ set_last_Java_frame(SP, noreg);
3333 __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), G2_thread, G4deopt_mode);
3334 #else
3335 // LP64 uses g4 in set_last_Java_frame
3336 __ mov(G4deopt_mode, O1);
3337 __ set_last_Java_frame(SP, G0);
3338 __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), G2_thread, O1);
3339 #endif
3340 __ reset_last_Java_frame();
3341 __ ldf(FloatRegisterImpl::D, saved_Freturn0_addr, Freturn0);
3342
3343 #if !defined(_LP64) && defined(COMPILER2)
3344 // In 32 bit, C2 returns longs in G1 so restore the saved G1 into
3345 // I0/I1 if the return value is long.
3346 Label not_long;
3347 __ cmp_and_br(O0,T_LONG, Assembler::notEqual, false, Assembler::pt, not_long);
3348 __ ldd(saved_Greturn1_addr,I0);
3349 __ bind(not_long);
3350 #endif
3351 __ ret();
3352 __ delayed()->restore();
3353
3354 masm->flush();
3355 _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, reexecute_offset, frame_size_words);
3356 _deopt_blob->set_unpack_with_exception_in_tls_offset(exception_in_tls_offset);
3357 }
3358
3359 #ifdef COMPILER2
3360
3361 //------------------------------generate_uncommon_trap_blob--------------------
3362 // Ought to generate an ideal graph & compile, but here's some SPARC ASM
3363 // instead.
3364 void SharedRuntime::generate_uncommon_trap_blob() {
3365 // allocate space for the code
3366 ResourceMark rm;
3367 // setup code generation tools
3500 // Do not use call_VM_leaf, because we need to make a GC map at this call site.
3501 __ mov(G2_thread, O0);
3502 __ save_thread(L7_thread_cache);
3503 __ call(call_ptr);
3504 __ delayed()->nop();
3505
3506 // Set an oopmap for the call site.
3507 // We need this not only for callee-saved registers, but also for volatile
3508 // registers that the compiler might be keeping live across a safepoint.
3509
3510 oop_maps->add_gc_map( __ offset() - start, map);
3511
3512 __ restore_thread(L7_thread_cache);
3513 // clear last_Java_sp
3514 __ reset_last_Java_frame();
3515
3516 // Check for exceptions
3517 Label pending;
3518
3519 __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O1);
3520 __ br_notnull(O1, true, Assembler::pn, pending);
3521
3522 RegisterSaver::restore_live_registers(masm);
3523
3524 // We are back the the original state on entry and ready to go.
3525
3526 __ retl();
3527 __ delayed()->nop();
3528
3529 // Pending exception after the safepoint
3530
3531 __ bind(pending);
3532
3533 RegisterSaver::restore_live_registers(masm);
3534
3535 // We are back the the original state on entry.
3536
3537 // Tail-call forward_exception_entry, with the issuing PC in O7,
3538 // so it looks like the original nmethod called forward_exception_entry.
3539 __ set((intptr_t)StubRoutines::forward_exception_entry(), O0);
3540 __ JMP(O0, 0);
3587 __ save_thread(L7_thread_cache);
3588 __ call(destination, relocInfo::runtime_call_type);
3589 __ delayed()->nop();
3590
3591 // O0 contains the address we are going to jump to assuming no exception got installed
3592
3593 // Set an oopmap for the call site.
3594 // We need this not only for callee-saved registers, but also for volatile
3595 // registers that the compiler might be keeping live across a safepoint.
3596
3597 oop_maps->add_gc_map( __ offset() - start, map);
3598
3599 __ restore_thread(L7_thread_cache);
3600 // clear last_Java_sp
3601 __ reset_last_Java_frame();
3602
3603 // Check for exceptions
3604 Label pending;
3605
3606 __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), O1);
3607 __ br_notnull(O1, true, Assembler::pn, pending);
3608
3609 // get the returned methodOop
3610
3611 __ get_vm_result(G5_method);
3612 __ stx(G5_method, SP, RegisterSaver::G5_offset()+STACK_BIAS);
3613
3614 // O0 is where we want to jump, overwrite G3 which is saved and scratch
3615
3616 __ stx(O0, SP, RegisterSaver::G3_offset()+STACK_BIAS);
3617
3618 RegisterSaver::restore_live_registers(masm);
3619
3620 // We are back the the original state on entry and ready to go.
3621
3622 __ JMP(G3, 0);
3623 __ delayed()->nop();
3624
3625 // Pending exception after the safepoint
3626
3627 __ 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);
|