44 #include "jfr/support/jfrThreadId.hpp"
45 #include "jvmtifiles/jvmtiEnv.hpp"
46 #include "logging/log.hpp"
47 #include "logging/logConfiguration.hpp"
48 #include "logging/logStream.hpp"
49 #include "memory/allocation.inline.hpp"
50 #include "memory/metaspaceShared.hpp"
51 #include "memory/oopFactory.hpp"
52 #include "memory/resourceArea.hpp"
53 #include "memory/universe.hpp"
54 #include "oops/access.inline.hpp"
55 #include "oops/instanceKlass.hpp"
56 #include "oops/objArrayOop.hpp"
57 #include "oops/oop.inline.hpp"
58 #include "oops/symbol.hpp"
59 #include "oops/typeArrayOop.inline.hpp"
60 #include "oops/verifyOopClosure.hpp"
61 #include "prims/jvm_misc.hpp"
62 #include "prims/jvmtiExport.hpp"
63 #include "prims/jvmtiThreadState.hpp"
64 #include "prims/privilegedStack.hpp"
65 #include "runtime/arguments.hpp"
66 #include "runtime/atomic.hpp"
67 #include "runtime/biasedLocking.hpp"
68 #include "runtime/fieldDescriptor.inline.hpp"
69 #include "runtime/flags/jvmFlagConstraintList.hpp"
70 #include "runtime/flags/jvmFlagRangeList.hpp"
71 #include "runtime/flags/jvmFlagWriteableList.hpp"
72 #include "runtime/deoptimization.hpp"
73 #include "runtime/frame.inline.hpp"
74 #include "runtime/handshake.hpp"
75 #include "runtime/init.hpp"
76 #include "runtime/interfaceSupport.inline.hpp"
77 #include "runtime/java.hpp"
78 #include "runtime/javaCalls.hpp"
79 #include "runtime/jniHandles.inline.hpp"
80 #include "runtime/jniPeriodicChecker.hpp"
81 #include "runtime/memprofiler.hpp"
82 #include "runtime/mutexLocker.hpp"
83 #include "runtime/objectMonitor.hpp"
84 #include "runtime/orderAccess.hpp"
1541
1542 set_saved_exception_pc(NULL);
1543 set_threadObj(NULL);
1544 _anchor.clear();
1545 set_entry_point(NULL);
1546 set_jni_functions(jni_functions());
1547 set_callee_target(NULL);
1548 set_vm_result(NULL);
1549 set_vm_result_2(NULL);
1550 set_vframe_array_head(NULL);
1551 set_vframe_array_last(NULL);
1552 set_deferred_locals(NULL);
1553 set_deopt_mark(NULL);
1554 set_deopt_compiled_method(NULL);
1555 clear_must_deopt_id();
1556 set_monitor_chunks(NULL);
1557 set_next(NULL);
1558 _on_thread_list = false;
1559 set_thread_state(_thread_new);
1560 _terminated = _not_terminated;
1561 _privileged_stack_top = NULL;
1562 _array_for_gc = NULL;
1563 _suspend_equivalent = false;
1564 _in_deopt_handler = 0;
1565 _doing_unsafe_access = false;
1566 _stack_guard_state = stack_guard_unused;
1567 #if INCLUDE_JVMCI
1568 _pending_monitorenter = false;
1569 _pending_deoptimization = -1;
1570 _pending_failed_speculation = 0;
1571 _pending_transfer_to_interpreter = false;
1572 _adjusting_comp_level = false;
1573 _in_retryable_allocation = false;
1574 _jvmci._alternate_call_target = NULL;
1575 assert(_jvmci._implicit_exception_pc == NULL, "must be");
1576 if (JVMCICounterSize > 0) {
1577 _jvmci_counters = NEW_C_HEAP_ARRAY(jlong, JVMCICounterSize, mtInternal);
1578 memset(_jvmci_counters, 0, sizeof(jlong) * JVMCICounterSize);
1579 } else {
1580 _jvmci_counters = NULL;
1581 }
1973 }
1974 // 6282335 JNI DetachCurrentThread spec states that all Java monitors
1975 // held by this thread must be released. The spec does not distinguish
1976 // between JNI-acquired and regular Java monitors. We can only see
1977 // regular Java monitors here if monitor enter-exit matching is broken.
1978 //
1979 // ensure_join() ignores IllegalThreadStateExceptions, and so does
1980 // ObjectSynchronizer::release_monitors_owned_by_thread().
1981 if (exit_type == jni_detach) {
1982 // Sanity check even though JNI DetachCurrentThread() would have
1983 // returned JNI_ERR if there was a Java frame. JavaThread exit
1984 // should be done executing Java code by the time we get here.
1985 assert(!this->has_last_Java_frame(),
1986 "should not have a Java frame when detaching or exiting");
1987 ObjectSynchronizer::release_monitors_owned_by_thread(this);
1988 assert(!this->has_pending_exception(), "release_monitors should have cleared");
1989 }
1990
1991 // These things needs to be done while we are still a Java Thread. Make sure that thread
1992 // is in a consistent state, in case GC happens
1993 assert(_privileged_stack_top == NULL, "must be NULL when we get here");
1994
1995 if (active_handles() != NULL) {
1996 JNIHandleBlock* block = active_handles();
1997 set_active_handles(NULL);
1998 JNIHandleBlock::release_block(block);
1999 }
2000
2001 if (free_handle_block() != NULL) {
2002 JNIHandleBlock* block = free_handle_block();
2003 set_free_handle_block(NULL);
2004 JNIHandleBlock::release_block(block);
2005 }
2006
2007 // These have to be removed while this is still a valid thread.
2008 remove_stack_guard_pages();
2009
2010 if (UseTLAB) {
2011 tlab().retire();
2012 }
2013
2822 ~RememberProcessedThread() {
2823 if (_cur_thr) {
2824 _cur_thr->set_processed_thread(NULL);
2825 }
2826 }
2827 };
2828
2829 void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
2830 // Verify that the deferred card marks have been flushed.
2831 assert(deferred_card_mark().is_empty(), "Should be empty during GC");
2832
2833 // Traverse the GCHandles
2834 Thread::oops_do(f, cf);
2835
2836 assert((!has_last_Java_frame() && java_call_counter() == 0) ||
2837 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!");
2838
2839 if (has_last_Java_frame()) {
2840 // Record JavaThread to GC thread
2841 RememberProcessedThread rpt(this);
2842
2843 // Traverse the privileged stack
2844 if (_privileged_stack_top != NULL) {
2845 _privileged_stack_top->oops_do(f);
2846 }
2847
2848 // traverse the registered growable array
2849 if (_array_for_gc != NULL) {
2850 for (int index = 0; index < _array_for_gc->length(); index++) {
2851 f->do_oop(_array_for_gc->adr_at(index));
2852 }
2853 }
2854
2855 // Traverse the monitor chunks
2856 for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) {
2857 chunk->oops_do(f);
2858 }
2859
2860 // Traverse the execution stack
2861 for (StackFrameStream fst(this); !fst.is_done(); fst.next()) {
2862 fst.current()->oops_do(f, cf, fst.register_map());
2863 }
2864 }
2865
2866 // callee_target is never live across a gc point so NULL it here should
|
44 #include "jfr/support/jfrThreadId.hpp"
45 #include "jvmtifiles/jvmtiEnv.hpp"
46 #include "logging/log.hpp"
47 #include "logging/logConfiguration.hpp"
48 #include "logging/logStream.hpp"
49 #include "memory/allocation.inline.hpp"
50 #include "memory/metaspaceShared.hpp"
51 #include "memory/oopFactory.hpp"
52 #include "memory/resourceArea.hpp"
53 #include "memory/universe.hpp"
54 #include "oops/access.inline.hpp"
55 #include "oops/instanceKlass.hpp"
56 #include "oops/objArrayOop.hpp"
57 #include "oops/oop.inline.hpp"
58 #include "oops/symbol.hpp"
59 #include "oops/typeArrayOop.inline.hpp"
60 #include "oops/verifyOopClosure.hpp"
61 #include "prims/jvm_misc.hpp"
62 #include "prims/jvmtiExport.hpp"
63 #include "prims/jvmtiThreadState.hpp"
64 #include "runtime/arguments.hpp"
65 #include "runtime/atomic.hpp"
66 #include "runtime/biasedLocking.hpp"
67 #include "runtime/fieldDescriptor.inline.hpp"
68 #include "runtime/flags/jvmFlagConstraintList.hpp"
69 #include "runtime/flags/jvmFlagRangeList.hpp"
70 #include "runtime/flags/jvmFlagWriteableList.hpp"
71 #include "runtime/deoptimization.hpp"
72 #include "runtime/frame.inline.hpp"
73 #include "runtime/handshake.hpp"
74 #include "runtime/init.hpp"
75 #include "runtime/interfaceSupport.inline.hpp"
76 #include "runtime/java.hpp"
77 #include "runtime/javaCalls.hpp"
78 #include "runtime/jniHandles.inline.hpp"
79 #include "runtime/jniPeriodicChecker.hpp"
80 #include "runtime/memprofiler.hpp"
81 #include "runtime/mutexLocker.hpp"
82 #include "runtime/objectMonitor.hpp"
83 #include "runtime/orderAccess.hpp"
1540
1541 set_saved_exception_pc(NULL);
1542 set_threadObj(NULL);
1543 _anchor.clear();
1544 set_entry_point(NULL);
1545 set_jni_functions(jni_functions());
1546 set_callee_target(NULL);
1547 set_vm_result(NULL);
1548 set_vm_result_2(NULL);
1549 set_vframe_array_head(NULL);
1550 set_vframe_array_last(NULL);
1551 set_deferred_locals(NULL);
1552 set_deopt_mark(NULL);
1553 set_deopt_compiled_method(NULL);
1554 clear_must_deopt_id();
1555 set_monitor_chunks(NULL);
1556 set_next(NULL);
1557 _on_thread_list = false;
1558 set_thread_state(_thread_new);
1559 _terminated = _not_terminated;
1560 _array_for_gc = NULL;
1561 _suspend_equivalent = false;
1562 _in_deopt_handler = 0;
1563 _doing_unsafe_access = false;
1564 _stack_guard_state = stack_guard_unused;
1565 #if INCLUDE_JVMCI
1566 _pending_monitorenter = false;
1567 _pending_deoptimization = -1;
1568 _pending_failed_speculation = 0;
1569 _pending_transfer_to_interpreter = false;
1570 _adjusting_comp_level = false;
1571 _in_retryable_allocation = false;
1572 _jvmci._alternate_call_target = NULL;
1573 assert(_jvmci._implicit_exception_pc == NULL, "must be");
1574 if (JVMCICounterSize > 0) {
1575 _jvmci_counters = NEW_C_HEAP_ARRAY(jlong, JVMCICounterSize, mtInternal);
1576 memset(_jvmci_counters, 0, sizeof(jlong) * JVMCICounterSize);
1577 } else {
1578 _jvmci_counters = NULL;
1579 }
1971 }
1972 // 6282335 JNI DetachCurrentThread spec states that all Java monitors
1973 // held by this thread must be released. The spec does not distinguish
1974 // between JNI-acquired and regular Java monitors. We can only see
1975 // regular Java monitors here if monitor enter-exit matching is broken.
1976 //
1977 // ensure_join() ignores IllegalThreadStateExceptions, and so does
1978 // ObjectSynchronizer::release_monitors_owned_by_thread().
1979 if (exit_type == jni_detach) {
1980 // Sanity check even though JNI DetachCurrentThread() would have
1981 // returned JNI_ERR if there was a Java frame. JavaThread exit
1982 // should be done executing Java code by the time we get here.
1983 assert(!this->has_last_Java_frame(),
1984 "should not have a Java frame when detaching or exiting");
1985 ObjectSynchronizer::release_monitors_owned_by_thread(this);
1986 assert(!this->has_pending_exception(), "release_monitors should have cleared");
1987 }
1988
1989 // These things needs to be done while we are still a Java Thread. Make sure that thread
1990 // is in a consistent state, in case GC happens
1991
1992 if (active_handles() != NULL) {
1993 JNIHandleBlock* block = active_handles();
1994 set_active_handles(NULL);
1995 JNIHandleBlock::release_block(block);
1996 }
1997
1998 if (free_handle_block() != NULL) {
1999 JNIHandleBlock* block = free_handle_block();
2000 set_free_handle_block(NULL);
2001 JNIHandleBlock::release_block(block);
2002 }
2003
2004 // These have to be removed while this is still a valid thread.
2005 remove_stack_guard_pages();
2006
2007 if (UseTLAB) {
2008 tlab().retire();
2009 }
2010
2819 ~RememberProcessedThread() {
2820 if (_cur_thr) {
2821 _cur_thr->set_processed_thread(NULL);
2822 }
2823 }
2824 };
2825
2826 void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
2827 // Verify that the deferred card marks have been flushed.
2828 assert(deferred_card_mark().is_empty(), "Should be empty during GC");
2829
2830 // Traverse the GCHandles
2831 Thread::oops_do(f, cf);
2832
2833 assert((!has_last_Java_frame() && java_call_counter() == 0) ||
2834 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!");
2835
2836 if (has_last_Java_frame()) {
2837 // Record JavaThread to GC thread
2838 RememberProcessedThread rpt(this);
2839
2840 // traverse the registered growable array
2841 if (_array_for_gc != NULL) {
2842 for (int index = 0; index < _array_for_gc->length(); index++) {
2843 f->do_oop(_array_for_gc->adr_at(index));
2844 }
2845 }
2846
2847 // Traverse the monitor chunks
2848 for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) {
2849 chunk->oops_do(f);
2850 }
2851
2852 // Traverse the execution stack
2853 for (StackFrameStream fst(this); !fst.is_done(); fst.next()) {
2854 fst.current()->oops_do(f, cf, fst.register_map());
2855 }
2856 }
2857
2858 // callee_target is never live across a gc point so NULL it here should
|