hotspot/src/share/vm/ci/ciField.hpp
author never
Wed, 04 Apr 2012 20:44:38 -0700
changeset 12982 7d7a3e02610e
parent 10516 2797e487c09f
child 19770 7cb9f982ea81
permissions -rw-r--r--
7152811: Issues in client compiler Reviewed-by: kvn, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12982
7d7a3e02610e 7152811: Issues in client compiler
never
parents: 10516
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_CI_CIFIELD_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_CI_CIFIELD_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "ci/ciClassList.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "ci/ciConstant.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "ci/ciFlags.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "ci/ciInstance.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// ciField
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// This class represents the result of a field lookup in the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// The lookup may not succeed, in which case the information in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// the ciField will be incomplete.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
class ciField : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  CI_PACKAGE_ACCESS
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  friend class ciEnv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  friend class ciInstanceKlass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  friend class NonStaticFieldFiller;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  ciFlags          _flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  ciInstanceKlass* _holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  ciSymbol*        _name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  ciSymbol*        _signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  ciType*          _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  int              _offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  bool             _is_constant;
12982
7d7a3e02610e 7152811: Issues in client compiler
never
parents: 10516
diff changeset
    52
  ciInstanceKlass* _known_to_link_with_put;
7d7a3e02610e 7152811: Issues in client compiler
never
parents: 10516
diff changeset
    53
  ciInstanceKlass* _known_to_link_with_get;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  ciConstant       _constant_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // Used for will_link
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  int              _cp_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  ciType* compute_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  ciType* compute_type_impl();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ciField(ciInstanceKlass* klass, int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  ciField(fieldDescriptor* fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // shared constructor code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  void initialize_from(fieldDescriptor* fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  ciFlags flags() { return _flags; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Of which klass is this field a member?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Usage note: the declared holder of a field is the class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // referenced by name in the bytecodes.  The canonical holder
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // is the most general class which holds the field.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // method returns the canonical holder.  The declared holder
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // can be accessed via a method in ciBytecodeStream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Ex.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  //     class A {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  //       public int f = 7;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  //     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  //     class B extends A {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  //       public void test() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  //         System.out.println(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  //       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  //     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  //   A java compiler is permitted to compile the access to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  //   field f as:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  //     getfield B.f
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  //   In that case the declared holder of f would be B and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  //   the canonical holder of f would be A.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  ciInstanceKlass* holder() { return _holder; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Name of this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  ciSymbol* name() { return _name; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // Signature of this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  ciSymbol* signature() { return _signature; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Of what type is this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  ciType* type() { return (_type == NULL) ? compute_type() : _type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // How is this field actually stored in memory?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  BasicType layout_type() { return type2field[(_type == NULL) ? T_OBJECT : _type->basic_type()]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // How big is this field in memory?
202
dc13bf0e5d5d 6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents: 1
diff changeset
   111
  int size_in_bytes() { return type2aelembytes(layout_type()); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // What is the offset of this field?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  int offset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    assert(_offset >= 1, "illegal call to offset()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    return _offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Same question, explicit units.  (Fields are aligned to the byte level.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  int offset_in_bytes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return offset();
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 shared?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  bool is_shared() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    // non-static fields of shared holders are cached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    return _holder->is_shared() && !is_static();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Is this field a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // Clarification: A field is considered constant if:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  //   1. The field is both static and final
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  //   2. The canonical holder of the field has undergone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  //      static initialization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  //   3. If the field is an object or array, then the oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  //      in question is allocated in perm space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  //   4. The field is not one of the special static/final
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  //      non-constant fields.  These are java.lang.System.in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  //      and java.lang.System.out.  Abomination.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // Note: the check for case 4 is not yet implemented.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  bool is_constant() { return _is_constant; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Get the constant value of this field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  ciConstant constant_value() {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   147
    assert(is_static() && is_constant(), "illegal call to constant_value()");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    return _constant_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   151
  // Get the constant value of non-static final field in the given
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   152
  // object.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   153
  ciConstant constant_value_of(ciObject* object) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   154
    assert(!is_static() && is_constant(), "only if field is non-static constant");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   155
    assert(object->is_instance(), "must be instance");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   156
    return object->as_instance()->field_value(this);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   157
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 670
diff changeset
   158
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Check for link time errors.  Accessing a field from a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // certain class via a certain bytecode may or may not be legal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // This call checks to see if an exception may be raised by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // an access of this field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // Usage note: if the same field is accessed multiple times
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // in the same compilation, will_link will need to be checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // at each point of access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  bool will_link(ciInstanceKlass* accessing_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                 Bytecodes::Code bc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // Java access flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  bool is_public      () { return flags().is_public(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  bool is_private     () { return flags().is_private(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  bool is_protected   () { return flags().is_protected(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  bool is_static      () { return flags().is_static(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  bool is_final       () { return flags().is_final(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  bool is_volatile    () { return flags().is_volatile(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  bool is_transient   () { return flags().is_transient(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
10510
ab626d1bdf53 7085404: JSR 292: VolatileCallSites should have push notification too
twisti
parents: 10508
diff changeset
   179
  bool is_call_site_target() {
10516
2797e487c09f 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 10510
diff changeset
   180
    ciInstanceKlass* callsite_klass = CURRENT_ENV->CallSite_klass();
2797e487c09f 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 10510
diff changeset
   181
    if (callsite_klass == NULL)
2797e487c09f 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 10510
diff changeset
   182
      return false;
2797e487c09f 7086560: 7085404 changes broke VM with -XX:-EnableInvokeDynamic
kvn
parents: 10510
diff changeset
   183
    return (holder()->is_subclass_of(callsite_klass) && (name() == ciSymbol::target_name()));
10510
ab626d1bdf53 7085404: JSR 292: VolatileCallSites should have push notification too
twisti
parents: 10508
diff changeset
   184
  }
10265
4c869854aebd 7071653: JSR 292: call site change notification should be pushed not pulled
twisti
parents: 7397
diff changeset
   185
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // Debugging output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  void print_name_on(outputStream* st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   190
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   191
#endif // SHARE_VM_CI_CIFIELD_HPP