GC and the stack

  • Thread starter Thomas Sondergaard
  • Start date
T

Thomas Sondergaard

Hello,

As far as I understand the ruby gc will not collect objects that are
referenced from the stack, ie the "C/native" stack in a ruby extension
module.

How does the ruby gc recognize what on the stack is a reference to a ruby
object? The types on and layout of the values in a particular stack frame is
not available at runtime is it?

The initial joy of the simplicity of the ruby C API has for me turned into a
fear of not knowing what is going on concerning especially garbage
collection.

Thomas
 
N

nobu.nokada

Hi,

At Wed, 8 Oct 2003 20:08:13 +0900,
Thomas said:
How does the ruby gc recognize what on the stack is a reference to a ruby
object? The types on and layout of the values in a particular stack frame is
not available at runtime is it?

By whether a value points an object in the slots. See
gc.c:is_pointer_to_heap().
 
T

Thomas Sondergaard

By whether a value points an object in the slots. See
gc.c:is_pointer_to_heap().

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?

Could you outline how the stack is processed? Is it just treated as a
continuous block of memory and scanned for dwords that "point" into the
heap?

Understanding this would be most helpful!

Thank you,

Thomas
 
D

Dan Sugalski

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. This is normal for conservative garbage collection schemes. (Which
ruby uses for its stack walking) It's very, *very* rarely an issue.

Dan
 
T

Thomas Sondergaard

Yes. This is normal for conservative garbage collection schemes. (Which
ruby uses for its stack walking) It's very, *very* rarely an issue.

I believe you. It is just important for me to understand what exactly it
takes to avoid getting reaped by the gc. My question about an integer
variable "pointing" into the ruby heap was not to point out a concern, but
to make sure that I understood it correctly.

So to sum it up: If I am sure that there is a (properly aligned) dword on
the stack that points to my sacred unreapable object it will be safe.

Thanks,

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top