Re: Memory Corruption Issue??
The fix turned out to be much simpler than what I had thought. https://github.com/D-Programming-Language/druntime/pull/1506
Re: Memory Corruption Issue??
Greetings I am using my D code as a dynamically loadable library that gets loaded at run time into C/C++ world. As discussed earlier on this thread, the GC does not mark TLS objects in this scenario and as a result the GC ends up collecting TLS objects even though these objects are still in use. More details of the issue can be found on the bug tracker https://issues.dlang.org/show_bug.cgi?id=15513 @Daniel provided two workarounds to this issue. One was to disable the GC altogether. I do not want to do that since my application generates too much data that necessitates regular sweeping. The other suggested workaround was to explicitly invoke GC.addRoot for all the TLS objects. This worked for me for some situations, but in other scenarios I am still facing crashes. I think these crashes may be resulting from the invisible TLS objects in phobos and druntime etc. I have confirmed that all these crashes subside if I disable GC altogether and also that the crashes do not happen if I make a D bases executable instead of DLL. I want to know if someone is working on this issue. If no one is, I am ready to spend time and get this behind me. Actually I have already worked on this bug and I think now I have a fair idea of what is happening. Is it the right forum to discuss my findings, or should I put my comments on bugzilla. I need some guidance in finding the right fix. Regards - Puneet
Re: Memory Corruption Issue??
Thanks Daniel I have added the testcase to a more obscure testcase that I had raised on Bugzilla earlier. https://issues.dlang.org/show_bug.cgi?id=15513 I want to request developers to show some love. Regards - Puneet
Re: Memory Corruption Issue??
Am Wed, 20 Jan 2016 09:12:57 + schrieb Bottled Gin: > Greetings > > I am struggling with strange memory corruption issues with > dmd-2.069.2 release. > Could be GC scanning issues. Can you try disabling the garbage collector and see if it still crashes?
Re: Memory Corruption Issue??
On Wednesday, 20 January 2016 at 09:12:57 UTC, Bottled Gin wrote: Greetings I am struggling with strange memory corruption issues with dmd-2.069.2 release. [...] As a workaround you can mark Hash class as a shared final shared class Hash
Re: Memory Corruption Issue??
On Wednesday, 20 January 2016 at 11:49:29 UTC, Daniel Kozak wrote: On Wednesday, 20 January 2016 at 09:12:57 UTC, Bottled Gin wrote: Greetings I am struggling with strange memory corruption issues with dmd-2.069.2 release. ... ./main Start frop from C 0 -> @�+ The last line is the content of an array which is actually filled with only dashes in the code. Kindly help. I want to make sure that I am not making a mistake before I file a bug on dlang bugzilla. Regards - Puneet Another workaround is to use GC.addRoot for dynamic allocated data in Dynamic.proc void proc () { import core.memory: GC; dash.length = 32; GC.addRoot(cast(void*)dash.ptr); dash[] = '-'; } And another one is hold pointer to data: class Dynamic { static char[] space; static char[] dash; char* dash_ptr; void rehash () { static Hash hash ; hash = new Hash; hash.clear(); } void proc () { import core.memory: GC; dash.length = 32; dash_ptr = dash.ptr; dash[] = '-'; } }
Re: Memory Corruption Issue??
On Wednesday, 20 January 2016 at 11:06:53 UTC, Daniel Kozak wrote: On Wednesday, 20 January 2016 at 09:12:57 UTC, Bottled Gin wrote: Greetings I am struggling with strange memory corruption issues with dmd-2.069.2 release. [...] As a workaround you can mark Hash class as a shared final shared class Hash But this will change behavour because it will not be in TLS anymore
Re: Memory Corruption Issue??
On Wednesday, 20 January 2016 at 11:08:46 UTC, Daniel Kozak wrote: On Wednesday, 20 January 2016 at 11:06:53 UTC, Daniel Kozak wrote: On Wednesday, 20 January 2016 at 09:12:57 UTC, Bottled Gin wrote: Greetings I am struggling with strange memory corruption issues with dmd-2.069.2 release. [...] As a workaround you can mark Hash class as a shared final shared class Hash But this will change behavour because it will not be in TLS anymore GC.disable seems help
Re: Memory Corruption Issue??
On Wednesday, 20 January 2016 at 09:12:57 UTC, Bottled Gin wrote: Greetings I am struggling with strange memory corruption issues with dmd-2.069.2 release. ... ./main Start frop from C 0 -> @�+ The last line is the content of an array which is actually filled with only dashes in the code. Kindly help. I want to make sure that I am not making a mistake before I file a bug on dlang bugzilla. Regards - Puneet Another workaround is to use GC.addRoot for dynamic allocated data in Dynamic.proc void proc () { import core.memory: GC; dash.length = 32; GC.addRoot(cast(void*)dash.ptr); dash[] = '-'; }
Re: Memory Corruption Issue??
Another workaround is to use GC.addRoot for dynamic allocated data in Dynamic.proc void proc () { import core.memory: GC; dash.length = 32; GC.addRoot(cast(void*)dash.ptr); dash[] = '-'; } And another one is hold pointer to data: class Dynamic { static char[] space; static char[] dash; char* dash_ptr; void rehash () { static Hash hash ; hash = new Hash; hash.clear(); } void proc () { import core.memory: GC; dash.length = 32; dash_ptr = dash.ptr; dash[] = '-'; } } Daniel, thanks for confirming the bug and for providing workaround. The second workaround (saving the pointer) will not work on my real project though. I have multiple threads and the TLS variable will have a different pointer on each thread. Also, can you please tell me how to addRoot an assoc array to GC. It seems there is no ptr property available for assoc arrays. Regards - Puneet
Re: Memory Corruption Issue??
V Wed, 20 Jan 2016 13:58:46 + Bottled Gin via Digitalmars-dnapsáno: > >> Another workaround is to use GC.addRoot for dynamic allocated > >> data in Dynamic.proc > >> > >> void proc () { > >> import core.memory: GC; > >> dash.length = 32; > >> GC.addRoot(cast(void*)dash.ptr); > >> dash[] = '-'; > >> } > > > > And another one is hold pointer to data: > > > > class Dynamic { > > static char[] space; > > static char[] dash; > > char* dash_ptr; > > void rehash () { > > static Hash hash ; > > hash = new Hash; > > hash.clear(); > > } > > void proc () { > > import core.memory: GC; > > dash.length = 32; > > dash_ptr = dash.ptr; > > dash[] = '-'; > > } > > } > > Daniel, thanks for confirming the bug and for providing > workaround. The second workaround (saving the pointer) will not > work on my real project though. I have multiple threads and the > TLS variable will have a different pointer on each thread. > > Also, can you please tell me how to addRoot an assoc array to GC. > It seems there is no ptr property available for assoc arrays. > > Regards > - Puneet > > > You can use cast(void *)aa; something like this: class Dynamic { static char[] space; static char[int] dash; void rehash () { static Hash hash ; hash = new Hash; hash.clear(); } void proc () { import core.memory: GC; //GC.addRoot(cast(void *)dash); // not here { dash[i] = '-'; } GC.addRoot(cast(void *)dash); // must be after allocation } } Be careful because you mast use addPtr after aa is initialized (you put something to it)