Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtime] Don't do GC Unsafe transition in mono_gchandle_free #15214

Merged
merged 3 commits into from
Jun 19, 2019

Conversation

lambdageek
Copy link
Member

Revert one part of #14979 - mono_gchandle_free can be called by Xamarin.Mac form xamarin_dispose_helper which can run on a thread that's not attached to the runtime.

This is fine for SGen since the gchandle code is lockfree.

SGen also calls back into Mono, which fires a profiler event. The profiler has its own mechanism for tracking threads, but in buffer_lock() we need to make sure that we don't do the Mono thread state transitions if the thread is attached to the profiler but not to Mono.

Follow-up PR for #14975

…hed to the

runtime.

Some profiler events (for example gc_handle_deleted) could be raised on threads
that aren't attached to the runtime.  Since the thread won't participate in
Mono's stop the world (since the runtime can't see it), there's no need to do
the transition to GC Safe while the thread is trying to grab the profiler
buffer lock.
Xamarin.Mac can call back here from a native thread that isn't attached to the
runtime.  SGen gchandle code is lockfree, and the profiler event can fire
without involving Mono.
@lambdageek
Copy link
Member Author

Sample stack trace:

2:57:21.8986730 2019-06-14 22:57:21.898 xammac_tests[73291:143748981] error: mono_gchandle_free Cannot enter GC unsafe region if the thread is not attached
22:57:21.8987030 
22:57:21.8987260 =================================================================
22:57:21.8987390 	Native Crash Reporting
22:57:21.8987490 =================================================================
22:57:21.8987590 Got a SIGABRT while executing native code. This usually indicates
22:57:21.8987680 a fatal error in the mono runtime or one of the native libraries 
22:57:21.8987770 used by your application.
22:57:21.8987860 =================================================================
22:57:21.8987950 
22:57:21.8988040 =================================================================
22:57:21.8988140 	Basic Fault Adddress Reporting
22:57:21.8988230 =================================================================
22:57:21.8988550 Memory around native instruction pointer (0x7fff75a632c6):0x7fff75a632b6  ff ff c3 90 90 90 b8 48 01 00 02 49 89 ca 0f 05  .......H...I....
22:57:21.8988680 0x7fff75a632c6  73 08 48 89 c7 e9 87 a1 ff ff c3 55 48 89 e5 41  s.H........UH..A
22:57:21.8988790 0x7fff75a632d6  57 41 56 41 55 41 54 53 48 81 ec 88 00 00 00 4d  WAVAUATSH......M
22:57:21.8988880 0x7fff75a632e6  89 cf 49 89 f4 48 8d 05 76 f2 ec 32 48 8b 00 48  ..I..H..v..2H..H
22:57:21.8988960 
22:57:21.8989060 =================================================================
22:57:21.8989150 	Native stacktrace:
22:57:21.8989240 =================================================================
22:57:21.8992450 	0x10c59bd34 - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : mono_dump_native_crash_info
22:57:21.8993060 	0x10c58f4e5 - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : mono_handle_native_crash
22:57:21.8993220 	0x7fff75b0db5d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
22:57:21.8993330 	0x0 - Unknown
22:57:21.8993580 	0x7fff759cd6a6 - /usr/lib/system/libsystem_c.dylib : abort
22:57:21.8993700 	0x10c4afca0 - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : _ZL12log_callbackPKcS0_S0_iPv
22:57:21.8994130 	0x10c7e085e - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : monoeg_g_logv_nofree
22:57:21.8994570 	0x10c7e0912 - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : monoeg_g_log
22:57:21.8995100 	0x10c7cf570 - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : check_info
22:57:21.8995450 	0x10c7cf780 - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : mono_threads_enter_gc_unsafe_region_unbalanced_with_info
22:57:21.8995890 	0x10c6e964b - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : mono_gchandle_free
22:57:21.8996400 	0x10c4ad159 - /Users/builder/jenkins/workspace/xamarin-macios-pr-builder/tests/xharness/tmp-test-dir/xammac tests1183/bin/x86/Release/xammac_tests.app/Contents/MacOS/xammac_tests : _ZL22xamarin_dispose_helperPv
22:57:21.8996820 	0x7fff75971bf3 - /usr/lib/system/libsystem_blocks.dylib : _Block_release
22:57:21.8996960 	0x7fff49f72fa9 - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZN2CI14WarpKernelNodeD2Ev
22:57:21.8997060 	0x7fff49f72f3a - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZN2CI14WarpKernelNodeD0Ev
22:57:21.8997410 	0x7fff49fa074f - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZN2CI13NodeWithChildD2Ev
22:57:21.8997620 	0x7fff49fa0720 - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZN2CI10AffineNodeD0Ev
22:57:21.8997740 	0x7fff4a0d1412 - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZN2CI11ProgramNodeD2Ev
22:57:21.8998060 	0x7fff4a0d14a2 - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZN2CI11ProgramNodeD0Ev
22:57:21.8998190 	0x7fff49ff81bc - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZNSt3__112__hash_tableINS_17__hash_value_typeIyN2CI11ObjectCacheINS2_4NodeELb0EE5EntryEEENS_22__unordered_map_hasherIyS7_NS_4hashIyEELb1EEENS_21__unordered_map_equalIyS7_NS_8equal_toIyEELb1EEENS_9allocatorIS7_EEE17__deallocate_nodeEPNS_16__hash_node_baseIPNS_11__hash_nodeIS7_PvEEEE
22:57:21.8998290 	0x7fff49ff8167 - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : _ZNSt3__112__hash_tableINS_17__hash_value_typeIyN2CI11ObjectCacheINS2_4NodeELb0EE5EntryEEENS_22__unordered_map_hasherIyS7_NS_4hashIyEELb1EEENS_21__unordered_map_equalIyS7_NS_8equal_toIyEELb1EEENS_9allocatorIS7_EEE5clearEv
22:57:21.8998390 	0x7fff49ff8212 - /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage : ___ZN2CI11ObjectCacheINS_4NodeELb0EE5clearEv_block_invoke
22:57:21.8998650 	0x7fff758da5f8 - /usr/lib/system/libdispatch.dylib : _dispatch_call_block_and_release
22:57:21.8998770 	0x7fff758db63d - /usr/lib/system/libdispatch.dylib : _dispatch_client_callout
22:57:21.8998870 	0x7fff758e18e0 - /usr/lib/system/libdispatch.dylib : _dispatch_lane_serial_drain
22:57:21.8998960 	0x7fff758e2396 - /usr/lib/system/libdispatch.dylib : _dispatch_lane_invoke
22:57:21.8999060 	0x7fff758ea6ed - /usr/lib/system/libdispatch.dylib : _dispatch_workloop_worker_thread
22:57:21.8999150 	0x7fff75b15611 - /usr/lib/system/libsystem_pthread.dylib : _pthread_wqthread
22:57:21.8999240 	0x7fff75b153fd - /usr/lib/system/libsystem_pthread.dylib : start_wqthread
22:57:21.9998840 Test run crashed (exit code: 134).

@chamons
Copy link
Contributor

chamons commented Jun 17, 2019

Please cherry pick to 2019-02 and notify us when it lands.

mono/utils/mono-threads-coop.h Outdated Show resolved Hide resolved
mono/profiler/log.c Show resolved Hide resolved
@lambdageek
Copy link
Member Author

@monojenkins backport to 2019-06
@monojenkins backport to 2019-02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants