jdk.internal.org.objectweb.asm.ClassVisitor Java Examples

The following examples show how to use jdk.internal.org.objectweb.asm.ClassVisitor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Test.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ClassVisitor make(ClassVisitor cv) {
    return new ClassVisitor(Opcodes.ASM5, cv) {

        @Override
        public void visitInnerClass(String name, String outerName,
                String innerName, int access) {
            if (whenVisitInner) {
                int access_ = (ACC_PROTECTED | access) & ~(ACC_PRIVATE | ACC_PUBLIC);
                System.out.println("visitInnerClass: name = " + name
                        + ", outerName = " + outerName
                        + ", innerName = " + innerName
                        + ", access original = 0x" + Integer.toHexString(access)
                        + ", access modified to 0x" + Integer.toHexString(access_));
                access = access_;
            }
            super.visitInnerClass(name, outerName, innerName, access);
        }
    };
}
 
Example #2
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean hasModuleTarget(InputStream in) throws IOException {
    ModuleTargetAttribute[] modTargets = new ModuleTargetAttribute[1];
    ClassVisitor cv = new ClassVisitor(Opcodes.ASM5) {
        @Override
        public void visitAttribute(Attribute attr) {
            if (attr instanceof ModuleTargetAttribute) {
                modTargets[0] = (ModuleTargetAttribute)attr;
            }
        }
    };

    // prototype of attributes that should be parsed
    Attribute[] attrs = new Attribute[] {
        new ModuleTargetAttribute()
    };

    // parse module-info.class
    ClassReader cr = new ClassReader(in);
    cr.accept(cv, attrs, 0);
    return modTargets[0] != null && modTargets[0].targetPlatform() != null;
}
 
