src/cpu/sparc/vm/c1_LIRAssembler_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/c1_LIRAssembler_sparc.cpp

Print this page




 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(G0, O7);
 221         __ br(Assembler::notEqual, false, Assembler::pt, L);
 222         __ delayed()->nop();
 223         __ stop("locked object is NULL");
 224         __ bind(L);
 225       }
 226 #endif // ASSERT
 227       // Copy the lock field into the compiled activation.
 228       __ ld_ptr(OSR_buf, slot_offset + 0, O7);
 229       __ st_ptr(O7, frame_map()->address_for_monitor_lock(i));
 230       __ ld_ptr(OSR_buf, slot_offset + 1*BytesPerWord, O7);
 231       __ st_ptr(O7, frame_map()->address_for_monitor_object(i));
 232     }
 233   }
 234 }
 235 
 236 
 237 // Optimized Library calls
 238 // This is the fast version of java.lang.String.compare; it has not
 239 // OSR-entry and therefore, we generate a slow version for OSR's
 240 void LIR_Assembler::emit_string_compare(LIR_Opr left, LIR_Opr right, LIR_Opr dst, CodeEmitInfo* info) {
 241   Register str0 = left->as_register();
 242   Register str1 = right->as_register();


2079     __ mov(dst_pos, O3);
2080     __ mov(length,  O4);
2081     address copyfunc_addr = StubRoutines::generic_arraycopy();
2082 
2083     if (copyfunc_addr == NULL) { // Use C version if stub was not generated
2084       __ call_VM_leaf(tmp, CAST_FROM_FN_PTR(address, Runtime1::arraycopy));
2085     } else {
2086 #ifndef PRODUCT
2087       if (PrintC1Statistics) {
2088         address counter = (address)&Runtime1::_generic_arraycopystub_cnt;
2089         __ inc_counter(counter, G1, G3);
2090       }
2091 #endif
2092       __ call_VM_leaf(tmp, copyfunc_addr);
2093     }
2094 
2095     if (copyfunc_addr != NULL) {
2096       __ xor3(O0, -1, tmp);
2097       __ sub(length, tmp, length);
2098       __ add(src_pos, tmp, src_pos);
2099       __ br_zero(Assembler::less, false, Assembler::pn, O0, *stub->entry());
2100       __ delayed()->add(dst_pos, tmp, dst_pos);
2101     } else {
2102       __ br_zero(Assembler::less, false, Assembler::pn, O0, *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           __ delayed()->nop();
2266           __ inc_counter((address)&Runtime1::_arraycopy_checkcast_cnt, G1, G3);
2267           __ bind(failed);
2268         }
2269 #endif
2270 
2271         __ br_null(O0, false, Assembler::pt,  *stub->continuation());
2272         __ delayed()->xor3(O0, -1, tmp);
2273 
2274 #ifndef PRODUCT
2275         if (PrintC1Statistics) {
2276           __ inc_counter((address)&Runtime1::_arraycopy_checkcast_attempt_cnt, G1, G3);
2277         }
2278 #endif
2279 
2280         __ sub(length, tmp, length);
2281         __ add(src_pos, tmp, src_pos);
2282         __ br(Assembler::always, false, Assembler::pt, *stub->entry());
2283         __ delayed()->add(dst_pos, tmp, dst_pos);
2284 
2285         __ bind(cont);


2297     // primitive case the types must match exactly with src.klass and
2298     // dst.klass each exactly matching the default type.  For the
2299     // object array case, if no type check is needed then either the
2300     // dst type is exactly the expected type and the src type is a
2301     // subtype which we can't check or src is the same array as dst
2302     // but not necessarily exactly of type default_type.
2303     Label known_ok, halt;
2304     jobject2reg(op->expected_type()->constant_encoding(), tmp);
2305     if (UseCompressedOops) {
2306       // tmp holds the default type. It currently comes uncompressed after the
2307       // load of a constant, so encode it.
2308       __ encode_heap_oop(tmp);
2309       // load the raw value of the dst klass, since we will be comparing
2310       // uncompressed values directly.
2311       __ lduw(dst, oopDesc::klass_offset_in_bytes(), tmp2);
2312       if (basic_type != T_OBJECT) {
2313         __ cmp(tmp, tmp2);
2314         __ br(Assembler::notEqual, false, Assembler::pn, halt);
2315         // load the raw value of the src klass.
2316         __ delayed()->lduw(src, oopDesc::klass_offset_in_bytes(), tmp2);
2317         __ cmp(tmp, tmp2);
2318         __ br(Assembler::equal, false, Assembler::pn, known_ok);
2319         __ delayed()->nop();
2320       } else {
2321         __ cmp(tmp, tmp2);
2322         __ br(Assembler::equal, false, Assembler::pn, known_ok);
2323         __ delayed()->cmp(src, dst);
2324         __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2325         __ delayed()->nop();
2326       }
2327     } else {
2328       __ ld_ptr(dst, oopDesc::klass_offset_in_bytes(), tmp2);
2329       if (basic_type != T_OBJECT) {
2330         __ cmp(tmp, tmp2);
2331         __ brx(Assembler::notEqual, false, Assembler::pn, halt);
2332         __ delayed()->ld_ptr(src, oopDesc::klass_offset_in_bytes(), tmp2);
2333         __ cmp(tmp, tmp2);
2334         __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2335         __ delayed()->nop();
2336       } else {
2337         __ cmp(tmp, tmp2);
2338         __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2339         __ delayed()->cmp(src, dst);
2340         __ brx(Assembler::equal, false, Assembler::pn, known_ok);
2341         __ delayed()->nop();
2342       }
2343     }
2344     __ bind(halt);
2345     __ stop("incorrect type information in arraycopy");
2346     __ bind(known_ok);
2347   }
2348 #endif
2349 
2350 #ifndef PRODUCT
2351   if (PrintC1Statistics) {
2352     address counter = Runtime1::arraycopy_count_address(basic_type);
2353     __ inc_counter(counter, G1, G3);
2354   }
2355 #endif


2513                       arrayOopDesc::header_size(op->type()),
2514                       type2aelembytes(op->type()),
2515                       op->klass()->as_register(),
2516                       *op->stub()->entry());
2517   }
2518   __ bind(*op->stub()->continuation());
2519 }
2520 
2521 
2522 void LIR_Assembler::type_profile_helper(Register mdo, int mdo_offset_bias,
2523                                         ciMethodData *md, ciProfileData *data,
2524                                         Register recv, Register tmp1, Label* update_done) {
2525   uint i;
2526   for (i = 0; i < VirtualCallData::row_limit(); i++) {
2527     Label next_test;
2528     // See if the receiver is receiver[n].
2529     Address receiver_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_offset(i)) -
2530                           mdo_offset_bias);
2531     __ ld_ptr(receiver_addr, tmp1);
2532     __ verify_oop(tmp1);
2533     __ cmp(recv, tmp1);
2534     __ brx(Assembler::notEqual, false, Assembler::pt, next_test);
2535     __ delayed()->nop();
2536     Address data_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_count_offset(i)) -
2537                       mdo_offset_bias);
2538     __ ld_ptr(data_addr, tmp1);
2539     __ add(tmp1, DataLayout::counter_increment, tmp1);
2540     __ st_ptr(tmp1, data_addr);
2541     __ ba(false, *update_done);
2542     __ delayed()->nop();
2543     __ bind(next_test);
2544   }
2545 
2546   // Didn't find receiver; find next empty slot and fill it in
2547   for (i = 0; i < VirtualCallData::row_limit(); i++) {
2548     Label next_test;
2549     Address recv_addr(mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_offset(i)) -
2550                       mdo_offset_bias);
2551     __ ld_ptr(recv_addr, tmp1);
2552     __ br_notnull(tmp1, false, Assembler::pt, next_test);
2553     __ delayed()->nop();
2554     __ st_ptr(recv, recv_addr);
2555     __ set(DataLayout::counter_increment, tmp1);
2556     __ st_ptr(tmp1, mdo, md->byte_offset_of_slot(data, ReceiverTypeData::receiver_count_offset(i)) -
2557               mdo_offset_bias);
2558     __ ba(false, *update_done);
2559     __ delayed()->nop();
2560     __ bind(next_test);
2561   }
2562 }
2563 
2564 
2565 void LIR_Assembler::setup_md_access(ciMethod* method, int bci,
2566                                     ciMethodData*& md, ciProfileData*& data, int& mdo_offset_bias) {
2567   md = method->method_data_or_null();
2568   assert(md != NULL, "Sanity");
2569   data = md->bci_to_data(bci);
2570   assert(data != NULL,       "need data for checkcast");
2571   assert(data->is_ReceiverTypeData(), "need ReceiverTypeData for type check");
2572   if (!Assembler::is_simm13(md->byte_offset_of_slot(data, DataLayout::header_offset()) + data->size_in_bytes())) {
2573     // The offset is large so bias the mdo by the base of the slot so
2574     // that the ld can use simm13s to reference the slots of the data
2575     mdo_offset_bias = md->byte_offset_of_slot(data, DataLayout::header_offset());
2576   }
2577 }
2578 


