Thu, 07 Sep 2017 09:17:43 -0400
8072428: Enable UseLoopCounter ergonomically if on-stack-replacement is enabled
Summary: Set UseLoopCounter ergonomically if on-stack-replacement is enabled. Print warning.
Reviewed-by: kvn
duke@435 | 1 | /* |
mikael@6198 | 2 | * Copyright (c) 1998, 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 | #ifndef SHARE_VM_RUNTIME_SYNCHRONIZER_HPP |
stefank@2314 | 26 | #define SHARE_VM_RUNTIME_SYNCHRONIZER_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "oops/markOop.hpp" |
stefank@2314 | 29 | #include "runtime/basicLock.hpp" |
stefank@2314 | 30 | #include "runtime/handles.hpp" |
stefank@2314 | 31 | #include "runtime/perfData.hpp" |
stefank@2314 | 32 | #include "utilities/top.hpp" |
stefank@2314 | 33 | |
duke@435 | 34 | |
duke@435 | 35 | class ObjectMonitor; |
duke@435 | 36 | |
duke@435 | 37 | class ObjectSynchronizer : AllStatic { |
duke@435 | 38 | friend class VMStructs; |
duke@435 | 39 | public: |
duke@435 | 40 | typedef enum { |
duke@435 | 41 | owner_self, |
duke@435 | 42 | owner_none, |
duke@435 | 43 | owner_other |
duke@435 | 44 | } LockOwnership; |
duke@435 | 45 | // exit must be implemented non-blocking, since the compiler cannot easily handle |
duke@435 | 46 | // deoptimization at monitor exit. Hence, it does not take a Handle argument. |
duke@435 | 47 | |
duke@435 | 48 | // This is full version of monitor enter and exit. I choose not |
duke@435 | 49 | // to use enter() and exit() in order to make sure user be ware |
duke@435 | 50 | // of the performance and semantics difference. They are normally |
duke@435 | 51 | // used by ObjectLocker etc. The interpreter and compiler use |
duke@435 | 52 | // assembly copies of these routines. Please keep them synchornized. |
duke@435 | 53 | // |
duke@435 | 54 | // attempt_rebias flag is used by UseBiasedLocking implementation |
duke@435 | 55 | static void fast_enter (Handle obj, BasicLock* lock, bool attempt_rebias, TRAPS); |
duke@435 | 56 | static void fast_exit (oop obj, BasicLock* lock, Thread* THREAD); |
duke@435 | 57 | |
duke@435 | 58 | // WARNING: They are ONLY used to handle the slow cases. They should |
duke@435 | 59 | // only be used when the fast cases failed. Use of these functions |
duke@435 | 60 | // without previous fast case check may cause fatal error. |
duke@435 | 61 | static void slow_enter (Handle obj, BasicLock* lock, TRAPS); |
duke@435 | 62 | static void slow_exit (oop obj, BasicLock* lock, Thread* THREAD); |
duke@435 | 63 | |
duke@435 | 64 | // Used only to handle jni locks or other unmatched monitor enter/exit |
duke@435 | 65 | // Internally they will use heavy weight monitor. |
duke@435 | 66 | static void jni_enter (Handle obj, TRAPS); |
duke@435 | 67 | static bool jni_try_enter(Handle obj, Thread* THREAD); // Implements Unsafe.tryMonitorEnter |
duke@435 | 68 | static void jni_exit (oop obj, Thread* THREAD); |
duke@435 | 69 | |
duke@435 | 70 | // Handle all interpreter, compiler and jni cases |
duke@435 | 71 | static void wait (Handle obj, jlong millis, TRAPS); |
duke@435 | 72 | static void notify (Handle obj, TRAPS); |
duke@435 | 73 | static void notifyall (Handle obj, TRAPS); |
duke@435 | 74 | |
duke@435 | 75 | // Special internal-use-only method for use by JVM infrastructure |
duke@435 | 76 | // that needs to wait() on a java-level object but that can't risk |
duke@435 | 77 | // throwing unexpected InterruptedExecutionExceptions. |
duke@435 | 78 | static void waitUninterruptibly (Handle obj, jlong Millis, Thread * THREAD) ; |
duke@435 | 79 | |
duke@435 | 80 | // used by classloading to free classloader object lock, |
duke@435 | 81 | // wait on an internal lock, and reclaim original lock |
duke@435 | 82 | // with original recursion count |
duke@435 | 83 | static intptr_t complete_exit (Handle obj, TRAPS); |
duke@435 | 84 | static void reenter (Handle obj, intptr_t recursion, TRAPS); |
duke@435 | 85 | |
duke@435 | 86 | // thread-specific and global objectMonitor free list accessors |
acorn@1995 | 87 | // static void verifyInUse (Thread * Self) ; too slow for general assert/debug |
duke@435 | 88 | static ObjectMonitor * omAlloc (Thread * Self) ; |
acorn@1995 | 89 | static void omRelease (Thread * Self, ObjectMonitor * m, bool FromPerThreadAlloc) ; |
duke@435 | 90 | static void omFlush (Thread * Self) ; |
duke@435 | 91 | |
duke@435 | 92 | // Inflate light weight monitor to heavy weight monitor |
duke@435 | 93 | static ObjectMonitor* inflate(Thread * Self, oop obj); |
duke@435 | 94 | // This version is only for internal use |
duke@435 | 95 | static ObjectMonitor* inflate_helper(oop obj); |
duke@435 | 96 | |
duke@435 | 97 | // Returns the identity hash value for an oop |
duke@435 | 98 | // NOTE: It may cause monitor inflation |
duke@435 | 99 | static intptr_t identity_hash_value_for(Handle obj); |
duke@435 | 100 | static intptr_t FastHashCode (Thread * Self, oop obj) ; |
duke@435 | 101 | |
duke@435 | 102 | // java.lang.Thread support |
duke@435 | 103 | static bool current_thread_holds_lock(JavaThread* thread, Handle h_obj); |
duke@435 | 104 | static LockOwnership query_lock_ownership(JavaThread * self, Handle h_obj); |
duke@435 | 105 | |
duke@435 | 106 | static JavaThread* get_lock_owner(Handle h_obj, bool doLock); |
duke@435 | 107 | |
duke@435 | 108 | // JNI detach support |
duke@435 | 109 | static void release_monitors_owned_by_thread(TRAPS); |
duke@435 | 110 | static void monitors_iterate(MonitorClosure* m); |
duke@435 | 111 | |
duke@435 | 112 | // GC: we current use aggressive monitor deflation policy |
duke@435 | 113 | // Basically we deflate all monitors that are not busy. |
duke@435 | 114 | // An adaptive profile-based deflation policy could be used if needed |
duke@435 | 115 | static void deflate_idle_monitors(); |
acorn@1995 | 116 | static int walk_monitor_list(ObjectMonitor** listheadp, |
acorn@1995 | 117 | ObjectMonitor** FreeHeadp, |
acorn@1995 | 118 | ObjectMonitor** FreeTailp); |
acorn@1942 | 119 | static bool deflate_monitor(ObjectMonitor* mid, oop obj, ObjectMonitor** FreeHeadp, |
acorn@1942 | 120 | ObjectMonitor** FreeTailp); |
duke@435 | 121 | static void oops_do(OopClosure* f); |
duke@435 | 122 | |
duke@435 | 123 | // debugging |
kevinw@8729 | 124 | static void sanity_checks(const bool verbose, |
kevinw@8729 | 125 | const unsigned int cache_line_size, |
kevinw@8729 | 126 | int *error_cnt_ptr, int *warning_cnt_ptr); |
duke@435 | 127 | static void verify() PRODUCT_RETURN; |
duke@435 | 128 | static int verify_objmon_isinpool(ObjectMonitor *addr) PRODUCT_RETURN0; |
duke@435 | 129 | |
acorn@2233 | 130 | static void RegisterSpinCallback (int (*)(intptr_t, int), intptr_t) ; |
acorn@2233 | 131 | |
duke@435 | 132 | private: |
duke@435 | 133 | enum { _BLOCKSIZE = 128 }; |
duke@435 | 134 | static ObjectMonitor* gBlockList; |
duke@435 | 135 | static ObjectMonitor * volatile gFreeList; |
acorn@1995 | 136 | static ObjectMonitor * volatile gOmInUseList; // for moribund thread, so monitors they inflated still get scanned |
acorn@1995 | 137 | static int gOmInUseCount; |
duke@435 | 138 | |
duke@435 | 139 | }; |
duke@435 | 140 | |
duke@435 | 141 | // ObjectLocker enforced balanced locking and can never thrown an |
duke@435 | 142 | // IllegalMonitorStateException. However, a pending exception may |
duke@435 | 143 | // have to pass through, and we must also be able to deal with |
duke@435 | 144 | // asynchronous exceptions. The caller is responsible for checking |
duke@435 | 145 | // the threads pending exception if needed. |
duke@435 | 146 | // doLock was added to support classloading with UnsyncloadClass which |
duke@435 | 147 | // requires flag based choice of locking the classloader lock. |
duke@435 | 148 | class ObjectLocker : public StackObj { |
duke@435 | 149 | private: |
duke@435 | 150 | Thread* _thread; |
duke@435 | 151 | Handle _obj; |
duke@435 | 152 | BasicLock _lock; |
duke@435 | 153 | bool _dolock; // default true |
duke@435 | 154 | public: |
duke@435 | 155 | ObjectLocker(Handle obj, Thread* thread, bool doLock = true); |
duke@435 | 156 | ~ObjectLocker(); |
duke@435 | 157 | |
duke@435 | 158 | // Monitor behavior |
duke@435 | 159 | void wait (TRAPS) { ObjectSynchronizer::wait (_obj, 0, CHECK); } // wait forever |
duke@435 | 160 | void notify_all(TRAPS) { ObjectSynchronizer::notifyall(_obj, CHECK); } |
duke@435 | 161 | void waitUninterruptibly (TRAPS) { ObjectSynchronizer::waitUninterruptibly (_obj, 0, CHECK);} |
duke@435 | 162 | // complete_exit gives up lock completely, returning recursion count |
duke@435 | 163 | // reenter reclaims lock with original recursion count |
duke@435 | 164 | intptr_t complete_exit(TRAPS) { return ObjectSynchronizer::complete_exit(_obj, CHECK_0); } |
duke@435 | 165 | void reenter(intptr_t recursion, TRAPS) { ObjectSynchronizer::reenter(_obj, recursion, CHECK); } |
duke@435 | 166 | }; |
stefank@2314 | 167 | |
stefank@2314 | 168 | #endif // SHARE_VM_RUNTIME_SYNCHRONIZER_HPP |