RFR: 8336856: Optimize String Concat [v11]
Chen Liang
liach at openjdk.org
Wed Jul 24 15:11:34 UTC 2024
On Wed, 24 Jul 2024 14:56:48 GMT, Shaojin Wen <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 1119:
>>
>>> 1117:
>>> 1118: private static MethodHandle generate(Lookup lookup, MethodType args, String[] constants) throws Exception {
>>> 1119: lookup = MethodHandles.Lookup.IMPL_LOOKUP;
>>
>> I think you can try moving the inline copy generation to java.lang's StringConcatHelper; this way, we don't need to expose stringSize, coder etc. through JavaLangAccess (we may update String impl detail in the future) and just access the generated MethodHandle.
>
> If you do not use TRUSTED Lookup, errors will occur when processing records.
>
> You can see this build error https://github.com/wenshao/jdk/actions/runs/10049344961/job/27775952878
>
> TEST: java/lang/reflect/records/RecordReflectionTest.java
>
>
> Caused by: java.lang.IllegalAccessException: no such method: java.lang.StringConcatHelper$$StringConcat/0xad1b77c0.concat(R1,R2,R3)String/invokeStatic
> at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:906)
> at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:989)
> at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:3750)
> at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:2648)
> at java.base/java.lang.invoke.StringConcatFactory$SimpleStringBuilderStrategy.generate(StringConcatFactory.java:727)
> ... 41 more
> Caused by: java.lang.LinkageError: bad method type alias: (R1,R2,R3)String not visible from class java.lang.StringConcatHelper$$StringConcat/0xad1b77c0
> at java.base/java.lang.invoke.MemberName.ensureTypeVisible(MemberName.java:812)
> at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:961)
> at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:986)
> ... 44 more
>
>
>
> record R1() {}
>
> record R2(int i, int j) {}
>
> record R3(List<String> ls) {}
>
> // error
> record R4(R1 r1, R2 r2, R3 r3) {}
>
>
> This PR also fixes the issue with TRUSTED not working in MemberName.java after using TRUSTED Lookup.
The solution is to call `.erase()` on the input method handle, and call `viewAsType` on the result method handle.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20273#discussion_r1689992258
More information about the core-libs-dev
mailing list