From 3c675980b033cd5094e60f14dac805813f0f1f6d Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Fri, 16 Sep 2016 13:55:39 +0100 Subject: [PATCH] Fix merge derp --- gradle.properties | 2 +- .../debug/RuntimeDecompilerAsync.java | 89 +++++++++++++++ .../asm/launch/MixinBootstrap.java | 2 +- .../asm/mixin/transformer/MethodMapper.java | 104 ++++++++++++++++++ 4 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompilerAsync.java create mode 100644 src/main/java/org/spongepowered/asm/mixin/transformer/MethodMapper.java diff --git a/gradle.properties b/gradle.properties index 4b9e2834..9bfdf2e5 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.12 +buildVersion=0.5.14 buildType=SNAPSHOT diff --git a/src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompilerAsync.java b/src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompilerAsync.java new file mode 100644 index 00000000..e0ded5f7 --- /dev/null +++ b/src/fernflower/java/org/spongepowered/asm/mixin/transformer/debug/RuntimeDecompilerAsync.java @@ -0,0 +1,89 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.asm.mixin.transformer.debug; + +import java.io.File; +import java.lang.Thread.UncaughtExceptionHandler; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.SynchronousQueue; + +/** + * Asynchronous decompiler, runs mixin export task in a separate thread to avoid + * slowing down loading time + */ +public class RuntimeDecompilerAsync extends RuntimeDecompiler implements Runnable, UncaughtExceptionHandler { + + private final BlockingQueue queue = new SynchronousQueue(); + + private final Thread thread; + + private boolean run = true; + + public RuntimeDecompilerAsync(File outputPath) { + super(outputPath); + this.thread = new Thread(this, "Decompiler thread"); + this.thread.setDaemon(true); + this.thread.setPriority(Thread.MIN_PRIORITY); + this.thread.setUncaughtExceptionHandler(this); + this.thread.start(); + } + + @Override + public void decompile(File file) { + if (this.run) { + this.queue.offer(file); + } else { + super.decompile(file); + } + } + + @Override + public void run() { + while (this.run) { + try { + File file = this.queue.take(); + super.decompile(file); + } catch (InterruptedException ex) { + this.run = false; + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + @Override + public void uncaughtException(Thread thread, Throwable ex) { + this.logger.error("Async decompiler encountered an error and will terminate. Further decompile requests will be handled synchronously. {} {}", + ex.getClass().getName(), ex.getMessage()); + this.flush(); + } + + private void flush() { + this.run = false; + for (File file = null; (file = this.queue.poll()) != null;) { + this.decompile(file); + } + } +} diff --git a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java index cd7035a3..d39a8600 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.12"; + public static final String VERSION = "0.5.14"; // Consts private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch."; diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MethodMapper.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MethodMapper.java new file mode 100644 index 00000000..c133a32b --- /dev/null +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MethodMapper.java @@ -0,0 +1,104 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.asm.mixin.transformer; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.spongepowered.asm.lib.tree.MethodNode; +import org.spongepowered.asm.mixin.MixinEnvironment; +import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; +import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; +import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinMethodNode; + +/** + * Maintains method remaps for a target class + */ +public class MethodMapper { + + /** + * Mutable integer + */ + static class Counter { + public int value; + } + + /** + * Logger + */ + private static final Logger logger = LogManager.getLogger("mixin"); + + /** + * Method descriptor to ID map, used to ensure that remappings are globally + * unique + */ + private static final Map methodIndices = new HashMap(); + + private final ClassInfo info; + + public MethodMapper(MixinEnvironment env, ClassInfo info) { + this.info = info; + } + + public ClassInfo getClassInfo() { + return this.info; + } + + public void remapHandlerMethod(MixinInfo mixin, MethodNode handler, Method method) { + if (!(handler instanceof MixinMethodNode) || !((MixinMethodNode)handler).isInjector()) { + return; + } + + if (method.isUnique()) { + MethodMapper.logger.warn("Redundant @Unique on injector method {} in {}. Injectors are implicitly unique", method, mixin); + } + + if (method.isRenamed()) { + handler.name = method.getName(); + return; + } + + String handlerName = this.getHandlerName((MixinMethodNode)handler); + handler.name = method.renameTo(handlerName); + } + + public String getHandlerName(MixinMethodNode method) { + String descriptor = String.format("%s%s", method.name, method.desc); + Counter id = MethodMapper.methodIndices.get(descriptor); + if (id == null) { + id = new Counter(); + MethodMapper.methodIndices.put(descriptor, id); + } else if (!method.isSurrogate()) { + id.value++; + } + + String prefix = InjectionInfo.getInjectorPrefix(method.getInjectorAnnotation()); + String uniqueIndex = Integer.toHexString(id.value); + return String.format("%s$%s$%s", prefix, method.name, uniqueIndex); + } + +}