6661861: Decrease memory use of Inflaters by ZipFile
authorbristor
Mon, 08 Sep 2008 13:44:32 -0700
changeset 1158 34d64e750f8e
parent 1157 cbfe7dbaf365
child 1159 ef22d0ad63bf
6661861: Decrease memory use of Inflaters by ZipFile Summary: Fix allows release of native resources earlier than without fix Reviewed-by: alanb
jdk/src/share/classes/java/util/zip/Inflater.java
jdk/src/share/classes/java/util/zip/ZipFile.java
--- a/jdk/src/share/classes/java/util/zip/Inflater.java	Thu Sep 04 14:55:12 2008 -0700
+++ b/jdk/src/share/classes/java/util/zip/Inflater.java	Mon Sep 08 13:44:32 2008 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -73,11 +73,13 @@
 public
 class Inflater {
     private long strm;
-    private byte[] buf = new byte[0];
+    private byte[] buf = defaultBuf;
     private int off, len;
     private boolean finished;
     private boolean needDict;
 
+    private static final byte[] defaultBuf = new byte[0];
+
     static {
         /* Zip library is loaded from System.initializeSystemClass */
         initIDs();
@@ -318,6 +320,7 @@
     public synchronized void reset() {
         ensureOpen();
         reset(strm);
+        buf = defaultBuf;
         finished = false;
         needDict = false;
         off = len = 0;
--- a/jdk/src/share/classes/java/util/zip/ZipFile.java	Thu Sep 04 14:55:12 2008 -0700
+++ b/jdk/src/share/classes/java/util/zip/ZipFile.java	Mon Sep 08 13:44:32 2008 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1995-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -278,7 +278,6 @@
             int size = inflaters.size();
             if (size > 0) {
                 Inflater inf = (Inflater)inflaters.remove(size - 1);
-                inf.reset();
                 return inf;
             } else {
                 return new Inflater(true);
@@ -291,6 +290,7 @@
      */
     private void releaseInflater(Inflater inf) {
         synchronized (inflaters) {
+            inf.reset();
             inflaters.add(inf);
         }
     }