8242943: Fix all remaining unchecked warnings in jdk.hotspot.agent

Reviewed-by: darcy, sspitsyn, dholmes
This commit is contained in:
Magnus Ihse Bursie 2020-04-21 13:55:23 +02:00
parent 48569d9da0
commit 93032c637b
14 changed files with 66 additions and 67 deletions

View File

@ -303,8 +303,8 @@ jdk.compiler_CLEAN_FILES += $(wildcard \
################################################################################ ################################################################################
jdk.hotspot.agent_DISABLED_WARNINGS += rawtypes serial unchecked \ jdk.hotspot.agent_DISABLED_WARNINGS += rawtypes serial cast static overrides \
cast static overrides fallthrough fallthrough
jdk.hotspot.agent_COPY += .gif .png sa.js .properties jdk.hotspot.agent_COPY += .gif .png sa.js .properties
################################################################################ ################################################################################

View File

@ -338,10 +338,14 @@ public class ciMethodData extends ciMetadata implements MethodDataInterface<ciKl
ProfileData pdata = firstData(); ProfileData pdata = firstData();
for ( ; isValid(pdata); pdata = nextData(pdata)) { for ( ; isValid(pdata); pdata = nextData(pdata)) {
if (pdata instanceof ReceiverTypeData) { if (pdata instanceof ReceiverTypeData) {
count = dumpReplayDataReceiverTypeHelper(out, round, count, (ReceiverTypeData<ciKlass,ciMethod>)pdata); @SuppressWarnings("unchecked")
ReceiverTypeData<ciKlass,ciMethod> receiverTypeData = (ReceiverTypeData<ciKlass,ciMethod>)pdata;
count = dumpReplayDataReceiverTypeHelper(out, round, count, receiverTypeData);
} }
if (pdata instanceof CallTypeDataInterface) { if (pdata instanceof CallTypeDataInterface) {
count = dumpReplayDataCallTypeHelper(out, round, count, (CallTypeDataInterface<ciKlass>)pdata); @SuppressWarnings("unchecked")
CallTypeDataInterface<ciKlass> callTypeData = (CallTypeDataInterface<ciKlass>)pdata;
count = dumpReplayDataCallTypeHelper(out, round, count, callTypeData);
} }
} }
if (parameters != null) { if (parameters != null) {

View File

@ -36,7 +36,7 @@ import sun.jvm.hotspot.utilities.*;
import sun.jvm.hotspot.utilities.Observable; import sun.jvm.hotspot.utilities.Observable;
import sun.jvm.hotspot.utilities.Observer; import sun.jvm.hotspot.utilities.Observer;
public class ConstMethod extends VMObject { public class ConstMethod extends Metadata {
static { static {
VM.registerVMInitializedObserver(new Observer() { VM.registerVMInitializedObserver(new Observer() {
public void update(Observable o, Object data) { public void update(Observable o, Object data) {

View File

@ -55,7 +55,7 @@ abstract public class Metadata extends VMObject {
private static VirtualBaseConstructor<Metadata> metadataConstructor; private static VirtualBaseConstructor<Metadata> metadataConstructor;
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
metadataConstructor = new VirtualBaseConstructor<Metadata>(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. // Define an explicit mapping since the C++ and Java type names don't match.
metadataConstructor.addMapping("Metadata", Metadata.class); metadataConstructor.addMapping("Metadata", Metadata.class);
metadataConstructor.addMapping("Klass", Klass.class); metadataConstructor.addMapping("Klass", Klass.class);

View File

@ -523,10 +523,14 @@ public class MethodData extends Metadata implements MethodDataInterface<Klass,Me
ProfileData pdata = firstData(); ProfileData pdata = firstData();
for ( ; isValid(pdata); pdata = nextData(pdata)) { for ( ; isValid(pdata); pdata = nextData(pdata)) {
if (pdata instanceof ReceiverTypeData) { if (pdata instanceof ReceiverTypeData) {
count = dumpReplayDataReceiverTypeHelper(out, round, count, (ReceiverTypeData<Klass,Method>)pdata); @SuppressWarnings("unchecked")
ReceiverTypeData<Klass,Method> receiverTypeData = (ReceiverTypeData<Klass,Method>)pdata;
count = dumpReplayDataReceiverTypeHelper(out, round, count, receiverTypeData);
} }
if (pdata instanceof CallTypeDataInterface) { if (pdata instanceof CallTypeDataInterface) {
count = dumpReplayDataCallTypeHelper(out, round, count, (CallTypeDataInterface<Klass>)pdata); @SuppressWarnings("unchecked")
CallTypeDataInterface<Klass> callTypeData = (CallTypeDataInterface<Klass>)pdata;
count = dumpReplayDataCallTypeHelper(out, round, count, callTypeData);
} }
} }
if (parameters != null) { if (parameters != null) {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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. */ /** Instantiate wrappers for statically typed instances. */
public class StaticBaseConstructor<T> extends InstanceConstructor { public class StaticBaseConstructor<T extends VMObject> extends InstanceConstructor<T> {
private Class staticType; private Class<T> staticType;
public StaticBaseConstructor(Class<T> t) { public StaticBaseConstructor(Class<T> t) {
staticType = t; staticType = t;
} }
/** Instantiate a wrapper using staticType */ /** Instantiate a wrapper using staticType */
public VMObject instantiateWrapperFor(Address addr) throws WrongTypeException { public T instantiateWrapperFor(Address addr) throws WrongTypeException {
if (addr == null) { if (addr == null) {
return null; return null;
} }
return (VMObject) VMObjectFactory.newObject(staticType, addr); return VMObjectFactory.newObject(staticType, addr);
} }
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -44,7 +44,7 @@ import sun.jvm.hotspot.types.*;
one.) </P> one.) </P>
*/ */
public class VMObjectFactory { public class VMObjectFactory<T extends VMObject> {
public static <T> T newObject(Class<T> clazz, Address addr) public static <T> T newObject(Class<T> clazz, Address addr)
throws ConstructionException { throws ConstructionException {
try { try {

View File

@ -36,13 +36,13 @@ import sun.jvm.hotspot.HotSpotTypeDataBase;
* type is know and the expected subclasses are within a particular * type is know and the expected subclasses are within a particular
* package. */ * package. */
public class VirtualBaseConstructor<T> extends InstanceConstructor { public class VirtualBaseConstructor<T> extends InstanceConstructor<T> {
private TypeDataBase db; private TypeDataBase db;
private Map<String, Class<?>> map; private Map<String, Class<? extends T>> map;
private Type baseType; private Type baseType;
private Class unknownTypeHandler; private Class<T> unknownTypeHandler;
public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName, Class unknownTypeHandler) { public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName, Class<T> unknownTypeHandler) {
this.db = (HotSpotTypeDataBase)db; this.db = (HotSpotTypeDataBase)db;
map = new HashMap<>(); map = new HashMap<>();
this.baseType = baseType; this.baseType = baseType;
@ -59,10 +59,12 @@ public class VirtualBaseConstructor<T> extends InstanceConstructor {
} }
if (superType == baseType) { if (superType == baseType) {
superType = t; superType = t;
Class c = null; Class<? extends T> c = null;
while (c == null && superType != null) { while (c == null && superType != null) {
try { try {
c = Class.forName(packageName + "." + superType.getName()); @SuppressWarnings("unchecked")
Class<? extends T> lookedUpClass = (Class<? extends T>)Class.forName(packageName + "." + superType.getName());
c = lookedUpClass;
} catch (Exception e) { } catch (Exception e) {
} }
if (c == null) superType = superType.getSuperclass(); if (c == null) superType = superType.getSuperclass();
@ -80,7 +82,7 @@ public class VirtualBaseConstructor<T> extends InstanceConstructor {
class. The latter must be a subclass of class. The latter must be a subclass of
sun.jvm.hotspot.runtime.VMObject. Returns false if there was sun.jvm.hotspot.runtime.VMObject. Returns false if there was
already a class for this type name in the map. */ already a class for this type name in the map. */
public boolean addMapping(String cTypeName, Class clazz) { public boolean addMapping(String cTypeName, Class<? extends T> clazz) {
if (map.get(cTypeName) != null) { if (map.get(cTypeName) != null) {
return false; return false;
} }
@ -101,9 +103,9 @@ public class VirtualBaseConstructor<T> extends InstanceConstructor {
Type type = db.findDynamicTypeForAddress(addr, baseType); Type type = db.findDynamicTypeForAddress(addr, baseType);
if (type != null) { 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) { } else if (unknownTypeHandler != null) {
return (T) VMObjectFactory.newObject(unknownTypeHandler, addr); return VMObjectFactory.newObject(unknownTypeHandler, addr);
} }
throw newWrongTypeException(addr); throw newWrongTypeException(addr);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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<VMObject> { public class VirtualConstructor extends InstanceConstructor<VMObject> {
private TypeDataBase db; private TypeDataBase db;
private Map map; // Map<String, Class> private Map<String, Class<? extends VMObject>> map;
public VirtualConstructor(TypeDataBase db) { public VirtualConstructor(TypeDataBase db) {
this.db = db; this.db = db;
map = new HashMap(); map = new HashMap<>();
} }
/** Adds a mapping from the given C++ type name to the given Java /** Adds a mapping from the given C++ type name to the given Java
class. The latter must be a subclass of class. The latter must be a subclass of
sun.jvm.hotspot.runtime.VMObject. Returns false if there was sun.jvm.hotspot.runtime.VMObject. Returns false if there was
already a class for this type name in the map. */ already a class for this type name in the map. */
public boolean addMapping(String cTypeName, Class clazz) { public boolean addMapping(String cTypeName, Class<? extends VMObject> clazz) {
if (map.get(cTypeName) != null) { if (map.get(cTypeName) != null) {
return false; return false;
} }
@ -70,10 +70,10 @@ public class VirtualConstructor extends InstanceConstructor<VMObject> {
return null; return null;
} }
for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) { for (Iterator<String> iter = map.keySet().iterator(); iter.hasNext(); ) {
String typeName = (String) iter.next(); String typeName = iter.next();
if (db.addressTypeIsEqualToType(addr, db.lookupType(typeName))) { if (db.addressTypeIsEqualToType(addr, db.lookupType(typeName))) {
return (VMObject) VMObjectFactory.newObject((Class) map.get(typeName), addr); return VMObjectFactory.newObject(map.get(typeName), addr);
} }
} }

View File

@ -160,7 +160,7 @@ public class ObjectHistogramPanel extends JPanel implements ActionListener {
/** /**
* A table model which encapsulates the ObjectHistogram * A table model which encapsulates the ObjectHistogram
*/ */
private class ObjectHistogramTableModel extends SortableTableModel { private class ObjectHistogramTableModel extends SortableTableModel<ObjectHistogramElement> {
private String[] columnNames = { "Size", "Count", "Class Description" }; private String[] columnNames = { "Size", "Count", "Class Description" };
private Class[] columnClasses = { Long.class, Long.class, String.class }; 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); return getValueForColumn(getElement(row), col);
} }
public Object getValueForColumn(Object obj, int col) { public Comparable<?> getValueForColumn(Object obj, int col) {
ObjectHistogramElement el = (ObjectHistogramElement)obj; ObjectHistogramElement el = (ObjectHistogramElement)obj;
switch (col) { switch (col) {
case 0: case 0:
@ -206,7 +206,7 @@ public class ObjectHistogramPanel extends JPanel implements ActionListener {
} }
public ObjectHistogramElement getElement(int index) { public ObjectHistogramElement getElement(int index) {
return (ObjectHistogramElement) elements.get(index); return elements.get(index);
} }
private class ObjectHistogramComparator extends TableModelComparator { 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 obj Object that was passed for Comparator
* @param column the column to retrieve * @param column the column to retrieve
*/ */
public Object getValueForColumn(Object obj, int column) { public Comparable<?> getValueForColumn(Object obj, int column) {
ObjectHistogramTableModel omodel = (ObjectHistogramTableModel)model; ObjectHistogramTableModel omodel = (ObjectHistogramTableModel)model;
return omodel.getValueForColumn(obj, column); return omodel.getValueForColumn(obj, column);
} }

View File

@ -43,7 +43,7 @@ import sun.jvm.hotspot.ui.tree.*;
public class ObjectListPanel extends SAPanel { public class ObjectListPanel extends SAPanel {
private ObjectListTableModel dataModel; private ObjectListTableModel dataModel;
private JTable table; private JTable table;
private java.util.List elements; private java.util.List<Oop> elements;
private HeapProgressThunk thunk; private HeapProgressThunk thunk;
private boolean checkedForArrays; private boolean checkedForArrays;
private boolean hasArrays; private boolean hasArrays;
@ -55,7 +55,7 @@ public class ObjectListPanel extends SAPanel {
/** Takes a List<Oop> in constructor, and an optional /** Takes a List<Oop> in constructor, and an optional
HeapProgressThunk used if computing liveness */ HeapProgressThunk used if computing liveness */
public ObjectListPanel(java.util.List els, public ObjectListPanel(java.util.List<Oop> els,
HeapProgressThunk thunk) { HeapProgressThunk thunk) {
super(); super();
@ -120,7 +120,7 @@ public class ObjectListPanel extends SAPanel {
// Internals only below this point // Internals only below this point
// //
private static class AddressWrapper implements Comparable { private static class AddressWrapper implements Comparable<AddressWrapper> {
private Address address; private Address address;
private AddressWrapper(Address address) { private AddressWrapper(Address address) {
@ -131,8 +131,7 @@ public class ObjectListPanel extends SAPanel {
return address.toString(); return address.toString();
} }
public int compareTo(Object o) { public int compareTo(AddressWrapper wrapper) {
AddressWrapper wrapper = (AddressWrapper) o;
Address addr = wrapper.address; Address addr = wrapper.address;
if (AddressOps.lessThan(address, addr)) return -1; if (AddressOps.lessThan(address, addr)) return -1;
if (AddressOps.greaterThan(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<Oop> {
public ObjectListTableModel() { public ObjectListTableModel() {
// Set the rows // Set the rows
this.elements = ObjectListPanel.this.elements; this.elements = ObjectListPanel.this.elements;
@ -180,7 +179,7 @@ public class ObjectListPanel extends SAPanel {
return getValueForColumn(oop, col); return getValueForColumn(oop, col);
} }
public Object getValueForColumn(Oop oop, int col) { public Comparable<?> getValueForColumn(Oop oop, int col) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
switch (col) { switch (col) {
@ -241,7 +240,7 @@ public class ObjectListPanel extends SAPanel {
* @param obj Object that was passed for Comparator * @param obj Object that was passed for Comparator
* @param column the column to retrieve * @param column the column to retrieve
*/ */
public Object getValueForColumn(Object obj, int column) { public Comparable<?> getValueForColumn(Object obj, int column) {
ObjectListTableModel omodel = (ObjectListTableModel)model; ObjectListTableModel omodel = (ObjectListTableModel)model;
return omodel.getValueForColumn((Oop) obj, column); return omodel.getValueForColumn((Oop) obj, column);
} }
@ -254,7 +253,7 @@ public class ObjectListPanel extends SAPanel {
return; return;
} }
Oop oop = (Oop) elements.get(i); Oop oop = elements.get(i);
for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { for (Iterator iter = listeners.iterator(); iter.hasNext(); ) {
SAListener listener = (SAListener) iter.next(); SAListener listener = (SAListener) iter.next();
@ -311,7 +310,7 @@ public class ObjectListPanel extends SAPanel {
return; return;
} }
Oop oop = (Oop) elements.get(i); Oop oop = elements.get(i);
LivenessPathList list = LivenessAnalysis.computeAllLivenessPaths(oop); LivenessPathList list = LivenessAnalysis.computeAllLivenessPaths(oop);
if (list == null) { if (list == null) {
return; // dead object return; // dead object

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * of the list may be sortable by column. The TableModelComparator
* must be set for sorting to be enabled. * must be set for sorting to be enabled.
*/ */
public abstract class SortableTableModel extends AbstractTableModel { public abstract class SortableTableModel<T> extends AbstractTableModel {
private TableModelComparator comparator; private TableModelComparator comparator;
/** /**
* All the rows are stored as a List. * All the rows are stored as a List.
*/ */
protected java.util.List elements; protected java.util.List<T> elements;
/** /**
* This comparator must be set. * This comparator must be set.

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * A comparator which compares rows in a table model
*/ */
public abstract class TableModelComparator implements Comparator { public abstract class TableModelComparator implements Comparator<Object> {
private boolean ascending; private boolean ascending;
protected TableModel model; protected TableModel model;
@ -81,8 +81,10 @@ public abstract class TableModelComparator implements Comparator {
public int compare(Object row1, Object row2) { public int compare(Object row1, Object row2) {
for (int i = 0; i < columns.length; i++) { for (int i = 0; i < columns.length; i++) {
Object o1 = getValueForColumn(row1, columns[i]); @SuppressWarnings("unchecked")
Object o2 = getValueForColumn(row2, columns[i]); Comparable<Object> o1 = (Comparable<Object>) getValueForColumn(row1, columns[i]);
@SuppressWarnings("unchecked")
Comparable<Object> o2 = (Comparable<Object>) getValueForColumn(row2, columns[i]);
// If both values are null, return 0. // If both values are null, return 0.
if (o1 == null && o2 == null) { if (o1 == null && o2 == null) {
@ -93,19 +95,7 @@ public abstract class TableModelComparator implements Comparator {
return 1; return 1;
} }
int result = 0; int result = o1.compareTo(o2);
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.
if (result != 0) { if (result != 0) {
return ascending ? result : -result; return ascending ? result : -result;
@ -121,6 +111,6 @@ public abstract class TableModelComparator implements Comparator {
* @param obj Row object that was passed into Comparator. * @param obj Row object that was passed into Comparator.
* @param column the column to retrieve * @param column the column to retrieve
*/ */
public abstract Object getValueForColumn(Object obj, int column); public abstract Comparable<?> getValueForColumn(Object obj, int column);
} }

View File

@ -297,7 +297,7 @@ public class ObjectReader {
return getProperties(oop); return getProperties(oop);
} }
Class clz = readClass(kls); Class<?> clz = readClass(kls);
try { try {
result = clz.getDeclaredConstructor().newInstance(); result = clz.getDeclaredConstructor().newInstance();
} catch (Exception ex) { } catch (Exception ex) {