From 2c72246fe0b67c145db5510e66c8873df18b5a9f Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Tue, 3 Jul 2018 13:08:56 +0100 Subject: [PATCH] Disable signature merging unless decompiler is active, closes #254 --- .../asm/mixin/MixinEnvironment.java | 9 +++++ .../transformer/MixinApplicatorStandard.java | 37 +++++++++++++++++-- .../extensions/ExtensionClassExporter.java | 4 ++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java index 0ca05f93b..7edfa2ac6 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java +++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java @@ -238,6 +238,15 @@ public static enum Option { */ DEBUG_EXPORT_DECOMPILE_THREADED(Option.DEBUG_EXPORT_DECOMPILE, Inherit.ALLOW_OVERRIDE, "async"), + /** + * By default, if the runtime export decompiler is active, mixin generic + * signatures are merged into target classes. However this can cause + * problems with some runtime subsystems which attempt to reify generics + * using the signature data. Set this option to false to + * disable generic signature merging. + */ + DEBUG_EXPORT_DECOMPILE_MERGESIGNATURES(Option.DEBUG_EXPORT_DECOMPILE, Inherit.ALLOW_OVERRIDE, "mergeGenericSignatures"), + /** * Run the CheckClassAdapter on all classes after mixins are applied, * also enables stricter checks on mixins for use at dev-time, promotes diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java index c90c1130f..aeeed5292 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java @@ -56,6 +56,7 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; +import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionClassExporter; import org.spongepowered.asm.mixin.transformer.meta.MixinMerged; import org.spongepowered.asm.mixin.transformer.meta.MixinRenamed; import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; @@ -237,10 +238,22 @@ public String toString() { */ protected final Profiler profiler = MixinEnvironment.getProfiler(); + /** + * Flag to track whether signatures from applied mixins should be merged + * into target classes. This is only true when the runtime decompiler is + * active. If this is disabled, signatures on merged mixin methods are + * stripped instead of remapped. + */ + protected final boolean mergeSignatures; + MixinApplicatorStandard(TargetClassContext context) { this.context = context; this.targetName = context.getClassName(); this.targetClass = context.getClassNode(); + + ExtensionClassExporter exporter = context.getExtensions().getExtension(ExtensionClassExporter.class); + this.mergeSignatures = exporter.isDecompilerActive() + && MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_EXPORT_DECOMPILE_MERGESIGNATURES); } /** @@ -316,7 +329,9 @@ protected final void applyMixin(MixinTargetContext mixin, ApplicatorPass pass) { } protected void applySignature(MixinTargetContext mixin) { - this.context.mergeSignature(mixin.getSignature()); + if (this.mergeSignatures) { + this.context.mergeSignature(mixin.getSignature()); + } } /** @@ -389,6 +404,16 @@ protected void mergeNewFields(MixinTargetContext mixin) { if (target == null) { // This is just a local field, so add it this.targetClass.fields.add(field); + + if (field.signature != null) { + if (this.mergeSignatures) { + SignatureVisitor sv = mixin.getSignature().getRemapper(); + new SignatureReader(field.signature).accept(sv); + field.signature = sv.toString(); + } else { + field.signature = null; + } + } } } } @@ -468,9 +493,13 @@ protected void mergeMethod(MixinTargetContext mixin, MethodNode method) { mixin.methodMerged(method); if (method.signature != null) { - SignatureVisitor sv = mixin.getSignature().getRemapper(); - new SignatureReader(method.signature).accept(sv); - method.signature = sv.toString(); + if (this.mergeSignatures) { + SignatureVisitor sv = mixin.getSignature().getRemapper(); + new SignatureReader(method.signature).accept(sv); + method.signature = sv.toString(); + } else { + method.signature = null; + } } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java index 564a85864..02b3664a2 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ext/extensions/ExtensionClassExporter.java @@ -75,6 +75,10 @@ public ExtensionClassExporter(MixinEnvironment env) { } } + public boolean isDecompilerActive() { + return this.decompiler != null; + } + private IDecompiler initDecompiler(MixinEnvironment env, File outputPath) { if (!env.getOption(Option.DEBUG_EXPORT_DECOMPILE)) { return null;