src/share/vm/services/lowMemoryDetector.cpp
Print this page
@@ -294,24 +294,46 @@
assert(count <= _pending_trigger_count, "just checking");
if (_sensor_obj != NULL) {
Klass* k = Management::sun_management_Sensor_klass(CHECK);
instanceKlassHandle sensorKlass (THREAD, k);
Handle sensor_h(THREAD, _sensor_obj);
- Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, CHECK);
+ Symbol* trigger_method_signature;
+
JavaValue result(T_VOID);
JavaCallArguments args(sensor_h);
args.push_int((int) count);
+
+ Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, THREAD);
+ // call Sensor::trigger(int, MemoryUsage) to send notification to listeners.
+ // when OOME occurs and fails to allocate MemoryUsage object, call
+ // Sensor::trigger(int) instead. The pending request will be processed
+ // but no notification will be sent.
+ if (HAS_PENDING_EXCEPTION) {
+ assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOME here");
+ CLEAR_PENDING_EXCEPTION;
+ trigger_method_signature = vmSymbols::int_void_signature();
+ } else {
+ trigger_method_signature = vmSymbols::trigger_method_signature();
args.push_oop(usage_h);
+ }
JavaCalls::call_virtual(&result,
sensorKlass,
vmSymbols::trigger_name(),
- vmSymbols::trigger_method_signature(),
+ trigger_method_signature,
&args,
- CHECK);
+ THREAD);
+
+ if (HAS_PENDING_EXCEPTION) {
+ // we just clear the OOM pending exception that we might have encountered
+ // in Java's tiggerAction(), and continue with updating the counters since
+ // the Java counters have been updated too.
+ assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOME here");
+ CLEAR_PENDING_EXCEPTION;
}
+ }
{
// Holds Service_lock and update the sensor state
MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
assert(_pending_trigger_count > 0, "Must have pending trigger");