1/* 2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 * 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. 24 */ 25 26package com.sun.jdi; 27 28import java.util.List; 29 30/** 31 * A mirror of an interface in the target VM. An InterfaceType is 32 * a refinement of {@link ReferenceType} that applies to true interfaces 33 * in the JLS sense of the definition (not a class, not an array type). 34 * An interface type will never be returned by 35 * {@link ObjectReference#referenceType}, but it may be in the list 36 * of implemented interfaces for a {@link ClassType} that is returned 37 * by that method. 38 * 39 * @see ObjectReference 40 * 41 * @author Robert Field 42 * @author Gordon Hirsch 43 * @author James McIlree 44 * @since 1.3 45 */ 46public interface InterfaceType extends ReferenceType { 47 48 /** 49 * Gets the interfaces directly extended by this interface. 50 * The returned list contains only those interfaces this 51 * interface has declared to be extended. 52 * 53 * @return a List of {@link InterfaceType} objects each mirroring 54 * an interface extended by this interface. 55 * If none exist, returns a zero length List. 56 * @throws ClassNotPreparedException if this class not yet been 57 * prepared. 58 */ 59 List<InterfaceType> superinterfaces(); 60 61 /** 62 * Gets the currently prepared interfaces which directly extend this 63 * interface. The returned list contains only those interfaces that 64 * declared this interface in their "extends" clause. 65 * 66 * @return a List of {@link InterfaceType} objects each mirroring 67 * an interface extending this interface. 68 * If none exist, returns a zero length List. 69 */ 70 List<InterfaceType> subinterfaces(); 71 72 /** 73 * Gets the currently prepared classes which directly implement this 74 * interface. The returned list contains only those classes that 75 * declared this interface in their "implements" clause. 76 * 77 * @return a List of {@link ClassType} objects each mirroring 78 * a class implementing this interface. 79 * If none exist, returns a zero length List. 80 */ 81 List<ClassType> implementors(); 82 83 /** 84 * Invokes the specified static {@link Method} in the 85 * target VM. The 86 * specified method must be defined in this interface. 87 * The method must be a static method 88 * but not a static initializer. 89 * <p> 90 * The method invocation will occur in the specified thread. 91 * Method invocation can occur only if the specified thread 92 * has been suspended by an event which occurred in that thread. 93 * Method invocation is not supported 94 * when the target VM has been suspended through 95 * {@link VirtualMachine#suspend} or when the specified thread 96 * is suspended through {@link ThreadReference#suspend}. 97 * <p> 98 * The specified method is invoked with the arguments in the specified 99 * argument list. The method invocation is synchronous; this method 100 * does not return until the invoked method returns in the target VM. 101 * If the invoked method throws an exception, this method will throw 102 * an {@link InvocationException} which contains a mirror to the exception 103 * object thrown. 104 * <p> 105 * Object arguments must be assignment compatible with the argument type 106 * (This implies that the argument type must be loaded through the 107 * enclosing class' class loader). Primitive arguments must be 108 * either assignment compatible with the argument type or must be 109 * convertible to the argument type without loss of information. 110 * If the method being called accepts a variable number of arguments, 111 * then the last argument type is an array of some component type. 112 * The argument in the matching position can be omitted, or can be null, 113 * an array of the same component type, or an argument of the 114 * component type followed by any number of other arguments of the same 115 * type. If the argument is omitted, then a 0 length array of the 116 * component type is passed. The component type can be a primitive type. 117 * Autoboxing is not supported. 118 * 119 * See Section 5.2 of 120 * <cite>The Java™ Language Specification</cite> 121 * for more information on assignment compatibility. 122 * <p> 123 * By default, all threads in the target VM are resumed while 124 * the method is being invoked if they were previously 125 * suspended by an event or by {@link VirtualMachine#suspend} or 126 * {@link ThreadReference#suspend}. This is done to prevent the deadlocks 127 * that will occur if any of the threads own monitors 128 * that will be needed by the invoked method. 129 * Note, however, that this implicit resume acts exactly like 130 * {@link ThreadReference#resume}, so if the thread's suspend 131 * count is greater than 1, it will remain in a suspended state 132 * during the invocation and thus a deadlock could still occur. 133 * By default, when the invocation completes, 134 * all threads in the target VM are suspended, regardless their state 135 * before the invocation. 136 * It is possible that 137 * breakpoints or other events might occur during the invocation. 138 * This can cause deadlocks as described above. It can also cause a deadlock 139 * if invokeMethod is called from the client's event handler thread. In this 140 * case, this thread will be waiting for the invokeMethod to complete and 141 * won't read the EventSet that comes in for the new event. If this 142 * new EventSet is SUSPEND_ALL, then a deadlock will occur because no 143 * one will resume the EventSet. To avoid this, all EventRequests should 144 * be disabled before doing the invokeMethod, or the invokeMethod should 145 * not be done from the client's event handler thread. 146 * <p> 147 * The resumption of other threads during the invocation can be prevented 148 * by specifying the {@link ClassType#INVOKE_SINGLE_THREADED} 149 * bit flag in the <code>options</code> argument; however, 150 * there is no protection against or recovery from the deadlocks 151 * described above, so this option should be used with great caution. 152 * Only the specified thread will be resumed (as described for all 153 * threads above). Upon completion of a single threaded invoke, the invoking thread 154 * will be suspended once again. Note that any threads started during 155 * the single threaded invocation will not be suspended when the 156 * invocation completes. 157 * <p> 158 * If the target VM is disconnected during the invoke (for example, through 159 * {@link VirtualMachine#dispose}) the method invocation continues. 160 * 161 * @param thread the thread in which to invoke. 162 * @param method the {@link Method} to invoke. 163 * @param arguments the list of {@link Value} arguments bound to the 164 * invoked method. Values from the list are assigned to arguments 165 * in the order they appear in the method signature. 166 * @param options the integer bit flag options. 167 * @return a {@link Value} mirror of the invoked method's return value. 168 * @throws java.lang.IllegalArgumentException if the method is not 169 * a member of this interface, if the size of the argument list 170 * does not match the number of declared arguments for the method, or 171 * if the method is not static or is a static initializer. 172 * @throws ClassNotLoadedException if any argument type has not yet been loaded 173 * through the appropriate class loader. 174 * @throws IncompatibleThreadStateException if the specified thread has not 175 * been suspended by an event. 176 * @throws InvocationException if the method invocation resulted in 177 * an exception in the target VM. 178 * @throws InvalidTypeException If the arguments do not meet this requirement -- 179 * Object arguments must be assignment compatible with the argument 180 * type. This implies that the argument type must be 181 * loaded through the enclosing class' class loader. 182 * Primitive arguments must be either assignment compatible with the 183 * argument type or must be convertible to the argument type without loss 184 * of information. See JLS section 5.2 for more information on assignment 185 * compatibility. 186 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}. 187 * 188 * @since 1.8 189 */ 190 default Value invokeMethod(ThreadReference thread, Method method, 191 List<? extends Value> arguments, int options) 192 throws InvalidTypeException, 193 ClassNotLoadedException, 194 IncompatibleThreadStateException, 195 InvocationException 196 { 197 throw new UnsupportedOperationException(); 198 } 199} 200