[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: GC and the stack

Weirich, James

10/8/2003 1:40:00 PM

> Okay. What if, in an extension, I have an integer on the
> stack that just happens to contain a value that interpreted
> as a pointer points into a valid point in the heap. Will
> that prevent the "pointed to" object from being gc'ed?

Yes. The Ruby collector is a conservative collector, meaning that it will
only find garbage, but might not find /all/ the garbage.

--
-- Jim Weirich / Compuware
-- Fidelity/FWP Capture Services
-- Phone: 859-386-8855

4 Answers

Thomas Sondergaard

10/8/2003 1:53:00 PM

0

> Yes. The Ruby collector is a conservative collector, meaning that it will
> only find garbage, but might not find /all/ the garbage.

I have heard statements indicating that you need to declare all local VALUEs
volatile, in order to ensure that they are put on the stack by the compiler
and not in a register. Can I get an authoritative answer to this question?
The ruby source code is full of "volatile", but it is not mentioned once
either on the rubygarden.org WIKI or the README.EXT. Why should this be
necessary? Couldn't the garbage collector check the registers too?

Thomas


nobu.nokada

10/8/2003 2:29:00 PM

0

Hi,

At Wed, 8 Oct 2003 23:09:08 +0900,
Thomas Sondergaard wrote:
> I have heard statements indicating that you need to declare all local VALUEs
> volatile, in order to ensure that they are put on the stack by the compiler
> and not in a register. Can I get an authoritative answer to this question?
> The ruby source code is full of "volatile", but it is not mentioned once
> either on the rubygarden.org WIKI or the README.EXT. Why should this be
> necessary? Couldn't the garbage collector check the registers too?

Unnecessary, in general. GC checks the registers of course.

However, you have to pay attention in this situation.

VALUE str = rb_str_new(0, 256); /* make a buffer */
char *ptr = RSTRING(str)->ptr;

If str isn't used later, compiler may remove it. And then ptr
may be freed when you call ruby APIs and GC runs.
StringValue() and StringValuePtr() are provided to avoid this.

--
Nobu Nakada

Sean O'Dell

10/8/2003 5:27:00 PM

0

nobu.nokada@softhome.net wrote:
> Hi,
>
> At Wed, 8 Oct 2003 23:09:08 +0900,
> Thomas Sondergaard wrote:
>
>>I have heard statements indicating that you need to declare all local VALUEs
>>volatile, in order to ensure that they are put on the stack by the compiler
>>and not in a register. Can I get an authoritative answer to this question?
>>The ruby source code is full of "volatile", but it is not mentioned once
>>either on the rubygarden.org WIKI or the README.EXT. Why should this be
>>necessary? Couldn't the garbage collector check the registers too?
>
> Unnecessary, in general. GC checks the registers of course.

Actually, he does need to mark them as volatile. My objects were
getting reaped unexpectedly on me because of this. The Ruby GC might
check the registers, but it wasn't finding my objects there, and it was
a fantastic waste of many hours scratching my head.

Sean O'Dell


nobu.nokada

10/8/2003 10:16:00 PM

0

Hi,

At Thu, 9 Oct 2003 02:27:08 +0900,
Sean O'Dell wrote:
> >>I have heard statements indicating that you need to declare all local VALUEs
> >>volatile, in order to ensure that they are put on the stack by the compiler
> >>and not in a register. Can I get an authoritative answer to this question?
> >>The ruby source code is full of "volatile", but it is not mentioned once
> >>either on the rubygarden.org WIKI or the README.EXT. Why should this be
> >>necessary? Couldn't the garbage collector check the registers too?
> >
> > Unnecessary, in general. GC checks the registers of course.
>
> Actually, he does need to mark them as volatile. My objects were
> getting reaped unexpectedly on me because of this. The Ruby GC might
> check the registers, but it wasn't finding my objects there, and it was
> a fantastic waste of many hours scratching my head.

Indeed, you'll need StringValue() or something similar in such
case. This might prevent it.

*(volatile VALUE *)&reaped_object;

--
Nobu Nakada