This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit b69d0c7fdf2e6c40d0d77819daffeff75dfcc296 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 | 20 +++----------------- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/java/org/apache/coyote/http2/AbstractNonZeroStream.java b/java/org/apache/coyote/http2/AbstractNonZeroStream.java index e1764a1..bad3b76 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 7d408ea..e6f90f0 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 protected 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 260ce54..22d62ed 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -66,7 +66,6 @@ public 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 @@ -90,11 +89,10 @@ public class Stream extends AbstractNonZeroStream implements HeaderEmitter { public 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(); @@ -192,13 +190,7 @@ public class Stream extends AbstractNonZeroStream implements HeaderEmitter { @Override - final void checkState(FrameType frameType) throws Http2Exception { - state.checkFrameType(frameType); - } - - - @Override - protected synchronized void incrementWindowSize(int windowSizeIncrement) throws Http2Exception { + protected 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 // notify all even though only one thread is waiting to be on the safe @@ -613,13 +605,7 @@ public class Stream extends AbstractNonZeroStream implements HeaderEmitter { } - @Override - final boolean isClosedFinal() { - return state.isClosedFinal(); - } - - - void closeIfIdle() { + final void closeIfIdle() { state.closeIfIdle(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org