-
Notifications
You must be signed in to change notification settings - Fork 3
/
thread.go
62 lines (49 loc) · 1011 Bytes
/
thread.go
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
package rtda
import (
"jvm/pkg/logger"
"jvm/pkg/rtda/heap"
)
var log = logger.NewLogrusLogger()
type Thread struct {
// 程序计数器
pc int
// 栈帧
stack *Stack
}
func NewThread() *Thread {
return &Thread{
stack: NewStack(1024),
}
}
func (this *Thread) NewFrame(method *heap.Method) *Frame {
return &Frame{
localVars: NewLocalVars(method.MaxLocals()),
operandStack: NewOperandStack(method.MaxStack()),
method: method,
thread: this,
}
}
func (this *Thread) PC() int {
return this.pc
}
func (this *Thread) SetPC(newPc int) {
this.pc = newPc
}
func (this *Thread) PushFrame(frame *Frame) {
this.stack.push(frame)
}
func (this *Thread) PopFrame() *Frame {
return this.stack.pop()
}
func (this *Thread) TopFrame() *Frame {
return this.stack.top()
}
func (this *Thread) CurrentFrame() *Frame {
return this.stack.top()
}
func (this *Thread) IsStackEmpty() bool {
return this.stack.size == 0
}
func (this *Thread) StackSize() uint {
return this.stack.size
}