src/share/vm/compiler/abstractCompiler.cpp
Print this page
@@ -23,42 +23,47 @@
#include "precompiled.hpp"
#include "compiler/abstractCompiler.hpp"
#include "runtime/mutexLocker.hpp"
-void AbstractCompiler::initialize_runtimes(initializer f, volatile int* state) {
- if (*state != initialized) {
- // We are thread in native here...
- CompilerThread* thread = CompilerThread::current();
- bool do_initialization = false;
- {
- ThreadInVMfromNative tv(thread);
- ResetNoHandleMark rnhm;
- MutexLocker only_one(CompileThread_lock, thread);
- if ( *state == uninitialized) {
- do_initialization = true;
- *state = initializing;
+bool AbstractCompiler::should_perform_init() {
+ if (_compiler_state != initialized) {
+ MutexLocker only_one(CompileThread_lock);
+
+ if (_compiler_state == uninitialized) {
+ _compiler_state = initializing;
+ return true;
} else {
- while (*state == initializing ) {
+ while (_compiler_state == initializing) {
CompileThread_lock->wait();
}
}
}
- if (do_initialization) {
- // We can not hold any locks here since JVMTI events may call agents
-
- // Compiler(s) run as native
-
- (*f)();
-
- // To in_vm so we can use the lock
+ return false;
+}
- ThreadInVMfromNative tv(thread);
- ResetNoHandleMark rnhm;
- MutexLocker only_one(CompileThread_lock, thread);
- assert(*state == initializing, "wrong state");
- *state = initialized;
- CompileThread_lock->notify_all();
+bool AbstractCompiler::should_perform_shutdown() {
+ MutexLocker only_one(CompileThread_lock);
+ _num_compiler_threads--;
+ if (_compiler_state == failed) {
+ _compiler_state = shutting_shown;
+
+ // Wait until all compiler threads are exiting before starting
+ // shutdown
+ while (_num_compiler_threads > 0) {
+ CompileThread_lock->wait();
}
+ return true;
}
+ return false;
+}
+
+void AbstractCompiler::set_state(int state) {
+ assert((_compiler_state == initializing) || (_compiler_state == failed), "wrong state");
+ MutexLocker only_one(CompileThread_lock);
+
+ // The state of the compiler could have been changed by another thread if
+ // memory allocation of the buffer blob failed.
+ _compiler_state = state;
+ CompileThread_lock->notify_all();
}