8243156: Fix deprecation and unchecked warnings in microbenchmark

Reviewed-by: erikj, redestad
This commit is contained in:
Magnus Ihse Bursie 2020-04-21 13:52:32 +02:00
parent 71b06ed298
commit 48569d9da0
10 changed files with 45 additions and 29 deletions

View File

@ -77,7 +77,7 @@ $(eval $(call SetupJavaCompilation, BUILD_INDIFY, \
SETUP := GENERATE_OLDBYTECODE, \ SETUP := GENERATE_OLDBYTECODE, \
SRC := $(TOPDIR)/test/jdk/java/lang/invoke, \ SRC := $(TOPDIR)/test/jdk/java/lang/invoke, \
INCLUDE_FILES := indify/Indify.java, \ INCLUDE_FILES := indify/Indify.java, \
DISABLED_WARNINGS := rawtypes unchecked serial deprecation, \ DISABLED_WARNINGS := rawtypes serial, \
BIN := $(MICROBENCHMARK_TOOLS_CLASSES), \ BIN := $(MICROBENCHMARK_TOOLS_CLASSES), \
)) ))
@ -99,7 +99,7 @@ $(eval $(call SetupJavaCompiler, MICROBENCHMARK_JAVA_COMPILER, \
$(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \
SETUP := MICROBENCHMARK_JAVA_COMPILER, \ SETUP := MICROBENCHMARK_JAVA_COMPILER, \
ADD_JAVAC_FLAGS := -cp $(MICROBENCHMARK_CLASSPATH), \ ADD_JAVAC_FLAGS := -cp $(MICROBENCHMARK_CLASSPATH), \
DISABLED_WARNINGS := processing rawtypes cast serial deprecation, \ DISABLED_WARNINGS := processing rawtypes cast serial, \
SRC := $(MICROBENCHMARK_SRC), \ SRC := $(MICROBENCHMARK_SRC), \
BIN := $(MICROBENCHMARK_CLASSES), \ BIN := $(MICROBENCHMARK_CLASSES), \
)) ))

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 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
@ -702,7 +702,9 @@ public class Indify {
args = jvm.args(3); // array, index, value args = jvm.args(3); // array, index, value
if (args.get(0) instanceof List && if (args.get(0) instanceof List &&
args.get(1) instanceof Integer) { args.get(1) instanceof Integer) {
((List<Object>)args.get(0)).set( (Integer)args.get(1), args.get(2) ); @SuppressWarnings("unchecked")
List<Object> arg0 = (List<Object>)args.get(0);
arg0.set( (Integer)args.get(1), args.get(2) );
} }
args.clear(); args.clear();
break; break;
@ -869,7 +871,7 @@ public class Indify {
if (patternMark != 'I') break decode; if (patternMark != 'I') break decode;
if ("invokeWithArguments".equals(intrinsic)) if ("invokeWithArguments".equals(intrinsic))
flattenVarargs(args); flattenVarargs(args);
bsmArgs = new ArrayList(args); bsmArgs = new ArrayList<>(args);
args.clear(); args.add("invokeGeneric"); args.clear(); args.add("invokeGeneric");
continue; continue;
case "Integer.valueOf": case "Integer.valueOf":
@ -970,8 +972,10 @@ public class Indify {
private void flattenVarargs(List<Object> args) { private void flattenVarargs(List<Object> args) {
int size = args.size(); int size = args.size();
if (size > 0 && args.get(size-1) instanceof List) if (size > 0 && args.get(size - 1) instanceof List) {
args.addAll((List<Object>) args.remove(size-1)); List<?> removedArg = (List<?>) args.remove(size - 1);
args.addAll(removedArg);
}
} }
private boolean isConstant(Object x, int tag) { private boolean isConstant(Object x, int tag) {
@ -1032,6 +1036,7 @@ public class Indify {
extraArgs.addAll(args.subList(argi, args.size() - 1)); extraArgs.addAll(args.subList(argi, args.size() - 1));
Object lastArg = args.get(args.size() - 1); Object lastArg = args.get(args.size() - 1);
if (lastArg instanceof List) { if (lastArg instanceof List) {
@SuppressWarnings("unchecked")
List<Object> lastArgs = (List<Object>) lastArg; List<Object> lastArgs = (List<Object>) lastArg;
removeEmptyJVMSlots(lastArgs); removeEmptyJVMSlots(lastArgs);
extraArgs.addAll(lastArgs); extraArgs.addAll(lastArgs);
@ -1098,7 +1103,9 @@ public class Indify {
} catch (IOException ex) { throw new InternalError(); } } catch (IOException ex) { throw new InternalError(); }
bsms.item = specs; bsms.item = specs;
} }
return (List<Object[]>) bsms.item; @SuppressWarnings("unchecked")
List<Object[]> specs = (List<Object[]>) bsms.item;
return specs;
} }
} }
@ -1168,7 +1175,7 @@ public class Indify {
data = in.readUTF(); data = in.readUTF();
} else if (Chunk.class.isAssignableFrom(dataClass)) { } else if (Chunk.class.isAssignableFrom(dataClass)) {
T obj; T obj;
try { obj = dataClass.newInstance(); } try { obj = dataClass.getDeclaredConstructor().newInstance(); }
catch (Exception ex) { throw new RuntimeException(ex); } catch (Exception ex) { throw new RuntimeException(ex); }
((Chunk)obj).readFrom(in); ((Chunk)obj).readFrom(in);
data = obj; data = obj;
@ -1317,7 +1324,7 @@ public class Indify {
readConstant(in); readConstant(in);
} }
} }
public <T> Constant<T> addConstant(byte tag, T item) { public <T> Constant addConstant(byte tag, T item) {
Constant<T> con = new Constant<>(size(), tag, item); Constant<T> con = new Constant<>(size(), tag, item);
int idx = indexOf(con); int idx = indexOf(con);
if (idx >= 0) return get(idx); if (idx >= 0) return get(idx);
@ -1339,7 +1346,7 @@ public class Indify {
arg = in.readInt(); break; arg = in.readInt(); break;
case CONSTANT_Long: case CONSTANT_Long:
case CONSTANT_Double: case CONSTANT_Double:
add(new Constant(index, tag, in.readLong())); add(new Constant<>(index, tag, in.readLong()));
add(null); add(null);
return; return;
case CONSTANT_Class: case CONSTANT_Class:
@ -1362,7 +1369,7 @@ public class Indify {
default: default:
throw new InternalError("bad CP tag "+tag); throw new InternalError("bad CP tag "+tag);
} }
add(new Constant(index, tag, arg)); add(new Constant<>(index, tag, arg));
} }
// Access: // Access:

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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
@ -60,6 +60,7 @@ public class NewInstance {
* Performs Class.newInstance on the same class over and over again. That it is the same class is not provable at * Performs Class.newInstance on the same class over and over again. That it is the same class is not provable at
* compile time. The class is protected. * compile time. The class is protected.
*/ */
@SuppressWarnings("deprecation")
@Benchmark @Benchmark
public void threeSameProtected(Blackhole bh) throws IllegalAccessException, InstantiationException { public void threeSameProtected(Blackhole bh) throws IllegalAccessException, InstantiationException {
for (Class<?> cl : sameProtectedClasses) { for (Class<?> cl : sameProtectedClasses) {
@ -71,6 +72,7 @@ public class NewInstance {
* Performs Class.newInstance on three different classes, just allocating one instance of one class at a time. The * Performs Class.newInstance on three different classes, just allocating one instance of one class at a time. The
* classes are all protected. * classes are all protected.
*/ */
@SuppressWarnings("deprecation")
@Benchmark @Benchmark
public void threeDifferentProtected(Blackhole bh) throws IllegalAccessException, InstantiationException { public void threeDifferentProtected(Blackhole bh) throws IllegalAccessException, InstantiationException {
for (Class<?> cl : differentProtectedClasses) { for (Class<?> cl : differentProtectedClasses) {
@ -82,6 +84,7 @@ public class NewInstance {
* Performs Class.newInstance on the same class over and over again. That it is the same class is not provable at * Performs Class.newInstance on the same class over and over again. That it is the same class is not provable at
* compile time. The class is public. * compile time. The class is public.
*/ */
@SuppressWarnings("deprecation")
@Benchmark @Benchmark
public void threeSamePublic(Blackhole bh) throws IllegalAccessException, InstantiationException { public void threeSamePublic(Blackhole bh) throws IllegalAccessException, InstantiationException {
for (Class<?> cl : samePublicClasses) { for (Class<?> cl : samePublicClasses) {
@ -93,6 +96,7 @@ public class NewInstance {
* Performs Class.newInstance on three different classes, just allocating one instance of one class at a time. The * Performs Class.newInstance on three different classes, just allocating one instance of one class at a time. The
* classes are all public. * classes are all public.
*/ */
@SuppressWarnings("deprecation")
@Benchmark @Benchmark
public void threeDifferentPublic(Blackhole bh) throws IllegalAccessException, InstantiationException { public void threeDifferentPublic(Blackhole bh) throws IllegalAccessException, InstantiationException {
for (Class<?> cl : differentPublicClasses) { for (Class<?> cl : differentPublicClasses) {
@ -104,6 +108,7 @@ public class NewInstance {
* Performs Class.newInstance on three different classes, just allocating one instance of one class at a time. The * Performs Class.newInstance on three different classes, just allocating one instance of one class at a time. The
* classes are all public. * classes are all public.
*/ */
@SuppressWarnings("deprecation")
@Benchmark @Benchmark
public void threeDifferentPublicConstant(Blackhole bh) throws IllegalAccessException, InstantiationException { public void threeDifferentPublicConstant(Blackhole bh) throws IllegalAccessException, InstantiationException {
bh.consume(Apub.class.newInstance()); bh.consume(Apub.class.newInstance());
@ -111,6 +116,7 @@ public class NewInstance {
bh.consume(Cpub.class.newInstance()); bh.consume(Cpub.class.newInstance());
} }
@SuppressWarnings("deprecation")
@Benchmark @Benchmark
public void threeDifferentPublicFinal(Blackhole bh) throws IllegalAccessException, InstantiationException { public void threeDifferentPublicFinal(Blackhole bh) throws IllegalAccessException, InstantiationException {
for (Class<?> cl : differentPublicClassesConstant) { for (Class<?> cl : differentPublicClassesConstant) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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
@ -59,9 +59,9 @@ public class MethodInvoke {
args_6ref = new Object[]{ new Object(), new Object(), args_6ref = new Object[]{ new Object(), new Object(),
new Object(), new Object(), new Object(), new Object()}; new Object(), new Object(), new Object(), new Object()};
args_6prim = new Object[]{ args_6prim = new Object[]{
new Integer(1), new Long(5L), 1, 5L,
new Double(5.6d), new Float(23.11f), 5.6d, 23.11f,
Boolean.TRUE, new Character('d') Boolean.TRUE, 'd'
}; };
staticMeth_0 = getMethodWithName("staticMethodWithoutParams"); staticMeth_0 = getMethodWithName("staticMethodWithoutParams");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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
@ -73,11 +73,13 @@ public class ProxyBench {
PkgPrivate1.class, PkgPrivate2.class}; PkgPrivate1.class, PkgPrivate2.class};
@Benchmark @Benchmark
@SuppressWarnings("deprecation")
public Class<?> getProxyClass1i() { public Class<?> getProxyClass1i() {
return Proxy.getProxyClass(loader1, interfaces1); return Proxy.getProxyClass(loader1, interfaces1);
} }
@Benchmark @Benchmark
@SuppressWarnings("deprecation")
public Class<?> getProxyClass4i() { public Class<?> getProxyClass4i() {
return Proxy.getProxyClass(loader4, interfaces4); return Proxy.getProxyClass(loader4, interfaces4);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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
@ -33,6 +33,7 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.infra.Blackhole;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -142,7 +143,7 @@ public class BigDecimals {
@OperationsPerInvocation(TEST_SIZE) @OperationsPerInvocation(TEST_SIZE)
public void testSetScale(Blackhole bh) { public void testSetScale(Blackhole bh) {
for (BigDecimal s : bigDecimals) { for (BigDecimal s : bigDecimals) {
bh.consume(s.setScale(2, BigDecimal.ROUND_HALF_UP)); bh.consume(s.setScale(2, RoundingMode.HALF_UP));
} }
} }
@ -152,7 +153,7 @@ public class BigDecimals {
public void testSetScaleVarious(Blackhole bh) { public void testSetScaleVarious(Blackhole bh) {
for (int scale = 0; scale < 50; scale++) { for (int scale = 0; scale < 50; scale++) {
for (BigDecimal s : bigDecimals) { for (BigDecimal s : bigDecimals) {
bh.consume(s.setScale(scale, BigDecimal.ROUND_HALF_UP)); bh.consume(s.setScale(scale, RoundingMode.HALF_UP));
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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
@ -62,7 +62,7 @@ public class Maps {
total = 0; total = 0;
key = new Integer[nkeys]; key = new Integer[nkeys];
for (int i = 0; i < key.length; ++i) { for (int i = 0; i < key.length; ++i) {
key[i] = new Integer(rng.next()); key[i] = rng.next();
} }
position = key.length / 2; position = key.length / 2;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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,7 +35,7 @@ public class IntegerDuplicateProblem {
Random rand = new Random(0x30052012); Random rand = new Random(0x30052012);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = new Integer(rand.nextInt()); data[i] = rand.nextInt();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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,7 +35,7 @@ public class IntegerMaxProblem {
Random rand = new Random(0x30052012); Random rand = new Random(0x30052012);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = new Integer(rand.nextInt()); data[i] = rand.nextInt();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 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,7 +35,7 @@ public class IntegerSumProblem {
Random rand = new Random(0x30052012); Random rand = new Random(0x30052012);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = new Integer(rand.nextInt()); data[i] = rand.nextInt();
} }
} }