1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/ciField.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,192 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_CI_CIFIELD_HPP 1.29 +#define SHARE_VM_CI_CIFIELD_HPP 1.30 + 1.31 +#include "ci/ciClassList.hpp" 1.32 +#include "ci/ciConstant.hpp" 1.33 +#include "ci/ciFlags.hpp" 1.34 +#include "ci/ciInstance.hpp" 1.35 + 1.36 +// ciField 1.37 +// 1.38 +// This class represents the result of a field lookup in the VM. 1.39 +// The lookup may not succeed, in which case the information in 1.40 +// the ciField will be incomplete. 1.41 +class ciField : public ResourceObj { 1.42 + CI_PACKAGE_ACCESS 1.43 + friend class ciEnv; 1.44 + friend class ciInstanceKlass; 1.45 + friend class NonStaticFieldFiller; 1.46 + 1.47 +private: 1.48 + ciFlags _flags; 1.49 + ciInstanceKlass* _holder; 1.50 + ciSymbol* _name; 1.51 + ciSymbol* _signature; 1.52 + ciType* _type; 1.53 + int _offset; 1.54 + bool _is_constant; 1.55 + ciInstanceKlass* _known_to_link_with_put; 1.56 + ciInstanceKlass* _known_to_link_with_get; 1.57 + ciConstant _constant_value; 1.58 + 1.59 + ciType* compute_type(); 1.60 + ciType* compute_type_impl(); 1.61 + 1.62 + ciField(ciInstanceKlass* klass, int index); 1.63 + ciField(fieldDescriptor* fd); 1.64 + 1.65 + // shared constructor code 1.66 + void initialize_from(fieldDescriptor* fd); 1.67 + 1.68 +public: 1.69 + ciFlags flags() { return _flags; } 1.70 + 1.71 + // Of which klass is this field a member? 1.72 + // 1.73 + // Usage note: the declared holder of a field is the class 1.74 + // referenced by name in the bytecodes. The canonical holder 1.75 + // is the most general class which holds the field. This 1.76 + // method returns the canonical holder. The declared holder 1.77 + // can be accessed via a method in ciBytecodeStream. 1.78 + // 1.79 + // Ex. 1.80 + // class A { 1.81 + // public int f = 7; 1.82 + // } 1.83 + // class B extends A { 1.84 + // public void test() { 1.85 + // System.out.println(f); 1.86 + // } 1.87 + // } 1.88 + // 1.89 + // A java compiler is permitted to compile the access to 1.90 + // field f as: 1.91 + // 1.92 + // getfield B.f 1.93 + // 1.94 + // In that case the declared holder of f would be B and 1.95 + // the canonical holder of f would be A. 1.96 + ciInstanceKlass* holder() { return _holder; } 1.97 + 1.98 + // Name of this field? 1.99 + ciSymbol* name() { return _name; } 1.100 + 1.101 + // Signature of this field? 1.102 + ciSymbol* signature() { return _signature; } 1.103 + 1.104 + // Of what type is this field? 1.105 + ciType* type() { return (_type == NULL) ? compute_type() : _type; } 1.106 + 1.107 + // How is this field actually stored in memory? 1.108 + BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; } 1.109 + 1.110 + // How big is this field in memory? 1.111 + int size_in_bytes() { return type2aelembytes(layout_type()); } 1.112 + 1.113 + // What is the offset of this field? 1.114 + int offset() { 1.115 + assert(_offset >= 1, "illegal call to offset()"); 1.116 + return _offset; 1.117 + } 1.118 + 1.119 + // Same question, explicit units. (Fields are aligned to the byte level.) 1.120 + int offset_in_bytes() { 1.121 + return offset(); 1.122 + } 1.123 + 1.124 + // Is this field shared? 1.125 + bool is_shared() { 1.126 + // non-static fields of shared holders are cached 1.127 + return _holder->is_shared() && !is_static(); 1.128 + } 1.129 + 1.130 + // Is this field a constant? 1.131 + // 1.132 + // Clarification: A field is considered constant if: 1.133 + // 1. The field is both static and final 1.134 + // 2. The canonical holder of the field has undergone 1.135 + // static initialization. 1.136 + // 3. If the field is an object or array, then the oop 1.137 + // in question is allocated in perm space. 1.138 + // 4. The field is not one of the special static/final 1.139 + // non-constant fields. These are java.lang.System.in 1.140 + // and java.lang.System.out. Abomination. 1.141 + // 1.142 + // A field is also considered constant if it is marked @Stable 1.143 + // and is non-null (or non-zero, if a primitive). 1.144 + // For non-static fields, the null/zero check must be 1.145 + // arranged by the user, as constant_value().is_null_or_zero(). 1.146 + bool is_constant() { return _is_constant; } 1.147 + 1.148 + // Get the constant value of this field. 1.149 + ciConstant constant_value() { 1.150 + assert(is_static() && is_constant(), "illegal call to constant_value()"); 1.151 + return _constant_value; 1.152 + } 1.153 + 1.154 + // Get the constant value of non-static final field in the given 1.155 + // object. 1.156 + ciConstant constant_value_of(ciObject* object) { 1.157 + assert(!is_static() && is_constant(), "only if field is non-static constant"); 1.158 + assert(object->is_instance(), "must be instance"); 1.159 + return object->as_instance()->field_value(this); 1.160 + } 1.161 + 1.162 + // Check for link time errors. Accessing a field from a 1.163 + // certain class via a certain bytecode may or may not be legal. 1.164 + // This call checks to see if an exception may be raised by 1.165 + // an access of this field. 1.166 + // 1.167 + // Usage note: if the same field is accessed multiple times 1.168 + // in the same compilation, will_link will need to be checked 1.169 + // at each point of access. 1.170 + bool will_link(ciInstanceKlass* accessing_klass, 1.171 + Bytecodes::Code bc); 1.172 + 1.173 + // Java access flags 1.174 + bool is_public () { return flags().is_public(); } 1.175 + bool is_private () { return flags().is_private(); } 1.176 + bool is_protected () { return flags().is_protected(); } 1.177 + bool is_static () { return flags().is_static(); } 1.178 + bool is_final () { return flags().is_final(); } 1.179 + bool is_stable () { return flags().is_stable(); } 1.180 + bool is_volatile () { return flags().is_volatile(); } 1.181 + bool is_transient () { return flags().is_transient(); } 1.182 + 1.183 + bool is_call_site_target() { 1.184 + ciInstanceKlass* callsite_klass = CURRENT_ENV->CallSite_klass(); 1.185 + if (callsite_klass == NULL) 1.186 + return false; 1.187 + return (holder()->is_subclass_of(callsite_klass) && (name() == ciSymbol::target_name())); 1.188 + } 1.189 + 1.190 + // Debugging output 1.191 + void print(); 1.192 + void print_name_on(outputStream* st); 1.193 +}; 1.194 + 1.195 +#endif // SHARE_VM_CI_CIFIELD_HPP