March 01, 2018
On Thu, Mar 01, 2018 at 02:52:26PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...]
> There are a few in there, which I think are over-the-top. Such as "don't cast a pointer to a non-pointer",
[...]

Isn't that necessary for a precise GC?

Also, AIUI the current GC already does not scan size_t[] blocks for pointers, so if you cast a pointer to size_t and put it in such an array with no other references to your object, you stand the chance of the GC collecting your object while it is still live.


> or "Do not take advantage of alignment of pointers to store bit flags in the low order bits".
[...]

Won't a precise GC scanning for pointers to aligned objects want to skip values that can't be an aligned pointer?  Though in D's case, being required to be conservative would negate this.


T

-- 
There are three kinds of people in the world: those who can count, and those who can't.
March 01, 2018
On 3/1/18 3:33 PM, H. S. Teoh wrote:
> On Thu, Mar 01, 2018 at 02:52:26PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:
> [...]
>> There are a few in there, which I think are over-the-top. Such as
>> "don't cast a pointer to a non-pointer",
> [...]
> 
> Isn't that necessary for a precise GC?

It's not strictly necessary for a precise GC. It's necessary for a copying GC. In that case, if the GC decides to move your object and update all the references, it would miss that one. And even there, it's not necessary that you refrain from casting, it's just necessary to refrain from using that as an actual pointer in the future. I can't see how you might print a pointer value without casting it to an integer ;)

What is more important is that you don't use that as the ONLY reference to the object.

> 
> Also, AIUI the current GC already does not scan size_t[] blocks for
> pointers, so if you cast a pointer to size_t and put it in such an array
> with no other references to your object, you stand the chance of the GC
> collecting your object while it is still live.

Again, the key is "no other references". The document referenced above just says you can't cast.

>> or "Do not take advantage of alignment of pointers to store bit flags
>> in the low order bits".
> [...]
> 
> Won't a precise GC scanning for pointers to aligned objects want to skip
> values that can't be an aligned pointer?  Though in D's case, being
> required to be conservative would negate this.

int[] x = [1,2,3];
void[] y = x;
y = y[1 .. $]; // misaligned pointer.

It's easy to do, and it's done all over the place (buffers anyone?).

-Steve
March 01, 2018
On Thursday, March 01, 2018 15:53:08 Steven Schveighoffer via Digitalmars-d- learn wrote:
> On 3/1/18 3:33 PM, H. S. Teoh wrote:
> > Won't a precise GC scanning for pointers to aligned objects want to skip values that can't be an aligned pointer?  Though in D's case, being required to be conservative would negate this.
>
> int[] x = [1,2,3];
> void[] y = x;
> y = y[1 .. $]; // misaligned pointer.
>
> It's easy to do, and it's done all over the place (buffers anyone?).

Yeah, until recently readText could kill your program because of that, which I found out the hard way when I had to muck around with some UTF-16 files. It's an easy mistake to make.

- Jonathan M Davis

March 02, 2018
On Thursday, 1 March 2018 at 12:20:08 UTC, Steven Schveighoffer wrote:
> On 3/1/18 7:05 AM, Gary Willoughby wrote:
>> On Thursday, 1 March 2018 at 10:10:27 UTC, John Burton wrote:
>>> My question is how do I tell if a pointer is "garbage collected" or not?
>> 
>> You could try `GC.addrOf()` or `GC.query()` in core.memory.
>
> I was going to say this, but then I realized, it's not that the pointer points at GC-allocated memory, but that the pointer itself is stored in a location that is scanned by the GC. That's not as easy to figure out, as you have to look at stacks, added ranges, etc.
>
> -Steve

It would be interesting to test whether those methods handle these scenarios.

March 02, 2018
On Friday, 2 March 2018 at 08:44:53 UTC, Gary Willoughby wrote:
> It would be interesting to test whether those methods handle these scenarios.

Yeah, it doesn't work.

https://dpaste.dzfl.pl/55116efd0c9c
1 2
Next ›   Last »