Path: blob/master/src/hotspot/share/ci/ciInstanceKlass.hpp
40930 views
/*1* Copyright (c) 1999, 2021, 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#ifndef SHARE_CI_CIINSTANCEKLASS_HPP25#define SHARE_CI_CIINSTANCEKLASS_HPP2627#include "ci/ciConstantPoolCache.hpp"28#include "ci/ciFlags.hpp"29#include "ci/ciKlass.hpp"30#include "ci/ciSymbol.hpp"31#include "oops/instanceKlass.hpp"3233// ciInstanceKlass34//35// This class represents a Klass* in the HotSpot virtual machine36// whose Klass part is an InstanceKlass. It may or may not37// be loaded.38class ciInstanceKlass : public ciKlass {39CI_PACKAGE_ACCESS40friend class ciBytecodeStream;41friend class ciEnv;42friend class ciExceptionHandler;43friend class ciMethod;44friend class ciField;4546private:47enum SubklassValue { subklass_unknown, subklass_false, subklass_true };4849jobject _loader;50jobject _protection_domain;5152InstanceKlass::ClassState _init_state; // state of class53bool _is_shared;54bool _has_finalizer;55SubklassValue _has_subklass;56bool _has_nonstatic_fields;57bool _has_nonstatic_concrete_methods;58bool _is_hidden;59bool _is_record;6061ciFlags _flags;62jint _nonstatic_field_size;63jint _nonstatic_oop_map_size;6465// Lazy fields get filled in only upon request.66ciInstanceKlass* _super;67ciInstance* _java_mirror;6869ciConstantPoolCache* _field_cache; // cached map index->field70GrowableArray<ciField*>* _nonstatic_fields;71int _has_injected_fields; // any non static injected fields? lazily initialized.7273// The possible values of the _implementor fall into following three cases:74// NULL: no implementor.75// A ciInstanceKlass that's not itself: one implementor.76// Itself: more than one implementor.77ciInstanceKlass* _implementor;7879void compute_injected_fields();80bool compute_injected_fields_helper();8182protected:83ciInstanceKlass(Klass* k);84ciInstanceKlass(ciSymbol* name, jobject loader, jobject protection_domain);8586InstanceKlass* get_instanceKlass() const {87return InstanceKlass::cast(get_Klass());88}8990oop loader();91jobject loader_handle();9293oop protection_domain();94jobject protection_domain_handle();9596const char* type_string() { return "ciInstanceKlass"; }9798bool is_in_package_impl(const char* packagename, int len);99100void print_impl(outputStream* st);101102ciConstantPoolCache* field_cache();103104bool is_shared() { return _is_shared; }105106void compute_shared_init_state();107bool compute_shared_has_subklass();108int compute_nonstatic_fields();109GrowableArray<ciField*>* compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields);110111// Update the init_state for shared klasses112void update_if_shared(InstanceKlass::ClassState expected) {113if (_is_shared && _init_state != expected) {114if (is_loaded()) compute_shared_init_state();115}116}117118public:119// Has this klass been initialized?120bool is_initialized() {121update_if_shared(InstanceKlass::fully_initialized);122return _init_state == InstanceKlass::fully_initialized;123}124bool is_not_initialized() {125update_if_shared(InstanceKlass::fully_initialized);126return _init_state < InstanceKlass::being_initialized;127}128// Is this klass being initialized?129bool is_being_initialized() {130update_if_shared(InstanceKlass::being_initialized);131return _init_state == InstanceKlass::being_initialized;132}133// Has this klass been linked?134bool is_linked() {135update_if_shared(InstanceKlass::linked);136return _init_state >= InstanceKlass::linked;137}138// Is this klass in error state?139bool is_in_error_state() {140update_if_shared(InstanceKlass::initialization_error);141return _init_state == InstanceKlass::initialization_error;142}143144// General klass information.145ciFlags flags() {146assert(is_loaded(), "must be loaded");147return _flags;148}149bool has_finalizer() {150assert(is_loaded(), "must be loaded");151return _has_finalizer; }152bool has_subklass() {153assert(is_loaded(), "must be loaded");154// Ignore cached subklass_false case.155// It could be invalidated by concurrent class loading and156// can result in type paradoxes during compilation when157// a subclass is observed, but has_subklass() returns false.158if (_has_subklass == subklass_true) {159return true;160}161if (flags().is_final()) {162return false;163}164return compute_shared_has_subklass();165}166167jint size_helper() {168return (Klass::layout_helper_size_in_bytes(layout_helper())169>> LogHeapWordSize);170}171jint nonstatic_field_size() {172assert(is_loaded(), "must be loaded");173return _nonstatic_field_size; }174jint has_nonstatic_fields() {175assert(is_loaded(), "must be loaded");176return _has_nonstatic_fields; }177jint nonstatic_oop_map_size() {178assert(is_loaded(), "must be loaded");179return _nonstatic_oop_map_size; }180ciInstanceKlass* super();181jint nof_implementors() {182ciInstanceKlass* impl;183assert(is_loaded(), "must be loaded");184impl = implementor();185if (impl == NULL) {186return 0;187} else if (impl != this) {188return 1;189} else {190return 2;191}192}193bool has_nonstatic_concrete_methods() {194assert(is_loaded(), "must be loaded");195return _has_nonstatic_concrete_methods;196}197198bool is_hidden() const {199return _is_hidden;200}201202bool is_record() const {203return _is_record;204}205206ciInstanceKlass* get_canonical_holder(int offset);207ciField* get_field_by_offset(int field_offset, bool is_static);208ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static);209210// total number of nonstatic fields (including inherited):211int nof_nonstatic_fields() {212if (_nonstatic_fields == NULL)213return compute_nonstatic_fields();214else215return _nonstatic_fields->length();216}217218bool has_injected_fields() {219if (_has_injected_fields == -1) {220compute_injected_fields();221}222return _has_injected_fields > 0 ? true : false;223}224225bool has_object_fields() const;226227// nth nonstatic field (presented by ascending address)228ciField* nonstatic_field_at(int i) {229assert(_nonstatic_fields != NULL, "");230return _nonstatic_fields->at(i);231}232233ciInstanceKlass* unique_concrete_subklass();234bool has_finalizable_subclass();235236bool contains_field_offset(int offset);237238// Get the instance of java.lang.Class corresponding to239// this klass. This instance is used for locking of240// synchronized static methods of this klass.241ciInstance* java_mirror();242243// Java access flags244bool is_public () { return flags().is_public(); }245bool is_final () { return flags().is_final(); }246bool is_super () { return flags().is_super(); }247bool is_interface () { return flags().is_interface(); }248bool is_abstract () { return flags().is_abstract(); }249250ciMethod* find_method(ciSymbol* name, ciSymbol* signature);251// Note: To find a method from name and type strings, use ciSymbol::make,252// but consider adding to vmSymbols.hpp instead.253254bool is_leaf_type();255ciInstanceKlass* implementor();256257ciInstanceKlass* unique_implementor() {258assert(is_loaded(), "must be loaded");259ciInstanceKlass* impl = implementor();260return (impl != this ? impl : NULL);261}262263// Is the defining class loader of this class the default loader?264bool uses_default_loader() const;265266bool is_java_lang_Object() const;267268BasicType box_klass_type() const;269bool is_box_klass() const;270bool is_boxed_value_offset(int offset) const;271bool is_box_cache_valid() const;272273// Is this klass in the given package?274bool is_in_package(const char* packagename) {275return is_in_package(packagename, (int) strlen(packagename));276}277bool is_in_package(const char* packagename, int len);278279// What kind of ciObject is this?280bool is_instance_klass() const { return true; }281bool is_java_klass() const { return true; }282283virtual ciKlass* exact_klass() {284if (is_loaded() && is_final() && !is_interface()) {285return this;286}287return NULL;288}289290bool can_be_instantiated() {291assert(is_loaded(), "must be loaded");292return !is_interface() && !is_abstract();293}294295// Dump the current state of this klass for compilation replay.296virtual void dump_replay_data(outputStream* out);297298#ifdef ASSERT299bool debug_final_field_at(int offset);300bool debug_stable_field_at(int offset);301#endif302};303304#endif // SHARE_CI_CIINSTANCEKLASS_HPP305306307