From 93032c637bc1459b1a8f87dcb2c966ff3a49e4bc Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Tue, 21 Apr 2020 13:55:23 +0200 Subject: [PATCH] 8242943: Fix all remaining unchecked warnings in jdk.hotspot.agent Reviewed-by: darcy, sspitsyn, dholmes --- make/CompileJavaModules.gmk | 4 +-- .../sun/jvm/hotspot/ci/ciMethodData.java | 8 ++++-- .../sun/jvm/hotspot/oops/ConstMethod.java | 2 +- .../sun/jvm/hotspot/oops/Metadata.java | 2 +- .../sun/jvm/hotspot/oops/MethodData.java | 8 ++++-- .../runtime/StaticBaseConstructor.java | 10 +++---- .../jvm/hotspot/runtime/VMObjectFactory.java | 4 +-- .../runtime/VirtualBaseConstructor.java | 20 +++++++------- .../hotspot/runtime/VirtualConstructor.java | 14 +++++----- .../jvm/hotspot/ui/ObjectHistogramPanel.java | 8 +++--- .../sun/jvm/hotspot/ui/ObjectListPanel.java | 19 +++++++------- .../hotspot/ui/table/SortableTableModel.java | 6 ++--- .../ui/table/TableModelComparator.java | 26 ++++++------------- .../jvm/hotspot/utilities/ObjectReader.java | 2 +- 14 files changed, 66 insertions(+), 67 deletions(-) diff --git a/make/CompileJavaModules.gmk b/make/CompileJavaModules.gmk index ced5020b000..cf441dc5be2 100644 --- a/make/CompileJavaModules.gmk +++ b/make/CompileJavaModules.gmk @@ -303,8 +303,8 @@ jdk.compiler_CLEAN_FILES += $(wildcard \ ################################################################################ -jdk.hotspot.agent_DISABLED_WARNINGS += rawtypes serial unchecked \ - cast static overrides fallthrough +jdk.hotspot.agent_DISABLED_WARNINGS += rawtypes serial cast static overrides \ + fallthrough jdk.hotspot.agent_COPY += .gif .png sa.js .properties ################################################################################ diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ci/ciMethodData.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ci/ciMethodData.java index 981cc072395..873d7f4f7e6 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ci/ciMethodData.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ci/ciMethodData.java @@ -338,10 +338,14 @@ public class ciMethodData extends ciMetadata implements MethodDataInterface)pdata); + @SuppressWarnings("unchecked") + ReceiverTypeData receiverTypeData = (ReceiverTypeData)pdata; + count = dumpReplayDataReceiverTypeHelper(out, round, count, receiverTypeData); } if (pdata instanceof CallTypeDataInterface) { - count = dumpReplayDataCallTypeHelper(out, round, count, (CallTypeDataInterface)pdata); + @SuppressWarnings("unchecked") + CallTypeDataInterface callTypeData = (CallTypeDataInterface)pdata; + count = dumpReplayDataCallTypeHelper(out, round, count, callTypeData); } } if (parameters != null) { diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstMethod.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstMethod.java index 82ca1e4fb8c..2854f8693ed 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstMethod.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstMethod.java @@ -36,7 +36,7 @@ import sun.jvm.hotspot.utilities.*; import sun.jvm.hotspot.utilities.Observable; import sun.jvm.hotspot.utilities.Observer; -public class ConstMethod extends VMObject { +public class ConstMethod extends Metadata { static { VM.registerVMInitializedObserver(new Observer() { public void update(Observable o, Object data) { diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Metadata.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Metadata.java index 8e9bf99c6ba..7f693547c9e 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Metadata.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Metadata.java @@ -55,7 +55,7 @@ abstract public class Metadata extends VMObject { private static VirtualBaseConstructor metadataConstructor; private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { - metadataConstructor = new VirtualBaseConstructor(db, db.lookupType("Metadata"), null, null); + metadataConstructor = new VirtualBaseConstructor<>(db, db.lookupType("Metadata"), null, null); // Define an explicit mapping since the C++ and Java type names don't match. metadataConstructor.addMapping("Metadata", Metadata.class); metadataConstructor.addMapping("Klass", Klass.class); diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/MethodData.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/MethodData.java index ba52d499c90..7af081869b7 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/MethodData.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/MethodData.java @@ -523,10 +523,14 @@ public class MethodData extends Metadata implements MethodDataInterface)pdata); + @SuppressWarnings("unchecked") + ReceiverTypeData receiverTypeData = (ReceiverTypeData)pdata; + count = dumpReplayDataReceiverTypeHelper(out, round, count, receiverTypeData); } if (pdata instanceof CallTypeDataInterface) { - count = dumpReplayDataCallTypeHelper(out, round, count, (CallTypeDataInterface)pdata); + @SuppressWarnings("unchecked") + CallTypeDataInterface callTypeData = (CallTypeDataInterface)pdata; + count = dumpReplayDataCallTypeHelper(out, round, count, callTypeData); } } if (parameters != null) { diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StaticBaseConstructor.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StaticBaseConstructor.java index c45f5249d38..ec99cdd4106 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StaticBaseConstructor.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StaticBaseConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,19 +34,19 @@ import sun.jvm.hotspot.HotSpotTypeDataBase; /** Instantiate wrappers for statically typed instances. */ -public class StaticBaseConstructor extends InstanceConstructor { - private Class staticType; +public class StaticBaseConstructor extends InstanceConstructor { + private Class staticType; public StaticBaseConstructor(Class t) { staticType = t; } /** Instantiate a wrapper using staticType */ - public VMObject instantiateWrapperFor(Address addr) throws WrongTypeException { + public T instantiateWrapperFor(Address addr) throws WrongTypeException { if (addr == null) { return null; } - return (VMObject) VMObjectFactory.newObject(staticType, addr); + return VMObjectFactory.newObject(staticType, addr); } } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VMObjectFactory.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VMObjectFactory.java index ec486667979..67476c5ca4b 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VMObjectFactory.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VMObjectFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,7 +44,7 @@ import sun.jvm.hotspot.types.*; one.)

*/ -public class VMObjectFactory { +public class VMObjectFactory { public static T newObject(Class clazz, Address addr) throws ConstructionException { try { diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualBaseConstructor.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualBaseConstructor.java index 1252c422a50..8b5fbca3f83 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualBaseConstructor.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualBaseConstructor.java @@ -36,13 +36,13 @@ import sun.jvm.hotspot.HotSpotTypeDataBase; * type is know and the expected subclasses are within a particular * package. */ -public class VirtualBaseConstructor extends InstanceConstructor { +public class VirtualBaseConstructor extends InstanceConstructor { private TypeDataBase db; - private Map> map; + private Map> map; private Type baseType; - private Class unknownTypeHandler; + private Class unknownTypeHandler; - public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName, Class unknownTypeHandler) { + public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName, Class unknownTypeHandler) { this.db = (HotSpotTypeDataBase)db; map = new HashMap<>(); this.baseType = baseType; @@ -59,10 +59,12 @@ public class VirtualBaseConstructor extends InstanceConstructor { } if (superType == baseType) { superType = t; - Class c = null; + Class c = null; while (c == null && superType != null) { try { - c = Class.forName(packageName + "." + superType.getName()); + @SuppressWarnings("unchecked") + Class lookedUpClass = (Class)Class.forName(packageName + "." + superType.getName()); + c = lookedUpClass; } catch (Exception e) { } if (c == null) superType = superType.getSuperclass(); @@ -80,7 +82,7 @@ public class VirtualBaseConstructor extends InstanceConstructor { class. The latter must be a subclass of sun.jvm.hotspot.runtime.VMObject. Returns false if there was already a class for this type name in the map. */ - public boolean addMapping(String cTypeName, Class clazz) { + public boolean addMapping(String cTypeName, Class clazz) { if (map.get(cTypeName) != null) { return false; } @@ -101,9 +103,9 @@ public class VirtualBaseConstructor extends InstanceConstructor { Type type = db.findDynamicTypeForAddress(addr, baseType); if (type != null) { - return (T) VMObjectFactory.newObject((Class) map.get(type.getName()), addr); + return VMObjectFactory.newObject(map.get(type.getName()), addr); } else if (unknownTypeHandler != null) { - return (T) VMObjectFactory.newObject(unknownTypeHandler, addr); + return VMObjectFactory.newObject(unknownTypeHandler, addr); } throw newWrongTypeException(addr); diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualConstructor.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualConstructor.java index acca1670c86..fc741ef2524 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualConstructor.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,18 +40,18 @@ import sun.jvm.hotspot.types.*; public class VirtualConstructor extends InstanceConstructor { private TypeDataBase db; - private Map map; // Map + private Map> map; public VirtualConstructor(TypeDataBase db) { this.db = db; - map = new HashMap(); + map = new HashMap<>(); } /** Adds a mapping from the given C++ type name to the given Java class. The latter must be a subclass of sun.jvm.hotspot.runtime.VMObject. Returns false if there was already a class for this type name in the map. */ - public boolean addMapping(String cTypeName, Class clazz) { + public boolean addMapping(String cTypeName, Class clazz) { if (map.get(cTypeName) != null) { return false; } @@ -70,10 +70,10 @@ public class VirtualConstructor extends InstanceConstructor { return null; } - for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) { - String typeName = (String) iter.next(); + for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) { + String typeName = iter.next(); if (db.addressTypeIsEqualToType(addr, db.lookupType(typeName))) { - return (VMObject) VMObjectFactory.newObject((Class) map.get(typeName), addr); + return VMObjectFactory.newObject(map.get(typeName), addr); } } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectHistogramPanel.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectHistogramPanel.java index 21a8ee97383..e856c9d73f7 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectHistogramPanel.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectHistogramPanel.java @@ -160,7 +160,7 @@ public class ObjectHistogramPanel extends JPanel implements ActionListener { /** * A table model which encapsulates the ObjectHistogram */ - private class ObjectHistogramTableModel extends SortableTableModel { + private class ObjectHistogramTableModel extends SortableTableModel { private String[] columnNames = { "Size", "Count", "Class Description" }; private Class[] columnClasses = { Long.class, Long.class, String.class }; @@ -191,7 +191,7 @@ public class ObjectHistogramPanel extends JPanel implements ActionListener { return getValueForColumn(getElement(row), col); } - public Object getValueForColumn(Object obj, int col) { + public Comparable getValueForColumn(Object obj, int col) { ObjectHistogramElement el = (ObjectHistogramElement)obj; switch (col) { case 0: @@ -206,7 +206,7 @@ public class ObjectHistogramPanel extends JPanel implements ActionListener { } public ObjectHistogramElement getElement(int index) { - return (ObjectHistogramElement) elements.get(index); + return elements.get(index); } private class ObjectHistogramComparator extends TableModelComparator { @@ -222,7 +222,7 @@ public class ObjectHistogramPanel extends JPanel implements ActionListener { * @param obj Object that was passed for Comparator * @param column the column to retrieve */ - public Object getValueForColumn(Object obj, int column) { + public Comparable getValueForColumn(Object obj, int column) { ObjectHistogramTableModel omodel = (ObjectHistogramTableModel)model; return omodel.getValueForColumn(obj, column); } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectListPanel.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectListPanel.java index d9a33e63917..41f149be5e9 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectListPanel.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectListPanel.java @@ -43,7 +43,7 @@ import sun.jvm.hotspot.ui.tree.*; public class ObjectListPanel extends SAPanel { private ObjectListTableModel dataModel; private JTable table; - private java.util.List elements; + private java.util.List elements; private HeapProgressThunk thunk; private boolean checkedForArrays; private boolean hasArrays; @@ -55,7 +55,7 @@ public class ObjectListPanel extends SAPanel { /** Takes a List in constructor, and an optional HeapProgressThunk used if computing liveness */ - public ObjectListPanel(java.util.List els, + public ObjectListPanel(java.util.List els, HeapProgressThunk thunk) { super(); @@ -120,7 +120,7 @@ public class ObjectListPanel extends SAPanel { // Internals only below this point // - private static class AddressWrapper implements Comparable { + private static class AddressWrapper implements Comparable { private Address address; private AddressWrapper(Address address) { @@ -131,8 +131,7 @@ public class ObjectListPanel extends SAPanel { return address.toString(); } - public int compareTo(Object o) { - AddressWrapper wrapper = (AddressWrapper) o; + public int compareTo(AddressWrapper wrapper) { Address addr = wrapper.address; if (AddressOps.lessThan(address, addr)) return -1; if (AddressOps.greaterThan(address, addr)) return 1; @@ -140,7 +139,7 @@ public class ObjectListPanel extends SAPanel { } } - private class ObjectListTableModel extends SortableTableModel { + private class ObjectListTableModel extends SortableTableModel { public ObjectListTableModel() { // Set the rows this.elements = ObjectListPanel.this.elements; @@ -180,7 +179,7 @@ public class ObjectListPanel extends SAPanel { return getValueForColumn(oop, col); } - public Object getValueForColumn(Oop oop, int col) { + public Comparable getValueForColumn(Oop oop, int col) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); switch (col) { @@ -241,7 +240,7 @@ public class ObjectListPanel extends SAPanel { * @param obj Object that was passed for Comparator * @param column the column to retrieve */ - public Object getValueForColumn(Object obj, int column) { + public Comparable getValueForColumn(Object obj, int column) { ObjectListTableModel omodel = (ObjectListTableModel)model; return omodel.getValueForColumn((Oop) obj, column); } @@ -254,7 +253,7 @@ public class ObjectListPanel extends SAPanel { return; } - Oop oop = (Oop) elements.get(i); + Oop oop = elements.get(i); for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { SAListener listener = (SAListener) iter.next(); @@ -311,7 +310,7 @@ public class ObjectListPanel extends SAPanel { return; } - Oop oop = (Oop) elements.get(i); + Oop oop = elements.get(i); LivenessPathList list = LivenessAnalysis.computeAllLivenessPaths(oop); if (list == null) { return; // dead object diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/SortableTableModel.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/SortableTableModel.java index 22d223313f3..a2c9b1600b6 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/SortableTableModel.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/SortableTableModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,14 +35,14 @@ import javax.swing.table.AbstractTableModel; * of the list may be sortable by column. The TableModelComparator * must be set for sorting to be enabled. */ -public abstract class SortableTableModel extends AbstractTableModel { +public abstract class SortableTableModel extends AbstractTableModel { private TableModelComparator comparator; /** * All the rows are stored as a List. */ - protected java.util.List elements; + protected java.util.List elements; /** * This comparator must be set. diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/TableModelComparator.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/TableModelComparator.java index 09dc0d4b8c1..cb02067624d 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/TableModelComparator.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/table/TableModelComparator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,7 @@ import javax.swing.event.TableModelEvent; /** * A comparator which compares rows in a table model */ -public abstract class TableModelComparator implements Comparator { +public abstract class TableModelComparator implements Comparator { private boolean ascending; protected TableModel model; @@ -81,8 +81,10 @@ public abstract class TableModelComparator implements Comparator { public int compare(Object row1, Object row2) { for (int i = 0; i < columns.length; i++) { - Object o1 = getValueForColumn(row1, columns[i]); - Object o2 = getValueForColumn(row2, columns[i]); + @SuppressWarnings("unchecked") + Comparable o1 = (Comparable) getValueForColumn(row1, columns[i]); + @SuppressWarnings("unchecked") + Comparable o2 = (Comparable) getValueForColumn(row2, columns[i]); // If both values are null, return 0. if (o1 == null && o2 == null) { @@ -93,19 +95,7 @@ public abstract class TableModelComparator implements Comparator { return 1; } - int result = 0; - - if (o1 instanceof Comparable) { - Comparable c1 = (Comparable)o1; - Comparable c2 = (Comparable)o2; - - result = c1.compareTo(c2); - } - - // XXX Should have some sort of provision for determininte - // if there is another way of comparing the objects. - // Perhaps we should add the requirement that all table - // values be Compabable. + int result = o1.compareTo(o2); if (result != 0) { return ascending ? result : -result; @@ -121,6 +111,6 @@ public abstract class TableModelComparator implements Comparator { * @param obj Row object that was passed into Comparator. * @param column the column to retrieve */ - public abstract Object getValueForColumn(Object obj, int column); + public abstract Comparable getValueForColumn(Object obj, int column); } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java index c540c1e548c..59d57709bc0 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java @@ -297,7 +297,7 @@ public class ObjectReader { return getProperties(oop); } - Class clz = readClass(kls); + Class clz = readClass(kls); try { result = clz.getDeclaredConstructor().newInstance(); } catch (Exception ex) {