0N/A/*
2362N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A *
2362N/A */
0N/A
0N/A#include "precompiled.hpp"
0N/A#include "ci/ciKlass.hpp"
0N/A#include "ci/ciSymbol.hpp"
0N/A#include "ci/ciUtilities.hpp"
0N/A#include "oops/oop.inline.hpp"
0N/A
0N/A// ciKlass
0N/A//
0N/A// This class represents a klassOop in the HotSpot virtual
0N/A// machine.
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::ciKlass
0N/AciKlass::ciKlass(KlassHandle h_k) : ciType(h_k) {
0N/A assert(get_oop()->is_klass(), "wrong type");
0N/A Klass* k = get_Klass();
0N/A _layout_helper = k->layout_helper();
0N/A Symbol* klass_name = k->name();
0N/A assert(klass_name != NULL, "wrong ciKlass constructor");
0N/A _name = CURRENT_ENV->get_symbol(klass_name);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::ciKlass
0N/A//
0N/A// Nameless klass variant.
0N/AciKlass::ciKlass(KlassHandle h_k, ciSymbol* name) : ciType(h_k) {
0N/A assert(get_oop()->is_klass(), "wrong type");
0N/A _name = name;
0N/A _layout_helper = Klass::_lh_neutral_value;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::ciKlass
0N/A//
0N/A// Unloaded klass variant.
0N/AciKlass::ciKlass(ciSymbol* name, ciKlass* klass) : ciType(klass) {
0N/A _name = name;
0N/A _layout_helper = Klass::_lh_neutral_value;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::is_subtype_of
0N/Abool ciKlass::is_subtype_of(ciKlass* that) {
0N/A assert(is_loaded() && that->is_loaded(), "must be loaded");
0N/A assert(is_java_klass() && that->is_java_klass(), "must be java klasses");
0N/A // Check to see if the klasses are identical.
0N/A if (this == that) {
0N/A return true;
0N/A }
0N/A
0N/A VM_ENTRY_MARK;
0N/A Klass* this_klass = get_Klass();
0N/A klassOop that_klass = that->get_klassOop();
0N/A bool result = this_klass->is_subtype_of(that_klass);
0N/A
0N/A return result;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::is_subclass_of
0N/Abool ciKlass::is_subclass_of(ciKlass* that) {
0N/A assert(is_loaded() && that->is_loaded(), "must be loaded");
0N/A assert(is_java_klass() && that->is_java_klass(), "must be java klasses");
0N/A // Check to see if the klasses are identical.
0N/A
0N/A VM_ENTRY_MARK;
0N/A Klass* this_klass = get_Klass();
0N/A klassOop that_klass = that->get_klassOop();
0N/A bool result = this_klass->is_subclass_of(that_klass);
0N/A
0N/A return result;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::super_depth
0N/Ajuint ciKlass::super_depth() {
0N/A assert(is_loaded(), "must be loaded");
0N/A assert(is_java_klass(), "must be java klasses");
0N/A
0N/A VM_ENTRY_MARK;
0N/A Klass* this_klass = get_Klass();
0N/A return this_klass->super_depth();
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::super_check_offset
0N/Ajuint ciKlass::super_check_offset() {
0N/A assert(is_loaded(), "must be loaded");
0N/A assert(is_java_klass(), "must be java klasses");
0N/A
0N/A VM_ENTRY_MARK;
1686N/A Klass* this_klass = get_Klass();
0N/A return this_klass->super_check_offset();
0N/A}
215N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::super_of_depth
0N/AciKlass* ciKlass::super_of_depth(juint i) {
0N/A assert(is_loaded(), "must be loaded");
0N/A assert(is_java_klass(), "must be java klasses");
0N/A
0N/A VM_ENTRY_MARK;
0N/A Klass* this_klass = get_Klass();
0N/A klassOop super = this_klass->primary_super_of_depth(i);
0N/A return (super != NULL) ? CURRENT_THREAD_ENV->get_object(super)->as_klass() : NULL;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::can_be_primary_super
0N/Abool ciKlass::can_be_primary_super() {
0N/A assert(is_loaded(), "must be loaded");
0N/A assert(is_java_klass(), "must be java klasses");
0N/A
0N/A VM_ENTRY_MARK;
0N/A Klass* this_klass = get_Klass();
0N/A return this_klass->can_be_primary_super();
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::least_common_ancestor
0N/A//
0N/A// Get the shared parent of two klasses.
0N/A//
0N/A// Implementation note: this method currently goes "over the wall"
0N/A// and does all of the work on the VM side. It could be rewritten
0N/A// to use the super() method and do all of the work (aside from the
0N/A// lazy computation of super()) in native mode. This may be
0N/A// worthwhile if the compiler is repeatedly requesting the same lca
0N/A// computation or possibly if most of the superklasses have already
0N/A// been created as ciObjects anyway. Something to think about...
0N/AciKlass*
0N/AciKlass::least_common_ancestor(ciKlass* that) {
0N/A assert(is_loaded() && that->is_loaded(), "must be loaded");
0N/A assert(is_java_klass() && that->is_java_klass(), "must be java klasses");
0N/A // Check to see if the klasses are identical.
0N/A if (this == that) {
0N/A return this;
0N/A }
0N/A
0N/A VM_ENTRY_MARK;
0N/A Klass* this_klass = get_Klass();
0N/A Klass* that_klass = that->get_Klass();
0N/A Klass* lca = this_klass->LCA(that_klass);
0N/A
0N/A // Many times the LCA will be either this_klass or that_klass.
0N/A // Treat these as special cases.
0N/A if (lca == that_klass) {
0N/A return that;
0N/A }
0N/A if (this_klass == lca) {
0N/A return this;
0N/A }
0N/A
0N/A // Create the ciInstanceKlass for the lca.
0N/A ciKlass* result =
0N/A CURRENT_THREAD_ENV->get_object(lca->as_klassOop())->as_klass();
0N/A
0N/A return result;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::find_klass
0N/A//
0N/A// Find a klass using this klass's class loader.
0N/AciKlass* ciKlass::find_klass(ciSymbol* klass_name) {
0N/A assert(is_loaded(), "cannot find_klass through an unloaded klass");
0N/A return CURRENT_ENV->get_klass_by_name(this,
0N/A klass_name, false);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::java_mirror
0N/A//
0N/A// Get the instance of java.lang.Class corresponding to this klass.
0N/A// If it is an unloaded instance or array klass, return an unloaded
0N/A// mirror object of type Class.
0N/AciInstance* ciKlass::java_mirror() {
0N/A GUARDED_VM_ENTRY(
0N/A if (!is_loaded())
0N/A return ciEnv::current()->get_unloaded_klass_mirror(this);
0N/A oop java_mirror = get_Klass()->java_mirror();
0N/A return CURRENT_ENV->get_object(java_mirror)->as_instance();
0N/A )
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::modifier_flags
0N/Ajint ciKlass::modifier_flags() {
0N/A assert(is_loaded(), "not loaded");
0N/A GUARDED_VM_ENTRY(
0N/A return get_Klass()->modifier_flags();
0N/A )
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::access_flags
0N/Ajint ciKlass::access_flags() {
0N/A assert(is_loaded(), "not loaded");
0N/A GUARDED_VM_ENTRY(
0N/A return get_Klass()->access_flags().as_int();
0N/A )
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::print_impl
0N/A//
0N/A// Implementation of the print method
0N/Avoid ciKlass::print_impl(outputStream* st) {
0N/A st->print(" name=");
0N/A print_name_on(st);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciKlass::print_name
0N/A//
0N/A// Print the name of this klass
0N/Avoid ciKlass::print_name_on(outputStream* st) {
0N/A name()->print_symbol_on(st);
0N/A}
0N/A