jdk/src/share/classes/com/sun/tools/example/debug/tty/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 1998-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.tty;
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.EventRequest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jdi.event.ClassPrepareEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class EventRequestSpecList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final int statusResolved = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final int statusUnresolved = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final int statusError = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // all specs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private List<EventRequestSpec> eventRequestSpecs = Collections.synchronizedList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                                                  new ArrayList<EventRequestSpec>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    EventRequestSpecList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Resolve all deferred eventRequests waiting for 'refType'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @return true if it completes successfully, false on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    boolean resolve(ClassPrepareEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        boolean failure = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        synchronized(eventRequestSpecs) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    58
            for (EventRequestSpec spec : eventRequestSpecs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                if (!spec.isResolved()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                        EventRequest eventRequest = spec.resolve(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                        if (eventRequest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                            MessageOutput.println("Set deferred", spec.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                        MessageOutput.println("Unable to set deferred",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                              new Object [] {spec.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                                             spec.errorMessageFor(e)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                        failure = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return !failure;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    void resolveAll() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    78
        for (EventRequestSpec spec : eventRequestSpecs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                EventRequest eventRequest = spec.resolveEagerly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                if (eventRequest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    MessageOutput.println("Set deferred", spec.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    boolean addEagerlyResolve(EventRequestSpec spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            eventRequestSpecs.add(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            EventRequest eventRequest = spec.resolveEagerly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (eventRequest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                MessageOutput.println("Set", spec.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            MessageOutput.println("Unable to set",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                  new Object [] {spec.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                                 spec.errorMessageFor(exc)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   105
    BreakpointSpec createBreakpoint(String classPattern, int line)
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   106
        throws ClassNotFoundException {
2
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 BreakpointSpec(refSpec, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   112
    BreakpointSpec createBreakpoint(String classPattern,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                 String methodId,
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   114
                                    List<String> methodArgs)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                throws MalformedMemberNameException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                       ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return new BreakpointSpec(refSpec, methodId, methodArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    EventRequestSpec createExceptionCatch(String classPattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                          boolean notifyCaught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                          boolean notifyUncaught)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                            throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return new ExceptionSpec(refSpec, notifyCaught, notifyUncaught);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   131
    WatchpointSpec createAccessWatchpoint(String classPattern,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                       String fieldId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                      throws MalformedMemberNameException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                             ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return new AccessWatchpointSpec(refSpec, fieldId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   140
    WatchpointSpec createModificationWatchpoint(String classPattern,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                       String fieldId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                      throws MalformedMemberNameException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                             ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        ReferenceTypeSpec refSpec =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            new PatternReferenceTypeSpec(classPattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return new ModificationWatchpointSpec(refSpec, fieldId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    boolean delete(EventRequestSpec proto) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        synchronized (eventRequestSpecs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            int inx = eventRequestSpecs.indexOf(proto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            if (inx != -1) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   153
                EventRequestSpec spec = eventRequestSpecs.get(inx);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                spec.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                eventRequestSpecs.remove(inx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
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
    List<EventRequestSpec> eventRequestSpecs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
       // We need to make a copy to avoid synchronization problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        synchronized (eventRequestSpecs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            return new ArrayList<EventRequestSpec>(eventRequestSpecs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}