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

8274755: Replace 'while' cycles with iterator with enhanced-for in jdk.jdi #5577

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@@ -37,8 +37,6 @@
import com.sun.jdi.LocalVariable;
import com.sun.jdi.Location;
import com.sun.jdi.VirtualMachine;
import com.sun.tools.jdi.JDWP.Method.VariableTable;
import com.sun.tools.jdi.JDWP.Method.VariableTableWithGeneric;

/**
* Represents methods with method bodies.
@@ -220,9 +218,7 @@ public List<LocalVariable> variablesByName(String name) throws AbsentInformation
List<LocalVariable> variables = getVariables();

List<LocalVariable> retList = new ArrayList<>(2);
Iterator<LocalVariable> iter = variables.iterator();
while(iter.hasNext()) {
LocalVariable variable = iter.next();
for (LocalVariable variable : variables) {
if (variable.name().equals(name)) {
retList.add(variable);
}
@@ -234,9 +230,7 @@ public List<LocalVariable> arguments() throws AbsentInformationException {
List<LocalVariable> variables = getVariables();

List<LocalVariable> retList = new ArrayList<>(variables.size());
Iterator<LocalVariable> iter = variables.iterator();
while(iter.hasNext()) {
LocalVariable variable = iter.next();
for (LocalVariable variable : variables) {
if (variable.isArgument()) {
retList.add(variable);
}
@@ -289,9 +283,8 @@ private SoftLocationXRefs getLocations(SDE.Stratum stratum) {
int highestLine = -1;
SDE.LineStratum lastLineStratum = null;
SDE.Stratum baseStratum = declaringType.stratum(SDE.BASE_STRATUM_NAME);
Iterator<Location> it = getBaseLocations().lineLocations.iterator();
while(it.hasNext()) {
LocationImpl loc = (LocationImpl)it.next();
for (Location lineLocation : getBaseLocations().lineLocations) {
LocationImpl loc = (LocationImpl) lineLocation;
int baseLineNumber = loc.lineNumber(baseStratum);
SDE.LineStratum lineStratum =
stratum.lineStratum(declaringType, baseLineNumber);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -51,9 +51,8 @@ public Map<String,Argument> defaultArguments() {
Map<String,Argument> defaults = new LinkedHashMap<>();
Collection<Argument> values = defaultArguments.values();

Iterator<Argument> iter = values.iterator();
while (iter.hasNext()) {
ArgumentImpl argument = (ArgumentImpl)iter.next();
for (Argument a : values) {
ArgumentImpl argument = (ArgumentImpl) a;
defaults.put(argument.name(), (Argument)argument.clone());
}
return defaults;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@@ -611,9 +610,7 @@ class StepRequestImpl extends ClassVisibleEventRequestImpl
* Make sure this isn't a duplicate
*/
List<StepRequest> requests = stepRequests();
Iterator<StepRequest> iter = requests.iterator();
while (iter.hasNext()) {
StepRequest request = iter.next();
for (StepRequest request : requests) {
if ((request != this) &&
request.isEnabled() &&
request.thread().equals(thread)) {
@@ -880,9 +877,8 @@ public void deleteEventRequest(EventRequest eventRequest) {
public void deleteEventRequests(List<? extends EventRequest> eventRequests) {
validateMirrors(eventRequests);
// copy the eventRequests to avoid ConcurrentModificationException
Iterator<? extends EventRequest> iter = (new ArrayList<>(eventRequests)).iterator();
while (iter.hasNext()) {
((EventRequestImpl)iter.next()).delete();
for (EventRequest eventRequest : new ArrayList<>(eventRequests)) {
((EventRequestImpl) eventRequest).delete();
turbanoff marked this conversation as resolved.
Show resolved Hide resolved
}
}

@@ -969,9 +965,8 @@ List<? extends EventRequest> unmodifiableRequestList(int eventCmd) {
EventRequest request(int eventCmd, int requestId) {
List<? extends EventRequest> rl = requestList(eventCmd);
synchronized(rl) { // Refer Collections.synchronizedList javadoc.
Iterator<? extends EventRequest> itr = rl.iterator();
while (itr.hasNext()){
EventRequestImpl er = (EventRequestImpl)itr.next();
for (EventRequest eventRequest : rl) {
EventRequestImpl er = (EventRequestImpl) eventRequest;
if (er.id == requestId)
return er;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 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,7 +26,6 @@
package com.sun.tools.jdi;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -141,9 +140,8 @@ boolean isAssignableTo(ReferenceType type) {
return true;
} else {
List<InterfaceType> interfaces = interfaces();
Iterator<InterfaceType> iter = interfaces.iterator();
while (iter.hasNext()) {
InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
for (InterfaceType interfaceType : interfaces) {
InterfaceTypeImpl interfaze = (InterfaceTypeImpl) interfaceType;
turbanoff marked this conversation as resolved.
Show resolved Hide resolved
if (interfaze.isAssignableTo(type)) {
return true;
}
@@ -159,9 +157,8 @@ final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> s
* parent types first, so that the methods in this class will
* overwrite them in the hash table
*/
Iterator<InterfaceType> iter = interfaces().iterator();
while (iter.hasNext()) {
InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
for (InterfaceType interfaceType : interfaces()) {
InterfaceTypeImpl interfaze = (InterfaceTypeImpl) interfaceType;
turbanoff marked this conversation as resolved.
Show resolved Hide resolved
if (!seenInterfaces.contains(interfaze)) {
interfaze.addVisibleMethods(methodMap, seenInterfaces);
seenInterfaces.add(interfaze);
@@ -177,9 +174,8 @@ final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> s
final void addInterfaces(List<InterfaceType> list) {
List<InterfaceType> immediate = interfaces();
list.addAll(interfaces());
Iterator<InterfaceType> iter = immediate.iterator();
while (iter.hasNext()) {
InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
for (InterfaceType interfaceType : immediate) {
InterfaceTypeImpl interfaze = (InterfaceTypeImpl) interfaceType;
turbanoff marked this conversation as resolved.
Show resolved Hide resolved
interfaze.addInterfaces(list);
}
ClassTypeImpl superclass = (ClassTypeImpl) superclass();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -118,9 +118,8 @@ Method getMethodMirror(long ref) {
// Fetch all methods for the class, check performance impact
// Needs no synchronization now, since methods() returns
// unmodifiable local data
Iterator<Method> it = methods().iterator();
while (it.hasNext()) {
MethodImpl method = (MethodImpl)it.next();
for (Method m : methods()) {
MethodImpl method = (MethodImpl) m;
if (method.ref() == ref) {
return method;
}
@@ -132,9 +131,8 @@ Field getFieldMirror(long ref) {
// Fetch all fields for the class, check performance impact
// Needs no synchronization now, since fields() returns
// unmodifiable local data
Iterator<Field>it = fields().iterator();
while (it.hasNext()) {
FieldImpl field = (FieldImpl)it.next();
for (Field f : fields()) {
FieldImpl field = (FieldImpl) f;
if (field.ref() == ref) {
return field;
}
@@ -420,12 +418,11 @@ public List<Field> visibleFields() {

/* Add inherited, visible fields */
List<? extends ReferenceType> types = inheritedTypes();
Iterator<? extends ReferenceType> iter = types.iterator();
while (iter.hasNext()) {
for (ReferenceType referenceType : types) {
/*
* TO DO: Be defensive and check for cyclic interface inheritance
*/
ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
ReferenceTypeImpl type = (ReferenceTypeImpl) referenceType;
type.addVisibleFields(visibleList, visibleTable, ambiguousNames);
}

@@ -454,9 +451,8 @@ void addAllFields(List<Field> fieldList, Set<ReferenceType> typeSet) {

/* Add inherited fields */
List<? extends ReferenceType> types = inheritedTypes();
Iterator<? extends ReferenceType> iter = types.iterator();
while (iter.hasNext()) {
ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
for (ReferenceType referenceType : types) {
ReferenceTypeImpl type = (ReferenceTypeImpl) referenceType;
type.addAllFields(fieldList, typeSet);
}
}
@@ -916,9 +912,8 @@ public List<Location> locationsOfLine(String stratumID,

List<Location> list = new ArrayList<Location>();

Iterator<Method> iter = methods.iterator();
while(iter.hasNext()) {
MethodImpl method = (MethodImpl)iter.next();
for (Method m : methods) {
MethodImpl method = (MethodImpl) m;
// eliminate native and abstract to eliminate
// false positives
if (!method.isAbstract() &&
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@@ -187,19 +186,16 @@ public void run() {
// Closing a queue causes a VMDisconnectEvent to
// be put onto the queue.
synchronized(eventQueues) {
Iterator<EventQueue> iter = eventQueues.iterator();
while (iter.hasNext()) {
((EventQueueImpl)iter.next()).close();
for (EventQueue eventQueue : eventQueues) {
((EventQueueImpl) eventQueue).close();
}
}

// indirectly throw VMDisconnectedException to
// command requesters.
synchronized(waitingQueue) {
Iterator<Packet> iter = waitingQueue.values().iterator();
while (iter.hasNext()) {
Packet packet = iter.next();
synchronized(packet) {
for (Packet packet : waitingQueue.values()) {
synchronized (packet) {
packet.notify();
}
}
@@ -258,9 +254,8 @@ private synchronized void controlEventFlow(int maxQueueSize) {
void notifyDequeueEventSet() {
int maxQueueSize = 0;
synchronized(eventQueues) {
Iterator<EventQueue> iter = eventQueues.iterator();
while (iter.hasNext()) {
EventQueueImpl queue = (EventQueueImpl)iter.next();
for (EventQueue eventQueue : eventQueues) {
EventQueueImpl queue = (EventQueueImpl) eventQueue;
maxQueueSize = Math.max(maxQueueSize, queue.size());
}
}
@@ -271,9 +266,8 @@ private void queueEventSet(EventSet eventSet) {
int maxQueueSize = 0;

synchronized(eventQueues) {
Iterator<EventQueue> iter = eventQueues.iterator();
while (iter.hasNext()) {
EventQueueImpl queue = (EventQueueImpl)iter.next();
for (EventQueue eventQueue : eventQueues) {
EventQueueImpl queue = (EventQueueImpl) eventQueue;
queue.enqueue(eventSet);
maxQueueSize = Math.max(maxQueueSize, queue.size());
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -314,9 +314,7 @@ public boolean isAtBreakpoint() {
StackFrame frame = frame(0);
Location location = frame.location();
List<BreakpointRequest> requests = vm.eventRequestManager().breakpointRequests();
Iterator<BreakpointRequest> iter = requests.iterator();
while (iter.hasNext()) {
BreakpointRequest request = iter.next();
for (BreakpointRequest request : requests) {
if (location.equals(request.location())) {
return true;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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
@@ -174,9 +174,7 @@ synchronized void addListener(VMListener listener) {
}

synchronized boolean hasListener(VMListener listener) {
Iterator<WeakReference<VMListener>> iter = listeners.iterator();
while (iter.hasNext()) {
WeakReference<VMListener> ref = iter.next();
for (WeakReference<VMListener> ref : listeners) {
if (listener.equals(ref.get())) {
return true;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -46,7 +46,6 @@
import com.sun.jdi.ByteValue;
import com.sun.jdi.CharType;
import com.sun.jdi.CharValue;
import com.sun.jdi.ClassLoaderReference;
import com.sun.jdi.ClassNotLoadedException;
import com.sun.jdi.DoubleType;
import com.sun.jdi.DoubleValue;
@@ -1179,9 +1178,7 @@ void waitForTargetReply(Packet packet) {

Type findBootType(String signature) throws ClassNotLoadedException {
List<ReferenceType> types = retrieveClassesBySignature(signature);
Iterator<ReferenceType> iter = types.iterator();
while (iter.hasNext()) {
ReferenceType type = iter.next();
for (ReferenceType type : types) {
if (type.classLoader() == null) {
return type;
}