< prev index next >

src/hotspot/share/opto/library_call.cpp

Print this page




 168                                       RegionNode* region, int null_path,
 169                                       int offset);
 170   Node* load_klass_from_mirror(Node* mirror, bool never_see_null,
 171                                RegionNode* region, int null_path) {
 172     int offset = java_lang_Class::klass_offset_in_bytes();
 173     return load_klass_from_mirror_common(mirror, never_see_null,
 174                                          region, null_path,
 175                                          offset);
 176   }
 177   Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
 178                                      RegionNode* region, int null_path) {
 179     int offset = java_lang_Class::array_klass_offset_in_bytes();
 180     return load_klass_from_mirror_common(mirror, never_see_null,
 181                                          region, null_path,
 182                                          offset);
 183   }
 184   Node* generate_access_flags_guard(Node* kls,
 185                                     int modifier_mask, int modifier_bits,
 186                                     RegionNode* region);
 187   Node* generate_interface_guard(Node* kls, RegionNode* region);

 188   Node* generate_array_guard(Node* kls, RegionNode* region) {
 189     return generate_array_guard_common(kls, region, false, false);
 190   }
 191   Node* generate_non_array_guard(Node* kls, RegionNode* region) {
 192     return generate_array_guard_common(kls, region, false, true);
 193   }
 194   Node* generate_objArray_guard(Node* kls, RegionNode* region) {
 195     return generate_array_guard_common(kls, region, true, false);
 196   }
 197   Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
 198     return generate_array_guard_common(kls, region, true, true);
 199   }
 200   Node* generate_array_guard_common(Node* kls, RegionNode* region,
 201                                     bool obj_array, bool not_array);
 202   Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
 203   CallJavaNode* generate_method_call(vmIntrinsics::ID method_id,
 204                                      bool is_virtual = false, bool is_static = false);
 205   CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) {
 206     return generate_method_call(method_id, false, true);
 207   }


 756   case vmIntrinsics::_allocateInstance:         return inline_unsafe_allocate();
 757   case vmIntrinsics::_copyMemory:               return inline_unsafe_copyMemory();
 758   case vmIntrinsics::_getLength:                return inline_native_getLength();
 759   case vmIntrinsics::_copyOf:                   return inline_array_copyOf(false);
 760   case vmIntrinsics::_copyOfRange:              return inline_array_copyOf(true);
 761   case vmIntrinsics::_equalsB:                  return inline_array_equals(StrIntrinsicNode::LL);
 762   case vmIntrinsics::_equalsC:                  return inline_array_equals(StrIntrinsicNode::UU);
 763   case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex();
 764   case vmIntrinsics::_clone:                    return inline_native_clone(intrinsic()->is_virtual());
 765 
 766   case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true);
 767   case vmIntrinsics::_newArray:                   return inline_unsafe_newArray(false);
 768 
 769   case vmIntrinsics::_isAssignableFrom:         return inline_native_subtype_check();
 770 
 771   case vmIntrinsics::_isInstance:
 772   case vmIntrinsics::_getModifiers:
 773   case vmIntrinsics::_isInterface:
 774   case vmIntrinsics::_isArray:
 775   case vmIntrinsics::_isPrimitive:

 776   case vmIntrinsics::_getSuperclass:
 777   case vmIntrinsics::_getClassAccessFlags:      return inline_native_Class_query(intrinsic_id());
 778 
 779   case vmIntrinsics::_floatToRawIntBits:
 780   case vmIntrinsics::_floatToIntBits:
 781   case vmIntrinsics::_intBitsToFloat:
 782   case vmIntrinsics::_doubleToRawLongBits:
 783   case vmIntrinsics::_doubleToLongBits:
 784   case vmIntrinsics::_longBitsToDouble:         return inline_fp_conversions(intrinsic_id());
 785 
 786   case vmIntrinsics::_numberOfLeadingZeros_i:
 787   case vmIntrinsics::_numberOfLeadingZeros_l:
 788   case vmIntrinsics::_numberOfTrailingZeros_i:
 789   case vmIntrinsics::_numberOfTrailingZeros_l:
 790   case vmIntrinsics::_bitCount_i:
 791   case vmIntrinsics::_bitCount_l:
 792   case vmIntrinsics::_reverseBytes_i:
 793   case vmIntrinsics::_reverseBytes_l:
 794   case vmIntrinsics::_reverseBytes_s:
 795   case vmIntrinsics::_reverseBytes_c:           return inline_number_methods(intrinsic_id());


