src/share/vm/ci/ciField.hpp

Tue, 10 Sep 2013 14:51:48 -0700

author
vlivanov
date
Tue, 10 Sep 2013 14:51:48 -0700
changeset 5658
edb5ab0f3fe5
parent 3854
e778c29768e6
child 5732
b2e698d2276c
permissions
-rw-r--r--

8001107: @Stable annotation for constant folding of lazily evaluated variables
Reviewed-by: rbackman, twisti, kvn
Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com

     1 /*
     2  * Copyright (c) 1999, 2012, 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  */
    25 #ifndef SHARE_VM_CI_CIFIELD_HPP
    26 #define SHARE_VM_CI_CIFIELD_HPP
    28 #include "ci/ciClassList.hpp"
    29 #include "ci/ciConstant.hpp"
    30 #include "ci/ciFlags.hpp"
    31 #include "ci/ciInstance.hpp"
    33 // ciField
    34 //
    35 // This class represents the result of a field lookup in the VM.
    36 // The lookup may not succeed, in which case the information in
    37 // the ciField will be incomplete.
    38 class ciField : public ResourceObj {
    39   CI_PACKAGE_ACCESS
    40   friend class ciEnv;
    41   friend class ciInstanceKlass;
    42   friend class NonStaticFieldFiller;
    44 private:
    45   ciFlags          _flags;
    46   ciInstanceKlass* _holder;
    47   ciSymbol*        _name;
    48   ciSymbol*        _signature;
    49   ciType*          _type;
    50   int              _offset;
    51   bool             _is_constant;
    52   ciInstanceKlass* _known_to_link_with_put;
    53   ciInstanceKlass* _known_to_link_with_get;
    54   ciConstant       _constant_value;
    56   // Used for will_link
    57   int              _cp_index;
    59   ciType* compute_type();
    60   ciType* compute_type_impl();
    62   ciField(ciInstanceKlass* klass, int index);
    63   ciField(fieldDescriptor* fd);
    65   // shared constructor code
    66   void initialize_from(fieldDescriptor* fd);
    68 public:
    69   ciFlags flags() { return _flags; }
    71   // Of which klass is this field a member?
    72   //
    73   // Usage note: the declared holder of a field is the class
    74   // referenced by name in the bytecodes.  The canonical holder
    75   // is the most general class which holds the field.  This
    76   // method returns the canonical holder.  The declared holder
    77   // can be accessed via a method in ciBytecodeStream.
    78   //
    79   // Ex.
    80   //     class A {
    81   //       public int f = 7;
    82   //     }
    83   //     class B extends A {
    84   //       public void test() {
    85   //         System.out.println(f);
    86   //       }
    87   //     }
    88   //
    89   //   A java compiler is permitted to compile the access to
    90   //   field f as:
    91   //
    92   //     getfield B.f
    93   //
    94   //   In that case the declared holder of f would be B and
    95   //   the canonical holder of f would be A.
    96   ciInstanceKlass* holder() { return _holder; }
    98   // Name of this field?
    99   ciSymbol* name() { return _name; }
   101   // Signature of this field?
   102   ciSymbol* signature() { return _signature; }
   104   // Of what type is this field?
   105   ciType* type() { return (_type == NULL) ? compute_type() : _type; }
   107   // How is this field actually stored in memory?
   108   BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; }
   110   // How big is this field in memory?
   111   int size_in_bytes() { return type2aelembytes(layout_type()); }
   113   // What is the offset of this field?
   114   int offset() {
   115     assert(_offset >= 1, "illegal call to offset()");
   116     return _offset;
   117   }
   119   // Same question, explicit units.  (Fields are aligned to the byte level.)
   120   int offset_in_bytes() {
   121     return offset();
   122   }
   124   // Is this field shared?
   125   bool is_shared() {
   126     // non-static fields of shared holders are cached
   127     return _holder->is_shared() && !is_static();
   128   }
   130   // Is this field a constant?
   131   //
   132   // Clarification: A field is considered constant if:
   133   //   1. The field is both static and final
   134   //   2. The canonical holder of the field has undergone
   135   //      static initialization.
   136   //   3. If the field is an object or array, then the oop
   137   //      in question is allocated in perm space.
   138   //   4. The field is not one of the special static/final
   139   //      non-constant fields.  These are java.lang.System.in
   140   //      and java.lang.System.out.  Abomination.
   141   //
   142   // A field is also considered constant if it is marked @Stable
   143   // and is non-null (or non-zero, if a primitive).
   144   // For non-static fields, the null/zero check must be
   145   // arranged by the user, as constant_value().is_null_or_zero().
   146   bool is_constant() { return _is_constant; }
   148   // Get the constant value of this field.
   149   ciConstant constant_value() {
   150     assert(is_static() && is_constant(), "illegal call to constant_value()");
   151     return _constant_value;
   152   }
   154   // Get the constant value of non-static final field in the given
   155   // object.
   156   ciConstant constant_value_of(ciObject* object) {
   157     assert(!is_static() && is_constant(), "only if field is non-static constant");
   158     assert(object->is_instance(), "must be instance");
   159     return object->as_instance()->field_value(this);
   160   }
   162   // Check for link time errors.  Accessing a field from a
   163   // certain class via a certain bytecode may or may not be legal.
   164   // This call checks to see if an exception may be raised by
   165   // an access of this field.
   166   //
   167   // Usage note: if the same field is accessed multiple times
   168   // in the same compilation, will_link will need to be checked
   169   // at each point of access.
   170   bool will_link(ciInstanceKlass* accessing_klass,
   171                  Bytecodes::Code bc);
   173   // Java access flags
   174   bool is_public      () { return flags().is_public(); }
   175   bool is_private     () { return flags().is_private(); }
   176   bool is_protected   () { return flags().is_protected(); }
   177   bool is_static      () { return flags().is_static(); }
   178   bool is_final       () { return flags().is_final(); }
   179   bool is_stable      () { return flags().is_stable(); }
   180   bool is_volatile    () { return flags().is_volatile(); }
   181   bool is_transient   () { return flags().is_transient(); }
   183   bool is_call_site_target() {
   184     ciInstanceKlass* callsite_klass = CURRENT_ENV->CallSite_klass();
   185     if (callsite_klass == NULL)
   186       return false;
   187     return (holder()->is_subclass_of(callsite_klass) && (name() == ciSymbol::target_name()));
   188   }
   190   // Debugging output
   191   void print();
   192   void print_name_on(outputStream* st);
   193 };
   195 #endif // SHARE_VM_CI_CIFIELD_HPP

mercurial