Skip to content

Commit e327dc5

Browse files
committed
Print out heap or thread exhaustion
1 parent d2727a2 commit e327dc5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/agentcontroller/controller.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ impl<'a> AgentController<'a> {
2828

2929
impl<'a> super::MutAction for AgentController<'a> {
3030
fn on_oom(&mut self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint) {
31+
let heap_exhausted = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP as ::jvmti::jint;
32+
let threads_exhausted = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_THREADS as ::jvmti::jint;
33+
if resourceExhaustionFlags & heap_exhausted == heap_exhausted {
34+
eprintln!("\nResource exhaustion event: the JVM was unable to allocate memory from the heap.");
35+
}
36+
if resourceExhaustionFlags & threads_exhausted == threads_exhausted {
37+
eprintln!("\nResource exhaustion event: the JVM was unable to create a thread.");
38+
}
39+
3140
if self.heuristic.on_oom() {
3241
for action in &self.actions {
3342
action.on_oom(jni_env, resourceExhaustionFlags);

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ pub extern fn Agent_OnLoad(vm: *mut jvmti::JavaVM, options: *mut ::std::os::raw:
6666
}
6767

6868
fn resource_exhausted(mut jvmti_env: env::JvmTiEnv, jni_env: env::JniEnv, flags: ::jvmti::jint) {
69-
println!("Resource exhausted callback driven!");
70-
7169
if let Err(err) = jvmti_env.raw_monitor_enter(&RAW_MONITOR_ID) {
7270
eprintln!("ERROR: RawMonitorEnter failed: {}", err);
7371
return

0 commit comments

Comments
 (0)