3126 }
3127 
3128 //--------------------(inline_native_Class_query helpers)---------------------
3129 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE_FAST, JVM_ACC_HAS_FINALIZER.
3130 // Fall through if (mods & mask) == bits, take the guard otherwise.
3131 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
3132   // Branch around if the given klass has the given modifier bit set.
3133   // Like generate_guard, adds a new path onto the region.
3134   Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset()));
3135   Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT, MemNode::unordered);
3136   Node* mask = intcon(modifier_mask);
3137   Node* bits = intcon(modifier_bits);
3138   Node* mbit = _gvn.transform(new AndINode(mods, mask));
3139   Node* cmp  = _gvn.transform(new CmpINode(mbit, bits));
3140   Node* bol  = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
3141   return generate_fair_guard(bol, region);
3142 }
3143 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
3144   return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region);
3145 }



3146 
3147 //-------------------------inline_native_Class_query-------------------
3148 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
3149   const Type* return_type = TypeInt::BOOL;
3150   Node* prim_return_value = top();  // what happens if it's a primitive class?
3151   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
3152   bool expect_prim = false;     // most of these guys expect to work on refs
3153 
3154   enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT };
3155 
3156   Node* mirror = argument(0);
3157   Node* obj    = top();
3158 
3159   switch (id) {
3160   case vmIntrinsics::_isInstance:
3161     // nothing is an instance of a primitive type
3162     prim_return_value = intcon(0);
3163     obj = argument(1);
3164     break;
3165   case vmIntrinsics::_getModifiers:
3166     prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
3167     assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line");
3168     return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin);
3169     break;
3170   case vmIntrinsics::_isInterface:
3171     prim_return_value = intcon(0);
3172     break;
3173   case vmIntrinsics::_isArray:
3174     prim_return_value = intcon(0);
3175     expect_prim = true;  // cf. ObjectStreamClass.getClassSignature
3176     break;
3177   case vmIntrinsics::_isPrimitive:
3178     prim_return_value = intcon(1);
3179     expect_prim = true;  // obviously
3180     break;



