8215648: remove equals and hashCode implementations from j.l.i.VarHandle
Reviewed-by: mchung
--- a/src/java.base/share/classes/java/lang/invoke/VarHandle.java Thu Jan 10 13:54:09 2019 +0100
+++ b/src/java.base/share/classes/java/lang/invoke/VarHandle.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, 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
@@ -1865,35 +1865,6 @@
}
/**
- * Compare this {@linkplain VarHandle} with another object for equality.
- * Two {@linkplain VarHandle}s are considered equal if they both describe the
- * same instance field, both describe the same static field, both describe
- * array elements for arrays with the same component type, or both describe
- * the same component of an off-heap structure.
- *
- * @param o the other object
- * @return Whether this {@linkplain VarHandle} is equal to the other object
- */
- @Override
- public final boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- VarHandle that = (VarHandle) o;
- return accessModeType(AccessMode.GET).equals(that.accessModeType(AccessMode.GET)) &&
- internalEquals(that);
- }
-
- abstract boolean internalEquals(VarHandle vh);
-
- @Override
- public final int hashCode() {
- return 31 * accessModeType(AccessMode.GET).hashCode() + internalHashCode();
- }
-
- abstract int internalHashCode();
-
- /**
* Returns a compact textual description of this {@linkplain VarHandle},
* including the type of variable described, and a description of its coordinates.
*
--- a/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template Thu Jan 10 13:54:09 2019 +0100
+++ b/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -64,17 +64,6 @@
}
@Override
- final boolean internalEquals(VarHandle vh) {
- FieldInstanceReadOnly that = (FieldInstanceReadOnly) vh;
- return fieldOffset == that.fieldOffset;
- }
-
- @Override
- final int internalHashCode() {
- return Long.hashCode(fieldOffset);
- }
-
- @Override
public Optional<VarHandleDesc> describeConstable() {
var receiverTypeRef = receiverType.describeConstable();
var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
@@ -350,17 +339,6 @@
}
@Override
- final boolean internalEquals(VarHandle vh) {
- FieldStaticReadOnly that = (FieldStaticReadOnly) vh;
- return base == that.base && fieldOffset == that.fieldOffset;
- }
-
- @Override
- final int internalHashCode() {
- return 31 * Long.hashCode(fieldOffset) + base.hashCode();
- }
-
- @Override
public Optional<VarHandleDesc> describeConstable() {
var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
if (!fieldTypeRef.isPresent())
@@ -640,20 +618,6 @@
}
@Override
- final boolean internalEquals(VarHandle vh) {
- // Equality of access mode types of AccessMode.GET is sufficient for
- // equality checks
- return true;
- }
-
- @Override
- final int internalHashCode() {
- // The hash code of the access mode types of AccessMode.GET is
- // sufficient for hash code generation
- return 0;
- }
-
- @Override
public Optional<VarHandleDesc> describeConstable() {
var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
if (!arrayTypeRef.isPresent())
--- a/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template Thu Jan 10 13:54:09 2019 +0100
+++ b/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -67,17 +67,6 @@
super(form);
this.be = be;
}
-
- @Override
- final boolean internalEquals(VarHandle vh) {
- ByteArrayViewVarHandle that = (ByteArrayViewVarHandle) vh;
- return be == that.be;
- }
-
- @Override
- final int internalHashCode() {
- return Boolean.hashCode(be);
- }
}
static final class ArrayHandle extends ByteArrayViewVarHandle {
--- a/test/jdk/java/lang/constant/CondyDescTest.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/constant/CondyDescTest.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, 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
@@ -67,7 +67,6 @@
private void testVarHandleDesc(DynamicConstantDesc<VarHandle> r, VarHandle vh) throws ReflectiveOperationException {
testSymbolicDesc(r);
- assertEquals(r.resolveConstantDesc(LOOKUP), vh);
assertEquals(vh.describeConstable().orElseThrow(), r);
}
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -141,8 +141,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -143,8 +143,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -93,8 +93,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -93,8 +93,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -93,8 +93,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -93,8 +93,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -93,8 +93,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);
--- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java Thu Jan 10 13:54:09 2019 +0100
+++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java Fri Jan 11 09:02:44 2019 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -93,8 +93,6 @@
for (int j = 0; j < vhs1.length; j++) {
if (i == j) {
assertEquals(vhs1[i], vhs1[i]);
- assertEquals(vhs1[i], vhs2[i]);
- assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
}
else {
assertNotEquals(vhs1[i], vhs1[j]);