RFR: 8295302: Do not use ArrayList when LambdaForm has a single ClassData [v2]
Ioi Lam
iklam at openjdk.org
Fri Oct 14 04:44:02 UTC 2022
On Thu, 13 Oct 2022 22:29:03 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
>> Ioi Lam has updated the pull request incrementally with one additional commit since the last revision:
>>
>> @iwanowww comments
>
> src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java line 321:
>
>> 319: private MemberName loadMethod(byte[] classFile) {
>> 320: Class<?> invokerClass = LOOKUP.makeHiddenClassDefiner(className, classFile, Set.of())
>> 321: .defineClass(true, classDataValues());
>
> Why not just put it in `classDataValues()` instead?
>
>
> Object classDataValues() {
> final List<ClassData> cd = classData;
> return switch(cd.size()) {
> case 0 -> null; // flatten for zero case
> case 1 -> cd.get(0).value; // flatten for single value case
> case 2 -> List.of(cd.get(0).value, cd.get(1).value);
> ...
>
>
> And it also covers zero case for free.
I fixed it as you suggested. I also changed the method to private to make sure no one else is using this method.
> src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java line 389:
>
>> 387: mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/invoke/MethodHandles",
>> 388: "classData", "(Ljava/lang/Class;)Ljava/lang/Object;", false);
>> 389: if (classData.size() == 1) {
>
> if (classData.size() < 2) {
>
> It works for zero case, because `checkcast` always succeeds on nulls.
Actually the zero case is already handled here:
static void clinit(ClassWriter cw, String className, List<ClassData> classData) {
if (classData.isEmpty())
return;
No `<clinit>` method is generated because we have no static field to initialize.
-------------
PR: https://git.openjdk.org/jdk/pull/10706
More information about the core-libs-dev
mailing list