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