comparison src/share/vm/runtime/advancedThresholdPolicy.cpp @ 20465:7301840ea20e

8023461: Thread holding lock at safepoint that vm can block on: MethodCompileQueue_lock Reviewed-by: kvn, iveresov
author vlivanov
date Tue, 11 Mar 2014 15:06:34 +0400
parents 7150b16fda52
children 41dcdd636080
comparison
equal deleted inserted replaced
20464:b2029969cc16 20465:7301840ea20e
73 set_start_time(os::javaTimeMillis()); 73 set_start_time(os::javaTimeMillis());
74 } 74 }
75 75
76 // update_rate() is called from select_task() while holding a compile queue lock. 76 // update_rate() is called from select_task() while holding a compile queue lock.
77 void AdvancedThresholdPolicy::update_rate(jlong t, Method* m) { 77 void AdvancedThresholdPolicy::update_rate(jlong t, Method* m) {
78 JavaThread* THREAD = JavaThread::current(); 78 // Skip update if counters are absent.
79 // Can't allocate them since we are holding compile queue lock.
80 if (m->method_counters() == NULL) return;
81
79 if (is_old(m)) { 82 if (is_old(m)) {
80 // We don't remove old methods from the queue, 83 // We don't remove old methods from the queue,
81 // so we can just zero the rate. 84 // so we can just zero the rate.
82 m->set_rate(0, THREAD); 85 m->set_rate(0);
83 return; 86 return;
84 } 87 }
85 88
86 // We don't update the rate if we've just came out of a safepoint. 89 // We don't update the rate if we've just came out of a safepoint.
87 // delta_s is the time since last safepoint in milliseconds. 90 // delta_s is the time since last safepoint in milliseconds.
93 96
94 // We should be running for at least 1ms. 97 // We should be running for at least 1ms.
95 if (delta_s >= TieredRateUpdateMinTime) { 98 if (delta_s >= TieredRateUpdateMinTime) {
96 // And we must've taken the previous point at least 1ms before. 99 // And we must've taken the previous point at least 1ms before.
97 if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) { 100 if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) {
98 m->set_prev_time(t, THREAD); 101 m->set_prev_time(t);
99 m->set_prev_event_count(event_count, THREAD); 102 m->set_prev_event_count(event_count);
100 m->set_rate((float)delta_e / (float)delta_t, THREAD); // Rate is events per millisecond 103 m->set_rate((float)delta_e / (float)delta_t); // Rate is events per millisecond
101 } else 104 } else {
102 if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) { 105 if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) {
103 // If nothing happened for 25ms, zero the rate. Don't modify prev values. 106 // If nothing happened for 25ms, zero the rate. Don't modify prev values.
104 m->set_rate(0, THREAD); 107 m->set_rate(0);
105 } 108 }
109 }
106 } 110 }
107 } 111 }
108 112
109 // Check if this method has been stale from a given number of milliseconds. 113 // Check if this method has been stale from a given number of milliseconds.
110 // See select_task(). 114 // See select_task().
162 jlong t = os::javaTimeMillis(); 166 jlong t = os::javaTimeMillis();
163 // Iterate through the queue and find a method with a maximum rate. 167 // Iterate through the queue and find a method with a maximum rate.
164 for (CompileTask* task = compile_queue->first(); task != NULL;) { 168 for (CompileTask* task = compile_queue->first(); task != NULL;) {
165 CompileTask* next_task = task->next(); 169 CompileTask* next_task = task->next();
166 Method* method = task->method(); 170 Method* method = task->method();
167 MethodData* mdo = method->method_data();
168 update_rate(t, method); 171 update_rate(t, method);
169 if (max_task == NULL) { 172 if (max_task == NULL) {
170 max_task = task; 173 max_task = task;
171 max_method = method; 174 max_method = method;
172 } else { 175 } else {
173 // If a method has been stale for some time, remove it from the queue. 176 // If a method has been stale for some time, remove it from the queue.
174 if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) { 177 if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
175 if (PrintTieredEvents) { 178 if (PrintTieredEvents) {
176 print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level()); 179 print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
177 } 180 }
178 CompileTaskWrapper ctw(task); // Frees the task 181 compile_queue->remove_and_mark_stale(task);
179 compile_queue->remove(task);
180 method->clear_queued_for_compilation(); 182 method->clear_queued_for_compilation();
181 task = next_task; 183 task = next_task;
182 continue; 184 continue;
183 } 185 }
184 186