src/jdk.jdi/share/classes/com/sun/tools/jdi/ClassTypeImpl.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/ClassTypeImpl.java@1820d351198d
child 54907 6bcda7ed24ef
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: 25859
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: 25859
diff changeset
    28
import java.util.ArrayList;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    29
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    31
import com.sun.jdi.ClassNotLoadedException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    32
import com.sun.jdi.ClassType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    33
import com.sun.jdi.Field;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    34
import com.sun.jdi.IncompatibleThreadStateException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    35
import com.sun.jdi.InterfaceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    36
import com.sun.jdi.InvalidTypeException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    37
import com.sun.jdi.InvocationException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    38
import com.sun.jdi.Method;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    39
import com.sun.jdi.ObjectReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    40
import com.sun.jdi.ReferenceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    41
import com.sun.jdi.ThreadReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    42
import com.sun.jdi.Value;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    43
import com.sun.jdi.VirtualMachine;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    45
final public class ClassTypeImpl extends InvokableTypeImpl
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    46
                                 implements ClassType
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    48
    private static class IResult implements InvocationResult {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    49
        final private JDWP.ClassType.InvokeMethod rslt;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    50
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    51
        public IResult(JDWP.ClassType.InvokeMethod rslt) {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    52
            this.rslt = rslt;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    53
        }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    54
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    55
        @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    56
        public ObjectReferenceImpl getException() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    57
            return rslt.exception;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    58
        }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    59
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    60
        @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    61
        public ValueImpl getResult() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    62
            return rslt.returnValue;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    63
        }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    64
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    65
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean cachedSuperclass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private ClassType superclass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private List<InterfaceType> interfaces = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    70
    protected ClassTypeImpl(VirtualMachine aVm, long aRef) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        super(aVm, aRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public ClassType superclass() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    75
        if (!cachedSuperclass)  {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            ClassTypeImpl sup = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                sup = JDWP.ClassType.Superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    process(vm, this).superclass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
             * If there is a superclass, cache its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
             * ClassType here. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
             * leave the cache reference null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (sup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                superclass = sup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            cachedSuperclass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return superclass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    98
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public List<InterfaceType> interfaces()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (interfaces == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            interfaces = getInterfaces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return interfaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   106
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   107
    public List<InterfaceType> allInterfaces() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   108
        return getAllInterfaces();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public List<ClassType> subclasses() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   112
        List<ClassType> subs = new ArrayList<>();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   113
        for (ReferenceType refType : vm.allClasses()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (refType instanceof ClassType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                ClassType clazz = (ClassType)refType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                ClassType superclass = clazz.superclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                if ((superclass != null) && superclass.equals(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    subs.add((ClassType)refType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return subs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public boolean isEnum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        ClassType superclass = superclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (superclass != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            superclass.name().equals("java.lang.Enum")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void setValue(Field field, Value value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        throws InvalidTypeException, ClassNotLoadedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        validateMirror(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        validateMirrorOrNull(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        validateFieldSet(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // More validation specific to setting from a ClassType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if(!field.isStatic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                            "Must set non-static field through an instance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            JDWP.ClassType.SetValues.FieldValue[] values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                          new JDWP.ClassType.SetValues.FieldValue[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            values[0] = new JDWP.ClassType.SetValues.FieldValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    ((FieldImpl)field).ref(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    // validate and convert if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    ValueImpl.prepareForAssignment(value, (FieldImpl)field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                JDWP.ClassType.SetValues.process(vm, this, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        } catch (ClassNotLoadedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
             * Since we got this exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
             * the field type must be a reference type. The value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
             * we're trying to set is null, but if the field's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
             * class has not yet been loaded through the enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
             * class loader, then setting to null is essentially a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
             * no-op, and we should allow it without an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    PacketStream sendNewInstanceCommand(final ThreadReferenceImpl thread,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   177
                                        final MethodImpl method,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   178
                                        final ValueImpl[] args,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   179
                                        final int options) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        CommandSender sender =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            new CommandSender() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                public PacketStream send() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    return JDWP.ClassType.NewInstance.enqueueCommand(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                          vm, ClassTypeImpl.this, thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                          method.ref(), args, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        PacketStream stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if ((options & INVOKE_SINGLE_THREADED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            stream = thread.sendResumingCommand(sender);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            stream = vm.sendResumingCommand(sender);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public ObjectReference newInstance(ThreadReference threadIntf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                       Method methodIntf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                       List<? extends Value> origArguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                       int options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                   throws InvalidTypeException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                          ClassNotLoadedException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                          IncompatibleThreadStateException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                          InvocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        validateMirror(threadIntf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        validateMirror(methodIntf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        validateMirrorsOrNulls(origArguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        MethodImpl method = (MethodImpl)methodIntf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        ThreadReferenceImpl thread = (ThreadReferenceImpl)threadIntf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        validateConstructorInvocation(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        List<Value> arguments = method.validateAndPrepareArgumentsForInvoke(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                                       origArguments);
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   217
        ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        JDWP.ClassType.NewInstance ret = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            PacketStream stream =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                sendNewInstanceCommand(thread, method, args, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            ret = JDWP.ClassType.NewInstance.waitForReply(vm, stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                throw new IncompatibleThreadStateException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * There is an implict VM-wide suspend at the conclusion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         * of a normal (non-single-threaded) method invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if ((options & INVOKE_SINGLE_THREADED) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            vm.notifySuspend();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (ret.exception != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new InvocationException(ret.exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return ret.newObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
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 Method concreteMethodByName(String name, String signature)  {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   247
        Method method = null;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   248
        for (Method candidate : visibleMethods()) {
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   249
            if (candidate.name().equals(name) &&
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   250
                candidate.signature().equals(signature) &&
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   251
                !candidate.isAbstract()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   253
                method = candidate;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   254
                break;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   255
            }
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   256
        }
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   257
        return method;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   258
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    void validateConstructorInvocation(Method method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                   throws InvalidTypeException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                          InvocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * Method must be in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        ReferenceTypeImpl declType = (ReferenceTypeImpl)method.declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (!declType.equals(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            throw new IllegalArgumentException("Invalid constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * Method must be a constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (!method.isConstructor()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            throw new IllegalArgumentException("Cannot create instance with non-constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
       return "class " + name() + " (" + loaderString() + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   282
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   283
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   284
    CommandSender getInvokeMethodSender(ThreadReferenceImpl thread,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   285
                                        MethodImpl method,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   286
                                        ValueImpl[] args,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   287
                                        int options) {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   288
        return () ->
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   289
            JDWP.ClassType.InvokeMethod.enqueueCommand(vm,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   290
                                                       ClassTypeImpl.this,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   291
                                                       thread,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   292
                                                       method.ref(),
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   293
                                                       args,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   294
                                                       options);
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   295
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   296
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   297
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   298
    InvocationResult waitForReply(PacketStream stream) throws JDWPException {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   299
        return new IResult(JDWP.ClassType.InvokeMethod.waitForReply(vm, stream));
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   300
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   301
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   302
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   303
    boolean canInvoke(Method method) {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   304
        // Method must be in this class or a superclass.
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   305
        return ((ReferenceTypeImpl)method.declaringType()).isAssignableFrom(this);
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   306
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}