Mercurial > hg > truffle
annotate src/share/vm/ci/ciKlass.cpp @ 4990:2551ebf25ff9
slightly prefer inlining within loops
author | Christian Haeubl <christian.haeubl@oracle.com> |
---|---|
date | Mon, 27 Feb 2012 19:15:30 -0800 |
parents | 532be189cf09 |
children | e522a00b91aa |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
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:
1138
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciKlass.hpp" | |
27 #include "ci/ciSymbol.hpp" | |
28 #include "ci/ciUtilities.hpp" | |
29 #include "oops/oop.inline.hpp" | |
0 | 30 |
31 // ciKlass | |
32 // | |
33 // This class represents a klassOop in the HotSpot virtual | |
34 // machine. | |
35 | |
36 // ------------------------------------------------------------------ | |
37 // ciKlass::ciKlass | |
38 ciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) { | |
39 assert(get_oop()->is_klass(), "wrong type"); | |
40 Klass* k = get_Klass(); | |
41 _layout_helper = k->layout_helper(); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
42 Symbol* klass_name = k->name(); |
0 | 43 assert(klass_name != NULL, "wrong ciKlass constructor"); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
44 _name = CURRENT_ENV->get_symbol(klass_name); |
0 | 45 } |
46 | |
47 // ------------------------------------------------------------------ | |
48 // ciKlass::ciKlass | |
49 // | |
50 // Nameless klass variant. | |
51 ciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) { | |
52 assert(get_oop()->is_klass(), "wrong type"); | |
53 _name = name; | |
54 _layout_helper = Klass::_lh_neutral_value; | |
55 } | |
56 | |
57 // ------------------------------------------------------------------ | |
58 // ciKlass::ciKlass | |
59 // | |
60 // Unloaded klass variant. | |
61 ciKlass::ciKlass(ciSymbol* name, ciKlass* klass) : ciType(klass) { | |
62 _name = name; | |
63 _layout_helper = Klass::_lh_neutral_value; | |
64 } | |
65 | |
66 // ------------------------------------------------------------------ | |
67 // ciKlass::is_subtype_of | |
68 bool ciKlass::is_subtype_of(ciKlass* that) { | |
69 assert(is_loaded() && that->is_loaded(), "must be loaded"); | |
70 assert(is_java_klass() && that->is_java_klass(), "must be java klasses"); | |
71 // Check to see if the klasses are identical. | |
72 if (this == that) { | |
73 return true; | |
74 } | |
4977
532be189cf09
Reducing diff to hsx24
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3672
diff
changeset
|
75 #ifndef GRAAL |
532be189cf09
Reducing diff to hsx24
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3672
diff
changeset
|
76 VM_ENTRY_MARK; |
532be189cf09
Reducing diff to hsx24
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3672
diff
changeset
|
77 #endif |
0 | 78 Klass* this_klass = get_Klass(); |
79 klassOop that_klass = that->get_klassOop(); | |
80 bool result = this_klass->is_subtype_of(that_klass); | |
81 | |
82 return result; | |
83 } | |
84 | |
85 // ------------------------------------------------------------------ | |
86 // ciKlass::is_subclass_of | |
87 bool ciKlass::is_subclass_of(ciKlass* that) { | |
88 assert(is_loaded() && that->is_loaded(), "must be loaded"); | |
89 assert(is_java_klass() && that->is_java_klass(), "must be java klasses"); | |
90 // Check to see if the klasses are identical. | |
91 | |
92 VM_ENTRY_MARK; | |
93 Klass* this_klass = get_Klass(); | |
94 klassOop that_klass = that->get_klassOop(); | |
95 bool result = this_klass->is_subclass_of(that_klass); | |
96 | |
97 return result; | |
98 } | |
99 | |
100 // ------------------------------------------------------------------ | |
101 // ciKlass::super_depth | |
102 juint ciKlass::super_depth() { | |
103 assert(is_loaded(), "must be loaded"); | |
104 assert(is_java_klass(), "must be java klasses"); | |
105 | |
106 VM_ENTRY_MARK; | |
107 Klass* this_klass = get_Klass(); | |
108 return this_klass->super_depth(); | |
109 } | |
110 | |
111 // ------------------------------------------------------------------ | |
112 // ciKlass::super_check_offset | |
113 juint ciKlass::super_check_offset() { | |
114 assert(is_loaded(), "must be loaded"); | |
115 assert(is_java_klass(), "must be java klasses"); | |
116 | |
117 VM_ENTRY_MARK; | |
118 Klass* this_klass = get_Klass(); | |
119 return this_klass->super_check_offset(); | |
120 } | |
121 | |
122 // ------------------------------------------------------------------ | |
123 // ciKlass::super_of_depth | |
124 ciKlass* ciKlass::super_of_depth(juint i) { | |
125 assert(is_loaded(), "must be loaded"); | |
126 assert(is_java_klass(), "must be java klasses"); | |
127 | |
128 VM_ENTRY_MARK; | |
129 Klass* this_klass = get_Klass(); | |
130 klassOop super = this_klass->primary_super_of_depth(i); | |
131 return (super != NULL) ? CURRENT_THREAD_ENV->get_object(super)->as_klass() : NULL; | |
132 } | |
133 | |
134 // ------------------------------------------------------------------ | |
135 // ciKlass::can_be_primary_super | |
136 bool ciKlass::can_be_primary_super() { | |
137 assert(is_loaded(), "must be loaded"); | |
138 assert(is_java_klass(), "must be java klasses"); | |
139 | |
140 VM_ENTRY_MARK; | |
141 Klass* this_klass = get_Klass(); | |
142 return this_klass->can_be_primary_super(); | |
143 } | |
144 | |
145 // ------------------------------------------------------------------ | |
146 // ciKlass::least_common_ancestor | |
147 // | |
148 // Get the shared parent of two klasses. | |
149 // | |
150 // Implementation note: this method currently goes "over the wall" | |
151 // and does all of the work on the VM side. It could be rewritten | |
152 // to use the super() method and do all of the work (aside from the | |
153 // lazy computation of super()) in native mode. This may be | |
154 // worthwhile if the compiler is repeatedly requesting the same lca | |
155 // computation or possibly if most of the superklasses have already | |
156 // been created as ciObjects anyway. Something to think about... | |
157 ciKlass* | |
158 ciKlass::least_common_ancestor(ciKlass* that) { | |
159 assert(is_loaded() && that->is_loaded(), "must be loaded"); | |
160 assert(is_java_klass() && that->is_java_klass(), "must be java klasses"); | |
161 // Check to see if the klasses are identical. | |
162 if (this == that) { | |
163 return this; | |
164 } | |
165 | |
166 VM_ENTRY_MARK; | |
167 Klass* this_klass = get_Klass(); | |
168 Klass* that_klass = that->get_Klass(); | |
169 Klass* lca = this_klass->LCA(that_klass); | |
170 | |
171 // Many times the LCA will be either this_klass or that_klass. | |
172 // Treat these as special cases. | |
173 if (lca == that_klass) { | |
174 return that; | |
175 } | |
176 if (this_klass == lca) { | |
177 return this; | |
178 } | |
179 | |
180 // Create the ciInstanceKlass for the lca. | |
181 ciKlass* result = | |
182 CURRENT_THREAD_ENV->get_object(lca->as_klassOop())->as_klass(); | |
183 | |
184 return result; | |
185 } | |
186 | |
187 // ------------------------------------------------------------------ | |
188 // ciKlass::find_klass | |
189 // | |
190 // Find a klass using this klass's class loader. | |
191 ciKlass* ciKlass::find_klass(ciSymbol* klass_name) { | |
192 assert(is_loaded(), "cannot find_klass through an unloaded klass"); | |
193 return CURRENT_ENV->get_klass_by_name(this, | |
194 klass_name, false); | |
195 } | |
196 | |
197 // ------------------------------------------------------------------ | |
198 // ciKlass::java_mirror | |
1604
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1552
diff
changeset
|
199 // |
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1552
diff
changeset
|
200 // Get the instance of java.lang.Class corresponding to this klass. |
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1552
diff
changeset
|
201 // If it is an unloaded instance or array klass, return an unloaded |
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1552
diff
changeset
|
202 // mirror object of type Class. |
0 | 203 ciInstance* ciKlass::java_mirror() { |
204 GUARDED_VM_ENTRY( | |
1604
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1552
diff
changeset
|
205 if (!is_loaded()) |
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1552
diff
changeset
|
206 return ciEnv::current()->get_unloaded_klass_mirror(this); |
0 | 207 oop java_mirror = get_Klass()->java_mirror(); |
208 return CURRENT_ENV->get_object(java_mirror)->as_instance(); | |
209 ) | |
210 } | |
211 | |
212 // ------------------------------------------------------------------ | |
213 // ciKlass::modifier_flags | |
214 jint ciKlass::modifier_flags() { | |
215 assert(is_loaded(), "not loaded"); | |
216 GUARDED_VM_ENTRY( | |
217 return get_Klass()->modifier_flags(); | |
218 ) | |
219 } | |
220 | |
221 // ------------------------------------------------------------------ | |
222 // ciKlass::access_flags | |
223 jint ciKlass::access_flags() { | |
224 assert(is_loaded(), "not loaded"); | |
225 GUARDED_VM_ENTRY( | |
226 return get_Klass()->access_flags().as_int(); | |
227 ) | |
228 } | |
229 | |
230 // ------------------------------------------------------------------ | |
231 // ciKlass::print_impl | |
232 // | |
233 // Implementation of the print method | |
234 void ciKlass::print_impl(outputStream* st) { | |
235 st->print(" name="); | |
236 print_name_on(st); | |
237 } | |
238 | |
239 // ------------------------------------------------------------------ | |
240 // ciKlass::print_name | |
241 // | |
242 // Print the name of this klass | |
243 void ciKlass::print_name_on(outputStream* st) { | |
244 name()->print_symbol_on(st); | |
245 } |