--- old/src/java.base/share/classes/jdk/internal/org/objectweb/asm/util/ASMifier.java Fri Oct 27 09:24:47 2017 +++ new/src/java.base/share/classes/jdk/internal/org/objectweb/asm/util/ASMifier.java Fri Oct 27 09:24:47 2017 @@ -110,6 +110,11 @@ private static final int ACCESS_INNER = 1048576; /** + * Pseudo access flag used to distinguish module requires/exports flags. + */ + private static final int ACCESS_MODULE = 2097152; + + /** * Constructs a new {@link ASMifier}. Subclasses must not use this * constructor. Instead, they must use the * {@link #ASMifier(int, String, int)} version. @@ -118,7 +123,7 @@ * If a subclass calls this constructor. */ public ASMifier() { - this(Opcodes.ASM5, "cw", 0); + this(Opcodes.ASM6, "cw", 0); if (getClass() != ASMifier.class) { throw new IllegalStateException(); } @@ -129,7 +134,7 @@ * * @param api * the ASM API version implemented by this class. Must be one of - * {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. + * {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. * @param name * the name of the visitor variable in the produced code. * @param id @@ -196,13 +201,17 @@ final String signature, final String superName, final String[] interfaces) { String simpleName; - int n = name.lastIndexOf('/'); - if (n == -1) { - simpleName = name; + if (name == null) { + simpleName = "module-info"; } else { - text.add("package asm." + name.substring(0, n).replace('/', '.') - + ";\n"); - simpleName = name.substring(n + 1); + int n = name.lastIndexOf('/'); + if (n == -1) { + simpleName = name; + } else { + text.add("package asm." + name.substring(0, n).replace('/', '.') + + ";\n"); + simpleName = name.substring(n + 1).replace('-', '_'); + } } text.add("import java.util.*;\n"); text.add("import jdk.internal.org.objectweb.asm.*;\n"); @@ -237,6 +246,12 @@ case Opcodes.V1_7: buf.append("V1_7"); break; + case Opcodes.V1_8: + buf.append("V1_8"); + break; + case Opcodes.V9: + buf.append("V9"); + break; default: buf.append(version); break; @@ -276,6 +291,24 @@ } @Override + public Printer visitModule(final String name, final int flags, + final String version) { + buf.setLength(0); + buf.append("ModuleVisitor mdv = cw.visitModule("); + appendConstant(name); + buf.append(", "); + appendAccess(flags | ACCESS_MODULE); + buf.append(", "); + appendConstant(version); + buf.append(");\n\n"); + text.add(buf.toString()); + ASMifier a = createASMifier("mdv", 0); + text.add(a.getText()); + text.add("}\n"); + return a; + } + + @Override public void visitOuterClass(final String owner, final String name, final String desc) { buf.setLength(0); @@ -386,6 +419,108 @@ } // ------------------------------------------------------------------------ + // Module + // ------------------------------------------------------------------------ + + @Override + public void visitMainClass(String mainClass) { + buf.setLength(0); + buf.append("mdv.visitMainClass("); + appendConstant(buf, mainClass); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitPackage(String packaze) { + buf.setLength(0); + buf.append("mdv.visitPackage("); + appendConstant(buf, packaze); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitRequire(String module, int access, String version) { + buf.setLength(0); + buf.append("mdv.visitRequire("); + appendConstant(buf, module); + buf.append(", "); + appendAccess(access | ACCESS_MODULE); + buf.append(", "); + appendConstant(buf, version); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitExport(String packaze, int access, String... modules) { + buf.setLength(0); + buf.append("mdv.visitExport("); + appendConstant(buf, packaze); + buf.append(", "); + appendAccess(access | ACCESS_MODULE); + if (modules != null && modules.length > 0) { + buf.append(", new String[] {"); + for (int i = 0; i < modules.length; ++i) { + buf.append(i == 0 ? " " : ", "); + appendConstant(modules[i]); + } + buf.append(" }"); + } + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitOpen(String packaze, int access, String... modules) { + buf.setLength(0); + buf.append("mdv.visitOpen("); + appendConstant(buf, packaze); + buf.append(", "); + appendAccess(access | ACCESS_MODULE); + if (modules != null && modules.length > 0) { + buf.append(", new String[] {"); + for (int i = 0; i < modules.length; ++i) { + buf.append(i == 0 ? " " : ", "); + appendConstant(modules[i]); + } + buf.append(" }"); + } + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitUse(String service) { + buf.setLength(0); + buf.append("mdv.visitUse("); + appendConstant(buf, service); + buf.append(");\n"); + text.add(buf.toString()); + } + + @Override + public void visitProvide(String service, String... providers) { + buf.setLength(0); + buf.append("mdv.visitProvide("); + appendConstant(buf, service); + buf.append(", new String[] {"); + for (int i = 0; i < providers.length; ++i) { + buf.append(i == 0 ? " " : ", "); + appendConstant(providers[i]); + } + buf.append(" });\n"); + text.add(buf.toString()); + } + + @Override + public void visitModuleEnd() { + text.add("mdv.visitEnd();\n"); + } + + + // ------------------------------------------------------------------------ // Annotations // ------------------------------------------------------------------------ @@ -972,7 +1107,7 @@ // ------------------------------------------------------------------------ protected ASMifier createASMifier(final String name, final int id) { - return new ASMifier(Opcodes.ASM5, name, id); + return new ASMifier(Opcodes.ASM6, name, id); } /** @@ -1000,7 +1135,11 @@ if (!first) { buf.append(" + "); } - buf.append("ACC_FINAL"); + if ((access & ACCESS_MODULE) == 0) { + buf.append("ACC_FINAL"); + } else { + buf.append("ACC_TRANSITIVE"); + } first = false; } if ((access & Opcodes.ACC_STATIC) != 0) { @@ -1010,31 +1149,35 @@ buf.append("ACC_STATIC"); first = false; } - if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) { + if ((access & (Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_SUPER | Opcodes.ACC_TRANSITIVE)) != 0) { if (!first) { buf.append(" + "); } if ((access & ACCESS_CLASS) == 0) { - buf.append("ACC_SYNCHRONIZED"); + if ((access & ACCESS_MODULE) == 0) { + buf.append("ACC_SYNCHRONIZED"); + } else { + buf.append("ACC_TRANSITIVE"); + } } else { buf.append("ACC_SUPER"); } first = false; } - if ((access & Opcodes.ACC_VOLATILE) != 0 - && (access & ACCESS_FIELD) != 0) { + if ((access & (Opcodes.ACC_VOLATILE | Opcodes.ACC_BRIDGE | Opcodes.ACC_STATIC_PHASE)) != 0) { if (!first) { buf.append(" + "); } - buf.append("ACC_VOLATILE"); - first = false; - } - if ((access & Opcodes.ACC_BRIDGE) != 0 && (access & ACCESS_CLASS) == 0 - && (access & ACCESS_FIELD) == 0) { - if (!first) { - buf.append(" + "); + if ((access & ACCESS_FIELD) == 0) { + if ((access & ACCESS_MODULE) == 0) { + buf.append("ACC_BRIDGE"); + } else { + buf.append("ACC_STATIC_PHASE"); + } + } else { + buf.append("ACC_VOLATILE"); } - buf.append("ACC_BRIDGE"); + first = false; } if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0 @@ -1113,11 +1256,15 @@ buf.append("ACC_DEPRECATED"); first = false; } - if ((access & Opcodes.ACC_MANDATED) != 0) { + if ((access & (Opcodes.ACC_MANDATED | Opcodes.ACC_MODULE)) != 0) { if (!first) { buf.append(" + "); } - buf.append("ACC_MANDATED"); + if ((access & ACCESS_CLASS) == 0) { + buf.append("ACC_MANDATED"); + } else { + buf.append("ACC_MODULE"); + } first = false; } if (first) { @@ -1163,7 +1310,8 @@ .append(", \""); buf.append(h.getOwner()).append("\", \""); buf.append(h.getName()).append("\", \""); - buf.append(h.getDesc()).append("\")"); + buf.append(h.getDesc()).append("\", "); + buf.append(h.isInterface()).append(")"); } else if (cst instanceof Byte) { buf.append("new Byte((byte)").append(cst).append(')'); } else if (cst instanceof Boolean) {