src/share/vm/classfile/verificationType.cpp

Wed, 23 Sep 2020 16:26:20 +0300

author
vkempik
date
Wed, 23 Sep 2020 16:26:20 +0300
changeset 10009
8adf45218add
parent 9550
270570f695e0
child 9572
624a0741915c
permissions
-rw-r--r--

8244955: Additional Fix for JDK-8240124
Reviewed-by: mbalao, andrew

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

mercurial