Skip to content

Commit

Permalink
add back getArrayLength
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshSingla committed Oct 4, 2023
1 parent 30cf76d commit 6ac8c0b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static MethodHandle defineClassJava9(MethodHandles.Lookup lookup) throws
}

/**
* "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(
Expand Down Expand Up @@ -147,7 +147,7 @@ private static MethodHandle defineClassJava8(MethodHandles.Lookup lookup) throws
// 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",
Expand All @@ -171,6 +171,11 @@ private static MethodHandle defineClassJava8(MethodHandles.Lookup lookup) throws
return defineClass;
}

static int getArrayLength(byte[] bytes)
{
return bytes.length;
}

public static Class defineClass(
Class<?> targetClass,
byte[] byteCode,
Expand Down

0 comments on commit 6ac8c0b

Please sign in to comment.