200 // Initialize monitors in the compiled activation.
201 // I0: pointer to osr buffer
202 //
203 // All other registers are dead at this point and the locals will be
204 // copied into place by code emitted in the IR.
205
206 Register OSR_buf = osrBufferPointer()->as_register();
207 { assert(frame::interpreter_frame_monitor_size() == BasicObjectLock::size(), "adjust code below");
208 int monitor_offset = BytesPerWord * method()->max_locals() +
209 (2 * BytesPerWord) * (number_of_locks - 1);
210 // SharedRuntime::OSR_migration_begin() packs BasicObjectLocks in
211 // the OSR buffer using 2 word entries: first the lock and then
212 // the oop.
213 for (int i = 0; i < number_of_locks; i++) {
214 int slot_offset = monitor_offset - ((i * 2) * BytesPerWord);
215 #ifdef ASSERT
216 // verify the interpreter's monitor has a non-null object
217 {
218 Label L;
219 __ ld_ptr(OSR_buf, slot_offset + 1*BytesPerWord, O7);
220 __ cmp_and_br(G0, O7, Assembler::notEqual, false, Assembler::pt, L);
221 __ stop("locked object is NULL");
222 __ bind(L);
223 }
224 #endif // ASSERT
225 // Copy the lock field into the compiled activation.
226 __ ld_ptr(OSR_buf, slot_offset + 0, O7);
227 __ st_ptr(O7, frame_map()->address_for_monitor_lock(i));
228 __ ld_ptr(OSR_buf, slot_offset + 1*BytesPerWord, O7);
229 __ st_ptr(O7, frame_map()->address_for_monitor_object(i));
230 }
231 }
232 }
233
234
235 // Optimized Library calls
236 // This is the fast version of java.lang.String.compare; it has not
237 // OSR-entry and therefore, we generate a slow version for OSR's
238 void LIR_Assembler::emit_string_compare(LIR_Opr left, LIR_Opr right, LIR_Opr dst, CodeEmitInfo* info) {
239 Register str0 = left->as_register();
240 Register str1 = right->as_register();
2077 __ mov(dst_pos, O3);
2078 __ mov(length, O4);
2079 address copyfunc_addr = StubRoutines::generic_arraycopy();
2080
2081 if (copyfunc_addr == NULL) { // Use C version if stub was not generated
2082 __ call_VM_leaf(tmp, CAST_FROM_FN_PTR(address, Runtime1::arraycopy));
2083 } else {
2084 #ifndef PRODUCT
2085 if (PrintC1Statistics) {
2086 address counter = (address)&Runtime1::_generic_arraycopystub_cnt;
2087 __ inc_counter(counter, G1, G3);
2088 }
2089 #endif
2090 __ call_VM_leaf(tmp, copyfunc_addr);
2091 }
2092
2093 if (copyfunc_addr != NULL) {
2094 __ xor3(O0, -1, tmp);
2095 __ sub(length, tmp, length);
2096 __ add(src_pos, tmp, src_pos);
2097 __ tst(O0);
2098 __ br(Assembler::less, false, Assembler::pn, *stub->entry());
2099 __ delayed()->add(dst_pos, tmp, dst_pos);
2100 } else {
2101 __ tst(O0);
2102 __ br(Assembler::less, false, Assembler::pn, *stub->entry());
2103 __ delayed()->nop();
2104 }
2105 __ bind(*stub->continuation());
2106 return;
2107 }
2108
2109 assert(default_type != NULL && default_type->is_array_klass(), "must be true at this point");
2110
2111 // make sure src and dst are non-null and load array length
2112 if (flags & LIR_OpArrayCopy::src_null_check) {
2113 __ tst(src);
2114 __ brx(Assembler::equal, false, Assembler::pn, *stub->entry());
2115 __ delayed()->nop();
2116 }
2117
2118 if (flags & LIR_OpArrayCopy::dst_null_check) {
2119 __ tst(dst);
2120 __ brx(Assembler::equal, false, Assembler::pn, *stub->entry());
2121 __ delayed()->nop();
2122 }
2123
2124 if (flags & LIR_OpArrayCopy::src_pos_positive_check) {
2125 // test src_pos register
2126 __ tst(src_pos);
2127 __ br(Assembler::less, false, Assembler::pn, *stub->entry());
2128 __ delayed()->nop();
2129 }
2130
2131 if (flags & LIR_OpArrayCopy::dst_pos_positive_check) {
2132 // test dst_pos register
2133 __ tst(dst_pos);
2134 __ br(Assembler::less, false, Assembler::pn, *stub->entry());
2135 __ delayed()->nop();
2136 }
2137
2138 if (flags & LIR_OpArrayCopy::length_positive_check) {
2139 // make sure length isn't negative
2140 __ tst(length);
2141 __ br(Assembler::less, false, Assembler::pn, *stub->entry());
2142 __ delayed()->nop();
2143 }
2144
2145 if (flags & LIR_OpArrayCopy::src_range_check) {
2146 __ ld(src, arrayOopDesc::length_offset_in_bytes(), tmp2);
2147 __ add(length, src_pos, tmp);
2148 __ cmp(tmp2, tmp);
2149 __ br(Assembler::carrySet, false, Assembler::pn, *stub->entry());
2150 __ delayed()->nop();
2151 }
2152
2153 if (flags & LIR_OpArrayCopy::dst_range_check) {
2154 __ ld(dst, arrayOopDesc::length_offset_in_bytes(), tmp2);
2155 __ add(length, dst_pos, tmp);
2156 __ cmp(tmp2, tmp);
2157 __ br(Assembler::carrySet, false, Assembler::pn, *stub->entry());
2158 __ delayed()->nop();
2159 }
2160
2161 int shift = shift_amount(basic_type);
2244 } else {
2245 __ sll(dst_pos, shift, tmp);
2246 __ add(dst_ptr, tmp, dst_ptr);
2247 }
2248 __ mov(length, len);
2249 __ load_klass(dst, tmp);
2250
2251 int ek_offset = (klassOopDesc::header_size() * HeapWordSize +
2252 objArrayKlass::element_klass_offset_in_bytes());
2253 __ ld_ptr(tmp, ek_offset, super_k);
2254
2255 int sco_offset = (klassOopDesc::header_size() * HeapWordSize +
2256 Klass::super_check_offset_offset_in_bytes());
2257 __ lduw(super_k, sco_offset, chk_off);
2258
2259 __ call_VM_leaf(tmp, copyfunc_addr);
2260
2261 #ifndef PRODUCT
2262 if (PrintC1Statistics) {
2263 Label failed;
2264 __ br_notnull(O0, false, Assembler::pn, failed);
2265 __ inc_counter((address)&Runtime1::_arraycopy_checkcast_cnt, G1, G3);
2266 __ bind(failed);
2267 }
2268 #endif
2269
2270 __ br_null(O0, false, Assembler::pt, *stub->continuation(), false);
2271 __ delayed()->xor3(O0, -1, tmp);
2272
2273 #ifndef PRODUCT
2274 if (PrintC1Statistics) {
2275 __ inc_counter((address)&Runtime1::_arraycopy_checkcast_attempt_cnt, G1, G3);
2276 }
2277 #endif
2278
2279 __ sub(length, tmp, length);
2280 __ add(src_pos, tmp, src_pos);
2281 __ br(Assembler::always, false, Assembler::pt, *stub->entry());
2282 __ delayed()->add(dst_pos, tmp, dst_pos);
2283
2284 __ bind(cont);
2296 // primitive case the types must match exactly with src.klass and
2297 // dst.klass each exactly matching the default type. For the
2298 // object array case, if no type check is needed then either the
2299 // dst type is exactly the expected type and the src type is a
2300 // subtype which we can't check or src is the same array as dst
2301 // but not necessarily exactly of type default_type.
2302 Label known_ok, halt;
2303 jobject2reg(op->expected_type()->constant_encoding(), tmp);
2304 if (UseCompressedOops) {
2305 // tmp holds the default type. It currently comes uncompressed after the
2306 // load of a constant, so encode it.
2307 __ encode_heap_oop(tmp);
2308 // load the raw value of the dst klass, since we will be comparing
2309 // uncompressed values directly.
2310 __ lduw(dst, oopDesc::klass_offset_in_bytes(), tmp2);
2311 if (basic_type != T_OBJECT) {
2312 __ cmp(tmp, tmp2);
2313 __ br(Assembler::notEqual, false, Assembler::pn, halt);
2314 // load the raw value of the src klass.
2315 __ delayed()->lduw(src, oopDesc::klass_offset_in_bytes(), tmp2);
2316 __ cmp_and_br(tmp, tmp2, Assembler::equal, false, Assembler::pn, known_ok);
2317 } else {
2318 __ cmp(tmp, tmp2);
2319 __ br(Assembler::equal, false, Assembler::pn, known_ok);
2320 __ delayed()->cmp(src, dst);
2321 __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2322 __ delayed()->nop();
2323 }
2324 } else {
2325 __ ld_ptr(dst, oopDesc::klass_offset_in_bytes(), tmp2);
2326 if (basic_type != T_OBJECT) {
2327 __ cmp(tmp, tmp2);
2328 __ brx(Assembler::notEqual, false, Assembler::pn, halt);
2329 __ delayed()->ld_ptr(src, oopDesc::klass_offset_in_bytes(), tmp2);
2330 __ cmp_and_brx(tmp, tmp2, Assembler::equal, false, Assembler::pn, known_ok);
2331 } else {
2332 __ cmp(tmp, tmp2);
2333 __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2334 __ delayed()->cmp(src, dst);
2335 __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2336 __ delayed()->nop();
2337 }
2338 }
2339 __ bind(halt);
2340 __ stop("incorrect type information in arraycopy");
2341 __ bind(known_ok);
2342 }
2343 #endif
2344
2345 #ifndef PRODUCT
2346 if (PrintC1Statistics) {
2347 address counter = Runtime1::arraycopy_count_address(basic_type);
2348 __ inc_counter(counter, G1, G3);
2349 }
2350 #endif
2508 arrayOopDesc::header_size(op->type()),
2509 type2aelembytes(op->type()),
2510 op->klass()->as_register(),
2511 *op->stub()->entry());
2512 }
2513 __ bind(*op->stub()->continuation());
2514 }
2515
2516
2517 void LIR_Assembler::type_profile_helper(Register mdo, int mdo_offset_bias,
2518 ciMethodData *md, ciProfileData *data,
2519 Register recv, Register tmp1, Label* update_done) {
2520 uint i;
2521 for (i = 0; i < VirtualCallData::row_limit(); i++) {
2522 Label next_test;
2523 // See if the receiver is receiver[n].
2524 Address receiver_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_offset(i)) -
2525 mdo_offset_bias);
2526 __ ld_ptr(receiver_addr, tmp1);
2527 __ verify_oop(tmp1);
2528 __ cmp_and_brx(recv, tmp1, Assembler::notEqual, false, Assembler::pt, next_test);
2529 Address data_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_count_offset(i)) -
2530 mdo_offset_bias);
2531 __ ld_ptr(data_addr, tmp1);
2532 __ add(tmp1, DataLayout::counter_increment, tmp1);
2533 __ st_ptr(tmp1, data_addr);
2534 __ ba(*update_done, false);
2535 __ delayed()->nop();
2536 __ bind(next_test);
2537 }
2538
2539 // Didn't find receiver; find next empty slot and fill it in
2540 for (i = 0; i < VirtualCallData::row_limit(); i++) {
2541 Label next_test;
2542 Address recv_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_offset(i)) -
2543 mdo_offset_bias);
2544 __ ld_ptr(recv_addr, tmp1);
2545 __ br_notnull(tmp1, false, Assembler::pt, next_test);
2546 __ st_ptr(recv, recv_addr);
2547 __ set(DataLayout::counter_increment, tmp1);
2548 __ st_ptr(tmp1, mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_count_offset(i)) -
2549 mdo_offset_bias);
2550 __ ba(*update_done, false);
2551 __ delayed()->nop();
2552 __ bind(next_test);
2553 }
2554 }
2555
2556
2557 void LIR_Assembler::setup_md_access(ciMethod* method, int bci,
2558 ciMethodData*& md, ciProfileData*& data, int& mdo_offset_bias) {
2559 md = method->method_data_or_null();
2560 assert(md != NULL, "Sanity");
2561 data = md->bci_to_data(bci);
2562 assert(data != NULL, "need data for checkcast");
2563 assert(data->is_ReceiverTypeData(), "need ReceiverTypeData for type check");
2564 if (!Assembler::is_simm13(md->byte_offset_of_slot(data, DataLayout::header_offset()) + data->size_in_bytes())) {
2565 // The offset is large so bias the mdo by the base of the slot so
2566 // that the ld can use simm13s to reference the slots of the data
2567 mdo_offset_bias = md->byte_offset_of_slot(data, DataLayout::header_offset());
2568 }
2569 }
2570
2576 Register klass_RInfo = op->tmp2()->as_register();
2577 Register dst = op->result_opr()->as_register();
2578 Register Rtmp1 = op->tmp3()->as_register();
2579 ciKlass* k = op->klass();
2580
2581
2582 if (obj == k_RInfo) {
2583 k_RInfo = klass_RInfo;
2584 klass_RInfo = obj;
2585 }
2586
2587 ciMethodData* md;
2588 ciProfileData* data;
2589 int mdo_offset_bias = 0;
2590 if (op->should_profile()) {
2591 ciMethod* method = op->profiled_method();
2592 assert(method != NULL, "Should have method");
2593 setup_md_access(method, op->profiled_bci(), md, data, mdo_offset_bias);
2594
2595 Label not_null;
2596 __ br_notnull(obj, false, Assembler::pn, not_null);
2597 Register mdo = k_RInfo;
2598 Register data_val = Rtmp1;
2599 jobject2reg(md->constant_encoding(), mdo);
2600 if (mdo_offset_bias > 0) {
2601 __ set(mdo_offset_bias, data_val);
2602 __ add(mdo, data_val, mdo);
2603 }
2604 Address flags_addr(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()) - mdo_offset_bias);
2605 __ ldub(flags_addr, data_val);
2606 __ or3(data_val, BitData::null_seen_byte_constant(), data_val);
2607 __ stb(data_val, flags_addr);
2608 __ ba(*obj_is_null, false);
2609 __ delayed()->nop();
2610 __ bind(not_null);
2611 } else {
2612 __ br_null(obj, false, Assembler::pn, *obj_is_null, false);
2613 __ delayed()->nop();
2614 }
2615
2616 Label profile_cast_failure, profile_cast_success;
2617 Label *failure_target = op->should_profile() ? &profile_cast_failure : failure;
2618 Label *success_target = op->should_profile() ? &profile_cast_success : success;
2619
2620 // patching may screw with our temporaries on sparc,
2621 // so let's do it before loading the class
2622 if (k->is_loaded()) {
2623 jobject2reg(k->constant_encoding(), k_RInfo);
2624 } else {
2625 jobject2reg_with_patching(k_RInfo, op->info_for_patch());
2626 }
2627 assert(obj != k_RInfo, "must be different");
2628
2656 __ delayed()->nop();
2657 __ cmp(G3, 0);
2658 __ br(Assembler::equal, false, Assembler::pn, *failure_target);
2659 __ delayed()->nop();
2660 // Fall through to success case
2661 }
2662 }
2663
2664 if (op->should_profile()) {
2665 Register mdo = klass_RInfo, recv = k_RInfo, tmp1 = Rtmp1;
2666 assert_different_registers(obj, mdo, recv, tmp1);
2667 __ bind(profile_cast_success);
2668 jobject2reg(md->constant_encoding(), mdo);
2669 if (mdo_offset_bias > 0) {
2670 __ set(mdo_offset_bias, tmp1);
2671 __ add(mdo, tmp1, mdo);
2672 }
2673 __ load_klass(obj, recv);
2674 type_profile_helper(mdo, mdo_offset_bias, md, data, recv, tmp1, success);
2675 // Jump over the failure case
2676 __ ba(*success, false);
2677 __ delayed()->nop();
2678 // Cast failure case
2679 __ bind(profile_cast_failure);
2680 jobject2reg(md->constant_encoding(), mdo);
2681 if (mdo_offset_bias > 0) {
2682 __ set(mdo_offset_bias, tmp1);
2683 __ add(mdo, tmp1, mdo);
2684 }
2685 Address data_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()) - mdo_offset_bias);
2686 __ ld_ptr(data_addr, tmp1);
2687 __ sub(tmp1, DataLayout::counter_increment, tmp1);
2688 __ st_ptr(tmp1, data_addr);
2689 __ ba(*failure, false);
2690 __ delayed()->nop();
2691 }
2692 __ ba(*success, false);
2693 __ delayed()->nop();
2694 }
2695
2696 void LIR_Assembler::emit_opTypeCheck(LIR_OpTypeCheck* op) {
2697 LIR_Code code = op->code();
2698 if (code == lir_store_check) {
2699 Register value = op->object()->as_register();
2700 Register array = op->array()->as_register();
2701 Register k_RInfo = op->tmp1()->as_register();
2702 Register klass_RInfo = op->tmp2()->as_register();
2703 Register Rtmp1 = op->tmp3()->as_register();
2704
2705 __ verify_oop(value);
2706 CodeStub* stub = op->stub();
2707 // check if it needs to be profiled
2708 ciMethodData* md;
2709 ciProfileData* data;
2710 int mdo_offset_bias = 0;
2711 if (op->should_profile()) {
2712 ciMethod* method = op->profiled_method();
2713 assert(method != NULL, "Should have method");
2714 setup_md_access(method, op->profiled_bci(), md, data, mdo_offset_bias);
2715 }
2716 Label profile_cast_success, profile_cast_failure, done;
2717 Label *success_target = op->should_profile() ? &profile_cast_success : &done;
2718 Label *failure_target = op->should_profile() ? &profile_cast_failure : stub->entry();
2719
2720 if (op->should_profile()) {
2721 Label not_null;
2722 __ br_notnull(value, false, Assembler::pn, not_null);
2723 Register mdo = k_RInfo;
2724 Register data_val = Rtmp1;
2725 jobject2reg(md->constant_encoding(), mdo);
2726 if (mdo_offset_bias > 0) {
2727 __ set(mdo_offset_bias, data_val);
2728 __ add(mdo, data_val, mdo);
2729 }
2730 Address flags_addr(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()) - mdo_offset_bias);
2731 __ ldub(flags_addr, data_val);
2732 __ or3(data_val, BitData::null_seen_byte_constant(), data_val);
2733 __ stb(data_val, flags_addr);
2734 __ ba(done);
2735 __ bind(not_null);
2736 } else {
2737 __ br_null(value, false, Assembler::pn, done);
2738 }
2739 add_debug_info_for_null_check_here(op->info_for_exception());
2740 __ load_klass(array, k_RInfo);
2741 __ load_klass(value, klass_RInfo);
2742
2743 // get instance klass
2744 __ ld_ptr(Address(k_RInfo, objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc)), k_RInfo);
2745 // perform the fast part of the checking logic
2746 __ check_klass_subtype_fast_path(klass_RInfo, k_RInfo, Rtmp1, O7, success_target, failure_target, NULL);
2747
2748 // call out-of-line instance of __ check_klass_subtype_slow_path(...):
2749 assert(klass_RInfo == G3 && k_RInfo == G1, "incorrect call setup");
2750 __ call(Runtime1::entry_for(Runtime1::slow_subtype_check_id), relocInfo::runtime_call_type);
2751 __ delayed()->nop();
2752 __ cmp(G3, 0);
2753 __ br(Assembler::equal, false, Assembler::pn, *failure_target);
2754 __ delayed()->nop();
2755 // fall through to the success case
2756
2757 if (op->should_profile()) {
2758 Register mdo = klass_RInfo, recv = k_RInfo, tmp1 = Rtmp1;
2759 assert_different_registers(value, mdo, recv, tmp1);
2760 __ bind(profile_cast_success);
2761 jobject2reg(md->constant_encoding(), mdo);
2762 if (mdo_offset_bias > 0) {
2763 __ set(mdo_offset_bias, tmp1);
2764 __ add(mdo, tmp1, mdo);
2765 }
2766 __ load_klass(value, recv);
2767 type_profile_helper(mdo, mdo_offset_bias, md, data, recv, tmp1, &done);
2768 __ ba(done);
2769 // Cast failure case
2770 __ bind(profile_cast_failure);
2771 jobject2reg(md->constant_encoding(), mdo);
2772 if (mdo_offset_bias > 0) {
2773 __ set(mdo_offset_bias, tmp1);
2774 __ add(mdo, tmp1, mdo);
2775 }
2776 Address data_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()) - mdo_offset_bias);
2777 __ ld_ptr(data_addr, tmp1);
2778 __ sub(tmp1, DataLayout::counter_increment, tmp1);
2779 __ st_ptr(tmp1, data_addr);
2780 __ ba(*stub->entry(), false);
2781 __ delayed()->nop();
2782 }
2783 __ bind(done);
2784 } else if (code == lir_checkcast) {
2785 Register obj = op->object()->as_register();
2786 Register dst = op->result_opr()->as_register();
2787 Label success;
2788 emit_typecheck_helper(op, &success, op->stub()->entry(), &success);
2789 __ bind(success);
2790 __ mov(obj, dst);
2791 } else if (code == lir_instanceof) {
2792 Register obj = op->object()->as_register();
2793 Register dst = op->result_opr()->as_register();
2794 Label success, failure, done;
2795 emit_typecheck_helper(op, &success, &failure, &failure);
2796 __ bind(failure);
2797 __ set(0, dst);
2798 __ ba(done);
2799 __ bind(success);
2800 __ set(1, dst);
2801 __ bind(done);
2802 } else {
2803 ShouldNotReachHere();
2804 }
2805
2806 }
2807
2808
2809 void LIR_Assembler::emit_compare_and_swap(LIR_OpCompareAndSwap* op) {
2810 if (op->code() == lir_cas_long) {
2811 assert(VM_Version::supports_cx8(), "wrong machine");
2812 Register addr = op->addr()->as_pointer_register();
2813 Register cmp_value_lo = op->cmp_value()->as_register_lo();
2814 Register cmp_value_hi = op->cmp_value()->as_register_hi();
2815 Register new_value_lo = op->new_value()->as_register_lo();
2816 Register new_value_hi = op->new_value()->as_register_hi();
2817 Register t1 = op->tmp1()->as_register();
2818 Register t2 = op->tmp2()->as_register();
|
200 // Initialize monitors in the compiled activation.
201 // I0: pointer to osr buffer
202 //
203 // All other registers are dead at this point and the locals will be
204 // copied into place by code emitted in the IR.
205
206 Register OSR_buf = osrBufferPointer()->as_register();
207 { assert(frame::interpreter_frame_monitor_size() == BasicObjectLock::size(), "adjust code below");
208 int monitor_offset = BytesPerWord * method()->max_locals() +
209 (2 * BytesPerWord) * (number_of_locks - 1);
210 // SharedRuntime::OSR_migration_begin() packs BasicObjectLocks in
211 // the OSR buffer using 2 word entries: first the lock and then
212 // the oop.
213 for (int i = 0; i < number_of_locks; i++) {
214 int slot_offset = monitor_offset - ((i * 2) * BytesPerWord);
215 #ifdef ASSERT
216 // verify the interpreter's monitor has a non-null object
217 {
218 Label L;
219 __ ld_ptr(OSR_buf, slot_offset + 1*BytesPerWord, O7);
220 __ cmp_and_br_short(O7, G0, Assembler::notEqual, Assembler::pt, L);
221 __ stop("locked object is NULL");
222 __ bind(L);
223 }
224 #endif // ASSERT
225 // Copy the lock field into the compiled activation.
226 __ ld_ptr(OSR_buf, slot_offset + 0, O7);
227 __ st_ptr(O7, frame_map()->address_for_monitor_lock(i));
228 __ ld_ptr(OSR_buf, slot_offset + 1*BytesPerWord, O7);
229 __ st_ptr(O7, frame_map()->address_for_monitor_object(i));
230 }
231 }
232 }
233
234
235 // Optimized Library calls
236 // This is the fast version of java.lang.String.compare; it has not
237 // OSR-entry and therefore, we generate a slow version for OSR's
238 void LIR_Assembler::emit_string_compare(LIR_Opr left, LIR_Opr right, LIR_Opr dst, CodeEmitInfo* info) {
239 Register str0 = left->as_register();
240 Register str1 = right->as_register();
2077 __ mov(dst_pos, O3);
2078 __ mov(length, O4);
2079 address copyfunc_addr = StubRoutines::generic_arraycopy();
2080
2081 if (copyfunc_addr == NULL) { // Use C version if stub was not generated
2082 __ call_VM_leaf(tmp, CAST_FROM_FN_PTR(address, Runtime1::arraycopy));
2083 } else {
2084 #ifndef PRODUCT
2085 if (PrintC1Statistics) {
2086 address counter = (address)&Runtime1::_generic_arraycopystub_cnt;
2087 __ inc_counter(counter, G1, G3);
2088 }
2089 #endif
2090 __ call_VM_leaf(tmp, copyfunc_addr);
2091 }
2092
2093 if (copyfunc_addr != NULL) {
2094 __ xor3(O0, -1, tmp);
2095 __ sub(length, tmp, length);
2096 __ add(src_pos, tmp, src_pos);
2097 __ cmp_zero_and_br(Assembler::less, O0, *stub->entry());
2098 __ delayed()->add(dst_pos, tmp, dst_pos);
2099 } else {
2100 __ cmp_zero_and_br(Assembler::less, O0, *stub->entry());
2101 __ delayed()->nop();
2102 }
2103 __ bind(*stub->continuation());
2104 return;
2105 }
2106
2107 assert(default_type != NULL && default_type->is_array_klass(), "must be true at this point");
2108
2109 // make sure src and dst are non-null and load array length
2110 if (flags & LIR_OpArrayCopy::src_null_check) {
2111 __ tst(src);
2112 __ brx(Assembler::equal, false, Assembler::pn, *stub->entry());
2113 __ delayed()->nop();
2114 }
2115
2116 if (flags & LIR_OpArrayCopy::dst_null_check) {
2117 __ tst(dst);
2118 __ brx(Assembler::equal, false, Assembler::pn, *stub->entry());
2119 __ delayed()->nop();
2120 }
2121
2122 if (flags & LIR_OpArrayCopy::src_pos_positive_check) {
2123 // test src_pos register
2124 __ cmp_zero_and_br(Assembler::less, src_pos, *stub->entry());
2125 __ delayed()->nop();
2126 }
2127
2128 if (flags & LIR_OpArrayCopy::dst_pos_positive_check) {
2129 // test dst_pos register
2130 __ cmp_zero_and_br(Assembler::less, dst_pos, *stub->entry());
2131 __ delayed()->nop();
2132 }
2133
2134 if (flags & LIR_OpArrayCopy::length_positive_check) {
2135 // make sure length isn't negative
2136 __ cmp_zero_and_br(Assembler::less, length, *stub->entry());
2137 __ delayed()->nop();
2138 }
2139
2140 if (flags & LIR_OpArrayCopy::src_range_check) {
2141 __ ld(src, arrayOopDesc::length_offset_in_bytes(), tmp2);
2142 __ add(length, src_pos, tmp);
2143 __ cmp(tmp2, tmp);
2144 __ br(Assembler::carrySet, false, Assembler::pn, *stub->entry());
2145 __ delayed()->nop();
2146 }
2147
2148 if (flags & LIR_OpArrayCopy::dst_range_check) {
2149 __ ld(dst, arrayOopDesc::length_offset_in_bytes(), tmp2);
2150 __ add(length, dst_pos, tmp);
2151 __ cmp(tmp2, tmp);
2152 __ br(Assembler::carrySet, false, Assembler::pn, *stub->entry());
2153 __ delayed()->nop();
2154 }
2155
2156 int shift = shift_amount(basic_type);
2239 } else {
2240 __ sll(dst_pos, shift, tmp);
2241 __ add(dst_ptr, tmp, dst_ptr);
2242 }
2243 __ mov(length, len);
2244 __ load_klass(dst, tmp);
2245
2246 int ek_offset = (klassOopDesc::header_size() * HeapWordSize +
2247 objArrayKlass::element_klass_offset_in_bytes());
2248 __ ld_ptr(tmp, ek_offset, super_k);
2249
2250 int sco_offset = (klassOopDesc::header_size() * HeapWordSize +
2251 Klass::super_check_offset_offset_in_bytes());
2252 __ lduw(super_k, sco_offset, chk_off);
2253
2254 __ call_VM_leaf(tmp, copyfunc_addr);
2255
2256 #ifndef PRODUCT
2257 if (PrintC1Statistics) {
2258 Label failed;
2259 __ br_notnull_short(O0, Assembler::pn, failed);
2260 __ inc_counter((address)&Runtime1::_arraycopy_checkcast_cnt, G1, G3);
2261 __ bind(failed);
2262 }
2263 #endif
2264
2265 __ br_null(O0, false, Assembler::pt, *stub->continuation(), false);
2266 __ delayed()->xor3(O0, -1, tmp);
2267
2268 #ifndef PRODUCT
2269 if (PrintC1Statistics) {
2270 __ inc_counter((address)&Runtime1::_arraycopy_checkcast_attempt_cnt, G1, G3);
2271 }
2272 #endif
2273
2274 __ sub(length, tmp, length);
2275 __ add(src_pos, tmp, src_pos);
2276 __ br(Assembler::always, false, Assembler::pt, *stub->entry());
2277 __ delayed()->add(dst_pos, tmp, dst_pos);
2278
2279 __ bind(cont);
2291 // primitive case the types must match exactly with src.klass and
2292 // dst.klass each exactly matching the default type. For the
2293 // object array case, if no type check is needed then either the
2294 // dst type is exactly the expected type and the src type is a
2295 // subtype which we can't check or src is the same array as dst
2296 // but not necessarily exactly of type default_type.
2297 Label known_ok, halt;
2298 jobject2reg(op->expected_type()->constant_encoding(), tmp);
2299 if (UseCompressedOops) {
2300 // tmp holds the default type. It currently comes uncompressed after the
2301 // load of a constant, so encode it.
2302 __ encode_heap_oop(tmp);
2303 // load the raw value of the dst klass, since we will be comparing
2304 // uncompressed values directly.
2305 __ lduw(dst, oopDesc::klass_offset_in_bytes(), tmp2);
2306 if (basic_type != T_OBJECT) {
2307 __ cmp(tmp, tmp2);
2308 __ br(Assembler::notEqual, false, Assembler::pn, halt);
2309 // load the raw value of the src klass.
2310 __ delayed()->lduw(src, oopDesc::klass_offset_in_bytes(), tmp2);
2311 __ cmp_and_br_short(tmp, tmp2, Assembler::equal, Assembler::pn, known_ok);
2312 } else {
2313 __ cmp(tmp, tmp2);
2314 __ br(Assembler::equal, false, Assembler::pn, known_ok);
2315 __ delayed()->cmp(src, dst);
2316 __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2317 __ delayed()->nop();
2318 }
2319 } else {
2320 __ ld_ptr(dst, oopDesc::klass_offset_in_bytes(), tmp2);
2321 if (basic_type != T_OBJECT) {
2322 __ cmp(tmp, tmp2);
2323 __ brx(Assembler::notEqual, false, Assembler::pn, halt);
2324 __ delayed()->ld_ptr(src, oopDesc::klass_offset_in_bytes(), tmp2);
2325 __ cmp_and_brx_short(tmp, tmp2, Assembler::equal, Assembler::pn, known_ok);
2326 } else {
2327 __ cmp(tmp, tmp2);
2328 __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2329 __ delayed()->cmp(src, dst);
2330 __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2331 __ delayed()->nop();
2332 }
2333 }
2334 __ bind(halt);
2335 __ stop("incorrect type information in arraycopy");
2336 __ bind(known_ok);
2337 }
2338 #endif
2339
2340 #ifndef PRODUCT
2341 if (PrintC1Statistics) {
2342 address counter = Runtime1::arraycopy_count_address(basic_type);
2343 __ inc_counter(counter, G1, G3);
2344 }
2345 #endif
2503 arrayOopDesc::header_size(op->type()),
2504 type2aelembytes(op->type()),
2505 op->klass()->as_register(),
2506 *op->stub()->entry());
2507 }
2508 __ bind(*op->stub()->continuation());
2509 }
2510
2511
2512 void LIR_Assembler::type_profile_helper(Register mdo, int mdo_offset_bias,
2513 ciMethodData *md, ciProfileData *data,
2514 Register recv, Register tmp1, Label* update_done) {
2515 uint i;
2516 for (i = 0; i < VirtualCallData::row_limit(); i++) {
2517 Label next_test;
2518 // See if the receiver is receiver[n].
2519 Address receiver_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_offset(i)) -
2520 mdo_offset_bias);
2521 __ ld_ptr(receiver_addr, tmp1);
2522 __ verify_oop(tmp1);
2523 __ cmp_and_brx_short(recv, tmp1, Assembler::notEqual, Assembler::pt, next_test);
2524 Address data_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_count_offset(i)) -
2525 mdo_offset_bias);
2526 __ ld_ptr(data_addr, tmp1);
2527 __ add(tmp1, DataLayout::counter_increment, tmp1);
2528 __ st_ptr(tmp1, data_addr);
2529 __ ba(*update_done);
2530 __ delayed()->nop();
2531 __ bind(next_test);
2532 }
2533
2534 // Didn't find receiver; find next empty slot and fill it in
2535 for (i = 0; i < VirtualCallData::row_limit(); i++) {
2536 Label next_test;
2537 Address recv_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_offset(i)) -
2538 mdo_offset_bias);
2539 __ ld_ptr(recv_addr, tmp1);
2540 __ br_notnull_short(tmp1, Assembler::pt, next_test);
2541 __ st_ptr(recv, recv_addr);
2542 __ set(DataLayout::counter_increment, tmp1);
2543 __ st_ptr(tmp1, mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_count_offset(i)) -
2544 mdo_offset_bias);
2545 __ ba(*update_done);
2546 __ delayed()->nop();
2547 __ bind(next_test);
2548 }
2549 }
2550
2551
2552 void LIR_Assembler::setup_md_access(ciMethod* method, int bci,
2553 ciMethodData*& md, ciProfileData*& data, int& mdo_offset_bias) {
2554 md = method->method_data_or_null();
2555 assert(md != NULL, "Sanity");
2556 data = md->bci_to_data(bci);
2557 assert(data != NULL, "need data for checkcast");
2558 assert(data->is_ReceiverTypeData(), "need ReceiverTypeData for type check");
2559 if (!Assembler::is_simm13(md->byte_offset_of_slot(data, DataLayout::header_offset()) + data->size_in_bytes())) {
2560 // The offset is large so bias the mdo by the base of the slot so
2561 // that the ld can use simm13s to reference the slots of the data
2562 mdo_offset_bias = md->byte_offset_of_slot(data, DataLayout::header_offset());
2563 }
2564 }
2565
2571 Register klass_RInfo = op->tmp2()->as_register();
2572 Register dst = op->result_opr()->as_register();
2573 Register Rtmp1 = op->tmp3()->as_register();
2574 ciKlass* k = op->klass();
2575
2576
2577 if (obj == k_RInfo) {
2578 k_RInfo = klass_RInfo;
2579 klass_RInfo = obj;
2580 }
2581
2582 ciMethodData* md;
2583 ciProfileData* data;
2584 int mdo_offset_bias = 0;
2585 if (op->should_profile()) {
2586 ciMethod* method = op->profiled_method();
2587 assert(method != NULL, "Should have method");
2588 setup_md_access(method, op->profiled_bci(), md, data, mdo_offset_bias);
2589
2590 Label not_null;
2591 __ br_notnull_short(obj, Assembler::pn, not_null);
2592 Register mdo = k_RInfo;
2593 Register data_val = Rtmp1;
2594 jobject2reg(md->constant_encoding(), mdo);
2595 if (mdo_offset_bias > 0) {
2596 __ set(mdo_offset_bias, data_val);
2597 __ add(mdo, data_val, mdo);
2598 }
2599 Address flags_addr(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()) - mdo_offset_bias);
2600 __ ldub(flags_addr, data_val);
2601 __ or3(data_val, BitData::null_seen_byte_constant(), data_val);
2602 __ stb(data_val, flags_addr);
2603 __ ba(*obj_is_null);
2604 __ delayed()->nop();
2605 __ bind(not_null);
2606 } else {
2607 __ br_null(obj, false, Assembler::pn, *obj_is_null, false);
2608 __ delayed()->nop();
2609 }
2610
2611 Label profile_cast_failure, profile_cast_success;
2612 Label *failure_target = op->should_profile() ? &profile_cast_failure : failure;
2613 Label *success_target = op->should_profile() ? &profile_cast_success : success;
2614
2615 // patching may screw with our temporaries on sparc,
2616 // so let's do it before loading the class
2617 if (k->is_loaded()) {
2618 jobject2reg(k->constant_encoding(), k_RInfo);
2619 } else {
2620 jobject2reg_with_patching(k_RInfo, op->info_for_patch());
2621 }
2622 assert(obj != k_RInfo, "must be different");
2623
2651 __ delayed()->nop();
2652 __ cmp(G3, 0);
2653 __ br(Assembler::equal, false, Assembler::pn, *failure_target);
2654 __ delayed()->nop();
2655 // Fall through to success case
2656 }
2657 }
2658
2659 if (op->should_profile()) {
2660 Register mdo = klass_RInfo, recv = k_RInfo, tmp1 = Rtmp1;
2661 assert_different_registers(obj, mdo, recv, tmp1);
2662 __ bind(profile_cast_success);
2663 jobject2reg(md->constant_encoding(), mdo);
2664 if (mdo_offset_bias > 0) {
2665 __ set(mdo_offset_bias, tmp1);
2666 __ add(mdo, tmp1, mdo);
2667 }
2668 __ load_klass(obj, recv);
2669 type_profile_helper(mdo, mdo_offset_bias, md, data, recv, tmp1, success);
2670 // Jump over the failure case
2671 __ ba(*success);
2672 __ delayed()->nop();
2673 // Cast failure case
2674 __ bind(profile_cast_failure);
2675 jobject2reg(md->constant_encoding(), mdo);
2676 if (mdo_offset_bias > 0) {
2677 __ set(mdo_offset_bias, tmp1);
2678 __ add(mdo, tmp1, mdo);
2679 }
2680 Address data_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()) - mdo_offset_bias);
2681 __ ld_ptr(data_addr, tmp1);
2682 __ sub(tmp1, DataLayout::counter_increment, tmp1);
2683 __ st_ptr(tmp1, data_addr);
2684 __ ba(*failure);
2685 __ delayed()->nop();
2686 }
2687 __ ba(*success);
2688 __ delayed()->nop();
2689 }
2690
2691 void LIR_Assembler::emit_opTypeCheck(LIR_OpTypeCheck* op) {
2692 LIR_Code code = op->code();
2693 if (code == lir_store_check) {
2694 Register value = op->object()->as_register();
2695 Register array = op->array()->as_register();
2696 Register k_RInfo = op->tmp1()->as_register();
2697 Register klass_RInfo = op->tmp2()->as_register();
2698 Register Rtmp1 = op->tmp3()->as_register();
2699
2700 __ verify_oop(value);
2701 CodeStub* stub = op->stub();
2702 // check if it needs to be profiled
2703 ciMethodData* md;
2704 ciProfileData* data;
2705 int mdo_offset_bias = 0;
2706 if (op->should_profile()) {
2707 ciMethod* method = op->profiled_method();
2708 assert(method != NULL, "Should have method");
2709 setup_md_access(method, op->profiled_bci(), md, data, mdo_offset_bias);
2710 }
2711 Label profile_cast_success, profile_cast_failure, done;
2712 Label *success_target = op->should_profile() ? &profile_cast_success : &done;
2713 Label *failure_target = op->should_profile() ? &profile_cast_failure : stub->entry();
2714
2715 if (op->should_profile()) {
2716 Label not_null;
2717 __ br_notnull_short(value, Assembler::pn, not_null);
2718 Register mdo = k_RInfo;
2719 Register data_val = Rtmp1;
2720 jobject2reg(md->constant_encoding(), mdo);
2721 if (mdo_offset_bias > 0) {
2722 __ set(mdo_offset_bias, data_val);
2723 __ add(mdo, data_val, mdo);
2724 }
2725 Address flags_addr(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()) - mdo_offset_bias);
2726 __ ldub(flags_addr, data_val);
2727 __ or3(data_val, BitData::null_seen_byte_constant(), data_val);
2728 __ stb(data_val, flags_addr);
2729 __ ba_short(done);
2730 __ bind(not_null);
2731 } else {
2732 __ br_null_short(value, Assembler::pn, done);
2733 }
2734 add_debug_info_for_null_check_here(op->info_for_exception());
2735 __ load_klass(array, k_RInfo);
2736 __ load_klass(value, klass_RInfo);
2737
2738 // get instance klass
2739 __ ld_ptr(Address(k_RInfo, objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc)), k_RInfo);
2740 // perform the fast part of the checking logic
2741 __ check_klass_subtype_fast_path(klass_RInfo, k_RInfo, Rtmp1, O7, success_target, failure_target, NULL);
2742
2743 // call out-of-line instance of __ check_klass_subtype_slow_path(...):
2744 assert(klass_RInfo == G3 && k_RInfo == G1, "incorrect call setup");
2745 __ call(Runtime1::entry_for(Runtime1::slow_subtype_check_id), relocInfo::runtime_call_type);
2746 __ delayed()->nop();
2747 __ cmp(G3, 0);
2748 __ br(Assembler::equal, false, Assembler::pn, *failure_target);
2749 __ delayed()->nop();
2750 // fall through to the success case
2751
2752 if (op->should_profile()) {
2753 Register mdo = klass_RInfo, recv = k_RInfo, tmp1 = Rtmp1;
2754 assert_different_registers(value, mdo, recv, tmp1);
2755 __ bind(profile_cast_success);
2756 jobject2reg(md->constant_encoding(), mdo);
2757 if (mdo_offset_bias > 0) {
2758 __ set(mdo_offset_bias, tmp1);
2759 __ add(mdo, tmp1, mdo);
2760 }
2761 __ load_klass(value, recv);
2762 type_profile_helper(mdo, mdo_offset_bias, md, data, recv, tmp1, &done);
2763 __ ba_short(done);
2764 // Cast failure case
2765 __ bind(profile_cast_failure);
2766 jobject2reg(md->constant_encoding(), mdo);
2767 if (mdo_offset_bias > 0) {
2768 __ set(mdo_offset_bias, tmp1);
2769 __ add(mdo, tmp1, mdo);
2770 }
2771 Address data_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()) - mdo_offset_bias);
2772 __ ld_ptr(data_addr, tmp1);
2773 __ sub(tmp1, DataLayout::counter_increment, tmp1);
2774 __ st_ptr(tmp1, data_addr);
2775 __ ba(*stub->entry());
2776 __ delayed()->nop();
2777 }
2778 __ bind(done);
2779 } else if (code == lir_checkcast) {
2780 Register obj = op->object()->as_register();
2781 Register dst = op->result_opr()->as_register();
2782 Label success;
2783 emit_typecheck_helper(op, &success, op->stub()->entry(), &success);
2784 __ bind(success);
2785 __ mov(obj, dst);
2786 } else if (code == lir_instanceof) {
2787 Register obj = op->object()->as_register();
2788 Register dst = op->result_opr()->as_register();
2789 Label success, failure, done;
2790 emit_typecheck_helper(op, &success, &failure, &failure);
2791 __ bind(failure);
2792 __ set(0, dst);
2793 __ ba_short(done);
2794 __ bind(success);
2795 __ set(1, dst);
2796 __ bind(done);
2797 } else {
2798 ShouldNotReachHere();
2799 }
2800
2801 }
2802
2803
2804 void LIR_Assembler::emit_compare_and_swap(LIR_OpCompareAndSwap* op) {
2805 if (op->code() == lir_cas_long) {
2806 assert(VM_Version::supports_cx8(), "wrong machine");
2807 Register addr = op->addr()->as_pointer_register();
2808 Register cmp_value_lo = op->cmp_value()->as_register_lo();
2809 Register cmp_value_hi = op->cmp_value()->as_register_hi();
2810 Register new_value_lo = op->new_value()->as_register_lo();
2811 Register new_value_hi = op->new_value()->as_register_hi();
2812 Register t1 = op->tmp1()->as_register();
2813 Register t2 = op->tmp2()->as_register();
|