On Aug 28, 12:41 pm, Tal Liron <tal.li...@gmail.com> wrote:
> > If you look at the links in my previous e-mail (specifically this one
> >https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/C...).
> > The reflection is done in the compiler only when there is a tag (i.e. a type
> > hint). Otherwise the compiler just emits an invoke instruction to call the
> > Reflector at runtime. That invoke could be replaced with an invokedynamic
> > instruction.
>
> Yes, that's exactly where one of us is mistaken. :) My understanding is that
> this constructor is only called once during the analysis mode. Then, one of
> the emit() methods is called, and from then on we are only executing the
> compiled code.

Well, the statement you just made is true, but nonetheless you are the
one who is mistaken. The emit() method is called, but if not enough
information was present at compile time to resolve to a real method
call (that is, if `method = null` was executed), then the emit() code
emits a call to clojure.lang.Reflector/invokeMatchingMethod, which
does runtime reflection. See
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L1426
where the "fast path" code is only emitted if `method != null`, and
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L1446
where the slow code is emitted instead.

Most of what I know about invokedynamic is from watching this thread,
but here seems to definitely be an area where you could avoid some
runtime reflection, which is quite slow.

You have to be careful, though, because the Method resolved the first
time may not be right the second time. Consider (. some-obj (size)).
If it is called on a j.u.Collection, we can do the reflection and
create a MethodHandle for faster dispatch later. but if someone later
passes in a j.u.Map (which is not a Collection), you have to reflect
again and come up with another MethodHandle. I assume there's some way
to do this, but it's harder than just shoving all runtime reflection
into MethodHandles.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to