2584   Register klass_RInfo = op->tmp2()->as_register();
2585   Register dst = op->result_opr()->as_register();
2586   Register Rtmp1 = op->tmp3()->as_register();
2587   ciKlass* k = op->klass();
2588 
2589 
2590   if (obj == k_RInfo) {
2591     k_RInfo = klass_RInfo;
2592     klass_RInfo = obj;
2593   }
2594 
2595   ciMethodData* md;
2596   ciProfileData* data;
2597   int mdo_offset_bias = 0;
2598   if (op->should_profile()) {
2599     ciMethod* method = op->profiled_method();
2600     assert(method != NULL, "Should have method");
2601     setup_md_access(method, op->profiled_bci(), md, data, mdo_offset_bias);
2602 
2603     Label not_null;
2604     __ br_notnull(obj, false, Assembler::pn, not_null);
2605     __ delayed()->nop();
2606     Register mdo      = k_RInfo;
2607     Register data_val = Rtmp1;
2608     jobject2reg(md->constant_encoding(), mdo);
2609     if (mdo_offset_bias > 0) {
2610       __ set(mdo_offset_bias, data_val);
2611       __ add(mdo, data_val, mdo);
2612     }
2613     Address flags_addr(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()) - mdo_offset_bias);
2614     __ ldub(flags_addr, data_val);
2615     __ or3(data_val, BitData::null_seen_byte_constant(), data_val);
2616     __ stb(data_val, flags_addr);
2617     __ ba(false, *obj_is_null);
2618     __ delayed()->nop();
2619     __ bind(not_null);
2620   } else {
2621     __ br_null(obj, false, Assembler::pn, *obj_is_null);
2622     __ delayed()->nop();
2623   }
2624 
2625   Label profile_cast_failure, profile_cast_success;
2626   Label *failure_target = op->should_profile() ? &profile_cast_failure : failure;
2627   Label *success_target = op->should_profile() ? &profile_cast_success : success;
2628 
2629   // patching may screw with our temporaries on sparc,
2630   // so let's do it before loading the class
2631   if (k->is_loaded()) {
2632     jobject2reg(k->constant_encoding(), k_RInfo);
2633   } else {
2634     jobject2reg_with_patching(k_RInfo, op->info_for_patch());
2635   }
2636   assert(obj != k_RInfo, "must be different");
2637 


