Skip to content
Permalink
Browse files
8274395: Use enhanced-for instead of plain 'for' in jdk.internal.jvmstat
Reviewed-by: cjplummer, amenkov, sspitsyn
  • Loading branch information
turbanoff authored and plummercj committed Nov 9, 2021
1 parent e35abe3 commit 93692ea0a9bc437309b808f511c771a79dcdfb9a
Showing 7 changed files with 38 additions and 46 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -507,10 +507,10 @@ public String getMode() {
String query = getQuery();
if (query != null) {
String[] queryArgs = query.split("\\+");
for (int i = 0; i < queryArgs.length; i++) {
if (queryArgs[i].startsWith("mode=")) {
int index = queryArgs[i].indexOf('=');
return queryArgs[i].substring(index+1);
for (String queryArg : queryArgs) {
if (queryArg.startsWith("mode=")) {
int index = queryArg.indexOf('=');
return queryArg.substring(index + 1);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -385,10 +385,10 @@ public String getMode() {
String query = getQuery();
if (query != null) {
String[] queryArgs = query.split("\\+");
for (int i = 0; i < queryArgs.length; i++) {
if (queryArgs[i].startsWith("mode=")) {
int index = queryArgs[i].indexOf('=');
return queryArgs[i].substring(index+1);
for (String queryArg : queryArgs) {
if (queryArg.startsWith("mode=")) {
int index = queryArg.indexOf('=');
return queryArg.substring(index + 1);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -205,9 +205,11 @@ protected Monitor findByAlias(String name) {
if (m == null) {
ArrayList<String> al = aliasMap.get(name);
if (al != null) {
for (Iterator<String> i = al.iterator(); i.hasNext() && m == null; ) {
String alias = i.next();
for (String alias : al) {
m = monitors.get(alias);
if (m != null) {
break;
}
}
}
}
@@ -293,8 +295,7 @@ public List<Monitor> findByPattern(String patternString)

Set<Map.Entry<String,Monitor>> monitorSet = monitors.entrySet();

for (Iterator<Map.Entry<String, Monitor>> i = monitorSet.iterator(); i.hasNext(); /* empty */) {
Map.Entry<String, Monitor> me = i.next();
for (Map.Entry<String, Monitor> me : monitorSet) {
String name = me.getKey();
Monitor m = me.getValue();

@@ -303,7 +304,7 @@ public List<Monitor> findByPattern(String patternString)

// if the pattern matches, then add monitor to list
if (matcher.lookingAt()) {
matches.add(me.getValue());
matches.add(me.getValue());
}
}
return matches;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,6 @@
package sun.jvmstat.perfdata.monitor.protocol.local;

import java.util.*;
import java.lang.reflect.*;
import java.io.*;

import sun.jvmstat.monitor.*;
import sun.jvmstat.monitor.event.*;
@@ -152,8 +150,7 @@ void fireMonitorStatusChangedEvents(List<Monitor> inserted, List<Monitor> remove
registered = (ArrayList)listeners.clone();
}

for (Iterator<VmListener> i = registered.iterator(); i.hasNext(); /* empty */) {
VmListener l = i.next();
for (VmListener l : registered) {
// lazily create the event object;
if (ev == null) {
ev = new MonitorStatusChangeEvent(this, inserted, removed);
@@ -25,8 +25,6 @@

package sun.jvmstat.perfdata.monitor.protocol.local;

import sun.jvmstat.monitor.*;
import sun.jvmstat.monitor.event.*;
import java.util.*;
import java.util.regex.*;
import java.io.*;
@@ -105,19 +103,19 @@ public synchronized Set<Integer> activeVms() {
// 1.4.2 and later: Look for the files {tmpdir}/hsperfdata_{any_user_name}/[0-9]+
// that are readable by the current user.
File[] dirs = tmpdir.listFiles(userDirFilter);
for (int i = 0 ; i < dirs.length; i ++) {
if (!dirs[i].isDirectory()) {
for (File subDir : dirs) {
if (!subDir.isDirectory()) {
continue;
}

// get a list of files from the directory
File[] files = dirs[i].listFiles(userDirFileFilter);
File[] files = subDir.listFiles(userDirFileFilter);
if (files != null) {
for (int j = 0; j < files.length; j++) {
if (files[j].isFile() && files[j].canRead()) {
int vmid = PerfDataFile.getLocalVmId(files[j]);
for (File file : files) {
if (file.isFile() && file.canRead()) {
int vmid = PerfDataFile.getLocalVmId(file);
if (vmid != -1) {
jvmSet.add(vmid);
jvmSet.add(vmid);
}
}
}
@@ -127,11 +125,11 @@ public synchronized Set<Integer> activeVms() {
// look for any 1.4.1 files that are readable by the current user.
File[] files = tmpdir.listFiles(oldtmpFileFilter);
if (files != null) {
for (int j = 0; j < files.length; j++) {
if (files[j].isFile() && files[j].canRead()) {
int vmid = PerfDataFile.getLocalVmId(files[j]);
for (File file : files) {
if (file.isFile() && file.canRead()) {
int vmid = PerfDataFile.getLocalVmId(file);
if (vmid != -1) {
jvmSet.add(vmid);
jvmSet.add(vmid);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -170,8 +170,7 @@ private void fireVmStatusChangedEvents(Set<Integer> active, Set<Integer> started
registered = (ArrayList)listeners.clone();
}

for (Iterator<HostListener> i = registered.iterator(); i.hasNext(); /* empty */) {
HostListener l = i.next();
for (HostListener l : registered) {
if (ev == null) {
ev = new VmStatusChangeEvent(this, active, started, terminated);
}
@@ -198,17 +197,14 @@ public void run() {
Set<Integer> startedVms = new HashSet<>();
Set<Integer> terminatedVms = new HashSet<>();

for (Iterator<Integer> i = activeVms.iterator(); i.hasNext(); /* empty */) {
Integer vmid = i.next();
for (Integer vmid : activeVms) {
if (!lastActiveVms.contains(vmid)) {
// a new file has been detected, add to set
startedVms.add(vmid);
}
}

for (Iterator<Integer> i = lastActiveVms.iterator(); i.hasNext();
/* empty */) {
Integer o = i.next();
for (Integer o : lastActiveVms) {
if (!activeVms.contains(o)) {
// JVM has terminated, remove it from the active list
terminatedVms.add(o);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -81,9 +81,9 @@ public int toChar() {
* a valid Java TypeCode.
*/
public static TypeCode toTypeCode(char c) {
for (int j = 0; j < basicTypes.length; j++) {
if (basicTypes[j].value == c) {
return (basicTypes[j]);
for (TypeCode basicType : basicTypes) {
if (basicType.value == c) {
return basicType;
}
}
throw new IllegalArgumentException();

1 comment on commit 93692ea

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 93692ea Nov 9, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.