src/jdk.jdi/share/classes/com/sun/tools/jdi/EventSetImpl.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/EventSetImpl.java@1820d351198d
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: 832
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: 832
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: 832
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 832
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 832
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.Collection;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    30
import java.util.Iterator;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    31
import java.util.NoSuchElementException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    32
import java.util.Spliterator;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    33
import java.util.Spliterators;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    35
import com.sun.jdi.Field;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    36
import com.sun.jdi.InternalException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    37
import com.sun.jdi.Locatable;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    38
import com.sun.jdi.Location;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    39
import com.sun.jdi.Method;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    40
import com.sun.jdi.ObjectReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    41
import com.sun.jdi.ReferenceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    42
import com.sun.jdi.ThreadReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    43
import com.sun.jdi.VMDisconnectedException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    44
import com.sun.jdi.Value;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    45
import com.sun.jdi.VirtualMachine;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    46
import com.sun.jdi.event.AccessWatchpointEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    47
import com.sun.jdi.event.BreakpointEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    48
import com.sun.jdi.event.ClassPrepareEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    49
import com.sun.jdi.event.ClassUnloadEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    50
import com.sun.jdi.event.Event;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    51
import com.sun.jdi.event.EventIterator;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    52
import com.sun.jdi.event.EventSet;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    53
import com.sun.jdi.event.ExceptionEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    54
import com.sun.jdi.event.MethodEntryEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    55
import com.sun.jdi.event.MethodExitEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    56
import com.sun.jdi.event.ModificationWatchpointEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    57
import com.sun.jdi.event.MonitorContendedEnterEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    58
import com.sun.jdi.event.MonitorContendedEnteredEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    59
import com.sun.jdi.event.MonitorWaitEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    60
import com.sun.jdi.event.MonitorWaitedEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    61
import com.sun.jdi.event.StepEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    62
import com.sun.jdi.event.ThreadDeathEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    63
import com.sun.jdi.event.ThreadStartEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    64
import com.sun.jdi.event.VMDeathEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    65
import com.sun.jdi.event.VMDisconnectEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    66
import com.sun.jdi.event.VMStartEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    67
import com.sun.jdi.event.WatchpointEvent;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    68
import com.sun.jdi.request.EventRequest;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    69
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
enum EventDestination {UNKNOWN_EVENT, INTERNAL_EVENT, CLIENT_EVENT};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * An EventSet is normally created by the transport reader thread when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * it reads a JDWP Composite command.  The constructor doesn't unpack
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * the events contained in the Composite command and create EventImpls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * for them because that process might involve calling back into the back-end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * which should not be done by the transport reader thread.  Instead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * the raw bytes of the packet are read and stored in the EventSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * The EventSet is then added to each EventQueue. When an EventSet is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * removed from an EventQueue, the EventSetImpl.build() method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * This method reads the packet bytes and creates the actual EventImpl objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * build() also filters out events for our internal handler and puts them in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * their own EventSet.  This means that the EventImpls that are in the EventSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * that is on the queues are all for client requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
public class EventSetImpl extends ArrayList<Event> implements EventSet {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
    87
    private static final long serialVersionUID = -4857338819787924570L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private VirtualMachineImpl vm; // we implement Mirror
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private Packet pkt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private byte suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private EventSetImpl internalEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        String string = "event set, policy:" + suspendPolicy +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        ", count:" + this.size() + " = {";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        boolean first = true;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    97
        for (Event event : this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            if (!first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                string += ", ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            string += event.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        string += "}";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    abstract class EventImpl extends MirrorImpl implements Event {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        private final byte eventCmd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        private final int requestID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // This is set only for client requests, not internal requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        private final EventRequest request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * Constructor for events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        protected EventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                            int requestID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            super(EventSetImpl.this.vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            this.eventCmd = evt.eventKind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            this.requestID = requestID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            EventRequestManagerImpl ermi = EventSetImpl.this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                vm.eventRequestManagerImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            this.request =  ermi.request(eventCmd, requestID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * Override superclass back to default equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return this == obj;
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 int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            return System.identityHashCode(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * Constructor for VM disconnected events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        protected EventImpl(byte eventCmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            super(EventSetImpl.this.vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            this.eventCmd = eventCmd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            this.requestID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            this.request = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        public EventRequest request() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return request;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        int requestID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return requestID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        EventDestination destination() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
             * We need to decide if this event is for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
             * 1. an internal request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
             * 2. a client request that is no longer available, ie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
             *    it has been deleted, or disabled and re-enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
             *    which gives it a new ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
             * 3. a current client request that is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
             * 4. a current enabled client request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
             * We will filter this set into a set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
             * that contains only 1s for our internal queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
             * and a set that contains only 4s for our client queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
             * If we get an EventSet that contains only 2 and 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
             * then we have to resume it if it is not SUSPEND_NONE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
             * because no one else will.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (requestID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                /* An unsolicited event.  These have traditionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                 * been treated as client events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return EventDestination.CLIENT_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            // Is this an event for a current client request?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (request == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                // Nope.  Is it an event for an internal request?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                EventRequestManagerImpl ermi = this.vm.getInternalEventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                if (ermi.request(eventCmd, requestID) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    // Yep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    return EventDestination.INTERNAL_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                return EventDestination.UNKNOWN_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            // We found a client request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (request.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                return EventDestination.CLIENT_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return EventDestination.UNKNOWN_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        abstract String eventName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return eventName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    abstract class ThreadedEventImpl extends EventImpl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        private ThreadReference thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        ThreadedEventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                          int requestID, ThreadReference thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            super(evt, requestID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            this.thread = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public ThreadReference thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            return thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return eventName() + " in thread " + thread.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    abstract class LocatableEventImpl extends ThreadedEventImpl
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   226
                                      implements Locatable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        private Location location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        LocatableEventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                           int requestID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                           ThreadReference thread, Location location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            super(evt, requestID, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            this.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        public Location location() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         * For MethodEntry and MethodExit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public Method method() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return location.method();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        public String toString() {
829
813b4d167747 6614556: null location for MonitorContendedEnterEvent
swamyv
parents: 51
diff changeset
   248
            return eventName() + "@" +
813b4d167747 6614556: null location for MonitorContendedEnterEvent
swamyv
parents: 51
diff changeset
   249
                   ((location() == null) ? " null" : location().toString()) +
813b4d167747 6614556: null location for MonitorContendedEnterEvent
swamyv
parents: 51
diff changeset
   250
                   " in thread " + thread().name();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    class BreakpointEventImpl extends LocatableEventImpl
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   255
                              implements BreakpointEvent {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        BreakpointEventImpl(JDWP.Event.Composite.Events.Breakpoint evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return "BreakpointEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    class StepEventImpl extends LocatableEventImpl implements StepEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        StepEventImpl(JDWP.Event.Composite.Events.SingleStep evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return "StepEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    class MethodEntryEventImpl extends LocatableEventImpl
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   276
                               implements MethodEntryEvent {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        MethodEntryEventImpl(JDWP.Event.Composite.Events.MethodEntry evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            return "MethodEntryEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    class MethodExitEventImpl extends LocatableEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                            implements MethodExitEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        private Value returnVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        MethodExitEventImpl(JDWP.Event.Composite.Events.MethodExit evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        MethodExitEventImpl(JDWP.Event.Composite.Events.MethodExitWithReturnValue evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            returnVal = evt.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return "MethodExitEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        public Value returnValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (!this.vm.canGetMethodReturnValues()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                throw new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                "target does not support return values in MethodExit events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return returnVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    class MonitorContendedEnterEventImpl extends LocatableEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                            implements MonitorContendedEnterEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        private ObjectReference monitor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        MonitorContendedEnterEventImpl(JDWP.Event.Composite.Events.MonitorContendedEnter evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            this.monitor = evt.object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            return "MonitorContendedEnter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        public ObjectReference  monitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            return monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    class MonitorContendedEnteredEventImpl extends LocatableEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                            implements MonitorContendedEnteredEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        private ObjectReference monitor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        MonitorContendedEnteredEventImpl(JDWP.Event.Composite.Events.MonitorContendedEntered evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            this.monitor = evt.object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            return "MonitorContendedEntered";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        public ObjectReference  monitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            return monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    class MonitorWaitEventImpl extends LocatableEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                            implements MonitorWaitEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        private ObjectReference monitor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        private long timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        MonitorWaitEventImpl(JDWP.Event.Composite.Events.MonitorWait evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            this.monitor = evt.object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            this.timeout = evt.timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            return "MonitorWait";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        public ObjectReference  monitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            return monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        public long timeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    class MonitorWaitedEventImpl extends LocatableEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                            implements MonitorWaitedEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        private ObjectReference monitor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        private boolean timed_out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        MonitorWaitedEventImpl(JDWP.Event.Composite.Events.MonitorWaited evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            this.monitor = evt.object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            this.timed_out = evt.timed_out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return "MonitorWaited";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        public ObjectReference  monitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            return monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        public boolean timedout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return timed_out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    class ClassPrepareEventImpl extends ThreadedEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                            implements ClassPrepareEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        private ReferenceType referenceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        ClassPrepareEventImpl(JDWP.Event.Composite.Events.ClassPrepare evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            super(evt, evt.requestID, evt.thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            referenceType = this.vm.referenceType(evt.typeID, evt.refTypeTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                                  evt.signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            ((ReferenceTypeImpl)referenceType).setStatus(evt.status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        public ReferenceType referenceType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return referenceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return "ClassPrepareEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    class ClassUnloadEventImpl extends EventImpl implements ClassUnloadEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        private String classSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        ClassUnloadEventImpl(JDWP.Event.Composite.Events.ClassUnload evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            super(evt, evt.requestID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            this.classSignature = evt.signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        public String className() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return classSignature.substring(1, classSignature.length()-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                .replace('/', '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        public String classSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return classSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return "ClassUnloadEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    class ExceptionEventImpl extends LocatableEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                                             implements ExceptionEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        private ObjectReference exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        private Location catchLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        ExceptionEventImpl(JDWP.Event.Composite.Events.Exception evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            super(evt, evt.requestID, evt.thread, evt.location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            this.exception = evt.exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            this.catchLocation = evt.catchLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        public ObjectReference exception() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            return exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        public Location catchLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            return catchLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return "ExceptionEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    class ThreadDeathEventImpl extends ThreadedEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                        implements ThreadDeathEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        ThreadDeathEventImpl(JDWP.Event.Composite.Events.ThreadDeath evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            super(evt, evt.requestID, evt.thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            return "ThreadDeathEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    class ThreadStartEventImpl extends ThreadedEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                        implements ThreadStartEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        ThreadStartEventImpl(JDWP.Event.Composite.Events.ThreadStart evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            super(evt, evt.requestID, evt.thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            return "ThreadStartEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    class VMStartEventImpl extends ThreadedEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                        implements VMStartEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        VMStartEventImpl(JDWP.Event.Composite.Events.VMStart evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            super(evt, evt.requestID, evt.thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return "VMStartEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    class VMDeathEventImpl extends EventImpl implements VMDeathEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        VMDeathEventImpl(JDWP.Event.Composite.Events.VMDeath evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            super(evt, evt.requestID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return "VMDeathEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    class VMDisconnectEventImpl extends EventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                         implements VMDisconnectEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        VMDisconnectEventImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            super((byte)JDWP.EventKind.VM_DISCONNECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            return "VMDisconnectEvent";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    abstract class WatchpointEventImpl extends LocatableEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                            implements WatchpointEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        private final ReferenceTypeImpl refType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        private final long fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        private final ObjectReference object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        private Field field = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        WatchpointEventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                            int requestID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                            ThreadReference thread, Location location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                            byte refTypeTag, long typeID, long fieldID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                            ObjectReference object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            super(evt, requestID, thread, location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            this.refType = this.vm.referenceType(typeID, refTypeTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            this.fieldID = fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            this.object = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        public Field field() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (field == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                field = refType.getFieldMirror(fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            return field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        public ObjectReference object() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            return object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        public Value valueCurrent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (object == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                return refType.getValue(field());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                return object.getValue(field());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    class AccessWatchpointEventImpl extends WatchpointEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                            implements AccessWatchpointEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        AccessWatchpointEventImpl(JDWP.Event.Composite.Events.FieldAccess evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            super(evt, evt.requestID, evt.thread, evt.location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                  evt.refTypeTag, evt.typeID, evt.fieldID, evt.object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return "AccessWatchpoint";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    class ModificationWatchpointEventImpl extends WatchpointEventImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                           implements ModificationWatchpointEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        Value newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        ModificationWatchpointEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                        JDWP.Event.Composite.Events.FieldModification evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            super(evt, evt.requestID, evt.thread, evt.location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                  evt.refTypeTag, evt.typeID, evt.fieldID, evt.object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            this.newValue = evt.valueToBe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        public Value valueToBe() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            return newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        String eventName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            return "ModificationWatchpoint";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * Events are constructed on the thread which reads all data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * transport. This means that the packet cannot be converted to real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * JDI objects as that may involve further communications with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * back end which would deadlock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * Hence the {@link #build()} method below called by EventQueue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    EventSetImpl(VirtualMachine aVm, Packet pkt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        // From "MirrorImpl":
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        // Yes, its a bit of a hack. But by doing it this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        // way, this is the only place we have to change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        // typing to substitute a new impl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        vm = (VirtualMachineImpl)aVm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        this.pkt = pkt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Constructor for special events like VM disconnected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    EventSetImpl(VirtualMachine aVm, byte eventCmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        this(aVm, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        suspendPolicy = JDWP.SuspendPolicy.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        switch (eventCmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            case JDWP.EventKind.VM_DISCONNECTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                addEvent(new VMDisconnectEventImpl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                throw new InternalException("Bad singleton event code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    private void addEvent(EventImpl evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        // Note that this class has a public add method that throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        // an exception so that clients can't modify the EventSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        super.add(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Complete the construction of an EventSet.  This is called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * an event handler thread.  It upacks the JDWP events inside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * the packet and creates EventImpls for them.  The EventSet is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * on EventQueues when this is called, so it has to be synch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    synchronized void build() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        if (pkt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        PacketStream ps = new PacketStream(vm, pkt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        JDWP.Event.Composite compEvt = new JDWP.Event.Composite(vm, ps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        suspendPolicy = compEvt.suspendPolicy;
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   647
        if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            switch(suspendPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                case JDWP.SuspendPolicy.ALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    vm.printTrace("EventSet: SUSPEND_ALL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                case JDWP.SuspendPolicy.EVENT_THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    vm.printTrace("EventSet: SUSPEND_EVENT_THREAD");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                case JDWP.SuspendPolicy.NONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    vm.printTrace("EventSet: SUSPEND_NONE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        ThreadReference fix6485605 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        for (int i = 0; i < compEvt.events.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            EventImpl evt = createEvent(compEvt.events[i]);
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   666
            if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                    vm.printTrace("Event: " + evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                } catch (VMDisconnectedException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    // ignore - see bug 6502716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            switch (evt.destination()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                case UNKNOWN_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    // Ignore disabled, deleted, unknown events, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    // save the thread if there is one since we might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    // have to resume it.  Note that events for different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    // threads can't be in the same event set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                    if (evt instanceof ThreadedEventImpl &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                        suspendPolicy == JDWP.SuspendPolicy.EVENT_THREAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                        fix6485605 = ((ThreadedEventImpl)evt).thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                case CLIENT_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    addEvent(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                case INTERNAL_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    if (internalEventSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        internalEventSet = new EventSetImpl(this.vm, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    internalEventSet.addEvent(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    throw new InternalException("Invalid event destination");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        pkt = null; // No longer needed - free it up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        // Avoid hangs described in 6296125, 6293795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        if (super.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            // This set has no client events.  If we don't do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            // needed resumes, no one else is going to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            if (suspendPolicy == JDWP.SuspendPolicy.ALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                vm.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            } else if (suspendPolicy == JDWP.SuspendPolicy.EVENT_THREAD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                // See bug 6485605.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                if (fix6485605 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    fix6485605.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    // apparently, there is nothing to resume.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            suspendPolicy = JDWP.SuspendPolicy.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Filter out internal events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    EventSet userFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Filter out user events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    EventSet internalFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return this.internalEventSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    EventImpl createEvent(JDWP.Event.Composite.Events evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        JDWP.Event.Composite.Events.EventsCommon comm = evt.aEventsCommon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        switch (evt.eventKind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            case JDWP.EventKind.THREAD_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                return new ThreadStartEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                      (JDWP.Event.Composite.Events.ThreadStart)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            case JDWP.EventKind.THREAD_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                return new ThreadDeathEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                      (JDWP.Event.Composite.Events.ThreadDeath)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            case JDWP.EventKind.EXCEPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                return new ExceptionEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                      (JDWP.Event.Composite.Events.Exception)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            case JDWP.EventKind.BREAKPOINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                return new BreakpointEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                      (JDWP.Event.Composite.Events.Breakpoint)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            case JDWP.EventKind.METHOD_ENTRY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                return new MethodEntryEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                      (JDWP.Event.Composite.Events.MethodEntry)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            case JDWP.EventKind.METHOD_EXIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                return new MethodExitEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                      (JDWP.Event.Composite.Events.MethodExit)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            case JDWP.EventKind.METHOD_EXIT_WITH_RETURN_VALUE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                return new MethodExitEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                      (JDWP.Event.Composite.Events.MethodExitWithReturnValue)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            case JDWP.EventKind.FIELD_ACCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                return new AccessWatchpointEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                      (JDWP.Event.Composite.Events.FieldAccess)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            case JDWP.EventKind.FIELD_MODIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                return new ModificationWatchpointEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                      (JDWP.Event.Composite.Events.FieldModification)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            case JDWP.EventKind.SINGLE_STEP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                return new StepEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                      (JDWP.Event.Composite.Events.SingleStep)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            case JDWP.EventKind.CLASS_PREPARE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                return new ClassPrepareEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                      (JDWP.Event.Composite.Events.ClassPrepare)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            case JDWP.EventKind.CLASS_UNLOAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                return new ClassUnloadEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                      (JDWP.Event.Composite.Events.ClassUnload)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            case JDWP.EventKind.MONITOR_CONTENDED_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                return new MonitorContendedEnterEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                      (JDWP.Event.Composite.Events.MonitorContendedEnter)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            case JDWP.EventKind.MONITOR_CONTENDED_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                return new MonitorContendedEnteredEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                      (JDWP.Event.Composite.Events.MonitorContendedEntered)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            case JDWP.EventKind.MONITOR_WAIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                return new MonitorWaitEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                      (JDWP.Event.Composite.Events.MonitorWait)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            case JDWP.EventKind.MONITOR_WAITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                return new MonitorWaitedEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                      (JDWP.Event.Composite.Events.MonitorWaited)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            case JDWP.EventKind.VM_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                return new VMStartEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                      (JDWP.Event.Composite.Events.VMStart)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            case JDWP.EventKind.VM_DEATH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                return new VMDeathEventImpl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                      (JDWP.Event.Composite.Events.VMDeath)comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                // Ignore unknown event types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                System.err.println("Ignoring event cmd " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                                   evt.eventKind + " from the VM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    public VirtualMachine virtualMachine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        return vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    public int suspendPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return EventRequestManagerImpl.JDWPtoJDISuspendPolicy(suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    private ThreadReference eventThread() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   826
        for (Event event : this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            if (event instanceof ThreadedEventImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                return ((ThreadedEventImpl)event).thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    public void resume() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        switch (suspendPolicy()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            case EventRequest.SUSPEND_ALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                vm.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            case EventRequest.SUSPEND_EVENT_THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                ThreadReference thread = eventThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                if (thread == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    throw new InternalException("Inconsistent suspend policy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                thread.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            case EventRequest.SUSPEND_NONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                // Do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                throw new InternalException("Invalid suspend policy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public Iterator<Event> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        return new Itr();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public EventIterator eventIterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return new Itr();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public class Itr implements EventIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * Index of element to be returned by subsequent call to next.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        int cursor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            return cursor != size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        public Event next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                Event nxt = get(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                ++cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                return nxt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            } catch(IndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        public Event nextEvent() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   883
            return next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   891
    @Override
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   892
    public Spliterator<Event> spliterator() {
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   893
        return Spliterators.spliterator(this, Spliterator.DISTINCT);
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   894
    }
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   895
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    /* below make this unmodifiable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    public boolean add(Event o){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    public boolean remove(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    public boolean addAll(Collection<? extends Event> coll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    public boolean removeAll(Collection<?> coll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    public boolean retainAll(Collection<?> coll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
}