From d1054d52ef961ebd94dd23509d22cfd92487266b Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 26 Mar 2018 01:40:09 -0400 Subject: [PATCH] Revert all Method Handle stuff. According to https://gist.github.com/raphw/881e1745996f9d314ab0 its not faster in dynamic, unknown situations. --- .../java/co/aikar/commands/BaseCommand.java | 20 ++++------------- .../co/aikar/commands/RegisteredCommand.java | 22 +++---------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/co/aikar/commands/BaseCommand.java b/core/src/main/java/co/aikar/commands/BaseCommand.java index 717b1e72..9b2502d3 100644 --- a/core/src/main/java/co/aikar/commands/BaseCommand.java +++ b/core/src/main/java/co/aikar/commands/BaseCommand.java @@ -42,10 +42,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.SetMultimap; import com.google.common.collect.Sets; -import org.jetbrains.annotations.Nullable; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -71,8 +68,7 @@ public abstract class BaseCommand { public static final String DEFAULT = "__default"; final SetMultimap subCommands = HashMultimap.create(); final Map, String> contextFlags = Maps.newHashMap(); - @Nullable private MethodHandle preCommandHandler = null; - private Method preCommandReflectiveHandler = null; + private Method preCommandHandler; @SuppressWarnings("WeakerAccess") private String execLabel; @@ -249,12 +245,7 @@ public abstract class BaseCommand { } } else if (preCommand) { if (this.preCommandHandler == null) { - this.preCommandReflectiveHandler = method; - try { - this.preCommandHandler = MethodHandles.lookup().unreflect(method); - } catch (IllegalAccessException ignored) { - // We use preCommandReflectiveHandler whenever the methodhandle is used instead - } + this.preCommandHandler = method; } else { ACFUtil.sneaky(new IllegalStateException("Multiple @PreCommand commands, duplicate on " + method.getDeclaringClass().getName() + "#" + method.getName())); } @@ -573,7 +564,7 @@ public abstract class BaseCommand { } private boolean checkPrecommand(CommandOperationContext commandOperationContext, RegisteredCommand cmd, CommandIssuer issuer, String[] args) { - Method pre = this.preCommandReflectiveHandler; + Method pre = this.preCommandHandler; if (pre != null) { try { Class[] types = pre.getParameterTypes(); @@ -594,11 +585,8 @@ public abstract class BaseCommand { } } - if (false) { // preCommandHandler != null) { //TODO: MethodHandle disabled due to WrongMethodTypeException - return (boolean) preCommandHandler.invoke(parameters); - } return (boolean) pre.invoke(this, parameters); - } catch (Throwable e) { + } catch (IllegalAccessException | InvocationTargetException e) { this.manager.log(LogLevel.ERROR, "Exception encountered while command pre-processing", e); } } diff --git a/core/src/main/java/co/aikar/commands/RegisteredCommand.java b/core/src/main/java/co/aikar/commands/RegisteredCommand.java index 4956afaf..10dd076d 100644 --- a/core/src/main/java/co/aikar/commands/RegisteredCommand.java +++ b/core/src/main/java/co/aikar/commands/RegisteredCommand.java @@ -37,8 +37,6 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.jetbrains.annotations.Nullable; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; @@ -53,7 +51,6 @@ import java.util.stream.Collectors; public class RegisteredCommand > { final BaseCommand scope; final Method method; - @Nullable final MethodHandle methodHandle; final CommandParameter[] parameters; final CommandManager manager; final List registeredSubcommands = new ArrayList<>(); @@ -82,14 +79,6 @@ public class RegisteredCommand passedArgs = resolveContexts(sender, args); if (passedArgs == null) return; - if (false) {// methodHandle != null) { //TODO: MethodHandle disabled due to WrongMethodTypeException - methodHandle.invokeWithArguments(passedArgs.values().toArray()); - } else { - // The offchance the method handle wasn't unreflected, we're going to use the slower, working reflection. - method.invoke(scope, passedArgs.values().toArray()); - } - } catch (Throwable throwable) { - handleException(sender, args, throwable instanceof Exception ? (Exception) throwable : new Exception(throwable)); + method.invoke(scope, passedArgs.values().toArray()); + } catch (Exception e) { + handleException(sender, args, e); } postCommand(); }