develooper Front page | perl.perl6.internals | Postings from July 2002

What's up with find_method?

Sean O'Rourke
July 21, 2002 10:24
What's up with find_method?
Message ID:
From the vtables PDD entry for find_method(interp, self, name):

"This subroutine PMC may be cached, so the method *must* return an
equivalent sub PMC each time, or be capable of dealing with the returned
sub PMCs being reused."

This seems bug-prone in a couple of ways:

First, what if the object at an address changes between when the lookup is
performed and the sub is used?  This can happen either because the object
changes its own vtable like the current Perl scalar types, or because the
GC has freed and reused a particular space.  So if I cache a method, then
call it later, the object can't just say "yep, that's mine", but has to
essentially find out what the method is trying to do, then look it up
again to see if it still makes sense.  It seems likely that doing a full
lookup when the method is called as well as when it's found is the only
way to guarantee correctness.

Second, what if one of the object's methods is redefined after having been
cached?  Sometimes, the old method will still be a valid thing to do to
the object, and it might be useful to keep a nameless handle to a method
around.  Sometimes, the cached version should transparently refer to the
new one.  This is less of an issue, since an object sophisticated enough
to allow redefining methods will also likely have the tuits to handle
these issues.

It seems much less error-prone to have method lookup happen at call time,
and if verifying cached methods when they're called gets tricky, then not
only will it be slow, but it will be easy to get wrong.  I get the feeling
this was all hashed out somewhere at some time, but I've had no luck with
Google so far.  Any pointers greatly appreciated.

/s Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About