From 12643e217ab9253082071d28d1b1df14321f5e2b Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Fri, 16 Aug 2019 01:39:32 +0300 Subject: [PATCH] Use generics instead of raw types where possible --- .gitignore | 3 + .../modules/tracer/impl/swing/ColorIcon.java | 2 +- .../overview/ApplicationOverviewModel.java | 13 ++-- .../visualvm/core/datasource/DataSource.java | 2 +- .../core/datasource/DataSourceProvider.java | 8 +-- .../core/datasupport/DataChangeSupport.java | 2 +- .../core/explorer/ExplorerModelBuilder.java | 5 +- .../core/ui/DataSourceViewsManager.java | 2 +- .../visualvm/coredump/CoreDumpsSorting.java | 2 +- .../coredump/impl/CoreDumpProvider.java | 6 +- .../heapviewer/model/ContainerNode.java | 4 +- .../heapviewer/oql/CustomOQLQueries.java | 4 +- .../visualvm/heapviewer/utils/HeapUtils.java | 2 +- .../org/graalvm/visualvm/host/impl/Ping.java | 4 +- .../visualvm/jmx/CredentialsProvider.java | 2 +- .../application/ConnectionsCustomizer.java | 4 +- .../lib/charts/swing/CrossBorderLayout.java | 2 +- .../visualvm/lib/ui/charts/BarChart.java | 6 +- .../lib/ui/components/tree/CheckTreeNode.java | 12 ++-- .../visualvm/lib/ui/cpu/CCTDisplay.java | 5 +- .../lib/ui/memory/AllocResultsPanel.java | 5 +- .../lib/jfluid/classfile/ClassFileCache.java | 26 +++---- .../lib/jfluid/classfile/ClassPath.java | 18 ++--- .../lib/jfluid/classfile/ClassRepository.java | 48 +++++++------ .../jfluid/classfile/DynamicClassInfo.java | 6 +- .../jfluid/classfile/SameNameClassGroup.java | 8 +-- .../jfluid/global/TransactionalSupport.java | 16 ++--- .../visualvm/lib/jfluid/heap/ClassDump.java | 58 +++++++--------- .../lib/jfluid/heap/ClassDumpSegment.java | 67 ++++++++----------- .../lib/jfluid/heap/ComputedSummary.java | 5 +- .../lib/jfluid/heap/DominatorTree.java | 14 ++-- .../lib/jfluid/heap/HeapProgress.java | 10 +-- .../visualvm/lib/jfluid/heap/HprofHeap.java | 21 +++--- .../CodeRegionMethodInstrumentor.java | 5 +- .../lib/jfluid/marker/CompositeMarker.java | 24 +++---- .../results/AbstractDataFrameProcessor.java | 10 +-- .../jfluid/results/BaseCallGraphBuilder.java | 22 +++--- .../lib/jfluid/results/DataManager.java | 24 +++---- .../results/cpu/CPUCCTClassContainer.java | 8 +-- .../jfluid/results/cpu/CPUCCTContainer.java | 4 +- .../results/cpu/CPUCallGraphBuilder.java | 4 +- .../results/cpu/CPUDataFrameProcessor.java | 8 +-- .../jfluid/results/cpu/CPUResultsDiff.java | 4 +- .../results/cpu/CPUResultsSnapshot.java | 16 ++--- .../cpu/CPUSamplingDataFrameProcessor.java | 8 +-- .../jfluid/results/cpu/cct/CCTFlattener.java | 6 +- .../results/cpu/cct/CCTResultsFilter.java | 24 +++---- .../lib/jfluid/server/ClassBytesLoader.java | 4 +- .../visualvm/lib/jfluid/utils/MiscUtils.java | 14 ++-- .../heapwalk/ClassesListController.java | 44 ++++++------ .../profiler/heapwalk/model/BrowserUtils.java | 2 +- .../snaptracer/impl/swing/ColorIcon.java | 2 +- .../profiler/v2/impl/ClassMethodSelector.java | 17 ++--- .../visualvm/sampler/cpu/CCTFlattener.java | 6 +- .../sampler/cpu/CPUSamplerSupport.java | 2 +- 55 files changed, 303 insertions(+), 347 deletions(-) diff --git a/.gitignore b/.gitignore index a63a9d610f..b8228f2650 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ /l10n/en.nbms/ /l10n/l10nantext.jar /plugins/nbproject/private/ +*.iml +/out/ +/.idea/ diff --git a/plugins/tracer/src/org/graalvm/visualvm/modules/tracer/impl/swing/ColorIcon.java b/plugins/tracer/src/org/graalvm/visualvm/modules/tracer/impl/swing/ColorIcon.java index d1f1d49602..383e054281 100644 --- a/plugins/tracer/src/org/graalvm/visualvm/modules/tracer/impl/swing/ColorIcon.java +++ b/plugins/tracer/src/org/graalvm/visualvm/modules/tracer/impl/swing/ColorIcon.java @@ -45,7 +45,7 @@ public final class ColorIcon implements javax.swing.Icon { private final boolean shadow; private final Color color; - private static final Map icons = new HashMap(); + private static final Map icons = new HashMap<>(); private ColorIcon(Color color) { diff --git a/visualvm/applicationviews/src/org/graalvm/visualvm/application/views/overview/ApplicationOverviewModel.java b/visualvm/applicationviews/src/org/graalvm/visualvm/application/views/overview/ApplicationOverviewModel.java index a3f731c4c3..6921674a2d 100644 --- a/visualvm/applicationviews/src/org/graalvm/visualvm/application/views/overview/ApplicationOverviewModel.java +++ b/visualvm/applicationviews/src/org/graalvm/visualvm/application/views/overview/ApplicationOverviewModel.java @@ -257,20 +257,17 @@ private static String formatJVMArgs(String jvmargs) { private static String formatSystemProperties(Properties properties) { StringBuilder text = new StringBuilder(200); - List keys = new ArrayList(); + List keys = new ArrayList<>(); Enumeration en = properties.propertyNames(); - Iterator keyIt; - + while (en.hasMoreElements()) { - keys.add(en.nextElement()); + keys.add((String) en.nextElement()); } Collections.sort(keys); - keyIt = keys.iterator(); - while (keyIt.hasNext()) { - String key = (String) keyIt.next(); + for (String key : keys) { String val = properties.getProperty(key); - + if ("line.separator".equals(key) && val != null) { // NOI18N val = val.replace("\n", "\\n"); // NOI18N val = val.replace("\r", "\\r"); // NOI18N diff --git a/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSource.java b/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSource.java index 121115a539..6f1ea87266 100644 --- a/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSource.java +++ b/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSource.java @@ -311,7 +311,7 @@ final boolean hasRemovedListeners() { } final synchronized Set> getRemovedListeners() { - if (!hasRemovedListeners()) removedListeners = Collections.synchronizedSet(new HashSet()); + if (!hasRemovedListeners()) removedListeners = Collections.synchronizedSet(new HashSet<>()); return removedListeners; } diff --git a/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSourceProvider.java b/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSourceProvider.java index 6637f58d6f..15e09016d7 100644 --- a/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSourceProvider.java +++ b/visualvm/core/src/org/graalvm/visualvm/core/datasource/DataSourceProvider.java @@ -51,8 +51,8 @@ public class DataSourceProvider { Boolean.getBoolean(DataSourceProvider.class.getName() + ".suppressExceptionsUI"); // NOI18N private static final Logger LOGGER = Logger.getLogger(DataSourceProvider.class.getName()); - private final Set dataSources = Collections.synchronizedSet(new HashSet()); - private final Map, Class> listeners = new HashMap(); + private final Set dataSources = Collections.synchronizedSet(new HashSet<>()); + private final Map, Class> listeners = new HashMap<>(); /** @@ -196,7 +196,7 @@ void unregisterDataSourcesImpl(Set removed) { } private Set checkAdded(Set added) { - Set uniqueAdded = new HashSet(added); + Set uniqueAdded = new HashSet<>(added); Iterator it = uniqueAdded.iterator(); while(it.hasNext()) { @@ -211,7 +211,7 @@ private Set checkAdded(Set added) { } private Set checkRemoved(Set removed) { - Set uniqueRemoved = new HashSet(removed); + Set uniqueRemoved = new HashSet<>(removed); Iterator it = uniqueRemoved.iterator(); while(it.hasNext()) { diff --git a/visualvm/core/src/org/graalvm/visualvm/core/datasupport/DataChangeSupport.java b/visualvm/core/src/org/graalvm/visualvm/core/datasupport/DataChangeSupport.java index 4978f9c739..ba91402a94 100644 --- a/visualvm/core/src/org/graalvm/visualvm/core/datasupport/DataChangeSupport.java +++ b/visualvm/core/src/org/graalvm/visualvm/core/datasupport/DataChangeSupport.java @@ -94,7 +94,7 @@ public void run() { private static class ChangeSupport { - private Set> listeners = new HashSet(); + private Set> listeners = new HashSet<>(); private Set currentSet; private void addChangeListener(DataChangeListener listener) { diff --git a/visualvm/core/src/org/graalvm/visualvm/core/explorer/ExplorerModelBuilder.java b/visualvm/core/src/org/graalvm/visualvm/core/explorer/ExplorerModelBuilder.java index aae70a18fc..da6bdb1d72 100644 --- a/visualvm/core/src/org/graalvm/visualvm/core/explorer/ExplorerModelBuilder.java +++ b/visualvm/core/src/org/graalvm/visualvm/core/explorer/ExplorerModelBuilder.java @@ -412,7 +412,7 @@ protected int getRelativePosition(DataSource d, int positionType) { } - private static class IndexNodePair implements Comparable { + private static class IndexNodePair implements Comparable { public int index; public ExplorerNode node; @@ -422,8 +422,7 @@ public IndexNodePair(int index, ExplorerNode node) { this.node = node; } - public int compareTo(Object o) { - IndexNodePair pair = (IndexNodePair)o; + public int compareTo(IndexNodePair pair) { if (index == pair.index) return 0; if (index > pair.index) return 1; else return -1; diff --git a/visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceViewsManager.java b/visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceViewsManager.java index fe99673d62..ef9cb22d41 100644 --- a/visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceViewsManager.java +++ b/visualvm/core/src/org/graalvm/visualvm/core/ui/DataSourceViewsManager.java @@ -49,7 +49,7 @@ public final class DataSourceViewsManager { private static DataSourceViewsManager sharedInstance; // TODO: implement some better data structure for cheaper providers query - private final Map> providers = Collections.synchronizedMap(new HashMap()); + private final Map> providers = Collections.synchronizedMap(new HashMap<>()); /** diff --git a/visualvm/coredump/src/org/graalvm/visualvm/coredump/CoreDumpsSorting.java b/visualvm/coredump/src/org/graalvm/visualvm/coredump/CoreDumpsSorting.java index 52a5e08618..4c4d4aea19 100644 --- a/visualvm/coredump/src/org/graalvm/visualvm/coredump/CoreDumpsSorting.java +++ b/visualvm/coredump/src/org/graalvm/visualvm/coredump/CoreDumpsSorting.java @@ -54,7 +54,7 @@ final class CoreDumpsSorting implements Presenter.Menu { private static final Comparator BY_TIME_COMPARATOR = byTimeComparator(); private static final Comparator BY_NAME_COMPARATOR = byNameComparator(); - private static final List> COMPARATORS = new ArrayList(); + private static final List> COMPARATORS = new ArrayList<>(); static { COMPARATORS.add(BY_TIME_COMPARATOR); COMPARATORS.add(BY_NAME_COMPARATOR); } private final Preferences prefs; diff --git a/visualvm/coredump/src/org/graalvm/visualvm/coredump/impl/CoreDumpProvider.java b/visualvm/coredump/src/org/graalvm/visualvm/coredump/impl/CoreDumpProvider.java index b2481fe0e3..3c5c8f884b 100644 --- a/visualvm/coredump/src/org/graalvm/visualvm/coredump/impl/CoreDumpProvider.java +++ b/visualvm/coredump/src/org/graalvm/visualvm/coredump/impl/CoreDumpProvider.java @@ -206,9 +206,9 @@ public boolean accept(File dir, String name) { } }); - Set unresolvedCoreDumpsF = new HashSet(); - Set unresolvedCoreDumpsS = new HashSet(); - Set coredumps = new HashSet(); + Set unresolvedCoreDumpsF = new HashSet<>(); + Set unresolvedCoreDumpsS = new HashSet<>(); + Set coredumps = new HashSet<>(); for (File file : files) { Storage storage = new Storage(file.getParentFile(), file.getName()); String[] propNames = new String[] { diff --git a/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/model/ContainerNode.java b/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/model/ContainerNode.java index bb186a050d..082f4715a2 100644 --- a/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/model/ContainerNode.java +++ b/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/model/ContainerNode.java @@ -47,7 +47,7 @@ public abstract class ContainerNode extends HeapViewerNode { protected final int maxNodes; - protected final List items; + protected final List items = new ArrayList<>(); protected final String name; @@ -63,8 +63,6 @@ public ContainerNode(String name) { public ContainerNode(String name, int maxNodes) { this.name = name; this.maxNodes = maxNodes; - - items = new ArrayList(); } public String getName() { diff --git a/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/oql/CustomOQLQueries.java b/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/oql/CustomOQLQueries.java index 2195582f5f..609b3ccba4 100644 --- a/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/oql/CustomOQLQueries.java +++ b/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/oql/CustomOQLQueries.java @@ -90,7 +90,7 @@ public synchronized void set(List queries) { } public synchronized List list() { - List list = new ArrayList(); + List list = new ArrayList<>(); for (OQLSupport.Query query : customQueries) list.add(new OQLSupport.Query(query.getScript(), query.getName(), query.getDescription())); return list; @@ -148,7 +148,7 @@ private static Properties listToProperties(List queries) { private CustomOQLQueries() { assert !SwingUtilities.isEventDispatchThread(); - customQueries = new ArrayList(); + customQueries = new ArrayList<>(); try { Properties p = new Properties(); diff --git a/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/utils/HeapUtils.java b/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/utils/HeapUtils.java index a57db11e05..c79c1cfe72 100644 --- a/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/utils/HeapUtils.java +++ b/visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/utils/HeapUtils.java @@ -58,7 +58,7 @@ public final class HeapUtils { // --- Heap utils ---------------------------------------------------------- public static Collection getSubclasses(Heap heap, String baseClass) { - HashSet subclasses = new HashSet(); + HashSet subclasses = new HashSet<>(); String escapedClassName = "\\Q" + baseClass + "\\E"; // NOI18N Collection jClasses = heap.getJavaClassesByRegExp(escapedClassName); diff --git a/visualvm/host/src/org/graalvm/visualvm/host/impl/Ping.java b/visualvm/host/src/org/graalvm/visualvm/host/impl/Ping.java index b2511b9543..e8a437edfb 100644 --- a/visualvm/host/src/org/graalvm/visualvm/host/impl/Ping.java +++ b/visualvm/host/src/org/graalvm/visualvm/host/impl/Ping.java @@ -164,10 +164,10 @@ void processPendingTargets() throws IOException { // Process keys that have become selected // void processSelectedKeys() throws IOException { - for (Iterator i = sel.selectedKeys().iterator(); i.hasNext();) { + for (Iterator i = sel.selectedKeys().iterator(); i.hasNext();) { // Retrieve the next key and remove it from the set - SelectionKey sk = (SelectionKey)i.next(); + SelectionKey sk = i.next(); i.remove(); // Retrieve the target and the channel diff --git a/visualvm/jmx/src/org/graalvm/visualvm/jmx/CredentialsProvider.java b/visualvm/jmx/src/org/graalvm/visualvm/jmx/CredentialsProvider.java index b3f26b3ee2..3ed0721a2b 100644 --- a/visualvm/jmx/src/org/graalvm/visualvm/jmx/CredentialsProvider.java +++ b/visualvm/jmx/src/org/graalvm/visualvm/jmx/CredentialsProvider.java @@ -179,7 +179,7 @@ boolean isPersistent(Storage storage) { // NOTE: clears the pword parameter! private static Map createMap(String username, char[] pword) { - Map map = new HashMap(); + Map map = new HashMap<>(); if (username != null && !username.isEmpty()) { map.put(JMXConnector.CREDENTIALS, new String[] { username, pword == null ? null : new String(decodePassword(pword)) }); diff --git a/visualvm/jvmstat/src/org/graalvm/visualvm/jvmstat/application/ConnectionsCustomizer.java b/visualvm/jvmstat/src/org/graalvm/visualvm/jvmstat/application/ConnectionsCustomizer.java index 7dfe92f21e..1c1f944a17 100644 --- a/visualvm/jvmstat/src/org/graalvm/visualvm/jvmstat/application/ConnectionsCustomizer.java +++ b/visualvm/jvmstat/src/org/graalvm/visualvm/jvmstat/application/ConnectionsCustomizer.java @@ -122,7 +122,7 @@ private static DefaultTableModel getModel(Set descriptors) } private static Set getDescriptors(DefaultTableModel model) { - Set descriptors = new HashSet(); + Set descriptors = new HashSet<>(); for (int i = 0; i < model.getRowCount(); i++) descriptors.add((ConnectionDescriptor)model.getValueAt(i, 0)); return descriptors; @@ -184,7 +184,7 @@ private boolean containsConnection(ConnectionDescriptor d) { } private int getUnusedPort() { - Set ports = new HashSet(); + Set ports = new HashSet<>(); for (int i = 0; i < table.getRowCount(); i++) ports.add(((ConnectionDescriptor)table.getValueAt(i, 0)).getPort()); for (int i = ConnectionDescriptor.createDefault().getPort() + 1; i < 65536; i++) diff --git a/visualvm/libs.profiler/lib.profiler.charts/src/org/graalvm/visualvm/lib/charts/swing/CrossBorderLayout.java b/visualvm/libs.profiler/lib.profiler.charts/src/org/graalvm/visualvm/lib/charts/swing/CrossBorderLayout.java index a10f8e163d..a79cdcd3ea 100644 --- a/visualvm/libs.profiler/lib.profiler.charts/src/org/graalvm/visualvm/lib/charts/swing/CrossBorderLayout.java +++ b/visualvm/libs.profiler/lib.profiler.charts/src/org/graalvm/visualvm/lib/charts/swing/CrossBorderLayout.java @@ -68,7 +68,7 @@ public class CrossBorderLayout implements LayoutManager2 { private static final int NONE = Integer.MIN_VALUE; - private Map map = new HashMap(); + private Map map = new HashMap<>(); private Component north; private Component west; diff --git a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/charts/BarChart.java b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/charts/BarChart.java index 37dcba21a5..3b523c45cd 100644 --- a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/charts/BarChart.java +++ b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/charts/BarChart.java @@ -76,7 +76,7 @@ public class BarChart extends JComponent implements ComponentListener, AncestorListener, ChartModelListener, Accessible { //~ Instance fields ---------------------------------------------------------------------------------------------------------- - List horizAxisXes = new ArrayList(); + List horizAxisXes = new ArrayList<>(); int horizAxisHeight = 0; int horizLegendWidth = 0; int vertAxisWidth = 0; @@ -513,14 +513,14 @@ protected void drawChart(Graphics2D g2) { offScreenImageInvalid = false; } - protected void drawHorizontalAxis(Graphics2D g2, List horizAxisXes, String[] xItems) { + protected void drawHorizontalAxis(Graphics2D g2, List horizAxisXes, String[] xItems) { g2.setPaint(axisPaint); g2.setStroke(axisStroke); g2.drawLine(vertAxisWidth - 3, drawHeight - horizAxisHeight, drawWidth, drawHeight - horizAxisHeight); for (int i = 0; i < horizAxisXes.size(); i++) { - int x = ((Integer) horizAxisXes.get(i)).intValue(); + int x = horizAxisXes.get(i).intValue(); g2.drawLine(x, drawHeight - horizAxisHeight + 1, x, drawHeight - horizAxisHeight + 3); drawHorizontalAxisLegendItem(g2, x, xItems[i]); } diff --git a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/components/tree/CheckTreeNode.java b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/components/tree/CheckTreeNode.java index de105b6fd6..a948a1e0db 100644 --- a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/components/tree/CheckTreeNode.java +++ b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/components/tree/CheckTreeNode.java @@ -134,8 +134,8 @@ public Collection toggleState() { } } - protected Collection setPartiallyChecked() { - Set changedNodes = new HashSet(); + protected Collection setPartiallyChecked() { + Set changedNodes = new HashSet<>(); changedNodes.add(this); // Check if change is needed @@ -160,8 +160,8 @@ protected Collection setPartiallyChecked() { // --------------------------------------------------------------------------- // --- Private implementation ------------------------------------------------ - private Collection setFullyChecked() { - Set changedNodes = new HashSet(); + private Collection setFullyChecked() { + Set changedNodes = new HashSet<>(); changedNodes.add(this); // Check if change is needed @@ -198,8 +198,8 @@ private Collection setFullyChecked() { return changedNodes; } - private Collection setUnchecked() { - Set changedNodes = new HashSet(); + private Collection setUnchecked() { + Set changedNodes = new HashSet<>(); changedNodes.add(this); // Check if change is needed diff --git a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/CCTDisplay.java b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/CCTDisplay.java index 9c297d1724..8a411cdeba 100644 --- a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/CCTDisplay.java +++ b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/CCTDisplay.java @@ -62,6 +62,7 @@ import org.graalvm.visualvm.lib.ui.components.treetable.JTreeTablePanel; import org.graalvm.visualvm.lib.ui.components.treetable.TreeTableModel; import org.graalvm.visualvm.lib.jfluid.utils.StringUtils; +import java.awt.AWTKeyStroke; import java.awt.KeyboardFocusManager; import java.awt.Rectangle; import java.awt.event.ActionEvent; @@ -560,11 +561,11 @@ public void actionPerformed(ActionEvent e) { }); // NOI18N // Disable traversing table cells using TAB and Shift+TAB - Set keys = new HashSet(treeTable.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); + Set keys = new HashSet<>(treeTable.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); keys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); treeTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); - keys = new HashSet(treeTable.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); + keys = new HashSet<>(treeTable.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); treeTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); diff --git a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/memory/AllocResultsPanel.java b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/memory/AllocResultsPanel.java index 775d534116..9947354bbc 100644 --- a/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/memory/AllocResultsPanel.java +++ b/visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/memory/AllocResultsPanel.java @@ -54,6 +54,7 @@ import org.graalvm.visualvm.lib.ui.components.table.ExtendedTableModel; import org.graalvm.visualvm.lib.ui.components.table.LabelBracketTableCellRenderer; import org.graalvm.visualvm.lib.ui.components.table.SortableTableModel; +import java.awt.AWTKeyStroke; import java.awt.KeyboardFocusManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -305,11 +306,11 @@ public void doLayout() { resTable.setRowHeight(UIUtils.getDefaultRowHeight() + 2); // Disable traversing table cells using TAB and Shift+TAB - Set keys = new HashSet(resTable.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); + Set keys = new HashSet<>(resTable.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); keys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); resTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); - keys = new HashSet(resTable.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); + keys = new HashSet<>(resTable.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); resTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassFileCache.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassFileCache.java index 6810835381..4afcd83c3f 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassFileCache.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassFileCache.java @@ -74,7 +74,7 @@ public class ClassFileCache { //~ Instance fields ---------------------------------------------------------------------------------------------------------- private ClassPath classPath; // Used to quickly obtain an open JAR file for a given name - private Hashtable vmSuppliedClassCache; + private Hashtable vmSuppliedClassCache; private byte[][] classFileBytes; private String[] classNameAndLocation; private long[] lastTimeUsed; @@ -82,8 +82,8 @@ public class ClassFileCache { private int size; private int sizeLimit; private long timeCounter; - private List preloadNames; - private List preloadLoaderIds; + private List preloadNames; + private List preloadLoaderIds; //~ Constructors ------------------------------------------------------------------------------------------------------------- @@ -96,9 +96,9 @@ public class ClassFileCache { classFileBytes = new byte[capacity][]; lastTimeUsed = new long[capacity]; - vmSuppliedClassCache = new Hashtable(); - preloadNames = new ArrayList(); - preloadLoaderIds = new ArrayList(); + vmSuppliedClassCache = new Hashtable<>(); + preloadNames = new ArrayList<>(); + preloadLoaderIds = new ArrayList<>(); } //~ Methods ------------------------------------------------------------------------------------------------------------------ @@ -120,7 +120,7 @@ byte[] getClassFile(String name, String location) throws IOException { byte[] res; if (location.startsWith(ClassRepository.LOCATION_VMSUPPLIED)) { - res = (byte[]) vmSuppliedClassCache.get(nameAndLocation); + res = vmSuppliedClassCache.get(nameAndLocation); if (res != null && res.length == 0) { try { // known class without bytecode; get it from TA @@ -128,10 +128,10 @@ byte[] getClassFile(String name, String location) throws IOException { if (!preloadNames.contains(name)) { preloadBytecode(name, location); } - String names[] = (String[]) preloadNames.toArray(new String[0]); + String names[] = preloadNames.toArray(new String[0]); int loadersId[] = new int[preloadLoaderIds.size()]; for (int i=0; i(); + preloadLoaderIds = new ArrayList<>(); + res = vmSuppliedClassCache.get(nameAndLocation); if (res.length == 0) { throw new IOException("Get class file for " + name + " not found in TA"); } @@ -171,7 +171,7 @@ byte[] getClassFile(String name, String location) throws IOException { void preloadBytecode(String name, String location) { String nameAndLocation = (name + "#" + location).intern(); // NOI18N if (location.startsWith(ClassRepository.LOCATION_VMSUPPLIED)) { - byte[] res = (byte[]) vmSuppliedClassCache.get(nameAndLocation); + byte[] res = vmSuppliedClassCache.get(nameAndLocation); if (res != null && res.length == 0) { // known class without bytecode; get it from TA preloadNames.add(name); diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassPath.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassPath.java index 75d96b756e..945e82b991 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassPath.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassPath.java @@ -64,7 +64,7 @@ public class ClassPath { private abstract static class PathEntry { //~ Instance fields ------------------------------------------------------------------------------------------------------ - protected HashSet entries; + protected HashSet entries; protected int hits; // This is done to avoid indexing of the JAR files too early and all at once protected int threshHits; // This is done to avoid indexing of the JAR files too early and all at once @@ -162,17 +162,17 @@ String getLocationForClassFile(String fileName) { } } - private static class JarLRUCache extends LinkedHashMap { + private static class JarLRUCache extends LinkedHashMap { private static final int MAX_CAPACITY = 100; private JarLRUCache() { super(10, 0.75f, true); } - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry eldest) { if (size()>MAX_CAPACITY) { try { - ((ZipFile)eldest.getValue()).close(); + eldest.getValue().close(); } catch (IOException ex) { // ignore } @@ -193,7 +193,7 @@ protected boolean removeEldestEntry(Map.Entry eldest) { public ClassPath(String classPath, boolean isCP) { this.isCP = isCP; - List vec = new ArrayList(); + List vec = new ArrayList<>(); zipFileNameToFile = new JarLRUCache(); for (StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator); tok.hasMoreTokens();) { @@ -212,7 +212,7 @@ public ClassPath(String classPath, boolean isCP) { } } - paths = (PathEntry[])vec.toArray(new PathEntry[0]); + paths = vec.toArray(new PathEntry[0]); } //~ Methods ------------------------------------------------------------------------------------------------------------------ @@ -253,7 +253,7 @@ public String getLocationForClass(String slashedClassName) { /** This is used to avoid repetitive creation of ZipFiles in the code that reads files from JARs given just the name of the latter */ public ZipFile getZipFileForName(String zipFileName) throws IOException { - ZipFile zip = (ZipFile) zipFileNameToFile.get(zipFileName); + ZipFile zip = zipFileNameToFile.get(zipFileName); if (zip == null) { zip = new ZipFile(zipFileName); zipFileNameToFile.put(zipFileName,zip); @@ -264,9 +264,9 @@ public ZipFile getZipFileForName(String zipFileName) throws IOException { public void close() { // close all ZipFiles in ClassPath, the files on disk would otherwise be locked // this is a bugfix for http://profiler.netbeans.org/issues/show_bug.cgi?id=61849 - for (Iterator it = zipFileNameToFile.values().iterator(); it.hasNext();) { + for (ZipFile zipFile : zipFileNameToFile.values()) { try { - ((ZipFile) it.next()).close(); + zipFile.close(); } catch (IOException e) { // ignore } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassRepository.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassRepository.java index 198ec2b834..468969f1cf 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassRepository.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassRepository.java @@ -105,9 +105,9 @@ public String toString() { // The below class file location signals to ClassFileCache that the class file should have been already supplied by the VM. static final String LOCATION_VMSUPPLIED = ""; // NOI18N private static ClassPath classPath; - private static Hashtable classes; - private static Set notFoundClasses; - private static Map definingClassLoaderMap; + private static Hashtable classes; + private static Set notFoundClasses; + private static Map definingClassLoaderMap; static { clearCache(); @@ -201,16 +201,14 @@ public static ClassPath getClassPath() { */ public static List getClassesOnClasspath(List classPathElementList) { // TODO CHECK: unused method - List list = new ArrayList(); + List list = new ArrayList<>(); list.addAll(classPathElementList); - List res = new ArrayList(); - - for (Iterator e = list.iterator(); e.hasNext();) { - String dirOrJar = (String) e.next(); + List res = new ArrayList<>(); + for (String dirOrJar : list) { if (!(dirOrJar.endsWith(".jar") || dirOrJar.endsWith(".zip"))) // NOI18N - { + { MiscUtils.getAllClassesInDir(dirOrJar, "", true, res); // NOI18N } else { MiscUtils.getAllClassesInJar(dirOrJar, true, res); @@ -398,10 +396,10 @@ public static void cleanup() { /** Will reset any cached data, will not reset data pertinent to session in progress */ public static void clearCache() { - classes = new Hashtable(); + classes = new Hashtable<>(); ClassFileCache.resetDefaultCache(); - notFoundClasses = new HashSet(); - definingClassLoaderMap = new HashMap(); + notFoundClasses = new HashSet<>(); + definingClassLoaderMap = new HashMap<>(); } /** @@ -413,25 +411,25 @@ public static void clearCache() { * @param classPaths the 3 elements should be the user, extension, and boot class paths, respectively */ public static void initClassPaths(String workingDir, String[] classPaths) { - List userClassPathElementList = MiscUtils.getPathComponents(classPaths[0], true, workingDir); - List bootClassPathElementList = MiscUtils.getPathComponents(classPaths[2], true, workingDir); + List userClassPathElementList = MiscUtils.getPathComponents(classPaths[0], true, workingDir); + List bootClassPathElementList = MiscUtils.getPathComponents(classPaths[2], true, workingDir); String extPath = classPaths[1]; - List extClassPathElementList = new ArrayList(); + List extClassPathElementList = new ArrayList<>(); // Extension class path needs special handling, since it consists of directories, which contain .jars // So we need to find all these .jars in all these dirs and add them to extClassPathElementList - List dirs = MiscUtils.getPathComponents(extPath, true, workingDir); + List dirs = MiscUtils.getPathComponents(extPath, true, workingDir); - for (Iterator e = dirs.iterator(); e.hasNext();) { - File extDir = new File((String) e.next()); + for (String dir : dirs) { + File extDir = new File(dir); String[] extensions = extDir.list(new FilenameFilter() { public boolean accept(File dir, String name) { name = name.toLowerCase(Locale.ENGLISH); return name.endsWith(".zip") || name.endsWith(".jar"); // NOI18N } - }); + }); if (extensions == null) { continue; @@ -439,20 +437,20 @@ public boolean accept(File dir, String name) { for (int i = 0; i < extensions.length; i++) { String extJar = extDir.getAbsolutePath() + File.separatorChar + extensions[i]; - List allJarComponents = MiscUtils.getPathComponents(extJar,true,workingDir); + List allJarComponents = MiscUtils.getPathComponents(extJar, true, workingDir); extClassPathElementList.addAll(allJarComponents); } } - List list = new ArrayList(); + List list = new ArrayList<>(); list.addAll(bootClassPathElementList); list.addAll(extClassPathElementList); list.addAll(userClassPathElementList); StringBuilder buf = new StringBuilder(); - for (Iterator e = list.iterator(); e.hasNext();) { - buf.append((String) e.next()); + for (Iterator e = list.iterator(); e.hasNext();) { + buf.append(e.next()); if (e.hasNext()) { buf.append(File.pathSeparatorChar); @@ -461,7 +459,7 @@ public boolean accept(File dir, String name) { classPath = new ClassPath(buf.toString(), true); - notFoundClasses = new HashSet(); + notFoundClasses = new HashSet<>(); } /** @@ -580,7 +578,7 @@ public static BaseClassInfo lookupSpecialClass(String className) { static int getDefiningClassLoaderId(String className, int classLoaderId) { String classId = className + "#" + classLoaderId; // NOI18N - Integer loaderInt = (Integer) definingClassLoaderMap.get(classId); + Integer loaderInt = definingClassLoaderMap.get(classId); if (loaderInt != null) { return loaderInt.intValue(); diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/DynamicClassInfo.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/DynamicClassInfo.java index 4426278925..0e1fd651f1 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/DynamicClassInfo.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/DynamicClassInfo.java @@ -57,7 +57,7 @@ public class DynamicClassInfo extends ClassInfo { //~ Instance fields ---------------------------------------------------------------------------------------------------------- - private ArrayList subclasses; // Subclasses as DynamicClassInfos + private ArrayList subclasses; // Subclasses as DynamicClassInfos private DynamicClassInfo superClass; // Superclass as a DynamicClassInfo (just name not is inconvenient when multiple classloaders are used) private String classFileLocation; // Directory or .jar file where the .class file is located. private int[] baseCPoolCount; @@ -438,9 +438,9 @@ public DynamicClassInfo[] getSuperInterfaces() { public void addSubclass(DynamicClassInfo subclass) { if (subclasses == null) { if (name == OBJECT_SLASHED_CLASS_NAME) { - subclasses = new ArrayList(500); + subclasses = new ArrayList<>(500); } else { - subclasses = new ArrayList(); + subclasses = new ArrayList<>(); } } if (isInterface() && subclasses.contains(subclass)) { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/SameNameClassGroup.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/SameNameClassGroup.java index 25725d140d..0e79388d54 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/SameNameClassGroup.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/SameNameClassGroup.java @@ -57,12 +57,12 @@ public class SameNameClassGroup { //~ Instance fields ---------------------------------------------------------------------------------------------------------- - private List classes; + // Hope we are not going to have too many class versions... + private List classes = new ArrayList<>(4); //~ Constructors ------------------------------------------------------------------------------------------------------------- public SameNameClassGroup() { - classes = new ArrayList(4); // Hope we are not going to have too many class versions... } //~ Methods ------------------------------------------------------------------------------------------------------------------ @@ -114,13 +114,13 @@ public static BaseClassInfo checkForCompatibility(BaseClassInfo clazz, int class public BaseClassInfo findCompatibleClass(int classLoaderId) { int size = classes.size(); for (int i = 0; i < size; i++) { - BaseClassInfo clazz = (BaseClassInfo) classes.get(i); + BaseClassInfo clazz = classes.get(i); if (clazz.getLoaderId() == classLoaderId) { return clazz; } } for (int i = 0; i < size; i++) { - BaseClassInfo clazz = (BaseClassInfo) classes.get(i); + BaseClassInfo clazz = classes.get(i); clazz = checkForCompatibility(clazz, classLoaderId); if (clazz != null) { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/global/TransactionalSupport.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/global/TransactionalSupport.java index 69a37903fb..d989734548 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/global/TransactionalSupport.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/global/TransactionalSupport.java @@ -59,9 +59,9 @@ public class TransactionalSupport { //~ Instance fields ---------------------------------------------------------------------------------------------------------- private final Object transactionLock = new Object(); - private final ThreadLocal interruptedFlag = new ThreadLocal(); - private final ThreadLocal lockRead = new ThreadLocal(); - private final ThreadLocal lockWrite = new ThreadLocal(); + private final ThreadLocal interruptedFlag = new ThreadLocal<>(); + private final ThreadLocal lockRead = new ThreadLocal<>(); + private final ThreadLocal lockWrite = new ThreadLocal<>(); // final static private Logger LOGGER = Logger.getLogger(TransactionalSupport.class.getName()); private boolean lockedExclusively = false; @@ -120,8 +120,8 @@ public boolean beginTrans(boolean mutable, boolean failEarly) { public void endTrans() { synchronized (transactionLock) { - Integer roCounter = (Integer) lockRead.get(); - Integer rwCounter = (Integer) lockWrite.get(); + Integer roCounter = lockRead.get(); + Integer rwCounter = lockWrite.get(); if (roCounter == null) { unlockShared(); @@ -204,7 +204,7 @@ private boolean lockShared() { lockedShared = true; - Integer counter = (Integer) lockRead.get(); + Integer counter = lockRead.get(); if (counter == null) { lockRead.set(new Integer(1)); @@ -229,7 +229,7 @@ private boolean promoteToExclusive() { return false; // can't promote a shared lock held by more threads } - Integer counter = (Integer) lockRead.get(); + Integer counter = lockRead.get(); if (counter != null) { if (DEBUG) { @@ -257,7 +257,7 @@ private boolean promoteToExclusive() { private boolean relockExclusively() { boolean result; - Integer counter = (Integer) lockWrite.get(); + Integer counter = lockWrite.get(); if (counter != null) { if (DEBUG) { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDump.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDump.java index ca798000c2..6756ed2367 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDump.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDump.java @@ -67,12 +67,12 @@ class ClassDump extends HprofObject implements JavaClass { //~ Static fields/initializers ----------------------------------------------------------------------------------------------- private static final boolean DEBUG = false; - private static final Set CANNOT_CONTAIN_ITSELF = new HashSet(Arrays.asList(new String[] { + private static final Set CANNOT_CONTAIN_ITSELF = new HashSet<>(Arrays.asList( "java.lang.String", // NOI18N "java.lang.StringBuffer", // NOI18N "java.lang.StringBuilder", // NOI18N "java.io.File" // NOI18N - })); + )); //~ Instance fields ---------------------------------------------------------------------------------------------------------- @@ -119,11 +119,9 @@ public Instance getClassLoader() { } public Field getField(String name) { - Iterator fIt = getFields().iterator(); - - while (fIt.hasNext()) { - Field field = (Field) fIt.next(); + List fields = getFields(); + for (Field field : fields) { if (field.getName().equals(name)) { return field; } @@ -133,7 +131,7 @@ public Field getField(String name) { } public List /**/ getFields() { - List filedsList = (List) classDumpSegment.fieldsCache.get(this); + List filedsList = classDumpSegment.fieldsCache.get(this); if (filedsList == null) { filedsList = Collections.unmodifiableList(computeFields()); classDumpSegment.fieldsCache.put(this,filedsList); @@ -169,7 +167,7 @@ public long getRetainedSizeByClass() { HprofHeap heap = getHprof(); HprofByteBuffer dumpBuffer = getHprofBuffer(); int idSize = dumpBuffer.getIDSize(); - List instancesList = new ArrayList(instancesCount); + List instancesList = new ArrayList<>(instancesCount); TagBounds allInstanceDumpBounds = heap.getAllInstanceDumpBounds(); long[] offset = new long[] { firstInstanceOffset }; @@ -248,15 +246,15 @@ public String getName() { } public Collection /**/ getSubClasses() { - List classes = getHprof().getAllClasses(); - List subclasses = new ArrayList(classes.size() / 10); - Map subclassesMap = new HashMap((classes.size() * 4) / 3); + List classes = getHprof().getAllClasses(); + List subclasses = new ArrayList<>(classes.size() / 10); + Map subclassesMap = new HashMap<>((classes.size() * 4) / 3); subclassesMap.put(this, Boolean.TRUE); for (int i = 0; i < classes.size(); i++) { - JavaClass jcls = (JavaClass) classes.get(i); - Boolean b = (Boolean) subclassesMap.get(jcls); + JavaClass jcls = classes.get(i); + Boolean b = subclassesMap.get(jcls); if (b == null) { b = isSubClass(jcls, subclassesMap); @@ -277,11 +275,9 @@ public JavaClass getSuperClass() { } public Object getValueOfStaticField(String name) { - Iterator fIt = getStaticFieldValues().iterator(); - - while (fIt.hasNext()) { - FieldValue fieldValue = (FieldValue) fIt.next(); + List staticFieldValues = getStaticFieldValues(); + for (FieldValue fieldValue : staticFieldValues) { if (fieldValue.getField().getName().equals(name)) { if (fieldValue instanceof HprofFieldObjectValue) { return ((HprofFieldObjectValue) fieldValue).getInstance(); @@ -294,12 +290,12 @@ public Object getValueOfStaticField(String name) { return null; } - private List /**/ computeFields() { + private List computeFields() { HprofByteBuffer buffer = getHprofBuffer(); long offset = fileOffset + getInstanceFieldOffset(); int i; int fields = buffer.getShort(offset); - List filedsList = new ArrayList(fields); + List filedsList = new ArrayList<>(fields); for (i = 0; i < fields; i++) { filedsList.add(new HprofField(this, offset + 2 + (i * classDumpSegment.fieldSize))); @@ -313,12 +309,12 @@ public Object getValueOfStaticField(String name) { long offset = fileOffset + getStaticFieldOffset(); int i; int fields; - List filedsList; + List filedsList; HprofHeap heap = getHprof(); fields = buffer.getShort(offset); offset += 2; - filedsList = new ArrayList(fields+(addClassLoader?0:1)); + filedsList = new ArrayList<>(fields+(addClassLoader?0:1)); for (i = 0; i < fields; i++) { byte type = buffer.get(offset + classDumpSegment.fieldTypeOffset); @@ -343,7 +339,7 @@ public Object getValueOfStaticField(String name) { } List getAllInstanceFields() { - List fields = new ArrayList(50); + List fields = new ArrayList<>(50); for (JavaClass jcls = this; jcls != null; jcls = jcls.getSuperClass()) { fields.addAll(jcls.getFields()); @@ -426,13 +422,13 @@ int getStaticFiledSize(int staticFieldOffset) { return (int) (fieldOffset - staticFieldOffset - fileOffset); } - void findStaticReferencesFor(long instanceId, List refs) { + void findStaticReferencesFor(long instanceId, List refs) { int i; HprofByteBuffer buffer = getHprofBuffer(); int idSize = buffer.getIDSize(); long fieldOffset = fileOffset + getStaticFieldOffset(); int fields = buffer.getShort(fieldOffset); - List staticFileds = null; + List staticFileds = null; HprofHeap heap = getHprof(); fieldOffset += 2; @@ -475,11 +471,9 @@ void addSizeForInstance(Instance i) { boolean canContainItself() { if (getInstancesCount()>=2 && !CANNOT_CONTAIN_ITSELF.contains(getName())) { - Iterator fieldsIt = getAllInstanceFields().iterator(); - - while(fieldsIt.hasNext()) { - Field f = (Field) fieldsIt.next(); + List allInstanceFields = getAllInstanceFields(); + for (Field f : allInstanceFields) { if (f.getType().getName().equals("object")) { // NOI18N return true; } @@ -491,14 +485,14 @@ boolean canContainItself() { return false; } - private static Boolean isSubClass(JavaClass jcls, Map subclassesMap) { + private static Boolean isSubClass(JavaClass jcls, Map subclassesMap) { JavaClass superClass = jcls.getSuperClass(); Boolean b; if (superClass == null) { b = Boolean.FALSE; } else { - b = (Boolean) subclassesMap.get(superClass); + b = subclassesMap.get(superClass); if (b == null) { b = isSubClass(superClass, subclassesMap); @@ -510,7 +504,7 @@ private static Boolean isSubClass(JavaClass jcls, Map subclassesMap) { return b; } - private class InstancesIterator implements Iterator { + private class InstancesIterator implements Iterator { private long instancesCount; private long[] offset; @@ -535,7 +529,7 @@ public boolean hasNext() { return false; } - public Object next() { + public Instance next() { while (hasNext()) { Instance i = heap.getInstanceByOffset(offset, ClassDump.this, classId); if (i != null) { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDumpSegment.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDumpSegment.java index 0899b5681a..c167e629a5 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDumpSegment.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ClassDumpSegment.java @@ -65,7 +65,7 @@ class ClassDumpSegment extends TagBounds { //~ Instance fields ---------------------------------------------------------------------------------------------------------- HprofHeap hprofHeap; - Map /**/ arrayMap; + Map /**/ arrayMap; final int classIDOffset; final int classLoaderIDOffset; final int constantPoolSizeOffset; @@ -83,9 +83,9 @@ class ClassDumpSegment extends TagBounds { final int superClassIDOffset; ClassDump java_lang_Class; boolean newSize; - Map /*>*/ fieldsCache; - private List /**/ classes; - private Map /**/ primitiveArrayMap; + Map> fieldsCache; + private List classes; + private Map primitiveArrayMap; //~ Constructors ------------------------------------------------------------------------------------------------------------- @@ -123,12 +123,12 @@ ClassDump getClassDumpByID(long classObjectID) { if (classObjectID == 0) { return null; } - List allClasses = createClassCollection(); + List allClasses = createClassCollection(); LongMap.Entry entry = hprofHeap.idToOffsetMap.get(classObjectID); if (entry != null) { try { - ClassDump dump = (ClassDump) allClasses.get(entry.getIndex() - 1); + ClassDump dump = allClasses.get(entry.getIndex() - 1); if (dump.fileOffset == entry.getOffset()) { return dump; } @@ -145,11 +145,8 @@ ClassDump getClassDumpByID(long classObjectID) { } JavaClass getJavaClassByName(String fqn) { - Iterator classIt = createClassCollection().iterator(); - - while (classIt.hasNext()) { - ClassDump cls = (ClassDump) classIt.next(); + for (ClassDump cls : createClassCollection()) { if (fqn.equals(cls.getName())) { return cls; } @@ -158,14 +155,11 @@ JavaClass getJavaClassByName(String fqn) { return null; } - Collection getJavaClassesByRegExp(String regexp) { - Iterator classIt = createClassCollection().iterator(); - Collection result = new ArrayList(256); + Collection getJavaClassesByRegExp(String regexp) { + Collection result = new ArrayList<>(256); Pattern pattern = Pattern.compile(regexp); - - while (classIt.hasNext()) { - ClassDump cls = (ClassDump) classIt.next(); + for (ClassDump cls : createClassCollection()) { if (pattern.matcher(cls.getName()).matches()) { result.add(cls); } @@ -178,7 +172,7 @@ int getMinimumInstanceSize() { } ClassDump getPrimitiveArrayClass(byte type) { - ClassDump primitiveArray = (ClassDump) primitiveArrayMap.get(Integer.valueOf(type)); + ClassDump primitiveArray = primitiveArrayMap.get(Integer.valueOf(type)); if (primitiveArray == null) { throw new IllegalArgumentException("Invalid type " + type); // NOI18N @@ -187,22 +181,19 @@ ClassDump getPrimitiveArrayClass(byte type) { return primitiveArray; } - Map getClassIdToClassMap() { - Collection allClasses = createClassCollection(); - Map map = new HashMap(allClasses.size()*4/3); - Iterator classIt = allClasses.iterator(); - - while(classIt.hasNext()) { - ClassDump cls = (ClassDump) classIt.next(); - - map.put(new Long(cls.getJavaClassId()),cls); + Map getClassIdToClassMap() { + Collection allClasses = createClassCollection(); + Map map = new HashMap<>(allClasses.size()*4/3); + + for (ClassDump cls : allClasses) { + map.put(new Long(cls.getJavaClassId()), cls); } return map; } void addInstanceSize(ClassDump cls, int tag, long instanceOffset) { if ((tag == HprofHeap.OBJECT_ARRAY_DUMP) || (tag == HprofHeap.PRIMITIVE_ARRAY_DUMP)) { - Long sizeLong = (Long) arrayMap.get(cls); + Long sizeLong = arrayMap.get(cls); long size = 0; HprofByteBuffer dumpBuffer = hprofHeap.dumpBuffer; int idSize = dumpBuffer.getIDSize(); @@ -226,12 +217,12 @@ void addInstanceSize(ClassDump cls, int tag, long instanceOffset) { } } - synchronized List /**/ createClassCollection() { + synchronized List createClassCollection() { if (classes != null) { return classes; } - List cls = new ArrayList /**/(1000); + List cls = new ArrayList<>(1000); long[] offset = new long[] { startOffset }; @@ -251,7 +242,7 @@ void addInstanceSize(ClassDump cls, int tag, long instanceOffset) { classes = Collections.unmodifiableList(cls); hprofHeap.getLoadClassSegment().setLoadClassOffsets(); - arrayMap = new HashMap(classes.size() / 15); + arrayMap = new HashMap<>(classes.size() / 15); extractSpecialClasses(); return classes; @@ -259,12 +250,10 @@ void addInstanceSize(ClassDump cls, int tag, long instanceOffset) { void extractSpecialClasses() { ClassDump java_lang_Object = null; - primitiveArrayMap = new HashMap(); - - Iterator classIt = classes.iterator(); + primitiveArrayMap = new HashMap<>(); - while (classIt.hasNext()) { - ClassDump jcls = (ClassDump) classIt.next(); + for (JavaClass aClass : classes) { + ClassDump jcls = (ClassDump) aClass; String vmName = jcls.getLoadClass().getVMName(); Integer typeObj = null; @@ -330,7 +319,7 @@ void writeToStream(DataOutputStream out) throws IOException { ClassDump classDump = (ClassDump) classes.get(i); classDump.writeToStream(out); - Long size = (Long) arrayMap.get(classDump); + Long size = arrayMap.get(classDump); out.writeBoolean(size != null); if (size != null) { out.writeLong(size.longValue()); @@ -343,8 +332,8 @@ void writeToStream(DataOutputStream out) throws IOException { this(heap, start, end); int classesSize = dis.readInt(); if (classesSize != 0) { - List cls = new ArrayList /**/(classesSize); - arrayMap = new HashMap(classesSize / 15); + List cls = new ArrayList<>(classesSize); + arrayMap = new HashMap<>(classesSize / 15); for (int i=0; i> { private static final int SIZE = 500; FieldsCache() { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ComputedSummary.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ComputedSummary.java index ea9f6cc8d8..e50631744e 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ComputedSummary.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/ComputedSummary.java @@ -62,10 +62,11 @@ class ComputedSummary implements HeapSummary { ComputedSummary(HprofHeap heap) { long bytesCount = 0; long instancesCount = 0; - Iterator classIt = heap.getAllClasses().iterator(); + @SuppressWarnings("unchecked") + Iterator classIt = heap.getAllClasses().iterator(); while (classIt.hasNext()) { - JavaClass jcls = (JavaClass) classIt.next(); + JavaClass jcls = classIt.next(); instancesCount += jcls.getInstancesCount(); bytesCount += jcls.getAllInstancesSize(); diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/DominatorTree.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/DominatorTree.java index b1e2efbbdb..9542341c06 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/DominatorTree.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/DominatorTree.java @@ -73,8 +73,8 @@ class DominatorTree { private LongHashMap map; private LongSet dirtySet; private int dirtySetSameSize; - private Map canContainItself; - private Map nearestGCRootCache = new NearestGCRootCache(400000); + private Map canContainItself; + private Map nearestGCRootCache = new NearestGCRootCache(400000); //~ Constructors ------------------------------------------------------------------------------------------------------------- @@ -242,10 +242,10 @@ boolean hasInstanceInChain(int tag, Instance i) { } javaClass = (ClassDump) i.getJavaClass(); if (canContainItself == null) { - canContainItself = new HashMap(heap.getAllClasses().size()/2); + canContainItself = new HashMap<>(heap.getAllClasses().size()/2); } if (tag == HprofHeap.INSTANCE_DUMP) { - Boolean canContain = (Boolean) canContainItself.get(javaClass); + Boolean canContain = canContainItself.get(javaClass); if (canContain == null) { canContain = Boolean.valueOf(javaClass.canContainItself()); @@ -270,7 +270,7 @@ boolean hasInstanceInChain(int tag, Instance i) { private Long getNearestGCRootPointer(Long instanceIdLong) { LongMap.Entry entry; - Long nearestGCLong = (Long) nearestGCRootCache.get(instanceIdLong); + Long nearestGCLong = nearestGCRootCache.get(instanceIdLong); Long nearestGC; if (nearestGCLong != null) { return nearestGCLong; @@ -380,7 +380,7 @@ void writeToStream(DataOutputStream out) throws IOException { map = new LongHashMap(dis); } - private static final class NearestGCRootCache extends LinkedHashMap { + private static final class NearestGCRootCache extends LinkedHashMap { private final int maxSize; private NearestGCRootCache(int size) { @@ -388,7 +388,7 @@ private NearestGCRootCache(int size) { maxSize = size; } - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry eldest) { return size() > maxSize; } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HeapProgress.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HeapProgress.java index 77e87bc873..b10b7b7d3e 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HeapProgress.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HeapProgress.java @@ -54,14 +54,14 @@ public final class HeapProgress { public static final int PROGRESS_MAX = 1000; - private static ThreadLocal progressThreadLocal = new ThreadLocal(); + private static ThreadLocal progressThreadLocal = new ThreadLocal<>(); private HeapProgress() { } public static BoundedRangeModel getProgress() { - ModelInfo info = (ModelInfo) progressThreadLocal.get(); + ModelInfo info = progressThreadLocal.get(); if (info == null) { info = new ModelInfo(); @@ -82,7 +82,7 @@ static void progress(long value, long endValue) { } private static void progress(final long value, final long endOffset, final long startOffset) { - ModelInfo info = (ModelInfo) progressThreadLocal.get(); + ModelInfo info = progressThreadLocal.get(); if (info != null) { if (info.level>info.divider) { info.divider = info.level; @@ -99,14 +99,14 @@ private static int levelAdd(ModelInfo info, int diff) { } static void progressStart() { - ModelInfo info = (ModelInfo) progressThreadLocal.get(); + ModelInfo info = progressThreadLocal.get(); if (info != null) { levelAdd(info, 1); } } static void progressFinish() { - ModelInfo info = (ModelInfo) progressThreadLocal.get(); + ModelInfo info = progressThreadLocal.get(); if (info != null) { int level = levelAdd(info, -1); diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HprofHeap.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HprofHeap.java index 33e7ddfeb0..e3a72c6ade 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HprofHeap.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/heap/HprofHeap.java @@ -542,7 +542,7 @@ void computeInstances() { ClassDumpSegment classDumpBounds = getClassDumpSegment(); int idSize = dumpBuffer.getIDSize(); long[] offset = new long[] { allInstanceDumpBounds.startOffset }; - Map classIdToClassMap = classDumpBounds.getClassIdToClassMap(); + Map classIdToClassMap = classDumpBounds.getClassIdToClassMap(); for (long counter = 0; offset[0] < allInstanceDumpBounds.endOffset; counter++) { int classIdOffset = 0; @@ -571,7 +571,7 @@ void computeInstances() { if (classIdOffset != 0) { long classId = dumpBuffer.getID(start + 1 + classIdOffset); - classDump = (ClassDump) classIdToClassMap.get(new Long(classId)); + classDump = classIdToClassMap.get(new Long(classId)); } if (classDump != null) { @@ -591,7 +591,7 @@ List findReferencesFor(long instanceId) { assert instanceId != 0L : "InstanceID is null"; computeReferences(); - List refs = new ArrayList(); + List refs = new ArrayList<>(); LongIterator refIdsIt = idToOffsetMap.get(instanceId).getReferences(); int idSize = dumpBuffer.getIDSize(); ClassDumpSegment classDumpBounds = getClassDumpSegment(); @@ -659,7 +659,7 @@ void computeReferences() { ClassDumpSegment classDumpBounds = getClassDumpSegment(); int idSize = dumpBuffer.getIDSize(); long[] offset = new long[] { allInstanceDumpBounds.startOffset }; - Map classIdToClassMap = classDumpBounds.getClassIdToClassMap(); + Map classIdToClassMap = classDumpBounds.getClassIdToClassMap(); computeInstances(); cacheDirectory.setDirty(true); @@ -669,7 +669,7 @@ void computeReferences() { if (tag == INSTANCE_DUMP) { long classId = dumpBuffer.getID(start+1+idSize+4); - ClassDump classDump = (ClassDump) classIdToClassMap.get(new Long(classId)); + ClassDump classDump = classIdToClassMap.get(new Long(classId)); if (classDump != null) { long instanceId = dumpBuffer.getID(start+1); long inOff = start+1+idSize+4+idSize+4; @@ -712,14 +712,13 @@ void computeReferences() { } HeapProgress.progress(counter,allInstanceDumpBounds.startOffset,start,allInstanceDumpBounds.endOffset); } - - Iterator classesIt = getClassDumpSegment().createClassCollection().iterator(); - - while (classesIt.hasNext()) { - ClassDump classDump = (ClassDump)classesIt.next(); + + List classCollection = getClassDumpSegment().createClassCollection(); + + for (ClassDump classDump : classCollection) { List fields = classDump.getStaticFieldValues(); Iterator fit = fields.iterator(); - + while(fit.hasNext()) { Object field = fit.next(); if (field instanceof HprofFieldObjectValue) { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/instrumentation/CodeRegionMethodInstrumentor.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/instrumentation/CodeRegionMethodInstrumentor.java index 8e18548c38..eb90b8c360 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/instrumentation/CodeRegionMethodInstrumentor.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/instrumentation/CodeRegionMethodInstrumentor.java @@ -66,7 +66,7 @@ public class CodeRegionMethodInstrumentor extends ClassManager { //~ Instance fields ---------------------------------------------------------------------------------------------------------- private ClientUtils.SourceCodeSelection sourceCodeSelection; - private ArrayList instrClasses; + private ArrayList instrClasses = new ArrayList<>(); private String className; private int nInstrClasses; @@ -76,7 +76,6 @@ public CodeRegionMethodInstrumentor(ProfilingSessionStatus status, SourceCodeSel super(status); sourceCodeSelection = codeSelection; className = sourceCodeSelection.getClassName().replace('.', '/').intern(); // NOI18N - instrClasses = new ArrayList(); } //~ Methods ------------------------------------------------------------------------------------------------------------------ @@ -170,7 +169,7 @@ private Object[] createInstrumentedMethodPack15() { byte[][] replacementClassFileBytes = new byte[nInstrClasses][]; for (int j = 0; j < nInstrClasses; j++) { - DynamicClassInfo clazz = (DynamicClassInfo) instrClasses.get(j); + DynamicClassInfo clazz = instrClasses.get(j); instrMethodClasses[j] = clazz.getName().replace('/', '.'); // NOI18N instrClassLoaderIds[j] = clazz.getLoaderId(); diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/marker/CompositeMarker.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/marker/CompositeMarker.java index 45e6cc549f..3ee7f8b4ed 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/marker/CompositeMarker.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/marker/CompositeMarker.java @@ -59,16 +59,16 @@ public class CompositeMarker implements Marker { //~ Instance fields ---------------------------------------------------------------------------------------------------------- - private Set delegates; + private Set delegates; //~ Constructors ------------------------------------------------------------------------------------------------------------- /** Creates a new instance of CompositeMarker */ public CompositeMarker() { - delegates = new LinkedHashSet(); + delegates = new LinkedHashSet<>(); } - public CompositeMarker(Set markerList) { + public CompositeMarker(Set markerList) { this(); delegates.addAll(markerList); } @@ -76,26 +76,24 @@ public CompositeMarker(Set markerList) { //~ Methods ------------------------------------------------------------------------------------------------------------------ public MarkMapping[] getMappings() { - Set markerMethods = new HashSet(); + Set markerMethods = new HashSet<>(); - for (Iterator iter = delegates.iterator(); iter.hasNext();) { - Marker delegate = (Marker) iter.next(); + for (Marker delegate : delegates) { MarkMapping[] mMethods = delegate.getMappings(); markerMethods.addAll(Arrays.asList(mMethods)); } - return (MarkMapping[]) markerMethods.toArray(new MarkMapping[0]); + return markerMethods.toArray(new MarkMapping[0]); } public Mark[] getMarks() { - Set allMarks = new HashSet(); + Set allMarks = new HashSet<>(); - for (Iterator iter = delegates.iterator(); iter.hasNext();) { - Marker delegate = (Marker) iter.next(); + for (Marker delegate : delegates) { Mark[] marks = delegate.getMarks(); allMarks.addAll(Arrays.asList(marks)); } - return (Mark[]) allMarks.toArray(new Mark[0]); + return allMarks.toArray(new Mark[0]); } public void addMarker(Marker marker) { @@ -106,7 +104,7 @@ public void addMarker(Marker marker) { delegates.add(marker); } - public void addMarkers(Collection markers) { + public void addMarkers(Collection markers) { if (markers == null) { return; } @@ -122,7 +120,7 @@ public void removeMarker(Marker marker) { delegates.remove(marker); } - public void removeMarkers(Collection markers) { + public void removeMarkers(Collection markers) { if (markers == null) { return; } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/AbstractDataFrameProcessor.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/AbstractDataFrameProcessor.java index b82dfdc0c3..54ad44852c 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/AbstractDataFrameProcessor.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/AbstractDataFrameProcessor.java @@ -74,7 +74,7 @@ protected static interface ListenerFunctor { protected volatile ProfilerClient client = null; protected volatile boolean collectingTwoTimeStamps; - private final Set listeners = new CopyOnWriteArraySet(); + private final Set listeners = new CopyOnWriteArraySet<>(); // @GuardedBy this private boolean processorLives = false; @@ -109,8 +109,8 @@ public void processDataFrame(byte[] buffer) { } public void removeAllListeners() { - for (Iterator iter = listeners.iterator(); iter.hasNext();) { - ((ProfilingResultListener) iter.next()).shutdown(); + for (ProfilingResultListener listener : listeners) { + listener.shutdown(); } listeners.clear(); } @@ -173,8 +173,8 @@ public void execute(ProfilingResultListener listener) { } protected void foreachListener(ListenerFunctor functor) { - for (Iterator iter = listeners.iterator(); iter.hasNext();) { - functor.execute((ProfilingResultListener) iter.next()); + for (ProfilingResultListener listener : listeners) { + functor.execute(listener); } } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/BaseCallGraphBuilder.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/BaseCallGraphBuilder.java index 6f264f152c..a1a9b8c08c 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/BaseCallGraphBuilder.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/BaseCallGraphBuilder.java @@ -66,10 +66,10 @@ public abstract class BaseCallGraphBuilder implements ProfilingResultListener, C //~ Instance fields ---------------------------------------------------------------------------------------------------------- - protected List /**/ afterBatchCommands = new ArrayList /**/(); + protected List afterBatchCommands = new ArrayList<>(); protected ProfilingSessionStatus status; - protected final Set cctListeners = new CopyOnWriteArraySet(); - protected WeakReference clientRef; + protected final Set cctListeners = new CopyOnWriteArraySet<>(); + protected WeakReference clientRef; protected boolean batchNotEmpty = false; //~ Constructors ------------------------------------------------------------------------------------------------------------- @@ -104,8 +104,8 @@ public void onBatchStop() { } if (!afterBatchCommands.isEmpty()) { - for (Iterator iter = afterBatchCommands.iterator(); iter.hasNext();) { - ((Runnable) iter.next()).run(); + for (Runnable afterBatchCommand : afterBatchCommands) { + afterBatchCommand.run(); } afterBatchCommands.clear(); @@ -145,7 +145,7 @@ public void shutdown() { public void startup(ProfilerClient profilerClient) { status = profilerClient.getStatus(); - clientRef = new WeakReference(profilerClient); + clientRef = new WeakReference<>(profilerClient); doStartup(profilerClient); } @@ -166,7 +166,7 @@ protected ProfilerClient getClient() { return null; } - return (ProfilerClient) clientRef.get(); + return clientRef.get(); } private void fireCCTEstablished(boolean empty) { @@ -176,14 +176,14 @@ private void fireCCTEstablished(boolean empty) { return; } - for (Iterator iter = cctListeners.iterator(); iter.hasNext();) { - ((CCTProvider.Listener) iter.next()).cctEstablished(appNode, empty); + for (Listener cctListener : cctListeners) { + cctListener.cctEstablished(appNode, empty); } } private void fireCCTReset() { - for (Iterator iter = cctListeners.iterator(); iter.hasNext();) { - ((CCTProvider.Listener) iter.next()).cctReset(); + for (Listener cctListener : cctListeners) { + cctListener.cctReset(); } } } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/DataManager.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/DataManager.java index 4d1115dd42..5ce34ccca6 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/DataManager.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/DataManager.java @@ -55,7 +55,7 @@ public abstract class DataManager { //~ Instance fields ---------------------------------------------------------------------------------------------------------- - private final Set listeners = new HashSet(); + private final Set listeners = new HashSet<>(); //~ Methods ------------------------------------------------------------------------------------------------------------------ @@ -87,17 +87,14 @@ protected void fireDataChanged() { return; } - Set toNotify; + Set toNotify; synchronized (listeners) { - toNotify = new HashSet(listeners); + toNotify = new HashSet<>(listeners); } - Iterator iterator = toNotify.iterator(); - - while (iterator.hasNext()) { - final DataManagerListener listener = ((DataManagerListener) iterator.next()); - listener.dataChanged(); + for (DataManagerListener dataManagerListener : toNotify) { + dataManagerListener.dataChanged(); } } @@ -109,17 +106,14 @@ protected void fireDataReset() { return; } - Set toNotify; + Set toNotify; synchronized (listeners) { - toNotify = new HashSet(listeners); + toNotify = new HashSet<>(listeners); } - Iterator iterator = toNotify.iterator(); - - while (iterator.hasNext()) { - final DataManagerListener listener = ((DataManagerListener) iterator.next()); - listener.dataReset(); + for (DataManagerListener dataManagerListener : toNotify) { + dataManagerListener.dataReset(); } } } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTClassContainer.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTClassContainer.java index 858d441a4a..d320c07d38 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTClassContainer.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTClassContainer.java @@ -148,7 +148,7 @@ protected int generateClassNodeFromMethodNodes(IntVector methodNodes, int dataOf // Now add all the children of methodNodes that have the same class, to thisNode, and collect the rest of the // children of methodNodes into sourceChildren vector. IntVector sourceChildren = new IntVector(); - Hashtable uniqChildrenCache = new Hashtable(); + Hashtable uniqChildrenCache = new Hashtable<>(); for (int i = 0; i < nMethodNodes; i++) { int methodNodeOfs = methodNodes.get(i); @@ -195,12 +195,12 @@ protected int generateClassNodeFromMethodNodes(IntVector methodNodes, int dataOf .get(i))); } - Enumeration e = uniqChildrenCache.elements(); + Enumeration e = uniqChildrenCache.elements(); for (int i = 0; e.hasMoreElements(); i++) { sameTypeChildren.clear(); - int sourceChildClassOrPackageId = ((Integer) e.nextElement()).intValue(); + int sourceChildClassOrPackageId = e.nextElement().intValue(); for (int j = 0; j < nAllChildren; j++) { if (sourceChildrenClassIds[j] == sourceChildClassOrPackageId) { @@ -242,7 +242,7 @@ protected int generateClassNodeFromMethodNodes(IntVector methodNodes, int dataOf * 3. All other source children are added to allSourceChildren, but not to uniqChildCache. */ protected void processChildren(int dataOfs, int methodNodeOfs, int nChildren, IntVector allSourceChildren, - Hashtable uniqChildCache) { + Hashtable uniqChildCache) { int thisNodeClassOrPackageId = getMethodIdForNodeOfs(dataOfs); int nCalls = 0; diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTContainer.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTContainer.java index 6ef7df15cc..dc51a0e07a 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTContainer.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCCTContainer.java @@ -114,7 +114,7 @@ public class CPUCCTContainer { protected long[] timePerMethodId1; protected long[] totalTimePerMethodId0; protected long[] totalTimePerMethodId1; - protected Set methodsOnStack; + protected Set methodsOnStack; protected boolean collectingTwoTimeStamps; // True if we collect two timestamps, absolute and thread CPU, for each method invocation protected boolean displayWholeThreadCPUTime; // True if we can calculate, and thus display, valid whole thread CPU time @@ -556,7 +556,7 @@ protected void preGenerateFlatProfile() { invPerMethodId = new int[totalMethods]; timePerMethodId0[0] = -1; // 0th element is a hidden "Thread" quazi-method. This prevents exposing it in a pathological case when all times are zero. totalTimePerMethodId0[0] = -1; // 0th element is a hidden "Thread" quazi-method. This prevents exposing it in a pathological case when all times are zero. - methodsOnStack = new HashSet(); + methodsOnStack = new HashSet<>(); } // -- Utility methods, not interesting enough to place earlier in the code diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCallGraphBuilder.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCallGraphBuilder.java index 3a64fd2bf2..280aecf439 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCallGraphBuilder.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUCallGraphBuilder.java @@ -147,7 +147,7 @@ public CPUCCTContainer[] createPresentationCCTs(CPUResultsSnapshot cpuSnapshot) return null; } - List ccts = new ArrayList(len); + List ccts = new ArrayList<>(len); int threadId = 0; @@ -174,7 +174,7 @@ public CPUCCTContainer[] createPresentationCCTs(CPUResultsSnapshot cpuSnapshot) undoDiffAtGetResultsMoment(ti); } - return (CPUCCTContainer[]) ccts.toArray(new CPUCCTContainer[0]); + return ccts.toArray(new CPUCCTContainer[0]); } finally { threadInfos.endTrans(); } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUDataFrameProcessor.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUDataFrameProcessor.java index 974ca7b925..29c539ef11 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUDataFrameProcessor.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUDataFrameProcessor.java @@ -64,7 +64,7 @@ public class CPUDataFrameProcessor extends AbstractLockDataFrameProcessor { private boolean hasMonitorInfo; - private Map methodParameters = new HashMap(); + private Map methodParameters = new HashMap<>(); //~ Methods ------------------------------------------------------------------------------------------------------------------ public void doProcessDataFrame(ByteBuffer buffer) { @@ -137,7 +137,7 @@ public void doProcessDataFrame(ByteBuffer buffer) { switch (eventType) { case CommonConstants.MARKER_ENTRY_UNSTAMPED: { - List parameters = (List) methodParameters.get(Integer.valueOf(currentThreadId)); + List parameters = methodParameters.get(Integer.valueOf(currentThreadId)); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.log(Level.FINEST, "Marker entry unstamped, tId={0}, mId={1}, pars={2}", new Object[]{currentThreadId, methodId, parameters.toString()}); // NOI18N } @@ -174,7 +174,7 @@ public void doProcessDataFrame(ByteBuffer buffer) { break; } case CommonConstants.MARKER_ENTRY: { - List parameters = (List) methodParameters.get(Integer.valueOf(currentThreadId)); + List parameters = methodParameters.get(Integer.valueOf(currentThreadId)); int depth = getDepth(buffer); int[] methodIds = new int[depth]; @@ -212,7 +212,7 @@ public void doProcessDataFrame(ByteBuffer buffer) { break; } case CommonConstants.MARKER_EXIT: { - List parameters = (List) methodParameters.get(Integer.valueOf(currentThreadId)); + List parameters = methodParameters.get(Integer.valueOf(currentThreadId)); Object retVal = parameters == null ? null : parameters.get(0); if (LOGGER.isLoggable(Level.FINEST)) { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsDiff.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsDiff.java index 1008c40543..333132b352 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsDiff.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsDiff.java @@ -163,9 +163,9 @@ public PrestimeCPUCCTNode getReverseRootNode(int view, Collection threa private Collection threads2(Collection threads1) { if (threads1 == null || threads1.isEmpty()) return threads1; - Set threads1Names = new HashSet(); + Set threads1Names = new HashSet<>(); for (int thread1Id : threads1) threads1Names.add(getThreadNameForId(thread1Id)); - Set threads2 = new HashSet(); + Set threads2 = new HashSet<>(); for (int thread2Id : snapshot2.getThreadIds()) if (threads1Names.contains(snapshot2.getThreadNameForId(thread2Id))) threads2.add(thread2Id); diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsSnapshot.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsSnapshot.java index 58c8cb76e9..05365e1b3b 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsSnapshot.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUResultsSnapshot.java @@ -151,7 +151,7 @@ public static class NoDataAvailableException extends Exception { //~ Instance fields ---------------------------------------------------------------------------------------------------------- - protected Map threadIdMap; + protected Map threadIdMap; protected CPUCCTContainer[] allThreadsMergedCCTContainers; // [method|class|package aggregation level] -> CPUCCTContainer Per-view representation of all threads merged CCT containers // ,, triplets corresponding to methodIds in the profiling results @@ -167,13 +167,13 @@ public static class NoDataAvailableException extends Exception { // Number of instrumented methods - may be smaller than the size of the above arrays protected int nInstrMethods; - private final Map sortInfos = new WeakHashMap(); + private final Map sortInfos = new WeakHashMap<>(); //~ Constructors ------------------------------------------------------------------------------------------------------------- public CPUResultsSnapshot() { // No-arg constructor needed for above serialization methods to work super(); - threadIdMap = new HashMap(); + threadIdMap = new HashMap<>(); } public CPUResultsSnapshot(long beginTime, long timeTaken, CPUCCTProvider cctProvider, boolean collectingTwoTimestamps, @@ -196,7 +196,7 @@ public CPUResultsSnapshot(long beginTime, long timeTaken, CPUCCTProvider cctProv throw new NoDataAvailableException(); } - threadIdMap = new HashMap(methodLevelCCTs.length); + threadIdMap = new HashMap<>(methodLevelCCTs.length); for (int i = 0; i < methodLevelCCTs.length; i++) { threadIdMap.put(Integer.valueOf(methodLevelCCTs[i].threadId), Integer.valueOf(i)); @@ -311,7 +311,7 @@ public PrestimeCPUCCTNode getRootNode(int view, Collection threads, boo return fixNCalls(getRootNode(view)); } else { int[] _threads = getThreadIds(); - threads = new ArrayList(_threads.length); + threads = new ArrayList<>(_threads.length); for (int t : _threads) threads.add(t); } } @@ -341,7 +341,7 @@ private PrestimeCPUCCTNode fixNCalls(PrestimeCPUCCTNode root) { } private PrestimeCPUCCTNode[] mergedChildren(PrestimeCPUCCTNode[] nodes) { - List merged = new ArrayList(); + List merged = new ArrayList<>(); for (PrestimeCPUCCTNode node : nodes) { CCTNode[] children = node.getChildren(); @@ -357,7 +357,7 @@ private PrestimeCPUCCTNode[] mergedChildren(PrestimeCPUCCTNode[] nodes) { public PrestimeCPUCCTNode getReverseRootNode(final int view, Collection threads, boolean merge) { int[] threadIds = getThreadIds(); - List nodes = new ArrayList(); + List nodes = new ArrayList<>(); for (int i = 0; i < threadIds.length; i++) { final int threadIdF = threadIds[i]; if (threads == null || threads.contains(threadIdF)) { @@ -683,7 +683,7 @@ private int getContainerIdForThreadId(int threadId) { Integer cId = null; if (threadIdMap.containsKey(tid)) { - cId = (Integer) threadIdMap.get(tid); + cId = threadIdMap.get(tid); } return (cId != null) ? cId.intValue() : 0; diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUSamplingDataFrameProcessor.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUSamplingDataFrameProcessor.java index 5d6e97c3bb..6b08c05618 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUSamplingDataFrameProcessor.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/CPUSamplingDataFrameProcessor.java @@ -75,7 +75,7 @@ public class CPUSamplingDataFrameProcessor extends AbstractLockDataFrameProcesso private long currentTimestamp; private Map currentThreadsDump; private Map lastThreadsDump; - private List threadDumps = new ArrayList(); + private List threadDumps = new ArrayList<>(); private MethodNameFormatter formatter = MethodNameFormatterFactory.getDefault(new DefaultMethodNameFormatter(DefaultMethodNameFormatter.VERBOSITY_FULLMETHOD)).getFormatter(); private StackTraceSnapshotBuilder builder; @@ -84,13 +84,13 @@ public class CPUSamplingDataFrameProcessor extends AbstractLockDataFrameProcesso public void doProcessDataFrame(ByteBuffer buffer) { JMethodIdTable methodIdsTable = JMethodIdTable.getDefault(); - threadDumps = new ArrayList(); + threadDumps = new ArrayList<>(); while (buffer.hasRemaining()) { byte eventType = buffer.get(); switch (eventType) { case CommonConstants.THREAD_DUMP_START: - currentThreadsDump = new HashMap(); + currentThreadsDump = new HashMap<>(); currentTimestamp = getTimeStamp(buffer); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Thread dump start: Timestamps:"+currentTimestamp); // NOI18N @@ -272,7 +272,7 @@ private static Thread.State getThreadState(int threadState) { } private void processCollectedDumps(JMethodIdTable methodIdTable, List threadDumps) { - Map stackTraceElements = new HashMap(); + Map stackTraceElements = new HashMap<>(); InstrumentationFilter filter = builder.getFilter(); for (ThreadDump td : threadDumps) { diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTFlattener.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTFlattener.java index 1409c39d2f..eded84abae 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTFlattener.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTFlattener.java @@ -78,8 +78,8 @@ public class CCTFlattener extends RuntimeCCTNodeProcessor.PluginAdapter { // @GuardedBy containerGuard private FlatProfileContainer container; private ProfilerClient client; - private Stack parentStack; - private Set methodsOnStack; + private Stack parentStack = new Stack<>(); + private Set methodsOnStack = new HashSet<>(); private int[] invDiff; private int[] invPM; private int[] nCalleeInvocations; @@ -99,8 +99,6 @@ public class CCTFlattener extends RuntimeCCTNodeProcessor.PluginAdapter { public CCTFlattener(ProfilerClient client, CCTResultsFilter filter) { this.client = client; - parentStack = new Stack(); - methodsOnStack = new HashSet(); this.currentFilter = filter; } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTResultsFilter.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTResultsFilter.java index e0a51055b1..e93c5bd7a9 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTResultsFilter.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/cct/CCTResultsFilter.java @@ -79,18 +79,16 @@ public static interface EvaluatorProvider { //~ Instance fields ---------------------------------------------------------------------------------------------------------- - private Set /**/ evaluators = null; - private Set evaluatorProviders = new HashSet(); + private Set evaluators = new HashSet<>(); + private Set evaluatorProviders = new HashSet<>(); - private Stack passFlagStack; + private Stack passFlagStack = new Stack<>(); private boolean passingFilter; //~ Constructors ------------------------------------------------------------------------------------------------------------- /** Creates a new instance of CategoryFilter */ public CCTResultsFilter() { - evaluators = new HashSet /**/(); - passFlagStack = new Stack(); doReset(); } @@ -107,9 +105,9 @@ public synchronized boolean passesFilter() { @Override public void onStart() { evaluators.clear(); - - for(Iterator iter = evaluatorProviders.iterator();iter.hasNext();) { - evaluators.addAll(((EvaluatorProvider)iter.next()).getEvaluators()); + + for (EvaluatorProvider evaluatorProvider : evaluatorProviders) { + evaluators.addAll(evaluatorProvider.getEvaluators()); } } @@ -128,8 +126,7 @@ public void onNode(ThreadCPUCCTNode node) { passFlagStack.push(Boolean.valueOf(passingFilter)); passingFilter = true; - for (Iterator iter = evaluators.iterator(); iter.hasNext();) { - Evaluator evaluator = (Evaluator) iter.next(); + for (Evaluator evaluator : evaluators) { passingFilter = passingFilter && evaluator.evaluate(Mark.DEFAULT); } @@ -145,8 +142,7 @@ public void onNode(MarkedCPUCCTNode node) { passFlagStack.push(Boolean.valueOf(passingFilter)); passingFilter = true; - for (Iterator iter = evaluators.iterator(); iter.hasNext();) { - Evaluator evaluator = (Evaluator) iter.next(); + for (Evaluator evaluator : evaluators) { passingFilter = passingFilter && evaluator.evaluate(node.getMark()); } } @@ -154,7 +150,7 @@ public void onNode(MarkedCPUCCTNode node) { @Override public void onBackout(ThreadCPUCCTNode node) { if (!passFlagStack.isEmpty()) { - passingFilter = ((Boolean) passFlagStack.pop()).booleanValue(); + passingFilter = passFlagStack.pop().booleanValue(); } } @@ -164,7 +160,7 @@ public void onBackout(MarkedCPUCCTNode node) { } if (!passFlagStack.isEmpty()) { - passingFilter = ((Boolean) passFlagStack.pop()).booleanValue(); + passingFilter = passFlagStack.pop().booleanValue(); } } diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/server/ClassBytesLoader.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/server/ClassBytesLoader.java index 18b778c729..91f41408e5 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/server/ClassBytesLoader.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/server/ClassBytesLoader.java @@ -66,7 +66,7 @@ public class ClassBytesLoader { //~ Static fields/initializers ----------------------------------------------------------------------------------------------- - private static Map jarCache = new HashMap(); + private static Map jarCache = new HashMap<>(); //~ Methods ------------------------------------------------------------------------------------------------------------------ public static URL getClassFileURL(String className) { @@ -161,7 +161,7 @@ private static byte[] readJar(final URL classUrl) throws IOException { int sep = filePart.lastIndexOf('!'); String file = filePart.substring(0, sep); String entry = filePart.substring(sep + 2); - ZipFile jarFile = (ZipFile) jarCache.get(file); + ZipFile jarFile = jarCache.get(file); InputStream is; ZipEntry zipEntry; byte[] buf; diff --git a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/utils/MiscUtils.java b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/utils/MiscUtils.java index ee8b1bae09..c23280c22a 100644 --- a/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/utils/MiscUtils.java +++ b/visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/utils/MiscUtils.java @@ -126,7 +126,7 @@ public static String getAbsoluteFilePath(String fileName, String baseDir) { return fileName; } - public static void getAllClassesInDir(String dirName, String packageName, boolean removeClassExt, Collection res) { + public static void getAllClassesInDir(String dirName, String packageName, boolean removeClassExt, Collection res) { File dir = new File(dirName); String[] fileNames = dir.list(); @@ -217,7 +217,7 @@ public static String getClassNameForSource(String sourceFileName, String mainSou continue; } - List paths = getPathComponents(sourcePath, true, workingDir); + List paths = getPathComponents(sourcePath, true, workingDir); for (int j = 0; j < paths.size(); j++) { String path = (String) paths.get(j); @@ -305,7 +305,7 @@ public static String getJDKVersionForJVMExeFile(File exeFile) /** For a string representing a class path, remove all entries that don't correspond to existing files, and return the remaining ones. */ public static String getLiveClassPathSubset(String path, String workingDir) { - List liveComponents = getPathComponents(path, true, workingDir); + List liveComponents = getPathComponents(path, true, workingDir); StringBuilder buf = new StringBuilder(liveComponents.size() * 10); if (liveComponents.size() > 0) { @@ -326,8 +326,8 @@ public static String getLiveClassPathSubset(String path, String workingDir) { * and returns only existing components. workingDir is needed in case the passed path has * a local form. */ - public static List getPathComponents(String path, boolean doCheck, String workingDir) { - ArrayList list = new ArrayList(); + public static List getPathComponents(String path, boolean doCheck, String workingDir) { + ArrayList list = new ArrayList<>(); if (path != null) { StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); @@ -489,7 +489,7 @@ public static File checkFileForName(String name) throws IOException { public static boolean containsDirectoryOnPath(String directory, String path) { String normalizedDirectory = new File(directory).getAbsolutePath().toLowerCase(Locale.ENGLISH); String normalizedPath = new File(path).getAbsolutePath().toLowerCase(Locale.ENGLISH); - List pathComponents = getPathComponents(normalizedPath, false, null); + List pathComponents = getPathComponents(normalizedPath, false, null); for (int i = 0; i < pathComponents.size(); i++) { if (normalizedDirectory.equals(pathComponents.get(i))) { @@ -501,7 +501,7 @@ public static boolean containsDirectoryOnPath(String directory, String path) { } public static void deleteHeapTempFiles() { - if (Platform.isWindows()) { // this is workaroud for JDK bug #6359560 + if (Platform.isWindows()) { // this is workaround for JDK bug #6359560 try { File tempDir = new File(System.getProperty("java.io.tmpdir")); // NOI18N diff --git a/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/ClassesListController.java b/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/ClassesListController.java index 3bdc53c9eb..8e2f0665da 100644 --- a/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/ClassesListController.java +++ b/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/ClassesListController.java @@ -75,7 +75,7 @@ public class ClassesListController extends AbstractController { //~ Inner Classes ------------------------------------------------------------------------------------------------------------ - private static class ClassesComparator implements Comparator { + private static class ClassesComparator implements Comparator { //~ Instance fields ------------------------------------------------------------------------------------------------------ private boolean sortingOrder; @@ -90,9 +90,9 @@ public ClassesComparator(int sortingColumn, boolean sortingOrder) { //~ Methods -------------------------------------------------------------------------------------------------------------- - public int compare(Object o1, Object o2) { - JavaClass jClass1 = sortingOrder ? (JavaClass) o1 : (JavaClass) o2; - JavaClass jClass2 = sortingOrder ? (JavaClass) o2 : (JavaClass) o1; + public int compare(JavaClass o1, JavaClass o2) { + JavaClass jClass1 = sortingOrder ? o1 : o2; + JavaClass jClass2 = sortingOrder ? o2 : o1; switch (sortingColumn) { case 0: @@ -383,13 +383,13 @@ public List getFilteredSortedClasses(String[] filterStrings, int filterType, boo HeapFragmentWalker fragmentWalker = classesController.getHeapFragmentWalker(); Heap heap = fragmentWalker.getHeapFragment(); - List filteredClasses; + List filteredClasses; if ((filterType == FILTER_SUBCLASS) && !((filterStrings == null) || filterStrings[0].isEmpty())) { // NOI18N filteredClasses = getFilteredClasses(getSubclasses(heap, diffClasses, filterStrings, fragmentWalker.getHeapDumpProject()), null, CommonConstants.FILTER_NONE, showZeroInstances, showZeroSize); } else { - List classes = diffClasses == null ? heap.getAllClasses() : diffClasses; + List classes = diffClasses == null ? heap.getAllClasses() : diffClasses; filteredClasses = getFilteredClasses(classes, filterStrings, filterType, showZeroInstances, showZeroSize); } @@ -445,7 +445,7 @@ private void hideDiffProgress() { ((ClassesListControllerUI) getPanel()).hideDiffProgress(); } - private List diffClasses; + private List diffClasses; private boolean comparingSnapshot = false; private boolean compareRetained; public void compareAction() { @@ -488,7 +488,7 @@ public boolean compareRetained() { return compareRetained; } - private List createDiffClasses(Heap h1, Heap h2) { + private List createDiffClasses(Heap h1, Heap h2) { if (compareRetained) classesController.getHeapFragmentWalker(). computeRetainedSizes(false, false); @@ -515,7 +515,7 @@ private List createDiffClasses(Heap h1, Heap h2) { else classes.put(id2, djc2); } - return new ArrayList(classes.values()); + return new ArrayList<>(classes.values()); } public void resetDiffAction() { @@ -537,7 +537,7 @@ protected JPanel createControllerUI() { } @NbBundle.Messages("ClassesListController_AnalyzingClassesMsg=Analyzing classes...") - private static Collection getContextSubclasses(Heap heap, String className, Lookup.Provider project) { + private static Collection getContextSubclasses(Heap heap, String className, Lookup.Provider project) { ProgressHandle pHandle = null; try { @@ -545,10 +545,10 @@ private static Collection getContextSubclasses(Heap heap, String className, Look pHandle.setInitialDelay(0); pHandle.start(); - HashSet subclasses = new HashSet(); + HashSet subclasses = new HashSet<>(); SourceClassInfo sci = ProfilerTypeUtils.resolveClass(className, project); - Collection impls = sci != null ? sci.getSubclasses() : Collections.EMPTY_LIST; + Collection impls = sci != null ? sci.getSubclasses() : Collections.emptyList(); for (SourceClassInfo ci : impls) { JavaClass jClass = heap.getJavaClassByName(ci.getQualifiedName()); @@ -566,15 +566,11 @@ private static Collection getContextSubclasses(Heap heap, String className, Look } } - private static List getFilteredClasses(List classes, String[] filterStrings, int filterType, boolean showZeroInstances, + private static List getFilteredClasses(List classes, String[] filterStrings, int filterType, boolean showZeroInstances, boolean showZeroSize) { - ArrayList filteredClasses = new ArrayList(); - - Iterator classesIterator = classes.iterator(); - - while (classesIterator.hasNext()) { - JavaClass jClass = (JavaClass) classesIterator.next(); + ArrayList filteredClasses = new ArrayList<>(); + for (JavaClass jClass : classes) { if (matchesFilter(jClass, filterStrings, filterType, showZeroInstances, showZeroSize)) { filteredClasses.add(jClass); } @@ -584,21 +580,21 @@ private static List getFilteredClasses(List classes, String[] filterStrings, int } // --- Private implementation ------------------------------------------------ - private static List getSortedClasses(List filteredClasses, int sortingColumn, boolean sortingOrder) { + private static List getSortedClasses(List filteredClasses, int sortingColumn, boolean sortingOrder) { Collections.sort(filteredClasses, new ClassesComparator(sortingColumn, sortingOrder)); return filteredClasses; } - private static List getSubclasses(Heap heap, List diffClasses, String[] filterStrings, Lookup.Provider project) { - HashSet subclasses = new HashSet(); + private static List getSubclasses(Heap heap, List diffClasses, String[] filterStrings, Lookup.Provider project) { + HashSet subclasses = new HashSet<>(); for (int i = 0; i < filterStrings.length; i++) { String escapedClassName = "\\Q"+filterStrings[i]+"\\E"; Collection jClasses = heap.getJavaClassesByRegExp(escapedClassName); for (JavaClass jClass : jClasses) { - Collection subclassesCol = jClass.getSubClasses(); + Collection subclassesCol = jClass.getSubClasses(); subclasses.add(jClass); // instanceof approach rather than subclassof if (subclassesCol.size() > 0) { @@ -623,7 +619,7 @@ private static List getSubclasses(Heap heap, List diffClasses, String[] filterSt } return ret; } else { - return new ArrayList(subclasses); + return new ArrayList<>(subclasses); } } diff --git a/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/model/BrowserUtils.java b/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/model/BrowserUtils.java index 965dcae94a..64510b0ddf 100644 --- a/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/model/BrowserUtils.java +++ b/visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/model/BrowserUtils.java @@ -188,7 +188,7 @@ public static boolean isStaticField(FieldValue fieldValue) { } public static TreePath ensurePathComputed(HeapWalkerNode root, TreePath path, Set processed) { - List p = new ArrayList(); + List p = new ArrayList<>(); Object[] obj = path.getPath(); if (root == null || !root.equals(obj[0])) return null; diff --git a/visualvm/libs.profiler/profiler.snaptracer/src/org/graalvm/visualvm/lib/profiler/snaptracer/impl/swing/ColorIcon.java b/visualvm/libs.profiler/profiler.snaptracer/src/org/graalvm/visualvm/lib/profiler/snaptracer/impl/swing/ColorIcon.java index 7cf73458c6..43087e6205 100644 --- a/visualvm/libs.profiler/profiler.snaptracer/src/org/graalvm/visualvm/lib/profiler/snaptracer/impl/swing/ColorIcon.java +++ b/visualvm/libs.profiler/profiler.snaptracer/src/org/graalvm/visualvm/lib/profiler/snaptracer/impl/swing/ColorIcon.java @@ -63,7 +63,7 @@ public final class ColorIcon implements javax.swing.Icon { private final boolean shadow; private final Color color; - private static final Map icons = new HashMap(); + private static final Map icons = new HashMap<>(); private ColorIcon(Color color) { diff --git a/visualvm/libs.profiler/profiler/src/org/graalvm/visualvm/lib/profiler/v2/impl/ClassMethodSelector.java b/visualvm/libs.profiler/profiler/src/org/graalvm/visualvm/lib/profiler/v2/impl/ClassMethodSelector.java index 53f7094723..edcc89e03b 100644 --- a/visualvm/libs.profiler/profiler/src/org/graalvm/visualvm/lib/profiler/v2/impl/ClassMethodSelector.java +++ b/visualvm/libs.profiler/profiler/src/org/graalvm/visualvm/lib/profiler/v2/impl/ClassMethodSelector.java @@ -734,7 +734,7 @@ public void run() { } private static Collection getProjectPackages(Lookup.Provider project, boolean sources, boolean dependencies) { - Set packages = new HashSet(); + Set packages = new HashSet<>(); if (sources) packages.addAll(ProfilerTypeUtils.getPackages(false, SourcePackageInfo.Scope.SOURCE, project)); if (dependencies) packages.addAll(ProfilerTypeUtils.getPackages(false, SourcePackageInfo.Scope.DEPENDENCIES, project)); @@ -750,7 +750,7 @@ public int compare(SourcePackageInfo p1, SourcePackageInfo p2) { } private static Collection getFilePackages(FileObject file) { - Set packages = new HashSet(ExternalPackages.forPath(file, true)); + Set packages = new HashSet<>(ExternalPackages.forPath(file, true)); Set sortedPackages = new TreeSet( new Comparator() { @@ -907,7 +907,7 @@ private static Collection getClasses(SourcePackageInfo pkg, boo Collection classes = pkg.getClasses(); if (inner) { - Set _classes = new HashSet(); + Set _classes = new HashSet<>(); while (!classes.isEmpty()) { SourceClassInfo cls = classes.iterator().next(); classes.remove(cls); @@ -1081,7 +1081,7 @@ public int compare(SourceMethodInfo m1, SourceMethodInfo m2) { } ); - Set methods = new HashSet(cls.getConstructors()); + Set methods = new HashSet<>(cls.getConstructors()); methods.addAll(cls.getMethods(inherited)); for (SourceMethodInfo method : methods) { int modifiers = method.getModifiers(); @@ -1223,7 +1223,7 @@ void setup(Boolean mode, Dimension size) { private static abstract class FilteredListModel implements ListModel { - private final Collection listeners; + private final Collection listeners = new HashSet<>(); private final ListModel data; @@ -1231,14 +1231,11 @@ private static abstract class FilteredListModel implements ListModel { private E selected; private GenericFilter filter; - private final List indices; + private final List indices = new ArrayList<>(); public FilteredListModel(ListModel data) { this.data = data; - - listeners = new HashSet(); - - indices = new ArrayList(); + doFilter(); this.data.addListDataListener(new ListDataListener() { diff --git a/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CCTFlattener.java b/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CCTFlattener.java index ecd789b4d0..9ec41b0b0e 100644 --- a/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CCTFlattener.java +++ b/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CCTFlattener.java @@ -46,8 +46,8 @@ final class CCTFlattener extends RuntimeCCTNodeProcessor.PluginAdapter { // @GuardedBy containerGuard private FlatProfileContainer container; - private Stack parentStack; - private Set methodsOnStack; + private Stack parentStack = new Stack<>(); + private Set methodsOnStack = new HashSet<>(); private int[] invDiff; private int[] invPM; private int[] nCalleeInvocations; @@ -63,8 +63,6 @@ final class CCTFlattener extends RuntimeCCTNodeProcessor.PluginAdapter { //~ Constructors ------------------------------------------------------------------------------------------------------------- CCTFlattener(boolean twoStamps, MethodInfoMapper mapper, InstrumentationFilter f) { - parentStack = new Stack(); - methodsOnStack = new HashSet(); nMethods = mapper.getMaxMethodId(); methodInfoMapper = mapper; twoTimestamps = twoStamps; diff --git a/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CPUSamplerSupport.java b/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CPUSamplerSupport.java index 428191085b..3c2461e4a4 100644 --- a/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CPUSamplerSupport.java +++ b/visualvm/sampler/src/org/graalvm/visualvm/sampler/cpu/CPUSamplerSupport.java @@ -268,7 +268,7 @@ public void run() { private class SamplerTask extends TimerTask { private final StackTraceSnapshotBuilder builder; - private final Set samplingThreads = new HashSet(); + private final Set samplingThreads = new HashSet<>(); public SamplerTask(StackTraceSnapshotBuilder builder) { this.builder = builder;