hotspot/src/share/vm/ci/ciField.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 202 dc13bf0e5d5d
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// ciField
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// This class represents the result of a field lookup in the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// The lookup may not succeed, in which case the information in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// the ciField will be incomplete.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
class ciField : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  CI_PACKAGE_ACCESS
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  friend class ciEnv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  friend class ciInstanceKlass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  friend class NonStaticFieldFiller;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  ciFlags          _flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  ciInstanceKlass* _holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  ciSymbol*        _name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  ciSymbol*        _signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  ciType*          _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  int              _offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  bool             _is_constant;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  ciInstanceKlass* _known_to_link_with;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  ciConstant       _constant_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // Used for will_link
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  int              _cp_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  ciType* compute_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  ciType* compute_type_impl();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  ciField(ciInstanceKlass* klass, int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  ciField(fieldDescriptor* fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // shared constructor code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  void initialize_from(fieldDescriptor* fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // The implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  void print_impl(outputStream* st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  ciFlags flags() { return _flags; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Of which klass is this field a member?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // Usage note: the declared holder of a field is the class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // referenced by name in the bytecodes.  The canonical holder
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // is the most general class which holds the field.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // method returns the canonical holder.  The declared holder
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // can be accessed via a method in ciBytecodeStream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Ex.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  //     class A {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  //       public int f = 7;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  //     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  //     class B extends A {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  //       public void test() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  //         System.out.println(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  //       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  //     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  //   A java compiler is permitted to compile the access to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  //   field f as:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  //     getfield B.f
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  //   In that case the declared holder of f would be B and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  //   the canonical holder of f would be A.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  ciInstanceKlass* holder() { return _holder; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Name of this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  ciSymbol* name() { return _name; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Signature of this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  ciSymbol* signature() { return _signature; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Of what type is this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  ciType* type() { return (_type == NULL) ? compute_type() : _type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // How is this field actually stored in memory?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // How big is this field in memory?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  int size_in_bytes() { return type2aelembytes[layout_type()]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // What is the offset of this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  int offset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    assert(_offset >= 1, "illegal call to offset()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return _offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // Same question, explicit units.  (Fields are aligned to the byte level.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  int offset_in_bytes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    return offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Is this field shared?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  bool is_shared() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // non-static fields of shared holders are cached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return _holder->is_shared() && !is_static();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // Is this field a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Clarification: A field is considered constant if:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  //   1. The field is both static and final
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  //   2. The canonical holder of the field has undergone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  //      static initialization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  //   3. If the field is an object or array, then the oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  //      in question is allocated in perm space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  //   4. The field is not one of the special static/final
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  //      non-constant fields.  These are java.lang.System.in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  //      and java.lang.System.out.  Abomination.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Note: the check for case 4 is not yet implemented.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  bool is_constant() { return _is_constant; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Get the constant value of this field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  ciConstant constant_value() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    assert(is_constant(), "illegal call to constant_value()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    return _constant_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Check for link time errors.  Accessing a field from a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // certain class via a certain bytecode may or may not be legal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // This call checks to see if an exception may be raised by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // an access of this field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Usage note: if the same field is accessed multiple times
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // in the same compilation, will_link will need to be checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // at each point of access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  bool will_link(ciInstanceKlass* accessing_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                 Bytecodes::Code bc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // Java access flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  bool is_public      () { return flags().is_public(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  bool is_private     () { return flags().is_private(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  bool is_protected   () { return flags().is_protected(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  bool is_static      () { return flags().is_static(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  bool is_final       () { return flags().is_final(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  bool is_volatile    () { return flags().is_volatile(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  bool is_transient   () { return flags().is_transient(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Debugging output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  void print_name_on(outputStream* st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
};