Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge/0.8.6 #141

Merged
merged 47 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ad1d110
Bump version to 0.8.6-SNAPSHOT
Mumfrey Dec 1, 2021
45856b4
Replace guava deleteRecursively with internal version for guava compat
Mumfrey Dec 4, 2021
a60200d
Restore compat with ASM 5.0.3 by dynamically creating ClassRemapper
Mumfrey Dec 4, 2021
89acb83
Prioritise TypeHandleASM when it is available.
LlamaLad7 Jul 24, 2022
1cec8b1
AP: Fix several cases of ASM TypeHandles breaking code that relies on…
LlamaLad7 Feb 13, 2023
2e4bf96
Fix resolution of upper bounds of intersection types.
LlamaLad7 Jul 24, 2022
be3b94d
AP: Skip superclass validation for imaginary and simulated targets.
LlamaLad7 Feb 16, 2023
ebc72cf
AP: Improve validation of mixin superclasses.
LlamaLad7 Feb 16, 2023
74c25d2
AP: Fix and simplify checking of factory invoker return types.
LlamaLad7 Feb 24, 2023
d633516
Bump AP to Java 8.
LlamaLad7 Aug 12, 2023
1edd5f1
Fix NPE when resolving fields in `TypeHandleASM`.
LlamaLad7 Aug 12, 2023
a40c96a
Rely on the ML-Specification version present in the ModLauncher envir…
shartte Jan 7, 2024
9e8af15
Style fixes
shartte Jan 8, 2024
e02f4ca
Refactoring cherry-pick from 0.8.6-dev for target selectors
Mumfrey Jan 21, 2024
5aa23b5
Update to register VirtualJar for synthetic classes
Mumfrey Jan 21, 2024
7a3cd42
Update ASM and add support for inject into constructor
Mumfrey Jan 21, 2024
f695176
Track source of mixin configs and use source id in conformed names
Mumfrey Jan 21, 2024
d5fc662
Add support for injectors in interface mixins
Mumfrey Jan 21, 2024
3104a5b
Revert method change which breaks MixinExtras
Mumfrey Jan 21, 2024
6948758
Merge remote-tracking branch 'origin/pr/638'
Mumfrey Jan 21, 2024
41a6885
Merge remote-tracking branch 'origin/pr/657'
Mumfrey Jan 21, 2024
3c8c913
Fix checkstyle and stale imports
Mumfrey Jan 24, 2024
73def35
Restore ctor init merging to previous logic, introduce PRE_BODY enforcer
Mumfrey Feb 3, 2024
9c1abe3
Fix broken invokers when target is an interface
Mumfrey Feb 3, 2024
a87babe
Fix missing field assignment for source in MixinConfig
Mumfrey Feb 3, 2024
c970d84
Wrap logger abstraction in agent classes to prevent crash at startup
Mumfrey Feb 10, 2024
5f57d50
Add fallback shim for synthetic package for older ModLauncher versions
Mumfrey Mar 2, 2024
f0d2cd2
Add constructor invokers to refmap when type is implied, closes #454
Mumfrey May 10, 2024
2e5a4b0
Fix descriptor filtering for NEW injection point, closes #515
Mumfrey May 10, 2024
1accf3f
Check for null when inspecting Mixin superclass, closes #546
Mumfrey May 10, 2024
480bd3d
Add missing toString override, closes #562
Mumfrey May 12, 2024
d2d1fbc
Move staticness check for mixin field after unique check, closes #576
Mumfrey May 12, 2024
53aa500
Update build.gradle for hardware signing token
Mumfrey May 12, 2024
2c9a967
Mixin 0.8.6 RELEASE
Mumfrey May 12, 2024
3a090bd
Revert "New: Allow injection point specifiers anywhere. (#129)"
LlamaLad7 May 19, 2024
9cf325d
Revert "Allowing injecting in constructor's (#30 #40)"
LlamaLad7 May 19, 2024
998f057
Initial merge for 0.8.6
LlamaLad7 May 19, 2024
a1d5bec
Fabric: Fall back to modid in MethodMapper#getMixinSourceId.
LlamaLad7 May 19, 2024
8fda508
Fabric: Re-allow jumps and array accesses inside initialisers.
LlamaLad7 May 19, 2024
fda52dc
Fix: Resolve inappropriate `null` default in Mixins#addConfiguration.
LlamaLad7 May 19, 2024
92a64e3
Fabric: Default `At#unsafe` to true.
LlamaLad7 May 19, 2024
0165cf9
Restore old findInitNodeFor used by MixinExtras, mark as deprecated
Mumfrey May 14, 2024
ab4dab0
buildscript: Relevant changes from 0.8.6
LlamaLad7 May 19, 2024
afb9f13
Fix: Restore removed methods relating to configs.
LlamaLad7 May 20, 2024
ea733f9
Change: Add stack checking to old `Target#findInitNodeFor` overload a…
LlamaLad7 May 21, 2024
18f632c
Build: Bump version.
LlamaLad7 Jun 1, 2024
8d413b8
Compat: Gate `NEW` descriptor filtering.
LlamaLad7 Jun 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ repositories {
}
maven {
// For modlauncher
name = 'forge'
url = 'https://files.minecraftforge.net/maven'
name = 'neoforged'
url = 'https://maven.neoforged.net/releases'
}
}

