List of usage examples for org.objectweb.asm Opcodes ACC_INTERFACE
int ACC_INTERFACE
To view the source code for org.objectweb.asm Opcodes ACC_INTERFACE.
Click Source Link
From source file:ch.eiafr.cojac.ModifiedClassWriter.java
License:Apache License
@Override protected String getCommonSuperClass(final String type1, final String type2) { try {/*from w w w .ja va 2 s . c o m*/ ClassReader info1 = typeInfo(type1); ClassReader info2 = typeInfo(type2); if ((info1.getAccess() & Opcodes.ACC_INTERFACE) != 0) { if (typeImplements(type2, info2, type1)) { return type1; } else { return "java/lang/Object"; } } if ((info2.getAccess() & Opcodes.ACC_INTERFACE) != 0) { if (typeImplements(type1, info1, type2)) { return type2; } else { return "java/lang/Object"; } } StringBuilder b1 = typeAncestors(type1, info1); StringBuilder b2 = typeAncestors(type2, info2); String result = "java/lang/Object"; int end1 = b1.length(); int end2 = b2.length(); while (true) { int start1 = b1.lastIndexOf(";", end1 - 1); int start2 = b2.lastIndexOf(";", end2 - 1); if (start1 != -1 && start2 != -1 && end1 - start1 == end2 - start2) { String p1 = b1.substring(start1 + 1, end1); String p2 = b2.substring(start2 + 1, end2); if (p1.equals(p2)) { result = p1; end1 = start1; end2 = start2; } else { return result; } } else { return result; } } } catch (IOException e) { throw new RuntimeException(e.toString() + " (cojac info added: " + type1 + " or " + type2 + ")"); } }
From source file:cl.inria.stiq.instrumenter.BCIUtils.java
License:Open Source License
public static boolean isInterface(int access) { return (access & Opcodes.ACC_INTERFACE) != 0; }
From source file:Client.JClassPatcher.java
License:Open Source License
private String decodeAccess(int access) { String res = ""; if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) res += "public "; if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) res += "private "; if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) res += "protected "; if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) res += "static "; if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) res += "final "; if ((access & Opcodes.ACC_VOLATILE) == Opcodes.ACC_VOLATILE) res += "protected "; if ((access & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED) res += "synchronized "; if ((access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) res += "abstract "; if ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE) res += "interface "; return res;/* www . j a v a2s . com*/ }
From source file:co.paralleluniverse.fibers.instrument.CheckInstrumentationVisitor.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from w ww .ja v a 2s. co m this.className = name; this.isInterface = (access & Opcodes.ACC_INTERFACE) != 0; this.classEntry = new ClassEntry(superName); classEntry.setInterfaces(interfaces); }
From source file:co.paralleluniverse.fibers.instrument.InstrumentClass.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {/*from w ww . ja v a2s . c o m*/ this.className = name; this.isInterface = (access & Opcodes.ACC_INTERFACE) != 0; this.classEntry = db.getOrCreateClassEntry(className, superName); classEntry.setInterfaces(interfaces); this.forceInstrumentation |= classEntry.requiresInstrumentation(); // need atleast 1.5 for annotations to work if (version < Opcodes.V1_5) version = Opcodes.V1_5; // When Java allows adding interfaces in retransformation, we can mark the class with an interface, which makes checking whether it's instrumented faster (with instanceof) // if(classEntry.requiresInstrumentation() && !contains(interfaces, SUSPENDABLE_NAME)) { // System.out.println("XX: Marking " + className + " as " + SUSPENDABLE_NAME); // interfaces = add(interfaces, SUSPENDABLE_NAME); // } super.visit(version, access, name, signature, superName, interfaces); }
From source file:com.alibaba.hotswap.processor.basic.BaseClassVisitor.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from w w w . j a v a 2 s . c o m this.className = name; this.isInterface = ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE); super.visit(version, access, name, signature, superName, interfaces); }
From source file:com.alibaba.hotswap.processor.clinit.ClinitVisitor.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {/*from w ww .j a v a 2 s. co m*/ super.visit(version, access, name, signature, superName, interfaces); isInterface = ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE); }
From source file:com.alibaba.hotswap.processor.field.holder.FieldHolderVisitor.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {// w w w . j av a2 s. c o m super.visit(version, access, name, signature, superName, interfaces); if ((access & Opcodes.ACC_INTERFACE) == 0) { addFieldHolder(); addStaticFieldHolder(); } }
From source file:com.alibaba.hotswap.processor.v.VClassGenerateVisitor.java
License:Open Source License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from ww w . jav a 2s .c om HotswapThreadLocalUtil.setClassName(name); super.visit(version, access, name, signature, superName, interfaces); boolean isInterface = ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE); if (isInterface && (access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) { // If it is a interface, then transformer it to class access = access - Opcodes.ACC_INTERFACE; } ClassMeta classMeta = HotswapRuntime.getClassMeta(className); classMeta.isInterface = isInterface; if (!classMeta.isLoaded()) { // First load for (String key : classMeta.primaryFieldKeyList) { classMeta.primaryFieldNodes.get(key).accept(cv); } } else { // Reload Map<String, FieldNode> loadedFieldNodes = new HashMap<String, FieldNode>(); loadedFieldNodes.putAll(classMeta.loadedFieldNodes); // 1. Visit the primary fields. for (String key : classMeta.primaryFieldKeyList) { FieldNode primaryFN = classMeta.primaryFieldNodes.get(key); FieldNode loadedFN = loadedFieldNodes.get(key); if (loadedFN != null) { if (loadedFN.access == primaryFN.access) { // Primary field(may change annotation/signature) or change from other field loadedFN.accept(cv); loadedFieldNodes.remove(key); } else { primaryFN.accept(cv); } } else { primaryFN.accept(cv); } } // 2. Add and remove modified field. for (FieldNode fn : loadedFieldNodes.values()) { // All these fields are the reloaded class's fields String fieldKey = HotswapFieldUtil.getFieldKey(fn.name, fn.desc); FieldMeta fm2 = classMeta.getFieldMeta(fieldKey); if (fm2 == null) { // This is a new field fn.accept(cv); } else { if (classMeta.primaryFieldKeyList.contains(fieldKey)) { // It's a primary field if (fn.access == fm2.access) { } else { // Modified field, alias it fn.name = HotswapConstants.PREFIX_FIELD_ALIAS + fn.name; fn.accept(cv); } } else { fn.accept(cv); } } } } }
From source file:com.android.build.gradle.internal.incremental.IncrementalVisitor.java
License:Apache License
@Nullable public static File instrumentClass(int targetApiLevel, @NonNull File inputRootDirectory, @NonNull File inputFile, @NonNull File outputDirectory, @NonNull VisitorBuilder visitorBuilder, @NonNull ILogger logger) throws IOException { byte[] classBytes; String path = FileUtils.relativePath(inputFile, inputRootDirectory); // if the class is not eligible for IR, return the non instrumented version or null if // the override class is requested. if (!isClassEligibleForInstantRun(inputFile)) { if (visitorBuilder.getOutputType() == OutputType.INSTRUMENT) { File outputFile = new File(outputDirectory, path); Files.createParentDirs(outputFile); Files.copy(inputFile, outputFile); return outputFile; } else {//from ww w.j a v a 2 s . com return null; } } classBytes = Files.toByteArray(inputFile); ClassReader classReader = new ClassReader(classBytes); // override the getCommonSuperClass to use the thread context class loader instead of // the system classloader. This is useful as ASM needs to load classes from the project // which the system classloader does not have visibility upon. // TODO: investigate if there is not a simpler way than overriding. ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES) { @Override protected String getCommonSuperClass(final String type1, final String type2) { Class<?> c, d; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { c = Class.forName(type1.replace('/', '.'), false, classLoader); d = Class.forName(type2.replace('/', '.'), false, classLoader); } catch (ClassNotFoundException e) { // This may happen if we're processing class files which reference APIs not // available on the target device. In this case return a dummy value, since this // is ignored during dx compilation. return "instant/run/NoCommonSuperClass"; } catch (Exception e) { throw new RuntimeException(e); } if (c.isAssignableFrom(d)) { return type1; } if (d.isAssignableFrom(c)) { return type2; } if (c.isInterface() || d.isInterface()) { return "java/lang/Object"; } else { do { c = c.getSuperclass(); } while (!c.isAssignableFrom(d)); return c.getName().replace('.', '/'); } } }; ClassNode classNode = AsmUtils.readClass(classReader); // when dealing with interface, we just copy the inputFile over without any changes unless // this is a package private interface. AccessRight accessRight = AccessRight.fromNodeAccess(classNode.access); File outputFile = new File(outputDirectory, path); if ((classNode.access & Opcodes.ACC_INTERFACE) != 0) { if (visitorBuilder.getOutputType() == OutputType.INSTRUMENT) { // don't change the name of interfaces. Files.createParentDirs(outputFile); if (accessRight == AccessRight.PACKAGE_PRIVATE) { classNode.access = classNode.access | Opcodes.ACC_PUBLIC; classNode.accept(classWriter); Files.write(classWriter.toByteArray(), outputFile); } else { // just copy the input file over, no change. Files.write(classBytes, outputFile); } return outputFile; } else { return null; } } AsmUtils.DirectoryBasedClassReader directoryClassReader = new AsmUtils.DirectoryBasedClassReader( getBinaryFolder(inputFile, classNode)); // if we are targeting a more recent version than the current device, disable instant run // for that class. List<ClassNode> parentsNodes = isClassTargetingNewerPlatform(targetApiLevel, TARGET_API_TYPE, directoryClassReader, classNode, logger) ? ImmutableList.of() : AsmUtils.parseParents(logger, directoryClassReader, classNode, targetApiLevel); // if we could not determine the parent hierarchy, disable instant run. if (parentsNodes.isEmpty() || isPackageInstantRunDisabled(inputFile)) { if (visitorBuilder.getOutputType() == OutputType.INSTRUMENT) { Files.createParentDirs(outputFile); Files.write(classBytes, outputFile); return outputFile; } else { return null; } } outputFile = new File(outputDirectory, visitorBuilder.getMangledRelativeClassFilePath(path)); Files.createParentDirs(outputFile); IncrementalVisitor visitor = visitorBuilder.build(classNode, parentsNodes, classWriter, logger); if (visitorBuilder.getOutputType() == OutputType.INSTRUMENT) { /* * Classes that do not have a serial version unique identifier, will be updated to * contain one. This is accomplished by using the {@link SerialVersionUIDAdder} class * visitor that is added when this visitor is created (see the constructor). This way, * the serialVersionUID is the same for instrumented and non-instrumented classes. All * classes will have a serialVersionUID, so if some of the classes that is extended * starts implementing {@link java.io.Serializable}, serialization and deserialization * will continue to work correctly. */ classNode.accept(new SerialVersionUIDAdder(visitor)); } else { classNode.accept(visitor); } Files.write(classWriter.toByteArray(), outputFile); return outputFile; }