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

8269957: facilitate alternate impls of NameTable and Name #13282

Closed
wants to merge 13 commits into from

Conversation

archiecobbs
Copy link
Contributor

@archiecobbs archiecobbs commented Apr 2, 2023

The Name.Table class is used by the compiler to hold unique instances of strings as Name objects.

In theory the Name superclass supports alternate implementations beyond the two existing implementations (SharedNameTable and UnsharedNameTable), but its current design presumes that strings are stored as UTF-8 byte arrays, which discourages other approaches.

The goal of this PR is to refactor things to allow for more flexibility in alternate Name implementations.

As a simple test case of this idea, it should be relatively simple to implement a Name.Table that stores Strings in a hash table. This patch includes such an example in the new class StringNameTable, which can be enabled via the -XDuseStringTable=true command line flag. A simple performance test with this class enabled (JavacNameTable.java.txt) shows a 17% speedup.

Changes:

  • Remove all byte-oriented methods from the Name and Name.Table API's, except for those that import/export Modified UTF-8.
  • Change the semantics of Name.subName() so the offset is a character offset, not a byte offset.
  • Consolidate the common UTF-8 machinery of SharedNameTable and UnsharedNameTable into a new common superclass Utf8NameTable.
  • Rename Name.lastIndexOf() -> Name.lastIndexOfAscii() to more accurately reflect its expected behavior.
  • Add new StringNameTable implementation.

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 2 Reviewers)

Issue

  • JDK-8269957: facilitate alternate impls of NameTable and Name (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13282

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 2, 2023

👋 Welcome back archiecobbs! 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
Copy link

openjdk bot commented Apr 2, 2023

@archiecobbs The following label will be automatically applied to this pull request:

  • compiler

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 compiler compiler-dev@openjdk.org label Apr 2, 2023
@jonathan-gibbons
Copy link
Contributor

Is it worth adding StringNameTable into the PR?

@jonathan-gibbons
Copy link
Contributor

Is it worth putting static factory methods on Name.Table ?

@archiecobbs
Copy link
Contributor Author

Is it worth adding StringNameTable into the PR?

I was going to ask you the same question :)

It's probably the right thing to do unless there's some rule against including code that's not normally going to be used.

We can add another secret flag to enable it. Currently we have -XDuseUnsharedTable=true which enables UnsharedNameTable, so we could add -XDuseStringTable to enable StringNameTable.

Added in 23bb345.

Is it worth putting static factory methods on Name.Table ?

Good idea.. but I think maybe they make more sense being added to Names rather than Name.Table since a Names object is a required parameter.

Added in c9cf303.

Comment on lines 106 to 111
if (obj == this)
return true;
if (obj == null || obj.getClass() != getClass())
return false;
final NameImpl that = (NameImpl)obj;
return that.table == table && that.string.equals(string);
Copy link

Choose a reason for hiding this comment

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

This can use instanceof <pattern> to match Utf8NameTable.NameImpl::equals:

Suggested change
if (obj == this)
return true;
if (obj == null || obj.getClass() != getClass())
return false;
final NameImpl that = (NameImpl)obj;
return that.table == table && that.string.equals(string);
return (obj instanceof NameImpl name)
&& table == name.table
&& string.equals(name.string);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I agree the two implementations should be consistent. However you also made me realize that some common logic (e.g., type and same table checks) can be pushed up into the superclass. Also I think we should keep the initial same object check though for performance.

Refactored in c5a2546.

@archiecobbs archiecobbs marked this pull request as ready for review April 4, 2023 19:03
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 4, 2023
@mlbridge
Copy link

mlbridge bot commented Apr 4, 2023

Webrevs

@jonathan-gibbons
Copy link
Contributor

It's probably the right thing to do unless there's some rule against including code that's not normally going to be used.

Well, while totally dead code is a bad thing, there is potential to explore the use of StringNameTable in both javadoc, and maybe even for javac.

@bridgekeeper
Copy link

bridgekeeper bot commented May 3, 2023

@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@archiecobbs
Copy link
Contributor Author

/pingbot

@openjdk
Copy link

openjdk bot commented May 3, 2023

@archiecobbs Unknown command pingbot - for a list of valid commands use /help.

@archiecobbs
Copy link
Contributor Author

I figured out how to run performance tests and ran tests using SharedNameTable, UnsharedNameTable, and the new StringNameTable.

The latter is about 17% faster:

Benchmark                         Mode  Cnt   Score   Error  Units
JavacNameTable.testSharedTable    avgt   25  52.601 ± 1.025  ms/op
JavacNameTable.testStringTable    avgt   25  43.331 ± 1.165  ms/op
JavacNameTable.testUnsharedTable  avgt   25  57.687 ± 1.728  ms/op

