From e33f01e0207cc153c6c9668f9a87c694e32b3e59 Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Mon, 26 Jan 2026 12:27:16 -0600 Subject: [PATCH] Copyright year, code style improvements --- src/hotspot/share/ci/ciArray.cpp | 2 +- src/hotspot/share/ci/ciInstance.cpp | 2 +- src/hotspot/share/ci/ciObject.cpp | 40 ++++++++++--------- src/hotspot/share/ci/ciObject.hpp | 18 +++++---- src/hotspot/share/oops/oop.hpp | 2 +- src/hotspot/share/oops/oop.inline.hpp | 2 +- src/hotspot/share/opto/library_call.cpp | 2 +- .../object/IdentityHashCodeFold.java | 24 ++++++++--- 8 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/hotspot/share/ci/ciArray.cpp b/src/hotspot/share/ci/ciArray.cpp index d4e4a7aef0f..fd345949e09 100644 --- a/src/hotspot/share/ci/ciArray.cpp +++ b/src/hotspot/share/ci/ciArray.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2026, 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 diff --git a/src/hotspot/share/ci/ciInstance.cpp b/src/hotspot/share/ci/ciInstance.cpp index 56faf8a96f1..e245cadcbc2 100644 --- a/src/hotspot/share/ci/ciInstance.cpp +++ b/src/hotspot/share/ci/ciInstance.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2026, 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 diff --git a/src/hotspot/share/ci/ciObject.cpp b/src/hotspot/share/ci/ciObject.cpp index 1250762eb3c..c8e2c264ac5 100644 --- a/src/hotspot/share/ci/ciObject.cpp +++ b/src/hotspot/share/ci/ciObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2026, 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 @@ -172,11 +172,11 @@ jobject ciObject::constant_encoding() { // // Cache constant value lookups to ensure that consistent values are observed // during compilation because fields may be (re-)initialized concurrently. -ciConstant ciObject::check_constant_value_cache(int off, BasicType bt) { +ciConstant ciObject::check_constant_value_cache(int key, BasicType bt) { if (_constant_values != nullptr) { for (int i = 0; i < _constant_values->length(); ++i) { ConstantValue cached_val = _constant_values->at(i); - if (cached_val.off() == off) { + if (cached_val.key() == key) { assert(cached_val.value().basic_type() == bt, "unexpected type"); return cached_val.value(); } @@ -189,14 +189,14 @@ ciConstant ciObject::check_constant_value_cache(int off, BasicType bt) { // ciObject::add_to_constant_value_cache() // // Add a constant value to the cache. -void ciObject::add_to_constant_value_cache(int off, ciConstant val) { +void ciObject::add_to_constant_value_cache(int key, ciConstant val) { assert(val.is_valid(), "value must be valid"); - assert(!check_constant_value_cache(off, val.basic_type()).is_valid(), "duplicate"); + assert(!check_constant_value_cache(key, val.basic_type()).is_valid(), "duplicate"); if (_constant_values == nullptr) { Arena* arena = CURRENT_ENV->arena(); _constant_values = new (arena) GrowableArray(arena, 1, 0, ConstantValue()); } - _constant_values->append(ConstantValue(off, val)); + _constant_values->append(ConstantValue(key, val)); } // ------------------------------------------------------------------ @@ -230,19 +230,21 @@ bool ciObject::should_be_constant() { // The identity hash code of an object or an empty constant if a hash is not computed yet. // Observed value is cached, so it doesn't change during compilation. ciConstant ciObject::identity_hash() { - if (!is_null_object()) { - // Handle identity hash as if it were a field. - ciConstant value = check_constant_value_cache(IDENTITY_HASH_OFFSET, T_INT); - if (!value.is_valid()) { - VM_ENTRY_MARK; - jint identity_hash = checked_cast(get_oop()->fast_identity_hash_or_no_hash()); - value = ciConstant(T_INT, identity_hash); - // Cache observed state so it doesn't change during compilation. - add_to_constant_value_cache(IDENTITY_HASH_OFFSET, value); - } - if (value.as_int() != markWord::no_hash) { - return value; - } + if (is_null_object()) { + // Note: library_call already has a path for System.identityHashCode(null) + return ciConstant(T_INT, 0); + } + // Handle identity hash as if it were a field value. + ciConstant value = check_constant_value_cache(identityHashKey, T_INT); + if (!value.is_valid()) { + VM_ENTRY_MARK; + jint identity_hash = checked_cast(get_oop()->fast_identity_hash_or_no_hash()); + value = ciConstant(T_INT, identity_hash); + // Cache observed state so it doesn't change during compilation. + add_to_constant_value_cache(identityHashKey, value); + } + if (value.as_int() != markWord::no_hash) { + return value; } return ciConstant(); // no hash computed } diff --git a/src/hotspot/share/ci/ciObject.hpp b/src/hotspot/share/ci/ciObject.hpp index 6ce574f00ef..55499df811e 100644 --- a/src/hotspot/share/ci/ciObject.hpp +++ b/src/hotspot/share/ci/ciObject.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2026, 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 @@ -63,17 +63,18 @@ private: class ConstantValue { private: ciConstant _value; - int _off; + int _key; public: - ConstantValue() : _value(ciConstant()), _off(0) { } - ConstantValue(int off, ciConstant value) : _value(value), _off(off) { } + ConstantValue() : _value(ciConstant()), _key(0) { } + ConstantValue(int key, ciConstant value) : _value(value), _key(key) { } - int off() const { return _off; } + int key() const { return _key; } ciConstant value() const { return _value; } }; - const int IDENTITY_HASH_OFFSET = -1; + // The reserved key for identity hash code + static constexpr int identityHashKey = -1; GrowableArray* _constant_values = nullptr; protected: @@ -114,8 +115,9 @@ public: jobject constant_encoding(); // Access to the constant value cache - ciConstant check_constant_value_cache(int off, BasicType bt); - void add_to_constant_value_cache(int off, ciConstant val); + // Key must be nonnegative. Negative keys are reserved. + ciConstant check_constant_value_cache(int key, BasicType bt); + void add_to_constant_value_cache(int key, ciConstant val); virtual bool is_object() const { return true; } diff --git a/src/hotspot/share/oops/oop.hpp b/src/hotspot/share/oops/oop.hpp index c60520a0961..54835cdd92e 100644 --- a/src/hotspot/share/oops/oop.hpp +++ b/src/hotspot/share/oops/oop.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 diff --git a/src/hotspot/share/oops/oop.inline.hpp b/src/hotspot/share/oops/oop.inline.hpp index 3977b35055d..6fb236408ca 100644 --- a/src/hotspot/share/oops/oop.inline.hpp +++ b/src/hotspot/share/oops/oop.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 diff --git a/src/hotspot/share/opto/library_call.cpp b/src/hotspot/share/opto/library_call.cpp index 0d6692ac7ae..91a7ff2a3b8 100644 --- a/src/hotspot/share/opto/library_call.cpp +++ b/src/hotspot/share/opto/library_call.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2026, 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 diff --git a/test/hotspot/jtreg/compiler/intrinsics/object/IdentityHashCodeFold.java b/test/hotspot/jtreg/compiler/intrinsics/object/IdentityHashCodeFold.java index d2f11ff7a2c..2a47717be38 100644 --- a/test/hotspot/jtreg/compiler/intrinsics/object/IdentityHashCodeFold.java +++ b/test/hotspot/jtreg/compiler/intrinsics/object/IdentityHashCodeFold.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026, 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 @@ -43,13 +43,13 @@ public class IdentityHashCodeFold { TestFramework.run(); } - static final Object a = new Object(), b = new Object(); + static final Object a = new Object(), b = new Object(), NULL = null; - static final int expectedResult; + static final int expectedSum; static { // This code runs in the interpreter - expectedResult = System.identityHashCode(a) + System.identityHashCode(b); + expectedSum = System.identityHashCode(a) + System.identityHashCode(b); } @Test @@ -60,9 +60,21 @@ public class IdentityHashCodeFold { @Check(test = "testSum") public void checkSum(int sum) { - if (sum != expectedResult) { - throw new IllegalStateException("Unexpected hash sum, expected %X actual %X".formatted(expectedResult, sum)); + if (sum != expectedSum) { + throw new IllegalStateException("Unexpected hash sum, expected %X actual %X".formatted(expectedSum, sum)); } } + @Test + @IR(failOn = {IRNode.ADD_I}) + public int testNullSum() { + return 42 + System.identityHashCode(NULL); + } + + @Check(test = "testNullSum") + public void checkNullSum(int sum) { + if (sum != 42) { + throw new IllegalStateException("Unexpected null hash sum, expected %X actual %X".formatted(42, sum)); + } + } }