From 6514d380d1de1368b7db091e592bdc3e076277f4 Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier Date: Wed, 8 Jan 2025 07:05:21 +0000 Subject: [PATCH] 8327460: Compile tests with the same visibility rules as product code Reviewed-by: mbaesken Backport-of: cc9a8aba67f4e240c8de2d1ae15d1b80bfa446a0 --- make/common/TestFilesCompilation.gmk | 24 +++++++++---- make/test/JtregNativeJdk.gmk | 17 +-------- .../macosx/native/applauncher/MacLauncher.cpp | 11 +++--- .../shenandoah/compiler/libLinkToNativeRBP.c | 6 +--- .../runtime/ErrorHandling/TestDwarf.java | 2 +- .../ErrorHandling/libTestDwarfHelper.h | 8 +++-- .../jdk/java/foreign/CallGeneratorHelper.java | 14 ++------ .../foreign/arraystructs/libArrayStructs.c | 8 ++--- .../capturecallstate/libCaptureCallState.c | 8 ++--- .../java/foreign/dontrelease/libDontRelease.c | 8 ++--- test/jdk/java/foreign/libAddressDereference.c | 8 ++--- test/jdk/java/foreign/libIntrinsics.c | 10 ++---- test/jdk/java/foreign/libLibraryLookup.c | 8 ++--- test/jdk/java/foreign/libLookupTest.c | 13 +++---- test/jdk/java/foreign/libNull.c | 10 ++---- test/jdk/java/foreign/libSafeAccess.c | 8 ++--- .../jdk/java/foreign/libTestUpcallHighArity.c | 8 ++--- .../java/foreign/libTestUpcallStructScope.c | 8 ++--- .../java/foreign/loaderLookup/lookup/libFoo.c | 8 ++--- test/jdk/java/foreign/nested/libNested.c | 8 ++--- .../jdk/java/foreign/normalize/libNormalize.c | 8 ++--- .../passheapsegment/libPassHeapSegment.c | 8 ++--- test/jdk/java/foreign/shared.h | 10 ++---- .../foreign/stackwalk/libAsyncStackWalk.cpp | 7 +--- .../foreign/stackwalk/libReentrantUpcalls.c | 8 ++--- .../jdk/java/foreign/stackwalk/libStackWalk.c | 8 ++--- test/jdk/java/foreign/trivial/libTrivial.c | 8 ++--- .../java/foreign/upcalldeopt/libUpcallDeopt.c | 8 ++--- test/jdk/java/foreign/virtual/libVirtual.c | 8 ++--- .../AttachCurrentThread/libImplicitAttach.c | 9 +++-- test/jdk/tools/launcher/exeJliLaunchTest.c | 5 +-- test/lib/native/export.h | 35 +++++++++++++++++++ .../bench/java/lang/foreign/libCallOverhead.c | 8 ++--- .../openjdk/bench/java/lang/foreign/libPtr.c | 10 ++---- .../bench/java/lang/foreign/libQSort.c | 9 ++--- .../bench/java/lang/foreign/libUpcalls.c | 8 ++--- .../lang/foreign/points/support/libPoint.c | 12 +++---- 37 files changed, 140 insertions(+), 224 deletions(-) create mode 100644 test/lib/native/export.h diff --git a/make/common/TestFilesCompilation.gmk b/make/common/TestFilesCompilation.gmk index 7075931d77c..9a70c7386c4 100644 --- a/make/common/TestFilesCompilation.gmk +++ b/make/common/TestFilesCompilation.gmk @@ -56,22 +56,34 @@ define SetupTestFilesCompilationBody $$(error There are duplicate test file names for $1: $$($1_DUPLICATED_NAMES)) endif + # Always include common test functionality + TEST_CFLAGS := -I$(TOPDIR)/test/lib/native + + ifeq ($(TOOLCHAIN_TYPE), gcc) + TEST_CFLAGS += -fvisibility=hidden + TEST_LDFLAGS += -Wl,--exclude-libs,ALL + else ifeq ($(TOOLCHAIN_TYPE), clang) + TEST_CFLAGS += -fvisibility=hidden + else ifeq ($(TOOLCHAIN_TYPE), xlc) + TEST_CFLAGS += -qvisibility=hidden + endif + # The list to depend on starts out empty $1 := ifeq ($$($1_TYPE), LIBRARY) $1_PREFIX = lib $1_OUTPUT_SUBDIR := lib - $1_BASE_CFLAGS := $(CFLAGS_JDKLIB) - $1_BASE_CXXFLAGS := $(CXXFLAGS_JDKLIB) - $1_LDFLAGS := $(LDFLAGS_JDKLIB) $$(call SET_SHARED_LIBRARY_ORIGIN) + $1_BASE_CFLAGS := $(CFLAGS_JDKLIB) $$(TEST_CFLAGS) + $1_BASE_CXXFLAGS := $(CXXFLAGS_JDKLIB) $$(TEST_CFLAGS) + $1_LDFLAGS := $(LDFLAGS_JDKLIB) $$(TEST_LDFLAGS) $$(call SET_SHARED_LIBRARY_ORIGIN) $1_COMPILATION_TYPE := LIBRARY $1_LOG_TYPE := library else ifeq ($$($1_TYPE), PROGRAM) $1_PREFIX = exe $1_OUTPUT_SUBDIR := bin - $1_BASE_CFLAGS := $(CFLAGS_JDKEXE) - $1_BASE_CXXFLAGS := $(CXXFLAGS_JDKEXE) - $1_LDFLAGS := $(LDFLAGS_JDKEXE) $(LDFLAGS_TESTEXE) + $1_BASE_CFLAGS := $(CFLAGS_JDKEXE) $$(TEST_CFLAGS) + $1_BASE_CXXFLAGS := $(CXXFLAGS_JDKEXE) $$(TEST_CFLAGS) + $1_LDFLAGS := $(LDFLAGS_JDKEXE) $$(TEST_LDFLAGS) $(LDFLAGS_TESTEXE) $1_COMPILATION_TYPE := EXECUTABLE $1_LOG_TYPE := executable else diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk index 94c8810bba9..e9260c8bac7 100644 --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2015, 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 @@ -53,8 +53,6 @@ BUILD_JDK_JTREG_EXECUTABLES_CFLAGS_exeJliLaunchTest := \ -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \ -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli -TEST_LIB_NATIVE_SRC := $(TOPDIR)/test/lib/native - # Platform specific setup ifeq ($(call isTargetOs, windows), true) BUILD_JDK_JTREG_EXCLUDE += libDirectIO.c libInheritedChannel.c \ @@ -69,14 +67,6 @@ ifeq ($(call isTargetOs, windows), true) BUILD_JDK_JTREG_EXECUTABLES_LIBS_exeNullCallerTest := $(LIBCXX) jvm.lib BUILD_JDK_JTREG_EXECUTABLES_LIBS_exerevokeall := advapi32.lib BUILD_JDK_JTREG_EXECUTABLES_CFLAGS_exeNullCallerTest := /EHsc - - # java.lang.foreign tests - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libAsyncStackWalk := -I$(TEST_LIB_NATIVE_SRC) - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libLinkerInvokerUnnamed := -I$(TEST_LIB_NATIVE_SRC) - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libLinkerInvokerModule := -I$(TEST_LIB_NATIVE_SRC) - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libLoaderLookupInvoker := -I$(TEST_LIB_NATIVE_SRC) - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libAsyncInvokers := -I$(TEST_LIB_NATIVE_SRC) - BUILD_JDK_JTREG_LIBRARIES_LIBS_libTracePinnedThreads := jvm.lib BUILD_JDK_JTREG_LIBRARIES_LIBS_libNewDirectByteBuffer := $(WIN_LIB_JAVA) BUILD_JDK_JTREG_LIBRARIES_LIBS_libGetXSpace := $(WIN_LIB_JAVA) @@ -88,15 +78,10 @@ else BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libNativeThread := -pthread # java.lang.foreign tests - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libAsyncStackWalk := -I$(TEST_LIB_NATIVE_SRC) BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libAsyncStackWalk := -pthread - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libAsyncInvokers := -I$(TEST_LIB_NATIVE_SRC) BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libAsyncInvokers := -pthread - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libLinkerInvokerUnnamed := -I$(TEST_LIB_NATIVE_SRC) BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libLinkerInvokerUnnamed := -pthread - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libLinkerInvokerModule := -I$(TEST_LIB_NATIVE_SRC) BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libLinkerInvokerModule := -pthread - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libLoaderLookupInvoker := -I$(TEST_LIB_NATIVE_SRC) BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libLoaderLookupInvoker := -pthread BUILD_JDK_JTREG_LIBRARIES_LIBS_libExplicitAttach := -ljvm diff --git a/src/jdk.jpackage/macosx/native/applauncher/MacLauncher.cpp b/src/jdk.jpackage/macosx/native/applauncher/MacLauncher.cpp index 1d315b9f02e..5c9ca8e9a04 100644 --- a/src/jdk.jpackage/macosx/native/applauncher/MacLauncher.cpp +++ b/src/jdk.jpackage/macosx/native/applauncher/MacLauncher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -23,13 +23,14 @@ * questions. */ -#include "AppLauncher.h" #include "app.h" +#include "AppLauncher.h" +#include "ErrorHandling.h" #include "FileUtils.h" +#include "jni.h" +#include "JvmLauncher.h" #include "PackageFile.h" #include "UnixSysInfo.h" -#include "JvmLauncher.h" -#include "ErrorHandling.h" namespace { @@ -89,7 +90,7 @@ void initJvmLauncher() { } // namespace -int main(int argc, char *argv[]) { +JNIEXPORT int main(int argc, char *argv[]) { if (jvmLauncher) { // This is the call from the thread spawned by JVM. // Skip initialization phase as we have done this already in the first diff --git a/test/hotspot/jtreg/gc/shenandoah/compiler/libLinkToNativeRBP.c b/test/hotspot/jtreg/gc/shenandoah/compiler/libLinkToNativeRBP.c index e57a86caa60..0f54c4c2402 100644 --- a/test/hotspot/jtreg/gc/shenandoah/compiler/libLinkToNativeRBP.c +++ b/test/hotspot/jtreg/gc/shenandoah/compiler/libLinkToNativeRBP.c @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT int foo() { return 0; diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java b/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java index 2ae46a36229..8c0c23e2a8b 100644 --- a/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java +++ b/test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java @@ -125,7 +125,7 @@ private static void test() throws Exception { new DwarfConstraint(1, "Java_TestDwarf_crashNativeMultipleMethods", "libTestDwarf.c", 70)); } runAndCheck(new Flags(TestDwarf.class.getCanonicalName(), "nativeDereferenceNull"), - new DwarfConstraint(0, "dereference_null", "libTestDwarfHelper.h", 44)); + new DwarfConstraint(0, "dereference_null", "libTestDwarfHelper.h", 46)); } // The full pattern accepts lines like: diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h b/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h index 3a162560b89..1da05c1c3d3 100644 --- a/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h +++ b/test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -21,9 +21,11 @@ * questions. */ -#include "jni.h" #include +#include "export.h" +#include "jni.h" + void unused1() { } @@ -39,7 +41,7 @@ void unused4() { void unused5() { } -void dereference_null() { +EXPORT void dereference_null() { int* x = (int*)0; *x = 34; // Crash } diff --git a/test/jdk/java/foreign/CallGeneratorHelper.java b/test/jdk/java/foreign/CallGeneratorHelper.java index ee3930a56e7..132a89b75f1 100644 --- a/test/jdk/java/foreign/CallGeneratorHelper.java +++ b/test/jdk/java/foreign/CallGeneratorHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -213,11 +213,7 @@ public static void main(String[] args) { static void generateDowncalls(boolean header) { if (header) { System.out.println( - "#ifdef _WIN64\n" + - "#define EXPORT __declspec(dllexport)\n" + - "#else\n" + - "#define EXPORT\n" + - "#endif\n" + "#include \"export.h\"\n" ); for (int j = 1; j <= MAX_FIELDS; j++) { @@ -267,11 +263,7 @@ static void generateDowncallFunction(String fName, Ret ret, List para static void generateUpcalls(boolean header) { if (header) { System.out.println( - "#ifdef _WIN64\n" + - "#define EXPORT __declspec(dllexport)\n" + - "#else\n" + - "#define EXPORT\n" + - "#endif\n" + "#include \"export.h\"\n" ); for (int j = 1; j <= MAX_FIELDS; j++) { diff --git a/test/jdk/java/foreign/arraystructs/libArrayStructs.c b/test/jdk/java/foreign/arraystructs/libArrayStructs.c index 28ab57093f5..7adf79551ec 100644 --- a/test/jdk/java/foreign/arraystructs/libArrayStructs.c +++ b/test/jdk/java/foreign/arraystructs/libArrayStructs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" struct S1 { char f0[1]; }; struct S2 { char f0[2]; }; diff --git a/test/jdk/java/foreign/capturecallstate/libCaptureCallState.c b/test/jdk/java/foreign/capturecallstate/libCaptureCallState.c index 9a8925474a2..d76c9d7beda 100644 --- a/test/jdk/java/foreign/capturecallstate/libCaptureCallState.c +++ b/test/jdk/java/foreign/capturecallstate/libCaptureCallState.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -23,11 +23,7 @@ #include -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void set_errno_V(int value) { errno = value; diff --git a/test/jdk/java/foreign/dontrelease/libDontRelease.c b/test/jdk/java/foreign/dontrelease/libDontRelease.c index c7a8f743083..bcaeb6aaa70 100644 --- a/test/jdk/java/foreign/dontrelease/libDontRelease.c +++ b/test/jdk/java/foreign/dontrelease/libDontRelease.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -21,10 +21,6 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void test_ptr(void* ptr) {} diff --git a/test/jdk/java/foreign/libAddressDereference.c b/test/jdk/java/foreign/libAddressDereference.c index b78b3d02f3e..d18d60e624e 100644 --- a/test/jdk/java/foreign/libAddressDereference.c +++ b/test/jdk/java/foreign/libAddressDereference.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -22,11 +22,7 @@ * */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void* get_addr(void* align) { return align; diff --git a/test/jdk/java/foreign/libIntrinsics.c b/test/jdk/java/foreign/libIntrinsics.c index 89d0a09c7b6..b52d2756fba 100644 --- a/test/jdk/java/foreign/libIntrinsics.c +++ b/test/jdk/java/foreign/libIntrinsics.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -24,11 +24,7 @@ #include -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void empty() { } @@ -85,4 +81,4 @@ EXPORT short invoke_high_arity5(int x, double d, long long l, float f, char c, s } EXPORT short invoke_high_arity6(int x, double d, long long l, float f, char c, short s1, short s2) { return s2; -} \ No newline at end of file +} diff --git a/test/jdk/java/foreign/libLibraryLookup.c b/test/jdk/java/foreign/libLibraryLookup.c index 4d3e9304ca3..a5375da3026 100644 --- a/test/jdk/java/foreign/libLibraryLookup.c +++ b/test/jdk/java/foreign/libLibraryLookup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -22,11 +22,7 @@ * */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" int count = 0; diff --git a/test/jdk/java/foreign/libLookupTest.c b/test/jdk/java/foreign/libLookupTest.c index 7aa6ca36031..5ad75a885dd 100644 --- a/test/jdk/java/foreign/libLookupTest.c +++ b/test/jdk/java/foreign/libLookupTest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -22,12 +22,7 @@ * */ - #ifdef _WIN64 - #define EXPORT __declspec(dllexport) - #else - #define EXPORT - #endif - - EXPORT void f() { } - EXPORT int c = 42; +#include "export.h" +EXPORT void f() { } +EXPORT int c = 42; diff --git a/test/jdk/java/foreign/libNull.c b/test/jdk/java/foreign/libNull.c index 52ea8493f21..a93c8d776f1 100644 --- a/test/jdk/java/foreign/libNull.c +++ b/test/jdk/java/foreign/libNull.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -21,12 +21,8 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif - #include +#include "export.h" + EXPORT void* get_null() { return NULL; } diff --git a/test/jdk/java/foreign/libSafeAccess.c b/test/jdk/java/foreign/libSafeAccess.c index 3a640329aa1..6202ded299a 100644 --- a/test/jdk/java/foreign/libSafeAccess.c +++ b/test/jdk/java/foreign/libSafeAccess.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -22,11 +22,7 @@ * */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" struct Point { int x; diff --git a/test/jdk/java/foreign/libTestUpcallHighArity.c b/test/jdk/java/foreign/libTestUpcallHighArity.c index 052bd2ce168..cd6b6de4e32 100644 --- a/test/jdk/java/foreign/libTestUpcallHighArity.c +++ b/test/jdk/java/foreign/libTestUpcallHighArity.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" struct S_PDI { void* p0; double p1; int p2; }; diff --git a/test/jdk/java/foreign/libTestUpcallStructScope.c b/test/jdk/java/foreign/libTestUpcallStructScope.c index e27ab0092cc..e778133b496 100644 --- a/test/jdk/java/foreign/libTestUpcallStructScope.c +++ b/test/jdk/java/foreign/libTestUpcallStructScope.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" struct S_PDI { void* p0; double p1; int p2; }; diff --git a/test/jdk/java/foreign/loaderLookup/lookup/libFoo.c b/test/jdk/java/foreign/loaderLookup/lookup/libFoo.c index 68525215b93..d9f07bcfd3a 100644 --- a/test/jdk/java/foreign/loaderLookup/lookup/libFoo.c +++ b/test/jdk/java/foreign/loaderLookup/lookup/libFoo.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -23,11 +23,7 @@ #include -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void foo(void) { // do nothing diff --git a/test/jdk/java/foreign/nested/libNested.c b/test/jdk/java/foreign/nested/libNested.c index a1414d6ed61..28c9724fdc0 100644 --- a/test/jdk/java/foreign/nested/libNested.c +++ b/test/jdk/java/foreign/nested/libNested.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" struct S1{ double f0; long long f1; double f2; int f3; }; union U1{ short f0; long long f1; short f2; char f3[4][3]; }; diff --git a/test/jdk/java/foreign/normalize/libNormalize.c b/test/jdk/java/foreign/normalize/libNormalize.c index 4a21551278f..68c352d8e86 100644 --- a/test/jdk/java/foreign/normalize/libNormalize.c +++ b/test/jdk/java/foreign/normalize/libNormalize.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" // we use 'int' here to make sure the native code doesn't touch any of the bits // the important part is that our Java code performs argument normalization diff --git a/test/jdk/java/foreign/passheapsegment/libPassHeapSegment.c b/test/jdk/java/foreign/passheapsegment/libPassHeapSegment.c index fdb1981ac65..850c2db8be9 100644 --- a/test/jdk/java/foreign/passheapsegment/libPassHeapSegment.c +++ b/test/jdk/java/foreign/passheapsegment/libPassHeapSegment.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void test_args(void* ptr) {} diff --git a/test/jdk/java/foreign/shared.h b/test/jdk/java/foreign/shared.h index 1cadc1075d6..fda94b92a2e 100644 --- a/test/jdk/java/foreign/shared.h +++ b/test/jdk/java/foreign/shared.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -21,6 +21,8 @@ * questions. */ +#include "export.h" + #ifdef __clang__ #pragma clang optimize off #elif defined __GNUC__ @@ -29,12 +31,6 @@ #pragma optimize( "", off ) #endif -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif - struct S_I { int p0; }; struct S_F { float p0; }; struct S_D { double p0; }; diff --git a/test/jdk/java/foreign/stackwalk/libAsyncStackWalk.cpp b/test/jdk/java/foreign/stackwalk/libAsyncStackWalk.cpp index a4ad799c1e4..e94c58bace4 100644 --- a/test/jdk/java/foreign/stackwalk/libAsyncStackWalk.cpp +++ b/test/jdk/java/foreign/stackwalk/libAsyncStackWalk.cpp @@ -22,14 +22,9 @@ * */ +#include "export.h" #include "testlib_threads.h" -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif - typedef void (*CB_t)(void); static void start(void* ctxt) { diff --git a/test/jdk/java/foreign/stackwalk/libReentrantUpcalls.c b/test/jdk/java/foreign/stackwalk/libReentrantUpcalls.c index 77a961c0fba..a7f33cec19c 100644 --- a/test/jdk/java/foreign/stackwalk/libReentrantUpcalls.c +++ b/test/jdk/java/foreign/stackwalk/libReentrantUpcalls.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -22,11 +22,7 @@ * */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void do_recurse(int depth, void (*cb)(int, void*)) { cb(depth, cb); diff --git a/test/jdk/java/foreign/stackwalk/libStackWalk.c b/test/jdk/java/foreign/stackwalk/libStackWalk.c index 4d36dbf5365..fa72254088b 100644 --- a/test/jdk/java/foreign/stackwalk/libStackWalk.c +++ b/test/jdk/java/foreign/stackwalk/libStackWalk.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -22,11 +22,7 @@ * */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void foo(void (*cb)(void)) { cb(); diff --git a/test/jdk/java/foreign/trivial/libTrivial.c b/test/jdk/java/foreign/trivial/libTrivial.c index bc3159f417f..7dc5e1303f2 100644 --- a/test/jdk/java/foreign/trivial/libTrivial.c +++ b/test/jdk/java/foreign/trivial/libTrivial.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -23,11 +23,7 @@ #include -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void empty() {} diff --git a/test/jdk/java/foreign/upcalldeopt/libUpcallDeopt.c b/test/jdk/java/foreign/upcalldeopt/libUpcallDeopt.c index ae2a8dc0173..c51dbc937ac 100644 --- a/test/jdk/java/foreign/upcalldeopt/libUpcallDeopt.c +++ b/test/jdk/java/foreign/upcalldeopt/libUpcallDeopt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void foo(void (*cb)(int, int, int, int), int a0, int a1, int a2, int a3) { cb(a0, a1, a2, a3); diff --git a/test/jdk/java/foreign/virtual/libVirtual.c b/test/jdk/java/foreign/virtual/libVirtual.c index 86c4c737a94..7f7961da408 100644 --- a/test/jdk/java/foreign/virtual/libVirtual.c +++ b/test/jdk/java/foreign/virtual/libVirtual.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -22,11 +22,7 @@ * */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT int funcA() { return 1; diff --git a/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libImplicitAttach.c b/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libImplicitAttach.c index a3dcb6ac050..ade58ccb7c0 100644 --- a/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libImplicitAttach.c +++ b/test/jdk/java/lang/Thread/jni/AttachCurrentThread/libImplicitAttach.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -20,15 +20,18 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -#include + #include +#include + +#include "export.h" #define STACK_SIZE 0x100000 /** * Creates n threads to execute the given function. */ -void start_threads(int n, void *(*f)(void *)) { +EXPORT void start_threads(int n, void *(*f)(void *)) { pthread_t tid; pthread_attr_t attr; int i; diff --git a/test/jdk/tools/launcher/exeJliLaunchTest.c b/test/jdk/tools/launcher/exeJliLaunchTest.c index ba348de6a97..6220a2f4b3b 100644 --- a/test/jdk/tools/launcher/exeJliLaunchTest.c +++ b/test/jdk/tools/launcher/exeJliLaunchTest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 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 @@ -30,9 +30,10 @@ * tools. The rest of the files will be linked in. */ +#include "export.h" #include "java.h" -int +EXPORT int main(int argc, char **args) { //avoid null-terminated array of arguments to test JDK-8303669 diff --git a/test/lib/native/export.h b/test/lib/native/export.h new file mode 100644 index 00000000000..7e0eac383a5 --- /dev/null +++ b/test/lib/native/export.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#ifndef TEST_LIB_NATIVE_EXPORT_H +#define TEST_LIB_NATIVE_EXPORT_H + +#ifdef _WIN64 + #define EXPORT __declspec(dllexport) +#elif defined(__GNUC__) + #define EXPORT __attribute__((visibility("default"))) +#else + #define EXPORT +#endif + +#endif // TEST_LIB_NATIVE_EXPORT_H diff --git a/test/micro/org/openjdk/bench/java/lang/foreign/libCallOverhead.c b/test/micro/org/openjdk/bench/java/lang/foreign/libCallOverhead.c index 8ad44f58cec..5297b77bb30 100644 --- a/test/micro/org/openjdk/bench/java/lang/foreign/libCallOverhead.c +++ b/test/micro/org/openjdk/bench/java/lang/foreign/libCallOverhead.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void func() {} diff --git a/test/micro/org/openjdk/bench/java/lang/foreign/libPtr.c b/test/micro/org/openjdk/bench/java/lang/foreign/libPtr.c index a26d679f18e..bb61791693d 100644 --- a/test/micro/org/openjdk/bench/java/lang/foreign/libPtr.c +++ b/test/micro/org/openjdk/bench/java/lang/foreign/libPtr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -23,14 +23,10 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif - #include +#include "export.h" + EXPORT long long id_long_long(long long value) { return value; } diff --git a/test/micro/org/openjdk/bench/java/lang/foreign/libQSort.c b/test/micro/org/openjdk/bench/java/lang/foreign/libQSort.c index cafb83d8708..01fe313e864 100644 --- a/test/micro/org/openjdk/bench/java/lang/foreign/libQSort.c +++ b/test/micro/org/openjdk/bench/java/lang/foreign/libQSort.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -21,12 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif - +#include "export.h" EXPORT int compar(const void* e0, const void* e1) { int i0 = *((int*) e0); diff --git a/test/micro/org/openjdk/bench/java/lang/foreign/libUpcalls.c b/test/micro/org/openjdk/bench/java/lang/foreign/libUpcalls.c index 220a890a812..fa534bca54f 100644 --- a/test/micro/org/openjdk/bench/java/lang/foreign/libUpcalls.c +++ b/test/micro/org/openjdk/bench/java/lang/foreign/libUpcalls.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -21,11 +21,7 @@ * questions. */ -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif +#include "export.h" EXPORT void blank(void (*cb)(void)) { cb(); diff --git a/test/micro/org/openjdk/bench/java/lang/foreign/points/support/libPoint.c b/test/micro/org/openjdk/bench/java/lang/foreign/points/support/libPoint.c index 5d4a23a8d6f..5e1913e2aa7 100644 --- a/test/micro/org/openjdk/bench/java/lang/foreign/points/support/libPoint.c +++ b/test/micro/org/openjdk/bench/java/lang/foreign/points/support/libPoint.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -20,17 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -#include + #include +#include +#include "export.h" #include "points.h" -#ifdef _WIN64 -#define EXPORT __declspec(dllexport) -#else -#define EXPORT -#endif - EXPORT double distance(Point p1, Point p2) { int xDist = abs(p1.x - p2.x); int yDist = abs(p1.y - p2.y);