Sat, 12 Jun 2010 22:53:43 -0700
6960865: ldc of unloaded class throws an assert in ciTypeFlow
Summary: Support java_mirror for unloaded klasses, arrays as well as instances. Simplify ciTypeFlow by removing unused path.
Reviewed-by: kvn
1 /*
2 * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_ciKlass.cpp.incl"
28 // ciKlass
29 //
30 // This class represents a klassOop in the HotSpot virtual
31 // machine.
33 // ------------------------------------------------------------------
34 // ciKlass::ciKlass
35 ciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) {
36 assert(get_oop()->is_klass(), "wrong type");
37 Klass* k = get_Klass();
38 _layout_helper = k->layout_helper();
39 symbolOop klass_name = k->name();
40 assert(klass_name != NULL, "wrong ciKlass constructor");
41 _name = CURRENT_ENV->get_object(klass_name)->as_symbol();
42 }
44 // ------------------------------------------------------------------
45 // ciKlass::ciKlass
46 //
47 // Nameless klass variant.
48 ciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) {
49 assert(get_oop()->is_klass(), "wrong type");
50 _name = name;
51 _layout_helper = Klass::_lh_neutral_value;
52 }
54 // ------------------------------------------------------------------
55 // ciKlass::ciKlass
56 //
57 // Unloaded klass variant.
58 ciKlass::ciKlass(ciSymbol* name, ciKlass* klass) : ciType(klass) {
59 _name = name;
60 _layout_helper = Klass::_lh_neutral_value;
61 }
63 // ------------------------------------------------------------------
64 // ciKlass::is_subtype_of
65 bool ciKlass::is_subtype_of(ciKlass* that) {
66 assert(is_loaded() && that->is_loaded(), "must be loaded");
67 assert(is_java_klass() && that->is_java_klass(), "must be java klasses");
68 // Check to see if the klasses are identical.
69 if (this == that) {
70 return true;
71 }
73 VM_ENTRY_MARK;
74 Klass* this_klass = get_Klass();
75 klassOop that_klass = that->get_klassOop();
76 bool result = this_klass->is_subtype_of(that_klass);
78 return result;
79 }
81 // ------------------------------------------------------------------
82 // ciKlass::is_subclass_of
83 bool ciKlass::is_subclass_of(ciKlass* that) {
84 assert(is_loaded() && that->is_loaded(), "must be loaded");
85 assert(is_java_klass() && that->is_java_klass(), "must be java klasses");
86 // Check to see if the klasses are identical.
88 VM_ENTRY_MARK;
89 Klass* this_klass = get_Klass();
90 klassOop that_klass = that->get_klassOop();
91 bool result = this_klass->is_subclass_of(that_klass);
93 return result;
94 }
96 // ------------------------------------------------------------------
97 // ciKlass::super_depth
98 juint ciKlass::super_depth() {
99 assert(is_loaded(), "must be loaded");
100 assert(is_java_klass(), "must be java klasses");
102 VM_ENTRY_MARK;
103 Klass* this_klass = get_Klass();
104 return this_klass->super_depth();
105 }
107 // ------------------------------------------------------------------
108 // ciKlass::super_check_offset
109 juint ciKlass::super_check_offset() {
110 assert(is_loaded(), "must be loaded");
111 assert(is_java_klass(), "must be java klasses");
113 VM_ENTRY_MARK;
114 Klass* this_klass = get_Klass();
115 return this_klass->super_check_offset();
116 }
118 // ------------------------------------------------------------------
119 // ciKlass::super_of_depth
120 ciKlass* ciKlass::super_of_depth(juint i) {
121 assert(is_loaded(), "must be loaded");
122 assert(is_java_klass(), "must be java klasses");
124 VM_ENTRY_MARK;
125 Klass* this_klass = get_Klass();
126 klassOop super = this_klass->primary_super_of_depth(i);
127 return (super != NULL) ? CURRENT_THREAD_ENV->get_object(super)->as_klass() : NULL;
128 }
130 // ------------------------------------------------------------------
131 // ciKlass::can_be_primary_super
132 bool ciKlass::can_be_primary_super() {
133 assert(is_loaded(), "must be loaded");
134 assert(is_java_klass(), "must be java klasses");
136 VM_ENTRY_MARK;
137 Klass* this_klass = get_Klass();
138 return this_klass->can_be_primary_super();
139 }
141 // ------------------------------------------------------------------
142 // ciKlass::least_common_ancestor
143 //
144 // Get the shared parent of two klasses.
145 //
146 // Implementation note: this method currently goes "over the wall"
147 // and does all of the work on the VM side. It could be rewritten
148 // to use the super() method and do all of the work (aside from the
149 // lazy computation of super()) in native mode. This may be
150 // worthwhile if the compiler is repeatedly requesting the same lca
151 // computation or possibly if most of the superklasses have already
152 // been created as ciObjects anyway. Something to think about...
153 ciKlass*
154 ciKlass::least_common_ancestor(ciKlass* that) {
155 assert(is_loaded() && that->is_loaded(), "must be loaded");
156 assert(is_java_klass() && that->is_java_klass(), "must be java klasses");
157 // Check to see if the klasses are identical.
158 if (this == that) {
159 return this;
160 }
162 VM_ENTRY_MARK;
163 Klass* this_klass = get_Klass();
164 Klass* that_klass = that->get_Klass();
165 Klass* lca = this_klass->LCA(that_klass);
167 // Many times the LCA will be either this_klass or that_klass.
168 // Treat these as special cases.
169 if (lca == that_klass) {
170 return that;
171 }
172 if (this_klass == lca) {
173 return this;
174 }
176 // Create the ciInstanceKlass for the lca.
177 ciKlass* result =
178 CURRENT_THREAD_ENV->get_object(lca->as_klassOop())->as_klass();
180 return result;
181 }
183 // ------------------------------------------------------------------
184 // ciKlass::find_klass
185 //
186 // Find a klass using this klass's class loader.
187 ciKlass* ciKlass::find_klass(ciSymbol* klass_name) {
188 assert(is_loaded(), "cannot find_klass through an unloaded klass");
189 return CURRENT_ENV->get_klass_by_name(this,
190 klass_name, false);
191 }
193 // ------------------------------------------------------------------
194 // ciKlass::java_mirror
195 //
196 // Get the instance of java.lang.Class corresponding to this klass.
197 // If it is an unloaded instance or array klass, return an unloaded
198 // mirror object of type Class.
199 ciInstance* ciKlass::java_mirror() {
200 GUARDED_VM_ENTRY(
201 if (!is_loaded())
202 return ciEnv::current()->get_unloaded_klass_mirror(this);
203 oop java_mirror = get_Klass()->java_mirror();
204 return CURRENT_ENV->get_object(java_mirror)->as_instance();
205 )
206 }
208 // ------------------------------------------------------------------
209 // ciKlass::modifier_flags
210 jint ciKlass::modifier_flags() {
211 assert(is_loaded(), "not loaded");
212 GUARDED_VM_ENTRY(
213 return get_Klass()->modifier_flags();
214 )
215 }
217 // ------------------------------------------------------------------
218 // ciKlass::access_flags
219 jint ciKlass::access_flags() {
220 assert(is_loaded(), "not loaded");
221 GUARDED_VM_ENTRY(
222 return get_Klass()->access_flags().as_int();
223 )
224 }
226 // ------------------------------------------------------------------
227 // ciKlass::print_impl
228 //
229 // Implementation of the print method
230 void ciKlass::print_impl(outputStream* st) {
231 st->print(" name=");
232 print_name_on(st);
233 }
235 // ------------------------------------------------------------------
236 // ciKlass::print_name
237 //
238 // Print the name of this klass
239 void ciKlass::print_name_on(outputStream* st) {
240 name()->print_symbol_on(st);
241 }