Revert all Method Handle stuff.

According to https://gist.github.com/raphw/881e1745996f9d314ab0 its not faster in dynamic, unknown situations.
This commit is contained in:
Aikar
2018-03-26 01:40:09 -04:00
parent 8147d3ce61
commit d1054d52ef
2 changed files with 7 additions and 35 deletions
@@ -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<String, RegisteredCommand> subCommands = HashMultimap.create();
final Map<Class<?>, 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);
}
}
@@ -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 <CEC extends CommandExecutionContext<CEC, ? extends CommandIssuer>> {
final BaseCommand scope;
final Method method;
@Nullable final MethodHandle methodHandle;
final CommandParameter<CEC>[] parameters;
final CommandManager manager;
final List<String> registeredSubcommands = new ArrayList<>();
@@ -82,14 +79,6 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
}
this.command = command + (!annotations.hasAnnotation(method, CommandAlias.class, false) && !prefSubCommand.isEmpty() ? prefSubCommand : "");
this.method = method;
MethodHandle methodHandle = null;
try {
methodHandle = MethodHandles.lookup().unreflect(method);
} catch (IllegalAccessException ignored) {
// As the method has been found, it cannot not have permission for it.
// In the case that it does however manage to fail this, keep it null and handle it later on.
}
this.methodHandle = methodHandle;
this.prefSubCommand = prefSubCommand;
this.permission = annotations.getAnnotationValue(method, CommandPermission.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);
@@ -150,14 +139,9 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
Map<String, Object> 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();
}