提交 bdaaed33 编写于 作者: B bristor

6661861: Decrease memory use of Inflaters by ZipFile

Summary: Fix allows release of native resources earlier than without fix
Reviewed-by: alanb
上级 9d7206b9
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -73,11 +73,13 @@ package java.util.zip; ...@@ -73,11 +73,13 @@ package java.util.zip;
public public
class Inflater { class Inflater {
private long strm; private long strm;
private byte[] buf = new byte[0]; private byte[] buf = defaultBuf;
private int off, len; private int off, len;
private boolean finished; private boolean finished;
private boolean needDict; private boolean needDict;
private static final byte[] defaultBuf = new byte[0];
static { static {
/* Zip library is loaded from System.initializeSystemClass */ /* Zip library is loaded from System.initializeSystemClass */
initIDs(); initIDs();
...@@ -318,6 +320,7 @@ class Inflater { ...@@ -318,6 +320,7 @@ class Inflater {
public synchronized void reset() { public synchronized void reset() {
ensureOpen(); ensureOpen();
reset(strm); reset(strm);
buf = defaultBuf;
finished = false; finished = false;
needDict = false; needDict = false;
off = len = 0; off = len = 0;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -278,7 +278,6 @@ class ZipFile implements ZipConstants { ...@@ -278,7 +278,6 @@ class ZipFile implements ZipConstants {
int size = inflaters.size(); int size = inflaters.size();
if (size > 0) { if (size > 0) {
Inflater inf = (Inflater)inflaters.remove(size - 1); Inflater inf = (Inflater)inflaters.remove(size - 1);
inf.reset();
return inf; return inf;
} else { } else {
return new Inflater(true); return new Inflater(true);
...@@ -291,6 +290,7 @@ class ZipFile implements ZipConstants { ...@@ -291,6 +290,7 @@ class ZipFile implements ZipConstants {
*/ */
private void releaseInflater(Inflater inf) { private void releaseInflater(Inflater inf) {
synchronized (inflaters) { synchronized (inflaters) {
inf.reset();
inflaters.add(inf); inflaters.add(inf);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册