Hi Claes,

I wonder if it is even possible to create a test that would do something like the following:

        String s = ...
        String s2 = s + "const1" + "const2" + s;

...since javac concatenates consecutive constants into a single constant. So this actually becomes:

        String s2 = s + "const1const2" + s;

...in bytecode.

The branch of code in the StringConcatFactory for constant != null:

1591                     case TAG_CONST: {
1592                         String constantValue = el.getValue();
1593                         initialLengthCoder = (long)mixer(String.class).invoke(initialLengthCoder, constantValue);
1594                         // fold sequential constants into one
1595                         constant = (constant != null) ? constant + constantValue : constantValue;
1596                         break;
1597                     }

...will therefore never actually be executed in programs compiled with javac. Other bytecode compilers or generators might trigger this though.

So what do you think? Is it important to test this or is it "obviously" correct?


Regards, Peter

On 4/25/19 2:20 PM, Claes Redestad wrote:
Hi,

sorry for the delay, got distracted by other things. Switch back:

http://cr.openjdk.java.net/~redestad/8222852/open.01/

Passed a sanity tier1 run.

/Claes

On 2019-04-23 13:27, Aleksey Shipilev wrote:
I'd keep the switch in the second loop, like this:

   for (RecipeElement el : recipe.getElements()) {
       switch (el.getTag()) {
           case TAG_ARG:
               ...
               break;
           case TAG_CONST:
               // Constants are already handled in the code above.
               break;
           default:
               throw new StringConcatException("Unhandled tag: " + el.getTag());
       }
   }

Reply via email to