Skip to content

Commit

Permalink
feat: fork dump support Android 12.1 - Android 14
Browse files Browse the repository at this point in the history
  • Loading branch information
zefengsysu committed Apr 10, 2024
1 parent cabc62d commit c607b81
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ buildscript {
'kotlin' : '1.3.72',
'kotlin_compiler' : '1.4.21',

// TODO(wangzefeng): upgrade ndk version to support Android 14
'ndk' : '23.1.7779620',
]

Expand Down
15 changes: 12 additions & 3 deletions koom-fast-dump/src/main/cpp/hprof_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#undef LOG_TAG
#define LOG_TAG "HprofDump"

// TODO(wangzefeng): remove this when we upgrade ndkVersion
#define __ANDROID_API_U__ 34

// TODO(wangzefeng):
// 1. fork dump may cause a child process crash on Android 12(__ANDROID_API_S__), will be optimized in the next version.
// 2. not work on Android 15, need adapt it

using namespace kwai::linker;

namespace kwai {
Expand All @@ -44,6 +51,8 @@ HprofDump::HprofDump() : init_done_(false), android_api_(0) {
android_api_ = android_get_device_api_level();
}

// NOTE(fork dump): fork dump check android_api_ first

void HprofDump::Initialize() {
if (init_done_ || android_api_ < __ANDROID_API_L__) {
return;
Expand All @@ -60,7 +69,7 @@ void HprofDump::Initialize() {
resume_vm_fnc_ = (void (*)())kwai::linker::DlFcn::dlsym(
handle, "_ZN3art3Dbg8ResumeVMEv");
KFINISHV_FNC(resume_vm_fnc_, DlFcn::dlclose, handle)
} else if (android_api_ <= __ANDROID_API_S__) {
} else if (android_api_ <= __ANDROID_API_U__) {
// Over size for device compatibility
ssa_instance_ = std::make_unique<char[]>(64);
sgc_instance_ = std::make_unique<char[]>(64);
Expand Down Expand Up @@ -105,7 +114,7 @@ pid_t HprofDump::SuspendAndFork() {

if (android_api_ < __ANDROID_API_R__) {
suspend_vm_fnc_();
} else if (android_api_ <= __ANDROID_API_S__) {
} else if (android_api_ <= __ANDROID_API_U__) {
void *self = __get_tls()[TLS_SLOT_ART_THREAD_SELF];
sgc_constructor_fnc_((void *)sgc_instance_.get(), self, kGcCauseHprof,
kCollectorTypeHprof);
Expand All @@ -129,7 +138,7 @@ bool HprofDump::ResumeAndWait(pid_t pid) {

if (android_api_ < __ANDROID_API_R__) {
resume_vm_fnc_();
} else if (android_api_ <= __ANDROID_API_S__) {
} else if (android_api_ <= __ANDROID_API_U__) {
void *self = __get_tls()[TLS_SLOT_ART_THREAD_SELF];
exclusive_lock_fnc_(*mutator_lock_ptr_, self);
ssa_destructor_fnc_((void *)ssa_instance_.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CommonConfig private constructor(
mDebugMode = debugMode
}

// NOTE(fork dump): fork dump check sdkVersionMatch first
fun setSdkVersionMatch(sdkVersionMatch: Boolean) = apply {
mSdkVersionMatch = sdkVersionMatch
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ object DefaultInitTask : InitTask {
.setApplication(application) // Set application
.setVersionNameInvoker { "1.0.0" } // Set version name, java leak feature use it
.setSdkVersionMatch(
Build.VERSION.SDK_INT <= Build.VERSION_CODES.S && Build.VERSION.SDK_INT
>= Build.VERSION_CODES.LOLLIPOP
Build.VERSION.SDK_INT <= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
) // Set if current sdk version is supported
.build()

Expand Down

0 comments on commit c607b81

Please sign in to comment.