attach

package module
v0.0.0-...-b2297cf Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 15 Imported by: 0

README

attach

A Go library for attaching to running JVMs via the Attach API.

Currently, only HotSpot-based JVMs are supported - no OpenJ9 support.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoProvider = errors.New("no provider available")

ErrNoProvider is an error returned when no provider is available, typically when the platform is not supported.

Functions

This section is empty.

Types

type ErrAgentLoad

type ErrAgentLoad struct {
	*ErrLoad
}

func (*ErrAgentLoad) Error

func (eal *ErrAgentLoad) Error() string

func (*ErrAgentLoad) Unwrap

func (eal *ErrAgentLoad) Unwrap() error

type ErrLoad

type ErrLoad struct {
	Code    int
	Message string
}

func (*ErrLoad) Error

func (el *ErrLoad) Error() string

type ErrParse

type ErrParse struct {
	Data string
}

func (*ErrParse) Error

func (ep *ErrParse) Error() string

type ErrResponse

type ErrResponse struct {
	Code int
	Data string
}

func (*ErrResponse) Error

func (er *ErrResponse) Error() string

type Provider

type Provider interface {
	// List returns a list of available JVMs that can be attached to.
	List() ([]*VMDescriptor, error)
	// Attach attaches to a JVM using its descriptor.
	Attach(desc *VMDescriptor) (VM, error)
	// AttachID attaches to a JVM using its ID (usually the PID).
	AttachID(id string) (VM, error)
}

Provider allows you to list and attach to JVMs. You can use the Default() function to get the current platform's provider.

func Default

func Default() (Provider, error)

Default returns the provider for the current platform.

type UnixProvider

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

func (*UnixProvider) Attach

func (up *UnixProvider) Attach(desc *VMDescriptor) (VM, error)

func (*UnixProvider) AttachID

func (up *UnixProvider) AttachID(id string) (VM, error)

func (UnixProvider) List

func (sp UnixProvider) List() ([]*VMDescriptor, error)

type VM

type VM interface {
	io.Closer

	// Load loads a Java agent into the attached JVM.
	Load(agent string, options string) error
	// LoadLibrary loads a Java agent library from the specified path into the attached JVM.
	LoadLibrary(path string, absolute bool, options string) error
	// Properties retrieves the properties of the attached JVM.
	Properties() (map[string]string, error)
	// ThreadDump retrieves a thread dump of the attached JVM.
	ThreadDump() (string, error)
}

VM represents an attached JVM instance.

type VMDescriptor

type VMDescriptor struct {
	// ID is the unique identifier for the JVM instance, usually the PID.
	ID string
	// DisplayName is a human-readable name for the JVM instance, may be empty, usually the process command line.
	DisplayName string
}

VMDescriptor is a descriptor for a JVM that can be attached to.

Jump to

Keyboard shortcuts

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