Bug 3454 – Inconsistent flag setting in GC.realloc()

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2009-10-29T17:26:00Z
Last change time
2015-06-09T01:26:56Z
Keywords
pull
Assigned to
sean
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2009-10-29T17:26:42Z
GC.realloc() doesn't set the flags on either the old or new memory block for a whole bunch of code paths. I was tipped off to this by reading the code while trying to add precise heap scanning. Here's a test program that demonstrates this. import std.stdio, core.memory; void main() { doTest(1); writeln(); doTest(1024 * 1024); } void doTest(size_t multiplier) { auto foo = GC.malloc(8 * multiplier); auto bar = GC.realloc(foo, 2 * multiplier, GC.BlkAttr.NO_SCAN); writeln("Old block attributes: ", GC.getAttr(foo)); writeln("New block attributes: ", GC.getAttr(bar)); writeln("Old Ptr: ", foo, " New Ptr: ", bar); } Output: Old block attributes: 2 New block attributes: 2 Old Ptr: 961E40 New Ptr: 961E30 Old block attributes: 0 New block attributes: 0 Old Ptr: 10C0000 New Ptr: 10C0000 This is caused by the GC returning early from the B_PAGE path, or if the new block is almost the same size as the old block. If I get precise heap scanning to work, I'll include a fix for this in the patch.
Comment #1 by safety0ff.bugz — 2013-10-25T12:07:56Z
I believe your test should be: ------------------------------------------------ import std.stdio, core.memory; void main() { doTest(1); writeln(); doTest(1024 * 1024); } void doTest(size_t multiplier) { auto foo = GC.malloc(8 * multiplier); writeln("Old block attributes: ", GC.getAttr(foo)); auto bar = GC.realloc(foo, 2 * multiplier, GC.BlkAttr.NO_SCAN); writeln("New block attributes: ", GC.getAttr(bar)); writeln("Old Ptr: ", foo, " New Ptr: ", bar); } ------------------------------------------------- I've put an ugly fix for this here: https://github.com/Safety0ff/druntime/commit/14148c8184b7094243f5ab74d703027d05c6e73a
Comment #2 by safety0ff.bugz — 2013-10-27T17:01:37Z
Comment #3 by github-bugzilla — 2013-10-31T10:26:34Z