Merge remote-tracking branch 'remotes/sponge/master' into fabric-0.8

# Conflicts:
#	build.gradle
#	gradle.properties
This commit is contained in:
modmuss50 committed 2020-01-13 17:20:03 +00:00
commit 5442b78e67
16 files changed
+257 -42

No files matched your search

+2 -2
View File
@@ -109,8 +109,8 @@ dependencies {
def guava = 'com.google.guava:guava:21.0' // from mc1.12 onwards
def log4j2 = 'org.apache.logging.log4j:log4j-core:2.0-beta9'
implementation guava
implementation log4j2
compile guava
compile log4j2
compile 'com.google.code.gson:gson:2.2.4'
if (Float.parseFloat(asmVersion) < 6) {
compile "org.ow2.asm:asm-debug-all:$asmVersion"
+1 -1
View File
@@ -5,7 +5,7 @@ description=Mixin (Fabric fork)
url=https://fabricmc.net
organization=FabricMC
buildVersion=0.8
buildType=SNAPSHOT
buildType=RELEASE
asmVersion=7.2
legacyForgeAsmVersion=5.0.3
modlauncherAsmVersion=6.2
@@ -29,11 +29,20 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.spongepowered.asm.mixin.gen.Accessor;
/**
* Use in conjunction with {@link Final} to indicate that whilst a field is
* final in the target class, mutation within the mixin is intentional.
* Use in conjunction with {@link Final} or {@link Accessor} to indicate that
* whilst a target field is final in the target class, mutation within the mixin
* is intentional.
*
* <p>Applying this annotation has the effect of removing the <tt>final</tt>
* modifier from the target field in order to avoid illegal access errors when a
* shadow visible outside the mixin class (eg. to derived or package-local
* mixins) is mutated. It also permits the mutation on Java runtimes which also
* check for mutation of <tt>private</tt> final variables (JRE 9 and later).</p>
*/
@Target(ElementType.FIELD)
@Target({ ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Mutable {
@@ -78,6 +78,14 @@ public abstract class AccessorGenerator {
accessor.maxStack = maxStack;
return accessor;
}
/**
* Perform pre-flight checks on the accessor, to ensure it can be generated
* sanely
*/
public void validate() {
// Stub for subclasses
}
/**
* Generate the accessor method
@@ -24,26 +24,57 @@
*/
package org.spongepowered.asm.mixin.gen;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.Bytecode;
/**
* Generator for field setters
*/
public class AccessorGeneratorFieldSetter extends AccessorGeneratorField {
/**
* True if the accessor method is decorated with {@link Mutable}
*/
private boolean mutable;
public AccessorGeneratorFieldSetter(AccessorInfo info) {
super(info);
}
@Override
public void validate() {
super.validate();
Method method = this.info.getClassInfo().findMethod(this.info.getMethod());
this.mutable = method.isDecoratedMutable();
if (this.mutable || !Bytecode.hasFlag(this.targetField, Opcodes.ACC_FINAL)) {
return;
}
if (this.info.getContext().getOption(Option.DEBUG_VERBOSE)) {
LogManager.getLogger("mixin").warn("{} for final field {}::{} is not @Mutable", this.info,
((MixinTargetContext)this.info.getContext()).getTarget(), this.targetField.name);
}
}
/* (non-Javadoc)
* @see org.spongepowered.asm.mixin.gen.AccessorGenerator#generate()
*/
@Override
public MethodNode generate() {
if (this.mutable) {
this.targetField.access &= ~Opcodes.ACC_FINAL;
}
int stackSpace = this.targetIsStatic ? 0 : 1; // Stack space for "this"
int maxLocals = stackSpace + this.targetType.getSize();
int maxStack = stackSpace + this.targetType.getSize();
@@ -58,9 +58,7 @@ public class AccessorGeneratorObjectFactory extends AccessorGeneratorMethodProxy
Bytecode.loadArgs(this.argTypes, method.instructions, 0);
method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, className, Constants.CTOR, this.targetMethod.desc, false));
method.instructions.add(new InsnNode(Opcodes.ARETURN));
assert 1 == 3;
return method;
}
@@ -282,6 +282,12 @@ public class AccessorInfo extends SpecialMethodInfo {
*/
protected MethodNode targetMethod;
/**
* Generator which will be responsible for actually generating the accessor
* method body
*/
protected AccessorGenerator generator;
public AccessorInfo(MixinTargetContext mixin, MethodNode method) {
this(mixin, method, Accessor.class);
}
@@ -401,6 +407,8 @@ public class AccessorInfo extends SpecialMethodInfo {
}
return null;
}
/**
* Get the inflected/specified target member for this accessor
@@ -466,6 +474,15 @@ public class AccessorInfo extends SpecialMethodInfo {
public void locate() {
this.targetField = this.findTargetField();
}
/**
* Called immediately after locate, initialises the generator for this
* accessor and runs validation.
*/
public void validate() {
this.generator = this.type.getGenerator(this);
this.generator.validate();
}
/**
* Second pass, generate the actual accessor method for this accessor. The
@@ -475,7 +492,7 @@ public class AccessorInfo extends SpecialMethodInfo {
* @return generated accessor method
*/
public MethodNode generate() {
MethodNode generatedAccessor = this.type.getGenerator(this).generate();
MethodNode generatedAccessor = this.generator.generate();
Annotations.merge(this.method, generatedAccessor);
return generatedAccessor;
}
@@ -42,7 +42,7 @@ import org.spongepowered.asm.util.asm.ElementNode;
*/
class InvokerInfo extends AccessorInfo {
public InvokerInfo(MixinTargetContext mixin, MethodNode method) {
InvokerInfo(MixinTargetContext mixin, MethodNode method) {
super(mixin, method, Invoker.class);
}
@@ -29,6 +29,7 @@ import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.IInjectionPointContext;
import org.spongepowered.asm.mixin.refmap.IMixinContext;
import org.spongepowered.asm.mixin.transformer.ClassInfo;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.asm.MethodNodeEx;
@@ -105,6 +106,13 @@ public abstract class SpecialMethodInfo implements IInjectionPointContext {
public final ClassNode getClassNode() {
return this.classNode;
}
/**
* Get the class metadata for the mixin
*/
public final ClassInfo getClassInfo() {
return this.mixin.getClassInfo();
}
/**
* Get method being called
@@ -403,7 +403,7 @@ public final class ClassInfo {
return this.decoratedMutable;
}
public void setDecoratedFinal(boolean decoratedFinal, boolean decoratedMutable) {
protected void setDecoratedFinal(boolean decoratedFinal, boolean decoratedMutable) {
this.decoratedFinal = decoratedFinal;
this.decoratedMutable = decoratedMutable;
}
@@ -486,11 +486,8 @@ public final class ClassInfo {
this.frames = member instanceof Method ? ((Method)member).frames : null;
}
@SuppressWarnings("unchecked")
public Method(MethodNode method) {
this(method, false);
this.setUnique(Annotations.getVisible(method, Unique.class) != null);
this.isAccessor = Annotations.getSingleVisible(method, Accessor.class, Invoker.class) != null;
}
@SuppressWarnings("unchecked")
@@ -499,6 +496,9 @@ public final class ClassInfo {
this.frames = this.gatherFrames(method);
this.setUnique(Annotations.getVisible(method, Unique.class) != null);
this.isAccessor = Annotations.getSingleVisible(method, Accessor.class, Invoker.class) != null;
boolean decoratedFinal = Annotations.getVisible(method, Final.class) != null;
boolean decoratedMutable = Annotations.getVisible(method, Mutable.class) != null;
this.setDecoratedFinal(decoratedFinal, decoratedMutable);
}
public Method(String name, String desc) {
@@ -606,7 +606,7 @@ public final class ClassInfo {
/**
* A field
*/
class Field extends Member {
public class Field extends Member {
public Field(Member member) {
super(member);
@@ -464,8 +464,8 @@ class MixinApplicatorStandard {
if (target != null) {
Annotations.merge(shadow, target);
// Strip the FINAL flag from @Mutable non-private fields
if (entry.getValue().isDecoratedMutable() && !Bytecode.hasFlag(target, Opcodes.ACC_PRIVATE)) {
// Strip the FINAL flag from @Mutable fields
if (entry.getValue().isDecoratedMutable()) {
target.access &= ~Opcodes.ACC_FINAL;
}
}
@@ -57,6 +57,8 @@ import org.spongepowered.asm.util.CompareUtil;
import org.spongepowered.asm.util.VersionNumber;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
@@ -906,8 +908,17 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
/**
* Get the list of mixin classes we will be applying
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public List<String> getClasses() {
return Collections.<String>unmodifiableList(this.mixinClasses);
Builder<String> list = ImmutableList.<String>builder();
for (List<String> classes : new List[] { this.mixinClasses, this.mixinClassesClient, this.mixinClassesServer} ) {
if (classes != null) {
for (String className : classes) {
list.add(this.mixinPackage + className);
}
}
}
return list.build();
}
/**
@@ -982,7 +993,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
public boolean packageMatch(String className) {
return className.startsWith(this.mixinPackage);
}
/**
* Check whether this configuration bundle has a mixin for the specified
* class
@@ -85,6 +85,33 @@ import com.google.common.collect.Lists;
*/
class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
/**
* Class variant, used to determine subtype
*/
enum Variant {
/**
* Standard mixin
*/
STANDARD,
/**
* Interface mixin
*/
INTERFACE,
/**
* Accessor mixin (interface mixin containing only accessors)
*/
ACCESSOR,
/**
* Type proxy
*/
PROXY
}
/**
* A MethodNode in a mixin
*/
@@ -650,22 +677,17 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
}
static SubType getTypeFor(MixinInfo mixin) {
if (!mixin.getClassInfo().isInterface()) {
return new SubType.Standard(mixin);
Variant variant = MixinInfo.getVariant(mixin.getClassInfo());
switch (variant) {
case STANDARD:
return new SubType.Standard(mixin);
case INTERFACE:
return new SubType.Interface(mixin);
case ACCESSOR:
return new SubType.Accessor(mixin);
default:
throw new IllegalStateException("Unsupported Mixin variant " + variant + " for " + mixin);
}
boolean containsNonAccessorMethod = false;
for (Method method : mixin.getClassInfo().getMethods()) {
containsNonAccessorMethod |= !method.isAccessor();
}
if (containsNonAccessorMethod) {
// If the mixin contains any other methods, treat it as a regular interface mixin
return new SubType.Interface(mixin);
}
// The mixin contains no non-accessor methods, so we can treat it as an accessor
return new SubType.Accessor(mixin);
}
}
@@ -1348,4 +1370,31 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
return String.format("%s:%s", this.parent.getName(), this.name);
}
static Variant getVariant(ClassNode classNode) {
return MixinInfo.getVariant(ClassInfo.fromClassNode(classNode));
}
static Variant getVariant(ClassInfo classInfo) {
// if (ProxyInfo.isProxy(classInfo)) {
// return Variant.PROXY;
// }
if (!classInfo.isInterface()) {
return Variant.STANDARD;
}
boolean containsNonAccessorMethod = false;
for (Method method : classInfo.getMethods()) {
containsNonAccessorMethod |= (!method.isAccessor() && !method.isSynthetic());
}
if (containsNonAccessorMethod) {
// If the mixin contains any other methods, treat it as a regular interface mixin
return Variant.INTERFACE;
}
// The mixin contains no non-accessor methods, so we can treat it as an accessor
return Variant.ACCESSOR;
}
}
@@ -30,7 +30,9 @@ import java.util.*;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
@@ -45,17 +47,20 @@ import org.spongepowered.asm.mixin.throwables.MixinApplyError;
import org.spongepowered.asm.mixin.throwables.MixinException;
import org.spongepowered.asm.mixin.throwables.MixinPrepareError;
import org.spongepowered.asm.mixin.transformer.MixinConfig.IListener;
import org.spongepowered.asm.mixin.transformer.MixinInfo.Variant;
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
import org.spongepowered.asm.mixin.transformer.ext.IHotSwap;
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionCheckClass.ValidationFailedException;
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionClassExporter;
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
import org.spongepowered.asm.mixin.transformer.throwables.IllegalClassLoadError;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
import org.spongepowered.asm.mixin.transformer.throwables.ReEntrantTransformerError;
import org.spongepowered.asm.service.IMixinAuditTrail;
import org.spongepowered.asm.service.IMixinService;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.PrettyPrinter;
import org.spongepowered.asm.util.ReEntranceLock;
import org.spongepowered.asm.util.perf.Profiler;
@@ -300,11 +305,14 @@ public class MixinProcessor {
}
SortedSet<MixinInfo> mixins = null;
boolean invalidRef = false;
MixinConfig packageOwnedByConfig = null;
for (MixinConfig config : this.configs) {
if (config.packageMatch(name)) {
invalidRef = true;
int packageLen = packageOwnedByConfig != null ? packageOwnedByConfig.getMixinPackage().length() : 0;
if (config.getMixinPackage().length() > packageLen) {
packageOwnedByConfig = config;
}
continue;
}
@@ -318,12 +326,11 @@ public class MixinProcessor {
}
}
if (invalidRef) {
throw new NoClassDefFoundError(String.format("%s is a mixin class and cannot be referenced directly", name));
if (packageOwnedByConfig != null) {
throw new IllegalClassLoadError(this.getInvalidClassError(name, targetClassNode, packageOwnedByConfig));
}
if (mixins != null) {
// Re-entrance is "safe" as long as we don't need to apply any mixins, if there are mixins then we need to panic now
if (locked) {
ReEntrantTransformerError error = new ReEntrantTransformerError("Re-entrance error.");
@@ -361,6 +368,30 @@ public class MixinProcessor {
}
return success;
}
private String getInvalidClassError(String name, ClassNode targetClassNode, MixinConfig ownedByConfig) {
if (ownedByConfig.getClasses().contains(name)) {
return String.format("Illegal classload request for %s. Mixin is defined in %s and cannot be referenced directly", name, ownedByConfig);
}
// AnnotationNode shadow = Annotations.getInvisible(targetClassNode, Shadow.class);
// if (shadow != null) {
// return String.format("Illegal classload request for UNRESOLVED @Shadow %s. "
// + "The proxy was referenced outside a mixin or the mixin processor encountered an internal error.", name);
// }
AnnotationNode mixin = Annotations.getInvisible(targetClassNode, Mixin.class);
if (mixin != null) {
Variant variant = MixinInfo.getVariant(targetClassNode);
if (variant == Variant.ACCESSOR) {
return String.format("Illegal classload request for accessor mixin %s. The mixin is missing from %s which owns "
+ "package %s* and the mixin has not been applied.", name, ownedByConfig, ownedByConfig.getMixinPackage());
}
}
return String.format("%s is in a defined mixin package %s* owned by %s and cannot be referenced directly",
name, ownedByConfig.getMixinPackage(), ownedByConfig);
}
/**
* Update a mixin class with new bytecode.
@@ -354,7 +354,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
* @return the local class info
*/
@Override
ClassInfo getClassInfo() {
public ClassInfo getClassInfo() {
return this.mixin.getClassInfo();
}
@@ -559,7 +559,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
if (methodRef.getOwner().equals(this.getClassRef())) {
methodRef.setOwner(this.getTarget().getClassRef());
Method md = this.getClassInfo().findMethod(methodRef.getName(), methodRef.getDesc(), ClassInfo.INCLUDE_ALL);
if (md != null && md.isRenamed() && md.getOriginalName().equals(methodRef.getName()) && md.isSynthetic()) {
if (md != null && md.isRenamed() && md.getOriginalName().equals(methodRef.getName()) && (md.isSynthetic() || md.isConformed())) {
methodRef.setName(md.getName());
}
this.upgradeMethodRef(method, methodRef, md);
@@ -1307,6 +1307,13 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
accessor.locate();
}
accessorActivity.next("Validate");
Activity validateActivity = this.activities.begin("?");
for (AccessorInfo accessor : this.accessors) {
validateActivity.next(accessor.toString());
accessor.validate();
}
accessorActivity.next("Generate");
Activity generateActivity = this.activities.begin("?");
for (AccessorInfo accessor : this.accessors) {
@@ -0,0 +1,46 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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.throwables;
/**
* Error thrown when a class defined in a mixin package is classloaded
*/
public class IllegalClassLoadError extends MixinTransformerError {
private static final long serialVersionUID = 1L;
public IllegalClassLoadError(String message) {
super(message);
}
public IllegalClassLoadError(Throwable cause) {
super(cause);
}
public IllegalClassLoadError(String message, Throwable cause) {
super(message, cause);
}
}