Showing the changes to java/pkg/com/sun/tools/example/debug/bdi/ThreadInfo.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,117 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2002, 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 | |||
| 26 | package com.sun.tools.example.debug.bdi; | ||
| 27 | |||
| 28 | import com.sun.jdi.*; | ||
| 29 | |||
| 30 | //### Should handle target VM death or connection failure cleanly. | ||
| 31 | |||
| 32 | public class ThreadInfo { | ||
| 33 | |||
| 34 | private ThreadReference thread; | ||
| 35 | private int status; | ||
| 36 | |||
| 37 | private int frameCount; | ||
| 38 | |||
| 39 | Object userObject; // User-supplied annotation. | ||
| 40 | |||
| 41 | private boolean interrupted = false; | ||
| 42 | |||
| 43 | private void assureInterrupted() throws VMNotInterruptedException { | ||
| 44 | if (!interrupted) { | ||
| 45 | throw new VMNotInterruptedException(); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | ThreadInfo (ThreadReference thread) { | ||
| 50 | this.thread = thread; | ||
| 51 | this.frameCount = -1; | ||
| 52 | } | ||
| 53 | |||
| 54 | public ThreadReference thread() { | ||
| 55 | return thread; | ||
| 56 | } | ||
| 57 | |||
| 58 | public int getStatus() throws VMNotInterruptedException { | ||
| 59 | assureInterrupted(); | ||
| 60 | update(); | ||
| 61 | return status; | ||
| 62 | } | ||
| 63 | |||
| 64 | public int getFrameCount() throws VMNotInterruptedException { | ||
| 65 | assureInterrupted(); | ||
| 66 | update(); | ||
| 67 | return frameCount; | ||
| 68 | } | ||
| 69 | |||
| 70 | public StackFrame getFrame(int index) throws VMNotInterruptedException { | ||
| 71 | assureInterrupted(); | ||
| 72 | update(); | ||
| 73 | try { | ||
| 74 | return thread.frame(index); | ||
| 75 | } catch (IncompatibleThreadStateException e) { | ||
| 76 | // Should not happen | ||
| 77 | interrupted = false; | ||
| 78 | throw new VMNotInterruptedException(); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | public Object getUserObject() { | ||
| 83 | return userObject; | ||
| 84 | } | ||
| 85 | |||
| 86 | public void setUserObject(Object obj) { | ||
| 87 | userObject = obj; | ||
| 88 | } | ||
| 89 | |||
| 90 | // Refresh upon first access after cache is cleared. | ||
| 91 | |||
| 92 | void update() throws VMNotInterruptedException { | ||
| 93 | if (frameCount == -1) { | ||
| 94 | try { | ||
| 95 | status = thread.status(); | ||
| 96 | frameCount = thread.frameCount(); | ||
| 97 | } catch (IncompatibleThreadStateException e) { | ||
| 98 | // Should not happen | ||
| 99 | interrupted = false; | ||
| 100 | throw new VMNotInterruptedException(); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | // Called from 'ExecutionManager'. | ||
| 106 | |||
| 107 | void validate() { | ||
| 108 | interrupted = true; | ||
| 109 | } | ||
| 110 | |||
| 111 | void invalidate() { | ||
| 112 | interrupted = false; | ||
| 113 | frameCount = -1; | ||
| 114 | status = ThreadReference.THREAD_STATUS_UNKNOWN; | ||
| 115 | } | ||
| 116 | |||
| 117 | } | ||