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