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

Unified · Split

java/pkg/com/sun/tools/jdi/ThreadGroupReferenceImpl.java+149−0
@@ -0,0 +1,149 @@
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
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 for (ThreadReference thread : threads()) {
90 thread.suspend();
91 }
92
93 for (ThreadGroupReference threadGroup : threadGroups()) {
94 threadGroup.suspend();
95 }
96 }
97
98 public void resume() {
99 for (ThreadReference thread : threads()) {
100 thread.resume();
101 }
102
103 for (ThreadGroupReference threadGroup : threadGroups()) {
104 threadGroup.resume();
105 }
106 }
107
108 private JDWP.ThreadGroupReference.Children kids() {
109 JDWP.ThreadGroupReference.Children kids = null;
110 try {
111 Cache local = (Cache)getCache();
112
113 if (local != null) {
114 kids = local.kids;
115 }
116 if (kids == null) {
117 kids = JDWP.ThreadGroupReference.Children
118 .process(vm, this);
119 if (local != null) {
120 local.kids = kids;
121 if ((vm.traceFlags & vm.TRACE_OBJREFS) != 0) {
122 vm.printTrace(description() +
123 " temporarily caching children ");
124 }
125 }
126 }
127 } catch (JDWPException exc) {
128 throw exc.toJDIException();
129 }
130 return kids;
131 }
132
133 public List<ThreadReference> threads() {
134 return Arrays.asList((ThreadReference[])kids().childThreads);
135 }
136
137 public List<ThreadGroupReference> threadGroups() {
138 return Arrays.asList((ThreadGroupReference[])kids().childGroups);
139 }
140
141 public String toString() {
142 return "instance of " + referenceType().name() +
143 "(name='" + name() + "', " + "id=" + uniqueID() + ")";
144 }
145
146 byte typeValueKey() {
147 return JDWP.Tag.THREAD_GROUP;
148 }
149}