Rob~ Such performance tests can be tricky to write correctly. You should make certain that the test actually involves resolving multiple dispatch targets rather than just a single one. The place where this architecture is a big win, is when you have multiple callsites, each of which resolves to one or two targets. The naive implementation will have a single call site (inside the dispatch method) that resolves to every possible target (this is known as a megamorphic call site), whereas invokedynamic will have multiple callsites each of which resolves to one or two targets (this is know as either monomorphic or bimorphic).
Matt On Sun, Aug 5, 2012 at 10:54 AM, Rob N <rob.nikan...@gmail.com> wrote: > Thanks. It will take me a while to understand that code. Once I do, > maybe I can write a performance test. I'd like to see a comparison > between invokedynamic with guarded/chained method handles, as you > described, vs calling the dispatch logic the old fashioned way. > > Rob > > On Aug 5, 3:18 am, Charles Oliver Nutter <head...@headius.com> wrote: > > A simple way to do what you want might be sketched out like this: > > > > * The bootstrap method returns a CallSite + handle for your > > multi-dispatch logic contained in another method. > > * The multi-dispatch logic receives the actual arguments for that first > call. > > * Based on those arguments, you build a guarded chain of method > > handles that calls the right target for the incoming types, and falls > > back on the multi-dispatch lookup logic again if new types come in. > > > > From here, you can do various combinations of guards, multiple > > targets, mechanisms for quickly calculating whether the incoming types > > have already been negotiated, and so on. > > > > You want to look at the bootstrap as your way to point future calls > > toward your own specialized logic; the bootstrap does not necessarily > > contain that logic. > > > > There's an example implementation of multi-dispatch here: > http://code.google.com/p/jsr292-cookbook/source/browse/trunk/multi-di... > > > > - Charlie > > > > > > > > > > > > > > > > On Sat, Aug 4, 2012 at 11:26 PM, Rob N <rob.nikan...@gmail.com> wrote: > > > Hi, > > > > > I'm trying to learn about invokedynamic and the supporting classes, > > > and I don't yet see how they help implement the dynamically typed > > > language I have in mind. From what I've read so far, when you emit an > > > invokedynamic instruction, you specify a bootstrap method in your > > > language's runtime, but that is only run once, and it must return a > > > MethodHandle for the CallSite. Lets say I wanted to emit something > > > for a CLOS-like multiple dispatch method (foo x y), that will select > > > an implementation method based on the classes of x and y. Would I not > > > have to return, from the bootstrap method, a handle to a method that > > > did that dispatch? So why not just emit an invokevirtual or > > > invokestatic directly to that method? What is the advantage of > > > invokedynamic here? > > > > > thanks, > > > Rob > > > > > -- > > > You received this message because you are subscribed to the Google > Groups "JVM Languages" group. > > > To post to this group, send email to jvm-languages@googlegroups.com. > > > To unsubscribe from this group, send email to > jvm-languages+unsubscr...@googlegroups.com. > > > For more options, visit this group athttp:// > groups.google.com/group/jvm-languages?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "JVM Languages" group. > To post to this group, send email to jvm-languages@googlegroups.com. > To unsubscribe from this group, send email to > jvm-languages+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/jvm-languages?hl=en. > > -- You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to jvm-languages@googlegroups.com. To unsubscribe from this group, send email to jvm-languages+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.