List of usage examples for org.objectweb.asm ClassReader getAccess
public int getAccess()
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. j a v a2 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:ch.puzzle.modjprof.instrumentation.InstrumentationClassFileTransformer.java
@Override public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { // do not instrument yourself if (!className.startsWith("ch/puzzle/modjprof")) { for (String packageToInstrument : config.getPackagesToInstrument()) { if (className.startsWith(packageToInstrument.replaceAll("\\.", "/"))) { try { ClassReader classReader = new ClassReader(classfileBuffer); // do not instrument interfaces, enums and annotations if ((classReader.getAccess() & (ACC_INTERFACE + ACC_ENUM + ACC_ANNOTATION)) == 0) { LOGGER.fine("instrumenting class " + className); ClassWriter classWriter = new AgentClassWriter(classReader, COMPUTE_FRAMES, loader); ClassVisitor classVisitor = new MethodSelectorClassVisitor(classWriter, className); classReader.accept(classVisitor, 0); return classWriter.toByteArray(); }/* www . j a va2 s . com*/ } catch (Throwable e) { e.printStackTrace(); } return classfileBuffer; } } } return classfileBuffer; }
From source file:com.develorium.metracer.asm.MetracerClassWriter.java
License:Apache License
protected String getCommonSuperClass(String theType1, String theType2) { try {//from ww w . j a v a 2 s .c o m ClassReader info1 = typeInfo(theType1); ClassReader info2 = typeInfo(theType2); if ((info1.getAccess() & Opcodes.ACC_INTERFACE) != 0) { if (typeImplements(theType2, info2, theType1)) { return theType1; } if ((info2.getAccess() & Opcodes.ACC_INTERFACE) != 0) { if (typeImplements(theType1, info1, theType2)) { return theType2; } } return "java/lang/Object"; } if ((info2.getAccess() & Opcodes.ACC_INTERFACE) != 0) { if (typeImplements(theType1, info1, theType2)) { return theType2; } else { return "java/lang/Object"; } } StringBuilder b1 = typeAncestors(theType1, info1); StringBuilder b2 = typeAncestors(theType2, 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()); } }
From source file:com.geeksaga.light.profiler.asm.TypeHierarchyUtil.java
License:Apache License
private TypeHierarchy obtainHierarchyOf(ClassReader reader) { return new TypeHierarchy(Type.getObjectType(reader.getClassName()), reader.getSuperName() == null ? null : Type.getObjectType(reader.getSuperName()), interfacesTypesFrom(reader.getInterfaces()), (reader.getAccess() & ACC_INTERFACE) != 0); }
From source file:com.google.devtools.build.android.desugar.ClassVsInterface.java
License:Open Source License
public boolean isOuterInterface(String outerName, String innerName) { Boolean result = known.get(outerName); if (result == null) { // We could just load the outer class here, but this tolerates incomplete classpaths better. // Note the outer class should be in the Jar we're desugaring, so it should always be there. ClassReader outerClass = classpath.readIfKnown(outerName); if (outerClass == null) { System.err.printf("WARNING: Couldn't find outer class %s of %s%n", outerName, innerName); // TODO(b/79155927): Make this an error when sources of this problem are fixed. result = false; // assume it's a class if we can't find it (b/79155927) } else {/*from w w w .j a v a2 s . c om*/ result = BitFlags.isInterface(outerClass.getAccess()); } known.put(outerName, result); } return result; }
From source file:com.google.devtools.build.android.desugar.io.HeaderClassLoader.java
License:Open Source License
/** * If the {@code reader} is an interface, then extract all the declared fields in it. Otherwise, * return an empty list.// w ww. jav a2 s. c o m */ private static ImmutableList<FieldInfo> getFieldsIfReaderIsInterface(ClassReader reader) { if (BitFlags.isSet(reader.getAccess(), Opcodes.ACC_INTERFACE)) { NonPrimitiveFieldCollector collector = new NonPrimitiveFieldCollector(); reader.accept(collector, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG); return collector.declaredNonPrimitiveFields.build(); } return ImmutableList.of(); }
From source file:com.navercorp.pinpoint.profiler.instrument.ASMClassWriter.java
License:Apache License
private boolean isInterface(final ClassReader classReader) { return (classReader.getAccess() & Opcodes.ACC_INTERFACE) != 0; }
From source file:com.navercorp.pinpoint.profiler.instrument.classreading.SimpleClassMetadataReader.java
License:Apache License
SimpleClassMetadataReader(byte[] classBinary) { if (classBinary == null) { throw new NullPointerException("classBinary must not be null"); }//from w w w. j ava 2 s .c o m final ClassReader classReader = new ClassReader(classBinary); int accessFlag = classReader.getAccess(); String className = classReader.getClassName(); String superClassName = classReader.getSuperName(); String[] interfaceNameList = classReader.getInterfaces(); // int offset = 0; // int version = classReader.readShort(offset + 6); // offset is zero int version = classReader.readShort(6); this.simpleClassMetadata = new DefaultSimpleClassMetadata(version, accessFlag, className, superClassName, interfaceNameList, classBinary); }
From source file:com.offbynull.coroutines.instrumenter.asm.FileSystemClassInformationRepository.java
License:Open Source License
private void populateSuperClassMapping(final InputStream is) throws IOException { ClassReader classReader = new ClassReader(is); String name = classReader.getClassName(); if (hierarchyMap.containsKey(name)) { // duplicate encounter, ignore return;//from w ww. j av a 2 s . com } String superName = classReader.getSuperName(); String[] interfaces = classReader.getInterfaces(); boolean interfaceMarker = (classReader.getAccess() & Opcodes.ACC_INTERFACE) != 0; hierarchyMap.put(name, new ClassInformation(superName, Arrays.asList(interfaces), interfaceMarker)); }
From source file:de.thetaphi.forbiddenapis.DeprecatedGen.java
License:Apache License
protected void parseClass(InputStream in) throws IOException { final ClassReader reader; try {/*from ww w . j a va 2 s .c om*/ reader = new ClassReader(in); } catch (IllegalArgumentException iae) { // unfortunately the ASM IAE has no message, so add good info! throw new IllegalArgumentException( "The class file format of your runtime seems to be too recent to be parsed by ASM (may need to be upgraded)."); } final String className = Type.getObjectType(reader.getClassName()).getClassName(); // exclude internal classes like Unsafe,... and non-public classes! // Note: reader.getAccess() does no indicate if class is deprecated, as this is a special // attribute or annotation (both is handled later), we have to parse the class - this is just early exit! if ((reader.getAccess() & ACC_PUBLIC) == 0 || AsmUtils.isInternalClass(className)) { return; } reader.accept(new ClassVisitor(ASM5) { boolean classDeprecated = false; @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { if (isDeprecated(access)) { deprecated.add(className); classDeprecated = true; } } @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { if (!classDeprecated && isDeprecated(access)) { final Type[] args = Type.getType(desc).getArgumentTypes(); final StringBuilder sb = new StringBuilder(className).append('#').append(name).append('('); boolean comma = false; for (final Type t : args) { if (comma) sb.append(','); sb.append(t.getClassName()); comma = true; } sb.append(')'); deprecated.add(sb.toString()); } return null; } @Override public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) { if (!classDeprecated && isDeprecated(access)) { deprecated.add(className + '#' + name); } return null; } }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); }