Skip to content

Commit 93032c6

Browse files
committed
8242943: Fix all remaining unchecked warnings in jdk.hotspot.agent
Reviewed-by: darcy, sspitsyn, dholmes
1 parent 48569d9 commit 93032c6

14 files changed

Lines changed: 66 additions & 67 deletions

make/CompileJavaModules.gmk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ jdk.compiler_CLEAN_FILES += $(wildcard \
303303

304304
################################################################################
305305

306-
jdk.hotspot.agent_DISABLED_WARNINGS += rawtypes serial unchecked \
307-
cast static overrides fallthrough
306+
jdk.hotspot.agent_DISABLED_WARNINGS += rawtypes serial cast static overrides \
307+
fallthrough
308308
jdk.hotspot.agent_COPY += .gif .png sa.js .properties
309309

310310
################################################################################

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ci/ciMethodData.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,14 @@ public void dumpReplayData(PrintStream out) {
338338
ProfileData pdata = firstData();
339339
for ( ; isValid(pdata); pdata = nextData(pdata)) {
340340
if (pdata instanceof ReceiverTypeData) {
341-
count = dumpReplayDataReceiverTypeHelper(out, round, count, (ReceiverTypeData<ciKlass,ciMethod>)pdata);
341+
@SuppressWarnings("unchecked")
342+
ReceiverTypeData<ciKlass,ciMethod> receiverTypeData = (ReceiverTypeData<ciKlass,ciMethod>)pdata;
343+
count = dumpReplayDataReceiverTypeHelper(out, round, count, receiverTypeData);
342344
}
343345
if (pdata instanceof CallTypeDataInterface) {
344-
count = dumpReplayDataCallTypeHelper(out, round, count, (CallTypeDataInterface<ciKlass>)pdata);
346+
@SuppressWarnings("unchecked")
347+
CallTypeDataInterface<ciKlass> callTypeData = (CallTypeDataInterface<ciKlass>)pdata;
348+
count = dumpReplayDataCallTypeHelper(out, round, count, callTypeData);
345349
}
346350
}
347351
if (parameters != null) {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import sun.jvm.hotspot.utilities.Observable;
3737
import sun.jvm.hotspot.utilities.Observer;
3838

39-
public class ConstMethod extends VMObject {
39+
public class ConstMethod extends Metadata {
4040
static {
4141
VM.registerVMInitializedObserver(new Observer() {
4242
public void update(Observable o, Object data) {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Metadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static long alignSize(long size) {
5555
private static VirtualBaseConstructor<Metadata> metadataConstructor;
5656

5757
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
58-
metadataConstructor = new VirtualBaseConstructor<Metadata>(db, db.lookupType("Metadata"), null, null);
58+
metadataConstructor = new VirtualBaseConstructor<>(db, db.lookupType("Metadata"), null, null);
5959
// Define an explicit mapping since the C++ and Java type names don't match.
6060
metadataConstructor.addMapping("Metadata", Metadata.class);
6161
metadataConstructor.addMapping("Klass", Klass.class);

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/MethodData.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,14 @@ public void dumpReplayData(PrintStream out) {
523523
ProfileData pdata = firstData();
524524
for ( ; isValid(pdata); pdata = nextData(pdata)) {
525525
if (pdata instanceof ReceiverTypeData) {
526-
count = dumpReplayDataReceiverTypeHelper(out, round, count, (ReceiverTypeData<Klass,Method>)pdata);
526+
@SuppressWarnings("unchecked")
527+
ReceiverTypeData<Klass,Method> receiverTypeData = (ReceiverTypeData<Klass,Method>)pdata;
528+
count = dumpReplayDataReceiverTypeHelper(out, round, count, receiverTypeData);
527529
}
528530
if (pdata instanceof CallTypeDataInterface) {
529-
count = dumpReplayDataCallTypeHelper(out, round, count, (CallTypeDataInterface<Klass>)pdata);
531+
@SuppressWarnings("unchecked")
532+
CallTypeDataInterface<Klass> callTypeData = (CallTypeDataInterface<Klass>)pdata;
533+
count = dumpReplayDataCallTypeHelper(out, round, count, callTypeData);
530534
}
531535
}
532536
if (parameters != null) {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StaticBaseConstructor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,19 +34,19 @@
3434

3535
/** Instantiate wrappers for statically typed instances. */
3636

37-
public class StaticBaseConstructor<T> extends InstanceConstructor {
38-
private Class staticType;
37+
public class StaticBaseConstructor<T extends VMObject> extends InstanceConstructor<T> {
38+
private Class<T> staticType;
3939

4040
public StaticBaseConstructor(Class<T> t) {
4141
staticType = t;
4242
}
4343

4444
/** Instantiate a wrapper using staticType */
45-
public VMObject instantiateWrapperFor(Address addr) throws WrongTypeException {
45+
public T instantiateWrapperFor(Address addr) throws WrongTypeException {
4646
if (addr == null) {
4747
return null;
4848
}
4949

50-
return (VMObject) VMObjectFactory.newObject(staticType, addr);
50+
return VMObjectFactory.newObject(staticType, addr);
5151
}
5252
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VMObjectFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@ were desired (though the current system is designed to not require
4444
one.) </P>
4545
*/
4646

47-
public class VMObjectFactory {
47+
public class VMObjectFactory<T extends VMObject> {
4848
public static <T> T newObject(Class<T> clazz, Address addr)
4949
throws ConstructionException {
5050
try {

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualBaseConstructor.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
* type is know and the expected subclasses are within a particular
3737
* package. */
3838

39-
public class VirtualBaseConstructor<T> extends InstanceConstructor {
39+
public class VirtualBaseConstructor<T> extends InstanceConstructor<T> {
4040
private TypeDataBase db;
41-
private Map<String, Class<?>> map;
41+
private Map<String, Class<? extends T>> map;
4242
private Type baseType;
43-
private Class unknownTypeHandler;
43+
private Class<T> unknownTypeHandler;
4444

45-
public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName, Class unknownTypeHandler) {
45+
public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName, Class<T> unknownTypeHandler) {
4646
this.db = (HotSpotTypeDataBase)db;
4747
map = new HashMap<>();
4848
this.baseType = baseType;
@@ -59,10 +59,12 @@ public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName
5959
}
6060
if (superType == baseType) {
6161
superType = t;
62-
Class c = null;
62+
Class<? extends T> c = null;
6363
while (c == null && superType != null) {
6464
try {
65-
c = Class.forName(packageName + "." + superType.getName());
65+
@SuppressWarnings("unchecked")
66+
Class<? extends T> lookedUpClass = (Class<? extends T>)Class.forName(packageName + "." + superType.getName());
67+
c = lookedUpClass;
6668
} catch (Exception e) {
6769
}
6870
if (c == null) superType = superType.getSuperclass();
@@ -80,7 +82,7 @@ public VirtualBaseConstructor(TypeDataBase db, Type baseType, String packageName
8082
class. The latter must be a subclass of
8183
sun.jvm.hotspot.runtime.VMObject. Returns false if there was
8284
already a class for this type name in the map. */
83-
public boolean addMapping(String cTypeName, Class clazz) {
85+
public boolean addMapping(String cTypeName, Class<? extends T> clazz) {
8486
if (map.get(cTypeName) != null) {
8587
return false;
8688
}
@@ -101,9 +103,9 @@ public T instantiateWrapperFor(Address addr) throws WrongTypeException {
101103

102104
Type type = db.findDynamicTypeForAddress(addr, baseType);
103105
if (type != null) {
104-
return (T) VMObjectFactory.newObject((Class) map.get(type.getName()), addr);
106+
return VMObjectFactory.newObject(map.get(type.getName()), addr);
105107
} else if (unknownTypeHandler != null) {
106-
return (T) VMObjectFactory.newObject(unknownTypeHandler, addr);
108+
return VMObjectFactory.newObject(unknownTypeHandler, addr);
107109
}
108110

109111
throw newWrongTypeException(addr);

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/VirtualConstructor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,18 +40,18 @@
4040

4141
public class VirtualConstructor extends InstanceConstructor<VMObject> {
4242
private TypeDataBase db;
43-
private Map map; // Map<String, Class>
43+
private Map<String, Class<? extends VMObject>> map;
4444

4545
public VirtualConstructor(TypeDataBase db) {
4646
this.db = db;
47-
map = new HashMap();
47+
map = new HashMap<>();
4848
}
4949

5050
/** Adds a mapping from the given C++ type name to the given Java
5151
class. The latter must be a subclass of
5252
sun.jvm.hotspot.runtime.VMObject. Returns false if there was
5353
already a class for this type name in the map. */
54-
public boolean addMapping(String cTypeName, Class clazz) {
54+
public boolean addMapping(String cTypeName, Class<? extends VMObject> clazz) {
5555
if (map.get(cTypeName) != null) {
5656
return false;
5757
}
@@ -70,10 +70,10 @@ public VMObject instantiateWrapperFor(Address addr) throws WrongTypeException {
7070
return null;
7171
}
7272

73-
for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
74-
String typeName = (String) iter.next();
73+
for (Iterator<String> iter = map.keySet().iterator(); iter.hasNext(); ) {
74+
String typeName = iter.next();
7575
if (db.addressTypeIsEqualToType(addr, db.lookupType(typeName))) {
76-
return (VMObject) VMObjectFactory.newObject((Class) map.get(typeName), addr);
76+
return VMObjectFactory.newObject(map.get(typeName), addr);
7777
}
7878
}
7979

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/ObjectHistogramPanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public ObjectHistogramColummModel() {
160160
/**
161161
* A table model which encapsulates the ObjectHistogram
162162
*/
163-
private class ObjectHistogramTableModel extends SortableTableModel {
163+
private class ObjectHistogramTableModel extends SortableTableModel<ObjectHistogramElement> {
164164
private String[] columnNames = { "Size", "Count", "Class Description" };
165165
private Class[] columnClasses = { Long.class, Long.class, String.class };
166166

@@ -191,7 +191,7 @@ public Object getValueAt(int row, int col) {
191191
return getValueForColumn(getElement(row), col);
192192
}
193193

194-
public Object getValueForColumn(Object obj, int col) {
194+
public Comparable<?> getValueForColumn(Object obj, int col) {
195195
ObjectHistogramElement el = (ObjectHistogramElement)obj;
196196
switch (col) {
197197
case 0:
@@ -206,7 +206,7 @@ public Object getValueForColumn(Object obj, int col) {
206206
}
207207

208208
public ObjectHistogramElement getElement(int index) {
209-
return (ObjectHistogramElement) elements.get(index);
209+
return elements.get(index);
210210
}
211211

212212
private class ObjectHistogramComparator extends TableModelComparator {
@@ -222,7 +222,7 @@ public ObjectHistogramComparator(ObjectHistogramTableModel model) {
222222
* @param obj Object that was passed for Comparator
223223
* @param column the column to retrieve
224224
*/
225-
public Object getValueForColumn(Object obj, int column) {
225+
public Comparable<?> getValueForColumn(Object obj, int column) {
226226
ObjectHistogramTableModel omodel = (ObjectHistogramTableModel)model;
227227
return omodel.getValueForColumn(obj, column);
228228
}

0 commit comments

Comments
 (0)