279 void SensorInfo::oops_do(OopClosure* f) { 280 f->do_oop((oop*) &_sensor_obj); 281 } 282 283 void SensorInfo::process_pending_requests(TRAPS) { 284 int pending_count = pending_trigger_count(); 285 if (pending_clear_count() > 0) { 286 clear(pending_count, CHECK); 287 } else { 288 trigger(pending_count, CHECK); 289 } 290 291 } 292 293 void SensorInfo::trigger(int count, TRAPS) { 294 assert(count <= _pending_trigger_count, "just checking"); 295 if (_sensor_obj != NULL) { 296 Klass* k = Management::sun_management_Sensor_klass(CHECK); 297 instanceKlassHandle sensorKlass (THREAD, k); 298 Handle sensor_h(THREAD, _sensor_obj); 299 Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, CHECK); 300 301 JavaValue result(T_VOID); 302 JavaCallArguments args(sensor_h); 303 args.push_int((int) count); 304 args.push_oop(usage_h); 305 306 JavaCalls::call_virtual(&result, 307 sensorKlass, 308 vmSymbols::trigger_name(), 309 vmSymbols::trigger_method_signature(), 310 &args, 311 CHECK); 312 } 313 314 { 315 // Holds Service_lock and update the sensor state 316 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); 317 assert(_pending_trigger_count > 0, "Must have pending trigger"); 318 _sensor_on = true; 319 _sensor_count += count; 320 _pending_trigger_count = _pending_trigger_count - count; 321 } 322 } 323 324 void SensorInfo::clear(int count, TRAPS) { 325 { 326 // Holds Service_lock and update the sensor state 327 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); 328 if (_pending_clear_count == 0) { 329 // Bail out if we lost a race to set_*_sensor_level() which may have 330 // reactivated the sensor in the meantime because it was triggered again. 331 return; 332 } | 279 void SensorInfo::oops_do(OopClosure* f) { 280 f->do_oop((oop*) &_sensor_obj); 281 } 282 283 void SensorInfo::process_pending_requests(TRAPS) { 284 int pending_count = pending_trigger_count(); 285 if (pending_clear_count() > 0) { 286 clear(pending_count, CHECK); 287 } else { 288 trigger(pending_count, CHECK); 289 } 290 291 } 292 293 void SensorInfo::trigger(int count, TRAPS) { 294 assert(count <= _pending_trigger_count, "just checking"); 295 if (_sensor_obj != NULL) { 296 Klass* k = Management::sun_management_Sensor_klass(CHECK); 297 instanceKlassHandle sensorKlass (THREAD, k); 298 Handle sensor_h(THREAD, _sensor_obj); 299 300 Symbol* trigger_method_signature; 301 302 JavaValue result(T_VOID); 303 JavaCallArguments args(sensor_h); 304 args.push_int((int) count); 305 306 Handle usage_h = MemoryService::create_MemoryUsage_obj(_usage, THREAD); 307 // call Sensor::trigger(int, MemoryUsage) to send notification to listeners. 308 // when OOME occurs and fails to allocate MemoryUsage object, call 309 // Sensor::trigger(int) instead. The pending request will be processed 310 // but no notification will be sent. 311 if (HAS_PENDING_EXCEPTION) { 312 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOME here"); 313 CLEAR_PENDING_EXCEPTION; 314 trigger_method_signature = vmSymbols::int_void_signature(); 315 } else { 316 trigger_method_signature = vmSymbols::trigger_method_signature(); 317 args.push_oop(usage_h); 318 } 319 320 JavaCalls::call_virtual(&result, 321 sensorKlass, 322 vmSymbols::trigger_name(), 323 trigger_method_signature, 324 &args, 325 THREAD); 326 327 if (HAS_PENDING_EXCEPTION) { 328 // we just clear the OOM pending exception that we might have encountered 329 // in Java's tiggerAction(), and continue with updating the counters since 330 // the Java counters have been updated too. 331 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOME here"); 332 CLEAR_PENDING_EXCEPTION; 333 } 334 } 335 336 { 337 // Holds Service_lock and update the sensor state 338 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); 339 assert(_pending_trigger_count > 0, "Must have pending trigger"); 340 _sensor_on = true; 341 _sensor_count += count; 342 _pending_trigger_count = _pending_trigger_count - count; 343 } 344 } 345 346 void SensorInfo::clear(int count, TRAPS) { 347 { 348 // Holds Service_lock and update the sensor state 349 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); 350 if (_pending_clear_count == 0) { 351 // Bail out if we lost a race to set_*_sensor_level() which may have 352 // reactivated the sensor in the meantime because it was triggered again. 353 return; 354 } |