8274395: Use enhanced-for instead of plain 'for' in jdk.internal.jvmstat

Reviewed-by: cjplummer, amenkov, sspitsyn
This commit is contained in:
Andrey Turbanov 2021-11-09 16:58:43 +00:00 committed by Chris Plummer
parent e35abe3235
commit 93692ea0a9
7 changed files with 38 additions and 46 deletions

View File

@ -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 class HostIdentifier {
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);
}
}
}

View File

@ -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 class VmIdentifier {
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);
}
}
}

View File

@ -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 @@ public abstract class PerfDataBufferImpl {
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 abstract class PerfDataBufferImpl {
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 abstract class PerfDataBufferImpl {
// if the pattern matches, then add monitor to list
if (matcher.lookingAt()) {
matches.add(me.getValue());
matches.add(me.getValue());
}
}
return matches;

View File

@ -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 @@ public class LocalMonitoredVm extends AbstractMonitoredVm {
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);

View File

@ -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 class LocalVmManager {
// 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 class LocalVmManager {
// 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);
}
}
}

View File

@ -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 @@ public class MonitoredHostProvider extends MonitoredHost {
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 class MonitoredHostProvider extends MonitoredHost {
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);

View File

@ -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 class TypeCode {
* 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();