1 /*
  2  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_RUNTIME_FIELDDESCRIPTOR_HPP
 26 #define SHARE_RUNTIME_FIELDDESCRIPTOR_HPP
 27 
 28 #include "oops/constantPool.hpp"
 29 #include "oops/fieldInfo.hpp"
 30 #include "oops/instanceKlass.hpp"
 31 #include "oops/symbol.hpp"
 32 #include "utilities/accessFlags.hpp"
 33 #include "utilities/constantTag.hpp"
 34 
 35 // A fieldDescriptor describes the attributes of a single field (instance or class variable).
 36 // It needs the class constant pool to work (because it only holds indices into the pool
 37 // rather than the actual info).
 38 
 39 class fieldDescriptor {
 40  private:
 41   FieldInfo           _fieldinfo;
 42   constantPoolHandle  _cp;
 43 
 44   inline FieldInfo field() const { return _fieldinfo; };
 45 
 46  public:
 47   fieldDescriptor() {}
 48   fieldDescriptor(InstanceKlass* ik, int index) {
 49     reinitialize(ik, index);
 50   }
 51   inline Symbol* name() const;
 52   inline Symbol* signature() const;
 53   inline InstanceKlass* field_holder() const {return _cp->pool_holder(); };
 54   inline ConstantPool* constants() const;
 55 
 56   AccessFlags access_flags()      const    { return _fieldinfo.access_flags(); }
 57   FieldInfo::FieldFlags field_flags() const { return _fieldinfo.field_flags(); }
 58   FieldStatus field_status()      const    { return field_holder()->fields_status()->at(_fieldinfo.index()); }
 59   oop loader()                    const;
 60   // Offset (in bytes) of field from start of instanceOop / Klass*
 61   inline int offset()             const;
 62   Symbol* generic_signature()     const;
 63   int index()                     const    { return _fieldinfo.index(); }
 64   AnnotationArray* annotations()  const;
 65   AnnotationArray* type_annotations()  const;
 66 
 67   // Initial field value
 68   inline bool has_initial_value()        const;
 69   inline int initial_value_index()       const;
 70   constantTag initial_value_tag() const;  // The tag will return true on one of is_int(), is_long(), is_single(), is_double()
 71   jint int_initial_value()        const;
 72   jlong long_initial_value()      const;
 73   jfloat float_initial_value()    const;
 74   jdouble double_initial_value()  const;
 75   oop string_initial_value(TRAPS) const;
 76 
 77   // Field signature type
 78   inline BasicType field_type() const;
 79 
 80   // Access flags
 81   bool is_private()               const    { return access_flags().is_private(); }
 82   bool is_protected()             const    { return access_flags().is_protected(); }
 83 
 84   bool is_static()                const    { return access_flags().is_static(); }
 85   bool is_final()                 const    { return access_flags().is_final(); }
 86   bool is_stable()                const    { return field_flags().is_stable(); }
 87   bool is_volatile()              const    { return access_flags().is_volatile(); }
 88   bool is_transient()             const    { return access_flags().is_transient(); }
 89   inline bool is_flat()           const;
 90   inline bool is_null_free_inline_type() const;
 91   inline bool has_null_marker()   const;
 92 
 93   bool is_synthetic()             const    { return access_flags().is_synthetic(); }
 94 
 95   bool is_field_access_watched()  const    { return field_status().is_access_watched(); }
 96   bool is_field_modification_watched() const
 97                                            { return field_status().is_modification_watched(); }
 98   bool has_initialized_final_update() const { return field_status().is_initialized_final_update(); }
 99   bool has_generic_signature()    const    { return field_flags().is_generic(); }
100 
101   bool is_trusted_final()         const;
102 
103   inline void set_is_field_access_watched(const bool value);
104   inline void set_is_field_modification_watched(const bool value);
105   inline void set_has_initialized_final_update(const bool value);
106 
107   // Initialization
108   void reinitialize(InstanceKlass* ik, int index);
109 
110   // Print
111   void print() const;
112   void print_on(outputStream* st) const;
113   void print_on_for(outputStream* st, oop obj);
114 };
115 
116 #endif // SHARE_RUNTIME_FIELDDESCRIPTOR_HPP