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

Loom Support: Pin Counters #15383

Merged
merged 1 commit into from
Jun 23, 2022
Merged

Conversation

babsingh
Copy link
Contributor

@babsingh babsingh commented Jun 21, 2022

Reasons for pinning:

	public enum Pinned {
		/** In native code */
		NATIVE,
		/** Holding monitor(s) */
		MONITOR,
		/** In critical section */
		CRITICAL_SECTION
	}

Support for #15174 and #15175:

  • J9VMThread->continuationPinCount will support native methods in
    class Continuation: pin() and unpin(). It will also be associated to
    Pinned.CRITICAL_SECTION.
  • J9VMThread->ownedMonitorCount will be associated to Pinned.MONITOR.
  • J9VMThread->callOutCount will be associated to Pinned.NATIVE.

Signed-off-by: Babneet Singh sbabneet@ca.ibm.com

@@ -4885,6 +4885,7 @@ typedef struct J9VMContinuation {
UDATA* stackOverflowMark;
UDATA* stackOverflowMark2;
J9JavaStack* stackObject;
UDATA pinCount;
Copy link
Contributor

@tajila tajila Jun 21, 2022

Choose a reason for hiding this comment

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

why is this separate from the others?

Copy link
Contributor

Choose a reason for hiding this comment

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

or perhaps, I'm misinterpreting this. Is that to track to number of times the continuation has been pinned?

Copy link
Contributor Author

@babsingh babsingh Jun 21, 2022

Choose a reason for hiding this comment

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

Because it is a property of the continuation. Others are properties of the thread.

Copy link
Contributor Author

@babsingh babsingh Jun 21, 2022

Choose a reason for hiding this comment

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

or perhaps, I'm misinterpreting this. Is that to track to number of times the continuation has been pinned?

Yes.

I don't see linkNext and linkPrevious fields in J9VMContinuation. Will J9VMThread maintain a list of Continuations? To support Continuation.isPinned, it needs to be a list since the parent of a Continuation also needs to be checked to determine if it is pinned.

Copy link
Contributor

Choose a reason for hiding this comment

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

tracking continuation lineage can be done in java code (ie. continuation.parent/child).

I don't see linkNext and linkPrevious fields in J9VMContinuation

This was intended for the purposes of finding all continuations in core dumps

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, it looks like the pinning fields are a lot like the interpreterfields in that the "live" versions are on the vmthread, and the "saved" versions are on the j9vmcontinuation.

So the short answer is all three can be put on the thread (this way it remains a fast path access). When we add support for nesting we'll need to add all three to the continuation as well. Updating the fields in the continuation will be handled by the code that does the enter/yield.

Copy link
Contributor

Choose a reason for hiding this comment

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

The pin/unpin natives pin the current continuation (and in the case of nesting, the most deeply nested one), which will always be the one with the live state on the j9vmthread.

Copy link
Contributor Author

@babsingh babsingh Jun 21, 2022

Choose a reason for hiding this comment

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

Updated as suggested. Note: RI handles nested continuations in its current implementation. Our current implementation won't be able to handle the below example. We are forcing a 1-to-1 relationship between a ContinuationScope and Continuation.

public static boolean isPinned(ContinuationScope scope) {

ContinuationScope X { Continuation A, Continuation B, Continuation C }

Continuation A { //Pinned    
   ...
   Continuation B { //Pinned
      ...
      Continuation C {
         ...
      }
      ...
   }
   ...
}

If nesting is required then we would need to put all 3 counters in the continuation object

We may only need ownedMonitorCount and pinCount in continuation. But, we will need to keep ownedMonitorCount in J9VMThread. We will also need to stackwalk in Coninuation.isPinned(ContinuationScope scope) to determine if any of the nested continuations has a stack frame on the thread. This will remove the need for callOutCount in J9VMThread.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since RI currently handles nested continuations, should we do the same?

Copy link
Contributor

Choose a reason for hiding this comment

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

We will, but for the purposes of unblocking JIT work I think we can keep this PR to the minimal set of changes we need right now

@babsingh babsingh force-pushed the loom_support branch 3 times, most recently from c74eba5 to 7bc8de4 Compare June 21, 2022 21:22
@tajila
Copy link
Contributor

tajila commented Jun 22, 2022

Jenkins test sanity amac jdk19

@gacholio
Copy link
Contributor

10:52:30  /Users/jenkins/workspace/Build_JDK19_aarch64_mac_Personal/openj9/runtime/vm/vmthread.cpp:265:13: error: no member named 'pinnedStateCounter' in 'J9VMThread'
10:52:30          newThread->pinnedStateCounter = 0;

@gacholio
Copy link
Contributor

Is there a good reason to add the flag in this PR? It's not something the JIT will need to see. I'd prefer if it were added and used in the same PR.

@babsingh
Copy link
Contributor Author

Is there a good reason to add the flag in this PR? It's not something the JIT will need to see. I'd prefer if it were added and used in the same PR.

As per #15175 (comment), the JIT plans to directly check if the bit is set.

@babsingh babsingh force-pushed the loom_support branch 2 times, most recently from cb66784 to df0d5c2 Compare June 22, 2022 18:09
@babsingh
Copy link
Contributor Author

error: no member named 'pinnedStateCounter' in 'J9VMThread'

Fixed. Testing locally.

@tajila
Copy link
Contributor

tajila commented Jun 22, 2022

Jenkins test sanity amac jdk19

@gacholio
Copy link
Contributor

I don't see why the JIT would check a bit (runtime checks are the very last thing the JIT ever wants to do). I'm also not clear on what thread this bit would be set - there are no J9VMThreads for virtual threads last time we discussed this.

@gacholio
Copy link
Contributor

I suppose it's the carrier thread that gets the bit.

To me, it would make more sense to inc/dec the counter in the inline JIT monent/exit code always (if the JCL level is high enough), and zero the counters whenever a vthread is mounted (we don't care about the values on the carrier thread itself).

@tajila
Copy link
Contributor

tajila commented Jun 22, 2022

I don't see why the JIT would check a bit (runtime checks are the very last thing the JIT ever wants to do). I'm also not clear on what thread this bit would be set - there are no J9VMThreads for virtual threads last time we discussed this.

The JIT needs a fast way to tell if there is a virtual thread mounted on the carrier thread (j9vmthread) so they know if they need to update the pin state counters or not. The flag seems like the simplest way. They could also check J9OBJECT_CLAZZ(j9vmthread->threadObject) == J9VM_JAVALANGVIRTUALTHREAD but thats more overhead.

@tajila
Copy link
Contributor

tajila commented Jun 22, 2022

To me, it would make more sense to inc/dec the counter in the inline JIT monent/exit code always (if the JCL level is high enough), and zero the counters whenever a vthread is mounted (we don't care about the values on the carrier thread itself).

@0xdaryl what are your thoughts on this?

@babsingh
Copy link
Contributor Author

https://openj9-jenkins.osuosl.org/job/Test_openjdk19_j9_sanity.functional_aarch64_mac_Personal/2/tapResults/

The test failure occurs in thrstatetest_0. All tests pass, but test suite has failed to destroy the JVM.

306/306 Tests passed. 0 Failures ignored. 123 Failures expected.
ALL TESTS COMPLETED AND PASSED
Failed to destroy JVM

thrstatetest_0_FAILED

I am investigating. Meanwhile, a decision on the new approach can be finalized.

@gacholio
Copy link
Contributor

We have our meeting today, so we can discuss.

@0xdaryl
Copy link
Contributor

0xdaryl commented Jun 23, 2022

The suggestion for a flag check was based on the understanding that the counters could only be updated under certain conditions and as a much faster alternative to calling out to the VM to determine those conditions (whether a virtual thread is mounted). If that's not true then I think unconditionally inc/dec'ing a counter will be a good solution (assuming the counter fields are on the VMThread and are in the cache).

Reasons for pinning:

	public enum Pinned {
		/** In native code */
		NATIVE,
		/** Holding monitor(s) */
		MONITOR,
		/** In critical section */
		CRITICAL_SECTION
	}

Support for eclipse-openj9#15174 and eclipse-openj9#15175:
- J9VMThread->continuationPinCount will support native methods in class
  Continuation: pin() and unpin(). It will also be associated to
  Pinned.CRITICAL_SECTION.
- J9VMThread->ownedMonitorCount will be associated to Pinned.MONITOR.
- J9VMThread->callOutCount will be associated to Pinned.NATIVE.

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
@babsingh babsingh changed the title Loom Support: Pinning + Virtual Thread Mounted Flag Loom Support: Pin Counters Jun 23, 2022
@babsingh
Copy link
Contributor Author

Copy link
Contributor

@gacholio gacholio left a comment

Choose a reason for hiding this comment

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

Zeroing the fields is unnecessary but we can fix that later.

@gacholio gacholio merged commit 58c648d into eclipse-openj9:master Jun 23, 2022
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.

4 participants