-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix一些问题 #54
base: master
Are you sure you want to change the base?
fix一些问题 #54
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,24 +434,31 @@ int processHeap(const void *buf, int firstIndex, int maxLen, int heapSerialNo, i | |
|
||
//裁剪掉基本类型数组,无论是否在system space都进行裁剪 | ||
//区别是数组左坐标,app space时带数组元信息(类型、长度)方便回填 | ||
if (isCurrentSystemHeap) { | ||
stripIndexListPair[stripIndex * 2] = firstIndex; | ||
} else { | ||
stripIndexListPair[stripIndex * 2] = | ||
primitiveArrayDumpIndex + BASIC_TYPE_BYTE_SIZE /*value type*/; | ||
} | ||
arraySerialNo++; | ||
// if (isCurrentSystemHeap) { | ||
// stripIndexListPair[stripIndex * 2] = firstIndex; | ||
// } else { | ||
// stripIndexListPair[stripIndex * 2] = | ||
// primitiveArrayDumpIndex + BASIC_TYPE_BYTE_SIZE /*value type*/; | ||
// } | ||
// arraySerialNo++; | ||
// | ||
// int valueSize = getByteSizeFromType(((unsigned char *)buf)[primitiveArrayDumpIndex]); | ||
// primitiveArrayDumpIndex += BASIC_TYPE_BYTE_SIZE /*value type*/ + valueSize * length; | ||
// | ||
// //数组右坐标 | ||
// stripIndexListPair[stripIndex * 2 + 1] = primitiveArrayDumpIndex; | ||
// | ||
// // app space时,不修改长度因为回填数组时会补齐 | ||
// if (isCurrentSystemHeap) { | ||
// stripBytesSum += primitiveArrayDumpIndex - firstIndex; | ||
// } | ||
|
||
stripIndexListPair[stripIndex * 2] = firstIndex; | ||
int valueSize = getByteSizeFromType(((unsigned char *)buf)[primitiveArrayDumpIndex]); | ||
primitiveArrayDumpIndex += BASIC_TYPE_BYTE_SIZE /*value type*/ + valueSize * length; | ||
|
||
//数组右坐标 | ||
stripIndexListPair[stripIndex * 2 + 1] = primitiveArrayDumpIndex; | ||
stripBytesSum += primitiveArrayDumpIndex - firstIndex; | ||
|
||
// app space时,不修改长度因为回填数组时会补齐 | ||
if (isCurrentSystemHeap) { | ||
stripBytesSum += primitiveArrayDumpIndex - firstIndex; | ||
} | ||
stripIndex++; | ||
|
||
arraySerialNo = processHeap(buf, primitiveArrayDumpIndex, maxLen, heapSerialNo, arraySerialNo); | ||
|
@@ -594,7 +601,8 @@ extern "C" { | |
#endif | ||
|
||
JNIEXPORT void JNICALL | ||
Java_com_kwai_koom_javaoom_dump_StripHprofHeapDumper_initStripDump(JNIEnv *env, jobject jObject) { | ||
Java_com_kwai_koom_javaoom_dump_StripHprofHeapDumper_initStripDump( | ||
JNIEnv *env, jobject jObject, int sdk_version) { | ||
hprofFd = -1; | ||
hprofName = nullptr; | ||
isDumpHookSucc = false; | ||
|
@@ -611,14 +619,20 @@ Java_com_kwai_koom_javaoom_dump_StripHprofHeapDumper_initStripDump(JNIEnv *env, | |
* android 7-10版本,open方法都在libart.so中 | ||
* libbase.so与libartbase.so,为保险操作 | ||
*/ | ||
xhook_register("libart.so", "open", (void *)hook_open, nullptr); | ||
xhook_register("libbase.so", "open", (void *)hook_open, nullptr); | ||
xhook_register("libartbase.so", "open", (void *)hook_open, nullptr); | ||
|
||
xhook_register("libc.so", "write", (void *)hook_write, nullptr); | ||
xhook_register("libart.so", "write", (void *)hook_write, nullptr); | ||
xhook_register("libbase.so", "write", (void *)hook_write, nullptr); | ||
xhook_register("libartbase.so", "write", (void *)hook_write, nullptr); | ||
if (sdk_version == 30) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为啥要特判30呢,这两个函数原本不是也hook了吗 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 30 不需要hook其他的,只要hook 2个就可以了,(我们还有其他的hook尽量少吧,也可以不判断,对程序结果不影响) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果这里特判了,其他版本感觉也要特判。但是可能会导致有些不遵守规范的rom版本用不了有问题,比如是6.0的android版本,但是实际上是5.0的虚拟机so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 最好其他也判断下,我们这边5.0的没上这个 |
||
xhook_register("libart.so", "open", (void *)hook_open, nullptr); | ||
xhook_register("libc.so", "write", (void *)hook_write, nullptr); | ||
} else { | ||
xhook_register("libart.so", "open", (void *)hook_open, nullptr); | ||
xhook_register("libbase.so", "open", (void *)hook_open, nullptr); | ||
xhook_register("libartbase.so", "open", (void *)hook_open, nullptr); | ||
|
||
xhook_register("libc.so", "write", (void *)hook_write, nullptr); | ||
xhook_register("libart.so", "write", (void *)hook_write, nullptr); | ||
xhook_register("libbase.so", "write", (void *)hook_write, nullptr); | ||
xhook_register("libartbase.so", "write", (void *)hook_write, nullptr); | ||
} | ||
|
||
xhook_refresh(0); | ||
xhook_clear(); | ||
|
@@ -638,10 +652,12 @@ static void initDumpHprofSymbols(); | |
static pthread_once_t once_control = PTHREAD_ONCE_INIT; | ||
|
||
JNIEXPORT void JNICALL | ||
Java_com_kwai_koom_javaoom_dump_ForkJvmHeapDumper_initForkDump(JNIEnv *env, jobject jObject) { | ||
if (!initForkVMSymbols()) { | ||
// Above android 11 | ||
Java_com_kwai_koom_javaoom_dump_ForkJvmHeapDumper_initForkDump( | ||
JNIEnv *env, jobject jObject, jint sdk_version) { | ||
if (sdk_version == 30) { | ||
pthread_once(&once_control, initDumpHprofSymbols); | ||
} else { | ||
initForkVMSymbols(); | ||
} | ||
} | ||
|
||
|
@@ -709,8 +725,6 @@ JNIEXPORT void JNICALL Java_com_kwai_koom_javaoom_dump_ForkJvmHeapDumper_waitPid | |
__asm__("mrc p15, 0, %0, c13, c0, 3" : "=r"(__val)); \ | ||
__val; \ | ||
}) | ||
#else | ||
#error unsupported architecture | ||
#endif | ||
|
||
// What caused the GC? | ||
|
@@ -881,16 +895,36 @@ JNIEXPORT jboolean JNICALL Java_com_kwai_koom_javaoom_dump_ForkJvmHeapDumper_dum | |
HprofConstructor == nullptr || HprofDestructor == nullptr || Dump == nullptr) { | ||
return JNI_FALSE; | ||
} | ||
#ifdef defined(__arm__) || defined(__aarch64__) | ||
ScopedGCCriticalSectionConstructor(gSGCSHandle, __get_tls()[TLS_SLOT_ART_THREAD_SELF], | ||
kGcCauseHprof, kCollectorTypeHprof); | ||
#else | ||
static pthread_key_t pthread_key_self_; | ||
void* thread = pthread_getspecific(pthread_key_self_); | ||
ScopedGCCriticalSectionConstructor(gSGCSHandle, thread, kGcCauseHprof, kCollectorTypeHprof); | ||
#endif | ||
ScopedSuspendAllConstructor(gSSAHandle, LOG_TAG, true); | ||
pid_t pid = fork(); | ||
if (pid == -1) { | ||
// Fork error. | ||
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "failed to fork!"); | ||
return JNI_FALSE; | ||
} | ||
if (pid != 0) { | ||
if (pid == 0) { | ||
if (nullptr == hprofName) { | ||
const char *filename = env->GetStringUTFChars(file_name, nullptr); | ||
HprofConstructor(gHprofHandle, filename, -1, false); | ||
Dump(gHprofHandle); | ||
HprofDestructor(gHprofHandle); | ||
env->ReleaseStringUTFChars(file_name, filename); | ||
} else { | ||
HprofConstructor(gHprofHandle, hprofName, -1, false); | ||
Dump(gHprofHandle); | ||
HprofDestructor(gHprofHandle); | ||
} | ||
isDumpHookSucc = true; | ||
_exit(0); | ||
} else { | ||
// Parent | ||
ScopedGCCriticalSectionDestructor(gSGCSHandle); | ||
ScopedSuspendAllDestructor(gSSAHandle); | ||
|
@@ -901,14 +935,8 @@ JNIEXPORT jboolean JNICALL Java_com_kwai_koom_javaoom_dump_ForkJvmHeapDumper_dum | |
break; | ||
} | ||
} | ||
return JNI_TRUE; | ||
} | ||
|
||
const char *filename = env->GetStringUTFChars(file_name, nullptr); | ||
HprofConstructor(gHprofHandle, filename, -1, false); | ||
Dump(gHprofHandle); | ||
HprofDestructor(gHprofHandle); | ||
env->ReleaseStringUTFChars(file_name, filename); | ||
return JNI_TRUE; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import com.kwai.koom.javaoom.common.KGlobalConfig; | ||
import com.kwai.koom.javaoom.common.KLog; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Copyright 2020 Kwai, Inc. All rights reserved. | ||
|
@@ -38,7 +39,7 @@ public class ForkJvmHeapDumper implements HeapDumper { | |
public ForkJvmHeapDumper() { | ||
soLoaded = KGlobalConfig.getSoLoader().loadLib("koom-java"); | ||
if (soLoaded) { | ||
initForkDump(); | ||
initForkDump(Build.VERSION.SDK_INT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不用传参,native也能判断 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是的,这个可以修改下 |
||
} | ||
} | ||
|
||
|
@@ -60,6 +61,19 @@ public boolean dump(String path) { | |
return false; | ||
} | ||
|
||
//modify file permission, adapt to some rom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里能说下具体哪些rom有哪些不兼容的现象吗 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. meizu 16T 和 oppo r11 2台手机我们这边都不行 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 有什么解决方案吗小老哥 |
||
File file = new File(path); | ||
if (file.exists()) { | ||
file.setReadable(true, false); | ||
} else { | ||
try { | ||
file.createNewFile(); | ||
file.setReadable(true, false); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
// Compatible with Android 11 | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) { | ||
return dumpHprofDataNative(path); | ||
|
@@ -96,7 +110,7 @@ private boolean waitDumping(int pid) { | |
* | ||
* @return init result | ||
*/ | ||
private native void initForkDump(); | ||
private native void initForkDump(int sdk_version); | ||
|
||
/** | ||
* First do suspend vm, then do fork. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方为什么要删掉?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
裁剪模式会导致分析的时候出现问题,并且也不需要这块的分析
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是为了裁剪掉更多的heap,如果注释掉了,会导致裁剪的内容变少。具体出现的问题是什么?