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