< prev index next >

src/share/vm/opto/library_call.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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  *


2527     }
2528   }
2529 
2530   // See if it is a narrow oop array.
2531   if (adr_type->isa_aryptr()) {
2532     if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) {
2533       const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr();
2534       if (elem_type != NULL) {
2535         sharpened_klass = elem_type->klass();
2536       }
2537     }
2538   }
2539 
2540   // The sharpened class might be unloaded if there is no class loader
2541   // contraint in place.
2542   if (sharpened_klass != NULL && sharpened_klass->is_loaded()) {
2543     const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass);
2544 
2545 #ifndef PRODUCT
2546     if (C->print_intrinsics() || C->print_inlining()) {
2547       tty->print("  from base type: ");  adr_type->dump();
2548       tty->print("  sharpened value: ");  tjp->dump();
2549     }
2550 #endif
2551     // Sharpen the value type.
2552     return tjp;
2553   }
2554   return NULL;
2555 }
2556 
2557 bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile, bool unaligned) {
2558   if (callee()->is_static())  return false;  // caller must have the capability!
2559   assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type");
2560 
2561 #ifndef PRODUCT
2562   {
2563     ResourceMark rm;
2564     // Check the signatures.
2565     ciSignature* sig = callee()->signature();
2566 #ifdef ASSERT
2567     if (!is_store) {
2568       // Object getObject(Object base, int/long offset), etc.


2615     offset = argument(2);  // type: long
2616     // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2617     // to be plain byte offsets, which are also the same as those accepted
2618     // by oopDesc::field_base.
2619     assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2620            "fieldOffset must be byte-scaled");
2621     // 32-bit machines ignore the high half!
2622     offset = ConvL2X(offset);
2623     adr = make_unsafe_address(base, offset);
2624     heap_base_oop = base;
2625     val = is_store ? argument(4) : NULL;
2626   } else {
2627     Node* ptr = argument(1);  // type: long
2628     ptr = ConvL2X(ptr);  // adjust Java long to machine word
2629     adr = make_unsafe_address(NULL, ptr);
2630     val = is_store ? argument(3) : NULL;
2631   }
2632 
2633   // Can base be NULL? Otherwise, always on-heap access.
2634   bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop));



2635 
2636   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2637 
2638   // Try to categorize the address.
2639   Compile::AliasType* alias_type = C->alias_type(adr_type);
2640   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2641 
2642   if (alias_type->adr_type() == TypeInstPtr::KLASS ||
2643       alias_type->adr_type() == TypeAryPtr::RANGE) {
2644     return false; // not supported
2645   }
2646 
2647   bool mismatched = false;
2648   BasicType bt = alias_type->basic_type();
2649   if (bt != T_ILLEGAL) {
2650     assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access");
2651     if (bt == T_BYTE && adr_type->isa_aryptr()) {
2652       // Alias type doesn't differentiate between byte[] and boolean[]).
2653       // Use address type to get the element type.
2654       bt = adr_type->is_aryptr()->elem()->array_element_basic_type();


2759     }
2760     // The load node has the control of the preceding MemBarCPUOrder.  All
2761     // following nodes will have the control of the MemBarCPUOrder inserted at
2762     // the end of this method.  So, pushing the load onto the stack at a later
2763     // point is fine.
2764     set_result(p);
2765   } else {
2766     // place effect of store into memory
2767     switch (type) {
2768     case T_DOUBLE:
2769       val = dstore_rounding(val);
2770       break;
2771     case T_ADDRESS:
2772       // Repackage the long as a pointer.
2773       val = ConvL2X(val);
2774       val = _gvn.transform(new (C) CastX2PNode(val));
2775       break;
2776     }
2777 
2778     MemNode::MemOrd mo = is_volatile ? MemNode::release : MemNode::unordered;
2779     if (type != T_OBJECT ) {
2780       (void) store_to_memory(control(), adr, val, type, adr_type, mo, is_volatile, unaligned, mismatched);
2781     } else {
2782       // Possibly an oop being stored to Java heap or native memory
2783       if (!can_access_non_heap) {
2784         // oop to Java heap.
2785         (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo, mismatched);
2786       } else {
2787         // We can't tell at compile time if we are storing in the Java heap or outside
2788         // of it. So we need to emit code to conditionally do the proper type of
2789         // store.
2790 
2791         IdealKit ideal(this);
2792 #define __ ideal.
2793         // QQQ who knows what probability is here??
2794         __ if_then(heap_base_oop, BoolTest::ne, null(), PROB_UNLIKELY(0.999)); {
2795           // Sync IdealKit and graphKit.
2796           sync_kit(ideal);
2797           Node* st = store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo, mismatched);
2798           // Update IdealKit memory.
2799           __ sync_kit(this);
2800         } __ else_(); {
2801           __ store(__ ctrl(), adr, val, type, alias_type->index(), mo, is_volatile, mismatched);
2802         } __ end_if();
2803         // Final sync IdealKit and GraphKit.
2804         final_sync(ideal);
2805 #undef __
2806       }
2807     }
2808   }
2809 
2810   if (is_volatile) {
2811     if (!is_store) {
2812       insert_mem_bar(Op_MemBarAcquire);
2813     } else {
2814       if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
2815         insert_mem_bar(Op_MemBarVolatile);
2816       }
2817     }
2818   }
2819 
2820   if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
2821 
2822   return true;
2823 }
2824 
2825 //----------------------------inline_unsafe_prefetch----------------------------
2826 


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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  *


