-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
提供JvmUtils #1698
提供JvmUtils #1698
Conversation
懂c++的大佬可以再优化下jni-library.cpp的实现,使得java层能够支持并发调用。 |
在我的macos上使用
|
之前构建不通过是因为后面构建的机器上的JDK,是OpenJDK,OpenJDK没有include文件夹,改成使用本地的头文件,就没问题了。另外,由于使用的是本地的头文件,所以目前仅仅支持linux、mac和windows(三种)的64位的操作系统,后续再支持32位操作系统。 |
API返回的对象是 LinkedList ,感觉这个直接用 ArrayList更合理?并且创建 ArrayList 时可以指定 size。 |
native-lib-loader 这个能否去掉?看了下它的代码,主要是判断不同的os,然后从ClassLoader找到对应的动态库文件,再解压到临时目录,再调用 或者可以把arthas里已有的 ProfilerCommand里加载的流程抽取出来,共用一份逻辑。 |
最开始想的是,获取系统中的所有Object对象,但实际不会有这种场景,因此Integer.MAX_VALUE - 8(数组的最大长度)想必是够用的,我将尽快修改。 |
使用 |
计划用 github ci构建好不同环境的so,然后下载放到目录下。和现在的代码里的 https://github.com/hengyunabc/test/blob/master/.github/workflows/test.yml#L18 |
放到目录里的话,so文件会被打到 |
|
建议写一个测试用例,反复调用10w+次,检查是否存在JNI内存泄漏(Native Memory)。 |
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.
https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#Deallocate
Deallocate
jvmtiError
Deallocate(jvmtiEnv* env,
unsigned char* mem)
Deallocate mem using the JVM TI allocator. This function should be used to deallocate any memory allocated and returned by a JVM TI function (including memory allocated with Allocate). All allocated memory must be deallocated or the memory cannot be reclaimed.
要检查每个方法的参数说明,根据需要调用Deallocate释放内存。
|
||
jint count = 0; | ||
jobject *instances; | ||
error = jvmti->GetObjectsWithTags(1, &tag, &count, &instances, NULL); |
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.
jobject *instances;
可能存在内存泄漏问题
|
||
jint count = 0; | ||
jobject *instances; | ||
error = jvmti->GetObjectsWithTags(1, &tag, &count, &instances, NULL); |
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.
jobject *instances; 可能存在内存泄漏问题
jclass *classes; | ||
jint count = 0; | ||
|
||
jvmtiError error = jvmti->GetLoadedClasses(&count, &classes); |
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.
jclass *classes;
这个数组是JVM申请的内存空间,好像需要使用完之后主动释放吧?
https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#GetLoadedClasses
Name Type Description class_count_ptr jint* On return, points to the number of classes.Agent passes a pointer to a jint. On return, the jint has been set. classes_ptr jclass** On return, points to an array of references, one for each class.Agent passes a pointer to a jclass*. On return, the jclass* points to a newly allocated array of size *class_count_ptr. The array should be freed with Deallocate. The objects returned by classes_ptr are JNI local references and must be managed.
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.
收到,感谢您的宝贵建议,我将尽快处理。
代码在这个commit里合并了: hengyunabc@59f4d10 |
JvmUtils
能够在不dump的前提下,获取:具体使用可参考测试用例
com.vdian.vclub.JvmUtilsTest
;