Bug 13878 – Appending to an array block with modified flags loses flag info

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2014-12-19T19:07:00Z
Last change time
2015-02-18T03:38:36Z
Assigned to
schveiguy
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2014-12-19T19:07:13Z
This happens because the block info is cached, but when you set the flags for that block, the flags do not get back to the cache. We can half-solve the problem because the block info cache only uses base, size, and the APPENDABLE flag. The other flags are just bonus storage, but can deviate from the block info in the GC. For example, if you create a block like so: ubyte[] b = new ubyte[1000]; Then cast it to a void []: void[] v = cast(void[]) b; GC.setAttr(v.ptr, GC.BlkAttr.APPENDABLE) // remove NO_SCAN Now, if we append to v, once it reallocates, it will use the cached bits, which contain the "NO_SCAN" bit, and remove the change we made. If v now has pointers in it, those may be collected prematurely. We need to provide a way for the runtime to copy the flags from one block to another, and use that instead of the cache bits. Otherwise, we cannot support setting flags on an array. It shouldn't be too bad performance-wise, because at that point, we are already reallocating anyway. I say half-solve, because removing the APPENDABLE bit will not clear it out of the cache, and we may make incorrect assumptions about the block from it's cached APPENDABLE bit. I would caution anyone, however, to not ever clear the APPENDABLE bit.
Comment #1 by schveiguy — 2014-12-19T19:09:34Z
Oops, that should be GC.clrAttr(v.ptr, GC.BlkAttr.NO_SCAN);
Comment #2 by github-bugzilla — 2014-12-30T03:46:33Z
Commit pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/c5d48c971e02747e102776778272d3356e502352 Merge pull request #1075 from schveiguy/issue13878 Fix issue 13878 - Appending to an array block with modified flags loses flag info
Comment #3 by github-bugzilla — 2015-02-18T03:38:36Z