jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExecutionManager.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.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.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jdi.connect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.example.debug.expr.ExpressionParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.example.debug.expr.ParseException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.example.debug.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.SwingUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Move this towards being only state and functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * that spans across Sessions (and thus VMs).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class ExecutionManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private Session session;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Get/set JDI trace mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    int traceMode = VirtualMachine.TRACE_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  //////////////////    Listener registration    //////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  // Session Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    Vector<SessionListener> sessionListeners = new Vector<SessionListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public void addSessionListener(SessionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        sessionListeners.add(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public void removeSessionListener(SessionListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        sessionListeners.remove(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  // Spec Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  Vector<SpecListener> specListeners = new Vector<SpecListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public void addSpecListener(SpecListener cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        specListeners.add(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public void removeSpecListener(SpecListener cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        specListeners.remove(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // JDI Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    Vector<JDIListener> jdiListeners = new Vector<JDIListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Adds a JDIListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void addJDIListener(JDIListener jl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        jdiListeners.add(jl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Adds a JDIListener - at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public void addJDIListener(int index, JDIListener jl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        jdiListeners.add(index, jl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Removes a JDIListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void removeJDIListener(JDIListener jl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        jdiListeners.remove(jl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  // App Echo Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private Vector<OutputListener> appEchoListeners = new Vector<OutputListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public void addApplicationEchoListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        appEchoListeners.addElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void removeApplicationEchoListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        appEchoListeners.removeElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  // App Output Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private Vector<OutputListener> appOutputListeners = new Vector<OutputListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void addApplicationOutputListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        appOutputListeners.addElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void removeApplicationOutputListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        appOutputListeners.removeElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  // App Error Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private Vector<OutputListener> appErrorListeners = new Vector<OutputListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void addApplicationErrorListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        appErrorListeners.addElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void removeApplicationErrorListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        appErrorListeners.removeElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
  // Diagnostic Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private Vector<OutputListener> diagnosticsListeners = new Vector<OutputListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public void addDiagnosticsListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        diagnosticsListeners.addElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void removeDiagnosticsListener(OutputListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        diagnosticsListeners.removeElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  ///////////    End Listener Registration    //////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    //### We probably don't want this public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public VirtualMachine vm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return session == null ? null : session.vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    void ensureActiveSession() throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (session == null) throw new NoSessionException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public EventRequestManager eventRequestManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return vm() == null ? null : vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Get JDI trace mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public int getTraceMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return traceMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Set JDI trace mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void setTraceMode(int mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        traceMode = mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (session != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            session.setTraceMode(mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Determine if VM is interrupted, i.e, present and not running.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public boolean isInterrupted() /* should: throws NoSessionException */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