2665       __ delayed()->nop();
2666       __ cmp(G3, 0);
2667       __ br(Assembler::equal, false, Assembler::pn, *failure_target);
2668       __ delayed()->nop();
2669       // Fall through to success case
2670     }
2671   }
2672 
2673   if (op->should_profile()) {
2674     Register mdo  = klass_RInfo, recv = k_RInfo, tmp1 = Rtmp1;
2675     assert_different_registers(obj, mdo, recv, tmp1);
2676     __ bind(profile_cast_success);
2677     jobject2reg(md->constant_encoding(), mdo);
2678     if (mdo_offset_bias > 0) {
2679       __ set(mdo_offset_bias, tmp1);
2680       __ add(mdo, tmp1, mdo);
2681     }
2682     __ load_klass(obj, recv);
2683     type_profile_helper(mdo, mdo_offset_bias, md, data, recv, tmp1, success);
2684     // Jump over the failure case
2685     __ ba(false, *success);
2686     __ delayed()->nop();
2687     // Cast failure case
2688     __ bind(profile_cast_failure);
2689     jobject2reg(md->constant_encoding(), mdo);
2690     if (mdo_offset_bias > 0) {
2691       __ set(mdo_offset_bias, tmp1);
2692       __ add(mdo, tmp1, mdo);
2693     }
2694     Address data_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()) - mdo_offset_bias);
2695     __ ld_ptr(data_addr, tmp1);
2696     __ sub(tmp1, DataLayout::counter_increment, tmp1);
2697     __ st_ptr(tmp1, data_addr);
2698     __ ba(false, *failure);
2699     __ delayed()->nop();
2700   }
2701   __ ba(false, *success);
2702   __ delayed()->nop();
2703 }
2704 
2705 void LIR_Assembler::emit_opTypeCheck(LIR_OpTypeCheck* op) {
2706   LIR_Code code = op->code();
2707   if (code == lir_store_check) {
2708     Register value = op->object()->as_register();
2709     Register array = op->array()->as_register();
2710     Register k_RInfo = op->tmp1()->as_register();
2711     Register klass_RInfo = op->tmp2()->as_register();
2712     Register Rtmp1 = op->tmp3()->as_register();
2713 
2714     __ verify_oop(value);
2715     CodeStub* stub = op->stub();
2716     // check if it needs to be profiled
2717     ciMethodData* md;
2718     ciProfileData* data;
2719     int mdo_offset_bias = 0;
2720     if (op->should_profile()) {
2721       ciMethod* method = op->profiled_method();
2722       assert(method != NULL, "Should have method");
2723       setup_md_access(method, op->profiled_bci(), md, data, mdo_offset_bias);
2724     }
2725     Label profile_cast_success, profile_cast_failure, done;
2726     Label *success_target = op->should_profile() ? &profile_cast_success : &done;
2727     Label *failure_target = op->should_profile() ? &profile_cast_failure : stub->entry();
2728 
2729     if (op->should_profile()) {
2730       Label not_null;
2731       __ br_notnull(value, false, Assembler::pn, not_null);
2732       __ delayed()->nop();
2733       Register mdo      = k_RInfo;
2734       Register data_val = Rtmp1;
2735       jobject2reg(md->constant_encoding(), mdo);
2736       if (mdo_offset_bias > 0) {
2737         __ set(mdo_offset_bias, data_val);
2738         __ add(mdo, data_val, mdo);
2739       }
2740       Address flags_addr(mdo, md->byte_offset_of_slot(data, DataLayout::flags_offset()) - mdo_offset_bias);
2741       __ ldub(flags_addr, data_val);
2742       __ or3(data_val, BitData::null_seen_byte_constant(), data_val);
2743       __ stb(data_val, flags_addr);
2744       __ ba(false, done);
2745       __ delayed()->nop();
2746       __ bind(not_null);
2747     } else {
2748       __ br_null(value, false, Assembler::pn, done);
2749       __ delayed()->nop();
2750     }
2751     add_debug_info_for_null_check_here(op->info_for_exception());
2752     __ load_klass(array, k_RInfo);
2753     __ load_klass(value, klass_RInfo);
2754 
2755     // get instance klass
2756     __ ld_ptr(Address(k_RInfo, objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc)), k_RInfo);
2757     // perform the fast part of the checking logic
2758     __ check_klass_subtype_fast_path(klass_RInfo, k_RInfo, Rtmp1, O7, success_target, failure_target, NULL);
2759 
2760     // call out-of-line instance of __ check_klass_subtype_slow_path(...):
2761     assert(klass_RInfo == G3 && k_RInfo == G1, "incorrect call setup");
2762     __ call(Runtime1::entry_for(Runtime1::slow_subtype_check_id), relocInfo::runtime_call_type);
2763     __ delayed()->nop();
2764     __ cmp(G3, 0);
2765     __ br(Assembler::equal, false, Assembler::pn, *failure_target);
2766     __ delayed()->nop();
2767     // fall through to the success case
2768 
2769     if (op->should_profile()) {
2770       Register mdo  = klass_RInfo, recv = k_RInfo, tmp1 = Rtmp1;
2771       assert_different_registers(value, mdo, recv, tmp1);
2772       __ bind(profile_cast_success);
2773       jobject2reg(md->constant_encoding(), mdo);
2774       if (mdo_offset_bias > 0) {
2775         __ set(mdo_offset_bias, tmp1);
2776         __ add(mdo, tmp1, mdo);
2777       }
2778       __ load_klass(value, recv);
2779       type_profile_helper(mdo, mdo_offset_bias, md, data, recv, tmp1, &done);
2780       __ ba(false, done);
2781       __ delayed()->nop();
2782       // Cast failure case
2783       __ bind(profile_cast_failure);
2784       jobject2reg(md->constant_encoding(), mdo);
2785       if (mdo_offset_bias > 0) {
2786         __ set(mdo_offset_bias, tmp1);
2787         __ add(mdo, tmp1, mdo);
2788       }
2789       Address data_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset()) - mdo_offset_bias);
2790       __ ld_ptr(data_addr, tmp1);
2791       __ sub(tmp1, DataLayout::counter_increment, tmp1);
2792       __ st_ptr(tmp1, data_addr);
2793       __ ba(false, *stub->entry());
2794       __ delayed()->nop();
2795     }
2796     __ bind(done);
2797   } else if (code == lir_checkcast) {
2798     Register obj = op->object()->as_register();
2799     Register dst = op->result_opr()->as_register();
2800     Label success;
2801     emit_typecheck_helper(op, &success, op->stub()->entry(), &success);
2802     __ bind(success);
2803     __ mov(obj, dst);
2804   } else if (code == lir_instanceof) {
2805     Register obj = op->object()->as_register();
2806     Register dst = op->result_opr()->as_register();
2807     Label success, failure, done;
2808     emit_typecheck_helper(op, &success, &failure, &failure);
2809     __ bind(failure);
2810     __ set(0, dst);
2811     __ ba(false, done);
2812     __ delayed()->nop();
2813     __ bind(success);
2814     __ set(1, dst);
2815     __ bind(done);
2816   } else {
2817     ShouldNotReachHere();
2818   }
2819 
2820 }
2821 
2822 
2823 void LIR_Assembler::emit_compare_and_swap(LIR_OpCompareAndSwap* op) {
2824   if (op->code() == lir_cas_long) {
2825     assert(VM_Version::supports_cx8(), "wrong machine");
2826     Register addr = op->addr()->as_pointer_register();
2827     Register cmp_value_lo = op->cmp_value()->as_register_lo();
2828     Register cmp_value_hi = op->cmp_value()->as_register_hi();
2829     Register new_value_lo = op->new_value()->as_register_lo();
2830     Register new_value_hi = op->new_value()->as_register_hi();
2831     Register t1 = op->tmp1()->as_register();
2832     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());
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);
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();


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