Daniel Berger wrote:
> On Oct 28, 12:53 am, Charles Oliver Nutter <charles.nut... / sun.com>
> wrote:
> <snip>
> 
>> So...I'm writing this to see what the general Ruby world thinks of us
>> having ObjectSpace disabled by default, enableable via a command line
>> option (or perhaps through a library? -robjectspace?).
> 
> .ext\common\win32\registry.rb:569:      ObjectSpace.define_finalizer
> self, @@final.call(@hkeyfinal)
> ext\dl\test\test.rb:187:  ObjectSpace.define_finalizer(fp)
> {File.unlink("tmp.txt")}
> ext\tk\lib\multi-tk.rb:493:        ObjectSpace.each_object(TclTkIp){|
> obj|
> ext\Win32API\lib\win32\registry.rb:569:
> ObjectSpace.define_finalizer self, @@final.call(@hkeyfinal)
> lib\cgi\session.rb:299:      ObjectSpace::define_finalizer(self,
> Session::callback(@dbprot))
> lib\drb\drb.rb:337:# object's ObjectSpace id as its dRuby id.  This
> means that the dRuby
> lib\drb\drb.rb:361:  # This, the default implementation, uses an
> object's local ObjectSpace
> lib\drb\drb.rb:375:      ObjectSpace._id2ref(ref)
> lib\finalize.rb:59:      ObjectSpace.call_finalizer(obj)
> lib\finalize.rb:169:      ObjectSpace.remove_finalizer(@proc)
> lib\finalize.rb:173:    ObjectSpace.add_finalizer(@proc)
> lib\finalize.rb:180:    # registering function to
> ObjectSpace#add_finalizer
> lib\finalize.rb:192:  ObjectSpace.add_finalizer(@proc)
> lib\irb\completion.rb:152:        ObjectSpace.each_object(Module){|m|
> lib\irb\ext\save-history.rb:69:      ObjectSpace.define_finalizer(obj,
> HistorySavingAbility.create_finalizer)
> lib\shell\process-controller.rb:216:    ObjectSpace.each_object(IO) do
> |io|
> lib\singleton.rb:23:#      ObjectSpace.each_object(OtherKlass){} # =>
> 0.
> lib\singleton.rb:190:    "#{ObjectSpace.each_object(klass){}} #{klass}
> instance(s)"
> lib\tempfile.rb:53:    ObjectSpace.define_finalizer(self, @clean_proc)
> lib\tempfile.rb:105:    ObjectSpace.undefine_finalizer(self)
> lib\tempfile.rb:118:      ObjectSpace.undefine_finalizer(self)
> lib\test\unit\autorunner.rb:17:        ObjectSpace.each_object(Class)
> do |klass|
> lib\test\unit\autorunner.rb:54:        :objectspace => proc do |r|
> lib\test\unit\autorunner.rb:55:          require 'test/unit/collector/
> objectspace'
> lib\test\unit\autorunner.rb:56:          c =
> Collector::ObjectSpace.new
> lib\test\unit\autorunner.rb:80:        @collector =
> COLLECTORS[(standalone ? :dir : :objectspace)]
> lib\test\unit\collector\dir.rb:13:        def initialize(dir=::Dir,
> file=::File, object_space=::ObjectSpace, req=nil)
> lib\test\unit\collector\objectspace.rb:10:      class ObjectSpace
> lib\test\unit\collector\objectspace.rb:13:        NAME = 'collected
> from the ObjectSpace'
> lib\test\unit\collector\objectspace.rb:15:        def
> initialize(source=::ObjectSpace)
> lib\test\unit.rb:252:  # the ObjectSpace and wrap them up into a suite
> for you. It then runs
> lib\weakref.rb:16:#   ObjectSpace.garbage_collect
> lib\weakref.rb:62:      ObjectSpace._id2ref(@__id)
> lib\weakref.rb:74:        ObjectSpace.define_finalizer obj, @@final
> lib\weakref.rb:75:        ObjectSpace.define_finalizer self, @@final
> lib\weakref.rb:98:  ObjectSpace.garbage_collect
> test\dbm\test_dbm.rb:45:      ObjectSpace.each_object(DBM) do |obj|
> test\gdbm\test_gdbm.rb:42:      ObjectSpace.each_object(GDBM) do |obj|
> test\ruby\test_objectspace.rb:3:class TestObjectSpace <
> Test::Unit::TestCase
> test\ruby\test_objectspace.rb:10:      o =
> ObjectSpace._id2ref(obj.object_id);\
> test\sdbm\test_sdbm.rb:15:    ObjectSpace.each_object(SDBM) do |obj|
> test\testunit\collector\test_dir.rb:62:          class ObjectSpace
> test\testunit\collector\test_dir.rb:81:            @object_space =
> ObjectSpace.new
> test\testunit\collector\test_objectspace.rb:6:require 'test/unit/
> collector/objectspace'
> test\testunit\collector\test_objectspace.rb:11:      class
> TC_ObjectSpace < TestCase
> test\testunit\collector\test_objectspace.rb:41:          @c =
> ObjectSpace.new(@object_space)
> test\testunit\collector\test_objectspace.rb:44:        def
> full_suite(name=ObjectSpace::NAME)
> test\testunit\collector\test_objectspace.rb:51:
> TestSuite.new(ObjectSpace::NAME)
> test\testunit\collector\test_objectspace.rb:83:          expected =
> TestSuite.new(ObjectSpace::NAME)
> test\testunit\collector\test_objectspace.rb:89:          expected =
> TestSuite.new(ObjectSpace::NAME)
> test\yaml\test_yaml.rb:1279:  ObjectSpace.each_object(Class) do |
> klass|
> 
> So, in summary, if we exclude those libraries where only tests are
> affected, this would affect:
> 
> win32-registry
> tk
> cgi
> drb
> finalize
> irb
> shell
> singleton
> tempfile
> test-unit
> weakref
> 
> Some comments on each of these as they relate to JRuby:

Of these, only the following would be affected, since only each_object 
would be disabled by default:

> tk: No one will care. They'll use SWT or Swing bindings. Besides, you
> would need JNA.
 > ext\tk\lib\multi-tk.rb:493:        ObjectSpace.each_object(TclTkIp){|

Quite right, and there are currently no plans (or demand) for Tk support 
in JRuby. Swing is a far better GUI API, especially when wrapped in Ruby.

> irb: You've got jirb.
 > lib\irb\completion.rb:152:        ObjectSpace.each_object(Module){|m|

This could still be supported through a similar mechanism as 
each_object(Class), by keeping a weak hash of all Module instances.

> shell: This could be a problem.
 > lib\shell\process-controller.rb:216:    ObjectSpace.each_object(IO) do

I'd be surprised if shell worked 100% correctly right now anyway, due to 
process-control requirements we can't support well on JVM. But I would 
also expect this use of each_object to have a "better" implementation, 
and if not it could again be a specific-purpose weak hash for IO streams 
(which we almost have already since we want to be able to clean them up 
on exit.

> singleton: Ditto.

I'd have to look at this one. This could be another good candidate for 
reimplementation in a lot less Java code; singleton support would be 
pretty easy to write up in a few lines of Java.

> test-unit: Already mentioned.

So pretty few libraries would be affected, and I don't think any 
couldn't be dealt with in other ways. And to reiterate: finalizers and 
_id2ref wouldn't be affected (though I'd prefer to find alternative 
mechanisms for _id2ref).

- Charlie