diff --git a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java index fbb7bdb2b5f6..2973005ea8af 100644 --- a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java +++ b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java @@ -54,8 +54,8 @@ public class Parser private int maxSettingsKeys = SettingsFrame.DEFAULT_MAX_KEYS; private boolean continuation; private State state = State.HEADER; - private long beginNanoTime = Long.MIN_VALUE; - private boolean nanoTimeRead = true; + private long beginNanoTime; + private boolean nanoTimeStored; public Parser(ByteBufferPool bufferPool, int maxHeaderSize) { @@ -66,11 +66,7 @@ public Parser(ByteBufferPool bufferPool, int maxHeaderSize, RateControl rateCont { this.bufferPool = bufferPool; this.headerParser = new HeaderParser(rateControl == null ? RateControl.NO_RATE_CONTROL : rateControl); - this.hpackDecoder = new HpackDecoder(maxHeaderSize, () -> - { - nanoTimeRead = true; - return beginNanoTime; - }); + this.hpackDecoder = new HpackDecoder(maxHeaderSize, this::loadAndClearBeginNanoTime); this.bodyParsers = new BodyParser[FrameType.values().length]; } @@ -108,18 +104,22 @@ private void reset() { headerParser.reset(); state = State.HEADER; - beginNanoTime = Long.MIN_VALUE; - nanoTimeRead = true; + nanoTimeStored = false; + } + + private long loadAndClearBeginNanoTime() + { + long beginNanoTime = this.beginNanoTime; + nanoTimeStored = false; + return beginNanoTime; } - protected void takeNanoTime() + private void storeBeginNanoTime() { - if (nanoTimeRead) + if (!nanoTimeStored) { - beginNanoTime = NanoTime.now(); // TODO #9900 check beginNanoTime's accuracy - if (beginNanoTime == Long.MIN_VALUE) - beginNanoTime++; - nanoTimeRead = false; + beginNanoTime = NanoTime.now(); + nanoTimeStored = true; } } @@ -138,9 +138,9 @@ public void parse(ByteBuffer buffer) { try { - takeNanoTime(); while (true) { + storeBeginNanoTime(); switch (state) { case HEADER: diff --git a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/ServerParser.java b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/ServerParser.java index 978c46354de3..4aa82b654c32 100644 --- a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/ServerParser.java +++ b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/parser/ServerParser.java @@ -86,7 +86,6 @@ public void parse(ByteBuffer buffer) { if (LOG.isDebugEnabled()) LOG.debug("Parsing {}", buffer); - takeNanoTime(); while (true) { switch (state)