|
Java example source code file (StackFrameImpl.java)
The StackFrameImpl.java Java example source code
/*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.jdi;
import com.sun.jdi.*;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Collections;
public class StackFrameImpl extends MirrorImpl
implements StackFrame, ThreadListener
{
/* Once false, frame should not be used.
* access synchronized on (vm.state())
*/
private boolean isValid = true;
private final ThreadReferenceImpl thread;
private final long id;
private final Location location;
private Map<String, LocalVariable> visibleVariables = null;
private ObjectReference thisObject = null;
StackFrameImpl(VirtualMachine vm, ThreadReferenceImpl thread,
long id, Location location) {
super(vm);
this.thread = thread;
this.id = id;
this.location = location;
thread.addListener(this);
}
/*
* ThreadListener implementation
* Must be synchronized since we must protect against
* sending defunct (isValid == false) stack ids to the back-end.
*/
public boolean threadResumable(ThreadAction action) {
synchronized (vm.state()) {
if (isValid) {
isValid = false;
return false; /* remove this stack frame as a listener */
} else {
throw new InternalException(
"Invalid stack frame thread listener");
}
}
}
void validateStackFrame() {
if (!isValid) {
throw new InvalidStackFrameException("Thread has been resumed");
}
}
/**
* Return the frame location.
* Need not be synchronized since it cannot be provably stale.
*/
public Location location() {
validateStackFrame();
return location;
}
/**
* Return the thread holding the frame.
* Need not be synchronized since it cannot be provably stale.
*/
public ThreadReference thread() {
validateStackFrame();
return thread;
}
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof StackFrameImpl)) {
StackFrameImpl other = (StackFrameImpl)obj;
return (id == other.id) &&
(thread().equals(other.thread())) &&
(location().equals(other.location())) &&
super.equals(obj);
} else {
return false;
}
}
public int hashCode() {
return (thread().hashCode() << 4) + ((int)id);
}
public ObjectReference thisObject() {
validateStackFrame();
MethodImpl currentMethod = (MethodImpl)location.method();
if (currentMethod.isStatic() || currentMethod.isNative()) {
return null;
} else {
if (thisObject == null) {
PacketStream ps;
/* protect against defunct frame id */
synchronized (vm.state()) {
validateStackFrame();
ps = JDWP.StackFrame.ThisObject.
enqueueCommand(vm, thread, id);
}
/* actually get it, now that order is guaranteed */
try {
thisObject = JDWP.StackFrame.ThisObject.
waitForReply(vm, ps).objectThis;
} catch (JDWPException exc) {
switch (exc.errorCode()) {
case JDWP.Error.INVALID_FRAMEID:
case JDWP.Error.THREAD_NOT_SUSPENDED:
case JDWP.Error.INVALID_THREAD:
throw new InvalidStackFrameException();
default:
throw exc.toJDIException();
}
}
}
}
return thisObject;
}
/**
* Build the visible variable map.
* Need not be synchronized since it cannot be provably stale.
*/
private void createVisibleVariables() throws AbsentInformationException {
if (visibleVariables == null) {
List<LocalVariable> allVariables = location.method().variables();
Map<String, LocalVariable> map = new HashMap
Other Java examples (source code examples)Here is a short list of links related to this Java StackFrameImpl.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.