blob: 4e1286ba2e4a515b05d4e1c64dc6a225826cdf46 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-1999 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.tools.jdi;
27
28import com.sun.jdi.*;
29import java.util.*;
30
31public class ThreadGroupReferenceImpl extends ObjectReferenceImpl
32 implements ThreadGroupReference, VMListener
33{
34 // Cached components that cannot change
35 String name;
36 ThreadGroupReference parent;
37 boolean triedParent;
38
39 // This is cached only while the VM is suspended
40 private static class Cache extends ObjectReferenceImpl.Cache {
41 JDWP.ThreadGroupReference.Children kids = null;
42 }
43
44 protected ObjectReferenceImpl.Cache newCache() {
45 return new Cache();
46 }
47
48 ThreadGroupReferenceImpl(VirtualMachine aVm,long aRef) {
49 super(aVm,aRef);
50 vm.state().addListener(this);
51 }
52
53 protected String description() {
54 return "ThreadGroupReference " + uniqueID();
55 }
56
57 public String name() {
58 if (name == null) {
59 // Does not need synchronization, since worst-case
60 // static info is fetched twice (Thread group name
61 // cannot change)
62 try {
63 name = JDWP.ThreadGroupReference.Name.
64 process(vm, this).groupName;
65 } catch (JDWPException exc) {
66 throw exc.toJDIException();
67 }
68 }
69 return name;
70 }
71
72 public ThreadGroupReference parent() {
73 if (!triedParent) {
74 // Does not need synchronization, since worst-case
75 // static info is fetched twice (Thread group parent cannot
76 // change)
77 try {
78 parent = JDWP.ThreadGroupReference.Parent.
79 process(vm, this).parentGroup;
80 triedParent = true;
81 } catch (JDWPException exc) {
82 throw exc.toJDIException();
83 }
84 }
85 return parent;
86 }
87
88 public void suspend() {
89 List threads = threads();
90 Iterator iter = threads.iterator();
91 while (iter.hasNext()) {
92 ((ThreadReference)iter.next()).suspend();
93 }
94
95 List groups = threadGroups();
96 iter = groups.iterator();
97 while (iter.hasNext()) {
98 ((ThreadGroupReference)iter.next()).suspend();
99 }
100 }
101
102 public void resume() {
103 List threads = threads();
104 Iterator iter = threads.iterator();
105 while (iter.hasNext()) {
106 ((ThreadReference)iter.next()).resume();
107 }
108
109 List groups = threadGroups();
110 iter = groups.iterator();
111 while (iter.hasNext()) {
112 ((ThreadGroupReference)iter.next()).resume();
113 }
114 }
115
116 private JDWP.ThreadGroupReference.Children kids() {
117 JDWP.ThreadGroupReference.Children kids = null;
118 try {
119 Cache local = (Cache)getCache();
120
121 if (local != null) {
122 kids = local.kids;
123 }
124 if (kids == null) {
125 kids = JDWP.ThreadGroupReference.Children
126 .process(vm, this);
127 if (local != null) {
128 local.kids = kids;
129 if ((vm.traceFlags & vm.TRACE_OBJREFS) != 0) {
130 vm.printTrace(description() +
131 " temporarily caching children ");
132 }
133 }
134 }
135 } catch (JDWPException exc) {
136 throw exc.toJDIException();
137 }
138 return kids;
139 }
140
141 public List<ThreadReference> threads() {
142 return Arrays.asList((ThreadReference[])kids().childThreads);
143 }
144
145 public List<ThreadGroupReference> threadGroups() {
146 return Arrays.asList((ThreadGroupReference[])kids().childGroups);
147 }
148
149 public String toString() {
150 return "instance of " + referenceType().name() +
151 "(name='" + name() + "', " + "id=" + uniqueID() + ")";
152 }
153
154 byte typeValueKey() {
155 return JDWP.Tag.THREAD_GROUP;
156 }
157}