src/jdk.jdi/share/classes/com/sun/tools/jdi/InterfaceTypeImpl.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/InterfaceTypeImpl.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: 30350
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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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: 30350
diff changeset
    28
import java.lang.ref.SoftReference;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collections;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 30350
diff changeset
    31
import java.util.List;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 30350
diff changeset
    32
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 30350
diff changeset
    33
import com.sun.jdi.ClassType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 30350
diff changeset
    34
import com.sun.jdi.InterfaceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 30350
diff changeset
    35
import com.sun.jdi.Method;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 30350
diff changeset
    36
import com.sun.jdi.ReferenceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 30350
diff changeset
    37
import com.sun.jdi.VirtualMachine;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    39
final public class InterfaceTypeImpl extends InvokableTypeImpl
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    40
                                     implements InterfaceType {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    41
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    42
    private static class IResult implements InvocationResult {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    43
        final private JDWP.InterfaceType.InvokeMethod rslt;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    44
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    45
        public IResult(JDWP.InterfaceType.InvokeMethod rslt) {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    46
            this.rslt = rslt;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    47
        }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    48
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    49
        @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    50
        public ObjectReferenceImpl getException() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    51
            return rslt.exception;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    52
        }
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
        @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    55
        public ValueImpl getResult() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    56
            return rslt.returnValue;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
    57
        }
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
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private SoftReference<List<InterfaceType>> superinterfacesRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected InterfaceTypeImpl(VirtualMachine aVm,long aRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        super(aVm, aRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public List<InterfaceType> superinterfaces() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        List<InterfaceType> superinterfaces = (superinterfacesRef == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                     superinterfacesRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (superinterfaces == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            superinterfaces = getInterfaces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            superinterfaces = Collections.unmodifiableList(superinterfaces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            superinterfacesRef = new SoftReference<List<InterfaceType>>(superinterfaces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return superinterfaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public List<InterfaceType> subinterfaces() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        List<InterfaceType> subs = new ArrayList<InterfaceType>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        for (ReferenceType refType : vm.allClasses()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (refType instanceof InterfaceType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                InterfaceType interfaze = (InterfaceType)refType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                if (interfaze.isPrepared() && interfaze.superinterfaces().contains(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    subs.add(interfaze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return subs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public List<ClassType> implementors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        List<ClassType> implementors = new ArrayList<ClassType>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        for (ReferenceType refType : vm.allClasses()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (refType instanceof ClassType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                ClassType clazz = (ClassType)refType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                if (clazz.isPrepared() && clazz.interfaces().contains(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    implementors.add(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return implementors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public boolean isInitialized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return isPrepared();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
       return "interface " + name() + " (" + loaderString() + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   111
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   112
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   113
    InvocationResult waitForReply(PacketStream stream) throws JDWPException {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   114
        return new IResult(JDWP.InterfaceType.InvokeMethod.waitForReply(vm, stream));
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   115
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   116
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   117
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   118
    CommandSender getInvokeMethodSender(final ThreadReferenceImpl thread,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   119
                                        final MethodImpl method,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   120
                                        final ValueImpl[] args,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   121
                                        final int options) {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   122
        return () ->
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   123
            JDWP.InterfaceType.InvokeMethod.enqueueCommand(vm,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   124
                                                           InterfaceTypeImpl.this,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   125
                                                           thread,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   126
                                                           method.ref(),
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   127
                                                           args,
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   128
                                                           options);
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   129
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   130
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   131
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   132
    ClassType superclass() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   133
        return null;
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   134
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   135
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   136
    @Override
30350
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   137
    boolean isAssignableTo(ReferenceType type) {
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   138
        if (type.name().equals("java.lang.Object")) {
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   139
            // interfaces are always assignable to j.l.Object
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   140
            return true;
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   141
        }
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   142
        return super.isAssignableTo(type);
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   143
    }
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   144
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   145
    @Override
24195
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   146
    List<InterfaceType> interfaces() {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   147
        return superinterfaces();
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   148
    }
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   149
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   150
    @Override
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   151
    boolean canInvoke(Method method) {
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   152
        // method must be directly in this interface
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   153
        return this.equals(method.declaringType());
705325a63a58 8042123: Support default and static interface methods in JDI, JDWP and JDB
jbachorik
parents: 24127
diff changeset
   154
    }
30350
c055af074935 8075331: jdb eval java.util.Arrays.asList(array) shows inconsistent behaviour
sla
parents: 25859
diff changeset
   155
}