Skip to content

Commit 6479338

Browse files
authored
Merge branch 'main' into prof-15098-context-by-id
2 parents 4d26a77 + 9218f0a commit 6479338

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

build-logic/conventions/src/main/kotlin/com/datadoghq/native/config/ConfigurationPresets.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,17 @@ object ConfigurationPresets {
217217
}
218218
// G1GC's heap reservation is placed just below 2 GB (0x7fff7000) by ASLR on
219219
// some kernel configurations, which is exactly where ASan needs to mmap its
220-
// shadow bytes [0x7fff7000-0x10007fff7fff]. This is not JDK-version specific
221-
// — it depends on the kernel's mmap base randomisation at the time the process
222-
// starts. Force the heap to a very low base address so the entire JVM
223-
// footprint (heap + class space + code cache) stays well below the shadow
224-
// range and the two regions never conflict.
225-
config.testJvmArgs.addAll(listOf(
226-
"-XX:HeapBaseMinAddress=0x4000000",
227-
"-Xmx512m",
228-
"-XX:CompressedClassSpaceSize=256m"
229-
))
220+
// shadow bytes [0x7fff7000-0x10007fff7fff]. Force the heap to a very low
221+
// base address so the entire JVM footprint stays below the shadow range.
222+
// HeapBaseMinAddress is not accepted by JDK <= 11 (constraint violation);
223+
// those JDKs rely on the vm.mmap_rnd_bits=8 CI-level mitigation instead.
224+
if (PlatformUtils.testJvmMajorVersion() >= 12) {
225+
config.testJvmArgs.addAll(listOf(
226+
"-XX:HeapBaseMinAddress=0x4000000",
227+
"-Xmx512m",
228+
"-XX:CompressedClassSpaceSize=256m"
229+
))
230+
}
230231
}
231232
}
232233
Platform.MACOS -> {

build-logic/conventions/src/main/kotlin/com/datadoghq/native/util/PlatformUtils.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,25 @@ object PlatformUtils {
350350
)
351351
}
352352

353+
/**
354+
* Returns the major version of the test JVM (e.g. 8, 11, 17, 21, 25).
355+
* Returns 0 if the version cannot be determined.
356+
*/
357+
fun testJvmMajorVersion(): Int {
358+
val javaHome = testJavaHome()
359+
return try {
360+
val process = ProcessBuilder("$javaHome/bin/java", "-version")
361+
.redirectErrorStream(true)
362+
.start()
363+
val output = process.inputStream.bufferedReader().readText()
364+
process.waitFor(10, TimeUnit.SECONDS)
365+
val match = Regex("""version "(?:1\.)?(\d+)""").find(output)
366+
match?.groupValues?.get(1)?.toIntOrNull() ?: 0
367+
} catch (_: Exception) {
368+
0
369+
}
370+
}
371+
353372
/**
354373
* Returns true if the test JVM (from JAVA_TEST_HOME or JAVA_HOME) is an OpenJ9/J9 JVM.
355374
* Probes `java -version` stderr output for "J9" or "OpenJ9".

0 commit comments

Comments
 (0)