String concatenation tweaks
Louis Wasserman
lowasser at google.com
Fri Apr 17 17:11:41 UTC 2015
I would be thrilled to see that level of magic, though that's probably
beyond my personal abilities to implement or contribute as a patch.
On Fri, Apr 17, 2015 at 10:05 AM Remi Forax <forax at univ-mlv.fr> wrote:
>
> On 04/17/2015 06:51 PM, Aleksey Shipilev wrote:
> > On 03/12/2015 11:34 AM, Aleksey Shipilev wrote:
> >> I am not really fond of doing the optimizations on javac level: asking
> >> users to recompile their programs for better performance and/or fixing
> >> the (probable) javac bugs is arguably against what users expect.
> >> But in this case, changing the bytecode shape before hitting the JIT
> >> compiler seems to be the sanest route. JIT compilers have to maintain
> >> more strong invariants than most users let on, see e.g.:
> >> https://bugs.openjdk.java.net/browse/JDK-8043677
> > All right, let me propose a radical alternative here. Asking users to
> > recompile their Java code for performance once is probably okay, if we
> > describe the performance boosts. But asking for the second, third,
> > (N+1)-th time would probably make our lives harder -- people would
> > refuse to migrate, and we will be stuck supporting multiple possible
> > code shapes in VM.
> >
> > Given we have arguments about the exact specifics how to generate string
> > concat on javac side, chances are we would not get it right from the
> > start; and we would need to make adjustments in future. This is
> > especially scary if we want to introduce special string builders that
> > would have to be leaked into bytecode ABIs.
> >
> > If only there was a way to declare the intent in Java code, and then
> > delay the exact specifics how that intent is fulfilled (e.g. what code
> > is generated) until the JVM runs... wait, that's invokedynamic!
> >
> > So, what if we make a radical ABI change once and for all: implement all
> > concatenations via (for example) the signature-polymorphic
> > java.lang.StringConcat.concat(Object... methods), and let JDK to figure
> > out how to do this exactly at runtime?
>
> yes :)
>
> you don't need a signature polymorphic method, indy is enough,
>
> Object a = ...
> int b = ..
> a + " foo " + b
>
> can be compiled to:
> aload 0 // a
> iload 1 // b
> invokedynamic (Ljava/lang/Object;I)Ljava/lang/String;
> java.lang.invoke.StringConcat [0, "foo", 1]
>
> note that in that case, Java can also support the interpolation syntax:
> "$a foo $b"
> because the translation is exactly the same :)
>
> >
> > Thanks,
> > -Aleksey.
> >
>
> cheers,
> Rémi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150417/7da73b57/attachment.html>
More information about the compiler-dev
mailing list