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

8308780: Fix the Java Integer types on Windows #14125

Closed
wants to merge 16 commits into from

Conversation

TheShermanTanker
Copy link
Contributor

@TheShermanTanker TheShermanTanker commented May 24, 2023

On Windows, the basic Java Integer types are defined as long and __int64 respectively. In particular, the former is rather problematic since it breaks compilation as the Visual C++ becomes stricter and more compliant with every release, which means the way Windows code treats long as a typedef for int is no longer correct, especially with -permissive- enabled. Instead of changing every piece of broken code to match the jint = long typedef, which is far too time consuming, we can instead change jint to an int (which is still the same 32 bit number type as long), as there are far fewer problems caused by this definition. It's better to get this over and done with sooner than later when a future version of Visual C++ finally starts to break on existing code


Progress

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

Issue

  • JDK-8308780: Fix the Java Integer types on Windows (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14125

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 24, 2023

👋 Welcome back jwaters! 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 May 24, 2023
@openjdk
Copy link

openjdk bot commented May 24, 2023

@TheShermanTanker The following labels will be automatically applied to this pull request:

  • client
  • core-libs
  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot-compiler hotspot-compiler-dev@openjdk.org client client-libs-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels May 24, 2023
@mlbridge
Copy link

mlbridge bot commented May 24, 2023

Copy link
Member

@dholmes-ora dholmes-ora 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 the JNI type definition change is okay.

However many of the other changes appear to me to not involve Java variables and so don't need to be Java types i.e they should be int rather than jint - though as these are native Windows types there may not actually be any reason to change them from long. This is for the client-libs folk to decide.

@@ -322,7 +322,7 @@ Java_sun_java2d_windows_GDIRenderer_doDrawArc
return;
}

long sx, sy, ex, ey;
jint sx, sy, ex, ey;
Copy link
Member

Choose a reason for hiding this comment

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

These are not Java variables. They get passed to the win32 GDI Arc function below which expects int.

@TheShermanTanker
Copy link
Contributor Author

I think the JNI type definition change is okay.

However many of the other changes appear to me to not involve Java variables and so don't need to be Java types i.e they should be int rather than jint - though as these are native Windows types there may not actually be any reason to change them from long. This is for the client-libs folk to decide.

All the changes from long were done since there was conversion from or to a jint somewhere down the line, and the compilation would fail if not done otherwise. I also changed them to jint rather than int so there wouldn't be a need to keep the variables in sync with the jni.h declarations, but I guess I'll wait for more reviews to see what to do here

@TheShermanTanker
Copy link
Contributor Author

Going to page for @aivanov-jdk for client-libs review

@dholmes-ora
Copy link
Member

All the changes from long were done since there was conversion from or to a jint somewhere down the line,

Okay I see that now. It is a messy situation - at some point the incoming jint's need to be "converted" to a native type.

@TheShermanTanker
Copy link
Contributor Author

I'll see what I can do, I'll check the parameter type for the methods that are called in relevant code, though if they take an int as an argument I'm not really sure what to change

@TheShermanTanker
Copy link
Contributor Author

TheShermanTanker commented May 25, 2023

For reference as to what types the calls in affected code accepts as parameters, so any future reviews don't need to dig through the code

GDIRenderer.cpp:

- Java_sun_java2d_windows_GDIRenderer_doFillArc
  * AngleToCoord takes jints as arguments
  * ::Pie takes ints as arguments

- Java_sun_java2d_windows_GDIRenderer_doDrawArc
  * AngleToCoord takes jints as arguments
  * ::Arc takes ints as arguments

GDIWindowSurfaceData.cpp:

- GDIWinSD_GetRasInfo
  * SurfaceDataRasInfo's lutBase field is a jint*

awt_MenuBar.cpp (Encompasses the changes in awt_Menu.h and awt_MenuBar.h as well):

- AwtMenuBar::GetItem passes the only relevant jint (formerly long) into env->CallObjectMethod()

ShellFolder2.cpp

* colorBits is passed to both SetIntArrayRegion (takes a jint pointer) and GetDIBits (takes a void pointer)

AccessInfo.cpp

- getAccessibleInfo
  * start and end (both formerly long) are both passed to GetAccessibleTextLineBounds and GetAccessibleTextRange which take jints

Only outlier is jaccesswalker, which I think I may have edited wrongly

@TheShermanTanker
Copy link
Contributor Author

Bumping

