src/share/vm/services/lowMemoryDetector.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
6766644 Cdiff src/share/vm/services/lowMemoryDetector.cpp
src/share/vm/services/lowMemoryDetector.cpp
Print this page
rev 2029 : 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
Summary: Defer posting events from the compiler thread -- use service thread
Reviewed-by:
* * *
*** 1,7 ****
/*
! * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 32,90 ****
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"
#include "services/lowMemoryDetector.hpp"
#include "services/management.hpp"
- LowMemoryDetectorThread* LowMemoryDetector::_detector_thread = NULL;
volatile bool LowMemoryDetector::_enabled_for_collected_pools = false;
volatile jint LowMemoryDetector::_disabled_count = 0;
- void LowMemoryDetector::initialize() {
- EXCEPTION_MARK;
-
- instanceKlassHandle klass (THREAD, SystemDictionary::Thread_klass());
- instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
-
- const char thread_name[] = "Low Memory Detector";
- Handle string = java_lang_String::create_from_str(thread_name, CHECK);
-
- // Initialize thread_oop to put it into the system threadGroup
- Handle thread_group (THREAD, Universe::system_thread_group());
- JavaValue result(T_VOID);
- JavaCalls::call_special(&result, thread_oop,
- klass,
- vmSymbolHandles::object_initializer_name(),
- vmSymbolHandles::threadgroup_string_void_signature(),
- thread_group,
- string,
- CHECK);
-
- {
- MutexLocker mu(Threads_lock);
- _detector_thread = new LowMemoryDetectorThread(&low_memory_detector_thread_entry);
-
- // At this point it may be possible that no osthread was created for the
- // JavaThread due to lack of memory. We would have to throw an exception
- // in that case. However, since this must work and we do not allow
- // exceptions anyway, check and abort if this fails.
- if (_detector_thread == NULL || _detector_thread->osthread() == NULL) {
- vm_exit_during_initialization("java.lang.OutOfMemoryError",
- "unable to create new native thread");
- }
-
- java_lang_Thread::set_thread(thread_oop(), _detector_thread);
- java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
- java_lang_Thread::set_daemon(thread_oop());
- _detector_thread->set_threadObj(thread_oop());
-
- Threads::add(_detector_thread);
- Thread::start(_detector_thread);
- }
- }
-
bool LowMemoryDetector::has_pending_requests() {
! assert(LowMemory_lock->owned_by_self(), "Must own LowMemory_lock");
bool has_requests = false;
int num_memory_pools = MemoryService::num_memory_pools();
for (int i = 0; i < num_memory_pools; i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
SensorInfo* sensor = pool->usage_sensor();
--- 32,46 ----
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"
#include "services/lowMemoryDetector.hpp"
#include "services/management.hpp"
volatile bool LowMemoryDetector::_enabled_for_collected_pools = false;
volatile jint LowMemoryDetector::_disabled_count = 0;
bool LowMemoryDetector::has_pending_requests() {
! assert(Service_lock->owned_by_self(), "Must own Service_lock");
bool has_requests = false;
int num_memory_pools = MemoryService::num_memory_pools();
for (int i = 0; i < num_memory_pools; i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
SensorInfo* sensor = pool->usage_sensor();
*** 98,136 ****
}
}
return has_requests;
}
! void LowMemoryDetector::low_memory_detector_thread_entry(JavaThread* jt, TRAPS) {
! while (true) {
! bool sensors_changed = false;
!
! {
! // _no_safepoint_check_flag is used here as LowMemory_lock is a
! // special lock and the VMThread may acquire this lock at safepoint.
! // Need state transition ThreadBlockInVM so that this thread
! // will be handled by safepoint correctly when this thread is
! // notified at a safepoint.
!
! // This ThreadBlockInVM object is not also considered to be
! // suspend-equivalent because LowMemoryDetector threads are
! // not visible to external suspension.
!
! ThreadBlockInVM tbivm(jt);
!
! MutexLockerEx ml(LowMemory_lock, Mutex::_no_safepoint_check_flag);
! while (!(sensors_changed = has_pending_requests())) {
! // wait until one of the sensors has pending requests
! LowMemory_lock->wait(Mutex::_no_safepoint_check_flag);
! }
! }
!
! {
ResourceMark rm(THREAD);
HandleMark hm(THREAD);
! // No need to hold LowMemory_lock to call out to Java
int num_memory_pools = MemoryService::num_memory_pools();
for (int i = 0; i < num_memory_pools; i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
SensorInfo* sensor = pool->usage_sensor();
SensorInfo* gc_sensor = pool->gc_usage_sensor();
--- 54,68 ----
}
}
return has_requests;
}
! void LowMemoryDetector::process_sensor_changes(TRAPS) {
ResourceMark rm(THREAD);
HandleMark hm(THREAD);
! // No need to hold Service_lock to call out to Java
int num_memory_pools = MemoryService::num_memory_pools();
for (int i = 0; i < num_memory_pools; i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
SensorInfo* sensor = pool->usage_sensor();
SensorInfo* gc_sensor = pool->gc_usage_sensor();
*** 139,156 ****
}
if (gc_sensor != NULL && gc_sensor->has_pending_requests()) {
gc_sensor->process_pending_requests(CHECK);
}
}
- }
- }
}
// This method could be called from any Java threads
// and also VMThread.
void LowMemoryDetector::detect_low_memory() {
! MutexLockerEx ml(LowMemory_lock, Mutex::_no_safepoint_check_flag);
bool has_pending_requests = false;
int num_memory_pools = MemoryService::num_memory_pools();
for (int i = 0; i < num_memory_pools; i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
--- 71,86 ----
}
if (gc_sensor != NULL && gc_sensor->has_pending_requests()) {
gc_sensor->process_pending_requests(CHECK);
}
}
}
// This method could be called from any Java threads
// and also VMThread.
void LowMemoryDetector::detect_low_memory() {
! MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
bool has_pending_requests = false;
int num_memory_pools = MemoryService::num_memory_pools();
for (int i = 0; i < num_memory_pools; i++) {
MemoryPool* pool = MemoryService::get_memory_pool(i);
*** 164,174 ****
has_pending_requests = has_pending_requests || sensor->has_pending_requests();
}
}
if (has_pending_requests) {
! LowMemory_lock->notify_all();
}
}
// This method could be called from any Java threads
// and also VMThread.
--- 94,104 ----
has_pending_requests = has_pending_requests || sensor->has_pending_requests();
}
}
if (has_pending_requests) {
! Service_lock->notify_all();
}
}
// This method could be called from any Java threads
// and also VMThread.
*** 179,196 ****
pool->usage_threshold()->high_threshold() == 0) {
return;
}
{
! MutexLockerEx ml(LowMemory_lock, Mutex::_no_safepoint_check_flag);
MemoryUsage usage = pool->get_memory_usage();
sensor->set_gauge_sensor_level(usage,
pool->usage_threshold());
if (sensor->has_pending_requests()) {
// notify sensor state update
! LowMemory_lock->notify_all();
}
}
}
// Only called by VMThread at GC time
--- 109,126 ----
pool->usage_threshold()->high_threshold() == 0) {
return;
}
{
! MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
MemoryUsage usage = pool->get_memory_usage();
sensor->set_gauge_sensor_level(usage,
pool->usage_threshold());
if (sensor->has_pending_requests()) {
// notify sensor state update
! Service_lock->notify_all();
}
}
}
// Only called by VMThread at GC time
*** 201,218 ****
pool->gc_usage_threshold()->high_threshold() == 0) {
return;
}
{
! MutexLockerEx ml(LowMemory_lock, Mutex::_no_safepoint_check_flag);
MemoryUsage usage = pool->get_last_collection_usage();
sensor->set_counter_sensor_level(usage, pool->gc_usage_threshold());
if (sensor->has_pending_requests()) {
// notify sensor state update
! LowMemory_lock->notify_all();
}
}
}
// recompute enabled flag
--- 131,148 ----
pool->gc_usage_threshold()->high_threshold() == 0) {
return;
}
{
! MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
MemoryUsage usage = pool->get_last_collection_usage();
sensor->set_counter_sensor_level(usage, pool->gc_usage_threshold());
if (sensor->has_pending_requests()) {
// notify sensor state update
! Service_lock->notify_all();
}
}
}
// recompute enabled flag
*** 382,393 ****
&args,
CHECK);
}
{
! // Holds LowMemory_lock and update the sensor state
! MutexLockerEx ml(LowMemory_lock, Mutex::_no_safepoint_check_flag);
_sensor_on = true;
_sensor_count += count;
_pending_trigger_count = _pending_trigger_count - count;
}
}
--- 312,323 ----
&args,
CHECK);
}
{
! // Holds Service_lock and update the sensor state
! MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
_sensor_on = true;
_sensor_count += count;
_pending_trigger_count = _pending_trigger_count - count;
}
}
*** 408,419 ****
&args,
CHECK);
}
{
! // Holds LowMemory_lock and update the sensor state
! MutexLockerEx ml(LowMemory_lock, Mutex::_no_safepoint_check_flag);
_sensor_on = false;
_pending_clear_count = 0;
_pending_trigger_count = _pending_trigger_count - count;
}
}
--- 338,349 ----
&args,
CHECK);
}
{
! // Holds Service_lock and update the sensor state
! MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
_sensor_on = false;
_pending_clear_count = 0;
_pending_trigger_count = _pending_trigger_count - count;
}
}
src/share/vm/services/lowMemoryDetector.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File