From 7a02a2bc7c74bc3b5d1923aec7a14a052c0c0b39 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Fri, 13 Dec 2024 13:51:37 +0100 Subject: [PATCH] 8346195: Fix static initialization problem in GDIHashtable --- .../native/libawt/windows/GDIHashtable.cpp | 8 +++----- .../windows/native/libawt/windows/GDIHashtable.h | 15 +++++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/java.desktop/windows/native/libawt/windows/GDIHashtable.cpp b/src/java.desktop/windows/native/libawt/windows/GDIHashtable.cpp index 18b4ea9edc13f..5968607c16e81 100644 --- a/src/java.desktop/windows/native/libawt/windows/GDIHashtable.cpp +++ b/src/java.desktop/windows/native/libawt/windows/GDIHashtable.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, 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 @@ #include "GDIHashtable.h" #include "awt_GDIObject.h" -GDIHashtable::BatchDestructionManager GDIHashtable::manager; - /* * The order of monitor entrance is BatchDestructionManager->List->Hashtable. * GDIHashtable::put() and GDIHashtable::release() are designed to be called @@ -35,12 +33,12 @@ GDIHashtable::BatchDestructionManager GDIHashtable::manager; */ void* GDIHashtable::put(void* key, void* value) { - manager.decrementCounter(); + manager().decrementCounter(); return Hashtable::put(key, value); } void GDIHashtable::release(void* key) { - if (!manager.isBatchingEnabled()) { + if (!manager().isBatchingEnabled()) { void* value = remove(key); DASSERT(value != NULL); m_deleteProc(value); diff --git a/src/java.desktop/windows/native/libawt/windows/GDIHashtable.h b/src/java.desktop/windows/native/libawt/windows/GDIHashtable.h index fff4429ed52ae..d7195bedf9ee8 100644 --- a/src/java.desktop/windows/native/libawt/windows/GDIHashtable.h +++ b/src/java.desktop/windows/native/libawt/windows/GDIHashtable.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, 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 @@ -162,11 +162,11 @@ class GDIHashtable : public Hashtable { GDIHashtable(const char* name, void (*deleteProc)(void*) = NULL, int initialCapacity = 29, float loadFactor = 0.75) : Hashtable(name, deleteProc, initialCapacity, loadFactor) { - manager.add(this); + manager().add(this); } ~GDIHashtable() { - manager.remove(this); + manager().remove(this); } /** @@ -192,14 +192,17 @@ class GDIHashtable : public Hashtable { /** * Flushes all existing GDIHashtable instances. */ - INLINE static void flushAll() { manager.flushAll(); } + INLINE static void flushAll() { manager().flushAll(); } - INLINE CriticalSection& getManagerLock() { return manager.getLock(); } + INLINE CriticalSection& getManagerLock() { return manager().getLock(); } private: - static BatchDestructionManager manager; + static BatchDestructionManager& manager() { + static BatchDestructionManager manager; + return manager; + } }; #endif // GDIHASHTABLE_H