src/share/vm/ci/ciKlass.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "ci/ciKlass.hpp"
aoqi@0 27 #include "ci/ciSymbol.hpp"
aoqi@0 28 #include "ci/ciUtilities.hpp"
aoqi@0 29 #include "oops/oop.inline.hpp"
aoqi@0 30
aoqi@0 31 // ciKlass
aoqi@0 32 //
aoqi@0 33 // This class represents a Klass* in the HotSpot virtual
aoqi@0 34 // machine.
aoqi@0 35
aoqi@0 36 // ------------------------------------------------------------------
aoqi@0 37 // ciKlass::ciKlass
aoqi@0 38 ciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) {
aoqi@0 39 assert(get_Klass()->is_klass(), "wrong type");
aoqi@0 40 Klass* k = get_Klass();
aoqi@0 41 _layout_helper = k->layout_helper();
aoqi@0 42 Symbol* klass_name = k->name();
aoqi@0 43 assert(klass_name != NULL, "wrong ciKlass constructor");
aoqi@0 44 _name = CURRENT_ENV->get_symbol(klass_name);
aoqi@0 45 }
aoqi@0 46
aoqi@0 47 // ------------------------------------------------------------------
aoqi@0 48 // ciKlass::ciKlass
aoqi@0 49 //
aoqi@0 50 // Nameless klass variant.
aoqi@0 51 ciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) {
aoqi@0 52 assert(get_Klass()->is_klass(), "wrong type");
aoqi@0 53 _name = name;
aoqi@0 54 _layout_helper = Klass::_lh_neutral_value;
aoqi@0 55 }
aoqi@0 56
aoqi@0 57 // ------------------------------------------------------------------
aoqi@0 58 // ciKlass::ciKlass
aoqi@0 59 //
aoqi@0 60 // Unloaded klass variant.
aoqi@0 61 ciKlass::ciKlass(ciSymbol* name, BasicType bt) : ciType(bt) {
aoqi@0 62 _name = name;
aoqi@0 63 _layout_helper = Klass::_lh_neutral_value;
aoqi@0 64 }
aoqi@0 65
aoqi@0 66 // ------------------------------------------------------------------
aoqi@0 67 // ciKlass::is_subtype_of
aoqi@0 68 bool ciKlass::is_subtype_of(ciKlass* that) {
aoqi@0 69 assert(this->is_loaded(), err_msg("must be loaded: %s", this->name()->as_quoted_ascii()));
aoqi@0 70 assert(that->is_loaded(), err_msg("must be loaded: %s", that->name()->as_quoted_ascii()));
aoqi@0 71
aoqi@0 72 // Check to see if the klasses are identical.
aoqi@0 73 if (this == that) {
aoqi@0 74 return true;
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 VM_ENTRY_MARK;
aoqi@0 78 Klass* this_klass = get_Klass();
aoqi@0 79 Klass* that_klass = that->get_Klass();
aoqi@0 80 bool result = this_klass->is_subtype_of(that_klass);
aoqi@0 81
aoqi@0 82 return result;
aoqi@0 83 }
aoqi@0 84
aoqi@0 85 // ------------------------------------------------------------------
aoqi@0 86 // ciKlass::is_subclass_of
aoqi@0 87 bool ciKlass::is_subclass_of(ciKlass* that) {
aoqi@0 88 assert(this->is_loaded(), err_msg("must be loaded: %s", this->name()->as_quoted_ascii()));
aoqi@0 89 assert(that->is_loaded(), err_msg("must be loaded: %s", that->name()->as_quoted_ascii()));
aoqi@0 90
aoqi@0 91 VM_ENTRY_MARK;
aoqi@0 92 Klass* this_klass = get_Klass();
aoqi@0 93 Klass* that_klass = that->get_Klass();
aoqi@0 94 bool result = this_klass->is_subclass_of(that_klass);
aoqi@0 95
aoqi@0 96 return result;
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 // ------------------------------------------------------------------
aoqi@0 100 // ciKlass::super_depth
aoqi@0 101 juint ciKlass::super_depth() {
aoqi@0 102 assert(is_loaded(), "must be loaded");
aoqi@0 103
aoqi@0 104 VM_ENTRY_MARK;
aoqi@0 105 Klass* this_klass = get_Klass();
aoqi@0 106 return this_klass->super_depth();
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 // ------------------------------------------------------------------
aoqi@0 110 // ciKlass::super_check_offset
aoqi@0 111 juint ciKlass::super_check_offset() {
aoqi@0 112 assert(is_loaded(), "must be loaded");
aoqi@0 113
aoqi@0 114 VM_ENTRY_MARK;
aoqi@0 115 Klass* this_klass = get_Klass();
aoqi@0 116 return this_klass->super_check_offset();
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 // ------------------------------------------------------------------
aoqi@0 120 // ciKlass::super_of_depth
aoqi@0 121 ciKlass* ciKlass::super_of_depth(juint i) {
aoqi@0 122 assert(is_loaded(), "must be loaded");
aoqi@0 123
aoqi@0 124 VM_ENTRY_MARK;
aoqi@0 125 Klass* this_klass = get_Klass();
aoqi@0 126 Klass* super = this_klass->primary_super_of_depth(i);
aoqi@0 127 return (super != NULL) ? CURRENT_THREAD_ENV->get_klass(super) : NULL;
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 // ------------------------------------------------------------------
aoqi@0 131 // ciKlass::can_be_primary_super
aoqi@0 132 bool ciKlass::can_be_primary_super() {
aoqi@0 133 assert(is_loaded(), "must be loaded");
aoqi@0 134
aoqi@0 135 VM_ENTRY_MARK;
aoqi@0 136 Klass* this_klass = get_Klass();
aoqi@0 137 return this_klass->can_be_primary_super();
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 // ------------------------------------------------------------------
aoqi@0 141 // ciKlass::least_common_ancestor
aoqi@0 142 //
aoqi@0 143 // Get the shared parent of two klasses.
aoqi@0 144 //
aoqi@0 145 // Implementation note: this method currently goes "over the wall"
aoqi@0 146 // and does all of the work on the VM side. It could be rewritten
aoqi@0 147 // to use the super() method and do all of the work (aside from the
aoqi@0 148 // lazy computation of super()) in native mode. This may be
aoqi@0 149 // worthwhile if the compiler is repeatedly requesting the same lca
aoqi@0 150 // computation or possibly if most of the superklasses have already
aoqi@0 151 // been created as ciObjects anyway. Something to think about...
aoqi@0 152 ciKlass*
aoqi@0 153 ciKlass::least_common_ancestor(ciKlass* that) {
aoqi@0 154 assert(is_loaded() && that->is_loaded(), "must be loaded");
aoqi@0 155 // Check to see if the klasses are identical.
aoqi@0 156 if (this == that) {
aoqi@0 157 return this;
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 VM_ENTRY_MARK;
aoqi@0 161 Klass* this_klass = get_Klass();
aoqi@0 162 Klass* that_klass = that->get_Klass();
aoqi@0 163 Klass* lca = this_klass->LCA(that_klass);
aoqi@0 164
aoqi@0 165 // Many times the LCA will be either this_klass or that_klass.
aoqi@0 166 // Treat these as special cases.
aoqi@0 167 if (lca == that_klass) {
aoqi@0 168 return that;
aoqi@0 169 }
aoqi@0 170 if (this_klass == lca) {
aoqi@0 171 return this;
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 // Create the ciInstanceKlass for the lca.
aoqi@0 175 ciKlass* result =
aoqi@0 176 CURRENT_THREAD_ENV->get_klass(lca);
aoqi@0 177
aoqi@0 178 return result;
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 // ------------------------------------------------------------------
aoqi@0 182 // ciKlass::find_klass
aoqi@0 183 //
aoqi@0 184 // Find a klass using this klass's class loader.
aoqi@0 185 ciKlass* ciKlass::find_klass(ciSymbol* klass_name) {
aoqi@0 186 assert(is_loaded(), "cannot find_klass through an unloaded klass");
aoqi@0 187 return CURRENT_ENV->get_klass_by_name(this,
aoqi@0 188 klass_name, false);
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 // ------------------------------------------------------------------
aoqi@0 192 // ciKlass::java_mirror
aoqi@0 193 //
aoqi@0 194 // Get the instance of java.lang.Class corresponding to this klass.
aoqi@0 195 // If it is an unloaded instance or array klass, return an unloaded
aoqi@0 196 // mirror object of type Class.
aoqi@0 197 ciInstance* ciKlass::java_mirror() {
aoqi@0 198 GUARDED_VM_ENTRY(
aoqi@0 199 if (!is_loaded())
aoqi@0 200 return ciEnv::current()->get_unloaded_klass_mirror(this);
aoqi@0 201 oop java_mirror = get_Klass()->java_mirror();
aoqi@0 202 return CURRENT_ENV->get_instance(java_mirror);
aoqi@0 203 )
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 // ------------------------------------------------------------------
aoqi@0 207 // ciKlass::modifier_flags
aoqi@0 208 jint ciKlass::modifier_flags() {
aoqi@0 209 assert(is_loaded(), "not loaded");
aoqi@0 210 GUARDED_VM_ENTRY(
aoqi@0 211 return get_Klass()->modifier_flags();
aoqi@0 212 )
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 // ------------------------------------------------------------------
aoqi@0 216 // ciKlass::access_flags
aoqi@0 217 jint ciKlass::access_flags() {
aoqi@0 218 assert(is_loaded(), "not loaded");
aoqi@0 219 GUARDED_VM_ENTRY(
aoqi@0 220 return get_Klass()->access_flags().as_int();
aoqi@0 221 )
aoqi@0 222 }
aoqi@0 223
aoqi@0 224 // ------------------------------------------------------------------
aoqi@0 225 // ciKlass::print_impl
aoqi@0 226 //
aoqi@0 227 // Implementation of the print method
aoqi@0 228 void ciKlass::print_impl(outputStream* st) {
aoqi@0 229 st->print(" name=");
aoqi@0 230 print_name_on(st);
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 // ------------------------------------------------------------------
aoqi@0 234 // ciKlass::print_name
aoqi@0 235 //
aoqi@0 236 // Print the name of this klass
aoqi@0 237 void ciKlass::print_name_on(outputStream* st) {
aoqi@0 238 name()->print_symbol_on(st);
aoqi@0 239 }

mercurial