Expand Down Expand Up @@ -226,7 +226,7 @@ dependencies {
modlauncher9Implementation ("cpw.mods:modlauncher:$modlauncherVersion") {
exclude module: 'jopt-simple'
}
modlauncher9Implementation 'cpw.mods:securejarhandler:0.9.+'
modlauncher9Implementation 'cpw.mods:securejarhandler:2.1.24'

// asm bridge
bridgeImplementation 'org.apache.logging.log4j:log4j-core:2.0-beta9'
Expand All @@ -243,7 +243,8 @@ javadoc {
source sourceSets.ap.allJava
options.encoding = 'UTF-8'
exclude {
it.relativePath.file && it.relativePath.pathString =~ 'tools' && !(it.name =~ /SuppressedBy|package-info/) }
it.relativePath.file && it.relativePath.pathString =~ 'tools' && !(it.name =~ /SuppressedBy|package-info/)
}
options {
docTitle 'Welcome to the Mixin Javadoc'
overview 'docs/javadoc/overview.html'
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ description=Mixin (Fabric fork)
url=https://fabricmc.net
organization=FabricMC
buildVersion=0.13.4
upstreamMixinVersion=0.8.5
upstreamMixinVersion=0.8.6
buildType=RELEASE
asmVersion=9.6
legacyForgeAsmVersion=5.0.3
modlauncherAsmVersion=9.1
modlauncherVersion=9.0.7
modlauncherAsmVersion=9.5
modlauncherVersion=10.0.9
legacyModlauncherVersion=7.0.0
38 changes: 26 additions & 12 deletions src/agent/java/org/spongepowered/tools/agent/MixinAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
import java.util.ArrayList;
import java.util.List;

import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.Level;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
import org.spongepowered.asm.mixin.transformer.ext.IHotSwap;
import org.spongepowered.asm.mixin.transformer.throwables.MixinReloadException;
import org.spongepowered.asm.service.IMixinService;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.service.ServiceNotAvailableError;
import org.spongepowered.asm.transformers.MixinClassReader;
import org.spongepowered.asm.util.asm.ASM;

Expand Down Expand Up @@ -76,23 +77,23 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
}

try {
MixinAgent.logger.info("Redefining class {}", className);
MixinAgent.log(Level.INFO, "Redefining class {}", className);
return MixinAgent.this.classTransformer.transformClassBytes(null, className, classfileBuffer);
} catch (Throwable th) {
MixinAgent.logger.error("Error while re-transforming class {}", className, th);
MixinAgent.log(Level.ERROR, "Error while re-transforming class {}", className, th);
return MixinAgent.ERROR_BYTECODE;
}
}

