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

8273261: Replace 'while' cycles with iterator with enhanced-for in java.base #5328

Conversation

turbanoff
Copy link
Member

@turbanoff turbanoff commented Sep 1, 2021

There are few places in code where manual while loop is used with Iterator to iterate over Collection.
Instead of manual while cycles it's preferred to use enhanced-for cycle instead: it's less verbose, makes code easier to read and it's less error-prone.
It doesn't have any performance impact: java compiler generates similar code when compiling enhanced-for cycle.

Similar cleanups:


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8273261: Replace 'while' cycles with iterator with enhanced-for in java.base

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5328/head:pull/5328
$ git checkout pull/5328

Update a local copy of the PR:
$ git checkout pull/5328
$ git pull https://git.openjdk.java.net/jdk pull/5328/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5328

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5328.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Sep 1, 2021

👋 Welcome back turbanoff! 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 openjdk bot commented Sep 1, 2021

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

  • core-libs
  • net
  • security

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 security core-libs net labels Sep 1, 2021
@turbanoff
Copy link
Member Author

@turbanoff turbanoff commented Sep 2, 2021

Tested "tier2" on linux-x86_64-server-fastdebug Ubuntu 21.04

==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR   
>> jtreg:test/jdk:tier2                               3772  3771     1     0 <<
   jtreg:test/langtools:tier2                           11    11     0     0   
   jtreg:test/jaxp:tier2                               452   452     0     0   
==============================
TEST FAILURE

Only one test java/nio/file/FileStore/Basic.java failed, but it fails without my changes too.

