The following commit has been merged in the master branch:
commit 9525b9189759e98277a77d1e140a167bc8029409
Author: Alan Bateman <alan.bate...@oracle.com>
Date:   Fri Dec 2 22:43:12 2011 +0100

    Sync with latest upstream.

diff --git a/jdk/.hg/cache/branchheads b/jdk/.hg/cache/branchheads
index 38c363d..1d20d56 100644
--- a/jdk/.hg/cache/branchheads
+++ b/jdk/.hg/cache/branchheads
@@ -1,2 +1,2 @@
-807e450b0e1c810720e6be6abc3ebe017e92578e 4996
-807e450b0e1c810720e6be6abc3ebe017e92578e default
+22ccf6e7a09237596d9640d586f39c0ea8c2129b 4997
+22ccf6e7a09237596d9640d586f39c0ea8c2129b default
diff --git a/jdk/.hg/dirstate b/jdk/.hg/dirstate
index 40df47d..93c4205 100644
Binary files a/jdk/.hg/dirstate and b/jdk/.hg/dirstate differ
diff --git a/jdk/.hg/store/00changelog.d b/jdk/.hg/store/00changelog.d
index 5387a3b..03ddae2 100644
Binary files a/jdk/.hg/store/00changelog.d and b/jdk/.hg/store/00changelog.d 
differ
diff --git a/jdk/.hg/store/00changelog.i b/jdk/.hg/store/00changelog.i
index 4b6d449..7e27f9a 100644
Binary files a/jdk/.hg/store/00changelog.i and b/jdk/.hg/store/00changelog.i 
differ
diff --git a/jdk/.hg/store/00manifest.d b/jdk/.hg/store/00manifest.d
index cc0c951..fcd9566 100644
Binary files a/jdk/.hg/store/00manifest.d and b/jdk/.hg/store/00manifest.d 
differ
diff --git a/jdk/.hg/store/00manifest.i b/jdk/.hg/store/00manifest.i
index cc90698..2422e60 100644
Binary files a/jdk/.hg/store/00manifest.i and b/jdk/.hg/store/00manifest.i 
differ
diff --git a/jdk/.hg/store/data/make/common/_defs-modules.gmk.i 
b/jdk/.hg/store/data/make/common/_defs-modules.gmk.i
index 414ce1a..302e93e 100644
Binary files a/jdk/.hg/store/data/make/common/_defs-modules.gmk.i and 
b/jdk/.hg/store/data/make/common/_defs-modules.gmk.i differ
diff --git a/jdk/.hg/store/data/make/common/_modules.gmk.i 
b/jdk/.hg/store/data/make/common/_modules.gmk.i
index 630f6bb..3e86e6f 100644
Binary files a/jdk/.hg/store/data/make/common/_modules.gmk.i and 
b/jdk/.hg/store/data/make/common/_modules.gmk.i differ
diff --git a/jdk/.hg/store/data/make/modules/_makefile.i 
b/jdk/.hg/store/data/make/modules/_makefile.i
index 39b806d..b46ccd6 100644
Binary files a/jdk/.hg/store/data/make/modules/_makefile.i and 
b/jdk/.hg/store/data/make/modules/_makefile.i differ
diff --git 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_class_info.java.i 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_class_info.java.i
index b98176d..890db0e 100644
Binary files 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_class_info.java.i 
and 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_class_info.java.i 
differ
diff --git 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_files.java.i 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_files.java.i
index b6f97d0..5ab311e 100644
Binary files 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_files.java.i and 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_files.java.i differ
diff --git 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_launcher.java.i 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_launcher.java.i
index 68baaf1..cd10d03 100644
Binary files 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_launcher.java.i and 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_launcher.java.i 
differ
diff --git 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_module_file.java.i 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_module_file.java.i
index eaaf69f..c7b19ed 100644
Binary files 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_module_file.java.i 
and 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_module_file.java.i 
differ
diff --git 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_simple_library.java.i
 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_simple_library.java.i
index 95678fc..b7f4144 100644
Binary files 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_simple_library.java.i
 and 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/_simple_library.java.i
 differ
diff --git 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_librarian.java.i 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_librarian.java.i
index 0142e5e..f0553d4 100644
Binary files 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_librarian.java.i 
and 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_librarian.java.i 
differ
diff --git 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_packager.java.i 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_packager.java.i
index 03a3d65..c7e9d7f 100644
Binary files 
a/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_packager.java.i 
and 
b/jdk/.hg/store/data/src/share/classes/org/openjdk/jigsaw/cli/_packager.java.i 
differ
diff --git a/jdk/.hg/store/data/test/org/openjdk/jigsaw/___library.java.i 
b/jdk/.hg/store/data/test/org/openjdk/jigsaw/___library.java.i
index 16250e5..f8d6454 100644
Binary files a/jdk/.hg/store/data/test/org/openjdk/jigsaw/___library.java.i and 
b/jdk/.hg/store/data/test/org/openjdk/jigsaw/___library.java.i differ
diff --git 
a/jdk/.hg/store/data/test/org/openjdk/jigsaw/___remote_repository_list.java.i 
b/jdk/.hg/store/data/test/org/openjdk/jigsaw/___remote_repository_list.java.i
index b67b049..b337d9a 100644
Binary files 
a/jdk/.hg/store/data/test/org/openjdk/jigsaw/___remote_repository_list.java.i 
and 
b/jdk/.hg/store/data/test/org/openjdk/jigsaw/___remote_repository_list.java.i 
differ
diff --git 
a/jdk/.hg/store/data/test/org/openjdk/jigsaw/_install_from_repo.java.i 
b/jdk/.hg/store/data/test/org/openjdk/jigsaw/_install_from_repo.java.i
index de015aa..a4b2805 100644
Binary files 
a/jdk/.hg/store/data/test/org/openjdk/jigsaw/_install_from_repo.java.i and 
b/jdk/.hg/store/data/test/org/openjdk/jigsaw/_install_from_repo.java.i differ
diff --git a/jdk/.hg/store/data/test/org/openjdk/jigsaw/cli/jmod-basic.sh.i 
b/jdk/.hg/store/data/test/org/openjdk/jigsaw/cli/jmod-basic.sh.i
index 04d8ac5..e00cacc 100644
Binary files a/jdk/.hg/store/data/test/org/openjdk/jigsaw/cli/jmod-basic.sh.i 
and b/jdk/.hg/store/data/test/org/openjdk/jigsaw/cli/jmod-basic.sh.i differ
diff --git a/jdk/.hg/store/undo b/jdk/.hg/store/undo
index 8d0dec9..932c931 100644
Binary files a/jdk/.hg/store/undo and b/jdk/.hg/store/undo differ
diff --git a/jdk/.hg/undo.desc b/jdk/.hg/undo.desc
index 5fafb69..d23fd9c 100644
--- a/jdk/.hg/undo.desc
+++ b/jdk/.hg/undo.desc
@@ -1,3 +1,3 @@
-4868
+4997
 pull
 http://hg.openjdk.java.net/jigsaw/jigsaw/jdk
