Skip to content

Conversation

@rkennke
Copy link
Contributor

@rkennke rkennke commented Jan 19, 2026

What does this PR do?:
This change removes the patching machinery that we used to consume upstream async-profiler source code. Instead, we will maintain our changes directly in soure code going forward.

Motivation:

  • Simplify source code management for day-to-day work
  • Avoid confusion as to what goes where and what comes from where, both for developers and IDEs.

Additional Notes:

I copied the sources that have been generated in src/main/cpp-external into src/main/cpp, except for log.h and spinLock.h which have been present in both cases and where we need our version from src/main/cpp. (Curiously, there has also been a duplicated file symbols.h, where we apparently need the version from cpp-external.)

I tried to remove everything that is related to the patching machinery, but might have missed some stuff.

How to test the change?:
Normal testing should not have any regressions.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: PROF-12123

@rkennke rkennke requested a review from Copilot January 19, 2026 15:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the upstream async-profiler patching machinery and integrates the source code directly into the repository. The change simplifies source code management by eliminating the need to maintain patches and instead managing changes directly in source files.

Changes:

  • Removed patching infrastructure including gradle tasks, configuration files, and lock files
  • Moved async-profiler source files from cpp-external to cpp directory
  • Updated build configurations to remove references to external source directories

Reviewed changes

Copilot reviewed 44 out of 45 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
gradle/patching.gradle Deleted entire patching configuration system with 288 lines removed
gradle/lock.properties Removed lock file tracking async-profiler branch and commit
doc/event-type-system.md Updated path reference from cpp-external to cpp
ddprof-lib/src/test/make/Makefile Removed cpp-external from source directories
ddprof-lib/src/test/fuzz/fuzz_dwarf.cpp Updated comment removing async-profiler upstream reference
ddprof-lib/src/main/cpp/*.{h,cpp} Added numerous async-profiler source files directly (vmStructs, symbols, stackFrame, stackWalker, os, etc.)
ddprof-lib/gtest/build.gradle Removed cpp-external includes and dependencies
ddprof-lib/fuzz/build.gradle Removed cpp-external includes and dependencies
ddprof-lib/build.gradle Removed cloning, copying, and patching tasks; updated source paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +788 to +799
uintptr_t base_addr = (uintptr_t)base;
uint64_t symbol_value = sym->st_value;

// Skip this symbol if addition would overflow
// First check if symbol_value exceeds the address space
if (symbol_value > UINTPTR_MAX) {
continue;
}
// Then check if addition would overflow
if (base_addr > UINTPTR_MAX - (uintptr_t)symbol_value) {
continue;
}
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The overflow protection logic contains duplicated code with symbols_linux.cpp line 793. Consider extracting this pattern into a helper function to avoid code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +545 to +552
if (EMPTY_FRAME_SIZE > 0 || f.pc_off != DW_LINK_REGISTER) {
pc = stripPointer(*(void**)(sp + f.pc_off));
} else if (depth == 1) {
pc = (const void*)frame.link();
} else {
break;
}

Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Duplicated code block appears at lines 537-543 and 545-551. This duplication suggests potential copy-paste error or missing refactoring.

Suggested change
if (EMPTY_FRAME_SIZE > 0 || f.pc_off != DW_LINK_REGISTER) {
pc = stripPointer(*(void**)(sp + f.pc_off));
} else if (depth == 1) {
pc = (const void*)frame.link();
} else {
break;
}

Copilot uses AI. Check for mistakes.
@dd-octo-sts
Copy link

dd-octo-sts bot commented Jan 19, 2026

Scan-Build Report

User:runner@runnervmmtnos
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 clean all
Clang Version:Ubuntu clang version 18.1.3 (1ubuntu1)
Date:Mon Jan 19 15:51:45 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs8
Unused code
Dead assignment1
Dead initialization6
Dead nested assignment1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead assignmentstackWalker.cppwalkVM5381
Unused codeDead initializationjavaApi.cppJava_com_datadoghq_profiler_JavaProfiler_getStatus01191
Unused codeDead initializationprofiler.cpprunInternal14961
Unused codeDead initializationflightRecorder.cppcleanupUnreferencedMethods6131
Unused codeDead initializationflightRecorder.cppcleanupUnreferencedMethods6461
Unused codeDead initializationjavaApi.cppJava_com_datadoghq_profiler_OTelContext_setProcessCtx04751
Unused codeDead initializationvmStructs_dd.cppinitOffsets561
Unused codeDead nested assignmentvmStructs_dd.cppcheckNativeBinding3881

@dd-octo-sts
Copy link

dd-octo-sts bot commented Jan 20, 2026

Scan-Build Report

User:runner@runnervmmtnos
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 clean all
Clang Version:Ubuntu clang version 18.1.3 (1ubuntu1)
Date:Tue Jan 20 10:43:59 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs9
Unused code
Dead assignment1
Dead initialization7
Dead nested assignment1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead assignmentstackWalker.cppwalkVM5511
Unused codeDead initializationjavaApi.cppJava_com_datadoghq_profiler_JavaProfiler_getStatus01191
Unused codeDead initializationprofiler.cpprunInternal16441
Unused codeDead initializationflightRecorder.cppcleanupUnreferencedMethods6581
Unused codeDead initializationflightRecorder.cppcleanupUnreferencedMethods6911
Unused codeDead initializationflightRecorder.cppresolveMethod3511
Unused codeDead initializationjavaApi.cppJava_com_datadoghq_profiler_OTelContext_setProcessCtx04751
Unused codeDead initializationvmStructs_dd.cppinitOffsets561
Unused codeDead nested assignmentvmStructs_dd.cppcheckNativeBinding3881

@rkennke rkennke marked this pull request as ready for review January 20, 2026 11:40
tasks.withType(CppCompile).configureEach {
dependsOn ':ddprof-lib:patchUpstreamFiles'

// TODO: Do we need this, or is this included by default?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the current state is ok. The remaining 'includes' will take care of the only source set we have

Copy link
Collaborator

@jbachorik jbachorik left a comment

Choose a reason for hiding this comment

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

Looking good. The copilot comments seem out of context, feel free to dismiss them.

As an idea for followup, you could create a Claude command in .claude/command that would take the brunt of checking the async-profiler upstream for any interesting/important modifications to the files we are using.

@dd-octo-sts
Copy link

dd-octo-sts bot commented Jan 20, 2026

Scan-Build Report

User:runner@runnervmmtnos
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 clean all
Clang Version:Ubuntu clang version 18.1.3 (1ubuntu1)
Date:Tue Jan 20 14:19:44 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs9
Unused code
Dead assignment1
Dead initialization7
Dead nested assignment1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead assignmentstackWalker.cppwalkVM5511
Unused codeDead initializationjavaApi.cppJava_com_datadoghq_profiler_JavaProfiler_getStatus01191
Unused codeDead initializationprofiler.cpprunInternal16441
Unused codeDead initializationflightRecorder.cppcleanupUnreferencedMethods6581
Unused codeDead initializationflightRecorder.cppcleanupUnreferencedMethods6911
Unused codeDead initializationflightRecorder.cppresolveMethod3511
Unused codeDead initializationjavaApi.cppJava_com_datadoghq_profiler_OTelContext_setProcessCtx04751
Unused codeDead initializationvmStructs_dd.cppinitOffsets561
Unused codeDead nested assignmentvmStructs_dd.cppcheckNativeBinding3881

@rkennke rkennke merged commit ebdcbc7 into main Jan 20, 2026
96 checks passed
@rkennke rkennke deleted the rkennke/PROF-13123 branch January 20, 2026 18:41
@github-actions github-actions bot added this to the 1.37.0 milestone Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants