jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpecList.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 51 6fe31bc95bbc
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 51
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.example.debug.bdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
class EventRequestSpecList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    // all specs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private List<EventRequestSpec> eventRequestSpecs = Collections.synchronizedList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                                                  new ArrayList<EventRequestSpec>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    final ExecutionManager runtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    EventRequestSpecList(ExecutionManager runtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        this.runtime = runtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Resolve all deferred eventRequests waiting for 'refType'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    void resolve(ReferenceType refType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        synchronized(eventRequestSpecs) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    50
            for (EventRequestSpec spec : eventRequestSpecs) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    51
                spec.attemptResolve(refType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    void install(EventRequestSpec ers, VirtualMachine vm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        synchronized (eventRequestSpecs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            eventRequestSpecs.add(ers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        if (vm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            ers.attemptImmediateResolve(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    BreakpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    createClassLineBreakpoint(String classPattern, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return new LineBreakpointSpec(this, refSpec, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    BreakpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    createSourceLineBreakpoint(String sourceName, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            new SourceNameReferenceTypeSpec(sourceName, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return new LineBreakpointSpec(this, refSpec, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    BreakpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    createMethodBreakpoint(String classPattern,
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    81
                           String methodId, List<String> methodArgs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return new MethodBreakpointSpec(this, refSpec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                        methodId, methodArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    ExceptionSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    createExceptionIntercept(String classPattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                             boolean notifyCaught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                             boolean notifyUncaught) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return new ExceptionSpec(this, refSpec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                 notifyCaught, notifyUncaught);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    AccessWatchpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    createAccessWatchpoint(String classPattern, String fieldId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return new AccessWatchpointSpec(this, refSpec, fieldId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    ModificationWatchpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    createModificationWatchpoint(String classPattern, String fieldId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return new ModificationWatchpointSpec(this, refSpec, fieldId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    void delete(EventRequestSpec ers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        EventRequest request = ers.getEventRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        synchronized (eventRequestSpecs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            eventRequestSpecs.remove(ers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (request != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            request.virtualMachine().eventRequestManager()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                .deleteEventRequest(request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        notifyDeleted(ers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        //### notify delete - here?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    List<EventRequestSpec> eventRequestSpecs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // We need to make a copy to avoid synchronization problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        synchronized (eventRequestSpecs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return new ArrayList<EventRequestSpec>(eventRequestSpecs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // --------  notify routines --------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   134
    @SuppressWarnings("unchecked")
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   135
    private Vector<SpecListener> specListeners() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   136
        return (Vector<SpecListener>)runtime.specListeners.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    void notifySet(EventRequestSpec spec) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   140
        Vector<SpecListener> l = specListeners();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        SpecEvent evt = new SpecEvent(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (int i = 0; i < l.size(); i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   143
            spec.notifySet(l.elementAt(i), evt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    void notifyDeferred(EventRequestSpec spec) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   148
        Vector<SpecListener> l = specListeners();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        SpecEvent evt = new SpecEvent(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        for (int i = 0; i < l.size(); i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   151
            spec.notifyDeferred(l.elementAt(i), evt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    void notifyDeleted(EventRequestSpec spec) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   156
        Vector<SpecListener> l = specListeners();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        SpecEvent evt = new SpecEvent(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        for (int i = 0; i < l.size(); i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   159
            spec.notifyDeleted(l.elementAt(i), evt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    void notifyResolved(EventRequestSpec spec) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   164
        Vector<SpecListener> l = specListeners();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        SpecEvent evt = new SpecEvent(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        for (int i = 0; i < l.size(); i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   167
            spec.notifyResolved(l.elementAt(i), evt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    void notifyError(EventRequestSpec spec, Exception exc) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   172
        Vector<SpecListener> l = specListeners();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        SpecErrorEvent evt = new SpecErrorEvent(spec, exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        for (int i = 0; i < l.size(); i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   175
            spec.notifyError(l.elementAt(i), evt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}