Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 464dc61

Browse filesBrowse files
author
hborders
committed
Added all files from com.sun.max.tele.interpreter package in Maxine VM.
Should have added all these initially.
1 parent 5fc9d80 commit 464dc61
Copy full SHA for 464dc61

6 files changed

+915Lines changed: 915 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+181Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
* Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3+
*
4+
* Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5+
* that is described in this document. In particular, and without limitation, these intellectual property
6+
* rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7+
* more additional patents or pending patent applications in the U.S. and in other countries.
8+
*
9+
* U.S. Government Rights - Commercial software. Government users are subject to the Sun
10+
* Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11+
* supplements.
12+
*
13+
* Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14+
* registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15+
* are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16+
* U.S. and other countries.
17+
*
18+
* UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19+
* Company, Ltd.
20+
*/
21+
package com.sun.max.tele.interpreter;
22+
23+
import java.util.*;
24+
25+
import com.sun.max.vm.actor.holder.*;
26+
import com.sun.max.vm.actor.member.*;
27+
import com.sun.max.vm.classfile.*;
28+
import com.sun.max.vm.classfile.constant.*;
29+
import com.sun.max.vm.value.*;
30+
31+
/**
32+
* Instances of this class represent individual execution frame entries on a given ExecutionThread's execution stack.
33+
*
34+
* @author Athul Acharya
35+
*/
36+
class ExecutionFrame {
37+
38+
private final ClassMethodActor method;
39+
private int currentOpcodePosition;
40+
private int currentBytePosition;
41+
private final Value[] locals;
42+
private final Stack<Value> operands;
43+
private final ExecutionFrame callersFrame;
44+
private final byte[] code;
45+
private final int depth;
46+
47+
public ExecutionFrame(ExecutionFrame callersFrame, ClassMethodActor method) {
48+
this.method = method;
49+
this.locals = new Value[method.codeAttribute().maxLocals];
50+
this.operands = new Stack<Value>();
51+
this.callersFrame = callersFrame;
52+
this.code = method.codeAttribute().code();
53+
this.depth = callersFrame == null ? 1 : callersFrame.depth + 1;
54+
}
55+
56+
/**
57+
* Computes the number of frames on the call stack up to and including this frame.
58+
*/
59+
public int depth() {
60+
return depth;
61+
}
62+
63+
public ExecutionFrame callersFrame() {
64+
return callersFrame;
65+
}
66+
67+
public void setLocal(int index, Value value) {
68+
locals[index] = value;
69+
}
70+
71+
public int readOpcode() {
72+
currentOpcodePosition = currentBytePosition;
73+
return readByte() & 0xff;
74+
}
75+
76+
public byte readByte() {
77+
try {
78+
return code[currentBytePosition++];
79+
} catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
80+
throw new VerifyError("Ran off end of code");
81+
}
82+
}
83+
84+
public short readShort() {
85+
final int high = readByte();
86+
final int low = readByte() & 0xff;
87+
return (short) ((high << 8) | low);
88+
}
89+
90+
public int readInt() {
91+
final int b3 = readByte() << 24;
92+
final int b2 = (readByte() & 0xff) << 16;
93+
final int b1 = (readByte() & 0xff) << 8;
94+
final int b0 = readByte() & 0xff;
95+
return b3 | b2 | b1 | b0;
96+
}
97+
98+
public void skipBytes(int n) {
99+
currentBytePosition += n;
100+
}
101+
102+
public void alignInstructionPosition() {
103+
final int remainder = currentBytePosition % 4;
104+
if (remainder != 0) {
105+
currentBytePosition += 4 - remainder;
106+
}
107+
}
108+
109+
public void jump(int offset) {
110+
currentBytePosition = currentOpcodePosition + offset;
111+
}
112+
113+
public int currentOpcodePosition() {
114+
return currentOpcodePosition;
115+
}
116+
117+
public int currentBytePosition() {
118+
return currentBytePosition;
119+
}
120+
121+
public void setBytecodePosition(int bcp) {
122+
currentBytePosition = bcp;
123+
}
124+
125+
public byte[] code() {
126+
return code;
127+
}
128+
129+
public Value getLocal(int index) {
130+
return locals[index];
131+
}
132+
133+
public Stack<Value> stack() {
134+
return operands;
135+
}
136+
137+
public ConstantPool constantPool() {
138+
return method.codeAttribute().constantPool;
139+
}
140+
141+
public ClassMethodActor method() {
142+
return method;
143+
}
144+
145+
@Override
146+
public String toString() {
147+
return method.format("%H.%n(%p) @ " + currentBytePosition);
148+
}
149+
150+
/**
151+
* Handles an exception at the current execution point in this frame by updating the {@linkplain #setBytecodePosition(int)
152+
* instruction pointer} to the matching exception handler in this frame. If no matching exception handler is found
153+
* for the current execution point and the given exception type, then the instruction pointer in this frame is left
154+
* unmodified.
155+
* <p>
156+
* The current execution point is derived from the value of {@link ExecutionFrame#currentBytePosition()} which is now at the first
157+
* byte passed the instruction currently being executed. That is, an instruction is completely decoded before any
158+
* exceptions are thrown while executing it.
159+
*
160+
* @param throwableClassActor the type of the exception being thrown
161+
* @return {@code true} if an exception handler was found, {@code false} otherwise
162+
*/
163+
public boolean handleException(ClassActor throwableClassActor) {
164+
final int bcp = currentOpcodePosition;
165+
final ExceptionHandlerEntry[] handlers = method().codeAttribute().exceptionHandlerTable();
166+
for (ExceptionHandlerEntry handler : handlers) {
167+
if (bcp >= handler.startPosition() && bcp < handler.endPosition()) {
168+
if (handler.catchTypeIndex() == 0) {
169+
currentBytePosition = handler.handlerPosition();
170+
return true;
171+
}
172+
final ClassActor catchType = constantPool().classAt(handler.catchTypeIndex()).resolve(constantPool(), handler.catchTypeIndex());
173+
if (catchType.isAssignableFrom(throwableClassActor)) {
174+
currentBytePosition = handler.handlerPosition();
175+
return true;
176+
}
177+
}
178+
}
179+
return false;
180+
}
181+
}
Collapse file
+118Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3+
*
4+
* Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5+
* that is described in this document. In particular, and without limitation, these intellectual property
6+
* rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7+
* more additional patents or pending patent applications in the U.S. and in other countries.
8+
*
9+
* U.S. Government Rights - Commercial software. Government users are subject to the Sun
10+
* Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11+
* supplements.
12+
*
13+
* Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14+
* registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15+
* are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16+
* U.S. and other countries.
17+
*
18+
* UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19+
* Company, Ltd.
20+
*/
21+
package com.sun.max.tele.interpreter;
22+
23+
import java.io.*;
24+
25+
import com.sun.max.vm.actor.holder.*;
26+
import com.sun.max.vm.actor.member.*;
27+
28+
/**
29+
* Instances of this class contain the execution state of a single thread in the system.
30+
* NOTE: currently there _is_ only one thread. Please ignore the man behind the curtain.
31+
*
32+
* @author Athul Acharya
33+
*/
34+
class ExecutionThread {
35+
36+
/**
37+
* The maximum frame depth for a thread.
38+
*/
39+
public static final int STACK_SIZE = 1000;
40+
41+
private ExecutionFrame frame;
42+
//private int _prio;
43+
//private ThreadType _threadType;
44+
45+
public ExecutionThread(int prio, ThreadType threadType) {
46+
//_prio = prio;
47+
//_threadType = threadType;
48+
frame = null;
49+
}
50+
51+
public ExecutionFrame pushFrame(ClassMethodActor method) {
52+
this.frame = new ExecutionFrame(frame, method);
53+
if (frame.depth() > STACK_SIZE) {
54+
throw new StackOverflowError();
55+
}
56+
return frame;
57+
}
58+
59+
public ExecutionFrame popFrame() {
60+
frame = frame.callersFrame();
61+
return frame;
62+
}
63+
64+
public ExecutionFrame frame() {
65+
return frame;
66+
}
67+
68+
public static enum ThreadType {
69+
NORMAL_THREAD,
70+
VM_THREAD,
71+
}
72+
73+
/**
74+
* Handles an exception at the current execution point in this thread by updating the call stack and instruction
75+
* pointer to a matching exception handler in this thread's current call stack. If no matching exception handler is
76+
* found for the current execution point and the given exception type, then the call stack and instruction pointer
77+
* in this thread are left unmodified.
78+
*
79+
* @param throwableClassActor
80+
* @return {@code true} if an exception handler was found, {@code false} otherwise
81+
*/
82+
public boolean handleException(ClassActor throwableClassActor) {
83+
ExecutionFrame frame = this.frame;
84+
while (frame != null) {
85+
if (frame.handleException(throwableClassActor)) {
86+
this.frame = frame;
87+
return true;
88+
}
89+
90+
frame = frame.callersFrame();
91+
}
92+
return false;
93+
}
94+
95+
public void printStackTrace(PrintStream printStream, TeleInterpreterException executionException) {
96+
ExecutionFrame frame = this.frame;
97+
printStream.println(executionException.getMessage());
98+
while (frame != null) {
99+
printStream.println("\tat " + frame.method().toStackTraceElement(frame.currentOpcodePosition()));
100+
frame = frame.callersFrame();
101+
}
102+
if (executionException.getCause() != null) {
103+
printStream.print("Caused by: ");
104+
executionException.getCause().printStackTrace(printStream);
105+
}
106+
}
107+
108+
@Override
109+
public String toString() {
110+
final StringBuilder sb = new StringBuilder(getClass().getSimpleName());
111+
ExecutionFrame frame = this.frame;
112+
while (frame != null) {
113+
sb.append(String.format("%n%s [bci:%d]", frame.method().toStackTraceElement(frame.currentOpcodePosition())));
114+
frame = frame.callersFrame();
115+
}
116+
return sb.toString();
117+
}
118+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.