1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/ciKlass.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,235 @@ 1.4 +/* 1.5 + * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_ciKlass.cpp.incl" 1.30 + 1.31 +// ciKlass 1.32 +// 1.33 +// This class represents a klassOop in the HotSpot virtual 1.34 +// machine. 1.35 + 1.36 +// ------------------------------------------------------------------ 1.37 +// ciKlass::ciKlass 1.38 +ciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) { 1.39 + assert(get_oop()->is_klass(), "wrong type"); 1.40 + Klass* k = get_Klass(); 1.41 + _layout_helper = k->layout_helper(); 1.42 + symbolOop klass_name = k->name(); 1.43 + assert(klass_name != NULL, "wrong ciKlass constructor"); 1.44 + _name = CURRENT_ENV->get_object(klass_name)->as_symbol(); 1.45 +} 1.46 + 1.47 +// ------------------------------------------------------------------ 1.48 +// ciKlass::ciKlass 1.49 +// 1.50 +// Nameless klass variant. 1.51 +ciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) { 1.52 + assert(get_oop()->is_klass(), "wrong type"); 1.53 + _name = name; 1.54 + _layout_helper = Klass::_lh_neutral_value; 1.55 +} 1.56 + 1.57 +// ------------------------------------------------------------------ 1.58 +// ciKlass::ciKlass 1.59 +// 1.60 +// Unloaded klass variant. 1.61 +ciKlass::ciKlass(ciSymbol* name, ciKlass* klass) : ciType(klass) { 1.62 + _name = name; 1.63 + _layout_helper = Klass::_lh_neutral_value; 1.64 +} 1.65 + 1.66 +// ------------------------------------------------------------------ 1.67 +// ciKlass::is_subtype_of 1.68 +bool ciKlass::is_subtype_of(ciKlass* that) { 1.69 + assert(is_loaded() && that->is_loaded(), "must be loaded"); 1.70 + assert(is_java_klass() && that->is_java_klass(), "must be java klasses"); 1.71 + // Check to see if the klasses are identical. 1.72 + if (this == that) { 1.73 + return true; 1.74 + } 1.75 + 1.76 + VM_ENTRY_MARK; 1.77 + Klass* this_klass = get_Klass(); 1.78 + klassOop that_klass = that->get_klassOop(); 1.79 + bool result = this_klass->is_subtype_of(that_klass); 1.80 + 1.81 + return result; 1.82 +} 1.83 + 1.84 +// ------------------------------------------------------------------ 1.85 +// ciKlass::is_subclass_of 1.86 +bool ciKlass::is_subclass_of(ciKlass* that) { 1.87 + assert(is_loaded() && that->is_loaded(), "must be loaded"); 1.88 + assert(is_java_klass() && that->is_java_klass(), "must be java klasses"); 1.89 + // Check to see if the klasses are identical. 1.90 + 1.91 + VM_ENTRY_MARK; 1.92 + Klass* this_klass = get_Klass(); 1.93 + klassOop that_klass = that->get_klassOop(); 1.94 + bool result = this_klass->is_subclass_of(that_klass); 1.95 + 1.96 + return result; 1.97 +} 1.98 + 1.99 +// ------------------------------------------------------------------ 1.100 +// ciKlass::super_depth 1.101 +juint ciKlass::super_depth() { 1.102 + assert(is_loaded(), "must be loaded"); 1.103 + assert(is_java_klass(), "must be java klasses"); 1.104 + 1.105 + VM_ENTRY_MARK; 1.106 + Klass* this_klass = get_Klass(); 1.107 + return this_klass->super_depth(); 1.108 +} 1.109 + 1.110 +// ------------------------------------------------------------------ 1.111 +// ciKlass::super_check_offset 1.112 +juint ciKlass::super_check_offset() { 1.113 + assert(is_loaded(), "must be loaded"); 1.114 + assert(is_java_klass(), "must be java klasses"); 1.115 + 1.116 + VM_ENTRY_MARK; 1.117 + Klass* this_klass = get_Klass(); 1.118 + return this_klass->super_check_offset(); 1.119 +} 1.120 + 1.121 +// ------------------------------------------------------------------ 1.122 +// ciKlass::super_of_depth 1.123 +ciKlass* ciKlass::super_of_depth(juint i) { 1.124 + assert(is_loaded(), "must be loaded"); 1.125 + assert(is_java_klass(), "must be java klasses"); 1.126 + 1.127 + VM_ENTRY_MARK; 1.128 + Klass* this_klass = get_Klass(); 1.129 + klassOop super = this_klass->primary_super_of_depth(i); 1.130 + return (super != NULL) ? CURRENT_THREAD_ENV->get_object(super)->as_klass() : NULL; 1.131 +} 1.132 + 1.133 +// ------------------------------------------------------------------ 1.134 +// ciKlass::can_be_primary_super 1.135 +bool ciKlass::can_be_primary_super() { 1.136 + assert(is_loaded(), "must be loaded"); 1.137 + assert(is_java_klass(), "must be java klasses"); 1.138 + 1.139 + VM_ENTRY_MARK; 1.140 + Klass* this_klass = get_Klass(); 1.141 + return this_klass->can_be_primary_super(); 1.142 +} 1.143 + 1.144 +// ------------------------------------------------------------------ 1.145 +// ciKlass::least_common_ancestor 1.146 +// 1.147 +// Get the shared parent of two klasses. 1.148 +// 1.149 +// Implementation note: this method currently goes "over the wall" 1.150 +// and does all of the work on the VM side. It could be rewritten 1.151 +// to use the super() method and do all of the work (aside from the 1.152 +// lazy computation of super()) in native mode. This may be 1.153 +// worthwhile if the compiler is repeatedly requesting the same lca 1.154 +// computation or possibly if most of the superklasses have already 1.155 +// been created as ciObjects anyway. Something to think about... 1.156 +ciKlass* 1.157 +ciKlass::least_common_ancestor(ciKlass* that) { 1.158 + assert(is_loaded() && that->is_loaded(), "must be loaded"); 1.159 + assert(is_java_klass() && that->is_java_klass(), "must be java klasses"); 1.160 + // Check to see if the klasses are identical. 1.161 + if (this == that) { 1.162 + return this; 1.163 + } 1.164 + 1.165 + VM_ENTRY_MARK; 1.166 + Klass* this_klass = get_Klass(); 1.167 + Klass* that_klass = that->get_Klass(); 1.168 + Klass* lca = this_klass->LCA(that_klass); 1.169 + 1.170 + // Many times the LCA will be either this_klass or that_klass. 1.171 + // Treat these as special cases. 1.172 + if (lca == that_klass) { 1.173 + return that; 1.174 + } 1.175 + if (this_klass == lca) { 1.176 + return this; 1.177 + } 1.178 + 1.179 + // Create the ciInstanceKlass for the lca. 1.180 + ciKlass* result = 1.181 + CURRENT_THREAD_ENV->get_object(lca->as_klassOop())->as_klass(); 1.182 + 1.183 + return result; 1.184 +} 1.185 + 1.186 +// ------------------------------------------------------------------ 1.187 +// ciKlass::find_klass 1.188 +// 1.189 +// Find a klass using this klass's class loader. 1.190 +ciKlass* ciKlass::find_klass(ciSymbol* klass_name) { 1.191 + assert(is_loaded(), "cannot find_klass through an unloaded klass"); 1.192 + return CURRENT_ENV->get_klass_by_name(this, 1.193 + klass_name, false); 1.194 +} 1.195 + 1.196 +// ------------------------------------------------------------------ 1.197 +// ciKlass::java_mirror 1.198 +ciInstance* ciKlass::java_mirror() { 1.199 + GUARDED_VM_ENTRY( 1.200 + oop java_mirror = get_Klass()->java_mirror(); 1.201 + return CURRENT_ENV->get_object(java_mirror)->as_instance(); 1.202 + ) 1.203 +} 1.204 + 1.205 +// ------------------------------------------------------------------ 1.206 +// ciKlass::modifier_flags 1.207 +jint ciKlass::modifier_flags() { 1.208 + assert(is_loaded(), "not loaded"); 1.209 + GUARDED_VM_ENTRY( 1.210 + return get_Klass()->modifier_flags(); 1.211 + ) 1.212 +} 1.213 + 1.214 +// ------------------------------------------------------------------ 1.215 +// ciKlass::access_flags 1.216 +jint ciKlass::access_flags() { 1.217 + assert(is_loaded(), "not loaded"); 1.218 + GUARDED_VM_ENTRY( 1.219 + return get_Klass()->access_flags().as_int(); 1.220 + ) 1.221 +} 1.222 + 1.223 +// ------------------------------------------------------------------ 1.224 +// ciKlass::print_impl 1.225 +// 1.226 +// Implementation of the print method 1.227 +void ciKlass::print_impl(outputStream* st) { 1.228 + st->print(" name="); 1.229 + print_name_on(st); 1.230 +} 1.231 + 1.232 +// ------------------------------------------------------------------ 1.233 +// ciKlass::print_name 1.234 +// 1.235 +// Print the name of this klass 1.236 +void ciKlass::print_name_on(outputStream* st) { 1.237 + name()->print_symbol_on(st); 1.238 +}