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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! High-level environment wrappers for JVMTI and JNI.
//!
//! This module provides ergonomic Rust wrappers around the raw JVMTI and JNI
//! environment pointers. These wrappers handle memory management, string conversion,
//! and provide Rust-friendly return types.
//!
//! # Quick Start
//!
//! ```rust,ignore
//! use jvmti_bindings::prelude::*;
//!
//! #[derive(Default)]
//! struct MyAgent;
//!
//! impl Agent for MyAgent {
//! fn on_load(&self, vm: *mut jni::JavaVM, options: &str) -> jni::jint {
//! // Get JVMTI environment
//! let jvmti = Jvmti::new(vm).expect("Failed to get JVMTI env");
//!
//! // Request capabilities
//! let mut caps = jvmti::jvmtiCapabilities::default();
//! caps.set_can_generate_all_class_hook_events(true);
//! jvmti.add_capabilities(&caps).expect("Failed to add capabilities");
//!
//! // Set up event callbacks
//! let callbacks = get_default_callbacks();
//! jvmti.set_event_callbacks(callbacks).expect("Failed to set callbacks");
//!
//! jni::JNI_OK
//! }
//!
//! fn vm_init(&self, jni_ptr: *mut jni::JNIEnv, _thread: jni::jthread) {
//! // Get JNI environment
//! let jni = unsafe { JniEnv::from_raw(jni_ptr) };
//!
//! // Find a class
//! if let Some(cls) = jni.find_class("java/lang/System") {
//! println!("Found System class!");
//! }
//!
//! // Create a string
//! if let Some(s) = jni.new_string_utf("Hello from Rust!") {
//! println!("Created Java string");
//! }
//! }
//! }
//!
//! export_agent!(MyAgent);
//! ```
//!
//! # JVMTI Environment
//!
//! The [`Jvmti`] struct wraps the JVMTI environment and provides methods for:
//!
//! - **Capabilities**: Request and query agent capabilities
//! - **Events**: Set up event callbacks and enable/disable events
//! - **Threads**: Enumerate, suspend, resume threads
//! - **Classes**: Get loaded classes, class info, bytecode
//! - **Methods**: Get method info, line numbers, local variables
//! - **Heap**: Object tagging, heap iteration, garbage collection
//! - **Stack**: Get stack traces, frame info, local variables
//! - **Monitors**: Create and manage raw monitors
//! - **Breakpoints**: Set and clear breakpoints
//! - **Class Transformation**: Redefine and retransform classes
//!
//! # JNI Environment
//!
//! The [`JniEnv`] struct wraps the JNI environment and provides methods for:
//!
//! - **Classes**: Find classes, check inheritance
//! - **Objects**: Create objects, check types
//! - **Strings**: Convert between Java strings and Rust strings
//! - **Arrays**: Create and access Java arrays
//! - **Methods**: Call instance and static methods
//! - **Fields**: Get and set instance and static fields
//! - **Exceptions**: Check, throw, and clear exceptions
//! - **References**: Manage local, global, and weak references
//!
//! # Reference Guards
//!
//! The module also provides RAII guards for automatic reference cleanup:
//!
//! - [`LocalRef`]: Automatically deletes a local reference when dropped
//! - [`GlobalRef`]: Automatically deletes a global reference when dropped
//!
//! ```rust,ignore
//! use jvmti_bindings::prelude::*;
//!
//! fn do_something(jni: &JniEnv) {
//! // LocalRef automatically cleans up when it goes out of scope
//! let class = LocalRef::new(jni, jni.find_class("java/lang/String").unwrap());
//!
//! // Use class.get() to access the underlying jclass
//! let method = jni.get_method_id(class.get(), "length", "()I");
//!
//! // class is automatically deleted here
//! }
//! ```
// Re-export the JVMTI wrapper
// Re-export the JNI wrapper
pub use ;
pub use ;