Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Field.java
41161 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.oops;2526import java.io.*;2728import sun.jvm.hotspot.runtime.*;29import sun.jvm.hotspot.utilities.*;3031// Super class for all fields in an object32public class Field {3334Field(FieldIdentifier id, long offset, boolean isVMField) {35this.offset = offset;36this.id = id;37this.isVMField = isVMField;38}3940/** Constructor for fields that are named in an InstanceKlass's41fields array (i.e., named, non-VM fields) */42Field(InstanceKlass holder, int fieldIndex) {43this.holder = holder;44this.fieldIndex = fieldIndex;4546offset = holder.getFieldOffset(fieldIndex);47genericSignature = holder.getFieldGenericSignature(fieldIndex);4849name = holder.getFieldName(fieldIndex);50id = new NamedFieldIdentifier(name.asString());5152signature = holder.getFieldSignature(fieldIndex);53fieldType = new FieldType(signature);5455short access = holder.getFieldAccessFlags(fieldIndex);56accessFlags = new AccessFlags(access);57}5859private Symbol name;60private long offset;61private FieldIdentifier id;62private boolean isVMField;63// Java fields only64private InstanceKlass holder;65private FieldType fieldType;66private Symbol signature;67private Symbol genericSignature;68private AccessFlags accessFlags;69private int fieldIndex;7071/** Returns the byte offset of the field within the object or klass */72public long getOffset() { return offset; }7374/** Returns the identifier of the field */75public FieldIdentifier getID() { return id; }7677public Symbol getName() { return name; }7879/** Indicates whether this is a VM field */80public boolean isVMField() { return isVMField; }8182/** Indicates whether this is a named field */83public boolean isNamedField() { return (id instanceof NamedFieldIdentifier); }8485public void printOn(PrintStream tty) {86getID().printOn(tty);87tty.print(" {" + getOffset() + "} :");88}8990/** (Named, non-VM fields only) Returns the InstanceKlass containing91this (static or non-static) field. */92public InstanceKlass getFieldHolder() {93return holder;94}9596/** (Named, non-VM fields only) Returns the index in the fields97TypeArray for this field. Equivalent to the "index" in the VM's98fieldDescriptors. */99public int getFieldIndex() {100return fieldIndex;101}102103/** (Named, non-VM fields only) Retrieves the access flags. */104public long getAccessFlags() { return accessFlags.getValue(); }105public AccessFlags getAccessFlagsObj() { return accessFlags; }106107/** (Named, non-VM fields only) Returns the type of this field. */108public FieldType getFieldType() { return fieldType; }109110/** (Named, non-VM fields only) Returns the signature of this111field. */112public Symbol getSignature() { return signature; }113public Symbol getGenericSignature() { return genericSignature; }114115public boolean hasInitialValue() { return holder.getFieldInitialValueIndex(fieldIndex) != 0; }116117//118// Following acccessors are for named, non-VM fields only119//120public boolean isPublic() { return accessFlags.isPublic(); }121public boolean isPrivate() { return accessFlags.isPrivate(); }122public boolean isProtected() { return accessFlags.isProtected(); }123public boolean isPackagePrivate() { return !isPublic() && !isPrivate() && !isProtected(); }124125public boolean isStatic() { return accessFlags.isStatic(); }126public boolean isFinal() { return accessFlags.isFinal(); }127public boolean isVolatile() { return accessFlags.isVolatile(); }128public boolean isTransient() { return accessFlags.isTransient(); }129130public boolean isSynthetic() { return accessFlags.isSynthetic(); }131public boolean isEnumConstant() { return accessFlags.isEnum(); }132133public boolean equals(Object obj) {134if (obj == null) {135return false;136}137138if (! (obj instanceof Field)) {139return false;140}141142Field other = (Field) obj;143return this.getFieldHolder().equals(other.getFieldHolder()) &&144this.getID().equals(other.getID());145}146147public int hashCode() {148return getFieldHolder().hashCode() ^ getID().hashCode();149}150}151152153