< prev index next >

src/hotspot/share/classfile/verificationType.cpp

Print this page




  37     case ITEM_Float:   return float_type();
  38     case ITEM_Double:  return double_type();
  39     case ITEM_Long:    return long_type();
  40     case ITEM_Null:    return null_type();
  41     default:
  42       ShouldNotReachHere();
  43       return bogus_type();
  44   }
  45 }
  46 
  47 bool VerificationType::resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
  48          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object, TRAPS) {
  49   HandleMark hm(THREAD);
  50   Klass* this_class = SystemDictionary::resolve_or_fail(
  51       name, Handle(THREAD, klass->class_loader()),
  52       Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  53   if (log_is_enabled(Debug, class, resolve)) {
  54     Verifier::trace_class_resolution(this_class, klass);
  55   }
  56 

  57   if (this_class->is_interface() && (!from_field_is_protected ||
  58       from_name != vmSymbols::java_lang_Object())) {
  59     // If we are not trying to access a protected field or method in
  60     // java.lang.Object then, for arrays, we only allow assignability
  61     // to interfaces java.lang.Cloneable and java.io.Serializable.
  62     // Otherwise, we treat interfaces as java.lang.Object.
  63     return !from_is_array ||
  64       this_class == SystemDictionary::Cloneable_klass() ||
  65       this_class == SystemDictionary::Serializable_klass();
  66   } else if (from_is_object) {
  67     Klass* from_class = SystemDictionary::resolve_or_fail(
  68         from_name, Handle(THREAD, klass->class_loader()),
  69         Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  70     if (log_is_enabled(Debug, class, resolve)) {
  71       Verifier::trace_class_resolution(from_class, klass);
  72     }
  73     return InstanceKlass::cast(from_class)->is_subclass_of(this_class);
  74   }
  75 
  76   return false;


  92     if (name() == vmSymbols::java_lang_Object()) {
  93       // any object or array is assignable to java.lang.Object
  94       return true;
  95     }
  96 
  97     if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
  98       if (SystemDictionaryShared::add_verification_constraint(klass,
  99               name(), from.name(), from_field_is_protected, from.is_array(),
 100               from.is_object())) {
 101         // If add_verification_constraint() returns true, the resolution/check should be
 102         // delayed until runtime.
 103         return true;
 104       }
 105     }
 106 
 107     return resolve_and_check_assignability(klass, name(), from.name(),
 108           from_field_is_protected, from.is_array(), from.is_object(), THREAD);
 109   } else if (is_array() && from.is_array()) {
 110     VerificationType comp_this = get_component(context, CHECK_false);
 111     VerificationType comp_from = from.get_component(context, CHECK_false);





























 112     if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
 113       return comp_this.is_component_assignable_from(comp_from, context,
 114                                                     from_field_is_protected, THREAD);
 115     }
 116   }
 117   return false;
 118 }
 119 





























 120 VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const {
 121   assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
 122   Symbol* component;
 123   switch (name()->char_at(1)) {
 124     case 'Z': return VerificationType(Boolean);
 125     case 'B': return VerificationType(Byte);
 126     case 'C': return VerificationType(Char);
 127     case 'S': return VerificationType(Short);
 128     case 'I': return VerificationType(Integer);
 129     case 'J': return VerificationType(Long);
 130     case 'F': return VerificationType(Float);
 131     case 'D': return VerificationType(Double);
 132     case '[':
 133       component = context->create_temporary_symbol(
 134         name(), 1, name()->utf8_length());
 135       return VerificationType::reference_type(component);
 136     case 'L':
 137       component = context->create_temporary_symbol(
 138         name(), 2, name()->utf8_length() - 1);
 139       return VerificationType::reference_type(component);




 140     default:
 141       // Met an invalid type signature, e.g. [X
 142       return VerificationType::bogus_type();
 143   }
 144 }
 145 
 146 void VerificationType::print_on(outputStream* st) const {
 147   switch (_u._data) {
 148     case Bogus:            st->print("top"); break;
 149     case Category1:        st->print("category1"); break;
 150     case Category2:        st->print("category2"); break;
 151     case Category2_2nd:    st->print("category2_2nd"); break;
 152     case Boolean:          st->print("boolean"); break;
 153     case Byte:             st->print("byte"); break;
 154     case Short:            st->print("short"); break;
 155     case Char:             st->print("char"); break;
 156     case Integer:          st->print("integer"); break;
 157     case Float:            st->print("float"); break;
 158     case Long:             st->print("long"); break;
 159     case Double:           st->print("double"); break;
 160     case Long_2nd:         st->print("long_2nd"); break;
 161     case Double_2nd:       st->print("double_2nd"); break;
 162     case Null:             st->print("null"); break;
 163     case ReferenceQuery:   st->print("reference type"); break;


 164     case Category1Query:   st->print("category1 type"); break;
 165     case Category2Query:   st->print("category2 type"); break;
 166     case Category2_2ndQuery: st->print("category2_2nd type"); break;
 167     default:
 168       if (is_uninitialized_this()) {
 169         st->print("uninitializedThis");
 170       } else if (is_uninitialized()) {
 171         st->print("uninitialized %d", bci());


 172       } else {
 173         if (name() != NULL) {
 174           name()->print_value_on(st);
 175         } else {
 176           st->print_cr("NULL");
 177         }
 178       }
 179   }
 180 }


  37     case ITEM_Float:   return float_type();
  38     case ITEM_Double:  return double_type();
  39     case ITEM_Long:    return long_type();
  40     case ITEM_Null:    return null_type();
  41     default:
  42       ShouldNotReachHere();
  43       return bogus_type();
  44   }
  45 }
  46 
  47 bool VerificationType::resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
  48          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object, TRAPS) {
  49   HandleMark hm(THREAD);
  50   Klass* this_class = SystemDictionary::resolve_or_fail(
  51       name, Handle(THREAD, klass->class_loader()),
  52       Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  53   if (log_is_enabled(Debug, class, resolve)) {
  54     Verifier::trace_class_resolution(this_class, klass);
  55   }
  56 
  57   if (this_class->access_flags().is_value_type()) return false;
  58   if (this_class->is_interface() && (!from_field_is_protected ||
  59       from_name != vmSymbols::java_lang_Object())) {
  60     // If we are not trying to access a protected field or method in
  61     // java.lang.Object then, for arrays, we only allow assignability
  62     // to interfaces java.lang.Cloneable and java.io.Serializable.
  63     // Otherwise, we treat interfaces as java.lang.Object.
  64     return !from_is_array ||
  65       this_class == SystemDictionary::Cloneable_klass() ||
  66       this_class == SystemDictionary::Serializable_klass();
  67   } else if (from_is_object) {
  68     Klass* from_class = SystemDictionary::resolve_or_fail(
  69         from_name, Handle(THREAD, klass->class_loader()),
  70         Handle(THREAD, klass->protection_domain()), true, CHECK_false);
  71     if (log_is_enabled(Debug, class, resolve)) {
  72       Verifier::trace_class_resolution(from_class, klass);
  73     }
  74     return InstanceKlass::cast(from_class)->is_subclass_of(this_class);
  75   }
  76 
  77   return false;


  93     if (name() == vmSymbols::java_lang_Object()) {
  94       // any object or array is assignable to java.lang.Object
  95       return true;
  96     }
  97 
  98     if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
  99       if (SystemDictionaryShared::add_verification_constraint(klass,
 100               name(), from.name(), from_field_is_protected, from.is_array(),
 101               from.is_object())) {
 102         // If add_verification_constraint() returns true, the resolution/check should be
 103         // delayed until runtime.
 104         return true;
 105       }
 106     }
 107 
 108     return resolve_and_check_assignability(klass, name(), from.name(),
 109           from_field_is_protected, from.is_array(), from.is_object(), THREAD);
 110   } else if (is_array() && from.is_array()) {
 111     VerificationType comp_this = get_component(context, CHECK_false);
 112     VerificationType comp_from = from.get_component(context, CHECK_false);
 113 
 114 /*
 115     // This code implements non-covariance between value type arrays and both
 116     // arrays of objects and arrays of interface types.  If covariance is
 117     // supported for value type arrays then this code should be removed.
 118     if (comp_from.is_valuetype() && !comp_this.is_null() && comp_this.is_reference()) {
 119       // An array of value types is not assignable to an array of java.lang.Objects.
 120       if (comp_this.name() == vmSymbols::java_lang_Object()) {
 121         return false;
 122       }
 123 
 124       // Need to load 'comp_this' to see if it is an interface.
 125       InstanceKlass* klass = context->current_class();
 126       {
 127         HandleMark hm(THREAD);
 128         Klass* comp_this_class = SystemDictionary::resolve_or_fail(
 129             comp_this.name(), Handle(THREAD, klass->class_loader()),
 130             Handle(THREAD, klass->protection_domain()), true, CHECK_false);
 131         klass->class_loader_data()->record_dependency(comp_this_class);
 132         if (log_is_enabled(Debug, class, resolve)) {
 133           Verifier::trace_class_resolution(comp_this_class, klass);
 134         }
 135         // An array of value types is not assignable to an array of interface types.
 136         if (comp_this_class->is_interface()) {
 137           return false;
 138         }
 139       }
 140     }
 141 */
 142     if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
 143       return comp_this.is_component_assignable_from(comp_from, context,
 144                                                     from_field_is_protected, THREAD);
 145     }
 146   }
 147   return false;
 148 }
 149 
 150 bool VerificationType::is_valuetype_assignable_from(const VerificationType& from) const {
 151   // Check that 'from' is not null, is a value type, and is the same value type.
 152   assert(is_valuetype(), "called with a non-valuetype type");
 153   assert(!is_null(), "valuetype is not null");
 154   return (!from.is_null() && from.is_valuetype() && name() == from.name());
 155 }
 156 
 157 bool VerificationType::is_ref_assignable_from_value_type(const VerificationType& from, ClassVerifier* context, TRAPS) const {
 158   assert(!from.is_null(), "Value type should not be null");
 159   if (!is_null() && (name()->is_same_fundamental_type(from.name()) ||
 160       name() == vmSymbols::java_lang_Object())) {
 161     return true;
 162   }
 163 
 164   // Need to load 'this' to see if it is an interface.
 165   InstanceKlass* klass = context->current_class();
 166   {
 167     HandleMark hm(THREAD);
 168     Klass* this_class = SystemDictionary::resolve_or_fail(
 169         name(), Handle(THREAD, klass->class_loader()),
 170         Handle(THREAD, klass->protection_domain()), true, CHECK_false);
 171     klass->class_loader_data()->record_dependency(this_class);
 172     if (log_is_enabled(Debug, class, resolve)) {
 173       Verifier::trace_class_resolution(this_class, klass);
 174     }
 175     return (this_class->is_interface());
 176   }
 177 }
 178 
 179 VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const {
 180   assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
 181   Symbol* component;
 182   switch (name()->char_at(1)) {
 183     case 'Z': return VerificationType(Boolean);
 184     case 'B': return VerificationType(Byte);
 185     case 'C': return VerificationType(Char);
 186     case 'S': return VerificationType(Short);
 187     case 'I': return VerificationType(Integer);
 188     case 'J': return VerificationType(Long);
 189     case 'F': return VerificationType(Float);
 190     case 'D': return VerificationType(Double);
 191     case '[':
 192       component = context->create_temporary_symbol(
 193         name(), 1, name()->utf8_length());
 194       return VerificationType::reference_type(component);
 195     case 'L':
 196       component = context->create_temporary_symbol(
 197         name(), 2, name()->utf8_length() - 1);
 198       return VerificationType::reference_type(component);
 199     case 'Q':
 200       component = context->create_temporary_symbol(
 201         name(), 2, name()->utf8_length() - 1);
 202       return VerificationType::valuetype_type(component);
 203     default:
 204       // Met an invalid type signature, e.g. [X
 205       return VerificationType::bogus_type();
 206   }
 207 }
 208 
 209 void VerificationType::print_on(outputStream* st) const {
 210   switch (_u._data) {
 211     case Bogus:            st->print("top"); break;
 212     case Category1:        st->print("category1"); break;
 213     case Category2:        st->print("category2"); break;
 214     case Category2_2nd:    st->print("category2_2nd"); break;
 215     case Boolean:          st->print("boolean"); break;
 216     case Byte:             st->print("byte"); break;
 217     case Short:            st->print("short"); break;
 218     case Char:             st->print("char"); break;
 219     case Integer:          st->print("integer"); break;
 220     case Float:            st->print("float"); break;
 221     case Long:             st->print("long"); break;
 222     case Double:           st->print("double"); break;
 223     case Long_2nd:         st->print("long_2nd"); break;
 224     case Double_2nd:       st->print("double_2nd"); break;
 225     case Null:             st->print("null"); break;
 226     case ReferenceQuery:   st->print("reference type"); break;
 227     case ValueTypeQuery:   st->print("inline type"); break;
 228     case NonScalarQuery:   st->print("reference or inline type"); break;
 229     case Category1Query:   st->print("category1 type"); break;
 230     case Category2Query:   st->print("category2 type"); break;
 231     case Category2_2ndQuery: st->print("category2_2nd type"); break;
 232     default:
 233       if (is_uninitialized_this()) {
 234         st->print("uninitializedThis");
 235       } else if (is_uninitialized()) {
 236         st->print("uninitialized %d", bci());
 237       } else if (is_valuetype()) {
 238         name()->print_Qvalue_on(st);
 239       } else {
 240         if (name() != NULL) {
 241           name()->print_value_on(st);
 242         } else {
 243           st->print_cr("NULL");
 244         }
 245       }
 246   }
 247 }
< prev index next >