Wed, 24 Oct 2018 17:32:10 +0000
8212821: CHECK_ must be used in the rhs of an assignment statement within a block (round 2)
Summary: Correction of failed backport of JDK-8211394 via JDK-8212696.
Reviewed-by: dholmes, coffeys
1 /*
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "precompiled.hpp"
26 #include "classfile/symbolTable.hpp"
27 #include "classfile/systemDictionaryShared.hpp"
28 #include "classfile/verificationType.hpp"
29 #include "classfile/verifier.hpp"
31 VerificationType VerificationType::from_tag(u1 tag) {
32 switch (tag) {
33 case ITEM_Top: return bogus_type();
34 case ITEM_Integer: return integer_type();
35 case ITEM_Float: return float_type();
36 case ITEM_Double: return double_type();
37 case ITEM_Long: return long_type();
38 case ITEM_Null: return null_type();
39 default:
40 ShouldNotReachHere();
41 return bogus_type();
42 }
43 }
45 bool VerificationType::is_reference_assignable_from(
46 const VerificationType& from, ClassVerifier* context,
47 bool from_field_is_protected, TRAPS) const {
48 instanceKlassHandle klass = context->current_class();
49 if (from.is_null()) {
50 // null is assignable to any reference
51 return true;
52 } else if (is_null()) {
53 return false;
54 } else if (name() == from.name()) {
55 return true;
56 } else if (is_object()) {
57 // We need check the class hierarchy to check assignability
58 if (name() == vmSymbols::java_lang_Object()) {
59 // any object or array is assignable to java.lang.Object
60 return true;
61 }
62 Klass* obj = SystemDictionary::resolve_or_fail(
63 name(), Handle(THREAD, klass->class_loader()),
64 Handle(THREAD, klass->protection_domain()), true, CHECK_false);
65 KlassHandle this_class(THREAD, obj);
66 klass->class_loader_data()->record_dependency(obj, CHECK_false);
68 if (this_class->is_interface() && (!from_field_is_protected ||
69 from.name() != vmSymbols::java_lang_Object())) {
70 // If we are not trying to access a protected field or method in
71 // java.lang.Object then we treat interfaces as java.lang.Object,
72 // including java.lang.Cloneable and java.io.Serializable.
73 return true;
74 } else if (from.is_object()) {
75 Klass* from_class = SystemDictionary::resolve_or_fail(
76 from.name(), Handle(THREAD, klass->class_loader()),
77 Handle(THREAD, klass->protection_domain()), true, CHECK_false);
78 klass->class_loader_data()->record_dependency(from_class, CHECK_false);
79 bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class());
80 if (result && DumpSharedSpaces) {
81 if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) {
82 // No need to save verification dependency. At run time, <klass> will be
83 // loaded from the archived only if <from_class> and <this_class> are
84 // also loaded from the archive. I.e., all 3 classes are exactly the same
85 // as we saw at archive creation time.
86 } else {
87 // Save the dependency. At run time, we need to check that the condition
88 // from_class->is_subclass_of(this_class() is still true.
89 Symbol* accessor_clsname = from.name();
90 Symbol* target_clsname = this_class()->name();
91 SystemDictionaryShared::add_verification_dependency(klass(),
92 accessor_clsname, target_clsname);
93 }
94 }
95 return result;
96 }
97 } else if (is_array() && from.is_array()) {
98 VerificationType comp_this = get_component(context, CHECK_false);
99 VerificationType comp_from = from.get_component(context, CHECK_false);
100 if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
101 return comp_this.is_assignable_from(comp_from, context,
102 from_field_is_protected, THREAD);
103 }
104 }
105 return false;
106 }
108 VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const {
109 assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
110 Symbol* component;
111 switch (name()->byte_at(1)) {
112 case 'Z': return VerificationType(Boolean);
113 case 'B': return VerificationType(Byte);
114 case 'C': return VerificationType(Char);
115 case 'S': return VerificationType(Short);
116 case 'I': return VerificationType(Integer);
117 case 'J': return VerificationType(Long);
118 case 'F': return VerificationType(Float);
119 case 'D': return VerificationType(Double);
120 case '[':
121 component = context->create_temporary_symbol(
122 name(), 1, name()->utf8_length(),
123 CHECK_(VerificationType::bogus_type()));
124 return VerificationType::reference_type(component);
125 case 'L':
126 component = context->create_temporary_symbol(
127 name(), 2, name()->utf8_length() - 1,
128 CHECK_(VerificationType::bogus_type()));
129 return VerificationType::reference_type(component);
130 default:
131 // Met an invalid type signature, e.g. [X
132 return VerificationType::bogus_type();
133 }
134 }
136 void VerificationType::print_on(outputStream* st) const {
137 switch (_u._data) {
138 case Bogus: st->print("top"); break;
139 case Category1: st->print("category1"); break;
140 case Category2: st->print("category2"); break;
141 case Category2_2nd: st->print("category2_2nd"); break;
142 case Boolean: st->print("boolean"); break;
143 case Byte: st->print("byte"); break;
144 case Short: st->print("short"); break;
145 case Char: st->print("char"); break;
146 case Integer: st->print("integer"); break;
147 case Float: st->print("float"); break;
148 case Long: st->print("long"); break;
149 case Double: st->print("double"); break;
150 case Long_2nd: st->print("long_2nd"); break;
151 case Double_2nd: st->print("double_2nd"); break;
152 case Null: st->print("null"); break;
153 case ReferenceQuery: st->print("reference type"); break;
154 case Category1Query: st->print("category1 type"); break;
155 case Category2Query: st->print("category2 type"); break;
156 case Category2_2ndQuery: st->print("category2_2nd type"); break;
157 default:
158 if (is_uninitialized_this()) {
159 st->print("uninitializedThis");
160 } else if (is_uninitialized()) {
161 st->print("uninitialized %d", bci());
162 } else {
163 name()->print_value_on(st);
164 }
165 }
166 }