Austin Hastings wrote:

> Dan Sugalski <[EMAIL PROTECTED]> wrote:
> 
> > There's a growing body of interesting work on what's essentially
> > disposable or partially-useful optimizations. Given the dynamic
> > nature of most of the languages we care about for parrot, 
> > throwaway optimizations make a lot of sense--we can build optimized
> > versions of functions for the current structure, and redo them if
> > the structure changes.
> > 
> > This isn't entirely an easy task, however, since you can't throw
> > away or redo a function/method/sub/whatever that you're already in 
> > somewhere in the call-chain, which means any optimizations will 
> > have to be either checked at runtime or undoable when code is in 
> > the middle of them.
> 
> Why is this?
> 
> Given that threads are present, and given the continuation based
> nature of the interpreter, I assume that code blocks can be closured.
> So why not allocate JITed methods on the heap and manage them as first
> class closures, so that the stackref will hold them until the stack
> exits?


Austin,

That's a fine and dandy way to do some things, like progressive
optimization ala HotSpot. (e.g., "Oh! I've been called 10,000 times.
Maybe you should bother to run a peephole analyzer over me?") But when
an assumption made by the already-executing routine is actually
violated, it causes incorrect behavior. Here's an example:

    class My::PluginBase;
    
    method say_hi() {
        # Default implementation.
        print "Hello, world.\n";
    }


    package main;
    
    load_plugin($filepath) { ... }

    my $plugin is My::PluginBase;
    $plugin = load_plugin($ARGV[0]);
    $plugin.SayHi();

Now, while it would obviously seem a bad idea to you, it would be
reasonable for perl to initially optimize the method call
$plugin.say_hi() to the function call My::PluginBase::say_hi($plugin).
But when load_plugin loads a subclass of My::PluginBase from the file
specified in $ARGV[0], then that assumption is violated. Now, the
optimization has to be backed out, or the program will never call the
subclass's say_hi. Letting the GC clean up the old version of main when
the notification is received isn't enough--the existing stack frame must
actually be rewritten to use the newly-compiled version.

--
 
Gordon Henriksen
IT Manager
ICLUBcentral Inc.
[EMAIL PROTECTED]


Reply via email to