src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45714 jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java@1820d351198d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    28
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.List;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    30
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    31
import com.sun.jdi.AbsentInformationException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    32
import com.sun.jdi.ArrayReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    33
import com.sun.jdi.ArrayType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    34
import com.sun.jdi.ClassNotLoadedException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    35
import com.sun.jdi.InterfaceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    36
import com.sun.jdi.InvalidTypeException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    37
import com.sun.jdi.Location;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    38
import com.sun.jdi.Method;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    39
import com.sun.jdi.Type;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    40
import com.sun.jdi.Value;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    41
import com.sun.jdi.VirtualMachine;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public abstract class MethodImpl extends TypeComponentImpl
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    44
                                 implements Method
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    45
{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private JNITypeParser signatureParser;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    47
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    abstract int argSlotCount() throws AbsentInformationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    abstract List<Location> allLineLocations(SDE.Stratum stratum,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    51
                                             String sourceName)
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    52
                            throws AbsentInformationException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    abstract List<Location> locationsOfLine(SDE.Stratum stratum,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    55
                                            String sourceName,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    56
                                            int lineNumber)
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    57
                            throws AbsentInformationException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    MethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    60
               long ref, String name, String signature,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
               String genericSignature, int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        super(vm, declaringType, ref, name, signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
              genericSignature, modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        signatureParser = new JNITypeParser(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static MethodImpl createMethodImpl(VirtualMachine vm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                       ReferenceTypeImpl declaringType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                       long ref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                       String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                       String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                       String genericSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                       int modifiers) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
    74
        if ((modifiers & (VMModifiers.NATIVE | VMModifiers.ABSTRACT)) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            return new NonConcreteMethodImpl(vm, declaringType, ref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                             name, signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                             genericSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                             modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            return new ConcreteMethodImpl(vm, declaringType, ref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                          name, signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                          genericSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                          modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if ((obj != null) && (obj instanceof MethodImpl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            MethodImpl other = (MethodImpl)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return (declaringType().equals(other.declaringType())) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                   (ref() == other.ref()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                   super.equals(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return (int)ref();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public final List<Location> allLineLocations()
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   103
                                throws AbsentInformationException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return allLineLocations(vm.getDefaultStratum(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public List<Location> allLineLocations(String stratumID,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   108
                                           String sourceName)
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   109
                          throws AbsentInformationException {
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   110
        return allLineLocations(declaringType.stratum(stratumID), sourceName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public final List<Location> locationsOfLine(int lineNumber)
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   114
                                throws AbsentInformationException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return locationsOfLine(vm.getDefaultStratum(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                               null, lineNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public List<Location> locationsOfLine(String stratumID,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   120
                                          String sourceName,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   121
                                          int lineNumber)
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   122
                          throws AbsentInformationException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return locationsOfLine(declaringType.stratum(stratumID),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                               sourceName, lineNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    LineInfo codeIndexToLineInfo(SDE.Stratum stratum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                 long codeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (stratum.isJava()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return new BaseLineInfo(-1, declaringType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   132
            return new StratumLineInfo(stratum.id(), -1, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return a text representation of the declared return type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public String returnTypeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return signatureParser.typeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private String returnSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return signatureParser.signature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public Type returnType() throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return findType(returnSignature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public Type findType(String signature) throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return enclosing.findType(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public List<String> argumentTypeNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return signatureParser.argumentTypeNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public List<String> argumentSignatures() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return signatureParser.argumentSignatures();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    Type argumentType(int index) throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   167
        String signature = argumentSignatures().get(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return enclosing.findType(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public List<Type> argumentTypes() throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        int size = argumentSignatures().size();
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   173
        List<Type> types = new ArrayList<>(size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        for (int i = 0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            Type type = argumentType(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            types.add(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public int compareTo(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int rc = declaringType.compareTo(method.declaringType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (rc == 0) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   186
            rc = declaringType.indexOf(this) - declaringType.indexOf(method);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public boolean isAbstract() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return isModifierSet(VMModifiers.ABSTRACT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   195
    public boolean isDefault() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   196
        return !isModifierSet(VMModifiers.ABSTRACT) &&
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   197
               !isModifierSet(VMModifiers.STATIC) &&
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   198
               !isModifierSet(VMModifiers.PRIVATE) &&
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   199
               declaringType() instanceof InterfaceType;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   200
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   201
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public boolean isSynchronized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return isModifierSet(VMModifiers.SYNCHRONIZED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public boolean isNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return isModifierSet(VMModifiers.NATIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public boolean isVarArgs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return isModifierSet(VMModifiers.VARARGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public boolean isBridge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return isModifierSet(VMModifiers.BRIDGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public boolean isConstructor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return name().equals("<init>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public boolean isStaticInitializer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return name().equals("<clinit>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public boolean isObsolete() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return JDWP.Method.IsObsolete.process(vm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                    declaringType, ref).isObsolete;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * A container class for the return value to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * proper type-checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    class ReturnContainer implements ValueContainer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        ReturnContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        public Type type() throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return returnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        public String typeName(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return returnTypeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        public String signature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return returnSignature(); //type().signature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        public Type findType(String signature) throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return MethodImpl.this.findType(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    ReturnContainer retValContainer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    ReturnContainer getReturnValueContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (retValContainer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            retValContainer = new ReturnContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return retValContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * A container class for the argument to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * proper type-checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    class ArgumentContainer implements ValueContainer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        ArgumentContainer(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        public Type type() throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return argumentType(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public String typeName(){
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   277
            return argumentTypeNames().get(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        public String signature() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   280
            return argumentSignatures().get(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        public Type findType(String signature) throws ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return MethodImpl.this.findType(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * This is a var args method.  Thus, its last param is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * array. If the method has n params, then:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * 1.  If there are n args and the last is the same type as the type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *     the last param, do nothing.  IE, a String[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *     can be passed to a String...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * 2.  If there are >= n arguments and for each arg whose number is >= n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *     the arg type is 'compatible' with the component type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *     the last param, then do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *     - create an array of the type of the last param
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *     - put the n, ... args into this array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *       We might have to do conversions here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *     - put this array into arguments(n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *     - delete arguments(n+1), ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * NOTE that this might modify the input list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    void handleVarArgs(List<Value> arguments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        throws ClassNotLoadedException, InvalidTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        List<Type> paramTypes = this.argumentTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        ArrayType lastParamType = (ArrayType)paramTypes.get(paramTypes.size() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        int argCount = arguments.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        int paramCount = paramTypes.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (argCount < paramCount - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // Error; will be caught later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (argCount == paramCount - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            // It is ok to pass 0 args to the var arg.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // We have to gen a 0 length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            ArrayReference argArray = lastParamType.newInstance(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            arguments.add(argArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   320
        Value nthArgValue = arguments.get(paramCount - 1);
42676
36fa143f8de8 8160024: jdb returns invalid argument count if first parameter to Arrays.asList is null
sspitsyn
parents: 25859
diff changeset
   321
        if (nthArgValue == null && argCount == paramCount) {
36fa143f8de8 8160024: jdb returns invalid argument count if first parameter to Arrays.asList is null
sspitsyn
parents: 25859
diff changeset
   322
            // We have one varargs parameter and it is null
36fa143f8de8 8160024: jdb returns invalid argument count if first parameter to Arrays.asList is null
sspitsyn
parents: 25859
diff changeset
   323
            // so we don't have to do anything.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
42676
36fa143f8de8 8160024: jdb returns invalid argument count if first parameter to Arrays.asList is null
sspitsyn
parents: 25859
diff changeset
   326
        // If the first varargs parameter is null, then don't
36fa143f8de8 8160024: jdb returns invalid argument count if first parameter to Arrays.asList is null
sspitsyn
parents: 25859
diff changeset
   327
        // access its type since it can't be an array.
36fa143f8de8 8160024: jdb returns invalid argument count if first parameter to Arrays.asList is null
sspitsyn
parents: 25859
diff changeset
   328
        Type nthArgType = (nthArgValue == null) ? null : nthArgValue.type();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (nthArgType instanceof ArrayTypeImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            if (argCount == paramCount &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                ((ArrayTypeImpl)nthArgType).isAssignableTo(lastParamType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                 * This is case 1.  A compatible array is being passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                 * var args array param.  We don't have to do anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * Case 2.  We have to verify that the n, n+1, ... args are compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * with componentType, and do conversions if necessary and create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * an array of componentType to hold these possibly converted values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        int count = argCount - paramCount + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        ArrayReference argArray = lastParamType.newInstance(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * This will copy arguments(paramCount - 1) ... to argArray(0) ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * doing whatever conversions are needed!  It will throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * exception if an incompatible arg is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        argArray.setValues(0, arguments, paramCount - 1, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        arguments.set(paramCount - 1, argArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * Remove the excess args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        for (int ii = paramCount; ii < argCount; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            arguments.remove(paramCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * The output list will be different than the input list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    List<Value> validateAndPrepareArgumentsForInvoke(List<? extends Value> origArguments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                         throws ClassNotLoadedException, InvalidTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 42676
diff changeset
   371
        List<Value> arguments = new ArrayList<>(origArguments);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (isVarArgs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            handleVarArgs(arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        int argSize = arguments.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        JNITypeParser parser = new JNITypeParser(signature());
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   379
        List<String> signatures = parser.argumentSignatures();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (signatures.size() != argSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            throw new IllegalArgumentException("Invalid argument count: expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                               signatures.size() + ", received " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                               arguments.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        for (int i = 0; i < argSize; i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   388
            Value value = arguments.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            value = ValueImpl.prepareForAssignment(value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                                   new ArgumentContainer(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            arguments.set(i, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 24195
diff changeset
   397
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        sb.append(declaringType().name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        sb.append(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        sb.append(name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        sb.append("(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        boolean first = true;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   403
        for (String name : argumentTypeNames()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if (!first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                sb.append(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   407
            sb.append(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        sb.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
}