50 // of the performance and semantics difference. They are normally |
50 // of the performance and semantics difference. They are normally |
51 // used by ObjectLocker etc. The interpreter and compiler use |
51 // used by ObjectLocker etc. The interpreter and compiler use |
52 // assembly copies of these routines. Please keep them synchronized. |
52 // assembly copies of these routines. Please keep them synchronized. |
53 // |
53 // |
54 // attempt_rebias flag is used by UseBiasedLocking implementation |
54 // attempt_rebias flag is used by UseBiasedLocking implementation |
55 static void fast_enter (Handle obj, BasicLock* lock, bool attempt_rebias, TRAPS); |
55 static void fast_enter(Handle obj, BasicLock* lock, bool attempt_rebias, |
56 static void fast_exit (oop obj, BasicLock* lock, Thread* THREAD); |
56 TRAPS); |
|
57 static void fast_exit(oop obj, BasicLock* lock, Thread* THREAD); |
57 |
58 |
58 // WARNING: They are ONLY used to handle the slow cases. They should |
59 // WARNING: They are ONLY used to handle the slow cases. They should |
59 // only be used when the fast cases failed. Use of these functions |
60 // only be used when the fast cases failed. Use of these functions |
60 // without previous fast case check may cause fatal error. |
61 // without previous fast case check may cause fatal error. |
61 static void slow_enter (Handle obj, BasicLock* lock, TRAPS); |
62 static void slow_enter(Handle obj, BasicLock* lock, TRAPS); |
62 static void slow_exit (oop obj, BasicLock* lock, Thread* THREAD); |
63 static void slow_exit(oop obj, BasicLock* lock, Thread* THREAD); |
63 |
64 |
64 // Used only to handle jni locks or other unmatched monitor enter/exit |
65 // Used only to handle jni locks or other unmatched monitor enter/exit |
65 // Internally they will use heavy weight monitor. |
66 // Internally they will use heavy weight monitor. |
66 static void jni_enter (Handle obj, TRAPS); |
67 static void jni_enter(Handle obj, TRAPS); |
67 static bool jni_try_enter(Handle obj, Thread* THREAD); // Implements Unsafe.tryMonitorEnter |
68 static bool jni_try_enter(Handle obj, Thread* THREAD); // Implements Unsafe.tryMonitorEnter |
68 static void jni_exit (oop obj, Thread* THREAD); |
69 static void jni_exit(oop obj, Thread* THREAD); |
69 |
70 |
70 // Handle all interpreter, compiler and jni cases |
71 // Handle all interpreter, compiler and jni cases |
71 static int wait (Handle obj, jlong millis, TRAPS); |
72 static int wait(Handle obj, jlong millis, TRAPS); |
72 static void notify (Handle obj, TRAPS); |
73 static void notify(Handle obj, TRAPS); |
73 static void notifyall (Handle obj, TRAPS); |
74 static void notifyall(Handle obj, TRAPS); |
74 |
75 |
75 // Special internal-use-only method for use by JVM infrastructure |
76 // Special internal-use-only method for use by JVM infrastructure |
76 // that needs to wait() on a java-level object but that can't risk |
77 // that needs to wait() on a java-level object but that can't risk |
77 // throwing unexpected InterruptedExecutionExceptions. |
78 // throwing unexpected InterruptedExecutionExceptions. |
78 static void waitUninterruptibly(Handle obj, jlong Millis, Thread * THREAD); |
79 static void waitUninterruptibly(Handle obj, jlong Millis, Thread * THREAD); |
79 |
80 |
80 // used by classloading to free classloader object lock, |
81 // used by classloading to free classloader object lock, |
81 // wait on an internal lock, and reclaim original lock |
82 // wait on an internal lock, and reclaim original lock |
82 // with original recursion count |
83 // with original recursion count |
83 static intptr_t complete_exit (Handle obj, TRAPS); |
84 static intptr_t complete_exit(Handle obj, TRAPS); |
84 static void reenter (Handle obj, intptr_t recursion, TRAPS); |
85 static void reenter (Handle obj, intptr_t recursion, TRAPS); |
85 |
86 |
86 // thread-specific and global objectMonitor free list accessors |
87 // thread-specific and global objectMonitor free list accessors |
87 static void verifyInUse(Thread * Self); |
88 static void verifyInUse(Thread * Self); |
88 static ObjectMonitor * omAlloc(Thread * Self); |
89 static ObjectMonitor * omAlloc(Thread * Self); |
89 static void omRelease(Thread * Self, ObjectMonitor * m, bool FromPerThreadAlloc); |
90 static void omRelease(Thread * Self, ObjectMonitor * m, |
|
91 bool FromPerThreadAlloc); |
90 static void omFlush(Thread * Self); |
92 static void omFlush(Thread * Self); |
91 |
93 |
92 // Inflate light weight monitor to heavy weight monitor |
94 // Inflate light weight monitor to heavy weight monitor |
93 static ObjectMonitor* inflate(Thread * Self, oop obj); |
95 static ObjectMonitor* inflate(Thread * Self, oop obj); |
94 // This version is only for internal use |
96 // This version is only for internal use |
114 // An adaptive profile-based deflation policy could be used if needed |
116 // An adaptive profile-based deflation policy could be used if needed |
115 static void deflate_idle_monitors(); |
117 static void deflate_idle_monitors(); |
116 static int walk_monitor_list(ObjectMonitor** listheadp, |
118 static int walk_monitor_list(ObjectMonitor** listheadp, |
117 ObjectMonitor** freeHeadp, |
119 ObjectMonitor** freeHeadp, |
118 ObjectMonitor** freeTailp); |
120 ObjectMonitor** freeTailp); |
119 static bool deflate_monitor(ObjectMonitor* mid, oop obj, ObjectMonitor** freeHeadp, |
121 static bool deflate_monitor(ObjectMonitor* mid, oop obj, |
|
122 ObjectMonitor** freeHeadp, |
120 ObjectMonitor** freeTailp); |
123 ObjectMonitor** freeTailp); |
121 static void oops_do(OopClosure* f); |
124 static void oops_do(OopClosure* f); |
122 |
125 |
123 // debugging |
126 // debugging |
124 static void sanity_checks(const bool verbose, |
127 static void sanity_checks(const bool verbose, |
157 public: |
160 public: |
158 ObjectLocker(Handle obj, Thread* thread, bool doLock = true); |
161 ObjectLocker(Handle obj, Thread* thread, bool doLock = true); |
159 ~ObjectLocker(); |
162 ~ObjectLocker(); |
160 |
163 |
161 // Monitor behavior |
164 // Monitor behavior |
162 void wait (TRAPS) { ObjectSynchronizer::wait (_obj, 0, CHECK); } // wait forever |
165 void wait(TRAPS) { ObjectSynchronizer::wait(_obj, 0, CHECK); } // wait forever |
163 void notify_all(TRAPS) { ObjectSynchronizer::notifyall(_obj, CHECK); } |
166 void notify_all(TRAPS) { ObjectSynchronizer::notifyall(_obj, CHECK); } |
164 void waitUninterruptibly (TRAPS) { ObjectSynchronizer::waitUninterruptibly (_obj, 0, CHECK); } |
167 void waitUninterruptibly(TRAPS) { ObjectSynchronizer::waitUninterruptibly(_obj, 0, CHECK); } |
165 // complete_exit gives up lock completely, returning recursion count |
168 // complete_exit gives up lock completely, returning recursion count |
166 // reenter reclaims lock with original recursion count |
169 // reenter reclaims lock with original recursion count |
167 intptr_t complete_exit(TRAPS) { return ObjectSynchronizer::complete_exit(_obj, CHECK_0); } |
170 intptr_t complete_exit(TRAPS) { return ObjectSynchronizer::complete_exit(_obj, CHECK_0); } |
168 void reenter(intptr_t recursion, TRAPS) { ObjectSynchronizer::reenter(_obj, recursion, CHECK); } |
171 void reenter(intptr_t recursion, TRAPS) { ObjectSynchronizer::reenter(_obj, recursion, CHECK); } |
169 }; |
172 }; |
170 |
173 |
171 #endif // SHARE_VM_RUNTIME_SYNCHRONIZER_HPP |
174 #endif // SHARE_VM_RUNTIME_SYNCHRONIZER_HPP |