hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/jdi/FieldImpl.java
changeset 40100 a9b665f0879f
parent 40099 24807846ffe1
child 40101 3b8101f0fd65
equal deleted inserted replaced
40099:24807846ffe1 40100:a9b665f0879f
     1 /*
       
     2  * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 package sun.jvm.hotspot.jdi;
       
    26 
       
    27 import com.sun.jdi.*;
       
    28 import sun.jvm.hotspot.oops.Oop;
       
    29 import sun.jvm.hotspot.oops.Instance;
       
    30 import sun.jvm.hotspot.oops.Array;
       
    31 import sun.jvm.hotspot.oops.InstanceKlass;
       
    32 import sun.jvm.hotspot.oops.Symbol;
       
    33 import sun.jvm.hotspot.oops.FieldIdentifier;
       
    34 
       
    35 import java.util.List;
       
    36 import java.util.Iterator;
       
    37 import java.util.ArrayList;
       
    38 import java.util.Comparator;
       
    39 
       
    40 public class FieldImpl extends TypeComponentImpl implements Field {
       
    41     private JNITypeParser signatureParser;
       
    42     private sun.jvm.hotspot.oops.Field saField;
       
    43 
       
    44     FieldImpl( VirtualMachine vm, ReferenceTypeImpl declaringType,
       
    45                sun.jvm.hotspot.oops.Field saField) {
       
    46         super(vm, declaringType);
       
    47         this.saField = saField;
       
    48         getParser();
       
    49     }
       
    50 
       
    51     private void getParser() {
       
    52         if (signatureParser == null) {
       
    53             Symbol sig1 = saField.getSignature();
       
    54             signature = sig1.asString();
       
    55             signatureParser = new JNITypeParser(signature);
       
    56         }
       
    57     }
       
    58 
       
    59     sun.jvm.hotspot.oops.Field ref() {
       
    60         return saField;
       
    61     }
       
    62 
       
    63     // get the value of static field
       
    64     ValueImpl getValue() {
       
    65         return getValue(saField.getFieldHolder().getJavaMirror());
       
    66     }
       
    67 
       
    68     // get the value of this Field from a specific Oop
       
    69     ValueImpl getValue(Oop target) {
       
    70         ValueImpl valueImpl;
       
    71         sun.jvm.hotspot.oops.Field saField = (sun.jvm.hotspot.oops.Field) ref();
       
    72         sun.jvm.hotspot.oops.FieldType ft = saField.getFieldType();
       
    73         if (ft.isArray()) {
       
    74             sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
       
    75             valueImpl = (ArrayReferenceImpl) vm.arrayMirror((Array)of.getValue(target));
       
    76         } else if (ft.isObject()) {
       
    77             sun.jvm.hotspot.oops.OopField of = (sun.jvm.hotspot.oops.OopField)saField;
       
    78             valueImpl = (ObjectReferenceImpl) vm.objectMirror(of.getValue(target));
       
    79         } else if (ft.isByte()) {
       
    80             sun.jvm.hotspot.oops.ByteField bf = (sun.jvm.hotspot.oops.ByteField)saField;
       
    81             valueImpl = (ByteValueImpl) vm.mirrorOf(bf.getValue(target));
       
    82         } else if (ft.isChar()) {
       
    83             sun.jvm.hotspot.oops.CharField cf = (sun.jvm.hotspot.oops.CharField)saField;
       
    84             valueImpl = (CharValueImpl) vm.mirrorOf(cf.getValue(target));
       
    85         } else if (ft.isDouble()) {
       
    86             sun.jvm.hotspot.oops.DoubleField df = (sun.jvm.hotspot.oops.DoubleField)saField;
       
    87             valueImpl = (DoubleValueImpl) vm.mirrorOf(df.getValue(target));
       
    88         } else if (ft.isFloat()) {
       
    89             sun.jvm.hotspot.oops.FloatField ff = (sun.jvm.hotspot.oops.FloatField)saField;
       
    90             valueImpl = (FloatValueImpl) vm.mirrorOf(ff.getValue(target));
       
    91         } else if (ft.isInt()) {
       
    92             sun.jvm.hotspot.oops.IntField iif = (sun.jvm.hotspot.oops.IntField)saField;
       
    93             valueImpl = (IntegerValueImpl) vm.mirrorOf(iif.getValue(target));
       
    94         } else if (ft.isLong()) {
       
    95             sun.jvm.hotspot.oops.LongField lf = (sun.jvm.hotspot.oops.LongField)saField;
       
    96             valueImpl = (LongValueImpl) vm.mirrorOf(lf.getValue(target));
       
    97         } else if (ft.isShort()) {
       
    98             sun.jvm.hotspot.oops.ShortField sf = (sun.jvm.hotspot.oops.ShortField)saField;
       
    99             valueImpl = (ShortValueImpl) vm.mirrorOf(sf.getValue(target));
       
   100         } else if (ft.isBoolean()) {
       
   101             sun.jvm.hotspot.oops.BooleanField bf = (sun.jvm.hotspot.oops.BooleanField)saField;
       
   102             valueImpl = (BooleanValueImpl) vm.mirrorOf(bf.getValue(target));
       
   103         } else {
       
   104             throw new RuntimeException("Should not reach here");
       
   105         }
       
   106         return valueImpl;
       
   107     }
       
   108 
       
   109     public boolean equals(Object obj) {
       
   110         if ((obj != null) && (obj instanceof FieldImpl)) {
       
   111             FieldImpl other = (FieldImpl)obj;
       
   112             return (declaringType().equals(other.declaringType())) &&
       
   113                 (ref().equals(other.ref())) &&
       
   114                 super.equals(obj);
       
   115         } else {
       
   116             return false;
       
   117         }
       
   118     }
       
   119 
       
   120     public boolean isTransient() {
       
   121         return saField.isTransient();
       
   122     }
       
   123 
       
   124     public boolean isVolatile() {
       
   125         return saField.isVolatile();
       
   126     }
       
   127 
       
   128     public boolean isEnumConstant() {
       
   129         return saField.isEnumConstant();
       
   130     }
       
   131 
       
   132     public Type type() throws ClassNotLoadedException {
       
   133         // So, we do it just like JDI does by searching the enclosing type.
       
   134         return findType(signature());
       
   135     }
       
   136 
       
   137     public String typeName() { //fixme jjh: jpda version creates redundant JNITypeParsers
       
   138         getParser();
       
   139         return signatureParser.typeName();
       
   140     }
       
   141 
       
   142     public String genericSignature() {
       
   143         Symbol genSig = saField.getGenericSignature();
       
   144         return (genSig != null)? genSig.asString() : null;
       
   145     }
       
   146 
       
   147     // From interface Comparable
       
   148     public int compareTo(Field field) {
       
   149         ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
       
   150         int rc = declaringType.compareTo(field.declaringType());
       
   151         if (rc == 0) {
       
   152             rc = declaringType.indexOf(this) -
       
   153                 declaringType.indexOf(field);
       
   154         }
       
   155         return rc;
       
   156     }
       
   157 
       
   158     // from interface Mirror
       
   159     public String toString() {
       
   160         StringBuffer buf = new StringBuffer();
       
   161 
       
   162         buf.append(declaringType().name());
       
   163         buf.append('.');
       
   164         buf.append(name());
       
   165         return buf.toString();
       
   166     }
       
   167 
       
   168     public String name() {
       
   169         FieldIdentifier myName =  saField.getID();
       
   170         return myName.getName();
       
   171     }
       
   172 
       
   173     // From interface Accessible
       
   174     public int modifiers() {
       
   175         return saField.getAccessFlagsObj().getStandardFlags();
       
   176     }
       
   177 
       
   178     public boolean isPackagePrivate() {
       
   179         return saField.isPackagePrivate();
       
   180     }
       
   181 
       
   182     public boolean isPrivate() {
       
   183         return saField.isPrivate();
       
   184     }
       
   185 
       
   186     public boolean isProtected() {
       
   187         return saField.isProtected();
       
   188     }
       
   189 
       
   190     public boolean isPublic() {
       
   191         return saField.isPublic();
       
   192     }
       
   193 
       
   194     public boolean isStatic() {
       
   195         return saField.isStatic();
       
   196     }
       
   197 
       
   198     public boolean isFinal() {
       
   199         return saField.isFinal();
       
   200     }
       
   201 
       
   202     public boolean isSynthetic() {
       
   203         return saField.isSynthetic();
       
   204     }
       
   205 
       
   206     public int hashCode() {
       
   207         return saField.hashCode();
       
   208     }
       
   209 
       
   210 
       
   211     private Type findType(String signature) throws ClassNotLoadedException {
       
   212         ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
       
   213         return enclosing.findType(signature);
       
   214     }
       
   215 
       
   216 }