annotate src/share/vm/classfile/verificationType.cpp @ 24225:a2dbb6fcc923

Added tag jvmci-0.33 for changeset 3aed4cb813f4
author Doug Simon <doug.simon@oracle.com>
date Fri, 18 Aug 2017 22:47:33 +0200
parents 50e62b688ddc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
23893
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1803
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1803
diff changeset
26 #include "classfile/symbolTable.hpp"
23893
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
27 #include "classfile/systemDictionaryShared.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1803
diff changeset
28 #include "classfile/verificationType.hpp"
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
29 #include "classfile/verifier.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 VerificationType VerificationType::from_tag(u1 tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 switch (tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 case ITEM_Top: return bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
34 case ITEM_Integer: return integer_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
35 case ITEM_Float: return float_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
36 case ITEM_Double: return double_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
37 case ITEM_Long: return long_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
38 case ITEM_Null: return null_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
39 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
40 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
41 return bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 bool VerificationType::is_reference_assignable_from(
18052
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
46 const VerificationType& from, ClassVerifier* context,
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
47 bool from_field_is_protected, TRAPS) const {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
48 instanceKlassHandle klass = context->current_class();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (from.is_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // null is assignable to any reference
a61af66fc99e Initial load
duke
parents:
diff changeset
51 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 } else if (is_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 } else if (name() == from.name()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 } else if (is_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // We need check the class hierarchy to check assignability
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if (name() == vmSymbols::java_lang_Object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // any object or array is assignable to java.lang.Object
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6605
diff changeset
62 Klass* obj = SystemDictionary::resolve_or_fail(
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
63 name(), Handle(THREAD, klass->class_loader()),
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
64 Handle(THREAD, klass->protection_domain()), true, CHECK_false);
1803
60f88489896f 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 1677
diff changeset
65 KlassHandle this_class(THREAD, obj);
60f88489896f 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 1677
diff changeset
66
18052
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
67 if (this_class->is_interface() && (!from_field_is_protected ||
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
68 from.name() != vmSymbols::java_lang_Object())) {
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
69 // If we are not trying to access a protected field or method in
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
70 // java.lang.Object then we treat interfaces as java.lang.Object,
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
71 // including java.lang.Cloneable and java.io.Serializable.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 } else if (from.is_object()) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6605
diff changeset
74 Klass* from_class = SystemDictionary::resolve_or_fail(
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
75 from.name(), Handle(THREAD, klass->class_loader()),
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
76 Handle(THREAD, klass->protection_domain()), true, CHECK_false);
23893
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
77 bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class());
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
78 if (result && DumpSharedSpaces) {
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
79 if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) {
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
80 // No need to save verification dependency. At run time, <klass> will be
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
81 // loaded from the archived only if <from_class> and <this_class> are
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
82 // also loaded from the archive. I.e., all 3 classes are exactly the same
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
83 // as we saw at archive creation time.
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
84 } else {
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
85 // Save the dependency. At run time, we need to check that the condition
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
86 // from_class->is_subclass_of(this_class() is still true.
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
87 Symbol* accessor_clsname = from.name();
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
88 Symbol* target_clsname = this_class()->name();
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
89 SystemDictionaryShared::add_verification_dependency(klass(),
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
90 accessor_clsname, target_clsname);
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
91 }
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
92 }
50e62b688ddc 8150752: Share Class Data
iklam
parents: 18052
diff changeset
93 return result;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 } else if (is_array() && from.is_array()) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
96 VerificationType comp_this = get_component(context, CHECK_false);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
97 VerificationType comp_from = from.get_component(context, CHECK_false);
1677
a5c9d63a187d 6964170: Verifier crashes
apangin
parents: 1552
diff changeset
98 if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
18052
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
99 return comp_this.is_assignable_from(comp_from, context,
2373a1f4987c 8036533: Method for correct defaults
hseigel
parents: 6725
diff changeset
100 from_field_is_protected, CHECK_false);
1677
a5c9d63a187d 6964170: Verifier crashes
apangin
parents: 1552
diff changeset
101 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
106 VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
108 Symbol* component;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
109 switch (name()->byte_at(1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 case 'Z': return VerificationType(Boolean);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 case 'B': return VerificationType(Byte);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 case 'C': return VerificationType(Char);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 case 'S': return VerificationType(Short);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case 'I': return VerificationType(Integer);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 case 'J': return VerificationType(Long);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 case 'F': return VerificationType(Float);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 case 'D': return VerificationType(Double);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 case '[':
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
119 component = context->create_temporary_symbol(
0
a61af66fc99e Initial load
duke
parents:
diff changeset
120 name(), 1, name()->utf8_length(),
a61af66fc99e Initial load
duke
parents:
diff changeset
121 CHECK_(VerificationType::bogus_type()));
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return VerificationType::reference_type(component);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 case 'L':
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
124 component = context->create_temporary_symbol(
0
a61af66fc99e Initial load
duke
parents:
diff changeset
125 name(), 2, name()->utf8_length() - 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
126 CHECK_(VerificationType::bogus_type()));
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return VerificationType::reference_type(component);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 default:
1677
a5c9d63a187d 6964170: Verifier crashes
apangin
parents: 1552
diff changeset
129 // Met an invalid type signature, e.g. [X
0
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return VerificationType::bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 void VerificationType::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 switch (_u._data) {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
136 case Bogus: st->print("top"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
137 case Category1: st->print("category1"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
138 case Category2: st->print("category2"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
139 case Category2_2nd: st->print("category2_2nd"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
140 case Boolean: st->print("boolean"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
141 case Byte: st->print("byte"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
142 case Short: st->print("short"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
143 case Char: st->print("char"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
144 case Integer: st->print("integer"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
145 case Float: st->print("float"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
146 case Long: st->print("long"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
147 case Double: st->print("double"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
148 case Long_2nd: st->print("long_2nd"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
149 case Double_2nd: st->print("double_2nd"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
150 case Null: st->print("null"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
151 case ReferenceQuery: st->print("reference type"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
152 case Category1Query: st->print("category1 type"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
153 case Category2Query: st->print("category2 type"); break;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
154 case Category2_2ndQuery: st->print("category2_2nd type"); break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (is_uninitialized_this()) {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
157 st->print("uninitializedThis");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158 } else if (is_uninitialized()) {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
159 st->print("uninitialized %d", bci());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else {
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
161 name()->print_value_on(st);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }