Skip to content

Commit b421b5b

Browse files
authored
Fix the annotation region format parsing on JDK 24/25 (#9234)
1 parent ac35199 commit b421b5b

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/main/java/com/datadog/profiling/controller/openjdk/events/SmapEntryCache.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ static class AnnotatedRegion {
6666
public List<SmapEntryEvent> getEvents() {
6767
long prevTimestamp = lastTimestamp;
6868
long thisTimestamp = System.nanoTime();
69-
// 500ms should be enough not to recollect the data when both single and aggregated events are
70-
// enabled
71-
// Also, this is short enough to avoid having stalled smap data reported
72-
if (thisTimestamp - prevTimestamp > 500_000_000L) {
69+
if (thisTimestamp - prevTimestamp > ttl) {
7370
if (UPDATER.compareAndSet(this, prevTimestamp, thisTimestamp)) {
7471
int currentIdx = INDEX_UPDATER.updateAndGet(this, x -> (x + 1) % 2);
7572
List<SmapEntryEvent> eventList = (List<SmapEntryEvent>) events[currentIdx];
@@ -92,14 +89,16 @@ static AnnotatedRegion fromAnnotatedEntry(String line, int javaVersion) {
9289
// Java 24-25
9390
// 0x0000000448800000-0x000000049d800000 1426063360 rw-p 1425514496 0 4K com JAVAHEAP
9491

92+
// unify the format of address range for Java 23 and 24+
93+
line = line.replace(" - ", "-");
9594
boolean isVsyscall =
9695
line.startsWith("0x" + VSYSCALL_START_ADDRESS_STR); // can't be parsed to Long safely(?)
9796
long startAddress = -1;
9897
int dashIndex = line.indexOf('-');
9998
if (dashIndex > 0) {
100-
startAddress = isVsyscall ? -0x1000 - 1 : Long.decode(line.substring(0, dashIndex - 1));
99+
startAddress = isVsyscall ? -0x1000 - 1 : Long.decode(line.substring(0, dashIndex));
101100
String description = extractElement(line, descIndex, dashIndex + 1);
102-
if (description == null || description.isEmpty()) {
101+
if (description == null || description.isEmpty() || "-".equals(description)) {
103102
return new AnnotatedRegion(startAddress, "UNDEFINED");
104103
} else if (description.startsWith("STACK")) {
105104
return new AnnotatedRegion(startAddress, "STACK");
@@ -139,7 +138,7 @@ static String extractElement(String line, int index, int from) {
139138
wsCount++;
140139
}
141140
}
142-
return wsCount == index ? line.substring(fromIndex, tillIndex).trim() : null;
141+
return wsCount <= index ? line.substring(fromIndex, tillIndex).trim() : null;
143142
}
144143

145144
private static boolean isSmapHeader(String line) {

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/test/java/com/datadog/profiling/controller/openjdk/events/SmapEntryFactoryTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,27 @@ void testAnnotatedRegionsSanity(int javaVersion) throws Exception {
2525
Objects.requireNonNull(
2626
SmapEntryFactory.class.getResourceAsStream(
2727
"/smap/annotated_regions_" + javaVersion + ".txt"))))) {
28+
29+
long sentinel = 0x1000000420000000L;
2830
String line = null;
2931
Set<String> descs = new HashSet<>();
32+
boolean sentinelFound = false;
33+
3034
while ((line = br.readLine()) != null) {
3135
SmapEntryCache.AnnotatedRegion region =
3236
SmapEntryCache.fromAnnotatedEntry(line, javaVersion);
3337
if (line.startsWith("0x")) {
3438
assertNotNull(region);
3539
descs.add(region.description);
40+
sentinelFound |= region.startAddress == sentinel;
3641
}
3742
}
43+
assertTrue(sentinelFound, "Sentinel address not found");
3844
assertTrue(descs.contains("JAVAHEAP"), "JAVAHEAP not found");
3945
assertTrue(descs.contains("GC"), "GC not found");
4046
assertTrue(descs.contains("META"), "META not found");
4147
assertTrue(descs.contains("STACK"), "STACK not found");
48+
assertTrue(descs.contains("UNDEFINED"), "UNDEFINED not found");
4249
}
4350
}
4451

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/test/resources/smap/annotated_regions_23.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Memory mappings:
1616
(*) - Mapping contains data from multiple regions
1717

1818
size prot offset What
19-
0x0000000420000000 - 0x000000043b000000 452984832 rw-p 00000000 JAVAHEAP
19+
0x1000000420000000 - 0x100000043b000000 452984832 rw-p 00000000 JAVAHEAP
20+
0x0000000420000000 - 0x000000043b000000 452984832 rw-p 00000000 JAVAHEAP
2021
0x000000043b000000 - 0x000000045b000000 536870912 ---p 00000000 JAVAHEAP
2122
0x000000045b000000 - 0x0000000491000000 905969664 rw-p 00000000 JAVAHEAP
2223
0x0000000491000000 - 0x00000004c9000000 939524096 ---p 00000000 JAVAHEAP

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/test/resources/smap/annotated_regions_24.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ file: file mapped, if mapping is not anonymous
3030

3131
from to vsize prot rss hugetlb pgsz notes info file
3232
========================================================================================================================================================================
33+
0x1000000420000000-0x100000043b000000 452984832 rw-p 00000000 0 4K com JAVAHEAP
3334
0x0000000448800000-0x000000049d800000 1426063360 rw-p 1425514496 0 4K com JAVAHEAP -
3435
0x000000049d800000-0x0000000800000000 14537457664 ---p 0 0 4K - JAVAHEAP -
3536
0x0000561c39706000-0x0000561c39707000 4096 r--p 4096 0 4K com - /home/bits/.sdkman/candidates/java/24.0.2-librca/bin/java

0 commit comments

Comments
 (0)