Skip to content

Commit

Permalink
Merge pull request #25262 from Sanne/ArCClassloadingMicroOpt
Browse files Browse the repository at this point in the history
ArC: avoid using Class.forName to load classes from the java. package
  • Loading branch information
geoand authored Apr 30, 2022
2 parents ee7344c + 3028715 commit 922a9e9
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,18 @@ public static ResultHandle getParameterizedType(BytecodeCreator creator, ResultH
}

private static ResultHandle doLoadClass(BytecodeCreator creator, String className, ResultHandle tccl) {
//we need to use Class.forName as the class may be package private
if (tccl == null) {
ResultHandle currentThread = creator
.invokeStaticMethod(MethodDescriptors.THREAD_CURRENT_THREAD);
tccl = creator.invokeVirtualMethod(MethodDescriptors.THREAD_GET_TCCL, currentThread);
if (className.startsWith("java.")) {
return creator.loadClass(className);
} else {
//we need to use Class.forName as the class may be package private
if (tccl == null) {
ResultHandle currentThread = creator
.invokeStaticMethod(MethodDescriptors.THREAD_CURRENT_THREAD);
tccl = creator.invokeVirtualMethod(MethodDescriptors.THREAD_GET_TCCL, currentThread);
}
return creator.invokeStaticMethod(MethodDescriptors.CL_FOR_NAME, creator.load(className), creator.load(false),
tccl);
}
return creator.invokeStaticMethod(MethodDescriptors.CL_FOR_NAME, creator.load(className), creator.load(false), tccl);
}

static Type getProviderType(ClassInfo classInfo) {
Expand Down

0 comments on commit 922a9e9

Please sign in to comment.