diff --git a/src/hotspot/os_cpu/linux_arm/atomicAccess_linux_arm.hpp b/src/hotspot/os_cpu/linux_arm/atomicAccess_linux_arm.hpp index 390207f9e5e..c03f5ed1c8b 100644 --- a/src/hotspot/os_cpu/linux_arm/atomicAccess_linux_arm.hpp +++ b/src/hotspot/os_cpu/linux_arm/atomicAccess_linux_arm.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 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 @@ -26,8 +26,6 @@ #define OS_CPU_LINUX_ARM_ATOMICACCESS_LINUX_ARM_HPP #include "memory/allStatic.hpp" -#include "runtime/os.hpp" -#include "runtime/vm_version.hpp" // Implementation of class AtomicAccess diff --git a/src/hotspot/os_cpu/linux_arm/orderAccess_linux_arm.hpp b/src/hotspot/os_cpu/linux_arm/orderAccess_linux_arm.hpp index 3bb357704fb..49c6942b8e0 100644 --- a/src/hotspot/os_cpu/linux_arm/orderAccess_linux_arm.hpp +++ b/src/hotspot/os_cpu/linux_arm/orderAccess_linux_arm.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 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 @@ -27,7 +27,6 @@ // Included in orderAccess.hpp header file. -#include "runtime/os.hpp" #include "runtime/vm_version.hpp" // Implementation of class OrderAccess. diff --git a/src/hotspot/os_cpu/linux_s390/atomicAccess_linux_s390.hpp b/src/hotspot/os_cpu/linux_s390/atomicAccess_linux_s390.hpp index f3c1e8f1a2c..492ccf73bdf 100644 --- a/src/hotspot/os_cpu/linux_s390/atomicAccess_linux_s390.hpp +++ b/src/hotspot/os_cpu/linux_s390/atomicAccess_linux_s390.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2019 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -26,10 +26,6 @@ #ifndef OS_CPU_LINUX_S390_ATOMICACCESS_LINUX_S390_HPP #define OS_CPU_LINUX_S390_ATOMICACCESS_LINUX_S390_HPP -#include "runtime/atomicAccess.hpp" -#include "runtime/os.hpp" -#include "runtime/vm_version.hpp" - // Note that the compare-and-swap instructions on System z perform // a serialization function before the storage operand is fetched // and again after the operation is completed. diff --git a/src/hotspot/os_cpu/windows_aarch64/atomicAccess_windows_aarch64.hpp b/src/hotspot/os_cpu/windows_aarch64/atomicAccess_windows_aarch64.hpp index f8119654c50..9238043f7a4 100644 --- a/src/hotspot/os_cpu/windows_aarch64/atomicAccess_windows_aarch64.hpp +++ b/src/hotspot/os_cpu/windows_aarch64/atomicAccess_windows_aarch64.hpp @@ -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. * Copyright (c) 2020, Microsoft Corporation. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -27,9 +27,7 @@ #define OS_CPU_WINDOWS_AARCH64_ATOMICACCESS_WINDOWS_AARCH64_HPP #include -#include "runtime/os.hpp" -#include "runtime/vm_version.hpp" - +#include // As per atomicAccess.hpp all read-modify-write operations have to provide two-way // barriers semantics. The memory_order parameter is ignored - we always provide diff --git a/src/hotspot/os_cpu/windows_x86/atomicAccess_windows_x86.hpp b/src/hotspot/os_cpu/windows_x86/atomicAccess_windows_x86.hpp index aa78a401235..252411f62bc 100644 --- a/src/hotspot/os_cpu/windows_x86/atomicAccess_windows_x86.hpp +++ b/src/hotspot/os_cpu/windows_x86/atomicAccess_windows_x86.hpp @@ -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 @@ -26,7 +26,7 @@ #define OS_CPU_WINDOWS_X86_ATOMICACCESS_WINDOWS_X86_HPP #include -#include "runtime/os.hpp" +#include // Note that in MSVC, volatile memory accesses are explicitly // guaranteed to have acquire release semantics (w.r.t. compiler diff --git a/src/hotspot/share/interpreter/interpreterRuntime.cpp b/src/hotspot/share/interpreter/interpreterRuntime.cpp index e3cf5d589c2..59d5f29023c 100644 --- a/src/hotspot/share/interpreter/interpreterRuntime.cpp +++ b/src/hotspot/share/interpreter/interpreterRuntime.cpp @@ -55,7 +55,6 @@ #include "prims/jvmtiExport.hpp" #include "prims/methodHandles.hpp" #include "prims/nativeLookup.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/continuation.hpp" #include "runtime/deoptimization.hpp" #include "runtime/fieldDescriptor.inline.hpp" @@ -75,6 +74,7 @@ #include "utilities/checkedCast.hpp" #include "utilities/copy.hpp" #include "utilities/events.hpp" +#include "utilities/exceptions.hpp" #if INCLUDE_JFR #include "jfr/jfr.inline.hpp" #endif @@ -352,7 +352,7 @@ JRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* current vmClasses::StackOverflowError_klass(), CHECK); // Increment counter for hs_err file reporting - AtomicAccess::inc(&Exceptions::_stack_overflow_errors); + Exceptions::increment_stack_overflow_errors(); // Remove the ScopedValue bindings in case we got a StackOverflowError // while we were trying to manipulate ScopedValue bindings. current->clear_scopedValueBindings(); @@ -366,7 +366,7 @@ JRT_ENTRY(void, InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* java_lang_Throwable::set_message(exception(), Universe::delayed_stack_overflow_error_message()); // Increment counter for hs_err file reporting - AtomicAccess::inc(&Exceptions::_stack_overflow_errors); + Exceptions::increment_stack_overflow_errors(); // Remove the ScopedValue bindings in case we got a StackOverflowError // while we were trying to manipulate ScopedValue bindings. current->clear_scopedValueBindings(); diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index ae3835dd344..917ff5b4545 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -82,6 +82,7 @@ #include "utilities/copy.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" +#include "utilities/exceptions.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/hashTable.hpp" #include "utilities/macros.hpp" @@ -931,7 +932,7 @@ void SharedRuntime::throw_StackOverflowError_common(JavaThread* current, bool de // bindings. current->clear_scopedValueBindings(); // Increment counter for hs_err file reporting - AtomicAccess::inc(&Exceptions::_stack_overflow_errors); + Exceptions::increment_stack_overflow_errors(); throw_and_post_jvmti_exception(current, exception); } diff --git a/src/hotspot/share/utilities/exceptions.cpp b/src/hotspot/share/utilities/exceptions.cpp index b54474ea6d6..4455ab801cb 100644 --- a/src/hotspot/share/utilities/exceptions.cpp +++ b/src/hotspot/share/utilities/exceptions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -32,7 +32,6 @@ #include "memory/resourceArea.hpp" #include "memory/universe.hpp" #include "oops/oop.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/handles.inline.hpp" #include "runtime/init.hpp" #include "runtime/java.hpp" @@ -203,7 +202,7 @@ void Exceptions::_throw(JavaThread* thread, const char* file, int line, Handle h } if (h_exception->is_a(vmClasses::LinkageError_klass())) { - AtomicAccess::inc(&_linkage_errors, memory_order_relaxed); + _linkage_errors.add_then_fetch(1, memory_order_relaxed); } assert(h_exception->is_a(vmClasses::Throwable_klass()), "exception is not a subclass of java/lang/Throwable"); @@ -268,6 +267,10 @@ void Exceptions::_throw_cause(JavaThread* thread, const char* file, int line, Sy } +void Exceptions::increment_stack_overflow_errors() { + Exceptions::_stack_overflow_errors.add_then_fetch(1, memory_order_relaxed); +} + void Exceptions::throw_stack_overflow_exception(JavaThread* THREAD, const char* file, int line, const methodHandle& method) { Handle exception; if (!THREAD->has_pending_exception()) { @@ -279,7 +282,7 @@ void Exceptions::throw_stack_overflow_exception(JavaThread* THREAD, const char* java_lang_Throwable::fill_in_stack_trace(exception, method); } // Increment counter for hs_err file reporting - AtomicAccess::inc(&Exceptions::_stack_overflow_errors, memory_order_relaxed); + increment_stack_overflow_errors(); } else { // if prior exception, throw that one instead exception = Handle(THREAD, THREAD->pending_exception()); @@ -518,20 +521,20 @@ void Exceptions::wrap_dynamic_exception(bool is_indy, JavaThread* THREAD) { } // Exception counting for hs_err file -volatile int Exceptions::_stack_overflow_errors = 0; -volatile int Exceptions::_linkage_errors = 0; -volatile int Exceptions::_out_of_memory_error_java_heap_errors = 0; -volatile int Exceptions::_out_of_memory_error_metaspace_errors = 0; -volatile int Exceptions::_out_of_memory_error_class_metaspace_errors = 0; +Atomic Exceptions::_stack_overflow_errors{0}; +Atomic Exceptions::_linkage_errors{0}; +Atomic Exceptions::_out_of_memory_error_java_heap_errors{0}; +Atomic Exceptions::_out_of_memory_error_metaspace_errors{0}; +Atomic Exceptions::_out_of_memory_error_class_metaspace_errors{0}; void Exceptions::count_out_of_memory_exceptions(Handle exception) { if (Universe::is_out_of_memory_error_metaspace(exception())) { - AtomicAccess::inc(&_out_of_memory_error_metaspace_errors, memory_order_relaxed); + _out_of_memory_error_metaspace_errors.add_then_fetch(1, memory_order_relaxed); } else if (Universe::is_out_of_memory_error_class_metaspace(exception())) { - AtomicAccess::inc(&_out_of_memory_error_class_metaspace_errors, memory_order_relaxed); + _out_of_memory_error_class_metaspace_errors.add_then_fetch(1, memory_order_relaxed); } else { - // everything else reported as java heap OOM - AtomicAccess::inc(&_out_of_memory_error_java_heap_errors, memory_order_relaxed); + // everything else reported as java heap OOM + _out_of_memory_error_java_heap_errors.add_then_fetch(1, memory_order_relaxed); } } @@ -542,19 +545,24 @@ static void print_oom_count(outputStream* st, const char *err, int count) { } bool Exceptions::has_exception_counts() { - return (_stack_overflow_errors + _out_of_memory_error_java_heap_errors + - _out_of_memory_error_metaspace_errors + _out_of_memory_error_class_metaspace_errors) > 0; + return (_stack_overflow_errors.load_relaxed() + + _out_of_memory_error_java_heap_errors.load_relaxed() + + _out_of_memory_error_metaspace_errors.load_relaxed() + + _out_of_memory_error_class_metaspace_errors.load_relaxed()) > 0; } void Exceptions::print_exception_counts_on_error(outputStream* st) { - print_oom_count(st, "java_heap_errors", _out_of_memory_error_java_heap_errors); - print_oom_count(st, "metaspace_errors", _out_of_memory_error_metaspace_errors); - print_oom_count(st, "class_metaspace_errors", _out_of_memory_error_class_metaspace_errors); - if (_stack_overflow_errors > 0) { - st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors); + print_oom_count(st, "java_heap_errors", + _out_of_memory_error_java_heap_errors.load_relaxed()); + print_oom_count(st, "metaspace_errors", + _out_of_memory_error_metaspace_errors.load_relaxed()); + print_oom_count(st, "class_metaspace_errors", + _out_of_memory_error_class_metaspace_errors.load_relaxed()); + if (_stack_overflow_errors.load_relaxed() > 0) { + st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors.load_relaxed()); } - if (_linkage_errors > 0) { - st->print_cr("LinkageErrors=%d", _linkage_errors); + if (_linkage_errors.load_relaxed() > 0) { + st->print_cr("LinkageErrors=%d", _linkage_errors.load_relaxed()); } } diff --git a/src/hotspot/share/utilities/exceptions.hpp b/src/hotspot/share/utilities/exceptions.hpp index e76a0041d20..0299dedf2e6 100644 --- a/src/hotspot/share/utilities/exceptions.hpp +++ b/src/hotspot/share/utilities/exceptions.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -27,6 +27,7 @@ #include "memory/allocation.hpp" #include "oops/oopsHierarchy.hpp" +#include "runtime/atomic.hpp" #include "utilities/ostream.hpp" #include "utilities/sizes.hpp" @@ -113,12 +114,16 @@ class Exceptions { static bool special_exception(JavaThread* thread, const char* file, int line, Handle exception, Symbol* name = nullptr, const char* message = nullptr); // Count out of memory errors that are interesting in error diagnosis - static volatile int _out_of_memory_error_java_heap_errors; - static volatile int _out_of_memory_error_metaspace_errors; - static volatile int _out_of_memory_error_class_metaspace_errors; + static Atomic _out_of_memory_error_java_heap_errors; + static Atomic _out_of_memory_error_metaspace_errors; + static Atomic _out_of_memory_error_class_metaspace_errors; // Count linkage errors - static volatile int _linkage_errors; + static Atomic _linkage_errors; + + // Count stack overflow errors. + static Atomic _stack_overflow_errors; + public: // this enum is defined to indicate whether it is safe to // ignore the encoding scheme of the original message string. @@ -179,10 +184,9 @@ class Exceptions { static void wrap_dynamic_exception(bool is_indy, JavaThread* thread); - // Exception counting for error files of interesting exceptions that may have - // caused a problem for the jvm - static volatile int _stack_overflow_errors; - + // Exception counting of interesting exceptions that may have caused a + // problem for the JVM, for reporting in the hs_err file. + static void increment_stack_overflow_errors(); static bool has_exception_counts(); static void count_out_of_memory_exceptions(Handle exception); static void print_exception_counts_on_error(outputStream* st);