Path: blob/master/src/hotspot/share/ci/ciKlass.cpp
40930 views
/*1* Copyright (c) 1999, 2020, 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.inline.hpp"28#include "oops/klass.inline.hpp"29#include "oops/oop.inline.hpp"3031// ciKlass32//33// This class represents a Klass* in the HotSpot virtual34// machine.3536// ------------------------------------------------------------------37// ciKlass::ciKlass38ciKlass::ciKlass(Klass* k) : ciType(k) {39assert(get_Klass()->is_klass(), "wrong type");40Klass* klass = get_Klass();41_layout_helper = klass->layout_helper();42Symbol* klass_name = klass->name();43assert(klass_name != NULL, "wrong ciKlass constructor");44_name = CURRENT_ENV->get_symbol(klass_name);45}4647// ------------------------------------------------------------------48// ciKlass::ciKlass49//50// Nameless klass variant.51ciKlass::ciKlass(Klass* k, ciSymbol* name) : ciType(k) {52assert(get_Klass()->is_klass(), "wrong type");53_name = name;54_layout_helper = Klass::_lh_neutral_value;55}5657// ------------------------------------------------------------------58// ciKlass::ciKlass59//60// Unloaded klass variant.61ciKlass::ciKlass(ciSymbol* name, BasicType bt) : ciType(bt) {62_name = name;63_layout_helper = Klass::_lh_neutral_value;64}6566// ------------------------------------------------------------------67// ciKlass::is_subtype_of68bool ciKlass::is_subtype_of(ciKlass* that) {69assert(this->is_loaded(), "must be loaded: %s", this->name()->as_quoted_ascii());70assert(that->is_loaded(), "must be loaded: %s", that->name()->as_quoted_ascii());7172// Check to see if the klasses are identical.73if (this == that) {74return true;75}7677bool is_subtype;78GUARDED_VM_ENTRY(is_subtype = get_Klass()->is_subtype_of(that->get_Klass());)7980// Ensure consistency with ciInstanceKlass::has_subklass().81assert(!that->is_instance_klass() || // array klasses are irrelevant82that->is_interface() || // has_subklass is always false for interfaces83!is_subtype || that->as_instance_klass()->has_subklass(), "inconsistent");8485return is_subtype;86}8788// ------------------------------------------------------------------89// ciKlass::is_subclass_of90bool ciKlass::is_subclass_of(ciKlass* that) {91assert(this->is_loaded(), "must be loaded: %s", this->name()->as_quoted_ascii());92assert(that->is_loaded(), "must be loaded: %s", that->name()->as_quoted_ascii());9394// Check to see if the klasses are identical.95if (this == that) {96return true;97}9899bool is_subclass;100GUARDED_VM_ENTRY(is_subclass = get_Klass()->is_subclass_of(that->get_Klass());)101102// Ensure consistency with ciInstanceKlass::has_subklass().103assert(!that->is_instance_klass() || // array klasses are irrelevant104that->is_interface() || // has_subklass is always false for interfaces105!is_subclass || that->as_instance_klass()->has_subklass(), "inconsistent");106107return is_subclass;108}109110// ------------------------------------------------------------------111// ciKlass::super_depth112juint ciKlass::super_depth() {113assert(is_loaded(), "must be loaded");114115VM_ENTRY_MARK;116Klass* this_klass = get_Klass();117return this_klass->super_depth();118}119120// ------------------------------------------------------------------121// ciKlass::super_check_offset122juint ciKlass::super_check_offset() {123assert(is_loaded(), "must be loaded");124125VM_ENTRY_MARK;126Klass* this_klass = get_Klass();127return this_klass->super_check_offset();128}129130// ------------------------------------------------------------------131// ciKlass::super_of_depth132ciKlass* ciKlass::super_of_depth(juint i) {133assert(is_loaded(), "must be loaded");134135VM_ENTRY_MARK;136Klass* this_klass = get_Klass();137Klass* super = this_klass->primary_super_of_depth(i);138return (super != NULL) ? CURRENT_THREAD_ENV->get_klass(super) : NULL;139}140141// ------------------------------------------------------------------142// ciKlass::least_common_ancestor143//144// Get the shared parent of two klasses.145//146// Implementation note: this method currently goes "over the wall"147// and does all of the work on the VM side. It could be rewritten148// to use the super() method and do all of the work (aside from the149// lazy computation of super()) in native mode. This may be150// worthwhile if the compiler is repeatedly requesting the same lca151// computation or possibly if most of the superklasses have already152// been created as ciObjects anyway. Something to think about...153ciKlass*154ciKlass::least_common_ancestor(ciKlass* that) {155assert(is_loaded() && that->is_loaded(), "must be loaded");156// Check to see if the klasses are identical.157if (this == that) {158return this;159}160161VM_ENTRY_MARK;162Klass* this_klass = get_Klass();163Klass* that_klass = that->get_Klass();164Klass* lca = this_klass->LCA(that_klass);165166// Many times the LCA will be either this_klass or that_klass.167// Treat these as special cases.168if (lca == that_klass) {169assert(this->is_subtype_of(that), "sanity");170return that;171}172if (this_klass == lca) {173assert(that->is_subtype_of(this), "sanity");174return this;175}176177// Create the ciInstanceKlass for the lca.178ciKlass* result =179CURRENT_THREAD_ENV->get_klass(lca);180181assert(this->is_subtype_of(result) && that->is_subtype_of(result), "sanity");182return result;183}184185// ------------------------------------------------------------------186// ciKlass::find_klass187//188// Find a klass using this klass's class loader.189ciKlass* ciKlass::find_klass(ciSymbol* klass_name) {190assert(is_loaded(), "cannot find_klass through an unloaded klass");191return CURRENT_ENV->get_klass_by_name(this,192klass_name, false);193}194195// ------------------------------------------------------------------196// ciKlass::java_mirror197//198// Get the instance of java.lang.Class corresponding to this klass.199// If it is an unloaded instance or array klass, return an unloaded200// mirror object of type Class.201ciInstance* ciKlass::java_mirror() {202GUARDED_VM_ENTRY(203if (!is_loaded())204return ciEnv::current()->get_unloaded_klass_mirror(this);205oop java_mirror = get_Klass()->java_mirror();206return CURRENT_ENV->get_instance(java_mirror);207)208}209210// ------------------------------------------------------------------211// ciKlass::modifier_flags212jint ciKlass::modifier_flags() {213assert(is_loaded(), "not loaded");214GUARDED_VM_ENTRY(215return get_Klass()->modifier_flags();216)217}218219// ------------------------------------------------------------------220// ciKlass::access_flags221jint ciKlass::access_flags() {222assert(is_loaded(), "not loaded");223GUARDED_VM_ENTRY(224return get_Klass()->access_flags().as_int();225)226}227228// ------------------------------------------------------------------229// ciKlass::print_impl230//231// Implementation of the print method232void ciKlass::print_impl(outputStream* st) {233st->print(" name=");234print_name_on(st);235}236237// ------------------------------------------------------------------238// ciKlass::print_name239//240// Print the name of this klass241void ciKlass::print_name_on(outputStream* st) {242name()->print_symbol_on(st);243}244245const char* ciKlass::external_name() const {246GUARDED_VM_ENTRY(247return get_Klass()->external_name();248)249}250251252