3181   case vmIntrinsics::_getSuperclass:
3182     prim_return_value = null();
3183     return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
3184     break;
3185   case vmIntrinsics::_getClassAccessFlags:
3186     prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
3187     return_type = TypeInt::INT;  // not bool!  6297094
3188     break;
3189   default:
3190     fatal_unexpected_iid(id);
3191     break;
3192   }
3193 
3194   const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
3195   if (mirror_con == NULL)  return false;  // cannot happen?
3196 
3197 #ifndef PRODUCT
3198   if (C->print_intrinsics() || C->print_inlining()) {
3199     ciType* k = mirror_con->java_mirror_type();
3200     if (k) {


3252     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3253     if (generate_interface_guard(kls, region) != NULL)
3254       // A guard was added.  If the guard is taken, it was an interface.
3255       phi->add_req(intcon(1));
3256     // If we fall through, it's a plain class.
3257     query_value = intcon(0);
3258     break;
3259 
3260   case vmIntrinsics::_isArray:
3261     // (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
3262     if (generate_array_guard(kls, region) != NULL)
3263       // A guard was added.  If the guard is taken, it was an array.
3264       phi->add_req(intcon(1));
3265     // If we fall through, it's a plain class.
3266     query_value = intcon(0);
3267     break;
3268 
3269   case vmIntrinsics::_isPrimitive:
3270     query_value = intcon(0); // "normal" path produces false
3271     break;










3272 
3273   case vmIntrinsics::_getSuperclass:
3274     // The rules here are somewhat unfortunate, but we can still do better
3275     // with random logic than with a JNI call.
3276     // Interfaces store null or Object as _super, but must report null.
3277     // Arrays store an intermediate super as _super, but must report Object.
3278     // Other types can report the actual _super.
3279     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3280     if (generate_interface_guard(kls, region) != NULL)
3281       // A guard was added.  If the guard is taken, it was an interface.
3282       phi->add_req(null());
3283     if (generate_array_guard(kls, region) != NULL)
3284       // A guard was added.  If the guard is taken, it was an array.
3285       phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
3286     // If we fall through, it's a plain class.  Get its _super.
3287     p = basic_plus_adr(kls, in_bytes(Klass::super_offset()));
3288     kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL));
3289     null_ctl = top();
3290     kls = null_check_oop(kls, &null_ctl);
3291     if (null_ctl != top()) {




 168                                       RegionNode* region, int null_path,
 169                                       int offset);
 170   Node* load_klass_from_mirror(Node* mirror, bool never_see_null,
 171                                RegionNode* region, int null_path) {
 172     int offset = java_lang_Class::klass_offset_in_bytes();
 173     return load_klass_from_mirror_common(mirror, never_see_null,
 174                                          region, null_path,
 175                                          offset);
 176   }
 177   Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
 178                                      RegionNode* region, int null_path) {
 179     int offset = java_lang_Class::array_klass_offset_in_bytes();
 180     return load_klass_from_mirror_common(mirror, never_see_null,
 181                                          region, null_path,
 182                                          offset);
 183   }
 184   Node* generate_access_flags_guard(Node* kls,
 185                                     int modifier_mask, int modifier_bits,
 186                                     RegionNode* region);
 187   Node* generate_interface_guard(Node* kls, RegionNode* region);
 188   Node* generate_hidden_class_guard(Node* kls, RegionNode* region);
 189   Node* generate_array_guard(Node* kls, RegionNode* region) {
 190     return generate_array_guard_common(kls, region, false, false);
 191   }
 192   Node* generate_non_array_guard(Node* kls, RegionNode* region) {
 193     return generate_array_guard_common(kls, region, false, true);
 194   }
 195   Node* generate_objArray_guard(Node* kls, RegionNode* region) {
 196     return generate_array_guard_common(kls, region, true, false);
 197   }
 198   Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
 199     return generate_array_guard_common(kls, region, true, true);
 200   }
 201   Node* generate_array_guard_common(Node* kls, RegionNode* region,
 202                                     bool obj_array, bool not_array);
 203   Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
 204   CallJavaNode* generate_method_call(vmIntrinsics::ID method_id,
 205                                      bool is_virtual = false, bool is_static = false);
 206   CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) {
 207     return generate_method_call(method_id, false, true);
 208   }


 757   case vmIntrinsics::_allocateInstance:         return inline_unsafe_allocate();
 758   case vmIntrinsics::_copyMemory:               return inline_unsafe_copyMemory();
 759   case vmIntrinsics::_getLength:                return inline_native_getLength();
 760   case vmIntrinsics::_copyOf:                   return inline_array_copyOf(false);
 761   case vmIntrinsics::_copyOfRange:              return inline_array_copyOf(true);
 762   case vmIntrinsics::_equalsB:                  return inline_array_equals(StrIntrinsicNode::LL);
 763   case vmIntrinsics::_equalsC:                  return inline_array_equals(StrIntrinsicNode::UU);
 764   case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex();
 765   case vmIntrinsics::_clone:                    return inline_native_clone(intrinsic()->is_virtual());
 766 
 767   case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true);
 768   case vmIntrinsics::_newArray:                   return inline_unsafe_newArray(false);
 769 
 770   case vmIntrinsics::_isAssignableFrom:         return inline_native_subtype_check();
 771 
 772   case vmIntrinsics::_isInstance:
 773   case vmIntrinsics::_getModifiers:
 774   case vmIntrinsics::_isInterface:
 775   case vmIntrinsics::_isArray:
 776   case vmIntrinsics::_isPrimitive:
 777   case vmIntrinsics::_isHiddenClass:
 778   case vmIntrinsics::_getSuperclass:
 779   case vmIntrinsics::_getClassAccessFlags:      return inline_native_Class_query(intrinsic_id());
 780 
 781   case vmIntrinsics::_floatToRawIntBits:
 782   case vmIntrinsics::_floatToIntBits:
 783   case vmIntrinsics::_intBitsToFloat:
 784   case vmIntrinsics::_doubleToRawLongBits:
 785   case vmIntrinsics::_doubleToLongBits:
 786   case vmIntrinsics::_longBitsToDouble:         return inline_fp_conversions(intrinsic_id());
 787 
 788   case vmIntrinsics::_numberOfLeadingZeros_i:
 789   case vmIntrinsics::_numberOfLeadingZeros_l:
 790   case vmIntrinsics::_numberOfTrailingZeros_i:
 791   case vmIntrinsics::_numberOfTrailingZeros_l:
 792   case vmIntrinsics::_bitCount_i:
 793   case vmIntrinsics::_bitCount_l:
 794   case vmIntrinsics::_reverseBytes_i:
 795   case vmIntrinsics::_reverseBytes_l:
 796   case vmIntrinsics::_reverseBytes_s:
 797   case vmIntrinsics::_reverseBytes_c:           return inline_number_methods(intrinsic_id());


