You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/02/13 18:26:54 UTC
httpcomponents-core git commit: ExpandableBuffer breaks on large
response
Repository: httpcomponents-core
Updated Branches:
refs/heads/master 7bcb19686 -> a96f30b90
ExpandableBuffer breaks on large response
Ticket: https://issues.apache.org/jira/browse/HTTPCORE-513
This closes #58
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/a96f30b9
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/a96f30b9
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/a96f30b9
Branch: refs/heads/master
Commit: a96f30b9072904e346272d2262c01c76a08f7ebb
Parents: 7bcb196
Author: imoldovan-intacct <im...@intacct.com>
Authored: Mon Feb 12 17:02:06 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Feb 13 19:23:23 2018 +0100
----------------------------------------------------------------------
.../hc/core5/http/impl/nio/ExpandableBuffer.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a96f30b9/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java
index e83e987..33699c4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ExpandableBuffer.java
@@ -110,7 +110,19 @@ public class ExpandableBuffer {
protected void expand() {
int newcapacity = (this.buffer.capacity() + 1) << 1;
if (newcapacity < 0) {
- newcapacity = Integer.MAX_VALUE;
+ final int vmBytes = Long.SIZE >> 3;
+ final int javaBytes = 8; // this is to be checked when the JVM version changes
+ @SuppressWarnings("unused") // we really need the 8 if we're going to make this foolproof
+ final int headRoom = (vmBytes >= javaBytes) ? vmBytes : javaBytes;
+ // Reason: In GC the size of objects is passed as int (2 bytes).
+ // Then, the header size of the objects is added to the size.
+ // Long has the longest header available. Object header seems to be linked to it.
+ // Details: I added a minimum of 8 just to be safe and because 8 is used in
+ // java.lang.Object.ArrayList: private static final int MAX_ARRAY_SIZE = 2147483639.
+ //
+ // WARNING: This code assumes you are providing enough heap room with -Xmx.
+ // source of inspiration: https://bugs.openjdk.java.net/browse/JDK-8059914
+ newcapacity = Integer.MAX_VALUE - headRoom;
}
expandCapacity(newcapacity);
}