comparison src/share/vm/compiler/abstractCompiler.cpp @ 12880:469216acdb28

8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash Summary: Ensure ensure correct initialization of compiler runtime Reviewed-by: kvn, twisti
author anoll
date Thu, 10 Oct 2013 15:44:12 +0200
parents 68c5a4e8881d
children de6a9e811145
comparison
equal deleted inserted replaced
12876:8b80b262e501 12880:469216acdb28
22 // 22 //
23 23
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "compiler/abstractCompiler.hpp" 26 #include "compiler/abstractCompiler.hpp"
27 #include "compiler/compileBroker.hpp"
27 #include "runtime/mutexLocker.hpp" 28 #include "runtime/mutexLocker.hpp"
28 void AbstractCompiler::initialize_runtimes(initializer f, volatile int* state) {
29 if (*state != initialized) {
30 29
31 // We are thread in native here... 30 bool AbstractCompiler::should_perform_init() {
32 CompilerThread* thread = CompilerThread::current(); 31 if (_compiler_state != initialized) {
33 bool do_initialization = false; 32 MutexLocker only_one(CompileThread_lock);
34 { 33
35 ThreadInVMfromNative tv(thread); 34 if (_compiler_state == uninitialized) {
36 ResetNoHandleMark rnhm; 35 _compiler_state = initializing;
37 MutexLocker only_one(CompileThread_lock, thread); 36 return true;
38 if ( *state == uninitialized) { 37 } else {
39 do_initialization = true; 38 while (_compiler_state == initializing) {
40 *state = initializing; 39 CompileThread_lock->wait();
41 } else {
42 while (*state == initializing ) {
43 CompileThread_lock->wait();
44 }
45 } 40 }
46 } 41 }
47 if (do_initialization) { 42 }
48 // We can not hold any locks here since JVMTI events may call agents 43 return false;
44 }
49 45
50 // Compiler(s) run as native 46 bool AbstractCompiler::should_perform_shutdown() {
47 // Since this method can be called by multiple threads, the lock ensures atomicity of
48 // decrementing '_num_compiler_threads' and the following operations.
49 MutexLocker only_one(CompileThread_lock);
50 _num_compiler_threads--;
51 assert (CompileBroker::is_compilation_disabled_forever(), "Must be set, otherwise thread waits forever");
51 52
52 (*f)(); 53 // Only the last thread will perform shutdown operations
54 if (_num_compiler_threads == 0) {
55 return true;
56 }
57 return false;
58 }
53 59
54 // To in_vm so we can use the lock 60 void AbstractCompiler::set_state(int state) {
55 61 // Ensure that ste is only set by one thread at a time
56 ThreadInVMfromNative tv(thread); 62 MutexLocker only_one(CompileThread_lock);
57 ResetNoHandleMark rnhm; 63 _compiler_state = state;
58 MutexLocker only_one(CompileThread_lock, thread); 64 CompileThread_lock->notify_all();
59 assert(*state == initializing, "wrong state");
60 *state = initialized;
61 CompileThread_lock->notify_all();
62 }
63 }
64 } 65 }