Sun, 15 Jan 2017 02:07:05 -0800
8034249: need more workarounds for suspend equivalent condition issue
Summary: Collect data at safepoint, do not rely on thread suspension
Reviewed-by: dcubed, dholmes
src/share/vm/prims/jvmtiEnv.cpp | file | annotate | diff | comparison | revisions | |
src/share/vm/prims/jvmtiEnvBase.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/prims/jvmtiEnv.cpp Wed Jan 11 04:26:49 2017 -0800 1.2 +++ b/src/share/vm/prims/jvmtiEnv.cpp Sun Jan 15 02:07:05 2017 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -1000,8 +1000,9 @@ 1.11 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list = 1.12 new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true); 1.13 1.14 - uint32_t debug_bits = 0; 1.15 - if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { 1.16 + // It is only safe to perform the direct operation on the current 1.17 + // thread. All other usage needs to use a vm-safepoint-op for safety. 1.18 + if (java_thread == calling_thread) { 1.19 err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); 1.20 } else { 1.21 // JVMTI get monitors info at safepoint. Do not require target thread to 1.22 @@ -1045,8 +1046,9 @@ 1.23 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list = 1.24 new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true); 1.25 1.26 - uint32_t debug_bits = 0; 1.27 - if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { 1.28 + // It is only safe to perform the direct operation on the current 1.29 + // thread. All other usage needs to use a vm-safepoint-op for safety. 1.30 + if (java_thread == calling_thread) { 1.31 err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); 1.32 } else { 1.33 // JVMTI get owned monitors info at safepoint. Do not require target thread to 1.34 @@ -1087,9 +1089,11 @@ 1.35 jvmtiError 1.36 JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_ptr) { 1.37 jvmtiError err = JVMTI_ERROR_NONE; 1.38 - uint32_t debug_bits = 0; 1.39 JavaThread* calling_thread = JavaThread::current(); 1.40 - if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { 1.41 + 1.42 + // It is only safe to perform the direct operation on the current 1.43 + // thread. All other usage needs to use a vm-safepoint-op for safety. 1.44 + if (java_thread == calling_thread) { 1.45 err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr); 1.46 } else { 1.47 // get contended monitor information at safepoint. 1.48 @@ -1298,8 +1302,10 @@ 1.49 jvmtiError 1.50 JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) { 1.51 jvmtiError err = JVMTI_ERROR_NONE; 1.52 - uint32_t debug_bits = 0; 1.53 - if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { 1.54 + 1.55 + // It is only safe to perform the direct operation on the current 1.56 + // thread. All other usage needs to use a vm-safepoint-op for safety. 1.57 + if (java_thread == JavaThread::current()) { 1.58 err = get_stack_trace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr); 1.59 } else { 1.60 // JVMTI get stack trace at safepoint. Do not require target thread to
2.1 --- a/src/share/vm/prims/jvmtiEnvBase.hpp Wed Jan 11 04:26:49 2017 -0800 2.2 +++ b/src/share/vm/prims/jvmtiEnvBase.hpp Sun Jan 15 02:07:05 2017 -0800 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -356,8 +356,12 @@ 2.11 } 2.12 VMOp_Type type() const { return VMOp_GetOwnedMonitorInfo; } 2.13 void doit() { 2.14 - ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread, 2.15 - _owned_monitors_list); 2.16 + _result = JVMTI_ERROR_THREAD_NOT_ALIVE; 2.17 + if (Threads::includes(_java_thread) && !_java_thread->is_exiting() 2.18 + && _java_thread->threadObj() != NULL) { 2.19 + _result = ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread, 2.20 + _owned_monitors_list); 2.21 + } 2.22 } 2.23 jvmtiError result() { return _result; } 2.24 }; 2.25 @@ -439,9 +443,13 @@ 2.26 jvmtiError result() { return _result; } 2.27 VMOp_Type type() const { return VMOp_GetStackTrace; } 2.28 void doit() { 2.29 - _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread, 2.30 - _start_depth, _max_count, 2.31 - _frame_buffer, _count_ptr); 2.32 + _result = JVMTI_ERROR_THREAD_NOT_ALIVE; 2.33 + if (Threads::includes(_java_thread) && !_java_thread->is_exiting() 2.34 + && _java_thread->threadObj() != NULL) { 2.35 + _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread, 2.36 + _start_depth, _max_count, 2.37 + _frame_buffer, _count_ptr); 2.38 + } 2.39 } 2.40 }; 2.41