-
Notifications
You must be signed in to change notification settings - Fork 5.8k
JDK-8261095: Add test for clhsdb "symbol" command #2863
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
Conversation
👋 Welcome back vsharma! A progress list of the required criteria for merging this PR into |
@Vipin-Sharma The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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.
Overall it looks good. I have some suggestions for improved comments and formatting, and also please use the line.separator property.
theApp = LingeredApp.startApp(); | ||
System.out.println("Started LingeredApp with pid " + theApp.getPid()); | ||
|
||
//Use command "class java.lang.Thread" to get the address of the InstanceKlass for java.lang.Thread |
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.
Put a space after the //
. Same goes for all the comments below.
//extract address comes along with Symbol instance, following is corresponding sample output line | ||
//Symbol* Klass::_name: Symbol @ 0x0000000800471120 |
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 inspect command output will have one line of output that looks like the following.
// Symbol* Klass::_name: Symbol @ 0x0000000800471120
// Extract the Symbol address from it.
throw new RuntimeException("Cannot find address with Symbol instance"); | ||
} | ||
|
||
//Running "symbol" command on the Symbol instance address extracted in previous step |
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.
// Run "symbol" command on the Symbol instance address extracted in previous step.
// It should produce the symbol for java/lang/Thread.
expStrMap = new HashMap<>(); | ||
expStrMap.put(cmdStr, List.of("#java/lang/Thread")); | ||
test.run(theApp.getPid(), cmds, expStrMap, null); | ||
|
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.
No need for newline here.
String threadAddress = null; | ||
String[] parts = classOutput.split("\n"); | ||
|
||
//extract thread address from the output line similar to "java/lang/Thread @0x000000080001d940" |
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'd prefer:
// Extract the thread InstanceKlass address from the output, which looks similar to the following:
// java/lang/Thread @0x000000080001d940
expStrMap.put(cmdStr, List.of("java/lang/Thread")); | ||
String classOutput = test.run(theApp.getPid(), cmds, expStrMap, null); | ||
String threadAddress = null; | ||
String[] parts = classOutput.split("\n"); |
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 you should be using the line.separator properly instead of "\n".
String linesep = System.getProperty("line.separator");
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.
It might be more simple if you use String::lines and stream API.
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.
Yes. Coincidentally I was just having an internal chat about split(linesep)
, and String.lines()
was mentioned. We have a lot of existing code that uses split(linesep)
because String.lines()
has only been around since JDK 11, and even some newer test code we have uses split(linsep)
because it was copied from older tests.
expStrMap.put(cmdStr, List.of("Symbol")); | ||
String inspectOutput = test.run(theApp.getPid(), cmds, expStrMap, null); | ||
String symbolAddress = null; | ||
parts = inspectOutput.split("\n"); |
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.
And here also use line.separator.
.map(part -> part.split(" @")) | ||
.findFirst() | ||
.map(addresses -> addresses[1]) | ||
.orElse(null); |
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.
It should just call get()
because NoSuchElementException
would be called when we cannot find out Thread class from stdout.
If you want to throw RuntimeException
like next step, you should use orElseThrow()
.
String symbolAddress = inspectOutput.lines().filter(part -> part.startsWith("Symbol")) | ||
.map(part -> part.split("@ ")) | ||
.findFirst().map(symbolParts -> symbolParts[1]) | ||
.orElse(null); |
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.
Same comment in above.
.orElseThrow(() -> new RuntimeException("Cannot find address of " + | ||
"the InstanceKlass for java.lang.Thread in output")); |
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.
These lines really don't format well, a reason why the previous orElse()
version is probably better. Maybe you can make this work by moving the .filter()
call to a new line that is indented 8 more than the previous line
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.
After moving the filter to the next line also can not fit this in one line.
In addition to the filter, moving all characters starting from "new RuntimeException(...." also goes till 126 char.
Following is one suggestion, does it look good?
String threadAddress = classOutput.lines()
.filter(part -> part.startsWith("java/lang/Thread"))
.map(part -> part.split(" @"))
.findFirst()
.map(addresses -> addresses[1])
.orElseThrow(() -> new RuntimeException(
"Cannot find address of the InstanceKlass for java.lang.Thread in output"));
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.
Formatting in my comment is not clear, so I have added one new commit for this.
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.
Formatting looked fine in the email. Try putting it in a code block to prevent the auto formatting being done on it.
Latest webrev looks good.
"the InstanceKlass for java.lang.Thread in output")); | ||
|
||
|
||
// Use "inspect" on the thread address we extracted in previous step |
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.
"in the
previous step"
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 didn't realize that lines()
returns a Stream
. TBH I find the original code a lot easier to read than the Stream
code, but that's pretty much always my opinion when I see Stream
code. Others will probably feel your new version is more elegant, so I won't protest.
Having said that, I also just learned that String.split("\R")
will properly split the lines with any newline character sequence. See Pattern:
\R Any Unicode linebreak sequence \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]
String inspectOutput = test.run(theApp.getPid(), cmds, expStrMap, null); | ||
|
||
// The inspect command output will have one line of output that looks like the following. | ||
// Symbol* Klass::_name: Symbol @ 0x0000000800471120 |
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.
Indent this line of the comment
.orElseThrow(() -> new RuntimeException( | ||
"Cannot find address with Symbol instance")); | ||
|
||
// Run "symbol" command on the Symbol instance address extracted in previous step. |
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.
"in the
previous step"
.orElseThrow(() -> new RuntimeException( | ||
"Cannot find address with Symbol instance")); |
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.
Same issue with formatting as above.
@Vipin-Sharma This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 36 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@plummercj, @YaSuenag) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@Vipin-Sharma |
This pull request is reviewed and ready to be integrated, please sponsor the request. |
Ok, I will sponsor you. |
/sponsor |
@YaSuenag @Vipin-Sharma Since your change was applied there have been 140 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 086a66a. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/2863/head:pull/2863
$ git checkout pull/2863