Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5D776E434 for ; Sat, 2 Feb 2013 10:37:38 +0000 (UTC) Received: (qmail 91630 invoked by uid 500); 2 Feb 2013 10:37:38 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 91609 invoked by uid 99); 2 Feb 2013 10:37:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Feb 2013 10:37:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Feb 2013 10:37:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1DFAF2388980; Sat, 2 Feb 2013 10:37:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1441727 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/CHANGES.txt lucene/core/ lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java Date: Sat, 02 Feb 2013 10:37:13 -0000 To: commits@lucene.apache.org From: uschindler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130202103714.1DFAF2388980@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: uschindler Date: Sat Feb 2 10:37:13 2013 New Revision: 1441727 URL: http://svn.apache.org/viewvc?rev=1441727&view=rev Log: Merged revision(s) 1441726 from lucene/dev/trunk: LUCENE-4740: Don't track clones of MMapIndexInput if unmapping is disabled. This reduces GC overhead. Modified: lucene/dev/branches/branch_4x/ (props changed) lucene/dev/branches/branch_4x/lucene/ (props changed) lucene/dev/branches/branch_4x/lucene/CHANGES.txt (contents, props changed) lucene/dev/branches/branch_4x/lucene/core/ (props changed) lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1441727&r1=1441726&r2=1441727&view=diff ============================================================================== --- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original) +++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Sat Feb 2 10:37:13 2013 @@ -51,6 +51,9 @@ Optimizations facets. Also added OrdinalPolicy.ALL_BUT_DIMENSION. (Shai Erera, Michael McCandless) +* LUCENE-4740: Don't track clones of MMapIndexInput if unmapping + is disabled. This reduces GC overhead. (Kristofer Karlsson, Uwe Schindler) + New Features * LUCENE-4686: New specialized DGapVInt8IntEncoder for facets (now the Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java?rev=1441727&r1=1441726&r2=1441727&view=diff ============================================================================== --- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java (original) +++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java Sat Feb 2 10:37:13 2013 @@ -51,14 +51,15 @@ abstract class ByteBufferIndexInput exte private ByteBuffer curBuf; // redundant for speed: buffers[curBufIndex] private boolean isClone = false; - private final WeakIdentityMap clones = WeakIdentityMap.newConcurrentHashMap(); + private final WeakIdentityMap clones; - ByteBufferIndexInput(String resourceDescription, ByteBuffer[] buffers, long length, int chunkSizePower) throws IOException { + ByteBufferIndexInput(String resourceDescription, ByteBuffer[] buffers, long length, int chunkSizePower, boolean trackClones) throws IOException { super(resourceDescription); this.buffers = buffers; this.length = length; this.chunkSizePower = chunkSizePower; this.chunkSizeMask = (1L << chunkSizePower) - 1L; + this.clones = trackClones ? WeakIdentityMap.newConcurrentHashMap() : null; assert chunkSizePower >= 0 && chunkSizePower <= 30; assert (length >>> chunkSizePower) < Integer.MAX_VALUE; @@ -231,7 +232,9 @@ abstract class ByteBufferIndexInput exte clone.length = length; // register the new clone in our clone list to clean it up on closing: - this.clones.put(clone, Boolean.TRUE); + if (clones != null) { + this.clones.put(clone, Boolean.TRUE); + } return clone; } @@ -272,17 +275,21 @@ abstract class ByteBufferIndexInput exte // make local copy, then un-set early final ByteBuffer[] bufs = buffers; unsetBuffers(); - clones.remove(this); + if (clones != null) { + clones.remove(this); + } if (isClone) return; // for extra safety unset also all clones' buffers: - for (Iterator it = this.clones.keyIterator(); it.hasNext();) { - final ByteBufferIndexInput clone = it.next(); - assert clone.isClone; - clone.unsetBuffers(); + if (clones != null) { + for (Iterator it = this.clones.keyIterator(); it.hasNext();) { + final ByteBufferIndexInput clone = it.next(); + assert clone.isClone; + clone.unsetBuffers(); + } + this.clones.clear(); } - this.clones.clear(); for (final ByteBuffer b : bufs) { freeBuffer(b); Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java?rev=1441727&r1=1441726&r2=1441727&view=diff ============================================================================== --- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java (original) +++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java Sat Feb 2 10:37:13 2013 @@ -178,36 +178,6 @@ public class MMapDirectory extends FSDir } /** - * Try to unmap the buffer, this method silently fails if no support - * for that in the JVM. On Windows, this leads to the fact, - * that mmapped files cannot be modified or deleted. - */ - final void cleanMapping(final ByteBuffer buffer) throws IOException { - if (useUnmapHack) { - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Object run() throws Exception { - final Method getCleanerMethod = buffer.getClass() - .getMethod("cleaner"); - getCleanerMethod.setAccessible(true); - final Object cleaner = getCleanerMethod.invoke(buffer); - if (cleaner != null) { - cleaner.getClass().getMethod("clean") - .invoke(cleaner); - } - return null; - } - }); - } catch (PrivilegedActionException e) { - final IOException ioe = new IOException("unable to unmap the mapped buffer"); - ioe.initCause(e.getCause()); - throw ioe; - } - } - } - - /** * Returns the current mmap chunk size. * @see #MMapDirectory(File, LockFactory, int) */ @@ -252,14 +222,42 @@ public class MMapDirectory extends FSDir } private final class MMapIndexInput extends ByteBufferIndexInput { + private final boolean useUnmapHack; MMapIndexInput(String resourceDescription, RandomAccessFile raf) throws IOException { - super(resourceDescription, map(raf, 0, raf.length()), raf.length(), chunkSizePower); + super(resourceDescription, map(raf, 0, raf.length()), raf.length(), chunkSizePower, getUseUnmap()); + this.useUnmapHack = getUseUnmap(); } + /** + * Try to unmap the buffer, this method silently fails if no support + * for that in the JVM. On Windows, this leads to the fact, + * that mmapped files cannot be modified or deleted. + */ @Override - protected void freeBuffer(ByteBuffer buffer) throws IOException { - cleanMapping(buffer); + protected void freeBuffer(final ByteBuffer buffer) throws IOException { + if (useUnmapHack) { + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + final Method getCleanerMethod = buffer.getClass() + .getMethod("cleaner"); + getCleanerMethod.setAccessible(true); + final Object cleaner = getCleanerMethod.invoke(buffer); + if (cleaner != null) { + cleaner.getClass().getMethod("clean") + .invoke(cleaner); + } + return null; + } + }); + } catch (PrivilegedActionException e) { + final IOException ioe = new IOException("unable to unmap the mapped buffer"); + ioe.initCause(e.getCause()); + throw ioe; + } + } } }