src/share/vm/classfile/verificationType.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/classfile

src/share/vm/classfile/verificationType.cpp

Print this page




  33     case ITEM_Integer: return integer_type();
  34     case ITEM_Float:   return float_type();
  35     case ITEM_Double:  return double_type();
  36     case ITEM_Long:    return long_type();
  37     case ITEM_Null:    return null_type();
  38     default:
  39       ShouldNotReachHere();
  40       return bogus_type();
  41   }
  42 }
  43 
  44 bool VerificationType::is_reference_assignable_from(
  45     const VerificationType& from, ClassVerifier* context,
  46     bool from_field_is_protected, TRAPS) const {
  47   instanceKlassHandle klass = context->current_class();
  48   if (from.is_null()) {
  49     // null is assignable to any reference
  50     return true;
  51   } else if (is_null()) {
  52     return false;
  53   } else if (name() == from.name()) {
  54     return true;
  55   } else if (is_object()) {
  56     // We need check the class hierarchy to check assignability
  57     if (name() == vmSymbols::java_lang_Object()) {
  58       // any object or array is assignable to java.lang.Object
  59       return true;
  60     }
  61     Klass* obj = SystemDictionary::resolve_or_fail(
  62         name(), Handle(THREAD, klass->class_loader()),
  63         Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  64     KlassHandle this_class(THREAD, obj);
  65 
  66     if (this_class->is_interface() && (!from_field_is_protected ||
  67         from.name() != vmSymbols::java_lang_Object())) {
  68       // If we are not trying to access a protected field or method in
  69       // java.lang.Object then we treat interfaces as java.lang.Object,
  70       // including java.lang.Cloneable and java.io.Serializable.
  71       return true;
  72     } else if (from.is_object()) {
  73       Klass* from_class = SystemDictionary::resolve_or_fail(
  74           from.name(), Handle(THREAD, klass->class_loader()),
  75           Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  76       return InstanceKlass::cast(from_class)->is_subclass_of(this_class());
  77     }
  78   } else if (is_array() && from.is_array()) {
  79     VerificationType comp_this = get_component(context, CHECK_false);
  80     VerificationType comp_from = from.get_component(context, CHECK_false);
  81     if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
  82       return comp_this.is_assignable_from(comp_from, context,
  83                                           from_field_is_protected, CHECK_false);
  84     }
  85   }
  86   return false;
  87 }




  33     case ITEM_Integer: return integer_type();
  34     case ITEM_Float:   return float_type();
  35     case ITEM_Double:  return double_type();
  36     case ITEM_Long:    return long_type();
  37     case ITEM_Null:    return null_type();
  38     default:
  39       ShouldNotReachHere();
  40       return bogus_type();
  41   }
  42 }
  43 
  44 bool VerificationType::is_reference_assignable_from(
  45     const VerificationType& from, ClassVerifier* context,
  46     bool from_field_is_protected, TRAPS) const {
  47   instanceKlassHandle klass = context->current_class();
  48   if (from.is_null()) {
  49     // null is assignable to any reference
  50     return true;
  51   } else if (is_null()) {
  52     return false;
  53   } else if (name()->equals(from.name())) {
  54     return true;
  55   } else if (is_object()) {
  56     // We need check the class hierarchy to check assignability
  57     if (name()->equals(vmSymbols::java_lang_Object())) {
  58       // any object or array is assignable to java.lang.Object
  59       return true;
  60     }
  61     Klass* obj = SystemDictionary::resolve_or_fail(
  62         name(), Handle(THREAD, klass->class_loader()),
  63         Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  64     KlassHandle this_class(THREAD, obj);
  65 
  66     if (this_class->is_interface() && (!from_field_is_protected ||
  67         from.name()->not_equals(vmSymbols::java_lang_Object()))) {
  68       // If we are not trying to access a protected field or method in
  69       // java.lang.Object then we treat interfaces as java.lang.Object,
  70       // including java.lang.Cloneable and java.io.Serializable.
  71       return true;
  72     } else if (from.is_object()) {
  73       Klass* from_class = SystemDictionary::resolve_or_fail(
  74           from.name(), Handle(THREAD, klass->class_loader()),
  75           Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  76       return InstanceKlass::cast(from_class)->is_subclass_of(this_class());
  77     }
  78   } else if (is_array() && from.is_array()) {
  79     VerificationType comp_this = get_component(context, CHECK_false);
  80     VerificationType comp_from = from.get_component(context, CHECK_false);
  81     if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
  82       return comp_this.is_assignable_from(comp_from, context,
  83                                           from_field_is_protected, CHECK_false);
  84     }
  85   }
  86   return false;
  87 }


src/share/vm/classfile/verificationType.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File