1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/fieldDescriptor.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,131 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 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_RUNTIME_FIELDDESCRIPTOR_HPP 1.29 +#define SHARE_VM_RUNTIME_FIELDDESCRIPTOR_HPP 1.30 + 1.31 +#include "oops/constantPool.hpp" 1.32 +#include "oops/symbol.hpp" 1.33 +#include "runtime/fieldType.hpp" 1.34 +#include "utilities/accessFlags.hpp" 1.35 +#include "utilities/constantTag.hpp" 1.36 + 1.37 +// A fieldDescriptor describes the attributes of a single field (instance or class variable). 1.38 +// It needs the class constant pool to work (because it only holds indices into the pool 1.39 +// rather than the actual info). 1.40 + 1.41 +class fieldDescriptor VALUE_OBJ_CLASS_SPEC { 1.42 + private: 1.43 + AccessFlags _access_flags; 1.44 + int _index; // the field index 1.45 + constantPoolHandle _cp; 1.46 + 1.47 + // update the access_flags for the field in the klass 1.48 + void update_klass_field_access_flag() { 1.49 + InstanceKlass* ik = field_holder(); 1.50 + ik->field(index())->set_access_flags(_access_flags.as_short()); 1.51 + } 1.52 + 1.53 + FieldInfo* field() const { 1.54 + InstanceKlass* ik = field_holder(); 1.55 + return ik->field(_index); 1.56 + } 1.57 + 1.58 + public: 1.59 + fieldDescriptor() { 1.60 + DEBUG_ONLY(_index = badInt); 1.61 + } 1.62 + fieldDescriptor(InstanceKlass* ik, int index) { 1.63 + DEBUG_ONLY(_index = badInt); 1.64 + reinitialize(ik, index); 1.65 + } 1.66 + Symbol* name() const { 1.67 + return field()->name(_cp); 1.68 + } 1.69 + Symbol* signature() const { 1.70 + return field()->signature(_cp); 1.71 + } 1.72 + InstanceKlass* field_holder() const { return _cp->pool_holder(); } 1.73 + ConstantPool* constants() const { return _cp(); } 1.74 + AccessFlags access_flags() const { return _access_flags; } 1.75 + oop loader() const; 1.76 + // Offset (in words) of field from start of instanceOop / Klass* 1.77 + int offset() const { return field()->offset(); } 1.78 + Symbol* generic_signature() const; 1.79 + int index() const { return _index; } 1.80 + AnnotationArray* annotations() const; 1.81 + AnnotationArray* type_annotations() const; 1.82 + 1.83 + // Initial field value 1.84 + bool has_initial_value() const { return field()->initval_index() != 0; } 1.85 + int initial_value_index() const { return field()->initval_index(); } 1.86 + constantTag initial_value_tag() const; // The tag will return true on one of is_int(), is_long(), is_single(), is_double() 1.87 + jint int_initial_value() const; 1.88 + jlong long_initial_value() const; 1.89 + jfloat float_initial_value() const; 1.90 + jdouble double_initial_value() const; 1.91 + oop string_initial_value(TRAPS) const; 1.92 + 1.93 + // Field signature type 1.94 + BasicType field_type() const { return FieldType::basic_type(signature()); } 1.95 + 1.96 + // Access flags 1.97 + bool is_public() const { return access_flags().is_public(); } 1.98 + bool is_private() const { return access_flags().is_private(); } 1.99 + bool is_protected() const { return access_flags().is_protected(); } 1.100 + bool is_package_private() const { return !is_public() && !is_private() && !is_protected(); } 1.101 + 1.102 + bool is_static() const { return access_flags().is_static(); } 1.103 + bool is_final() const { return access_flags().is_final(); } 1.104 + bool is_volatile() const { return access_flags().is_volatile(); } 1.105 + bool is_transient() const { return access_flags().is_transient(); } 1.106 + 1.107 + bool is_synthetic() const { return access_flags().is_synthetic(); } 1.108 + 1.109 + bool is_field_access_watched() const { return access_flags().is_field_access_watched(); } 1.110 + bool is_field_modification_watched() const 1.111 + { return access_flags().is_field_modification_watched(); } 1.112 + bool has_generic_signature() const { return access_flags().field_has_generic_signature(); } 1.113 + 1.114 + void set_is_field_access_watched(const bool value) { 1.115 + _access_flags.set_is_field_access_watched(value); 1.116 + update_klass_field_access_flag(); 1.117 + } 1.118 + 1.119 + void set_is_field_modification_watched(const bool value) { 1.120 + _access_flags.set_is_field_modification_watched(value); 1.121 + update_klass_field_access_flag(); 1.122 + } 1.123 + 1.124 + // Initialization 1.125 + void reinitialize(InstanceKlass* ik, int index); 1.126 + 1.127 + // Print 1.128 + void print() { print_on(tty); } 1.129 + void print_on(outputStream* st) const PRODUCT_RETURN; 1.130 + void print_on_for(outputStream* st, oop obj) PRODUCT_RETURN; 1.131 + void verify() const PRODUCT_RETURN; 1.132 +}; 1.133 + 1.134 +#endif // SHARE_VM_RUNTIME_FIELDDESCRIPTOR_HPP