2527     }
2528   }
2529 
2530   // See if it is a narrow oop array.
2531   if (adr_type->isa_aryptr()) {
2532     if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) {
2533       const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr();
2534       if (elem_type != NULL) {
2535         sharpened_klass = elem_type->klass();
2536       }
2537     }
2538   }
2539 
2540   // The sharpened class might be unloaded if there is no class loader
2541   // contraint in place.
2542   if (sharpened_klass != NULL && sharpened_klass->is_loaded()) {
2543     const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass);
2544 
2545 #ifndef PRODUCT
2546     if (C->print_intrinsics() || C->print_inlining()) {
2547       tty->print("  from base type:  ");  adr_type->dump(); tty->cr();
2548       tty->print("  sharpened value: ");  tjp->dump();      tty->cr();
2549     }
2550 #endif
2551     // Sharpen the value type.
2552     return tjp;
2553   }
2554   return NULL;
2555 }
2556 
2557 bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile, bool unaligned) {
2558   if (callee()->is_static())  return false;  // caller must have the capability!
2559   assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type");
2560 
2561 #ifndef PRODUCT
2562   {
2563     ResourceMark rm;
2564     // Check the signatures.
2565     ciSignature* sig = callee()->signature();
2566 #ifdef ASSERT
2567     if (!is_store) {
2568       // Object getObject(Object base, int/long offset), etc.


2615     offset = argument(2);  // type: long
2616     // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2617     // to be plain byte offsets, which are also the same as those accepted
2618     // by oopDesc::field_base.
2619     assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2620            "fieldOffset must be byte-scaled");
2621     // 32-bit machines ignore the high half!
2622     offset = ConvL2X(offset);
2623     adr = make_unsafe_address(base, offset);
2624     heap_base_oop = base;
2625     val = is_store ? argument(4) : NULL;
2626   } else {
2627     Node* ptr = argument(1);  // type: long
2628     ptr = ConvL2X(ptr);  // adjust Java long to machine word
2629     adr = make_unsafe_address(NULL, ptr);
2630     val = is_store ? argument(3) : NULL;
2631   }
2632 
2633   // Can base be NULL? Otherwise, always on-heap access.
2634   bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop));
2635   if (can_access_non_heap && type == T_OBJECT) {
2636     return false; // off-heap oop accesses are not supported
2637   }
2638 
2639   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2640 
2641   // Try to categorize the address.
2642   Compile::AliasType* alias_type = C->alias_type(adr_type);
2643   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2644 
2645   if (alias_type->adr_type() == TypeInstPtr::KLASS ||
2646       alias_type->adr_type() == TypeAryPtr::RANGE) {
2647     return false; // not supported
2648   }
2649 
2650   bool mismatched = false;
2651   BasicType bt = alias_type->basic_type();
2652   if (bt != T_ILLEGAL) {
2653     assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access");
2654     if (bt == T_BYTE && adr_type->isa_aryptr()) {
2655       // Alias type doesn't differentiate between byte[] and boolean[]).
2656       // Use address type to get the element type.
2657       bt = adr_type->is_aryptr()->elem()->array_element_basic_type();


2762     }
2763     // The load node has the control of the preceding MemBarCPUOrder.  All
2764     // following nodes will have the control of the MemBarCPUOrder inserted at
2765     // the end of this method.  So, pushing the load onto the stack at a later
2766     // point is fine.
2767     set_result(p);
2768   } else {
2769     // place effect of store into memory
2770     switch (type) {
2771     case T_DOUBLE:
2772       val = dstore_rounding(val);
2773       break;
2774     case T_ADDRESS:
2775       // Repackage the long as a pointer.
2776       val = ConvL2X(val);
2777       val = _gvn.transform(new (C) CastX2PNode(val));
2778       break;
2779     }
2780 
2781     MemNode::MemOrd mo = is_volatile ? MemNode::release : MemNode::unordered;
2782     if (type == T_OBJECT ) {





2783       (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo, mismatched);
2784     } else {
2785       (void) store_to_memory(control(), adr, val, type, adr_type, mo, is_volatile, unaligned, mismatched);



















2786     }
2787   }
2788 
2789   if (is_volatile) {
2790     if (!is_store) {
2791       insert_mem_bar(Op_MemBarAcquire);
2792     } else {
2793       if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
2794         insert_mem_bar(Op_MemBarVolatile);
2795       }
2796     }
2797   }
2798 
2799   if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
2800 
2801   return true;
2802 }
2803 
2804 //----------------------------inline_unsafe_prefetch----------------------------
2805 


< prev index next >