Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto-Gentili committed May 1, 2024
1 parent bf338e4 commit db034ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,28 @@ public static class ForJava9 extends Abst {

public ForJava9(Map<Object, Object> context) throws Throwable {
ObjectProvider functionProvider = ObjectProvider.get(context);
Class<?> accessorImplClass = Class.forName("jdk.internal.reflect.NativeConstructorAccessorImpl");
Class<?> accessorImplClass = Class.forName(retrieveNativeAccessorClassName());
Method method = accessorImplClass.getDeclaredMethod("newInstance0", Constructor.class, Object[].class);
ConsulterSupplyFunction getConsulterFunction = functionProvider.getOrBuildObject(ConsulterSupplyFunction.class, context);
MethodHandles.Lookup consulter = getConsulterFunction.apply(accessorImplClass);
methodHandle = consulter.unreflect(method);
}

protected String retrieveNativeAccessorClassName() {
return "jdk.internal.reflect.NativeConstructorAccessorImpl";
}

}

public static class ForJava22 extends Abst {
public static class ForJava22 extends ForJava9 {

public ForJava22(Map<Object, Object> context) throws Throwable {
ObjectProvider functionProvider = ObjectProvider.get(context);
Class<?> accessorImplClass = Class.forName("jdk.internal.reflect.DirectConstructorHandleAccessor$NativeAccessor");
Method method = accessorImplClass.getDeclaredMethod("newInstance0", Constructor.class, Object[].class);
ConsulterSupplyFunction getConsulterFunction = functionProvider.getOrBuildObject(ConsulterSupplyFunction.class, context);
MethodHandles.Lookup consulter = getConsulterFunction.apply(accessorImplClass);
methodHandle = consulter.unreflect(method);
super(context);
}

@Override
protected String retrieveNativeAccessorClassName() {
return "jdk.internal.reflect.DirectConstructorHandleAccessor$NativeAccessor";
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ForJava7(Map<Object, Object> context) throws Throwable {
public static class ForJava9 extends Abst {

public ForJava9(Map<Object, Object> context) throws Throwable {
Class<?> accessorImplClass = Class.forName("jdk.internal.reflect.NativeMethodAccessorImpl");
Class<?> accessorImplClass = Class.forName(retrieveNativeAccessorClassName());
Method invoker = accessorImplClass.getDeclaredMethod("invoke0", Method.class, Object.class, Object[].class);
ObjectProvider functionProvider = ObjectProvider.get(context);
ConsulterSupplyFunction consulterSupplyFunction = functionProvider.getOrBuildObject(ConsulterSupplyFunction.class, context);
Expand All @@ -74,18 +74,21 @@ public ForJava9(Map<Object, Object> context) throws Throwable {
methodHandle = consulter.unreflect(invoker);
}

protected String retrieveNativeAccessorClassName() {
return "jdk.internal.reflect.NativeMethodAccessorImpl";
}

}

public static class ForJava22 extends Abst {
public static class ForJava22 extends ForJava9 {

public ForJava22(Map<Object, Object> context) throws Throwable {
Class<?> accessorImplClass = Class.forName("jdk.internal.reflect.DirectMethodHandleAccessor$NativeAccessor");
Method invoker = accessorImplClass.getDeclaredMethod("invoke0", Method.class, Object.class, Object[].class);
ObjectProvider functionProvider = ObjectProvider.get(context);
ConsulterSupplyFunction consulterSupplyFunction = functionProvider.getOrBuildObject(ConsulterSupplyFunction.class, context);
MethodHandles.Lookup consulter = consulterSupplyFunction.apply(accessorImplClass);
functionProvider.getOrBuildObject(SetAccessibleFunction.class, context).accept(invoker, true);
methodHandle = consulter.unreflect(invoker);
super(context);
}

@Override
protected String retrieveNativeAccessorClassName() {
return "jdk.internal.reflect.DirectMethodHandleAccessor$NativeAccessor";
}

}
Expand Down

0 comments on commit db034ef

Please sign in to comment.