diff --git a/make/hotspot/lib/JvmFeatures.gmk b/make/hotspot/lib/JvmFeatures.gmk index 9477b0925d2..7dc5fd676a1 100644 --- a/make/hotspot/lib/JvmFeatures.gmk +++ b/make/hotspot/lib/JvmFeatures.gmk @@ -173,6 +173,10 @@ ifeq ($(call check-jvm-feature, link-time-opt), true) ifneq ($(call isCompiler, microsoft), true) JVM_LDFLAGS_FEATURES += $(CXX_O_FLAG_HIGHEST_JVM) endif + # avoid elimination of Metadata vtable when using LTO (important for serviceability agent) + ifeq ($(call isCompiler, gcc), true) + JVM_LDFLAGS_FEATURES += -Wl,--undefined=_ZTV8Metadata + endif else JVM_LTO := false ifeq ($(call isCompiler, gcc), true) diff --git a/src/hotspot/share/oops/metadata.hpp b/src/hotspot/share/oops/metadata.hpp index d88bd9d087d..bd3f17fa3f4 100644 --- a/src/hotspot/share/oops/metadata.hpp +++ b/src/hotspot/share/oops/metadata.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -35,6 +35,11 @@ class Metadata : public MetaspaceObj { NOT_PRODUCT(int _valid;) public: NOT_PRODUCT(Metadata() : _valid(0) {}) + + // We have to keep the vtable alive under LTGC dead-section removal/LTO + // for serviceability tests to work. + // This can be done by linker settings or modifications to the Metadata class. + NOT_PRODUCT(bool is_valid() const { return _valid == 0; }) int identity_hash() { return (int)(uintptr_t)this; }