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

8303018: Unicode Emoji Properties #13006

Closed
wants to merge 8 commits into from

Conversation

naotoj
Copy link
Member

@naotoj naotoj commented Mar 13, 2023

Proposing accessor methods to Emoji properties defined in Unicode Technical Standard #51 in java.lang.Character class. This is per a request from the client group, as well as refining the currently existing ad-hoc emoji implementation in regex. A CSR has also been drafted, and I would appreciate reviews for it too.


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
  • Change requires CSR request JDK-8304027 to be approved

Issues

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13006

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 13, 2023

👋 Welcome back naoto! 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 Mar 13, 2023
@openjdk
Copy link

openjdk bot commented Mar 13, 2023

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

  • build
  • core-libs
  • i18n

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 build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Mar 13, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 13, 2023

Webrevs

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 13, 2023
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.

Not at all familiar with all these templates but everything I do understand lgtm :-)

* {@code false} otherwise.
* @since 21
*/
public static boolean isExtendedPictographic(int codePoint) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a "cut 'n paste" error here, it looks like the description has been copied from isEmojiComponent.

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad. You are right. Corrected.


/**
* Determines if the specified character (Unicode code point) has the
* Emoji Presentation by default.
Copy link
Contributor

Choose a reason for hiding this comment

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

"has the Emoji Presentation", should that be "has the Emoji Presentation property"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this one as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed this one as well

Spec update looks good. I suppose I have to use an emoji to react to that 👍

Copy link
Member

@erikj79 erikj79 left a comment

Choose a reason for hiding this comment

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

Build changes look ok.

Comment on lines 210 to 215
maskEmojiPresentation = 0x008000000000L,
maskEmojiModifier = 0x010000000000L,
maskEmojiModifierBase = 0x020000000000L,
maskEmojiComponent = 0x040000000000L,
maskExtendedPictographic = 0x080000000000L;

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice the have the '=' aligned in the same column as the ones above, or at least have the emoji ones align with each other.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Indentation aligned, and although in production -string is used so comments are not emitted, added information for B table in GenerateCharacter.propertiesComments for consistency.

@eirbjo
Copy link
Contributor

eirbjo commented Mar 14, 2023

Would it make sense to add something like the following to GenerateCharacter.propertiesComments?

if ((val & maskEmoji) == maskEmoji) {
    result.append(", emoji ");
}
if ((val & maskEmojiPresentation) == maskEmojiPresentation) {
    result.append(", emojiPresentation ");
}
if ((val & maskEmojiModifier) == maskEmojiModifier) {
    result.append(", emojiModifier ");
}
if ((val & maskEmojiModifierBase) == maskEmojiModifierBase) {
    result.append(", emojiModifierBase ");
}
if ((val & maskEmojiComponent) == maskEmojiComponent) {
    result.append(", emojiComponent ");
}
if ((val & maskExtendedPictographic) == maskExtendedPictographic) {
    result.append(", extendedPictographic ");
}

This updates the comments of the B table to something like this sample:

0x0000,  //  34   unassigned, L
0x0440,  //  35   unassigned, L, emoji , emojiComponent
0x0000,  //  36   unassigned, L

Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

Looks good.
There are opportunities to modernize the code, but maybe separately.

case "Emoji_Modifier_Base" -> EMOJI_MODIFIER_BASE;
case "Emoji_Component" -> EMOJI_COMPONENT;
case "Extended_Pictographic" -> EXTENDED_PICTOGRAPHIC;
default -> throw new InternalError();
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful to include the "type" as the exception argument. It give some idea as to the corruption or missing case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added type to the error message

Comment on lines 203 to 214
maskOtherLowercase = 0x000100000000L,
maskOtherUppercase = 0x000200000000L,
maskOtherAlphabetic = 0x000400000000L,
maskIdeographic = 0x000800000000L,
maskIDStart = 0x001000000000L,
maskIDContinue = 0x002000000000L,
maskEmoji = 0x004000000000L,
maskEmojiPresentation = 0x008000000000L,
maskEmojiModifier = 0x010000000000L,
maskEmojiModifierBase = 0x020000000000L,
maskEmojiComponent = 0x040000000000L,
maskExtendedPictographic = 0x080000000000L;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to leverage a common definition (perhaps a bit number) here and in EmojiData.java
and build the constants with <<< shifts.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I managed to get rid of the constants in EmojiData altogether, by using the constants in GenerateCharacter. Used the bit numbers to construct constants.

Comment on lines +805 to +810
if (x.equals("maskEmoji")) return "0x" + hex4(maskEmoji >> 32);
if (x.equals("maskEmojiPresentation")) return "0x" + hex4(maskEmojiPresentation >> 32);
if (x.equals("maskEmojiModifier")) return "0x" + hex4(maskEmojiModifier >> 32);
if (x.equals("maskEmojiModifierBase")) return "0x" + hex4(maskEmojiModifierBase >> 32);
if (x.equals("maskEmojiComponent")) return "0x" + hex4(maskEmojiComponent >> 32);
if (x.equals("maskExtendedPictographic")) return "0x" + hex4(maskExtendedPictographic >> 32);
Copy link
Contributor

Choose a reason for hiding this comment

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

An upgrade would be to modify hex4(), hexNN() to use HexFormat.of().toUpperCase().toHexDigits((short)xxx)
The HexFormat is reusable and would avoid creating extra strings.
Perhaps also create a method that combines the repetitive shift and prefixing.

This if...then... sequence could be an expression switch (x) {...}.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be good, but it would be for another day IMO.

@eirbjo
Copy link
Contributor

eirbjo commented Mar 15, 2023

Unrelated side note: Reviewing this PR inspired me to see if one could generate more efficient switch expressions for the CharacterDataLatin1 methods as replacement for the property lookup / masking done today. This seemed to give a small improvements on benchmarks and also collapsed a few methods to simply "return false". Could be something to explore at a later point.

@naotoj
Copy link
Member Author

naotoj commented Mar 15, 2023

Unrelated side note: Reviewing this PR inspired me to see if one could generate more efficient switch expressions for the CharacterDataLatin1 methods as replacement for the property lookup / masking done today. This seemed to give a small improvements on benchmarks and also collapsed a few methods to simply "return false". Could be something to explore at a later point.

Yeah, agree. Latin1 can be (should be?) fast-path'ed as always.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Mar 20, 2023
@openjdk
Copy link

openjdk bot commented Mar 20, 2023

@naotoj 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:

8303018: Unicode Emoji Properties

Reviewed-by: prr, erikj, rriggs

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

  • bc0ed73: 8304303: implement VirtualThread class notifyJvmti methods as C2 intrinsics
  • 2d0d057: 8304016: Add BitMap find_last suite of functions
  • 42723dc: 8304420: Regression ~11% with Javac-Generates on all platforms in b14
  • 19f2edd: 8304541: Modules THROW_MSG_ should return nullptr instead of JNI_FALSE
  • 622f239: 8304163: Move jdk.internal.module.ModuleInfoWriter to the test library
  • 4c8c993: 8304364: [AIX] Build erroneously determines build disk is non-local when using GNU-utils df on AIX
  • 4ed7350: 8304393: Provide method to iterate over regions of humongous object in G1
  • eb73fa8: 8301715: CDS should be disabled in exploded JDK
  • 80e9797: 8304433: cleanup sentence breaker code in DocTreeMaker
  • c396f1e: 8304443: bootcycle builds fail after JDK-8015831
  • ... and 78 more: https://git.openjdk.org/jdk/compare/5685107579f0f00b5eae881311315cec34c1ddcb...master

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 Mar 20, 2023
@naotoj
Copy link
Member Author

naotoj commented Mar 20, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Mar 20, 2023

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

  • bc0ed73: 8304303: implement VirtualThread class notifyJvmti methods as C2 intrinsics
  • 2d0d057: 8304016: Add BitMap find_last suite of functions
  • 42723dc: 8304420: Regression ~11% with Javac-Generates on all platforms in b14
  • 19f2edd: 8304541: Modules THROW_MSG_ should return nullptr instead of JNI_FALSE
  • 622f239: 8304163: Move jdk.internal.module.ModuleInfoWriter to the test library
  • 4c8c993: 8304364: [AIX] Build erroneously determines build disk is non-local when using GNU-utils df on AIX
  • 4ed7350: 8304393: Provide method to iterate over regions of humongous object in G1
  • eb73fa8: 8301715: CDS should be disabled in exploded JDK
  • 80e9797: 8304433: cleanup sentence breaker code in DocTreeMaker
  • c396f1e: 8304443: bootcycle builds fail after JDK-8015831
  • ... and 78 more: https://git.openjdk.org/jdk/compare/5685107579f0f00b5eae881311315cec34c1ddcb...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 20, 2023

@naotoj Pushed as commit f593a6b.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated
6 participants