Skip to content

Commit dbda939

Browse files
committed
Tidy up
1 parent 5951d0b commit dbda939

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/agentcontroller/controller.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ impl<'a> AgentController<'a> {
4343
}
4444

4545
impl<'a> super::MutAction for AgentController<'a> {
46-
fn on_oom(&mut self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint) {
47-
let heap_exhausted = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP as ::jvmti::jint;
48-
let threads_exhausted = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_THREADS as ::jvmti::jint;
49-
if resourceExhaustionFlags & heap_exhausted == heap_exhausted {
46+
fn on_oom(&mut self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint) {
47+
const heap_exhausted: ::jvmti::jint = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP as ::jvmti::jint;
48+
const threads_exhausted: ::jvmti::jint = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_THREADS as ::jvmti::jint;
49+
const oom_error: ::jvmti::jint = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR as ::jvmti::jint;
50+
51+
if resource_exhaustion_flags & heap_exhausted == heap_exhausted {
5052
eprintln!("\nResource exhaustion event: the JVM was unable to allocate memory from the heap.");
5153
}
52-
if resourceExhaustionFlags & threads_exhausted == threads_exhausted {
54+
if resource_exhaustion_flags & threads_exhausted == threads_exhausted {
5355
eprintln!("\nResource exhaustion event: the JVM was unable to create a thread.");
5456
}
5557

5658
if self.heuristic.on_oom() {
5759
for action in &self.actions {
58-
action.on_oom(jni_env, resourceExhaustionFlags);
60+
action.on_oom(jni_env, resource_exhaustion_flags);
5961
}
60-
} else {
62+
} else if resource_exhaustion_flags & oom_error == oom_error {
6163
eprintln!("\nThe JVM is about to throw a java.lang.OutOfMemoryError.");
6264
}
6365
}

src/agentcontroller/heaphistogram.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ impl HeapHistogram {
2727
}
2828

2929
impl super::Action for HeapHistogram {
30-
fn on_oom(&self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint) {
30+
fn on_oom(&self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint) {
3131
}
3232
}

src/agentcontroller/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod controller;
1818

1919
pub trait MutAction {
2020
// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#jvmtiResourceExhaustionFlags
21-
fn on_oom(&mut self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint);
21+
fn on_oom(&mut self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint);
2222
}
2323

2424
mod heaphistogram;
@@ -32,5 +32,5 @@ trait Heuristic {
3232

3333
trait Action {
3434
// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#jvmtiResourceExhaustionFlags
35-
fn on_oom(&self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint);
35+
fn on_oom(&self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint);
3636
}

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ impl<'a> AgentContext<'a> {
5353
self.ac = Some(a);
5454
}
5555

56-
pub fn on_oom(&mut self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint) {
57-
self.ac.as_mut().map(|mut a| a.on_oom(jni_env, resourceExhaustionFlags));
56+
pub fn on_oom(&mut self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint) {
57+
self.ac.as_mut().map(|mut a| a.on_oom(jni_env, resource_exhaustion_flags));
5858
}
5959
}
6060

0 commit comments

Comments
 (0)