Mon, 24 Dec 2012 11:46:38 -0800
Merge
duke@435 | 1 | /* |
kamg@3992 | 2 | * Copyright (c) 2003, 2012, 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" |
stefank@2314 | 27 | #include "classfile/verificationType.hpp" |
coleenp@2497 | 28 | #include "classfile/verifier.hpp" |
duke@435 | 29 | |
duke@435 | 30 | VerificationType VerificationType::from_tag(u1 tag) { |
duke@435 | 31 | switch (tag) { |
duke@435 | 32 | case ITEM_Top: return bogus_type(); |
duke@435 | 33 | case ITEM_Integer: return integer_type(); |
duke@435 | 34 | case ITEM_Float: return float_type(); |
duke@435 | 35 | case ITEM_Double: return double_type(); |
duke@435 | 36 | case ITEM_Long: return long_type(); |
duke@435 | 37 | case ITEM_Null: return null_type(); |
duke@435 | 38 | default: |
duke@435 | 39 | ShouldNotReachHere(); |
duke@435 | 40 | return bogus_type(); |
duke@435 | 41 | } |
duke@435 | 42 | } |
duke@435 | 43 | |
duke@435 | 44 | bool VerificationType::is_reference_assignable_from( |
coleenp@2497 | 45 | const VerificationType& from, ClassVerifier* context, TRAPS) const { |
coleenp@2497 | 46 | instanceKlassHandle klass = context->current_class(); |
duke@435 | 47 | if (from.is_null()) { |
duke@435 | 48 | // null is assignable to any reference |
duke@435 | 49 | return true; |
duke@435 | 50 | } else if (is_null()) { |
duke@435 | 51 | return false; |
duke@435 | 52 | } else if (name() == from.name()) { |
duke@435 | 53 | return true; |
duke@435 | 54 | } else if (is_object()) { |
duke@435 | 55 | // We need check the class hierarchy to check assignability |
duke@435 | 56 | if (name() == vmSymbols::java_lang_Object()) { |
duke@435 | 57 | // any object or array is assignable to java.lang.Object |
duke@435 | 58 | return true; |
duke@435 | 59 | } |
coleenp@4037 | 60 | Klass* obj = SystemDictionary::resolve_or_fail( |
coleenp@2497 | 61 | name(), Handle(THREAD, klass->class_loader()), |
coleenp@2497 | 62 | Handle(THREAD, klass->protection_domain()), true, CHECK_false); |
kamg@2158 | 63 | KlassHandle this_class(THREAD, obj); |
kamg@2158 | 64 | |
kamg@2158 | 65 | if (this_class->is_interface()) { |
duke@435 | 66 | // We treat interfaces as java.lang.Object, including |
duke@435 | 67 | // java.lang.Cloneable and java.io.Serializable |
duke@435 | 68 | return true; |
duke@435 | 69 | } else if (from.is_object()) { |
coleenp@4037 | 70 | Klass* from_class = SystemDictionary::resolve_or_fail( |
coleenp@2497 | 71 | from.name(), Handle(THREAD, klass->class_loader()), |
coleenp@2497 | 72 | Handle(THREAD, klass->protection_domain()), true, CHECK_false); |
coleenp@4037 | 73 | return InstanceKlass::cast(from_class)->is_subclass_of(this_class()); |
duke@435 | 74 | } |
duke@435 | 75 | } else if (is_array() && from.is_array()) { |
coleenp@2497 | 76 | VerificationType comp_this = get_component(context, CHECK_false); |
coleenp@2497 | 77 | VerificationType comp_from = from.get_component(context, CHECK_false); |
apangin@2032 | 78 | if (!comp_this.is_bogus() && !comp_from.is_bogus()) { |
apangin@2032 | 79 | return comp_this.is_assignable_from(comp_from, context, CHECK_false); |
apangin@2032 | 80 | } |
duke@435 | 81 | } |
duke@435 | 82 | return false; |
duke@435 | 83 | } |
duke@435 | 84 | |
coleenp@2497 | 85 | VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const { |
duke@435 | 86 | assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array"); |
coleenp@2497 | 87 | Symbol* component; |
duke@435 | 88 | switch (name()->byte_at(1)) { |
duke@435 | 89 | case 'Z': return VerificationType(Boolean); |
duke@435 | 90 | case 'B': return VerificationType(Byte); |
duke@435 | 91 | case 'C': return VerificationType(Char); |
duke@435 | 92 | case 'S': return VerificationType(Short); |
duke@435 | 93 | case 'I': return VerificationType(Integer); |
duke@435 | 94 | case 'J': return VerificationType(Long); |
duke@435 | 95 | case 'F': return VerificationType(Float); |
duke@435 | 96 | case 'D': return VerificationType(Double); |
duke@435 | 97 | case '[': |
coleenp@2497 | 98 | component = context->create_temporary_symbol( |
duke@435 | 99 | name(), 1, name()->utf8_length(), |
duke@435 | 100 | CHECK_(VerificationType::bogus_type())); |
duke@435 | 101 | return VerificationType::reference_type(component); |
duke@435 | 102 | case 'L': |
coleenp@2497 | 103 | component = context->create_temporary_symbol( |
duke@435 | 104 | name(), 2, name()->utf8_length() - 1, |
duke@435 | 105 | CHECK_(VerificationType::bogus_type())); |
duke@435 | 106 | return VerificationType::reference_type(component); |
duke@435 | 107 | default: |
apangin@2032 | 108 | // Met an invalid type signature, e.g. [X |
duke@435 | 109 | return VerificationType::bogus_type(); |
duke@435 | 110 | } |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | void VerificationType::print_on(outputStream* st) const { |
duke@435 | 114 | switch (_u._data) { |
kamg@3992 | 115 | case Bogus: st->print("top"); break; |
kamg@3992 | 116 | case Category1: st->print("category1"); break; |
kamg@3992 | 117 | case Category2: st->print("category2"); break; |
kamg@3992 | 118 | case Category2_2nd: st->print("category2_2nd"); break; |
kamg@3992 | 119 | case Boolean: st->print("boolean"); break; |
kamg@3992 | 120 | case Byte: st->print("byte"); break; |
kamg@3992 | 121 | case Short: st->print("short"); break; |
kamg@3992 | 122 | case Char: st->print("char"); break; |
kamg@3992 | 123 | case Integer: st->print("integer"); break; |
kamg@3992 | 124 | case Float: st->print("float"); break; |
kamg@3992 | 125 | case Long: st->print("long"); break; |
kamg@3992 | 126 | case Double: st->print("double"); break; |
kamg@3992 | 127 | case Long_2nd: st->print("long_2nd"); break; |
kamg@3992 | 128 | case Double_2nd: st->print("double_2nd"); break; |
kamg@3992 | 129 | case Null: st->print("null"); break; |
kamg@3992 | 130 | case ReferenceQuery: st->print("reference type"); break; |
kamg@3992 | 131 | case Category1Query: st->print("category1 type"); break; |
kamg@3992 | 132 | case Category2Query: st->print("category2 type"); break; |
kamg@3992 | 133 | case Category2_2ndQuery: st->print("category2_2nd type"); break; |
duke@435 | 134 | default: |
duke@435 | 135 | if (is_uninitialized_this()) { |
kamg@3992 | 136 | st->print("uninitializedThis"); |
duke@435 | 137 | } else if (is_uninitialized()) { |
kamg@3992 | 138 | st->print("uninitialized %d", bci()); |
duke@435 | 139 | } else { |
kamg@3992 | 140 | name()->print_value_on(st); |
duke@435 | 141 | } |
duke@435 | 142 | } |
duke@435 | 143 | } |