Skip to content

Commit

Permalink
8321279: Implement hashCode() in Heap-X-Buffer.java.template
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, bpb
  • Loading branch information
Sergey Tsypanov authored and Alan Bateman committed Dec 13, 2023
1 parent 3d9d353 commit 8a0a6f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -29,6 +29,7 @@ package java.nio;

import java.lang.foreign.MemorySegment;
import java.util.Objects;
import jdk.internal.util.ArraysSupport;

/**
#if[rw]
Expand Down Expand Up @@ -705,6 +706,9 @@ class Heap$Type$Buffer$RW$
addr, segment)));
}

public int hashCode() {
return ArraysSupport.vectorizedHashCode(hb, ix(position()), remaining(), 1, ArraysSupport.T_BYTE);
}

#end[byte]

Expand Down Expand Up @@ -733,6 +737,9 @@ class Heap$Type$Buffer$RW$
offset, segment);
}

public int hashCode() {
return ArraysSupport.vectorizedHashCode(hb, ix(position()), remaining(), 1, ArraysSupport.T_CHAR);
}
#end[char]


Expand Down
7 changes: 6 additions & 1 deletion test/micro/org/openjdk/bench/java/nio/ByteBuffers.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, 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
Expand Down Expand Up @@ -923,4 +923,9 @@ public double testDirectLoopGetDouble() {
}
return r;
}

@Benchmark
public int testHeapHashCode() {
return heapByteBuffer.hashCode();
}
}

1 comment on commit 8a0a6f8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.