1 /* |
1 /* |
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
296 |
296 |
297 if (_sensor_obj != NULL) { |
297 if (_sensor_obj != NULL) { |
298 Klass* k = Management::sun_management_Sensor_klass(CHECK); |
298 Klass* k = Management::sun_management_Sensor_klass(CHECK); |
299 instanceKlassHandle sensorKlass (THREAD, k); |
299 instanceKlassHandle sensorKlass (THREAD, k); |
300 Handle sensor_h(THREAD, _sensor_obj); |
300 Handle sensor_h(THREAD, _sensor_obj); |
301 Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, CHECK); |
301 |
|
302 Symbol* trigger_method_signature; |
302 |
303 |
303 JavaValue result(T_VOID); |
304 JavaValue result(T_VOID); |
304 JavaCallArguments args(sensor_h); |
305 JavaCallArguments args(sensor_h); |
305 args.push_int((int) count); |
306 args.push_int((int) count); |
306 args.push_oop(usage_h); |
307 |
|
308 Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, THREAD); |
|
309 // Call Sensor::trigger(int, MemoryUsage) to send notification to listeners. |
|
310 // When OOME occurs and fails to allocate MemoryUsage object, call |
|
311 // Sensor::trigger(int) instead. The pending request will be processed |
|
312 // but no notification will be sent. |
|
313 if (HAS_PENDING_EXCEPTION) { |
|
314 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOME here"); |
|
315 CLEAR_PENDING_EXCEPTION; |
|
316 trigger_method_signature = vmSymbols::int_void_signature(); |
|
317 } else { |
|
318 trigger_method_signature = vmSymbols::trigger_method_signature(); |
|
319 args.push_oop(usage_h); |
|
320 } |
307 |
321 |
308 JavaCalls::call_virtual(&result, |
322 JavaCalls::call_virtual(&result, |
309 sensorKlass, |
323 sensorKlass, |
310 vmSymbols::trigger_name(), |
324 vmSymbols::trigger_name(), |
311 vmSymbols::trigger_method_signature(), |
325 trigger_method_signature, |
312 &args, |
326 &args, |
313 CHECK); |
327 THREAD); |
|
328 |
|
329 if (HAS_PENDING_EXCEPTION) { |
|
330 // We just clear the OOM pending exception that we might have encountered |
|
331 // in Java's tiggerAction(), and continue with updating the counters since |
|
332 // the Java counters have been updated too. |
|
333 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOME here"); |
|
334 CLEAR_PENDING_EXCEPTION; |
|
335 } |
314 } |
336 } |
315 |
337 |
316 { |
338 { |
317 // Holds Service_lock and update the sensor state |
339 // Holds Service_lock and update the sensor state |
318 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); |
340 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); |