:(

@TheShermanTanker
Copy link
Contributor Author

TheShermanTanker commented Jun 1, 2023

While looking through the code for this I've come to realize that a staggering amount of code in the accessibility binaries specify longs where unsigned longs would be much more appropriate (see the one example in this PR for instance), wonder if this should also be fixed in the long term too

@prrace
Copy link
Contributor

prrace commented Jun 1, 2023

I'm not sure I understand the logic here.
I would not want to move to using Java typedefs in places where the windows APIs specify the types they are expecting.
If something comes in from a JNI down-call we should convert it to the type expected by Windows using the name expected by Windows.

Also "compilation" isn't nearly good enough. How is this being tested ?

@TheShermanTanker
Copy link
Contributor Author

I'm not sure I understand the logic here. I would not want to move to using Java typedefs in places where the windows APIs specify the types they are expecting. If something comes in from a JNI down-call we should convert it to the type expected by Windows using the name expected by Windows.

I can change the jints in this PR to regular ints if required. As listed above, the native Windows API routines that the java.desktop code calls are actually expecting ints, so our existing declarations of passing longs to them are also wrong regardless, even without the Java typedefs

Actually, now that I revisit this issue (shown in the list above), the only actual calls in this change that don't take Java typedefs are the calls to ::Arc and ::Pie, so this is less of a problem than initially expected

Also "compilation" isn't nearly good enough. How is this being tested?

-permissive-

@TheShermanTanker
Copy link
Contributor Author

Bumping

@TheShermanTanker
Copy link
Contributor Author

Anyone?

@aivanov-jdk
Copy link
Member

I'll take a look… hopefully next week.

@TheShermanTanker
Copy link
Contributor Author

Bumping

@TheShermanTanker
Copy link
Contributor Author

Bumping

@mlbridge
Copy link

mlbridge bot commented Jun 21, 2023

Mailing list message from Patrick Chen on client-libs-dev:

No rejected

Le mer. 21 juin 2023, 08:47, Julian Waters <jwaters at openjdk.org> a ?crit :

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20230621/9855c0aa/attachment.htm>

@TheShermanTanker
Copy link
Contributor Author

...

@TheShermanTanker
Copy link
Contributor Author

Will do, thanks Daniel
@prrace @dholmes-ora Are both of you happy with the changes?

Copy link
Member

@aivanov-jdk aivanov-jdk left a comment

Choose a reason for hiding this comment

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

Looks fine to me, except for a few comments.

The size of the types for jint and jlong remains the same after amending the typedef jni_md.h. Yet I'm still cautious about it. You should have an approval from hotspot.

Please also update the copyright year in the modified files.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Hotspot changes still approved.

Other changes seem okay to me.

Thanks

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 23, 2023
@TheShermanTanker
Copy link
Contributor Author

Alright, I'll integrate once Alexsey approve, anyone else has further objections?

@@ -73,7 +73,7 @@ class AwtMenu : public AwtMenuItem {

/*for multifont menu */
BOOL IsTopMenu();
virtual AwtMenuItem* GetItem(jobject target, long index);
virtual AwtMenuItem* GetItem(jobject target, int index);
Copy link
Member

Choose a reason for hiding this comment

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

Hi @aivanov-jdk are you OK leaving this inconsistent with the definition?

AwtMenuItem* AwtMenu::GetItem(jobject target, jint index)

Copy link
Member

Choose a reason for hiding this comment

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

The declaration and implementation have to match.

Copy link
Member

Choose a reason for hiding this comment

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

To minimise the number of changes, we can go for using jint in AwtMenu::GetItem.

What do you thing, @djelinski and @TheShermanTanker?

Copy link
Contributor Author

@TheShermanTanker TheShermanTanker Jun 23, 2023

Choose a reason for hiding this comment

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

Hmm, I lean towards jint as I feel it conveys the fact that it is a Java parameter clearer, intuitively to me it makes sense that a Java integer type would still work in a C++ for loop in native code

Copy link
Member

Choose a reason for hiding this comment

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

You're right… it gives a hint it'll be an upcall into Java. Let's go for jint then.

I don't think there's a need to change the type of the for-loop variable to jint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh no, I didn't mean to change the loop variable, rather that leaving the jint as is should be fine in the for loop

@TheShermanTanker
Copy link
Contributor Author

TheShermanTanker commented Jun 23, 2023

Wait a minute, I was right, it was a jint the whole time! Oh well, I'll wait for what @aivanov-jdk has to say, but I don't like the idea of leaving both inconsistent

@TheShermanTanker
Copy link
Contributor Author

Alright, waiting for you to do the honours :)

@TheShermanTanker
Copy link
Contributor Author

Alright, done

@TheShermanTanker
Copy link
Contributor Author

@aivanov-jdk Is the final change ok with you?

@aivanov-jdk
Copy link
Member

@aivanov-jdk Is the final change ok with you?

Looks good now. Thanks!

I've run client tests, all is green.

@TheShermanTanker
Copy link
Contributor Author

Haha, thanks Alexsey!

@TheShermanTanker
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 25, 2023

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 25, 2023

@TheShermanTanker Pushed as commit c92b049.

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

@TheShermanTanker TheShermanTanker deleted the integers branch June 25, 2023 23:43
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 core-libs core-libs-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants