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