//      ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return session.interrupted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Return a list of ReferenceType objects for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * currently loaded classes and interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Array types are not returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public List<ReferenceType> allClasses() throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return vm().allClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Return a ReferenceType object for the currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * loaded class or interface whose fully-qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * class name is specified, else return null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * is none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * In general, we must return a list of types, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * multiple class loaders could have loaded a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * with the same fully-qualified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public List<ReferenceType> findClassesByName(String name) throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return vm().classesByName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Return a list of ReferenceType objects for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * currently loaded classes and interfaces whose name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * matches the given pattern.  The pattern syntax is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * open to some future revision, but currently consists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * of a fully-qualified class name in which the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * component may optionally be a "*" character, designating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * an arbitrary prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public List<ReferenceType> findClassesMatchingPattern(String pattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                                throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        List<ReferenceType> result = new ArrayList<ReferenceType>();  //### Is default size OK?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (pattern.startsWith("*.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // Wildcard matches any leading package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            pattern = pattern.substring(1);
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   235
            for (ReferenceType type : vm().allClasses()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (type.name().endsWith(pattern)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    result.add(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            // It's a class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return vm().classesByName(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Return a list of ThreadReference objects corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * to the threads that are currently active in the VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * A thread is removed from the list just before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * thread terminates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public List<ThreadReference> allThreads() throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return vm().allThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Return a list of ThreadGroupReference objects corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * to the top-level threadgroups that are currently active in the VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Note that a thread group may be empty, or contain no threads as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * descendents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public List<ThreadGroupReference> topLevelThreadGroups() throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return vm().topLevelThreadGroups();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Return the system threadgroup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public ThreadGroupReference systemThreadGroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                                throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        ensureActiveSession();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   278
        return vm().topLevelThreadGroups().get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Evaluate an expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public Value evaluate(final StackFrame f, String expr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        throws ParseException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                            InvocationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                            InvalidTypeException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                            ClassNotLoadedException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                            NoSessionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                            IncompatibleThreadStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        ExpressionParser.GetFrame frameGetter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            frameGetter = new ExpressionParser.GetFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                public StackFrame get() /* throws IncompatibleThreadStateException */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return ExpressionParser.evaluate(expr, vm(), frameGetter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Start a new VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public void run(boolean suspended,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    String vmArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    String args) throws VMLaunchFailureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        endSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        //### Set a breakpoint on 'main' method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        //### Would be cleaner if we could just bring up VM already suspended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (suspended) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            //### Set breakpoint at 'main(java.lang.String[])'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            List<String> argList = new ArrayList<String>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            argList.add("java.lang.String[]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            createMethodBreakpoint(className, "main", argList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        String cmdLine = className + " " + args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        startSession(new ChildSession(this, vmArgs, cmdLine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                      appInput, appOutput, appError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                      diagnostics));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Attach to an existing VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public void attach(String portName) throws VMLaunchFailureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        endSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        //### Changes made here for connectors have broken the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        //### the 'Session' abstraction.  The 'Session.attach()'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        //### method is intended to encapsulate all of the various
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        //### ways in which session start-up can fail. (maddox 12/18/98)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * Now that attaches and launches both go through Connectors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * it may be worth creating a new subclass of Session for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * attach sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        VirtualMachineManager mgr = Bootstrap.virtualMachineManager();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   349
        AttachingConnector connector = mgr.attachingConnectors().get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        Map<String, Connector.Argument> arguments = connector.defaultArguments();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   351
        arguments.get("port").setValue(portName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        Session newSession = internalAttach(connector, arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (newSession != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            startSession(newSession);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private Session internalAttach(AttachingConnector connector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                   Map<String, Connector.Argument> arguments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            VirtualMachine vm = connector.attach(arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            return new Session(vm, this, diagnostics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            diagnostics.putString("\n Unable to attach to target VM: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                  ioe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } catch (IllegalConnectorArgumentsException icae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            diagnostics.putString("\n Invalid connector arguments: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                  icae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private Session internalListen(ListeningConnector connector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                   Map<String, Connector.Argument> arguments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            VirtualMachine vm = connector.accept(arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return new Session(vm, this, diagnostics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            diagnostics.putString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                  "\n Unable to accept connection to target VM: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                  ioe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        } catch (IllegalConnectorArgumentsException icae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            diagnostics.putString("\n Invalid connector arguments: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                  icae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Connect via user specified arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @return true on success
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public boolean explictStart(Connector connector, Map<String, Connector.Argument> arguments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                           throws VMLaunchFailureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        Session newSession = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        endSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (connector instanceof LaunchingConnector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            // we were launched, use ChildSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            newSession = new ChildSession(this, (LaunchingConnector)connector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                          arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                          appInput, appOutput, appError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                          diagnostics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        } else if (connector instanceof AttachingConnector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            newSession = internalAttach((AttachingConnector)connector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                                        arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        } else if (connector instanceof ListeningConnector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            newSession = internalListen((ListeningConnector)connector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                        arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            diagnostics.putString("\n Unknown connector: " + connector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (newSession != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            startSession(newSession);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return newSession != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Detach from VM.  If VM was started by debugger, terminate it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public void detach() throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        endSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    private void startSession(Session s) throws VMLaunchFailureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (!s.attach()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            throw new VMLaunchFailureException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        session = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        EventRequestManager em = vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        ClassPrepareRequest classPrepareRequest = em.createClassPrepareRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        //### We must allow the deferred breakpoints to be resolved before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        //### we continue executing the class.  We could optimize if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        //### were no deferred breakpoints outstanding for a particular class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        //### Can we do this with JDI?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        classPrepareRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        classPrepareRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        ClassUnloadRequest classUnloadRequest = em.createClassUnloadRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        classUnloadRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        classUnloadRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        ThreadStartRequest threadStartRequest = em.createThreadStartRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        threadStartRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        threadStartRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        ThreadDeathRequest threadDeathRequest = em.createThreadDeathRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        threadDeathRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        threadDeathRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        ExceptionRequest exceptionRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                em.createExceptionRequest(null, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        exceptionRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        validateThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        session.interrupted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        notifySessionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    void endSession() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (session != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            session.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            session = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            invalidateThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            notifySessionDeath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Suspend all VM activity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public void interrupt() throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        vm().suspend();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        //### Is it guaranteed that the interrupt has happened?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        validateThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        session.interrupted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        notifyInterrupted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Resume interrupted VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public void go() throws NoSessionException, VMNotInterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        invalidateThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        session.interrupted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        notifyContinued();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        vm().resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Stepping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    void clearPreviousStep(ThreadReference thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
         * A previous step may not have completed on this thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         * if so, it gets removed here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         EventRequestManager mgr = vm().eventRequestManager();
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   503
         for (StepRequest request : mgr.stepRequests()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
             if (request.thread().equals(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                 mgr.deleteEventRequest(request);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                 break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    private void generalStep(ThreadReference thread, int size, int depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        invalidateThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        session.interrupted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        notifyContinued();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        clearPreviousStep(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        EventRequestManager reqMgr = vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        StepRequest request = reqMgr.createStepRequest(thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                                       size, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        // We want just the next step event and no others
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        request.addCountFilter(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        request.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        vm().resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public void stepIntoInstruction(ThreadReference thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                        throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public void stepOverInstruction(ThreadReference thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                        throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public void stepIntoLine(ThreadReference thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        throws NoSessionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                        AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        generalStep(thread, StepRequest.STEP_LINE, StepRequest.STEP_INTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    public void stepOverLine(ThreadReference thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        throws NoSessionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                        AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        generalStep(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
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 void stepOut(ThreadReference thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Thread control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public void suspendThread(ThreadReference thread) throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        thread.suspend();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public void resumeThread(ThreadReference thread) throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        thread.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    public void stopThread(ThreadReference thread) throws NoSessionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        ensureActiveSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        //### Need an exception now.  Which one to use?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        //thread.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * ThreadInfo objects -- Allow query of thread status and stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    private List<ThreadInfo> threadInfoList = new LinkedList<ThreadInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    //### Should be weak! (in the value, not the key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    private HashMap<ThreadReference, ThreadInfo> threadInfoMap = new HashMap<ThreadReference, ThreadInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    public ThreadInfo threadInfo(ThreadReference thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (session == null || thread == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   587
        ThreadInfo info = threadInfoMap.get(thread);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        if (info == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            //### Should not hardcode initial frame count and prefetch here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            //info = new ThreadInfo(thread, 10, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            info = new ThreadInfo(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            if (session.interrupted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                info.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            threadInfoList.add(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            threadInfoMap.put(thread, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     void validateThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        session.interrupted = true;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   603
        for (ThreadInfo threadInfo : threadInfoList) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   604
            threadInfo.validate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    private void invalidateThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (session != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            session.interrupted = false;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   611
            for (ThreadInfo threadInfo : threadInfoList) {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   612
                threadInfo.invalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    void removeThreadInfo(ThreadReference thread) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   618
        ThreadInfo info = threadInfoMap.get(thread);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            info.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            threadInfoMap.remove(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            threadInfoList.remove(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Listen for Session control events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    private void notifyInterrupted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        Vector l = (Vector)sessionListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        EventObject evt = new EventObject(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            ((SessionListener)l.elementAt(i)).sessionInterrupt(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    private void notifyContinued() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        Vector l = (Vector)sessionListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        EventObject evt = new EventObject(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            ((SessionListener)l.elementAt(i)).sessionContinue(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    private void notifySessionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        Vector l = (Vector)sessionListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        EventObject evt = new EventObject(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            ((SessionListener)l.elementAt(i)).sessionStart(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    private void notifySessionDeath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
/*** noop for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        Vector l = (Vector)sessionListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        EventObject evt = new EventObject(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            ((SessionListener)l.elementAt(i)).sessionDeath(evt);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Listen for input and output requests from the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * being debugged.  These are generated only when the debuggee
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * is spawned as a child of the debugger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private Object inputLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    private LinkedList<String> inputBuffer = new LinkedList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    private void resetInputBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        synchronized (inputLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            inputBuffer = new LinkedList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    public void sendLineToApplication(String line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        synchronized (inputLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            inputBuffer.addFirst(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            inputLock.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    private InputListener appInput = new InputListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        public String getLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            // Don't allow reader to be interrupted -- catch and retry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            String line = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            while (line == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                synchronized (inputLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        while (inputBuffer.size() < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                            inputLock.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   696
                        line = inputBuffer.removeLast();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    } catch (InterruptedException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            // We must not be holding inputLock here, as the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            // that we call to echo a line might call us re-entrantly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            // to provide another line of input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            // Run in Swing event dispatcher thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            final String input = line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            SwingUtilities.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    echoInputLine(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            return line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    private static String newline = System.getProperty("line.separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    private void echoInputLine(String line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        Vector l = (Vector)appEchoListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            OutputListener ol = (OutputListener)l.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            ol.putString(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            ol.putString(newline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    private OutputListener appOutput = new OutputListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        public void putString(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            Vector l = (Vector)appOutputListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                ((OutputListener)l.elementAt(i)).putString(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    private OutputListener appError = new OutputListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        public void putString(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            Vector l = (Vector)appErrorListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                ((OutputListener)l.elementAt(i)).putString(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
   private OutputListener diagnostics = new OutputListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        public void putString(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            Vector l = (Vector)diagnosticsListeners.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            for (int i = 0; i < l.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                ((OutputListener)l.elementAt(i)).putString(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
   };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
  /////////////    Spec Request Creation/Deletion/Query   ///////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    private EventRequestSpecList specList = new EventRequestSpecList(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    public BreakpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    createSourceLineBreakpoint(String sourceName, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        return specList.createSourceLineBreakpoint(sourceName, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    public BreakpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    createClassLineBreakpoint(String classPattern, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        return specList.createClassLineBreakpoint(classPattern, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public BreakpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    createMethodBreakpoint(String classPattern,
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   768
                           String methodId, List<String> methodArgs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        return specList.createMethodBreakpoint(classPattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                                                 methodId, methodArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    public ExceptionSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    createExceptionIntercept(String classPattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                             boolean notifyCaught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                             boolean notifyUncaught) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        return specList.createExceptionIntercept(classPattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                                   notifyCaught,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                                                   notifyUncaught);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public AccessWatchpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    createAccessWatchpoint(String classPattern, String fieldId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        return specList.createAccessWatchpoint(classPattern, fieldId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    public ModificationWatchpointSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    createModificationWatchpoint(String classPattern, String fieldId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        return specList.createModificationWatchpoint(classPattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                                                       fieldId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    public void delete(EventRequestSpec spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        specList.delete(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    void resolve(ReferenceType refType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        specList.resolve(refType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    public void install(EventRequestSpec spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        specList.install(spec, vm());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   805
    public List<EventRequestSpec> eventRequestSpecs() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        return specList.eventRequestSpecs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
}