Example #3
Source File: ClassGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void addSetter(final ClassVisitor cv, final String owner, final MemberInfo memInfo) {
    final int access = ACC_PUBLIC;
    final String name = SETTER_PREFIX + memInfo.getJavaName();
    final String desc = setterDesc(memInfo);
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    final MethodGenerator mi = new MethodGenerator(mv, access, name, desc);
    mi.visitCode();
    if (memInfo.isStatic() && memInfo.getKind() == Kind.PROPERTY) {
        mi.loadLocal(1);
        mi.putStatic(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    } else {
        mi.loadLocal(0);
        mi.loadLocal(1);
        mi.putField(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    }
    mi.returnVoid();
    mi.computeMaxs();
    mi.visitEnd();
}
 
Example #4
Source File: ClassGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static void addSetter(final ClassVisitor cv, final String owner, final MemberInfo memInfo) {
    final int access = ACC_PUBLIC;
    final String name = SETTER_PREFIX + memInfo.getJavaName();
    final String desc = setterDesc(memInfo);
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    final MethodGenerator mi = new MethodGenerator(mv, access, name, desc);
    mi.visitCode();
    if (memInfo.isStatic() && memInfo.getKind() == Kind.PROPERTY) {
        mi.loadLocal(1);
        mi.putStatic(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    } else {
        mi.loadLocal(0);
        mi.loadLocal(1);
        mi.putField(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    }
    mi.returnVoid();
    mi.computeMaxs();
    mi.visitEnd();
}
 
Example #5
Source File: ClassGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void addGetter(final ClassVisitor cv, final String owner, final MemberInfo memInfo) {
    final int access = ACC_PUBLIC;
    final String name = GETTER_PREFIX + memInfo.getJavaName();
    final String desc = getterDesc(memInfo);
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    final MethodGenerator mi = new MethodGenerator(mv, access, name, desc);
    mi.visitCode();
    if (memInfo.isStatic() && memInfo.getKind() == Kind.PROPERTY) {
        mi.getStatic(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    } else {
        mi.loadLocal(0);
        mi.getField(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    }
    mi.returnValue();
    mi.computeMaxs();
    mi.visitEnd();
}
 
Example #6
Source File: RedefineAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public byte[] asm(ClassLoader loader, String className,
        Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer)
    throws IllegalClassFormatException {

    ClassWriter cw = new ClassWriter(0);
    ClassVisitor cv = new ReAddDummyFieldsClassVisitor(ASM5, cw) { };
    ClassReader cr = new ClassReader(classfileBuffer);
    cr.accept(cv, 0);
    return cw.toByteArray();
}
 
Example #7
Source File: MethodNode.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes the given class visitor visit this method.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    String[] exceptions = new String[this.exceptions.size()];
    this.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
            exceptions);
    if (mv != null) {
        accept(mv);
    }
}
 
Example #8
Source File: RedefineAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public byte[] asm(ClassLoader loader, String className,
        Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer)
    throws IllegalClassFormatException {

    ClassWriter cw = new ClassWriter(0);
    ClassVisitor cv = new ReAddDummyFieldsClassVisitor(ASM5, cw) { };
    ClassReader cr = new ClassReader(classfileBuffer);
    cr.accept(cv, 0);
    return cw.toByteArray();
}
 
Example #9
Source File: ClassGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example #10
Source File: JIInliner.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A ClassVisitor which will check all methods of the class it visits against the instrumentationMethods
 * list. If a method is on that list, the method will be further processed for inlining into that
 * method.
 */
JIInliner(int api, ClassVisitor cv, String targetClassName, String instrumentationClassName,
        ClassReader targetClassReader,
        List<Method> instrumentationMethods) {
    super(api, cv);
    this.targetClassName = targetClassName;
    this.instrumentationClassName = instrumentationClassName;
    this.instrumentationMethods = instrumentationMethods;

    ClassNode cn = new ClassNode(Opcodes.ASM5);
    targetClassReader.accept(cn, ClassReader.EXPAND_FRAMES);
    this.targetClassNode = cn;
}
 
Example #11
Source File: Method.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Method(ClassConstruct ownerClass, ClassVisitor cv, String name, String descriptor, int access,
              ClassBuilder.ExecutionMode execMode) {
    this.ownerClassName = ownerClass.getName();
    this.ownerClass = ownerClass;
    this.execMode = execMode;
    this.cv = cv;
    mv = cv.visitMethod(access, name, descriptor, null, null);
    mv.visitCode();
}
 
Example #12
Source File: ClassGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void addMapField(final ClassVisitor cv) {
    // add a PropertyMap static field
    final FieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL,
        PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC, null, null);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example #13
Source File: JIMethodMergeAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Methods in methodFilter that exist in cn will be merged into cv. If the method already exists,
 * the original method will be deleted.
 *
 * @param cv
 * @param cn - a ClassNode with Methods that will be merged into this class
 * @param methodFilter - only methods in this list will be merged
 * @param typeMappings - while merging, type references in the methods will be changed according to this map
 */
public JIMethodMergeAdapter(ClassVisitor cv, ClassNode cn, List<Method> methodFilter, JITypeMapping[] typeMappings) {
    super(Opcodes.ASM5, cv);
    this.cn = cn;
    this.methodFilter = methodFilter;

    this.typeMap = new HashMap<>();
    for (JITypeMapping tm : typeMappings) {
        typeMap.put(tm.from().replace('.', '/'), tm.to().replace('.', '/'));
    }
}
 
Example #14
Source File: MethodNode.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes the given class visitor visit this method.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    String[] exceptions = new String[this.exceptions.size()];
    this.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
            exceptions);
    if (mv != null) {
        accept(mv);
    }
}
 
Example #15
Source File: ScriptClassInstrumentor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
ScriptClassInstrumentor(final ClassVisitor visitor, final ScriptClassInfo sci) {
    super(Opcodes.ASM4, visitor);
    if (sci == null) {
        throw new IllegalArgumentException("Null ScriptClassInfo, is the class annotated?");
    }
    this.scriptClassInfo = sci;
    this.memberCount = scriptClassInfo.getInstancePropertyCount();
}
 
Example #16
Source File: ClassGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void addMapField(final ClassVisitor cv) {
    // add a PropertyMap static field
    final FieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL,
        PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC, null, null);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example #17
Source File: ScriptClassInstrumentor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
ScriptClassInstrumentor(final ClassVisitor visitor, final ScriptClassInfo sci) {
    super(Opcodes.ASM4, visitor);
    if (sci == null) {
        throw new IllegalArgumentException("Null ScriptClassInfo, is the class annotated?");
    }
    this.scriptClassInfo = sci;
    this.memberCount = scriptClassInfo.getInstancePropertyCount();
}
 
Example #18
Source File: RedefineAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public byte[] asm(ClassLoader loader, String className,
        Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer)
    throws IllegalClassFormatException {

    ClassWriter cw = new ClassWriter(0);
    ClassVisitor cv = new ReAddDummyFieldsClassVisitor(ASM5, cw) { };
    ClassReader cr = new ClassReader(classfileBuffer);
    cr.accept(cv, 0);
    return cw.toByteArray();
}
 
Example #19
Source File: ClassGenerator.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
static void addMapField(final ClassVisitor cv) {
    // add a PropertyMap static field
    final FieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL,
        PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC, null, null);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example #20
Source File: JIMethodMergeAdapter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Methods in methodFilter that exist in cn will be merged into cv. If the method already exists,
 * the original method will be deleted.
 *
 * @param cv
 * @param cn - a ClassNode with Methods that will be merged into this class
 * @param methodFilter - only methods in this list will be merged
 * @param typeMappings - while merging, type references in the methods will be changed according to this map
 */
public JIMethodMergeAdapter(ClassVisitor cv, ClassNode cn, List<Method> methodFilter, JITypeMapping[] typeMappings) {
    super(Opcodes.ASM5, cv);
    this.cn = cn;
    this.methodFilter = methodFilter;

    this.typeMap = new HashMap<>();
    for (JITypeMapping tm : typeMappings) {
        typeMap.put(tm.from().replace('.', '/'), tm.to().replace('.', '/'));
    }
}
 
Example #21
Source File: ScriptClassInfoCollector.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
ScriptClassInfoCollector(final ClassVisitor visitor) {
    super(Opcodes.ASM4, visitor);
}
 
Example #22
Source File: RemappingClassAdapter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected RemappingClassAdapter(final int api, final ClassVisitor cv,
        final Remapper remapper) {
    super(api, cv);
    this.remapper = remapper;
}
 
Example #23
Source File: ScriptClassInfoCollector.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
ScriptClassInfoCollector(final ClassVisitor visitor) {
    super(Opcodes.ASM4, visitor);
}
 
Example #24
Source File: ClassGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static MethodGenerator makeStaticInitializer(final ClassVisitor cv) {
    return makeStaticInitializer(cv, CLINIT);
}
 
Example #25
Source File: RemappingClassAdapter.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public RemappingClassAdapter(final ClassVisitor cv, final Remapper remapper) {
    this(Opcodes.ASM5, cv, remapper);
}
 
Example #26
Source File: ClassGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void addField(final ClassVisitor cv, final String name, final String desc) {
    final FieldVisitor fv = cv.visitField(ACC_PRIVATE, name, desc, null, null);
    if (fv != null) {
        fv.visitEnd();
    }
}
 
Example #27
Source File: ScriptClassInfoCollector.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
ScriptClassInfoCollector(final ClassVisitor visitor) {
    super(Opcodes.ASM4, visitor);
}
 
Example #28
Source File: RemappingClassAdapter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected RemappingClassAdapter(final int api, final ClassVisitor cv,
        final Remapper remapper) {
    super(api, cv);
    this.remapper = remapper;
}
 
Example #29
Source File: StaticInitMerger.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public StaticInitMerger(final String prefix, final ClassVisitor cv) {
    this(Opcodes.ASM5, prefix, cv);
}
 
Example #30
Source File: StaticInitMerger.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public StaticInitMerger(final String prefix, final ClassVisitor cv) {
    this(Opcodes.ASM5, prefix, cv);
}