src/jdk.jdi/share/classes/com/sun/tools/jdi/VMState.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45714 jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/VMState.java@1820d351198d
child 52068 218b5b64f102
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    28
import java.lang.ref.WeakReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    29
import java.util.ArrayList;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    30
import java.util.Arrays;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    31
import java.util.Iterator;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    32
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    34
import com.sun.jdi.ThreadGroupReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    35
import com.sun.jdi.ThreadReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    36
import com.sun.jdi.VirtualMachine;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class VMState {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private final VirtualMachineImpl vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    // Listeners
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    42
    private final List<WeakReference<VMListener>> listeners = new ArrayList<>(); // synchronized (this)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private boolean notifyingListeners = false;  // synchronized (this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Certain information can be cached only when the entire VM is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * suspended and there are no pending resumes. The fields below
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * are used to track whether there are pending resumes. (There
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * is an assumption that JDWP command ids are increasing over time.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private int lastCompletedCommandId = 0;   // synchronized (this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private int lastResumeCommandId = 0;      // synchronized (this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // This is cached only while the VM is suspended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static class Cache {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        List<ThreadGroupReference> groups = null;  // cached Top Level ThreadGroups
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        List<ThreadReference> threads = null; // cached Threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Cache cache = null;               // synchronized (this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final Cache markerCache = new Cache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private void disableCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            cache = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private void enableCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            cache = markerCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private Cache getCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            if (cache == markerCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                cache = new Cache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            return cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    VMState(VirtualMachineImpl vm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this.vm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Is the VM currently suspended, for the purpose of caching?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Must be called synchronized on vm.state()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    boolean isSuspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return cache != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * A JDWP command has been completed (reply has been received).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Update data that tracks pending resume commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    synchronized void notifyCommandComplete(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        lastCompletedCommandId = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    synchronized void freeze() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (cache == null && (lastCompletedCommandId >= lastResumeCommandId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
             * No pending resumes to worry about. The VM is suspended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
             * and additional state can be cached. Notify all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
             * interested listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            processVMAction(new VMAction(vm, VMAction.VM_SUSPENDED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            enableCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    synchronized PacketStream thawCommand(CommandSender sender) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        PacketStream stream = sender.send();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        lastResumeCommandId = stream.id();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        thaw();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   124
     * All threads are resuming
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   126
    void thaw() {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   127
        thaw(null);
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   128
    }
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   129
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   130
    /**
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   131
     * Tell listeners to invalidate suspend-sensitive caches.
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   132
     * If resumingThread != null, then only that thread is being
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   133
     * resumed.
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   134
     */
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   135
    synchronized void thaw(ThreadReference resumingThread) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (cache != null) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   137
            if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                vm.printTrace("Clearing VM suspended cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            disableCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   142
        processVMAction(new VMAction(vm, resumingThread, VMAction.VM_NOT_SUSPENDED));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private synchronized void processVMAction(VMAction action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!notifyingListeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            // Prevent recursion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            notifyingListeners = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   150
            Iterator<WeakReference<VMListener>> iter = listeners.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            while (iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   152
                WeakReference<VMListener> ref = iter.next();
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   153
                VMListener listener = ref.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    boolean keep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    switch (action.id()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        case VMAction.VM_SUSPENDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                            keep = listener.vmSuspended(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        case VMAction.VM_NOT_SUSPENDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                            keep = listener.vmNotSuspended(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    if (!keep) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    // Listener is unreachable; clean up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            notifyingListeners = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    synchronized void addListener(VMListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        listeners.add(new WeakReference<VMListener>(listener));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    synchronized boolean hasListener(VMListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return listeners.contains(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    synchronized void removeListener(VMListener listener) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   186
        Iterator<WeakReference<VMListener>> iter = listeners.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        while (iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   188
            WeakReference<VMListener> ref = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (listener.equals(ref.get())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                iter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    List<ThreadReference> allThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        List<ThreadReference> threads = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            Cache local = getCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (local != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                // may be stale when returned, but not provably so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                threads = local.threads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (threads == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                threads = Arrays.asList((ThreadReference[])JDWP.VirtualMachine.AllThreads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                        process(vm).threads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (local != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    local.threads = threads;
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   210
                    if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        vm.printTrace("Caching all threads (count = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                      threads.size() + ") while VM suspended");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return threads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    List<ThreadGroupReference> topLevelThreadGroups() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        List<ThreadGroupReference> groups = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            Cache local = getCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (local != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                groups = local.groups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (groups == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                groups = Arrays.asList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                (ThreadGroupReference[])JDWP.VirtualMachine.TopLevelThreadGroups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                       process(vm).groups);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                if (local != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    local.groups = groups;
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   237
                    if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        vm.printTrace(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                          "Caching top level thread groups (count = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                          groups.size() + ") while VM suspended");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return groups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}