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/tty/EventRequestSpecList.java (1 of 18352 files). Show all

Unified · Split

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