Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import datadog.environment.OperatingSystem;
import datadog.trace.api.Config;
import datadog.trace.api.civisibility.config.TestFQN;
import datadog.trace.api.config.CiVisibilityConfig;
Expand Down Expand Up @@ -40,6 +41,9 @@ public abstract class CiVisibilitySmokeTest {

private static final Map<String, String> DEFAULT_TRACER_CONFIG = defaultJvmArguments();

private static final String JAVA_TOOL_OPTIONS = "JAVA_TOOL_OPTIONS";
private static final String DISABLE_CDS = "-Xshare:off";

@TempDir protected Path prefsDir;

protected static String buildJavaHome() {
Expand Down Expand Up @@ -101,6 +105,9 @@ private static Map<String, String> buildJvmArgMap(
protected List<String> buildJvmArguments(
String mockBackendIntakeUrl, String serviceName, Map<String, String> additionalArgs) {
List<String> arguments = new ArrayList<>(Arrays.asList("-Xms256m", "-Xmx512m"));
if (isLinuxArm64()) {
arguments.add(DISABLE_CDS);
}

arguments.add(preventJulPrefsFileLock());

Expand Down Expand Up @@ -149,6 +156,27 @@ protected String preventJulPrefsFileLock() {
return "-Djava.util.prefs.userRoot=" + resolved.toAbsolutePath();
}

/**
* Disables CDS in every JVM started with {@code environment}, including nested build tool
* processes, to avoid SIGSEGVs on Linux arm64.
*/
protected static void disableCdsOnLinuxArm64(Map<String, String> environment) {
if (!isLinuxArm64()) {
return;
}
String options = environment.get(JAVA_TOOL_OPTIONS);
if (options == null) {
options = System.getenv(JAVA_TOOL_OPTIONS);
}
environment.put(
JAVA_TOOL_OPTIONS,
options == null || options.isEmpty() ? DISABLE_CDS : options + " " + DISABLE_CDS);
}

private static boolean isLinuxArm64() {
return OperatingSystem.isLinux() && OperatingSystem.architecture().isArm64();
}

private static Path tempUserPrefsPath() {
String uniqueId =
System.currentTimeMillis() + "_" + System.nanoTime() + "_" + Thread.currentThread().getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ private BuildResult runGradle(
buildEnv.put("MAVEN_REPOSITORY_PROXY", mavenRepositoryProxy);
}
GradleDistribution.propagateMassReadUrl(buildEnv);
disableCdsOnLinuxArm64(buildEnv);
Comment thread
daniel-mohedano marked this conversation as resolved.

GradleRunner gradleRunner =
GradleDistribution.withDistribution(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void stopGradleBuildDaemon() {
Map<String, String> env = new HashMap<>();
env.put("JAVA_HOME", JAVA_HOME);
env.put("GRADLE_USER_HOME", gradleUserHome.toString());
disableCdsOnLinuxArm64(env);
env.put("GRADLE_ARGS", "");
env.put("GRADLE_OPTS", "");
ShellCommandExecutor shellCommandExecutor =
Expand All @@ -115,6 +116,7 @@ private void givenGradleWrapper(String gradleVersion) throws Exception {
Map<String, String> env = new HashMap<>();
env.put("JAVA_HOME", JAVA_HOME);
env.put("GRADLE_USER_HOME", gradleUserHome.toString());
disableCdsOnLinuxArm64(env);
// Avoid inheriting CI Gradle launcher settings that might be incompatible with this wrapper.
env.put("GRADLE_ARGS", "");
env.put("GRADLE_OPTS", "");
Expand All @@ -141,6 +143,7 @@ private String whenRunningGradleLauncherWithJavaTracerInjected(String gradleDaem
Map<String, String> env = new HashMap<>();
env.put("JAVA_HOME", JAVA_HOME);
env.put("GRADLE_USER_HOME", gradleUserHome.toString());
disableCdsOnLinuxArm64(env);
env.put("GRADLE_ARGS", "");
env.put("GRADLE_OPTS", "-javaagent:" + AGENT_JAR);
env.put("DD_CIVISIBILITY_ENABLED", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ ProcessBuilder createProcessBuilder(
if (mavenRepositoryProxy != null) {
processBuilder.environment().put("MAVEN_REPOSITORY_PROXY", mavenRepositoryProxy);
}
disableCdsOnLinuxArm64(processBuilder.environment());

return processBuilder;
}
Expand Down
Loading