[nicl] RFR: Override hashCode and equals for BoundedPoitner

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu May 24 20:15:39 UTC 2018


Looks good

Maurizio


On 24/05/18 20:50, Henry Jen wrote:
> Hi,
>
> Please review following quick patch to properly compare Pointers base on the address they pointed to.
>
> Cheers,
> Henry
>   
> diff -r 565c7beca6d2 src/java.base/share/classes/jdk/internal/nicl/types/BoundedPointer.java
> --- a/src/java.base/share/classes/jdk/internal/nicl/types/BoundedPointer.java   Thu May 24 11:54:32 2018 -0700
> +++ b/src/java.base/share/classes/jdk/internal/nicl/types/BoundedPointer.java   Thu May 24 12:47:40 2018 -0700
> @@ -40,6 +40,28 @@
>           return addr == 0;
>       }
>
> +    @Override
> +    public int hashCode() {
> +        return Long.valueOf(effectiveAddress()).hashCode();
> +    }
> +
> +    @Override
> +    public boolean equals(Object o) {
> +        if (o == this) {
> +            return true;
> +        } else if (o instanceof BoundedPointer) {
> +            return ((BoundedPointer) o).effectiveAddress() == effectiveAddress();
> +        } else if (o instanceof Pointer) {
> +            try {
> +                return ((Pointer) o).addr() == effectiveAddress();
> +            } catch (IllegalAccessException iae) {
> +                throw new IllegalStateException();
> +            }
> +        } else {
> +            return false;
> +        }
> +    }
> +
>       protected final BoundedMemoryRegion region;
>       protected final long offset;
>



More information about the panama-dev mailing list