----------System.out:(46/2591)----------
/sys (sysfs) (name=sysfs type=sysfs)
/proc (proc) (name=proc type=proc)
/dev (udev) (name=udev type=devtmpfs)
/dev/pts (devpts) (name=devpts type=devpts)
/run (tmpfs) (name=tmpfs type=tmpfs)
/ (/dev/sda3) (name=/dev/sda3 type=ext4)
/sys/kernel/security (securityfs) (name=securityfs type=securityfs)
/dev/shm (tmpfs) (name=tmpfs type=tmpfs)
/run/lock (tmpfs) (name=tmpfs type=tmpfs)
/sys/fs/cgroup (tmpfs) (name=tmpfs type=tmpfs)
/sys/fs/cgroup/unified (cgroup2) (name=cgroup2 type=cgroup2)
/sys/fs/cgroup/systemd (cgroup) (name=cgroup type=cgroup)
/sys/fs/pstore (pstore) (name=pstore type=pstore)
/sys/fs/bpf (none) (name=none type=bpf)
/sys/fs/cgroup/perf_event (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/cpuset (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/hugetlb (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/rdma (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/net_cls,net_prio (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/blkio (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/freezer (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/cpu,cpuacct (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/devices (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/pids (cgroup) (name=cgroup type=cgroup)
/sys/fs/cgroup/memory (cgroup) (name=cgroup type=cgroup)
/proc/sys/fs/binfmt_misc (systemd-1) (name=systemd-1 type=autofs)
/sys/kernel/tracing (tracefs) (name=tracefs type=tracefs)
/dev/mqueue (mqueue) (name=mqueue type=mqueue)
/sys/kernel/debug (debugfs) (name=debugfs type=debugfs)
/dev/hugepages (hugetlbfs) (name=hugetlbfs type=hugetlbfs)
/sys/fs/fuse/connections (fusectl) (name=fusectl type=fusectl)
/sys/kernel/config (configfs) (name=configfs type=configfs)
/snap/core18/1997 (/dev/loop0) (name=/dev/loop0 type=squashfs)
/snap/gnome-3-34-1804/66 (/dev/loop2) (name=/dev/loop2 type=squashfs)
/snap/gnome-3-34-1804/72 (/dev/loop3) (name=/dev/loop3 type=squashfs)
/snap/core18/2128 (/dev/loop1) (name=/dev/loop1 type=squashfs)
/snap/gtk-common-themes/1514 (/dev/loop4) (name=/dev/loop4 type=squashfs)
/snap/snapd/12704 (/dev/loop8) (name=/dev/loop8 type=squashfs)
/snap/gtk-common-themes/1515 (/dev/loop5) (name=/dev/loop5 type=squashfs)
/snap/snap-store/547 (/dev/loop7) (name=/dev/loop7 type=squashfs)
/snap/snap-store/518 (/dev/loop6) (name=/dev/loop6 type=squashfs)
/snap/snapd/12883 (/dev/loop9) (name=/dev/loop9 type=squashfs)
/boot/efi (/dev/sda2) (name=/dev/sda2 type=vfat)
/run/user/1000 (tmpfs) (name=tmpfs type=tmpfs)
/run/user/1000/gvfs (gvfsd-fuse) (name=gvfsd-fuse type=fuse.gvfsd-fuse)
/run/user/1000/doc (portal) (name=portal type=fuse.portal)
----------System.err:(18/1172)----------
java.nio.file.FileSystemException: /run/user/1000/doc: Operation not permitted
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:100)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixFileStore.readAttributes(UnixFileStore.java:115)
	at java.base/sun.nio.fs.UnixFileStore.getTotalSpace(UnixFileStore.java:122)
	at Basic.doTests(Basic.java:135)
	at Basic.main(Basic.java:49)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:312)
	at java.base/java.lang.Thread.run(Thread.java:833)

@openjdk
Copy link

@openjdk openjdk bot commented Sep 2, 2021

@turbanoff Unknown command sys - for a list of valid commands use /help.

@openjdk
Copy link

@openjdk openjdk bot commented Sep 2, 2021

@turbanoff Unknown command proc - for a list of valid commands use /help.

@openjdk
Copy link

@openjdk openjdk bot commented Sep 2, 2021

@turbanoff Unknown command dev - for a list of valid commands use /help.

@openjdk
Copy link

@openjdk openjdk bot commented Sep 2, 2021

@turbanoff Unknown command run - for a list of valid commands use /help.

@turbanoff turbanoff changed the title [PATCH] Replace while cycles with iterator with enhanced-for in java.base 8273261: Replace 'while' cycles with iterator with enhanced-for in java.base Sep 2, 2021
@openjdk openjdk bot added the rfr label Sep 2, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Sep 2, 2021

Webrevs

dfuch
dfuch approved these changes Sep 2, 2021
Copy link
Member

@dfuch dfuch left a comment

Generally this looks like a good improvement as the resulting code becomes more readable.
Changes in sun/net or jar index classes look fine. Please obtain approval from maintainers of the other areas before integrating.

@openjdk
Copy link

@openjdk openjdk bot commented Sep 2, 2021

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

8273261: Replace 'while' cycles with iterator with enhanced-for in java.base

Reviewed-by: dfuchs, rriggs, iris, mullan

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

  • 8c37909: 8273234: extended 'for' with expression of type tvar causes the compiler to crash
  • 28ba78e: 8244675: assert(IncrementalInline || (_late_inlines.length() == 0 && !has_mh_late_inlines()))
  • d05494f: 8266239: Some duplicated javac command-line options have repeated effect
  • 93eec9a: 8272776: NullPointerException not reported
  • 7b023a3: 8273257: jshell doesn't compile a sealed hierarchy with a sealed interface and a non-sealed leaf
  • f17ee0c: 8273263: Incorrect recovery attribution of record component type when j.l.Record is unavailable
  • fa9c865: 8273112: -Xloggc: should override -verbose:gc
  • dd87181: 8214761: Bug in parallel Kahan summation implementation
  • 7fff22a: 8272805: Avoid looking up standard charsets
  • 92b05fe: 8273251: Call check_possible_safepoint() from SafepointMechanism::process_if_requested()
  • ... and 21 more: https://git.openjdk.java.net/jdk/compare/e600fe1a1a57d7e4060b3a1b9a8ecdb65664a506...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 (@dfuch, @RogerRiggs, @irisclark, @seanjmullan) 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 label Sep 2, 2021
Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

LGTM

For the security related code a second reviewer would be good.

@turbanoff
Copy link
Member Author

@turbanoff turbanoff commented Sep 2, 2021

/integrate

@openjdk openjdk bot added the sponsor label Sep 2, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Sep 2, 2021

@turbanoff
Your change (at version 79c44a0) is now ready to be sponsored by a Committer.

Copy link
Member

@seanjmullan seanjmullan left a comment

The security related changes look fine to me.

@turbanoff
Copy link
Member Author

@turbanoff turbanoff commented Sep 23, 2021

Can someone sponsor changes, please? I believe we have enough approvals.

@RogerRiggs
Copy link
Contributor

@RogerRiggs RogerRiggs commented Sep 23, 2021

/sponsor

@openjdk
Copy link

@openjdk openjdk bot commented Sep 23, 2021

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

  • 0aa63fe: 8274216: ProblemList 2 serviceability/dcmd/gc tests with ZGC on linux-all and windows-all
  • 5ffbe75: 8274195: Doc cleanup in java.nio.file
  • 1fdc656: 8274175: (fc) java/nio/channels/FileChannel/Transfer2GPlus.java still failed in timeout
  • 3b1b8fc: 8269850: Most JDK releases report macOS version 12 as 10.16 instead of 12.0
  • 1b7f4b7: 8274169: HotSpot Style Guide has stale link to chromium style guide
  • 653a612: 8270156: Add "randomness" and "stress" keys to JTreg tests which use StressGCM, StressLCM and/or StressIGVN
  • 66ce09f: 8272703: StressSeed should be set via FLAG_SET_ERGO
  • c434528: 8273546: DecimalFormat documentation contains literal HTML character references
  • d098751: 8273916: Remove 'special' ranking
  • 4f3b626: 8271567: AArch64: AES Galois CounterMode (GCM) interleaved implementation using vector instructions
  • ... and 277 more: https://git.openjdk.java.net/jdk/compare/e600fe1a1a57d7e4060b3a1b9a8ecdb65664a506...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Sep 23, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Sep 23, 2021
@openjdk openjdk bot removed the sponsor label Sep 23, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Sep 23, 2021

@RogerRiggs @turbanoff Pushed as commit 56b8b35.

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

@turbanoff turbanoff deleted the replace_while_with_enhanced-for_in_java.base branch Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs integrated net security
5 participants