Mercurial > hg > graal-compiler
annotate src/share/vm/runtime/vmThread.cpp @ 14495:cd5d10655495
8027754: Enable loop optimizations for loops with MathExact inside
Reviewed-by: kvn, iveresov
author | rbackman |
---|---|
date | Thu, 23 Jan 2014 12:08:28 +0100 |
parents | e6195383bcaf |
children | f460c6926af7 |
rev | line source |
---|---|
0 | 1 /* |
7630
5ce621176715
8004903: VMThread::execute() calls Thread::check_for_valid_safepoint_state() on concurrent VM ops
dcubed
parents:
7180
diff
changeset
|
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "compiler/compileBroker.hpp" | |
27 #include "gc_interface/collectedHeap.hpp" | |
28 #include "memory/resourceArea.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6008
diff
changeset
|
29 #include "oops/method.hpp" |
1972 | 30 #include "oops/oop.inline.hpp" |
31 #include "runtime/interfaceSupport.hpp" | |
32 #include "runtime/mutexLocker.hpp" | |
33 #include "runtime/os.hpp" | |
7180
f34d701e952e
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
7179
diff
changeset
|
34 #include "runtime/thread.inline.hpp" |
1972 | 35 #include "runtime/vmThread.hpp" |
36 #include "runtime/vm_operations.hpp" | |
37 #include "services/runtimeService.hpp" | |
10405 | 38 #include "trace/tracing.hpp" |
1972 | 39 #include "utilities/dtrace.hpp" |
40 #include "utilities/events.hpp" | |
41 #include "utilities/xmlstream.hpp" | |
0 | 42 |
43 // Dummy VM operation to act as first element in our circular double-linked list | |
44 class VM_Dummy: public VM_Operation { | |
45 VMOp_Type type() const { return VMOp_Dummy; } | |
46 void doit() {}; | |
47 }; | |
48 | |
49 VMOperationQueue::VMOperationQueue() { | |
50 // The queue is a circular doubled-linked list, which always contains | |
51 // one element (i.e., one element means empty). | |
52 for(int i = 0; i < nof_priorities; i++) { | |
53 _queue_length[i] = 0; | |
54 _queue_counter = 0; | |
55 _queue[i] = new VM_Dummy(); | |
56 _queue[i]->set_next(_queue[i]); | |
57 _queue[i]->set_prev(_queue[i]); | |
58 } | |
59 _drain_list = NULL; | |
60 } | |
61 | |
62 | |
63 bool VMOperationQueue::queue_empty(int prio) { | |
64 // It is empty if there is exactly one element | |
65 bool empty = (_queue[prio] == _queue[prio]->next()); | |
66 assert( (_queue_length[prio] == 0 && empty) || | |
67 (_queue_length[prio] > 0 && !empty), "sanity check"); | |
68 return _queue_length[prio] == 0; | |
69 } | |
70 | |
71 // Inserts an element to the right of the q element | |
72 void VMOperationQueue::insert(VM_Operation* q, VM_Operation* n) { | |
73 assert(q->next()->prev() == q && q->prev()->next() == q, "sanity check"); | |
74 n->set_prev(q); | |
75 n->set_next(q->next()); | |
76 q->next()->set_prev(n); | |
77 q->set_next(n); | |
78 } | |
79 | |
80 void VMOperationQueue::queue_add_front(int prio, VM_Operation *op) { | |
81 _queue_length[prio]++; | |
82 insert(_queue[prio]->next(), op); | |
83 } | |
84 | |
85 void VMOperationQueue::queue_add_back(int prio, VM_Operation *op) { | |
86 _queue_length[prio]++; | |
87 insert(_queue[prio]->prev(), op); | |
88 } | |
89 | |
90 | |
91 void VMOperationQueue::unlink(VM_Operation* q) { | |
92 assert(q->next()->prev() == q && q->prev()->next() == q, "sanity check"); | |
93 q->prev()->set_next(q->next()); | |
94 q->next()->set_prev(q->prev()); | |
95 } | |
96 | |
97 VM_Operation* VMOperationQueue::queue_remove_front(int prio) { | |
98 if (queue_empty(prio)) return NULL; | |
99 assert(_queue_length[prio] >= 0, "sanity check"); | |
100 _queue_length[prio]--; | |
101 VM_Operation* r = _queue[prio]->next(); | |
102 assert(r != _queue[prio], "cannot remove base element"); | |
103 unlink(r); | |
104 return r; | |
105 } | |
106 | |
107 VM_Operation* VMOperationQueue::queue_drain(int prio) { | |
108 if (queue_empty(prio)) return NULL; | |
109 DEBUG_ONLY(int length = _queue_length[prio];); | |
110 assert(length >= 0, "sanity check"); | |
111 _queue_length[prio] = 0; | |
112 VM_Operation* r = _queue[prio]->next(); | |
113 assert(r != _queue[prio], "cannot remove base element"); | |
114 // remove links to base element from head and tail | |
115 r->set_prev(NULL); | |
116 _queue[prio]->prev()->set_next(NULL); | |
117 // restore queue to empty state | |
118 _queue[prio]->set_next(_queue[prio]); | |
119 _queue[prio]->set_prev(_queue[prio]); | |
1489
cff162798819
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
1324
diff
changeset
|
120 assert(queue_empty(prio), "drain corrupted queue"); |
9152 | 121 #ifdef ASSERT |
0 | 122 int len = 0; |
123 VM_Operation* cur; | |
124 for(cur = r; cur != NULL; cur=cur->next()) len++; | |
125 assert(len == length, "drain lost some ops"); | |
126 #endif | |
127 return r; | |
128 } | |
129 | |
130 void VMOperationQueue::queue_oops_do(int queue, OopClosure* f) { | |
131 VM_Operation* cur = _queue[queue]; | |
132 cur = cur->next(); | |
133 while (cur != _queue[queue]) { | |
134 cur->oops_do(f); | |
135 cur = cur->next(); | |
136 } | |
137 } | |
138 | |
139 void VMOperationQueue::drain_list_oops_do(OopClosure* f) { | |
140 VM_Operation* cur = _drain_list; | |
141 while (cur != NULL) { | |
142 cur->oops_do(f); | |
143 cur = cur->next(); | |
144 } | |
145 } | |
146 | |
147 //----------------------------------------------------------------- | |
148 // High-level interface | |
149 bool VMOperationQueue::add(VM_Operation *op) { | |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1260
diff
changeset
|
150 |
4006 | 151 HOTSPOT_VMOPS_REQUEST( |
152 (char *) op->name(), strlen(op->name()), | |
153 op->evaluation_mode()); | |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1260
diff
changeset
|
154 |
0 | 155 // Encapsulates VM queue policy. Currently, that |
156 // only involves putting them on the right list | |
157 if (op->evaluate_at_safepoint()) { | |
158 queue_add_back(SafepointPriority, op); | |
159 return true; | |
160 } | |
161 | |
162 queue_add_back(MediumPriority, op); | |
163 return true; | |
164 } | |
165 | |
166 VM_Operation* VMOperationQueue::remove_next() { | |
167 // Assuming VMOperation queue is two-level priority queue. If there are | |
168 // more than two priorities, we need a different scheduling algorithm. | |
169 assert(SafepointPriority == 0 && MediumPriority == 1 && nof_priorities == 2, | |
170 "current algorithm does not work"); | |
171 | |
172 // simple counter based scheduling to prevent starvation of lower priority | |
173 // queue. -- see 4390175 | |
174 int high_prio, low_prio; | |
175 if (_queue_counter++ < 10) { | |
176 high_prio = SafepointPriority; | |
177 low_prio = MediumPriority; | |
178 } else { | |
179 _queue_counter = 0; | |
180 high_prio = MediumPriority; | |
181 low_prio = SafepointPriority; | |
182 } | |
183 | |
184 return queue_remove_front(queue_empty(high_prio) ? low_prio : high_prio); | |
185 } | |
186 | |
187 void VMOperationQueue::oops_do(OopClosure* f) { | |
188 for(int i = 0; i < nof_priorities; i++) { | |
189 queue_oops_do(i, f); | |
190 } | |
191 drain_list_oops_do(f); | |
192 } | |
193 | |
194 | |
195 //------------------------------------------------------------------------------------------------------------------ | |
196 // Implementation of VMThread stuff | |
197 | |
198 bool VMThread::_should_terminate = false; | |
199 bool VMThread::_terminated = false; | |
200 Monitor* VMThread::_terminate_lock = NULL; | |
201 VMThread* VMThread::_vm_thread = NULL; | |
202 VM_Operation* VMThread::_cur_vm_operation = NULL; | |
203 VMOperationQueue* VMThread::_vm_queue = NULL; | |
204 PerfCounter* VMThread::_perf_accumulated_vm_operation_time = NULL; | |
205 | |
206 | |
207 void VMThread::create() { | |
208 assert(vm_thread() == NULL, "we can only allocate one VMThread"); | |
209 _vm_thread = new VMThread(); | |
210 | |
211 // Create VM operation queue | |
212 _vm_queue = new VMOperationQueue(); | |
213 guarantee(_vm_queue != NULL, "just checking"); | |
214 | |
215 _terminate_lock = new Monitor(Mutex::safepoint, "VMThread::_terminate_lock", true); | |
216 | |
217 if (UsePerfData) { | |
218 // jvmstat performance counters | |
219 Thread* THREAD = Thread::current(); | |
220 _perf_accumulated_vm_operation_time = | |
221 PerfDataManager::create_counter(SUN_THREADS, "vmOperationTime", | |
222 PerfData::U_Ticks, CHECK); | |
223 } | |
224 } | |
225 | |
226 | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
989
diff
changeset
|
227 VMThread::VMThread() : NamedThread() { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
989
diff
changeset
|
228 set_name("VM Thread"); |
0 | 229 } |
230 | |
231 void VMThread::destroy() { | |
232 if (_vm_thread != NULL) { | |
233 delete _vm_thread; | |
234 _vm_thread = NULL; // VM thread is gone | |
235 } | |
236 } | |
237 | |
238 void VMThread::run() { | |
239 assert(this == vm_thread(), "check"); | |
240 | |
241 this->initialize_thread_local_storage(); | |
242 this->record_stack_base_and_size(); | |
243 // Notify_lock wait checks on active_handles() to rewait in | |
244 // case of spurious wakeup, it should wait on the last | |
245 // value set prior to the notify | |
246 this->set_active_handles(JNIHandleBlock::allocate_block()); | |
247 | |
248 { | |
249 MutexLocker ml(Notify_lock); | |
250 Notify_lock->notify(); | |
251 } | |
252 // Notify_lock is destroyed by Threads::create_vm() | |
253 | |
254 int prio = (VMThreadPriority == -1) | |
255 ? os::java_to_os_priority[NearMaxPriority] | |
256 : VMThreadPriority; | |
257 // Note that I cannot call os::set_priority because it expects Java | |
258 // priorities and I am *explicitly* using OS priorities so that it's | |
259 // possible to set the VM thread priority higher than any Java thread. | |
260 os::set_native_priority( this, prio ); | |
261 | |
262 // Wait for VM_Operations until termination | |
263 this->loop(); | |
264 | |
265 // Note the intention to exit before safepointing. | |
266 // 6295565 This has the effect of waiting for any large tty | |
267 // outputs to finish. | |
268 if (xtty != NULL) { | |
269 ttyLocker ttyl; | |
270 xtty->begin_elem("destroy_vm"); | |
271 xtty->stamp(); | |
272 xtty->end_elem(); | |
273 assert(should_terminate(), "termination flag must be set"); | |
274 } | |
275 | |
276 // 4526887 let VM thread exit at Safepoint | |
277 SafepointSynchronize::begin(); | |
278 | |
279 if (VerifyBeforeExit) { | |
280 HandleMark hm(VMThread::vm_thread()); | |
281 // Among other things, this ensures that Eden top is correct. | |
282 Universe::heap()->prepare_for_verify(); | |
283 os::check_heap(); | |
3293
1f4413413144
7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents:
1972
diff
changeset
|
284 // Silent verification so as not to pollute normal output, |
1f4413413144
7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents:
1972
diff
changeset
|
285 // unless we really asked for it. |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
9152
diff
changeset
|
286 Universe::verify(!(PrintGCDetails || Verbose) || VerifySilently); |
0 | 287 } |
288 | |
289 CompileBroker::set_should_block(); | |
290 | |
291 // wait for threads (compiler threads or daemon threads) in the | |
292 // _thread_in_native state to block. | |
293 VM_Exit::wait_for_threads_in_native_to_block(); | |
294 | |
295 // signal other threads that VM process is gone | |
296 { | |
297 // Note: we must have the _no_safepoint_check_flag. Mutex::lock() allows | |
298 // VM thread to enter any lock at Safepoint as long as its _owner is NULL. | |
299 // If that happens after _terminate_lock->wait() has unset _owner | |
300 // but before it actually drops the lock and waits, the notification below | |
301 // may get lost and we will have a hang. To avoid this, we need to use | |
302 // Mutex::lock_without_safepoint_check(). | |
303 MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag); | |
304 _terminated = true; | |
305 _terminate_lock->notify(); | |
306 } | |
307 | |
308 // Deletion must be done synchronously by the JNI DestroyJavaVM thread | |
309 // so that the VMThread deletion completes before the main thread frees | |
310 // up the CodeHeap. | |
311 | |
312 } | |
313 | |
314 | |
315 // Notify the VMThread that the last non-daemon JavaThread has terminated, | |
316 // and wait until operation is performed. | |
317 void VMThread::wait_for_vm_thread_exit() { | |
318 { MutexLocker mu(VMOperationQueue_lock); | |
319 _should_terminate = true; | |
320 VMOperationQueue_lock->notify(); | |
321 } | |
322 | |
323 // Note: VM thread leaves at Safepoint. We are not stopped by Safepoint | |
324 // because this thread has been removed from the threads list. But anything | |
325 // that could get blocked by Safepoint should not be used after this point, | |
326 // otherwise we will hang, since there is no one can end the safepoint. | |
327 | |
328 // Wait until VM thread is terminated | |
329 // Note: it should be OK to use Terminator_lock here. But this is called | |
330 // at a very delicate time (VM shutdown) and we are operating in non- VM | |
331 // thread at Safepoint. It's safer to not share lock with other threads. | |
332 { MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag); | |
333 while(!VMThread::is_terminated()) { | |
334 _terminate_lock->wait(Mutex::_no_safepoint_check_flag); | |
335 } | |
336 } | |
337 } | |
338 | |
339 void VMThread::print_on(outputStream* st) const { | |
340 st->print("\"%s\" ", name()); | |
341 Thread::print_on(st); | |
342 st->cr(); | |
343 } | |
344 | |
345 void VMThread::evaluate_operation(VM_Operation* op) { | |
346 ResourceMark rm; | |
347 | |
348 { | |
349 PerfTraceTime vm_op_timer(perf_accumulated_vm_operation_time()); | |
4006 | 350 HOTSPOT_VMOPS_BEGIN( |
351 (char *) op->name(), strlen(op->name()), | |
352 op->evaluation_mode()); | |
10405 | 353 |
354 EventExecuteVMOperation event; | |
355 | |
0 | 356 op->evaluate(); |
10405 | 357 |
358 if (event.should_commit()) { | |
359 bool is_concurrent = op->evaluate_concurrently(); | |
360 event.set_operation(op->type()); | |
361 event.set_safepoint(op->evaluate_at_safepoint()); | |
362 event.set_blocking(!is_concurrent); | |
363 // Only write caller thread information for non-concurrent vm operations. | |
364 // For concurrent vm operations, the thread id is set to 0 indicating thread is unknown. | |
365 // This is because the caller thread could have exited already. | |
366 event.set_caller(is_concurrent ? 0 : op->calling_thread()->osthread()->thread_id()); | |
367 event.commit(); | |
368 } | |
369 | |
4006 | 370 HOTSPOT_VMOPS_END( |
371 (char *) op->name(), strlen(op->name()), | |
372 op->evaluation_mode()); | |
0 | 373 } |
374 | |
375 // Last access of info in _cur_vm_operation! | |
376 bool c_heap_allocated = op->is_cheap_allocated(); | |
377 | |
378 // Mark as completed | |
379 if (!op->evaluate_concurrently()) { | |
380 op->calling_thread()->increment_vm_operation_completed_count(); | |
381 } | |
382 // It is unsafe to access the _cur_vm_operation after the 'increment_vm_operation_completed_count' call, | |
383 // since if it is stack allocated the calling thread might have deallocated | |
384 if (c_heap_allocated) { | |
385 delete _cur_vm_operation; | |
386 } | |
387 } | |
388 | |
389 | |
390 void VMThread::loop() { | |
391 assert(_cur_vm_operation == NULL, "no current one should be executing"); | |
392 | |
393 while(true) { | |
394 VM_Operation* safepoint_ops = NULL; | |
395 // | |
396 // Wait for VM operation | |
397 // | |
398 // use no_safepoint_check to get lock without attempting to "sneak" | |
399 { MutexLockerEx mu_queue(VMOperationQueue_lock, | |
400 Mutex::_no_safepoint_check_flag); | |
401 | |
402 // Look for new operation | |
403 assert(_cur_vm_operation == NULL, "no current one should be executing"); | |
404 _cur_vm_operation = _vm_queue->remove_next(); | |
405 | |
406 // Stall time tracking code | |
407 if (PrintVMQWaitTime && _cur_vm_operation != NULL && | |
408 !_cur_vm_operation->evaluate_concurrently()) { | |
409 long stall = os::javaTimeMillis() - _cur_vm_operation->timestamp(); | |
410 if (stall > 0) | |
411 tty->print_cr("%s stall: %Ld", _cur_vm_operation->name(), stall); | |
412 } | |
413 | |
414 while (!should_terminate() && _cur_vm_operation == NULL) { | |
415 // wait with a timeout to guarantee safepoints at regular intervals | |
416 bool timedout = | |
417 VMOperationQueue_lock->wait(Mutex::_no_safepoint_check_flag, | |
418 GuaranteedSafepointInterval); | |
419 | |
420 // Support for self destruction | |
421 if ((SelfDestructTimer != 0) && !is_error_reported() && | |
422 (os::elapsedTime() > SelfDestructTimer * 60)) { | |
423 tty->print_cr("VM self-destructed"); | |
424 exit(-1); | |
425 } | |
426 | |
427 if (timedout && (SafepointALot || | |
428 SafepointSynchronize::is_cleanup_needed())) { | |
429 MutexUnlockerEx mul(VMOperationQueue_lock, | |
430 Mutex::_no_safepoint_check_flag); | |
431 // Force a safepoint since we have not had one for at least | |
432 // 'GuaranteedSafepointInterval' milliseconds. This will run all | |
433 // the clean-up processing that needs to be done regularly at a | |
434 // safepoint | |
435 SafepointSynchronize::begin(); | |
436 #ifdef ASSERT | |
437 if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot(); | |
438 #endif | |
439 SafepointSynchronize::end(); | |
440 } | |
441 _cur_vm_operation = _vm_queue->remove_next(); | |
442 | |
443 // If we are at a safepoint we will evaluate all the operations that | |
444 // follow that also require a safepoint | |
445 if (_cur_vm_operation != NULL && | |
446 _cur_vm_operation->evaluate_at_safepoint()) { | |
447 safepoint_ops = _vm_queue->drain_at_safepoint_priority(); | |
448 } | |
449 } | |
450 | |
451 if (should_terminate()) break; | |
452 } // Release mu_queue_lock | |
453 | |
454 // | |
455 // Execute VM operation | |
456 // | |
457 { HandleMark hm(VMThread::vm_thread()); | |
458 | |
459 EventMark em("Executing VM operation: %s", vm_operation()->name()); | |
460 assert(_cur_vm_operation != NULL, "we should have found an operation to execute"); | |
461 | |
462 // Give the VM thread an extra quantum. Jobs tend to be bursty and this | |
463 // helps the VM thread to finish up the job. | |
464 // FIXME: When this is enabled and there are many threads, this can degrade | |
465 // performance significantly. | |
466 if( VMThreadHintNoPreempt ) | |
467 os::hint_no_preempt(); | |
468 | |
469 // If we are at a safepoint we will evaluate all the operations that | |
470 // follow that also require a safepoint | |
471 if (_cur_vm_operation->evaluate_at_safepoint()) { | |
472 | |
473 _vm_queue->set_drain_list(safepoint_ops); // ensure ops can be scanned | |
474 | |
475 SafepointSynchronize::begin(); | |
476 evaluate_operation(_cur_vm_operation); | |
477 // now process all queued safepoint ops, iteratively draining | |
478 // the queue until there are none left | |
479 do { | |
480 _cur_vm_operation = safepoint_ops; | |
481 if (_cur_vm_operation != NULL) { | |
482 do { | |
483 // evaluate_operation deletes the op object so we have | |
484 // to grab the next op now | |
485 VM_Operation* next = _cur_vm_operation->next(); | |
486 _vm_queue->set_drain_list(next); | |
487 evaluate_operation(_cur_vm_operation); | |
488 _cur_vm_operation = next; | |
489 if (PrintSafepointStatistics) { | |
490 SafepointSynchronize::inc_vmop_coalesced_count(); | |
491 } | |
492 } while (_cur_vm_operation != NULL); | |
493 } | |
494 // There is a chance that a thread enqueued a safepoint op | |
495 // since we released the op-queue lock and initiated the safepoint. | |
496 // So we drain the queue again if there is anything there, as an | |
497 // optimization to try and reduce the number of safepoints. | |
498 // As the safepoint synchronizes us with JavaThreads we will see | |
499 // any enqueue made by a JavaThread, but the peek will not | |
500 // necessarily detect a concurrent enqueue by a GC thread, but | |
501 // that simply means the op will wait for the next major cycle of the | |
502 // VMThread - just as it would if the GC thread lost the race for | |
503 // the lock. | |
504 if (_vm_queue->peek_at_safepoint_priority()) { | |
505 // must hold lock while draining queue | |
506 MutexLockerEx mu_queue(VMOperationQueue_lock, | |
507 Mutex::_no_safepoint_check_flag); | |
508 safepoint_ops = _vm_queue->drain_at_safepoint_priority(); | |
509 } else { | |
510 safepoint_ops = NULL; | |
511 } | |
512 } while(safepoint_ops != NULL); | |
513 | |
514 _vm_queue->set_drain_list(NULL); | |
515 | |
516 // Complete safepoint synchronization | |
517 SafepointSynchronize::end(); | |
518 | |
519 } else { // not a safepoint operation | |
520 if (TraceLongCompiles) { | |
521 elapsedTimer t; | |
522 t.start(); | |
523 evaluate_operation(_cur_vm_operation); | |
524 t.stop(); | |
525 double secs = t.seconds(); | |
526 if (secs * 1e3 > LongCompileThreshold) { | |
527 // XXX - _cur_vm_operation should not be accessed after | |
528 // the completed count has been incremented; the waiting | |
529 // thread may have already freed this memory. | |
530 tty->print_cr("vm %s: %3.7f secs]", _cur_vm_operation->name(), secs); | |
531 } | |
532 } else { | |
533 evaluate_operation(_cur_vm_operation); | |
534 } | |
535 | |
536 _cur_vm_operation = NULL; | |
537 } | |
538 } | |
539 | |
540 // | |
541 // Notify (potential) waiting Java thread(s) - lock without safepoint | |
542 // check so that sneaking is not possible | |
543 { MutexLockerEx mu(VMOperationRequest_lock, | |
544 Mutex::_no_safepoint_check_flag); | |
545 VMOperationRequest_lock->notify_all(); | |
546 } | |
547 | |
548 // | |
549 // We want to make sure that we get to a safepoint regularly. | |
550 // | |
551 if (SafepointALot || SafepointSynchronize::is_cleanup_needed()) { | |
552 long interval = SafepointSynchronize::last_non_safepoint_interval(); | |
553 bool max_time_exceeded = GuaranteedSafepointInterval != 0 && (interval > GuaranteedSafepointInterval); | |
554 if (SafepointALot || max_time_exceeded) { | |
555 HandleMark hm(VMThread::vm_thread()); | |
556 SafepointSynchronize::begin(); | |
557 SafepointSynchronize::end(); | |
558 } | |
559 } | |
560 } | |
561 } | |
562 | |
563 void VMThread::execute(VM_Operation* op) { | |
564 Thread* t = Thread::current(); | |
565 | |
566 if (!t->is_VM_thread()) { | |
806
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
0
diff
changeset
|
567 SkipGCALot sgcalot(t); // avoid re-entrant attempts to gc-a-lot |
0 | 568 // JavaThread or WatcherThread |
7630
5ce621176715
8004903: VMThread::execute() calls Thread::check_for_valid_safepoint_state() on concurrent VM ops
dcubed
parents:
7180
diff
changeset
|
569 bool concurrent = op->evaluate_concurrently(); |
5ce621176715
8004903: VMThread::execute() calls Thread::check_for_valid_safepoint_state() on concurrent VM ops
dcubed
parents:
7180
diff
changeset
|
570 // only blocking VM operations need to verify the caller's safepoint state: |
5ce621176715
8004903: VMThread::execute() calls Thread::check_for_valid_safepoint_state() on concurrent VM ops
dcubed
parents:
7180
diff
changeset
|
571 if (!concurrent) { |
5ce621176715
8004903: VMThread::execute() calls Thread::check_for_valid_safepoint_state() on concurrent VM ops
dcubed
parents:
7180
diff
changeset
|
572 t->check_for_valid_safepoint_state(true); |
5ce621176715
8004903: VMThread::execute() calls Thread::check_for_valid_safepoint_state() on concurrent VM ops
dcubed
parents:
7180
diff
changeset
|
573 } |
0 | 574 |
575 // New request from Java thread, evaluate prologue | |
576 if (!op->doit_prologue()) { | |
577 return; // op was cancelled | |
578 } | |
579 | |
580 // Setup VM_operations for execution | |
581 op->set_calling_thread(t, Thread::get_priority(t)); | |
582 | |
583 // It does not make sense to execute the epilogue, if the VM operation object is getting | |
584 // deallocated by the VM thread. | |
585 bool execute_epilog = !op->is_cheap_allocated(); | |
586 assert(!concurrent || op->is_cheap_allocated(), "concurrent => cheap_allocated"); | |
587 | |
588 // Get ticket number for non-concurrent VM operations | |
589 int ticket = 0; | |
590 if (!concurrent) { | |
591 ticket = t->vm_operation_ticket(); | |
592 } | |
593 | |
594 // Add VM operation to list of waiting threads. We are guaranteed not to block while holding the | |
595 // VMOperationQueue_lock, so we can block without a safepoint check. This allows vm operation requests | |
596 // to be queued up during a safepoint synchronization. | |
597 { | |
598 VMOperationQueue_lock->lock_without_safepoint_check(); | |
599 bool ok = _vm_queue->add(op); | |
10405 | 600 op->set_timestamp(os::javaTimeMillis()); |
0 | 601 VMOperationQueue_lock->notify(); |
602 VMOperationQueue_lock->unlock(); | |
603 // VM_Operation got skipped | |
604 if (!ok) { | |
605 assert(concurrent, "can only skip concurrent tasks"); | |
606 if (op->is_cheap_allocated()) delete op; | |
607 return; | |
608 } | |
609 } | |
610 | |
611 if (!concurrent) { | |
612 // Wait for completion of request (non-concurrent) | |
613 // Note: only a JavaThread triggers the safepoint check when locking | |
614 MutexLocker mu(VMOperationRequest_lock); | |
615 while(t->vm_operation_completed_count() < ticket) { | |
616 VMOperationRequest_lock->wait(!t->is_Java_thread()); | |
617 } | |
618 } | |
619 | |
620 if (execute_epilog) { | |
621 op->doit_epilogue(); | |
622 } | |
623 } else { | |
624 // invoked by VM thread; usually nested VM operation | |
625 assert(t->is_VM_thread(), "must be a VM thread"); | |
626 VM_Operation* prev_vm_operation = vm_operation(); | |
627 if (prev_vm_operation != NULL) { | |
628 // Check the VM operation allows nested VM operation. This normally not the case, e.g., the compiler | |
629 // does not allow nested scavenges or compiles. | |
630 if (!prev_vm_operation->allow_nested_vm_operations()) { | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1489
diff
changeset
|
631 fatal(err_msg("Nested VM operation %s requested by operation %s", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1489
diff
changeset
|
632 op->name(), vm_operation()->name())); |
0 | 633 } |
634 op->set_calling_thread(prev_vm_operation->calling_thread(), prev_vm_operation->priority()); | |
635 } | |
636 | |
637 EventMark em("Executing %s VM operation: %s", prev_vm_operation ? "nested" : "", op->name()); | |
638 | |
639 // Release all internal handles after operation is evaluated | |
640 HandleMark hm(t); | |
641 _cur_vm_operation = op; | |
642 | |
643 if (op->evaluate_at_safepoint() && !SafepointSynchronize::is_at_safepoint()) { | |
644 SafepointSynchronize::begin(); | |
645 op->evaluate(); | |
646 SafepointSynchronize::end(); | |
647 } else { | |
648 op->evaluate(); | |
649 } | |
650 | |
651 // Free memory if needed | |
652 if (op->is_cheap_allocated()) delete op; | |
653 | |
654 _cur_vm_operation = prev_vm_operation; | |
655 } | |
656 } | |
657 | |
658 | |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
6725
diff
changeset
|
659 void VMThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
6725
diff
changeset
|
660 Thread::oops_do(f, cld_f, cf); |
0 | 661 _vm_queue->oops_do(f); |
662 } | |
663 | |
664 //------------------------------------------------------------------------------------------------------------------ | |
665 #ifndef PRODUCT | |
666 | |
667 void VMOperationQueue::verify_queue(int prio) { | |
668 // Check that list is correctly linked | |
669 int length = _queue_length[prio]; | |
670 VM_Operation *cur = _queue[prio]; | |
671 int i; | |
672 | |
673 // Check forward links | |
674 for(i = 0; i < length; i++) { | |
675 cur = cur->next(); | |
676 assert(cur != _queue[prio], "list to short (forward)"); | |
677 } | |
678 assert(cur->next() == _queue[prio], "list to long (forward)"); | |
679 | |
680 // Check backwards links | |
681 cur = _queue[prio]; | |
682 for(i = 0; i < length; i++) { | |
683 cur = cur->prev(); | |
684 assert(cur != _queue[prio], "list to short (backwards)"); | |
685 } | |
686 assert(cur->prev() == _queue[prio], "list to long (backwards)"); | |
687 } | |
688 | |
689 #endif | |
690 | |
691 void VMThread::verify() { | |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
6725
diff
changeset
|
692 oops_do(&VerifyOopClosure::verify_oop, NULL, NULL); |
0 | 693 } |