Path: blob/master/src/hotspot/share/ci/ciField.hpp
40930 views
/*1* Copyright (c) 1999, 2019, 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_CIFIELD_HPP25#define SHARE_CI_CIFIELD_HPP2627#include "ci/ciClassList.hpp"28#include "ci/ciConstant.hpp"29#include "ci/ciFlags.hpp"30#include "ci/ciInstance.hpp"31#include "ci/ciUtilities.hpp"3233// ciField34//35// This class represents the result of a field lookup in the VM.36// The lookup may not succeed, in which case the information in37// the ciField will be incomplete.38class ciField : public ResourceObj {39CI_PACKAGE_ACCESS40friend class ciEnv;41friend class ciInstanceKlass;4243private:44ciFlags _flags;45ciInstanceKlass* _holder;46ciSymbol* _name;47ciSymbol* _signature;48ciType* _type;49int _offset;50bool _is_constant;51ciMethod* _known_to_link_with_put;52ciInstanceKlass* _known_to_link_with_get;53ciConstant _constant_value;5455ciType* compute_type();56ciType* compute_type_impl();5758ciField(ciInstanceKlass* klass, int index);59ciField(fieldDescriptor* fd);6061// shared constructor code62void initialize_from(fieldDescriptor* fd);6364public:65ciFlags flags() const { return _flags; }6667// Of which klass is this field a member?68//69// Usage note: the declared holder of a field is the class70// referenced by name in the bytecodes. The canonical holder71// is the most general class which holds the field. This72// method returns the canonical holder. The declared holder73// can be accessed via a method in ciBytecodeStream.74//75// Ex.76// class A {77// public int f = 7;78// }79// class B extends A {80// public void test() {81// System.out.println(f);82// }83// }84//85// A java compiler is permitted to compile the access to86// field f as:87//88// getfield B.f89//90// In that case the declared holder of f would be B and91// the canonical holder of f would be A.92ciInstanceKlass* holder() const { return _holder; }9394// Name of this field?95ciSymbol* name() const { return _name; }9697// Signature of this field?98ciSymbol* signature() const { return _signature; }99100// Of what type is this field?101ciType* type() { return (_type == NULL) ? compute_type() : _type; }102103// How is this field actually stored in memory?104BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; }105106// How big is this field in memory?107int size_in_bytes() { return type2aelembytes(layout_type()); }108109// What is the offset of this field?110int offset() const {111assert(_offset >= 1, "illegal call to offset()");112return _offset;113}114115// Same question, explicit units. (Fields are aligned to the byte level.)116int offset_in_bytes() const {117return offset();118}119120// Is this field shared?121bool is_shared() {122// non-static fields of shared holders are cached123return _holder->is_shared() && !is_static();124}125126// Is this field a constant?127//128// Clarification: A field is considered constant if:129// 1. The field is both static and final130// 2. The field is not one of the special static/final131// non-constant fields. These are java.lang.System.in132// and java.lang.System.out. Abomination.133//134// A field is also considered constant if135// - it is marked @Stable and is non-null (or non-zero, if a primitive) or136// - it is trusted or137// - it is the target field of a CallSite object.138//139// See ciField::initialize_from() for more details.140//141// A user should also check the field value (constant_value().is_valid()), since142// constant fields of non-initialized classes don't have values yet.143bool is_constant() const { return _is_constant; }144145// Get the constant value of the static field.146ciConstant constant_value();147148bool is_static_constant() {149return is_static() && is_constant() && constant_value().is_valid();150}151152// Get the constant value of non-static final field in the given153// object.154ciConstant constant_value_of(ciObject* object);155156// Check for link time errors. Accessing a field from a157// certain method via a certain bytecode may or may not be legal.158// This call checks to see if an exception may be raised by159// an access of this field.160//161// Usage note: if the same field is accessed multiple times162// in the same compilation, will_link will need to be checked163// at each point of access.164bool will_link(ciMethod* accessing_method,165Bytecodes::Code bc);166167// Java access flags168bool is_public () const { return flags().is_public(); }169bool is_private () const { return flags().is_private(); }170bool is_protected () const { return flags().is_protected(); }171bool is_static () const { return flags().is_static(); }172bool is_final () const { return flags().is_final(); }173bool is_stable () const { return flags().is_stable(); }174bool is_volatile () const { return flags().is_volatile(); }175bool is_transient () const { return flags().is_transient(); }176// The field is modified outside of instance initializer methods177// (or class/initializer methods if the field is static).178bool has_initialized_final_update() const { return flags().has_initialized_final_update(); }179180bool is_call_site_target();181182bool is_autobox_cache();183184// Debugging output185void print();186void print_name_on(outputStream* st);187};188189#endif // SHARE_CI_CIFIELD_HPP190191192