Mercurial > hg > graal-jvmci-8
annotate src/share/vm/classfile/verificationType.cpp @ 24218:719853999215 jvmci-0.32
Merge with jdk8u141-b15
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 14 Aug 2017 23:20:38 +0200 |
parents | 50e62b688ddc |
children |
rev | line source |
---|---|
0 | 1 /* |
23893 | 2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
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 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/symbolTable.hpp" | |
23893 | 27 #include "classfile/systemDictionaryShared.hpp" |
1972 | 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 | 30 |
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 } | |
44 | |
45 bool VerificationType::is_reference_assignable_from( | |
18052 | 46 const VerificationType& from, ClassVerifier* context, |
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 | 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 } | |
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 | 65 KlassHandle this_class(THREAD, obj); |
66 | |
18052 | 67 if (this_class->is_interface() && (!from_field_is_protected || |
68 from.name() != vmSymbols::java_lang_Object())) { | |
69 // If we are not trying to access a protected field or method in | |
70 // java.lang.Object then we treat interfaces as java.lang.Object, | |
71 // including java.lang.Cloneable and java.io.Serializable. | |
0 | 72 return true; |
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 | 77 bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class()); |
78 if (result && DumpSharedSpaces) { | |
79 if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) { | |
80 // No need to save verification dependency. At run time, <klass> will be | |
81 // loaded from the archived only if <from_class> and <this_class> are | |
82 // also loaded from the archive. I.e., all 3 classes are exactly the same | |
83 // as we saw at archive creation time. | |
84 } else { | |
85 // Save the dependency. At run time, we need to check that the condition | |
86 // from_class->is_subclass_of(this_class() is still true. | |
87 Symbol* accessor_clsname = from.name(); | |
88 Symbol* target_clsname = this_class()->name(); | |
89 SystemDictionaryShared::add_verification_dependency(klass(), | |
90 accessor_clsname, target_clsname); | |
91 } | |
92 } | |
93 return result; | |
0 | 94 } |
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 | 98 if (!comp_this.is_bogus() && !comp_from.is_bogus()) { |
18052 | 99 return comp_this.is_assignable_from(comp_from, context, |
100 from_field_is_protected, CHECK_false); | |
1677 | 101 } |
0 | 102 } |
103 return false; | |
104 } | |
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 | 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 | 109 switch (name()->byte_at(1)) { |
110 case 'Z': return VerificationType(Boolean); | |
111 case 'B': return VerificationType(Byte); | |
112 case 'C': return VerificationType(Char); | |
113 case 'S': return VerificationType(Short); | |
114 case 'I': return VerificationType(Integer); | |
115 case 'J': return VerificationType(Long); | |
116 case 'F': return VerificationType(Float); | |
117 case 'D': return VerificationType(Double); | |
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 | 120 name(), 1, name()->utf8_length(), |
121 CHECK_(VerificationType::bogus_type())); | |
122 return VerificationType::reference_type(component); | |
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 | 125 name(), 2, name()->utf8_length() - 1, |
126 CHECK_(VerificationType::bogus_type())); | |
127 return VerificationType::reference_type(component); | |
128 default: | |
1677 | 129 // Met an invalid type signature, e.g. [X |
0 | 130 return VerificationType::bogus_type(); |
131 } | |
132 } | |
133 | |
134 void VerificationType::print_on(outputStream* st) const { | |
135 switch (_u._data) { | |
6605 | 136 case Bogus: st->print("top"); break; |
137 case Category1: st->print("category1"); break; | |
138 case Category2: st->print("category2"); break; | |
139 case Category2_2nd: st->print("category2_2nd"); break; | |
140 case Boolean: st->print("boolean"); break; | |
141 case Byte: st->print("byte"); break; | |
142 case Short: st->print("short"); break; | |
143 case Char: st->print("char"); break; | |
144 case Integer: st->print("integer"); break; | |
145 case Float: st->print("float"); break; | |
146 case Long: st->print("long"); break; | |
147 case Double: st->print("double"); break; | |
148 case Long_2nd: st->print("long_2nd"); break; | |
149 case Double_2nd: st->print("double_2nd"); break; | |
150 case Null: st->print("null"); break; | |
151 case ReferenceQuery: st->print("reference type"); break; | |
152 case Category1Query: st->print("category1 type"); break; | |
153 case Category2Query: st->print("category2 type"); break; | |
154 case Category2_2ndQuery: st->print("category2_2nd type"); break; | |
0 | 155 default: |
156 if (is_uninitialized_this()) { | |
6605 | 157 st->print("uninitializedThis"); |
0 | 158 } else if (is_uninitialized()) { |
6605 | 159 st->print("uninitialized %d", bci()); |
0 | 160 } else { |
6605 | 161 name()->print_value_on(st); |
0 | 162 } |
163 } | |
164 } |