heap

package
v0.0.0-...-2ded9d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACC_PUBLIC       = 0x0001 // class field method
	ACC_PRIVATE      = 0x0002 //       field method
	ACC_PROTECTED    = 0x0004 //       field method
	ACC_STATIC       = 0x0008 //       field method
	ACC_FINAL        = 0x0010 // class field method
	ACC_SUPER        = 0x0020 // class
	ACC_SYNCHRONIZED = 0x0020 //             method
	ACC_VOLATILE     = 0x0040 //       field
	ACC_BRIDGE       = 0x0040 //             method
	ACC_TRANSIENT    = 0x0080 //       field
	ACC_VARARGS      = 0x0080 //             method
	ACC_NATIVE       = 0x0100 //             method
	ACC_INTERFACE    = 0x0200 // class
	ACC_ABSTRACT     = 0x0400 // class       method
	ACC_STRICT       = 0x0800 //             method
	ACC_SYNTHETIC    = 0x1000 // class field method
	ACC_ANNOTATION   = 0x2000 // class
	ACC_ENUM         = 0x4000 // class field
)

Variables

This section is empty.

Functions

func ArrayCopy

func ArrayCopy(src, dest *Object, srcPos, dstPos, length int32)

func GoString

func GoString(jStr *Object) string

java.lang.String -> go string

Types

type Class

type Class struct {

	//实例变量(及private String name)占据的空间大小
	InstanceSlotCount uint
	// contains filtered or unexported fields
}

*

我们需要注意一下JVM中的class
我们这里的class,是运行时常量池里的class

我们的java.lang.Class 继承 java.lang.Object
java.lang.Object.class 又需要有一个 java.lang.Class(java.lang.Object.class 是存放在堆内存中的,相当于java.lang.Class的实例)
那么问题来了,是现有的java.lang.Object还是先有的java.lang.Class

这种问题,非常类似于spring解决set方式的循环依赖,都是通过在“混沌态”的时候解决问题。
JVM也是这样的,在这两个class在运行时常量池中还没完全初始化的时候,暴露出引用,来解决这个问题,这样我们就有了java世界里最最基础的两个class

*

func (*Class) ArrayClass

func (self *Class) ArrayClass() *Class

func (*Class) ComponentClass

func (self *Class) ComponentClass() *Class

func (*Class) ConstantPool

func (self *Class) ConstantPool() *ConstantPool

getters start

func (*Class) Fields

func (self *Class) Fields() []*Field

func (*Class) GetClinitMethod

func (self *Class) GetClinitMethod() *Method

func (*Class) GetInstanceMethod

func (self *Class) GetInstanceMethod(name, descriptor string) *Method

func (*Class) GetMainMethod

func (self *Class) GetMainMethod() *Method

func (*Class) GetPackageName

func (self *Class) GetPackageName() string

func (*Class) GetRefVar

func (self *Class) GetRefVar(fieldName, fieldDescriptor string) *Object

func (*Class) InitStarted

func (self *Class) InitStarted() bool

func (*Class) IsAbstract

func (self *Class) IsAbstract() bool

func (*Class) IsAnnotation

func (self *Class) IsAnnotation() bool

func (*Class) IsArray

func (self *Class) IsArray() bool

func (*Class) IsAssignableFrom

func (self *Class) IsAssignableFrom(other *Class) bool

*

一个类是否是可以看成是另外一个

func (*Class) IsEnum

func (self *Class) IsEnum() bool

func (*Class) IsFinal

func (self *Class) IsFinal() bool

func (*Class) IsImplements

func (self *Class) IsImplements(iface *Class) bool

self implements iface

func (*Class) IsInterface

func (self *Class) IsInterface() bool

func (*Class) IsPrimitive

func (self *Class) IsPrimitive() bool

* 是否是基本类型

func (*Class) IsPublic

func (self *Class) IsPublic() bool

func (*Class) IsSubClassOf

func (self *Class) IsSubClassOf(other *Class) bool

self extends other

func (*Class) IsSuper

func (self *Class) IsSuper() bool

func (*Class) IsSuperClassOf

func (self *Class) IsSuperClassOf(other *Class) bool

other extends self

func (*Class) IsSynthetic

func (self *Class) IsSynthetic() bool

func (*Class) JClass

