hotspot/src/share/vm/opto/library_call.cpp
changeset 38211 fe30fdab0f62
parent 38131 7bb27ec1a3d8
child 38246 518c89421883
equal deleted inserted replaced
38209:b2a58604e046 38211:fe30fdab0f62
    91  private:
    91  private:
    92   LibraryIntrinsic* _intrinsic;     // the library intrinsic being called
    92   LibraryIntrinsic* _intrinsic;     // the library intrinsic being called
    93   Node*             _result;        // the result node, if any
    93   Node*             _result;        // the result node, if any
    94   int               _reexecute_sp;  // the stack pointer when bytecode needs to be reexecuted
    94   int               _reexecute_sp;  // the stack pointer when bytecode needs to be reexecuted
    95 
    95 
    96   const TypeOopPtr* sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr = false);
    96   const TypeOopPtr* sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type);
    97 
    97 
    98  public:
    98  public:
    99   LibraryCallKit(JVMState* jvms, LibraryIntrinsic* intrinsic)
    99   LibraryCallKit(JVMState* jvms, LibraryIntrinsic* intrinsic)
   100     : GraphKit(jvms),
   100     : GraphKit(jvms),
   101       _intrinsic(intrinsic),
   101       _intrinsic(intrinsic),
   245   // Generates the guards that check whether the result of
   245   // Generates the guards that check whether the result of
   246   // Unsafe.getObject should be recorded in an SATB log buffer.
   246   // Unsafe.getObject should be recorded in an SATB log buffer.
   247   void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar);
   247   void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar);
   248 
   248 
   249   typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
   249   typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
   250   bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
   250   bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
   251   static bool klass_needs_init_guard(Node* kls);
   251   static bool klass_needs_init_guard(Node* kls);
   252   bool inline_unsafe_allocate();
   252   bool inline_unsafe_allocate();
   253   bool inline_unsafe_newArray(bool uninitialized);
   253   bool inline_unsafe_newArray(bool uninitialized);
   254   bool inline_unsafe_copyMemory();
   254   bool inline_unsafe_copyMemory();
   255   bool inline_native_currentThread();
   255   bool inline_native_currentThread();
   473 
   473 
   474 bool LibraryCallKit::try_to_inline(int predicate) {
   474 bool LibraryCallKit::try_to_inline(int predicate) {
   475   // Handle symbolic names for otherwise undistinguished boolean switches:
   475   // Handle symbolic names for otherwise undistinguished boolean switches:
   476   const bool is_store       = true;
   476   const bool is_store       = true;
   477   const bool is_compress    = true;
   477   const bool is_compress    = true;
   478   const bool is_native_ptr  = true;
       
   479   const bool is_static      = true;
   478   const bool is_static      = true;
   480   const bool is_volatile    = true;
   479   const bool is_volatile    = true;
   481 
   480 
   482   if (!jvms()->has_method()) {
   481   if (!jvms()->has_method()) {
   483     // Root JVMState has a null method.
   482     // Root JVMState has a null method.
   553   case vmIntrinsics::_compressStringC:
   552   case vmIntrinsics::_compressStringC:
   554   case vmIntrinsics::_compressStringB:          return inline_string_copy( is_compress);
   553   case vmIntrinsics::_compressStringB:          return inline_string_copy( is_compress);
   555   case vmIntrinsics::_inflateStringC:
   554   case vmIntrinsics::_inflateStringC:
   556   case vmIntrinsics::_inflateStringB:           return inline_string_copy(!is_compress);
   555   case vmIntrinsics::_inflateStringB:           return inline_string_copy(!is_compress);
   557 
   556 
   558   case vmIntrinsics::_getObject:                return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT,   Relaxed, false);
   557   case vmIntrinsics::_getObject:                return inline_unsafe_access(!is_store, T_OBJECT,   Relaxed, false);
   559   case vmIntrinsics::_getBoolean:               return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN,  Relaxed, false);
   558   case vmIntrinsics::_getBoolean:               return inline_unsafe_access(!is_store, T_BOOLEAN,  Relaxed, false);
   560   case vmIntrinsics::_getByte:                  return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE,     Relaxed, false);
   559   case vmIntrinsics::_getByte:                  return inline_unsafe_access(!is_store, T_BYTE,     Relaxed, false);
   561   case vmIntrinsics::_getShort:                 return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT,    Relaxed, false);
   560   case vmIntrinsics::_getShort:                 return inline_unsafe_access(!is_store, T_SHORT,    Relaxed, false);
   562   case vmIntrinsics::_getChar:                  return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR,     Relaxed, false);
   561   case vmIntrinsics::_getChar:                  return inline_unsafe_access(!is_store, T_CHAR,     Relaxed, false);
   563   case vmIntrinsics::_getInt:                   return inline_unsafe_access(!is_native_ptr, !is_store, T_INT,      Relaxed, false);
   562   case vmIntrinsics::_getInt:                   return inline_unsafe_access(!is_store, T_INT,      Relaxed, false);
   564   case vmIntrinsics::_getLong:                  return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG,     Relaxed, false);
   563   case vmIntrinsics::_getLong:                  return inline_unsafe_access(!is_store, T_LONG,     Relaxed, false);
   565   case vmIntrinsics::_getFloat:                 return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT,    Relaxed, false);
   564   case vmIntrinsics::_getFloat:                 return inline_unsafe_access(!is_store, T_FLOAT,    Relaxed, false);
   566   case vmIntrinsics::_getDouble:                return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE,   Relaxed, false);
   565   case vmIntrinsics::_getDouble:                return inline_unsafe_access(!is_store, T_DOUBLE,   Relaxed, false);
   567 
   566 
   568   case vmIntrinsics::_putObject:                return inline_unsafe_access(!is_native_ptr,  is_store, T_OBJECT,   Relaxed, false);
   567   case vmIntrinsics::_putObject:                return inline_unsafe_access( is_store, T_OBJECT,   Relaxed, false);
   569   case vmIntrinsics::_putBoolean:               return inline_unsafe_access(!is_native_ptr,  is_store, T_BOOLEAN,  Relaxed, false);
   568   case vmIntrinsics::_putBoolean:               return inline_unsafe_access( is_store, T_BOOLEAN,  Relaxed, false);
   570   case vmIntrinsics::_putByte:                  return inline_unsafe_access(!is_native_ptr,  is_store, T_BYTE,     Relaxed, false);
   569   case vmIntrinsics::_putByte:                  return inline_unsafe_access( is_store, T_BYTE,     Relaxed, false);
   571   case vmIntrinsics::_putShort:                 return inline_unsafe_access(!is_native_ptr,  is_store, T_SHORT,    Relaxed, false);
   570   case vmIntrinsics::_putShort:                 return inline_unsafe_access( is_store, T_SHORT,    Relaxed, false);
   572   case vmIntrinsics::_putChar:                  return inline_unsafe_access(!is_native_ptr,  is_store, T_CHAR,     Relaxed, false);
   571   case vmIntrinsics::_putChar:                  return inline_unsafe_access( is_store, T_CHAR,     Relaxed, false);
   573   case vmIntrinsics::_putInt:                   return inline_unsafe_access(!is_native_ptr,  is_store, T_INT,      Relaxed, false);
   572   case vmIntrinsics::_putInt:                   return inline_unsafe_access( is_store, T_INT,      Relaxed, false);
   574   case vmIntrinsics::_putLong:                  return inline_unsafe_access(!is_native_ptr,  is_store, T_LONG,     Relaxed, false);
   573   case vmIntrinsics::_putLong:                  return inline_unsafe_access( is_store, T_LONG,     Relaxed, false);
   575   case vmIntrinsics::_putFloat:                 return inline_unsafe_access(!is_native_ptr,  is_store, T_FLOAT,    Relaxed, false);
   574   case vmIntrinsics::_putFloat:                 return inline_unsafe_access( is_store, T_FLOAT,    Relaxed, false);
   576   case vmIntrinsics::_putDouble:                return inline_unsafe_access(!is_native_ptr,  is_store, T_DOUBLE,   Relaxed, false);
   575   case vmIntrinsics::_putDouble:                return inline_unsafe_access( is_store, T_DOUBLE,   Relaxed, false);
   577 
   576 
   578   case vmIntrinsics::_getByte_raw:              return inline_unsafe_access( is_native_ptr, !is_store, T_BYTE,     Relaxed, false);
   577   case vmIntrinsics::_getObjectVolatile:        return inline_unsafe_access(!is_store, T_OBJECT,   Volatile, false);
   579   case vmIntrinsics::_getShort_raw:             return inline_unsafe_access( is_native_ptr, !is_store, T_SHORT,    Relaxed, false);
   578   case vmIntrinsics::_getBooleanVolatile:       return inline_unsafe_access(!is_store, T_BOOLEAN,  Volatile, false);
   580   case vmIntrinsics::_getChar_raw:              return inline_unsafe_access( is_native_ptr, !is_store, T_CHAR,     Relaxed, false);
   579   case vmIntrinsics::_getByteVolatile:          return inline_unsafe_access(!is_store, T_BYTE,     Volatile, false);
   581   case vmIntrinsics::_getInt_raw:               return inline_unsafe_access( is_native_ptr, !is_store, T_INT,      Relaxed, false);
   580   case vmIntrinsics::_getShortVolatile:         return inline_unsafe_access(!is_store, T_SHORT,    Volatile, false);
   582   case vmIntrinsics::_getLong_raw:              return inline_unsafe_access( is_native_ptr, !is_store, T_LONG,     Relaxed, false);
   581   case vmIntrinsics::_getCharVolatile:          return inline_unsafe_access(!is_store, T_CHAR,     Volatile, false);
   583   case vmIntrinsics::_getFloat_raw:             return inline_unsafe_access( is_native_ptr, !is_store, T_FLOAT,    Relaxed, false);
   582   case vmIntrinsics::_getIntVolatile:           return inline_unsafe_access(!is_store, T_INT,      Volatile, false);
   584   case vmIntrinsics::_getDouble_raw:            return inline_unsafe_access( is_native_ptr, !is_store, T_DOUBLE,   Relaxed, false);
   583   case vmIntrinsics::_getLongVolatile:          return inline_unsafe_access(!is_store, T_LONG,     Volatile, false);
   585   case vmIntrinsics::_getAddress_raw:           return inline_unsafe_access( is_native_ptr, !is_store, T_ADDRESS,  Relaxed, false);
   584   case vmIntrinsics::_getFloatVolatile:         return inline_unsafe_access(!is_store, T_FLOAT,    Volatile, false);
   586 
   585   case vmIntrinsics::_getDoubleVolatile:        return inline_unsafe_access(!is_store, T_DOUBLE,   Volatile, false);
   587   case vmIntrinsics::_putByte_raw:              return inline_unsafe_access( is_native_ptr,  is_store, T_BYTE,     Relaxed, false);
   586 
   588   case vmIntrinsics::_putShort_raw:             return inline_unsafe_access( is_native_ptr,  is_store, T_SHORT,    Relaxed, false);
   587   case vmIntrinsics::_putObjectVolatile:        return inline_unsafe_access( is_store, T_OBJECT,   Volatile, false);
   589   case vmIntrinsics::_putChar_raw:              return inline_unsafe_access( is_native_ptr,  is_store, T_CHAR,     Relaxed, false);
   588   case vmIntrinsics::_putBooleanVolatile:       return inline_unsafe_access( is_store, T_BOOLEAN,  Volatile, false);
   590   case vmIntrinsics::_putInt_raw:               return inline_unsafe_access( is_native_ptr,  is_store, T_INT,      Relaxed, false);
   589   case vmIntrinsics::_putByteVolatile:          return inline_unsafe_access( is_store, T_BYTE,     Volatile, false);
   591   case vmIntrinsics::_putLong_raw:              return inline_unsafe_access( is_native_ptr,  is_store, T_LONG,     Relaxed, false);
   590   case vmIntrinsics::_putShortVolatile:         return inline_unsafe_access( is_store, T_SHORT,    Volatile, false);
   592   case vmIntrinsics::_putFloat_raw:             return inline_unsafe_access( is_native_ptr,  is_store, T_FLOAT,    Relaxed, false);
   591   case vmIntrinsics::_putCharVolatile:          return inline_unsafe_access( is_store, T_CHAR,     Volatile, false);
   593   case vmIntrinsics::_putDouble_raw:            return inline_unsafe_access( is_native_ptr,  is_store, T_DOUBLE,   Relaxed, false);
   592   case vmIntrinsics::_putIntVolatile:           return inline_unsafe_access( is_store, T_INT,      Volatile, false);
   594   case vmIntrinsics::_putAddress_raw:           return inline_unsafe_access( is_native_ptr,  is_store, T_ADDRESS,  Relaxed, false);
   593   case vmIntrinsics::_putLongVolatile:          return inline_unsafe_access( is_store, T_LONG,     Volatile, false);
   595 
   594   case vmIntrinsics::_putFloatVolatile:         return inline_unsafe_access( is_store, T_FLOAT,    Volatile, false);
   596   case vmIntrinsics::_getObjectVolatile:        return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT,   Volatile, false);
   595   case vmIntrinsics::_putDoubleVolatile:        return inline_unsafe_access( is_store, T_DOUBLE,   Volatile, false);
   597   case vmIntrinsics::_getBooleanVolatile:       return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN,  Volatile, false);
   596 
   598   case vmIntrinsics::_getByteVolatile:          return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE,     Volatile, false);
   597   case vmIntrinsics::_getShortUnaligned:        return inline_unsafe_access(!is_store, T_SHORT,    Relaxed, true);
   599   case vmIntrinsics::_getShortVolatile:         return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT,    Volatile, false);
   598   case vmIntrinsics::_getCharUnaligned:         return inline_unsafe_access(!is_store, T_CHAR,     Relaxed, true);
   600   case vmIntrinsics::_getCharVolatile:          return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR,     Volatile, false);
   599   case vmIntrinsics::_getIntUnaligned:          return inline_unsafe_access(!is_store, T_INT,      Relaxed, true);
   601   case vmIntrinsics::_getIntVolatile:           return inline_unsafe_access(!is_native_ptr, !is_store, T_INT,      Volatile, false);
   600   case vmIntrinsics::_getLongUnaligned:         return inline_unsafe_access(!is_store, T_LONG,     Relaxed, true);
   602   case vmIntrinsics::_getLongVolatile:          return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG,     Volatile, false);
   601 
   603   case vmIntrinsics::_getFloatVolatile:         return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT,    Volatile, false);
   602   case vmIntrinsics::_putShortUnaligned:        return inline_unsafe_access( is_store, T_SHORT,    Relaxed, true);
   604   case vmIntrinsics::_getDoubleVolatile:        return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE,   Volatile, false);
   603   case vmIntrinsics::_putCharUnaligned:         return inline_unsafe_access( is_store, T_CHAR,     Relaxed, true);
   605 
   604   case vmIntrinsics::_putIntUnaligned:          return inline_unsafe_access( is_store, T_INT,      Relaxed, true);
   606   case vmIntrinsics::_putObjectVolatile:        return inline_unsafe_access(!is_native_ptr,  is_store, T_OBJECT,   Volatile, false);
   605   case vmIntrinsics::_putLongUnaligned:         return inline_unsafe_access( is_store, T_LONG,     Relaxed, true);
   607   case vmIntrinsics::_putBooleanVolatile:       return inline_unsafe_access(!is_native_ptr,  is_store, T_BOOLEAN,  Volatile, false);
   606 
   608   case vmIntrinsics::_putByteVolatile:          return inline_unsafe_access(!is_native_ptr,  is_store, T_BYTE,     Volatile, false);
   607   case vmIntrinsics::_getObjectAcquire:         return inline_unsafe_access(!is_store, T_OBJECT,   Acquire, false);
   609   case vmIntrinsics::_putShortVolatile:         return inline_unsafe_access(!is_native_ptr,  is_store, T_SHORT,    Volatile, false);
   608   case vmIntrinsics::_getBooleanAcquire:        return inline_unsafe_access(!is_store, T_BOOLEAN,  Acquire, false);
   610   case vmIntrinsics::_putCharVolatile:          return inline_unsafe_access(!is_native_ptr,  is_store, T_CHAR,     Volatile, false);
   609   case vmIntrinsics::_getByteAcquire:           return inline_unsafe_access(!is_store, T_BYTE,     Acquire, false);
   611   case vmIntrinsics::_putIntVolatile:           return inline_unsafe_access(!is_native_ptr,  is_store, T_INT,      Volatile, false);
   610   case vmIntrinsics::_getShortAcquire:          return inline_unsafe_access(!is_store, T_SHORT,    Acquire, false);
   612   case vmIntrinsics::_putLongVolatile:          return inline_unsafe_access(!is_native_ptr,  is_store, T_LONG,     Volatile, false);
   611   case vmIntrinsics::_getCharAcquire:           return inline_unsafe_access(!is_store, T_CHAR,     Acquire, false);
   613   case vmIntrinsics::_putFloatVolatile:         return inline_unsafe_access(!is_native_ptr,  is_store, T_FLOAT,    Volatile, false);
   612   case vmIntrinsics::_getIntAcquire:            return inline_unsafe_access(!is_store, T_INT,      Acquire, false);
   614   case vmIntrinsics::_putDoubleVolatile:        return inline_unsafe_access(!is_native_ptr,  is_store, T_DOUBLE,   Volatile, false);
   613   case vmIntrinsics::_getLongAcquire:           return inline_unsafe_access(!is_store, T_LONG,     Acquire, false);
   615 
   614   case vmIntrinsics::_getFloatAcquire:          return inline_unsafe_access(!is_store, T_FLOAT,    Acquire, false);
   616   case vmIntrinsics::_getShortUnaligned:        return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT,    Relaxed, true);
   615   case vmIntrinsics::_getDoubleAcquire:         return inline_unsafe_access(!is_store, T_DOUBLE,   Acquire, false);
   617   case vmIntrinsics::_getCharUnaligned:         return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR,     Relaxed, true);
   616 
   618   case vmIntrinsics::_getIntUnaligned:          return inline_unsafe_access(!is_native_ptr, !is_store, T_INT,      Relaxed, true);
   617   case vmIntrinsics::_putObjectRelease:         return inline_unsafe_access( is_store, T_OBJECT,   Release, false);
   619   case vmIntrinsics::_getLongUnaligned:         return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG,     Relaxed, true);
   618   case vmIntrinsics::_putBooleanRelease:        return inline_unsafe_access( is_store, T_BOOLEAN,  Release, false);
   620 
   619   case vmIntrinsics::_putByteRelease:           return inline_unsafe_access( is_store, T_BYTE,     Release, false);
   621   case vmIntrinsics::_putShortUnaligned:        return inline_unsafe_access(!is_native_ptr,  is_store, T_SHORT,    Relaxed, true);
   620   case vmIntrinsics::_putShortRelease:          return inline_unsafe_access( is_store, T_SHORT,    Release, false);
   622   case vmIntrinsics::_putCharUnaligned:         return inline_unsafe_access(!is_native_ptr,  is_store, T_CHAR,     Relaxed, true);
   621   case vmIntrinsics::_putCharRelease:           return inline_unsafe_access( is_store, T_CHAR,     Release, false);
   623   case vmIntrinsics::_putIntUnaligned:          return inline_unsafe_access(!is_native_ptr,  is_store, T_INT,      Relaxed, true);
   622   case vmIntrinsics::_putIntRelease:            return inline_unsafe_access( is_store, T_INT,      Release, false);
   624   case vmIntrinsics::_putLongUnaligned:         return inline_unsafe_access(!is_native_ptr,  is_store, T_LONG,     Relaxed, true);
   623   case vmIntrinsics::_putLongRelease:           return inline_unsafe_access( is_store, T_LONG,     Release, false);
   625 
   624   case vmIntrinsics::_putFloatRelease:          return inline_unsafe_access( is_store, T_FLOAT,    Release, false);
   626   case vmIntrinsics::_getObjectAcquire:         return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT,   Acquire, false);
   625   case vmIntrinsics::_putDoubleRelease:         return inline_unsafe_access( is_store, T_DOUBLE,   Release, false);
   627   case vmIntrinsics::_getBooleanAcquire:        return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN,  Acquire, false);
   626 
   628   case vmIntrinsics::_getByteAcquire:           return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE,     Acquire, false);
   627   case vmIntrinsics::_getObjectOpaque:          return inline_unsafe_access(!is_store, T_OBJECT,   Opaque, false);
   629   case vmIntrinsics::_getShortAcquire:          return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT,    Acquire, false);
   628   case vmIntrinsics::_getBooleanOpaque:         return inline_unsafe_access(!is_store, T_BOOLEAN,  Opaque, false);
   630   case vmIntrinsics::_getCharAcquire:           return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR,     Acquire, false);
   629   case vmIntrinsics::_getByteOpaque:            return inline_unsafe_access(!is_store, T_BYTE,     Opaque, false);
   631   case vmIntrinsics::_getIntAcquire:            return inline_unsafe_access(!is_native_ptr, !is_store, T_INT,      Acquire, false);
   630   case vmIntrinsics::_getShortOpaque:           return inline_unsafe_access(!is_store, T_SHORT,    Opaque, false);
   632   case vmIntrinsics::_getLongAcquire:           return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG,     Acquire, false);
   631   case vmIntrinsics::_getCharOpaque:            return inline_unsafe_access(!is_store, T_CHAR,     Opaque, false);
   633   case vmIntrinsics::_getFloatAcquire:          return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT,    Acquire, false);
   632   case vmIntrinsics::_getIntOpaque:             return inline_unsafe_access(!is_store, T_INT,      Opaque, false);
   634   case vmIntrinsics::_getDoubleAcquire:         return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE,   Acquire, false);
   633   case vmIntrinsics::_getLongOpaque:            return inline_unsafe_access(!is_store, T_LONG,     Opaque, false);
   635 
   634   case vmIntrinsics::_getFloatOpaque:           return inline_unsafe_access(!is_store, T_FLOAT,    Opaque, false);
   636   case vmIntrinsics::_putObjectRelease:         return inline_unsafe_access(!is_native_ptr,  is_store, T_OBJECT,   Release, false);
   635   case vmIntrinsics::_getDoubleOpaque:          return inline_unsafe_access(!is_store, T_DOUBLE,   Opaque, false);
   637   case vmIntrinsics::_putBooleanRelease:        return inline_unsafe_access(!is_native_ptr,  is_store, T_BOOLEAN,  Release, false);
   636 
   638   case vmIntrinsics::_putByteRelease:           return inline_unsafe_access(!is_native_ptr,  is_store, T_BYTE,     Release, false);
   637   case vmIntrinsics::_putObjectOpaque:          return inline_unsafe_access( is_store, T_OBJECT,   Opaque, false);
   639   case vmIntrinsics::_putShortRelease:          return inline_unsafe_access(!is_native_ptr,  is_store, T_SHORT,    Release, false);
   638   case vmIntrinsics::_putBooleanOpaque:         return inline_unsafe_access( is_store, T_BOOLEAN,  Opaque, false);
   640   case vmIntrinsics::_putCharRelease:           return inline_unsafe_access(!is_native_ptr,  is_store, T_CHAR,     Release, false);
   639   case vmIntrinsics::_putByteOpaque:            return inline_unsafe_access( is_store, T_BYTE,     Opaque, false);
   641   case vmIntrinsics::_putIntRelease:            return inline_unsafe_access(!is_native_ptr,  is_store, T_INT,      Release, false);
   640   case vmIntrinsics::_putShortOpaque:           return inline_unsafe_access( is_store, T_SHORT,    Opaque, false);
   642   case vmIntrinsics::_putLongRelease:           return inline_unsafe_access(!is_native_ptr,  is_store, T_LONG,     Release, false);
   641   case vmIntrinsics::_putCharOpaque:            return inline_unsafe_access( is_store, T_CHAR,     Opaque, false);
   643   case vmIntrinsics::_putFloatRelease:          return inline_unsafe_access(!is_native_ptr,  is_store, T_FLOAT,    Release, false);
   642   case vmIntrinsics::_putIntOpaque:             return inline_unsafe_access( is_store, T_INT,      Opaque, false);
   644   case vmIntrinsics::_putDoubleRelease:         return inline_unsafe_access(!is_native_ptr,  is_store, T_DOUBLE,   Release, false);
   643   case vmIntrinsics::_putLongOpaque:            return inline_unsafe_access( is_store, T_LONG,     Opaque, false);
   645 
   644   case vmIntrinsics::_putFloatOpaque:           return inline_unsafe_access( is_store, T_FLOAT,    Opaque, false);
   646   case vmIntrinsics::_getObjectOpaque:          return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT,   Opaque, false);
   645   case vmIntrinsics::_putDoubleOpaque:          return inline_unsafe_access( is_store, T_DOUBLE,   Opaque, false);
   647   case vmIntrinsics::_getBooleanOpaque:         return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN,  Opaque, false);
       
   648   case vmIntrinsics::_getByteOpaque:            return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE,     Opaque, false);
       
   649   case vmIntrinsics::_getShortOpaque:           return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT,    Opaque, false);
       
   650   case vmIntrinsics::_getCharOpaque:            return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR,     Opaque, false);
       
   651   case vmIntrinsics::_getIntOpaque:             return inline_unsafe_access(!is_native_ptr, !is_store, T_INT,      Opaque, false);
       
   652   case vmIntrinsics::_getLongOpaque:            return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG,     Opaque, false);
       
   653   case vmIntrinsics::_getFloatOpaque:           return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT,    Opaque, false);
       
   654   case vmIntrinsics::_getDoubleOpaque:          return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE,   Opaque, false);
       
   655 
       
   656   case vmIntrinsics::_putObjectOpaque:          return inline_unsafe_access(!is_native_ptr,  is_store, T_OBJECT,   Opaque, false);
       
   657   case vmIntrinsics::_putBooleanOpaque:         return inline_unsafe_access(!is_native_ptr,  is_store, T_BOOLEAN,  Opaque, false);
       
   658   case vmIntrinsics::_putByteOpaque:            return inline_unsafe_access(!is_native_ptr,  is_store, T_BYTE,     Opaque, false);
       
   659   case vmIntrinsics::_putShortOpaque:           return inline_unsafe_access(!is_native_ptr,  is_store, T_SHORT,    Opaque, false);
       
   660   case vmIntrinsics::_putCharOpaque:            return inline_unsafe_access(!is_native_ptr,  is_store, T_CHAR,     Opaque, false);
       
   661   case vmIntrinsics::_putIntOpaque:             return inline_unsafe_access(!is_native_ptr,  is_store, T_INT,      Opaque, false);
       
   662   case vmIntrinsics::_putLongOpaque:            return inline_unsafe_access(!is_native_ptr,  is_store, T_LONG,     Opaque, false);
       
   663   case vmIntrinsics::_putFloatOpaque:           return inline_unsafe_access(!is_native_ptr,  is_store, T_FLOAT,    Opaque, false);
       
   664   case vmIntrinsics::_putDoubleOpaque:          return inline_unsafe_access(!is_native_ptr,  is_store, T_DOUBLE,   Opaque, false);
       
   665 
   646 
   666   case vmIntrinsics::_compareAndSwapObject:             return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap,      Volatile);
   647   case vmIntrinsics::_compareAndSwapObject:             return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap,      Volatile);
   667   case vmIntrinsics::_compareAndSwapInt:                return inline_unsafe_load_store(T_INT,    LS_cmp_swap,      Volatile);
   648   case vmIntrinsics::_compareAndSwapInt:                return inline_unsafe_load_store(T_INT,    LS_cmp_swap,      Volatile);
   668   case vmIntrinsics::_compareAndSwapLong:               return inline_unsafe_load_store(T_LONG,   LS_cmp_swap,      Volatile);
   649   case vmIntrinsics::_compareAndSwapLong:               return inline_unsafe_load_store(T_LONG,   LS_cmp_swap,      Volatile);
   669 
   650 
  2194   return true;
  2175   return true;
  2195 }
  2176 }
  2196 
  2177 
  2197 //----------------------------inline_unsafe_access----------------------------
  2178 //----------------------------inline_unsafe_access----------------------------
  2198 
  2179 
  2199 const static BasicType T_ADDRESS_HOLDER = T_LONG;
       
  2200 
       
  2201 // Helper that guards and inserts a pre-barrier.
  2180 // Helper that guards and inserts a pre-barrier.
  2202 void LibraryCallKit::insert_pre_barrier(Node* base_oop, Node* offset,
  2181 void LibraryCallKit::insert_pre_barrier(Node* base_oop, Node* offset,
  2203                                         Node* pre_val, bool need_mem_bar) {
  2182                                         Node* pre_val, bool need_mem_bar) {
  2204   // We could be accessing the referent field of a reference object. If so, when G1
  2183   // We could be accessing the referent field of a reference object. If so, when G1
  2205   // is enabled, we need to log the value in the referent field in an SATB buffer.
  2184   // is enabled, we need to log the value in the referent field in an SATB buffer.
  2296   final_sync(ideal);
  2275   final_sync(ideal);
  2297 #undef __
  2276 #undef __
  2298 }
  2277 }
  2299 
  2278 
  2300 
  2279 
  2301 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr) {
  2280 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) {
  2302   // Attempt to infer a sharper value type from the offset and base type.
  2281   // Attempt to infer a sharper value type from the offset and base type.
  2303   ciKlass* sharpened_klass = NULL;
  2282   ciKlass* sharpened_klass = NULL;
  2304 
  2283 
  2305   // See if it is an instance field, with an object type.
  2284   // See if it is an instance field, with an object type.
  2306   if (alias_type->field() != NULL) {
  2285   if (alias_type->field() != NULL) {
  2307     assert(!is_native_ptr, "native pointer op cannot use a java address");
       
  2308     if (alias_type->field()->type()->is_klass()) {
  2286     if (alias_type->field()->type()->is_klass()) {
  2309       sharpened_klass = alias_type->field()->type()->as_klass();
  2287       sharpened_klass = alias_type->field()->type()->as_klass();
  2310     }
  2288     }
  2311   }
  2289   }
  2312 
  2290 
  2335     return tjp;
  2313     return tjp;
  2336   }
  2314   }
  2337   return NULL;
  2315   return NULL;
  2338 }
  2316 }
  2339 
  2317 
  2340 bool LibraryCallKit::inline_unsafe_access(const bool is_native_ptr, bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) {
  2318 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) {
  2341   if (callee()->is_static())  return false;  // caller must have the capability!
  2319   if (callee()->is_static())  return false;  // caller must have the capability!
  2342   guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads");
  2320   guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads");
  2343   guarantee( is_store || kind != Release, "Release accesses can be produced only for stores");
  2321   guarantee( is_store || kind != Release, "Release accesses can be produced only for stores");
  2344   assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type");
  2322   assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type");
  2345 
  2323 
  2350     ciSignature* sig = callee()->signature();
  2328     ciSignature* sig = callee()->signature();
  2351 #ifdef ASSERT
  2329 #ifdef ASSERT
  2352     if (!is_store) {
  2330     if (!is_store) {
  2353       // Object getObject(Object base, int/long offset), etc.
  2331       // Object getObject(Object base, int/long offset), etc.
  2354       BasicType rtype = sig->return_type()->basic_type();
  2332       BasicType rtype = sig->return_type()->basic_type();
  2355       if (rtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::getAddress_name())
       
  2356           rtype = T_ADDRESS;  // it is really a C void*
       
  2357       assert(rtype == type, "getter must return the expected value");
  2333       assert(rtype == type, "getter must return the expected value");
  2358       if (!is_native_ptr) {
  2334       assert(sig->count() == 2, "oop getter has 2 arguments");
  2359         assert(sig->count() == 2, "oop getter has 2 arguments");
  2335       assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object");
  2360         assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object");
  2336       assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct");
  2361         assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct");
       
  2362       } else {
       
  2363         assert(sig->count() == 1, "native getter has 1 argument");
       
  2364         assert(sig->type_at(0)->basic_type() == T_LONG, "getter base is long");
       
  2365       }
       
  2366     } else {
  2337     } else {
  2367       // void putObject(Object base, int/long offset, Object x), etc.
  2338       // void putObject(Object base, int/long offset, Object x), etc.
  2368       assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value");
  2339       assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value");
  2369       if (!is_native_ptr) {
  2340       assert(sig->count() == 3, "oop putter has 3 arguments");
  2370         assert(sig->count() == 3, "oop putter has 3 arguments");
  2341       assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object");
  2371         assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object");
  2342       assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct");
  2372         assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct");
       
  2373       } else {
       
  2374         assert(sig->count() == 2, "native putter has 2 arguments");
       
  2375         assert(sig->type_at(0)->basic_type() == T_LONG, "putter base is long");
       
  2376       }
       
  2377       BasicType vtype = sig->type_at(sig->count()-1)->basic_type();
  2343       BasicType vtype = sig->type_at(sig->count()-1)->basic_type();
  2378       if (vtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::putAddress_name())
       
  2379         vtype = T_ADDRESS;  // it is really a C void*
       
  2380       assert(vtype == type, "putter must accept the expected value");
  2344       assert(vtype == type, "putter must accept the expected value");
  2381     }
  2345     }
  2382 #endif // ASSERT
  2346 #endif // ASSERT
  2383  }
  2347  }
  2384 #endif //PRODUCT
  2348 #endif //PRODUCT
  2391   Node* adr;
  2355   Node* adr;
  2392   Node* heap_base_oop = top();
  2356   Node* heap_base_oop = top();
  2393   Node* offset = top();
  2357   Node* offset = top();
  2394   Node* val;
  2358   Node* val;
  2395 
  2359 
  2396   if (!is_native_ptr) {
  2360   // The base is either a Java object or a value produced by Unsafe.staticFieldBase
  2397     // The base is either a Java object or a value produced by Unsafe.staticFieldBase
  2361   Node* base = argument(1);  // type: oop
  2398     Node* base = argument(1);  // type: oop
  2362   // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
  2399     // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
  2363   offset = argument(2);  // type: long
  2400     offset = argument(2);  // type: long
  2364   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
  2401     // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
  2365   // to be plain byte offsets, which are also the same as those accepted
  2402     // to be plain byte offsets, which are also the same as those accepted
  2366   // by oopDesc::field_base.
  2403     // by oopDesc::field_base.
  2367   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
  2404     assert(Unsafe_field_offset_to_byte_offset(11) == 11,
  2368          "fieldOffset must be byte-scaled");
  2405            "fieldOffset must be byte-scaled");
  2369   // 32-bit machines ignore the high half!
  2406     // 32-bit machines ignore the high half!
  2370   offset = ConvL2X(offset);
  2407     offset = ConvL2X(offset);
  2371   adr = make_unsafe_address(base, offset);
  2408     adr = make_unsafe_address(base, offset);
  2372   if (_gvn.type(base)->isa_ptr() != TypePtr::NULL_PTR) {
  2409     heap_base_oop = base;
  2373     heap_base_oop = base;
  2410     val = is_store ? argument(4) : NULL;
  2374   }
  2411   } else {
  2375   val = is_store ? argument(4) : NULL;
  2412     Node* ptr = argument(1);  // type: long
       
  2413     ptr = ConvL2X(ptr);  // adjust Java long to machine word
       
  2414     adr = make_unsafe_address(NULL, ptr);
       
  2415     val = is_store ? argument(3) : NULL;
       
  2416   }
       
  2417 
  2376 
  2418   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
  2377   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
  2419 
  2378 
  2420   // Try to categorize the address.  If it comes up as TypeJavaPtr::BOTTOM,
  2379   // Try to categorize the address.  If it comes up as TypeJavaPtr::BOTTOM,
  2421   // there was not enough information to nail it down.
  2380   // there was not enough information to nail it down.
  2492   // object (either by using Unsafe directly or through reflection)
  2451   // object (either by using Unsafe directly or through reflection)
  2493   // then, if G1 is enabled, we need to record the referent in an
  2452   // then, if G1 is enabled, we need to record the referent in an
  2494   // SATB log buffer using the pre-barrier mechanism.
  2453   // SATB log buffer using the pre-barrier mechanism.
  2495   // Also we need to add memory barrier to prevent commoning reads
  2454   // Also we need to add memory barrier to prevent commoning reads
  2496   // from this field across safepoint since GC can change its value.
  2455   // from this field across safepoint since GC can change its value.
  2497   bool need_read_barrier = !is_native_ptr && !is_store &&
  2456   bool need_read_barrier = !is_store &&
  2498                            offset != top() && heap_base_oop != top();
  2457                            offset != top() && heap_base_oop != top();
  2499 
  2458 
  2500   if (!is_store && type == T_OBJECT) {
  2459   if (!is_store && type == T_OBJECT) {
  2501     const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type, is_native_ptr);
  2460     const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);
  2502     if (tjp != NULL) {
  2461     if (tjp != NULL) {
  2503       value_type = tjp;
  2462       value_type = tjp;
  2504     }
  2463     }
  2505   }
  2464   }
  2506 
  2465