Commit 22d58967 authored by Lubomir Bulej's avatar Lubomir Bulej

Use the Access enum where approriate instead of Opcodes.ACC_

parent 21219395
package ch.usi.dag.disl;
import ch.usi.dag.disl.AsmHelper.Insns;
import ch.usi.dag.disl.annotation.SyntheticLocal;
import ch.usi.dag.disl.annotation.SyntheticLocal.Initialize;
import ch.usi.dag.disl.annotation.ThreadLocal;
import ch.usi.dag.util.logging.Logger;
import static ch.usi.dag.disl.AbstractLocalVar.fqFieldNameFor;
import static ch.usi.dag.util.asm.Access.STATIC;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.IntInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.objectweb.asm.tree.analysis.Frame;
import org.objectweb.asm.tree.analysis.SourceValue;
import java.util.*;
import ch.usi.dag.disl.AsmHelper.Insns;
import ch.usi.dag.disl.annotation.SyntheticLocal;
import ch.usi.dag.disl.annotation.SyntheticLocal.Initialize;
import ch.usi.dag.disl.annotation.ThreadLocal;
import ch.usi.dag.util.logging.Logger;
/**
* Parses DiSL class with local variables.
......@@ -126,10 +145,10 @@ abstract class AbstractParser {
final AnnotationNode annotation
) throws ParserException {
//
// Ensure that the thread local field is declared static
// Ensure that the @ThreadLocal field is declared static
// and parse the annotation data.
//
if ((field.access & Opcodes.ACC_STATIC) == 0) {
if (STATIC.isNotSet (field.access)) {
throw new ParserException("Field " + className + "." + field.name
+ " declared as ThreadLocal but is not static");
}
......@@ -164,11 +183,11 @@ abstract class AbstractParser {
final AnnotationNode annotation
) throws ParserException {
//
// Ensure that the synthetic local field is declared static, parse
// Ensure that the @SyntheticLocal field is declared static, parse
// annotation data and determine the initialization mode for the
// variable.
//
if ((field.access & Opcodes.ACC_STATIC) == 0) {
if (STATIC.isNotSet (field.access)) {
throw new ParserException("Field " + field.name + className
+ "." + " declared as SyntheticLocal but is not static");
}
......@@ -222,9 +241,9 @@ abstract class AbstractParser {
//
// Skip accesses to fields that are not synthetic locals.
//
final SyntheticLocalVar slv = slvs.get (SyntheticLocalVar.fqFieldNameFor (
lastInitInsn.owner, lastInitInsn.name
));
final SyntheticLocalVar slv = slvs.get (
fqFieldNameFor (lastInitInsn.owner, lastInitInsn.name)
);
if (slv == null) {
// RFC LB: Advance firstInitInsn here as well?
continue;
......@@ -298,9 +317,9 @@ abstract class AbstractParser {
//
// Skip accesses to fields that are not thread locals.
//
final ThreadLocalVar tlv = tlvs.get (ThreadLocalVar.fqFieldNameFor (
className, fieldInsn.name
));
final ThreadLocalVar tlv = tlvs.get (
fqFieldNameFor (className, fieldInsn.name)
);
if (tlv == null) {
continue;
}
......@@ -424,7 +443,7 @@ abstract class AbstractParser {
static void ensureMethodIsStatic (
final MethodNode method
) throws ParserException {
if ((method.access & Opcodes.ACC_STATIC) == 0) {
if (STATIC.isNotSet (method.access)) {
throw new ParserException ("method must be declared static!");
}
}
......
package ch.usi.dag.disl.staticcontext;
import static ch.usi.dag.util.asm.Access.ABSTRACT;
import static ch.usi.dag.util.asm.Access.ANNOTATION;
import static ch.usi.dag.util.asm.Access.ENUM;
import static ch.usi.dag.util.asm.Access.FINAL;
import static ch.usi.dag.util.asm.Access.INTERFACE;
import static ch.usi.dag.util.asm.Access.PRIVATE;
import static ch.usi.dag.util.asm.Access.PROTECTED;
import static ch.usi.dag.util.asm.Access.PUBLIC;
import static ch.usi.dag.util.asm.Access.SYNTHETIC;
import ch.usi.dag.disl.JavaNames;
import org.objectweb.asm.Opcodes;
import ch.usi.dag.util.asm.Access;
/**
......@@ -103,7 +114,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is abstract.
*/
public boolean isAbstract () {
return __classAccessFlag (Opcodes.ACC_ABSTRACT);
return __classAccessFlag (ABSTRACT);
}
......@@ -111,7 +122,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is an annotation.
*/
public boolean isAnnotation () {
return __classAccessFlag (Opcodes.ACC_ANNOTATION);
return __classAccessFlag (ANNOTATION);
}
......@@ -119,7 +130,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is an enum.
*/
public boolean isEnum () {
return __classAccessFlag (Opcodes.ACC_ENUM);
return __classAccessFlag (ENUM);
}
......@@ -127,7 +138,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is final.
*/
public boolean isFinal () {
return __classAccessFlag (Opcodes.ACC_FINAL);
return __classAccessFlag (FINAL);
}
......@@ -135,7 +146,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is an interface.
*/
public boolean isInterface () {
return __classAccessFlag (Opcodes.ACC_INTERFACE);
return __classAccessFlag (INTERFACE);
}
......@@ -143,7 +154,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is private.
*/
public boolean isPrivate () {
return __classAccessFlag (Opcodes.ACC_PRIVATE);
return __classAccessFlag (PRIVATE);
}
......@@ -151,7 +162,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is protected.
*/
public boolean isProtected () {
return __classAccessFlag (Opcodes.ACC_PROTECTED);
return __classAccessFlag (PROTECTED);
}
......@@ -159,7 +170,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is public.
*/
public boolean isPublic () {
return __classAccessFlag (Opcodes.ACC_PUBLIC);
return __classAccessFlag (PUBLIC);
}
......@@ -167,7 +178,7 @@ public class ClassStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented class is synthetic.
*/
public boolean isSynthetic () {
return __classAccessFlag (Opcodes.ACC_SYNTHETIC);
return __classAccessFlag (SYNTHETIC);
}
//
......@@ -177,9 +188,8 @@ public class ClassStaticContext extends AbstractStaticContext {
}
private boolean __classAccessFlag (final int flagMask) {
final int access = staticContextData.getClassNode ().access;
return (access & flagMask) != 0;
private boolean __classAccessFlag (final Access access) {
return access.isSet (staticContextData.getClassNode ().access);
}
}
package ch.usi.dag.disl.staticcontext;
import ch.usi.dag.disl.JavaNames;
import org.objectweb.asm.Opcodes;
import static ch.usi.dag.util.asm.Access.ABSTRACT;
import static ch.usi.dag.util.asm.Access.ANNOTATION;
import static ch.usi.dag.util.asm.Access.BRIDGE;
import static ch.usi.dag.util.asm.Access.ENUM;
import static ch.usi.dag.util.asm.Access.FINAL;
import static ch.usi.dag.util.asm.Access.INTERFACE;
import static ch.usi.dag.util.asm.Access.PRIVATE;
import static ch.usi.dag.util.asm.Access.PROTECTED;
import static ch.usi.dag.util.asm.Access.PUBLIC;
import static ch.usi.dag.util.asm.Access.STATIC;
import static ch.usi.dag.util.asm.Access.SYNCHRONIZED;
import static ch.usi.dag.util.asm.Access.VARARGS;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.JavaNames;
import ch.usi.dag.util.asm.Access;
/**
* Provides method related static context information for the method being
......@@ -149,7 +164,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassAbstract () {
return __classAccessFlag (Opcodes.ACC_ABSTRACT);
return __classAccessFlag (ABSTRACT);
}
......@@ -161,7 +176,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassAnnotation () {
return __classAccessFlag (Opcodes.ACC_ANNOTATION);
return __classAccessFlag (ANNOTATION);
}
......@@ -173,7 +188,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassEnum () {
return __classAccessFlag (Opcodes.ACC_ENUM);
return __classAccessFlag (ENUM);
}
......@@ -185,7 +200,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassFinal () {
return __classAccessFlag (Opcodes.ACC_FINAL);
return __classAccessFlag (FINAL);
}
......@@ -197,7 +212,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassInterface () {
return __classAccessFlag (Opcodes.ACC_INTERFACE);
return __classAccessFlag (INTERFACE);
}
......@@ -209,7 +224,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassPrivate () {
return __classAccessFlag (Opcodes.ACC_PRIVATE);
return __classAccessFlag (PRIVATE);
}
......@@ -221,7 +236,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassProtected () {
return __classAccessFlag (Opcodes.ACC_PROTECTED);
return __classAccessFlag (PROTECTED);
}
......@@ -233,7 +248,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassPublic () {
return __classAccessFlag (Opcodes.ACC_PUBLIC);
return __classAccessFlag (PUBLIC);
}
......@@ -245,7 +260,7 @@ public class MethodStaticContext extends AbstractStaticContext {
*/
@Deprecated
public boolean isClassSynthetic () {
return __classAccessFlag (Opcodes.ACC_SYNTHETIC);
return __classAccessFlag (Access.SYNTHETIC);
}
......@@ -320,7 +335,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented method is a bridge.
*/
public boolean isMethodBridge () {
return __methodAccessFlag (Opcodes.ACC_BRIDGE);
return __methodAccessFlag (BRIDGE);
}
......@@ -328,7 +343,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented method is final.
*/
public boolean isMethodFinal () {
return __methodAccessFlag (Opcodes.ACC_FINAL);
return __methodAccessFlag (FINAL);
}
......@@ -336,7 +351,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented method is private.
*/
public boolean isMethodPrivate () {
return __methodAccessFlag (Opcodes.ACC_PRIVATE);
return __methodAccessFlag (PRIVATE);
}
......@@ -344,7 +359,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented method is protected.
*/
public boolean isMethodProtected () {
return __methodAccessFlag (Opcodes.ACC_PROTECTED);
return __methodAccessFlag (PROTECTED);
}
......@@ -352,7 +367,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented method is public.
*/
public boolean isMethodPublic () {
return __methodAccessFlag (Opcodes.ACC_PUBLIC);
return __methodAccessFlag (PUBLIC);
}
......@@ -360,7 +375,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented method is static.
*/
public boolean isMethodStatic () {
return __methodAccessFlag (Opcodes.ACC_STATIC);
return __methodAccessFlag (STATIC);
}
......@@ -368,7 +383,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* Returns {@code true} if the instrumented method is synchronized.
*/
public boolean isMethodSynchronized () {
return __methodAccessFlag (Opcodes.ACC_SYNCHRONIZED);
return __methodAccessFlag (SYNCHRONIZED);
}
......@@ -377,7 +392,7 @@ public class MethodStaticContext extends AbstractStaticContext {
* of arguments.
*/
public boolean isMethodVarArgs () {
return __methodAccessFlag (Opcodes.ACC_VARARGS);
return __methodAccessFlag (VARARGS);
}
......@@ -388,9 +403,8 @@ public class MethodStaticContext extends AbstractStaticContext {
}
private boolean __classAccessFlag (final int flagMask) {
final int access = __classNode ().access;
return (access & flagMask) != 0;
private boolean __classAccessFlag (final Access access) {
return access.isSet (__classNode ().access);
}
......@@ -409,9 +423,8 @@ public class MethodStaticContext extends AbstractStaticContext {
}
private boolean __methodAccessFlag (final int flagMask) {
final int access = __methodNode ().access;
return (access & flagMask) != 0;
private boolean __methodAccessFlag (final Access access) {
return access.isSet (__methodNode ().access);
}
}
package ch.usi.dag.disl;
import static ch.usi.dag.util.asm.Access.STATIC;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.AbstractList;
......@@ -424,9 +426,7 @@ public abstract class AsmHelper {
throw new DiSLFatalException ("parameter index out of bounds");
}
final boolean isStatic = (method.access & Opcodes.ACC_STATIC) != 0;
int slot = isStatic ? 0 : 1;
int slot = STATIC.isSet (method.access) ? 0 : 1;
for (int i = 0; i < paramIndex; i++) {
// add number of occupied slots
slot += paramTypes [i].getSize ();
......@@ -442,9 +442,7 @@ public abstract class AsmHelper {
*/
static int getParameterSlotCount (final MethodNode method) {
final Type [] types = Type.getArgumentTypes (method.desc);
final boolean isStatic = (method.access & Opcodes.ACC_STATIC) != 0;
int result = isStatic ? 0 : 1;
int result = STATIC.isSet (method.access) ? 0 : 1;
for (final Type type : types) {
result += type.getSize ();
}
......
......@@ -5,6 +5,8 @@ import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import static ch.usi.dag.util.asm.Access.STATIC;
import java.util.List;
public class MaxCalculator {
......@@ -37,7 +39,7 @@ public class MaxCalculator {
int maxLocals = (Type.getArgumentsAndReturnSizes(desc) >> 2);
if ((access & Opcodes.ACC_STATIC) != 0) {
if (STATIC.isSet (access)) {
--maxLocals;
}
......
package ch.usi.dag.disl;
import static ch.usi.dag.util.asm.Access.STATIC;
import java.util.List;
import java.util.Set;
......@@ -233,9 +235,10 @@ public class WeavingCode {
//
// Ensure getThis() returns null in static methods.
final boolean isStatic = (method.access & Opcodes.ACC_STATIC) != 0;
insns.insert (invokeInsn,
isStatic ? AsmHelper.loadNull () : AsmHelper.loadThis ()
STATIC.isSet (method.access) ?
AsmHelper.loadNull () :
AsmHelper.loadThis ()
);
// Remove the invocation sequence.
......@@ -1053,8 +1056,6 @@ public class WeavingCode {
// Handle individual methods.
//
final String methodName = invokeInsn.name;
final boolean isStatic = (method.access & Opcodes.ACC_STATIC) != 0;
if ("getArgs".equals (methodName)) {
//
// ALOAD (ArgumentProcessorContext reference)
......@@ -1069,7 +1070,7 @@ public class WeavingCode {
InsnList getArgsInsns = null;
if (mode == ArgumentProcessorMode.METHOD_ARGS) {
final int thisOffset = isStatic ? 0 : 1;
final int thisOffset = STATIC.isSet (method.access) ? 0 : 1;
final int firstSlot = thisOffset - method.maxLocals;
getArgsInsns = __createGetArgsCode (method.desc, firstSlot);
......@@ -1148,8 +1149,9 @@ public class WeavingCode {
if (mode == ArgumentProcessorMode.METHOD_ARGS) {
// Return null as receiver for static methods.
insns.insert (invokeInsn,
isStatic ? AsmHelper.loadNull ()
: AsmHelper.loadObjectVar (-method.maxLocals)
STATIC.isSet (method.access) ?
AsmHelper.loadNull () :
AsmHelper.loadObjectVar (-method.maxLocals)
);
} else if (mode == ArgumentProcessorMode.CALLSITE_ARGS) {
......
......@@ -69,6 +69,10 @@ public enum Access {
return (access & __flag) != 0;
}
public boolean isNotSet (final int access) {
return (access & __flag) == 0;
}
public String keyword (final int access) {
if ((access & __flag) == 0) {
return null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment