0N/A/*
2362N/A * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.jdi;
0N/A
0N/Aimport com.sun.jdi.*;
0N/Aimport java.util.*;
0N/A
0N/Apublic class ThreadGroupReferenceImpl extends ObjectReferenceImpl
0N/A implements ThreadGroupReference, VMListener
0N/A{
0N/A // Cached components that cannot change
0N/A String name;
0N/A ThreadGroupReference parent;
0N/A boolean triedParent;
0N/A
0N/A // This is cached only while the VM is suspended
0N/A private static class Cache extends ObjectReferenceImpl.Cache {
0N/A JDWP.ThreadGroupReference.Children kids = null;
0N/A }
0N/A
0N/A protected ObjectReferenceImpl.Cache newCache() {
0N/A return new Cache();
0N/A }
0N/A
0N/A ThreadGroupReferenceImpl(VirtualMachine aVm,long aRef) {
0N/A super(aVm,aRef);
0N/A vm.state().addListener(this);
0N/A }
0N/A
0N/A protected String description() {
0N/A return "ThreadGroupReference " + uniqueID();
0N/A }
0N/A
0N/A public String name() {
0N/A if (name == null) {
0N/A // Does not need synchronization, since worst-case
0N/A // static info is fetched twice (Thread group name
0N/A // cannot change)
0N/A try {
0N/A name = JDWP.ThreadGroupReference.Name.
0N/A process(vm, this).groupName;
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A return name;
0N/A }
0N/A
0N/A public ThreadGroupReference parent() {
0N/A if (!triedParent) {
0N/A // Does not need synchronization, since worst-case
0N/A // static info is fetched twice (Thread group parent cannot
0N/A // change)
0N/A try {
0N/A parent = JDWP.ThreadGroupReference.Parent.
0N/A process(vm, this).parentGroup;
0N/A triedParent = true;
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A return parent;
0N/A }
0N/A
0N/A public void suspend() {
28N/A for (ThreadReference thread : threads()) {
28N/A thread.suspend();
0N/A }
0N/A
28N/A for (ThreadGroupReference threadGroup : threadGroups()) {
28N/A threadGroup.suspend();
0N/A }
0N/A }
0N/A
0N/A public void resume() {
28N/A for (ThreadReference thread : threads()) {
28N/A thread.resume();
0N/A }
0N/A
28N/A for (ThreadGroupReference threadGroup : threadGroups()) {
28N/A threadGroup.resume();
0N/A }
0N/A }
0N/A
0N/A private JDWP.ThreadGroupReference.Children kids() {
0N/A JDWP.ThreadGroupReference.Children kids = null;
0N/A try {
0N/A Cache local = (Cache)getCache();
0N/A
0N/A if (local != null) {
0N/A kids = local.kids;
0N/A }
0N/A if (kids == null) {
0N/A kids = JDWP.ThreadGroupReference.Children
0N/A .process(vm, this);
0N/A if (local != null) {
0N/A local.kids = kids;
0N/A if ((vm.traceFlags & vm.TRACE_OBJREFS) != 0) {
0N/A vm.printTrace(description() +
0N/A " temporarily caching children ");
0N/A }
0N/A }
0N/A }
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A return kids;
0N/A }
0N/A
0N/A public List<ThreadReference> threads() {
0N/A return Arrays.asList((ThreadReference[])kids().childThreads);
0N/A }
0N/A
0N/A public List<ThreadGroupReference> threadGroups() {
0N/A return Arrays.asList((ThreadGroupReference[])kids().childGroups);
0N/A }
0N/A
0N/A public String toString() {
0N/A return "instance of " + referenceType().name() +
0N/A "(name='" + name() + "', " + "id=" + uniqueID() + ")";
0N/A }
0N/A
0N/A byte typeValueKey() {
0N/A return JDWP.Tag.THREAD_GROUP;
0N/A }
0N/A}