func (self *Class) JClass() *Object

func (*Class) JavaName

func (self *Class) JavaName() string

func (*Class) Loader

func (self *Class) Loader() *ClassLoader

func (*Class) Methods

func (self *Class) Methods() []*Method

func (*Class) Name

func (self *Class) Name() string

func (*Class) NewArray

func (self *Class) NewArray(count uint) *Object

func (*Class) NewObject

func (self *Class) NewObject() *Object

func (*Class) SetRefVar

func (self *Class) SetRefVar(fieldName, fieldDescriptor string, ref *Object)

func (*Class) SourceFile

func (self *Class) SourceFile() string

func (*Class) StartInit

func (self *Class) StartInit()

func (*Class) StaticVars

func (self *Class) StaticVars() Slots

func (*Class) SuperClass

func (self *Class) SuperClass() *Class

type ClassLoader

type ClassLoader struct {
	// contains filtered or unexported fields
}

func NewClassLoader

func NewClassLoader(cp *classpath.Classpath, verboseFlag bool) *ClassLoader

func (*ClassLoader) LoadClass

func (self *ClassLoader) LoadClass(name string) *Class

type ClassMember

type ClassMember struct {
	// contains filtered or unexported fields
}

*

存放字段和方法公有的信息

func (*ClassMember) Class

func (self *ClassMember) Class() *Class

func (*ClassMember) Descriptor

func (self *ClassMember) Descriptor() string

func (*ClassMember) IsFinal

func (self *ClassMember) IsFinal() bool

func (*ClassMember) IsPrivate

func (self *ClassMember) IsPrivate() bool

func (*ClassMember) IsProtected

func (self *ClassMember) IsProtected() bool

func (*ClassMember) IsPublic

func (self *ClassMember) IsPublic() bool

func (*ClassMember) IsStatic

func (self *ClassMember) IsStatic() bool

func (*ClassMember) IsSynthetic

func (self *ClassMember) IsSynthetic() bool

func (*ClassMember) Name

func (self *ClassMember) Name() string

getters

type ClassRef

type ClassRef struct {
	SymRef
}

type Constant

type Constant interface {
}

能存放任何类型

type ConstantPool

type ConstantPool struct {
	// contains filtered or unexported fields
}

func (*ConstantPool) GetConstant

func (self *ConstantPool) GetConstant(index uint) Constant

*

根据索引返回常量

type ExceptionHandler

type ExceptionHandler struct {
	// contains filtered or unexported fields
}

*

异常处理器

type ExceptionTable

type ExceptionTable []*ExceptionHandler

type Field

type Field struct {
	//继承自ClassMember,字段和方法都属于类的成员
	ClassMember
	// contains filtered or unexported fields
}

func (*Field) ConstValueIndex

func (self *Field) ConstValueIndex() uint

func (*Field) SlotId

func (self *Field) SlotId() uint

type FieldRef

type FieldRef struct {
	MemberRef
	// contains filtered or unexported fields
}

func (*FieldRef) ResolvedField

func (self *FieldRef) ResolvedField() *Field

*

解析字段

type InterfaceMethodRef

type InterfaceMethodRef struct {
	MemberRef
	// contains filtered or unexported fields
}

func (*InterfaceMethodRef) ResolvedInterfaceMethod

func (self *InterfaceMethodRef) ResolvedInterfaceMethod() *Method

type MemberRef

type MemberRef struct {
	SymRef
	// contains filtered or unexported fields
}

*

存放字段和方法符号引用公有的信息

func (*MemberRef) Descriptor

func (self *MemberRef) Descriptor() string

func (*MemberRef) Name

func (self *MemberRef) Name() string

type Method

type Method struct {
	//继承自ClassMember,字段和方法都属于类的成员
	ClassMember
	// contains filtered or unexported fields
}

func LookupMethodInClass

func LookupMethodInClass(class *Class, name, descriptor string) *Method

*

从父类中找方法

func (*Method) ArgSlotCount

func (self *Method) ArgSlotCount() uint

func (*Method) Code

func (self *Method) Code() []byte

func (*Method) FindExceptionHandler

func (self *Method) FindExceptionHandler(exClass *Class, pc int) int

*

从方法的异常表中找异常处理器

func (*Method) GetLineNumber

func (self *Method) GetLineNumber(pc int) int

