author | simonis |
Tue, 19 Jun 2018 09:43:53 +0200 | |
changeset 50625 | d9753e3db0c6 |
parent 49770 | 0a8a11767c3d |
child 51997 | 9ce37fa2e179 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49393 | 2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/symbolTable.hpp" |
|
39713 | 27 |
#include "classfile/systemDictionaryShared.hpp" |
7397 | 28 |
#include "classfile/verificationType.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
29 |
#include "classfile/verifier.hpp" |
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49393
diff
changeset
|
30 |
#include "logging/log.hpp" |
49393 | 31 |
#include "runtime/handles.inline.hpp" |
1 | 32 |
|
33 |
VerificationType VerificationType::from_tag(u1 tag) { |
|
34 |
switch (tag) { |
|
35 |
case ITEM_Top: return bogus_type(); |
|
36 |
case ITEM_Integer: return integer_type(); |
|
37 |
case ITEM_Float: return float_type(); |
|
38 |
case ITEM_Double: return double_type(); |
|
39 |
case ITEM_Long: return long_type(); |
|
40 |
case ITEM_Null: return null_type(); |
|
41 |
default: |
|
42 |
ShouldNotReachHere(); |
|
43 |
return bogus_type(); |
|
44 |
} |
|
45 |
} |
|
46 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
47 |
bool VerificationType::resolve_and_check_assignability(InstanceKlass* klass, Symbol* name, |
39713 | 48 |
Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object, TRAPS) { |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
39713
diff
changeset
|
49 |
HandleMark hm(THREAD); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
50 |
Klass* this_class = SystemDictionary::resolve_or_fail( |
39713 | 51 |
name, Handle(THREAD, klass->class_loader()), |
52 |
Handle(THREAD, klass->protection_domain()), true, CHECK_false); |
|
49770 | 53 |
klass->class_loader_data()->record_dependency(this_class); |
39713 | 54 |
if (log_is_enabled(Debug, class, resolve)) { |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
55 |
Verifier::trace_class_resolution(this_class, klass); |
39713 | 56 |
} |
57 |
||
58 |
if (this_class->is_interface() && (!from_field_is_protected || |
|
59 |
from_name != vmSymbols::java_lang_Object())) { |
|
60 |
// If we are not trying to access a protected field or method in |
|
61 |
// java.lang.Object then, for arrays, we only allow assignability |
|
62 |
// to interfaces java.lang.Cloneable and java.io.Serializable. |
|
63 |
// Otherwise, we treat interfaces as java.lang.Object. |
|
64 |
return !from_is_array || |
|
65 |
this_class == SystemDictionary::Cloneable_klass() || |
|
66 |
this_class == SystemDictionary::Serializable_klass(); |
|
67 |
} else if (from_is_object) { |
|
68 |
Klass* from_class = SystemDictionary::resolve_or_fail( |
|
69 |
from_name, Handle(THREAD, klass->class_loader()), |
|
70 |
Handle(THREAD, klass->protection_domain()), true, CHECK_false); |
|
49770 | 71 |
klass->class_loader_data()->record_dependency(from_class); |
39713 | 72 |
if (log_is_enabled(Debug, class, resolve)) { |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
73 |
Verifier::trace_class_resolution(from_class, klass); |
39713 | 74 |
} |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
75 |
return InstanceKlass::cast(from_class)->is_subclass_of(this_class); |
39713 | 76 |
} |
77 |
||
78 |
return false; |
|
79 |
} |
|
80 |
||
1 | 81 |
bool VerificationType::is_reference_assignable_from( |
27022 | 82 |
const VerificationType& from, ClassVerifier* context, |
83 |
bool from_field_is_protected, TRAPS) const { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
84 |
InstanceKlass* klass = context->current_class(); |
1 | 85 |
if (from.is_null()) { |
86 |
// null is assignable to any reference |
|
87 |
return true; |
|
88 |
} else if (is_null()) { |
|
89 |
return false; |
|
90 |
} else if (name() == from.name()) { |
|
91 |
return true; |
|
92 |
} else if (is_object()) { |
|
93 |
// We need check the class hierarchy to check assignability |
|
94 |
if (name() == vmSymbols::java_lang_Object()) { |
|
95 |
// any object or array is assignable to java.lang.Object |
|
96 |
return true; |
|
97 |
} |
|
39713 | 98 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
99 |
if (DumpSharedSpaces && SystemDictionaryShared::add_verification_constraint(klass, |
39713 | 100 |
name(), from.name(), from_field_is_protected, from.is_array(), |
101 |
from.is_object())) { |
|
102 |
// If add_verification_constraint() returns true, the resolution/check should be |
|
103 |
// delayed until runtime. |
|
104 |
return true; |
|
30616
fde3a4fee412
8076318: split verifier needs to add TraceClassResolution
hseigel
parents:
27022
diff
changeset
|
105 |
} |
fde3a4fee412
8076318: split verifier needs to add TraceClassResolution
hseigel
parents:
27022
diff
changeset
|
106 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46271
diff
changeset
|
107 |
return resolve_and_check_assignability(klass, name(), from.name(), |
39713 | 108 |
from_field_is_protected, from.is_array(), from.is_object(), THREAD); |
1 | 109 |
} else if (is_array() && from.is_array()) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
110 |
VerificationType comp_this = get_component(context, CHECK_false); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
111 |
VerificationType comp_from = from.get_component(context, CHECK_false); |
6172 | 112 |
if (!comp_this.is_bogus() && !comp_from.is_bogus()) { |
31966
aa9c386e1240
8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents:
30616
diff
changeset
|
113 |
return comp_this.is_component_assignable_from(comp_from, context, |
27022 | 114 |
from_field_is_protected, CHECK_false); |
6172 | 115 |
} |
1 | 116 |
} |
117 |
return false; |
|
118 |
} |
|
119 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
120 |
VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const { |
1 | 121 |
assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array"); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
122 |
Symbol* component; |
1 | 123 |
switch (name()->byte_at(1)) { |
124 |
case 'Z': return VerificationType(Boolean); |
|
125 |
case 'B': return VerificationType(Byte); |
|
126 |
case 'C': return VerificationType(Char); |
|
127 |
case 'S': return VerificationType(Short); |
|
128 |
case 'I': return VerificationType(Integer); |
|
129 |
case 'J': return VerificationType(Long); |
|
130 |
case 'F': return VerificationType(Float); |
|
131 |
case 'D': return VerificationType(Double); |
|
132 |
case '[': |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
133 |
component = context->create_temporary_symbol( |
1 | 134 |
name(), 1, name()->utf8_length(), |
135 |
CHECK_(VerificationType::bogus_type())); |
|
136 |
return VerificationType::reference_type(component); |
|
137 |
case 'L': |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
138 |
component = context->create_temporary_symbol( |
1 | 139 |
name(), 2, name()->utf8_length() - 1, |
140 |
CHECK_(VerificationType::bogus_type())); |
|
141 |
return VerificationType::reference_type(component); |
|
142 |
default: |
|
6172 | 143 |
// Met an invalid type signature, e.g. [X |
1 | 144 |
return VerificationType::bogus_type(); |
145 |
} |
|
146 |
} |
|
147 |
||
148 |
void VerificationType::print_on(outputStream* st) const { |
|
149 |
switch (_u._data) { |
|
13476 | 150 |
case Bogus: st->print("top"); break; |
151 |
case Category1: st->print("category1"); break; |
|
152 |
case Category2: st->print("category2"); break; |
|
153 |
case Category2_2nd: st->print("category2_2nd"); break; |
|
154 |
case Boolean: st->print("boolean"); break; |
|
155 |
case Byte: st->print("byte"); break; |
|
156 |
case Short: st->print("short"); break; |
|
157 |
case Char: st->print("char"); break; |
|
158 |
case Integer: st->print("integer"); break; |
|
159 |
case Float: st->print("float"); break; |
|
160 |
case Long: st->print("long"); break; |
|
161 |
case Double: st->print("double"); break; |
|
162 |
case Long_2nd: st->print("long_2nd"); break; |
|
163 |
case Double_2nd: st->print("double_2nd"); break; |
|
164 |
case Null: st->print("null"); break; |
|
165 |
case ReferenceQuery: st->print("reference type"); break; |
|
166 |
case Category1Query: st->print("category1 type"); break; |
|
167 |
case Category2Query: st->print("category2 type"); break; |
|
168 |
case Category2_2ndQuery: st->print("category2_2nd type"); break; |
|
1 | 169 |
default: |
170 |
if (is_uninitialized_this()) { |
|
13476 | 171 |
st->print("uninitializedThis"); |
1 | 172 |
} else if (is_uninitialized()) { |
13476 | 173 |
st->print("uninitialized %d", bci()); |
1 | 174 |
} else { |
13476 | 175 |
name()->print_value_on(st); |
1 | 176 |
} |
177 |
} |
|
178 |
} |