Merge remote-tracking branch 'remotes/upstream/0.8' into fabric-0.8

# Conflicts:
#	build.gradle
#	src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java
This commit is contained in:
modmuss50 committed 2019-10-11 20:58:42 +01:00
commit ed1a103051
50 files changed
+747 -868

No files matched your search

@@ -82,11 +82,6 @@ public abstract class MixinBootstrap {
* Platform manager instance
*/
private static MixinPlatformManager platform;
/**
* Connectors
*/
private static MixinConnectorManager connectors = new MixinConnectorManager();
private MixinBootstrap() {}
@@ -193,7 +188,6 @@ public abstract class MixinBootstrap {
static void inject() {
MixinBootstrap.getPlatform().inject();
MixinBootstrap.connectors.inject();
}
private static boolean isSubsystemRegistered() {
@@ -22,17 +22,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.launch;
package org.spongepowered.asm.launch.platform;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.connect.IMixinConnector;
import org.spongepowered.asm.service.IClassProvider;
import org.spongepowered.asm.service.MixinService;
/**
* Manager for Mixin containers bootstrapping via {@link IMixinConnector}
@@ -43,27 +44,50 @@ public class MixinConnectorManager {
* Logging to the max
*/
private static final Logger logger = LogManager.getLogger("mixin");
private final Set<String> connectorClasses = new LinkedHashSet<String>();
private List<IMixinConnector> connectors = new ArrayList<IMixinConnector>();
private final List<IMixinConnector> connectors = new ArrayList<IMixinConnector>();
MixinConnectorManager() {
}
void addConnector(String connectorClass) {
this.connectorClasses.add(connectorClass);
}
void inject() {
this.loadConnectors();
this.initConnectors();
}
@SuppressWarnings("unchecked")
void loadConnectors() {
ServiceLoader<IMixinConnector> serviceLoader = ServiceLoader.load(IMixinConnector.class);
for (Iterator<IMixinConnector> iterator = serviceLoader.iterator(); iterator.hasNext(); ) {
IClassProvider classProvider = MixinService.getService().getClassProvider();
for (String connectorClassName : this.connectorClasses) {
Class<IMixinConnector> connectorClass = null;
try {
IMixinConnector connector = iterator.next();
Class<?> clazz = classProvider.findClass(connectorClassName);
if (!IMixinConnector.class.isAssignableFrom(clazz)) {
MixinConnectorManager.logger.error("Mixin Connector [" + connectorClassName + "] does not implement IMixinConnector");
continue;
}
connectorClass = (Class<IMixinConnector>)clazz;
} catch (ClassNotFoundException ex) {
MixinConnectorManager.logger.catching(ex);
continue;
}
try {
IMixinConnector connector = connectorClass.newInstance();
this.connectors.add(connector);
} catch (ServiceConfigurationError e) {
MixinConnectorManager.logger.catching(e);
MixinConnectorManager.logger.info("Successfully loaded Mixin Connector [" + connectorClassName + "]");
} catch (ReflectiveOperationException ex) {
MixinConnectorManager.logger.warn("Error loading Mixin Connector [" + connectorClassName + "]", ex);
}
}
this.connectorClasses.clear();
}
void initConnectors() {
@@ -53,6 +53,11 @@ public class MixinPlatformAgentDefault extends MixinPlatformAgentAbstract {
this.manager.addTokenProvider(provider.trim());
}
}
String connectorClass = this.handle.getAttribute(ManifestAttributes.MIXINCONNECTOR);
if (connectorClass != null) {
this.manager.addConnector(connectorClass.trim());
}
}
}
@@ -68,6 +68,12 @@ public class MixinPlatformManager {
*/
private final Map<IContainerHandle, MixinContainer> containers = new LinkedHashMap<IContainerHandle, MixinContainer>();
/**
* Connectors
*/
private final MixinConnectorManager connectors = new MixinConnectorManager();
/**
* Container for this tweaker
*/
@@ -187,6 +193,8 @@ public class MixinPlatformManager {
ex.printStackTrace();
}
}
this.connectors.inject();
}
/**
@@ -280,5 +288,16 @@ public class MixinPlatformManager {
MixinEnvironment.getDefaultEnvironment().registerTokenProviderClass(provider);
}
/**
* Add a mixin connector class for a jar manifest source. Supports only bare
* class names.
*
* @param connectorClass Name of the connector class to load
*/
final void addConnector(String connectorClass) {
this.connectors.addConnector(connectorClass);
}
}
@@ -55,6 +55,7 @@ import org.spongepowered.asm.util.IConsumer;
import org.spongepowered.asm.util.ITokenProvider;
import org.spongepowered.asm.util.JavaVersion;
import org.spongepowered.asm.util.PrettyPrinter;
import org.spongepowered.asm.util.asm.ASM;
import org.spongepowered.asm.util.perf.Profiler;
import com.google.common.collect.ImmutableList;
@@ -700,12 +701,17 @@ public final class MixinEnvironment implements ITokenProvider {
public static final int NESTING = 4;
/**
* Native nesting
* Dynamic constants
*/
public static final int DYNAMIC_CONSTANTS = 8;
}
/**
* Default compatibility level to use if not specified by the service
*/
public static CompatibilityLevel DEFAULT = CompatibilityLevel.JAVA_6;
private final int ver;
private final int classVersion;
@@ -720,11 +726,6 @@ public final class MixinEnvironment implements ITokenProvider {
this.languageFeatures = languageFeatures;
}
@SuppressWarnings("unused")
private void setMaxCompatibleLevel(CompatibilityLevel maxCompatibleLevel) {
this.maxCompatibleLevel = maxCompatibleLevel;
}
/**
* Get whether this compatibility level is supported in the current
* environment
@@ -773,6 +774,16 @@ public final class MixinEnvironment implements ITokenProvider {
return level == null || this.ver >= level.ver;
}
/**
* Get whether this level is less than the specified level
*
* @param level level to compare to
* @return true if this level is less than the supplied level
*/
public boolean isLessThan(CompatibilityLevel level) {
return level == null || this.ver < level.ver;
}
/**
* Get whether this level can be elevated to the specified level
*
@@ -882,7 +893,7 @@ public final class MixinEnvironment implements ITokenProvider {
/**
* Current compatibility level
*/
private static CompatibilityLevel compatibility = Option.DEFAULT_COMPATIBILITY_LEVEL.<CompatibilityLevel>getEnumValue(CompatibilityLevel.JAVA_6);
private static CompatibilityLevel compatibility;
/**
* Show debug header info on first environment construction
@@ -991,7 +1002,9 @@ public final class MixinEnvironment implements ITokenProvider {
printer.add("SpongePowered MIXIN%s", verbose ? " (Verbose debugging enabled)" : "").centre().hr();
printer.kv("Code source", codeSource);
printer.kv("Internal Version", version);
printer.kv("Java Versions Supported", CompatibilityLevel.getSupportedVersions()).hr();
printer.kv("Java Versions Supported", CompatibilityLevel.getSupportedVersions());
printer.kv("Current Compatibility Level", MixinEnvironment.getCompatibilityLevel());
printer.kv("Detected ASM API Version", ASM.getApiVersionString()).hr();
printer.kv("Service Name", serviceName);
printer.kv("Mixin Service Class", this.service.getClass().getName());
printer.kv("Global Property Service Class", MixinService.getGlobalPropertyService().getClass().getName()).hr();
@@ -1368,9 +1381,19 @@ public final class MixinEnvironment implements ITokenProvider {
* Get the current compatibility level
*/
public static CompatibilityLevel getCompatibilityLevel() {
if (MixinEnvironment.compatibility == null) {
CompatibilityLevel minLevel = MixinEnvironment.getMinCompatibilityLevel();
CompatibilityLevel optionLevel = Option.DEFAULT_COMPATIBILITY_LEVEL.<CompatibilityLevel>getEnumValue(minLevel);
MixinEnvironment.compatibility = optionLevel.isAtLeast(minLevel) ? optionLevel : minLevel;
}
return MixinEnvironment.compatibility;
}
private static CompatibilityLevel getMinCompatibilityLevel() {
CompatibilityLevel minLevel = MixinService.getService().getMinCompatibilityLevel();
return minLevel == null ? CompatibilityLevel.DEFAULT : minLevel;
}
/**
* Set desired compatibility level for the entire environment
*
@@ -1385,10 +1408,18 @@ public final class MixinEnvironment implements ITokenProvider {
MixinEnvironment.logger.warn("MixinEnvironment::setCompatibilityLevel is deprecated and will be removed. Set level via config instead!");
}
if (level != MixinEnvironment.compatibility && level.isAtLeast(MixinEnvironment.compatibility)) {
CompatibilityLevel currentLevel = MixinEnvironment.getCompatibilityLevel();
if (level != currentLevel && level.isAtLeast(currentLevel)) {
if (!level.isSupported()) {
throw new IllegalArgumentException("The requested compatibility level " + level + " could not be set. Level is not supported");
}
IMixinService service = MixinService.getService();
CompatibilityLevel maxLevel = service.getMaxCompatibilityLevel();
if (maxLevel != null && maxLevel.isLessThan(level)) {
MixinEnvironment.logger.warn("The requested compatibility level {} is higher than the level supported by the active subsystem '{}'"
+ " which supports {}. This is not a supported configuration and instability may occur.", level, service.getName(), maxLevel);
}
MixinEnvironment.compatibility = level;
MixinEnvironment.logger.info("Compatibility level set to {}", level);
@@ -31,7 +31,7 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
import org.spongepowered.asm.mixin.refmap.IMixinContext;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.asm.ASM;
/**
* Base class for accessor generators
@@ -70,7 +70,7 @@ public abstract class AccessorGenerator {
*/
protected final MethodNode createMethod(int maxLocals, int maxStack) {
MethodNode method = this.info.getMethod();
MethodNode accessor = new MethodNode(Bytecode.ASM_API_VERSION, (method.access & ~Opcodes.ACC_ABSTRACT) | Opcodes.ACC_SYNTHETIC, method.name,
MethodNode accessor = new MethodNode(ASM.API_VERSION, (method.access & ~Opcodes.ACC_ABSTRACT) | Opcodes.ACC_SYNTHETIC, method.name,
method.desc, null, null);
accessor.visibleAnnotations = new ArrayList<AnnotationNode>();
accessor.visibleAnnotations.add(this.info.getAnnotation());
@@ -29,6 +29,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.Map.Entry;
@@ -58,11 +59,13 @@ import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionExceptio
import org.spongepowered.asm.mixin.refmap.IMixinContext;
import org.spongepowered.asm.mixin.struct.SpecialMethodInfo;
import org.spongepowered.asm.mixin.throwables.MixinError;
import org.spongepowered.asm.mixin.throwables.MixinException;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.asm.ASM;
import org.spongepowered.asm.util.asm.ElementNode;
import com.google.common.base.Strings;
@@ -131,6 +134,13 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
InjectionInfo create(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
try {
return this.ctor.newInstance(mixin, method, annotation);
} catch (InvocationTargetException itex) {
Throwable cause = itex.getCause();
if (cause instanceof MixinException) {
throw (MixinException)cause;
}
Throwable ex = cause != null ? cause : itex;
throw new MixinError("Error initialising injector metaclass [" + this.type + "] for annotation " + annotation.desc, ex);
} catch (ReflectiveOperationException ex) {
throw new MixinError("Failed to instantiate injector metaclass [" + this.type + "] for annotation " + annotation.desc, ex);
}
@@ -457,7 +467,7 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
* @return new method
*/
public MethodNode addMethod(int access, String name, String desc) {
MethodNode method = new MethodNode(Bytecode.ASM_API_VERSION, access | Opcodes.ACC_SYNTHETIC, name, desc, null, null);
MethodNode method = new MethodNode(ASM.API_VERSION, access | Opcodes.ACC_SYNTHETIC, name, desc, null, null);
this.injectedMethods.add(method);
return method;
}
@@ -58,6 +58,7 @@ import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinClassNode;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.ClassSignature;
import org.spongepowered.asm.util.Locals;
import org.spongepowered.asm.util.perf.Profiler;
import org.spongepowered.asm.util.perf.Profiler.Section;
@@ -205,17 +206,24 @@ public final class ClassInfo {
* Frame local count
*/
public final int locals;
/**
* Frame local size
*/
public final int size;
FrameData(int index, int type, int locals) {
FrameData(int index, int type, int locals, int size) {
this.index = index;
this.type = type;
this.locals = locals;
this.size = size;
}
FrameData(int index, FrameNode frameNode) {
this.index = index;
this.type = frameNode.type;
this.locals = frameNode.local != null ? frameNode.local.size() : 0;
this.size = Locals.computeFrameSize(frameNode);
}
/* (non-Javadoc)
@@ -42,8 +42,8 @@ import org.spongepowered.asm.mixin.transformer.ext.IClassGenerator;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.service.ISyntheticClassInfo;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.IConsumer;
import org.spongepowered.asm.util.asm.ASM;
/**
* Class generator which creates unique copies of inner classes within mixins
@@ -200,7 +200,7 @@ final class InnerClassGenerator implements IClassGenerator {
private final InnerClassInfo info;
public InnerClassAdapter(ClassVisitor cv, InnerClassInfo info) {
super(Bytecode.ASM_API_VERSION, cv, info);
super(ASM.API_VERSION, cv, info);
this.info = info;
}
@@ -67,6 +67,7 @@ import org.spongepowered.asm.service.IMixinService;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.asm.ASM;
import org.spongepowered.asm.util.CompareUtil;
import org.spongepowered.asm.util.perf.Profiler;
import org.spongepowered.asm.util.perf.Profiler.Section;
@@ -88,7 +89,7 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
private final String originalName;
public MixinMethodNode(int access, String name, String desc, String signature, String[] exceptions) {
super(Bytecode.ASM_API_VERSION, access, name, desc, signature, exceptions);
super(ASM.API_VERSION, access, name, desc, signature, exceptions);
this.originalName = name;
}
@@ -135,7 +136,7 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
public final List<MixinMethodNode> mixinMethods;
MixinClassNode(MixinInfo mixin) {
this(Bytecode.ASM_API_VERSION);
this(ASM.API_VERSION);
}
@SuppressWarnings("unchecked")
@@ -798,7 +799,7 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
} catch (InvalidMixinException ex) {
throw ex;
} catch (Exception ex) {
throw new InvalidMixinException(this, ex);
throw new InvalidMixinException(this, ex.getMessage(), ex);
}
if (!this.type.isLoadable()) {
@@ -29,9 +29,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
@@ -32,8 +32,8 @@ import org.spongepowered.asm.mixin.throwables.MixinException;
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
import org.spongepowered.asm.mixin.transformer.ext.IExtensionRegistry;
import org.spongepowered.asm.transformers.TreeTransformer;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.asm.util.asm.ASM;
/**
* Transformer which manages the mixin configuration and application process
@@ -203,7 +203,7 @@ class MixinTransformer extends TreeTransformer implements IMixinTransformer {
* You need to ask yourself why you're reading this comment
*/
private static ClassNode createEmptyClass(String name) {
ClassNode classNode = new ClassNode(Bytecode.ASM_API_VERSION);
ClassNode classNode = new ClassNode(ASM.API_VERSION);
classNode.name = name.replace('.', '/');
classNode.version = MixinEnvironment.getCompatibilityLevel().classVersion();
classNode.superName = Constants.OBJECT;
@@ -77,7 +77,7 @@ public class ExtensionClassExporter implements IExtension {
try {
MoreFiles.deleteRecursively(this.classExportDir.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
} catch (IOException ex) {
ExtensionClassExporter.logger.warn("Error cleaning class output directory: {}", ex.getMessage());
ExtensionClassExporter.logger.debug("Error cleaning class output directory: {}", ex.getMessage());
}
}
@@ -28,6 +28,7 @@ import java.io.InputStream;
import java.util.Collection;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.util.ReEntranceLock;
@@ -176,5 +177,25 @@ public interface IMixinService {
* Get the detected side name for this environment
*/
public abstract String getSideName();
/**
* Get the minimum compatibility level supported by this service. Can return
* <tt>null</tt> if the service has no specific minimum compatibility level,
* however if a value is returned, it will be used as the minimum
* compatibility level and no lower levels will be supported.
*
* @return minimum supported {@link CompatibilityLevel} or null
*/
public abstract CompatibilityLevel getMinCompatibilityLevel();
/**
* Get the maximum compatibility level supported by this service. Can return
* <tt>null</tt> if the service has no specific maximum compatibility level.
* If a value is returned, a warning will be raised if a configuration
* attempts to se a higher compatibility level.
*
* @return minimum supported {@link CompatibilityLevel} or null
*/
public abstract CompatibilityLevel getMaxCompatibilityLevel();
}
@@ -24,8 +24,10 @@
*/
package org.spongepowered.asm.service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
@@ -33,6 +35,8 @@ import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.common.base.Joiner;
/**
* Provides access to the service layer which connects the mixin transformer to
* a particular host environment. Host environments are implemented as services
@@ -79,15 +83,17 @@ public final class MixinService {
private void runBootServices() {
this.bootstrapServiceLoader = ServiceLoader.<IMixinServiceBootstrap>load(IMixinServiceBootstrap.class, this.getClass().getClassLoader());
for (IMixinServiceBootstrap bootService : this.bootstrapServiceLoader) {
Iterator<IMixinServiceBootstrap> iter = this.bootstrapServiceLoader.iterator();
while (iter.hasNext()) {
try {
IMixinServiceBootstrap bootService = iter.next();
bootService.bootstrap();
this.bootedServices.add(bootService.getServiceClassName());
} catch (ServiceInitialisationException ex) {
// Expected if service cannot start
MixinService.logger.debug("Mixin bootstrap service {} is not available: {}", bootService.getClass().getName(), ex.getMessage());
MixinService.logger.error("Mixin bootstrap service {} is not available: {}", ex.getStackTrace()[0].getClassName(), ex.getMessage());
} catch (Throwable th) {
MixinService.logger.throwing(th);
MixinService.logger.debug("Catching {}:{} initialising service", th.getClass().getName(), th.getMessage(), th);
}
}
}
@@ -124,6 +130,7 @@ public final class MixinService {
private IMixinService initService() {
this.serviceLoader = ServiceLoader.<IMixinService>load(IMixinService.class, this.getClass().getClassLoader());
Iterator<IMixinService> iter = this.serviceLoader.iterator();
List<String> rejectedServices = new ArrayList<String>();
while (iter.hasNext()) {
try {
IMixinService service = iter.next();
@@ -133,13 +140,14 @@ public final class MixinService {
if (service.isValid()) {
return service;
}
rejectedServices.add(service.getName());
} catch (ServiceConfigurationError serviceError) {
// serviceError.printStackTrace();
} catch (Throwable th) {
// th.printStackTrace();
}
}
throw new ServiceNotAvailableError("No mixin host service is available");
throw new ServiceNotAvailableError("No mixin host service is available. Rejected services: " + Joiner.on(", ").join(rejectedServices));
}
/**
@@ -33,6 +33,7 @@ import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.launch.platform.IMixinPlatformAgent;
import org.spongepowered.asm.launch.platform.IMixinPlatformServiceAgent;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.asm.util.IConsumer;
@@ -71,19 +72,50 @@ public abstract class MixinServiceAbstract implements IMixinService {
*/
private String sideName;
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService#prepare()
*/
@Override
public void prepare() {
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService#getInitialPhase()
*/
@Override
public Phase getInitialPhase() {
return Phase.PREINIT;
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService
* #getMinCompatibilityLevel()
*/
@Override
public CompatibilityLevel getMinCompatibilityLevel() {
return null;
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService
* #getMaxCompatibilityLevel()
*/
@Override
public CompatibilityLevel getMaxCompatibilityLevel() {
return null;
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService#beginPhase()
*/
@Override
public void beginPhase() {
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService
* #checkEnv(java.lang.Object)
*/
@Override
public void checkEnv(Object bootSource) {
}
@@ -43,6 +43,7 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.util.CheckClassAdapter;
import org.objectweb.asm.util.TraceClassVisitor;
import org.spongepowered.asm.util.asm.ASM;
import org.spongepowered.asm.util.throwables.SyntheticBridgeException;
import org.spongepowered.asm.util.throwables.SyntheticBridgeException.Problem;
@@ -143,8 +144,6 @@ public final class Bytecode {
return this.isSuper ? "super" : "this";
}
}
public static final int ASM_API_VERSION = Opcodes.ASM6;
/**
* Integer constant opcodes
@@ -390,8 +389,9 @@ public final class Bytecode {
*/
public static void printMethod(MethodNode method) {
System.err.printf("%s%s\n", method.name, method.desc);
int index = 0;
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
System.err.print(" ");
System.err.printf("%-4d ", index++);
Bytecode.printNode(iter.next());
}
}
@@ -1161,7 +1161,6 @@ public final class Bytecode {
dest.sourceDebug = source.sourceDebug;
dest.sourceFile = source.sourceFile;
dest.module = source.module;
dest.outerClass = source.outerClass;
dest.outerMethod = source.outerMethod;
dest.outerMethodDesc = source.outerMethodDesc;
@@ -1175,7 +1174,10 @@ public final class Bytecode {
Bytecode.<InnerClassNode>clear(dest.innerClasses);
Bytecode.<FieldNode>clear(dest.fields);
Bytecode.<MethodNode>clear(dest.methods);
if (ASM.API_VERSION >= Opcodes.ASM6) {
dest.module = source.module;
}
// TODO Java 10
// dest.nestHostClassExperimental = source.nestHostClassExperimental;
@@ -1216,4 +1218,5 @@ public final class Bytecode {
destination.addAll(source);
return destination;
}
}
@@ -39,6 +39,7 @@ import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.signature.SignatureWriter;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.util.asm.ASM;
/**
* Represents an object-oriented view of a generic class signature. We use ASM's
@@ -660,7 +661,7 @@ public class ClassSignature {
abstract class SignatureElement extends SignatureVisitor {
public SignatureElement() {
super(Bytecode.ASM_API_VERSION);
super(ASM.API_VERSION);
}
}
@@ -897,7 +898,7 @@ public class ClassSignature {
private FormalParamElement param;
SignatureParser() {
super(Bytecode.ASM_API_VERSION);
super(ASM.API_VERSION);
}
@Override
@@ -69,6 +69,7 @@ public abstract class Constants {
public static final String MAINCLASS = "Main-Class";
public static final String MIXINCONFIGS = "MixinConfigs";
public static final String TOKENPROVIDERS = "MixinTokenProviders";
public static final String MIXINCONNECTOR = "MixinConnector";
@Deprecated
public static final String COMPATIBILITY = "MixinCompatibilityLevel";
@@ -48,6 +48,7 @@ import org.objectweb.asm.tree.analysis.Frame;
import org.spongepowered.asm.mixin.transformer.ClassInfo;
import org.spongepowered.asm.mixin.transformer.ClassInfo.FrameData;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.util.asm.ASM;
import org.spongepowered.asm.util.asm.MixinVerifier;
import org.spongepowered.asm.util.throwables.LVTGeneratorError;
@@ -56,6 +57,11 @@ import org.spongepowered.asm.util.throwables.LVTGeneratorError;
*/
public final class Locals {
/**
* Frame type names just for the purposes of debug printing
*/
private static final String[] FRAME_TYPES = { "TOP", "INTEGER", "FLOAT", "DOUBLE", "LONG", "NULL", "UNINITIALIZED_THIS" };
/**
* Cached local variable lists, to avoid having to recalculate them
* (expensive) if multiple injectors are working with the same method
@@ -157,24 +163,56 @@ public final class Locals {
}
int initialFrameSize = local;
int frameIndex = -1, locals = 0;
int frameSize = local;
int frameIndex = -1;
int lastFrameSize = local;
VarInsnNode storeInsn = null;
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
AbstractInsnNode insn = iter.next();
if (insn instanceof FrameNode) {
if (storeInsn != null) {
frame[storeInsn.var] = Locals.getLocalVariableAt(classNode, method, insn, storeInsn.var);
storeInsn = null;
}
handleFrame: if (insn instanceof FrameNode) {
frameIndex++;
FrameNode frameNode = (FrameNode)insn;
FrameData frameData = frameIndex < frames.size() ? frames.get(frameIndex) : null;
if (frameNode.type == Opcodes.F_SAME || frameNode.type == Opcodes.F_SAME1) {
break handleFrame;
}
locals = frameData != null && frameData.type == Opcodes.F_FULL ? Math.min(locals, frameData.locals) : frameNode.local.size();
FrameData frameData = frameIndex < frames.size() ? frames.get(frameIndex) : null;
if (frameData != null) {
if (frameData.type == Opcodes.F_FULL) {
frameSize = Math.min(frameSize, frameData.locals);
lastFrameSize = frameSize;
} else {
frameSize = Locals.getAdjustedFrameSize(frameSize, frameData);
}
} else {
frameSize = Locals.getAdjustedFrameSize(frameSize, frameNode);
}
if (frameNode.type == Opcodes.F_CHOP) {
for (int framePos = frameSize; framePos < frame.length; framePos++) {
frame[framePos] = null;
}
lastFrameSize = frameSize;
break handleFrame;
}
int framePos = frameNode.type == Opcodes.F_APPEND ? lastFrameSize : 0;
lastFrameSize = frameSize;
// localPos tracks the location in the frame node's locals list, which doesn't leave space for TOP entries
for (int localPos = 0, framePos = 0; framePos < frame.length; framePos++, localPos++) {
for (int localPos = 0; framePos < frame.length; framePos++, localPos++) {
// Get the local at the current position in the FrameNode's locals list
final Object localType = (localPos < frameNode.local.size()) ? frameNode.local.get(localPos) : null;
if (localType instanceof String) { // String refers to a reference type
frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos);
frame[framePos] = Locals.getLocalVariableAt(classNode, method, insn, framePos);
} else if (localType instanceof Integer) { // Integer refers to a primitive type or other marker
boolean isMarkerType = localType == Opcodes.UNINITIALIZED_THIS || localType == Opcodes.NULL;
boolean is32bitValue = localType == Opcodes.INTEGER || localType == Opcodes.FLOAT;
@@ -184,8 +222,8 @@ public final class Locals {
} else if (isMarkerType) {
frame[framePos] = null;
} else if (is32bitValue || is64bitValue) {
frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos);
frame[framePos] = Locals.getLocalVariableAt(classNode, method, insn, framePos);
if (is64bitValue) {
framePos++;
frame[framePos] = null; // TOP
@@ -195,9 +233,11 @@ public final class Locals {
+ " in " + classNode.name + "." + method.name + method.desc);
}
} else if (localType == null) {
if (framePos >= initialFrameSize && framePos >= locals && locals > 0) {
if (framePos >= initialFrameSize && framePos >= frameSize && frameSize > 0) {
frame[framePos] = null;
}
} else if (localType instanceof LabelNode) {
// Uninitialised
} else {
throw new LVTGeneratorError("Invalid value " + localType + " in locals array at position " + localPos
+ " in " + classNode.name + "." + method.name + method.desc);
@@ -205,8 +245,16 @@ public final class Locals {
}
} else if (insn instanceof VarInsnNode) {
VarInsnNode varNode = (VarInsnNode) insn;
frame[varNode.var] = Locals.getLocalVariableAt(classNode, method, node, varNode.var);
}
boolean isLoad = insn.getOpcode() >= Opcodes.ILOAD && insn.getOpcode() <= Opcodes.SALOAD;
if (isLoad) {
frame[varNode.var] = Locals.getLocalVariableAt(classNode, method, insn, varNode.var);
} else {
// Update the LVT for the opcode AFTER this one, since we always want to know
// the frame state BEFORE the *current* instruction to match the contract of
// injection points
storeInsn = varNode;
}
}
if (insn == node) {
break;
@@ -223,7 +271,7 @@ public final class Locals {
return frame;
}
/**
/**
* Attempts to locate the appropriate entry in the local variable table for
* the specified local variable index at the location specified by node.
*
@@ -277,7 +325,7 @@ public final class Locals {
}
private static boolean isOpcodeInRange(InsnList insns, LocalVariableNode local, int pos) {
return insns.indexOf(local.start) < pos && insns.indexOf(local.end) > pos;
return insns.indexOf(local.start) <= pos && insns.indexOf(local.end) > pos;
}
/**
@@ -341,7 +389,7 @@ public final class Locals {
// Use Analyzer to generate the bytecode frames
Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(
new MixinVerifier(Bytecode.ASM_API_VERSION, Type.getObjectType(classNode.name), objectType, interfaces, false));
new MixinVerifier(ASM.API_VERSION, Type.getObjectType(classNode.name), objectType, interfaces, false));
try {
analyzer.analyze(classNode.name, method);
} catch (AnalyzerException ex) {
@@ -449,5 +497,108 @@ public final class Locals {
}
return insn;
}
/**
* Compute a new frame size based on the supplied frame type and the size of
* locals contained in the frame (this may differ from the number of actual
* frame slots if the frame contains doubles or longs)
*
* @param currentSize current frame size
* @param frameNode frame entry
* @return new frame size
*/
private static int getAdjustedFrameSize(int currentSize, FrameNode frameNode) {
return Locals.getAdjustedFrameSize(currentSize, frameNode.type, Locals.computeFrameSize(frameNode));
}
/**
* Compute a new frame size based on the supplied frame type and the size of
* locals contained in the frame (this may differ from the number of actual
* frame slots if the frame contains doubles or longs)
*
* @param currentSize current frame size
* @param frameData frame entry
* @return new frame size
*/
private static int getAdjustedFrameSize(int currentSize, FrameData frameData) {
return Locals.getAdjustedFrameSize(currentSize, frameData.type, frameData.size);
}
/**
* Compute a new frame size based on the supplied frame type and the size of
* locals contained in the frame (this may differ from the number of actual
* frame slots if the frame contains doubles or longs)
*
* @param currentSize current frame size
* @param type frame entry type
* @param size frame entry size
* @return new frame size
*/
private static int getAdjustedFrameSize(int currentSize, int type, int size) {
switch (type) {
case Opcodes.F_NEW:
case Opcodes.F_FULL:
return size;
case Opcodes.F_APPEND:
return currentSize + size;
case Opcodes.F_CHOP:
return currentSize - size;
case Opcodes.F_SAME:
case Opcodes.F_SAME1:
return currentSize;
default:
return currentSize;
}
}
/**
* Compute the size required to accomodate the entries described by the
* supplied frame node
*
* @param frameNode frame node with locals to compute
* @return size of frame node locals
*/
public static int computeFrameSize(FrameNode frameNode) {
if (frameNode.local == null) {
return 0;
}
int size = 0;
for (Object local : frameNode.local) {
if (local instanceof Integer) {
size += (local == Opcodes.DOUBLE || local == Opcodes.LONG) ? 2 : 1;
} else {
size++;
}
}
return size;
}
/**
* Debug function to return printable name of a frame entry
*
* @param frameEntry Frame entry
* @return string representation of the supplied frame entry
*/
public static String getFrameTypeName(Object frameEntry) {
if (frameEntry == null) {
return "NULL";
}
if (frameEntry instanceof String) {
return Bytecode.getSimpleName(frameEntry.toString());
}
if (frameEntry instanceof Integer) {
int type = ((Integer)frameEntry).intValue();
if (type >= Locals.FRAME_TYPES.length) {
return "INVALID";
}
return Locals.FRAME_TYPES[type];
}
return "?";
}
}
@@ -0,0 +1,89 @@
/*
* 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.util.asm;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
/**
* Utility methods for determining ASM version and other version-specific
* shenanigans
*/
public final class ASM {
@SuppressWarnings("deprecation")
private static final int[] EXPERIMENTAL_VERSIONS = { Opcodes.ASM7_EXPERIMENTAL };
private static final int[] SUPPORTED_VERSIONS = { Opcodes.ASM6, Opcodes.ASM5 };
public static final int API_VERSION = ASM.detectVersion();
private static boolean experimental;
private ASM() {
}
/**
* Get the ASM API version as a string (mostly for debugging and the banner)
*
* @return
*/
public static String getApiVersionString() {
String suffix = "";
if (ASM.experimental) {
int version = ASM.detectVersion(ASM.SUPPORTED_VERSIONS);
suffix = String.format("-EXPERIMENTAL (%d.%d)", ((0xFF0000 & version) >> 16), ((0xFF00 & version) >> 8));
}
return String.format("ASM %d.%d%s", ((0xFF0000 & ASM.API_VERSION) >> 16), ((0xFF00 & ASM.API_VERSION) >> 8), suffix);
}
private static int detectVersion() {
int expVersion = ASM.detectVersion(ASM.EXPERIMENTAL_VERSIONS);
if (expVersion > 0) {
ASM.experimental = true;
return expVersion;
}
ASM.experimental = false;
int version = ASM.detectVersion(ASM.SUPPORTED_VERSIONS);
if (version > 0) {
return version;
}
return Opcodes.ASM5;
}
private static int detectVersion(int[] versions) {
for (int version : versions) {
try {
new ClassNode(version).hashCode();
return version;
} catch (IllegalArgumentException ex) {
// expected, this version is not supported
}
}
return 0;
}
}
@@ -34,7 +34,7 @@ import org.spongepowered.asm.util.Bytecode;
public class MethodVisitorEx extends MethodVisitor {
public MethodVisitorEx(MethodVisitor mv) {
super(Bytecode.ASM_API_VERSION, mv);
super(ASM.API_VERSION, mv);
}
/**