6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/macroAssembler.hpp"
26 #include "ci/ciSymbols.hpp"
27 #include "ci/ciUtilities.inline.hpp"
28 #include "classfile/vmIntrinsics.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "gc/shared/barrierSet.hpp"
32 #include "jfr/support/jfrIntrinsics.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/klass.inline.hpp"
35 #include "oops/objArrayKlass.hpp"
36 #include "opto/addnode.hpp"
37 #include "opto/arraycopynode.hpp"
38 #include "opto/c2compiler.hpp"
39 #include "opto/castnode.hpp"
40 #include "opto/cfgnode.hpp"
41 #include "opto/convertnode.hpp"
42 #include "opto/countbitsnode.hpp"
43 #include "opto/idealKit.hpp"
44 #include "opto/library_call.hpp"
45 #include "opto/mathexactnode.hpp"
46 #include "opto/mulnode.hpp"
47 #include "opto/narrowptrnode.hpp"
48 #include "opto/opaquenode.hpp"
49 #include "opto/parse.hpp"
50 #include "opto/rootnode.hpp"
51 #include "opto/runtime.hpp"
52 #include "opto/subnode.hpp"
53 #include "opto/vectornode.hpp"
54 #include "prims/jvmtiExport.hpp"
55 #include "prims/jvmtiThreadState.hpp"
56 #include "prims/unsafe.hpp"
57 #include "runtime/jniHandles.inline.hpp"
58 #include "runtime/mountUnmountDisabler.hpp"
59 #include "runtime/objectMonitor.hpp"
60 #include "runtime/sharedRuntime.hpp"
61 #include "runtime/stubRoutines.hpp"
62 #include "utilities/macros.hpp"
63 #include "utilities/powerOfTwo.hpp"
64
65 //---------------------------make_vm_intrinsic----------------------------
66 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
67 vmIntrinsicID id = m->intrinsic_id();
68 assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
69
70 if (!m->is_loaded()) {
71 // Do not attempt to inline unloaded methods.
72 return nullptr;
73 }
74
75 C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization);
76 bool is_available = false;
77
78 {
79 // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag
80 // the compiler must transition to '_thread_in_vm' state because both
81 // methods access VM-internal data.
392 case vmIntrinsics::_getReferenceOpaque: return inline_unsafe_access(!is_store, T_OBJECT, Opaque, false);
393 case vmIntrinsics::_getBooleanOpaque: return inline_unsafe_access(!is_store, T_BOOLEAN, Opaque, false);
394 case vmIntrinsics::_getByteOpaque: return inline_unsafe_access(!is_store, T_BYTE, Opaque, false);
395 case vmIntrinsics::_getShortOpaque: return inline_unsafe_access(!is_store, T_SHORT, Opaque, false);
396 case vmIntrinsics::_getCharOpaque: return inline_unsafe_access(!is_store, T_CHAR, Opaque, false);
397 case vmIntrinsics::_getIntOpaque: return inline_unsafe_access(!is_store, T_INT, Opaque, false);
398 case vmIntrinsics::_getLongOpaque: return inline_unsafe_access(!is_store, T_LONG, Opaque, false);
399 case vmIntrinsics::_getFloatOpaque: return inline_unsafe_access(!is_store, T_FLOAT, Opaque, false);
400 case vmIntrinsics::_getDoubleOpaque: return inline_unsafe_access(!is_store, T_DOUBLE, Opaque, false);
401
402 case vmIntrinsics::_putReferenceOpaque: return inline_unsafe_access( is_store, T_OBJECT, Opaque, false);
403 case vmIntrinsics::_putBooleanOpaque: return inline_unsafe_access( is_store, T_BOOLEAN, Opaque, false);
404 case vmIntrinsics::_putByteOpaque: return inline_unsafe_access( is_store, T_BYTE, Opaque, false);
405 case vmIntrinsics::_putShortOpaque: return inline_unsafe_access( is_store, T_SHORT, Opaque, false);
406 case vmIntrinsics::_putCharOpaque: return inline_unsafe_access( is_store, T_CHAR, Opaque, false);
407 case vmIntrinsics::_putIntOpaque: return inline_unsafe_access( is_store, T_INT, Opaque, false);
408 case vmIntrinsics::_putLongOpaque: return inline_unsafe_access( is_store, T_LONG, Opaque, false);
409 case vmIntrinsics::_putFloatOpaque: return inline_unsafe_access( is_store, T_FLOAT, Opaque, false);
410 case vmIntrinsics::_putDoubleOpaque: return inline_unsafe_access( is_store, T_DOUBLE, Opaque, false);
411
412 case vmIntrinsics::_compareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap, Volatile);
413 case vmIntrinsics::_compareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap, Volatile);
414 case vmIntrinsics::_compareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap, Volatile);
415 case vmIntrinsics::_compareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap, Volatile);
416 case vmIntrinsics::_compareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap, Volatile);
417
418 case vmIntrinsics::_weakCompareAndSetReferencePlain: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed);
419 case vmIntrinsics::_weakCompareAndSetReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire);
420 case vmIntrinsics::_weakCompareAndSetReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release);
421 case vmIntrinsics::_weakCompareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile);
422 case vmIntrinsics::_weakCompareAndSetBytePlain: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Relaxed);
423 case vmIntrinsics::_weakCompareAndSetByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Acquire);
424 case vmIntrinsics::_weakCompareAndSetByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Release);
425 case vmIntrinsics::_weakCompareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Volatile);
426 case vmIntrinsics::_weakCompareAndSetShortPlain: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Relaxed);
427 case vmIntrinsics::_weakCompareAndSetShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Acquire);
428 case vmIntrinsics::_weakCompareAndSetShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Release);
429 case vmIntrinsics::_weakCompareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Volatile);
430 case vmIntrinsics::_weakCompareAndSetIntPlain: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Relaxed);
431 case vmIntrinsics::_weakCompareAndSetIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Acquire);
451 case vmIntrinsics::_compareAndExchangeLong: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Volatile);
452 case vmIntrinsics::_compareAndExchangeLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Acquire);
453 case vmIntrinsics::_compareAndExchangeLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Release);
454
455 case vmIntrinsics::_getAndAddByte: return inline_unsafe_load_store(T_BYTE, LS_get_add, Volatile);
456 case vmIntrinsics::_getAndAddShort: return inline_unsafe_load_store(T_SHORT, LS_get_add, Volatile);
457 case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_get_add, Volatile);
458 case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_get_add, Volatile);
459
460 case vmIntrinsics::_getAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_get_set, Volatile);
461 case vmIntrinsics::_getAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_get_set, Volatile);
462 case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_get_set, Volatile);
463 case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_get_set, Volatile);
464 case vmIntrinsics::_getAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_get_set, Volatile);
465
466 case vmIntrinsics::_loadFence:
467 case vmIntrinsics::_storeFence:
468 case vmIntrinsics::_storeStoreFence:
469 case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id());
470
471 case vmIntrinsics::_onSpinWait: return inline_onspinwait();
472
473 case vmIntrinsics::_currentCarrierThread: return inline_native_currentCarrierThread();
474 case vmIntrinsics::_currentThread: return inline_native_currentThread();
475 case vmIntrinsics::_setCurrentThread: return inline_native_setCurrentThread();
476
477 case vmIntrinsics::_scopedValueCache: return inline_native_scopedValueCache();
478 case vmIntrinsics::_setScopedValueCache: return inline_native_setScopedValueCache();
479
480 case vmIntrinsics::_Continuation_pin: return inline_native_Continuation_pinning(false);
481 case vmIntrinsics::_Continuation_unpin: return inline_native_Continuation_pinning(true);
482
483 case vmIntrinsics::_vthreadEndFirstTransition: return inline_native_vthread_end_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_end_first_transition_Java()),
484 "endFirstTransition", true);
485 case vmIntrinsics::_vthreadStartFinalTransition: return inline_native_vthread_start_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_start_final_transition_Java()),
486 "startFinalTransition", true);
487 case vmIntrinsics::_vthreadStartTransition: return inline_native_vthread_start_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_start_transition_Java()),
488 "startTransition", false);
489 case vmIntrinsics::_vthreadEndTransition: return inline_native_vthread_end_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_end_transition_Java()),
490 "endTransition", false);
500 #endif
501 case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis");
502 case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime");
503 case vmIntrinsics::_writeback0: return inline_unsafe_writeback0();
504 case vmIntrinsics::_writebackPreSync0: return inline_unsafe_writebackSync0(true);
505 case vmIntrinsics::_writebackPostSync0: return inline_unsafe_writebackSync0(false);
506 case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate();
507 case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory();
508 case vmIntrinsics::_setMemory: return inline_unsafe_setMemory();
509 case vmIntrinsics::_getLength: return inline_native_getLength();
510 case vmIntrinsics::_copyOf: return inline_array_copyOf(false);
511 case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true);
512 case vmIntrinsics::_equalsB: return inline_array_equals(StrIntrinsicNode::LL);
513 case vmIntrinsics::_equalsC: return inline_array_equals(StrIntrinsicNode::UU);
514 case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex(T_INT);
515 case vmIntrinsics::_Preconditions_checkLongIndex: return inline_preconditions_checkIndex(T_LONG);
516 case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual());
517
518 case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true);
519 case vmIntrinsics::_newArray: return inline_unsafe_newArray(false);
520
521 case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check();
522
523 case vmIntrinsics::_isInstance:
524 case vmIntrinsics::_isHidden:
525 case vmIntrinsics::_getSuperclass: return inline_native_Class_query(intrinsic_id());
526
527 case vmIntrinsics::_floatToRawIntBits:
528 case vmIntrinsics::_floatToIntBits:
529 case vmIntrinsics::_intBitsToFloat:
530 case vmIntrinsics::_doubleToRawLongBits:
531 case vmIntrinsics::_doubleToLongBits:
532 case vmIntrinsics::_longBitsToDouble:
533 case vmIntrinsics::_floatToFloat16:
534 case vmIntrinsics::_float16ToFloat: return inline_fp_conversions(intrinsic_id());
535 case vmIntrinsics::_sqrt_float16: return inline_fp16_operations(intrinsic_id(), 1);
536 case vmIntrinsics::_fma_float16: return inline_fp16_operations(intrinsic_id(), 3);
537 case vmIntrinsics::_floatIsFinite:
538 case vmIntrinsics::_floatIsInfinite:
539 case vmIntrinsics::_doubleIsFinite:
2269 case vmIntrinsics::_remainderUnsigned_l: {
2270 zero_check_long(argument(2));
2271 // Compile-time detect of null-exception
2272 if (stopped()) {
2273 return true; // keep the graph constructed so far
2274 }
2275 n = new UModLNode(control(), argument(0), argument(2));
2276 break;
2277 }
2278 default: fatal_unexpected_iid(id); break;
2279 }
2280 set_result(_gvn.transform(n));
2281 return true;
2282 }
2283
2284 //----------------------------inline_unsafe_access----------------------------
2285
2286 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) {
2287 // Attempt to infer a sharper value type from the offset and base type.
2288 ciKlass* sharpened_klass = nullptr;
2289
2290 // See if it is an instance field, with an object type.
2291 if (alias_type->field() != nullptr) {
2292 if (alias_type->field()->type()->is_klass()) {
2293 sharpened_klass = alias_type->field()->type()->as_klass();
2294 }
2295 }
2296
2297 const TypeOopPtr* result = nullptr;
2298 // See if it is a narrow oop array.
2299 if (adr_type->isa_aryptr()) {
2300 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) {
2301 const TypeOopPtr* elem_type = adr_type->is_aryptr()->elem()->make_oopptr();
2302 if (elem_type != nullptr && elem_type->is_loaded()) {
2303 // Sharpen the value type.
2304 result = elem_type;
2305 }
2306 }
2307 }
2308
2309 // The sharpened class might be unloaded if there is no class loader
2310 // contraint in place.
2311 if (result == nullptr && sharpened_klass != nullptr && sharpened_klass->is_loaded()) {
2312 // Sharpen the value type.
2313 result = TypeOopPtr::make_from_klass(sharpened_klass);
2314 }
2315 if (result != nullptr) {
2316 #ifndef PRODUCT
2317 if (C->print_intrinsics() || C->print_inlining()) {
2318 tty->print(" from base type: "); adr_type->dump(); tty->cr();
2319 tty->print(" sharpened value: "); result->dump(); tty->cr();
2320 }
2321 #endif
2322 }
2323 return result;
2324 }
2325
2326 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) {
2327 switch (kind) {
2328 case Relaxed:
2329 return MO_UNORDERED;
2330 case Opaque:
2331 return MO_RELAXED;
2332 case Acquire:
2333 return MO_ACQUIRE;
2381 #endif // ASSERT
2382 }
2383 #endif //PRODUCT
2384
2385 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
2386
2387 Node* receiver = argument(0); // type: oop
2388
2389 // Build address expression.
2390 Node* heap_base_oop = top();
2391
2392 // The base is either a Java object or a value produced by Unsafe.staticFieldBase
2393 Node* base = argument(1); // type: oop
2394 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
2395 Node* offset = argument(2); // type: long
2396 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2397 // to be plain byte offsets, which are also the same as those accepted
2398 // by oopDesc::field_addr.
2399 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2400 "fieldOffset must be byte-scaled");
2401 // 32-bit machines ignore the high half!
2402 offset = ConvL2X(offset);
2403
2404 // Save state and restore on bailout
2405 SavedState old_state(this);
2406
2407 Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed);
2408 assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly");
2409
2410 bool is_non_heap_access = (_gvn.type(base->uncast())->isa_ptr() == TypePtr::NULL_PTR);
2411 if (is_non_heap_access) {
2412 if (type != T_OBJECT) {
2413 decorators |= IN_NATIVE; // off-heap primitive access
2414 } else {
2415 return false; // off-heap oop accesses are not supported
2416 }
2417 } else {
2418 heap_base_oop = base; // on-heap or mixed access
2419 }
2420
2430 Node* val = is_store ? argument(4) : nullptr;
2431
2432 const TypePtr* adr_type = _gvn.type(adr)->isa_ptr();
2433 if (adr_type == TypePtr::NULL_PTR) {
2434 return false; // off-heap access with zero address
2435 }
2436
2437 // Try to categorize the address.
2438 Compile::AliasType* alias_type = C->alias_type(adr_type);
2439 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2440
2441 assert((alias_type->index() == Compile::AliasIdxRaw) ==
2442 (is_non_heap_access || (can_access_non_heap && alias_type->field() == nullptr)), "wrong alias");
2443
2444 if (alias_type->adr_type() == TypeInstPtr::KLASS ||
2445 alias_type->adr_type() == TypeAryPtr::RANGE) {
2446 return false; // not supported
2447 }
2448
2449 bool mismatched = false;
2450 BasicType bt = alias_type->basic_type();
2451 if (bt != T_ILLEGAL) {
2452 assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access");
2453 if (bt == T_BYTE && adr_type->isa_aryptr()) {
2454 // Alias type doesn't differentiate between byte[] and boolean[]).
2455 // Use address type to get the element type.
2456 bt = adr_type->is_aryptr()->elem()->array_element_basic_type();
2457 }
2458 if (is_reference_type(bt, true)) {
2459 // accessing an array field with getReference is not a mismatch
2460 bt = T_OBJECT;
2461 }
2462 if ((bt == T_OBJECT) != (type == T_OBJECT)) {
2463 // Don't intrinsify mismatched object accesses
2464 return false;
2465 }
2466 mismatched = (bt != type);
2467 } else if (alias_type->adr_type()->isa_oopptr()) {
2468 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched
2469 }
2470
2489 }
2490 } else if (type == T_BOOLEAN) {
2491 if (mismatched || alias_type->index() == Compile::AliasIdxRaw) {
2492 value_type = TypeInt::UBYTE;
2493 }
2494 }
2495 }
2496
2497 receiver = null_check(receiver);
2498 if (stopped()) {
2499 return true;
2500 }
2501 // Heap pointers get a null-check from the interpreter,
2502 // as a courtesy. However, this is not guaranteed by Unsafe,
2503 // and it is not possible to fully distinguish unintended nulls
2504 // from intended ones in this API.
2505
2506 if (!is_store) {
2507 Node* p = nullptr;
2508 // Try to constant fold a load from a constant field
2509 ciField* field = alias_type->field();
2510 if (heap_base_oop != top() && field != nullptr && field->is_constant() && !mismatched) {
2511 // final or stable field
2512 p = make_constant_from_field(field, heap_base_oop);
2513 }
2514
2515 if (p == nullptr) { // Could not constant fold the load
2516 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators);
2517 }
2518 if (type == T_ADDRESS) {
2519 p = gvn().transform(new CastP2XNode(nullptr, p));
2520 p = ConvX2UL(p);
2521 } else if (type == T_BOOLEAN) {
2522 // Truncate boolean values returned by unsafe operations.
2523 p = gvn().transform(new AndINode(p, gvn().intcon(0x1)));
2524 }
2525 // The load node has the control of the preceding MemBarCPUOrder. All
2526 // following nodes will have the control of the MemBarCPUOrder inserted at
2527 // the end of this method. So, pushing the load onto the stack at a later
2528 // point is fine.
2529 set_result(p);
2530 } else {
2531 if (bt == T_ADDRESS) {
2532 // Repackage the long as a pointer.
2533 val = ConvL2X(val);
2534 val = gvn().transform(new CastX2PNode(val));
2535 }
2536 access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators);
2537 }
2538
2539 return true;
2540 }
2541
2542 //----------------------------inline_unsafe_load_store----------------------------
2543 // This method serves a couple of different customers (depending on LoadStoreKind):
2544 //
2545 // LS_cmp_swap:
2546 //
2547 // boolean compareAndSetReference(Object o, long offset, Object expected, Object x);
2548 // boolean compareAndSetInt( Object o, long offset, int expected, int x);
2549 // boolean compareAndSetLong( Object o, long offset, long expected, long x);
2550 //
2551 // LS_cmp_swap_weak:
2552 //
2553 // boolean weakCompareAndSetReference( Object o, long offset, Object expected, Object x);
2554 // boolean weakCompareAndSetReferencePlain( Object o, long offset, Object expected, Object x);
2555 // boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x);
2556 // boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x);
2557 //
2558 // boolean weakCompareAndSetInt( Object o, long offset, int expected, int x);
2559 // boolean weakCompareAndSetIntPlain( Object o, long offset, int expected, int x);
2560 // boolean weakCompareAndSetIntAcquire( Object o, long offset, int expected, int x);
2561 // boolean weakCompareAndSetIntRelease( Object o, long offset, int expected, int x);
2724 }
2725 case LS_cmp_swap:
2726 case LS_cmp_swap_weak:
2727 case LS_get_add:
2728 break;
2729 default:
2730 ShouldNotReachHere();
2731 }
2732
2733 // Null check receiver.
2734 receiver = null_check(receiver);
2735 if (stopped()) {
2736 return true;
2737 }
2738
2739 int alias_idx = C->get_alias_index(adr_type);
2740
2741 if (is_reference_type(type)) {
2742 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF;
2743
2744 // Transformation of a value which could be null pointer (CastPP #null)
2745 // could be delayed during Parse (for example, in adjust_map_after_if()).
2746 // Execute transformation here to avoid barrier generation in such case.
2747 if (_gvn.type(newval) == TypePtr::NULL_PTR)
2748 newval = _gvn.makecon(TypePtr::NULL_PTR);
2749
2750 if (oldval != nullptr && _gvn.type(oldval) == TypePtr::NULL_PTR) {
2751 // Refine the value to a null constant, when it is known to be null
2752 oldval = _gvn.makecon(TypePtr::NULL_PTR);
2753 }
2754 }
2755
2756 Node* result = nullptr;
2757 switch (kind) {
2758 case LS_cmp_exchange: {
2759 result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx,
2760 oldval, newval, value_type, type, decorators);
2761 break;
2762 }
2763 case LS_cmp_swap_weak:
2792 insert_mem_bar(Op_MemBarCPUOrder);
2793 switch(id) {
2794 case vmIntrinsics::_loadFence:
2795 insert_mem_bar(Op_LoadFence);
2796 return true;
2797 case vmIntrinsics::_storeFence:
2798 insert_mem_bar(Op_StoreFence);
2799 return true;
2800 case vmIntrinsics::_storeStoreFence:
2801 insert_mem_bar(Op_StoreStoreFence);
2802 return true;
2803 case vmIntrinsics::_fullFence:
2804 insert_mem_bar(Op_MemBarFull);
2805 return true;
2806 default:
2807 fatal_unexpected_iid(id);
2808 return false;
2809 }
2810 }
2811
2812 bool LibraryCallKit::inline_onspinwait() {
2813 insert_mem_bar(Op_OnSpinWait);
2814 return true;
2815 }
2816
2817 bool LibraryCallKit::klass_needs_init_guard(Node* kls) {
2818 if (!kls->is_Con()) {
2819 return true;
2820 }
2821 const TypeInstKlassPtr* klsptr = kls->bottom_type()->isa_instklassptr();
2822 if (klsptr == nullptr) {
2823 return true;
2824 }
2825 ciInstanceKlass* ik = klsptr->instance_klass();
2826 // don't need a guard for a klass that is already initialized
2827 return !ik->is_initialized();
2828 }
2829
2830 //----------------------------inline_unsafe_writeback0-------------------------
2831 // public native void Unsafe.writeback0(long address)
2910 Deoptimization::Action_make_not_entrant);
2911 }
2912 if (stopped()) {
2913 return true;
2914 }
2915 #endif //INCLUDE_JVMTI
2916
2917 Node* test = nullptr;
2918 if (LibraryCallKit::klass_needs_init_guard(kls)) {
2919 // Note: The argument might still be an illegal value like
2920 // Serializable.class or Object[].class. The runtime will handle it.
2921 // But we must make an explicit check for initialization.
2922 Node* insp = off_heap_plus_addr(kls, in_bytes(InstanceKlass::init_state_offset()));
2923 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler
2924 // can generate code to load it as unsigned byte.
2925 Node* inst = make_load(nullptr, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::acquire);
2926 Node* bits = intcon(InstanceKlass::fully_initialized);
2927 test = _gvn.transform(new SubINode(inst, bits));
2928 // The 'test' is non-zero if we need to take a slow path.
2929 }
2930
2931 Node* obj = new_instance(kls, test);
2932 set_result(obj);
2933 return true;
2934 }
2935
2936 //------------------------inline_native_time_funcs--------------
2937 // inline code for System.currentTimeMillis() and System.nanoTime()
2938 // these have the same type and signature
2939 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) {
2940 const TypeFunc* tf = OptoRuntime::void_long_Type();
2941 const TypePtr* no_memory_effects = nullptr;
2942 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects);
2943 Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0));
2944 #ifdef ASSERT
2945 Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1));
2946 assert(value_top == top(), "second value must be top");
2947 #endif
2948 set_result(value);
2949 return true;
2950 }
3476 vthread_compare_mem->init_req(_false_path, input_memory_state);
3477 vthread_compare_io->init_req(_true_path, _gvn.transform(exclude_compare_io));
3478 vthread_compare_io->init_req(_false_path, input_io_state);
3479 tid->init_req(_true_path, vthread_tid);
3480 tid->init_req(_false_path, thread_obj_tid);
3481 exclusion->init_req(_true_path, vthread_is_excluded);
3482 exclusion->init_req(_false_path, threadObj_is_excluded);
3483 pinVirtualThread->init_req(_true_path, continuation_support);
3484 pinVirtualThread->init_req(_false_path, _gvn.intcon(0));
3485
3486 // Update branch state.
3487 set_control(_gvn.transform(vthread_compare_rgn));
3488 set_all_memory(_gvn.transform(vthread_compare_mem));
3489 set_i_o(_gvn.transform(vthread_compare_io));
3490
3491 // Load the event writer oop by dereferencing the jobject handle.
3492 ciKlass* klass_EventWriter = env()->find_system_klass(ciSymbol::make("jdk/jfr/internal/event/EventWriter"));
3493 assert(klass_EventWriter->is_loaded(), "invariant");
3494 ciInstanceKlass* const instklass_EventWriter = klass_EventWriter->as_instance_klass();
3495 const TypeKlassPtr* const aklass = TypeKlassPtr::make(instklass_EventWriter);
3496 const TypeOopPtr* const xtype = aklass->as_instance_type();
3497 Node* jobj_untagged = _gvn.transform(AddPNode::make_off_heap(jobj, _gvn.MakeConX(-JNIHandles::TypeTag::global)));
3498 Node* event_writer = access_load(jobj_untagged, xtype, T_OBJECT, IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD);
3499
3500 // Load the current thread id from the event writer object.
3501 Node* const event_writer_tid = load_field_from_object(event_writer, "threadID", "J");
3502 // Get the field offset to, conditionally, store an updated tid value later.
3503 Node* const event_writer_tid_field = field_address_from_object(event_writer, "threadID", "J", false);
3504 // Get the field offset to, conditionally, store an updated exclusion value later.
3505 Node* const event_writer_excluded_field = field_address_from_object(event_writer, "excluded", "Z", false);
3506 // Get the field offset to, conditionally, store an updated pinVirtualThread value later.
3507 Node* const event_writer_pin_field = field_address_from_object(event_writer, "pinVirtualThread", "Z", false);
3508
3509 RegionNode* event_writer_tid_compare_rgn = new RegionNode(PATH_LIMIT);
3510 record_for_igvn(event_writer_tid_compare_rgn);
3511 PhiNode* event_writer_tid_compare_mem = new PhiNode(event_writer_tid_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
3512 record_for_igvn(event_writer_tid_compare_mem);
3513 PhiNode* event_writer_tid_compare_io = new PhiNode(event_writer_tid_compare_rgn, Type::ABIO);
3514 record_for_igvn(event_writer_tid_compare_io);
3515
3516 // Compare the current tid from the thread object to what is currently stored in the event writer object.
3841 Node* arr = argument(1);
3842 Node* thread = _gvn.transform(new ThreadLocalNode());
3843 Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::vthread_offset()));
3844 Node* thread_obj_handle
3845 = make_load(nullptr, p, p->bottom_type()->is_ptr(), T_OBJECT, MemNode::unordered);
3846 const TypePtr *adr_type = _gvn.type(thread_obj_handle)->isa_ptr();
3847 access_store_at(nullptr, thread_obj_handle, adr_type, arr, _gvn.type(arr), T_OBJECT, IN_NATIVE | MO_UNORDERED);
3848
3849 // Change the _monitor_owner_id of the JavaThread
3850 Node* tid = load_field_from_object(arr, "tid", "J");
3851 Node* monitor_owner_id_offset = off_heap_plus_addr(thread, in_bytes(JavaThread::monitor_owner_id_offset()));
3852 store_to_memory(control(), monitor_owner_id_offset, tid, T_LONG, MemNode::unordered, true);
3853
3854 JFR_ONLY(extend_setCurrentThread(thread, arr);)
3855 return true;
3856 }
3857
3858 const Type* LibraryCallKit::scopedValueCache_type() {
3859 ciKlass* objects_klass = ciObjArrayKlass::make(env()->Object_klass());
3860 const TypeOopPtr* etype = TypeOopPtr::make_from_klass(env()->Object_klass());
3861 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3862
3863 // Because we create the scopedValue cache lazily we have to make the
3864 // type of the result BotPTR.
3865 bool xk = etype->klass_is_exact();
3866 const Type* objects_type = TypeAryPtr::make(TypePtr::BotPTR, arr0, objects_klass, xk, 0);
3867 return objects_type;
3868 }
3869
3870 Node* LibraryCallKit::scopedValueCache_helper() {
3871 Node* thread = _gvn.transform(new ThreadLocalNode());
3872 Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::scopedValueCache_offset()));
3873 // We cannot use immutable_memory() because we might flip onto a
3874 // different carrier thread, at which point we'll need to use that
3875 // carrier thread's cache.
3876 // return _gvn.transform(LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(),
3877 // TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered));
3878 return make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered);
3879 }
3880
3881 //------------------------inline_native_scopedValueCache------------------
3882 bool LibraryCallKit::inline_native_scopedValueCache() {
3883 Node* cache_obj_handle = scopedValueCache_helper();
3884 const Type* objects_type = scopedValueCache_type();
3885 set_result(access_load(cache_obj_handle, objects_type, T_OBJECT, IN_NATIVE));
3886
4022 }
4023 return kls;
4024 }
4025
4026 //--------------------(inline_native_Class_query helpers)---------------------
4027 // Use this for JVM_ACC_INTERFACE.
4028 // Fall through if (mods & mask) == bits, take the guard otherwise.
4029 Node* LibraryCallKit::generate_klass_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region,
4030 ByteSize offset, const Type* type, BasicType bt) {
4031 // Branch around if the given klass has the given modifier bit set.
4032 // Like generate_guard, adds a new path onto the region.
4033 Node* modp = off_heap_plus_addr(kls, in_bytes(offset));
4034 Node* mods = make_load(nullptr, modp, type, bt, MemNode::unordered);
4035 Node* mask = intcon(modifier_mask);
4036 Node* bits = intcon(modifier_bits);
4037 Node* mbit = _gvn.transform(new AndINode(mods, mask));
4038 Node* cmp = _gvn.transform(new CmpINode(mbit, bits));
4039 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
4040 return generate_fair_guard(bol, region);
4041 }
4042 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
4043 return generate_klass_flags_guard(kls, JVM_ACC_INTERFACE, 0, region,
4044 InstanceKlass::access_flags_offset(), TypeInt::CHAR, T_CHAR);
4045 }
4046
4047 // Use this for testing if Klass is_hidden, has_finalizer, and is_cloneable_fast.
4048 Node* LibraryCallKit::generate_misc_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
4049 return generate_klass_flags_guard(kls, modifier_mask, modifier_bits, region,
4050 Klass::misc_flags_offset(), TypeInt::UBYTE, T_BOOLEAN);
4051 }
4052
4053 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) {
4054 return generate_misc_flags_guard(kls, KlassFlags::_misc_is_hidden_class, 0, region);
4055 }
4056
4057 //-------------------------inline_native_Class_query-------------------
4058 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
4059 const Type* return_type = TypeInt::BOOL;
4060 Node* prim_return_value = top(); // what happens if it's a primitive class?
4061 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
4147
4148
4149 case vmIntrinsics::_getSuperclass:
4150 // The rules here are somewhat unfortunate, but we can still do better
4151 // with random logic than with a JNI call.
4152 // Interfaces store null or Object as _super, but must report null.
4153 // Arrays store an intermediate super as _super, but must report Object.
4154 // Other types can report the actual _super.
4155 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
4156 if (generate_array_guard(kls, region) != nullptr) {
4157 // A guard was added. If the guard is taken, it was an array.
4158 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
4159 }
4160 // Check for interface after array since this checks AccessFlags offset into InstanceKlass.
4161 // In other words, we are accessing subtype-specific information, so we need to determine the subtype first.
4162 if (generate_interface_guard(kls, region) != nullptr) {
4163 // A guard was added. If the guard is taken, it was an interface.
4164 phi->add_req(null());
4165 }
4166 // If we fall through, it's a plain class. Get its _super.
4167 p = off_heap_plus_addr(kls, in_bytes(Klass::super_offset()));
4168 kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
4169 null_ctl = top();
4170 kls = null_check_oop(kls, &null_ctl);
4171 if (null_ctl != top()) {
4172 // If the guard is taken, Object.superClass is null (both klass and mirror).
4173 region->add_req(null_ctl);
4174 phi ->add_req(null());
4175 }
4176 if (!stopped()) {
4177 query_value = load_mirror_from_klass(kls);
4178 }
4179 break;
4180
4181 default:
4182 fatal_unexpected_iid(id);
4183 break;
4184 }
4185
4186 // Fall-through is the normal case of a query to a real class.
4187 phi->init_req(1, query_value);
4188 region->init_req(1, control());
4189
4190 C->set_has_split_ifs(true); // Has chance for split-if optimization
4191 set_result(region, phi);
4192 return true;
4193 }
4194
4195 //-------------------------inline_Class_cast-------------------
4196 bool LibraryCallKit::inline_Class_cast() {
4197 Node* mirror = argument(0); // Class
4198 Node* obj = argument(1);
4199 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
4200 if (mirror_con == nullptr) {
4201 return false; // dead path (mirror->is_top()).
4202 }
4203 if (obj == nullptr || obj->is_top()) {
4204 return false; // dead path
4205 }
4206 const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr();
4207
4208 // First, see if Class.cast() can be folded statically.
4209 // java_mirror_type() returns non-null for compile-time Class constants.
4210 ciType* tm = mirror_con->java_mirror_type();
4211 if (tm != nullptr && tm->is_klass() &&
4212 tp != nullptr) {
4213 if (!tp->is_loaded()) {
4214 // Don't use intrinsic when class is not loaded.
4215 return false;
4216 } else {
4217 int static_res = C->static_subtype_check(TypeKlassPtr::make(tm->as_klass(), Type::trust_interfaces), tp->as_klass_type());
4218 if (static_res == Compile::SSC_always_true) {
4219 // isInstance() is true - fold the code.
4220 set_result(obj);
4221 return true;
4222 } else if (static_res == Compile::SSC_always_false) {
4223 // Don't use intrinsic, have to throw ClassCastException.
4224 // If the reference is null, the non-intrinsic bytecode will
4225 // be optimized appropriately.
4226 return false;
4227 }
4228 }
4229 }
4230
4231 // Bailout intrinsic and do normal inlining if exception path is frequent.
4232 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
4233 return false;
4234 }
4235
4236 // Generate dynamic checks.
4237 // Class.cast() is java implementation of _checkcast bytecode.
4238 // Do checkcast (Parse::do_checkcast()) optimizations here.
4239
4240 mirror = null_check(mirror);
4241 // If mirror is dead, only null-path is taken.
4242 if (stopped()) {
4243 return true;
4244 }
4245
4246 // Not-subtype or the mirror's klass ptr is null (in case it is a primitive).
4247 enum { _bad_type_path = 1, _prim_path = 2, PATH_LIMIT };
4248 RegionNode* region = new RegionNode(PATH_LIMIT);
4249 record_for_igvn(region);
4250
4251 // Now load the mirror's klass metaobject, and null-check it.
4252 // If kls is null, we have a primitive mirror and
4253 // nothing is an instance of a primitive type.
4254 Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path);
4255
4256 Node* res = top();
4257 if (!stopped()) {
4258 Node* bad_type_ctrl = top();
4259 // Do checkcast optimizations.
4260 res = gen_checkcast(obj, kls, &bad_type_ctrl);
4261 region->init_req(_bad_type_path, bad_type_ctrl);
4262 }
4263 if (region->in(_prim_path) != top() ||
4264 region->in(_bad_type_path) != top()) {
4265 // Let Interpreter throw ClassCastException.
4266 PreserveJVMState pjvms(this);
4267 set_control(_gvn.transform(region));
4268 uncommon_trap(Deoptimization::Reason_intrinsic,
4269 Deoptimization::Action_maybe_recompile);
4270 }
4271 if (!stopped()) {
4272 set_result(res);
4273 }
4274 return true;
4275 }
4276
4277
4278 //--------------------------inline_native_subtype_check------------------------
4279 // This intrinsic takes the JNI calls out of the heart of
4280 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
4281 bool LibraryCallKit::inline_native_subtype_check() {
4282 // Pull both arguments off the stack.
4283 Node* args[2]; // two java.lang.Class mirrors: superc, subc
4284 args[0] = argument(0);
4285 args[1] = argument(1);
4286 Node* klasses[2]; // corresponding Klasses: superk, subk
4287 klasses[0] = klasses[1] = top();
4288
4289 enum {
4290 // A full decision tree on {superc is prim, subc is prim}:
4291 _prim_0_path = 1, // {P,N} => false
4292 // {P,P} & superc!=subc => false
4293 _prim_same_path, // {P,P} & superc==subc => true
4294 _prim_1_path, // {N,P} => false
4295 _ref_subtype_path, // {N,N} & subtype check wins => true
4296 _both_ref_path, // {N,N} & subtype check loses => false
4297 PATH_LIMIT
4298 };
4299
4300 RegionNode* region = new RegionNode(PATH_LIMIT);
4301 Node* phi = new PhiNode(region, TypeInt::BOOL);
4302 record_for_igvn(region);
4303
4304 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads
4305 const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL;
4306 int class_klass_offset = java_lang_Class::klass_offset();
4307
4308 // First null-check both mirrors and load each mirror's klass metaobject.
4309 int which_arg;
4310 for (which_arg = 0; which_arg <= 1; which_arg++) {
4311 Node* arg = args[which_arg];
4312 arg = null_check(arg);
4313 if (stopped()) break;
4314 args[which_arg] = arg;
4315
4316 Node* p = basic_plus_adr(arg, class_klass_offset);
4317 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type);
4318 klasses[which_arg] = _gvn.transform(kls);
4319 }
4320
4321 // Having loaded both klasses, test each for null.
4322 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
4323 for (which_arg = 0; which_arg <= 1; which_arg++) {
4324 Node* kls = klasses[which_arg];
4325 Node* null_ctl = top();
4326 kls = null_check_oop(kls, &null_ctl, never_see_null);
4327 int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path);
4328 region->init_req(prim_path, null_ctl);
4329 if (stopped()) break;
4330 klasses[which_arg] = kls;
4331 }
4332
4333 if (!stopped()) {
4334 // now we have two reference types, in klasses[0..1]
4335 Node* subk = klasses[1]; // the argument to isAssignableFrom
4336 Node* superk = klasses[0]; // the receiver
4337 region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
4338 // now we have a successful reference subtype check
4339 region->set_req(_ref_subtype_path, control());
4340 }
4341
4342 // If both operands are primitive (both klasses null), then
4343 // we must return true when they are identical primitives.
4344 // It is convenient to test this after the first null klass check.
4345 set_control(region->in(_prim_0_path)); // go back to first null check
4346 if (!stopped()) {
4347 // Since superc is primitive, make a guard for the superc==subc case.
4348 Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
4349 Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
4350 generate_guard(bol_eq, region, PROB_FAIR);
4351 if (region->req() == PATH_LIMIT+1) {
4352 // A guard was added. If the added guard is taken, superc==subc.
4353 region->swap_edges(PATH_LIMIT, _prim_same_path);
4354 region->del_req(PATH_LIMIT);
4355 }
4356 region->set_req(_prim_0_path, control()); // Not equal after all.
4357 }
4358
4359 // these are the only paths that produce 'true':
4360 phi->set_req(_prim_same_path, intcon(1));
4361 phi->set_req(_ref_subtype_path, intcon(1));
4362
4363 // pull together the cases:
4364 assert(region->req() == PATH_LIMIT, "sane region");
4365 for (uint i = 1; i < region->req(); i++) {
4366 Node* ctl = region->in(i);
4367 if (ctl == nullptr || ctl == top()) {
4368 region->set_req(i, top());
4369 phi ->set_req(i, top());
4370 } else if (phi->in(i) == nullptr) {
4371 phi->set_req(i, intcon(0)); // all other paths produce 'false'
4372 }
4373 }
4374
4375 set_control(_gvn.transform(region));
4376 set_result(_gvn.transform(phi));
4377 return true;
4378 }
4379
4380 //---------------------generate_array_guard_common------------------------
4381 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
4382 bool obj_array, bool not_array, Node** obj) {
4383
4384 if (stopped()) {
4385 return nullptr;
4386 }
4387
4388 // If obj_array/non_array==false/false:
4389 // Branch around if the given klass is in fact an array (either obj or prim).
4390 // If obj_array/non_array==false/true:
4391 // Branch around if the given klass is not an array klass of any kind.
4392 // If obj_array/non_array==true/true:
4393 // Branch around if the kls is not an oop array (kls is int[], String, etc.)
4394 // If obj_array/non_array==true/false:
4395 // Branch around if the kls is an oop array (Object[] or subtype)
4396 //
4397 // Like generate_guard, adds a new path onto the region.
4398 jint layout_con = 0;
4399 Node* layout_val = get_layout_helper(kls, layout_con);
4400 if (layout_val == nullptr) {
4401 bool query = (obj_array
4402 ? Klass::layout_helper_is_objArray(layout_con)
4403 : Klass::layout_helper_is_array(layout_con));
4404 if (query == not_array) {
4405 return nullptr; // never a branch
4406 } else { // always a branch
4407 Node* always_branch = control();
4408 if (region != nullptr)
4409 region->add_req(always_branch);
4410 set_control(top());
4411 return always_branch;
4412 }
4413 }
4414 // Now test the correct condition.
4415 jint nval = (obj_array
4416 ? (jint)(Klass::_lh_array_tag_type_value
4417 << Klass::_lh_array_tag_shift)
4418 : Klass::_lh_neutral_value);
4419 Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval)));
4420 BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array
4421 // invert the test if we are looking for a non-array
4422 if (not_array) btest = BoolTest(btest).negate();
4423 Node* bol = _gvn.transform(new BoolNode(cmp, btest));
4424 Node* ctrl = generate_fair_guard(bol, region);
4425 Node* is_array_ctrl = not_array ? control() : ctrl;
4426 if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top()) {
4427 // Keep track of the fact that 'obj' is an array to prevent
4428 // array specific accesses from floating above the guard.
4429 *obj = _gvn.transform(new CheckCastPPNode(is_array_ctrl, *obj, TypeAryPtr::BOTTOM));
4430 }
4431 return ctrl;
4432 }
4433
4434
4435 //-----------------------inline_native_newArray--------------------------
4436 // private static native Object java.lang.reflect.newArray(Class<?> componentType, int length);
4437 // private native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size);
4438 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) {
4439 Node* mirror;
4440 Node* count_val;
4441 if (uninitialized) {
4442 null_check_receiver();
4443 mirror = argument(1);
4444 count_val = argument(2);
4445 } else {
4446 mirror = argument(0);
4447 count_val = argument(1);
4448 }
4449
4450 mirror = null_check(mirror);
4451 // If mirror or obj is dead, only null-path is taken.
4452 if (stopped()) return true;
4453
4454 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT };
4455 RegionNode* result_reg = new RegionNode(PATH_LIMIT);
4456 PhiNode* result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
4474 CallJavaNode* slow_call = nullptr;
4475 if (uninitialized) {
4476 // Generate optimized virtual call (holder class 'Unsafe' is final)
4477 slow_call = generate_method_call(vmIntrinsics::_allocateUninitializedArray, false, false, true);
4478 } else {
4479 slow_call = generate_method_call_static(vmIntrinsics::_newArray, true);
4480 }
4481 Node* slow_result = set_results_for_java_call(slow_call);
4482 // this->control() comes from set_results_for_java_call
4483 result_reg->set_req(_slow_path, control());
4484 result_val->set_req(_slow_path, slow_result);
4485 result_io ->set_req(_slow_path, i_o());
4486 result_mem->set_req(_slow_path, reset_memory());
4487 }
4488
4489 set_control(normal_ctl);
4490 if (!stopped()) {
4491 // Normal case: The array type has been cached in the java.lang.Class.
4492 // The following call works fine even if the array type is polymorphic.
4493 // It could be a dynamic mix of int[], boolean[], Object[], etc.
4494 Node* obj = new_array(klass_node, count_val, 0); // no arguments to push
4495 result_reg->init_req(_normal_path, control());
4496 result_val->init_req(_normal_path, obj);
4497 result_io ->init_req(_normal_path, i_o());
4498 result_mem->init_req(_normal_path, reset_memory());
4499
4500 if (uninitialized) {
4501 // Mark the allocation so that zeroing is skipped
4502 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj);
4503 alloc->maybe_set_complete(&_gvn);
4504 }
4505 }
4506
4507 // Return the combined state.
4508 set_i_o( _gvn.transform(result_io) );
4509 set_all_memory( _gvn.transform(result_mem));
4510
4511 C->set_has_split_ifs(true); // Has chance for split-if optimization
4512 set_result(result_reg, result_val);
4513 return true;
4554 Node* original = argument(0);
4555 Node* start = is_copyOfRange? argument(1): intcon(0);
4556 Node* end = is_copyOfRange? argument(2): argument(1);
4557 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2);
4558
4559 Node* newcopy = nullptr;
4560
4561 // Set the original stack and the reexecute bit for the interpreter to reexecute
4562 // the bytecode that invokes Arrays.copyOf if deoptimization happens.
4563 { PreserveReexecuteState preexecs(this);
4564 jvms()->set_should_reexecute(true);
4565
4566 array_type_mirror = null_check(array_type_mirror);
4567 original = null_check(original);
4568
4569 // Check if a null path was taken unconditionally.
4570 if (stopped()) return true;
4571
4572 Node* orig_length = load_array_length(original);
4573
4574 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, nullptr, 0);
4575 klass_node = null_check(klass_node);
4576
4577 RegionNode* bailout = new RegionNode(1);
4578 record_for_igvn(bailout);
4579
4580 // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc.
4581 // Bail out if that is so.
4582 Node* not_objArray = generate_non_objArray_guard(klass_node, bailout);
4583 if (not_objArray != nullptr) {
4584 // Improve the klass node's type from the new optimistic assumption:
4585 ciKlass* ak = ciArrayKlass::make(env()->Object_klass());
4586 const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/);
4587 Node* cast = new CastPPNode(control(), klass_node, akls);
4588 klass_node = _gvn.transform(cast);
4589 }
4590
4591 // Bail out if either start or end is negative.
4592 generate_negative_guard(start, bailout, &start);
4593 generate_negative_guard(end, bailout, &end);
4594
4595 Node* length = end;
4596 if (_gvn.type(start) != TypeInt::ZERO) {
4597 length = _gvn.transform(new SubINode(end, start));
4598 }
4599
4600 // Bail out if length is negative (i.e., if start > end).
4601 // Without this the new_array would throw
4602 // NegativeArraySizeException but IllegalArgumentException is what
4603 // should be thrown
4604 generate_negative_guard(length, bailout, &length);
4605
4606 // Bail out if start is larger than the original length
4607 Node* orig_tail = _gvn.transform(new SubINode(orig_length, start));
4608 generate_negative_guard(orig_tail, bailout, &orig_tail);
4609
4610 if (bailout->req() > 1) {
4611 PreserveJVMState pjvms(this);
4612 set_control(_gvn.transform(bailout));
4613 uncommon_trap(Deoptimization::Reason_intrinsic,
4614 Deoptimization::Action_maybe_recompile);
4615 }
4616
4617 if (!stopped()) {
4618 // How many elements will we copy from the original?
4619 // The answer is MinI(orig_tail, length).
4620 Node* moved = _gvn.transform(new MinINode(orig_tail, length));
4621
4622 // Generate a direct call to the right arraycopy function(s).
4623 // We know the copy is disjoint but we might not know if the
4624 // oop stores need checking.
4625 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class).
4626 // This will fail a store-check if x contains any non-nulls.
4627
4628 // ArrayCopyNode:Ideal may transform the ArrayCopyNode to
4629 // loads/stores but it is legal only if we're sure the
4630 // Arrays.copyOf would succeed. So we need all input arguments
4631 // to the copyOf to be validated, including that the copy to the
4632 // new array won't trigger an ArrayStoreException. That subtype
4633 // check can be optimized if we know something on the type of
4634 // the input array from type speculation.
4645 }
4646 }
4647
4648 bool validated = false;
4649 // Reason_class_check rather than Reason_intrinsic because we
4650 // want to intrinsify even if this traps.
4651 if (!too_many_traps(Deoptimization::Reason_class_check)) {
4652 Node* not_subtype_ctrl = gen_subtype_check(original, klass_node);
4653
4654 if (not_subtype_ctrl != top()) {
4655 PreserveJVMState pjvms(this);
4656 set_control(not_subtype_ctrl);
4657 uncommon_trap(Deoptimization::Reason_class_check,
4658 Deoptimization::Action_make_not_entrant);
4659 assert(stopped(), "Should be stopped");
4660 }
4661 validated = true;
4662 }
4663
4664 if (!stopped()) {
4665 newcopy = new_array(klass_node, length, 0); // no arguments to push
4666
4667 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, true,
4668 load_object_klass(original), klass_node);
4669 if (!is_copyOfRange) {
4670 ac->set_copyof(validated);
4671 } else {
4672 ac->set_copyofrange(validated);
4673 }
4674 Node* n = _gvn.transform(ac);
4675 if (n == ac) {
4676 ac->connect_outputs(this);
4677 } else {
4678 assert(validated, "shouldn't transform if all arguments not validated");
4679 set_all_memory(n);
4680 }
4681 }
4682 }
4683 } // original reexecute is set back here
4684
4685 C->set_has_split_ifs(true); // Has chance for split-if optimization
4686 if (!stopped()) {
4687 set_result(newcopy);
4688 }
4689 return true;
4690 }
4691
4692
4693 //----------------------generate_virtual_guard---------------------------
4694 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call.
4695 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,
4696 RegionNode* slow_region) {
4697 ciMethod* method = callee();
4698 int vtable_index = method->vtable_index();
4699 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
4700 "bad index %d", vtable_index);
4701 // Get the Method* out of the appropriate vtable entry.
4702 int entry_offset = in_bytes(Klass::vtable_start_offset()) +
4703 vtable_index*vtableEntry::size_in_bytes() +
4704 in_bytes(vtableEntry::method_offset());
4705 Node* entry_addr = off_heap_plus_addr(obj_klass, entry_offset);
4706 Node* target_call = make_load(nullptr, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered);
4707
4708 // Compare the target method with the expected method (e.g., Object.hashCode).
4709 const TypePtr* native_call_addr = TypeMetadataPtr::make(method);
4710
4711 Node* native_call = makecon(native_call_addr);
4717
4718 //-----------------------generate_method_call----------------------------
4719 // Use generate_method_call to make a slow-call to the real
4720 // method if the fast path fails. An alternative would be to
4721 // use a stub like OptoRuntime::slow_arraycopy_Java.
4722 // This only works for expanding the current library call,
4723 // not another intrinsic. (E.g., don't use this for making an
4724 // arraycopy call inside of the copyOf intrinsic.)
4725 CallJavaNode*
4726 LibraryCallKit::generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null) {
4727 // When compiling the intrinsic method itself, do not use this technique.
4728 guarantee(callee() != C->method(), "cannot make slow-call to self");
4729
4730 ciMethod* method = callee();
4731 // ensure the JVMS we have will be correct for this call
4732 guarantee(method_id == method->intrinsic_id(), "must match");
4733
4734 const TypeFunc* tf = TypeFunc::make(method);
4735 if (res_not_null) {
4736 assert(tf->return_type() == T_OBJECT, "");
4737 const TypeTuple* range = tf->range();
4738 const Type** fields = TypeTuple::fields(range->cnt());
4739 fields[TypeFunc::Parms] = range->field_at(TypeFunc::Parms)->filter_speculative(TypePtr::NOTNULL);
4740 const TypeTuple* new_range = TypeTuple::make(range->cnt(), fields);
4741 tf = TypeFunc::make(tf->domain(), new_range);
4742 }
4743 CallJavaNode* slow_call;
4744 if (is_static) {
4745 assert(!is_virtual, "");
4746 slow_call = new CallStaticJavaNode(C, tf,
4747 SharedRuntime::get_resolve_static_call_stub(), method);
4748 } else if (is_virtual) {
4749 assert(!gvn().type(argument(0))->maybe_null(), "should not be null");
4750 int vtable_index = Method::invalid_vtable_index;
4751 if (UseInlineCaches) {
4752 // Suppress the vtable call
4753 } else {
4754 // hashCode and clone are not a miranda methods,
4755 // so the vtable index is fixed.
4756 // No need to use the linkResolver to get it.
4757 vtable_index = method->vtable_index();
4758 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
4759 "bad index %d", vtable_index);
4760 }
4761 slow_call = new CallDynamicJavaNode(tf,
4778 set_edges_for_java_call(slow_call);
4779 return slow_call;
4780 }
4781
4782
4783 /**
4784 * Build special case code for calls to hashCode on an object. This call may
4785 * be virtual (invokevirtual) or bound (invokespecial). For each case we generate
4786 * slightly different code.
4787 */
4788 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
4789 assert(is_static == callee()->is_static(), "correct intrinsic selection");
4790 assert(!(is_virtual && is_static), "either virtual, special, or static");
4791
4792 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT };
4793
4794 RegionNode* result_reg = new RegionNode(PATH_LIMIT);
4795 PhiNode* result_val = new PhiNode(result_reg, TypeInt::INT);
4796 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO);
4797 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
4798 Node* obj = nullptr;
4799 if (!is_static) {
4800 // Check for hashing null object
4801 obj = null_check_receiver();
4802 if (stopped()) return true; // unconditionally null
4803 result_reg->init_req(_null_path, top());
4804 result_val->init_req(_null_path, top());
4805 } else {
4806 // Do a null check, and return zero if null.
4807 // System.identityHashCode(null) == 0
4808 obj = argument(0);
4809 Node* null_ctl = top();
4810 obj = null_check_oop(obj, &null_ctl);
4811 result_reg->init_req(_null_path, null_ctl);
4812 result_val->init_req(_null_path, _gvn.intcon(0));
4813 }
4814
4815 // Unconditionally null? Then return right away.
4816 if (stopped()) {
4817 set_control( result_reg->in(_null_path));
4818 if (!stopped())
4819 set_result(result_val->in(_null_path));
4820 return true;
4821 }
4822
4823 // We only go to the fast case code if we pass a number of guards. The
4824 // paths which do not pass are accumulated in the slow_region.
4825 RegionNode* slow_region = new RegionNode(1);
4826 record_for_igvn(slow_region);
4827
4828 // If this is a virtual call, we generate a funny guard. We pull out
4829 // the vtable entry corresponding to hashCode() from the target object.
4830 // If the target method which we are calling happens to be the native
4831 // Object hashCode() method, we pass the guard. We do not need this
4832 // guard for non-virtual calls -- the caller is known to be the native
4833 // Object hashCode().
4834 if (is_virtual) {
4835 // After null check, get the object's klass.
4836 Node* obj_klass = load_object_klass(obj);
4837 generate_virtual_guard(obj_klass, slow_region);
4838 }
4839
4840 // Get the header out of the object, use LoadMarkNode when available
4841 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
4842 // The control of the load must be null. Otherwise, the load can move before
4843 // the null check after castPP removal.
4844 Node* no_ctrl = nullptr;
4845 Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
4846
4847 if (!UseObjectMonitorTable) {
4848 // Test the header to see if it is safe to read w.r.t. locking.
4849 Node *lock_mask = _gvn.MakeConX(markWord::lock_mask_in_place);
4850 Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask));
4851 Node *monitor_val = _gvn.MakeConX(markWord::monitor_value);
4852 Node *chk_monitor = _gvn.transform(new CmpXNode(lmasked_header, monitor_val));
4853 Node *test_monitor = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq));
4854
4855 generate_slow_guard(test_monitor, slow_region);
4856 }
4857
4858 // Get the hash value and check to see that it has been properly assigned.
4859 // We depend on hash_mask being at most 32 bits and avoid the use of
4860 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit
4861 // vm: see markWord.hpp.
4862 Node *hash_mask = _gvn.intcon(markWord::hash_mask);
4863 Node *hash_shift = _gvn.intcon(markWord::hash_shift);
4864 Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift));
4865 // This hack lets the hash bits live anywhere in the mark object now, as long
4866 // as the shift drops the relevant bits into the low 32 bits. Note that
4867 // Java spec says that HashCode is an int so there's no point in capturing
4868 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
4896 // this->control() comes from set_results_for_java_call
4897 result_reg->init_req(_slow_path, control());
4898 result_val->init_req(_slow_path, slow_result);
4899 result_io ->set_req(_slow_path, i_o());
4900 result_mem ->set_req(_slow_path, reset_memory());
4901 }
4902
4903 // Return the combined state.
4904 set_i_o( _gvn.transform(result_io) );
4905 set_all_memory( _gvn.transform(result_mem));
4906
4907 set_result(result_reg, result_val);
4908 return true;
4909 }
4910
4911 //---------------------------inline_native_getClass----------------------------
4912 // public final native Class<?> java.lang.Object.getClass();
4913 //
4914 // Build special case code for calls to getClass on an object.
4915 bool LibraryCallKit::inline_native_getClass() {
4916 Node* obj = null_check_receiver();
4917 if (stopped()) return true;
4918 set_result(load_mirror_from_klass(load_object_klass(obj)));
4919 return true;
4920 }
4921
4922 //-----------------inline_native_Reflection_getCallerClass---------------------
4923 // public static native Class<?> sun.reflect.Reflection.getCallerClass();
4924 //
4925 // In the presence of deep enough inlining, getCallerClass() becomes a no-op.
4926 //
4927 // NOTE: This code must perform the same logic as JVM_GetCallerClass
4928 // in that it must skip particular security frames and checks for
4929 // caller sensitive methods.
4930 bool LibraryCallKit::inline_native_Reflection_getCallerClass() {
4931 #ifndef PRODUCT
4932 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
4933 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass");
4934 }
4935 #endif
4936
5311
5312 //------------------------inline_native_clone----------------------------
5313 // protected native Object java.lang.Object.clone();
5314 //
5315 // Here are the simple edge cases:
5316 // null receiver => normal trap
5317 // virtual and clone was overridden => slow path to out-of-line clone
5318 // not cloneable or finalizer => slow path to out-of-line Object.clone
5319 //
5320 // The general case has two steps, allocation and copying.
5321 // Allocation has two cases, and uses GraphKit::new_instance or new_array.
5322 //
5323 // Copying also has two cases, oop arrays and everything else.
5324 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy).
5325 // Everything else uses the tight inline loop supplied by CopyArrayNode.
5326 //
5327 // These steps fold up nicely if and when the cloned object's klass
5328 // can be sharply typed as an object array, a type array, or an instance.
5329 //
5330 bool LibraryCallKit::inline_native_clone(bool is_virtual) {
5331 PhiNode* result_val;
5332
5333 // Set the reexecute bit for the interpreter to reexecute
5334 // the bytecode that invokes Object.clone if deoptimization happens.
5335 { PreserveReexecuteState preexecs(this);
5336 jvms()->set_should_reexecute(true);
5337
5338 Node* obj = null_check_receiver();
5339 if (stopped()) return true;
5340
5341 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
5342
5343 // If we are going to clone an instance, we need its exact type to
5344 // know the number and types of fields to convert the clone to
5345 // loads/stores. Maybe a speculative type can help us.
5346 if (!obj_type->klass_is_exact() &&
5347 obj_type->speculative_type() != nullptr &&
5348 obj_type->speculative_type()->is_instance_klass()) {
5349 ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass();
5350 if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem &&
5351 !spec_ik->has_injected_fields()) {
5352 if (!obj_type->isa_instptr() ||
5353 obj_type->is_instptr()->instance_klass()->has_subklass()) {
5354 obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false);
5355 }
5356 }
5357 }
5358
5359 // Conservatively insert a memory barrier on all memory slices.
5360 // Do not let writes into the original float below the clone.
5361 insert_mem_bar(Op_MemBarCPUOrder);
5362
5363 // paths into result_reg:
5364 enum {
5365 _slow_path = 1, // out-of-line call to clone method (virtual or not)
5366 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy
5367 _array_path, // plain array allocation, plus arrayof_long_arraycopy
5368 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy
5369 PATH_LIMIT
5370 };
5371 RegionNode* result_reg = new RegionNode(PATH_LIMIT);
5372 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
5373 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO);
5374 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
5375 record_for_igvn(result_reg);
5376
5377 Node* obj_klass = load_object_klass(obj);
5378 Node* array_obj = obj;
5379 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)nullptr, &array_obj);
5380 if (array_ctl != nullptr) {
5381 // It's an array.
5382 PreserveJVMState pjvms(this);
5383 set_control(array_ctl);
5384 Node* obj_length = load_array_length(array_obj);
5385 Node* array_size = nullptr; // Size of the array without object alignment padding.
5386 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &array_size, /*deoptimize_on_exception=*/true);
5387
5388 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
5389 if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Parsing)) {
5390 // If it is an oop array, it requires very special treatment,
5391 // because gc barriers are required when accessing the array.
5392 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)nullptr);
5393 if (is_obja != nullptr) {
5394 PreserveJVMState pjvms2(this);
5395 set_control(is_obja);
5396 // Generate a direct call to the right arraycopy function(s).
5397 // Clones are always tightly coupled.
5398 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, array_obj, intcon(0), alloc_obj, intcon(0), obj_length, true, false);
5399 ac->set_clone_oop_array();
5400 Node* n = _gvn.transform(ac);
5401 assert(n == ac, "cannot disappear");
5402 ac->connect_outputs(this, /*deoptimize_on_exception=*/true);
5403
5404 result_reg->init_req(_objArray_path, control());
5405 result_val->init_req(_objArray_path, alloc_obj);
5406 result_i_o ->set_req(_objArray_path, i_o());
5407 result_mem ->set_req(_objArray_path, reset_memory());
5408 }
5409 }
5410 // Otherwise, there are no barriers to worry about.
5411 // (We can dispense with card marks if we know the allocation
5412 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks
5413 // causes the non-eden paths to take compensating steps to
5414 // simulate a fresh allocation, so that no further
5415 // card marks are required in compiled code to initialize
5416 // the object.)
5417
5418 if (!stopped()) {
5419 copy_to_clone(array_obj, alloc_obj, array_size, true);
5420
5421 // Present the results of the copy.
5422 result_reg->init_req(_array_path, control());
5423 result_val->init_req(_array_path, alloc_obj);
5424 result_i_o ->set_req(_array_path, i_o());
5425 result_mem ->set_req(_array_path, reset_memory());
5426 }
5427 }
5428
5429 // We only go to the instance fast case code if we pass a number of guards.
5430 // The paths which do not pass are accumulated in the slow_region.
5431 RegionNode* slow_region = new RegionNode(1);
5432 record_for_igvn(slow_region);
5433 if (!stopped()) {
5434 // It's an instance (we did array above). Make the slow-path tests.
5435 // If this is a virtual call, we generate a funny guard. We grab
5436 // the vtable entry corresponding to clone() from the target object.
5437 // If the target method which we are calling happens to be the
5438 // Object clone() method, we pass the guard. We do not need this
5439 // guard for non-virtual calls; the caller is known to be the native
5440 // Object clone().
5441 if (is_virtual) {
5442 generate_virtual_guard(obj_klass, slow_region);
5443 }
5444
5445 // The object must be easily cloneable and must not have a finalizer.
5446 // Both of these conditions may be checked in a single test.
5447 // We could optimize the test further, but we don't care.
5448 generate_misc_flags_guard(obj_klass,
5449 // Test both conditions:
5450 KlassFlags::_misc_is_cloneable_fast | KlassFlags::_misc_has_finalizer,
5451 // Must be cloneable but not finalizer:
5452 KlassFlags::_misc_is_cloneable_fast,
5544 set_jvms(sfpt->jvms());
5545 _reexecute_sp = jvms()->sp();
5546
5547 return saved_jvms;
5548 }
5549 }
5550 }
5551 return nullptr;
5552 }
5553
5554 // Clone the JVMState of the array allocation and create a new safepoint with it. Re-push the array length to the stack
5555 // such that uncommon traps can be emitted to re-execute the array allocation in the interpreter.
5556 SafePointNode* LibraryCallKit::create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const {
5557 JVMState* old_jvms = alloc->jvms()->clone_shallow(C);
5558 uint size = alloc->req();
5559 SafePointNode* sfpt = new SafePointNode(size, old_jvms);
5560 old_jvms->set_map(sfpt);
5561 for (uint i = 0; i < size; i++) {
5562 sfpt->init_req(i, alloc->in(i));
5563 }
5564 // re-push array length for deoptimization
5565 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), alloc->in(AllocateNode::ALength));
5566 old_jvms->set_sp(old_jvms->sp()+1);
5567 old_jvms->set_monoff(old_jvms->monoff()+1);
5568 old_jvms->set_scloff(old_jvms->scloff()+1);
5569 old_jvms->set_endoff(old_jvms->endoff()+1);
5570 old_jvms->set_should_reexecute(true);
5571
5572 sfpt->set_i_o(map()->i_o());
5573 sfpt->set_memory(map()->memory());
5574 sfpt->set_control(map()->control());
5575 return sfpt;
5576 }
5577
5578 // In case of a deoptimization, we restart execution at the
5579 // allocation, allocating a new array. We would leave an uninitialized
5580 // array in the heap that GCs wouldn't expect. Move the allocation
5581 // after the traps so we don't allocate the array if we
5582 // deoptimize. This is possible because tightly_coupled_allocation()
5583 // guarantees there's no observer of the allocated array at this point
5584 // and the control flow is simple enough.
5585 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms_before_guards,
5586 int saved_reexecute_sp, uint new_idx) {
5587 if (saved_jvms_before_guards != nullptr && !stopped()) {
5588 replace_unrelated_uncommon_traps_with_alloc_state(alloc, saved_jvms_before_guards);
5589
5590 assert(alloc != nullptr, "only with a tightly coupled allocation");
5591 // restore JVM state to the state at the arraycopy
5592 saved_jvms_before_guards->map()->set_control(map()->control());
5593 assert(saved_jvms_before_guards->map()->memory() == map()->memory(), "memory state changed?");
5594 assert(saved_jvms_before_guards->map()->i_o() == map()->i_o(), "IO state changed?");
5595 // If we've improved the types of some nodes (null check) while
5596 // emitting the guards, propagate them to the current state
5597 map()->replaced_nodes().apply(saved_jvms_before_guards->map(), new_idx);
5598 set_jvms(saved_jvms_before_guards);
5599 _reexecute_sp = saved_reexecute_sp;
5600
5601 // Remove the allocation from above the guards
5602 CallProjections callprojs;
5603 alloc->extract_projections(&callprojs, true);
5604 InitializeNode* init = alloc->initialization();
5605 Node* alloc_mem = alloc->in(TypeFunc::Memory);
5606 C->gvn_replace_by(callprojs.fallthrough_ioproj, alloc->in(TypeFunc::I_O));
5607 init->replace_mem_projs_by(alloc_mem, C);
5608
5609 // The CastIINode created in GraphKit::new_array (in AllocateArrayNode::make_ideal_length) must stay below
5610 // the allocation (i.e. is only valid if the allocation succeeds):
5611 // 1) replace CastIINode with AllocateArrayNode's length here
5612 // 2) Create CastIINode again once allocation has moved (see below) at the end of this method
5613 //
5614 // Multiple identical CastIINodes might exist here. Each GraphKit::load_array_length() call will generate
5615 // new separate CastIINode (arraycopy guard checks or any array length use between array allocation and ararycopy)
5616 Node* init_control = init->proj_out(TypeFunc::Control);
5617 Node* alloc_length = alloc->Ideal_length();
5618 #ifdef ASSERT
5619 Node* prev_cast = nullptr;
5620 #endif
5621 for (uint i = 0; i < init_control->outcnt(); i++) {
5622 Node* init_out = init_control->raw_out(i);
5623 if (init_out->is_CastII() && init_out->in(TypeFunc::Control) == init_control && init_out->in(1) == alloc_length) {
5624 #ifdef ASSERT
5625 if (prev_cast == nullptr) {
5626 prev_cast = init_out;
5628 if (prev_cast->cmp(*init_out) == false) {
5629 prev_cast->dump();
5630 init_out->dump();
5631 assert(false, "not equal CastIINode");
5632 }
5633 }
5634 #endif
5635 C->gvn_replace_by(init_out, alloc_length);
5636 }
5637 }
5638 C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0));
5639
5640 // move the allocation here (after the guards)
5641 _gvn.hash_delete(alloc);
5642 alloc->set_req(TypeFunc::Control, control());
5643 alloc->set_req(TypeFunc::I_O, i_o());
5644 Node *mem = reset_memory();
5645 set_all_memory(mem);
5646 alloc->set_req(TypeFunc::Memory, mem);
5647 set_control(init->proj_out_or_null(TypeFunc::Control));
5648 set_i_o(callprojs.fallthrough_ioproj);
5649
5650 // Update memory as done in GraphKit::set_output_for_allocation()
5651 const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength));
5652 const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_instance_type();
5653 if (ary_type->isa_aryptr() && length_type != nullptr) {
5654 ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
5655 }
5656 const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot);
5657 int elemidx = C->get_alias_index(telemref);
5658 // Need to properly move every memory projection for the Initialize
5659 #ifdef ASSERT
5660 int mark_idx = C->get_alias_index(ary_type->add_offset(oopDesc::mark_offset_in_bytes()));
5661 int klass_idx = C->get_alias_index(ary_type->add_offset(oopDesc::klass_offset_in_bytes()));
5662 #endif
5663 auto move_proj = [&](ProjNode* proj) {
5664 int alias_idx = C->get_alias_index(proj->adr_type());
5665 assert(alias_idx == Compile::AliasIdxRaw ||
5666 alias_idx == elemidx ||
5667 alias_idx == mark_idx ||
5668 alias_idx == klass_idx, "should be raw memory or array element type");
5669 set_memory(proj, alias_idx);
5670 };
5671 init->for_each_proj(move_proj, TypeFunc::Memory);
5672
5978 top_src = src_type->isa_aryptr();
5979 has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM);
5980 src_spec = true;
5981 }
5982 if (!has_dest) {
5983 dest = maybe_cast_profiled_obj(dest, dest_k, true);
5984 dest_type = _gvn.type(dest);
5985 top_dest = dest_type->isa_aryptr();
5986 has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM);
5987 dest_spec = true;
5988 }
5989 }
5990 }
5991
5992 if (has_src && has_dest && can_emit_guards) {
5993 BasicType src_elem = top_src->isa_aryptr()->elem()->array_element_basic_type();
5994 BasicType dest_elem = top_dest->isa_aryptr()->elem()->array_element_basic_type();
5995 if (is_reference_type(src_elem, true)) src_elem = T_OBJECT;
5996 if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT;
5997
5998 if (src_elem == dest_elem && src_elem == T_OBJECT) {
5999 // If both arrays are object arrays then having the exact types
6000 // for both will remove the need for a subtype check at runtime
6001 // before the call and may make it possible to pick a faster copy
6002 // routine (without a subtype check on every element)
6003 // Do we have the exact type of src?
6004 bool could_have_src = src_spec;
6005 // Do we have the exact type of dest?
6006 bool could_have_dest = dest_spec;
6007 ciKlass* src_k = nullptr;
6008 ciKlass* dest_k = nullptr;
6009 if (!src_spec) {
6010 src_k = src_type->speculative_type_not_null();
6011 if (src_k != nullptr && src_k->is_array_klass()) {
6012 could_have_src = true;
6013 }
6014 }
6015 if (!dest_spec) {
6016 dest_k = dest_type->speculative_type_not_null();
6017 if (dest_k != nullptr && dest_k->is_array_klass()) {
6018 could_have_dest = true;
6019 }
6020 }
6021 if (could_have_src && could_have_dest) {
6022 // If we can have both exact types, emit the missing guards
6023 if (could_have_src && !src_spec) {
6024 src = maybe_cast_profiled_obj(src, src_k, true);
6025 }
6026 if (could_have_dest && !dest_spec) {
6027 dest = maybe_cast_profiled_obj(dest, dest_k, true);
6028 }
6029 }
6030 }
6031 }
6032
6033 ciMethod* trap_method = method();
6034 int trap_bci = bci();
6035 if (saved_jvms_before_guards != nullptr) {
6036 trap_method = alloc->jvms()->method();
6037 trap_bci = alloc->jvms()->bci();
6038 }
6039
6040 bool negative_length_guard_generated = false;
6041
6042 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &&
6043 can_emit_guards &&
6044 !src->is_top() && !dest->is_top()) {
6045 // validate arguments: enables transformation the ArrayCopyNode
6046 validated = true;
6047
6048 RegionNode* slow_region = new RegionNode(1);
6049 record_for_igvn(slow_region);
6050
6051 // (1) src and dest are arrays.
6052 generate_non_array_guard(load_object_klass(src), slow_region, &src);
6053 generate_non_array_guard(load_object_klass(dest), slow_region, &dest);
6054
6055 // (2) src and dest arrays must have elements of the same BasicType
6056 // done at macro expansion or at Ideal transformation time
6057
6058 // (4) src_offset must not be negative.
6059 generate_negative_guard(src_offset, slow_region);
6060
6061 // (5) dest_offset must not be negative.
6062 generate_negative_guard(dest_offset, slow_region);
6063
6064 // (7) src_offset + length must not exceed length of src.
6065 generate_limit_guard(src_offset, length,
6066 load_array_length(src),
6067 slow_region);
6068
6069 // (8) dest_offset + length must not exceed length of dest.
6070 generate_limit_guard(dest_offset, length,
6071 load_array_length(dest),
6072 slow_region);
6073
6074 // (6) length must not be negative.
6075 // This is also checked in generate_arraycopy() during macro expansion, but
6076 // we also have to check it here for the case where the ArrayCopyNode will
6077 // be eliminated by Escape Analysis.
6078 if (EliminateAllocations) {
6079 generate_negative_guard(length, slow_region);
6080 negative_length_guard_generated = true;
6081 }
6082
6083 // (9) each element of an oop array must be assignable
6084 Node* dest_klass = load_object_klass(dest);
6085 if (src != dest) {
6086 Node* not_subtype_ctrl = gen_subtype_check(src, dest_klass);
6087
6088 if (not_subtype_ctrl != top()) {
6089 PreserveJVMState pjvms(this);
6090 set_control(not_subtype_ctrl);
6091 uncommon_trap(Deoptimization::Reason_intrinsic,
6092 Deoptimization::Action_make_not_entrant);
6093 assert(stopped(), "Should be stopped");
6094 }
6095 }
6096 {
6097 PreserveJVMState pjvms(this);
6098 set_control(_gvn.transform(slow_region));
6099 uncommon_trap(Deoptimization::Reason_intrinsic,
6100 Deoptimization::Action_make_not_entrant);
6101 assert(stopped(), "Should be stopped");
6102 }
6103
6104 const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->is_klassptr();
6105 const Type *toop = dest_klass_t->cast_to_exactness(false)->as_instance_type();
6106 src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
6107 arraycopy_move_allocation_here(alloc, dest, saved_jvms_before_guards, saved_reexecute_sp, new_idx);
6108 }
6109
6110 if (stopped()) {
6111 return true;
6112 }
6113
6114 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != nullptr, negative_length_guard_generated,
6115 // Create LoadRange and LoadKlass nodes for use during macro expansion here
6116 // so the compiler has a chance to eliminate them: during macro expansion,
6117 // we have to set their control (CastPP nodes are eliminated).
6118 load_object_klass(src), load_object_klass(dest),
6119 load_array_length(src), load_array_length(dest));
6120
6121 ac->set_arraycopy(validated);
6122
6123 Node* n = _gvn.transform(ac);
6124 if (n == ac) {
6125 ac->connect_outputs(this);
6126 } else {
6127 assert(validated, "shouldn't transform if all arguments not validated");
6128 set_all_memory(n);
6129 }
6130 clear_upper_avx();
6131
6132
6133 return true;
6134 }
6135
6136
6137 // Helper function which determines if an arraycopy immediately follows
6138 // an allocation, with no intervening tests or other escapes for the object.
7345 dest_start = array_element_address(dest, dest_offset, T_BYTE);
7346 }
7347
7348 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
7349 // (because of the predicated logic executed earlier).
7350 // so we cast it here safely.
7351 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
7352
7353 Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
7354 if (embeddedCipherObj == nullptr) return false;
7355
7356 // cast it to what we know it will be at runtime
7357 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr();
7358 assert(tinst != nullptr, "CBC obj is null");
7359 assert(tinst->is_loaded(), "CBC obj is not loaded");
7360 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
7361 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
7362
7363 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
7364 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
7365 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
7366 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
7367 aescrypt_object = _gvn.transform(aescrypt_object);
7368
7369 // we need to get the start of the aescrypt_object's expanded key array
7370 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
7371 if (k_start == nullptr) return false;
7372
7373 // similarly, get the start address of the r vector
7374 Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B");
7375 if (objRvec == nullptr) return false;
7376 Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE);
7377
7378 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
7379 Node* cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
7380 OptoRuntime::cipherBlockChaining_aescrypt_Type(),
7381 stubAddr, stubName, TypePtr::BOTTOM,
7382 src_start, dest_start, k_start, r_start, len);
7383
7384 // return cipher length (int)
7385 Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms));
7432 dest_start = array_element_address(dest, dest_offset, T_BYTE);
7433 }
7434
7435 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
7436 // (because of the predicated logic executed earlier).
7437 // so we cast it here safely.
7438 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
7439
7440 Node* embeddedCipherObj = load_field_from_object(electronicCodeBook_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
7441 if (embeddedCipherObj == nullptr) return false;
7442
7443 // cast it to what we know it will be at runtime
7444 const TypeInstPtr* tinst = _gvn.type(electronicCodeBook_object)->isa_instptr();
7445 assert(tinst != nullptr, "ECB obj is null");
7446 assert(tinst->is_loaded(), "ECB obj is not loaded");
7447 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
7448 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
7449
7450 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
7451 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
7452 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
7453 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
7454 aescrypt_object = _gvn.transform(aescrypt_object);
7455
7456 // we need to get the start of the aescrypt_object's expanded key array
7457 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
7458 if (k_start == nullptr) return false;
7459
7460 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
7461 Node* ecbCrypt = make_runtime_call(RC_LEAF | RC_NO_FP,
7462 OptoRuntime::electronicCodeBook_aescrypt_Type(),
7463 stubAddr, stubName, TypePtr::BOTTOM,
7464 src_start, dest_start, k_start, len);
7465
7466 // return cipher length (int)
7467 Node* retvalue = _gvn.transform(new ProjNode(ecbCrypt, TypeFunc::Parms));
7468 set_result(retvalue);
7469 return true;
7470 }
7471
7472 //------------------------------inline_counterMode_AESCrypt-----------------------
7501 if (src_offset != nullptr || dest_offset != nullptr) {
7502 assert(src_offset != nullptr && dest_offset != nullptr, "");
7503 src_start = array_element_address(src, src_offset, T_BYTE);
7504 dest_start = array_element_address(dest, dest_offset, T_BYTE);
7505 }
7506
7507 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
7508 // (because of the predicated logic executed earlier).
7509 // so we cast it here safely.
7510 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
7511 Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
7512 if (embeddedCipherObj == nullptr) return false;
7513 // cast it to what we know it will be at runtime
7514 const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr();
7515 assert(tinst != nullptr, "CTR obj is null");
7516 assert(tinst->is_loaded(), "CTR obj is not loaded");
7517 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
7518 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
7519 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
7520 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
7521 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
7522 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
7523 aescrypt_object = _gvn.transform(aescrypt_object);
7524 // we need to get the start of the aescrypt_object's expanded key array
7525 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
7526 if (k_start == nullptr) return false;
7527 // similarly, get the start address of the r vector
7528 Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B");
7529 if (obj_counter == nullptr) return false;
7530 Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE);
7531
7532 Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B");
7533 if (saved_encCounter == nullptr) return false;
7534 Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE);
7535 Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false);
7536
7537 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
7538 Node* ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
7539 OptoRuntime::counterMode_aescrypt_Type(),
7540 stubAddr, stubName, TypePtr::BOTTOM,
7541 src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used);
8674 if (stub_addr == nullptr) return false;
8675
8676 // get DigestBase klass to lookup for SHA klass
8677 const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr();
8678 assert(tinst != nullptr, "digestBase_obj is not instance???");
8679 assert(tinst->is_loaded(), "DigestBase is not loaded");
8680
8681 ciKlass* klass_digestBase = tinst->instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name));
8682 assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded");
8683 ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass();
8684 return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit);
8685 }
8686 return false;
8687 }
8688
8689 //------------------------------inline_digestBase_implCompressMB-----------------------
8690 bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase,
8691 BasicType elem_type, address stubAddr, const char *stubName,
8692 Node* src_start, Node* ofs, Node* limit) {
8693 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase);
8694 const TypeOopPtr* xtype = aklass->cast_to_exactness(false)->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
8695 Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype);
8696 digest_obj = _gvn.transform(digest_obj);
8697
8698 Node* state = get_state_from_digest_object(digest_obj, elem_type);
8699 if (state == nullptr) return false;
8700
8701 Node* block_size = nullptr;
8702 if (strcmp("sha3_implCompressMB", stubName) == 0) {
8703 block_size = get_block_size_from_digest_object(digest_obj);
8704 if (block_size == nullptr) return false;
8705 }
8706
8707 // Call the stub.
8708 Node* call;
8709 if (block_size == nullptr) {
8710 call = make_runtime_call(RC_LEAF|RC_NO_FP,
8711 OptoRuntime::digestBase_implCompressMB_Type(false),
8712 stubAddr, stubName, TypePtr::BOTTOM,
8713 src_start, state, ofs, limit);
8714 } else {
8767 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
8768 // (because of the predicated logic executed earlier).
8769 // so we cast it here safely.
8770 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
8771 Node* embeddedCipherObj = load_field_from_object(gctr_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
8772 Node* counter = load_field_from_object(gctr_object, "counter", "[B");
8773 Node* subkeyHtbl = load_field_from_object(ghash_object, "subkeyHtbl", "[J");
8774 Node* state = load_field_from_object(ghash_object, "state", "[J");
8775
8776 if (embeddedCipherObj == nullptr || counter == nullptr || subkeyHtbl == nullptr || state == nullptr) {
8777 return false;
8778 }
8779 // cast it to what we know it will be at runtime
8780 const TypeInstPtr* tinst = _gvn.type(gctr_object)->isa_instptr();
8781 assert(tinst != nullptr, "GCTR obj is null");
8782 assert(tinst->is_loaded(), "GCTR obj is not loaded");
8783 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
8784 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
8785 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
8786 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
8787 const TypeOopPtr* xtype = aklass->as_instance_type();
8788 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
8789 aescrypt_object = _gvn.transform(aescrypt_object);
8790 // we need to get the start of the aescrypt_object's expanded key array
8791 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
8792 if (k_start == nullptr) return false;
8793 // similarly, get the start address of the r vector
8794 Node* cnt_start = array_element_address(counter, intcon(0), T_BYTE);
8795 Node* state_start = array_element_address(state, intcon(0), T_LONG);
8796 Node* subkeyHtbl_start = array_element_address(subkeyHtbl, intcon(0), T_LONG);
8797
8798
8799 // Call the stub, passing params
8800 Node* gcmCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
8801 OptoRuntime::galoisCounterMode_aescrypt_Type(),
8802 stubAddr, stubName, TypePtr::BOTTOM,
8803 in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start);
8804
8805 // return cipher length (int)
8806 Node* retvalue = _gvn.transform(new ProjNode(gcmCrypt, TypeFunc::Parms));
8807 set_result(retvalue);
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/macroAssembler.hpp"
26 #include "ci/ciArrayKlass.hpp"
27 #include "ci/ciFlatArrayKlass.hpp"
28 #include "ci/ciInstanceKlass.hpp"
29 #include "ci/ciSymbols.hpp"
30 #include "ci/ciUtilities.inline.hpp"
31 #include "classfile/vmIntrinsics.hpp"
32 #include "compiler/compileBroker.hpp"
33 #include "compiler/compileLog.hpp"
34 #include "gc/shared/barrierSet.hpp"
35 #include "gc/shared/c2/barrierSetC2.hpp"
36 #include "jfr/support/jfrIntrinsics.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/accessDecorators.hpp"
39 #include "oops/klass.inline.hpp"
40 #include "oops/layoutKind.hpp"
41 #include "oops/objArrayKlass.hpp"
42 #include "opto/addnode.hpp"
43 #include "opto/arraycopynode.hpp"
44 #include "opto/c2compiler.hpp"
45 #include "opto/castnode.hpp"
46 #include "opto/cfgnode.hpp"
47 #include "opto/convertnode.hpp"
48 #include "opto/countbitsnode.hpp"
49 #include "opto/graphKit.hpp"
50 #include "opto/idealKit.hpp"
51 #include "opto/inlinetypenode.hpp"
52 #include "opto/library_call.hpp"
53 #include "opto/mathexactnode.hpp"
54 #include "opto/mulnode.hpp"
55 #include "opto/narrowptrnode.hpp"
56 #include "opto/opaquenode.hpp"
57 #include "opto/opcodes.hpp"
58 #include "opto/parse.hpp"
59 #include "opto/rootnode.hpp"
60 #include "opto/runtime.hpp"
61 #include "opto/subnode.hpp"
62 #include "opto/type.hpp"
63 #include "opto/vectornode.hpp"
64 #include "prims/jvmtiExport.hpp"
65 #include "prims/jvmtiThreadState.hpp"
66 #include "prims/unsafe.hpp"
67 #include "runtime/globals.hpp"
68 #include "runtime/jniHandles.inline.hpp"
69 #include "runtime/mountUnmountDisabler.hpp"
70 #include "runtime/objectMonitor.hpp"
71 #include "runtime/sharedRuntime.hpp"
72 #include "runtime/stubRoutines.hpp"
73 #include "utilities/globalDefinitions.hpp"
74 #include "utilities/macros.hpp"
75 #include "utilities/powerOfTwo.hpp"
76
77 //---------------------------make_vm_intrinsic----------------------------
78 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
79 vmIntrinsicID id = m->intrinsic_id();
80 assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
81
82 if (!m->is_loaded()) {
83 // Do not attempt to inline unloaded methods.
84 return nullptr;
85 }
86
87 C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization);
88 bool is_available = false;
89
90 {
91 // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag
92 // the compiler must transition to '_thread_in_vm' state because both
93 // methods access VM-internal data.
404 case vmIntrinsics::_getReferenceOpaque: return inline_unsafe_access(!is_store, T_OBJECT, Opaque, false);
405 case vmIntrinsics::_getBooleanOpaque: return inline_unsafe_access(!is_store, T_BOOLEAN, Opaque, false);
406 case vmIntrinsics::_getByteOpaque: return inline_unsafe_access(!is_store, T_BYTE, Opaque, false);
407 case vmIntrinsics::_getShortOpaque: return inline_unsafe_access(!is_store, T_SHORT, Opaque, false);
408 case vmIntrinsics::_getCharOpaque: return inline_unsafe_access(!is_store, T_CHAR, Opaque, false);
409 case vmIntrinsics::_getIntOpaque: return inline_unsafe_access(!is_store, T_INT, Opaque, false);
410 case vmIntrinsics::_getLongOpaque: return inline_unsafe_access(!is_store, T_LONG, Opaque, false);
411 case vmIntrinsics::_getFloatOpaque: return inline_unsafe_access(!is_store, T_FLOAT, Opaque, false);
412 case vmIntrinsics::_getDoubleOpaque: return inline_unsafe_access(!is_store, T_DOUBLE, Opaque, false);
413
414 case vmIntrinsics::_putReferenceOpaque: return inline_unsafe_access( is_store, T_OBJECT, Opaque, false);
415 case vmIntrinsics::_putBooleanOpaque: return inline_unsafe_access( is_store, T_BOOLEAN, Opaque, false);
416 case vmIntrinsics::_putByteOpaque: return inline_unsafe_access( is_store, T_BYTE, Opaque, false);
417 case vmIntrinsics::_putShortOpaque: return inline_unsafe_access( is_store, T_SHORT, Opaque, false);
418 case vmIntrinsics::_putCharOpaque: return inline_unsafe_access( is_store, T_CHAR, Opaque, false);
419 case vmIntrinsics::_putIntOpaque: return inline_unsafe_access( is_store, T_INT, Opaque, false);
420 case vmIntrinsics::_putLongOpaque: return inline_unsafe_access( is_store, T_LONG, Opaque, false);
421 case vmIntrinsics::_putFloatOpaque: return inline_unsafe_access( is_store, T_FLOAT, Opaque, false);
422 case vmIntrinsics::_putDoubleOpaque: return inline_unsafe_access( is_store, T_DOUBLE, Opaque, false);
423
424 case vmIntrinsics::_getFlatValue: return inline_unsafe_flat_access(!is_store, Relaxed);
425 case vmIntrinsics::_putFlatValue: return inline_unsafe_flat_access( is_store, Relaxed);
426
427 case vmIntrinsics::_compareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap, Volatile);
428 case vmIntrinsics::_compareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap, Volatile);
429 case vmIntrinsics::_compareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap, Volatile);
430 case vmIntrinsics::_compareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap, Volatile);
431 case vmIntrinsics::_compareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap, Volatile);
432
433 case vmIntrinsics::_weakCompareAndSetReferencePlain: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed);
434 case vmIntrinsics::_weakCompareAndSetReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire);
435 case vmIntrinsics::_weakCompareAndSetReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release);
436 case vmIntrinsics::_weakCompareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile);
437 case vmIntrinsics::_weakCompareAndSetBytePlain: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Relaxed);
438 case vmIntrinsics::_weakCompareAndSetByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Acquire);
439 case vmIntrinsics::_weakCompareAndSetByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Release);
440 case vmIntrinsics::_weakCompareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Volatile);
441 case vmIntrinsics::_weakCompareAndSetShortPlain: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Relaxed);
442 case vmIntrinsics::_weakCompareAndSetShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Acquire);
443 case vmIntrinsics::_weakCompareAndSetShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Release);
444 case vmIntrinsics::_weakCompareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Volatile);
445 case vmIntrinsics::_weakCompareAndSetIntPlain: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Relaxed);
446 case vmIntrinsics::_weakCompareAndSetIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Acquire);
466 case vmIntrinsics::_compareAndExchangeLong: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Volatile);
467 case vmIntrinsics::_compareAndExchangeLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Acquire);
468 case vmIntrinsics::_compareAndExchangeLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Release);
469
470 case vmIntrinsics::_getAndAddByte: return inline_unsafe_load_store(T_BYTE, LS_get_add, Volatile);
471 case vmIntrinsics::_getAndAddShort: return inline_unsafe_load_store(T_SHORT, LS_get_add, Volatile);
472 case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_get_add, Volatile);
473 case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_get_add, Volatile);
474
475 case vmIntrinsics::_getAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_get_set, Volatile);
476 case vmIntrinsics::_getAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_get_set, Volatile);
477 case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_get_set, Volatile);
478 case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_get_set, Volatile);
479 case vmIntrinsics::_getAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_get_set, Volatile);
480
481 case vmIntrinsics::_loadFence:
482 case vmIntrinsics::_storeFence:
483 case vmIntrinsics::_storeStoreFence:
484 case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id());
485
486 case vmIntrinsics::_arrayInstanceBaseOffset: return inline_arrayInstanceBaseOffset();
487 case vmIntrinsics::_arrayInstanceIndexScale: return inline_arrayInstanceIndexScale();
488 case vmIntrinsics::_arrayLayout: return inline_arrayLayout();
489 case vmIntrinsics::_getFieldMap: return inline_getFieldMap();
490
491 case vmIntrinsics::_onSpinWait: return inline_onspinwait();
492
493 case vmIntrinsics::_currentCarrierThread: return inline_native_currentCarrierThread();
494 case vmIntrinsics::_currentThread: return inline_native_currentThread();
495 case vmIntrinsics::_setCurrentThread: return inline_native_setCurrentThread();
496
497 case vmIntrinsics::_scopedValueCache: return inline_native_scopedValueCache();
498 case vmIntrinsics::_setScopedValueCache: return inline_native_setScopedValueCache();
499
500 case vmIntrinsics::_Continuation_pin: return inline_native_Continuation_pinning(false);
501 case vmIntrinsics::_Continuation_unpin: return inline_native_Continuation_pinning(true);
502
503 case vmIntrinsics::_vthreadEndFirstTransition: return inline_native_vthread_end_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_end_first_transition_Java()),
504 "endFirstTransition", true);
505 case vmIntrinsics::_vthreadStartFinalTransition: return inline_native_vthread_start_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_start_final_transition_Java()),
506 "startFinalTransition", true);
507 case vmIntrinsics::_vthreadStartTransition: return inline_native_vthread_start_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_start_transition_Java()),
508 "startTransition", false);
509 case vmIntrinsics::_vthreadEndTransition: return inline_native_vthread_end_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_end_transition_Java()),
510 "endTransition", false);
520 #endif
521 case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis");
522 case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime");
523 case vmIntrinsics::_writeback0: return inline_unsafe_writeback0();
524 case vmIntrinsics::_writebackPreSync0: return inline_unsafe_writebackSync0(true);
525 case vmIntrinsics::_writebackPostSync0: return inline_unsafe_writebackSync0(false);
526 case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate();
527 case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory();
528 case vmIntrinsics::_setMemory: return inline_unsafe_setMemory();
529 case vmIntrinsics::_getLength: return inline_native_getLength();
530 case vmIntrinsics::_copyOf: return inline_array_copyOf(false);
531 case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true);
532 case vmIntrinsics::_equalsB: return inline_array_equals(StrIntrinsicNode::LL);
533 case vmIntrinsics::_equalsC: return inline_array_equals(StrIntrinsicNode::UU);
534 case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex(T_INT);
535 case vmIntrinsics::_Preconditions_checkLongIndex: return inline_preconditions_checkIndex(T_LONG);
536 case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual());
537
538 case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true);
539 case vmIntrinsics::_newArray: return inline_unsafe_newArray(false);
540 case vmIntrinsics::_newNullRestrictedNonAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ false);
541 case vmIntrinsics::_newNullRestrictedAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ true);
542 case vmIntrinsics::_newNullableAtomicArray: return inline_newArray(/* null_free */ false, /* atomic */ true);
543 case vmIntrinsics::_isFlatArray: return inline_getArrayProperties(IsFlat);
544 case vmIntrinsics::_isNullRestrictedArray: return inline_getArrayProperties(IsNullRestricted);
545 case vmIntrinsics::_isAtomicArray: return inline_getArrayProperties(IsAtomic);
546
547 case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check();
548
549 case vmIntrinsics::_isInstance:
550 case vmIntrinsics::_isHidden:
551 case vmIntrinsics::_getSuperclass: return inline_native_Class_query(intrinsic_id());
552
553 case vmIntrinsics::_floatToRawIntBits:
554 case vmIntrinsics::_floatToIntBits:
555 case vmIntrinsics::_intBitsToFloat:
556 case vmIntrinsics::_doubleToRawLongBits:
557 case vmIntrinsics::_doubleToLongBits:
558 case vmIntrinsics::_longBitsToDouble:
559 case vmIntrinsics::_floatToFloat16:
560 case vmIntrinsics::_float16ToFloat: return inline_fp_conversions(intrinsic_id());
561 case vmIntrinsics::_sqrt_float16: return inline_fp16_operations(intrinsic_id(), 1);
562 case vmIntrinsics::_fma_float16: return inline_fp16_operations(intrinsic_id(), 3);
563 case vmIntrinsics::_floatIsFinite:
564 case vmIntrinsics::_floatIsInfinite:
565 case vmIntrinsics::_doubleIsFinite:
2295 case vmIntrinsics::_remainderUnsigned_l: {
2296 zero_check_long(argument(2));
2297 // Compile-time detect of null-exception
2298 if (stopped()) {
2299 return true; // keep the graph constructed so far
2300 }
2301 n = new UModLNode(control(), argument(0), argument(2));
2302 break;
2303 }
2304 default: fatal_unexpected_iid(id); break;
2305 }
2306 set_result(_gvn.transform(n));
2307 return true;
2308 }
2309
2310 //----------------------------inline_unsafe_access----------------------------
2311
2312 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) {
2313 // Attempt to infer a sharper value type from the offset and base type.
2314 ciKlass* sharpened_klass = nullptr;
2315 bool null_free = false;
2316
2317 // See if it is an instance field, with an object type.
2318 if (alias_type->field() != nullptr) {
2319 if (alias_type->field()->type()->is_klass()) {
2320 sharpened_klass = alias_type->field()->type()->as_klass();
2321 null_free = alias_type->field()->is_null_free();
2322 }
2323 }
2324
2325 const TypeOopPtr* result = nullptr;
2326 // See if it is a narrow oop array.
2327 if (adr_type->isa_aryptr()) {
2328 if (adr_type->offset() >= refArrayOopDesc::base_offset_in_bytes()) {
2329 const TypeOopPtr* elem_type = adr_type->is_aryptr()->elem()->make_oopptr();
2330 null_free = adr_type->is_aryptr()->is_null_free();
2331 if (elem_type != nullptr && elem_type->is_loaded()) {
2332 // Sharpen the value type.
2333 result = elem_type;
2334 }
2335 }
2336 }
2337
2338 // The sharpened class might be unloaded if there is no class loader
2339 // contraint in place.
2340 if (result == nullptr && sharpened_klass != nullptr && sharpened_klass->is_loaded()) {
2341 // Sharpen the value type.
2342 result = TypeOopPtr::make_from_klass(sharpened_klass);
2343 if (null_free) {
2344 result = result->join_speculative(TypePtr::NOTNULL)->is_oopptr();
2345 }
2346 }
2347 if (result != nullptr) {
2348 #ifndef PRODUCT
2349 if (C->print_intrinsics() || C->print_inlining()) {
2350 tty->print(" from base type: "); adr_type->dump(); tty->cr();
2351 tty->print(" sharpened value: "); result->dump(); tty->cr();
2352 }
2353 #endif
2354 }
2355 return result;
2356 }
2357
2358 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) {
2359 switch (kind) {
2360 case Relaxed:
2361 return MO_UNORDERED;
2362 case Opaque:
2363 return MO_RELAXED;
2364 case Acquire:
2365 return MO_ACQUIRE;
2413 #endif // ASSERT
2414 }
2415 #endif //PRODUCT
2416
2417 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
2418
2419 Node* receiver = argument(0); // type: oop
2420
2421 // Build address expression.
2422 Node* heap_base_oop = top();
2423
2424 // The base is either a Java object or a value produced by Unsafe.staticFieldBase
2425 Node* base = argument(1); // type: oop
2426 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
2427 Node* offset = argument(2); // type: long
2428 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2429 // to be plain byte offsets, which are also the same as those accepted
2430 // by oopDesc::field_addr.
2431 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2432 "fieldOffset must be byte-scaled");
2433
2434 if (base->is_InlineType()) {
2435 assert(!is_store, "InlineTypeNodes are non-larval value objects");
2436 InlineTypeNode* vt = base->as_InlineType();
2437 if (offset->is_Con()) {
2438 long off = find_long_con(offset, 0);
2439 ciInlineKlass* vk = vt->type()->inline_klass();
2440 if ((long)(int)off != off || !vk->contains_field_offset(off)) {
2441 return false;
2442 }
2443
2444 ciField* field = vk->get_non_flat_field_by_offset(off);
2445 if (field != nullptr) {
2446 BasicType bt = type2field[field->type()->basic_type()];
2447 if (bt == T_ARRAY || bt == T_NARROWOOP) {
2448 bt = T_OBJECT;
2449 }
2450 if (bt == type && !field->is_flat()) {
2451 Node* value = vt->field_value_by_offset(off, false);
2452 const Type* value_type = _gvn.type(value);
2453 if (value_type->is_inlinetypeptr()) {
2454 value = InlineTypeNode::make_from_oop(this, value, value_type->inline_klass());
2455 }
2456 set_result(value);
2457 return true;
2458 }
2459 }
2460 }
2461 {
2462 // Re-execute the unsafe access if allocation triggers deoptimization.
2463 PreserveReexecuteState preexecs(this);
2464 jvms()->set_should_reexecute(true);
2465 vt = vt->buffer(this);
2466 }
2467 base = vt->get_oop();
2468 }
2469
2470 // 32-bit machines ignore the high half!
2471 offset = ConvL2X(offset);
2472
2473 // Save state and restore on bailout
2474 SavedState old_state(this);
2475
2476 Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed);
2477 assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly");
2478
2479 bool is_non_heap_access = (_gvn.type(base->uncast())->isa_ptr() == TypePtr::NULL_PTR);
2480 if (is_non_heap_access) {
2481 if (type != T_OBJECT) {
2482 decorators |= IN_NATIVE; // off-heap primitive access
2483 } else {
2484 return false; // off-heap oop accesses are not supported
2485 }
2486 } else {
2487 heap_base_oop = base; // on-heap or mixed access
2488 }
2489
2499 Node* val = is_store ? argument(4) : nullptr;
2500
2501 const TypePtr* adr_type = _gvn.type(adr)->isa_ptr();
2502 if (adr_type == TypePtr::NULL_PTR) {
2503 return false; // off-heap access with zero address
2504 }
2505
2506 // Try to categorize the address.
2507 Compile::AliasType* alias_type = C->alias_type(adr_type);
2508 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2509
2510 assert((alias_type->index() == Compile::AliasIdxRaw) ==
2511 (is_non_heap_access || (can_access_non_heap && alias_type->field() == nullptr)), "wrong alias");
2512
2513 if (alias_type->adr_type() == TypeInstPtr::KLASS ||
2514 alias_type->adr_type() == TypeAryPtr::RANGE) {
2515 return false; // not supported
2516 }
2517
2518 bool mismatched = false;
2519 BasicType bt = T_ILLEGAL;
2520 ciField* field = nullptr;
2521 if (adr_type->isa_instptr()) {
2522 const TypeInstPtr* instptr = adr_type->is_instptr();
2523 ciInstanceKlass* k = instptr->instance_klass();
2524 int off = instptr->offset();
2525 if (instptr->const_oop() != nullptr &&
2526 k == ciEnv::current()->Class_klass() &&
2527 instptr->offset() >= (k->size_helper() * wordSize)) {
2528 k = instptr->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
2529 field = k->get_field_by_offset(off, true);
2530 } else {
2531 field = k->get_non_flat_field_by_offset(off);
2532 }
2533 if (field != nullptr) {
2534 bt = type2field[field->type()->basic_type()];
2535 }
2536 if (bt != alias_type->basic_type()) {
2537 // Type mismatch. Is it an access to a nested flat field?
2538 field = k->get_field_by_offset(off, false);
2539 if (field != nullptr) {
2540 bt = type2field[field->type()->basic_type()];
2541 }
2542 }
2543 assert(bt == alias_type->basic_type(), "should match");
2544 } else {
2545 bt = alias_type->basic_type();
2546 }
2547
2548 if (bt != T_ILLEGAL) {
2549 assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access");
2550 if (bt == T_BYTE && adr_type->isa_aryptr()) {
2551 // Alias type doesn't differentiate between byte[] and boolean[]).
2552 // Use address type to get the element type.
2553 bt = adr_type->is_aryptr()->elem()->array_element_basic_type();
2554 }
2555 if (is_reference_type(bt, true)) {
2556 // accessing an array field with getReference is not a mismatch
2557 bt = T_OBJECT;
2558 }
2559 if ((bt == T_OBJECT) != (type == T_OBJECT)) {
2560 // Don't intrinsify mismatched object accesses
2561 return false;
2562 }
2563 mismatched = (bt != type);
2564 } else if (alias_type->adr_type()->isa_oopptr()) {
2565 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched
2566 }
2567
2586 }
2587 } else if (type == T_BOOLEAN) {
2588 if (mismatched || alias_type->index() == Compile::AliasIdxRaw) {
2589 value_type = TypeInt::UBYTE;
2590 }
2591 }
2592 }
2593
2594 receiver = null_check(receiver);
2595 if (stopped()) {
2596 return true;
2597 }
2598 // Heap pointers get a null-check from the interpreter,
2599 // as a courtesy. However, this is not guaranteed by Unsafe,
2600 // and it is not possible to fully distinguish unintended nulls
2601 // from intended ones in this API.
2602
2603 if (!is_store) {
2604 Node* p = nullptr;
2605 // Try to constant fold a load from a constant field
2606
2607 if (heap_base_oop != top() && field != nullptr && field->is_constant() && !field->is_flat() && !mismatched) {
2608 // final or stable field
2609 p = make_constant_from_field(field, heap_base_oop);
2610 }
2611
2612 if (p == nullptr) { // Could not constant fold the load
2613 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators);
2614 const TypeOopPtr* ptr = value_type->make_oopptr();
2615 if (ptr != nullptr && ptr->is_inlinetypeptr()) {
2616 // Load a non-flattened inline type from memory
2617 p = InlineTypeNode::make_from_oop(this, p, ptr->inline_klass());
2618 }
2619 }
2620 if (type == T_ADDRESS) {
2621 p = gvn().transform(new CastP2XNode(nullptr, p));
2622 p = ConvX2UL(p);
2623 } else if (type == T_BOOLEAN) {
2624 // Truncate boolean values returned by unsafe operations.
2625 p = gvn().transform(new AndINode(p, gvn().intcon(0x1)));
2626 }
2627 // The load node has the control of the preceding MemBarCPUOrder. All
2628 // following nodes will have the control of the MemBarCPUOrder inserted at
2629 // the end of this method. So, pushing the load onto the stack at a later
2630 // point is fine.
2631 set_result(p);
2632 } else {
2633 if (bt == T_ADDRESS) {
2634 // Repackage the long as a pointer.
2635 val = ConvL2X(val);
2636 val = gvn().transform(new CastX2PNode(val));
2637 }
2638 access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators);
2639 }
2640
2641 return true;
2642 }
2643
2644 bool LibraryCallKit::inline_unsafe_flat_access(bool is_store, AccessKind kind) {
2645 #ifdef ASSERT
2646 {
2647 ResourceMark rm;
2648 // Check the signatures.
2649 ciSignature* sig = callee()->signature();
2650 assert(sig->type_at(0)->basic_type() == T_OBJECT, "base should be object, but is %s", type2name(sig->type_at(0)->basic_type()));
2651 assert(sig->type_at(1)->basic_type() == T_LONG, "offset should be long, but is %s", type2name(sig->type_at(1)->basic_type()));
2652 assert(sig->type_at(2)->basic_type() == T_INT, "layout kind should be int, but is %s", type2name(sig->type_at(3)->basic_type()));
2653 assert(sig->type_at(3)->basic_type() == T_OBJECT, "value klass should be object, but is %s", type2name(sig->type_at(4)->basic_type()));
2654 if (is_store) {
2655 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value, but returns %s", type2name(sig->return_type()->basic_type()));
2656 assert(sig->count() == 5, "flat putter should have 5 arguments, but has %d", sig->count());
2657 assert(sig->type_at(4)->basic_type() == T_OBJECT, "put value should be object, but is %s", type2name(sig->type_at(5)->basic_type()));
2658 } else {
2659 assert(sig->return_type()->basic_type() == T_OBJECT, "getter must return an object, but returns %s", type2name(sig->return_type()->basic_type()));
2660 assert(sig->count() == 4, "flat getter should have 4 arguments, but has %d", sig->count());
2661 }
2662 }
2663 #endif // ASSERT
2664
2665 assert(kind == Relaxed, "Only plain accesses for now");
2666 if (callee()->is_static()) {
2667 // caller must have the capability!
2668 return false;
2669 }
2670 C->set_has_unsafe_access(true);
2671
2672 const TypeInstPtr* value_klass_node = _gvn.type(argument(5))->isa_instptr();
2673 if (value_klass_node == nullptr || value_klass_node->const_oop() == nullptr) {
2674 // parameter valueType is not a constant
2675 return false;
2676 }
2677 ciType* mirror_type = value_klass_node->const_oop()->as_instance()->java_mirror_type();
2678 if (!mirror_type->is_inlinetype()) {
2679 // Dead code
2680 return false;
2681 }
2682 ciInlineKlass* value_klass = mirror_type->as_inline_klass();
2683
2684 const TypeInt* layout_type = _gvn.type(argument(4))->isa_int();
2685 if (layout_type == nullptr || !layout_type->is_con()) {
2686 // parameter layoutKind is not a constant
2687 return false;
2688 }
2689 assert(layout_type->get_con() >= static_cast<int>(LayoutKind::REFERENCE) &&
2690 layout_type->get_con() < static_cast<int>(LayoutKind::UNKNOWN),
2691 "invalid layoutKind %d", layout_type->get_con());
2692 LayoutKind layout = static_cast<LayoutKind>(layout_type->get_con());
2693 assert(layout == LayoutKind::REFERENCE || LayoutKindHelper::is_flat(layout),
2694 "unexpected layoutKind %d", layout_type->get_con());
2695
2696 null_check(argument(0));
2697 if (stopped()) {
2698 return true;
2699 }
2700
2701 Node* base = must_be_not_null(argument(1), true);
2702 Node* offset = argument(2);
2703 const Type* base_type = _gvn.type(base);
2704
2705 Node* ptr;
2706 bool immutable_memory = false;
2707 DecoratorSet decorators = C2_UNSAFE_ACCESS | IN_HEAP | MO_UNORDERED;
2708 if (base_type->isa_instptr()) {
2709 const TypeLong* offset_type = _gvn.type(offset)->isa_long();
2710 if (offset_type == nullptr || !offset_type->is_con()) {
2711 // Offset into a non-array should be a constant
2712 decorators |= C2_MISMATCHED;
2713 } else {
2714 int offset_con = checked_cast<int>(offset_type->get_con());
2715 ciInstanceKlass* base_klass = base_type->is_instptr()->instance_klass();
2716 ciField* field = base_klass->get_non_flat_field_by_offset(offset_con);
2717 if (field == nullptr) {
2718 assert(!base_klass->is_final(), "non-existence field at offset %d of class %s", offset_con, base_klass->name()->as_utf8());
2719 decorators |= C2_MISMATCHED;
2720 } else {
2721 assert(field->type() == value_klass, "field at offset %d of %s is of type %s, but valueType is %s",
2722 offset_con, base_klass->name()->as_utf8(), field->type()->name(), value_klass->name()->as_utf8());
2723 immutable_memory = field->is_strict() && field->is_final();
2724
2725 if (base->is_InlineType()) {
2726 assert(!is_store, "Cannot store into a non-larval value object");
2727 set_result(base->as_InlineType()->field_value_by_offset(offset_con, false));
2728 return true;
2729 }
2730 }
2731 }
2732
2733 if (base->is_InlineType()) {
2734 assert(!is_store, "Cannot store into a non-larval value object");
2735 base = base->as_InlineType()->buffer(this, true);
2736 }
2737 ptr = basic_plus_adr(base, ConvL2X(offset));
2738 } else if (base_type->isa_aryptr()) {
2739 decorators |= IS_ARRAY;
2740 if (layout == LayoutKind::REFERENCE) {
2741 if (!base_type->is_aryptr()->is_not_flat()) {
2742 const TypeAryPtr* array_type = base_type->is_aryptr()->cast_to_not_flat();
2743 // TODO 8350865 This should be a CheckCastPP, can we add a test?
2744 Node* new_base = _gvn.transform(new CastPPNode(control(), base, array_type, ConstraintCastNode::DependencyType::NonFloatingNarrowing));
2745 replace_in_map(base, new_base);
2746 base = new_base;
2747 }
2748 ptr = basic_plus_adr(base, ConvL2X(offset));
2749 } else {
2750 if (UseArrayFlattening) {
2751 // Flat array must have an exact type
2752 bool is_null_free = !LayoutKindHelper::is_nullable_flat(layout);
2753 bool is_atomic = LayoutKindHelper::is_atomic_flat(layout);
2754 Node* new_base = cast_to_flat_array_exact(base, value_klass, is_null_free, is_atomic);
2755 replace_in_map(base, new_base);
2756 base = new_base;
2757 ptr = basic_plus_adr(base, ConvL2X(offset));
2758 const TypeAryPtr* ptr_type = _gvn.type(ptr)->is_aryptr();
2759 if (ptr_type->field_offset().get() != 0) {
2760 // TODO 8350865 This should be a CheckCastPP, can we add a test?
2761 ptr = _gvn.transform(new CastPPNode(control(), ptr, ptr_type->with_field_offset(0), ConstraintCastNode::DependencyType::NonFloatingNarrowing));
2762 }
2763 } else {
2764 uncommon_trap(Deoptimization::Reason_intrinsic,
2765 Deoptimization::Action_none);
2766 return true;
2767 }
2768 }
2769 } else {
2770 decorators |= C2_MISMATCHED;
2771 ptr = basic_plus_adr(base, ConvL2X(offset));
2772 }
2773
2774 if (is_store) {
2775 Node* value = argument(6);
2776 const Type* value_type = _gvn.type(value);
2777 if (!value_type->is_inlinetypeptr()) {
2778 value_type = Type::get_const_type(value_klass)->filter_speculative(value_type);
2779 Node* new_value = _gvn.transform(new CheckCastPPNode(control(), value, value_type, ConstraintCastNode::DependencyType::NonFloatingNarrowing));
2780 new_value = InlineTypeNode::make_from_oop(this, new_value, value_klass);
2781 replace_in_map(value, new_value);
2782 value = new_value;
2783 }
2784
2785 assert(value_type->inline_klass() == value_klass, "value is of type %s while valueType is %s", value_type->inline_klass()->name()->as_utf8(), value_klass->name()->as_utf8());
2786 if (layout == LayoutKind::REFERENCE) {
2787 const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr();
2788 access_store_at(base, ptr, ptr_type, value, value_type, T_OBJECT, decorators);
2789 } else {
2790 bool atomic = LayoutKindHelper::is_atomic_flat(layout);
2791 bool null_free = !LayoutKindHelper::is_nullable_flat(layout);
2792 value->as_InlineType()->store_flat(this, base, ptr, atomic, immutable_memory, null_free, decorators);
2793 }
2794
2795 return true;
2796 } else {
2797 decorators |= (C2_CONTROL_DEPENDENT_LOAD | C2_UNKNOWN_CONTROL_LOAD);
2798 InlineTypeNode* result;
2799 if (layout == LayoutKind::REFERENCE) {
2800 const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr();
2801 Node* oop = access_load_at(base, ptr, ptr_type, Type::get_const_type(value_klass), T_OBJECT, decorators);
2802 result = InlineTypeNode::make_from_oop(this, oop, value_klass);
2803 } else {
2804 bool atomic = LayoutKindHelper::is_atomic_flat(layout);
2805 bool null_free = !LayoutKindHelper::is_nullable_flat(layout);
2806 result = InlineTypeNode::make_from_flat(this, value_klass, base, ptr, atomic, immutable_memory, null_free, decorators);
2807 }
2808
2809 set_result(result);
2810 return true;
2811 }
2812 }
2813
2814 //----------------------------inline_unsafe_load_store----------------------------
2815 // This method serves a couple of different customers (depending on LoadStoreKind):
2816 //
2817 // LS_cmp_swap:
2818 //
2819 // boolean compareAndSetReference(Object o, long offset, Object expected, Object x);
2820 // boolean compareAndSetInt( Object o, long offset, int expected, int x);
2821 // boolean compareAndSetLong( Object o, long offset, long expected, long x);
2822 //
2823 // LS_cmp_swap_weak:
2824 //
2825 // boolean weakCompareAndSetReference( Object o, long offset, Object expected, Object x);
2826 // boolean weakCompareAndSetReferencePlain( Object o, long offset, Object expected, Object x);
2827 // boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x);
2828 // boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x);
2829 //
2830 // boolean weakCompareAndSetInt( Object o, long offset, int expected, int x);
2831 // boolean weakCompareAndSetIntPlain( Object o, long offset, int expected, int x);
2832 // boolean weakCompareAndSetIntAcquire( Object o, long offset, int expected, int x);
2833 // boolean weakCompareAndSetIntRelease( Object o, long offset, int expected, int x);
2996 }
2997 case LS_cmp_swap:
2998 case LS_cmp_swap_weak:
2999 case LS_get_add:
3000 break;
3001 default:
3002 ShouldNotReachHere();
3003 }
3004
3005 // Null check receiver.
3006 receiver = null_check(receiver);
3007 if (stopped()) {
3008 return true;
3009 }
3010
3011 int alias_idx = C->get_alias_index(adr_type);
3012
3013 if (is_reference_type(type)) {
3014 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF;
3015
3016 if (oldval != nullptr && oldval->is_InlineType()) {
3017 // Re-execute the unsafe access if allocation triggers deoptimization.
3018 PreserveReexecuteState preexecs(this);
3019 jvms()->set_should_reexecute(true);
3020 oldval = oldval->as_InlineType()->buffer(this)->get_oop();
3021 }
3022 if (newval != nullptr && newval->is_InlineType()) {
3023 // Re-execute the unsafe access if allocation triggers deoptimization.
3024 PreserveReexecuteState preexecs(this);
3025 jvms()->set_should_reexecute(true);
3026 newval = newval->as_InlineType()->buffer(this)->get_oop();
3027 }
3028
3029 // Transformation of a value which could be null pointer (CastPP #null)
3030 // could be delayed during Parse (for example, in adjust_map_after_if()).
3031 // Execute transformation here to avoid barrier generation in such case.
3032 if (_gvn.type(newval) == TypePtr::NULL_PTR)
3033 newval = _gvn.makecon(TypePtr::NULL_PTR);
3034
3035 if (oldval != nullptr && _gvn.type(oldval) == TypePtr::NULL_PTR) {
3036 // Refine the value to a null constant, when it is known to be null
3037 oldval = _gvn.makecon(TypePtr::NULL_PTR);
3038 }
3039 }
3040
3041 Node* result = nullptr;
3042 switch (kind) {
3043 case LS_cmp_exchange: {
3044 result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx,
3045 oldval, newval, value_type, type, decorators);
3046 break;
3047 }
3048 case LS_cmp_swap_weak:
3077 insert_mem_bar(Op_MemBarCPUOrder);
3078 switch(id) {
3079 case vmIntrinsics::_loadFence:
3080 insert_mem_bar(Op_LoadFence);
3081 return true;
3082 case vmIntrinsics::_storeFence:
3083 insert_mem_bar(Op_StoreFence);
3084 return true;
3085 case vmIntrinsics::_storeStoreFence:
3086 insert_mem_bar(Op_StoreStoreFence);
3087 return true;
3088 case vmIntrinsics::_fullFence:
3089 insert_mem_bar(Op_MemBarFull);
3090 return true;
3091 default:
3092 fatal_unexpected_iid(id);
3093 return false;
3094 }
3095 }
3096
3097 // private native int arrayInstanceBaseOffset0(Object[] array);
3098 bool LibraryCallKit::inline_arrayInstanceBaseOffset() {
3099 Node* array = argument(1);
3100 Node* klass_node = load_object_klass(array);
3101
3102 jint layout_con = Klass::_lh_neutral_value;
3103 Node* layout_val = get_layout_helper(klass_node, layout_con);
3104 int layout_is_con = (layout_val == nullptr);
3105
3106 Node* header_size = nullptr;
3107 if (layout_is_con) {
3108 int hsize = Klass::layout_helper_header_size(layout_con);
3109 header_size = intcon(hsize);
3110 } else {
3111 Node* hss = intcon(Klass::_lh_header_size_shift);
3112 Node* hsm = intcon(Klass::_lh_header_size_mask);
3113 header_size = _gvn.transform(new URShiftINode(layout_val, hss));
3114 header_size = _gvn.transform(new AndINode(header_size, hsm));
3115 }
3116 set_result(header_size);
3117 return true;
3118 }
3119
3120 // private native int arrayInstanceIndexScale0(Object[] array);
3121 bool LibraryCallKit::inline_arrayInstanceIndexScale() {
3122 Node* array = argument(1);
3123 Node* klass_node = load_object_klass(array);
3124
3125 jint layout_con = Klass::_lh_neutral_value;
3126 Node* layout_val = get_layout_helper(klass_node, layout_con);
3127 int layout_is_con = (layout_val == nullptr);
3128
3129 Node* element_size = nullptr;
3130 if (layout_is_con) {
3131 int log_element_size = Klass::layout_helper_log2_element_size(layout_con);
3132 int elem_size = 1 << log_element_size;
3133 element_size = intcon(elem_size);
3134 } else {
3135 Node* ess = intcon(Klass::_lh_log2_element_size_shift);
3136 Node* esm = intcon(Klass::_lh_log2_element_size_mask);
3137 Node* log_element_size = _gvn.transform(new URShiftINode(layout_val, ess));
3138 log_element_size = _gvn.transform(new AndINode(log_element_size, esm));
3139 element_size = _gvn.transform(new LShiftINode(intcon(1), log_element_size));
3140 }
3141 set_result(element_size);
3142 return true;
3143 }
3144
3145 // private native int arrayLayout0(Object[] array);
3146 bool LibraryCallKit::inline_arrayLayout() {
3147 RegionNode* region = new RegionNode(2);
3148 Node* phi = new PhiNode(region, TypeInt::POS);
3149
3150 Node* array = argument(1);
3151 Node* klass_node = load_object_klass(array);
3152 generate_refArray_guard(klass_node, region);
3153 if (region->req() == 3) {
3154 phi->add_req(intcon((jint)LayoutKind::REFERENCE));
3155 }
3156
3157 int layout_kind_offset = in_bytes(FlatArrayKlass::layout_kind_offset());
3158 Node* layout_kind_addr = basic_plus_adr(top(), klass_node, layout_kind_offset);
3159 Node* layout_kind = make_load(nullptr, layout_kind_addr, TypeInt::POS, T_INT, MemNode::unordered);
3160
3161 region->init_req(1, control());
3162 phi->init_req(1, layout_kind);
3163
3164 set_control(_gvn.transform(region));
3165 set_result(_gvn.transform(phi));
3166 return true;
3167 }
3168
3169 // private native int[] getFieldMap0(Class <?> c);
3170 // int offset = c._klass._acmp_maps_offset;
3171 // return (int[])c.obj_field(offset);
3172 bool LibraryCallKit::inline_getFieldMap() {
3173 Node* mirror = argument(1);
3174 Node* klass = load_klass_from_mirror(mirror, false, nullptr, 0);
3175
3176 int field_map_offset_offset = in_bytes(InstanceKlass::acmp_maps_offset_offset());
3177 Node* field_map_offset_addr = basic_plus_adr(top(), klass, field_map_offset_offset);
3178 Node* field_map_offset = make_load(nullptr, field_map_offset_addr, TypeInt::INT, T_INT, MemNode::unordered);
3179 field_map_offset = _gvn.transform(ConvI2L(field_map_offset));
3180
3181 Node* map_addr = basic_plus_adr(mirror, field_map_offset);
3182 const TypeAryPtr* val_type = TypeAryPtr::INTS->cast_to_ptr_type(TypePtr::NotNull)->with_offset(0);
3183 Node* map = access_load_at(mirror, map_addr, TypeAryPtr::INTS, val_type, T_ARRAY, IN_HEAP | MO_UNORDERED);
3184
3185 set_result(map);
3186 return true;
3187 }
3188
3189 bool LibraryCallKit::inline_onspinwait() {
3190 insert_mem_bar(Op_OnSpinWait);
3191 return true;
3192 }
3193
3194 bool LibraryCallKit::klass_needs_init_guard(Node* kls) {
3195 if (!kls->is_Con()) {
3196 return true;
3197 }
3198 const TypeInstKlassPtr* klsptr = kls->bottom_type()->isa_instklassptr();
3199 if (klsptr == nullptr) {
3200 return true;
3201 }
3202 ciInstanceKlass* ik = klsptr->instance_klass();
3203 // don't need a guard for a klass that is already initialized
3204 return !ik->is_initialized();
3205 }
3206
3207 //----------------------------inline_unsafe_writeback0-------------------------
3208 // public native void Unsafe.writeback0(long address)
3287 Deoptimization::Action_make_not_entrant);
3288 }
3289 if (stopped()) {
3290 return true;
3291 }
3292 #endif //INCLUDE_JVMTI
3293
3294 Node* test = nullptr;
3295 if (LibraryCallKit::klass_needs_init_guard(kls)) {
3296 // Note: The argument might still be an illegal value like
3297 // Serializable.class or Object[].class. The runtime will handle it.
3298 // But we must make an explicit check for initialization.
3299 Node* insp = off_heap_plus_addr(kls, in_bytes(InstanceKlass::init_state_offset()));
3300 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler
3301 // can generate code to load it as unsigned byte.
3302 Node* inst = make_load(nullptr, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::acquire);
3303 Node* bits = intcon(InstanceKlass::fully_initialized);
3304 test = _gvn.transform(new SubINode(inst, bits));
3305 // The 'test' is non-zero if we need to take a slow path.
3306 }
3307 Node* obj = new_instance(kls, test);
3308 set_result(obj);
3309 return true;
3310 }
3311
3312 //------------------------inline_native_time_funcs--------------
3313 // inline code for System.currentTimeMillis() and System.nanoTime()
3314 // these have the same type and signature
3315 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) {
3316 const TypeFunc* tf = OptoRuntime::void_long_Type();
3317 const TypePtr* no_memory_effects = nullptr;
3318 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects);
3319 Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0));
3320 #ifdef ASSERT
3321 Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1));
3322 assert(value_top == top(), "second value must be top");
3323 #endif
3324 set_result(value);
3325 return true;
3326 }
3852 vthread_compare_mem->init_req(_false_path, input_memory_state);
3853 vthread_compare_io->init_req(_true_path, _gvn.transform(exclude_compare_io));
3854 vthread_compare_io->init_req(_false_path, input_io_state);
3855 tid->init_req(_true_path, vthread_tid);
3856 tid->init_req(_false_path, thread_obj_tid);
3857 exclusion->init_req(_true_path, vthread_is_excluded);
3858 exclusion->init_req(_false_path, threadObj_is_excluded);
3859 pinVirtualThread->init_req(_true_path, continuation_support);
3860 pinVirtualThread->init_req(_false_path, _gvn.intcon(0));
3861
3862 // Update branch state.
3863 set_control(_gvn.transform(vthread_compare_rgn));
3864 set_all_memory(_gvn.transform(vthread_compare_mem));
3865 set_i_o(_gvn.transform(vthread_compare_io));
3866
3867 // Load the event writer oop by dereferencing the jobject handle.
3868 ciKlass* klass_EventWriter = env()->find_system_klass(ciSymbol::make("jdk/jfr/internal/event/EventWriter"));
3869 assert(klass_EventWriter->is_loaded(), "invariant");
3870 ciInstanceKlass* const instklass_EventWriter = klass_EventWriter->as_instance_klass();
3871 const TypeKlassPtr* const aklass = TypeKlassPtr::make(instklass_EventWriter);
3872 const TypeOopPtr* const xtype = aklass->as_exact_instance_type();
3873 Node* jobj_untagged = _gvn.transform(AddPNode::make_off_heap(jobj, _gvn.MakeConX(-JNIHandles::TypeTag::global)));
3874 Node* event_writer = access_load(jobj_untagged, xtype, T_OBJECT, IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD);
3875
3876 // Load the current thread id from the event writer object.
3877 Node* const event_writer_tid = load_field_from_object(event_writer, "threadID", "J");
3878 // Get the field offset to, conditionally, store an updated tid value later.
3879 Node* const event_writer_tid_field = field_address_from_object(event_writer, "threadID", "J", false);
3880 // Get the field offset to, conditionally, store an updated exclusion value later.
3881 Node* const event_writer_excluded_field = field_address_from_object(event_writer, "excluded", "Z", false);
3882 // Get the field offset to, conditionally, store an updated pinVirtualThread value later.
3883 Node* const event_writer_pin_field = field_address_from_object(event_writer, "pinVirtualThread", "Z", false);
3884
3885 RegionNode* event_writer_tid_compare_rgn = new RegionNode(PATH_LIMIT);
3886 record_for_igvn(event_writer_tid_compare_rgn);
3887 PhiNode* event_writer_tid_compare_mem = new PhiNode(event_writer_tid_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
3888 record_for_igvn(event_writer_tid_compare_mem);
3889 PhiNode* event_writer_tid_compare_io = new PhiNode(event_writer_tid_compare_rgn, Type::ABIO);
3890 record_for_igvn(event_writer_tid_compare_io);
3891
3892 // Compare the current tid from the thread object to what is currently stored in the event writer object.
4217 Node* arr = argument(1);
4218 Node* thread = _gvn.transform(new ThreadLocalNode());
4219 Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::vthread_offset()));
4220 Node* thread_obj_handle
4221 = make_load(nullptr, p, p->bottom_type()->is_ptr(), T_OBJECT, MemNode::unordered);
4222 const TypePtr *adr_type = _gvn.type(thread_obj_handle)->isa_ptr();
4223 access_store_at(nullptr, thread_obj_handle, adr_type, arr, _gvn.type(arr), T_OBJECT, IN_NATIVE | MO_UNORDERED);
4224
4225 // Change the _monitor_owner_id of the JavaThread
4226 Node* tid = load_field_from_object(arr, "tid", "J");
4227 Node* monitor_owner_id_offset = off_heap_plus_addr(thread, in_bytes(JavaThread::monitor_owner_id_offset()));
4228 store_to_memory(control(), monitor_owner_id_offset, tid, T_LONG, MemNode::unordered, true);
4229
4230 JFR_ONLY(extend_setCurrentThread(thread, arr);)
4231 return true;
4232 }
4233
4234 const Type* LibraryCallKit::scopedValueCache_type() {
4235 ciKlass* objects_klass = ciObjArrayKlass::make(env()->Object_klass());
4236 const TypeOopPtr* etype = TypeOopPtr::make_from_klass(env()->Object_klass());
4237 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
4238
4239 // Because we create the scopedValue cache lazily we have to make the
4240 // type of the result BotPTR.
4241 bool xk = etype->klass_is_exact();
4242 const Type* objects_type = TypeAryPtr::make(TypePtr::BotPTR, arr0, objects_klass, xk, TypeAryPtr::Offset(0));
4243 return objects_type;
4244 }
4245
4246 Node* LibraryCallKit::scopedValueCache_helper() {
4247 Node* thread = _gvn.transform(new ThreadLocalNode());
4248 Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::scopedValueCache_offset()));
4249 // We cannot use immutable_memory() because we might flip onto a
4250 // different carrier thread, at which point we'll need to use that
4251 // carrier thread's cache.
4252 // return _gvn.transform(LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(),
4253 // TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered));
4254 return make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered);
4255 }
4256
4257 //------------------------inline_native_scopedValueCache------------------
4258 bool LibraryCallKit::inline_native_scopedValueCache() {
4259 Node* cache_obj_handle = scopedValueCache_helper();
4260 const Type* objects_type = scopedValueCache_type();
4261 set_result(access_load(cache_obj_handle, objects_type, T_OBJECT, IN_NATIVE));
4262
4398 }
4399 return kls;
4400 }
4401
4402 //--------------------(inline_native_Class_query helpers)---------------------
4403 // Use this for JVM_ACC_INTERFACE.
4404 // Fall through if (mods & mask) == bits, take the guard otherwise.
4405 Node* LibraryCallKit::generate_klass_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region,
4406 ByteSize offset, const Type* type, BasicType bt) {
4407 // Branch around if the given klass has the given modifier bit set.
4408 // Like generate_guard, adds a new path onto the region.
4409 Node* modp = off_heap_plus_addr(kls, in_bytes(offset));
4410 Node* mods = make_load(nullptr, modp, type, bt, MemNode::unordered);
4411 Node* mask = intcon(modifier_mask);
4412 Node* bits = intcon(modifier_bits);
4413 Node* mbit = _gvn.transform(new AndINode(mods, mask));
4414 Node* cmp = _gvn.transform(new CmpINode(mbit, bits));
4415 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
4416 return generate_fair_guard(bol, region);
4417 }
4418
4419 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
4420 return generate_klass_flags_guard(kls, JVM_ACC_INTERFACE, 0, region,
4421 InstanceKlass::access_flags_offset(), TypeInt::CHAR, T_CHAR);
4422 }
4423
4424 // Use this for testing if Klass is_hidden, has_finalizer, and is_cloneable_fast.
4425 Node* LibraryCallKit::generate_misc_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
4426 return generate_klass_flags_guard(kls, modifier_mask, modifier_bits, region,
4427 Klass::misc_flags_offset(), TypeInt::UBYTE, T_BOOLEAN);
4428 }
4429
4430 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) {
4431 return generate_misc_flags_guard(kls, KlassFlags::_misc_is_hidden_class, 0, region);
4432 }
4433
4434 //-------------------------inline_native_Class_query-------------------
4435 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
4436 const Type* return_type = TypeInt::BOOL;
4437 Node* prim_return_value = top(); // what happens if it's a primitive class?
4438 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
4524
4525
4526 case vmIntrinsics::_getSuperclass:
4527 // The rules here are somewhat unfortunate, but we can still do better
4528 // with random logic than with a JNI call.
4529 // Interfaces store null or Object as _super, but must report null.
4530 // Arrays store an intermediate super as _super, but must report Object.
4531 // Other types can report the actual _super.
4532 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
4533 if (generate_array_guard(kls, region) != nullptr) {
4534 // A guard was added. If the guard is taken, it was an array.
4535 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
4536 }
4537 // Check for interface after array since this checks AccessFlags offset into InstanceKlass.
4538 // In other words, we are accessing subtype-specific information, so we need to determine the subtype first.
4539 if (generate_interface_guard(kls, region) != nullptr) {
4540 // A guard was added. If the guard is taken, it was an interface.
4541 phi->add_req(null());
4542 }
4543 // If we fall through, it's a plain class. Get its _super.
4544 if (!stopped()) {
4545 p = basic_plus_adr(top(), kls, in_bytes(Klass::super_offset()));
4546 kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
4547 null_ctl = top();
4548 kls = null_check_oop(kls, &null_ctl);
4549 if (null_ctl != top()) {
4550 // If the guard is taken, Object.superClass is null (both klass and mirror).
4551 region->add_req(null_ctl);
4552 phi ->add_req(null());
4553 }
4554 if (!stopped()) {
4555 query_value = load_mirror_from_klass(kls);
4556 }
4557 }
4558 break;
4559
4560 default:
4561 fatal_unexpected_iid(id);
4562 break;
4563 }
4564
4565 // Fall-through is the normal case of a query to a real class.
4566 phi->init_req(1, query_value);
4567 region->init_req(1, control());
4568
4569 C->set_has_split_ifs(true); // Has chance for split-if optimization
4570 set_result(region, phi);
4571 return true;
4572 }
4573
4574
4575 //-------------------------inline_Class_cast-------------------
4576 bool LibraryCallKit::inline_Class_cast() {
4577 Node* mirror = argument(0); // Class
4578 Node* obj = argument(1);
4579 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
4580 if (mirror_con == nullptr) {
4581 return false; // dead path (mirror->is_top()).
4582 }
4583 if (obj == nullptr || obj->is_top()) {
4584 return false; // dead path
4585 }
4586 const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr();
4587
4588 // First, see if Class.cast() can be folded statically.
4589 // java_mirror_type() returns non-null for compile-time Class constants.
4590 ciType* tm = mirror_con->java_mirror_type();
4591 if (tm != nullptr && tm->is_klass() &&
4592 tp != nullptr) {
4593 if (!tp->is_loaded()) {
4594 // Don't use intrinsic when class is not loaded.
4595 return false;
4596 } else {
4597 const TypeKlassPtr* tklass = TypeKlassPtr::make(tm->as_klass(), Type::trust_interfaces);
4598 int static_res = C->static_subtype_check(tklass, tp->as_klass_type());
4599 if (static_res == Compile::SSC_always_true) {
4600 // isInstance() is true - fold the code.
4601 set_result(obj);
4602 return true;
4603 } else if (static_res == Compile::SSC_always_false) {
4604 // Don't use intrinsic, have to throw ClassCastException.
4605 // If the reference is null, the non-intrinsic bytecode will
4606 // be optimized appropriately.
4607 return false;
4608 }
4609 }
4610 }
4611
4612 // Bailout intrinsic and do normal inlining if exception path is frequent.
4613 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
4614 return false;
4615 }
4616
4617 // Generate dynamic checks.
4618 // Class.cast() is java implementation of _checkcast bytecode.
4619 // Do checkcast (Parse::do_checkcast()) optimizations here.
4620
4621 mirror = null_check(mirror);
4622 // If mirror is dead, only null-path is taken.
4623 if (stopped()) {
4624 return true;
4625 }
4626
4627 // Not-subtype or the mirror's klass ptr is nullptr (in case it is a primitive).
4628 enum { _bad_type_path = 1, _prim_path = 2, _npe_path = 3, PATH_LIMIT };
4629 RegionNode* region = new RegionNode(PATH_LIMIT);
4630 record_for_igvn(region);
4631
4632 // Now load the mirror's klass metaobject, and null-check it.
4633 // If kls is null, we have a primitive mirror and
4634 // nothing is an instance of a primitive type.
4635 Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path);
4636
4637 Node* res = top();
4638 Node* io = i_o();
4639 Node* mem = merged_memory();
4640 SafePointNode* new_cast_failure_map = nullptr;
4641
4642 if (!stopped()) {
4643
4644 Node* bad_type_ctrl = top();
4645 // Do checkcast optimizations.
4646 res = gen_checkcast(obj, kls, &bad_type_ctrl, &new_cast_failure_map);
4647 region->init_req(_bad_type_path, bad_type_ctrl);
4648 }
4649 if (region->in(_prim_path) != top() ||
4650 region->in(_bad_type_path) != top() ||
4651 region->in(_npe_path) != top()) {
4652 // Let Interpreter throw ClassCastException.
4653 PreserveJVMState pjvms(this);
4654 if (new_cast_failure_map != nullptr) {
4655 // The current map on the success path could have been modified. Use the dedicated failure path map.
4656 set_map(new_cast_failure_map);
4657 }
4658 set_control(_gvn.transform(region));
4659 // Set IO and memory because gen_checkcast may override them when buffering inline types
4660 set_i_o(io);
4661 set_all_memory(mem);
4662 uncommon_trap(Deoptimization::Reason_intrinsic,
4663 Deoptimization::Action_maybe_recompile);
4664 }
4665 if (!stopped()) {
4666 set_result(res);
4667 }
4668 return true;
4669 }
4670
4671
4672 //--------------------------inline_native_subtype_check------------------------
4673 // This intrinsic takes the JNI calls out of the heart of
4674 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
4675 bool LibraryCallKit::inline_native_subtype_check() {
4676 // Pull both arguments off the stack.
4677 Node* args[2]; // two java.lang.Class mirrors: superc, subc
4678 args[0] = argument(0);
4679 args[1] = argument(1);
4680 Node* klasses[2]; // corresponding Klasses: superk, subk
4681 klasses[0] = klasses[1] = top();
4682
4683 enum {
4684 // A full decision tree on {superc is prim, subc is prim}:
4685 _prim_0_path = 1, // {P,N} => false
4686 // {P,P} & superc!=subc => false
4687 _prim_same_path, // {P,P} & superc==subc => true
4688 _prim_1_path, // {N,P} => false
4689 _ref_subtype_path, // {N,N} & subtype check wins => true
4690 _both_ref_path, // {N,N} & subtype check loses => false
4691 PATH_LIMIT
4692 };
4693
4694 RegionNode* region = new RegionNode(PATH_LIMIT);
4695 RegionNode* prim_region = new RegionNode(2);
4696 Node* phi = new PhiNode(region, TypeInt::BOOL);
4697 record_for_igvn(region);
4698 record_for_igvn(prim_region);
4699
4700 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads
4701 const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL;
4702 int class_klass_offset = java_lang_Class::klass_offset();
4703
4704 // First null-check both mirrors and load each mirror's klass metaobject.
4705 int which_arg;
4706 for (which_arg = 0; which_arg <= 1; which_arg++) {
4707 Node* arg = args[which_arg];
4708 arg = null_check(arg);
4709 if (stopped()) break;
4710 args[which_arg] = arg;
4711
4712 Node* p = basic_plus_adr(arg, class_klass_offset);
4713 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type);
4714 klasses[which_arg] = _gvn.transform(kls);
4715 }
4716
4717 // Having loaded both klasses, test each for null.
4718 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
4719 for (which_arg = 0; which_arg <= 1; which_arg++) {
4720 Node* kls = klasses[which_arg];
4721 Node* null_ctl = top();
4722 kls = null_check_oop(kls, &null_ctl, never_see_null);
4723 if (which_arg == 0) {
4724 prim_region->init_req(1, null_ctl);
4725 } else {
4726 region->init_req(_prim_1_path, null_ctl);
4727 }
4728 if (stopped()) break;
4729 klasses[which_arg] = kls;
4730 }
4731
4732 if (!stopped()) {
4733 // now we have two reference types, in klasses[0..1]
4734 Node* subk = klasses[1]; // the argument to isAssignableFrom
4735 Node* superk = klasses[0]; // the receiver
4736 region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
4737 region->set_req(_ref_subtype_path, control());
4738 }
4739
4740 // If both operands are primitive (both klasses null), then
4741 // we must return true when they are identical primitives.
4742 // It is convenient to test this after the first null klass check.
4743 // This path is also used if superc is a value mirror.
4744 set_control(_gvn.transform(prim_region));
4745 if (!stopped()) {
4746 // Since superc is primitive, make a guard for the superc==subc case.
4747 Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
4748 Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
4749 generate_fair_guard(bol_eq, region);
4750 if (region->req() == PATH_LIMIT+1) {
4751 // A guard was added. If the added guard is taken, superc==subc.
4752 region->swap_edges(PATH_LIMIT, _prim_same_path);
4753 region->del_req(PATH_LIMIT);
4754 }
4755 region->set_req(_prim_0_path, control()); // Not equal after all.
4756 }
4757
4758 // these are the only paths that produce 'true':
4759 phi->set_req(_prim_same_path, intcon(1));
4760 phi->set_req(_ref_subtype_path, intcon(1));
4761
4762 // pull together the cases:
4763 assert(region->req() == PATH_LIMIT, "sane region");
4764 for (uint i = 1; i < region->req(); i++) {
4765 Node* ctl = region->in(i);
4766 if (ctl == nullptr || ctl == top()) {
4767 region->set_req(i, top());
4768 phi ->set_req(i, top());
4769 } else if (phi->in(i) == nullptr) {
4770 phi->set_req(i, intcon(0)); // all other paths produce 'false'
4771 }
4772 }
4773
4774 set_control(_gvn.transform(region));
4775 set_result(_gvn.transform(phi));
4776 return true;
4777 }
4778
4779 //---------------------generate_array_guard_common------------------------
4780 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, ArrayKind kind, Node** obj) {
4781
4782 if (stopped()) {
4783 return nullptr;
4784 }
4785
4786 // Like generate_guard, adds a new path onto the region.
4787 jint layout_con = 0;
4788 Node* layout_val = get_layout_helper(kls, layout_con);
4789 if (layout_val == nullptr) {
4790 bool query = 0;
4791 switch(kind) {
4792 case RefArray: query = Klass::layout_helper_is_refArray(layout_con); break;
4793 case NonRefArray: query = !Klass::layout_helper_is_refArray(layout_con); break;
4794 case TypeArray: query = Klass::layout_helper_is_typeArray(layout_con); break;
4795 case AnyArray: query = Klass::layout_helper_is_array(layout_con); break;
4796 case NonArray: query = !Klass::layout_helper_is_array(layout_con); break;
4797 default:
4798 ShouldNotReachHere();
4799 }
4800 if (!query) {
4801 return nullptr; // never a branch
4802 } else { // always a branch
4803 Node* always_branch = control();
4804 if (region != nullptr)
4805 region->add_req(always_branch);
4806 set_control(top());
4807 return always_branch;
4808 }
4809 }
4810 unsigned int value = 0;
4811 BoolTest::mask btest = BoolTest::illegal;
4812 switch(kind) {
4813 case RefArray:
4814 case NonRefArray: {
4815 value = Klass::_lh_array_tag_ref_value;
4816 layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift)));
4817 btest = (kind == RefArray) ? BoolTest::eq : BoolTest::ne;
4818 break;
4819 }
4820 case TypeArray: {
4821 value = Klass::_lh_array_tag_type_value;
4822 layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift)));
4823 btest = BoolTest::eq;
4824 break;
4825 }
4826 case AnyArray: value = Klass::_lh_neutral_value; btest = BoolTest::lt; break;
4827 case NonArray: value = Klass::_lh_neutral_value; btest = BoolTest::gt; break;
4828 default:
4829 ShouldNotReachHere();
4830 }
4831 // Now test the correct condition.
4832 jint nval = (jint)value;
4833 Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval)));
4834 Node* bol = _gvn.transform(new BoolNode(cmp, btest));
4835 Node* ctrl = generate_fair_guard(bol, region);
4836 Node* is_array_ctrl = kind == NonArray ? control() : ctrl;
4837 if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top()) {
4838 // Keep track of the fact that 'obj' is an array to prevent
4839 // array specific accesses from floating above the guard.
4840 *obj = _gvn.transform(new CheckCastPPNode(is_array_ctrl, *obj, TypeAryPtr::BOTTOM));
4841 }
4842 return ctrl;
4843 }
4844
4845 // public static native Object[] ValueClass::newNullRestrictedAtomicArray(Class<?> componentType, int length, Object initVal);
4846 // public static native Object[] ValueClass::newNullRestrictedNonAtomicArray(Class<?> componentType, int length, Object initVal);
4847 // public static native Object[] ValueClass::newNullableAtomicArray(Class<?> componentType, int length);
4848 bool LibraryCallKit::inline_newArray(bool null_free, bool atomic) {
4849 assert(null_free || atomic, "nullable implies atomic");
4850 Node* componentType = argument(0);
4851 Node* length = argument(1);
4852 Node* init_val = null_free ? argument(2) : nullptr;
4853
4854 const TypeInstPtr* tp = _gvn.type(componentType)->isa_instptr();
4855 if (tp != nullptr) {
4856 ciInstanceKlass* ik = tp->instance_klass();
4857 if (ik == C->env()->Class_klass()) {
4858 ciType* t = tp->java_mirror_type();
4859 if (t != nullptr && t->is_inlinetype()) {
4860
4861 ciArrayKlass* array_klass = ciArrayKlass::make(t, null_free, atomic, true);
4862 assert(array_klass->is_elem_null_free() == null_free, "inconsistency");
4863
4864 // TODO 8350865 ZGC needs card marks on initializing oop stores
4865 if ((UseZGC || UseShenandoahGC) && null_free && !array_klass->is_flat_array_klass()) {
4866 return false;
4867 }
4868
4869 if (array_klass->is_loaded() && array_klass->element_klass()->as_inline_klass()->is_initialized()) {
4870 const TypeAryKlassPtr* array_klass_type = TypeAryKlassPtr::make(array_klass, Type::trust_interfaces);
4871 if (null_free) {
4872 if (init_val->is_InlineType()) {
4873 if (array_klass_type->is_flat() && init_val->as_InlineType()->is_all_zero(&gvn(), /* flat */ true)) {
4874 // Zeroing is enough because the init value is the all-zero value
4875 init_val = nullptr;
4876 } else {
4877 init_val = init_val->as_InlineType()->buffer(this);
4878 }
4879 }
4880 if (init_val != nullptr) {
4881 #ifdef ASSERT
4882 init_val = null_check(init_val);
4883 Node* wrong_type_ctl = gen_subtype_check(init_val, makecon(TypeKlassPtr::make(array_klass->element_klass())));
4884 {
4885 PreserveJVMState pjvms(this);
4886 set_control(wrong_type_ctl);
4887 halt(control(), frameptr(), "incompatible type for initVal in newArray");
4888 stop_and_kill_map();
4889 }
4890 #endif
4891 init_val = _gvn.transform(new CheckCastPPNode(control(), init_val, TypeOopPtr::make_from_klass(array_klass->element_klass()), ConstraintCastNode::DependencyType::NonFloatingNarrowing));
4892 }
4893 }
4894 Node* obj = new_array(makecon(array_klass_type), length, 0, nullptr, false, init_val);
4895 const TypeAryPtr* arytype = gvn().type(obj)->is_aryptr();
4896 assert(arytype->is_null_free() == null_free, "inconsistency");
4897 assert(arytype->is_not_null_free() == !null_free, "inconsistency");
4898 set_result(obj);
4899 return true;
4900 }
4901 }
4902 }
4903 }
4904 return false;
4905 }
4906
4907 // public static native boolean ValueClass::isFlatArray(Object array);
4908 // public static native boolean ValueClass::isNullRestrictedArray(Object array);
4909 // public static native boolean ValueClass::isAtomicArray(Object array);
4910 bool LibraryCallKit::inline_getArrayProperties(ArrayPropertiesCheck check) {
4911 Node* array = argument(0);
4912
4913 Node* bol;
4914 switch(check) {
4915 case IsFlat:
4916 bol = flat_array_test(load_object_klass(array));
4917 break;
4918 case IsNullRestricted:
4919 bol = null_free_array_test(array);
4920 break;
4921 case IsAtomic: {
4922 // See conditions in JVM_IsAtomicArray
4923 // 1. If not flat, then atomic, or else...
4924 RegionNode* atomic_region = new RegionNode(1);
4925 RegionNode* non_atomic_region = new RegionNode(1);
4926 Node* array_klass = load_object_klass(array);
4927 Node* is_flat_bol = flat_array_test(array_klass);
4928 IfNode* iff_is_flat = create_and_xform_if(control(), is_flat_bol, PROB_FAIR, COUNT_UNKNOWN);
4929 atomic_region->add_req(_gvn.transform(new IfFalseNode(iff_is_flat)));
4930 set_control(_gvn.transform(new IfTrueNode(iff_is_flat)));
4931
4932 // 2. ...if the layout is atomic, then atomic, or else...
4933 Node* layout_kind = atomic_layout_array_test_and_get_layout_kind(array, atomic_region);
4934
4935 // 3. ...if the element type is naturally atomic and null-free OR empty and nullable, then atomic, or else...
4936 int element_klass_offset = in_bytes(ObjArrayKlass::element_klass_offset());
4937 Node* array_element_klass_addr = off_heap_plus_addr(array_klass, element_klass_offset);
4938 Node* array_element_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), array_element_klass_addr, _gvn.type(array_klass)->is_klassptr()));
4939 int klass_flags_offset = in_bytes(InstanceKlass::misc_flags_offset() + InstanceKlassFlags::flags_offset());
4940 Node* array_element_klass_flags_addr = off_heap_plus_addr(array_element_klass, klass_flags_offset);
4941 Node* array_element_klass_flags = make_load(control(), array_element_klass_flags_addr, TypeInt::INT, T_INT, MemNode::unordered);
4942
4943 // Here, layout can only be non-atomic, otherwise atomic_layout_array_test_and_get_layout_kind already decides the array to be atomic.
4944 Node* is_null_free_cmp = _gvn.transform(new CmpINode(layout_kind, intcon(static_cast<jint>(LayoutKind::NULL_FREE_NON_ATOMIC_FLAT))));
4945 Node* is_null_free_bol = _gvn.transform(new BoolNode(is_null_free_cmp, BoolTest::eq));
4946 IfNode* iff_is_null_free_bol = create_and_xform_if(control(), is_null_free_bol, PROB_FAIR, COUNT_UNKNOWN);
4947 Node* is_null_free_ctl = _gvn.transform(new IfTrueNode(iff_is_null_free_bol));
4948 Node* is_nullable_ctl = _gvn.transform(new IfFalseNode(iff_is_null_free_bol));
4949
4950 Node* is_naturally_atomic_flag = _gvn.transform(new AndINode(array_element_klass_flags, intcon(InstanceKlassFlags::_misc_is_naturally_atomic)));
4951 Node* is_naturally_atomic_cmp = _gvn.transform(new CmpINode(is_naturally_atomic_flag, intcon(0)));
4952 Node* is_naturally_atomic_bol = _gvn.transform(new BoolNode(is_naturally_atomic_cmp, BoolTest::ne));
4953 IfNode* iff_is_naturally_atomic = create_and_xform_if(is_null_free_ctl, is_naturally_atomic_bol, PROB_FAIR, COUNT_UNKNOWN);
4954 Node* is_naturally_atomic_ctl = _gvn.transform(new IfTrueNode(iff_is_naturally_atomic));
4955 Node* is_not_naturally_atomic_ctl = _gvn.transform(new IfFalseNode(iff_is_naturally_atomic));
4956 atomic_region->add_req(is_naturally_atomic_ctl);
4957 non_atomic_region->add_req(is_not_naturally_atomic_ctl);
4958
4959 Node* is_empty_inline_type_flag = _gvn.transform(new AndINode(array_element_klass_flags, intcon(InstanceKlassFlags::_misc_is_empty_inline_type)));
4960 Node* is_empty_inline_type_cmp = _gvn.transform(new CmpINode(is_empty_inline_type_flag, intcon(0)));
4961 Node* is_empty_inline_type_bol = _gvn.transform(new BoolNode(is_empty_inline_type_cmp, BoolTest::ne));
4962 IfNode* iff_is_empty_inline_type = create_and_xform_if(is_nullable_ctl, is_empty_inline_type_bol, PROB_FAIR, COUNT_UNKNOWN);
4963 Node* is_empty_inline_type_ctl = _gvn.transform(new IfTrueNode(iff_is_empty_inline_type));
4964 Node* is_nonempty_inline_type_ctl = _gvn.transform(new IfFalseNode(iff_is_empty_inline_type));
4965 atomic_region->add_req(is_empty_inline_type_ctl);
4966 non_atomic_region->add_req(is_nonempty_inline_type_ctl);
4967
4968 // ...non-atomic, but we tried everything.
4969 RegionNode* decision = new RegionNode(3);
4970 decision->set_req(1, _gvn.transform(atomic_region));
4971 decision->set_req(2, _gvn.transform(non_atomic_region));
4972 PhiNode* result = PhiNode::make(decision, intcon(1), TypeInt::BOOL);
4973 result->set_req(2, intcon(0));
4974 set_control(_gvn.transform(decision));
4975 set_result(_gvn.transform(result));
4976 return true;
4977 }
4978 default:
4979 ShouldNotReachHere();
4980 }
4981
4982 Node* res = gvn().transform(new CMoveINode(bol, intcon(0), intcon(1), TypeInt::BOOL));
4983 set_result(res);
4984 return true;
4985 }
4986
4987 // Load the default refined array klass from an ObjArrayKlass. This relies on the first entry in the
4988 // '_next_refined_array_klass' linked list being the default (see ObjArrayKlass::klass_with_properties).
4989 Node* LibraryCallKit::load_default_refined_array_klass(Node* klass_node, bool type_array_guard) {
4990 RegionNode* region = new RegionNode(2);
4991 Node* phi = new PhiNode(region, TypeInstKlassPtr::OBJECT_OR_NULL);
4992
4993 if (type_array_guard) {
4994 generate_typeArray_guard(klass_node, region);
4995 if (region->req() == 3) {
4996 phi->add_req(klass_node);
4997 }
4998 }
4999 Node* adr_refined_klass = basic_plus_adr(top(), klass_node, in_bytes(ObjArrayKlass::next_refined_array_klass_offset()));
5000 Node* refined_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), adr_refined_klass, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
5001
5002 // Can be null if not initialized yet, just deopt
5003 Node* null_ctl = top();
5004 refined_klass = null_check_oop(refined_klass, &null_ctl, /* never_see_null= */ true);
5005
5006 region->init_req(1, control());
5007 phi->init_req(1, refined_klass);
5008
5009 set_control(_gvn.transform(region));
5010 return _gvn.transform(phi);
5011 }
5012
5013 // Load the non-refined array klass from an ObjArrayKlass.
5014 Node* LibraryCallKit::load_non_refined_array_klass(Node* klass_node) {
5015 const TypeAryKlassPtr* ary_klass_ptr = _gvn.type(klass_node)->isa_aryklassptr();
5016 if (ary_klass_ptr != nullptr && ary_klass_ptr->klass_is_exact()) {
5017 return _gvn.makecon(ary_klass_ptr->cast_to_refined_array_klass_ptr(false));
5018 }
5019
5020 RegionNode* region = new RegionNode(2);
5021 Node* phi = new PhiNode(region, TypeInstKlassPtr::OBJECT);
5022
5023 generate_typeArray_guard(klass_node, region);
5024 if (region->req() == 3) {
5025 phi->add_req(klass_node);
5026 }
5027 Node* super_adr = basic_plus_adr(top(), klass_node, in_bytes(Klass::super_offset()));
5028 Node* super_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), super_adr, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT));
5029
5030 region->init_req(1, control());
5031 phi->init_req(1, super_klass);
5032
5033 set_control(_gvn.transform(region));
5034 return _gvn.transform(phi);
5035 }
5036
5037 //-----------------------inline_native_newArray--------------------------
5038 // private static native Object java.lang.reflect.Array.newArray(Class<?> componentType, int length);
5039 // private native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size);
5040 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) {
5041 Node* mirror;
5042 Node* count_val;
5043 if (uninitialized) {
5044 null_check_receiver();
5045 mirror = argument(1);
5046 count_val = argument(2);
5047 } else {
5048 mirror = argument(0);
5049 count_val = argument(1);
5050 }
5051
5052 mirror = null_check(mirror);
5053 // If mirror or obj is dead, only null-path is taken.
5054 if (stopped()) return true;
5055
5056 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT };
5057 RegionNode* result_reg = new RegionNode(PATH_LIMIT);
5058 PhiNode* result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
5076 CallJavaNode* slow_call = nullptr;
5077 if (uninitialized) {
5078 // Generate optimized virtual call (holder class 'Unsafe' is final)
5079 slow_call = generate_method_call(vmIntrinsics::_allocateUninitializedArray, false, false, true);
5080 } else {
5081 slow_call = generate_method_call_static(vmIntrinsics::_newArray, true);
5082 }
5083 Node* slow_result = set_results_for_java_call(slow_call);
5084 // this->control() comes from set_results_for_java_call
5085 result_reg->set_req(_slow_path, control());
5086 result_val->set_req(_slow_path, slow_result);
5087 result_io ->set_req(_slow_path, i_o());
5088 result_mem->set_req(_slow_path, reset_memory());
5089 }
5090
5091 set_control(normal_ctl);
5092 if (!stopped()) {
5093 // Normal case: The array type has been cached in the java.lang.Class.
5094 // The following call works fine even if the array type is polymorphic.
5095 // It could be a dynamic mix of int[], boolean[], Object[], etc.
5096
5097 klass_node = load_default_refined_array_klass(klass_node);
5098
5099 Node* obj = new_array(klass_node, count_val, 0); // no arguments to push
5100 result_reg->init_req(_normal_path, control());
5101 result_val->init_req(_normal_path, obj);
5102 result_io ->init_req(_normal_path, i_o());
5103 result_mem->init_req(_normal_path, reset_memory());
5104
5105 if (uninitialized) {
5106 // Mark the allocation so that zeroing is skipped
5107 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj);
5108 alloc->maybe_set_complete(&_gvn);
5109 }
5110 }
5111
5112 // Return the combined state.
5113 set_i_o( _gvn.transform(result_io) );
5114 set_all_memory( _gvn.transform(result_mem));
5115
5116 C->set_has_split_ifs(true); // Has chance for split-if optimization
5117 set_result(result_reg, result_val);
5118 return true;
5159 Node* original = argument(0);
5160 Node* start = is_copyOfRange? argument(1): intcon(0);
5161 Node* end = is_copyOfRange? argument(2): argument(1);
5162 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2);
5163
5164 Node* newcopy = nullptr;
5165
5166 // Set the original stack and the reexecute bit for the interpreter to reexecute
5167 // the bytecode that invokes Arrays.copyOf if deoptimization happens.
5168 { PreserveReexecuteState preexecs(this);
5169 jvms()->set_should_reexecute(true);
5170
5171 array_type_mirror = null_check(array_type_mirror);
5172 original = null_check(original);
5173
5174 // Check if a null path was taken unconditionally.
5175 if (stopped()) return true;
5176
5177 Node* orig_length = load_array_length(original);
5178
5179 RegionNode* bailout = new RegionNode(2);
5180 record_for_igvn(bailout);
5181
5182 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, bailout, 1);
5183 if (stopped()) {
5184 // Arrays.copyOf() uses a generic Class parameter which is erased to the raw type Class. This also allows
5185 // passing in primitive class mirrors like int.class which do not have corresponding Klass* pointers.
5186 // In these cases, klass_node will be top. Emit a trap to throw in the interpreter in this case.
5187 bail_out_from_array_copyOf(bailout);
5188 return true;
5189 }
5190
5191 klass_node = null_check(klass_node);
5192
5193 const TypeAryPtr* src_t = _gvn.type(original)->is_aryptr();
5194 const TypeKlassPtr* dest_klass_t = _gvn.type(klass_node)->is_klassptr()->is_klassptr();
5195
5196 Node* success_proj;
5197 if (should_bail_out_on_non_ref_arrays(src_t, dest_klass_t)) {
5198 success_proj = generate_non_refArray_guard(klass_node, bailout);
5199 } else {
5200 success_proj = generate_typeArray_guard(klass_node, bailout);
5201 }
5202
5203 Node* refined_klass_node = load_default_refined_array_klass(klass_node, /* type_array_guard= */ false);
5204
5205 if (success_proj != nullptr) {
5206 // Improve the klass node's type from the new optimistic assumption:
5207 ciKlass* ak = ciArrayKlass::make(env()->Object_klass());
5208 bool not_flat = !UseArrayFlattening;
5209 bool not_null_free = !Arguments::is_valhalla_enabled();
5210 const Type* akls = TypeAryKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0), Type::trust_interfaces, not_flat, not_null_free, false, false, not_flat, true);
5211 Node* cast = new CastPPNode(control(), refined_klass_node, akls);
5212 refined_klass_node = _gvn.transform(cast);
5213 }
5214
5215 // Bail out if either start or end is negative.
5216 generate_negative_guard(start, bailout, &start);
5217 generate_negative_guard(end, bailout, &end);
5218
5219 Node* length = end;
5220 if (_gvn.type(start) != TypeInt::ZERO) {
5221 length = _gvn.transform(new SubINode(end, start));
5222 }
5223
5224 // Bail out if length is negative (i.e., if start > end).
5225 // Without this the new_array would throw
5226 // NegativeArraySizeException but IllegalArgumentException is what
5227 // should be thrown
5228 generate_negative_guard(length, bailout, &length);
5229
5230 // Handle inline type arrays
5231 // TODO 8251971 This is too strong
5232 generate_fair_guard(flat_array_test(load_object_klass(original)), bailout);
5233 generate_fair_guard(flat_array_test(refined_klass_node), bailout);
5234 generate_fair_guard(null_free_array_test(original), bailout);
5235
5236 // Bail out if start is larger than the original length
5237 Node* orig_tail = _gvn.transform(new SubINode(orig_length, start));
5238 generate_negative_guard(orig_tail, bailout, &orig_tail);
5239
5240 if (bailout->req() > 1) {
5241 bail_out_from_array_copyOf(bailout);
5242 }
5243
5244 if (!stopped()) {
5245 // How many elements will we copy from the original?
5246 // The answer is MinI(orig_tail, length).
5247 Node* moved = _gvn.transform(new MinINode(orig_tail, length));
5248
5249 // Generate a direct call to the right arraycopy function(s).
5250 // We know the copy is disjoint but we might not know if the
5251 // oop stores need checking.
5252 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class).
5253 // This will fail a store-check if x contains any non-nulls.
5254
5255 // ArrayCopyNode:Ideal may transform the ArrayCopyNode to
5256 // loads/stores but it is legal only if we're sure the
5257 // Arrays.copyOf would succeed. So we need all input arguments
5258 // to the copyOf to be validated, including that the copy to the
5259 // new array won't trigger an ArrayStoreException. That subtype
5260 // check can be optimized if we know something on the type of
5261 // the input array from type speculation.
5272 }
5273 }
5274
5275 bool validated = false;
5276 // Reason_class_check rather than Reason_intrinsic because we
5277 // want to intrinsify even if this traps.
5278 if (!too_many_traps(Deoptimization::Reason_class_check)) {
5279 Node* not_subtype_ctrl = gen_subtype_check(original, klass_node);
5280
5281 if (not_subtype_ctrl != top()) {
5282 PreserveJVMState pjvms(this);
5283 set_control(not_subtype_ctrl);
5284 uncommon_trap(Deoptimization::Reason_class_check,
5285 Deoptimization::Action_make_not_entrant);
5286 assert(stopped(), "Should be stopped");
5287 }
5288 validated = true;
5289 }
5290
5291 if (!stopped()) {
5292 newcopy = new_array(refined_klass_node, length, 0); // no arguments to push
5293
5294 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, true,
5295 load_object_klass(original), klass_node);
5296 if (!is_copyOfRange) {
5297 ac->set_copyof(validated);
5298 } else {
5299 ac->set_copyofrange(validated);
5300 }
5301 Node* n = _gvn.transform(ac);
5302 if (n == ac) {
5303 ac->connect_outputs(this);
5304 } else {
5305 assert(validated, "shouldn't transform if all arguments not validated");
5306 set_all_memory(n);
5307 }
5308 }
5309 }
5310 } // original reexecute is set back here
5311
5312 C->set_has_split_ifs(true); // Has chance for split-if optimization
5313 if (!stopped()) {
5314 set_result(newcopy);
5315 }
5316 return true;
5317 }
5318
5319 void LibraryCallKit::bail_out_from_array_copyOf(RegionNode* bailout_region) {
5320 PreserveJVMState pjvms(this);
5321 set_control(_gvn.transform(bailout_region));
5322 uncommon_trap(Deoptimization::Reason_intrinsic,
5323 Deoptimization::Action_maybe_recompile);
5324 }
5325
5326 bool LibraryCallKit::should_bail_out_on_non_ref_arrays(const TypeAryPtr* src_type, const TypeKlassPtr* dest_klass_type) {
5327 const TypeAryKlassPtr* dest_ary_klass_type = dest_klass_type->isa_aryklassptr();
5328 if (dest_ary_klass_type == nullptr) {
5329 // Dest klass is not known to be an array class. There are multiple cases:
5330 // - Primitive class mirror: We already bailed out before.
5331 // - Instance class mirror: We should bail out.
5332 // - java.lang.Object (possible due to type erasure): Could be anything including primitive or instance class mirror
5333 // or also flat arrays. Bail out.
5334 return true;
5335 }
5336
5337 if (UseArrayFlattening) {
5338 // The remaining checks revolve around array flatness. Without array flatness, we don't need the stronger non-ref
5339 // runtime check excluding flat arrays.
5340 return false;
5341 }
5342
5343 // We now know that src and dest are proper array pointers.
5344 const bool src_maybe_flat = !src_type->is_not_flat();
5345 const bool dest_maybe_flat = !dest_ary_klass_type->is_not_flat();
5346
5347 // We could have abstract flat value class arrays whose layout we don't know. Bail out.
5348 const bool can_src_be_abstract_flat_value_class_array = src_maybe_flat && !src_type->elem()->is_inlinetypeptr();
5349 const bool can_dest_be_abstract_flat_value_class_array = dest_maybe_flat &&
5350 !dest_ary_klass_type->elem()->is_instklassptr()->instance_klass()->is_inlinetype();
5351 if (can_src_be_abstract_flat_value_class_array || can_dest_be_abstract_flat_value_class_array) {
5352 return true;
5353 }
5354
5355 // Value class array may have object field that would require a write barrier. Conservatively bail out.
5356 // TODO 8251971: Optimize for the case when flat src/dst are later found to not contain
5357 // oops (i.e., move this check to the macro expansion phase).
5358 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
5359 if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, false, false, BarrierSetC2::Parsing)) {
5360 // No barriers required.
5361 return false;
5362 }
5363
5364 const bool can_src_be_flat_with_oops = src_maybe_flat && src_type->elem()->inline_klass()->contains_oops();
5365 const bool can_dest_be_flat_with_oops = dest_maybe_flat && dest_ary_klass_type->elem()->is_instklassptr()->instance_klass()->as_inline_klass()->contains_oops();
5366 if (can_src_be_flat_with_oops || can_dest_be_flat_with_oops) {
5367 return true;
5368 }
5369
5370 // Can handle remaining flat arrays.
5371 return false;
5372 }
5373
5374 //----------------------generate_virtual_guard---------------------------
5375 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call.
5376 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,
5377 RegionNode* slow_region) {
5378 ciMethod* method = callee();
5379 int vtable_index = method->vtable_index();
5380 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
5381 "bad index %d", vtable_index);
5382 // Get the Method* out of the appropriate vtable entry.
5383 int entry_offset = in_bytes(Klass::vtable_start_offset()) +
5384 vtable_index*vtableEntry::size_in_bytes() +
5385 in_bytes(vtableEntry::method_offset());
5386 Node* entry_addr = off_heap_plus_addr(obj_klass, entry_offset);
5387 Node* target_call = make_load(nullptr, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered);
5388
5389 // Compare the target method with the expected method (e.g., Object.hashCode).
5390 const TypePtr* native_call_addr = TypeMetadataPtr::make(method);
5391
5392 Node* native_call = makecon(native_call_addr);
5398
5399 //-----------------------generate_method_call----------------------------
5400 // Use generate_method_call to make a slow-call to the real
5401 // method if the fast path fails. An alternative would be to
5402 // use a stub like OptoRuntime::slow_arraycopy_Java.
5403 // This only works for expanding the current library call,
5404 // not another intrinsic. (E.g., don't use this for making an
5405 // arraycopy call inside of the copyOf intrinsic.)
5406 CallJavaNode*
5407 LibraryCallKit::generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null) {
5408 // When compiling the intrinsic method itself, do not use this technique.
5409 guarantee(callee() != C->method(), "cannot make slow-call to self");
5410
5411 ciMethod* method = callee();
5412 // ensure the JVMS we have will be correct for this call
5413 guarantee(method_id == method->intrinsic_id(), "must match");
5414
5415 const TypeFunc* tf = TypeFunc::make(method);
5416 if (res_not_null) {
5417 assert(tf->return_type() == T_OBJECT, "");
5418 const TypeTuple* range = tf->range_cc();
5419 const Type** fields = TypeTuple::fields(range->cnt());
5420 fields[TypeFunc::Parms] = range->field_at(TypeFunc::Parms)->filter_speculative(TypePtr::NOTNULL);
5421 const TypeTuple* new_range = TypeTuple::make(range->cnt(), fields);
5422 tf = TypeFunc::make(tf->domain_cc(), new_range);
5423 }
5424 CallJavaNode* slow_call;
5425 if (is_static) {
5426 assert(!is_virtual, "");
5427 slow_call = new CallStaticJavaNode(C, tf,
5428 SharedRuntime::get_resolve_static_call_stub(), method);
5429 } else if (is_virtual) {
5430 assert(!gvn().type(argument(0))->maybe_null(), "should not be null");
5431 int vtable_index = Method::invalid_vtable_index;
5432 if (UseInlineCaches) {
5433 // Suppress the vtable call
5434 } else {
5435 // hashCode and clone are not a miranda methods,
5436 // so the vtable index is fixed.
5437 // No need to use the linkResolver to get it.
5438 vtable_index = method->vtable_index();
5439 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
5440 "bad index %d", vtable_index);
5441 }
5442 slow_call = new CallDynamicJavaNode(tf,
5459 set_edges_for_java_call(slow_call);
5460 return slow_call;
5461 }
5462
5463
5464 /**
5465 * Build special case code for calls to hashCode on an object. This call may
5466 * be virtual (invokevirtual) or bound (invokespecial). For each case we generate
5467 * slightly different code.
5468 */
5469 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
5470 assert(is_static == callee()->is_static(), "correct intrinsic selection");
5471 assert(!(is_virtual && is_static), "either virtual, special, or static");
5472
5473 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT };
5474
5475 RegionNode* result_reg = new RegionNode(PATH_LIMIT);
5476 PhiNode* result_val = new PhiNode(result_reg, TypeInt::INT);
5477 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO);
5478 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
5479 Node* obj = argument(0);
5480
5481 // Don't intrinsify hashcode on inline types for now.
5482 // The "is locked" runtime check also subsumes the inline type check (as inline types cannot be locked) and goes to the slow path.
5483 if (gvn().type(obj)->is_inlinetypeptr()) {
5484 return false;
5485 }
5486
5487 if (!is_static) {
5488 // Check for hashing null object
5489 obj = null_check_receiver();
5490 if (stopped()) return true; // unconditionally null
5491 result_reg->init_req(_null_path, top());
5492 result_val->init_req(_null_path, top());
5493 } else {
5494 // Do a null check, and return zero if null.
5495 // System.identityHashCode(null) == 0
5496 Node* null_ctl = top();
5497 obj = null_check_oop(obj, &null_ctl);
5498 result_reg->init_req(_null_path, null_ctl);
5499 result_val->init_req(_null_path, _gvn.intcon(0));
5500 }
5501
5502 // Unconditionally null? Then return right away.
5503 if (stopped()) {
5504 set_control( result_reg->in(_null_path));
5505 if (!stopped())
5506 set_result(result_val->in(_null_path));
5507 return true;
5508 }
5509
5510 // We only go to the fast case code if we pass a number of guards. The
5511 // paths which do not pass are accumulated in the slow_region.
5512 RegionNode* slow_region = new RegionNode(1);
5513 record_for_igvn(slow_region);
5514
5515 // If this is a virtual call, we generate a funny guard. We pull out
5516 // the vtable entry corresponding to hashCode() from the target object.
5517 // If the target method which we are calling happens to be the native
5518 // Object hashCode() method, we pass the guard. We do not need this
5519 // guard for non-virtual calls -- the caller is known to be the native
5520 // Object hashCode().
5521 if (is_virtual) {
5522 // After null check, get the object's klass.
5523 Node* obj_klass = load_object_klass(obj);
5524 generate_virtual_guard(obj_klass, slow_region);
5525 }
5526
5527 // Get the header out of the object, use LoadMarkNode when available
5528 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
5529 // The control of the load must be null. Otherwise, the load can move before
5530 // the null check after castPP removal.
5531 Node* no_ctrl = nullptr;
5532 Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
5533
5534 if (!UseObjectMonitorTable) {
5535 // Test the header to see if it is safe to read w.r.t. locking.
5536 // We cannot use the inline type mask as this may check bits that are overridden
5537 // by an object monitor's pointer when inflating locking.
5538 Node *lock_mask = _gvn.MakeConX(markWord::lock_mask_in_place);
5539 Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask));
5540 Node *monitor_val = _gvn.MakeConX(markWord::monitor_value);
5541 Node *chk_monitor = _gvn.transform(new CmpXNode(lmasked_header, monitor_val));
5542 Node *test_monitor = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq));
5543
5544 generate_slow_guard(test_monitor, slow_region);
5545 }
5546
5547 // Get the hash value and check to see that it has been properly assigned.
5548 // We depend on hash_mask being at most 32 bits and avoid the use of
5549 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit
5550 // vm: see markWord.hpp.
5551 Node *hash_mask = _gvn.intcon(markWord::hash_mask);
5552 Node *hash_shift = _gvn.intcon(markWord::hash_shift);
5553 Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift));
5554 // This hack lets the hash bits live anywhere in the mark object now, as long
5555 // as the shift drops the relevant bits into the low 32 bits. Note that
5556 // Java spec says that HashCode is an int so there's no point in capturing
5557 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
5585 // this->control() comes from set_results_for_java_call
5586 result_reg->init_req(_slow_path, control());
5587 result_val->init_req(_slow_path, slow_result);
5588 result_io ->set_req(_slow_path, i_o());
5589 result_mem ->set_req(_slow_path, reset_memory());
5590 }
5591
5592 // Return the combined state.
5593 set_i_o( _gvn.transform(result_io) );
5594 set_all_memory( _gvn.transform(result_mem));
5595
5596 set_result(result_reg, result_val);
5597 return true;
5598 }
5599
5600 //---------------------------inline_native_getClass----------------------------
5601 // public final native Class<?> java.lang.Object.getClass();
5602 //
5603 // Build special case code for calls to getClass on an object.
5604 bool LibraryCallKit::inline_native_getClass() {
5605 Node* obj = argument(0);
5606 if (obj->is_InlineType()) {
5607 const Type* t = _gvn.type(obj);
5608 if (t->maybe_null()) {
5609 null_check(obj);
5610 }
5611 set_result(makecon(TypeInstPtr::make(t->inline_klass()->java_mirror())));
5612 return true;
5613 }
5614 obj = null_check_receiver();
5615 if (stopped()) return true;
5616 set_result(load_mirror_from_klass(load_object_klass(obj)));
5617 return true;
5618 }
5619
5620 //-----------------inline_native_Reflection_getCallerClass---------------------
5621 // public static native Class<?> sun.reflect.Reflection.getCallerClass();
5622 //
5623 // In the presence of deep enough inlining, getCallerClass() becomes a no-op.
5624 //
5625 // NOTE: This code must perform the same logic as JVM_GetCallerClass
5626 // in that it must skip particular security frames and checks for
5627 // caller sensitive methods.
5628 bool LibraryCallKit::inline_native_Reflection_getCallerClass() {
5629 #ifndef PRODUCT
5630 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
5631 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass");
5632 }
5633 #endif
5634
6009
6010 //------------------------inline_native_clone----------------------------
6011 // protected native Object java.lang.Object.clone();
6012 //
6013 // Here are the simple edge cases:
6014 // null receiver => normal trap
6015 // virtual and clone was overridden => slow path to out-of-line clone
6016 // not cloneable or finalizer => slow path to out-of-line Object.clone
6017 //
6018 // The general case has two steps, allocation and copying.
6019 // Allocation has two cases, and uses GraphKit::new_instance or new_array.
6020 //
6021 // Copying also has two cases, oop arrays and everything else.
6022 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy).
6023 // Everything else uses the tight inline loop supplied by CopyArrayNode.
6024 //
6025 // These steps fold up nicely if and when the cloned object's klass
6026 // can be sharply typed as an object array, a type array, or an instance.
6027 //
6028 bool LibraryCallKit::inline_native_clone(bool is_virtual) {
6029 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
6030 return false;
6031 }
6032
6033 PhiNode* result_val;
6034
6035 // Set the reexecute bit for the interpreter to reexecute
6036 // the bytecode that invokes Object.clone if deoptimization happens.
6037 { PreserveReexecuteState preexecs(this);
6038 jvms()->set_should_reexecute(true);
6039
6040 Node* obj = argument(0);
6041 obj = null_check_receiver();
6042 if (stopped()) return true;
6043
6044 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
6045 if (obj_type->is_inlinetypeptr()) {
6046 // If the object to clone is an inline type, we can simply return it (i.e. a nop) since inline types have
6047 // no identity. But we first need to check whether the value class is actually implementing the Cloneable
6048 // interface. If not, we trap.
6049 if (obj_type->inline_klass()->is_cloneable()) {
6050 set_result(obj);
6051 } else {
6052 uncommon_trap(Deoptimization::Reason_intrinsic,
6053 Deoptimization::Action_maybe_recompile);
6054 }
6055 return true;
6056 }
6057
6058 // If we are going to clone an instance, we need its exact type to
6059 // know the number and types of fields to convert the clone to
6060 // loads/stores. Maybe a speculative type can help us.
6061 if (!obj_type->klass_is_exact() &&
6062 obj_type->speculative_type() != nullptr &&
6063 obj_type->speculative_type()->is_instance_klass() &&
6064 !obj_type->speculative_type()->is_inlinetype()) {
6065 ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass();
6066 if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem &&
6067 !spec_ik->has_injected_fields()) {
6068 if (!obj_type->isa_instptr() ||
6069 obj_type->is_instptr()->instance_klass()->has_subklass()) {
6070 obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false);
6071 }
6072 }
6073 }
6074
6075 // Conservatively insert a memory barrier on all memory slices.
6076 // Do not let writes into the original float below the clone.
6077 insert_mem_bar(Op_MemBarCPUOrder);
6078
6079 // paths into result_reg:
6080 enum {
6081 _slow_path = 1, // out-of-line call to clone method (virtual or not)
6082 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy
6083 _array_path, // plain array allocation, plus arrayof_long_arraycopy
6084 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy
6085 PATH_LIMIT
6086 };
6087 RegionNode* result_reg = new RegionNode(PATH_LIMIT);
6088 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
6089 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO);
6090 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
6091 record_for_igvn(result_reg);
6092
6093 Node* obj_klass = load_object_klass(obj);
6094 // We only go to the fast case code if we pass a number of guards.
6095 // The paths which do not pass are accumulated in the slow_region.
6096 RegionNode* slow_region = new RegionNode(1);
6097 record_for_igvn(slow_region);
6098
6099 Node* array_obj = obj;
6100 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)nullptr, &array_obj);
6101 if (array_ctl != nullptr) {
6102 // It's an array.
6103 PreserveJVMState pjvms(this);
6104 set_control(array_ctl);
6105
6106 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
6107 const TypeAryPtr* ary_ptr = obj_type->isa_aryptr();
6108 if (UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Expansion) &&
6109 obj_type->can_be_inline_array() &&
6110 (ary_ptr == nullptr || (!ary_ptr->is_not_flat() && (!ary_ptr->is_flat() || ary_ptr->elem()->inline_klass()->contains_oops())))) {
6111 // Flat inline type array may have object field that would require a
6112 // write barrier. Conservatively, go to slow path.
6113 generate_fair_guard(flat_array_test(obj_klass), slow_region);
6114 }
6115
6116 if (!stopped()) {
6117 Node* obj_length = load_array_length(array_obj);
6118 Node* array_size = nullptr; // Size of the array without object alignment padding.
6119 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &array_size, /*deoptimize_on_exception=*/true);
6120
6121 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
6122 if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Parsing)) {
6123 // If it is an oop array, it requires very special treatment,
6124 // because gc barriers are required when accessing the array.
6125 Node* is_obja = generate_refArray_guard(obj_klass, (RegionNode*)nullptr);
6126 if (is_obja != nullptr) {
6127 PreserveJVMState pjvms2(this);
6128 set_control(is_obja);
6129 // Generate a direct call to the right arraycopy function(s).
6130 // Clones are always tightly coupled.
6131 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, array_obj, intcon(0), alloc_obj, intcon(0), obj_length, true, false);
6132 ac->set_clone_oop_array();
6133 Node* n = _gvn.transform(ac);
6134 assert(n == ac, "cannot disappear");
6135 ac->connect_outputs(this, /*deoptimize_on_exception=*/true);
6136
6137 result_reg->init_req(_objArray_path, control());
6138 result_val->init_req(_objArray_path, alloc_obj);
6139 result_i_o ->set_req(_objArray_path, i_o());
6140 result_mem ->set_req(_objArray_path, reset_memory());
6141 }
6142 }
6143 // Otherwise, there are no barriers to worry about.
6144 // (We can dispense with card marks if we know the allocation
6145 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks
6146 // causes the non-eden paths to take compensating steps to
6147 // simulate a fresh allocation, so that no further
6148 // card marks are required in compiled code to initialize
6149 // the object.)
6150
6151 if (!stopped()) {
6152 copy_to_clone(obj, alloc_obj, array_size, true);
6153
6154 // Present the results of the copy.
6155 result_reg->init_req(_array_path, control());
6156 result_val->init_req(_array_path, alloc_obj);
6157 result_i_o ->set_req(_array_path, i_o());
6158 result_mem ->set_req(_array_path, reset_memory());
6159 }
6160 }
6161 }
6162
6163 if (!stopped()) {
6164 // It's an instance (we did array above). Make the slow-path tests.
6165 // If this is a virtual call, we generate a funny guard. We grab
6166 // the vtable entry corresponding to clone() from the target object.
6167 // If the target method which we are calling happens to be the
6168 // Object clone() method, we pass the guard. We do not need this
6169 // guard for non-virtual calls; the caller is known to be the native
6170 // Object clone().
6171 if (is_virtual) {
6172 generate_virtual_guard(obj_klass, slow_region);
6173 }
6174
6175 // The object must be easily cloneable and must not have a finalizer.
6176 // Both of these conditions may be checked in a single test.
6177 // We could optimize the test further, but we don't care.
6178 generate_misc_flags_guard(obj_klass,
6179 // Test both conditions:
6180 KlassFlags::_misc_is_cloneable_fast | KlassFlags::_misc_has_finalizer,
6181 // Must be cloneable but not finalizer:
6182 KlassFlags::_misc_is_cloneable_fast,
6274 set_jvms(sfpt->jvms());
6275 _reexecute_sp = jvms()->sp();
6276
6277 return saved_jvms;
6278 }
6279 }
6280 }
6281 return nullptr;
6282 }
6283
6284 // Clone the JVMState of the array allocation and create a new safepoint with it. Re-push the array length to the stack
6285 // such that uncommon traps can be emitted to re-execute the array allocation in the interpreter.
6286 SafePointNode* LibraryCallKit::create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const {
6287 JVMState* old_jvms = alloc->jvms()->clone_shallow(C);
6288 uint size = alloc->req();
6289 SafePointNode* sfpt = new SafePointNode(size, old_jvms);
6290 old_jvms->set_map(sfpt);
6291 for (uint i = 0; i < size; i++) {
6292 sfpt->init_req(i, alloc->in(i));
6293 }
6294 int adjustment = 1;
6295 const TypeAryKlassPtr* ary_klass_ptr = alloc->in(AllocateNode::KlassNode)->bottom_type()->is_aryklassptr();
6296 if (ary_klass_ptr->is_null_free()) {
6297 // A null-free, tightly coupled array allocation can only come from LibraryCallKit::inline_newArray which
6298 // also requires the componentType and initVal on stack for re-execution.
6299 // Re-create and push the componentType.
6300 ciArrayKlass* klass = ary_klass_ptr->exact_klass()->as_array_klass();
6301 ciInstance* instance = klass->component_mirror_instance();
6302 const TypeInstPtr* t_instance = TypeInstPtr::make(instance);
6303 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), makecon(t_instance));
6304 adjustment++;
6305 }
6306 // re-push array length for deoptimization
6307 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment - 1, alloc->in(AllocateNode::ALength));
6308 if (ary_klass_ptr->is_null_free()) {
6309 // Re-create and push the initVal.
6310 Node* init_val = alloc->in(AllocateNode::InitValue);
6311 if (init_val == nullptr) {
6312 init_val = InlineTypeNode::make_all_zero(_gvn, ary_klass_ptr->elem()->is_instklassptr()->instance_klass()->as_inline_klass());
6313 } else if (UseCompressedOops) {
6314 init_val = _gvn.transform(new DecodeNNode(init_val, init_val->bottom_type()->make_ptr()));
6315 }
6316 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment, init_val);
6317 adjustment++;
6318 }
6319 old_jvms->set_sp(old_jvms->sp() + adjustment);
6320 old_jvms->set_monoff(old_jvms->monoff() + adjustment);
6321 old_jvms->set_scloff(old_jvms->scloff() + adjustment);
6322 old_jvms->set_endoff(old_jvms->endoff() + adjustment);
6323 old_jvms->set_should_reexecute(true);
6324
6325 sfpt->set_i_o(map()->i_o());
6326 sfpt->set_memory(map()->memory());
6327 sfpt->set_control(map()->control());
6328 return sfpt;
6329 }
6330
6331 // In case of a deoptimization, we restart execution at the
6332 // allocation, allocating a new array. We would leave an uninitialized
6333 // array in the heap that GCs wouldn't expect. Move the allocation
6334 // after the traps so we don't allocate the array if we
6335 // deoptimize. This is possible because tightly_coupled_allocation()
6336 // guarantees there's no observer of the allocated array at this point
6337 // and the control flow is simple enough.
6338 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms_before_guards,
6339 int saved_reexecute_sp, uint new_idx) {
6340 if (saved_jvms_before_guards != nullptr && !stopped()) {
6341 replace_unrelated_uncommon_traps_with_alloc_state(alloc, saved_jvms_before_guards);
6342
6343 assert(alloc != nullptr, "only with a tightly coupled allocation");
6344 // restore JVM state to the state at the arraycopy
6345 saved_jvms_before_guards->map()->set_control(map()->control());
6346 assert(saved_jvms_before_guards->map()->memory() == map()->memory(), "memory state changed?");
6347 assert(saved_jvms_before_guards->map()->i_o() == map()->i_o(), "IO state changed?");
6348 // If we've improved the types of some nodes (null check) while
6349 // emitting the guards, propagate them to the current state
6350 map()->replaced_nodes().apply(saved_jvms_before_guards->map(), new_idx);
6351 set_jvms(saved_jvms_before_guards);
6352 _reexecute_sp = saved_reexecute_sp;
6353
6354 // Remove the allocation from above the guards
6355 CallProjections* callprojs = alloc->extract_projections(true);
6356 InitializeNode* init = alloc->initialization();
6357 Node* alloc_mem = alloc->in(TypeFunc::Memory);
6358 C->gvn_replace_by(callprojs->fallthrough_ioproj, alloc->in(TypeFunc::I_O));
6359 init->replace_mem_projs_by(alloc_mem, C);
6360
6361 // The CastIINode created in GraphKit::new_array (in AllocateArrayNode::make_ideal_length) must stay below
6362 // the allocation (i.e. is only valid if the allocation succeeds):
6363 // 1) replace CastIINode with AllocateArrayNode's length here
6364 // 2) Create CastIINode again once allocation has moved (see below) at the end of this method
6365 //
6366 // Multiple identical CastIINodes might exist here. Each GraphKit::load_array_length() call will generate
6367 // new separate CastIINode (arraycopy guard checks or any array length use between array allocation and ararycopy)
6368 Node* init_control = init->proj_out(TypeFunc::Control);
6369 Node* alloc_length = alloc->Ideal_length();
6370 #ifdef ASSERT
6371 Node* prev_cast = nullptr;
6372 #endif
6373 for (uint i = 0; i < init_control->outcnt(); i++) {
6374 Node* init_out = init_control->raw_out(i);
6375 if (init_out->is_CastII() && init_out->in(TypeFunc::Control) == init_control && init_out->in(1) == alloc_length) {
6376 #ifdef ASSERT
6377 if (prev_cast == nullptr) {
6378 prev_cast = init_out;
6380 if (prev_cast->cmp(*init_out) == false) {
6381 prev_cast->dump();
6382 init_out->dump();
6383 assert(false, "not equal CastIINode");
6384 }
6385 }
6386 #endif
6387 C->gvn_replace_by(init_out, alloc_length);
6388 }
6389 }
6390 C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0));
6391
6392 // move the allocation here (after the guards)
6393 _gvn.hash_delete(alloc);
6394 alloc->set_req(TypeFunc::Control, control());
6395 alloc->set_req(TypeFunc::I_O, i_o());
6396 Node *mem = reset_memory();
6397 set_all_memory(mem);
6398 alloc->set_req(TypeFunc::Memory, mem);
6399 set_control(init->proj_out_or_null(TypeFunc::Control));
6400 set_i_o(callprojs->fallthrough_ioproj);
6401
6402 // Update memory as done in GraphKit::set_output_for_allocation()
6403 const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength));
6404 const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_exact_instance_type();
6405 if (ary_type->isa_aryptr() && length_type != nullptr) {
6406 ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
6407 }
6408 const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot);
6409 int elemidx = C->get_alias_index(telemref);
6410 // Need to properly move every memory projection for the Initialize
6411 #ifdef ASSERT
6412 int mark_idx = C->get_alias_index(ary_type->add_offset(oopDesc::mark_offset_in_bytes()));
6413 int klass_idx = C->get_alias_index(ary_type->add_offset(oopDesc::klass_offset_in_bytes()));
6414 #endif
6415 auto move_proj = [&](ProjNode* proj) {
6416 int alias_idx = C->get_alias_index(proj->adr_type());
6417 assert(alias_idx == Compile::AliasIdxRaw ||
6418 alias_idx == elemidx ||
6419 alias_idx == mark_idx ||
6420 alias_idx == klass_idx, "should be raw memory or array element type");
6421 set_memory(proj, alias_idx);
6422 };
6423 init->for_each_proj(move_proj, TypeFunc::Memory);
6424
6730 top_src = src_type->isa_aryptr();
6731 has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM);
6732 src_spec = true;
6733 }
6734 if (!has_dest) {
6735 dest = maybe_cast_profiled_obj(dest, dest_k, true);
6736 dest_type = _gvn.type(dest);
6737 top_dest = dest_type->isa_aryptr();
6738 has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM);
6739 dest_spec = true;
6740 }
6741 }
6742 }
6743
6744 if (has_src && has_dest && can_emit_guards) {
6745 BasicType src_elem = top_src->isa_aryptr()->elem()->array_element_basic_type();
6746 BasicType dest_elem = top_dest->isa_aryptr()->elem()->array_element_basic_type();
6747 if (is_reference_type(src_elem, true)) src_elem = T_OBJECT;
6748 if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT;
6749
6750 if (src_elem == dest_elem && top_src->is_flat() == top_dest->is_flat() && src_elem == T_OBJECT) {
6751 // If both arrays are object arrays then having the exact types
6752 // for both will remove the need for a subtype check at runtime
6753 // before the call and may make it possible to pick a faster copy
6754 // routine (without a subtype check on every element)
6755 // Do we have the exact type of src?
6756 bool could_have_src = src_spec;
6757 // Do we have the exact type of dest?
6758 bool could_have_dest = dest_spec;
6759 ciKlass* src_k = nullptr;
6760 ciKlass* dest_k = nullptr;
6761 if (!src_spec) {
6762 src_k = src_type->speculative_type_not_null();
6763 if (src_k != nullptr && src_k->is_array_klass()) {
6764 could_have_src = true;
6765 }
6766 }
6767 if (!dest_spec) {
6768 dest_k = dest_type->speculative_type_not_null();
6769 if (dest_k != nullptr && dest_k->is_array_klass()) {
6770 could_have_dest = true;
6771 }
6772 }
6773 if (could_have_src && could_have_dest) {
6774 // If we can have both exact types, emit the missing guards
6775 if (could_have_src && !src_spec) {
6776 src = maybe_cast_profiled_obj(src, src_k, true);
6777 src_type = _gvn.type(src);
6778 top_src = src_type->isa_aryptr();
6779 }
6780 if (could_have_dest && !dest_spec) {
6781 dest = maybe_cast_profiled_obj(dest, dest_k, true);
6782 dest_type = _gvn.type(dest);
6783 top_dest = dest_type->isa_aryptr();
6784 }
6785 }
6786 }
6787 }
6788
6789 ciMethod* trap_method = method();
6790 int trap_bci = bci();
6791 if (saved_jvms_before_guards != nullptr) {
6792 trap_method = alloc->jvms()->method();
6793 trap_bci = alloc->jvms()->bci();
6794 }
6795
6796 bool negative_length_guard_generated = false;
6797
6798 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &&
6799 can_emit_guards && !src->is_top() && !dest->is_top()) {
6800 // validate arguments: enables transformation the ArrayCopyNode
6801 validated = true;
6802
6803 RegionNode* slow_region = new RegionNode(1);
6804 record_for_igvn(slow_region);
6805
6806 // (1) src and dest are arrays.
6807 generate_non_array_guard(load_object_klass(src), slow_region, &src);
6808 generate_non_array_guard(load_object_klass(dest), slow_region, &dest);
6809
6810 // (2) src and dest arrays must have elements of the same BasicType
6811 // done at macro expansion or at Ideal transformation time
6812
6813 // (4) src_offset must not be negative.
6814 generate_negative_guard(src_offset, slow_region);
6815
6816 // (5) dest_offset must not be negative.
6817 generate_negative_guard(dest_offset, slow_region);
6818
6819 // (7) src_offset + length must not exceed length of src.
6820 generate_limit_guard(src_offset, length,
6821 load_array_length(src),
6822 slow_region);
6823
6824 // (8) dest_offset + length must not exceed length of dest.
6825 generate_limit_guard(dest_offset, length,
6826 load_array_length(dest),
6827 slow_region);
6828
6829 // (6) length must not be negative.
6830 // This is also checked in generate_arraycopy() during macro expansion, but
6831 // we also have to check it here for the case where the ArrayCopyNode will
6832 // be eliminated by Escape Analysis.
6833 if (EliminateAllocations) {
6834 generate_negative_guard(length, slow_region);
6835 negative_length_guard_generated = true;
6836 }
6837
6838 // (9) each element of an oop array must be assignable
6839 Node* dest_klass = load_object_klass(dest);
6840 Node* refined_dest_klass = dest_klass;
6841 if (src != dest) {
6842 dest_klass = load_non_refined_array_klass(refined_dest_klass);
6843 Node* not_subtype_ctrl = gen_subtype_check(src, dest_klass);
6844 slow_region->add_req(not_subtype_ctrl);
6845 }
6846
6847 // TODO 8251971 Improve this. What about atomicity? Make sure this is always folded for type arrays.
6848 // If destination is null-restricted, source must be null-restricted as well: src_null_restricted || !dst_null_restricted
6849 Node* src_klass = load_object_klass(src);
6850 Node* adr_prop_src = basic_plus_adr(top(), src_klass, in_bytes(ArrayKlass::properties_offset()));
6851 Node* prop_src = _gvn.transform(LoadNode::make(_gvn, control(), immutable_memory(), adr_prop_src,
6852 _gvn.type(adr_prop_src)->is_ptr(), TypeInt::INT, T_INT,
6853 MemNode::unordered));
6854 Node* adr_prop_dest = basic_plus_adr(top(), refined_dest_klass, in_bytes(ArrayKlass::properties_offset()));
6855 Node* prop_dest = _gvn.transform(LoadNode::make(_gvn, control(), immutable_memory(), adr_prop_dest,
6856 _gvn.type(adr_prop_dest)->is_ptr(), TypeInt::INT, T_INT,
6857 MemNode::unordered));
6858
6859 const ArrayProperties props_null_restricted = ArrayProperties::Default().with_null_restricted();
6860 jint props_value = (jint)props_null_restricted.value();
6861
6862 prop_dest = _gvn.transform(new XorINode(prop_dest, intcon(props_value)));
6863 prop_src = _gvn.transform(new OrINode(prop_dest, prop_src));
6864 prop_src = _gvn.transform(new AndINode(prop_src, intcon(props_value)));
6865
6866 Node* chk = _gvn.transform(new CmpINode(prop_src, intcon(props_value)));
6867 Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::ne));
6868 generate_fair_guard(tst, slow_region);
6869
6870 // TODO 8251971 This is too strong
6871 generate_fair_guard(flat_array_test(src), slow_region);
6872 generate_fair_guard(flat_array_test(dest), slow_region);
6873
6874 {
6875 PreserveJVMState pjvms(this);
6876 set_control(_gvn.transform(slow_region));
6877 uncommon_trap(Deoptimization::Reason_intrinsic,
6878 Deoptimization::Action_make_not_entrant);
6879 assert(stopped(), "Should be stopped");
6880 }
6881
6882 const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->isa_klassptr();
6883 if (dest_klass_t == nullptr) {
6884 // refined_dest_klass may not be an array, which leads to dest_klass being top. This means we
6885 // are in a dead path.
6886 uncommon_trap(Deoptimization::Reason_intrinsic,
6887 Deoptimization::Action_make_not_entrant);
6888 return true;
6889 }
6890
6891 const Type* toop = dest_klass_t->as_subtype_instance_type();
6892 src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
6893 arraycopy_move_allocation_here(alloc, dest, saved_jvms_before_guards, saved_reexecute_sp, new_idx);
6894 }
6895
6896 if (stopped()) {
6897 return true;
6898 }
6899
6900 Node* dest_klass = load_object_klass(dest);
6901 dest_klass = load_non_refined_array_klass(dest_klass);
6902
6903 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != nullptr, negative_length_guard_generated,
6904 // Create LoadRange and LoadKlass nodes for use during macro expansion here
6905 // so the compiler has a chance to eliminate them: during macro expansion,
6906 // we have to set their control (CastPP nodes are eliminated).
6907 load_object_klass(src), dest_klass,
6908 load_array_length(src), load_array_length(dest));
6909
6910 ac->set_arraycopy(validated);
6911
6912 Node* n = _gvn.transform(ac);
6913 if (n == ac) {
6914 ac->connect_outputs(this);
6915 } else {
6916 assert(validated, "shouldn't transform if all arguments not validated");
6917 set_all_memory(n);
6918 }
6919 clear_upper_avx();
6920
6921
6922 return true;
6923 }
6924
6925
6926 // Helper function which determines if an arraycopy immediately follows
6927 // an allocation, with no intervening tests or other escapes for the object.
8134 dest_start = array_element_address(dest, dest_offset, T_BYTE);
8135 }
8136
8137 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
8138 // (because of the predicated logic executed earlier).
8139 // so we cast it here safely.
8140 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
8141
8142 Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
8143 if (embeddedCipherObj == nullptr) return false;
8144
8145 // cast it to what we know it will be at runtime
8146 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr();
8147 assert(tinst != nullptr, "CBC obj is null");
8148 assert(tinst->is_loaded(), "CBC obj is not loaded");
8149 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
8150 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
8151
8152 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
8153 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
8154 const TypeOopPtr* xtype = aklass->as_exact_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
8155 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
8156 aescrypt_object = _gvn.transform(aescrypt_object);
8157
8158 // we need to get the start of the aescrypt_object's expanded key array
8159 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
8160 if (k_start == nullptr) return false;
8161
8162 // similarly, get the start address of the r vector
8163 Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B");
8164 if (objRvec == nullptr) return false;
8165 Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE);
8166
8167 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
8168 Node* cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
8169 OptoRuntime::cipherBlockChaining_aescrypt_Type(),
8170 stubAddr, stubName, TypePtr::BOTTOM,
8171 src_start, dest_start, k_start, r_start, len);
8172
8173 // return cipher length (int)
8174 Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms));
8221 dest_start = array_element_address(dest, dest_offset, T_BYTE);
8222 }
8223
8224 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
8225 // (because of the predicated logic executed earlier).
8226 // so we cast it here safely.
8227 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
8228
8229 Node* embeddedCipherObj = load_field_from_object(electronicCodeBook_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
8230 if (embeddedCipherObj == nullptr) return false;
8231
8232 // cast it to what we know it will be at runtime
8233 const TypeInstPtr* tinst = _gvn.type(electronicCodeBook_object)->isa_instptr();
8234 assert(tinst != nullptr, "ECB obj is null");
8235 assert(tinst->is_loaded(), "ECB obj is not loaded");
8236 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
8237 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
8238
8239 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
8240 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
8241 const TypeOopPtr* xtype = aklass->as_exact_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
8242 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
8243 aescrypt_object = _gvn.transform(aescrypt_object);
8244
8245 // we need to get the start of the aescrypt_object's expanded key array
8246 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
8247 if (k_start == nullptr) return false;
8248
8249 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
8250 Node* ecbCrypt = make_runtime_call(RC_LEAF | RC_NO_FP,
8251 OptoRuntime::electronicCodeBook_aescrypt_Type(),
8252 stubAddr, stubName, TypePtr::BOTTOM,
8253 src_start, dest_start, k_start, len);
8254
8255 // return cipher length (int)
8256 Node* retvalue = _gvn.transform(new ProjNode(ecbCrypt, TypeFunc::Parms));
8257 set_result(retvalue);
8258 return true;
8259 }
8260
8261 //------------------------------inline_counterMode_AESCrypt-----------------------
8290 if (src_offset != nullptr || dest_offset != nullptr) {
8291 assert(src_offset != nullptr && dest_offset != nullptr, "");
8292 src_start = array_element_address(src, src_offset, T_BYTE);
8293 dest_start = array_element_address(dest, dest_offset, T_BYTE);
8294 }
8295
8296 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
8297 // (because of the predicated logic executed earlier).
8298 // so we cast it here safely.
8299 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
8300 Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
8301 if (embeddedCipherObj == nullptr) return false;
8302 // cast it to what we know it will be at runtime
8303 const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr();
8304 assert(tinst != nullptr, "CTR obj is null");
8305 assert(tinst->is_loaded(), "CTR obj is not loaded");
8306 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
8307 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
8308 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
8309 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
8310 const TypeOopPtr* xtype = aklass->as_exact_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
8311 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
8312 aescrypt_object = _gvn.transform(aescrypt_object);
8313 // we need to get the start of the aescrypt_object's expanded key array
8314 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
8315 if (k_start == nullptr) return false;
8316 // similarly, get the start address of the r vector
8317 Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B");
8318 if (obj_counter == nullptr) return false;
8319 Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE);
8320
8321 Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B");
8322 if (saved_encCounter == nullptr) return false;
8323 Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE);
8324 Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false);
8325
8326 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
8327 Node* ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
8328 OptoRuntime::counterMode_aescrypt_Type(),
8329 stubAddr, stubName, TypePtr::BOTTOM,
8330 src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used);
9463 if (stub_addr == nullptr) return false;
9464
9465 // get DigestBase klass to lookup for SHA klass
9466 const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr();
9467 assert(tinst != nullptr, "digestBase_obj is not instance???");
9468 assert(tinst->is_loaded(), "DigestBase is not loaded");
9469
9470 ciKlass* klass_digestBase = tinst->instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name));
9471 assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded");
9472 ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass();
9473 return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit);
9474 }
9475 return false;
9476 }
9477
9478 //------------------------------inline_digestBase_implCompressMB-----------------------
9479 bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase,
9480 BasicType elem_type, address stubAddr, const char *stubName,
9481 Node* src_start, Node* ofs, Node* limit) {
9482 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase);
9483 const TypeOopPtr* xtype = aklass->as_subtype_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
9484 Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype);
9485 digest_obj = _gvn.transform(digest_obj);
9486
9487 Node* state = get_state_from_digest_object(digest_obj, elem_type);
9488 if (state == nullptr) return false;
9489
9490 Node* block_size = nullptr;
9491 if (strcmp("sha3_implCompressMB", stubName) == 0) {
9492 block_size = get_block_size_from_digest_object(digest_obj);
9493 if (block_size == nullptr) return false;
9494 }
9495
9496 // Call the stub.
9497 Node* call;
9498 if (block_size == nullptr) {
9499 call = make_runtime_call(RC_LEAF|RC_NO_FP,
9500 OptoRuntime::digestBase_implCompressMB_Type(false),
9501 stubAddr, stubName, TypePtr::BOTTOM,
9502 src_start, state, ofs, limit);
9503 } else {
9556 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
9557 // (because of the predicated logic executed earlier).
9558 // so we cast it here safely.
9559 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
9560 Node* embeddedCipherObj = load_field_from_object(gctr_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
9561 Node* counter = load_field_from_object(gctr_object, "counter", "[B");
9562 Node* subkeyHtbl = load_field_from_object(ghash_object, "subkeyHtbl", "[J");
9563 Node* state = load_field_from_object(ghash_object, "state", "[J");
9564
9565 if (embeddedCipherObj == nullptr || counter == nullptr || subkeyHtbl == nullptr || state == nullptr) {
9566 return false;
9567 }
9568 // cast it to what we know it will be at runtime
9569 const TypeInstPtr* tinst = _gvn.type(gctr_object)->isa_instptr();
9570 assert(tinst != nullptr, "GCTR obj is null");
9571 assert(tinst->is_loaded(), "GCTR obj is not loaded");
9572 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
9573 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
9574 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
9575 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
9576 const TypeOopPtr* xtype = aklass->as_exact_instance_type();
9577 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
9578 aescrypt_object = _gvn.transform(aescrypt_object);
9579 // we need to get the start of the aescrypt_object's expanded key array
9580 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
9581 if (k_start == nullptr) return false;
9582 // similarly, get the start address of the r vector
9583 Node* cnt_start = array_element_address(counter, intcon(0), T_BYTE);
9584 Node* state_start = array_element_address(state, intcon(0), T_LONG);
9585 Node* subkeyHtbl_start = array_element_address(subkeyHtbl, intcon(0), T_LONG);
9586
9587
9588 // Call the stub, passing params
9589 Node* gcmCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
9590 OptoRuntime::galoisCounterMode_aescrypt_Type(),
9591 stubAddr, stubName, TypePtr::BOTTOM,
9592 in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start);
9593
9594 // return cipher length (int)
9595 Node* retvalue = _gvn.transform(new ProjNode(gcmCrypt, TypeFunc::Parms));
9596 set_result(retvalue);
|