Fri, 06 Jun 2008 13:43:36 -0400
Merge
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2003-2006 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_verificationType.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | VerificationType VerificationType::from_tag(u1 tag) { |
duke@435 | 29 | switch (tag) { |
duke@435 | 30 | case ITEM_Top: return bogus_type(); |
duke@435 | 31 | case ITEM_Integer: return integer_type(); |
duke@435 | 32 | case ITEM_Float: return float_type(); |
duke@435 | 33 | case ITEM_Double: return double_type(); |
duke@435 | 34 | case ITEM_Long: return long_type(); |
duke@435 | 35 | case ITEM_Null: return null_type(); |
duke@435 | 36 | default: |
duke@435 | 37 | ShouldNotReachHere(); |
duke@435 | 38 | return bogus_type(); |
duke@435 | 39 | } |
duke@435 | 40 | } |
duke@435 | 41 | |
duke@435 | 42 | bool VerificationType::is_reference_assignable_from( |
duke@435 | 43 | const VerificationType& from, instanceKlassHandle context, TRAPS) const { |
duke@435 | 44 | if (from.is_null()) { |
duke@435 | 45 | // null is assignable to any reference |
duke@435 | 46 | return true; |
duke@435 | 47 | } else if (is_null()) { |
duke@435 | 48 | return false; |
duke@435 | 49 | } else if (name() == from.name()) { |
duke@435 | 50 | return true; |
duke@435 | 51 | } else if (is_object()) { |
duke@435 | 52 | // We need check the class hierarchy to check assignability |
duke@435 | 53 | if (name() == vmSymbols::java_lang_Object()) { |
duke@435 | 54 | // any object or array is assignable to java.lang.Object |
duke@435 | 55 | return true; |
duke@435 | 56 | } |
duke@435 | 57 | klassOop this_class = SystemDictionary::resolve_or_fail( |
duke@435 | 58 | name_handle(), Handle(THREAD, context->class_loader()), |
duke@435 | 59 | Handle(THREAD, context->protection_domain()), true, CHECK_false); |
duke@435 | 60 | if (this_class->klass_part()->is_interface()) { |
duke@435 | 61 | // We treat interfaces as java.lang.Object, including |
duke@435 | 62 | // java.lang.Cloneable and java.io.Serializable |
duke@435 | 63 | return true; |
duke@435 | 64 | } else if (from.is_object()) { |
duke@435 | 65 | klassOop from_class = SystemDictionary::resolve_or_fail( |
duke@435 | 66 | from.name_handle(), Handle(THREAD, context->class_loader()), |
duke@435 | 67 | Handle(THREAD, context->protection_domain()), true, CHECK_false); |
duke@435 | 68 | return instanceKlass::cast(from_class)->is_subclass_of(this_class); |
duke@435 | 69 | } |
duke@435 | 70 | } else if (is_array() && from.is_array()) { |
duke@435 | 71 | VerificationType comp_this = get_component(CHECK_false); |
duke@435 | 72 | VerificationType comp_from = from.get_component(CHECK_false); |
duke@435 | 73 | return comp_this.is_assignable_from(comp_from, context, CHECK_false); |
duke@435 | 74 | } |
duke@435 | 75 | return false; |
duke@435 | 76 | } |
duke@435 | 77 | |
duke@435 | 78 | VerificationType VerificationType::get_component(TRAPS) const { |
duke@435 | 79 | assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array"); |
duke@435 | 80 | symbolOop component; |
duke@435 | 81 | switch (name()->byte_at(1)) { |
duke@435 | 82 | case 'Z': return VerificationType(Boolean); |
duke@435 | 83 | case 'B': return VerificationType(Byte); |
duke@435 | 84 | case 'C': return VerificationType(Char); |
duke@435 | 85 | case 'S': return VerificationType(Short); |
duke@435 | 86 | case 'I': return VerificationType(Integer); |
duke@435 | 87 | case 'J': return VerificationType(Long); |
duke@435 | 88 | case 'F': return VerificationType(Float); |
duke@435 | 89 | case 'D': return VerificationType(Double); |
duke@435 | 90 | case '[': |
duke@435 | 91 | component = SymbolTable::lookup( |
duke@435 | 92 | name(), 1, name()->utf8_length(), |
duke@435 | 93 | CHECK_(VerificationType::bogus_type())); |
duke@435 | 94 | return VerificationType::reference_type(component); |
duke@435 | 95 | case 'L': |
duke@435 | 96 | component = SymbolTable::lookup( |
duke@435 | 97 | name(), 2, name()->utf8_length() - 1, |
duke@435 | 98 | CHECK_(VerificationType::bogus_type())); |
duke@435 | 99 | return VerificationType::reference_type(component); |
duke@435 | 100 | default: |
duke@435 | 101 | ShouldNotReachHere(); |
duke@435 | 102 | return VerificationType::bogus_type(); |
duke@435 | 103 | } |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | #ifndef PRODUCT |
duke@435 | 107 | |
duke@435 | 108 | void VerificationType::print_on(outputStream* st) const { |
duke@435 | 109 | switch (_u._data) { |
duke@435 | 110 | case Bogus: st->print(" bogus "); break; |
duke@435 | 111 | case Category1: st->print(" category1 "); break; |
duke@435 | 112 | case Category2: st->print(" category2 "); break; |
duke@435 | 113 | case Category2_2nd: st->print(" category2_2nd "); break; |
duke@435 | 114 | case Boolean: st->print(" boolean "); break; |
duke@435 | 115 | case Byte: st->print(" byte "); break; |
duke@435 | 116 | case Short: st->print(" short "); break; |
duke@435 | 117 | case Char: st->print(" char "); break; |
duke@435 | 118 | case Integer: st->print(" integer "); break; |
duke@435 | 119 | case Float: st->print(" float "); break; |
duke@435 | 120 | case Long: st->print(" long "); break; |
duke@435 | 121 | case Double: st->print(" double "); break; |
duke@435 | 122 | case Long_2nd: st->print(" long_2nd "); break; |
duke@435 | 123 | case Double_2nd: st->print(" double_2nd "); break; |
duke@435 | 124 | case Null: st->print(" null "); break; |
duke@435 | 125 | default: |
duke@435 | 126 | if (is_uninitialized_this()) { |
duke@435 | 127 | st->print(" uninitializedThis "); |
duke@435 | 128 | } else if (is_uninitialized()) { |
duke@435 | 129 | st->print(" uninitialized %d ", bci()); |
duke@435 | 130 | } else { |
duke@435 | 131 | st->print(" class %s ", name()->as_klass_external_name()); |
duke@435 | 132 | } |
duke@435 | 133 | } |
duke@435 | 134 | } |
duke@435 | 135 | |
duke@435 | 136 | #endif |