*

方法没有行号表,返回-1
本地方法没有字节码,返回-2

func (*Method) IsAbstract

func (self *Method) IsAbstract() bool

func (*Method) IsBridge

func (self *Method) IsBridge() bool

func (*Method) IsNative

func (self *Method) IsNative() bool

func (*Method) IsStrict

func (self *Method) IsStrict() bool

func (*Method) IsSynchronized

func (self *Method) IsSynchronized() bool

func (*Method) IsVarargs

func (self *Method) IsVarargs() bool

func (*Method) MaxLocals

func (method *Method) MaxLocals() uint

func (*Method) MaxStack

func (method *Method) MaxStack() uint

type MethodDescriptor

type MethodDescriptor struct {
	// contains filtered or unexported fields
}

type MethodDescriptorParser

type MethodDescriptorParser struct {
	// contains filtered or unexported fields
}

type MethodRef

type MethodRef struct {
	MemberRef
	// contains filtered or unexported fields
}

func (*MethodRef) ResolvedMethod

func (self *MethodRef) ResolvedMethod() *Method

type Object

type Object struct {
	// contains filtered or unexported fields
}

func InternString

func InternString(str *Object) *Object

*

intern方法

func JString

func JString(loader *ClassLoader, goStr string) *Object

func (*Object) ArrayLength

func (self *Object) ArrayLength() int32

*

数组长度

func (*Object) Bytes

func (self *Object) Bytes() []int8

*

将使用int8型来标识boolean类型

func (*Object) Chars

func (self *Object) Chars() []uint16

func (*Object) Class

func (self *Object) Class() *Class

func (*Object) Clone

func (self *Object) Clone() *Object

func (*Object) Doubles

func (self *Object) Doubles() []float64

func (*Object) Extra

func (self *Object) Extra() interface{}

func (*Object) Fields

func (self *Object) Fields() Slots

getter start

func (*Object) Floats

func (self *Object) Floats() []float32

func (*Object) GetRefVar

func (self *Object) GetRefVar(name, descriptor string) *Object

*

获取一个对象中的某个字段的值

func (*Object) Ints

func (self *Object) Ints() []int32

func (*Object) IsInstanceOf

func (self *Object) IsInstanceOf(class *Class) bool

func (*Object) Longs

func (self *Object) Longs() []int64

func (*Object) Refs

func (self *Object) Refs() []*Object

func (*Object) SetExtra

func (self *Object) SetExtra(extra interface{})

func (*Object) SetRefVar

func (self *Object) SetRefVar(name, descriptor string, ref *Object)

reflection

func (*Object) Shorts

func (self *Object) Shorts() []int16

type Slot

type Slot struct {
	//虚拟机规范要求每个元素至少可以容纳一个int或引用,这里存放int,下面ref存放引用
	//连续两个Slot可以存放double、long
	Num int32
	//引用
	Ref *Object
}

type Slots

type Slots []Slot

func NewSlots

func NewSlots(slotCount uint) Slots

func (Slots) GetDouble

func (self Slots) GetDouble(index uint) float64

func (Slots) GetFloat

func (self Slots) GetFloat(index uint) float32

func (Slots) GetInt

func (self Slots) GetInt(index uint) int32

func (Slots) GetLong

func (self Slots) GetLong(index uint) int64

func (Slots) GetRef

func (self Slots) GetRef(index uint) *Object

func (Slots) SetDouble

func (self Slots) SetDouble(index uint, val float64)

double consumes two slots

func (Slots) SetFloat

func (self Slots) SetFloat(index uint, val float32)

func (Slots) SetInt

func (self Slots) SetInt(index uint, val int32)

func (Slots) SetLong

func (self Slots) SetLong(index uint, val int64)

long consumes two slots

func (Slots) SetRef

func (self Slots) SetRef(index uint, ref *Object)

type SymRef

type SymRef struct {
	// contains filtered or unexported fields
}

*

类、字段、方法和接口符号的引用引用 都是常量
运行时常量池主要存放两类信息:字面量 和 符号引用
字面量包括:整数、浮点数和字符串字面量
符号引用包括:类符号引用、字段符号引用、方法符号引用和接口符号引用

func (*SymRef) ResolvedClass

func (self *SymRef) ResolvedClass() *Class

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL