This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 2b2ac4f3ce99027d8589595e921570495f7b08c0 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Sep 24 21:47:09 2020 +0100 Reduce memory footprint of closed http/2 streams This refactoring replaces closed streams with a new RecycledStream object and changes the mechanism used to look up known streams. Pull up state --- .../apache/coyote/http2/AbstractNonZeroStream.java | 21 ++++++++++++++++----- java/org/apache/coyote/http2/RecycledStream.java | 16 +--------------- java/org/apache/coyote/http2/Stream.java | 16 +--------------- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/java/org/apache/coyote/http2/AbstractNonZeroStream.java b/java/org/apache/coyote/http2/AbstractNonZeroStream.java index 582ab1e..084de33 100644 --- a/java/org/apache/coyote/http2/AbstractNonZeroStream.java +++ b/java/org/apache/coyote/http2/AbstractNonZeroStream.java @@ -31,17 +31,22 @@ abstract class AbstractNonZeroStream extends AbstractStream { private static final Log log = LogFactory.getLog(AbstractNonZeroStream.class); private static final StringManager sm = StringManager.getManager(AbstractNonZeroStream.class); + protected final StreamStateMachine state; + private volatile int weight; - AbstractNonZeroStream(Integer identifier) { - this(identifier, Constants.DEFAULT_WEIGHT); + AbstractNonZeroStream(String connectionId, Integer identifier) { + super(identifier); + this.weight = Constants.DEFAULT_WEIGHT; + this.state = new StreamStateMachine(connectionId, getIdAsString()); } - AbstractNonZeroStream(Integer identifier, int weight) { + AbstractNonZeroStream(Integer identifier, int weight, StreamStateMachine state) { super(identifier); this.weight = weight; + this.state = state; } @@ -97,7 +102,13 @@ abstract class AbstractNonZeroStream extends AbstractStream { this.weight = weight; } - abstract boolean isClosedFinal(); - abstract void checkState(FrameType frameType) throws Http2Exception; + final boolean isClosedFinal() { + return state.isClosedFinal(); + } + + + final void checkState(FrameType frameType) throws Http2Exception { + state.checkFrameType(frameType); + } } diff --git a/java/org/apache/coyote/http2/RecycledStream.java b/java/org/apache/coyote/http2/RecycledStream.java index 1915dff..9d6177c 100644 --- a/java/org/apache/coyote/http2/RecycledStream.java +++ b/java/org/apache/coyote/http2/RecycledStream.java @@ -23,12 +23,10 @@ package org.apache.coyote.http2; class RecycledStream extends AbstractNonZeroStream { private final String connectionId; - private final StreamStateMachine state; RecycledStream(String connectionId, Integer identifier, int weight, StreamStateMachine state) { - super(identifier, weight); + super(identifier, weight, state); this.connectionId = connectionId; - this.state = state; } @@ -38,18 +36,6 @@ class RecycledStream extends AbstractNonZeroStream { } - @Override - boolean isClosedFinal() { - return state.isClosedFinal(); - } - - - @Override - final void checkState(FrameType frameType) throws Http2Exception { - state.checkFrameType(frameType); - } - - @SuppressWarnings("sync-override") @Override void incrementWindowSize(int increment) throws Http2Exception { diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index f6210d7..140a76d 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -69,7 +69,6 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { private volatile long contentLengthReceived = 0; private final Http2UpgradeHandler handler; - private final StreamStateMachine state; private final WindowAllocationManager allocationManager = new WindowAllocationManager(this); // State machine would be too much overhead @@ -93,11 +92,10 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { Stream(Integer identifier, Http2UpgradeHandler handler, Request coyoteRequest) { - super(identifier); + super(handler.getConnectionId(), identifier); this.handler = handler; handler.addChild(this); setWindowSize(handler.getRemoteSettings().getInitialWindowSize()); - state = new StreamStateMachine(getConnectionId(), getIdAsString()); if (coyoteRequest == null) { // HTTP/2 new request this.coyoteRequest = new Request(); @@ -194,12 +192,6 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { @Override - final void checkState(FrameType frameType) throws Http2Exception { - state.checkFrameType(frameType); - } - - - @Override final synchronized void incrementWindowSize(int windowSizeIncrement) throws Http2Exception { // If this is zero then any thread that has been trying to write for // this stream will be waiting. Notify that thread it can continue. Use @@ -647,12 +639,6 @@ class Stream extends AbstractNonZeroStream implements HeaderEmitter { } - @Override - final boolean isClosedFinal() { - return state.isClosedFinal(); - } - - final void closeIfIdle() { state.closeIfIdle(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org