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-- |
2 | 1 |
/* |
45714 | 2 |
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.jdi; |
|
27 |
||
45714 | 28 |
import java.lang.ref.SoftReference; |
2 | 29 |
import java.util.ArrayList; |
30 |
import java.util.Collections; |
|
45714 | 31 |
import java.util.List; |
32 |
||
33 |
import com.sun.jdi.ClassType; |
|
34 |
import com.sun.jdi.InterfaceType; |
|
35 |
import com.sun.jdi.Method; |
|
36 |
import com.sun.jdi.ReferenceType; |
|
37 |
import com.sun.jdi.VirtualMachine; |
|
2 | 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 | 60 |
|
61 |
private SoftReference<List<InterfaceType>> superinterfacesRef = null; |
|
62 |
||
63 |
protected InterfaceTypeImpl(VirtualMachine aVm,long aRef) { |
|
64 |
super(aVm, aRef); |
|
65 |
} |
|
66 |
||
67 |
public List<InterfaceType> superinterfaces() { |
|
68 |
List<InterfaceType> superinterfaces = (superinterfacesRef == null) ? null : |
|
69 |
superinterfacesRef.get(); |
|
70 |
if (superinterfaces == null) { |
|
71 |
superinterfaces = getInterfaces(); |
|
72 |
superinterfaces = Collections.unmodifiableList(superinterfaces); |
|
73 |
superinterfacesRef = new SoftReference<List<InterfaceType>>(superinterfaces); |
|
74 |
} |
|
75 |
return superinterfaces; |
|
76 |
} |
|
77 |
||
78 |
public List<InterfaceType> subinterfaces() { |
|
79 |
List<InterfaceType> subs = new ArrayList<InterfaceType>(); |
|
80 |
for (ReferenceType refType : vm.allClasses()) { |
|
81 |
if (refType instanceof InterfaceType) { |
|
82 |
InterfaceType interfaze = (InterfaceType)refType; |
|
83 |
if (interfaze.isPrepared() && interfaze.superinterfaces().contains(this)) { |
|
84 |
subs.add(interfaze); |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
return subs; |
|
89 |
} |
|
90 |
||
91 |
public List<ClassType> implementors() { |
|
92 |
List<ClassType> implementors = new ArrayList<ClassType>(); |
|
93 |
for (ReferenceType refType : vm.allClasses()) { |
|
94 |
if (refType instanceof ClassType) { |
|
95 |
ClassType clazz = (ClassType)refType; |
|
96 |
if (clazz.isPrepared() && clazz.interfaces().contains(this)) { |
|
97 |
implementors.add(clazz); |
|
98 |
} |
|
99 |
} |
|
100 |
} |
|
101 |
return implementors; |
|
102 |
} |
|
103 |
||
104 |
public boolean isInitialized() { |
|
105 |
return isPrepared(); |
|
106 |
} |
|
107 |
||
108 |
public String toString() { |
|
109 |
return "interface " + name() + " (" + loaderString() + ")"; |
|
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 |
} |