1 /* |
1 /* |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
100 return is_active(); |
100 return is_active(); |
101 } |
101 } |
102 |
102 |
103 void GCLocker::stall_until_clear() { |
103 void GCLocker::stall_until_clear() { |
104 assert(!JavaThread::current()->in_critical(), "Would deadlock"); |
104 assert(!JavaThread::current()->in_critical(), "Would deadlock"); |
105 MutexLocker ml(JNICritical_lock); |
105 MonitorLocker ml(JNICritical_lock); |
106 |
106 |
107 if (needs_gc()) { |
107 if (needs_gc()) { |
108 log_debug_jni("Allocation failed. Thread stalled by JNI critical section."); |
108 log_debug_jni("Allocation failed. Thread stalled by JNI critical section."); |
109 } |
109 } |
110 |
110 |
111 // Wait for _needs_gc to be cleared |
111 // Wait for _needs_gc to be cleared |
112 while (needs_gc()) { |
112 while (needs_gc()) { |
113 JNICritical_lock->wait(); |
113 ml.wait(); |
114 } |
114 } |
115 } |
115 } |
116 |
116 |
117 void GCLocker::jni_lock(JavaThread* thread) { |
117 void GCLocker::jni_lock(JavaThread* thread) { |
118 assert(!thread->in_critical(), "shouldn't currently be in a critical region"); |
118 assert(!thread->in_critical(), "shouldn't currently be in a critical region"); |
119 MutexLocker mu(JNICritical_lock); |
119 MonitorLocker ml(JNICritical_lock); |
120 // Block entering threads if we know at least one thread is in a |
120 // Block entering threads if we know at least one thread is in a |
121 // JNI critical region and we need a GC. |
121 // JNI critical region and we need a GC. |
122 // We check that at least one thread is in a critical region before |
122 // We check that at least one thread is in a critical region before |
123 // blocking because blocked threads are woken up by a thread exiting |
123 // blocking because blocked threads are woken up by a thread exiting |
124 // a JNI critical region. |
124 // a JNI critical region. |
125 while (is_active_and_needs_gc() || _doing_gc) { |
125 while (is_active_and_needs_gc() || _doing_gc) { |
126 JNICritical_lock->wait(); |
126 ml.wait(); |
127 } |
127 } |
128 thread->enter_critical(); |
128 thread->enter_critical(); |
129 _jni_lock_count++; |
129 _jni_lock_count++; |
130 increment_debug_jni_lock_count(); |
130 increment_debug_jni_lock_count(); |
131 } |
131 } |