From 451f24a6da72b53e8a5a93451a16caf0f9d2d224 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Fri, 16 Sep 2016 13:53:48 +0100 Subject: [PATCH] Merge mapper fixes and async decompiler --- gradle.properties | 2 +- .../transformer/debug/RuntimeDecompiler.java | 2 +- .../asm/launch/MixinBootstrap.java | 2 +- .../asm/mixin/MixinEnvironment.java | 28 ++++-- .../mixin/injection/struct/InjectionInfo.java | 5 +- .../asm/mixin/transformer/ClassInfo.java | 39 +++++--- .../asm/mixin/transformer/MixinConfig.java | 6 +- .../asm/mixin/transformer/MixinInfo.java | 23 ++++- .../MixinPreProcessorStandard.java | 95 +++++++++---------- .../mixin/transformer/MixinTargetContext.java | 4 - .../mixin/transformer/MixinTransformer.java | 13 ++- .../mixin/transformer/TargetClassContext.java | 41 +------- 12 files changed, 133 insertions(+), 127 deletions(-) diff --git a/gradle.properties b/gradle.properties index e2ef9039..4b9e2834 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,5 +4,5 @@ packaging=jar description=Mixin url=https://www.spongepowered.org organization=SpongePowered -buildVersion=0.5.13 +buildVersion=0.5.12 buildType=SNAPSHOT diff --git a/src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompiler.java b/src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompiler.java index 55be5049..e4e635a7 100644 --- a/src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompiler.java +++ b/src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompiler.java @@ -53,7 +53,7 @@ public class RuntimeDecompiler extends IFernflowerLogger implements IDecompiler, private final File outputPath; - private final Logger logger = LogManager.getLogger("fernflower"); + protected final Logger logger = LogManager.getLogger("fernflower"); public RuntimeDecompiler(File outputPath) { this.outputPath = outputPath; diff --git a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java index 5c99bde3..cd7035a3 100644 --- a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java +++ b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java @@ -62,7 +62,7 @@ public abstract class MixinBootstrap { /** * Subsystem version */ - public static final String VERSION = "0.5.13"; + public static final String VERSION = "0.5.12"; // Consts private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch."; diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java index acd95e7a..a1a90d60 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java +++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java @@ -276,6 +276,20 @@ public final class MixinEnvironment implements ITokenProvider { } }, + /** + * Run fernflower in a separate thread. In general this will allow + * export to impact startup time much less (decompiling normally adds + * about 20% to load times) with the trade-off that crashes may lead to + * undecompiled exports. + */ + DEBUG_EXPORT_DECOMPILE_THREADED(Option.DEBUG_EXPORT_DECOMPILE, "async") { + @Override + boolean getBooleanValue() { + // Allow a local FALSE to override a parent TRUE + return Booleans.parseBoolean(System.getProperty(this.property), super.getBooleanValue()); + } + }, + /** * Run the CheckClassAdapter on all classes after mixins are applied, * also enables stricter checks on mixins for use at dev-time, promotes @@ -321,13 +335,13 @@ public final class MixinEnvironment implements ITokenProvider { /** * Disable the injector handler remapper */ - DEBUG_DISABLE_HANDLER_REMAP(Option.DEBUG_ALL, "disableHandlerRename") { - @Override - boolean getBooleanValue() { - // Allow a local FALSE to override a parent TRUE - return Booleans.parseBoolean(System.getProperty(this.property), super.getBooleanValue()); - } - }, +// DEBUG_DISABLE_HANDLER_REMAP(Option.DEBUG_ALL, "disableHandlerRename") { +// @Override +// boolean getBooleanValue() { +// // Allow a local FALSE to override a parent TRUE +// return Booleans.parseBoolean(System.getProperty(this.property), super.getBooleanValue()); +// } +// }, /** * Dumps the bytecode for the target class to disk when mixin diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java index 9de737f8..77b0c719 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java @@ -40,6 +40,7 @@ import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; import org.spongepowered.asm.mixin.injection.InjectionPoint; @@ -414,7 +415,7 @@ public abstract class InjectionInfo { } public static InjectionInfo parse(MixinTargetContext mixin, MethodNode method) { - AnnotationNode annotation = InjectionInfo.getInjectorAnnotation(mixin, method); + AnnotationNode annotation = InjectionInfo.getInjectorAnnotation(mixin.getMixin(), method); if (annotation == null) { return null; @@ -436,7 +437,7 @@ public abstract class InjectionInfo { } @SuppressWarnings("unchecked") - public static AnnotationNode getInjectorAnnotation(MixinTargetContext mixin, MethodNode method) { + public static AnnotationNode getInjectorAnnotation(IMixinInfo mixin, MethodNode method) { AnnotationNode annotation = null; try { annotation = ASMHelper.getSingleVisibleAnnotation(method, diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java index edc384f3..adff0c6b 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java @@ -308,8 +308,13 @@ public class ClassInfo extends TreeInfo { return this.modifiers; } - public void renameTo(String name) { + /** + * @param name + * @return the passed-in argument, for fluency + */ + public String renameTo(String name) { this.currentName = name; + return name; } public boolean equals(String name, String desc) { @@ -557,7 +562,9 @@ public class ClassInfo extends TreeInfo { * Mixin info if this class is a mixin itself */ private final MixinInfo mixin; - + + private final MethodMapper methodMapper; + /** * True if this is a mixin rather than a class */ @@ -610,6 +617,7 @@ public class ClassInfo extends TreeInfo { this.access = Opcodes.ACC_PUBLIC; this.isMixin = false; this.mixin = null; + this.methodMapper = null; } /** @@ -654,6 +662,7 @@ public class ClassInfo extends TreeInfo { this.isProbablyStatic = isProbablyStatic; this.outerName = outerName; + this.methodMapper = new MethodMapper(MixinEnvironment.getCurrentEnvironment(), this); } void addInterface(String iface) { @@ -747,6 +756,10 @@ public class ClassInfo extends TreeInfo { public String toString() { return this.name; } + + public MethodMapper getMethodMapper() { + return this.methodMapper; + } public int getAccess() { return this.access; @@ -840,10 +853,10 @@ public class ClassInfo extends TreeInfo { public Set getInterfaceMethods(boolean includeMixins) { Set methods = new HashSet(); - ClassInfo superClass = this.addMethodsRecursive(methods, includeMixins); + ClassInfo supClass = this.addMethodsRecursive(methods, includeMixins); if (!this.isInterface) { - while (superClass != null && superClass != ClassInfo.OBJECT) { - superClass = superClass.addMethodsRecursive(methods, includeMixins); + while (supClass != null && supClass != ClassInfo.OBJECT) { + supClass = supClass.addMethodsRecursive(methods, includeMixins); } } @@ -1062,13 +1075,13 @@ public class ClassInfo extends TreeInfo { return false; } - ClassInfo superClass = this.getSuperClass(); + ClassInfo supClass = this.getSuperClass(); - while (superClass != null && superClass != ClassInfo.OBJECT) { - if (superClass.isMixin) { + while (supClass != null && supClass != ClassInfo.OBJECT) { + if (supClass.isMixin) { return true; } - superClass = superClass.getSuperClass(); + supClass = supClass.getSuperClass(); } return false; @@ -1087,13 +1100,13 @@ public class ClassInfo extends TreeInfo { return false; } - ClassInfo superClass = this.getSuperClass(); + ClassInfo supClass = this.getSuperClass(); - while (superClass != null && superClass != ClassInfo.OBJECT) { - if (superClass.mixins.size() > 0) { + while (supClass != null && supClass != ClassInfo.OBJECT) { + if (supClass.mixins.size() > 0) { return true; } - superClass = superClass.getSuperClass(); + supClass = supClass.getSuperClass(); } return false; diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java index 9a7b6545..14eed789 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java @@ -307,10 +307,10 @@ class MixinConfig implements Comparable, IMixinConfig { private MixinEnvironment parseSelector(String target, MixinEnvironment fallbackEnvironment) { if (target != null) { String[] selectors = target.split("[&\\| ]"); - for (String selector : selectors) { - selector = selector.trim(); + for (String sel : selectors) { + sel = sel.trim(); Pattern environmentSelector = Pattern.compile("^@env(?:ironment)?\\(([A-Z]+)\\)$"); - Matcher environmentSelectorMatcher = environmentSelector.matcher(selector); + Matcher environmentSelectorMatcher = environmentSelector.matcher(sel); if (environmentSelectorMatcher.matches()) { // only parse first env selector return MixinEnvironment.getEnvironment(Phase.forName(environmentSelectorMatcher.group(1))); diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java index 8d4265da..4035541b 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -55,6 +55,8 @@ import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.extensibility.IMixinConfig; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.asm.mixin.injection.Surrogate; +import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; import org.spongepowered.asm.mixin.transformer.throwables.MixinReloadException; import org.spongepowered.asm.mixin.transformer.throwables.MixinTargetAlreadyLoadedException; @@ -93,6 +95,18 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { return this.originalName; } + public boolean isInjector() { + return (this.getInjectorAnnotation() != null || this.isSurrogate()); + } + + public boolean isSurrogate() { + return ASMHelper.getVisibleAnnotation(this, Surrogate.class) != null; + } + + public AnnotationNode getInjectorAnnotation() { + return InjectionInfo.getInjectorAnnotation(MixinInfo.this, this); + } + } /** @@ -199,7 +213,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { return this.mixinBytes; } - ClassNode getClassNode() { + MixinClassNode getClassNode() { return this.classNode; } @@ -243,6 +257,11 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * @param targetClasses Mixin's target classes */ void validate(SubType type, List targetClasses) { + MixinPreProcessorStandard preProcessor = type.createPreProcessor(this.getClassNode()).prepare(); + for (ClassInfo target : targetClasses) { + preProcessor.conform(target); + } + type.validate(this, targetClasses); this.detachedSuper = type.isDetachedSuper(); @@ -697,7 +716,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * @param suppressPlugin * @return target class list read from classNode */ - protected List readTargetClasses(ClassNode classNode, boolean suppressPlugin) { + protected List readTargetClasses(MixinClassNode classNode, boolean suppressPlugin) { if (classNode == null) { return Collections.emptyList(); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java index 2bcffcbf..edf29b9d 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java @@ -40,8 +40,6 @@ import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.Surrogate; -import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinClassNode; @@ -105,17 +103,19 @@ class MixinPreProcessorStandard { * @return Prepared classnode */ MixinPreProcessorStandard prepare() { - if (!this.prepared) { - this.prepared = true; - - for (MixinMethodNode mixinMethod : this.classNode.mixinMethods) { - Method method = this.mixin.getClassInfo().findMethod(mixinMethod); - this.prepareMethod(mixinMethod, method); - } - - for (FieldNode mixinField : this.classNode.fields) { - this.prepareField(mixinField); - } + if (this.prepared) { + return this; + } + + this.prepared = true; + + for (MixinMethodNode mixinMethod : this.classNode.mixinMethods) { + Method method = this.mixin.getClassInfo().findMethod(mixinMethod); + this.prepareMethod(mixinMethod, method); + } + + for (FieldNode mixinField : this.classNode.fields) { + this.prepareField(mixinField); } return this; @@ -136,8 +136,7 @@ class MixinPreProcessorStandard { if (mixinMethod.name.startsWith(prefix)) { ASMHelper.setVisibleAnnotation(mixinMethod, MixinRenamed.class, "originalName", mixinMethod.name); String newName = mixinMethod.name.substring(prefix.length()); - method.renameTo(newName); - mixinMethod.name = newName; + mixinMethod.name = method.renameTo(newName); } } @@ -152,9 +151,29 @@ class MixinPreProcessorStandard { protected void prepareField(FieldNode mixinField) { // stub } + + MixinPreProcessorStandard conform(TargetClassContext target) { + return this.conform(target.getClassInfo()); + } + + MixinPreProcessorStandard conform(ClassInfo target) { + for (MixinMethodNode mixinMethod : this.classNode.mixinMethods) { + if (mixinMethod.isInjector()) { + Method method = this.mixin.getClassInfo().findMethod(mixinMethod, ClassInfo.INCLUDE_ALL); + this.conformInjector(target, mixinMethod, method); + } + } + return this; + } + + private void conformInjector(ClassInfo targetClass, MixinMethodNode mixinMethod, Method method) { + MethodMapper methodMapper = targetClass.getMethodMapper(); + methodMapper.remapHandlerMethod(this.mixin, mixinMethod, method); + } MixinTargetContext createContextFor(TargetClassContext target) { MixinTargetContext context = new MixinTargetContext(this.mixin, this.classNode, target); + this.conform(target); this.attach(context); return context; } @@ -164,7 +183,7 @@ class MixinPreProcessorStandard { * * @param context */ - void attach(MixinTargetContext context) { + MixinPreProcessorStandard attach(MixinTargetContext context) { if (this.attached) { throw new IllegalStateException("Preprocessor was already attached"); } @@ -177,6 +196,7 @@ class MixinPreProcessorStandard { // Apply transformations to the mixin bytecode this.transform(context); + return this; } protected void attachMethods(MixinTargetContext context) { @@ -188,7 +208,7 @@ class MixinPreProcessorStandard { continue; } - if (this.processInjectorMethod(context, mixinMethod)) { + if (mixinMethod.isInjector()) { continue; } @@ -215,26 +235,6 @@ class MixinPreProcessorStandard { return true; } - protected boolean processInjectorMethod(MixinTargetContext context, MixinMethodNode mixinMethod) { - AnnotationNode annotation = InjectionInfo.getInjectorAnnotation(context, mixinMethod); - boolean surrogate = ASMHelper.getVisibleAnnotation(mixinMethod, Surrogate.class) != null; - if (annotation == null && !surrogate) { - return false; - } - - String handlerName = context.getHandlerName(annotation, mixinMethod, surrogate); - Method method = this.mixin.getClassInfo().findMethod(mixinMethod, ClassInfo.INCLUDE_ALL); - - if (method.isUnique()) { - MixinPreProcessorStandard.logger.warn("Redundant @Unique on injector method {} in {}. Injectors are implicitly unique", method, context); - } - - method.renameTo(handlerName); - mixinMethod.name = handlerName; - - return true; - } - protected boolean processShadowMethod(MixinTargetContext context, MixinMethodNode mixinMethod) { return this.processSpecialMethod(context, mixinMethod, Shadow.class, false); } @@ -271,8 +271,7 @@ class MixinPreProcessorStandard { throw new InvalidMixinException(this.mixin, "@" + ASMHelper.getSimpleName(type) + " method " + mixinMethod.name + " was not located in the target class"); } - mixinMethod.name = target.name; - method.renameTo(target.name); + mixinMethod.name = method.renameTo(target.name); } if (Constants.CTOR.equals(target.name)) { @@ -284,8 +283,7 @@ class MixinPreProcessorStandard { throw new InvalidMixinException(this.mixin, "Non-private method cannot be aliased. Found " + target.name); } - mixinMethod.name = target.name; - method.renameTo(target.name); + mixinMethod.name = method.renameTo(target.name); } return true; @@ -306,8 +304,7 @@ class MixinPreProcessorStandard { String uniqueName = context.getUniqueName(mixinMethod); MixinPreProcessorStandard.logger.log(this.mixin.getLoggingLevel(), "Renaming @Unique method {}{} to {} in {}", mixinMethod.name, mixinMethod.desc, uniqueName, this.mixin); - mixinMethod.name = uniqueName; - method.renameTo(uniqueName); + mixinMethod.name = method.renameTo(uniqueName); return false; } @@ -330,8 +327,7 @@ class MixinPreProcessorStandard { Method parentMethod = this.mixin.getClassInfo().findMethodInHierarchy(mixinMethod, false); if (parentMethod != null && parentMethod.isRenamed()) { - mixinMethod.name = parentMethod.getName(); - method.renameTo(parentMethod.getName()); + mixinMethod.name = method.renameTo(parentMethod.getName()); } } @@ -363,8 +359,7 @@ class MixinPreProcessorStandard { // If this field is a shadow field but is NOT found in the target class, that's bad, mmkay throw new InvalidMixinException(this.mixin, "Shadow field " + mixinField.name + " was not located in the target class"); } - mixinField.name = target.name; - field.renameTo(target.name); + mixinField.name = field.renameTo(target.name); } if (field.isUnique()) { @@ -372,8 +367,7 @@ class MixinPreProcessorStandard { String uniqueName = context.getUniqueName(mixinField); MixinPreProcessorStandard.logger.log(this.mixin.getLoggingLevel(), "Renaming @Unique field {}{} to {} in {}", mixinField.name, mixinField.desc, uniqueName, this.mixin); - mixinField.name = uniqueName; - field.renameTo(uniqueName); + mixinField.name = field.renameTo(uniqueName); continue; } @@ -399,8 +393,7 @@ class MixinPreProcessorStandard { throw new InvalidMixinException(this.mixin, "Non-private field cannot be aliased. Found " + target.name); } - mixinField.name = target.name; - field.renameTo(target.name); + mixinField.name = field.renameTo(target.name); } // Shadow fields get stripped from the mixin class diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java index ff89ce28..9842f3bd 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java @@ -971,10 +971,6 @@ public class MixinTargetContext implements IReferenceMapperContext { this.mixin.postApply(transformedName, targetClass); } - public String getHandlerName(AnnotationNode annotation, MethodNode method, boolean surrogate) { - return this.targetClass.getHandlerName(annotation, method, surrogate); - } - public String getUniqueName(MethodNode method) { return this.targetClass.getUniqueName(method); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java index c2849c4f..4d3b0f9b 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java @@ -390,18 +390,21 @@ public class MixinTransformer extends TreeTransformer { } private IDecompiler initDecompiler(File outputPath) { - if (!MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_EXPORT_DECOMPILE)) { + MixinEnvironment env = MixinEnvironment.getCurrentEnvironment(); + if (!env.getOption(Option.DEBUG_EXPORT_DECOMPILE)) { return null; } - + try { - this.logger.info("Attempting to load Fernflower decompiler"); + boolean as = env.getOption(Option.DEBUG_EXPORT_DECOMPILE_THREADED); + this.logger.info("Attempting to load Fernflower decompiler{}", as ? " (Threaded mode)" : ""); @SuppressWarnings("unchecked") Class clazz = - (Class)Class.forName("org.spongepowered.asm.mixin.transformer.debug.RuntimeDecompiler"); + (Class)Class.forName("org.spongepowered.asm.mixin.transformer.debug.RuntimeDecompiler" + (as ? "Async" : "")); Constructor ctor = clazz.getDeclaredConstructor(File.class); IDecompiler decompiler = ctor.newInstance(outputPath); - this.logger.info("Fernflower decompiler was successfully initialised, exported classes will be decompiled"); + this.logger.info("Fernflower decompiler was successfully initialised, exported classes will be decompiled{}", + as ? " in a separate thread" : ""); return decompiler; } catch (Throwable th) { this.logger.info("Fernflower could not be loaded, exported classes will not be decompiled. {}: {}", diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java index 2ba06fb5..f423b65c 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java @@ -37,7 +37,6 @@ import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.Debug; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; -import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; import org.spongepowered.asm.util.ASMHelper; @@ -45,13 +44,6 @@ import org.spongepowered.asm.util.ASMHelper; * Struct for containing target class information during mixin application */ class TargetClassContext { - - /** - * Mutable integer - */ - static class Counter { - public int value; - } /** * Transformer session ID @@ -77,22 +69,12 @@ class TargetClassContext { * Mixins to apply */ private final SortedSet mixins; - - /** - * Injector Method descriptor to ID map - */ - private final Map injectorMethodIndices = new HashMap(); /** * Information about methods in the target class, used to keep track of * transformations we apply */ private final Map targetMethods = new HashMap(); - - /** - * Do not remap injector handler methods (debug option) - */ - private final boolean disableHandlerRemap; /** * Unique method and field indices @@ -116,7 +98,6 @@ class TargetClassContext { this.classNode = classNode; this.classInfo = ClassInfo.fromClassNode(classNode); this.mixins = mixins; - this.disableHandlerRemap = MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_DISABLE_HANDLER_REMAP); } @Override @@ -244,29 +225,15 @@ class TargetClassContext { } return target; } - - public String getHandlerName(AnnotationNode annotation, MethodNode method, boolean surrogate) { - if (this.disableHandlerRemap) { - return method.name; - } - - String descriptor = String.format("%s%s", method.name, method.desc); - Counter id = this.injectorMethodIndices.get(descriptor); - if (id == null) { - id = new Counter(); - this.injectorMethodIndices.put(descriptor, id); - } else if (!surrogate) { - id.value++; - } - return String.format("%s$%s$%d", InjectionInfo.getInjectorPrefix(annotation), method.name, id.value); - } public String getUniqueName(MethodNode method) { - return String.format("md%s$%s$%d", this.sessionId.substring(30), method.name, this.nextUniqueMethodIndex++); + String uniqueIndex = Integer.toHexString(this.nextUniqueMethodIndex++); + return String.format("md%s$%s$%s", this.sessionId.substring(30), method.name, uniqueIndex); } public String getUniqueName(FieldNode field) { - return String.format("fd%s$%s$%d", this.sessionId.substring(30), field.name, this.nextUniqueFieldIndex++); + String uniqueIndex = Integer.toHexString(this.nextUniqueFieldIndex++); + return String.format("fd%s$%s$%s", this.sessionId.substring(30), field.name, uniqueIndex); } /**