History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/com/sun/tools/example/debug/bdi/JDIEventSource.java (1 of 18352 files). Show all

Unified · Split

java/pkg/com/sun/tools/example/debug/bdi/JDIEventSource.java+184−0
@@ -0,0 +1,184 @@
1/*
2 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.tools.example.debug.bdi;
27
28import com.sun.jdi.*;
29import com.sun.jdi.event.*;
30
31import com.sun.tools.example.debug.event.*;
32
33import javax.swing.SwingUtilities;
34
35/**
36 */
37class JDIEventSource extends Thread {
38
39 private /*final*/ EventQueue queue;
40 private /*final*/ Session session;
41 private /*final*/ ExecutionManager runtime;
42 private final JDIListener firstListener = new FirstListener();
43
44 private boolean wantInterrupt; //### Hack
45
46 /**
47 * Create event source.
48 */
49 JDIEventSource(Session session) {
50 super("JDI Event Set Dispatcher");
51 this.session = session;
52 this.runtime = session.runtime;
53 this.queue = session.vm.eventQueue();
54 }
55
56 @Override
57 public void run() {
58 try {
59 runLoop();
60 } catch (Exception exc) {
61 //### Do something different for InterruptedException???
62 // just exit
63 }
64 session.running = false;
65 }
66
67 private void runLoop() throws InterruptedException {
68 AbstractEventSet es;
69 do {
70 EventSet jdiEventSet = queue.remove();
71 es = AbstractEventSet.toSpecificEventSet(jdiEventSet);
72 session.interrupted = es.suspendedAll();
73 dispatchEventSet(es);
74 } while(!(es instanceof VMDisconnectEventSet));
75 }
76
77 //### Gross foul hackery!
78 private void dispatchEventSet(final AbstractEventSet es) {
79 SwingUtilities.invokeLater(new Runnable() {
80 @Override
81 public void run() {
82 boolean interrupted = es.suspendedAll();
83 es.notify(firstListener);
84 boolean wantInterrupt = JDIEventSource.this.wantInterrupt;
85 for (JDIListener jl : session.runtime.jdiListeners) {
86 es.notify(jl);
87 }
88 if (interrupted && !wantInterrupt) {
89 session.interrupted = false;
90 //### Catch here is a hack
91 try {
92 session.vm.resume();
93 } catch (VMDisconnectedException ee) {}
94 }
95 if (es instanceof ThreadDeathEventSet) {
96 ThreadReference t = ((ThreadDeathEventSet)es).getThread();
97 session.runtime.removeThreadInfo(t);
98 }
99 }
100 });
101 }
102
103 private void finalizeEventSet(AbstractEventSet es) {
104 if (session.interrupted && !wantInterrupt) {
105 session.interrupted = false;
106 //### Catch here is a hack
107 try {
108 session.vm.resume();
109 } catch (VMDisconnectedException ee) {}
110 }
111 if (es instanceof ThreadDeathEventSet) {
112 ThreadReference t = ((ThreadDeathEventSet)es).getThread();
113 session.runtime.removeThreadInfo(t);
114 }
115 }
116
117 //### This is a Hack, deal with it
118 private class FirstListener implements JDIListener {
119
120 @Override
121 public void accessWatchpoint(AccessWatchpointEventSet e) {
122 session.runtime.validateThreadInfo();
123 wantInterrupt = true;
124 }
125
126 @Override
127 public void classPrepare(ClassPrepareEventSet e) {
128 wantInterrupt = false;
129 runtime.resolve(e.getReferenceType());
130 }
131
132 @Override
133 public void classUnload(ClassUnloadEventSet e) {
134 wantInterrupt = false;
135 }
136
137 @Override
138 public void exception(ExceptionEventSet e) {
139 wantInterrupt = true;
140 }
141
142 @Override
143 public void locationTrigger(LocationTriggerEventSet e) {
144 session.runtime.validateThreadInfo();
145 wantInterrupt = true;
146 }
147
148 @Override
149 public void modificationWatchpoint(ModificationWatchpointEventSet e) {
150 session.runtime.validateThreadInfo();
151 wantInterrupt = true;
152 }
153
154 @Override
155 public void threadDeath(ThreadDeathEventSet e) {
156 wantInterrupt = false;
157 }
158
159 @Override
160 public void threadStart(ThreadStartEventSet e) {
161 wantInterrupt = false;
162 }
163
164 @Override
165 public void vmDeath(VMDeathEventSet e) {
166 //### Should have some way to notify user
167 //### that VM died before the session ended.
168 wantInterrupt = false;
169 }
170
171 @Override
172 public void vmDisconnect(VMDisconnectEventSet e) {
173 //### Notify user?
174 wantInterrupt = false;
175 session.runtime.endSession();
176 }
177
178 @Override
179 public void vmStart(VMStartEventSet e) {
180 //### Do we need to do anything with it?
181 wantInterrupt = false;
182 }
183 }
184}