Fix monomorphic processing code running on JDK8 since it references a non-existing method (#15092)

Code relying on monomorphic processing on JDK8 doesn't work correctly, since it tries to reference getArrayLength using method handles, which might have been accidentally removed here since it seems unused. This PR adds the method back as is.
This commit is contained in:
Laksh Singla 2023-10-05 11:05:38 +05:30 committed by GitHub
parent b4bc9b6950
commit 2c286d6f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -95,7 +95,7 @@ public class DefineClassUtils
}
/**
* "Compile" a MethodHandle that is equilavent to:
* "Compile" a MethodHandle that is equivalent to:
*
* Class<?> defineClass(Class targetClass, byte[] byteCode, String className) {
* return Unsafe.defineClass(
@ -147,7 +147,7 @@ public class DefineClassUtils
// defineClass(className, byteCode, 0, length, targetClass)
defineClass = MethodHandles.insertArguments(defineClass, 2, (int) 0);
// JDK8 does not implement MethodHandles.arrayLength so we have to roll our own
// JDK8 does not implement MethodHandles.arrayLength, so we have to roll our own
MethodHandle arrayLength = lookup.findStatic(
lookup.lookupClass(),
"getArrayLength",
@ -171,6 +171,16 @@ public class DefineClassUtils
return defineClass;
}
/**
* This method is referenced in Java 8 using method handle, therefore it is not actually unused, and shouldn't be
* removed (till Java 8 is supported)
*/
@SuppressWarnings("unused") // method is referenced and used in defineClassJava8
static int getArrayLength(byte[] bytes)
{
return bytes.length;
}
public static Class defineClass(
Class<?> targetClass,
byte[] byteCode,