8382338: Various serviceability agent tests fail on Linux x86_64 with LTO enabled

Reviewed-by: lucy, erikj
This commit is contained in:
Matthias Baesken 2026-06-24 10:28:22 +00:00
parent f1cd7f6ab9
commit 24a724f0fe
2 changed files with 10 additions and 1 deletions

View File

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

View File

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