3128 }
3129 
3130 //--------------------(inline_native_Class_query helpers)---------------------
3131 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE_FAST, JVM_ACC_HAS_FINALIZER.
3132 // Fall through if (mods & mask) == bits, take the guard otherwise.
3133 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
3134   // Branch around if the given klass has the given modifier bit set.
3135   // Like generate_guard, adds a new path onto the region.
3136   Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset()));
3137   Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT, MemNode::unordered);
3138   Node* mask = intcon(modifier_mask);
3139   Node* bits = intcon(modifier_bits);
3140   Node* mbit = _gvn.transform(new AndINode(mods, mask));
3141   Node* cmp  = _gvn.transform(new CmpINode(mbit, bits));
3142   Node* bol  = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
3143   return generate_fair_guard(bol, region);
3144 }
3145 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
3146   return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region);
3147 }
3148 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) {
3149   return generate_access_flags_guard(kls, JVM_ACC_IS_HIDDEN_CLASS, 0, region);
3150 }
3151 
3152 //-------------------------inline_native_Class_query-------------------
3153 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
3154   const Type* return_type = TypeInt::BOOL;
3155   Node* prim_return_value = top();  // what happens if it's a primitive class?
3156   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
3157   bool expect_prim = false;     // most of these guys expect to work on refs
3158 
3159   enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT };
3160 
3161   Node* mirror = argument(0);
3162   Node* obj    = top();
3163 
3164   switch (id) {
3165   case vmIntrinsics::_isInstance:
3166     // nothing is an instance of a primitive type
3167     prim_return_value = intcon(0);
3168     obj = argument(1);
3169     break;
3170   case vmIntrinsics::_getModifiers:
3171     prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
3172     assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line");
3173     return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin);
3174     break;
3175   case vmIntrinsics::_isInterface:
3176     prim_return_value = intcon(0);
3177     break;
3178   case vmIntrinsics::_isArray:
3179     prim_return_value = intcon(0);
3180     expect_prim = true;  // cf. ObjectStreamClass.getClassSignature
3181     break;
3182   case vmIntrinsics::_isPrimitive:
3183     prim_return_value = intcon(1);
3184     expect_prim = true;  // obviously
3185     break;
3186   case vmIntrinsics::_isHiddenClass:
3187     prim_return_value = intcon(0);
3188     break;
3189   case vmIntrinsics::_getSuperclass:
3190     prim_return_value = null();
3191     return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
3192     break;
3193   case vmIntrinsics::_getClassAccessFlags:
3194     prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
3195     return_type = TypeInt::INT;  // not bool!  6297094
3196     break;
3197   default:
3198     fatal_unexpected_iid(id);
3199     break;
3200   }
3201 
3202   const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
3203   if (mirror_con == NULL)  return false;  // cannot happen?
3204 
3205 #ifndef PRODUCT
3206   if (C->print_intrinsics() || C->print_inlining()) {
3207     ciType* k = mirror_con->java_mirror_type();
3208     if (k) {


3260     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3261     if (generate_interface_guard(kls, region) != NULL)
3262       // A guard was added.  If the guard is taken, it was an interface.
3263       phi->add_req(intcon(1));
3264     // If we fall through, it's a plain class.
3265     query_value = intcon(0);
3266     break;
3267 
3268   case vmIntrinsics::_isArray:
3269     // (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
3270     if (generate_array_guard(kls, region) != NULL)
3271       // A guard was added.  If the guard is taken, it was an array.
3272       phi->add_req(intcon(1));
3273     // If we fall through, it's a plain class.
3274     query_value = intcon(0);
3275     break;
3276 
3277   case vmIntrinsics::_isPrimitive:
3278     query_value = intcon(0); // "normal" path produces false
3279     break;
3280 
3281   case vmIntrinsics::_isHiddenClass:
3282     // (To verify this code sequence, check the asserts in JVM_IsHiddenClass.)
3283     if (generate_hidden_class_guard(kls, region) != NULL)
3284       // A guard was added.  If the guard is taken, it was an hidden class.
3285       phi->add_req(intcon(1));
3286     // If we fall through, it's a plain class.
3287     query_value = intcon(0);
3288     break;
3289 
3290 
3291   case vmIntrinsics::_getSuperclass:
3292     // The rules here are somewhat unfortunate, but we can still do better
3293     // with random logic than with a JNI call.
3294     // Interfaces store null or Object as _super, but must report null.
3295     // Arrays store an intermediate super as _super, but must report Object.
3296     // Other types can report the actual _super.
3297     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3298     if (generate_interface_guard(kls, region) != NULL)
3299       // A guard was added.  If the guard is taken, it was an interface.
3300       phi->add_req(null());
3301     if (generate_array_guard(kls, region) != NULL)
3302       // A guard was added.  If the guard is taken, it was an array.
3303       phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
3304     // If we fall through, it's a plain class.  Get its _super.
3305     p = basic_plus_adr(kls, in_bytes(Klass::super_offset()));
3306     kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL));
3307     null_ctl = top();
3308     kls = null_check_oop(kls, &null_ctl);
3309     if (null_ctl != top()) {


< prev index next >