diff --git a/jdk/.hg/undo.dirstate b/jdk/.hg/undo.dirstate
index e6cccfe..40df47d 100644
Binary files a/jdk/.hg/undo.dirstate and b/jdk/.hg/undo.dirstate differ
diff --git a/jdk/make/common/Defs-modules.gmk b/jdk/make/common/Defs-modules.gmk
index f77e470..a1bf4bb 100644
--- a/jdk/make/common/Defs-modules.gmk
+++ b/jdk/make/common/Defs-modules.gmk
@@ -136,3 +136,13 @@ endef
 define TouchModule
 $(ECHO) $(MODULE) >> $(MODULES_UPDATE_MARKER)
 endef
+
+# 
+# Minimize module library footprint. For now this applies to
+# both the JRE and JDK images that the build generates.
+#
+ifeq ($(MINIMIZE_MLIB_FOOTPRINT),true)
+    JMOD_CREATE_ARGS += -z
+    JMOD_INSTALL_ARGS += -G
+endif
+
diff --git a/jdk/make/common/Modules.gmk b/jdk/make/common/Modules.gmk
index 2e4a2d1..6f74bd2 100644
--- a/jdk/make/common/Modules.gmk
+++ b/jdk/make/common/Modules.gmk
@@ -138,7 +138,7 @@ define create-module-library
 image=$(strip $1); \
 mlib=$(MODULE_IMAGES_DIR)/$$image/lib/modules; \
 $(ECHO) "Creating module library $$mlib" ; \
-$(HOST_JMOD_CMD) create -N -L $$mlib
+$(HOST_JMOD_CMD) create -N $(JMOD_CREATE_ARGS) -L $$mlib
 endef
 
 # Copy module content to the module image
@@ -188,9 +188,9 @@ if [ "x$$mid" = "x" ] ; then \
    $(ECHO) "Installing module $$m in $$image" ; \
    $(CD) $(ABS_MODULEPATH_DIR) && \
    if [ -d $$m/resources ] ; then \
-      $(HOST_JMOD_CMD) install $$m/classes -r $$m/resources -L $$mlib $$m || 
exit 1; \
+      $(HOST_JMOD_CMD) install $$m/classes -r $$m/resources -L $$mlib 
$(JMOD_INSTALL_ARGS) $$m || exit 1; \
    else \
-      $(HOST_JMOD_CMD) install $$m/classes -L $$mlib $$m || exit 1; \
+      $(HOST_JMOD_CMD) install $$m/classes -L $$mlib $(JMOD_INSTALL_ARGS) $$m 
|| exit 1; \
    fi ; \
    $(call copy-module-content,$1,$2) ; \
 else \
diff --git a/jdk/make/modules/Makefile b/jdk/make/modules/Makefile
index 4cd4809..0475edc 100644
--- a/jdk/make/modules/Makefile
+++ b/jdk/make/modules/Makefile
@@ -167,7 +167,7 @@ include $(BUILDDIR)/common/Classes.gmk
 # javac depends on the jigsaw module library to exist
 module-info-classes:
        if [ ! -d $(JIGSAW_MODULE_LIB) ] ; then \
-          $(HOST_JMOD_CMD) create -N -L $(JIGSAW_MODULE_LIB) ; \
+          $(HOST_JMOD_CMD) create -N $(JMOD_CREATE_ARGS) -L 
$(JIGSAW_MODULE_LIB) ; \
        fi
        $(MAKE) classes || exit 1
 
@@ -227,7 +227,7 @@ define install-module
   $(RM) -r $(JIGSAW_MODULE_LIB)/$$m ; \
   $(ECHO) "Installing module $$m" ; \
   $(CD) $(MODULEPATH_DIR) && \
-  $(HOST_JMOD_CMD) install $$m/classes $$m -L $(JIGSAW_MODULE_LIB) || exit 1 ; 
+  $(HOST_JMOD_CMD) install $$m/classes $$m -L $(JIGSAW_MODULE_LIB) 
$(JMOD_INSTALL_ARGS) || exit 1 ; 
 endef
 
 #
diff --git a/jdk/src/share/classes/org/openjdk/jigsaw/ClassInfo.java 
b/jdk/src/share/classes/org/openjdk/jigsaw/ClassInfo.java
index 1493d67..3054f88 100644
--- a/jdk/src/share/classes/org/openjdk/jigsaw/ClassInfo.java
+++ b/jdk/src/share/classes/org/openjdk/jigsaw/ClassInfo.java
@@ -28,6 +28,7 @@ package org.openjdk.jigsaw;
 import java.io.*;
 import java.nio.*;
 import java.nio.channels.*;
