src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Field.java
author shade
Tue, 12 Jun 2018 15:03:00 +0200
changeset 50523 7b7c75d87f9b
parent 47216 71c04702a3d5
child 50929 ef57cfcd22ff
permissions -rw-r--r--
8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector Summary: Introduce Epsilon GC Reviewed-by: rkennke, ihse, pliden, eosterlund, lmesnik, jgeorge, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
     2
 * Copyright (c) 2000, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.runtime.*;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
    30
import sun.jvm.hotspot.utilities.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Super class for all fields in an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
public class Field {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  Field(FieldIdentifier id, long offset, boolean isVMField) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    this.offset    = offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    this.id        = id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    this.isVMField = isVMField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  /** Constructor for fields that are named in an InstanceKlass's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
      fields array (i.e., named, non-VM fields) */
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    43
  Field(InstanceKlass holder, int fieldIndex) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    this.holder = holder;
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    45
    this.fieldIndex = fieldIndex;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    46
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    47
    offset               = holder.getFieldOffset(fieldIndex);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    48
    genericSignature     = holder.getFieldGenericSignature(fieldIndex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    50
    Symbol name          = holder.getFieldName(fieldIndex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    id          = new NamedFieldIdentifier(name.asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    53
    signature            = holder.getFieldSignature(fieldIndex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    fieldType   = new FieldType(signature);
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    55
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    56
    short access         = holder.getFieldAccessFlags(fieldIndex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    accessFlags = new AccessFlags(access);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  private long            offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  private FieldIdentifier id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private boolean         isVMField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Java fields only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  private InstanceKlass   holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private FieldType       fieldType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  private Symbol          signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  private Symbol          genericSignature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  private AccessFlags     accessFlags;
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    69
  private int             fieldIndex;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  /** Returns the byte offset of the field within the object or klass */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  public long getOffset() { return offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  /** Returns the identifier of the field */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  public FieldIdentifier getID() { return id; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  /** Indicates whether this is a VM field */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  public boolean isVMField() { return isVMField; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  /** Indicates whether this is a named field */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    getID().printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    tty.print(" {" + getOffset() + "} :");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  /** (Named, non-VM fields only) Returns the InstanceKlass containing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      this (static or non-static) field. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public InstanceKlass getFieldHolder() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  /** (Named, non-VM fields only) Returns the index in the fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      TypeArray for this field. Equivalent to the "index" in the VM's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      fieldDescriptors. */
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    97
  public int getFieldIndex() {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 5547
diff changeset
    98
    return fieldIndex;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  /** (Named, non-VM fields only) Retrieves the access flags. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  public long getAccessFlags() { return accessFlags.getValue(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  public AccessFlags getAccessFlagsObj() { return accessFlags; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  /** (Named, non-VM fields only) Returns the type of this field. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public FieldType getFieldType() { return fieldType; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  /** (Named, non-VM fields only) Returns the signature of this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      field. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  public Symbol getSignature() { return signature; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  public Symbol getGenericSignature() { return genericSignature; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   113
  public boolean hasInitialValue()           { return holder.getFieldInitialValueIndex(fieldIndex) != 0;    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   114
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Following acccessors are for named, non-VM fields only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  public boolean isPublic()                  { return accessFlags.isPublic(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  public boolean isPrivate()                 { return accessFlags.isPrivate(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  public boolean isProtected()               { return accessFlags.isProtected(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  public boolean isPackagePrivate()          { return !isPublic() && !isPrivate() && !isProtected(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  public boolean isStatic()                  { return accessFlags.isStatic(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  public boolean isFinal()                   { return accessFlags.isFinal(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  public boolean isVolatile()                { return accessFlags.isVolatile(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  public boolean isTransient()               { return accessFlags.isTransient(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  public boolean isSynthetic()               { return accessFlags.isSynthetic(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  public boolean isEnumConstant()            { return accessFlags.isEnum();      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  public boolean equals(Object obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
     if (obj == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
     if (! (obj instanceof Field)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
     Field other = (Field) obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
     return this.getFieldHolder().equals(other.getFieldHolder()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
            this.getID().equals(other.getID());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  public int hashCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
     return getFieldHolder().hashCode() ^ getID().hashCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}