Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
glyn committed Jun 14, 2017
1 parent 5951d0b commit dbda939
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/agentcontroller/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ impl<'a> AgentController<'a> {
}

impl<'a> super::MutAction for AgentController<'a> {
fn on_oom(&mut self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint) {
let heap_exhausted = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP as ::jvmti::jint;
let threads_exhausted = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_THREADS as ::jvmti::jint;
if resourceExhaustionFlags & heap_exhausted == heap_exhausted {
fn on_oom(&mut self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint) {
const heap_exhausted: ::jvmti::jint = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP as ::jvmti::jint;
const threads_exhausted: ::jvmti::jint = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_THREADS as ::jvmti::jint;
const oom_error: ::jvmti::jint = ::jvmti::JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR as ::jvmti::jint;

if resource_exhaustion_flags & heap_exhausted == heap_exhausted {
eprintln!("\nResource exhaustion event: the JVM was unable to allocate memory from the heap.");
}
if resourceExhaustionFlags & threads_exhausted == threads_exhausted {
if resource_exhaustion_flags & threads_exhausted == threads_exhausted {
eprintln!("\nResource exhaustion event: the JVM was unable to create a thread.");
}

if self.heuristic.on_oom() {
for action in &self.actions {
action.on_oom(jni_env, resourceExhaustionFlags);
action.on_oom(jni_env, resource_exhaustion_flags);
}
} else {
} else if resource_exhaustion_flags & oom_error == oom_error {
eprintln!("\nThe JVM is about to throw a java.lang.OutOfMemoryError.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/agentcontroller/heaphistogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ impl HeapHistogram {
}

impl super::Action for HeapHistogram {
fn on_oom(&self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint) {
fn on_oom(&self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint) {
}
}
4 changes: 2 additions & 2 deletions src/agentcontroller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod controller;

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

mod heaphistogram;
Expand All @@ -32,5 +32,5 @@ trait Heuristic {

trait Action {
// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#jvmtiResourceExhaustionFlags
fn on_oom(&self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint);
fn on_oom(&self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint);
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl<'a> AgentContext<'a> {
self.ac = Some(a);
}

pub fn on_oom(&mut self, jni_env: ::env::JniEnv, resourceExhaustionFlags: ::jvmti::jint) {
self.ac.as_mut().map(|mut a| a.on_oom(jni_env, resourceExhaustionFlags));
pub fn on_oom(&mut self, jni_env: ::env::JniEnv, resource_exhaustion_flags: ::jvmti::jint) {
self.ac.as_mut().map(|mut a| a.on_oom(jni_env, resource_exhaustion_flags));
}
}

Expand Down

0 comments on commit dbda939

Please sign in to comment.