public static void retransformClasses(Instrumentation inst, ClassFileTransformer transformer,
                                          Set<Class<?>> classes) {
        try {
            inst.addTransformer(transformer, true);

            for (Class<?> clazz : classes) {
                try {
                    inst.retransformClasses(clazz);
                } catch (Throwable e) {
                    LogUtils.logit("retransformClasses class error, name: " + clazz.getName());
                }
            }
        } finally {
            inst.removeTransformer(transformer);
        }
    }
referer https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/InstrumentationUtils.java
agent/src/main/java/code/landgrey/copagent/utils/InstrumentationUtils.java