-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8343110: Add getChars(int, int, char[], int) to CharSequence and CharBuffer #21730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back mkarg! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
/csr |
@mkarg has indicated that a compatibility and specification (CSR) request is needed for this pull request. @mkarg please create a CSR request for issue JDK-8343110 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
Sorry for belated mail response, but I think we should design the API to not take source start/end. I think JIT can escape analysis the new String in practice. |
Chen, thank you for chiming in! There is nothing to be sorry, I was just posting drafts so far! 🙂 Regarding your actual question, I do understand your idea and while originally I had the same in mind (it really is appealing!), I came up with a draft using the original
|
Hi Markus, I recommend to continue the discussion on the mailing list instead of on GitHub. Note that GitHub pull requests are only forwarded to the mailing list when it's ready for review, and this proposal is way too early. (And the CSR is too early, too: we should agree on an API surface, such as exception contracts, first) Sorry that no one has responded to you yet, but many engineers are busy with other areas, such as pushing the JEPs (as you see, we have a huge number of candidate/submitted JEPs right now, and JDK 24 RDP1 is just 6 weeks away). They are monitoring your core-libs thread, stay assured! |
@liach Agreed with all you say, but actually: I did not expect any response - in particular on a weekend! I do not know why apparently people started to review the draft documents. I just filed it for no other purpose than taking note of its existence. 🤔 I thought it is pretty clear to everybody that draft means "do not review". At least this is how I used draft documents in the past 30 years. 🙂 So it seems there was a misunderstanding here regarding my drafts. My intention ever was and still is to first finish the discussion about alternatives (A)...(E) on the core-lib mailing list first. My PR and CSR drafts are intentionally in draft state, which means, they are not open for review yet (there is no |
@mkarg This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Kindly asking anybody's contribution to the ongoing discussion on the core-devs mailing list. Thanks you. |
@mkarg this pull request can not be integrated into git checkout getchars
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
Webrevs
|
@mkarg 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 add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Kindly asking for more comments! Something I am missing? Some good reason to not adopt my proposal? |
/reviewers 2 reviewer |
…to the given destination array
…did something get deleted?
…E behavior - when an IOOBE is thrown, some characters may be already transferred (this is important for concurrent char sequences)'
All requested changes are included in this PR since last week. Kindly asking to re-review / mark as reviewed, so we can proceed with the needed CSR. Thanks. |
I think the API docs in the latest draft looks okay. It mildly bothers me a bit is that getChars is JDK 1.0 API but the trade off with doing a new API is that it would need to be implemented by String and SB so I think the proposal on the table is okay. |
Kindly asking to mark this PR as reviewed, so I will go on with the CSR next. |
Should we ask hotspot compiler engineers for inputs on how useful this API is for allowing batch/vectorized copy and eliminating overheads of defensive copy array allocation? |
I have no strong feelings about that. As it looks like we reached concensus on the proposed change, I have now copied the spec into the CSR and set it into the proposed state. Kindly asking for your reviews of the CSR, so it can rather soon proceed into the provisional state. |
* Concurrent truncation of this character sequence can throw | ||
* {@code IndexOutOfBoundsException}. In this case, some characters, but not | ||
* all, may be already transferred. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though its been absent for decades, it might be worthwhile to include a class level warning that the implementations of the interface are not known or required to be thread safe and if used concurrently by multiple threads the behavior is unpredictable. I'd be more circumspect than trying to specify the only aberrant behavior is IndexOutOfBounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any quick proposals how to rephrase JavaDocs and CSR? As the CSR is already reviewed I am a bit reluctant to hold the train for this, as IMHO masses of classes and interfaces would need such a disclaimer, if we kick-off that ball here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Roger's suggestion is for a different JBS issue / PR / CSR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we already added this API to allow implementations to be more consistent under race condition. So for changing char sequences, this method's default implementation can throw IOOBE, but it is already specified so it is well-behaved even under race (as you can argue a read observed the shorter state of the CS that causes the failure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omitting it is fine, it was just a reminder that an interface cannot make any definitive statements about its implementations and sometime should warn the unwary user. (We all expect them to adhere to the contract described in each method, but who knows.)
The statement in the implSpec is fine as it only applies to the default implementation, but can be mis-read and thought to apply to all implementations. YMMV.
And though I see consensus, I don't see any approvals yet, including the CSR.
Its good to see it settle down and make progress.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alan, I am a bit lost here. How to proceed: Change the JavaDocs, or keep them as found in the CSR?
The implementation looks good. Do you think we need some unit tests for this new API, especially against the default implementation? |
IMHO the existing |
Relying on another user is not a good practice - it is possible that we switch |
Nevertheless, the tests are there, so no new ones are needed. We can duplicate them, if a majority thinks it is beneficial. |
As noted in the contribution guide (https://openjdk.org/guide/#testing-the-jdk), regression tests are expected for a majority of changes that are done in the JDK. There are situations where regressions tests cannot be added, but this isn't one. I believe a new method with a default specified implementation in a public exported interface deserves a regression test of its own. |
The docs do not say that the regression test must be separate. Again: We do have testing covered. The question is not whether we need a test -we do have one-, but whether to duplicate it. Edit: Don't get me wrong, I do not have any strong feelings here. If duplication is wanted, I will do it. I am just waiting for a majority to clearly say that they want duplication. What I do not want is to duplicate the tests and later another reviewer chimes in asking me to throw the duplicate away. |
By duplication, do you mean copy pasting the Implementing a test that calls |
IIUC then you will be fine with a test that solely tests the default implementation of |
Correct. And a similar separate test for |
…t implementation of CharSequence.getChars() and for CharBuffer.getChars()
I now have covered |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit tests look good.
* @summary Check for expected behavior of CharBuffer.getChars(). | ||
* @run testng GetChars | ||
*/ | ||
public class GetChars { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests for buffers, including CharBuffer, are in test/jdk/java/nio/Buffer. Look at the existing Chars.java tests idea, and specifically the DataProvider "createCharBuffers" as it will show the different kinds of CharBuffers that can be tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this tip, Alan! I have move the unit test from nio/CharBuffer
to nio/Buffer
, and appended it with the randomized test found in Buffer/Chars.java
. Hope it looks fine now?
…getChars() with unit test for CharBuffer.chars()
This Pull Request proposes an implementation for JDK-8343110: Adding the new method
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
to theCharSequence
interface, providing a bulk-read facility including a default implementation iterating overcharAt(int)
.In addition, this Pull Request proposes to replace the implementation of
Reader.of(CharSequence).read(char[] cbuf, int off, int len)
to invokeCharSequence.getChars(next, next + n, cbuf, off)
instead of utilizing pattern matching for switch. Also, this PR proposes to implementCharBuffer.getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
as an alias forCharBuffer.get(srcBegin, dst, dstBegin, srcEnd - srcBegin)
.To ensure quality...
AbstractStringBuilder.getChars(...)
.Reader.of(CharSequence)
, as these provide sufficient coverage of all changes introduced by this PR.Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21730/head:pull/21730
$ git checkout pull/21730
Update a local copy of the PR:
$ git checkout pull/21730
$ git pull https://git.openjdk.org/jdk.git pull/21730/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21730
View PR using the GUI difftool:
$ git pr show -t 21730
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21730.diff
Using Webrev
Link to Webrev Comment