changeset 50180 | ffa644980dff |
parent 50113 | caf115bb98ad |
child 50399 | ee87876734c9 |
50179:d9bc8557ae16 | 50180:ffa644980dff |
---|---|
242 bool inline_notify(vmIntrinsics::ID id); |
242 bool inline_notify(vmIntrinsics::ID id); |
243 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y); |
243 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y); |
244 // This returns Type::AnyPtr, RawPtr, or OopPtr. |
244 // This returns Type::AnyPtr, RawPtr, or OopPtr. |
245 int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type); |
245 int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type); |
246 Node* make_unsafe_address(Node*& base, Node* offset, BasicType type = T_ILLEGAL, bool can_cast = false); |
246 Node* make_unsafe_address(Node*& base, Node* offset, BasicType type = T_ILLEGAL, bool can_cast = false); |
247 // Helper for inline_unsafe_access. |
|
248 // Generates the guards that check whether the result of |
|
249 // Unsafe.getObject should be recorded in an SATB log buffer. |
|
250 void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar); |
|
251 |
247 |
252 typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind; |
248 typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind; |
249 DecoratorSet mo_decorator_for_access_kind(AccessKind kind); |
|
253 bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned); |
250 bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned); |
254 static bool klass_needs_init_guard(Node* kls); |
251 static bool klass_needs_init_guard(Node* kls); |
255 bool inline_unsafe_allocate(); |
252 bool inline_unsafe_allocate(); |
256 bool inline_unsafe_newArray(bool uninitialized); |
253 bool inline_unsafe_newArray(bool uninitialized); |
257 bool inline_unsafe_copyMemory(); |
254 bool inline_unsafe_copyMemory(); |
267 bool inline_native_subtype_check(); |
264 bool inline_native_subtype_check(); |
268 bool inline_native_getLength(); |
265 bool inline_native_getLength(); |
269 bool inline_array_copyOf(bool is_copyOfRange); |
266 bool inline_array_copyOf(bool is_copyOfRange); |
270 bool inline_array_equals(StrIntrinsicNode::ArgEnc ae); |
267 bool inline_array_equals(StrIntrinsicNode::ArgEnc ae); |
271 bool inline_preconditions_checkIndex(); |
268 bool inline_preconditions_checkIndex(); |
272 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark); |
269 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array); |
273 bool inline_native_clone(bool is_virtual); |
270 bool inline_native_clone(bool is_virtual); |
274 bool inline_native_Reflection_getCallerClass(); |
271 bool inline_native_Reflection_getCallerClass(); |
275 // Helper function for inlining native object hash method |
272 // Helper function for inlining native object hash method |
276 bool inline_native_hashcode(bool is_virtual, bool is_static); |
273 bool inline_native_hashcode(bool is_virtual, bool is_static); |
277 bool inline_native_getClass(); |
274 bool inline_native_getClass(); |
283 JVMState* arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp); |
280 JVMState* arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp); |
284 void arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, int saved_reexecute_sp, |
281 void arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, int saved_reexecute_sp, |
285 uint new_idx); |
282 uint new_idx); |
286 |
283 |
287 typedef enum { LS_get_add, LS_get_set, LS_cmp_swap, LS_cmp_swap_weak, LS_cmp_exchange } LoadStoreKind; |
284 typedef enum { LS_get_add, LS_get_set, LS_cmp_swap, LS_cmp_swap_weak, LS_cmp_exchange } LoadStoreKind; |
288 MemNode::MemOrd access_kind_to_memord_LS(AccessKind access_kind, bool is_store); |
|
289 MemNode::MemOrd access_kind_to_memord(AccessKind access_kind); |
|
290 bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind, AccessKind access_kind); |
285 bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind, AccessKind access_kind); |
291 bool inline_unsafe_fence(vmIntrinsics::ID id); |
286 bool inline_unsafe_fence(vmIntrinsics::ID id); |
292 bool inline_onspinwait(); |
287 bool inline_onspinwait(); |
293 bool inline_fp_conversions(vmIntrinsics::ID id); |
288 bool inline_fp_conversions(vmIntrinsics::ID id); |
294 bool inline_number_methods(vmIntrinsics::ID id); |
289 bool inline_number_methods(vmIntrinsics::ID id); |
2222 return true; |
2217 return true; |
2223 } |
2218 } |
2224 |
2219 |
2225 //----------------------------inline_unsafe_access---------------------------- |
2220 //----------------------------inline_unsafe_access---------------------------- |
2226 |
2221 |
2227 // Helper that guards and inserts a pre-barrier. |
|
2228 void LibraryCallKit::insert_pre_barrier(Node* base_oop, Node* offset, |
|
2229 Node* pre_val, bool need_mem_bar) { |
|
2230 // We could be accessing the referent field of a reference object. If so, when G1 |
|
2231 // is enabled, we need to log the value in the referent field in an SATB buffer. |
|
2232 // This routine performs some compile time filters and generates suitable |
|
2233 // runtime filters that guard the pre-barrier code. |
|
2234 // Also add memory barrier for non volatile load from the referent field |
|
2235 // to prevent commoning of loads across safepoint. |
|
2236 if (!UseG1GC && !need_mem_bar) |
|
2237 return; |
|
2238 |
|
2239 // Some compile time checks. |
|
2240 |
|
2241 // If offset is a constant, is it java_lang_ref_Reference::_reference_offset? |
|
2242 const TypeX* otype = offset->find_intptr_t_type(); |
|
2243 if (otype != NULL && otype->is_con() && |
|
2244 otype->get_con() != java_lang_ref_Reference::referent_offset) { |
|
2245 // Constant offset but not the reference_offset so just return |
|
2246 return; |
|
2247 } |
|
2248 |
|
2249 // We only need to generate the runtime guards for instances. |
|
2250 const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr(); |
|
2251 if (btype != NULL) { |
|
2252 if (btype->isa_aryptr()) { |
|
2253 // Array type so nothing to do |
|
2254 return; |
|
2255 } |
|
2256 |
|
2257 const TypeInstPtr* itype = btype->isa_instptr(); |
|
2258 if (itype != NULL) { |
|
2259 // Can the klass of base_oop be statically determined to be |
|
2260 // _not_ a sub-class of Reference and _not_ Object? |
|
2261 ciKlass* klass = itype->klass(); |
|
2262 if ( klass->is_loaded() && |
|
2263 !klass->is_subtype_of(env()->Reference_klass()) && |
|
2264 !env()->Object_klass()->is_subtype_of(klass)) { |
|
2265 return; |
|
2266 } |
|
2267 } |
|
2268 } |
|
2269 |
|
2270 // The compile time filters did not reject base_oop/offset so |
|
2271 // we need to generate the following runtime filters |
|
2272 // |
|
2273 // if (offset == java_lang_ref_Reference::_reference_offset) { |
|
2274 // if (instance_of(base, java.lang.ref.Reference)) { |
|
2275 // pre_barrier(_, pre_val, ...); |
|
2276 // } |
|
2277 // } |
|
2278 |
|
2279 float likely = PROB_LIKELY( 0.999); |
|
2280 float unlikely = PROB_UNLIKELY(0.999); |
|
2281 |
|
2282 IdealKit ideal(this); |
|
2283 #define __ ideal. |
|
2284 |
|
2285 Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset); |
|
2286 |
|
2287 __ if_then(offset, BoolTest::eq, referent_off, unlikely); { |
|
2288 // Update graphKit memory and control from IdealKit. |
|
2289 sync_kit(ideal); |
|
2290 |
|
2291 Node* ref_klass_con = makecon(TypeKlassPtr::make(env()->Reference_klass())); |
|
2292 Node* is_instof = gen_instanceof(base_oop, ref_klass_con); |
|
2293 |
|
2294 // Update IdealKit memory and control from graphKit. |
|
2295 __ sync_kit(this); |
|
2296 |
|
2297 Node* one = __ ConI(1); |
|
2298 // is_instof == 0 if base_oop == NULL |
|
2299 __ if_then(is_instof, BoolTest::eq, one, unlikely); { |
|
2300 |
|
2301 // Update graphKit from IdeakKit. |
|
2302 sync_kit(ideal); |
|
2303 |
|
2304 // Use the pre-barrier to record the value in the referent field |
|
2305 pre_barrier(false /* do_load */, |
|
2306 __ ctrl(), |
|
2307 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */, |
|
2308 pre_val /* pre_val */, |
|
2309 T_OBJECT); |
|
2310 if (need_mem_bar) { |
|
2311 // Add memory barrier to prevent commoning reads from this field |
|
2312 // across safepoint since GC can change its value. |
|
2313 insert_mem_bar(Op_MemBarCPUOrder); |
|
2314 } |
|
2315 // Update IdealKit from graphKit. |
|
2316 __ sync_kit(this); |
|
2317 |
|
2318 } __ end_if(); // _ref_type != ref_none |
|
2319 } __ end_if(); // offset == referent_offset |
|
2320 |
|
2321 // Final sync IdealKit and GraphKit. |
|
2322 final_sync(ideal); |
|
2323 #undef __ |
|
2324 } |
|
2325 |
|
2326 |
|
2327 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) { |
2222 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) { |
2328 // Attempt to infer a sharper value type from the offset and base type. |
2223 // Attempt to infer a sharper value type from the offset and base type. |
2329 ciKlass* sharpened_klass = NULL; |
2224 ciKlass* sharpened_klass = NULL; |
2330 |
2225 |
2331 // See if it is an instance field, with an object type. |
2226 // See if it is an instance field, with an object type. |
2360 return tjp; |
2255 return tjp; |
2361 } |
2256 } |
2362 return NULL; |
2257 return NULL; |
2363 } |
2258 } |
2364 |
2259 |
2260 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) { |
|
2261 switch (kind) { |
|
2262 case Relaxed: |
|
2263 return MO_UNORDERED; |
|
2264 case Opaque: |
|
2265 return MO_RELAXED; |
|
2266 case Acquire: |
|
2267 return MO_ACQUIRE; |
|
2268 case Release: |
|
2269 return MO_RELEASE; |
|
2270 case Volatile: |
|
2271 return MO_SEQ_CST; |
|
2272 default: |
|
2273 ShouldNotReachHere(); |
|
2274 return 0; |
|
2275 } |
|
2276 } |
|
2277 |
|
2365 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) { |
2278 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) { |
2366 if (callee()->is_static()) return false; // caller must have the capability! |
2279 if (callee()->is_static()) return false; // caller must have the capability! |
2280 DecoratorSet decorators = C2_UNSAFE_ACCESS; |
|
2367 guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads"); |
2281 guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads"); |
2368 guarantee( is_store || kind != Release, "Release accesses can be produced only for stores"); |
2282 guarantee( is_store || kind != Release, "Release accesses can be produced only for stores"); |
2369 assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type"); |
2283 assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type"); |
2284 |
|
2285 if (type == T_OBJECT || type == T_ARRAY) { |
|
2286 decorators |= ON_UNKNOWN_OOP_REF; |
|
2287 } |
|
2288 |
|
2289 if (unaligned) { |
|
2290 decorators |= C2_UNALIGNED; |
|
2291 } |
|
2370 |
2292 |
2371 #ifndef PRODUCT |
2293 #ifndef PRODUCT |
2372 { |
2294 { |
2373 ResourceMark rm; |
2295 ResourceMark rm; |
2374 // Check the signatures. |
2296 // Check the signatures. |
2424 } |
2346 } |
2425 |
2347 |
2426 // Can base be NULL? Otherwise, always on-heap access. |
2348 // Can base be NULL? Otherwise, always on-heap access. |
2427 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop)); |
2349 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop)); |
2428 |
2350 |
2351 if (!can_access_non_heap) { |
|
2352 decorators |= IN_HEAP; |
|
2353 } |
|
2354 |
|
2429 val = is_store ? argument(4) : NULL; |
2355 val = is_store ? argument(4) : NULL; |
2430 |
2356 |
2431 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); |
2357 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); |
2432 |
2358 |
2433 // Try to categorize the address. |
2359 // Try to categorize the address. |
2461 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched |
2387 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched |
2462 } |
2388 } |
2463 |
2389 |
2464 assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched"); |
2390 assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched"); |
2465 |
2391 |
2392 if (mismatched) { |
|
2393 decorators |= C2_MISMATCHED; |
|
2394 } |
|
2395 |
|
2466 // First guess at the value type. |
2396 // First guess at the value type. |
2467 const Type *value_type = Type::get_const_basic_type(type); |
2397 const Type *value_type = Type::get_const_basic_type(type); |
2468 |
2398 |
2469 // We will need memory barriers unless we can determine a unique |
|
2470 // alias category for this reference. (Note: If for some reason |
|
2471 // the barriers get omitted and the unsafe reference begins to "pollute" |
|
2472 // the alias analysis of the rest of the graph, either Compile::can_alias |
|
2473 // or Compile::must_alias will throw a diagnostic assert.) |
|
2474 bool need_mem_bar = false; |
|
2475 switch (kind) { |
|
2476 case Relaxed: |
|
2477 need_mem_bar = (mismatched && !adr_type->isa_aryptr()) || can_access_non_heap; |
|
2478 break; |
|
2479 case Opaque: |
|
2480 // Opaque uses CPUOrder membars for protection against code movement. |
|
2481 case Acquire: |
|
2482 case Release: |
|
2483 case Volatile: |
|
2484 need_mem_bar = true; |
|
2485 break; |
|
2486 default: |
|
2487 ShouldNotReachHere(); |
|
2488 } |
|
2489 |
|
2490 // Some accesses require access atomicity for all types, notably longs and doubles. |
|
2491 // When AlwaysAtomicAccesses is enabled, all accesses are atomic. |
|
2492 bool requires_atomic_access = false; |
|
2493 switch (kind) { |
|
2494 case Relaxed: |
|
2495 requires_atomic_access = AlwaysAtomicAccesses; |
|
2496 break; |
|
2497 case Opaque: |
|
2498 // Opaque accesses are atomic. |
|
2499 case Acquire: |
|
2500 case Release: |
|
2501 case Volatile: |
|
2502 requires_atomic_access = true; |
|
2503 break; |
|
2504 default: |
|
2505 ShouldNotReachHere(); |
|
2506 } |
|
2507 |
|
2508 // Figure out the memory ordering. |
2399 // Figure out the memory ordering. |
2509 // Acquire/Release/Volatile accesses require marking the loads/stores with MemOrd |
2400 decorators |= mo_decorator_for_access_kind(kind); |
2510 MemNode::MemOrd mo = access_kind_to_memord_LS(kind, is_store); |
|
2511 |
|
2512 // If we are reading the value of the referent field of a Reference |
|
2513 // object (either by using Unsafe directly or through reflection) |
|
2514 // then, if G1 is enabled, we need to record the referent in an |
|
2515 // SATB log buffer using the pre-barrier mechanism. |
|
2516 // Also we need to add memory barrier to prevent commoning reads |
|
2517 // from this field across safepoint since GC can change its value. |
|
2518 bool need_read_barrier = !is_store && |
|
2519 offset != top() && heap_base_oop != top(); |
|
2520 |
2401 |
2521 if (!is_store && type == T_OBJECT) { |
2402 if (!is_store && type == T_OBJECT) { |
2522 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); |
2403 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); |
2523 if (tjp != NULL) { |
2404 if (tjp != NULL) { |
2524 value_type = tjp; |
2405 value_type = tjp; |
2531 } |
2412 } |
2532 // Heap pointers get a null-check from the interpreter, |
2413 // Heap pointers get a null-check from the interpreter, |
2533 // as a courtesy. However, this is not guaranteed by Unsafe, |
2414 // as a courtesy. However, this is not guaranteed by Unsafe, |
2534 // and it is not possible to fully distinguish unintended nulls |
2415 // and it is not possible to fully distinguish unintended nulls |
2535 // from intended ones in this API. |
2416 // from intended ones in this API. |
2536 |
|
2537 // We need to emit leading and trailing CPU membars (see below) in |
|
2538 // addition to memory membars for special access modes. This is a little |
|
2539 // too strong, but avoids the need to insert per-alias-type |
|
2540 // volatile membars (for stores; compare Parse::do_put_xxx), which |
|
2541 // we cannot do effectively here because we probably only have a |
|
2542 // rough approximation of type. |
|
2543 |
|
2544 switch(kind) { |
|
2545 case Relaxed: |
|
2546 case Opaque: |
|
2547 case Acquire: |
|
2548 break; |
|
2549 case Release: |
|
2550 case Volatile: |
|
2551 if (is_store) { |
|
2552 insert_mem_bar(Op_MemBarRelease); |
|
2553 } else { |
|
2554 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { |
|
2555 insert_mem_bar(Op_MemBarVolatile); |
|
2556 } |
|
2557 } |
|
2558 break; |
|
2559 default: |
|
2560 ShouldNotReachHere(); |
|
2561 } |
|
2562 |
|
2563 // Memory barrier to prevent normal and 'unsafe' accesses from |
|
2564 // bypassing each other. Happens after null checks, so the |
|
2565 // exception paths do not take memory state from the memory barrier, |
|
2566 // so there's no problems making a strong assert about mixing users |
|
2567 // of safe & unsafe memory. |
|
2568 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); |
|
2569 |
2417 |
2570 if (!is_store) { |
2418 if (!is_store) { |
2571 Node* p = NULL; |
2419 Node* p = NULL; |
2572 // Try to constant fold a load from a constant field |
2420 // Try to constant fold a load from a constant field |
2573 ciField* field = alias_type->field(); |
2421 ciField* field = alias_type->field(); |
2574 if (heap_base_oop != top() && field != NULL && field->is_constant() && !mismatched) { |
2422 if (heap_base_oop != top() && field != NULL && field->is_constant() && !mismatched) { |
2575 // final or stable field |
2423 // final or stable field |
2576 p = make_constant_from_field(field, heap_base_oop); |
2424 p = make_constant_from_field(field, heap_base_oop); |
2577 } |
2425 } |
2578 if (p == NULL) { |
2426 |
2579 // To be valid, unsafe loads may depend on other conditions than |
2427 if (p == NULL) { // Could not constant fold the load |
2580 // the one that guards them: pin the Load node |
2428 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators); |
2581 LoadNode::ControlDependency dep = LoadNode::Pinned; |
2429 // Normalize the value returned by getBoolean in the following cases |
2582 Node* ctrl = control(); |
2430 if (type == T_BOOLEAN && |
2583 // non volatile loads may be able to float |
2431 (mismatched || |
2584 if (!need_mem_bar && adr_type->isa_instptr()) { |
2432 heap_base_oop == top() || // - heap_base_oop is NULL or |
2585 assert(adr_type->meet(TypePtr::NULL_PTR) != adr_type->remove_speculative(), "should be not null"); |
2433 (can_access_non_heap && field == NULL)) // - heap_base_oop is potentially NULL |
2586 intptr_t offset = Type::OffsetBot; |
2434 // and the unsafe access is made to large offset |
2587 AddPNode::Ideal_base_and_offset(adr, &_gvn, offset); |
2435 // (i.e., larger than the maximum offset necessary for any |
2588 if (offset >= 0) { |
2436 // field access) |
2589 int s = Klass::layout_helper_size_in_bytes(adr_type->isa_instptr()->klass()->layout_helper()); |
|
2590 if (offset < s) { |
|
2591 // Guaranteed to be a valid access, no need to pin it |
|
2592 dep = LoadNode::DependsOnlyOnTest; |
|
2593 ctrl = NULL; |
|
2594 } |
|
2595 } |
|
2596 } |
|
2597 p = make_load(ctrl, adr, value_type, type, adr_type, mo, dep, requires_atomic_access, unaligned, mismatched); |
|
2598 // load value |
|
2599 switch (type) { |
|
2600 case T_BOOLEAN: |
|
2601 { |
|
2602 // Normalize the value returned by getBoolean in the following cases |
|
2603 if (mismatched || |
|
2604 heap_base_oop == top() || // - heap_base_oop is NULL or |
|
2605 (can_access_non_heap && alias_type->field() == NULL) // - heap_base_oop is potentially NULL |
|
2606 // and the unsafe access is made to large offset |
|
2607 // (i.e., larger than the maximum offset necessary for any |
|
2608 // field access) |
|
2609 ) { |
2437 ) { |
2610 IdealKit ideal = IdealKit(this); |
2438 IdealKit ideal = IdealKit(this); |
2611 #define __ ideal. |
2439 #define __ ideal. |
2612 IdealVariable normalized_result(ideal); |
2440 IdealVariable normalized_result(ideal); |
2613 __ declarations_done(); |
2441 __ declarations_done(); |
2616 __ set(normalized_result, ideal.ConI(1)); |
2444 __ set(normalized_result, ideal.ConI(1)); |
2617 ideal.end_if(); |
2445 ideal.end_if(); |
2618 final_sync(ideal); |
2446 final_sync(ideal); |
2619 p = __ value(normalized_result); |
2447 p = __ value(normalized_result); |
2620 #undef __ |
2448 #undef __ |
2621 } |
|
2622 } |
2449 } |
2623 case T_CHAR: |
2450 } |
2624 case T_BYTE: |
2451 if (type == T_ADDRESS) { |
2625 case T_SHORT: |
2452 p = gvn().transform(new CastP2XNode(NULL, p)); |
2626 case T_INT: |
2453 p = ConvX2UL(p); |
2627 case T_LONG: |
|
2628 case T_FLOAT: |
|
2629 case T_DOUBLE: |
|
2630 break; |
|
2631 case T_OBJECT: |
|
2632 if (need_read_barrier) { |
|
2633 // We do not require a mem bar inside pre_barrier if need_mem_bar |
|
2634 // is set: the barriers would be emitted by us. |
|
2635 insert_pre_barrier(heap_base_oop, offset, p, !need_mem_bar); |
|
2636 } |
|
2637 break; |
|
2638 case T_ADDRESS: |
|
2639 // Cast to an int type. |
|
2640 p = _gvn.transform(new CastP2XNode(NULL, p)); |
|
2641 p = ConvX2UL(p); |
|
2642 break; |
|
2643 default: |
|
2644 fatal("unexpected type %d: %s", type, type2name(type)); |
|
2645 break; |
|
2646 } |
|
2647 } |
2454 } |
2648 // The load node has the control of the preceding MemBarCPUOrder. All |
2455 // The load node has the control of the preceding MemBarCPUOrder. All |
2649 // following nodes will have the control of the MemBarCPUOrder inserted at |
2456 // following nodes will have the control of the MemBarCPUOrder inserted at |
2650 // the end of this method. So, pushing the load onto the stack at a later |
2457 // the end of this method. So, pushing the load onto the stack at a later |
2651 // point is fine. |
2458 // point is fine. |
2652 set_result(p); |
2459 set_result(p); |
2653 } else { |
2460 } else { |
2654 // place effect of store into memory |
2461 if (bt == T_ADDRESS) { |
2655 switch (type) { |
|
2656 case T_DOUBLE: |
|
2657 val = dstore_rounding(val); |
|
2658 break; |
|
2659 case T_ADDRESS: |
|
2660 // Repackage the long as a pointer. |
2462 // Repackage the long as a pointer. |
2661 val = ConvL2X(val); |
2463 val = ConvL2X(val); |
2662 val = _gvn.transform(new CastX2PNode(val)); |
2464 val = gvn().transform(new CastX2PNode(val)); |
2663 break; |
2465 } |
2664 default: |
2466 access_store_at(control(), heap_base_oop, adr, adr_type, val, value_type, type, decorators); |
2665 break; |
2467 } |
2666 } |
|
2667 |
|
2668 if (type == T_OBJECT) { |
|
2669 store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo, mismatched); |
|
2670 } else { |
|
2671 store_to_memory(control(), adr, val, type, adr_type, mo, requires_atomic_access, unaligned, mismatched); |
|
2672 } |
|
2673 } |
|
2674 |
|
2675 switch(kind) { |
|
2676 case Relaxed: |
|
2677 case Opaque: |
|
2678 case Release: |
|
2679 break; |
|
2680 case Acquire: |
|
2681 case Volatile: |
|
2682 if (!is_store) { |
|
2683 insert_mem_bar(Op_MemBarAcquire); |
|
2684 } else { |
|
2685 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { |
|
2686 insert_mem_bar(Op_MemBarVolatile); |
|
2687 } |
|
2688 } |
|
2689 break; |
|
2690 default: |
|
2691 ShouldNotReachHere(); |
|
2692 } |
|
2693 |
|
2694 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); |
|
2695 |
2468 |
2696 return true; |
2469 return true; |
2697 } |
2470 } |
2698 |
2471 |
2699 //----------------------------inline_unsafe_load_store---------------------------- |
2472 //----------------------------inline_unsafe_load_store---------------------------- |
2755 // possible are retained from inline_unsafe_access though to make |
2528 // possible are retained from inline_unsafe_access though to make |
2756 // the correspondences clearer. - dl |
2529 // the correspondences clearer. - dl |
2757 |
2530 |
2758 if (callee()->is_static()) return false; // caller must have the capability! |
2531 if (callee()->is_static()) return false; // caller must have the capability! |
2759 |
2532 |
2533 DecoratorSet decorators = C2_UNSAFE_ACCESS; |
|
2534 decorators |= mo_decorator_for_access_kind(access_kind); |
|
2535 |
|
2760 #ifndef PRODUCT |
2536 #ifndef PRODUCT |
2761 BasicType rtype; |
2537 BasicType rtype; |
2762 { |
2538 { |
2763 ResourceMark rm; |
2539 ResourceMark rm; |
2764 // Check the signatures. |
2540 // Check the signatures. |
2886 return true; |
2662 return true; |
2887 } |
2663 } |
2888 |
2664 |
2889 int alias_idx = C->get_alias_index(adr_type); |
2665 int alias_idx = C->get_alias_index(adr_type); |
2890 |
2666 |
2891 // Memory-model-wise, a LoadStore acts like a little synchronized |
2667 if (type == T_OBJECT || type == T_ARRAY) { |
2892 // block, so needs barriers on each side. These don't translate |
2668 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF; |
2893 // into actual barriers on most machines, but we still need rest of |
2669 |
2894 // compiler to respect ordering. |
|
2895 |
|
2896 switch (access_kind) { |
|
2897 case Relaxed: |
|
2898 case Acquire: |
|
2899 break; |
|
2900 case Release: |
|
2901 insert_mem_bar(Op_MemBarRelease); |
|
2902 break; |
|
2903 case Volatile: |
|
2904 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { |
|
2905 insert_mem_bar(Op_MemBarVolatile); |
|
2906 } else { |
|
2907 insert_mem_bar(Op_MemBarRelease); |
|
2908 } |
|
2909 break; |
|
2910 default: |
|
2911 ShouldNotReachHere(); |
|
2912 } |
|
2913 insert_mem_bar(Op_MemBarCPUOrder); |
|
2914 |
|
2915 // Figure out the memory ordering. |
|
2916 MemNode::MemOrd mo = access_kind_to_memord(access_kind); |
|
2917 |
|
2918 // 4984716: MemBars must be inserted before this |
|
2919 // memory node in order to avoid a false |
|
2920 // dependency which will confuse the scheduler. |
|
2921 Node *mem = memory(alias_idx); |
|
2922 |
|
2923 // For now, we handle only those cases that actually exist: ints, |
|
2924 // longs, and Object. Adding others should be straightforward. |
|
2925 Node* load_store = NULL; |
|
2926 switch(type) { |
|
2927 case T_BYTE: |
|
2928 switch(kind) { |
|
2929 case LS_get_add: |
|
2930 load_store = _gvn.transform(new GetAndAddBNode(control(), mem, adr, newval, adr_type)); |
|
2931 break; |
|
2932 case LS_get_set: |
|
2933 load_store = _gvn.transform(new GetAndSetBNode(control(), mem, adr, newval, adr_type)); |
|
2934 break; |
|
2935 case LS_cmp_swap_weak: |
|
2936 load_store = _gvn.transform(new WeakCompareAndSwapBNode(control(), mem, adr, newval, oldval, mo)); |
|
2937 break; |
|
2938 case LS_cmp_swap: |
|
2939 load_store = _gvn.transform(new CompareAndSwapBNode(control(), mem, adr, newval, oldval, mo)); |
|
2940 break; |
|
2941 case LS_cmp_exchange: |
|
2942 load_store = _gvn.transform(new CompareAndExchangeBNode(control(), mem, adr, newval, oldval, adr_type, mo)); |
|
2943 break; |
|
2944 default: |
|
2945 ShouldNotReachHere(); |
|
2946 } |
|
2947 break; |
|
2948 case T_SHORT: |
|
2949 switch(kind) { |
|
2950 case LS_get_add: |
|
2951 load_store = _gvn.transform(new GetAndAddSNode(control(), mem, adr, newval, adr_type)); |
|
2952 break; |
|
2953 case LS_get_set: |
|
2954 load_store = _gvn.transform(new GetAndSetSNode(control(), mem, adr, newval, adr_type)); |
|
2955 break; |
|
2956 case LS_cmp_swap_weak: |
|
2957 load_store = _gvn.transform(new WeakCompareAndSwapSNode(control(), mem, adr, newval, oldval, mo)); |
|
2958 break; |
|
2959 case LS_cmp_swap: |
|
2960 load_store = _gvn.transform(new CompareAndSwapSNode(control(), mem, adr, newval, oldval, mo)); |
|
2961 break; |
|
2962 case LS_cmp_exchange: |
|
2963 load_store = _gvn.transform(new CompareAndExchangeSNode(control(), mem, adr, newval, oldval, adr_type, mo)); |
|
2964 break; |
|
2965 default: |
|
2966 ShouldNotReachHere(); |
|
2967 } |
|
2968 break; |
|
2969 case T_INT: |
|
2970 switch(kind) { |
|
2971 case LS_get_add: |
|
2972 load_store = _gvn.transform(new GetAndAddINode(control(), mem, adr, newval, adr_type)); |
|
2973 break; |
|
2974 case LS_get_set: |
|
2975 load_store = _gvn.transform(new GetAndSetINode(control(), mem, adr, newval, adr_type)); |
|
2976 break; |
|
2977 case LS_cmp_swap_weak: |
|
2978 load_store = _gvn.transform(new WeakCompareAndSwapINode(control(), mem, adr, newval, oldval, mo)); |
|
2979 break; |
|
2980 case LS_cmp_swap: |
|
2981 load_store = _gvn.transform(new CompareAndSwapINode(control(), mem, adr, newval, oldval, mo)); |
|
2982 break; |
|
2983 case LS_cmp_exchange: |
|
2984 load_store = _gvn.transform(new CompareAndExchangeINode(control(), mem, adr, newval, oldval, adr_type, mo)); |
|
2985 break; |
|
2986 default: |
|
2987 ShouldNotReachHere(); |
|
2988 } |
|
2989 break; |
|
2990 case T_LONG: |
|
2991 switch(kind) { |
|
2992 case LS_get_add: |
|
2993 load_store = _gvn.transform(new GetAndAddLNode(control(), mem, adr, newval, adr_type)); |
|
2994 break; |
|
2995 case LS_get_set: |
|
2996 load_store = _gvn.transform(new GetAndSetLNode(control(), mem, adr, newval, adr_type)); |
|
2997 break; |
|
2998 case LS_cmp_swap_weak: |
|
2999 load_store = _gvn.transform(new WeakCompareAndSwapLNode(control(), mem, adr, newval, oldval, mo)); |
|
3000 break; |
|
3001 case LS_cmp_swap: |
|
3002 load_store = _gvn.transform(new CompareAndSwapLNode(control(), mem, adr, newval, oldval, mo)); |
|
3003 break; |
|
3004 case LS_cmp_exchange: |
|
3005 load_store = _gvn.transform(new CompareAndExchangeLNode(control(), mem, adr, newval, oldval, adr_type, mo)); |
|
3006 break; |
|
3007 default: |
|
3008 ShouldNotReachHere(); |
|
3009 } |
|
3010 break; |
|
3011 case T_OBJECT: |
|
3012 // Transformation of a value which could be NULL pointer (CastPP #NULL) |
2670 // Transformation of a value which could be NULL pointer (CastPP #NULL) |
3013 // could be delayed during Parse (for example, in adjust_map_after_if()). |
2671 // could be delayed during Parse (for example, in adjust_map_after_if()). |
3014 // Execute transformation here to avoid barrier generation in such case. |
2672 // Execute transformation here to avoid barrier generation in such case. |
3015 if (_gvn.type(newval) == TypePtr::NULL_PTR) |
2673 if (_gvn.type(newval) == TypePtr::NULL_PTR) |
3016 newval = _gvn.makecon(TypePtr::NULL_PTR); |
2674 newval = _gvn.makecon(TypePtr::NULL_PTR); |
3017 |
2675 |
3018 // Reference stores need a store barrier. |
2676 if (oldval != NULL && _gvn.type(oldval) == TypePtr::NULL_PTR) { |
3019 switch(kind) { |
2677 // Refine the value to a null constant, when it is known to be null |
3020 case LS_get_set: { |
2678 oldval = _gvn.makecon(TypePtr::NULL_PTR); |
3021 // If pre-barrier must execute before the oop store, old value will require do_load here. |
2679 } |
3022 if (!can_move_pre_barrier()) { |
2680 } |
3023 pre_barrier(true /* do_load*/, |
2681 |
3024 control(), base, adr, alias_idx, newval, value_type->make_oopptr(), |
2682 Node* result = NULL; |
3025 NULL /* pre_val*/, |
2683 switch (kind) { |
3026 T_OBJECT); |
2684 case LS_cmp_exchange: { |
3027 } // Else move pre_barrier to use load_store value, see below. |
2685 result = access_atomic_cmpxchg_val_at(control(), base, adr, adr_type, alias_idx, |
3028 break; |
2686 oldval, newval, value_type, type, decorators); |
3029 } |
|
3030 case LS_cmp_swap_weak: |
|
3031 case LS_cmp_swap: |
|
3032 case LS_cmp_exchange: { |
|
3033 // Same as for newval above: |
|
3034 if (_gvn.type(oldval) == TypePtr::NULL_PTR) { |
|
3035 oldval = _gvn.makecon(TypePtr::NULL_PTR); |
|
3036 } |
|
3037 // The only known value which might get overwritten is oldval. |
|
3038 pre_barrier(false /* do_load */, |
|
3039 control(), NULL, NULL, max_juint, NULL, NULL, |
|
3040 oldval /* pre_val */, |
|
3041 T_OBJECT); |
|
3042 break; |
|
3043 } |
|
3044 default: |
|
3045 ShouldNotReachHere(); |
|
3046 } |
|
3047 |
|
3048 #ifdef _LP64 |
|
3049 if (adr->bottom_type()->is_ptr_to_narrowoop()) { |
|
3050 Node *newval_enc = _gvn.transform(new EncodePNode(newval, newval->bottom_type()->make_narrowoop())); |
|
3051 |
|
3052 switch(kind) { |
|
3053 case LS_get_set: |
|
3054 load_store = _gvn.transform(new GetAndSetNNode(control(), mem, adr, newval_enc, adr_type, value_type->make_narrowoop())); |
|
3055 break; |
|
3056 case LS_cmp_swap_weak: { |
|
3057 Node *oldval_enc = _gvn.transform(new EncodePNode(oldval, oldval->bottom_type()->make_narrowoop())); |
|
3058 load_store = _gvn.transform(new WeakCompareAndSwapNNode(control(), mem, adr, newval_enc, oldval_enc, mo)); |
|
3059 break; |
|
3060 } |
|
3061 case LS_cmp_swap: { |
|
3062 Node *oldval_enc = _gvn.transform(new EncodePNode(oldval, oldval->bottom_type()->make_narrowoop())); |
|
3063 load_store = _gvn.transform(new CompareAndSwapNNode(control(), mem, adr, newval_enc, oldval_enc, mo)); |
|
3064 break; |
|
3065 } |
|
3066 case LS_cmp_exchange: { |
|
3067 Node *oldval_enc = _gvn.transform(new EncodePNode(oldval, oldval->bottom_type()->make_narrowoop())); |
|
3068 load_store = _gvn.transform(new CompareAndExchangeNNode(control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo)); |
|
3069 break; |
|
3070 } |
|
3071 default: |
|
3072 ShouldNotReachHere(); |
|
3073 } |
|
3074 } else |
|
3075 #endif |
|
3076 switch (kind) { |
|
3077 case LS_get_set: |
|
3078 load_store = _gvn.transform(new GetAndSetPNode(control(), mem, adr, newval, adr_type, value_type->is_oopptr())); |
|
3079 break; |
|
3080 case LS_cmp_swap_weak: |
|
3081 load_store = _gvn.transform(new WeakCompareAndSwapPNode(control(), mem, adr, newval, oldval, mo)); |
|
3082 break; |
|
3083 case LS_cmp_swap: |
|
3084 load_store = _gvn.transform(new CompareAndSwapPNode(control(), mem, adr, newval, oldval, mo)); |
|
3085 break; |
|
3086 case LS_cmp_exchange: |
|
3087 load_store = _gvn.transform(new CompareAndExchangePNode(control(), mem, adr, newval, oldval, adr_type, value_type->is_oopptr(), mo)); |
|
3088 break; |
|
3089 default: |
|
3090 ShouldNotReachHere(); |
|
3091 } |
|
3092 |
|
3093 // Emit the post barrier only when the actual store happened. This makes sense |
|
3094 // to check only for LS_cmp_* that can fail to set the value. |
|
3095 // LS_cmp_exchange does not produce any branches by default, so there is no |
|
3096 // boolean result to piggyback on. TODO: When we merge CompareAndSwap with |
|
3097 // CompareAndExchange and move branches here, it would make sense to conditionalize |
|
3098 // post_barriers for LS_cmp_exchange as well. |
|
3099 // |
|
3100 // CAS success path is marked more likely since we anticipate this is a performance |
|
3101 // critical path, while CAS failure path can use the penalty for going through unlikely |
|
3102 // path as backoff. Which is still better than doing a store barrier there. |
|
3103 switch (kind) { |
|
3104 case LS_get_set: |
|
3105 case LS_cmp_exchange: { |
|
3106 post_barrier(control(), load_store, base, adr, alias_idx, newval, T_OBJECT, true); |
|
3107 break; |
|
3108 } |
|
3109 case LS_cmp_swap_weak: |
|
3110 case LS_cmp_swap: { |
|
3111 IdealKit ideal(this); |
|
3112 ideal.if_then(load_store, BoolTest::ne, ideal.ConI(0), PROB_STATIC_FREQUENT); { |
|
3113 sync_kit(ideal); |
|
3114 post_barrier(ideal.ctrl(), load_store, base, adr, alias_idx, newval, T_OBJECT, true); |
|
3115 ideal.sync_kit(this); |
|
3116 } ideal.end_if(); |
|
3117 final_sync(ideal); |
|
3118 break; |
|
3119 } |
|
3120 default: |
|
3121 ShouldNotReachHere(); |
|
3122 } |
|
3123 break; |
|
3124 default: |
|
3125 fatal("unexpected type %d: %s", type, type2name(type)); |
|
3126 break; |
|
3127 } |
|
3128 |
|
3129 // SCMemProjNodes represent the memory state of a LoadStore. Their |
|
3130 // main role is to prevent LoadStore nodes from being optimized away |
|
3131 // when their results aren't used. |
|
3132 Node* proj = _gvn.transform(new SCMemProjNode(load_store)); |
|
3133 set_memory(proj, alias_idx); |
|
3134 |
|
3135 if (type == T_OBJECT && (kind == LS_get_set || kind == LS_cmp_exchange)) { |
|
3136 #ifdef _LP64 |
|
3137 if (adr->bottom_type()->is_ptr_to_narrowoop()) { |
|
3138 load_store = _gvn.transform(new DecodeNNode(load_store, load_store->get_ptr_type())); |
|
3139 } |
|
3140 #endif |
|
3141 if (can_move_pre_barrier() && kind == LS_get_set) { |
|
3142 // Don't need to load pre_val. The old value is returned by load_store. |
|
3143 // The pre_barrier can execute after the xchg as long as no safepoint |
|
3144 // gets inserted between them. |
|
3145 pre_barrier(false /* do_load */, |
|
3146 control(), NULL, NULL, max_juint, NULL, NULL, |
|
3147 load_store /* pre_val */, |
|
3148 T_OBJECT); |
|
3149 } |
|
3150 } |
|
3151 |
|
3152 // Add the trailing membar surrounding the access |
|
3153 insert_mem_bar(Op_MemBarCPUOrder); |
|
3154 |
|
3155 switch (access_kind) { |
|
3156 case Relaxed: |
|
3157 case Release: |
|
3158 break; // do nothing |
|
3159 case Acquire: |
|
3160 case Volatile: |
|
3161 insert_mem_bar(Op_MemBarAcquire); |
|
3162 // !support_IRIW_for_not_multiple_copy_atomic_cpu handled in platform code |
|
3163 break; |
2687 break; |
2688 } |
|
2689 case LS_cmp_swap_weak: |
|
2690 decorators |= C2_WEAK_CMPXCHG; |
|
2691 case LS_cmp_swap: { |
|
2692 result = access_atomic_cmpxchg_bool_at(control(), base, adr, adr_type, alias_idx, |
|
2693 oldval, newval, value_type, type, decorators); |
|
2694 break; |
|
2695 } |
|
2696 case LS_get_set: { |
|
2697 result = access_atomic_xchg_at(control(), base, adr, adr_type, alias_idx, |
|
2698 newval, value_type, type, decorators); |
|
2699 break; |
|
2700 } |
|
2701 case LS_get_add: { |
|
2702 result = access_atomic_add_at(control(), base, adr, adr_type, alias_idx, |
|
2703 newval, value_type, type, decorators); |
|
2704 break; |
|
2705 } |
|
3164 default: |
2706 default: |
3165 ShouldNotReachHere(); |
2707 ShouldNotReachHere(); |
3166 } |
2708 } |
3167 |
2709 |
3168 assert(type2size[load_store->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); |
2710 assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); |
3169 set_result(load_store); |
2711 set_result(result); |
3170 return true; |
2712 return true; |
3171 } |
|
3172 |
|
3173 MemNode::MemOrd LibraryCallKit::access_kind_to_memord_LS(AccessKind kind, bool is_store) { |
|
3174 MemNode::MemOrd mo = MemNode::unset; |
|
3175 switch(kind) { |
|
3176 case Opaque: |
|
3177 case Relaxed: mo = MemNode::unordered; break; |
|
3178 case Acquire: mo = MemNode::acquire; break; |
|
3179 case Release: mo = MemNode::release; break; |
|
3180 case Volatile: mo = is_store ? MemNode::release : MemNode::acquire; break; |
|
3181 default: |
|
3182 ShouldNotReachHere(); |
|
3183 } |
|
3184 guarantee(mo != MemNode::unset, "Should select memory ordering"); |
|
3185 return mo; |
|
3186 } |
|
3187 |
|
3188 MemNode::MemOrd LibraryCallKit::access_kind_to_memord(AccessKind kind) { |
|
3189 MemNode::MemOrd mo = MemNode::unset; |
|
3190 switch(kind) { |
|
3191 case Opaque: |
|
3192 case Relaxed: mo = MemNode::unordered; break; |
|
3193 case Acquire: mo = MemNode::acquire; break; |
|
3194 case Release: mo = MemNode::release; break; |
|
3195 case Volatile: mo = MemNode::seqcst; break; |
|
3196 default: |
|
3197 ShouldNotReachHere(); |
|
3198 } |
|
3199 guarantee(mo != MemNode::unset, "Should select memory ordering"); |
|
3200 return mo; |
|
3201 } |
2713 } |
3202 |
2714 |
3203 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { |
2715 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { |
3204 // Regardless of form, don't allow previous ld/st to move down, |
2716 // Regardless of form, don't allow previous ld/st to move down, |
3205 // then issue acquire, release, or volatile mem_bar. |
2717 // then issue acquire, release, or volatile mem_bar. |
4634 return true; |
4146 return true; |
4635 } |
4147 } |
4636 |
4148 |
4637 //------------------------clone_coping----------------------------------- |
4149 //------------------------clone_coping----------------------------------- |
4638 // Helper function for inline_native_clone. |
4150 // Helper function for inline_native_clone. |
4639 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark) { |
4151 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) { |
4640 assert(obj_size != NULL, ""); |
4152 assert(obj_size != NULL, ""); |
4641 Node* raw_obj = alloc_obj->in(1); |
4153 Node* raw_obj = alloc_obj->in(1); |
4642 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); |
4154 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); |
4643 |
4155 |
4644 AllocateNode* alloc = NULL; |
4156 AllocateNode* alloc = NULL; |
4654 alloc->initialization()->set_complete_with_arraycopy(); |
4166 alloc->initialization()->set_complete_with_arraycopy(); |
4655 } |
4167 } |
4656 |
4168 |
4657 // Copy the fastest available way. |
4169 // Copy the fastest available way. |
4658 // TODO: generate fields copies for small objects instead. |
4170 // TODO: generate fields copies for small objects instead. |
4659 Node* src = obj; |
|
4660 Node* dest = alloc_obj; |
|
4661 Node* size = _gvn.transform(obj_size); |
4171 Node* size = _gvn.transform(obj_size); |
4662 |
4172 |
4663 // Exclude the header but include array length to copy by 8 bytes words. |
4173 access_clone(control(), obj, alloc_obj, size, is_array); |
4664 // Can't use base_offset_in_bytes(bt) since basic type is unknown. |
|
4665 int base_off = is_array ? arrayOopDesc::length_offset_in_bytes() : |
|
4666 instanceOopDesc::base_offset_in_bytes(); |
|
4667 // base_off: |
|
4668 // 8 - 32-bit VM |
|
4669 // 12 - 64-bit VM, compressed klass |
|
4670 // 16 - 64-bit VM, normal klass |
|
4671 if (base_off % BytesPerLong != 0) { |
|
4672 assert(UseCompressedClassPointers, ""); |
|
4673 if (is_array) { |
|
4674 // Exclude length to copy by 8 bytes words. |
|
4675 base_off += sizeof(int); |
|
4676 } else { |
|
4677 // Include klass to copy by 8 bytes words. |
|
4678 base_off = instanceOopDesc::klass_offset_in_bytes(); |
|
4679 } |
|
4680 assert(base_off % BytesPerLong == 0, "expect 8 bytes alignment"); |
|
4681 } |
|
4682 src = basic_plus_adr(src, base_off); |
|
4683 dest = basic_plus_adr(dest, base_off); |
|
4684 |
|
4685 // Compute the length also, if needed: |
|
4686 Node* countx = size; |
|
4687 countx = _gvn.transform(new SubXNode(countx, MakeConX(base_off))); |
|
4688 countx = _gvn.transform(new URShiftXNode(countx, intcon(LogBytesPerLong) )); |
|
4689 |
|
4690 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; |
|
4691 |
|
4692 ArrayCopyNode* ac = ArrayCopyNode::make(this, false, src, NULL, dest, NULL, countx, false, false); |
|
4693 ac->set_clonebasic(); |
|
4694 Node* n = _gvn.transform(ac); |
|
4695 if (n == ac) { |
|
4696 set_predefined_output_for_runtime_call(ac, ac->in(TypeFunc::Memory), raw_adr_type); |
|
4697 } else { |
|
4698 set_all_memory(n); |
|
4699 } |
|
4700 |
|
4701 // If necessary, emit some card marks afterwards. (Non-arrays only.) |
|
4702 if (card_mark) { |
|
4703 assert(!is_array, ""); |
|
4704 // Put in store barrier for any and all oops we are sticking |
|
4705 // into this object. (We could avoid this if we could prove |
|
4706 // that the object type contains no oop fields at all.) |
|
4707 Node* no_particular_value = NULL; |
|
4708 Node* no_particular_field = NULL; |
|
4709 int raw_adr_idx = Compile::AliasIdxRaw; |
|
4710 post_barrier(control(), |
|
4711 memory(raw_adr_type), |
|
4712 alloc_obj, |
|
4713 no_particular_field, |
|
4714 raw_adr_idx, |
|
4715 no_particular_value, |
|
4716 T_OBJECT, |
|
4717 false); |
|
4718 } |
|
4719 |
4174 |
4720 // Do not let reads from the cloned object float above the arraycopy. |
4175 // Do not let reads from the cloned object float above the arraycopy. |
4721 if (alloc != NULL) { |
4176 if (alloc != NULL) { |
4722 // Do not let stores that initialize this object be reordered with |
4177 // Do not let stores that initialize this object be reordered with |
4723 // a subsequent store that would make this object accessible by |
4178 // a subsequent store that would make this object accessible by |
4803 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); |
4258 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); |
4804 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO); |
4259 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO); |
4805 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); |
4260 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); |
4806 record_for_igvn(result_reg); |
4261 record_for_igvn(result_reg); |
4807 |
4262 |
4808 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; |
|
4809 int raw_adr_idx = Compile::AliasIdxRaw; |
|
4810 |
|
4811 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); |
4263 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); |
4812 if (array_ctl != NULL) { |
4264 if (array_ctl != NULL) { |
4813 // It's an array. |
4265 // It's an array. |
4814 PreserveJVMState pjvms(this); |
4266 PreserveJVMState pjvms(this); |
4815 set_control(array_ctl); |
4267 set_control(array_ctl); |
4816 Node* obj_length = load_array_length(obj); |
4268 Node* obj_length = load_array_length(obj); |
4817 Node* obj_size = NULL; |
4269 Node* obj_size = NULL; |
4818 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size); // no arguments to push |
4270 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size); // no arguments to push |
4819 |
4271 |
4820 if (!use_ReduceInitialCardMarks()) { |
4272 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); |
4273 if (bs->array_copy_requires_gc_barriers(T_OBJECT)) { |
|
4821 // If it is an oop array, it requires very special treatment, |
4274 // If it is an oop array, it requires very special treatment, |
4822 // because card marking is required on each card of the array. |
4275 // because gc barriers are required when accessing the array. |
4823 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); |
4276 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); |
4824 if (is_obja != NULL) { |
4277 if (is_obja != NULL) { |
4825 PreserveJVMState pjvms2(this); |
4278 PreserveJVMState pjvms2(this); |
4826 set_control(is_obja); |
4279 set_control(is_obja); |
4827 // Generate a direct call to the right arraycopy function(s). |
4280 // Generate a direct call to the right arraycopy function(s). |
4836 result_val->init_req(_objArray_path, alloc_obj); |
4289 result_val->init_req(_objArray_path, alloc_obj); |
4837 result_i_o ->set_req(_objArray_path, i_o()); |
4290 result_i_o ->set_req(_objArray_path, i_o()); |
4838 result_mem ->set_req(_objArray_path, reset_memory()); |
4291 result_mem ->set_req(_objArray_path, reset_memory()); |
4839 } |
4292 } |
4840 } |
4293 } |
4841 // Otherwise, there are no card marks to worry about. |
4294 // Otherwise, there are no barriers to worry about. |
4842 // (We can dispense with card marks if we know the allocation |
4295 // (We can dispense with card marks if we know the allocation |
4843 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks |
4296 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks |
4844 // causes the non-eden paths to take compensating steps to |
4297 // causes the non-eden paths to take compensating steps to |
4845 // simulate a fresh allocation, so that no further |
4298 // simulate a fresh allocation, so that no further |
4846 // card marks are required in compiled code to initialize |
4299 // card marks are required in compiled code to initialize |
4847 // the object.) |
4300 // the object.) |
4848 |
4301 |
4849 if (!stopped()) { |
4302 if (!stopped()) { |
4850 copy_to_clone(obj, alloc_obj, obj_size, true, false); |
4303 copy_to_clone(obj, alloc_obj, obj_size, true); |
4851 |
4304 |
4852 // Present the results of the copy. |
4305 // Present the results of the copy. |
4853 result_reg->init_req(_array_path, control()); |
4306 result_reg->init_req(_array_path, control()); |
4854 result_val->init_req(_array_path, alloc_obj); |
4307 result_val->init_req(_array_path, alloc_obj); |
4855 result_i_o ->set_req(_array_path, i_o()); |
4308 result_i_o ->set_req(_array_path, i_o()); |
4891 // Need to deoptimize on exception from allocation since Object.clone intrinsic |
4344 // Need to deoptimize on exception from allocation since Object.clone intrinsic |
4892 // is reexecuted if deoptimization occurs and there could be problems when merging |
4345 // is reexecuted if deoptimization occurs and there could be problems when merging |
4893 // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false). |
4346 // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false). |
4894 Node* alloc_obj = new_instance(obj_klass, NULL, &obj_size, /*deoptimize_on_exception=*/true); |
4347 Node* alloc_obj = new_instance(obj_klass, NULL, &obj_size, /*deoptimize_on_exception=*/true); |
4895 |
4348 |
4896 copy_to_clone(obj, alloc_obj, obj_size, false, !use_ReduceInitialCardMarks()); |
4349 copy_to_clone(obj, alloc_obj, obj_size, false); |
4897 |
4350 |
4898 // Present the results of the slow call. |
4351 // Present the results of the slow call. |
4899 result_reg->init_req(_instance_path, control()); |
4352 result_reg->init_req(_instance_path, control()); |
4900 result_val->init_req(_instance_path, alloc_obj); |
4353 result_val->init_req(_instance_path, alloc_obj); |
4901 result_i_o ->set_req(_instance_path, i_o()); |
4354 result_i_o ->set_req(_instance_path, i_o()); |
6098 |
5551 |
6099 // Get the argument: |
5552 // Get the argument: |
6100 Node* reference_obj = null_check_receiver(); |
5553 Node* reference_obj = null_check_receiver(); |
6101 if (stopped()) return true; |
5554 if (stopped()) return true; |
6102 |
5555 |
5556 const TypeInstPtr* tinst = _gvn.type(reference_obj)->isa_instptr(); |
|
5557 assert(tinst != NULL, "obj is null"); |
|
5558 assert(tinst->klass()->is_loaded(), "obj is not loaded"); |
|
5559 ciInstanceKlass* referenceKlass = tinst->klass()->as_instance_klass(); |
|
5560 ciField* field = referenceKlass->get_field_by_name(ciSymbol::make("referent"), |
|
5561 ciSymbol::make("Ljava/lang/Object;"), |
|
5562 false); |
|
5563 assert (field != NULL, "undefined field"); |
|
5564 |
|
6103 Node* adr = basic_plus_adr(reference_obj, reference_obj, referent_offset); |
5565 Node* adr = basic_plus_adr(reference_obj, reference_obj, referent_offset); |
5566 const TypePtr* adr_type = C->alias_type(field)->adr_type(); |
|
6104 |
5567 |
6105 ciInstanceKlass* klass = env()->Object_klass(); |
5568 ciInstanceKlass* klass = env()->Object_klass(); |
6106 const TypeOopPtr* object_type = TypeOopPtr::make_from_klass(klass); |
5569 const TypeOopPtr* object_type = TypeOopPtr::make_from_klass(klass); |
6107 |
5570 |
6108 Node* no_ctrl = NULL; |
5571 DecoratorSet decorators = IN_HEAP | ON_WEAK_OOP_REF; |
6109 Node* result = make_load(no_ctrl, adr, object_type, T_OBJECT, MemNode::unordered); |
5572 Node* result = access_load_at(reference_obj, adr, adr_type, object_type, T_OBJECT, decorators); |
6110 |
|
6111 // Use the pre-barrier to record the value in the referent field |
|
6112 pre_barrier(false /* do_load */, |
|
6113 control(), |
|
6114 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */, |
|
6115 result /* pre_val */, |
|
6116 T_OBJECT); |
|
6117 |
|
6118 // Add memory barrier to prevent commoning reads from this field |
5573 // Add memory barrier to prevent commoning reads from this field |
6119 // across safepoint since GC can change its value. |
5574 // across safepoint since GC can change its value. |
6120 insert_mem_bar(Op_MemBarCPUOrder); |
5575 insert_mem_bar(Op_MemBarCPUOrder); |
6121 |
5576 |
6122 set_result(result); |
5577 set_result(result); |
6165 type = TypeOopPtr::make_from_klass(field_klass->as_klass()); |
5620 type = TypeOopPtr::make_from_klass(field_klass->as_klass()); |
6166 } else { |
5621 } else { |
6167 type = Type::get_const_basic_type(bt); |
5622 type = Type::get_const_basic_type(bt); |
6168 } |
5623 } |
6169 |
5624 |
6170 if (support_IRIW_for_not_multiple_copy_atomic_cpu && is_vol) { |
5625 DecoratorSet decorators = IN_HEAP; |
6171 insert_mem_bar(Op_MemBarVolatile); // StoreLoad barrier |
5626 |
6172 } |
|
6173 // Build the load. |
|
6174 MemNode::MemOrd mo = is_vol ? MemNode::acquire : MemNode::unordered; |
|
6175 Node* loadedField = make_load(NULL, adr, type, bt, adr_type, mo, LoadNode::DependsOnlyOnTest, is_vol); |
|
6176 // If reference is volatile, prevent following memory ops from |
|
6177 // floating up past the volatile read. Also prevents commoning |
|
6178 // another volatile read. |
|
6179 if (is_vol) { |
5627 if (is_vol) { |
6180 // Memory barrier includes bogus read of value to force load BEFORE membar |
5628 decorators |= MO_SEQ_CST; |
6181 insert_mem_bar(Op_MemBarAcquire, loadedField); |
5629 } |
6182 } |
5630 |
6183 return loadedField; |
5631 return access_load_at(fromObj, adr, adr_type, type, bt, decorators); |
6184 } |
5632 } |
6185 |
5633 |
6186 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, |
5634 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, |
6187 bool is_exact = true, bool is_static = false, |
5635 bool is_exact = true, bool is_static = false, |
6188 ciInstanceKlass * fromKls = NULL) { |
5636 ciInstanceKlass * fromKls = NULL) { |