Skip to content
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

Add new ThreadMXBean APIs #1471

Merged
merged 1 commit into from
Mar 20, 2018
Merged

Conversation

pdbain-ibm
Copy link
Contributor

@pdbain-ibm pdbain-ibm commented Mar 19, 2018

Add Add ThreadMXBean.dumpAllThreads(..., int maxDepth) and getThreadInfo(..., int maxDepth) APIs
for Java 10.

Add tests for the new APIs, including stack frames with method handles and lambdas.

Fix incorrect copyright.

Fixes #577

Signed-off-by: Peter Bain [email protected]

@pdbain-ibm
Copy link
Contributor Author

Tested in a personal build, but results are no longer available. Would a committer kindly run a test build?

Ran the new tests manually with logging enabled:
[APITestJava10] [DEBUG] testDumpLimits
[APITestJava10] [DEBUG] start 24
[APITestJava10] [DEBUG] start TestThread #24
[APITestJava10] [DEBUG] start 25
[APITestJava10] [DEBUG] start TestThread #25
[APITestJava10] [DEBUG] start 26
[APITestJava10] [DEBUG] start TestThread #26
[APITestJava10] [DEBUG] start 27
[APITestJava10] [DEBUG] start TestThread #27
[APITestJava10] [DEBUG] start 28
[APITestJava10] [DEBUG] start TestThread #28
[APITestJava10] [DEBUG] start 29
[APITestJava10] [DEBUG] start TestThread #29
[APITestJava10] [DEBUG] start 30
[APITestJava10] [DEBUG] start TestThread #30
[APITestJava10] [DEBUG] start 31
[APITestJava10] [DEBUG] start TestThread #31
[APITestJava10] [DEBUG] start 32
[APITestJava10] [DEBUG] start TestThread #32
[APITestJava10] [DEBUG] start 33
[APITestJava10] [DEBUG] start TestThread #33
[APITestJava10] [DEBUG] maxDepth = 0
[APITestJava10] [DEBUG] maxDepth = 1
[APITestJava10] [DEBUG] maxDepth = 2
[APITestJava10] [DEBUG] maxDepth = 3
[APITestJava10] [DEBUG] maxDepth = 4
[APITestJava10] [DEBUG] maxDepth = 5
[APITestJava10] [DEBUG] maxDepth = 6
[APITestJava10] [DEBUG] maxDepth = 7
[APITestJava10] [DEBUG] maxDepth = 8
[APITestJava10] [DEBUG] maxDepth = 9
[APITestJava10] [DEBUG] wait for 24
[APITestJava10] [DEBUG] end TestThread #25
[APITestJava10] [DEBUG] end TestThread #27
[APITestJava10] [DEBUG] end TestThread #30
[APITestJava10] [DEBUG] end TestThread #28
[APITestJava10] [DEBUG] end TestThread #31
[APITestJava10] [DEBUG] end TestThread #26
[APITestJava10] [DEBUG] end TestThread #32
[APITestJava10] [DEBUG] end TestThread #29
[APITestJava10] [DEBUG] end TestThread #24
[APITestJava10] [DEBUG] end TestThread #33
[APITestJava10] [DEBUG] wait for 25
[APITestJava10] [DEBUG] wait for 26
[APITestJava10] [DEBUG] wait for 27
[APITestJava10] [DEBUG] wait for 28
[APITestJava10] [DEBUG] wait for 29
[APITestJava10] [DEBUG] wait for 30
[APITestJava10] [DEBUG] wait for 31
[APITestJava10] [DEBUG] wait for 32
[APITestJava10] [DEBUG] wait for 33
PASSED: testDumpLimits
PASSED: testDumpLimitsWithLambdas
PASSED: testDumpLimitsWithMethodHandles

===============================================
threadMXBeanTestSuiteJava10
Tests run: 3, Failures: 0, Skips: 0

===============================================
Java9andUp suite
Total tests run: 3, Failures: 0, Skips: 0

* <li><code>lockedSynchronizers</code> is <code>true</code>
* but a call to {@link #isSynchronizerUsageSupported()} would
* result in a <code>false</code> value
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</ul> is missing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add @since 10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Override
public ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,
boolean lockedSynchronizers, int maxDepth) {
// K0662 = maxDepth must not be negative.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These external message declarations are supposed to be preprocessor commands, not comments. Please restore the appropriate preprocessor format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return this.getMultiThreadInfoImpl(ids, Integer.MAX_VALUE,
lockedMonitors, lockedSynchronizers);
}
boolean lockedSynchronizers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original file uses tabs, but the changes use spaces to indent. Please make the new code consistent with the rest of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@pdbain-ibm pdbain-ibm force-pushed the threadmxbean branch 2 times, most recently from 52e8fef to a256e18 Compare March 19, 2018 15:26
* but a call to {@link #isSynchronizerUsageSupported()} would
* result in a <code>false</code> value
* </ul>
* @since 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some unnecessary indenting here and in the next method as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was copied that from the other versions. I cleaned it up and added missing s.
Do you want me to clean up the originals?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the extra tab before @since 10, which is still there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I will push the changes with changes from @llxia 's review.

continue;
}
int requestedDepth = requestedDepthTemp;
if (id != myId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this conditional always be true, since myId is not added to expectedDepths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't always true, but a bug fix made it a tautology. Refactored and fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed how?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now:
a) check all threads against the maximum depth at the top of the loop.
b) omit the check against myId.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see the check against myId at L178.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Missed that.

if (id != myId) {
checkDepth(requestedDepth, maxDepth, trace, "dumpAllThreads");
} else {
Assert.assertTrue(trace.length <= maxDepth, "dumpAllThreads: Wrong stack size when maxDepth = "+maxDepth);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code compile? trace is not declared in this scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's declared on line 159.

waitObject.notifyAll();
}
for (Thread t: myThreads) {
if (Thread.currentThread().equals(t)) {
Copy link
Member

@pshipton pshipton Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be any point in adding the current thread to myThreads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Fixed.

Assert.assertEquals(trace.length, maxDepth, msg+": Wrong stack size when requested depth > maxDepth = "+maxDepth);
} else {
Assert.assertTrue(trace.length <= maxDepth, msg+": Stack exceeds maxDepth = "+maxDepth);
Assert.assertTrue(trace.length >= requestedDepth, msg+": Stack less than minimum expected");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would == work here instead of >=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that.
The actual depth may be greater than the expected depth due to internal calls within wait().

@pshipton
Copy link
Member

@llxia please review the tests

</levels>
<groups>
<group>functional</group>
</groups>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have subset? Is this test for java10?

<subsets>
	<subset>SE100</subset>
</subsets>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

@pdbain-ibm pdbain-ibm force-pushed the threadmxbean branch 3 times, most recently from 87a96ff to 1a1f463 Compare March 20, 2018 15:58
Add Add ThreadMXBean.dumpAllThreads(..., int maxDepth) and getThreadInfo(...,
int maxDepth) APIs for Java 10.

Add tests for the new APIs, including stack frames with method handles and
lambdas.

Fix incorrect copyright.

Signed-off-by: Peter Bain <[email protected]>
@llxia
Copy link
Contributor

llxia commented Mar 20, 2018

Jenkins test sanity plinux jdk9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants