Skip to content

Commit

Permalink
8327460: Compile tests with the same visibility rules as product code
Browse files Browse the repository at this point in the history
Reviewed-by: erikj, jvernee, dholmes, alanb
  • Loading branch information
magicus committed Mar 13, 2024
1 parent 3b18c5d commit cc9a8ab
Show file tree
Hide file tree
Showing 39 changed files with 145 additions and 235 deletions.
24 changes: 18 additions & 6 deletions make/common/TestFilesCompilation.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 1 addition & 16 deletions make/test/JtregNativeJdk.gmk
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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)
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/jdk.jpackage/macosx/native/applauncher/MacLauncher.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
* questions.
*/

#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#include "export.h"

EXPORT int foo() {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/runtime/ErrorHandling/TestDwarf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions test/hotspot/jtreg/runtime/ErrorHandling/libTestDwarfHelper.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,9 +21,11 @@
* questions.
*/

#include "jni.h"
#include <stdio.h>

#include "export.h"
#include "jni.h"

void unused1() {
}

Expand All @@ -39,7 +41,7 @@ void unused4() {
void unused5() {
}

void dereference_null() {
EXPORT void dereference_null() {
int* x = (int*)0;
*x = 34; // Crash
}
14 changes: 3 additions & 11 deletions test/jdk/java/foreign/CallGeneratorHelper.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -267,11 +263,7 @@ static void generateDowncallFunction(String fName, Ret ret, List<ParamType> 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++) {
Expand Down
8 changes: 2 additions & 6 deletions test/jdk/java/foreign/arraystructs/libArrayStructs.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]; };
Expand Down
8 changes: 2 additions & 6 deletions test/jdk/java/foreign/capturecallstate/libCaptureCallState.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,11 +23,7 @@

#include <errno.h>

#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#include "export.h"

EXPORT void set_errno_V(int value) {
errno = value;
Expand Down
8 changes: 2 additions & 6 deletions test/jdk/java/foreign/critical/libCritical.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,11 +23,7 @@

#include <errno.h>

#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#include "export.h"

EXPORT void empty() {}

Expand Down
8 changes: 2 additions & 6 deletions test/jdk/java/foreign/dontrelease/libDontRelease.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,10 +21,6 @@
* questions.
*/

#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#include "export.h"

EXPORT void test_ptr(void* ptr) {}
8 changes: 2 additions & 6 deletions test/jdk/java/foreign/libAddressDereference.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions test/jdk/java/foreign/libIntrinsics.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,11 +24,7 @@

#include <stdbool.h>

#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#include "export.h"

EXPORT void empty() {
}
Expand Down Expand Up @@ -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;
}
}
8 changes: 2 additions & 6 deletions test/jdk/java/foreign/libLibraryLookup.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,11 +21,7 @@
* questions.
*/

#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#include "export.h"

int count = 0;

Expand Down
13 changes: 4 additions & 9 deletions test/jdk/java/foreign/libLookupTest.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,12 +21,7 @@
* questions.
*/

#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;
10 changes: 3 additions & 7 deletions test/jdk/java/foreign/libNull.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,12 +21,8 @@
* questions.
*/

#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif

#include <stddef.h>

#include "export.h"

EXPORT void* get_null() { return NULL; }
Loading

1 comment on commit cc9a8ab

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.