diff -r 56bcd6cdfc36 api.debugger.jpda/apichanges.xml --- a/api.debugger.jpda/apichanges.xml Thu May 29 16:35:41 2008 +0400 +++ b/api.debugger.jpda/apichanges.xml Fri May 30 16:23:27 2008 +0200 @@ -641,6 +641,53 @@ These are mainly class and thread filter + + + Enhance JPDA API with better thread control. + + + + + + This API change is necessary for the redesign of the debugger UI and + it's behavior with respect to threads. +

+ Added classes:
+ org.netbeans.api.debugger.jpda.DeadlockDetector, + org.netbeans.api.debugger.jpda.MonitorInfo, + org.netbeans.api.debugger.jpda.ThreadsCollector +

+

+ Added methods:
+ CallStackFrame.getFrameDepth(), + CallStackFrame.getOwnedMonitors(), + JPDADebugger.getAllThreads(), + JPDADebugger.getThreadsCollector(), + JPDADebugger.getDeadlockDetector(), + JPDAThread.getCurrentBreakpoint(), + JPDAThread.getContendedMonitorAndOwner(), + JPDAThread.getOwnedMonitorsAndFrames(), + EditorContext.annotate() with thread argument +

+

+ Added fields:
+ JPDADebugger.PROP_THREAD_STARTED, + JPDADebugger.PROP_THREAD_DIED, + JPDADebugger.PROP_THREAD_GROUP_ADDED, + JPDAThread.PROP_SUSPENDED, + JPDAThread.PROP_BREAKPOINT, + EditorContext.OTHER_THREAD_ANNOTATION_TYPE +

