jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 25513 jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java@296740f55f9b
child 36511 9d0388c6b336
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 11277
diff changeset
     2
 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public abstract class ReferenceTypeImpl extends TypeImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
implements ReferenceType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    protected long ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private String signature = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private String genericSignature = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private boolean genericSignatureGotten = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private String baseSourceName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private String baseSourceDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private String baseSourcePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    protected int modifiers = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private SoftReference<List<Field>> fieldsRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private SoftReference<List<Method>> methodsRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private SoftReference<SDE> sdeRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private boolean isClassLoaderCached = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private ClassLoaderReference classLoader = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private ClassObjectReference classObject = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private boolean isPrepared = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private boolean versionNumberGotten = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int majorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private int minorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private boolean constantPoolInfoGotten = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private int constanPoolCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private byte[] constantPoolBytes;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    62
    private SoftReference<byte[]> constantPoolBytesRef = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* to mark a SourceFile request that returned a genuine JDWP.Error.ABSENT_INFORMATION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final String ABSENT_BASE_SOURCE_NAME = "**ABSENT_BASE_SOURCE_NAME**";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /* to mark when no info available */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static final SDE NO_SDE_INFO_MARK = new SDE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // bits set when initialization was attempted (succeeded or failed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int INITIALIZED_OR_FAILED =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        JDWP.ClassStatus.INITIALIZED | JDWP.ClassStatus.ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected ReferenceTypeImpl(VirtualMachine aVm, long aRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        super(aVm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        ref = aRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        genericSignatureGotten = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    void noticeRedefineClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        //Invalidate information previously fetched and cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        //These will be refreshed later on demand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        baseSourceName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        baseSourcePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        modifiers = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        fieldsRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        methodsRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        sdeRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        versionNumberGotten = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        constantPoolInfoGotten = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    Method getMethodMirror(long ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (ref == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            // obsolete method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return new ObsoleteMethodImpl(vm, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // Fetch all methods for the class, check performance impact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // Needs no synchronization now, since methods() returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // unmodifiable local data
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   102
        Iterator<Method> it = methods().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            MethodImpl method = (MethodImpl)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (method.ref() == ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        throw new IllegalArgumentException("Invalid method id: " + ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    Field getFieldMirror(long ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // Fetch all fields for the class, check performance impact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // Needs no synchronization now, since fields() returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // unmodifiable local data
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   116
        Iterator<Field>it = fields().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            FieldImpl field = (FieldImpl)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (field.ref() == ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                return field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        throw new IllegalArgumentException("Invalid field id: " + ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if ((obj != null) && (obj instanceof ReferenceTypeImpl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            ReferenceTypeImpl other = (ReferenceTypeImpl)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            return (ref() == other.ref()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                (vm.equals(other.virtualMachine()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return(int)ref();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public int compareTo(ReferenceType object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         * Note that it is critical that compareTo() == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * implies that equals() == true. Otherwise, TreeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * will collapse classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * (Classes of the same name loaded by different class loaders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * or in different VMs must not return 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        ReferenceTypeImpl other = (ReferenceTypeImpl)object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int comp = name().compareTo(other.name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (comp == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            long rf1 = ref();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            long rf2 = other.ref();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // optimize for typical case: refs equal and VMs equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (rf1 == rf2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                // sequenceNumbers are always positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                comp = vm.sequenceNumber -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                 ((VirtualMachineImpl)(other.virtualMachine())).sequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                comp = (rf1 < rf2)? -1 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public String signature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (signature == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            // Does not need synchronization, since worst-case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            // static info is fetched twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (vm.canGet1_5LanguageFeatures()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                 * we might as well get both the signature and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                 * generic signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    signature = JDWP.ReferenceType.Signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        process(vm, this).signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public String genericSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // This gets both the signature and the generic signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (vm.canGet1_5LanguageFeatures() && !genericSignatureGotten) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // Does not need synchronization, since worst-case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            // static info is fetched twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            JDWP.ReferenceType.SignatureWithGeneric result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                result = JDWP.ReferenceType.SignatureWithGeneric.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    process(vm, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            signature = result.signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            setGenericSignature(result.genericSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return genericSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public ClassLoaderReference classLoader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (!isClassLoaderCached) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // Does not need synchronization, since worst-case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // static info is fetched twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                classLoader = (ClassLoaderReference)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    JDWP.ReferenceType.ClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    process(vm, this).classLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                isClassLoaderCached = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return classLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public boolean isPublic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (modifiers == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return((modifiers & VMModifiers.PUBLIC) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public boolean isProtected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (modifiers == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return((modifiers & VMModifiers.PROTECTED) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public boolean isPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (modifiers == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return((modifiers & VMModifiers.PRIVATE) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public boolean isPackagePrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return !isPublic() && !isPrivate() && !isProtected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public boolean isAbstract() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (modifiers == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return((modifiers & VMModifiers.ABSTRACT) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public boolean isFinal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (modifiers == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return((modifiers & VMModifiers.FINAL) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public boolean isStatic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (modifiers == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return((modifiers & VMModifiers.STATIC) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public boolean isPrepared() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // This ref type may have been prepared before we were getting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // events, so get it once.  After that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // this status flag is updated through the ClassPrepareEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // there is no need for the expense of a JDWP query.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (status == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            updateStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return isPrepared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public boolean isVerified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // Once true, it never resets, so we don't need to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if ((status & JDWP.ClassStatus.VERIFIED) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            updateStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return (status & JDWP.ClassStatus.VERIFIED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public boolean isInitialized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // Once initialization succeeds or fails, it never resets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // so we don't need to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if ((status & INITIALIZED_OR_FAILED) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            updateStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return (status & JDWP.ClassStatus.INITIALIZED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public boolean failedToInitialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // Once initialization succeeds or fails, it never resets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // so we don't need to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if ((status & INITIALIZED_OR_FAILED) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            updateStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return (status & JDWP.ClassStatus.ERROR) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public List<Field> fields() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        List<Field> fields = (fieldsRef == null) ? null : fieldsRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (fields == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (vm.canGet1_5LanguageFeatures()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                JDWP.ReferenceType.FieldsWithGeneric.FieldInfo[] jdwpFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    jdwpFields = JDWP.ReferenceType.FieldsWithGeneric.process(vm, this).declared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                fields = new ArrayList<Field>(jdwpFields.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                for (int i=0; i<jdwpFields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    JDWP.ReferenceType.FieldsWithGeneric.FieldInfo fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        = jdwpFields[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    Field field = new FieldImpl(vm, this, fi.fieldID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                                fi.name, fi.signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                                fi.genericSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                                                fi.modBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    fields.add(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                JDWP.ReferenceType.Fields.FieldInfo[] jdwpFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    jdwpFields = JDWP.ReferenceType.Fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        process(vm, this).declared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                fields = new ArrayList<Field>(jdwpFields.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                for (int i=0; i<jdwpFields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    JDWP.ReferenceType.Fields.FieldInfo fi = jdwpFields[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    Field field = new FieldImpl(vm, this, fi.fieldID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                            fi.name, fi.signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                            fi.modBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    fields.add(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            fields = Collections.unmodifiableList(fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            fieldsRef = new SoftReference<List<Field>>(fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return fields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    abstract List<? extends ReferenceType> inheritedTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    void addVisibleFields(List<Field> visibleList, Map<String, Field> visibleTable, List<String> ambiguousNames) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   355
        for (Field field : visibleFields()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            String name = field.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (!ambiguousNames.contains(name)) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   358
                Field duplicate = visibleTable.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                if (duplicate == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    visibleList.add(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    visibleTable.put(name, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                } else if (!field.equals(duplicate)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    ambiguousNames.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    visibleTable.remove(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    visibleList.remove(duplicate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    // identical field from two branches; do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public List<Field> visibleFields() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         * Maintain two different collections of visible fields. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * list maintains a reasonable order for return. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         * hash map provides an efficient way to lookup visible fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         * by name, important for finding hidden or ambiguous fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        List<Field> visibleList = new ArrayList<Field>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Map<String, Field>  visibleTable = new HashMap<String, Field>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        /* Track fields removed from above collection due to ambiguity */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        List<String> ambiguousNames = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        /* Add inherited, visible fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        List<? extends ReferenceType> types = inheritedTypes();
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   388
        Iterator<? extends ReferenceType> iter = types.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
             * TO DO: Be defensive and check for cyclic interface inheritance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            type.addVisibleFields(visibleList, visibleTable, ambiguousNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         * Insert fields from this type, removing any inherited fields they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         * hide.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        List<Field> retList = new ArrayList<Field>(fields());
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   402
        for (Field field : retList) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   403
            Field hidden = visibleTable.get(field.name());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if (hidden != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                visibleList.remove(hidden);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        retList.addAll(visibleList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    void addAllFields(List<Field> fieldList, Set<ReferenceType> typeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        /* Continue the recursion only if this type is new */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (!typeSet.contains(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            typeSet.add((ReferenceType)this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            /* Add local fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            fieldList.addAll(fields());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            /* Add inherited fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            List<? extends ReferenceType> types = inheritedTypes();
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   422
            Iterator<? extends ReferenceType> iter = types.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                type.addAllFields(fieldList, typeSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public List<Field> allFields() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        List<Field> fieldList = new ArrayList<Field>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        Set<ReferenceType> typeSet = new HashSet<ReferenceType>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        addAllFields(fieldList, typeSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return fieldList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public Field fieldByName(String fieldName) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   437
        List<Field> searchList = visibleFields();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        for (int i=0; i<searchList.size(); i++) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   440
            Field f = searchList.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (f.name().equals(fieldName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        //throw new NoSuchFieldException("Field '" + fieldName + "' not found in " + name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public List<Method> methods() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        List<Method> methods = (methodsRef == null) ? null : methodsRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (methods == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if (!vm.canGet1_5LanguageFeatures()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                methods = methods1_4();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                JDWP.ReferenceType.MethodsWithGeneric.MethodInfo[] declared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    declared = JDWP.ReferenceType.MethodsWithGeneric.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                        process(vm, this).declared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                methods = new ArrayList<Method>(declared.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                for (int i=0; i<declared.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    JDWP.ReferenceType.MethodsWithGeneric.MethodInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                        mi = declared[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    Method method = MethodImpl.createMethodImpl(vm, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                                         mi.methodID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                                         mi.name, mi.signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                                         mi.genericSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                                         mi.modBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    methods.add(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            methods = Collections.unmodifiableList(methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            methodsRef = new SoftReference<List<Method>>(methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return methods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    private List<Method> methods1_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        List<Method> methods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        JDWP.ReferenceType.Methods.MethodInfo[] declared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            declared = JDWP.ReferenceType.Methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                process(vm, this).declared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        methods = new ArrayList<Method>(declared.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        for (int i=0; i<declared.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            JDWP.ReferenceType.Methods.MethodInfo mi = declared[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            Method method = MethodImpl.createMethodImpl(vm, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                                        mi.methodID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                                        mi.name, mi.signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                                        null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                                        mi.modBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            methods.add(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return methods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Utility method used by subclasses to build lists of visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    void addToMethodMap(Map<String, Method> methodMap, List<Method> methodList) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   510
        for (Method method : methodList)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            methodMap.put(method.name().concat(method.signature()), method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
22049
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents: 14342
diff changeset
   514
    abstract void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public List<Method> visibleMethods() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         * Build a collection of all visible methods. The hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         * map allows us to do this efficiently by keying on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * concatenation of name and signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        Map<String, Method> map = new HashMap<String, Method>();
22049
15b9d7db4ad7 8028430: JDI: ReferenceType.visibleMethods() return wrong visible methods
sla
parents: 14342
diff changeset
   523
        addVisibleMethods(map, new HashSet<InterfaceType>());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * ... but the hash map destroys order. Methods should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * returned in a sensible order, as they are in allMethods().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * So, start over with allMethods() and use the hash map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         * to filter that ordered collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        List<Method> list = allMethods();
25513
296740f55f9b 8042778: Getting all visible methods in ReferenceTypeImpl is slow
jmanson
parents: 24969
diff changeset
   532
        list.retainAll(new HashSet<Method>(map.values()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    abstract public List<Method> allMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public List<Method> methodsByName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        List<Method> methods = visibleMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        ArrayList<Method> retList = new ArrayList<Method>(methods.size());
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   541
        for (Method candidate : methods) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            if (candidate.name().equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                retList.add(candidate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        retList.trimToSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public List<Method> methodsByName(String name, String signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        List<Method> methods = visibleMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        ArrayList<Method> retList = new ArrayList<Method>(methods.size());
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   553
        for (Method candidate : methods) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            if (candidate.name().equals(name) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                candidate.signature().equals(signature)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                retList.add(candidate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        retList.trimToSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    List<InterfaceType> getInterfaces() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        InterfaceTypeImpl[] intfs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            intfs = JDWP.ReferenceType.Interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                         process(vm, this).interfaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return Arrays.asList((InterfaceType[])intfs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    public List<ReferenceType> nestedTypes() {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   575
        List<ReferenceType> all = vm.allClasses();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        List<ReferenceType> nested = new ArrayList<ReferenceType>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        String outername = name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        int outerlen = outername.length();
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   579
        Iterator<ReferenceType> iter = all.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        while (iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   581
            ReferenceType refType = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            String name = refType.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            int len = name.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            /* The separator is historically '$' but could also be '#' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            if ( len > outerlen && name.startsWith(outername) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                char c = name.charAt(outerlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                if ( c =='$' || c== '#' ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    nested.add(refType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return nested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public Value getValue(Field sig) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        List<Field> list = new ArrayList<Field>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        list.add(sig);
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   598
        Map<Field, Value> map = getValues(list);
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   599
        return map.get(sig);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    void validateFieldAccess(Field field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         * Field must be in this object's class, a superclass, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         * implemented interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        ReferenceTypeImpl declType = (ReferenceTypeImpl)field.declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (!declType.isAssignableFrom(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            throw new IllegalArgumentException("Invalid field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    void validateFieldSet(Field field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        validateFieldAccess(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (field.isFinal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            throw new IllegalArgumentException("Cannot set value of final field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Returns a map of field values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public Map<Field,Value> getValues(List<? extends Field> theFields) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        validateMirrors(theFields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        int size = theFields.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        JDWP.ReferenceType.GetValues.Field[] queryFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                         new JDWP.ReferenceType.GetValues.Field[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        for (int i=0; i<size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            FieldImpl field = (FieldImpl)theFields.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            validateFieldAccess(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            // Do more validation specific to ReferenceType field getting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            if (!field.isStatic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                     "Attempt to use non-static field with ReferenceType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            queryFields[i] = new JDWP.ReferenceType.GetValues.Field(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                         field.ref());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        Map<Field, Value> map = new HashMap<Field, Value>(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        ValueImpl[] values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            values = JDWP.ReferenceType.GetValues.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                                     process(vm, this, queryFields).values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (size != values.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            throw new InternalException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                         "Wrong number of values returned from target VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        for (int i=0; i<size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            FieldImpl field = (FieldImpl)theFields.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            map.put(field, values[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    public ClassObjectReference classObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        if (classObject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            // Are classObjects unique for an Object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            // created each time? Is this spec'ed?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                if (classObject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                        classObject = JDWP.ReferenceType.ClassObject.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                            process(vm, this).classObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                        throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return classObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    SDE.Stratum stratum(String stratumID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        SDE sde = sourceDebugExtensionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (!sde.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            sde = NO_SDE_INFO_MARK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return sde.stratum(stratumID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    public String sourceName() throws AbsentInformationException {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   694
        return sourceNames(vm.getDefaultStratum()).get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public List<String> sourceNames(String stratumID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                                throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        SDE.Stratum stratum = stratum(stratumID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        if (stratum.isJava()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            List<String> result = new ArrayList<String>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            result.add(baseSourceName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return stratum.sourceNames(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public List<String> sourcePaths(String stratumID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                                throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        SDE.Stratum stratum = stratum(stratumID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        if (stratum.isJava()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            List<String> result = new ArrayList<String>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            result.add(baseSourceDir() + baseSourceName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        return stratum.sourcePaths(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    String baseSourceName() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        String bsn = baseSourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        if (bsn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            // Does not need synchronization, since worst-case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            // static info is fetched twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                bsn = JDWP.ReferenceType.SourceFile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    process(vm, this).sourceFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    bsn = ABSENT_BASE_SOURCE_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            baseSourceName = bsn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        if (bsn == ABSENT_BASE_SOURCE_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        return bsn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    String baseSourcePath() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        String bsp = baseSourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (bsp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            bsp = baseSourceDir() + baseSourceName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            baseSourcePath = bsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return bsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    String baseSourceDir() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if (baseSourceDir == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            String typeName = name();
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 22049
diff changeset
   754
            StringBuilder sb = new StringBuilder(typeName.length() + 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            int nextIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            while ((nextIndex = typeName.indexOf('.', index)) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                sb.append(typeName.substring(index, nextIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                sb.append(java.io.File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                index = nextIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            baseSourceDir = sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return baseSourceDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public String sourceDebugExtension()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                           throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        if (!vm.canGetSourceDebugExtension()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        SDE sde = sourceDebugExtensionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (sde == NO_SDE_INFO_MARK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        return sde.sourceDebugExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private SDE sourceDebugExtensionInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        if (!vm.canGetSourceDebugExtension()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            return NO_SDE_INFO_MARK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   784
        SDE sde = (sdeRef == null) ?  null : sdeRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        if (sde == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            String extension = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                extension = JDWP.ReferenceType.SourceDebugExtension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    process(vm, this).extension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                if (exc.errorCode() != JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    sdeRef = new SoftReference<SDE>(NO_SDE_INFO_MARK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            if (extension == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                sde = NO_SDE_INFO_MARK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                sde = new SDE(extension);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            sdeRef = new SoftReference<SDE>(sde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        return sde;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public List<String> availableStrata() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        SDE sde = sourceDebugExtensionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if (sde.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            return sde.availableStrata();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            List<String> strata = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            strata.add(SDE.BASE_STRATUM_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            return strata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * Always returns non-null stratumID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    public String defaultStratum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        SDE sdei = sourceDebugExtensionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        if (sdei.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            return sdei.defaultStratumId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            return SDE.BASE_STRATUM_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public int modifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        if (modifiers == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    public List<Location> allLineLocations()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        return allLineLocations(vm.getDefaultStratum(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public List<Location> allLineLocations(String stratumID, String sourceName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        boolean someAbsent = false; // A method that should have info, didn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        SDE.Stratum stratum = stratum(stratumID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        List<Location> list = new ArrayList<Location>();  // location list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   847
        for (Iterator<Method> iter = methods().iterator(); iter.hasNext(); ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            MethodImpl method = (MethodImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                list.addAll(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                   method.allLineLocations(stratum, sourceName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            } catch(AbsentInformationException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                someAbsent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        // If we retrieved no line info, and at least one of the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        // should have had some (as determined by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        // AbsentInformationException being thrown) then we rethrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        // the AbsentInformationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if (someAbsent && list.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    public List<Location> locationsOfLine(int lineNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                           throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return locationsOfLine(vm.getDefaultStratum(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                               null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                               lineNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    public List<Location> locationsOfLine(String stratumID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                                String sourceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                                int lineNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                           throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        // A method that should have info, didn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        boolean someAbsent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        // A method that should have info, did
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        boolean somePresent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        List<Method> methods = methods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        SDE.Stratum stratum = stratum(stratumID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        List<Location> list = new ArrayList<Location>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   887
        Iterator<Method> iter = methods.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        while(iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            MethodImpl method = (MethodImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            // eliminate native and abstract to eliminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            // false positives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            if (!method.isAbstract() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                !method.isNative()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                    list.addAll(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                       method.locationsOfLine(stratum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                                              sourceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                                              lineNumber));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    somePresent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                } catch(AbsentInformationException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    someAbsent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        if (someAbsent && !somePresent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    public List<ObjectReference> instances(long maxInstances) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        if (!vm.canGetInstanceInfo()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            throw new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                "target does not support getting instances");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if (maxInstances < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            throw new IllegalArgumentException("maxInstances is less than zero: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                                              + maxInstances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        int intMax = (maxInstances > Integer.MAX_VALUE)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            Integer.MAX_VALUE: (int)maxInstances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        // JDWP can't currently handle more than this (in mustang)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            return Arrays.asList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                (ObjectReference[])JDWP.ReferenceType.Instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                        process(vm, this, intMax).instances);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    private void getClassFileVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (!vm.canGetClassFileVersion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        JDWP.ReferenceType.ClassFileVersion classFileVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (versionNumberGotten) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                classFileVersion = JDWP.ReferenceType.ClassFileVersion.process(vm, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                    majorVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    minorVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                    versionNumberGotten = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            majorVersion = classFileVersion.majorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            minorVersion = classFileVersion.minorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            versionNumberGotten = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    public int majorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            getClassFileVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        } catch (RuntimeException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            throw exc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        return majorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    public int minorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            getClassFileVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        } catch (RuntimeException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            throw exc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        return minorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    private void getConstantPoolInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        JDWP.ReferenceType.ConstantPool jdwpCPool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        if (!vm.canGetConstantPool()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        if (constantPoolInfoGotten) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                jdwpCPool = JDWP.ReferenceType.ConstantPool.process(vm, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    constanPoolCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    constantPoolBytesRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                    constantPoolInfoGotten = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            byte[] cpbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            constanPoolCount = jdwpCPool.count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            cpbytes = jdwpCPool.bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            constantPoolBytesRef = new SoftReference<byte[]>(cpbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            constantPoolInfoGotten = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    public int constantPoolCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            getConstantPoolInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        } catch (RuntimeException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            throw exc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        return constanPoolCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    public byte[] constantPool() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            getConstantPoolInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        } catch (RuntimeException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            throw exc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        if (constantPoolBytesRef != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1022
            byte[] cpbytes = constantPoolBytesRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
             * Arrays are always modifiable, so it is a little unsafe
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
             * to return the cached bytecodes directly; instead, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
             * make a clone at the cost of using more memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
             */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1028
            return cpbytes.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    // Does not need synchronization, since worst-case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    // static info is fetched twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    void getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (modifiers != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            modifiers = JDWP.ReferenceType.Modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                                  process(vm, this).modBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    void decodeStatus(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        this.status = status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        if ((status & JDWP.ClassStatus.PREPARED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            isPrepared = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    void updateStatus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            decodeStatus(JDWP.ReferenceType.Status.process(vm, this).status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    void markPrepared() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        isPrepared = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    long ref() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        return ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    int indexOf(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        // Make sure they're all here - the obsolete method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        // won't be found and so will have index -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        return methods().indexOf(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    int indexOf(Field field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        // Make sure they're all here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        return fields().indexOf(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * Return true if an instance of this type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * can be assigned to a variable of the given type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    abstract boolean isAssignableTo(ReferenceType type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    boolean isAssignableFrom(ReferenceType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        return ((ReferenceTypeImpl)type).isAssignableTo(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    boolean isAssignableFrom(ObjectReference object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        return object == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
               isAssignableFrom(object.referenceType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    void setStatus(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        decodeStatus(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    void setSignature(String signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    void setGenericSignature(String signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        if (signature != null && signature.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            this.genericSignature = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        } else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            this.genericSignature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        this.genericSignatureGotten = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    private static boolean isPrimitiveArray(String signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        int i = signature.lastIndexOf('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
         * TO DO: Centralize JNI signature knowledge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
         * Ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
         *  jdk1.4/doc/guide/jpda/jdi/com/sun/jdi/doc-files/signature.html
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        boolean isPA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        if (i < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            isPA = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            char c = signature.charAt(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            isPA = (c != 'L');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        return isPA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    Type findType(String signature) throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        Type type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        if (signature.length() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            /* OTI FIX: Must be a primitive type or the void type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            char sig = signature.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            if (sig == 'V') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                type = vm.theVoidType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                type = vm.primitiveTypeMirror((byte)sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            // Must be a reference type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            ClassLoaderReferenceImpl loader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                       (ClassLoaderReferenceImpl)classLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            if ((loader == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                (isPrimitiveArray(signature)) //Work around 4450091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                // Caller wants type of boot class field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                type = vm.findBootType(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                // Caller wants type of non-boot class field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                type = loader.findType(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    String loaderString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        if (classLoader() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            return "loaded by " + classLoader().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            return "no class loader";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
}