annotate src/share/vm/classfile/verificationType.cpp @ 1955:1070423b51f3

6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>' Summary: Update verifier to conform to spec re: reference vs. 'Object' types Reviewed-by: dholmes, coleenp
author kamg
date Wed, 27 Oct 2010 12:53:36 -0400
parents 60f88489896f
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_verificationType.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 VerificationType VerificationType::from_tag(u1 tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 switch (tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 case ITEM_Top: return bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
31 case ITEM_Integer: return integer_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
32 case ITEM_Float: return float_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
33 case ITEM_Double: return double_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
34 case ITEM_Long: return long_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
35 case ITEM_Null: return null_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
36 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
37 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
38 return bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
39 }
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 bool VerificationType::is_reference_assignable_from(
a61af66fc99e Initial load
duke
parents:
diff changeset
43 const VerificationType& from, instanceKlassHandle context, TRAPS) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 if (from.is_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // null is assignable to any reference
a61af66fc99e Initial load
duke
parents:
diff changeset
46 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 } else if (is_null()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 } else if (name() == from.name()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 } else if (is_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // We need check the class hierarchy to check assignability
a61af66fc99e Initial load
duke
parents:
diff changeset
53 if (name() == vmSymbols::java_lang_Object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // any object or array is assignable to java.lang.Object
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
1803
60f88489896f 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 1677
diff changeset
57 klassOop obj = SystemDictionary::resolve_or_fail(
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58 name_handle(), Handle(THREAD, context->class_loader()),
a61af66fc99e Initial load
duke
parents:
diff changeset
59 Handle(THREAD, context->protection_domain()), true, CHECK_false);
1803
60f88489896f 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 1677
diff changeset
60 KlassHandle this_class(THREAD, obj);
60f88489896f 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 1677
diff changeset
61
60f88489896f 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 1677
diff changeset
62 if (this_class->is_interface()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // We treat interfaces as java.lang.Object, including
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // java.lang.Cloneable and java.io.Serializable
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 } else if (from.is_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 klassOop from_class = SystemDictionary::resolve_or_fail(
a61af66fc99e Initial load
duke
parents:
diff changeset
68 from.name_handle(), Handle(THREAD, context->class_loader()),
a61af66fc99e Initial load
duke
parents:
diff changeset
69 Handle(THREAD, context->protection_domain()), true, CHECK_false);
1803
60f88489896f 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 1677
diff changeset
70 return instanceKlass::cast(from_class)->is_subclass_of(this_class());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 } else if (is_array() && from.is_array()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 VerificationType comp_this = get_component(CHECK_false);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 VerificationType comp_from = from.get_component(CHECK_false);
1677
a5c9d63a187d 6964170: Verifier crashes
apangin
parents: 1552
diff changeset
75 if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
a5c9d63a187d 6964170: Verifier crashes
apangin
parents: 1552
diff changeset
76 return comp_this.is_assignable_from(comp_from, context, CHECK_false);
a5c9d63a187d 6964170: Verifier crashes
apangin
parents: 1552
diff changeset
77 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 VerificationType VerificationType::get_component(TRAPS) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 symbolOop component;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 switch (name()->byte_at(1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 case 'Z': return VerificationType(Boolean);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case 'B': return VerificationType(Byte);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 case 'C': return VerificationType(Char);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 case 'S': return VerificationType(Short);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 case 'I': return VerificationType(Integer);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 case 'J': return VerificationType(Long);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 case 'F': return VerificationType(Float);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 case 'D': return VerificationType(Double);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
95 component = SymbolTable::lookup(
a61af66fc99e Initial load
duke
parents:
diff changeset
96 name(), 1, name()->utf8_length(),
a61af66fc99e Initial load
duke
parents:
diff changeset
97 CHECK_(VerificationType::bogus_type()));
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return VerificationType::reference_type(component);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
100 component = SymbolTable::lookup(
a61af66fc99e Initial load
duke
parents:
diff changeset
101 name(), 2, name()->utf8_length() - 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
102 CHECK_(VerificationType::bogus_type()));
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return VerificationType::reference_type(component);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 default:
1677
a5c9d63a187d 6964170: Verifier crashes
apangin
parents: 1552
diff changeset
105 // Met an invalid type signature, e.g. [X
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return VerificationType::bogus_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void VerificationType::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 switch (_u._data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case Bogus: st->print(" bogus "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 case Category1: st->print(" category1 "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 case Category2: st->print(" category2 "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 case Category2_2nd: st->print(" category2_2nd "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 case Boolean: st->print(" boolean "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 case Byte: st->print(" byte "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 case Short: st->print(" short "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 case Char: st->print(" char "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 case Integer: st->print(" integer "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 case Float: st->print(" float "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 case Long: st->print(" long "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 case Double: st->print(" double "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 case Long_2nd: st->print(" long_2nd "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 case Double_2nd: st->print(" double_2nd "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 case Null: st->print(" null "); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (is_uninitialized_this()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 st->print(" uninitializedThis ");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } else if (is_uninitialized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 st->print(" uninitialized %d ", bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
134 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 st->print(" class %s ", name()->as_klass_external_name());
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 #endif