jgo

package
v0.0.0-...-ffd0cae Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright 2020 chuanshenglu@gmail.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// Fake events
	JVMTI_MIN_FAKE_EVENT_TYPE_VAL = 100
	JVMTI_EVENT_AGENT_UNLOAD      = 100
	JVMTI_MAX_FAKE_EVENT_TYPE_VAL = 100
	JVMTI_EVENT_TYPE_LIMIT        = 100
)

JVMTI event ID definitions TODO: need shorter GO name

View Source
const (
	JVMTI_VERSION_1   = 0x30010000
	JVMTI_VERSION_1_0 = 0x30010000
	JVMTI_VERSION_1_1 = 0x30010100
	JVMTI_VERSION_1_2 = 0x30010200
	JVMTI_VERSION_9   = 0x30090000
	JVMTI_VERSION_11  = 0x300B0000

	JVMTI_VERSION = 0x30000000 + (14 * 0x10000) + (0 * 0x100) + 0 /* version: 14.0.0 */
)
View Source
const (
	JVMTI_THREAD_STATE_ALIVE                    = 0x0001
	JVMTI_THREAD_STATE_TERMINATED               = 0x0002
	JVMTI_THREAD_STATE_RUNNABLE                 = 0x0004
	JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER = 0x0400
	JVMTI_THREAD_STATE_WAITING                  = 0x0080
	JVMTI_THREAD_STATE_WAITING_INDEFINITELY     = 0x0010
	JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT     = 0x0020
	JVMTI_THREAD_STATE_SLEEPING                 = 0x0040
	JVMTI_THREAD_STATE_IN_OBJECT_WAIT           = 0x0100
	JVMTI_THREAD_STATE_PARKED                   = 0x0200
	JVMTI_THREAD_STATE_SUSPENDED                = 0x100000
	JVMTI_THREAD_STATE_INTERRUPTED              = 0x200000
	JVMTI_THREAD_STATE_IN_NATIVE                = 0x400000
	JVMTI_THREAD_STATE_VENDOR_1                 = 0x10000000
	JVMTI_THREAD_STATE_VENDOR_2                 = 0x20000000
	JVMTI_THREAD_STATE_VENDOR_3                 = 0x40000000
)
View Source
const (
	JVMTI_THREAD_MIN_PRIORITY  = 1
	JVMTI_THREAD_NORM_PRIORITY = 5
	JVMTI_THREAD_MAX_PRIORITY  = 10
)
View Source
const (
	JVMTI_HEAP_FILTER_TAGGED         = 0x4
	JVMTI_HEAP_FILTER_UNTAGGED       = 0x8
	JVMTI_HEAP_FILTER_CLASS_TAGGED   = 0x10
	JVMTI_HEAP_FILTER_CLASS_UNTAGGED = 0x20
)
View Source
const (
	JVMTI_VISIT_OBJECTS = 0x100
	JVMTI_VISIT_ABORT   = 0x8000
)
View Source
const (
	JVMTI_HEAP_REFERENCE_CLASS             = 1
	JVMTI_HEAP_REFERENCE_FIELD             = 2
	JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT     = 3
	JVMTI_HEAP_REFERENCE_CLASS_LOADER      = 4
	JVMTI_HEAP_REFERENCE_SIGNERS           = 5
	JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN = 6
	JVMTI_HEAP_REFERENCE_INTERFACE         = 7
	JVMTI_HEAP_REFERENCE_STATIC_FIELD      = 8
	JVMTI_HEAP_REFERENCE_CONSTANT_POOL     = 9
	JVMTI_HEAP_REFERENCE_SUPERCLASS        = 10
	JVMTI_HEAP_REFERENCE_JNI_GLOBAL        = 21
	JVMTI_HEAP_REFERENCE_SYSTEM_CLASS      = 22
	JVMTI_HEAP_REFERENCE_MONITOR           = 23
	JVMTI_HEAP_REFERENCE_STACK_LOCAL       = 24
	JVMTI_HEAP_REFERENCE_JNI_LOCAL         = 25
	JVMTI_HEAP_REFERENCE_THREAD            = 26
	JVMTI_HEAP_REFERENCE_OTHER             = 27
)
View Source
const (
	JVMTI_PRIMITIVE_TYPE_BOOLEAN = 90
	JVMTI_PRIMITIVE_TYPE_BYTE    = 66
	JVMTI_PRIMITIVE_TYPE_CHAR    = 67
	JVMTI_PRIMITIVE_TYPE_SHORT   = 83
	JVMTI_PRIMITIVE_TYPE_INT     = 73
	JVMTI_PRIMITIVE_TYPE_LONG    = 74
	JVMTI_PRIMITIVE_TYPE_FLOAT   = 70
	JVMTI_PRIMITIVE_TYPE_DOUBLE  = 68
)
View Source
const (
	JVMTI_HEAP_OBJECT_TAGGED   = 1
	JVMTI_HEAP_OBJECT_UNTAGGED = 2
	JVMTI_HEAP_OBJECT_EITHER   = 3
)
View Source
const (
	JVMTI_HEAP_ROOT_JNI_GLOBAL   = 1
	JVMTI_HEAP_ROOT_SYSTEM_CLASS = 2
	JVMTI_HEAP_ROOT_MONITOR      = 3
	JVMTI_HEAP_ROOT_STACK_LOCAL  = 4
	JVMTI_HEAP_ROOT_JNI_LOCAL    = 5
	JVMTI_HEAP_ROOT_THREAD       = 6
	JVMTI_HEAP_ROOT_OTHER        = 7
)
View Source
const (
	JVMTI_REFERENCE_CLASS             = 1
	JVMTI_REFERENCE_FIELD             = 2
	JVMTI_REFERENCE_ARRAY_ELEMENT     = 3
	JVMTI_REFERENCE_CLASS_LOADER      = 4
	JVMTI_REFERENCE_SIGNERS           = 5
	JVMTI_REFERENCE_PROTECTION_DOMAIN = 6
	JVMTI_REFERENCE_INTERFACE         = 7
	JVMTI_REFERENCE_STATIC_FIELD      = 8
	JVMTI_REFERENCE_CONSTANT_POOL     = 9
)
View Source
const (
	JVMTI_ITERATION_CONTINUE = 1
	JVMTI_ITERATION_IGNORE   = 2
	JVMTI_ITERATION_ABORT    = 0
)
View Source
const (
	JVMTI_CLASS_STATUS_VERIFIED    = 1
	JVMTI_CLASS_STATUS_PREPARED    = 2
	JVMTI_CLASS_STATUS_INITIALIZED = 4
	JVMTI_CLASS_STATUS_ERROR       = 8
	JVMTI_CLASS_STATUS_ARRAY       = 16
	JVMTI_CLASS_STATUS_PRIMITIVE   = 32
)
View Source
const (
	JVMTI_ENABLE  = 1
	JVMTI_DISABLE = 0
)
View Source
const (
	JVMTI_TYPE_JBYTE     = 101
	JVMTI_TYPE_JCHAR     = 102
	JVMTI_TYPE_JSHORT    = 103
	JVMTI_TYPE_JINT      = 104
	JVMTI_TYPE_JLONG     = 105
	JVMTI_TYPE_JFLOAT    = 106
	JVMTI_TYPE_JDOUBLE   = 107
	JVMTI_TYPE_JBOOLEAN  = 108
	JVMTI_TYPE_JOBJECT   = 109
	JVMTI_TYPE_JTHREAD   = 110
	JVMTI_TYPE_JCLASS    = 111
	JVMTI_TYPE_JVALUE    = 112
	JVMTI_TYPE_JFIELDID  = 113
	JVMTI_TYPE_JMETHODID = 114
	JVMTI_TYPE_CCHAR     = 115
	JVMTI_TYPE_CVOID     = 116
	JVMTI_TYPE_JNIENV    = 117
)
View Source
const (
	JVMTI_KIND_IN              = 91
	JVMTI_KIND_IN_PTR          = 92
	JVMTI_KIND_IN_BUF          = 93
	JVMTI_KIND_ALLOC_BUF       = 94
	JVMTI_KIND_ALLOC_ALLOC_BUF = 95
	JVMTI_KIND_OUT             = 96
	JVMTI_KIND_OUT_BUF         = 97
)
View Source
const (
	JVMTI_TIMER_USER_CPU  = 30
	JVMTI_TIMER_TOTAL_CPU = 31
	JVMTI_TIMER_ELAPSED   = 32
)
View Source
const (
	JVMTI_PHASE_ONLOAD     = 1
	JVMTI_PHASE_PRIMORDIAL = 2
	JVMTI_PHASE_START      = 6
	JVMTI_PHASE_LIVE       = 4
	JVMTI_PHASE_DEAD       = 8
)
View Source
const (
	JVMTI_VERSION_INTERFACE_JNI   = 0x00000000
	JVMTI_VERSION_INTERFACE_JVMTI = 0x30000000
)
View Source
const (
	JVMTI_VERSION_MASK_INTERFACE_TYPE = 0x70000000
	JVMTI_VERSION_MASK_MAJOR          = 0x0FFF0000
	JVMTI_VERSION_MASK_MINOR          = 0x0000FF00
	JVMTI_VERSION_MASK_MICRO          = 0x000000FF
)
View Source
const (
	JVMTI_VERSION_SHIFT_MAJOR = 16
	JVMTI_VERSION_SHIFT_MINOR = 8
	JVMTI_VERSION_SHIFT_MICRO = 0
)
View Source
const (
	JVMTI_VERBOSE_OTHER = 0
	JVMTI_VERBOSE_GC    = 1
	JVMTI_VERBOSE_CLASS = 2
	JVMTI_VERBOSE_JNI   = 4
)
View Source
const (
	JVMTI_JLOCATION_JVMBCI    = 1
	JVMTI_JLOCATION_MACHINEPC = 2
	JVMTI_JLOCATION_OTHER     = 0
)
View Source
const (
	JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR = 0x0001
	JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP = 0x0002
	JVMTI_RESOURCE_EXHAUSTED_THREADS   = 0x0004
)
View Source
const (
	JVMTI_ERROR_NONE                                              = 0
	JVMTI_ERROR_INVALID_THREAD                                    = 10
	JVMTI_ERROR_INVALID_THREAD_GROUP                              = 11
	JVMTI_ERROR_INVALID_PRIORITY                                  = 12
	JVMTI_ERROR_THREAD_NOT_SUSPENDED                              = 13
	JVMTI_ERROR_THREAD_SUSPENDED                                  = 14
	JVMTI_ERROR_THREAD_NOT_ALIVE                                  = 15
	JVMTI_ERROR_INVALID_OBJECT                                    = 20
	JVMTI_ERROR_INVALID_CLASS                                     = 21
	JVMTI_ERROR_CLASS_NOT_PREPARED                                = 22
	JVMTI_ERROR_INVALID_METHODID                                  = 23
	JVMTI_ERROR_INVALID_LOCATION                                  = 24
	JVMTI_ERROR_INVALID_FIELDID                                   = 25
	JVMTI_ERROR_INVALID_MODULE                                    = 26
	JVMTI_ERROR_NO_MORE_FRAMES                                    = 31
	JVMTI_ERROR_OPAQUE_FRAME                                      = 32
	JVMTI_ERROR_TYPE_MISMATCH                                     = 34
	JVMTI_ERROR_INVALID_SLOT                                      = 35
	JVMTI_ERROR_DUPLICATE                                         = 40
	JVMTI_ERROR_NOT_FOUND                                         = 41
	JVMTI_ERROR_INVALID_MONITOR                                   = 50
	JVMTI_ERROR_NOT_MONITOR_OWNER                                 = 51
	JVMTI_ERROR_INTERRUPT                                         = 52
	JVMTI_ERROR_INVALID_CLASS_FORMAT                              = 60
	JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION                         = 61
	JVMTI_ERROR_FAILS_VERIFICATION                                = 62
	JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED             = 63
	JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED           = 64
	JVMTI_ERROR_INVALID_TYPESTATE                                 = 65
	JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED        = 66
	JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED           = 67
	JVMTI_ERROR_UNSUPPORTED_VERSION                               = 68
	JVMTI_ERROR_NAMES_DONT_MATCH                                  = 69
	JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED  = 70
	JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED = 71
	JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED  = 72
	JVMTI_ERROR_UNMODIFIABLE_CLASS                                = 79
	JVMTI_ERROR_UNMODIFIABLE_MODULE                               = 80
	JVMTI_ERROR_NOT_AVAILABLE                                     = 98
	JVMTI_ERROR_MUST_POSSESS_CAPABILITY                           = 99
	JVMTI_ERROR_NULL_POINTER                                      = 100
	JVMTI_ERROR_ABSENT_INFORMATION                                = 101
	JVMTI_ERROR_INVALID_EVENT_TYPE                                = 102
	JVMTI_ERROR_ILLEGAL_ARGUMENT                                  = 103
	JVMTI_ERROR_NATIVE_METHOD                                     = 104
	JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED                          = 106
	JVMTI_ERROR_OUT_OF_MEMORY                                     = 110
	JVMTI_ERROR_ACCESS_DENIED                                     = 111
	JVMTI_ERROR_WRONG_PHASE                                       = 112
	JVMTI_ERROR_INTERNAL                                          = 113
	JVMTI_ERROR_UNATTACHED_THREAD                                 = 115
	JVMTI_ERROR_INVALID_ENVIRONMENT                               = 116
	JVMTI_ERROR_MAX                                               = 116
)
View Source
const (
	JVMTI_MIN_EVENT_TYPE_VAL              = 50
	JVMTI_EVENT_VM_INIT                   = 50
	JVMTI_EVENT_VM_DEATH                  = 51
	JVMTI_EVENT_THREAD_START              = 52
	JVMTI_EVENT_THREAD_END                = 53
	JVMTI_EVENT_CLASS_FILE_LOAD_HOOK      = 54
	JVMTI_EVENT_CLASS_LOAD                = 55
	JVMTI_EVENT_CLASS_PREPARE             = 56
	JVMTI_EVENT_VM_START                  = 57
	JVMTI_EVENT_EXCEPTION                 = 58
	JVMTI_EVENT_EXCEPTION_CATCH           = 59
	JVMTI_EVENT_SINGLE_STEP               = 60
	JVMTI_EVENT_FRAME_POP                 = 61
	JVMTI_EVENT_BREAKPOINT                = 62
	JVMTI_EVENT_FIELD_ACCESS              = 63
	JVMTI_EVENT_FIELD_MODIFICATION        = 64
	JVMTI_EVENT_METHOD_ENTRY              = 65
	JVMTI_EVENT_METHOD_EXIT               = 66
	JVMTI_EVENT_NATIVE_METHOD_BIND        = 67
	JVMTI_EVENT_COMPILED_METHOD_LOAD      = 68
	JVMTI_EVENT_COMPILED_METHOD_UNLOAD    = 69
	JVMTI_EVENT_DYNAMIC_CODE_GENERATED    = 70
	JVMTI_EVENT_DATA_DUMP_REQUEST         = 71
	JVMTI_EVENT_MONITOR_WAIT              = 73
	JVMTI_EVENT_MONITOR_WAITED            = 74
	JVMTI_EVENT_MONITOR_CONTENDED_ENTER   = 75
	JVMTI_EVENT_MONITOR_CONTENDED_ENTERED = 76
	JVMTI_EVENT_RESOURCE_EXHAUSTED        = 80
	JVMTI_EVENT_GARBAGE_COLLECTION_START  = 81
	JVMTI_EVENT_GARBAGE_COLLECTION_FINISH = 82
	JVMTI_EVENT_OBJECT_FREE               = 83
	JVMTI_EVENT_VM_OBJECT_ALLOC           = 84
	JVMTI_EVENT_SAMPLED_OBJECT_ALLOC      = 86
	JVMTI_MAX_EVENT_TYPE_VAL              = 86
)

