Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State based hashcode for value types #15529

Closed
hangshao0 opened this issue Jul 12, 2022 · 6 comments
Closed

State based hashcode for value types #15529

hangshao0 opened this issue Jul 12, 2022 · 6 comments
Labels
comp:vm project:valhalla Used to track Project Valhalla related work

Comments

@hangshao0
Copy link
Contributor

hangshao0 commented Jul 12, 2022

The hash code of a value type should be based on its state rather than the identity (address).
Currently OpenJ9 still calculates the hash code of value types using its address rather than its value.

@hangshao0 hangshao0 added comp:vm project:valhalla Used to track Project Valhalla related work labels Jul 12, 2022
@hangshao0
Copy link
Contributor Author

This is related to #15497.

JCL has a private helper in class PrimitiveObjectMethods that calculates the VT hash code:
private static int primitiveObjectHashCode(Object o)

@hangshao0
Copy link
Contributor Author

@ehrenjulzert will be look at this.

@hangshao0
Copy link
Contributor Author

Doing call-in inside existing native method convertValueToHash() is not an option, see the discussions here: #15741.

@ehrenjulzert
Copy link

As we discussed in #15880, implementing hashcodes for value types natively will be difficult and require changes to the GC. It also may not be worth it to sink too too much time into the native implementation since the spec may change in the future to remove the need to hash value types at all. For this reason I've decided to instead make a temporary implementation purely in Java which just calls the primitiveObjectHashCode helper function.

ehrenjulzert pushed a commit to ehrenjulzert/openj9 that referenced this issue Sep 22, 2022
- Add valueHashCode function to J9VMInternals.java and call
  it from Object.java
- Create new native helper function positiveOnlyHashcodes
  to check if hashcodes are all positive
- Change DDR's hashcode command to display an error when
  trying to get the hashcode of a valuetype

for eclipse-openj9#15529

Signed-off-by: Ehren Julien-Neitzert <[email protected]>
ehrenjulzert pushed a commit to ehrenjulzert/openj9 that referenced this issue Oct 27, 2022
- Add valueHashCode function to J9VMInternals.java and call
  it from Object.java
- Create new native helper function positiveOnlyHashcodes
  to check if hashcodes are all positive
- Change DDR's hashcode command to display an error when
  trying to get the hashcode of a valuetype
- Update java_lang_invoke_MethodHandleNatives.cpp to
  ensure that the MN_FLATTENED flag is set correctly

for eclipse-openj9#15529

Signed-off-by: Ehren Julien-Neitzert <[email protected]>
ehrenjulzert pushed a commit to ehrenjulzert/openj9 that referenced this issue Nov 7, 2022
Tests code added in PR eclipse-openj9#15922
Part of solution of issue eclipse-openj9#15529

Signed-off-by: Ehren Julien-Neitzert <[email protected]>
@hangshao0
Copy link
Contributor Author

This can be closed.

Copy link

github-actions bot commented Oct 3, 2024

Issue Number: 15529
Status: Closed
Actual Components: comp:vm, project:valhalla
Actual Assignees: No one :(
PR Assignees: ehrenjulzert, ehrenjulzert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:vm project:valhalla Used to track Project Valhalla related work
Projects
None yet
Development

No branches or pull requests

2 participants