You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
Simple/Threading test is crashing intermittently on Linux/OSX Release #4676
and the register we're trying to report as live is R15 (callee-saved), which contradicts the comment on RhpPInvoke where we say 'the codegenerator must ensure that there are no live GC references in callee saved registers.'
I'm not familiar with the LSRA code @sandreenko fixed, so I don't know yet why that fix isn't sufficient.
Based on the GC liveness info, we're dropping R15 at offset 280 and then making it live again at 314.
However, our transition frame that we push prior to the PInvoke has the RIP at offset 275, which explains why we think R15 is still live. Oops, I misread this part. The RIP in the transition frame is actually at offset 280.
Think I've found a similar issue, running code that uses several threads where the number of threads are configurable (lowering the number of thread reduces the chance of this issue happening). The code works fine when running just as JIT code but not as AOT compiled to native code. Code running on Ubuntu 14.04.5 LTS. Call stack as follows:
It is call to CoreLibNative_GetTickCount64 above. The codegen part of the spilling works fine. The problem is that the spilling is not reflected in the GCInfo correctly. The registers are still reported as alive during RhpPInvoke call, and they are reported dead right after the RhpPInvoke call.
In this example, we use 0x1001e5b0c for the GC reporting during the PInvoke. This IP still has the registers reported as alive.
I can think of several options on how to fix this:
Option 1: Make sure that the registers are reported dead in GCInfo before the RhpPInvoke helper. The following code seems to be taking care of it for the regular PInvoke callsites. Does it need to be changed to emit the label for RhpPInvoke helper instead, or in addition to the regular callsite, when JIT_FLAG_USE_PINVOKE_HELPERS is set?
// For a pinvoke to unmanaged code we emit a label to clear
// the GC pointer state before the callsite.
// We can't utilize the typical lazy killing of GC pointers
// at (or inside) the callsite.
if (call->IsUnmanaged())
{
genDefineTempLabel(genCreateTempLabel());
}
Option 2: Add argument to RhpPInvoke helper that describes the actual IP of the PInvoke callsite return. It is what happens for regular inlined PInvokes - look for genPendingCallLabel. The address of this pending label would be used as the RhpPInvoke helper argument.
If we went with this option, we would use 0x1001e5b11 IP for the GC reporting during the PInvoke in the example above and everything would be good.
Option 3: Change the CoreRT stackwalker to track where the IP came from and pass this information into the ICodeManager::EnumGcRefs to let it adjust the IP accordingly. We would bump the IP for reporting when we know that it is coming from PInvoke. There is similar mechanism for hardware exceptions today - look for RemapHardwareFaultToGCSafePoint. This would mean generalizing this mechanism for other cases. I think this would be my least favorite option.
@sandreenko Could you please look into feasibility of options 1 and 2 on the JIT side?
Do you mean warnings when I build corert or my project? For my project there is an .so that is C/C++ code build by gcc and installed as a release build and then the C# code is using pinvoke to talk to it. I'm getting an unmanaged warning but pretty sure it's unrelated:
I'll get a debug build of the .so and debug symbols to see if that helps. For the code I'm running there are various system tests and I'm trying to run the worse case system stress test under corert. All the tests pass when running on linux under JIT and the code set is out there in production on .Net framework 2.0 and 4.0. So should be pretty stable but maybe something being provoked by something we're doing.
I've tried with a debug build of the .so after I'm getting a slightly different call stack that's missing the RedhawkGCInterface::EnumGcRefs frame, so not sure what to disassemble further.
so far it looks related to a structure along the lines of
If the struct is passed by value, could you try debugging around the p/invoke? I'm wondering if this could be some sort of corruption because we don't have the implementation for #158 yet.
Where the RecordUpdate is the struct previously mentioned. Would you still like me to debug the pinvoke? I'm in the uk so will be signing off soon but can pick up tomorrow.
The test is using the .so to receive a list of 50k items over tcpip and present it to a managed api interface. It uses a few threads but I've minimized the thread usage as much as possible. Just processing one set of 50k items usually fails but I have managed infrequently to run several times in a loop the same test before it fails. So it does basically work and if I reduce the test to 500 items and loop it 10 times for example I haven't seen it fail yet. It feels like some race in the gc/unmanaged code->managed code collection somewhere. If I run very similar tests but fake the data coming back from unmanaged so everything is managed I never get a failure.
These structs are passed by reference. They won't hit the with missing implementation for #158.
This looks like a GC heap corruption. It does not look related to the original problem tracked by this issue. The problem seems to be that the GC collected an object that is still referenced from somewhere; or that something (e.g. interop) overrun the GC allocated buffer. You can try to look around the objects that the GC was scanning when the crash happened to see whether there is any pattern (e.g. what is the object being scanned by mark_object_simple). I am sorry - it is hard to debug these kind of issue over the phone.
You can try to workaround it by enabling conservative GC reporting - remove ifdef around RhpEnableConservativeStackReporting() in src\Native\Bootstrap\main.cpp. It would help us to know whether this workaround make the crash go away for you.
If there is a real bug, we will very likely hit it and fix it eventually as we get more CoreRT testing in place (e.g. we plan to work on corefx tests).
Thanks, jkotas, I've updated to #4812 and also remove ifdef around RhpEnableConservativeStackReporting() I'm still seeing the issue and the call stack still looks corrupt, I've put the details at the end of this post. I'm happy to spend more time on this but I'll leave it to you to advice on how to proceed. If you'd like me to wait until there are more tests happy to do that, if you'd like to remotely connect to diagnose happy to do that too or happy to carry on investigating. In the mean time I'm pretty sure I have a good idea of the factors involved (all the items mentioned previously) that provoke this issue, I'll work on getting a test I can share with yourselves.
As a side note, I've been watching the progress of corert with interest since the start of the project, every now and then I'll update with the latest corert and give native compilation a go. This time around, obviously with this issue we are discussing here aside, I had to put in workarounds in for #2619 and #3408 and after that I have our baseline .Net code running as a native exe on linux, which is simply astounding, really impressed with everything you are doing here!
Ok, the next thing to look at are the types of object that are being scanned. E.g. MetadataReader
and NativeFormatRuntimeNamedTypeInfo are the objects being scanned in my example below. Try this on a few different crashes to see whether the type is always the same. I expect that the object scanned in mark_object_simple1 is going to be invalid in your case, but the object in mark_object_simple should be good.
(gdb) frame 0
#0 WKS::gc_heap::mark_object_simple1 (oo=0x7fffe5f169c0 "q\245", <incomplete sequence \331>,
start=0x7fffe5f169c0 "q\245", <incomplete sequence \331>)
at /home/jkotas/corert/src/Native/Runtime/Full/../../gc/gc.cpp:17593
17593 SERVER_SC_MARK_VOLATILE(uint8_t*)* mark_stack_limit = (SERVER_SC_MARK_VOLATILE(uint8_t*)*)&mark_stack_array[mark_stack_array_length];
(gdb) info symbol *(void**)oo
vtable for S_P_Reflection_Metadata_Internal_Metadata_NativeFormat_MetadataReader + 1 in section .data of /home/jkotas/corert/tests/src/Simple/Threading/bin/Debug/x64/native/Threading
(gdb) frame 1
#1 0x00000000004954fb in WKS::gc_heap::mark_object_simple (po=0x7fffe4edc9f0)
at /home/jkotas/corert/src/Native/Runtime/Full/../../gc/gc.cpp:18174
18174 go_through_object_cl (method_table(o), o, s, poo,
(gdb) info symbol **(void***)po
vtable for S_P_Reflection_Core_System_Reflection_Runtime_TypeInfos_NativeFormat_NativeFormatRuntimeNamedTypeInfo + 1 in section .data of /home/jkotas/corert/tests/src/Simple/Threading/bin/Debug/x64/native/Threading
I've used lldb to look up the information, so focusing in on mark_object_simple/mark_object_simple1 the section from lldb bt gives (I've pasted 2 runs here but the 3rd was the same):
frame #2: 0x0000000000497d53 ConsoleApp1`WKS::gc_heap::mark_object_simple1(unsigned char*, unsigned char*) [inlined] WKS::my_get_size(ob=0x00007fffdfd742a0) + 25 at gc.cpp:8897
frame #3: 0x0000000000497d3a ConsoleApp1`WKS::gc_heap::mark_object_simple1(oo="Il�, start="Il�) + 8282 at gc.cpp:17730
frame #4: 0x000000000049889b ConsoleApp1`WKS::gc_heap::mark_object_simple(po=0x00007fffcd99d0a0) + 1883 at gc.cpp:18174
So problem seems to be that array backing Dictionary<string,string> is pointing to a string that got collected by the garbage collector already. The most likely cause is a missing GC write barrier somewhere.
If the inconsistency check fails, it should break in debugger like this:
#2 0x00000000005e799c in Assert (expr=0x97a293 "!\"Pointer updated without using write barrier\"",
file=0x96c334 "/home/jkotas/corert/src/Native/Runtime/Full/../../gc/gc.cpp", line_num=36733, message=0x0)
at /home/jkotas/corert/src/Native/Runtime/rhassert.cpp:25
#3 0x00000000004e5d2f in WKS::testGCShadow (ptr=0x7fffe5f252b8)
at /home/jkotas/corert/src/Native/Runtime/Full/../../gc/gc.cpp:36733
Again, print the vtable of the object that is failing the check. Hopefully, it will be the array backing Dictionary<string,string> again.
Also, it may be useful to find out what are the strings stored in the dictionary that is hitting the problem. It should allow us to guess where the dictionary came from. The first 8 bytes in array object is pointer to the vtable. The next 8 bytes are number of elements. And then there are the array elements. In the case of Dictionary backing array, each element is 24 bytes: 32-bit string hashcode, 32-bit index, and two string object pointers. You can try to look around what kind of strings are stored in the dictionary.
I've rebuilt everything from your branch, I did it quickly as I'm about to head off so I might have made a mistake. On the face of it, the results look the same. Anyway to verify the build is correct from the callstack?
It is quite possible that the problem is something else. If you would like to double check that the instrumentation is kicking in, you can set a breakpoint at RhpAssignRef assembly helper, single step through it and verify that it is running through the GCShadow path.
So it may be useful to look at the content of the corrupted array - find out what kind of strings are stored into it.
I have also talked to @sergiy-k about this. He may have some tips how to get the GC to run more often so that it crashes closer to the problem.
Another thing you can try is to change int GetGCgen0size () const { return 0; } to int GetGCgen0size () const { return 64 * 1024; } in gcenv.h. It will cause the GC to run more frequently - hopefully, it will break closer to the place where the problem happens.
Activity
jkotas commentedon Oct 5, 2017
The thread that we are stackwalking is stopped at:
Looks like the GCInfo around
CoreLibNative_GetTickCount64PInvoke is not right, or is not interpreted correctly.jkotas commentedon Oct 5, 2017
cc @adityamandaleeka
jkotas commentedon Oct 5, 2017
It does not repro with debug build.
It does repro in release build with optimizations disabled and debug info enabled for the unmanaged runtime here (useful for debugging): https://github.com/dotnet/corert/blob/master/src/Native/CMakeLists.txt#L229 .
adityamandaleeka commentedon Oct 5, 2017
Thanks @jkotas. I'm trying to repro it now. Roughly how frequently does it repro for you?
jkotas commentedon Oct 5, 2017
Repros reliably in <10 tries (on Macbook).
jkotas commentedon Oct 5, 2017
BTW: The crash looks exactly same as #4214 . It looks like that the fix was incomplete.
adityamandaleeka commentedon Oct 5, 2017
Thanks, I am able to reproduce this now.
sergiy-k commentedon Oct 6, 2017
cc @sandreenko
adityamandaleeka commentedon Oct 8, 2017
Yea, this is the same issue as #4214. The thread we're scanning is here:
and the register we're trying to report as live is R15 (callee-saved), which contradicts the comment on RhpPInvoke where we say 'the codegenerator must ensure that there are no live GC references in callee saved registers.'
I'm not familiar with the LSRA code @sandreenko fixed, so I don't know yet why that fix isn't sufficient.
sandreenko commentedon Oct 9, 2017
I will take a look.
adityamandaleeka commentedon Oct 9, 2017
@sandreenko I might have a clue about what's going on. Here's an extended snippet of the disassembly:
Based on the GC liveness info, we're dropping R15 at offset 280 and then making it live again at 314.
However, our transition frame that we push prior to the PInvoke has the RIP at offset 275, which explains why we think R15 is still live.Oops, I misread this part. The RIP in the transition frame is actually at offset 280.dlewis-arcontech commentedon Oct 20, 2017
Think I've found a similar issue, running code that uses several threads where the number of threads are configurable (lowering the number of thread reduces the chance of this issue happening). The code works fine when running just as JIT code but not as AOT compiled to native code. Code running on Ubuntu 14.04.5 LTS. Call stack as follows:
EEType::get_BaseSize(this=0x0000000000000000) + 12 at eetype.h:365 frame #1: 0x00000000004edfd5 ConsoleApp1MethodTable::GetBaseSize(this=0x0000000000000000) + 21 at gcenv.h:91frame Add basic build scripts #2: 0x0000000000494328 ConsoleApp1
WKS::gc_heap::mark_object_simple1(unsigned char*, unsigned char*) [inlined] WKS::my_get_size(ob=0x00007fffdfd4b568) + 25 at gc.cpp:8897 frame #3: 0x000000000049430f ConsoleApp1WKS::gc_heap::mark_object_simple1(oo="\x01��", start="\xb0\x87\xaa���") + 6927 at gc.cpp:17730frame Improve .gitignore #4: 0x00000000004953bb ConsoleApp1
WKS::gc_heap::mark_object_simple(po=0x00007fffccb1b020) + 1883 at gc.cpp:18174 frame #5: 0x000000000049e281 ConsoleApp1WKS::GCHeap::Promote(ppObject=0x00007fffccb1cc28, sc=0x00007fffccb1bfc8, flags=0) + 1137 at gc.cpp:33817frame CoreLib doesn't implement Environment.GetEnvironmentVariable and friends #6: 0x0000000000419313 ConsoleApp1
GcEnumObject(ppObj=0x00007fffccb1cc28, flags=0, fnGcEnumRef=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), pSc=0x00007fffccb1bfc8)(Object**, ScanContext*, unsigned int), ScanContext*) + 131 at gcrhscan.cpp:150frame Add type system source files #7: 0x0000000000415c54 ConsoleApp1
EnumGcRefsCallback(hCallback=0x00007fffccb1b9a0, pObject=0x00007fffccb1cc28, flags=0) + 68 at gcrhenv.cpp:508 frame #8: 0x00000000005db4dc ConsoleApp1GcInfoDecoder::ReportStackSlotToGC(this=0x00007fffccb1b8c8, spOffset=-72, spBase=GC_FRAMEREG_REL, gcFlags=0, pRD=0x00007fffccb1bae0, flags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffccb1b9a0)(void*, void**, unsigned int), void*) + 156 at gcinfodecoder.cpp:1827 frame #9: 0x00000000005dcd29 ConsoleApp1GcInfoDecoder::ReportSlotToGC(this=0x00007fffccb1b8c8, slotDecoder=0x00007fffccb1b7c8, slotIndex=15, pRD=0x00007fffccb1bae0, reportScratchSlots=true, inputFlags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffccb1b9a0)(void*, void**, unsigned int), void*) + 377 at gcinfodecoder.h:688 frame #10: 0x00000000005da12a ConsoleApp1GcInfoDecoder::ReportUntrackedSlots(this=0x00007fffccb1b8c8, slotDecoder=0x00007fffccb1b7c8, pRD=0x00007fffccb1bae0, inputFlags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffccb1b9a0)(void*, void**, unsigned int), void*) + 138 at gcinfodecoder.cpp:1008 frame #11: 0x00000000005d75e3 ConsoleApp1GcInfoDecoder::EnumerateLiveSlots(this=0x00007fffccb1b8c8, pRD=0x00007fffccb1bae0, reportScratchSlots=false, inputFlags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffccb1b9a0)(void*, void**, unsigned int), void*) + 8707 at gcinfodecoder.cpp:957 frame #12: 0x00000000005db9a9 ConsoleApp1UnixNativeCodeManager::EnumGcRefs(this=0x0000000000dbe850, pMethodInfo=0x00007fffccb1bb78, safePointAddress=0x0000000000673d86, pRegisterSet=0x00007fffccb1bae0, hCallback=0x00007fffccb1b9a0) + 473 at UnixNativeCodeManager.cpp:153frame Initial population of CoreRT Runtime files. #13: 0x0000000000415bed ConsoleApp1
RedhawkGCInterface::EnumGcRefs(pCodeManager=0x0000000000dbe850, pMethodInfo=0x00007fffccb1bb78, safePointAddress=0x0000000000673d86, pRegisterSet=0x00007fffccb1bae0, pfnEnumCallback=0x000000000049de10, pvCallbackData=0x00007fffccb1bfc8) + 141 at gcrhenv.cpp:534 frame #14: 0x000000000043611c ConsoleApp1Thread::GcScanRootsWorker(this=0x00007fffccb1d5e8, pfnEnumCallback=0x000000000049de10, pvCallbackData=0x00007fffccb1bfc8, frameIterator=0x00007fffccb1bac0) + 572 at thread.cpp:491frame Set AllowUnsafeBlocks irrespective of build configuration #15: 0x0000000000435eb4 ConsoleApp1
Thread::GcScanRoots(this=0x00007fffccb1d5e8, pfnEnumCallback=0x000000000049de10, pvCallbackData=0x00007fffccb1bfc8) + 132 at thread.cpp:408 frame #16: 0x0000000000418f35 ConsoleApp1GCToEEInterface::GcScanRoots(fn=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), condemned=2, max_gen=2, sc=0x00007fffccb1bfc8)(Object**, ScanContext*, unsigned int), int, int, ScanContext*) + 501 at gcrhscan.cpp:85 frame #17: 0x00000000005c3fb9 ConsoleApp1GCScan::GcScanRoots(fn=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), condemned=2, max_gen=2, sc=0x00007fffccb1bfc8)(Object**, ScanContext*, unsigned int), int, int, ScanContext*) + 41 at gcscan.cpp:170 frame #18: 0x0000000000479a4c ConsoleApp1WKS::gc_heap::mark_phase(condemned_gen_number=2, mark_only_p=NO) + 2060 at gc.cpp:19592frame Unify caching pattern between EcmaMethod and EcmaField #19: 0x00000000004713d7 ConsoleApp1
WKS::gc_heap::gc1() + 519 at gc.cpp:15262 frame #20: 0x000000000048e3d3 ConsoleApp1WKS::gc_heap::garbage_collect(n=0) + 3395 at gc.cpp:16853frame Wire up CppCodeGen into ILToNative #21: 0x0000000000463051 ConsoleApp1
WKS::GCHeap::GarbageCollectGeneration(this=0x0000000000db61e0, gen=0, reason=reason_alloc_loh) + 2049 at gc.cpp:35188 frame #22: 0x00000000004681ff ConsoleApp1WKS::gc_heap::try_allocate_more_space(acontext=0x00007fffccb1c9b0, size=131128, gen_number=3) + 1503 at gc.cpp:13066frame Make ThreadSafeFlags public #23: 0x0000000000468373 ConsoleApp1
WKS::gc_heap::allocate_more_space(acontext=0x00007fffccb1c9b0, size=131128, alloc_generation_number=3) + 35 at gc.cpp:13362 frame #24: 0x00000000004d9a74 ConsoleApp1WKS::gc_heap::allocate_large_object(jsize=131096, alloc_bytes=0x00007fffccb1d600) + 500 at gc.cpp:30569frame Make build.cmd more like the build.cmd in CoreCLR repo #25: 0x00000000004e1ace ConsoleApp1
WKS::GCHeap::Alloc(this=0x0000000000db61e0, context=0x00007fffccb1d5e8, size=131096, flags=0) + 446 at gc.cpp:34542 frame #26: 0x0000000000415933 ConsoleApp1::RhpGcAlloc(pEEType=0x0000000000cad100, uFlags=0, cbSize=131096, pTransitionFrame=0x00007fffccb1cb18) + 211 at gcrhenv.cpp:273frame Enhance virtual function resolution logic to be roughly correct. #27: 0x00000000005e49ca ConsoleApp1
RhpNewArrayRare + 54 at unixasmmacrosamd64.inc:651 frame #28: 0x00000000005fd198 ConsoleApp1 frame #29: 0x0000000000686ce3 ConsoleApp1 frame #30: 0x000000000064b9fd ConsoleApp1 frame #31: 0x000000000061a111 ConsoleApp1 frame #32: 0x0000000000673d86 ConsoleApp1 frame #33: 0x000000000062d949 ConsoleApp1 frame #34: 0x0000000000622f80 ConsoleApp1 frame #35: 0x00000000006922d8 ConsoleApp1 frame #36: 0x000000000067db78 ConsoleApp1 frame #37: 0x00007ffff6d93184 libpthread.so.0start_thread(arg=0x00007fffccb1d700) + 196 at pthread_create.c:312frame Fix project GUID in the ProjectReference from ILToNative #38: 0x00007ffff6ac037d libc.so.6`__clone + 109 at clone.S:111
sandreenko commentedon Oct 21, 2017
I checked that if we spill all gc refs before each call the issue still occurs.
Did anybody found the bad method name?
jkotas commentedon Oct 21, 2017
It is call to
CoreLibNative_GetTickCount64above. The codegen part of the spilling works fine. The problem is that the spilling is not reflected in the GCInfo correctly. The registers are still reported as alive during RhpPInvoke call, and they are reported dead right after the RhpPInvoke call.In this example, we use
0x1001e5b0cfor the GC reporting during the PInvoke. This IP still has the registers reported as alive.I can think of several options on how to fix this:
Option 1: Make sure that the registers are reported dead in GCInfo before the RhpPInvoke helper. The following code seems to be taking care of it for the regular PInvoke callsites. Does it need to be changed to emit the label for RhpPInvoke helper instead, or in addition to the regular callsite, when
JIT_FLAG_USE_PINVOKE_HELPERSis set?Option 2: Add argument to RhpPInvoke helper that describes the actual IP of the PInvoke callsite return. It is what happens for regular inlined PInvokes - look for
genPendingCallLabel. The address of this pending label would be used as the RhpPInvoke helper argument.If we went with this option, we would use
0x1001e5b11IP for the GC reporting during the PInvoke in the example above and everything would be good.Option 3: Change the CoreRT stackwalker to track where the IP came from and pass this information into the ICodeManager::EnumGcRefs to let it adjust the IP accordingly. We would bump the IP for reporting when we know that it is coming from PInvoke. There is similar mechanism for hardware exceptions today - look for
RemapHardwareFaultToGCSafePoint. This would mean generalizing this mechanism for other cases. I think this would be my least favorite option.@sandreenko Could you please look into feasibility of options 1 and 2 on the JIT side?
9 remaining items
jkotas commentedon Oct 26, 2017
This looks like a regular managed method. I think we need to find out why it does not have the right symbol. It is likely symptom of the problem.
Do you see any warnings from the unmanaged linker (
clang-3.9) during the compilation by any chance?dlewis-arcontech commentedon Oct 26, 2017
Do you mean warnings when I build corert or my project? For my project there is an .so that is C/C++ code build by gcc and installed as a release build and then the C# code is using pinvoke to talk to it. I'm getting an unmanaged warning but pretty sure it's unrelated:
EXEC : warning : Method
[System.Text.RegularExpressions]System.Text.RegularExpressions.Regex.Compilewill always throw because: [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.Reflection.Emit.ILGenerator, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a [/home/darren/DNAStandard/ConsoleApp1/ConsoleApp1.csproj]I'll get a debug build of the .so and debug symbols to see if that helps. For the code I'm running there are various system tests and I'm trying to run the worse case system stress test under corert. All the tests pass when running on linux under JIT and the code set is out there in production on .Net framework 2.0 and 4.0. So should be pretty stable but maybe something being provoked by something we're doing.
dlewis-arcontech commentedon Oct 26, 2017
I've tried with a debug build of the .so after I'm getting a slightly different call stack that's missing the RedhawkGCInterface::EnumGcRefs frame, so not sure what to disassemble further.
Process 9969 stopped
EEType::get_BaseSize(this=0x0000000000000000) + 12 at eetype.h:365, name = 'ConsoleApp1', stop reason = signal SIGSEGV: invalid address (fault address: 0x4) frame #0: 0x000000000041aeac ConsoleApp1EEType::get_BaseSize(this=0x0000000000000000) + 12 at eetype.h:365362
363 #ifndef RHDUMP
364 UInt32 get_BaseSize()
-> 365 { return m_uBaseSize; }
366
367 UInt16 get_ComponentSize()
368 { return m_usComponentSize; }
(lldb) bt
EEType::get_BaseSize(this=0x0000000000000000) + 12 at eetype.h:365 frame #1: 0x00000000004f14a5 ConsoleApp1MethodTable::GetBaseSize(this=0x0000000000000000) + 21 at gcenv.h:91frame Add basic build scripts #2: 0x0000000000498369 ConsoleApp1
WKS::gc_heap::mark_object_simple(unsigned char**) [inlined] WKS::my_get_size(ob=0x00007fffdfa80e88) + 34 at gc.cpp:8897 frame #3: 0x0000000000498347 ConsoleApp1WKS::gc_heap::mark_object_simple(po=0x00007fffeeefd300) + 535 at gc.cpp:18171frame Improve .gitignore #4: 0x00000000004a6ed1 ConsoleApp1
WKS::gc_heap::mark_through_cards_for_large_objects(void (*)(unsigned char**), unsigned int) [inlined] WKS::gc_heap::mark_through_cards_helper(poo=0x00007fffeeefd300, n_gen=0x00007fffcd99d370, cg_pointers_found=0x00007fffcd99d380, fn=(ConsoleApp1WKS::gc_heap::mark_object_simple(unsigned char**) at gc.cpp:18157), nhigh="�J����", next_boundary="p!\x01\x01")(unsigned char**), unsigned char*, unsigned char*) + 79 at gc.cpp:27545frame Make GC and GCSample compile and run on Linux #5: 0x00000000004a6e82 ConsoleApp1
WKS::gc_heap::mark_through_cards_for_large_objects(fn=(ConsoleApp1WKS::gc_heap::mark_object_simple(unsigned char**) at gc.cpp:18157), relocating=NO)(unsigned char**), unsigned int) + 8786 at gc.cpp:31857frame CoreLib doesn't implement Environment.GetEnvironmentVariable and friends #6: 0x000000000047d53f ConsoleApp1
WKS::gc_heap::mark_phase(condemned_gen_number=0, mark_only_p=NO) + 3631 at gc.cpp:19662 frame #7: 0x00000000004748a7 ConsoleApp1WKS::gc_heap::gc1() + 519 at gc.cpp:15262frame Add type system source files #8: 0x00000000004918a3 ConsoleApp1
WKS::gc_heap::garbage_collect(n=0) + 3395 at gc.cpp:16853 frame #9: 0x0000000000466521 ConsoleApp1WKS::GCHeap::GarbageCollectGeneration(this=0x000000000101c1e0, gen=0, reason=reason_alloc_soh) + 2049 at gc.cpp:35188frame Add ILToNative source files #10: 0x000000000046b6cf ConsoleApp1
WKS::gc_heap::try_allocate_more_space(acontext=0x00007fffcd99f5e8, size=24, gen_number=0) + 1503 at gc.cpp:13066 frame #11: 0x000000000046b843 ConsoleApp1WKS::gc_heap::allocate_more_space(acontext=0x00007fffcd99f5e8, size=24, alloc_generation_number=0) + 35 at gc.cpp:13362frame Make simple test work #12: 0x00000000004e4f55 ConsoleApp1
WKS::GCHeap::Alloc(gc_alloc_context*, unsigned long, unsigned int) + 277 at gc.cpp:13393 frame #13: 0x00000000004e4e40 ConsoleApp1WKS::GCHeap::Alloc(this=0x000000000101c1e0, context=0x00007fffcd99f5e8, size=24, flags=0) + 96 at gc.cpp:34534frame Implement simple casting #14: 0x0000000000418c23 ConsoleApp1
::RhpGcAlloc(pEEType=0x0000000000ef3b78, uFlags=0, cbSize=24, pTransitionFrame=0x00007fffcd99dff8) + 211 at gcrhenv.cpp:273 frame #15: 0x00000000005e7d38 ConsoleApp1RhpNewObject + 48 at unixasmmacrosamd64.inc:428frame Fix build warnings around NuGet dependencies #16: 0x00000000007fadf7 ConsoleApp1
S_P_CoreLib_System_Collections_Generic_DefaultComparer_1<Int32>__Compare + 47 at Comparer.cs:65 frame #17: 0x00000000007fa8ee ConsoleApp1 at WaitHandleArray.cs:122 frame #18: 0x00000000009bb41f ConsoleApp1 at CustomAttributeExtensions.cs:261 frame #19: 0x00000000009bb61e ConsoleApp1 at CustomAttributeExtensions.cs:261 frame #20: 0x00000000009b4d73 ConsoleApp1 at ServerMonitor.cs:263 frame #21: 0x00000000009aff47 ConsoleApp1 at FeedObjectBase.cs:45 frame #22: 0x000000000099896d ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__ExtractChainImage + 2321 at ChainWatcher.cs:1851frame Make ThreadSafeFlags public #23: 0x000000000098f5d4 ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__ParseChainUpdate + 388 at ChainWatcher.cs:1990 frame #24: 0x0000000000985419 ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__Arcontech_DotNetAPI_FeedApi_IFeedInstrumentWatcher_Update + 233 at ChainWatcher.cs:2191frame Make build.cmd more like the build.cmd in CoreCLR repo #25: 0x00000000009688b9 ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerInstrumentWatcher__ProcessBatch + 1161 at FeedHandlerInstrumentWatcher.cs:113 frame #26: 0x0000000000950984 ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerBase_1<System___Canon>__Arcontech_DotNetAPI_FeedApi_IFeedQueueItem_DispatchMessage + 224 at FeedHandlerBase.cs:863frame Enhance virtual function resolution logic to be roughly correct. #27: 0x000000000091aaaf ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerQueueDispatcher_QueueItem__Dispatch + 43 at FeedHandlerQueueDispatcher.cs:38 frame #28: 0x0000000000908bc3 ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerQueueDispatcher__ProcessQueue + 287 at FeedHandlerQueueDispatcher.cs:147frame Fix build break #29: 0x0000000000749a3b ConsoleApp1 at WorkItemDispatcher.cs:175
frame Add field layout tests #30: 0x000000000082bf43 ConsoleApp1
S_P_CoreLib_Internal_Runtime_Augments_RuntimeThread__StartThread + 287 at RuntimeThread.cs:486 frame #31: 0x0000000000813e8a ConsoleApp1S_P_CoreLib_Internal_Runtime_Augments_RuntimeThread__ThreadEntryPoint + 54 at RuntimeThread.Unix.cs:143frame Name mangling robustness #32: 0x00007ffff6d93184 libpthread.so.0
start_thread(arg=0x00007fffcd99f700) + 196 at pthread_create.c:312 frame #33: 0x00007ffff6ac037d libc.so.6__clone + 109 at clone.S:111MichalStrehovsky commentedon Oct 26, 2017
If the struct is passed by value, could you try debugging around the p/invoke? I'm wondering if this could be some sort of corruption because we don't have the implementation for #158 yet.
dlewis-arcontech commentedon Oct 26, 2017
It might be related, the struct is passed into a pinvoke function as a ref parameter. The flow of events are
First call this:
Where you register a callback function as:
internal delegate int FeedCallback(int feedCallbackID, int feedHandle, int serverStatus);
Then during the callback from unmanaged code to managed code (FeedCallback) this function is called:
Where the RecordUpdate is the struct previously mentioned. Would you still like me to debug the pinvoke? I'm in the uk so will be signing off soon but can pick up tomorrow.
dlewis-arcontech commentedon Oct 26, 2017
The test is using the .so to receive a list of 50k items over tcpip and present it to a managed api interface. It uses a few threads but I've minimized the thread usage as much as possible. Just processing one set of 50k items usually fails but I have managed infrequently to run several times in a loop the same test before it fails. So it does basically work and if I reduce the test to 500 items and loop it 10 times for example I haven't seen it fail yet. It feels like some race in the gc/unmanaged code->managed code collection somewhere. If I run very similar tests but fake the data coming back from unmanaged so everything is managed I never get a failure.
jkotas commentedon Oct 26, 2017
These structs are passed by reference. They won't hit the with missing implementation for #158.
This looks like a GC heap corruption. It does not look related to the original problem tracked by this issue. The problem seems to be that the GC collected an object that is still referenced from somewhere; or that something (e.g. interop) overrun the GC allocated buffer. You can try to look around the objects that the GC was scanning when the crash happened to see whether there is any pattern (e.g. what is the object being scanned by
mark_object_simple). I am sorry - it is hard to debug these kind of issue over the phone.You can try to workaround it by enabling conservative GC reporting - remove ifdef around RhpEnableConservativeStackReporting() in src\Native\Bootstrap\main.cpp. It would help us to know whether this workaround make the crash go away for you.
If there is a real bug, we will very likely hit it and fix it eventually as we get more CoreRT testing in place (e.g. we plan to work on corefx tests).
dlewis-arcontech commentedon Oct 27, 2017
Thanks, jkotas, I've updated to #4812 and also remove ifdef around RhpEnableConservativeStackReporting() I'm still seeing the issue and the call stack still looks corrupt, I've put the details at the end of this post. I'm happy to spend more time on this but I'll leave it to you to advice on how to proceed. If you'd like me to wait until there are more tests happy to do that, if you'd like to remotely connect to diagnose happy to do that too or happy to carry on investigating. In the mean time I'm pretty sure I have a good idea of the factors involved (all the items mentioned previously) that provoke this issue, I'll work on getting a test I can share with yourselves.
As a side note, I've been watching the progress of corert with interest since the start of the project, every now and then I'll update with the latest corert and give native compilation a go. This time around, obviously with this issue we are discussing here aside, I had to put in workarounds in for #2619 and #3408 and after that I have our baseline .Net code running as a native exe on linux, which is simply astounding, really impressed with everything you are doing here!
(lldb) bt
frame #0: 0x000000000041aebc ConsoleApp1
EEType::get_BaseSize(this=0x0065005400000012) + 12 at eetype.h:365 frame #1: 0x00000000004f14b5 ConsoleApp1MethodTable::GetBaseSize(this=0x0065005400000012) + 21 at gcenv.h:91frame Add basic build scripts #2: 0x0000000000497d53 ConsoleApp1
WKS::gc_heap::mark_object_simple1(unsigned char*, unsigned char*) [inlined] WKS::my_get_size(ob=0x00007fffdf88af38) + 25 at gc.cpp:8897 frame #3: 0x0000000000497d3a ConsoleApp1WKS::gc_heap::mark_object_simple1(oo="Il�, start="Il�) + 8282 at gc.cpp:17730frame Improve .gitignore #4: 0x000000000049889b ConsoleApp1
WKS::gc_heap::mark_object_simple(po=0x00007fffcd99d0a0) + 1883 at gc.cpp:18174 frame #5: 0x00000000004a1761 ConsoleApp1WKS::GCHeap::Promote(ppObject=0x00007fffcd99e378, sc=0x00007fffcd99d738, flags=3) + 1137 at gc.cpp:33817frame CoreLib doesn't implement Environment.GetEnvironmentVariable and friends #6: 0x000000000041c3d2 ConsoleApp1
GcEnumObjectsConservatively(ppLowerBound=0x00007fffcd99e0d0, ppUpperBound=0x00007fffcd9a0000, fnGcEnumRef=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), pSc=0x00007fffcd99d738)(Object**, ScanContext*, unsigned int), ScanContext*) + 130 at gcrhscan.cpp:179frame Add type system source files #7: 0x0000000000418fd3 ConsoleApp1
RedhawkGCInterface::EnumGcRefsInRegionConservatively(pLowerBound=0x00007fffcd99e0d0, pUpperBound=0x00007fffcd9a0000, pfnEnumCallback=0x00000000004a12f0, pvCallbackData=0x00007fffcd99d738) + 67 at gcrhenv.cpp:546 frame #8: 0x0000000000439516 ConsoleApp1Thread::GcScanRootsWorker(this=0x00007fffcd99f5e8, pfnEnumCallback=0x00000000004a12f0, pvCallbackData=0x00007fffcd99d738, frameIterator=0x00007fffcd99d230) + 342 at thread.cpp:473frame Add initial corert build scripts #9: 0x0000000000439394 ConsoleApp1
Thread::GcScanRoots(this=0x00007fffcd99f5e8, pfnEnumCallback=0x00000000004a12f0, pvCallbackData=0x00007fffcd99d738) + 132 at thread.cpp:408 frame #10: 0x000000000041c235 ConsoleApp1GCToEEInterface::GcScanRoots(fn=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), condemned=2, max_gen=2, sc=0x00007fffcd99d738)(Object**, ScanContext*, unsigned int), int, int, ScanContext*) + 501 at gcrhscan.cpp:85 frame #11: 0x00000000005c7499 ConsoleApp1GCScan::GcScanRoots(fn=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), condemned=2, max_gen=2, sc=0x00007fffcd99d738)(Object**, ScanContext*, unsigned int), int, int, ScanContext*) + 41 at gcscan.cpp:170 frame #12: 0x000000000047cf2c ConsoleApp1WKS::gc_heap::mark_phase(condemned_gen_number=2, mark_only_p=NO) + 2060 at gc.cpp:19592frame Initial population of CoreRT Runtime files. #13: 0x00000000004748b7 ConsoleApp1
WKS::gc_heap::gc1() + 519 at gc.cpp:15262 frame #14: 0x00000000004918b3 ConsoleApp1WKS::gc_heap::garbage_collect(n=0) + 3395 at gc.cpp:16853frame Set AllowUnsafeBlocks irrespective of build configuration #15: 0x0000000000466531 ConsoleApp1
WKS::GCHeap::GarbageCollectGeneration(this=0x000000000101f1e0, gen=0, reason=reason_alloc_soh) + 2049 at gc.cpp:35188 frame #16: 0x000000000046b6df ConsoleApp1WKS::gc_heap::try_allocate_more_space(acontext=0x00007fffcd99f5e8, size=24, gen_number=0) + 1503 at gc.cpp:13066frame Add support for non-GC static fields #17: 0x000000000046b853 ConsoleApp1
WKS::gc_heap::allocate_more_space(acontext=0x00007fffcd99f5e8, size=24, alloc_generation_number=0) + 35 at gc.cpp:13362 frame #18: 0x00000000004e4f65 ConsoleApp1WKS::GCHeap::Alloc(gc_alloc_context*, unsigned long, unsigned int) + 277 at gc.cpp:13393frame Unify caching pattern between EcmaMethod and EcmaField #19: 0x00000000004e4e50 ConsoleApp1
WKS::GCHeap::Alloc(this=0x000000000101f1e0, context=0x00007fffcd99f5e8, size=24, flags=0) + 96 at gc.cpp:34534 frame #20: 0x0000000000418c33 ConsoleApp1::RhpGcAlloc(pEEType=0x0000000000ef6658, uFlags=0, cbSize=24, pTransitionFrame=0x00007fffcd99e0d0) + 211 at gcrhenv.cpp:273frame Wire up CppCodeGen into ILToNative #21: 0x00000000005e7d4c ConsoleApp1
RhpNewObject + 52 at unixasmmacrosamd64.inc:427 frame #22: 0x00000000007facfa ConsoleApp1S_P_CoreLib_System_Collections_Generic_DefaultComparer_1__Compare + 202 at Comparer.cs:75frame Make ThreadSafeFlags public #23: 0x00000000007fa756 ConsoleApp1 at WaitHandleArray.cs:122
frame Add VS project for add hoc testing of CppCodeGen #24: 0x00000000009b4de5 ConsoleApp1 at ServerMonitor.cs:263
frame Make build.cmd more like the build.cmd in CoreCLR repo #25: 0x00000000009b0001 ConsoleApp1 at FeedObjectBase.cs:45
frame Enhance virtual function resolution logic to be roughly correct. #26: 0x0000000000998a59 ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__ExtractChainImage + 2321 at ChainWatcher.cs:1851 frame #27: 0x000000000098f728 ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__ParseChainUpdate + 388 at ChainWatcher.cs:1990frame Factor out name mangling into separate class #28: 0x000000000098556d ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__Arcontech_DotNetAPI_FeedApi_IFeedInstrumentWatcher_Update + 233 at ChainWatcher.cs:2191 frame #29: 0x0000000000968859 ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerInstrumentWatcher__ProcessBatch + 1161 at FeedHandlerInstrumentWatcher.cs:113frame Add field layout tests #30: 0x0000000000950748 ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerBase_1<System___Canon>__Arcontech_DotNetAPI_FeedApi_IFeedQueueItem_DispatchMessage + 224 at FeedHandlerBase.cs:863 frame #31: 0x000000000091a6ab ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerQueueDispatcher_QueueItem__Dispatch + 43 at FeedHandlerQueueDispatcher.cs:38frame Name mangling robustness #32: 0x00000000009087bf ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerQueueDispatcher__ProcessQueue + 287 at FeedHandlerQueueDispatcher.cs:147 frame #33: 0x0000000000749a4b ConsoleApp1 at WorkItemDispatcher.cs:175 frame #34: 0x000000000082bdab ConsoleApp1S_P_CoreLib_Internal_Runtime_Augments_RuntimeThread__StartThread + 287 at RuntimeThread.cs:486frame Initial hookup of GC code to MRT code #35: 0x0000000000813cf2 ConsoleApp1
S_P_CoreLib_Internal_Runtime_Augments_RuntimeThread__ThreadEntryPoint + 54 at RuntimeThread.Unix.cs:143 frame #36: 0x00007ffff6d93184 libpthread.so.0start_thread(arg=0x00007fffcd99f700) + 196 at pthread_create.c:312frame Factor out the type system into a separate assembly #37: 0x00007ffff6ac037d libc.so.6`__clone + 109 at clone.S:111
Frame Make build.cmd more like the build.cmd in CoreCLR repo #25, Add VS project for add hoc testing of CppCodeGen #24 and Make ThreadSafeFlags public #23 still look wrong to me.
(lldb) f 7 (Note I'm guessing this is the correct frame after the RhpEnableConservativeStackReporting change)
frame Add type system source files #7: 0x0000000000418fd3 ConsoleApp1`RedhawkGCInterface::EnumGcRefsInRegionConservatively(pLowerBound=0x00007fffcd99e0d0, pUpperBound=0x00007fffcd9a0000, pfnEnumCallback=0x00000000004a12f0, pvCallbackData=0x00007fffcd99d738) + 67 at gcrhenv.cpp:546
543 void * pfnEnumCallback,
544 void * pvCallbackData)
545 {
-> 546 GcEnumObjectsConservatively((PTR_OBJECTREF)pLowerBound, (PTR_OBJECTREF)pUpperBound, (EnumGcRefCallbackFunc *)pfnEnumCallback, (EnumGcRefScanContext *)pvCallbackData);
547 }
548
549 // static
Note sure where to go next from here?
jkotas commentedon Oct 27, 2017
Ok, the next thing to look at are the types of object that are being scanned. E.g. MetadataReader
and NativeFormatRuntimeNamedTypeInfo are the objects being scanned in my example below. Try this on a few different crashes to see whether the type is always the same. I expect that the object scanned in mark_object_simple1 is going to be invalid in your case, but the object in mark_object_simple should be good.
dlewis-arcontech commentedon Oct 27, 2017
I've used lldb to look up the information, so focusing in on mark_object_simple/mark_object_simple1 the section from lldb bt gives (I've pasted 2 runs here but the 3rd was the same):
(lldb) f 4
frame #4: 0x000000000049889b ConsoleApp1
WKS::gc_heap::mark_object_simple(po=0x00007fffcd99d0a0) + 1883 at gc.cpp:18174 18171 size_t s = size (o); 18172 promoted_bytes (thread) += s; 18173 { -> 18174 go_through_object_cl (method_table(o), o, s, poo, 18175 { 18176 uint8_t* oo = *poo; 18177 if (gc_mark (oo, gc_low, gc_high)) (lldb) image lookup --address *(void**)oo Address: ConsoleApp1[0x0000000000f26fc9] (ConsoleApp1..data + 948473) Summary: vtable for S_P_CoreLib_System_Collections_Generic_Dictionary_2<String__String> + 1 (lldb) f 3 frame #3: 0x0000000000497d3a ConsoleApp1WKS::gc_heap::mark_object_simple1(oo="Il�, start="Il�) + 8282 at gc.cpp:1773017727 int i = num_partial_refs;
17728 uint8_t* ref_to_continue = 0;
17729
-> 17730 go_through_object (method_table(oo), oo, s, ppslot,
17731 start, use_start, (oo + s),
17732 {
17733 uint8_t* o = ppslot;
(lldb) image lookup --address (void)oo
Address: ConsoleApp1[0x0000000000f26c49] (ConsoleApp1..data + 947577)
Summary: vtable for __Array<S_P_CoreLib_System_Collections_Generic_Dictionary_2_Entry<String__String>> + 1
(lldb) f 2
frame #2: 0x0000000000497d53 ConsoleApp1`WKS::gc_heap::mark_object_simple1(unsigned char*, unsigned char*) [inlined] WKS::my_get_size(ob=0x00007fffdfd742a0) + 25 at gc.cpp:8897
8894 inline size_t my_get_size (Object* ob)
8895 {
8896 MethodTable* mT = header(ob)->GetMethodTable();
-> 8897 return (mT->GetBaseSize() +
8898 (mT->HasComponentSize() ?
8899 ((size_t)((CObjectHeader*)ob)->GetNumComponents() * mT->RawGetComponentSize()) : 0));
8900 }
(lldb) image lookup --address (void*)oo
error: address expression "*(void**)oo" evaluation failed
(lldb)
(lldb) f 4
frame #4: 0x000000000049889b ConsoleApp1
WKS::gc_heap::mark_object_simple(po=0x00007fffcd99cff0) + 1883 at gc.cpp:18174 18171 size_t s = size (o); 18172 promoted_bytes (thread) += s; 18173 { -> 18174 go_through_object_cl (method_table(o), o, s, poo, 18175 { 18176 uint8_t* oo = *poo; 18177 if (gc_mark (oo, gc_low, gc_high)) (lldb) image lookup --address *(void**)oo Address: ConsoleApp1[0x0000000000f26fc9] (ConsoleApp1..data + 948473) Summary: vtable for S_P_CoreLib_System_Collections_Generic_Dictionary_2<String__String> + 1 (lldb) f 3 frame #3: 0x0000000000497d3a ConsoleApp1WKS::gc_heap::mark_object_simple1(oo="Il�, start="Il�) + 8282 at gc.cpp:1773017727 int i = num_partial_refs;
17728 uint8_t* ref_to_continue = 0;
17729
-> 17730 go_through_object (method_table(oo), oo, s, ppslot,
17731 start, use_start, (oo + s),
17732 {
17733 uint8_t* o = ppslot;
(lldb) image lookup --address (void)oo
Address: ConsoleApp1[0x0000000000f26c49] (ConsoleApp1..data + 947577)
Summary: vtable for __Array<S_P_CoreLib_System_Collections_Generic_Dictionary_2_Entry<String__String>> + 1
(lldb) f 2
frame #2: 0x0000000000497d53 ConsoleApp1`WKS::gc_heap::mark_object_simple1(unsigned char*, unsigned char*) [inlined] WKS::my_get_size(ob=0x00007fffdf822d48) + 25 at gc.cpp:8897
8894 inline size_t my_get_size (Object* ob)
8895 {
8896 MethodTable* mT = header(ob)->GetMethodTable();
-> 8897 return (mT->GetBaseSize() +
8898 (mT->HasComponentSize() ?
8899 ((size_t)((CObjectHeader*)ob)->GetNumComponents() * mT->RawGetComponentSize()) : 0));
8900 }
(lldb) image lookup --address (void*)oo
error: address expression "*(void**)oo" evaluation failed
(lldb)
jkotas commentedon Oct 27, 2017
So problem seems to be that array backing
Dictionary<string,string>is pointing to a string that got collected by the garbage collector already. The most likely cause is a missing GC write barrier somewhere.Could you please cherry pick https://github.com/jkotas/corert/commit/21ad08ee6ab4ffc0e1bc35ddd67063b441c9299f and run your test with it? This enables some extra consistency checks around GC write barriers.
If the inconsistency check fails, it should break in debugger like this:
Again, print the vtable of the object that is failing the check. Hopefully, it will be the array backing
Dictionary<string,string>again.Also, it may be useful to find out what are the strings stored in the dictionary that is hitting the problem. It should allow us to guess where the dictionary came from. The first 8 bytes in array object is pointer to the vtable. The next 8 bytes are number of elements. And then there are the array elements. In the case of Dictionary backing array, each element is 24 bytes: 32-bit string hashcode, 32-bit index, and two string object pointers. You can try to look around what kind of strings are stored in the dictionary.
dlewis-arcontech commentedon Oct 27, 2017
I've rebuilt everything from your branch, I did it quickly as I'm about to head off so I might have made a mistake. On the face of it, the results look the same. Anyway to verify the build is correct from the callstack?
Process 19622 stopped
EEType::get_BaseSize(this=0x0000000000000640) + 12 at eetype.h:365, name = 'ConsoleApp1', stop reason = signal SIGSEGV: invalid address (fault address: 0x644) frame #0: 0x000000000041aeac ConsoleApp1EEType::get_BaseSize(this=0x0000000000000640) + 12 at eetype.h:365362
363 #ifndef RHDUMP
364 UInt32 get_BaseSize()
-> 365 { return m_uBaseSize; }
366
367 UInt16 get_ComponentSize()
368 { return m_usComponentSize; }
(lldb) bt
EEType::get_BaseSize(this=0x0000000000000640) + 12 at eetype.h:365 frame #1: 0x00000000004f14a5 ConsoleApp1MethodTable::GetBaseSize(this=0x0000000000000640) + 21 at gcenv.h:91frame Add basic build scripts #2: 0x0000000000497d43 ConsoleApp1
WKS::gc_heap::mark_object_simple1(unsigned char*, unsigned char*) [inlined] WKS::my_get_size(ob=0x00007fffdfc1a628) + 25 at gc.cpp:8897 frame #3: 0x0000000000497d2a ConsoleApp1WKS::gc_heap::mark_object_simple1(oo="Il�, start="Il�) + 8282 at gc.cpp:17730frame Improve .gitignore #4: 0x000000000049888b ConsoleApp1
WKS::gc_heap::mark_object_simple(po=0x00007fffcd99c6b0) + 1883 at gc.cpp:18174 frame #5: 0x00000000004a1751 ConsoleApp1WKS::GCHeap::Promote(ppObject=0x00007fffcd99e568, sc=0x00007fffcd99d658, flags=0) + 1137 at gc.cpp:33817frame CoreLib doesn't implement Environment.GetEnvironmentVariable and friends #6: 0x000000000041c603 ConsoleApp1
GcEnumObject(ppObj=0x00007fffcd99e568, flags=0, fnGcEnumRef=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), pSc=0x00007fffcd99d658)(Object**, ScanContext*, unsigned int), ScanContext*) + 131 at gcrhscan.cpp:150frame Add type system source files #7: 0x0000000000418f44 ConsoleApp1
EnumGcRefsCallback(hCallback=0x00007fffcd99d030, pObject=0x00007fffcd99e568, flags=0) + 68 at gcrhenv.cpp:508 frame #8: 0x00000000005de9ac ConsoleApp1GcInfoDecoder::ReportStackSlotToGC(this=0x00007fffcd99cf58, spOffset=-360, spBase=GC_FRAMEREG_REL, gcFlags=0, pRD=0x00007fffcd99d170, flags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffcd99d030)(void*, void**, unsigned int), void*) + 156 at gcinfodecoder.cpp:1827 frame #9: 0x00000000005e01f9 ConsoleApp1GcInfoDecoder::ReportSlotToGC(this=0x00007fffcd99cf58, slotDecoder=0x00007fffcd99ce58, slotIndex=50, pRD=0x00007fffcd99d170, reportScratchSlots=true, inputFlags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffcd99d030)(void*, void**, unsigned int), void*) + 377 at gcinfodecoder.h:688 frame #10: 0x00000000005dd5fa ConsoleApp1GcInfoDecoder::ReportUntrackedSlots(this=0x00007fffcd99cf58, slotDecoder=0x00007fffcd99ce58, pRD=0x00007fffcd99d170, inputFlags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffcd99d030)(void*, void**, unsigned int), void*) + 138 at gcinfodecoder.cpp:1008 frame #11: 0x00000000005daab3 ConsoleApp1GcInfoDecoder::EnumerateLiveSlots(this=0x00007fffcd99cf58, pRD=0x00007fffcd99d170, reportScratchSlots=false, inputFlags=0, pCallBack=(ConsoleApp1EnumGcRefsCallback(void*, void**, unsigned int) at gcrhenv.cpp:505), hCallBack=0x00007fffcd99d030)(void*, void**, unsigned int), void*) + 8707 at gcinfodecoder.cpp:957 frame #12: 0x00000000005dee79 ConsoleApp1UnixNativeCodeManager::EnumGcRefs(this=0x0000000001027850, pMethodInfo=0x00007fffcd99d208, safePointAddress=0x0000000000998a49, pRegisterSet=0x00007fffcd99d170, hCallback=0x00007fffcd99d030) + 473 at UnixNativeCodeManager.cpp:153frame Initial population of CoreRT Runtime files. #13: 0x0000000000418edd ConsoleApp1
RedhawkGCInterface::EnumGcRefs(pCodeManager=0x0000000001027850, pMethodInfo=0x00007fffcd99d208, safePointAddress=0x0000000000998a49, pRegisterSet=0x00007fffcd99d170, pfnEnumCallback=0x00000000004a12e0, pvCallbackData=0x00007fffcd99d658) + 141 at gcrhenv.cpp:534 frame #14: 0x00000000004395ec ConsoleApp1Thread::GcScanRootsWorker(this=0x00007fffcd99f5e8, pfnEnumCallback=0x00000000004a12e0, pvCallbackData=0x00007fffcd99d658, frameIterator=0x00007fffcd99d150) + 572 at thread.cpp:491frame Set AllowUnsafeBlocks irrespective of build configuration #15: 0x0000000000439384 ConsoleApp1
Thread::GcScanRoots(this=0x00007fffcd99f5e8, pfnEnumCallback=0x00000000004a12e0, pvCallbackData=0x00007fffcd99d658) + 132 at thread.cpp:408 frame #16: 0x000000000041c225 ConsoleApp1GCToEEInterface::GcScanRoots(fn=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), condemned=2, max_gen=2, sc=0x00007fffcd99d658)(Object**, ScanContext*, unsigned int), int, int, ScanContext*) + 501 at gcrhscan.cpp:85 frame #17: 0x00000000005c7489 ConsoleApp1GCScan::GcScanRoots(fn=(ConsoleApp1WKS::GCHeap::Promote(Object**, ScanContext*, unsigned int) at gc.cpp:33749), condemned=2, max_gen=2, sc=0x00007fffcd99d658)(Object**, ScanContext*, unsigned int), int, int, ScanContext*) + 41 at gcscan.cpp:170 frame #18: 0x000000000047cf1c ConsoleApp1WKS::gc_heap::mark_phase(condemned_gen_number=2, mark_only_p=NO) + 2060 at gc.cpp:19592frame Unify caching pattern between EcmaMethod and EcmaField #19: 0x00000000004748a7 ConsoleApp1
WKS::gc_heap::gc1() + 519 at gc.cpp:15262 frame #20: 0x00000000004918a3 ConsoleApp1WKS::gc_heap::garbage_collect(n=0) + 3395 at gc.cpp:16853frame Wire up CppCodeGen into ILToNative #21: 0x0000000000466521 ConsoleApp1
WKS::GCHeap::GarbageCollectGeneration(this=0x000000000101f1e0, gen=0, reason=reason_alloc_soh) + 2049 at gc.cpp:35188 frame #22: 0x000000000046b6cf ConsoleApp1WKS::gc_heap::try_allocate_more_space(acontext=0x00007fffcd99f5e8, size=24, gen_number=0) + 1503 at gc.cpp:13066frame Make ThreadSafeFlags public #23: 0x000000000046b843 ConsoleApp1
WKS::gc_heap::allocate_more_space(acontext=0x00007fffcd99f5e8, size=24, alloc_generation_number=0) + 35 at gc.cpp:13362 frame #24: 0x00000000004e4f55 ConsoleApp1WKS::GCHeap::Alloc(gc_alloc_context*, unsigned long, unsigned int) + 277 at gc.cpp:13393frame Make build.cmd more like the build.cmd in CoreCLR repo #25: 0x00000000004e4e40 ConsoleApp1
WKS::GCHeap::Alloc(this=0x000000000101f1e0, context=0x00007fffcd99f5e8, size=24, flags=0) + 96 at gc.cpp:34534 frame #26: 0x0000000000418c23 ConsoleApp1::RhpGcAlloc(pEEType=0x0000000000ef6658, uFlags=0, cbSize=24, pTransitionFrame=0x00007fffcd99dff8) + 211 at gcrhenv.cpp:273frame Enhance virtual function resolution logic to be roughly correct. #27: 0x00000000005e7d38 ConsoleApp1
RhpNewObject + 48 at unixasmmacrosamd64.inc:428 frame #28: 0x00000000007facb6 ConsoleApp1S_P_CoreLib_System_Collections_Generic_DefaultComparer_1__Compare + 150 at Comparer.cs:72frame Fix build break #29: 0x00000000007fa746 ConsoleApp1 at WaitHandleArray.cs:122
frame Add field layout tests #30: 0x00000000009bb59f ConsoleApp1 at CustomAttributeExtensions.cs:261
frame Improve name mangling #31: 0x00000000009bb79e ConsoleApp1 at CustomAttributeExtensions.cs:261
frame Name mangling robustness #32: 0x00000000009b4e8f ConsoleApp1 at ServerMonitor.cs:263
frame Add tests for static field layout #33: 0x00000000009b0063 ConsoleApp1 at FeedObjectBase.cs:45
frame Static/instance field layout tests for non x64 architectures #34: 0x0000000000998a49 ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__ExtractChainImage + 2321 at ChainWatcher.cs:1851 frame #35: 0x000000000098f718 ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__ParseChainUpdate + 388 at ChainWatcher.cs:1990frame Get Array1 to work #36: 0x000000000098555d ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_ChainWatcher__Arcontech_DotNetAPI_FeedApi_IFeedInstrumentWatcher_Update + 233 at ChainWatcher.cs:2191 frame #37: 0x0000000000968849 ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerInstrumentWatcher__ProcessBatch + 1161 at FeedHandlerInstrumentWatcher.cs:113frame Fix project GUID in the ProjectReference from ILToNative #38: 0x0000000000950738 ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerBase_1<System___Canon>__Arcontech_DotNetAPI_FeedApi_IFeedQueueItem_DispatchMessage + 224 at FeedHandlerBase.cs:863 frame #39: 0x000000000091a69b ConsoleApp1Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerQueueDispatcher_QueueItem__Dispatch + 43 at FeedHandlerQueueDispatcher.cs:38frame Switch to protojit.dll #40: 0x00000000009087af ConsoleApp1
Arcontech_DotNetAPI_Arcontech_DotNetAPI_FeedApi_FeedHandlerQueueDispatcher__ProcessQueue + 287 at FeedHandlerQueueDispatcher.cs:147 frame #41: 0x0000000000749a3b ConsoleApp1 at WorkItemDispatcher.cs:175 frame #42: 0x000000000082bd9b ConsoleApp1S_P_CoreLib_Internal_Runtime_Augments_RuntimeThread__StartThread + 287 at RuntimeThread.cs:486frame Fix incorrect handling of MethodSpecificiations for MethodImpl overrides #43: 0x0000000000813ce2 ConsoleApp1
S_P_CoreLib_Internal_Runtime_Augments_RuntimeThread__ThreadEntryPoint + 54 at RuntimeThread.Unix.cs:143 frame #44: 0x00007ffff6d93184 libpthread.so.0start_thread(arg=0x00007fffcd99f700) + 196 at pthread_create.c:312frame Initial commit for System.Private.CoreLib #45: 0x00007ffff6ac037d libc.so.6`__clone + 109 at clone.S:111
jkotas commentedon Oct 27, 2017
It is quite possible that the problem is something else. If you would like to double check that the instrumentation is kicking in, you can set a breakpoint at
RhpAssignRefassembly helper, single step through it and verify that it is running through the GCShadow path.So it may be useful to look at the content of the corrupted array - find out what kind of strings are stored into it.
I have also talked to @sergiy-k about this. He may have some tips how to get the GC to run more often so that it crashes closer to the problem.
jkotas commentedon Oct 27, 2017
Also, opened #4822
jkotas commentedon Oct 27, 2017
Another thing you can try is to change
int GetGCgen0size () const { return 0; }toint GetGCgen0size () const { return 64 * 1024; }in gcenv.h. It will cause the GC to run more frequently - hopefully, it will break closer to the place where the problem happens.