Variables

The global instance of this agent lib

Functions

func MainForwardLoop

func MainForwardLoop()

func OnAgentLoad

func OnAgentLoad(javaVM, jvmti uintptr, options *C.char)

func OnAgentUnload

func OnAgentUnload() int32

func OnJvmtiEvent

func OnJvmtiEvent(eventId int, jvmti, params uintptr, paramsLen int)

OnJvmtiEvent dispatches all the event to corresponding Go handlers runs on a JavaThread

Types

type AgentLib

type AgentLib struct {

	// command line options to this agent
	Options string
	// contains filtered or unexported fields
}

AgentLib defines the information of a agent library

func (*AgentLib) GetCallbacks

func (agent *AgentLib) GetCallbacks() *JvmtiCallbacks

GetCallbacks returns the callbacks of this lib

type AgentOnLoadCallback

type AgentOnLoadCallback func(*AgentLib)

type AgentOnUnloadCallback

type AgentOnUnloadCallback func()

type Frame

type Frame struct {
	PC     uintptr
	Func   string
	Source string
}

func (*Frame) String

func (f *Frame) String() string

type JClass

type JClass uintptr

type JObject

type JObject uintptr

type JVM

type JVM jni.VM

func (JVM) VM

func (vm JVM) VM() jni.VM

type JavaVM

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

Unified interface for both jni and jvmti

func CurrentVM

func CurrentVM() *JavaVM

Retrieve the unique VM instance Current spec only allows one JVM in each process

func Exec

func Exec(args []string) (*JavaVM, error)

create and launch a new Java virtual machine with current thread attached as the main thread

func (*JavaVM) CurrentThread

func (jvm *JavaVM) CurrentThread() (rt *Thread, err error)

func (*JavaVM) DumpThreads

func (jvm *JavaVM) DumpThreads() (thrds []*Thread, err error)

func (*JavaVM) FullVersion

func (jvm *JavaVM) FullVersion() string

func (*JavaVM) GetSystemProperties

func (jvm *JavaVM) GetSystemProperties() (map[string]string, error)

Retrieve all the properties from the Java VM

func (*JavaVM) GetSystemProperty

func (jvm *JavaVM) GetSystemProperty(key string) string

Retrieve property value of given key returns "" if not found or error

func (*JavaVM) SetSystemProperty

func (jvm *JavaVM) SetSystemProperty(key, value string) error

Set the value of target system property only allowed to be called at agent OnLoad phase According to https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#GetSystemProperty

type JniEnv

type JniEnv jni.Env

func (JniEnv) Env

func (e JniEnv) Env() jni.Env

type JvmtiArg

type JvmtiArg uintptr

type JvmtiCallbacks

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

JvmtiCallbacks holds the JVMTI event callbacks

func (*JvmtiCallbacks) SetCallback

func (callbacks *JvmtiCallbacks) SetCallback(eventId int, fn func(jvmtiEnv, ...JvmtiArg))

SetCallback links a go method to process a specific JVMTI event

type Thread

type Thread struct {
	IsDaemon    bool
	Name        string
	StackTraces []Frame
	// contains filtered or unexported fields
}

func (*Thread) String

func (t *Thread) String() string

Jump to

Keyboard shortcuts

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