8354076: LinkedBlockingDeque offer() creates nodes even if capacity has been reached#24521
8354076: LinkedBlockingDeque offer() creates nodes even if capacity has been reached#24521kabutz wants to merge 1 commit into
Conversation
… space in the LBD.
|
👋 Welcome back kabutz! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
If we strictly adhere to this interpretation of "create nodes", then we must only call a constructor after the locked capacity check has passed in places like I think the correct way to interpret the spec here is that "create node" means a node is created in the linked list, so we can interpret that as a change in collection membership reflected in accessor methods. |
|
My code is similar to how LinkedBlockingQueue works. From LinkedBlockingQueue: However, I'm not sure whether it is a good idea to make this change, since making count volatile in LBD might impact performance for the most common use case (unbounded deque). For example: Output with Java 25+17: Output with these changes: |
|
@kabutz This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a |
|
@viktorklang-ora Is it possible for you to take a look at this? |
|
These changes have been included in #24925 |
In the JavaDoc of LinkedBlockingDeque, it states: "Linked nodes are dynamically created upon each insertion unless this would bring the deque above capacity." However, in the current implementation, nodes are always created, even if the deque is full. This is because count is non-volatile, and we only check inside the linkFirst/Last() methods whether the queue is full. At this point we have already locked and have created the Node. Instead, the count could be volatile, and we could check before locking.
In the current version, calling offer() on a full LinkedBlockingDeque creates unnecessary objects and contention. Similarly for poll() and peek(), we could exit prior to locking by checking the count field.
Our suggestion is to make count volatile, and then exiting early from poll() and offer()
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24521/head:pull/24521$ git checkout pull/24521Update a local copy of the PR:
$ git checkout pull/24521$ git pull https://git.openjdk.org/jdk.git pull/24521/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24521View PR using the GUI difftool:
$ git pr show -t 24521Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24521.diff
Using Webrev
Link to Webrev Comment