JDK-8150180 : String.value contents should be trusted
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-02-18
  • Updated: 2017-09-07
  • Resolved: 2016-02-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b110Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
JDK-8149813 had exposed java.lang.String to the trusted classes, and that makes both C1 and C2 trust String.coder and String.value fields, making up a good length() folding.

However, that trust is not enough to constant fold the String.value *contents*. Which means the code like this is not folded:

    static final String TEST_STRING_LATIN1 = "Foo";

    @Benchmark
    public int string_latin1() {
        return TEST_STRING_LATIN1.charAt(0);
    }

A simple change may force VM to trust String.value:
  http://cr.openjdk.java.net/~shade/8150180/webrev.jdk.01/ 
  http://cr.openjdk.java.net/~shade/8150180/webrev.hs.01/ 

Notes: 
 http://cr.openjdk.java.net/~shade/8150180/notes.txt