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 }
107 }
108
109 #if INCLUDE_CDS
110 if (CDSConfig::is_dumping_archive()) {
111 bool skip_assignability_check = false;
112 SystemDictionaryShared::add_verification_constraint(klass,
113 name(), from.name(), from_field_is_protected, from.is_array(),
114 from.is_object(), &skip_assignability_check);
115 if (skip_assignability_check) {
116 // We are not able to resolve name() or from.name(). The actual assignability check
117 // will be delayed until runtime.
118 return true;
119 }
120 }
121 #endif
122 return resolve_and_check_assignability(klass, name(), from.name(),
123 from_field_is_protected, from.is_array(), from.is_object(), THREAD);
124 } else if (is_array() && from.is_array()) {
125 VerificationType comp_this = get_component(context);
126 VerificationType comp_from = from.get_component(context);
127 if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
128 return comp_this.is_component_assignable_from(comp_from, context,
129 from_field_is_protected, THREAD);
130 }
131 }
132 return false;
133 }
134
135 VerificationType VerificationType::get_component(ClassVerifier *context) const {
136 assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
137 SignatureStream ss(name(), false);
138 ss.skip_array_prefix(1);
139 switch (ss.type()) {
140 case T_BOOLEAN: return VerificationType(Boolean);
141 case T_BYTE: return VerificationType(Byte);
142 case T_CHAR: return VerificationType(Char);
143 case T_SHORT: return VerificationType(Short);
144 case T_INT: return VerificationType(Integer);
145 case T_LONG: return VerificationType(Long);
146 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 }
114 }
115
116 #if INCLUDE_CDS
117 if (CDSConfig::is_dumping_archive()) {
118 bool skip_assignability_check = false;
119 SystemDictionaryShared::add_verification_constraint(klass,
120 name(), from.name(), from_field_is_protected, from.is_array(),
121 from.is_object(), &skip_assignability_check);
122 if (skip_assignability_check) {
123 // We are not able to resolve name() or from.name(). The actual assignability check
124 // will be delayed until runtime.
125 return true;
126 }
127 }
128 #endif
129 return resolve_and_check_assignability(klass, name(), from.name(),
130 from_field_is_protected, from.is_array(), from.is_object(), THREAD);
131 } else if (is_array() && from.is_array()) {
132 VerificationType comp_this = get_component(context);
133 VerificationType comp_from = from.get_component(context);
134
135 if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
136 return comp_this.is_component_assignable_from(comp_from, context,
137 from_field_is_protected, THREAD);
138 }
139 }
140 return false;
141 }
142
143 VerificationType VerificationType::get_component(ClassVerifier *context) const {
144 assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
145 SignatureStream ss(name(), false);
146 ss.skip_array_prefix(1);
147 switch (ss.type()) {
148 case T_BOOLEAN: return VerificationType(Boolean);
149 case T_BYTE: return VerificationType(Byte);
150 case T_CHAR: return VerificationType(Char);
151 case T_SHORT: return VerificationType(Short);
152 case T_INT: return VerificationType(Integer);
153 case T_LONG: return VerificationType(Long);
154 case T_FLOAT: return VerificationType(Float);
|