March 02, 2014 Re: GC.BlkAttr.FINALIZE | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Sunday, 2 March 2014 at 20:45:42 UTC, Steven Schveighoffer wrote:
> On Sun, 02 Mar 2014 15:44:47 -0500, Namespace <rswhite4@googlemail.com> wrote:
>
>> On Sunday, 2 March 2014 at 20:21:51 UTC, Steven Schveighoffer wrote:
>>> On Sat, 01 Mar 2014 09:57:44 -0500, Namespace <rswhite4@googlemail.com> wrote:
>>>
>>>>
>>>> I tried to enable the printf's in rt/lifetime.d (e.g.: https://github.com/D-Programming-Language/druntime/blob/e47a00bff935c3f079bb567a6ec97663ba384487/src/rt/lifetime.d#L1125) to see what happens if I/the GC delete an array. But I see no output, no matter what I try to allocate/deallocate.
>>>
>>> Enabling debugging code in druntime is really hard. I remember struggling with that when I was changing the array append code. It does work when you get it right...
>>>
>>> -Steve
>>
>> Great... :D I have no idea how. :P Should I recompile phobos also? Or try something special...?
>
> You HAVE to recompile phobos, because druntime is statically included inside it ;)
>
> -Steve
Ahh.. I thought it is enough to recompile druntime... :)
|
March 03, 2014 Re: GC.BlkAttr.FINALIZE | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | It's working now, I get all my debug infos I need. But: I have absolutly no idea how to get the correct TypeInfo in rt_finalize2. The ClassInfo is identified by casting the void* pointer to a void** and then cast this void** to ClassInfo*. But for other TypeInfos this weird trick doesn't work. How can I extract the correct TypeInfo from this void**? :P |
March 03, 2014 Re: GC.BlkAttr.FINALIZE | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Monday, 3 March 2014 at 02:44:09 UTC, Namespace wrote:
> It's working now, I get all my debug infos I need.
> But: I have absolutly no idea how to get the correct TypeInfo in rt_finalize2. The ClassInfo is identified by casting the void* pointer to a void** and then cast this void** to ClassInfo*. But for other TypeInfos this weird trick doesn't work. How can I extract the correct TypeInfo from this void**? :P
I get the real TypeInfo (not sure if this was intended this way) and in my test base it works! But in druntime I get the weird error:
src\rt\lifetime.d(1256): Error: variable a1 used before set
----
if (gc_getAttr(p) & BlkAttr.APPENDABLE)
{
void[] a1 = *cast(void[]*) ppv;
//printf("len = %d\n", a1.length);
void* p_a1 = &a1;
void* tp = p_a1 + 12;
TypeInfo* ti = cast(TypeInfo*) tp;
import std.string : toStringz;
string s = ti.toString(); // line 1256
printf("Type = %s\n", toStringz(s));
return;
}
----
Any call to ti will invoke the error. Any idea why?
|
March 03, 2014 Re: GC.BlkAttr.FINALIZE | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Mon, 03 Mar 2014 12:03:12 -0500, Namespace <rswhite4@googlemail.com> wrote:
> On Monday, 3 March 2014 at 02:44:09 UTC, Namespace wrote:
>> It's working now, I get all my debug infos I need.
>> But: I have absolutly no idea how to get the correct TypeInfo in rt_finalize2. The ClassInfo is identified by casting the void* pointer to a void** and then cast this void** to ClassInfo*. But for other TypeInfos this weird trick doesn't work. How can I extract the correct TypeInfo from this void**? :P
>
> I get the real TypeInfo (not sure if this was intended this way) and in my test base it works! But in druntime I get the weird error:
> src\rt\lifetime.d(1256): Error: variable a1 used before set
>
> ----
> if (gc_getAttr(p) & BlkAttr.APPENDABLE)
> {
> void[] a1 = *cast(void[]*) ppv;
> //printf("len = %d\n", a1.length);
>
> void* p_a1 = &a1;
> void* tp = p_a1 + 12;
>
> TypeInfo* ti = cast(TypeInfo*) tp;
>
> import std.string : toStringz;
> string s = ti.toString(); // line 1256
> printf("Type = %s\n", toStringz(s));
>
> return;
> }
> ----
>
> Any call to ti will invoke the error. Any idea why?
Not really any clue.
But if this is in druntime, it should not be importing anything from std.
-Steve
|
March 03, 2014 Re: GC.BlkAttr.FINALIZE | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 3 March 2014 at 18:36:56 UTC, Steven Schveighoffer wrote:
> On Mon, 03 Mar 2014 12:03:12 -0500, Namespace <rswhite4@googlemail.com> wrote:
>
>> On Monday, 3 March 2014 at 02:44:09 UTC, Namespace wrote:
>>> It's working now, I get all my debug infos I need.
>>> But: I have absolutly no idea how to get the correct TypeInfo in rt_finalize2. The ClassInfo is identified by casting the void* pointer to a void** and then cast this void** to ClassInfo*. But for other TypeInfos this weird trick doesn't work. How can I extract the correct TypeInfo from this void**? :P
>>
>> I get the real TypeInfo (not sure if this was intended this way) and in my test base it works! But in druntime I get the weird error:
>> src\rt\lifetime.d(1256): Error: variable a1 used before set
>>
>> ----
>> if (gc_getAttr(p) & BlkAttr.APPENDABLE)
>> {
>> void[] a1 = *cast(void[]*) ppv;
>> //printf("len = %d\n", a1.length);
>>
>> void* p_a1 = &a1;
>> void* tp = p_a1 + 12;
>>
>> TypeInfo* ti = cast(TypeInfo*) tp;
>>
>> import std.string : toStringz;
>> string s = ti.toString(); // line 1256
>> printf("Type = %s\n", toStringz(s));
>>
>> return;
>> }
>> ----
>>
>> Any call to ti will invoke the error. Any idea why?
>
> Not really any clue.
>
> But if this is in druntime, it should not be importing anything from std.
>
> -Steve
Even without I get this weird error. Is this a bug?
|
March 03, 2014 Re: GC.BlkAttr.FINALIZE | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Mon, 03 Mar 2014 15:34:18 -0500, Namespace <rswhite4@googlemail.com> wrote:
> On Monday, 3 March 2014 at 18:36:56 UTC, Steven Schveighoffer wrote:
>> On Mon, 03 Mar 2014 12:03:12 -0500, Namespace <rswhite4@googlemail.com> wrote:
>>
>>> On Monday, 3 March 2014 at 02:44:09 UTC, Namespace wrote:
>>>> It's working now, I get all my debug infos I need.
>>>> But: I have absolutly no idea how to get the correct TypeInfo in rt_finalize2. The ClassInfo is identified by casting the void* pointer to a void** and then cast this void** to ClassInfo*. But for other TypeInfos this weird trick doesn't work. How can I extract the correct TypeInfo from this void**? :P
>>>
>>> I get the real TypeInfo (not sure if this was intended this way) and in my test base it works! But in druntime I get the weird error:
>>> src\rt\lifetime.d(1256): Error: variable a1 used before set
>>>
>>> ----
>>> if (gc_getAttr(p) & BlkAttr.APPENDABLE)
>>> {
>>> void[] a1 = *cast(void[]*) ppv;
>>> //printf("len = %d\n", a1.length);
>>>
>>> void* p_a1 = &a1;
>>> void* tp = p_a1 + 12;
>>>
>>> TypeInfo* ti = cast(TypeInfo*) tp;
>>>
>>> import std.string : toStringz;
>>> string s = ti.toString(); // line 1256
>>> printf("Type = %s\n", toStringz(s));
>>>
>>> return;
>>> }
>>> ----
>>>
>>> Any call to ti will invoke the error. Any idea why?
>>
>> Not really any clue.
>>
>> But if this is in druntime, it should not be importing anything from std.
>
> Even without I get this weird error. Is this a bug?
It sounds suspicious. Clearly, you are not accessing a1 there, and clearly a1 is set before being used.
Any chance to reduce it?
-Steve
|
March 03, 2014 Re: GC.BlkAttr.FINALIZE | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | > It sounds suspicious. Clearly, you are not accessing a1 there, and clearly a1 is set before being used.
>
> Any chance to reduce it?
>
> -Steve
I don't know. But I know that my little trick doesn't work in lifetime.d although it works locally. Here what I tried:
----
import std.stdio;
struct Foo {
int id;
}
void main() {
Foo[] fs;
fs ~= Foo(45);
fs ~= Foo(46);
fs ~= Foo(47);
fs ~= Foo(48);
auto ti = typeid(fs);
writeln("&ti = ", &ti);
void* p = fs.ptr;
void[] arr = *cast(void[]*) p;
void* tp = cast(void*)((&arr) - cast(void*) 8);
TypeInfo ti2 = *cast(TypeInfo*) tp;
writeln(ti, " versus ", ti2);
}
----
Since rt_finalize and the GC have the same pointer as 'fs.ptr' I cast it to an array struct. From the pointer of this struct I subtract 8 (8 because of try and error until the pointer was equal the real TypeInfo pointer). This I can cast to the TypeInfo: it works. But not in lifetime.d. Was a try, but I have no idea why it doesn't work (the pointers aren't equal). An idea or alternative?
|
Copyright © 1999-2021 by the D Language Foundation