+
+ + + + + + + +
+ diff -r 56bcd6cdfc36 api.debugger.jpda/manifest.mf --- a/api.debugger.jpda/manifest.mf Thu May 29 16:35:41 2008 +0400 +++ b/api.debugger.jpda/manifest.mf Fri May 30 16:23:27 2008 +0200 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.debugger.jpda/2 OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/jpda/Bundle.properties -OpenIDE-Module-Specification-Version: 2.15 +OpenIDE-Module-Specification-Version: 2.16 OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager] diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/api/debugger/jpda/CallStackFrame.java --- a/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/CallStackFrame.java Thu May 29 16:35:41 2008 +0400 +++ b/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/CallStackFrame.java Fri May 30 16:23:27 2008 +0200 @@ -66,6 +66,13 @@ public interface CallStackFrame { * @return line number associated with this this stack frame */ public abstract int getLineNumber (String struts); + + /** + * Get the depth of this stack frame. + * @return The depth + * @since 2.16 + */ + public abstract int getFrameDepth(); /** * Returns the current operation (if any) at the location of this call stack frame. @@ -183,5 +190,13 @@ public interface CallStackFrame { * @return thread */ public abstract JPDAThread getThread (); + + /** + * Get the list of monitors aquired in this frame + * + * @return the list of monitors aquired in this frame + * @since 2.16 + */ + List getOwnedMonitors(); } \ No newline at end of file diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/api/debugger/jpda/DeadlockDetector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/DeadlockDetector.java Fri May 30 16:23:27 2008 +0200 @@ -0,0 +1,137 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.jpda; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.Collection; +import java.util.Set; + +/** + * Service that detects deadlocks and fires an event when the deadlock occurs. + * + *
+ * Since JDI interfaces evolve from one version to another, it's strongly recommended
+ * not to implement this abstract class in client code. New methods can be added to
+ * this class at any time to keep up with the JDI functionality.
+ * + * @author Martin Entlicher + * @since 2.16 + */ +public abstract class DeadlockDetector { + + /** + * Name of property which is fired when deadlock occurs. + */ + public static final String PROP_DEADLOCK = "deadlock"; // NOI18N + + private Set deadlocks; + private PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + /** + * Get the set of detected deadlocks. + * @return The set of deadlocks. + */ + public final synchronized Set getDeadlocks() { + return deadlocks; + } + + /** + * Used by overriding class to set the deadlocks when found. + * + * @param deadlocks The set of deadlocks. + */ + protected final void setDeadlocks(Set deadlocks) { + synchronized (this) { + this.deadlocks = deadlocks; + } + firePropertyChange(PROP_DEADLOCK, null, deadlocks); + } + + /** + * Utility method used by the implementing class to create deadlock instances. + * @param threads The threads in deadlock + * @return Deadlock instance + */ + protected final Deadlock createDeadlock(Collection threads) { + return new Deadlock(threads); + } + + private void firePropertyChange(String name, Object oldValue, Object newValue) { + pcs.firePropertyChange(name, oldValue, newValue); + } + + /** + * Add a PropertyChangeListener to this deadlock detector. + * @param l The listener + */ + public final void addPropertyChangeListener(PropertyChangeListener l) { + pcs.addPropertyChangeListener(l); + } + + /** + * Remove a PropertyChangeListener from this deadlock detector. + * @param l The listener + */ + public final void removePropertyChangeListener(PropertyChangeListener l) { + pcs.removePropertyChangeListener(l); + } + + /** + * Representation of a deadlock - one set of mutually deadlocked threads. + */ + public static final class Deadlock { + + private Collection threads; + + private Deadlock(Collection threads) { + this.threads = threads; + } + + /** + * Get the threads in deadlock. + * @return The threads in deadlock. + */ + public Collection getThreads() { + return threads; + } + } + +} diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDABreakpoint.java --- a/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDABreakpoint.java Thu May 29 16:35:41 2008 +0400 +++ b/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDABreakpoint.java Fri May 30 16:23:27 2008 +0200 @@ -80,7 +80,7 @@ public class JPDABreakpoint extends Brea /** Set of actions. */ private boolean enabled = true; private boolean hidden = false; - private int suspend = SUSPEND_ALL; + private int suspend = SUSPEND_EVENT_THREAD; private String printText; private Collection breakpointListeners = new HashSet(); diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java --- a/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java Thu May 29 16:35:41 2008 +0400 +++ b/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java Fri May 30 16:23:27 2008 +0200 @@ -88,6 +88,16 @@ public abstract class JPDADebugger { /** Property name constant. */ public static final String PROP_SUSPEND = "suspend"; // NOI18N + /** Property name constant. + * @since 2.16 */ + public static final String PROP_THREAD_STARTED = "threadStarted"; // NOI18N + /** Property name constant. + * @since 2.16 */ + public static final String PROP_THREAD_DIED = "threadDied"; // NOI18N + /** Property name constant. + * @since 2.16 */ + public static final String PROP_THREAD_GROUP_ADDED = "threadGroupAdded"; // NOI18N + /** Suspend property value constant. */ public static final int SUSPEND_ALL = EventRequest.SUSPEND_ALL; /** Suspend property value constant. */ @@ -315,6 +325,16 @@ public abstract class JPDADebugger { public abstract void setSuspend (int s); /** + * Returns all threads that exist in the debuggee. + * + * @return all threads + * @since 2.16 + */ + public List getAllThreads() { + return Collections.emptyList(); + } + + /** * Returns current thread or null. * * @return current thread or null @@ -491,5 +511,25 @@ public abstract class JPDADebugger { public long[] getInstanceCounts(List classTypes) throws UnsupportedOperationException { throw new UnsupportedOperationException("Not supported."); } + + /** + * Get the collector of threads. + * + * @return The threads collector + * @since 2.16 + */ + public ThreadsCollector getThreadsCollector() { + return null; + } + + /** + * Creates a deadlock detector. + * @return deadlock detector with automatic detection of deadlock among suspended threads + * @since 2.16 + * + public DeadlockDetector getDeadlockDetector() { + return new DeadlockDetector() {}; + } + */ } diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDAThread.java --- a/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDAThread.java Thu May 29 16:35:41 2008 +0400 +++ b/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDAThread.java Fri May 30 16:23:27 2008 +0200 @@ -76,10 +76,18 @@ public interface JPDAThread { /** Thread state constant. */ public static final int STATE_ZOMBIE = ThreadReference.THREAD_STATUS_ZOMBIE; + /** + * Suspended property of the thread. Fired when isSuspended() changes. + * @since 2.16 + */ + public static final String PROP_SUSPENDED = "suspended"; /** Property name constant. */ public static final String PROP_CALLSTACK = "callStack"; /** Property name constant. */ public static final String PROP_VARIABLES = "variables"; + /** Property name constant. + * @since 2.16 */ + public static final String PROP_BREAKPOINT = "currentBreakpoint"; @@ -114,6 +122,13 @@ public interface JPDAThread { * @see {@link CallStackFrame#getCurrentOperation} */ public abstract Operation getCurrentOperation(); + + /** + * Returns the current breakpoint hit by this thread. + * @return The current breakpoint, or null. + * @since 2.16 + */ + public abstract JPDABreakpoint getCurrentBreakpoint(); /** * Returns the list of the last operations, that were performed on this thread. @@ -237,9 +252,26 @@ public interface JPDAThread { public abstract ObjectVariable getContendedMonitor (); /** + * Returns monitor this thread is waiting on, with the information + * about the owner of the monitor. + * + * @return monitor this thread is waiting on, with the owner. + * @since 2.16 + */ + public abstract MonitorInfo getContendedMonitorAndOwner (); + + /** * Returns monitors owned by this thread. * * @return monitors owned by this thread */ public abstract ObjectVariable[] getOwnedMonitors (); + + /** + * Get the list of monitors with stack frame info owned by this thread. + * + * @return the list of monitors with stack frame info + * @since 2.16 + */ + List getOwnedMonitorsAndFrames(); } diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/api/debugger/jpda/MonitorInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/MonitorInfo.java Fri May 30 16:23:27 2008 +0200 @@ -0,0 +1,86 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.api.debugger.jpda; + +import com.sun.jdi.AbsentInformationException; +import java.beans.PropertyChangeListener; +import java.util.List; +import org.netbeans.spi.debugger.jpda.EditorContext.Operation; + + +/** + * Represents one owned monitor. + * + *
+ * Since JDI interfaces evolve from one version to another, it's strongly recommended
+ * not to implement this interface in client code. New methods can be added to
+ * this interface at any time to keep up with the JDI functionality.
+ * + * @author Martin Entlicher + * @since 2.16 + */ +public interface MonitorInfo { + + /** + * Returns the acquired monitor object + * + * @return monitor object + */ + ObjectVariable getMonitor(); + + /** + * Returns the frame at which this monitor was acquired by the owning thread. + * + * @return The frame, or null when the implementation cannot + * determine the stack frame (e.g., for monitors acquired by JNI). + */ + CallStackFrame getFrame(); + + /** + * Get the owning thread. + * + * @return the thread. + */ + JPDAThread getThread(); + +} + \ No newline at end of file diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/api/debugger/jpda/ThreadsCollector.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/ThreadsCollector.java Fri May 30 16:23:27 2008 +0200 @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.api.debugger.jpda; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.List; + +/** + * Collector of threads running inside the debuggee. + * Fires changes when threads change. + * + *
+ * Since JDI interfaces evolve from one version to another, it's strongly recommended
+ * not to implement this abstract class in client code. New methods can be added to
+ * this class at any time to keep up with the JDI functionality.
+ * + * @author Martin Entlicher + * @since 2.16 + */ +public abstract class ThreadsCollector { + + private final PropertyChangeSupport pch = new PropertyChangeSupport(this); + + /** Property name constant. */ + public static final String PROP_THREAD_STARTED = "threadStarted"; // NOI18N + /** Property name constant. */ + public static final String PROP_THREAD_DIED = "threadDied"; // NOI18N + /** Property name constant. */ + public static final String PROP_THREAD_GROUP_ADDED = "threadGroupAdded"; // NOI18N + + /** Property name constant. */ + public static final String PROP_THREAD_SUSPENDED = "threadSuspended"; // NOI18N + /** Property name constant. */ + public static final String PROP_THREAD_RESUMED = "threadResumed"; // NOI18N + + + /** + * Add a PropertyChangeListener to be notified about threads changes. + * @param l The listener + */ + public final void addPropertyChangeListener(PropertyChangeListener l) { + pch.addPropertyChangeListener(l); + } + + /** + * Remove a PropertyChangeListener. + * @param l The listener + */ + public final void removePropertyChangeListener(PropertyChangeListener l) { + pch.removePropertyChangeListener(l); + } + + protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + pch.firePropertyChange(propertyName, oldValue, newValue); + } + + /** + * Returns all threads that exist in the debuggee. + * + * @return all threads + */ + public abstract List getAllThreads(); + + /** + * Creates a deadlock detector. + * @return deadlock detector with automatic detection of deadlock among suspended threads + */ + public abstract DeadlockDetector getDeadlockDetector(); +} diff -r 56bcd6cdfc36 api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java --- a/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java Thu May 29 16:35:41 2008 +0400 +++ b/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java Fri May 30 16:23:27 2008 +0200 @@ -46,6 +46,7 @@ import java.util.Collections; import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.netbeans.api.debugger.jpda.JPDAThread; import org.netbeans.api.debugger.jpda.LineBreakpoint; import org.netbeans.api.debugger.jpda.LocalVariable; import org.netbeans.api.debugger.jpda.Variable; @@ -86,6 +87,9 @@ public abstract class EditorContext { public static final String CURRENT_EXPRESSION_SECONDARY_LINE_ANNOTATION_TYPE = "CurrentExpression"; /** Annotation type constant. */ public static final String CURRENT_EXPRESSION_CURRENT_LINE_ANNOTATION_TYPE = "CurrentExpressionLine"; + /** Annotation type constant. + * @since 2.16 */ + public static final String OTHER_THREAD_ANNOTATION_TYPE = "OtherThread"; /** Property name constant. */ public static final String PROP_LINE_NUMBER = "lineNumber"; @@ -143,6 +147,29 @@ public abstract class EditorContext { String annotationType, Object timeStamp ); + + /** + * Adds annotation to given url on given line. + * + * @param url a url of source annotation should be set into + * @param lineNumber a number of line annotation should be set into + * @param annotationType a type of annotation to be set + * @param timeStamp a time stamp to be used + * @param thread the thread to annotate + * + * @return annotation or null, when the annotation can not be + * created at the given URL or line number. + * @since 2.16 + */ + public Object annotate ( + String url, + int lineNumber, + String annotationType, + Object timeStamp, + JPDAThread thread + ) { + return null; + } /** * Adds annotation to given url on given character range.