Copyright year, code style improvements

This commit is contained in:
Chen Liang 2026-01-26 12:27:16 -06:00
parent 45c554adfc
commit e33f01e020
8 changed files with 54 additions and 38 deletions

View File

@ -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

View File

@ -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

View File

@ -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<ConstantValue>(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<jint>(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<jint>(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
}

View File

@ -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<ConstantValue>* _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; }

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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));
}
}
}