Repository navigation
Expand file tree
/
Copy pathExecutionThread.java
More file actions
118 lines (104 loc) · 4.21 KB
/
Copy pathExecutionThread.java
File metadata and controls
118 lines (104 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
*
* Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
* that is described in this document. In particular, and without limitation, these intellectual property
* rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
* more additional patents or pending patent applications in the U.S. and in other countries.
*
* U.S. Government Rights - Commercial software. Government users are subject to the Sun
* Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
* supplements.
*
* Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
* registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
* are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
* U.S. and other countries.
*
* UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
* Company, Ltd.
*/
package com.sun.max.tele.interpreter;
import java.io.*;
import com.sun.max.vm.actor.holder.*;
import com.sun.max.vm.actor.member.*;
/**
* Instances of this class contain the execution state of a single thread in the system.
* NOTE: currently there _is_ only one thread. Please ignore the man behind the curtain.
*
* @author Athul Acharya
*/
class ExecutionThread {
/**
* The maximum frame depth for a thread.
*/
public static final int STACK_SIZE = 1000;
private ExecutionFrame frame;
//private int _prio;
//private ThreadType _threadType;
public ExecutionThread(int prio, ThreadType threadType) {
//_prio = prio;
//_threadType = threadType;
frame = null;
}
public ExecutionFrame pushFrame(ClassMethodActor method) {
this.frame = new ExecutionFrame(frame, method);
if (frame.depth() > STACK_SIZE) {
throw new StackOverflowError();
}
return frame;
}
public ExecutionFrame popFrame() {
frame = frame.callersFrame();
return frame;
}
public ExecutionFrame frame() {
return frame;
}
public static enum ThreadType {
NORMAL_THREAD,
VM_THREAD,
}
/**
* Handles an exception at the current execution point in this thread by updating the call stack and instruction
* pointer to a matching exception handler in this thread's current call stack. If no matching exception handler is
* found for the current execution point and the given exception type, then the call stack and instruction pointer
* in this thread are left unmodified.
*
* @param throwableClassActor
* @return {@code true} if an exception handler was found, {@code false} otherwise
*/
public boolean handleException(ClassActor throwableClassActor) {
ExecutionFrame frame = this.frame;
while (frame != null) {
if (frame.handleException(throwableClassActor)) {
this.frame = frame;
return true;
}
frame = frame.callersFrame();
}
return false;
}
public void printStackTrace(PrintStream printStream, TeleInterpreterException executionException) {
ExecutionFrame frame = this.frame;
printStream.println(executionException.getMessage());
while (frame != null) {
printStream.println("\tat " + frame.method().toStackTraceElement(frame.currentOpcodePosition()));
frame = frame.callersFrame();
}
if (executionException.getCause() != null) {
printStream.print("Caused by: ");
executionException.getCause().printStackTrace(printStream);
}
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder(getClass().getSimpleName());
ExecutionFrame frame = this.frame;
while (frame != null) {
sb.append(String.format("%n%s [bci:%d]", frame.method().toStackTraceElement(frame.currentOpcodePosition())));
frame = frame.callersFrame();
}
return sb.toString();
}
}