Wed, 22 Jan 2014 17:42:23 -0800
Merge
duke@435 | 1 | // |
mikael@6198 | 2 | // Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | // |
duke@435 | 5 | // This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | // under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | // published by the Free Software Foundation. |
duke@435 | 8 | // |
duke@435 | 9 | // This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | // version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | // accompanied this code). |
duke@435 | 14 | // |
duke@435 | 15 | // You should have received a copy of the GNU General Public License version |
duke@435 | 16 | // 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | // |
trims@1907 | 19 | // Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | // or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | // questions. |
duke@435 | 22 | // |
duke@435 | 23 | |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "compiler/abstractCompiler.hpp" |
anoll@5919 | 27 | #include "compiler/compileBroker.hpp" |
stefank@2314 | 28 | #include "runtime/mutexLocker.hpp" |
duke@435 | 29 | |
anoll@5919 | 30 | bool AbstractCompiler::should_perform_init() { |
anoll@5919 | 31 | if (_compiler_state != initialized) { |
anoll@5919 | 32 | MutexLocker only_one(CompileThread_lock); |
anoll@5919 | 33 | |
anoll@5919 | 34 | if (_compiler_state == uninitialized) { |
anoll@5919 | 35 | _compiler_state = initializing; |
anoll@5919 | 36 | return true; |
anoll@5919 | 37 | } else { |
anoll@5919 | 38 | while (_compiler_state == initializing) { |
anoll@5919 | 39 | CompileThread_lock->wait(); |
duke@435 | 40 | } |
duke@435 | 41 | } |
anoll@5919 | 42 | } |
anoll@5919 | 43 | return false; |
anoll@5919 | 44 | } |
duke@435 | 45 | |
anoll@5919 | 46 | bool AbstractCompiler::should_perform_shutdown() { |
anoll@5919 | 47 | // Since this method can be called by multiple threads, the lock ensures atomicity of |
anoll@5919 | 48 | // decrementing '_num_compiler_threads' and the following operations. |
anoll@5919 | 49 | MutexLocker only_one(CompileThread_lock); |
anoll@5919 | 50 | _num_compiler_threads--; |
anoll@5919 | 51 | assert (CompileBroker::is_compilation_disabled_forever(), "Must be set, otherwise thread waits forever"); |
duke@435 | 52 | |
anoll@5919 | 53 | // Only the last thread will perform shutdown operations |
anoll@5919 | 54 | if (_num_compiler_threads == 0) { |
anoll@5919 | 55 | return true; |
anoll@5919 | 56 | } |
anoll@5919 | 57 | return false; |
anoll@5919 | 58 | } |
duke@435 | 59 | |
anoll@5919 | 60 | void AbstractCompiler::set_state(int state) { |
anoll@5919 | 61 | // Ensure that ste is only set by one thread at a time |
anoll@5919 | 62 | MutexLocker only_one(CompileThread_lock); |
anoll@5919 | 63 | _compiler_state = state; |
anoll@5919 | 64 | CompileThread_lock->notify_all(); |
duke@435 | 65 | } |