1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
184 // JVMTI) happy. ThreadState is legacy code (see notes in
185 // osThread.hpp).
186 //
187 // 2. It would be more natural if set_external_suspend() is private and
188 // part of java_suspend(), but that probably would affect the suspend/query
189 // performance. Need more investigation on this.
190
191 // suspend/resume lock: used for self-suspend
192 Monitor* _SR_lock;
193
194 protected:
195 enum SuspendFlags {
196 // NOTE: avoid using the sign-bit as cc generates different test code
197 // when the sign-bit is used, and sometimes incorrectly - see CR 6398077
198
199 _external_suspend = 0x20000000U, // thread is asked to self suspend
200 _ext_suspended = 0x40000000U, // thread has self-suspended
201 _deopt_suspend = 0x10000000U, // thread needs to self suspend for deopt
202
203 _has_async_exception = 0x00000001U, // there is a pending async exception
204 _critical_native_unlock = 0x00000002U // Must call back to unlock JNI critical lock
205 };
206
207 // various suspension related flags - atomically updated
208 // overloaded for async exception checking in check_special_condition_for_native_trans.
209 volatile uint32_t _suspend_flags;
210
211 private:
212 int _num_nested_signal;
213
214 DEBUG_ONLY(bool _suspendible_thread;)
215
216 public:
217 void enter_signal_handler() { _num_nested_signal++; }
218 void leave_signal_handler() { _num_nested_signal--; }
219 bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
220
221 #ifdef ASSERT
222 void set_suspendible_thread() {
223 _suspendible_thread = true;
224 }
364 assert(Thread::current() == this, "set_native_thread_name can only be called on the current thread");
365 os::set_native_thread_name(name);
366 }
367
368 ObjectMonitor** omInUseList_addr() { return (ObjectMonitor **)&omInUseList; }
369 Monitor* SR_lock() const { return _SR_lock; }
370
371 bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
372
373 inline void set_suspend_flag(SuspendFlags f);
374 inline void clear_suspend_flag(SuspendFlags f);
375
376 inline void set_has_async_exception();
377 inline void clear_has_async_exception();
378
379 bool do_critical_native_unlock() const { return (_suspend_flags & _critical_native_unlock) != 0; }
380
381 inline void set_critical_native_unlock();
382 inline void clear_critical_native_unlock();
383
384 // Support for Unhandled Oop detection
385 // Add the field for both, fastdebug and debug, builds to keep
386 // Thread's fields layout the same.
387 // Note: CHECK_UNHANDLED_OOPS is defined only for fastdebug build.
388 #ifdef CHECK_UNHANDLED_OOPS
389 private:
390 UnhandledOops* _unhandled_oops;
391 #elif defined(ASSERT)
392 private:
393 void* _unhandled_oops;
394 #endif
395 #ifdef CHECK_UNHANDLED_OOPS
396 public:
397 UnhandledOops* unhandled_oops() { return _unhandled_oops; }
398 // Mark oop safe for gc. It may be stack allocated but won't move.
399 void allow_unhandled_oop(oop *op) {
400 if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op);
401 }
402 // Clear oops at safepoint so crashes point to unhandled oop violator
403 void clear_unhandled_oops() {
432 void set_handle_area(HandleArea* area) { _handle_area = area; }
433
434 GrowableArray<Metadata*>* metadata_handles() const { return _metadata_handles; }
435 void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
436
437 // Thread-Local Allocation Buffer (TLAB) support
438 ThreadLocalAllocBuffer& tlab() { return _tlab; }
439 void initialize_tlab() {
440 if (UseTLAB) {
441 tlab().initialize();
442 }
443 }
444
445 jlong allocated_bytes() { return _allocated_bytes; }
446 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
447 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
448 inline jlong cooked_allocated_bytes();
449
450 TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET;
451 TRACE_DATA* trace_data() const { return &_trace_data; }
452
453 const ThreadExt& ext() const { return _ext; }
454 ThreadExt& ext() { return _ext; }
455
456 // VM operation support
457 int vm_operation_ticket() { return ++_vm_operation_started_count; }
458 int vm_operation_completed_count() { return _vm_operation_completed_count; }
459 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
460
461 // For tracking the heavyweight monitor the thread is pending on.
462 ObjectMonitor* current_pending_monitor() {
463 return _current_pending_monitor;
464 }
465 void set_current_pending_monitor(ObjectMonitor* monitor) {
466 _current_pending_monitor = monitor;
467 }
468 void set_current_pending_monitor_is_from_java(bool from_java) {
469 _current_pending_monitor_is_from_java = from_java;
470 }
471 bool current_pending_monitor_is_from_java() {
1254
1255 void check_and_handle_async_exceptions(bool check_unsafe_error = true);
1256
1257 // these next two are also used for self-suspension and async exception support
1258 void handle_special_runtime_exit_condition(bool check_asyncs = true);
1259
1260 // Return true if JavaThread has an asynchronous condition or
1261 // if external suspension is requested.
1262 bool has_special_runtime_exit_condition() {
1263 // We call is_external_suspend() last since external suspend should
1264 // be less common. Because we don't use is_external_suspend_with_lock
1265 // it is possible that we won't see an asynchronous external suspend
1266 // request that has just gotten started, i.e., SR_lock grabbed but
1267 // _external_suspend field change either not made yet or not visible
1268 // yet. However, this is okay because the request is asynchronous and
1269 // we will see the new flag value the next time through. It's also
1270 // possible that the external suspend request is dropped after
1271 // we have checked is_external_suspend(), we will recheck its value
1272 // under SR_lock in java_suspend_self().
1273 return (_special_runtime_exit_condition != _no_async_condition) ||
1274 is_external_suspend() || is_deopt_suspend();
1275 }
1276
1277 void set_pending_unsafe_access_error() { _special_runtime_exit_condition = _async_unsafe_access_error; }
1278
1279 inline void set_pending_async_exception(oop e);
1280
1281 // Fast-locking support
1282 bool is_lock_owned(address adr) const;
1283
1284 // Accessors for vframe array top
1285 // The linked list of vframe arrays are sorted on sp. This means when we
1286 // unpack the head must contain the vframe array to unpack.
1287 void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
1288 vframeArray* vframe_array_head() const { return _vframe_array_head; }
1289
1290 // Side structure for deferring update of java frame locals until deopt occurs
1291 GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred_locals() const { return _deferred_locals_updates; }
1292 void set_deferred_locals(GrowableArray<jvmtiDeferredLocalVariableSet *>* vf) { _deferred_locals_updates = vf; }
1293
1294 // These only really exist to make debugging deopt problems simpler
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
184 // JVMTI) happy. ThreadState is legacy code (see notes in
185 // osThread.hpp).
186 //
187 // 2. It would be more natural if set_external_suspend() is private and
188 // part of java_suspend(), but that probably would affect the suspend/query
189 // performance. Need more investigation on this.
190
191 // suspend/resume lock: used for self-suspend
192 Monitor* _SR_lock;
193
194 protected:
195 enum SuspendFlags {
196 // NOTE: avoid using the sign-bit as cc generates different test code
197 // when the sign-bit is used, and sometimes incorrectly - see CR 6398077
198
199 _external_suspend = 0x20000000U, // thread is asked to self suspend
200 _ext_suspended = 0x40000000U, // thread has self-suspended
201 _deopt_suspend = 0x10000000U, // thread needs to self suspend for deopt
202
203 _has_async_exception = 0x00000001U, // there is a pending async exception
204 _critical_native_unlock = 0x00000002U, // Must call back to unlock JNI critical lock
205
206 _trace_flag = 0x00000004U // call tracing backend
207 };
208
209 // various suspension related flags - atomically updated
210 // overloaded for async exception checking in check_special_condition_for_native_trans.
211 volatile uint32_t _suspend_flags;
212
213 private:
214 int _num_nested_signal;
215
216 DEBUG_ONLY(bool _suspendible_thread;)
217
218 public:
219 void enter_signal_handler() { _num_nested_signal++; }
220 void leave_signal_handler() { _num_nested_signal--; }
221 bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
222
223 #ifdef ASSERT
224 void set_suspendible_thread() {
225 _suspendible_thread = true;
226 }
366 assert(Thread::current() == this, "set_native_thread_name can only be called on the current thread");
367 os::set_native_thread_name(name);
368 }
369
370 ObjectMonitor** omInUseList_addr() { return (ObjectMonitor **)&omInUseList; }
371 Monitor* SR_lock() const { return _SR_lock; }
372
373 bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
374
375 inline void set_suspend_flag(SuspendFlags f);
376 inline void clear_suspend_flag(SuspendFlags f);
377
378 inline void set_has_async_exception();
379 inline void clear_has_async_exception();
380
381 bool do_critical_native_unlock() const { return (_suspend_flags & _critical_native_unlock) != 0; }
382
383 inline void set_critical_native_unlock();
384 inline void clear_critical_native_unlock();
385
386 inline void set_trace_flag();
387 inline void clear_trace_flag();
388
389 // Support for Unhandled Oop detection
390 // Add the field for both, fastdebug and debug, builds to keep
391 // Thread's fields layout the same.
392 // Note: CHECK_UNHANDLED_OOPS is defined only for fastdebug build.
393 #ifdef CHECK_UNHANDLED_OOPS
394 private:
395 UnhandledOops* _unhandled_oops;
396 #elif defined(ASSERT)
397 private:
398 void* _unhandled_oops;
399 #endif
400 #ifdef CHECK_UNHANDLED_OOPS
401 public:
402 UnhandledOops* unhandled_oops() { return _unhandled_oops; }
403 // Mark oop safe for gc. It may be stack allocated but won't move.
404 void allow_unhandled_oop(oop *op) {
405 if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op);
406 }
407 // Clear oops at safepoint so crashes point to unhandled oop violator
408 void clear_unhandled_oops() {
437 void set_handle_area(HandleArea* area) { _handle_area = area; }
438
439 GrowableArray<Metadata*>* metadata_handles() const { return _metadata_handles; }
440 void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
441
442 // Thread-Local Allocation Buffer (TLAB) support
443 ThreadLocalAllocBuffer& tlab() { return _tlab; }
444 void initialize_tlab() {
445 if (UseTLAB) {
446 tlab().initialize();
447 }
448 }
449
450 jlong allocated_bytes() { return _allocated_bytes; }
451 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
452 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
453 inline jlong cooked_allocated_bytes();
454
455 TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET;
456 TRACE_DATA* trace_data() const { return &_trace_data; }
457 bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
458
459 const ThreadExt& ext() const { return _ext; }
460 ThreadExt& ext() { return _ext; }
461
462 // VM operation support
463 int vm_operation_ticket() { return ++_vm_operation_started_count; }
464 int vm_operation_completed_count() { return _vm_operation_completed_count; }
465 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
466
467 // For tracking the heavyweight monitor the thread is pending on.
468 ObjectMonitor* current_pending_monitor() {
469 return _current_pending_monitor;
470 }
471 void set_current_pending_monitor(ObjectMonitor* monitor) {
472 _current_pending_monitor = monitor;
473 }
474 void set_current_pending_monitor_is_from_java(bool from_java) {
475 _current_pending_monitor_is_from_java = from_java;
476 }
477 bool current_pending_monitor_is_from_java() {
1260
1261 void check_and_handle_async_exceptions(bool check_unsafe_error = true);
1262
1263 // these next two are also used for self-suspension and async exception support
1264 void handle_special_runtime_exit_condition(bool check_asyncs = true);
1265
1266 // Return true if JavaThread has an asynchronous condition or
1267 // if external suspension is requested.
1268 bool has_special_runtime_exit_condition() {
1269 // We call is_external_suspend() last since external suspend should
1270 // be less common. Because we don't use is_external_suspend_with_lock
1271 // it is possible that we won't see an asynchronous external suspend
1272 // request that has just gotten started, i.e., SR_lock grabbed but
1273 // _external_suspend field change either not made yet or not visible
1274 // yet. However, this is okay because the request is asynchronous and
1275 // we will see the new flag value the next time through. It's also
1276 // possible that the external suspend request is dropped after
1277 // we have checked is_external_suspend(), we will recheck its value
1278 // under SR_lock in java_suspend_self().
1279 return (_special_runtime_exit_condition != _no_async_condition) ||
1280 is_external_suspend() || is_deopt_suspend() || is_trace_suspend();
1281 }
1282
1283 void set_pending_unsafe_access_error() { _special_runtime_exit_condition = _async_unsafe_access_error; }
1284
1285 inline void set_pending_async_exception(oop e);
1286
1287 // Fast-locking support
1288 bool is_lock_owned(address adr) const;
1289
1290 // Accessors for vframe array top
1291 // The linked list of vframe arrays are sorted on sp. This means when we
1292 // unpack the head must contain the vframe array to unpack.
1293 void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
1294 vframeArray* vframe_array_head() const { return _vframe_array_head; }
1295
1296 // Side structure for deferring update of java frame locals until deopt occurs
1297 GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred_locals() const { return _deferred_locals_updates; }
1298 void set_deferred_locals(GrowableArray<jvmtiDeferredLocalVariableSet *>* vf) { _deferred_locals_updates = vf; }
1299
1300 // These only really exist to make debugging deopt problems simpler
|