Here is the test I ran: JavacNameTable.java

@openjdk
Copy link

openjdk bot commented Jun 12, 2023

@archiecobbs this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8269957
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Jun 12, 2023
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Jun 12, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 10, 2023

@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@archiecobbs
Copy link
Contributor Author

Keep alive...

Does a 17% speedup in compile time interest anyone??

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 7, 2023

@archiecobbs This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@archiecobbs
Copy link
Contributor Author

pingbot

@jonathan-gibbons
Copy link
Contributor

jonathan-gibbons commented Aug 25, 2023

Verified javadoc tests all pass if StringNameTable is on by default in javadoc

@jonathan-gibbons
Copy link
Contributor

jonathan-gibbons commented Aug 25, 2023

Verified API documentation is unchanged if StringNameTable is on by default in javadoc

@jonathan-gibbons
Copy link
Contributor

CI job for all tier1 tests, with StringNameTable enabled by default, passed.

Copy link
Contributor

@jonathan-gibbons jonathan-gibbons left a comment

Choose a reason for hiding this comment

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

The code passes javadoc tests and :tier1 tests with StringNameTable enabled.

I'll approve, but recommend we get Vicente's approval, as a javac dev, as well.

@openjdk
Copy link

openjdk bot commented Aug 26, 2023

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

8269957: facilitate alternate impls of NameTable and Name

Reviewed-by: jjg, vromero

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

  • acd9310: 8313430: [JVMCI] fatal error: Never compilable: in JVMCI shutdown
  • 8a5db6b: 8237542: JMapHeapConfigTest.java doesn't work with negative jlong values
  • d0cc043: 8314550: [macosx-aarch64] serviceability/sa/TestJmapCore.java fails with "sun.jvm.hotspot.debugger.UnmappedAddressException: 801000800"
  • 837d2e1: 8314483: Optionally override copyright header in generated source
  • 3201623: 8310454: Introduce static-libs-graal bundle
  • e9ba8d5: 8314960: Add Certigna Root CA - 2
  • 837cf85: 8312547: Max/Min nodes Value implementation could be improved
  • 7342f5a: 8314333: Update com/sun/jdi/ProcessAttachTest.java to use ProcessTools.createTestJvm(..)
  • f139f30: 8315033: Problemlist java/lang/template/StringTemplateTest.java
  • f2383b3: 8314063: The socket is not closed in Connection::createSocket when the handshake failed for LDAP connection
  • ... and 118 more: https://git.openjdk.org/jdk/compare/f23995465767fa7319d2f6fac62b6ec74c0e4986...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jonathan-gibbons, @vicente-romero-oracle) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 26, 2023
@archiecobbs
Copy link
Contributor Author

I'll approve, but recommend we get Vicente's approval, as a javac dev, as well.

Thanks @jonathan-gibbons. I agree and will bump the required reviewer count.

/reviewers 2 reviewer

@openjdk
Copy link

openjdk bot commented Aug 26, 2023

@archiecobbs
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 2 Reviewers).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 26, 2023
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle 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 to me too, thanks for fixing this!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 26, 2023
@archiecobbs
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Aug 26, 2023
@openjdk
Copy link

openjdk bot commented Aug 26, 2023

@archiecobbs
Your change (at version 193d066) is now ready to be sponsored by a Committer.

@vicente-romero-oracle
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Aug 28, 2023

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

  • 725ec0c: 8315020: The macro definition for LoongArch64 zero build is not accurate.
  • 1c3177e: 8315029: [BACKOUT] Generational ZGC: Tests crash with assert(index == 0 || is_power_of_2(index))
  • dd23f7d: 8315039: Parallel: Remove unimplemented PSYoungGen::oop_iterate
  • 5c4f1dc: 8314513: [IR Framework] Some internal IR Framework tests are failing after JDK-8310308 on PPC and Cascade Lake
  • cf2d33c: 8299658: C1 compilation crashes in LinearScan::resolve_exception_edge
  • 1664e79: 8311792: java/net/httpclient/ResponsePublisher.java fails intermittently with AssertionError: Found some outstanding operations
  • 0901d75: 8314762: Make {@Incubating} conventional
  • 12de9b0: 8314148: Fix variable scope in SunMSCAPI
  • 7fbad4c: 8310596: Utilize existing method frame::interpreter_frame_monitor_size_in_bytes()
  • 752a438: 8314684: Add overview docs to loaderConstraints.cpp
  • ... and 128 more: https://git.openjdk.org/jdk/compare/f23995465767fa7319d2f6fac62b6ec74c0e4986...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 28, 2023

@vicente-romero-oracle @archiecobbs Pushed as commit 11da15d.

💡 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
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
4 participants