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

8310054: ScrollPane insets are incorrect #14478

Closed

Conversation

aivanov-jdk
Copy link
Member

@aivanov-jdk aivanov-jdk commented Jun 14, 2023

After the size of ScrollPane child component changes, it recalculates the size of the scroll bars and hides or shows them as necessary. This situation is handled in WScrollPanePeer.childResized:

public void childResized(int width, int height) {
ScrollPane sp = (ScrollPane)target;
Dimension vs = sp.getSize();
setSpans(vs.width, vs.height, width, height);
setInsets();
}

After JDK-8297923, setSpans is run asynchronously on the toolkit thread. Thus, setInsets calculates the incorrect values because setSpans hasn't updated the sizes yet.

This is a regression from JDK-8297923.

Fix

The insets are updated in the native implementation of setSpans directly.

The native implementation of setInsets method is run on the toolkit thread as a synchronous call because the insets are used in WScrollPanePeer.initialize.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8310054: ScrollPane insets are incorrect (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14478/head:pull/14478
$ git checkout pull/14478

Update a local copy of the PR:
$ git checkout pull/14478
$ git pull https://git.openjdk.org/jdk.git pull/14478/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14478

View PR using the GUI difftool:
$ git pr show -t 14478

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14478.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 14, 2023

👋 Welcome back aivanov! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 14, 2023
@openjdk
Copy link

openjdk bot commented Jun 14, 2023

@aivanov-jdk The following label will be automatically applied to this pull request:

  • client

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.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Jun 14, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 14, 2023

Webrevs

@prrace
Copy link
Contributor

prrace commented Jun 15, 2023

Hmm, I did ask during the previous review if there was any reason to block with
_SetScrollPos or "the case below" - ie _SetSpans... but perhaps it is more complex than that.

I need some clarification
Before any changes, using SyncCall , _SetSpans was called synchronously.
After the first change to use InvokeFunctionLater, _SetSpans was called asynchronously .
Now with InvokeFunction, _SetSpans is again called synchronously

So why do you also need the change to set it in native ?

The difference I can see is that although it is synchronous it now requires jumping on to the Toolkit thread
and so other pending processing on the Toolkit thread will run first.

But I'm not sure that's relevant here.

So can you expand on why you also had to move the call to setInsets() to native ?

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

@aivanov-jdk If just the _SetSpans() on native is changed to run as InvokeFunction instead of InvokeFunctionLater both the tests - ScrollPaneLeakTest.java & ScrollPaneExtraScrollBar.java pass without additional code changes to WScrollPanePeer.java.childResized and _setInsets.

Perhaps logging the order in which the Java and native calls are made (& also which calls are EDT vs non-EDT) can be helpful to understand the fix better?

@aivanov-jdk
Copy link
Member Author

@aivanov-jdk If just the _SetSpans() on native is changed to run as InvokeFunction instead of InvokeFunctionLater both the tests - ScrollPaneLeakTest.java & ScrollPaneExtraScrollBar.java pass without additional code changes to WScrollPanePeer.java.childResized and _setInsets.

I know it. But I think it's bad. If both _SetSpans and _SetInsets are synchronous by using InvokeFunction, you block EDT to run some code on the toolkit thread twice:

  1. EDT calls _SetSpans, it gets blocked until SetSpans completes on the toolkit thread;
  2. EDT calls _SetInsets, it gets blocked until SetInsets completes on the toolkit thread.

I think blocking is bad. I coalesced these two calls into one asynchronous call. There's no EDT blocking with the same result.

@aivanov-jdk
Copy link
Member Author

Hmm, I did ask during the previous review if there was any reason to block with _SetScrollPos or "the case below" - ie _SetSpans... but perhaps it is more complex than that.

I didn't find any reason to block either.

I considered _SetInsets for using InvokeFunction or InvokeFunctionLater. I deliberately decided not to.

But I eventually missed the case where SetInsets depends on the results of SetSpans when they're called together in WScrollPanePeer.childResized.

(In my initial approach, I used InvokeFunction because I overlooked InvokeFunctionLater at first; they're not close in the header file and in the implementation files. Yet I was bothered by blocking EDT where it wasn't needed. I found InvokeFunctionLater and used it — the result was the same.)

I need some clarification Before any changes, using SyncCall , _SetSpans was called synchronously. After the first change to use InvokeFunctionLater, _SetSpans was called asynchronously .

Yes, when using SyncCall both _SetSpans and _SetInsets were called synchronously, so _SetInsets could use the updated spans.

Now with InvokeFunction, _SetSpans is again called synchronously

No, it's still called asynchronously.

So why do you also need the change to set it in native ?

It is the reason why I moved setInsets from Java into native implementation.

Without moving SetInsets into the native, both _SetSpans and _SetInsets need to blocking calls that follow each other. In my opinion, it's not a good approach. I elaborated on it in my reply to Harshitha's comment.

The difference I can see is that although it is synchronous it now requires jumping on to the Toolkit thread and so other pending processing on the Toolkit thread will run first.

But I'm not sure that's relevant here.

So can you expand on why you also had to move the call to setInsets() to native ?

To avoid making both _SetSpans and _SetInsets synchronous calls;
To avoid another JNI call when both actions could be easily coalesced.

SetInsets must always be called after SetSpans. Why do we need to call both from Java side, where native implementation for SetSpans can as easily call it directly?

@honkar-jdk
Copy link
Contributor

@aivanov-jdk If just the _SetSpans() on native is changed to run as InvokeFunction instead of InvokeFunctionLater both the tests - ScrollPaneLeakTest.java & ScrollPaneExtraScrollBar.java pass without additional code changes to WScrollPanePeer.java.childResized and _setInsets.

I know it. But I think it's bad. If both _SetSpans and _SetInsets are synchronous by using InvokeFunction, you block EDT to run some code on the toolkit thread twice:

  1. EDT calls _SetSpans, it gets blocked until SetSpans completes on the toolkit thread;
  2. EDT calls _SetInsets, it gets blocked until SetInsets completes on the toolkit thread.

I think blocking is bad. I coalesced these two calls into one asynchronous call. There's no EDT blocking with the same result.

Thank you for the details. I'll play around with the 2 tests, trace out the calls and check if we are hitting any other corner cases.

@aivanov-jdk
Copy link
Member Author

Following the same way of thought, I'd like to coalesce setInsets, getInsets followed by setScrollPosition in WScrollPanePeer.initialize into one native call as well. I believe this would be more efficient. I've already submitted JDK-8310056 for it.

That change is related to this but I'd rather keep them separate: it's safer to make small changes. Moreover they're independent.

@prrace
Copy link
Contributor

prrace commented Jun 15, 2023

Now with InvokeFunction, _SetSpans is again called synchronously
No, it's still called asynchronously.

===

INLINE void * InvokeFunction(void*(*ftn)(void)) {
return (void *)SendMessage(WM_AWT_INVOKE_VOID_METHOD, (WPARAM)ftn, 0);

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessage

Sends the specified message to a window or windows.
The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

===

So how is that not synchronous ?

Oh wait, that is _SetInsets you updated here. I thought I had these calls straight but I need to look again.

So I think I see with the benefit of your recent comments.
It seemed that reverting _SetSpans to synchronous would fix this and somehow I read that was what you were doing.
But you didn't want to do that and you were forced into making _SetInsets synchronous because of the initalization usage
and hence moving the update of insets needed by setSpans avoided that.

@honkar-jdk
Copy link
Contributor

Oh wait, that is _SetInsets you updated here. I thought I had these calls straight but I need to look again.

@prrace That is correct. It is_SetInsets which has been changed to be called as InvokeFunction and _SetSpans is still being called as InvokeFunctionLater as per @aivanov-jdk previous fix.

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

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

I think I got it now.

@openjdk
Copy link

openjdk bot commented Jun 15, 2023

@aivanov-jdk 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:

8310054: ScrollPane insets are incorrect

Reviewed-by: honkar, prr

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 34 new commits pushed to the master branch:

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 15, 2023
@aivanov-jdk
Copy link
Member Author

So I think I see with the benefit of your recent comments.
It seemed that reverting _SetSpans to synchronous would fix this and somehow I read that was what you were doing.
But you didn't want to do that and you were forced into making _SetInsets synchronous because of the initalization usage
and hence moving the update of insets needed by setSpans avoided that.

Yes, that's right.

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

PR changes look good. All ScrollPane related tests work as expected with the changes.

@aivanov-jdk
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 16, 2023

Going to push as commit d6c2ee3.
Since your change was applied there have been 37 commits pushed to the master branch:

  • 4eb4f20: 8308808: SunMSCAPI public keys returns internal key array
  • 53abba3: 8309499: javac fails to report compiler.err.no.java.lang with annotation processing enabled
  • cf8d0b0: 8309964: Use directed inheritDoc for javax.lang.model API
  • a45f929: 8310076: Reduce inclusion of bytecodeStream.hpp
  • 21f6d83: 8309471: Limit key characters in static index pages
  • 44a8aa0: 8308609: java/lang/ScopedValue/StressStackOverflow.java fails with "-XX:-VMContinuations"
  • b412fc7: 8309937: Add @sealedGraph for some Panama FFM interfaces
  • fb024fd: 8248149: G1: change _cleaning_claimed from int to bool
  • c2b043e: 8310183: Update GitHub Actions to use boot JDK for building jtreg
  • 238c51e: 8293069: Make -XX:+Verbose less verbose
  • ... and 27 more: https://git.openjdk.org/jdk/compare/57b8251241e2044d5039ce162bf4637a9b2e5466...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 16, 2023
@openjdk openjdk bot closed this Jun 16, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 16, 2023
@openjdk
Copy link

openjdk bot commented Jun 16, 2023

@aivanov-jdk Pushed as commit d6c2ee3.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@@ -525,6 +525,7 @@ void AwtScrollPane::_SetSpans(void *param)
parentWidth, parentHeight, childWidth, childHeight);
s->RecalcSizes(parentWidth, parentHeight, childWidth, childHeight);
s->VerifyState();
s->SetInsets(env);
Copy link
Member

Choose a reason for hiding this comment

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

I guess we should call "s->VerifyState();" after the "s->SetInsets(env);" similar to what we do in the "AwtScrollPane::_SetInsets"

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we should call "s->VerifyState();" after the "s->SetInsets(env);" similar to what we do in the "AwtScrollPane::_SetInsets"

@mrserb An interesting question… You're right, I've introduced an inconsistency.

Yet I don't think it matters because SetInsets doesn't change any members of AwtScrollPane object which are asserted in VerifyState. In addition to it, VerifyState is a no-op in release builds.

I'll take this into account in JDK-8310056.

@aivanov-jdk aivanov-jdk deleted the 8310054-ScrollPane-insets branch July 11, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
4 participants