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

What's up with find_method?

From:
Sean O'Rourke
Date:
July 21, 2002 10:24
Subject:
What's up with find_method?
Message ID:
Pine.GSO.4.33.0207210955010.28766-100000@beowulf.ucsd.edu
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




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About