Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciKlass.cpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "ci/ciKlass.hpp"26#include "ci/ciSymbol.hpp"27#include "ci/ciUtilities.hpp"28#include "oops/oop.inline.hpp"2930// ciKlass31//32// This class represents a Klass* in the HotSpot virtual33// machine.3435// ------------------------------------------------------------------36// ciKlass::ciKlass37ciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) {38assert(get_Klass()->is_klass(), "wrong type");39Klass* k = get_Klass();40_layout_helper = k->layout_helper();41Symbol* klass_name = k->name();42assert(klass_name != NULL, "wrong ciKlass constructor");43_name = CURRENT_ENV->get_symbol(klass_name);44}4546// ------------------------------------------------------------------47// ciKlass::ciKlass48//49// Nameless klass variant.50ciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) {51assert(get_Klass()->is_klass(), "wrong type");52_name = name;53_layout_helper = Klass::_lh_neutral_value;54}5556// ------------------------------------------------------------------57// ciKlass::ciKlass58//59// Unloaded klass variant.60ciKlass::ciKlass(ciSymbol* name, BasicType bt) : ciType(bt) {61_name = name;62_layout_helper = Klass::_lh_neutral_value;63}6465// ------------------------------------------------------------------66// ciKlass::is_subtype_of67bool ciKlass::is_subtype_of(ciKlass* that) {68assert(this->is_loaded(), err_msg("must be loaded: %s", this->name()->as_quoted_ascii()));69assert(that->is_loaded(), err_msg("must be loaded: %s", that->name()->as_quoted_ascii()));7071// Check to see if the klasses are identical.72if (this == that) {73return true;74}7576VM_ENTRY_MARK;77Klass* this_klass = get_Klass();78Klass* that_klass = that->get_Klass();79bool result = this_klass->is_subtype_of(that_klass);8081return result;82}8384// ------------------------------------------------------------------85// ciKlass::is_subclass_of86bool ciKlass::is_subclass_of(ciKlass* that) {87assert(this->is_loaded(), err_msg("must be loaded: %s", this->name()->as_quoted_ascii()));88assert(that->is_loaded(), err_msg("must be loaded: %s", that->name()->as_quoted_ascii()));8990VM_ENTRY_MARK;91Klass* this_klass = get_Klass();92Klass* that_klass = that->get_Klass();93bool result = this_klass->is_subclass_of(that_klass);9495return result;96}9798// ------------------------------------------------------------------99// ciKlass::super_depth100juint ciKlass::super_depth() {101assert(is_loaded(), "must be loaded");102103VM_ENTRY_MARK;104Klass* this_klass = get_Klass();105return this_klass->super_depth();106}107108// ------------------------------------------------------------------109// ciKlass::super_check_offset110juint ciKlass::super_check_offset() {111assert(is_loaded(), "must be loaded");112113VM_ENTRY_MARK;114Klass* this_klass = get_Klass();115return this_klass->super_check_offset();116}117118// ------------------------------------------------------------------119// ciKlass::super_of_depth120ciKlass* ciKlass::super_of_depth(juint i) {121assert(is_loaded(), "must be loaded");122123VM_ENTRY_MARK;124Klass* this_klass = get_Klass();125Klass* super = this_klass->primary_super_of_depth(i);126return (super != NULL) ? CURRENT_THREAD_ENV->get_klass(super) : NULL;127}128129// ------------------------------------------------------------------130// ciKlass::can_be_primary_super131bool ciKlass::can_be_primary_super() {132assert(is_loaded(), "must be loaded");133134VM_ENTRY_MARK;135Klass* this_klass = get_Klass();136return this_klass->can_be_primary_super();137}138139// ------------------------------------------------------------------140// ciKlass::least_common_ancestor141//142// Get the shared parent of two klasses.143//144// Implementation note: this method currently goes "over the wall"145// and does all of the work on the VM side. It could be rewritten146// to use the super() method and do all of the work (aside from the147// lazy computation of super()) in native mode. This may be148// worthwhile if the compiler is repeatedly requesting the same lca149// computation or possibly if most of the superklasses have already150// been created as ciObjects anyway. Something to think about...151ciKlass*152ciKlass::least_common_ancestor(ciKlass* that) {153assert(is_loaded() && that->is_loaded(), "must be loaded");154// Check to see if the klasses are identical.155if (this == that) {156return this;157}158159VM_ENTRY_MARK;160Klass* this_klass = get_Klass();161Klass* that_klass = that->get_Klass();162Klass* lca = this_klass->LCA(that_klass);163164// Many times the LCA will be either this_klass or that_klass.165// Treat these as special cases.166if (lca == that_klass) {167return that;168}169if (this_klass == lca) {170return this;171}172173// Create the ciInstanceKlass for the lca.174ciKlass* result =175CURRENT_THREAD_ENV->get_klass(lca);176177return result;178}179180// ------------------------------------------------------------------181// ciKlass::find_klass182//183// Find a klass using this klass's class loader.184ciKlass* ciKlass::find_klass(ciSymbol* klass_name) {185assert(is_loaded(), "cannot find_klass through an unloaded klass");186return CURRENT_ENV->get_klass_by_name(this,187klass_name, false);188}189190// ------------------------------------------------------------------191// ciKlass::java_mirror192//193// Get the instance of java.lang.Class corresponding to this klass.194// If it is an unloaded instance or array klass, return an unloaded195// mirror object of type Class.196ciInstance* ciKlass::java_mirror() {197GUARDED_VM_ENTRY(198if (!is_loaded())199return ciEnv::current()->get_unloaded_klass_mirror(this);200oop java_mirror = get_Klass()->java_mirror();201return CURRENT_ENV->get_instance(java_mirror);202)203}204205// ------------------------------------------------------------------206// ciKlass::modifier_flags207jint ciKlass::modifier_flags() {208assert(is_loaded(), "not loaded");209GUARDED_VM_ENTRY(210return get_Klass()->modifier_flags();211)212}213214// ------------------------------------------------------------------215// ciKlass::access_flags216jint ciKlass::access_flags() {217assert(is_loaded(), "not loaded");218GUARDED_VM_ENTRY(219return get_Klass()->access_flags().as_int();220)221}222223// ------------------------------------------------------------------224// ciKlass::print_impl225//226// Implementation of the print method227void ciKlass::print_impl(outputStream* st) {228st->print(" name=");229print_name_on(st);230}231232// ------------------------------------------------------------------233// ciKlass::print_name234//235// Print the name of this klass236void ciKlass::print_name_on(outputStream* st) {237name()->print_symbol_on(st);238}239240241