ara.t.howard wrote:
>
> On Oct 27, 2007, at 11:46 PM, Charles Oliver Nutter wrote:
>
>> Because ObjectSpace needs to be loaded/enabled *before* the objects
>> you want to track come into existance. Unlike Ruby's simple GC and
>> memory model, in JRuby we have to explicitly add objects created to a
>> walkable list. There's no capability on most modern GCed VMs to walk
>> the heap at will. Because of that, any objects created before
>> ObjectSpace is enabled would not be visible during any subsequent
>> walk. Generally, autoload would be far too late.
>
> hmmm. an exception seems best then - force the require up front. or,
> is there perhaps a lighter weight method to mark things so you *could*
> bootstrap ObjectSpace once it was loaded?
Not really; we've made it as lightweight as possible. The problem is
that there's no capability in the JVM to say "let me walk all objects",
largely because of how that would impact GC operation and security
(should objects created in other classloaders be walkable? internal JVM
objects? should you be able to reach objects you'd *never* be able to
construct or reference yourself? so many questions).
So the only way to ever be able to reach objects in the future is to
have a reference to them somewhere. So we create a very lightweight
linked list of references to all objects created. However it gets more
complicated: ObjectSpace references shouldn't keep objects from getting
collected. So every reference is a Java weak reference, and we
periodically clean the list of dead references.
Tracking every object created + weak references + periodic cleanup = slow.
So ObjectSpace either needs to be there when the object is created, or
you must accept that you can't ever walk it.
- Charlie