1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/ciKlass.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,239 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "ci/ciKlass.hpp" 1.30 +#include "ci/ciSymbol.hpp" 1.31 +#include "ci/ciUtilities.hpp" 1.32 +#include "oops/oop.inline.hpp" 1.33 + 1.34 +// ciKlass 1.35 +// 1.36 +// This class represents a Klass* in the HotSpot virtual 1.37 +// machine. 1.38 + 1.39 +// ------------------------------------------------------------------ 1.40 +// ciKlass::ciKlass 1.41 +ciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) { 1.42 + assert(get_Klass()->is_klass(), "wrong type"); 1.43 + Klass* k = get_Klass(); 1.44 + _layout_helper = k->layout_helper(); 1.45 + Symbol* klass_name = k->name(); 1.46 + assert(klass_name != NULL, "wrong ciKlass constructor"); 1.47 + _name = CURRENT_ENV->get_symbol(klass_name); 1.48 +} 1.49 + 1.50 +// ------------------------------------------------------------------ 1.51 +// ciKlass::ciKlass 1.52 +// 1.53 +// Nameless klass variant. 1.54 +ciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) { 1.55 + assert(get_Klass()->is_klass(), "wrong type"); 1.56 + _name = name; 1.57 + _layout_helper = Klass::_lh_neutral_value; 1.58 +} 1.59 + 1.60 +// ------------------------------------------------------------------ 1.61 +// ciKlass::ciKlass 1.62 +// 1.63 +// Unloaded klass variant. 1.64 +ciKlass::ciKlass(ciSymbol* name, BasicType bt) : ciType(bt) { 1.65 + _name = name; 1.66 + _layout_helper = Klass::_lh_neutral_value; 1.67 +} 1.68 + 1.69 +// ------------------------------------------------------------------ 1.70 +// ciKlass::is_subtype_of 1.71 +bool ciKlass::is_subtype_of(ciKlass* that) { 1.72 + assert(this->is_loaded(), err_msg("must be loaded: %s", this->name()->as_quoted_ascii())); 1.73 + assert(that->is_loaded(), err_msg("must be loaded: %s", that->name()->as_quoted_ascii())); 1.74 + 1.75 + // Check to see if the klasses are identical. 1.76 + if (this == that) { 1.77 + return true; 1.78 + } 1.79 + 1.80 + VM_ENTRY_MARK; 1.81 + Klass* this_klass = get_Klass(); 1.82 + Klass* that_klass = that->get_Klass(); 1.83 + bool result = this_klass->is_subtype_of(that_klass); 1.84 + 1.85 + return result; 1.86 +} 1.87 + 1.88 +// ------------------------------------------------------------------ 1.89 +// ciKlass::is_subclass_of 1.90 +bool ciKlass::is_subclass_of(ciKlass* that) { 1.91 + assert(this->is_loaded(), err_msg("must be loaded: %s", this->name()->as_quoted_ascii())); 1.92 + assert(that->is_loaded(), err_msg("must be loaded: %s", that->name()->as_quoted_ascii())); 1.93 + 1.94 + VM_ENTRY_MARK; 1.95 + Klass* this_klass = get_Klass(); 1.96 + Klass* that_klass = that->get_Klass(); 1.97 + bool result = this_klass->is_subclass_of(that_klass); 1.98 + 1.99 + return result; 1.100 +} 1.101 + 1.102 +// ------------------------------------------------------------------ 1.103 +// ciKlass::super_depth 1.104 +juint ciKlass::super_depth() { 1.105 + assert(is_loaded(), "must be loaded"); 1.106 + 1.107 + VM_ENTRY_MARK; 1.108 + Klass* this_klass = get_Klass(); 1.109 + return this_klass->super_depth(); 1.110 +} 1.111 + 1.112 +// ------------------------------------------------------------------ 1.113 +// ciKlass::super_check_offset 1.114 +juint ciKlass::super_check_offset() { 1.115 + assert(is_loaded(), "must be loaded"); 1.116 + 1.117 + VM_ENTRY_MARK; 1.118 + Klass* this_klass = get_Klass(); 1.119 + return this_klass->super_check_offset(); 1.120 +} 1.121 + 1.122 +// ------------------------------------------------------------------ 1.123 +// ciKlass::super_of_depth 1.124 +ciKlass* ciKlass::super_of_depth(juint i) { 1.125 + assert(is_loaded(), "must be loaded"); 1.126 + 1.127 + VM_ENTRY_MARK; 1.128 + Klass* this_klass = get_Klass(); 1.129 + Klass* super = this_klass->primary_super_of_depth(i); 1.130 + return (super != NULL) ? CURRENT_THREAD_ENV->get_klass(super) : 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 + 1.138 + VM_ENTRY_MARK; 1.139 + Klass* this_klass = get_Klass(); 1.140 + return this_klass->can_be_primary_super(); 1.141 +} 1.142 + 1.143 +// ------------------------------------------------------------------ 1.144 +// ciKlass::least_common_ancestor 1.145 +// 1.146 +// Get the shared parent of two klasses. 1.147 +// 1.148 +// Implementation note: this method currently goes "over the wall" 1.149 +// and does all of the work on the VM side. It could be rewritten 1.150 +// to use the super() method and do all of the work (aside from the 1.151 +// lazy computation of super()) in native mode. This may be 1.152 +// worthwhile if the compiler is repeatedly requesting the same lca 1.153 +// computation or possibly if most of the superklasses have already 1.154 +// been created as ciObjects anyway. Something to think about... 1.155 +ciKlass* 1.156 +ciKlass::least_common_ancestor(ciKlass* that) { 1.157 + assert(is_loaded() && that->is_loaded(), "must be loaded"); 1.158 + // Check to see if the klasses are identical. 1.159 + if (this == that) { 1.160 + return this; 1.161 + } 1.162 + 1.163 + VM_ENTRY_MARK; 1.164 + Klass* this_klass = get_Klass(); 1.165 + Klass* that_klass = that->get_Klass(); 1.166 + Klass* lca = this_klass->LCA(that_klass); 1.167 + 1.168 + // Many times the LCA will be either this_klass or that_klass. 1.169 + // Treat these as special cases. 1.170 + if (lca == that_klass) { 1.171 + return that; 1.172 + } 1.173 + if (this_klass == lca) { 1.174 + return this; 1.175 + } 1.176 + 1.177 + // Create the ciInstanceKlass for the lca. 1.178 + ciKlass* result = 1.179 + CURRENT_THREAD_ENV->get_klass(lca); 1.180 + 1.181 + return result; 1.182 +} 1.183 + 1.184 +// ------------------------------------------------------------------ 1.185 +// ciKlass::find_klass 1.186 +// 1.187 +// Find a klass using this klass's class loader. 1.188 +ciKlass* ciKlass::find_klass(ciSymbol* klass_name) { 1.189 + assert(is_loaded(), "cannot find_klass through an unloaded klass"); 1.190 + return CURRENT_ENV->get_klass_by_name(this, 1.191 + klass_name, false); 1.192 +} 1.193 + 1.194 +// ------------------------------------------------------------------ 1.195 +// ciKlass::java_mirror 1.196 +// 1.197 +// Get the instance of java.lang.Class corresponding to this klass. 1.198 +// If it is an unloaded instance or array klass, return an unloaded 1.199 +// mirror object of type Class. 1.200 +ciInstance* ciKlass::java_mirror() { 1.201 + GUARDED_VM_ENTRY( 1.202 + if (!is_loaded()) 1.203 + return ciEnv::current()->get_unloaded_klass_mirror(this); 1.204 + oop java_mirror = get_Klass()->java_mirror(); 1.205 + return CURRENT_ENV->get_instance(java_mirror); 1.206 + ) 1.207 +} 1.208 + 1.209 +// ------------------------------------------------------------------ 1.210 +// ciKlass::modifier_flags 1.211 +jint ciKlass::modifier_flags() { 1.212 + assert(is_loaded(), "not loaded"); 1.213 + GUARDED_VM_ENTRY( 1.214 + return get_Klass()->modifier_flags(); 1.215 + ) 1.216 +} 1.217 + 1.218 +// ------------------------------------------------------------------ 1.219 +// ciKlass::access_flags 1.220 +jint ciKlass::access_flags() { 1.221 + assert(is_loaded(), "not loaded"); 1.222 + GUARDED_VM_ENTRY( 1.223 + return get_Klass()->access_flags().as_int(); 1.224 + ) 1.225 +} 1.226 + 1.227 +// ------------------------------------------------------------------ 1.228 +// ciKlass::print_impl 1.229 +// 1.230 +// Implementation of the print method 1.231 +void ciKlass::print_impl(outputStream* st) { 1.232 + st->print(" name="); 1.233 + print_name_on(st); 1.234 +} 1.235 + 1.236 +// ------------------------------------------------------------------ 1.237 +// ciKlass::print_name 1.238 +// 1.239 +// Print the name of this klass 1.240 +void ciKlass::print_name_on(outputStream* st) { 1.241 + name()->print_symbol_on(st); 1.242 +}