changeset 4476:51f0bf95d616

Add classfile Module_attribute.OPensEntry
author jjg
date Tue, 22 Nov 2016 18:42:46 -0800
parents ea87091ceefc
children f3be37a11045
files src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassWriter.java src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java
diffstat 4 files changed, 80 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassWriter.java	Tue Nov 22 18:18:59 2016 -0800
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassWriter.java	Tue Nov 22 18:42:46 2016 -0800
@@ -566,11 +566,11 @@
             }
 
             out.writeShort(attr.opens.length);
-            for (Module_attribute.ExportsEntry e: attr.opens) {
-                out.writeShort(e.exports_index);
-                out.writeShort(e.exports_flags);
-                out.writeShort(e.exports_to_index.length);
-                for (int index: e.exports_to_index)
+            for (Module_attribute.OpensEntry e: attr.opens) {
+                out.writeShort(e.opens_index);
+                out.writeShort(e.opens_flags);
+                out.writeShort(e.opens_to_index.length);
+                for (int index: e.opens_to_index)
                     out.writeShort(index);
             }
 
--- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java	Tue Nov 22 18:18:59 2016 -0800
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java	Tue Nov 22 18:42:46 2016 -0800
@@ -59,9 +59,9 @@
             exports[i] = new ExportsEntry(cr);
 
         opens_count = cr.readUnsignedShort();
-        opens = new ExportsEntry[opens_count];
+        opens = new OpensEntry[opens_count];
         for (int i = 0; i < opens_count; i++)
-            opens[i] = new ExportsEntry(cr);
+            opens[i] = new OpensEntry(cr);
 
         uses_count = cr.readUnsignedShort();
         uses_index = new int[uses_count];
@@ -79,7 +79,7 @@
             int module_flags,
             RequiresEntry[] requires,
             ExportsEntry[] exports,
-            ExportsEntry[] opens,
+            OpensEntry[] opens,
             int[] uses,
             ProvidesEntry[] provides) {
         super(name_index, 2);
@@ -114,7 +114,7 @@
     public final int exports_count;
     public final ExportsEntry[] exports;
     public final int opens_count;
-    public final ExportsEntry[] opens;
+    public final OpensEntry[] opens;
     public final int uses_count;
     public final int[] uses_index;
     public final int provides_count;
@@ -168,6 +168,33 @@
         public final int[] exports_to_index;
     }
 
+    public static class OpensEntry {
+        OpensEntry(ClassReader cr) throws IOException {
+            opens_index = cr.readUnsignedShort();
+            opens_flags = cr.readUnsignedShort();
+            opens_to_count = cr.readUnsignedShort();
+            opens_to_index = new int[opens_to_count];
+            for (int i = 0; i < opens_to_count; i++)
+                opens_to_index[i] = cr.readUnsignedShort();
+        }
+
+        public OpensEntry(int index, int flags, int[] to) {
+            this.opens_index = index;
+            this.opens_flags = flags;
+            this.opens_to_count = to.length;
+            this.opens_to_index = to;
+        }
+
+        public int length() {
+            return 4 + 2 * opens_to_index.length;
+        }
+
+        public final int opens_index;
+        public final int opens_flags;
+        public final int opens_to_count;
+        public final int[] opens_to_index;
+    }
+
     public static class ProvidesEntry {
         ProvidesEntry(ClassReader cr) throws IOException {
             provides_index = cr.readUnsignedShort();
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java	Tue Nov 22 18:18:59 2016 -0800
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java	Tue Nov 22 18:42:46 2016 -0800
@@ -517,8 +517,8 @@
         println();
 
         printRequiresTable(attr);
-        printExportsTable(attr, true);
-        printExportsTable(attr, false);
+        printExportsTable(attr);
+        printOpensTable(attr);
         printUsesTable(attr);
         printProvidesTable(attr);
         indent(-1);
@@ -548,41 +548,53 @@
         indent(-1);
     }
 
-    protected void printExportsTable(Module_attribute attr, boolean exports) {
-        Module_attribute.ExportsEntry[] entries = exports ? attr.exports : attr.opens;
+    protected void printExportsTable(Module_attribute attr) {
+        Module_attribute.ExportsEntry[] entries = attr.exports;
         print(entries.length);
         tab();
-        println("// " + (exports ? "exports" : "opens"));
+        println("// exports");
         indent(+1);
         for (Module_attribute.ExportsEntry e: entries) {
-            print("#" + e.exports_index + "," + String.format("%x", e.exports_flags));
-            tab();
-            print("// ");
-            if (e.exports_index == 0) {
-                print("default");
-            } else {
-                print(constantWriter.stringValue(e.exports_index));
-            }
-            if ((e.exports_flags & Module_attribute.ACC_MANDATED) != 0)
-                print(" ACC_MANDATED");
-            if ((e.exports_flags & Module_attribute.ACC_SYNTHETIC) != 0)
-                print(" ACC_SYNTHETIC");
-            if (e.exports_to_index.length == 0) {
-                println();
-            } else {
-                println(" to ... " + e.exports_to_index.length);
-                indent(+1);
-                for (int to: e.exports_to_index) {
-                    print("#" + to);
-                    tab();
-                    println("// ... to " + constantWriter.stringValue(to));
-                }
-                indent(-1);
-            }
+            printExportOpenEntry(e.exports_index, e.exports_flags, e.exports_to_index);
         }
         indent(-1);
     }
 
+    protected void printOpensTable(Module_attribute attr) {
+        Module_attribute.OpensEntry[] entries = attr.opens;
+        print(entries.length);
+        tab();
+        println("// opens");
+        indent(+1);
+        for (Module_attribute.OpensEntry e: entries) {
+            printExportOpenEntry(e.opens_index, e.opens_flags, e.opens_to_index);
+        }
+        indent(-1);
+    }
+
+    protected void printExportOpenEntry(int index, int flags, int[] to_index) {
+        print("#" + index + "," + String.format("%x", flags));
+        tab();
+        print("// ");
+        print(constantWriter.stringValue(index));
+        if ((flags & Module_attribute.ACC_MANDATED) != 0)
+            print(" ACC_MANDATED");
+        if ((flags & Module_attribute.ACC_SYNTHETIC) != 0)
+            print(" ACC_SYNTHETIC");
+        if (to_index.length == 0) {
+            println();
+        } else {
+            println(" to ... " + to_index.length);
+            indent(+1);
+            for (int to: to_index) {
+                print("#" + to);
+                tab();
+                println("// ... to " + constantWriter.stringValue(to));
+            }
+            indent(-1);
+        }
+    }
+
     protected void printUsesTable(Module_attribute attr) {
         int[] entries = attr.uses_index;
         print(entries.length);
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java	Tue Nov 22 18:18:59 2016 -0800
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java	Tue Nov 22 18:42:46 2016 -0800
@@ -632,12 +632,12 @@
                 indent(-1);
         }
 
-        for (Module_attribute.ExportsEntry entry: m.opens) {
+        for (Module_attribute.OpensEntry entry: m.opens) {
             print("opens");
             print(" ");
-            print(getUTF8Value(entry.exports_index).replace('/', '.'));
+            print(getUTF8Value(entry.opens_index).replace('/', '.'));
             boolean first = true;
-            for (int i: entry.exports_to_index) {
+            for (int i: entry.opens_to_index) {
                 String mname;
                 try {
                     mname = classFile.constant_pool.getUTF8Value(i).replace('/', '.');