8215648: remove equals and hashCode implementations from j.l.i.VarHandle

Reviewed-by: mchung
This commit is contained in:
Vicente Romero 2019-01-11 09:02:44 -05:00
parent 8243e7f9fa
commit 0032475ef1
19 changed files with 19 additions and 126 deletions

View file

@ -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. * 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
@ -1864,35 +1864,6 @@ public abstract class VarHandle implements Constable {
} }
} }
/**
* 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}, * Returns a compact textual description of this {@linkplain VarHandle},
* including the type of variable described, and a description of its coordinates. * including the type of variable described, and a description of its coordinates.

View file

@ -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. * 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
@ -63,17 +63,6 @@ final class VarHandle$Type$s {
return accessMode.at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class}); return accessMode.at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
} }
@Override
final boolean internalEquals(VarHandle vh) {
FieldInstanceReadOnly that = (FieldInstanceReadOnly) vh;
return fieldOffset == that.fieldOffset;
}
@Override
final int internalHashCode() {
return Long.hashCode(fieldOffset);
}
@Override @Override
public Optional<VarHandleDesc> describeConstable() { public Optional<VarHandleDesc> describeConstable() {
var receiverTypeRef = receiverType.describeConstable(); var receiverTypeRef = receiverType.describeConstable();
@ -349,17 +338,6 @@ final class VarHandle$Type$s {
#end[Object] #end[Object]
} }
@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 @Override
public Optional<VarHandleDesc> describeConstable() { public Optional<VarHandleDesc> describeConstable() {
var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable(); var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
@ -639,20 +617,6 @@ final class VarHandle$Type$s {
#end[Object] #end[Object]
} }
@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 @Override
public Optional<VarHandleDesc> describeConstable() { public Optional<VarHandleDesc> describeConstable() {
var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable(); var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();

View file

@ -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. * 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
@ -67,17 +67,6 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
super(form); super(form);
this.be = be; 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 { static final class ArrayHandle extends ByteArrayViewVarHandle {

View file

@ -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. * 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
@ -67,7 +67,6 @@ public class CondyDescTest extends SymbolicDescTest {
private void testVarHandleDesc(DynamicConstantDesc<VarHandle> r, VarHandle vh) throws ReflectiveOperationException { private void testVarHandleDesc(DynamicConstantDesc<VarHandle> r, VarHandle vh) throws ReflectiveOperationException {
testSymbolicDesc(r); testSymbolicDesc(r);
assertEquals(r.resolveConstantDesc(LOOKUP), vh);
assertEquals(vh.describeConstable().orElseThrow(), r); assertEquals(vh.describeConstable().orElseThrow(), r);
} }

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -141,8 +141,6 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -143,8 +143,6 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -93,8 +93,6 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -93,8 +93,6 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -93,8 +93,6 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -93,8 +93,6 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -93,8 +93,6 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);

View file

@ -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. * 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
@ -93,8 +93,6 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
for (int j = 0; j < vhs1.length; j++) { for (int j = 0; j < vhs1.length; j++) {
if (i == j) { if (i == j) {
assertEquals(vhs1[i], vhs1[i]); assertEquals(vhs1[i], vhs1[i]);
assertEquals(vhs1[i], vhs2[i]);
assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
} }
else { else {
assertNotEquals(vhs1[i], vhs1[j]); assertNotEquals(vhs1[i], vhs1[j]);