+import java.util.Arrays;
 
 import static java.lang.System.out;
 
@@ -321,19 +322,42 @@ public class ClassInfo {
         load(bb, f.getPath());
     }
 
+    private static byte[] readAllBytes(InputStream in, int initialSize)
+        throws IOException
+    {
+        int capacity = (initialSize > 0) ? initialSize : 8192;
+        byte[] buf = new byte[capacity];
+        int nread = 0;
+        int rem = buf.length;
+        int n;
+        // read to EOF which may read more or less than initialSize
+        while ((n = in.read(buf, nread, rem)) > 0) {
+            nread += n;
+            rem -= n;
+            assert rem >= 0;
+            if (rem == 0) {
+                // need larger buffer
+                int newCapacity = capacity << 1;
+                if (newCapacity < 0) {
+                    if (capacity == Integer.MAX_VALUE)
+                        throw new OutOfMemoryError("Required array size too 
large");
+                    newCapacity = Integer.MAX_VALUE;
+                }
+                rem = newCapacity - capacity;
+                buf = Arrays.copyOf(buf, newCapacity);
+                capacity = newCapacity;
+            }
+        }
+        return (capacity == nread) ? buf : Arrays.copyOf(buf, nread);
+    }
+
     private void load(InputStream in, int size, String path)
         throws IOException
     {
-        assert size >= 0 : "oops: " + size;
-        byte[] buf = new byte[size];
-        int i = 0, n;
-        try {
-            while ((n = in.read(buf, i, size - i)) > 0)
-                i += n;
-        } finally {
-            in.close();
+        try (InputStream source = in) {
+            byte[] buf = readAllBytes(in, size);
+            load(ByteBuffer.wrap(buf, 0, buf.length), path);
         }
-        load(ByteBuffer.wrap(buf, 0, i), path);
     }
 
     // -- Entry points --
diff --git a/jdk/src/share/classes/org/openjdk/jigsaw/Files.java 
b/jdk/src/share/classes/org/openjdk/jigsaw/Files.java
index 9cf8925..e02e8eb 100644
--- a/jdk/src/share/classes/org/openjdk/jigsaw/Files.java
+++ b/jdk/src/share/classes/org/openjdk/jigsaw/Files.java
@@ -159,7 +159,7 @@ public final class Files {
         copyTree(src, dst, null);
     }
 
-    private static void storeTree(File src, JarOutputStream dst,
+    private static void storeTree(File src, JarOutputStream dst, boolean 
deflate,
                                   Filter<File> filter, String dstPath)
         throws IOException
     {
@@ -170,24 +170,25 @@ public final class Files {
             if (filter != null && !filter.accept(sf))
                 continue;
             String dp = (dstPath == null) ? sls[i] : dstPath + "/" + sls[i];
-            if (sf.isDirectory())
-                storeTree(sf, dst, filter, dp);
-            else
-                copy(sf, newOutputStream(dst, dp));
+            if (sf.isDirectory()) {
+                storeTree(sf, dst, deflate, filter, dp);
+            } else {
+                copy(sf, newOutputStream(dst, deflate, dp));
+            }
         }
     }
 
-    public static void storeTree(File src, JarOutputStream dst,
-                                  Filter<File> filter)
+    public static void storeTree(File src, JarOutputStream dst, boolean 
deflate,
+                                 Filter<File> filter)
         throws IOException
     {
-        storeTree(src, dst, filter, null);
+        storeTree(src, dst, deflate, filter, null);
     }
 
-    public static void storeTree(File src, JarOutputStream dst)
+    public static void storeTree(File src, JarOutputStream dst, boolean 
deflate)
         throws IOException
     {
-        storeTree(src, dst, null, null);
+        storeTree(src, dst, deflate, null, null);
     }
 
     public static interface Visitor<T> {
@@ -276,9 +277,11 @@ public final class Files {
         ByteArrayOutputStream baos;
         CheckedOutputStream cos;
         JarOutputStream jos;
+        boolean deflate;
         String path;
 
         private JarEntryOutputStream(JarOutputStream jos,
+                                     boolean deflate,
                                      CRC32 crc,
                                      ByteArrayOutputStream baos,
                                      CheckedOutputStream cos,
@@ -286,6 +289,7 @@ public final class Files {
         {
             super(cos);
             this.jos = jos;
+            this.deflate = deflate;
             this.crc = crc;
             this.baos = baos;
             this.cos = cos;
@@ -295,10 +299,14 @@ public final class Files {
         public void close() throws IOException {
             cos.close();
             JarEntry je = new JarEntry(path);
-            je.setMethod(JarEntry.STORED);
-            je.setCrc(crc.getValue());
-            je.setSize(baos.size());
-            je.setCompressedSize(baos.size());
+            if (deflate) {
+                je.setMethod(JarEntry.DEFLATED);
+            } else {
+                je.setMethod(JarEntry.STORED);
+                je.setCrc(crc.getValue());
+                je.setSize(baos.size());
+                je.setCompressedSize(baos.size());
+            }
             jos.putNextEntry(je);
             baos.writeTo(jos);
             jos.closeEntry();
@@ -307,13 +315,18 @@ public final class Files {
     }
 
     public static JarEntryOutputStream
-        newOutputStream(JarOutputStream jos, String path)
+        newOutputStream(JarOutputStream jos, boolean deflate, String path)
     {
         // Gee, dac, that zip API sure is broken, isn't it?
         CRC32 crc = new CRC32();
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         CheckedOutputStream cos = new CheckedOutputStream(baos, crc);
-        return new JarEntryOutputStream(jos, crc, baos, cos, path);
+        return new JarEntryOutputStream(jos, deflate, crc, baos, cos, path);
     }
 
+    public static JarEntryOutputStream
+        newOutputStream(JarOutputStream jos, String path)
+    {
+        return newOutputStream(jos, false, path);
+    }
 }
diff --git a/jdk/src/share/classes/org/openjdk/jigsaw/Launcher.java 
b/jdk/src/share/classes/org/openjdk/jigsaw/Launcher.java
index 5fe1d2d..d640e1e 100644
--- a/jdk/src/share/classes/org/openjdk/jigsaw/Launcher.java
+++ b/jdk/src/share/classes/org/openjdk/jigsaw/Launcher.java
@@ -44,7 +44,7 @@ public final class Launcher {
         throws IOException
     {
 
-        Library lb = SimpleLibrary.open(libPath, false);
+        Library lb = SimpleLibrary.open(libPath);
         ModuleId mid = lb.findLatestModuleId(midq);
         if (mid == null)
             throw new Error(midq + ": No installed module"
diff --git a/jdk/src/share/classes/org/openjdk/jigsaw/ModuleFile.java 
b/jdk/src/share/classes/org/openjdk/jigsaw/ModuleFile.java
index a60312f..235fa3c 100644
--- a/jdk/src/share/classes/org/openjdk/jigsaw/ModuleFile.java
+++ b/jdk/src/share/classes/org/openjdk/jigsaw/ModuleFile.java
@@ -60,6 +60,7 @@ public final class ModuleFile {
 
         private DataInputStream stream;
         private File destination;
+        private boolean deflate;
         private HashType hashtype;
 
         private static class CountingInputStream extends FilterInputStream {
@@ -179,12 +180,12 @@ public final class ModuleFile {
 
         public void readRest() throws IOException {
             extract = false;
-            readRest(null);
+            readRest(null, false);
         }
 
-        public void readRest(File dst) throws IOException {
-
-            destination = dst;
+        public void readRest(File dst, boolean deflate) throws IOException {
+            this.destination = dst;
+            this.deflate = deflate;
             try {
                 if (extract)
                     Files.store(moduleInfoBytes, computeRealPath("info"));
@@ -279,7 +280,7 @@ public final class ModuleFile {
 
         public void readModule(File dst) throws IOException {
             readStart();
-            readRest(dst);
+            readRest(dst, false);
         }
 
         private void readSignatureSection(DataInputStream stream,
@@ -508,6 +509,10 @@ public final class ModuleFile {
                     public void close() throws IOException {}
                 };
             Pack200.Unpacker unpacker = Pack200.newUnpacker();
+            if (deflate) {
+                Map<String,String> p = unpacker.properties();
+                p.put(Pack200.Unpacker.DEFLATE_HINT, Pack200.Unpacker.TRUE);
+            }
             unpacker.unpack(gis, contentStream());
         }
 
diff --git a/jdk/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java 
b/jdk/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java
index c942919..db16870 100644
--- a/jdk/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java
+++ b/jdk/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java
@@ -134,33 +134,51 @@ public final class SimpleLibrary
 
     }
 
+    /**
+     * Defines the storage options that SimpleLibrary supports.
+     */
+    public static enum StorageOption {
+        DEFLATED,
+    }
+
     private static final class Header
         extends MetaData
     {
-
-        private static String FILE
+        private static final String FILE
             = FileConstants.META_PREFIX + "jigsaw-library";
 
-        private static int MAJOR_VERSION = 0;
-        private static int MINOR_VERSION = 1;
+        private static final int MAJOR_VERSION = 0;
+        private static final int MINOR_VERSION = 1;
+
+        private static final int DEFLATED = 1 << 0;
 
         private File parent;
+        private Set<StorageOption> opts;
+
         public File parent() { return parent; }
+        public boolean isDeflated() {
+           return opts.contains(StorageOption.DEFLATED);
+        }
 
-        private Header(File root, File p) {
+        private Header(File root, File p, Set<StorageOption> opts) {
             super(MAJOR_VERSION, MINOR_VERSION,
                   FileConstants.Type.LIBRARY_HEADER,
                   new File(root, FILE));
             this.parent = p;
+            this.opts = new HashSet<>(opts);
         }
 
         private Header(File root) {
-            this(root, null);
+            this(root, null, Collections.<StorageOption>emptySet());
         }
 
         protected void storeRest(DataOutputStream out)
             throws IOException
         {
+            int flags = 0;
+            if (isDeflated())
+                flags |= DEFLATED;
+            out.writeShort(flags);
             out.writeByte((parent != null) ? 1 : 0);
             if (parent != null)
                 out.writeUTF(parent.toString());
@@ -169,6 +187,10 @@ public final class SimpleLibrary
         protected void loadRest(DataInputStream in)
             throws IOException
         {
+            opts = new HashSet<StorageOption>();
+            int flags = in.readShort();
+            if ((flags & DEFLATED) == DEFLATED)
+                opts.add(StorageOption.DEFLATED);
             int b = in.readByte();
             if (b != 0)
                 parent = new File(in.readUTF());
@@ -195,6 +217,7 @@ public final class SimpleLibrary
     public int majorVersion() { return hd.majorVersion; }
     public int minorVersion() { return hd.minorVersion; }
     public SimpleLibrary parent() { return parent; }
+    public boolean isDeflated() { return hd.isDeflated(); }
 
     private URI location = null;
     public URI location() {
@@ -210,7 +233,7 @@ public final class SimpleLibrary
                 + ", v" + hd.majorVersion + "." + hd.minorVersion + "]");
     }
 
-    private SimpleLibrary(File path, boolean create, File parentPath)
+    private SimpleLibrary(File path, boolean create, File parentPath, 
Set<StorageOption> opts)
         throws IOException
     {
         root = path;
@@ -233,27 +256,33 @@ public final class SimpleLibrary
         }
         if (!root.mkdirs())
             throw new IOException(root + ": Cannot create library directory");
-        hd = new Header(canonicalRoot, this.parentPath);
+        hd = new Header(canonicalRoot, this.parentPath, opts);
         hd.store();
     }
 
-    public static SimpleLibrary open(File path, boolean create, File parent)
+    public static SimpleLibrary create(File path, File parent, 
Set<StorageOption> opts)
         throws IOException
     {
-        return new SimpleLibrary(path, create, parent);
+        return new SimpleLibrary(path, true, parent, opts);
     }
 
-    public static SimpleLibrary open(File path, boolean create)
+    public static SimpleLibrary create(File path, File parent)
+        throws IOException 
+    {
+       return new SimpleLibrary(path, true, parent, 
Collections.<StorageOption>emptySet());
+    }
+
+    public static SimpleLibrary create(File path, Set<StorageOption> opts)
         throws IOException
     {
         // ## Should default parent to $JAVA_HOME/lib/modules
-        return new SimpleLibrary(path, create, null);
+        return new SimpleLibrary(path, true, null, opts);
     }
 
     public static SimpleLibrary open(File path)
         throws IOException
     {
-        return new SimpleLibrary(path, false, null);
+        return new SimpleLibrary(path, false, null, 
Collections.<StorageOption>emptySet());
     }
 
     private static final JigsawModuleSystem jms
@@ -795,7 +824,35 @@ public final class SimpleLibrary
         ix.store();
     }
 
-    private void install(Manifest mf, File dst)
+    /**
+     * Strip the debug attributes from the classes in a given module
+     * directory.
+     */
+    private void strip(File md) throws IOException {
+        File classes = new File(md, "classes"); 
+        if (classes.isFile()) {
+            File pf = new File(md, "classes.pack");
+            try (JarFile jf = new JarFile(classes);
+                FileOutputStream out = new FileOutputStream(pf)) 
+            {
+                Pack200.Packer packer = Pack200.newPacker();
+                Map<String,String> p = packer.properties();
+                p.put("com.sun.java.util.jar.pack.strip.debug", 
Pack200.Packer.TRUE);
+                packer.pack(jf, out);
+            }
+
+            try (OutputStream out = new FileOutputStream(classes);
+                 JarOutputStream jos = new JarOutputStream(out))
+            {
+               Pack200.Unpacker unpacker = Pack200.newUnpacker();
+                unpacker.unpack(pf, jos);
+            } finally {
+                pf.delete();
+           }
+        }
+    }
+
+    private void install(Manifest mf, File dst, boolean strip)
         throws IOException
     {
         if (mf.classes().size() > 1)
@@ -855,7 +912,6 @@ public final class SimpleLibrary
                     }});
             ix.store();
         } else {
-
             FileOutputStream fos
                 = new FileOutputStream(new File(mdst, "classes"));
             JarOutputStream jos
@@ -864,7 +920,7 @@ public final class SimpleLibrary
 
                 // Copy class files and build index
                 final Index ix = new Index(mdst);
-                Files.storeTree(src, jos, new Files.Filter<File>() {
+                Files.storeTree(src, jos, isDeflated(), new 
Files.Filter<File>() {
                         public boolean accept(File f) throws IOException {
                             if (f.isDirectory())
                                 return true;
@@ -878,28 +934,36 @@ public final class SimpleLibrary
             } finally {
                 jos.close();
             }
-
+            if (strip)
+                strip(mdst);
         }
 
     }
 
-    private void install(Collection<Manifest> mfs, File dst)
+    private void install(Collection<Manifest> mfs, File dst, boolean strip)
         throws IOException
     {
         for (Manifest mf : mfs)
-            install(mf, dst);
+            install(mf, dst, strip);
     }
 
-    public void installFromManifests(Collection<Manifest> mfs)
+    public void installFromManifests(Collection<Manifest> mfs, boolean strip)
         throws ConfigurationException, IOException
     {
-        install(mfs, root);
+        install(mfs, root, strip);
         configure(null);
     }
 
+    @Override
+    public void installFromManifests(Collection<Manifest> mfs)
+       throws ConfigurationException, IOException
+    {
+       installFromManifests(mfs, false);
+    }
+
     private ModuleFileVerifier.Parameters mfvParams;
 
-    private ModuleId install(InputStream is, boolean verifySignature)
+    private ModuleId install(InputStream is, boolean verifySignature, boolean 
strip)
         throws ConfigurationException, IOException, SignatureException
     {
         BufferedInputStream bin = new BufferedInputStream(is);
@@ -934,11 +998,14 @@ public final class SimpleLibrary
                 new Signers(md, signers).store();
 
                 // Read and verify the rest of the hashes
-                mr.readRest(md);
+                mr.readRest(md, isDeflated());
                 mfv.verifyHashesRest(mfvParams);
             } else {
-                mr.readRest(md);
+                mr.readRest(md, isDeflated());
             }
+ 
+            if (strip) 
+                strip(md);
             reIndex(mid);         // ## Could do this while reading module file
             return mid;
 
@@ -955,7 +1022,7 @@ public final class SimpleLibrary
         }
     }
 
-    private ModuleId installFromJarFile(File mf, boolean verifySignature)
+    private ModuleId installFromJarFile(File mf, boolean verifySignature, 
boolean strip)
         throws ConfigurationException, IOException, SignatureException
     {
         File md = null;
@@ -973,7 +1040,7 @@ public final class SimpleLibrary
 
             boolean signed = false;
 
-            // copy the jar file to the module library in STORED compression
+            // copy the jar file to the module library
             File classesDir = new File(md, "classes");
             try (FileOutputStream fos = new FileOutputStream(classesDir);
                  BufferedOutputStream bos = new BufferedOutputStream(fos);
@@ -1010,6 +1077,8 @@ public final class SimpleLibrary
                 throw new SignatureException(ce);
             }
 
+            if (strip)
+                strip(md);
             reIndex(mid);
             return mid;
         } catch (IOException | SignatureException x) {
@@ -1085,9 +1154,8 @@ public final class SimpleLibrary
         throws IOException, SignatureException
     {
         JarEntry entry = new JarEntry(je.getName());
-        entry.setMethod(ZipOutputStream.STORED);
+        entry.setMethod(isDeflated() ? ZipEntry.DEFLATED : ZipEntry.STORED);
         entry.setTime(je.getTime());
-        entry.setCrc(je.getCrc());
         try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
             int size = 0;
             byte[] bs = new byte[1024];
@@ -1097,8 +1165,11 @@ public final class SimpleLibrary
                 baos.write(bs, 0, cc);
                 size += cc;
             }
-            entry.setSize(size);
-            entry.setCompressedSize(size);
+            if (!isDeflated()) {
+                entry.setSize(size);
+                entry.setCrc(je.getCrc());
+                entry.setCompressedSize(size);
+            }
             jos.putNextEntry(entry);
             if (baos.size() > 0)
                 baos.writeTo(jos);
@@ -1108,17 +1179,21 @@ public final class SimpleLibrary
         }
     }
 
-    private ModuleId install(File mf, boolean verifySignature)
+    private ModuleId install(File mf, boolean verifySignature, boolean strip)
         throws ConfigurationException, IOException, SignatureException
     {
+        ModuleId mid;
         if (mf.getName().endsWith(".jar"))
-            return installFromJarFile(mf, verifySignature);
-        else
-            return install(new FileInputStream(mf), verifySignature);
-
+            mid = installFromJarFile(mf, verifySignature, strip);
+        else {
+            try (FileInputStream in = new FileInputStream(mf)) {
+                mid = install(in, verifySignature, strip);
+            }
+        }
+        return mid;
     }
 
-    public void install(Collection<File> mfs, boolean verifySignature)
+    public void install(Collection<File> mfs, boolean verifySignature, boolean 
strip)
         throws ConfigurationException, IOException, SignatureException
     {
         List<ModuleId> mids = new ArrayList<>();
@@ -1126,7 +1201,7 @@ public final class SimpleLibrary
         Throwable ox = null;
         try {
             for (File mf : mfs)
-                mids.add(install(mf, verifySignature));
+                mids.add(install(mf, verifySignature, strip));
             configure(mids);
             complete = true;
         } catch (IOException|ConfigurationException x) {
@@ -1146,6 +1221,13 @@ public final class SimpleLibrary
         }
     }
 
+    @Override
+    public void install(Collection<File> mfs, boolean verifySignature)
+        throws ConfigurationException, IOException, SignatureException
+    {
+       install(mfs, verifySignature, false);
+    }
+
     // Public entry point, since the Resolver itself is package-private
     //
     public Resolution resolve(Collection<ModuleIdQuery> midqs)
@@ -1154,10 +1236,9 @@ public final class SimpleLibrary
         return Resolver.run(this, midqs);
     }
 
-    public void install(Resolution res, boolean verifySignature)
+    public void install(Resolution res, boolean verifySignature, boolean strip)
         throws ConfigurationException, IOException, SignatureException
     {
-
         // ## Handle case of installing multiple root modules
         assert res.rootQueries.size() == 1;
         ModuleIdQuery midq = res.rootQueries.iterator().next();
@@ -1177,7 +1258,7 @@ public final class SimpleLibrary
             assert u != null;
             RemoteRepository rr = repositoryList().firstRepository();
             assert rr != null;
-            install(rr.fetch(mid), verifySignature);
+            install(rr.fetch(mid), verifySignature, strip);
             res.locationForName.put(mid.name(), location());
             // ## If something goes wrong, delete all our modules
         }
@@ -1187,7 +1268,13 @@ public final class SimpleLibrary
         Configuration<Context> cf
             = Configurator.configure(this, res);
         new StoredConfiguration(moduleDir(root.id()), cf).store();
+    }
 
+    @Override
+    public void install(Resolution res, boolean verifySignature)
+        throws ConfigurationException, IOException, SignatureException
+    {
+       install(res, verifySignature, false);
     }
 
     /**
@@ -1211,7 +1298,7 @@ public final class SimpleLibrary
         throws IOException
     {
         Files.mkdirs(dst, "module destination");
-        install(mfs, dst);
+        install(mfs, dst, false);
     }
 
     public void preInstall(Manifest mf, File dst)
diff --git a/jdk/src/share/classes/org/openjdk/jigsaw/cli/Librarian.java 
b/jdk/src/share/classes/org/openjdk/jigsaw/cli/Librarian.java
index 37bdbf6..28cc660 100644
--- a/jdk/src/share/classes/org/openjdk/jigsaw/cli/Librarian.java
+++ b/jdk/src/share/classes/org/openjdk/jigsaw/cli/Librarian.java
@@ -38,6 +38,7 @@ import static java.lang.System.out;
 import static java.lang.System.err;
 
 import org.openjdk.jigsaw.*;
+import org.openjdk.jigsaw.SimpleLibrary.StorageOption;
 import org.openjdk.internal.joptsimple.*;
 
 
@@ -128,7 +129,7 @@ public class Librarian {
                     Path path = classes.toPath();
                     Files.deleteIfExists(path);
                     Files.createDirectory(path);
-                    reader.readRest(classes);
+                    reader.readRest(classes, false);
                 }
                 catch (IOException x) {
                     // Try to cleanup if an exception is thrown
@@ -154,6 +155,7 @@ public class Librarian {
             String key = takeArg();
             File kf = new File(key);
             boolean verifySignature = !opts.has("noverify");
+            boolean strip = opts.has("G");
 
             // Old form: install <classes-dir> <module-name> ...
             //
@@ -164,7 +166,7 @@ public class Librarian {
                     mfs.add(Manifest.create(takeArg(), kf));
                 finishArgs();
                 try {
-                    lib.installFromManifests(mfs);
+                    lib.installFromManifests(mfs, strip);
                 } catch (ConfigurationException x) {
                     throw new Command.Exception(x);
                 } catch (IOException x) {
@@ -183,7 +185,7 @@ public class Librarian {
                     fs.add(new File(takeArg()));
                 finishArgs();
                 try {
-                    lib.install(fs, verifySignature);
+                    lib.install(fs, verifySignature, strip);
                 } catch (ConfigurationException x) {
                     throw new Command.Exception(x);
                 } catch (IOException x) {
@@ -228,7 +230,7 @@ public class Librarian {
                 }
                 if (dry)
                     return;
-                lib.install(res, verifySignature);
+                lib.install(res, verifySignature, strip);
             } catch (ConfigurationException x) {
                 throw new Command.Exception(x);
             } catch (IOException x) {
@@ -505,7 +507,6 @@ public class Librarian {
     }
 
     private void exec(String[] args) throws OptionException, Command.Exception 
{
-
         parser = new OptionParser();
 
         // ## Need subcommand-specific option parsing
@@ -530,6 +531,8 @@ public class Librarian {
                           "Show this help message");
         parser.acceptsAll(Arrays.asList("p", "parent"),
                           "Apply operation to parent library, if any");
+        parser.acceptsAll(Arrays.asList("z", "enable-compression"),
+                          "Enable compression of module contents");
         repoIndex
             = (parser.acceptsAll(Arrays.asList("i"),
                                  "Repository-list index")
@@ -545,6 +548,8 @@ public class Librarian {
         parser.acceptsAll(Arrays.asList("noverify"),
                           "Do not verify module signatures. "
                           + "Treat as unsigned.");
+        parser.acceptsAll(Arrays.asList("G", "strip-debug"),
+                          "Strip debug attributes during installation");
         
         if (args.length == 0)
             usage();
@@ -580,7 +585,14 @@ public class Librarian {
         }
         SimpleLibrary lib = null;
         try {
-            lib = SimpleLibrary.open(lp, verb.equals("create"), pp);
+            if (verb.equals("create")) {
+                Set<StorageOption> createOpts = new HashSet<>();
+                if (opts.has("z"))
+                    createOpts.add(StorageOption.DEFLATED);
+                lib = SimpleLibrary.create(lp, pp, createOpts);
+            } else {
+                lib = SimpleLibrary.open(lp);
+            }
         } catch (FileNotFoundException x) {
             String msg = null;
             File f = new File(x.getMessage());
diff --git a/jdk/src/share/classes/org/openjdk/jigsaw/cli/Packager.java 
b/jdk/src/share/classes/org/openjdk/jigsaw/cli/Packager.java
index b358be3..ec21946 100644
--- a/jdk/src/share/classes/org/openjdk/jigsaw/cli/Packager.java
+++ b/jdk/src/share/classes/org/openjdk/jigsaw/cli/Packager.java
@@ -34,6 +34,7 @@ import static java.lang.System.out;
 import static java.lang.System.err;
 
 import org.openjdk.jigsaw.*;
+import org.openjdk.jigsaw.SimpleLibrary.StorageOption;
 import org.openjdk.internal.joptsimple.*;
 
 /* Interface:
@@ -182,7 +183,7 @@ public class Packager {
                 }
             }
             finishArgs();
-        }       
+        }
     }
 
     static private ModuleInfo getModuleInfo(Manifest mf)
@@ -237,15 +238,15 @@ public class Packager {
             try {
 
                 createModuleLibraryWorkDir();
-
+                Set<StorageOption> opts = Collections.emptySet();
                 if (BOOT_MODULE.equals(manifest.module())) {
                     // Create a module library to the boot module package
-                    SimpleLibrary.open(tmp_module_dst, true, 
null).installFromManifests(Collections.singleton(manifest));
+                    SimpleLibrary.create(tmp_module_dst, 
opts).installFromManifests(Collections.singleton(manifest));
                 } else {
                     // We need to create a throwaway SimpleLibrary to work 
with it,
                     // As there is no static preInstall method
                     File scratchlib_dst = new File(tmp_dst, "scratchlib");
-                    SimpleLibrary.open(scratchlib_dst, true, 
null).preInstall(manifest, tmp_module_dst);
+                    SimpleLibrary.create(scratchlib_dst, 
opts).preInstall(manifest, tmp_module_dst);
                     Files.deleteTree(scratchlib_dst);
                 }
             } catch (IOException | ConfigurationException x) {
@@ -814,7 +815,7 @@ public class Packager {
         else if (cmd == Jmod.class)
             (new Jmod()).run(null, opts);
     }
-   
+
     /**
      * Helper method to check if a path exists before using it further.
      *
diff --git a/jdk/test/org/openjdk/jigsaw/InstallFromRepo.java 
b/jdk/test/org/openjdk/jigsaw/InstallFromRepo.java
index 6848fa8..03e97d4 100644
--- a/jdk/test/org/openjdk/jigsaw/InstallFromRepo.java
+++ b/jdk/test/org/openjdk/jigsaw/InstallFromRepo.java
@@ -47,8 +47,8 @@ public class InstallFromRepo {
     static void test(int port) throws Exception {
 
         URI u = URI.create("http://localhost:"; + port);
-        Library lib = SimpleLibrary.open(LIB, true,
-                                         Library.systemLibraryPath());
+        Library lib = SimpleLibrary.create(LIB,
+                                           Library.systemLibraryPath());
         RemoteRepositoryList rrl = lib.repositoryList();
         rrl.add(u, 0);
 
diff --git a/jdk/test/org/openjdk/jigsaw/_Library.java 
b/jdk/test/org/openjdk/jigsaw/_Library.java
index ffa53ec..78f9d9d 100644
--- a/jdk/test/org/openjdk/jigsaw/_Library.java
+++ b/jdk/test/org/openjdk/jigsaw/_Library.java
@@ -67,7 +67,7 @@ public class _Library {
         // Create
         File jhlib = new File(System.getProperty("java.home"),
                               "lib/modules");
-        Library lib = SimpleLibrary.open(libPath, true, jhlib);
+        Library lib = SimpleLibrary.create(libPath, jhlib);
         out.format("%s%n", lib);
 
         // Check
@@ -232,7 +232,7 @@ public class _Library {
 
         // Delegation
         File lib2path = new File("z.lib2");
-        Library lib2 = SimpleLibrary.open(lib2path, true, libPath);
+        Library lib2 = SimpleLibrary.create(lib2path, libPath);
         lib2 = SimpleLibrary.open(lib2path);
         eq(lib2.findModuleIds("com.foo.bar"), Arrays.asList(foomid));
         eq(lib2.findModuleIds("net.baz.aar"), Arrays.asList(bazmid));
diff --git a/jdk/test/org/openjdk/jigsaw/_RemoteRepositoryList.java 
b/jdk/test/org/openjdk/jigsaw/_RemoteRepositoryList.java
index f646781..c262237 100644
--- a/jdk/test/org/openjdk/jigsaw/_RemoteRepositoryList.java
+++ b/jdk/test/org/openjdk/jigsaw/_RemoteRepositoryList.java
@@ -33,6 +33,7 @@ import java.nio.*;
 import java.nio.channels.*;
 import java.nio.file.*;
 import org.openjdk.jigsaw.*;
+import org.openjdk.jigsaw.SimpleLibrary.StorageOption;
 
 import static java.lang.System.out;
 import static java.nio.file.StandardOpenOption.*;
@@ -126,7 +127,8 @@ public class _RemoteRepositoryList {
     static void testAddRemove(int port) throws Exception {
 
         File LIB = new File("z.lib.addrem");
-        Library lib = SimpleLibrary.open(LIB, true);
+        Set<StorageOption> opts = Collections.emptySet();
+        Library lib = SimpleLibrary.create(LIB, opts);
         RemoteRepositoryList rl = lib.repositoryList();
         assert rl.repositories().isEmpty();
 
@@ -172,7 +174,8 @@ public class _RemoteRepositoryList {
         File LIB = new File("z.lib.fetch");
         URI u = URI.create("http://localhost:"; + port);
 
-        Library lib = SimpleLibrary.open(LIB, true);
+        Set<StorageOption> opts = Collections.emptySet();
+        Library lib = SimpleLibrary.create(LIB, opts);
         RemoteRepositoryList rl = lib.repositoryList();
         rl.add(u, 0);
 
diff --git a/jdk/test/org/openjdk/jigsaw/cli/jmod-basic.sh 
b/jdk/test/org/openjdk/jigsaw/cli/jmod-basic.sh
index 3e7db45..7e0631e 100644
--- a/jdk/test/org/openjdk/jigsaw/cli/jmod-basic.sh
+++ b/jdk/test/org/openjdk/jigsaw/cli/jmod-basic.sh
@@ -63,14 +63,31 @@ EOF
 rm -rf z.modules && mkdir z.modules
 $BIN/javac -source 8 -d z.modules -modulepath z.modules `find z.src -name 
'*.java'`
 
-rm -rf z.lib
 JAVA_MODULES=z.lib
 export JAVA_MODULES
-$BIN/jmod create
-$BIN/jmod id
-$BIN/jmod install z.modules com.foo.bar
-$BIN/jmod install z.modules com.foo.byz
-$BIN/jmod list
-$BIN/jmod list -v
-$BIN/jmod dump-class com.foo.bar@1.2.3_01-4a com.foo.bar.Main z
-cmp z z.modules/com.foo.bar/com/foo/bar/Main.class
+
+testjmod() {
+  createargs=$1
+  installargs=$2
+  rm -rf $JAVA_MODULES
+  $BIN/jmod create $createargs
+  $BIN/jmod id
+  $BIN/jmod install $installargs z.modules com.foo.bar
+  $BIN/jmod install $installargs z.modules com.foo.byz
+  $BIN/jmod list
+  $BIN/jmod list -v
+  $BIN/jmod dump-class com.foo.bar@1.2.3_01-4a com.foo.bar.Main z
+  if [ "$installargs" = "" ]; then
+    cmp z z.modules/com.foo.bar/com/foo/bar/Main.class 
+  fi
+}
+
+# Test combinations of compressed/uncompressed module library and
+# debug attributes stripped/not stripped during installation
+# debug attributes stripped.
+testjmod
+testjmod -z
+testjmod --enable-compression
+testjmod "" -G
+testjmod "" --strip-debug
+testjmod -z -G

-- 
jigsaw packaging

_______________________________________________
pkg-java-commits mailing list
pkg-java-comm...@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

Reply via email to