hotspot/agent/src/share/classes/sun/jvm/hotspot/jdi/FieldImpl.java
author never
Fri, 18 Mar 2011 16:00:34 -0700
changeset 8725 8c1e3dd5fe1b
parent 5547 f4b087cbb361
child 9127 c3fc6f9ed68d
permissions -rw-r--r--
7017732: move static fields into Class to prepare for perm gen removal Reviewed-by: kvn, coleenp, twisti, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 5547
diff changeset
     2
 * Copyright (c) 2002, 2011, 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.jdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import com.sun.jdi.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.oops.Oop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.oops.Instance;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.oops.Array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.oops.InstanceKlass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.oops.Symbol;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.oops.FieldIdentifier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import java.util.Iterator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import java.util.ArrayList;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
import java.util.Comparator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
public class FieldImpl extends TypeComponentImpl implements Field {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    private JNITypeParser signatureParser;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    private sun.jvm.hotspot.oops.Field saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    FieldImpl( VirtualMachine vm, ReferenceTypeImpl declaringType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
               sun.jvm.hotspot.oops.Field saField) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
        super(vm, declaringType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
        this.saField = saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
        getParser();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    private void getParser() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
        if (signatureParser == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
            Symbol sig1 = saField.getSignature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
            signature = sig1.asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
            signatureParser = new JNITypeParser(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    sun.jvm.hotspot.oops.Field ref() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
        return saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    // get the value of static field
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    ValueImpl getValue() {
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 5547
diff changeset
    65
        return getValue(saField.getFieldHolder().getJavaMirror());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    // get the value of this Field from a specific Oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    ValueImpl getValue(Oop target) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        ValueImpl valueImpl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        sun.jvm.hotspot.oops.Field saField = (sun.jvm.hotspot.oops.Field) ref();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
        sun.jvm.hotspot.oops.FieldType ft = saField.getFieldType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        if (ft.isArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
            sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
            valueImpl = (ArrayReferenceImpl) vm.arrayMirror((Array)of.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        } else if (ft.isObject()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
            sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
            valueImpl = (ObjectReferenceImpl) vm.objectMirror(of.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        } else if (ft.isByte()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
            sun.jvm.hotspot.oops.ByteField bf = (sun.jvm.hotspot.oops.ByteField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
            valueImpl = (ByteValueImpl) vm.mirrorOf(bf.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
        } else if (ft.isChar()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
            sun.jvm.hotspot.oops.CharField cf = (sun.jvm.hotspot.oops.CharField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
            valueImpl = (CharValueImpl) vm.mirrorOf(cf.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        } else if (ft.isDouble()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
            sun.jvm.hotspot.oops.DoubleField df = (sun.jvm.hotspot.oops.DoubleField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
            valueImpl = (DoubleValueImpl) vm.mirrorOf(df.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
        } else if (ft.isFloat()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
            sun.jvm.hotspot.oops.FloatField ff = (sun.jvm.hotspot.oops.FloatField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
            valueImpl = (FloatValueImpl) vm.mirrorOf(ff.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        } else if (ft.isInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
            sun.jvm.hotspot.oops.IntField iif = (sun.jvm.hotspot.oops.IntField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
            valueImpl = (IntegerValueImpl) vm.mirrorOf(iif.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        } else if (ft.isLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
            sun.jvm.hotspot.oops.LongField lf = (sun.jvm.hotspot.oops.LongField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
            valueImpl = (LongValueImpl) vm.mirrorOf(lf.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        } else if (ft.isShort()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
            sun.jvm.hotspot.oops.ShortField sf = (sun.jvm.hotspot.oops.ShortField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
            valueImpl = (ShortValueImpl) vm.mirrorOf(sf.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        } else if (ft.isBoolean()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
            sun.jvm.hotspot.oops.BooleanField bf = (sun.jvm.hotspot.oops.BooleanField)saField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
            valueImpl = (BooleanValueImpl) vm.mirrorOf(bf.getValue(target));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
            throw new RuntimeException("Should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        return valueImpl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    public boolean equals(Object obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        if ((obj != null) && (obj instanceof FieldImpl)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
            FieldImpl other = (FieldImpl)obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
            return (declaringType().equals(other.declaringType())) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
                (ref().equals(other.ref())) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
                super.equals(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
            return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    public boolean isTransient() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        return saField.isTransient();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    public boolean isVolatile() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        return saField.isVolatile();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    public boolean isEnumConstant() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        return saField.isEnumConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    public Type type() throws ClassNotLoadedException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        // So, we do it just like JDI does by searching the enclosing type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
        return findType(signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    public String typeName() { //fixme jjh: jpda version creates redundant JNITypeParsers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        getParser();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        return signatureParser.typeName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    public String genericSignature() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        Symbol genSig = saField.getGenericSignature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        return (genSig != null)? genSig.asString() : null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    // From interface Comparable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    public int compareTo(Object object) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        Field field = (Field)object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        int rc = declaringType.compareTo(field.declaringType());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        if (rc == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
            rc = declaringType.indexOf(this) -
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                declaringType.indexOf(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        return rc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    // from interface Mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    public String toString() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        StringBuffer buf = new StringBuffer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        buf.append(declaringType().name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        buf.append('.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        buf.append(name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        return buf.toString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    public String name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        FieldIdentifier myName =  saField.getID();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        return myName.getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    // From interface Accessible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    public int modifiers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        return saField.getAccessFlagsObj().getStandardFlags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    public boolean isPackagePrivate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        return saField.isPackagePrivate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    public boolean isPrivate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        return saField.isPrivate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    public boolean isProtected() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        return saField.isProtected();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    public boolean isPublic() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        return saField.isPublic();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    public boolean isStatic() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        return saField.isStatic();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    public boolean isFinal() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
        return saField.isFinal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    public boolean isSynthetic() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        return saField.isSynthetic();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    public int hashCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        return saField.hashCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    private Type findType(String signature) throws ClassNotLoadedException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        return enclosing.findType(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}