core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

core is a package for parsing JVM .hprof files.

Models are based on the following JDK source: https://github.com/openjdk/jdk/blob/c1e39faaa99ee62ff626ffec9f978ed0f8ffaca1/src/hotspot/share/services/heapDumper.cpp

It contains basic utility primitives that should be used to parse the given .hprof dump in the form of io.Reader. Functions in this packages are not aware of the position in the input, they are simple primitives to parse structures that .hprof could contain. The whole structure of .hprof file is written in code comment at the link above.

Index

Constants

View Source
const (
	ValidProfileVersion = "JAVA PROFILE 1.0.2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileHeader

type FileHeader struct {
	Header         string
	IdentifierSize uint32
	Timestamp      time.Time
}

func ParseFileHeader

func ParseFileHeader(heapDump io.Reader) (FileHeader, error)

ParseFileHeader reads the header of .hprof file.

type HprofFrame

type HprofFrame struct {
	StackFrameId      Identifier
	MethodNameId      Identifier
	MethodSignatureId Identifier
	SourceFileNameId  Identifier
	ClassSerialNumber uint32
	LineNumber        LineNumber
}

type HprofGcClassDump

type HprofGcClassDump struct {
	ClassObjectId            Identifier
	StackTraceSerialNumber   uint32
	SuperclassObjectId       Identifier
	ClassloaderObjectId      Identifier
	SignersObjectId          Identifier
	ProtectionDomainObjectId Identifier
	InstanceSize             int32
	SizeOfConstantPool       uint16
	ConstantPoolRecords      []HprofGcClassDumpConstantPoolRecord
	NumberOfStaticFields     uint16
	StaticFieldRecords       []HprofGcClassDumpStaticFieldsRecord
	NumberOfInstanceFields   uint16
	InstanceFieldRecords     []HprofGcClassDumpInstanceFieldsRecord
}

type HprofGcClassDumpConstantPoolRecord

type HprofGcClassDumpConstantPoolRecord struct {
	ConstantPoolIndex uint16
	Ty                JavaType
	Value             JavaValue
}

type HprofGcClassDumpInstanceDumpHeader

type HprofGcClassDumpInstanceDumpHeader struct {
	ObjectId                Identifier
	StackTraceSerialNumber  uint32
	ClassObjectId           Identifier
	NumberOfBytesThatFollow uint32
}

type HprofGcClassDumpInstanceFieldsRecord

type HprofGcClassDumpInstanceFieldsRecord struct {
	InstanceFieldName Identifier
	Ty                JavaType
}

type HprofGcClassDumpStaticFieldsRecord

type HprofGcClassDumpStaticFieldsRecord struct {
	StaticFieldName Identifier
	Ty              JavaType
	Value           JavaValue
}

type HprofGcObjArrayDumpHeader

type HprofGcObjArrayDumpHeader struct {
	ArrayObjectId          Identifier
	StackTraceSerialNumber uint32
	NumberOfElements       uint32
	ArrayClassId           Identifier
}

type HprofGcPrimArrayDumpHeader

type HprofGcPrimArrayDumpHeader struct {
	ArrayObjectId          Identifier
	StackTraceSerialNumber uint32
	NumberOfElements       uint32
	ElementType            JavaType
}

type HprofGcRootJavaFrame

type HprofGcRootJavaFrame struct {
	ObjectId                Identifier
	ThreadSerialNumber      uint32
	FrameNumberInStackTrace uint32
}

type HprofGcRootJniGlobal

type HprofGcRootJniGlobal struct {
	ObjectId       Identifier
	JniGlobalRefId Identifier
}

type HprofGcRootJniLocal

type HprofGcRootJniLocal struct {
	ObjectId                Identifier
	ThreadSerialNumber      uint32
	FrameNumberInStackTrace uint32
}

type HprofGcRootStickyClass

type HprofGcRootStickyClass struct {
	ObjectId Identifier
}

type HprofGcRootThreadObj

type HprofGcRootThreadObj struct {
	ThreadObjectId           Identifier
	ThreadSequenceNumber     uint32
	StackTraceSequenceNumber uint32
}

type HprofLoadClass

type HprofLoadClass struct {
	ClassSerialNumber      uint32
	ClassObjectId          Identifier
	StackTraceSerialNumber uint32
	ClassNameId            Identifier
}

type HprofTrace

type HprofTrace struct {
	StackTraceSerialNumber uint32
	ThreadSerialNumber     uint32
	NumberOfFrames         uint32
	StackFrameIds          []Identifier
}

type HprofUtf8

type HprofUtf8 struct {
	Identifier Identifier
	Characters string
}

type Identifier

type Identifier uint64

Identifier represents Java identifier. uint64 is used to store it because actual size can be 4 or 8 bytes.

type JavaType

type JavaType uint8

JavaType if representation of Java types with string values for readability.

const (
	Object  JavaType = 2
	Boolean JavaType = 4
	Char    JavaType = 5
	Float   JavaType = 6
	Double  JavaType = 7
	Byte    JavaType = 8
	Short   JavaType = 9
	Int     JavaType = 10
	Long    JavaType = 11
)

func (JavaType) String

func (j JavaType) String() string

type JavaValue

type JavaValue struct {
	Type  JavaType
	Value any
}

JavaValue wraps type of the constant and the value converted to corresponding Go type.

func (JavaValue) ToBool

func (jv JavaValue) ToBool() (bool, error)

func (JavaValue) ToInt

func (jv JavaValue) ToInt() (int, error)

func (JavaValue) ToLong

func (jv JavaValue) ToLong() (int, error)

func (JavaValue) ToObject

func (jv JavaValue) ToObject() (Identifier, error)

type LineNumber

type LineNumber int32

LineNumber is the wrapper for int32 with verbose values for some constants (Unknown, CompiledMethod, NativeMethod). It's stringified integer if > 0.

const (
	Unknown        LineNumber = -1
	CompiledMethod LineNumber = -2
	NativeMethod   LineNumber = -3
)

func (LineNumber) String

func (l LineNumber) String() string

type PrimitiveParser

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

PrimitiveParser is a parser that allows to read low-level primitives like u1, u2, u4, etc. numbers and other types that presented in heap dump.

func NewPrimitiveParser

func NewPrimitiveParser(heapDump io.Reader, idSize uint32) *PrimitiveParser

func (*PrimitiveParser) ParseByteSeq

func (parser *PrimitiveParser) ParseByteSeq(n int) ([]byte, error)

ParseByteSeq reads n bytes from underlying reader

func (*PrimitiveParser) ParseIdentifier

func (parser *PrimitiveParser) ParseIdentifier() (Identifier, error)

ParseIdentifier reads JVM identifier that can be 32 or 64 bit value. It depends on the machine on which JVM runs.

func (*PrimitiveParser) ParseInt32

func (parser *PrimitiveParser) ParseInt32() (int32, error)

ParseInt32 reads 32-bit signed (i4) number.

func (*PrimitiveParser) ParseJavaType

func (parser *PrimitiveParser) ParseJavaType() (JavaType, error)

ParseJavaType reads JavaType which is 8-bit unsigned under the hood.

func (*PrimitiveParser) ParseJavaValue

func (parser *PrimitiveParser) ParseJavaValue(ty JavaType) (JavaValue, error)

ParseJavaValue reads JavaValue of given JavaType and stores it in struct along with the type for future use.

func (*PrimitiveParser) ParseLineNumber

func (parser *PrimitiveParser) ParseLineNumber() (LineNumber, error)

ParseLineNumber reads LineNumber which is 32-bit signed under the hood.

func (*PrimitiveParser) ParseUint16

func (parser *PrimitiveParser) ParseUint16() (uint16, error)

ParseUint16 reads 16-bit unsigned (u2) number.

func (*PrimitiveParser) ParseUint32

func (parser *PrimitiveParser) ParseUint32() (uint32, error)

ParseUint32 reads 32-bit unsigned (u4) number.

func (*PrimitiveParser) ParseUint8

func (parser *PrimitiveParser) ParseUint8() (uint8, error)

ParseUint8 reads 8-bit unsigned (u1) number.

type RecordHeader

type RecordHeader struct {
	Tag       Tag
	Remaining uint32
}

type RecordParser

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

RecordParser is used to parse HprofRecords from raw heap dump.

func NewRecordParser

func NewRecordParser(heapDump io.Reader, idSize uint32) *RecordParser

func (*RecordParser) ParseHprofFrame

func (parser *RecordParser) ParseHprofFrame() (HprofFrame, error)

ParseHprofFrame reads HPROF_FRAME record.

func (*RecordParser) ParseHprofGcClassDump

func (parser *RecordParser) ParseHprofGcClassDump() (HprofGcClassDump, error)

ParseHprofGcClassDump reads HPROF_GC_CLASS_DUMP sub-record.

func (*RecordParser) ParseHprofGcClassDumpInstanceDumpHeader

func (parser *RecordParser) ParseHprofGcClassDumpInstanceDumpHeader() (HprofGcClassDumpInstanceDumpHeader, error)

ParseHprofGcClassDumpInstanceDumpHeader reads "header" information from HPROF_GC_INSTANCE_DUMP. It does not read array of instance field values, so ParseHprofGcClassDumpInstanceDumpRecord does.

func (*RecordParser) ParseHprofGcObjArrayDumpHeader

func (parser *RecordParser) ParseHprofGcObjArrayDumpHeader() (HprofGcObjArrayDumpHeader, error)

ParseHprofGcObjArrayDumpHeader reads "header" information from HPROF_GC_OBJ_ARRAY_DUMP. It does not read array of elements, so ParseHprofGcObjArrayDumpRecord does.

func (*RecordParser) ParseHprofGcPrimArrayDumpHeader

func (parser *RecordParser) ParseHprofGcPrimArrayDumpHeader() (HprofGcPrimArrayDumpHeader, error)

ParseHprofGcPrimArrayDumpHeader reads "header" information from HPROF_GC_PRIM_ARRAY_DUMP. It does not read array of elements, so ParseHprofGcPrimArrayDumpRecord does.

func (*RecordParser) ParseHprofGcRootJavaFrame

func (parser *RecordParser) ParseHprofGcRootJavaFrame() (HprofGcRootJavaFrame, error)

ParseHprofGcRootJavaFrame reads HPROF_GC_ROOT_JAVA_FRAME sub-record.

func (*RecordParser) ParseHprofGcRootJniGlobal

func (parser *RecordParser) ParseHprofGcRootJniGlobal() (HprofGcRootJniGlobal, error)

ParseHprofGcRootJniGlobal reads HPROF_GC_ROOT_JNI_GLOBAL sub-record.

func (*RecordParser) ParseHprofGcRootJniLocal

func (parser *RecordParser) ParseHprofGcRootJniLocal() (HprofGcRootJniLocal, error)

ParseHprofGcRootJniLocal reads HPROF_GC_ROOT_JNI_LOCAL sub-record.

func (*RecordParser) ParseHprofGcRootStickyClass

func (parser *RecordParser) ParseHprofGcRootStickyClass() (HprofGcRootStickyClass, error)

ParseHprofGcRootStickyClass reads HPROF_GC_ROOT_STICKY_CLASS sub-record.

func (*RecordParser) ParseHprofGcRootThreadObj

func (parser *RecordParser) ParseHprofGcRootThreadObj() (HprofGcRootThreadObj, error)

ParseHprofGcRootThreadObj reads HPROF_GC_ROOT_THREAD_OBJ sub-record.

func (*RecordParser) ParseHprofLoadClass

func (parser *RecordParser) ParseHprofLoadClass() (HprofLoadClass, error)

ParseHprofLoadClass reads HPROF_LOAD_CLASS record.

func (*RecordParser) ParseHprofTrace

func (parser *RecordParser) ParseHprofTrace() (HprofTrace, error)

ParseHprofTrace reads HPROF_TRACE record.

func (*RecordParser) ParseHprofUtf8

func (parser *RecordParser) ParseHprofUtf8(remaining uint32) (HprofUtf8, error)

ParseHprofUtf8 reads HPROF_UTF8 record

func (*RecordParser) ParseRecordHeader

func (parser *RecordParser) ParseRecordHeader() (RecordHeader, error)

ParseRecordHeader reads the header of Hprof records which contain information about record's TAG and remaining bytes.

func (*RecordParser) ParseSubRecordHeader

func (parser *RecordParser) ParseSubRecordHeader() (SubRecordHeader, error)

ParseSubRecordHeader reads the type of the sub-record inside HPROF_HEAP_DUMP_SEGMENT.

func (*RecordParser) ReadBytes

func (parser *RecordParser) ReadBytes(n int) ([]byte, error)

ReadBytes read n bytes from underlying io.Reader

type SizeInfo

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

func NewSizeInfo

func NewSizeInfo(idSize uint32) *SizeInfo

func (SizeInfo) Of

func (s SizeInfo) Of(record any) int

func (SizeInfo) OfObject

func (s SizeInfo) OfObject(record any) (size, recordsSize int)

func (SizeInfo) OfType

func (s SizeInfo) OfType(javaType JavaType) int

type SubRecordHeader

type SubRecordHeader struct {
	SubRecordType SubRecordType
}

type SubRecordType

type SubRecordType byte
const (
	HprofGcRootJniGlobalType   SubRecordType = 0x01
	HprofGcRootJniLocalType    SubRecordType = 0x02
	HprofGcRootJavaFrameType   SubRecordType = 0x03
	HprofGcRootStickyClassType SubRecordType = 0x05
	HprofGcRootThreadObjType   SubRecordType = 0x08
	HprofGcClassDumpType       SubRecordType = 0x20
	HprofGcInstanceDumpType    SubRecordType = 0x21
	HprofGcObjArrayDumpType    SubRecordType = 0x22
	HprofGcPrimArrayDumpType   SubRecordType = 0x23
)
const (
	HprofHeapDumpEndSubRecord     SubRecordType = 0x2c
	HprofHeapDumpSegmentSubRecord SubRecordType = 0x1c
)

these duplicated tags from Tags to be able to exit parse subrecords loop.

func (SubRecordType) String

func (s SubRecordType) String() string

type Tag

type Tag byte
const (
	HprofUtf8Tag            Tag = 0x01
	HprofLoadClassTag       Tag = 0x02
	HprofFrameTag           Tag = 0x04
	HprofTraceTag           Tag = 0x05
	HprofHeapDumpSegmentTag Tag = 0x1c
	HprofHeapDumpEndTag     Tag = 0x2c
)

func (Tag) String

func (t Tag) String() string

Jump to

Keyboard shortcuts

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