< prev index next >

src/hotspot/share/classfile/verificationType.cpp

Print this page

 45     default:
 46       ShouldNotReachHere();
 47       return bogus_type();
 48   }
 49 }
 50 
 51 bool VerificationType::resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
 52          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object, TRAPS) {
 53   HandleMark hm(THREAD);
 54   Klass* this_class;
 55   if (klass->is_hidden() && klass->name() == name) {
 56     this_class = klass;
 57   } else {
 58     this_class = SystemDictionary::resolve_or_fail(
 59       name, Handle(THREAD, klass->class_loader()), true, CHECK_false);
 60     if (log_is_enabled(Debug, class, resolve)) {
 61       Verifier::trace_class_resolution(this_class, klass);
 62     }
 63   }
 64 







 65   if (this_class->is_interface() && (!from_field_is_protected ||
 66       from_name != vmSymbols::java_lang_Object())) {
 67     // If we are not trying to access a protected field or method in
 68     // java.lang.Object then, for arrays, we only allow assignability
 69     // to interfaces java.lang.Cloneable and java.io.Serializable.
 70     // Otherwise, we treat interfaces as java.lang.Object.
 71     return !from_is_array ||
 72       this_class == vmClasses::Cloneable_klass() ||
 73       this_class == vmClasses::Serializable_klass();
 74   } else if (from_is_object) {
 75     Klass* from_class;
 76     if (klass->is_hidden() && klass->name() == from_name) {
 77       from_class = klass;
 78     } else {
 79       from_class = SystemDictionary::resolve_or_fail(
 80         from_name, Handle(THREAD, klass->class_loader()), true, CHECK_false);
 81       if (log_is_enabled(Debug, class, resolve)) {
 82         Verifier::trace_class_resolution(from_class, klass);
 83       }
 84     }
 85     return from_class->is_subclass_of(this_class);
 86   }
 87 
 88   return false;
 89 }

104     if (name() == vmSymbols::java_lang_Object()) {
105       // any object or array is assignable to java.lang.Object
106       return true;
107     }
108 
109     if (CDSConfig::is_dumping_archive()) {
110       if (SystemDictionaryShared::add_verification_constraint(klass,
111               name(), from.name(), from_field_is_protected, from.is_array(),
112               from.is_object())) {
113         // If add_verification_constraint() returns true, the resolution/check should be
114         // delayed until runtime.
115         return true;
116       }
117     }
118 
119     return resolve_and_check_assignability(klass, name(), from.name(),
120           from_field_is_protected, from.is_array(), from.is_object(), THREAD);
121   } else if (is_array() && from.is_array()) {
122     VerificationType comp_this = get_component(context);
123     VerificationType comp_from = from.get_component(context);

124     if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
125       return comp_this.is_component_assignable_from(comp_from, context,
126                                                     from_field_is_protected, THREAD);
127     }
128   }
129   return false;
130 }
131 
132 VerificationType VerificationType::get_component(ClassVerifier *context) const {
133   assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
134   SignatureStream ss(name(), false);
135   ss.skip_array_prefix(1);
136   switch (ss.type()) {
137     case T_BOOLEAN: return VerificationType(Boolean);
138     case T_BYTE:    return VerificationType(Byte);
139     case T_CHAR:    return VerificationType(Char);
140     case T_SHORT:   return VerificationType(Short);
141     case T_INT:     return VerificationType(Integer);
142     case T_LONG:    return VerificationType(Long);
143     case T_FLOAT:   return VerificationType(Float);

 45     default:
 46       ShouldNotReachHere();
 47       return bogus_type();
 48   }
 49 }
 50 
 51 bool VerificationType::resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
 52          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object, TRAPS) {
 53   HandleMark hm(THREAD);
 54   Klass* this_class;
 55   if (klass->is_hidden() && klass->name() == name) {
 56     this_class = klass;
 57   } else {
 58     this_class = SystemDictionary::resolve_or_fail(
 59       name, Handle(THREAD, klass->class_loader()), true, CHECK_false);
 60     if (log_is_enabled(Debug, class, resolve)) {
 61       Verifier::trace_class_resolution(this_class, klass);
 62     }
 63   }
 64 
 65   // Need to do this check when called from CDS.
 66   // if (this_class->access_flags().is_primitive_class()) {
 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   //   return from_class == this_class;
 71   // }
 72   if (this_class->is_interface() && (!from_field_is_protected ||
 73       from_name != vmSymbols::java_lang_Object())) {
 74     // If we are not trying to access a protected field or method in
 75     // java.lang.Object then, for arrays, we only allow assignability
 76     // to interfaces java.lang.Cloneable and java.io.Serializable
 77     // Otherwise, we treat interfaces as java.lang.Object.
 78     return !from_is_array ||
 79       this_class == vmClasses::Cloneable_klass() ||
 80       this_class == vmClasses::Serializable_klass();
 81   } else if (from_is_object) {
 82     Klass* from_class;
 83     if (klass->is_hidden() && klass->name() == from_name) {
 84       from_class = klass;
 85     } else {
 86       from_class = SystemDictionary::resolve_or_fail(
 87         from_name, Handle(THREAD, klass->class_loader()), true, CHECK_false);
 88       if (log_is_enabled(Debug, class, resolve)) {
 89         Verifier::trace_class_resolution(from_class, klass);
 90       }
 91     }
 92     return from_class->is_subclass_of(this_class);
 93   }
 94 
 95   return false;
 96 }

111     if (name() == vmSymbols::java_lang_Object()) {
112       // any object or array is assignable to java.lang.Object
113       return true;
114     }
115 
116     if (CDSConfig::is_dumping_archive()) {
117       if (SystemDictionaryShared::add_verification_constraint(klass,
118               name(), from.name(), from_field_is_protected, from.is_array(),
119               from.is_object())) {
120         // If add_verification_constraint() returns true, the resolution/check should be
121         // delayed until runtime.
122         return true;
123       }
124     }
125 
126     return resolve_and_check_assignability(klass, name(), from.name(),
127           from_field_is_protected, from.is_array(), from.is_object(), THREAD);
128   } else if (is_array() && from.is_array()) {
129     VerificationType comp_this = get_component(context);
130     VerificationType comp_from = from.get_component(context);
131 
132     if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
133       return comp_this.is_component_assignable_from(comp_from, context,
134                                                     from_field_is_protected, THREAD);
135     }
136   }
137   return false;
138 }
139 
140 VerificationType VerificationType::get_component(ClassVerifier *context) const {
141   assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
142   SignatureStream ss(name(), false);
143   ss.skip_array_prefix(1);
144   switch (ss.type()) {
145     case T_BOOLEAN: return VerificationType(Boolean);
146     case T_BYTE:    return VerificationType(Byte);
147     case T_CHAR:    return VerificationType(Char);
148     case T_SHORT:   return VerificationType(Short);
149     case T_INT:     return VerificationType(Integer);
150     case T_LONG:    return VerificationType(Long);
151     case T_FLOAT:   return VerificationType(Float);
< prev index next >