-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add mallocTrim command to vmTool #3030
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
base: master
Are you sure you want to change the base?
Conversation
缺少测试,需要增加基本的能调用成功的测试。不一定要构造出对应的场景。比如在 linux 下跑测试时要调用成功。 |
根据 malloc_trim 的官方文档 https://man7.org/linux/man-pages/man3/malloc_trim.3.html 而且 trim_native_heap 的实现 https://github.com/openjdk/jdk21/blob/jdk-21%2B35/src/hotspot/os/linux/os_linux.cpp#L5518 所以如果要补充单元测试的话,可能只有直接调用,并不能检测结果是否 true. @Test
public void testMallocTrim() {
VmTool vmtool = initVmTool();
vmtool.mallocTrim();
} 另外: 非 glibc 的 mallocTrim 返回 false 是否更合适 |
看起来,好像是 mallocTrim 函数要返回两个信息: 是否有支持,是否有成功。 |
可以把返回改为 int,然后 command 层去适配输出。。 主要我是觉得单元测试不好写,只能是像上个回复一样简单的调用,还有必要写吗 |
单元测试的作用主要是确保编译为 so 之后,在java层能正常调用。功能是否正常可以先不管。 另外需要同步更新下 wiki 文档。 |
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.
Pull Request Overview
This PR adds two new commands, mallocTrim and mallocStats, to vmTool to help diagnose Java memory issues as described in the linked issue and reference article.
- Updated English and Chinese documentation with usage examples.
- Extended VmToolCommand, VmToolMXBean, and VmTool classes to support new actions.
- Added native JNI implementations and test cases for the new commands.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
site/docs/en/doc/vmtool.md | Added commands and usage examples for mallocTrim and mallocStats in English. |
site/docs/doc/vmtool.md | Added commands and usage examples for mallocTrim and mallocStats in Chinese. |
core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java | Updated command help text, enum, and process() method to include new actions. |
arthas-vmtool/src/test/java/arthas/VmToolTest.java | Added basic tests for mallocTrim and mallocStats. |
arthas-vmtool/src/main/native/src/jni-library.cpp | Added JNI implementations for mallocTrim and mallocStats. |
arthas-vmtool/src/main/java/arthas/VmToolMXBean.java | Updated interface to include mallocTrim and mallocStats methods. |
arthas-vmtool/src/main/java/arthas/VmTool.java | Provided native method wrappers for mallocTrim and mallocStats. |
Comments suppressed due to low confidence (2)
arthas-vmtool/src/test/java/arthas/VmToolTest.java:215
- Consider adding assertions to validate the result of mallocTrim instead of just executing the method.
public void testMallocTrim() {
arthas-vmtool/src/test/java/arthas/VmToolTest.java:221
- Consider adding assertions or validations to ensure mallocStats returns the expected outcome.
public void testMallocStats() {
malloc_trim 是排查 java 64M 问题的重要函数,参考 https://juejin.cn/post/6854573220733911048
CLOSE: #3020