0N/A//
1879N/A// Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A//
0N/A// This code is free software; you can redistribute it and/or modify it
0N/A// under the terms of the GNU General Public License version 2 only, as
0N/A// published by the Free Software Foundation.
0N/A//
0N/A// This code is distributed in the hope that it will be useful, but WITHOUT
0N/A// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A// version 2 for more details (a copy is included in the LICENSE file that
0N/A// accompanied this code).
0N/A//
0N/A// You should have received a copy of the GNU General Public License version
0N/A// 2 along with this work; if not, write to the Free Software Foundation,
0N/A// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A//
1472N/A// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A// or visit www.oracle.com if you need additional information or have any
1472N/A// questions.
0N/A//
0N/A
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "compiler/abstractCompiler.hpp"
1879N/A#include "runtime/mutexLocker.hpp"
0N/Avoid AbstractCompiler::initialize_runtimes(initializer f, volatile int* state) {
0N/A if (*state != initialized) {
0N/A
0N/A // We are thread in native here...
0N/A CompilerThread* thread = CompilerThread::current();
0N/A bool do_initialization = false;
0N/A {
0N/A ThreadInVMfromNative tv(thread);
1980N/A ResetNoHandleMark rnhm;
0N/A MutexLocker only_one(CompileThread_lock, thread);
0N/A if ( *state == uninitialized) {
0N/A do_initialization = true;
0N/A *state = initializing;
0N/A } else {
0N/A while (*state == initializing ) {
0N/A CompileThread_lock->wait();
0N/A }
0N/A }
0N/A }
0N/A if (do_initialization) {
0N/A // We can not hold any locks here since JVMTI events may call agents
0N/A
0N/A // Compiler(s) run as native
0N/A
0N/A (*f)();
0N/A
0N/A // To in_vm so we can use the lock
0N/A
0N/A ThreadInVMfromNative tv(thread);
1980N/A ResetNoHandleMark rnhm;
0N/A MutexLocker only_one(CompileThread_lock, thread);
0N/A assert(*state == initializing, "wrong state");
0N/A *state = initialized;
0N/A CompileThread_lock->notify_all();
0N/A }
0N/A }
0N/A}