-
Notifications
You must be signed in to change notification settings - Fork 2
/
attr_code.go
71 lines (64 loc) · 1.56 KB
/
attr_code.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
63
64
65
66
67
68
69
70
71
package classfile
/*
方法属性表
*/
type CodeAttribute struct {
// 常量池指针
cp ConstantPool
// 最大栈
maxStack uint16
// 局部变量表大小
maxLocals uint16
/*
方法的内容编译后存放在code表中
method body after compile
内容就是iconst_0,istore_1等
*/
code []byte
// 受检查异常,对应了方法后面throw的部分
exceptionTable []*ExceptionTableEntry
// 属性表
attributes []AttributeInfo
}
/*
受检查异常结构
*/
type ExceptionTableEntry struct {
startPc uint16
endPc uint16
handlerPc uint16
catchType uint16
}
func (self *CodeAttribute) readInfo(reader *ClassReader) {
self.maxStack = reader.readUint16()
self.maxLocals = reader.readUint16()
codeLength := reader.readUint32()
self.code = reader.readBytes(codeLength)
self.exceptionTable = readExceptionTable(reader)
self.attributes = readAttributes(reader, self.cp)
}
func readExceptionTable(reader *ClassReader) []*ExceptionTableEntry {
exceptionTableLength := reader.readUint16()
exceptionTable := make([]*ExceptionTableEntry, exceptionTableLength)
for i := range exceptionTable {
exceptionTable[i] = &ExceptionTableEntry{
startPc: reader.readUint16(), endPc: reader.readUint16(), handlerPc: reader.readUint16(), catchType: reader.readUint16(),
}
}
return exceptionTable
}
/*
操作数栈最大大小
*/
func (self CodeAttribute) MaxStack() uint {
return uint(self.maxStack)
}
/*
局部变量表最大值
*/
func (self CodeAttribute) MaxLocals() uint {
return uint(self.maxLocals)
}
func (self CodeAttribute) Code() []byte {
return self.code
}