From ed7c78ce6d903a46649522ec5d0b21e79e799542 Mon Sep 17 00:00:00 2001 From: gf2121 <52390227+gf2121@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:30:09 +0800 Subject: [PATCH] LUCENE-10366: Override #readVInt and #readVLong for ByteBufferDataInput to avoid the abstraction confusion of #readByte. (#592) --- lucene/CHANGES.txt | 2 ++ .../apache/lucene/store/ByteBufferIndexInput.java | 14 +++++++++++++- .../lucene/store/MemorySegmentIndexInput.java | 12 ++++++++++++ .../lucene/store/MemorySegmentIndexInput.java | 12 ++++++++++++ .../lucene/store/MemorySegmentIndexInput.java | 12 ++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 46c1a42679f..89edb6e5b90 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -205,6 +205,8 @@ Improvements Optimizations --------------------- +* LUCENE-10366: Override readVInt() and readVLong() in ByteBufferDataInput to help Hotspot inline method. (Guo Feng) + * GITHUB#12839: Introduce method to grow arrays up to a given upper limit and use it to reduce overallocation for DirectoryTaxonomyReader#getBulkOrdinals. (Stefan Vodita) diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java index 77840df9ed6..6d6040bd437 100644 --- a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java +++ b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java @@ -159,7 +159,7 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA } @Override - public void readLongs(long[] dst, int offset, int length) throws IOException { + public final void readLongs(long[] dst, int offset, int length) throws IOException { // ByteBuffer#getLong could work but it has some per-long overhead and there // is no ByteBuffer#getLongs to read multiple longs at once. So we use the // below trick in order to be able to leverage LongBuffer#get(long[]) to @@ -283,6 +283,18 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA } } + @Override + public final int readVInt() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVInt(); + } + + @Override + public final long readVLong() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVLong(); + } + @Override public final long readLong() throws IOException { try { diff --git a/lucene/core/src/java19/org/apache/lucene/store/MemorySegmentIndexInput.java b/lucene/core/src/java19/org/apache/lucene/store/MemorySegmentIndexInput.java index 72c7d69a1f2..ff2ab999319 100644 --- a/lucene/core/src/java19/org/apache/lucene/store/MemorySegmentIndexInput.java +++ b/lucene/core/src/java19/org/apache/lucene/store/MemorySegmentIndexInput.java @@ -254,6 +254,18 @@ abstract class MemorySegmentIndexInput extends IndexInput implements RandomAcces } } + @Override + public final int readVInt() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVInt(); + } + + @Override + public final long readVLong() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVLong(); + } + @Override public final long readLong() throws IOException { try { diff --git a/lucene/core/src/java20/org/apache/lucene/store/MemorySegmentIndexInput.java b/lucene/core/src/java20/org/apache/lucene/store/MemorySegmentIndexInput.java index c8eec75249d..ba890d8056c 100644 --- a/lucene/core/src/java20/org/apache/lucene/store/MemorySegmentIndexInput.java +++ b/lucene/core/src/java20/org/apache/lucene/store/MemorySegmentIndexInput.java @@ -252,6 +252,18 @@ abstract class MemorySegmentIndexInput extends IndexInput implements RandomAcces } } + @Override + public final int readVInt() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVInt(); + } + + @Override + public final long readVLong() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVLong(); + } + @Override public final long readLong() throws IOException { try { diff --git a/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java b/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java index c8eec75249d..ba890d8056c 100644 --- a/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java +++ b/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java @@ -252,6 +252,18 @@ abstract class MemorySegmentIndexInput extends IndexInput implements RandomAcces } } + @Override + public final int readVInt() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVInt(); + } + + @Override + public final long readVLong() throws IOException { + // this can make JVM less confused (see LUCENE-10366) + return super.readVLong(); + } + @Override public final long readLong() throws IOException { try {