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

Update jvmtiGetThreadGroupChildren for java 19 #15539

Merged
merged 1 commit into from
Aug 10, 2022

Conversation

EricYangIBM
Copy link
Contributor

@EricYangIBM EricYangIBM commented Jul 13, 2022

The ThreadGroup class does not store its threads anymore and child groups
are separated into "groups" and "weaks" ThreadGroup arrays.

The child ThreadGroups array is populated from the ThreadGroup's "groups"
and "weaks" arrays, which are the child ThreadGroups that are strongly
and weakly reachable from the parent.

The threads array is constructed by iterating over all J9VMThreads and
adding the threads that belong in the given ThreadGroup.

The returned arrays are constructed while locking on the ThreadGroup
object.

Fixes: #15244
Issue: #15183
Signed-off-by: Eric Yang eric.yang@ibm.com

@EricYangIBM EricYangIBM force-pushed the getThreadGroupChildren branch 2 times, most recently from cab5162 to c41c9d9 Compare July 13, 2022 20:36
@EricYangIBM
Copy link
Contributor Author

Test in linked issue passes with these changes

@EricYangIBM EricYangIBM marked this pull request as ready for review July 19, 2022 16:37
@babsingh babsingh self-requested a review July 19, 2022 16:38
Copy link
Contributor

@babsingh babsingh left a comment

Choose a reason for hiding this comment

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

The commit message/description should include few lines on how the threads and groups arrays are created for Java 19+. It will make it easier to follow the source code.

runtime/jvmti/jvmtiThreadGroup.c Outdated Show resolved Hide resolved
runtime/jvmti/jvmtiThreadGroup.c Outdated Show resolved Hide resolved
runtime/jvmti/jvmtiThreadGroup.c Show resolved Hide resolved
} while ((targetThread = targetThread->linkNext) != vm->mainThread);

*rv_thread_count = nLiveThreads;
*rv_threads = threads;
Copy link
Contributor

Choose a reason for hiding this comment

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

On return, the jthread* points to a newly allocated array of size*thread_count_ptr

threads array is of size totalThreadCount which is greater than nLiveThreads. Is it fine to return an array of larger size? We allow this in our current implementation; the answer may be "yes".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We return the actual number of threads in the array so it probably is fine

Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of allocated memory will be unused if the filter excludes a lot of threads. Filter: include only platform threads which match the thread_group.

*rv_thread_count = nLiveThreads;
*rv_threads = threads;
*rv_group_count = nGroupsTotal;
*rv_groups = groups;
Copy link
Contributor

Choose a reason for hiding this comment

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

On return, the jthreadGroup* points to a newly allocated array of size*group_count_ptr

groups array is of size nGroups + nWeaks, which is greater than nGroupsTotal. Is it fine to return an array of larger size? We allow this in our current implementation; the answer may be "yes".

Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of allocated memory will be unused if a lot of weak references are null.

@babsingh
Copy link
Contributor

@EricYangIBM The commits can be squashed.

@tajila These changes should work fine. But, still doubtful about the memory allocated for threads and groups arrays which are returned from this method (see comments inlined in code). Should we create new arrays with smaller/required size and copy the elements from the bigger array and free the bigger array?

@tajila
Copy link
Contributor

tajila commented Aug 4, 2022

But, still doubtful about the memory allocated for threads and groups arrays which are returned from this method (see comments inlined in code). Should we create new arrays with smaller/required size and copy the elements from the bigger array and free the bigger array?

This is not going to return vthreads correct? If so, then I dont think returning a potentially larger buffer is a big deal as platform threads arent created as frequently

@tajila
Copy link
Contributor

tajila commented Aug 4, 2022

It could be an optimization that is added later

@babsingh
Copy link
Contributor

babsingh commented Aug 4, 2022

This is not going to return vthreads correct?

Vthreads will not be returned. See ref below. @EricYangIBM Can you add a comment in code and open an issue regarding this optimization for tracking purposes?

Ref: https://download.java.net/java/early_access/jdk19/docs/specs/jvmti.html#GetThreadGroupChildren

@EricYangIBM
Copy link
Contributor Author

I will open the issue after this PR is merged (to link to the comment)

@babsingh
Copy link
Contributor

babsingh commented Aug 4, 2022

LGTM. The commits need to be squashed before the PR builds are launched.

The ThreadGroup class does not store its threads anymore and child groups
are separated into "groups" and "weaks" ThreadGroup arrays.

The child ThreadGroups array is populated from the ThreadGroup's "groups"
and "weaks" arrays, which are the child ThreadGroups that are strongly
and weakly reachable from the parent.

The threads array is constructed by iterating over all J9VMThreads and
adding the threads that belong in the given ThreadGroup.

The returned arrays are constructed while locking on the ThreadGroup
object.

Fixes: eclipse-openj9#15244
Issue: eclipse-openj9#15183
Signed-off-by: Eric Yang <eric.yang@ibm.com>
@EricYangIBM
Copy link
Contributor Author

Squashed

@babsingh
Copy link
Contributor

babsingh commented Aug 4, 2022

jenkins compile win jdk19,jdk17

@babsingh
Copy link
Contributor

babsingh commented Aug 4, 2022

Does not work for me yet. Need to wait for @AdamBrousseau to add me.

@babsingh
Copy link
Contributor

babsingh commented Aug 5, 2022

jenkins compile win jdk19,jdk17

@babsingh
Copy link
Contributor

babsingh commented Aug 5, 2022

jenkins test sanity amac jdk19,jdk17

@babsingh
Copy link
Contributor

babsingh commented Aug 5, 2022

These JVMTI changes should only impact the gtgc001 test, which has been enabled and passes for JDK17 and JDK19.

https://openj9-jenkins.osuosl.org/job/Test_openjdk17_j9_sanity.functional_aarch64_mac_Personal/75/

jit_vich_0_FAILED is unrelated to this PR. All tests in this suite pass but there is an error at the end (Invalid JIT return address).

===============================================
JIT_Test suite
Total tests run: 18, Failures: 0, Skips: 0
===============================================

*** Invalid JIT return address 000000037A4175E0 in 000000016FBDFD98

jit_vich_0_FAILED

Copy link
Contributor

@babsingh babsingh left a comment

Choose a reason for hiding this comment

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

LGTM. Opened #15673 for the JIT failure.

@babsingh
Copy link
Contributor

babsingh commented Aug 5, 2022

Still can't merge the PR. Need to wait for @AdamBrousseau to give the required permissions.

@AdamBrousseau
Copy link
Contributor

Still can't merge the PR

This is an Eclipse Github team thing. It should be automatic. If it's not working then I would open an Eclipse ticket.
https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues?sort=created_date&state=opened

@babsingh babsingh merged commit d31ce9c into eclipse-openj9:master Aug 10, 2022
@EricYangIBM EricYangIBM deleted the getThreadGroupChildren branch August 11, 2022 12:53
babsingh added a commit to babsingh/openj9 that referenced this pull request Nov 21, 2022
GetThreadGroupChildren was fixed by eclipse-openj9#15539.

The above PR removed the exclude for JDK19.

But, the exclude for JDK20 was not removed.

Related: eclipse-openj9#15244

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JDK19: Address threadgroup jvmti failures
4 participants