private List<String> reloadMixin(String className, ClassNode classNode) {
MixinAgent.logger.info("Redefining mixin {}", className);
MixinAgent.log(Level.INFO, "Redefining mixin {}", className);
try {
return MixinAgent.this.classTransformer.reload(className.replace('/', '.'), classNode);
} catch (MixinReloadException e) {
MixinAgent.logger.error("Mixin {} cannot be reloaded, needs a restart to be applied: {} ", e.getMixinInfo(), e.getMessage());
MixinAgent.log(Level.ERROR, "Mixin {} cannot be reloaded, needs a restart to be applied: {} ", e.getMixinInfo(), e.getMessage());
} catch (Throwable th) {
// catch everything as otherwise it is ignored
MixinAgent.logger.error("Error while finding targets for mixin {}", className, th);
MixinAgent.log(Level.ERROR, "Error while finding targets for mixin {}", className, th);
}
return null;
}
Expand All @@ -109,18 +110,18 @@ private boolean reApplyMixins(List<String> targets) {

for (String target : targets) {
String targetName = target.replace('/', '.');
MixinAgent.logger.debug("Re-transforming target class {}", target);
MixinAgent.log(Level.DEBUG, "Re-transforming target class {}", target);
try {
Class<?> targetClass = service.getClassProvider().findClass(targetName);
byte[] targetBytecode = MixinAgent.classLoader.getOriginalTargetBytecode(targetName);
if (targetBytecode == null) {
MixinAgent.logger.error("Target class {} bytecode is not registered", targetName);
MixinAgent.log(Level.ERROR, "Target class {} bytecode is not registered", targetName);
return false;
}
targetBytecode = MixinAgent.this.classTransformer.transformClassBytes(null, targetName, targetBytecode);
MixinAgent.instrumentation.redefineClasses(new ClassDefinition(targetClass, targetBytecode));
} catch (Throwable th) {
MixinAgent.logger.error("Error while re-transforming target class {}", target, th);
MixinAgent.log(Level.ERROR, "Error while re-transforming target class {}", target, th);
return false;
}
}
Expand All @@ -140,8 +141,6 @@ private boolean reApplyMixins(List<String> targets) {
*/
static final MixinAgentClassLoader classLoader = new MixinAgentClassLoader();

static final ILogger logger = MixinService.getService().getLogger("mixin.agent");

/**
* Instance used to register the transformer
*/
Expand Down Expand Up @@ -195,7 +194,7 @@ public void registerTargetClass(String name, ClassNode classNode) {
public static void init(Instrumentation instrumentation) {
MixinAgent.instrumentation = instrumentation;
if (!MixinAgent.instrumentation.isRedefineClassesSupported()) {
MixinAgent.logger.error("The instrumentation doesn't support re-definition of classes");
MixinAgent.log(Level.ERROR, "The instrumentation doesn't support re-definition of classes");
}
for (MixinAgent agent : MixinAgent.agents) {
agent.initTransformer();
Expand Down Expand Up @@ -229,4 +228,19 @@ public static void agentmain(String arg, Instrumentation instrumentation) {
MixinAgent.init(instrumentation);
}

/**
* Wrapper for logger since we can't access the log abstraction in premain
*
* @param level the logging level
* @param message the message to log
* @param params parameters to the message
*/
public static void log(Level level, String message, Object... params) {
try {
MixinService.getService().getLogger("mixin.agent").log(level, message, params);
} catch (ServiceNotAvailableError err) {
System.err.printf("MixinAgent: %s: %s", level.name(), String.format(message, params));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
import java.util.HashMap;
import java.util.Map;

import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.Level;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.service.ServiceNotAvailableError;
import org.spongepowered.asm.util.Constants;

/**
Expand All @@ -43,8 +44,6 @@
*/
class MixinAgentClassLoader extends ClassLoader {

private static final ILogger logger = MixinService.getService().getLogger("mixin.agent");

/**
* Mapping of mixin mixin classes to their fake classes
*/
Expand All @@ -62,7 +61,7 @@ class MixinAgentClassLoader extends ClassLoader {
* @param name Name of the fake class
*/
void addMixinClass(String name) {
MixinAgentClassLoader.logger.debug("Mixin class {} added to class loader", name);
MixinAgentClassLoader.log(Level.DEBUG, "Mixin class {} added to class loader", name);
try {
byte[] bytes = this.materialise(name);
Class<?> clazz = this.defineClass(name, bytes, 0, bytes.length);
Expand All @@ -71,7 +70,7 @@ void addMixinClass(String name) {
clazz.getDeclaredConstructor().newInstance();
this.mixins.put(clazz, bytes);
} catch (Throwable e) {
MixinAgentClassLoader.logger.catching(e);
MixinAgentClassLoader.log(Level.ERROR, "Catching {}", e);
}
}

Expand All @@ -91,9 +90,9 @@ void addTargetClass(String name, ClassNode classNode) {
classNode.accept(cw);
this.targets.put(name, cw.toByteArray());
} catch (Exception ex) {
MixinAgentClassLoader.logger.error("Error storing original class bytecode for {} in mixin hotswap agent. {}: {}",
MixinAgentClassLoader.log(Level.ERROR, "Error storing original class bytecode for {} in mixin hotswap agent. {}: {}",
name, ex.getClass().getName(), ex.getMessage());
MixinAgentClassLoader.logger.debug(ex.toString());
MixinAgentClassLoader.log(Level.DEBUG, ex.toString());
}
}
}
Expand Down Expand Up @@ -144,4 +143,19 @@ private byte[] materialise(String name) {
return cw.toByteArray();
}

/**
* Wrapper for logger since we can't access the log abstraction in premain
*
* @param level the logging level
* @param message the message to log
* @param params parameters to the message
*/
public static void log(Level level, String message, Object... params) {
try {
MixinService.getService().getLogger("mixin.agent").log(level, message, params);
} catch (ServiceNotAvailableError err) {
System.err.printf("MixinAgent: %s: %s", level.name(), String.format(message, params));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ public ReferenceMapper getReferenceMapper() {
public String getClassName() {
return this.getClassRef().replace('/', '.');
}

@Override
public String getTargetClassName() {
return this.primaryTarget.toString();
}

@Override
public String getTargetClassRef() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public String remap(String reference) {
return reference;
}

@Override
public String getElementDescription() {
return String.format("%s annotation on %s", this.getAnnotation(), this);
}

@Override
public String toString() {
return TypeUtils.getName(this.element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public String toString() {
static class AnnotatedElementInvoker extends AnnotatedElementAccessor {

private AccessorType type = AccessorType.METHOD_PROXY;

public AnnotatedElementInvoker(ExecutableElement element, AnnotationHandle annotation, IMixinContext context, boolean shouldRemap) {
super(element, annotation, context, shouldRemap);
}
Expand All @@ -165,16 +165,24 @@ public void attach(TypeHandle target) {

for (String prefix : AccessorType.OBJECT_FACTORY.getExpectedPrefixes()) {
if (prefix.equals(accessorName.prefix)
&& (Constants.CTOR.equals(accessorName.name) || target.getSimpleName().equals(accessorName.name))) {
&& (Constants.CTOR.equals(accessorName.name) || target.getSimpleName().equalsIgnoreCase(accessorName.name))) {
this.type = AccessorType.OBJECT_FACTORY;
return;
}
}
}

@Override
public String getAnnotationValue() {
String value = super.getAnnotationValue();
return (this.type == AccessorType.OBJECT_FACTORY && value == null) ? this.returnType.toString() : value;
}

@Override
public boolean shouldRemap() {
return (this.type == AccessorType.METHOD_PROXY || this.getAnnotationValue() != null) && super.shouldRemap();
return (this.type == AccessorType.OBJECT_FACTORY
|| this.type == AccessorType.METHOD_PROXY
|| this.getAnnotationValue() != null) && super.shouldRemap();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ private boolean registerInjector(AnnotatedElementInjector elem, String reference
}
}

IReferenceManager refMap = this.obf.getReferenceManager();
IReferenceManager refMaps = this.obf.getReferenceManager();
try {
// If the original owner is unspecified, and the mixin is multi-target, we strip the owner from the obf mappings
if ((targetMember.getOwner() == null && this.mixin.isMultiTarget()) || target.isSimulated()) {
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripOwnerData(obfData);
}
refMap.addMethodMapping(this.classRef, reference, obfData);
refMaps.addMethodMapping(this.classRef, reference, obfData);
} catch (ReferenceConflictException ex) {
String conflictType = this.mixin.isMultiTarget() ? "Multi-target" : "Target";

Expand All @@ -270,9 +270,9 @@ private boolean registerInjector(AnnotatedElementInjector elem, String reference
String newName = newMember instanceof ITargetSelectorByName ? ((ITargetSelectorByName)newMember).getName() : newMember.toString();
if (oldName != null && oldName.equals(newName)) {
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripDescriptors(obfData);
refMap.setAllowConflicts(true);
refMap.addMethodMapping(this.classRef, reference, obfData);
refMap.setAllowConflicts(false);
refMaps.setAllowConflicts(true);
refMaps.addMethodMapping(this.classRef, reference, obfData);
refMaps.setAllowConflicts(false);

// This is bad because in notch mappings, using the bare target name might cause everything to explode
elem.printMessage(this.ap, MessageType.BARE_REFERENCE, "Coerced " + conflictType + " reference has conflicting descriptors for "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@

import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic.Kind;

import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class SupportedOptions {
public static final String PLUGIN_VERSION = "pluginVersion";
public static final String QUIET = "quiet";
public static final String SHOW_MESSAGE_TYPES = "showMessageTypes";
public static final String DISABLE_INTERFACE_MIXINS = "disableInterfaceMixins";

private SupportedOptions() {}

Expand All @@ -70,7 +71,8 @@ public static Set<String> getAllOptions() {
SupportedOptions.MAPPING_TYPES,
SupportedOptions.PLUGIN_VERSION,
SupportedOptions.QUIET,
SupportedOptions.SHOW_MESSAGE_TYPES
SupportedOptions.SHOW_MESSAGE_TYPES,
SupportedOptions.DISABLE_INTERFACE_MIXINS
);
options.addAll(
ObfuscationServices.getInstance().getSupportedOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import java.util.List;
import java.util.Set;

import javax.lang.model.element.TypeElement;

import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeReference;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ public static void applyOptions(CompilerEnvironment env, IOptionProvider options
// Apply the "quiet" option if specified, or if in dev env
MessageType.INFO.setEnabled(!(env.isDevelopmentEnvironment() || "true".equalsIgnoreCase(options.getOption(SupportedOptions.QUIET))));

// Selectively enable injector-in-interface as an error based on user option
MessageType.INJECTOR_IN_INTERFACE.setEnabled(options.getOption(SupportedOptions.DISABLE_INTERFACE_MIXINS, false));

// Legacy option
if ("error".equalsIgnoreCase(options.getOption(SupportedOptions.OVERWRITE_ERROR_LEVEL))) {
MessageType.OVERWRITE_DOCS.setKind(Kind.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class TypeHandle {
* for related classes (eg. superclass) without using mirror
*/
protected final ITypeHandleProvider typeProvider;

/**
* Reference to this handle, for serialisation
*/
Expand Down Expand Up @@ -295,6 +295,8 @@ public boolean isNotInterface() {

/**
* Gets whether this handle is a supertype of the other handle
*
* @param other the TypeHandle to compare with
*/
public boolean isSuperTypeOf(TypeHandle other) {
List<TypeHandle> superTypes = new ArrayList<>();
Expand All @@ -309,7 +311,7 @@ public boolean isSuperTypeOf(TypeHandle other) {
}
return false;
}

/**
* Get the TypeReference for this type, used for serialisation
*/
Expand Down
Loading
Loading