--- old/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java 2018-05-18 03:24:09.751629482 -0400 +++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java 2018-05-18 03:24:08.179538416 -0400 @@ -31,6 +31,7 @@ import java.util.Set; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.stream.Collectors; import javax.tools.JavaFileManager; import javax.tools.FileObject; @@ -1103,6 +1104,56 @@ endAttr(alenIdx); } + /** + * Write NestMembers attribute (if needed) + */ + int writeNestMembersIfNeeded(ClassSymbol csym) { + ListBuffer nested = new ListBuffer<>(); + listNested(csym, nested); + Set nestedUnique = new LinkedHashSet<>(nested); + if (csym.owner.kind == PCK && !nestedUnique.isEmpty()) { + int alenIdx = writeAttr(names.NestMembers); + databuf.appendChar(nestedUnique.size()); + for (Symbol s : nestedUnique) { + databuf.appendChar(pool.put(s)); + } + endAttr(alenIdx); + return 1; + } + return 0; + } + + /** + * Write NestHost attribute (if needed) + */ + int writeNestHostIfNeeded(ClassSymbol csym) { + if (csym.owner.kind != PCK) { + int alenIdx = writeAttr(names.NestHost); + databuf.appendChar(pool.put(csym.outermostClass())); + endAttr(alenIdx); + return 1; + } + return 0; + } + + private void listNested(Symbol sym, ListBuffer seen) { + if (sym.kind != TYP) return; + ClassSymbol csym = (ClassSymbol)sym; + if (csym.owner.kind != PCK) { + seen.add(csym); + } + if (csym.members() != null) { + for (Symbol s : sym.members().getSymbols()) { + listNested(s, seen); + } + } + if (csym.trans_local != null) { + for (Symbol s : csym.trans_local) { + listNested(s, seen); + } + } + } + /** Write "bootstrapMethods" attribute. */ void writeBootstrapMethods() { @@ -1830,6 +1881,13 @@ } poolbuf.appendChar(target.majorVersion); + if (c.owner.kind != MDL) { + if (target.hasNestmateAccess()) { + acount += writeNestMembersIfNeeded(c); + acount += writeNestHostIfNeeded(c); + } + } + writePool(c.pool); if (innerClasses != null) {