-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Closed
Closed
提供JvmUtils #1698
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ccd69bb
提供JvmUtils
loongs-zhang 995e59f
降低Spring-core的版本
loongs-zhang d469316
Merge remote-tracking branch 'upstream/master' into dev_jvmutils_support
loongs-zhang aa31870
改成构建时生成
loongs-zhang a90bade
Merge remote-tracking branch 'upstream/master' into dev_jvmutils_support
loongs-zhang d1436de
不同硬件架构生成不同的jar包
loongs-zhang 8da3b13
修正注释
loongs-zhang 21acaac
尝试降低jdk最小依赖版本
loongs-zhang a2f8297
更新gitignore
loongs-zhang aae10f4
适配绝大多数操作系统,更新README
loongs-zhang 49f01d3
fix bug
loongs-zhang c0a4f93
使用本地的头文件
loongs-zhang c5391e1
修复在macos上误打linux的动态链接库的bug
loongs-zhang dc829fd
更新readme
loongs-zhang 3d85b8b
返回值类型改为ArrayList
loongs-zhang f2c4769
Merge remote-tracking branch 'upstream/master' into dev_jvmutils_support
loongs-zhang 4418722
支持并发调用
loongs-zhang e5153a1
处理内存泄漏问题,大幅度优化性能
loongs-zhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
支持并发调用
- Loading branch information
commit 4418722b837c8f1b96a82047e7b833eee400a84b
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,19 @@ jobject createJavaInstance(JNIEnv *env, jclass javaClass) { | |
return env->NewObject(javaClass, construct, ""); | ||
} | ||
|
||
extern "C" | ||
jlong getClassHashCode(JNIEnv *env, jclass javaClass) { | ||
//找到java类的hashCode方法 | ||
jmethodID hashCodeMethod = env->GetMethodID(javaClass, "hashCode", "()I"); | ||
//生成java类实例 | ||
return env->CallLongMethod(javaClass, hashCodeMethod); | ||
} | ||
|
||
extern "C" | ||
jvmtiIterationControl JNICALL | ||
HeapObjectCallback(jlong class_tag, jlong size, jlong *tag_ptr, void *user_data) { | ||
*tag_ptr = 1; | ||
auto *data = static_cast<jlong *>(user_data); | ||
*tag_ptr = *data; | ||
return JVMTI_ITERATION_CONTINUE; | ||
} | ||
|
||
|
@@ -49,15 +58,15 @@ Java_com_vdian_vclub_JvmUtils_getInstances(JNIEnv *env, jclass thisClass, jclass | |
printf("ERROR: JVMTI AddCapabilities failed!%u\n", error); | ||
return JNI_FALSE; | ||
} | ||
//todo 支持并发调用 | ||
//这里用hashCode作为标记 | ||
jlong tag = getClassHashCode(env, klass); | ||
error = jvmti->IterateOverInstancesOfClass(klass, JVMTI_HEAP_OBJECT_EITHER, | ||
HeapObjectCallback, NULL); | ||
HeapObjectCallback, &tag); | ||
if (error) { | ||
printf("ERROR: JVMTI IterateOverInstancesOfClass failed!%u\n", error); | ||
return JNI_FALSE; | ||
} | ||
|
||
jlong tag = 1; | ||
jint count = 0; | ||
jobject *instances; | ||
error = jvmti->GetObjectsWithTags(1, &tag, &count, &instances, NULL); | ||
|
@@ -90,15 +99,15 @@ Java_com_vdian_vclub_JvmUtils_sumInstanceSize(JNIEnv *env, jclass thisClass, jcl | |
printf("ERROR: JVMTI AddCapabilities failed!%u\n", error); | ||
return JNI_FALSE; | ||
} | ||
//todo 支持并发调用 | ||
//这里用hashCode作为标记 | ||
jlong tag = getClassHashCode(env, klass); | ||
error = jvmti->IterateOverInstancesOfClass(klass, JVMTI_HEAP_OBJECT_EITHER, | ||
HeapObjectCallback, NULL); | ||
HeapObjectCallback, &tag); | ||
if (error) { | ||
printf("ERROR: JVMTI IterateOverInstancesOfClass failed!%u\n", error); | ||
return JNI_FALSE; | ||
} | ||
|
||
jlong tag = 1; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
@@ -144,15 +153,15 @@ Java_com_vdian_vclub_JvmUtils_countInstances(JNIEnv *env, jclass thisClass, jcla | |
printf("ERROR: JVMTI AddCapabilities failed!%u\n", error); | ||
return JNI_FALSE; | ||
} | ||
//todo 支持并发调用 | ||
//这里用hashCode作为标记 | ||
jlong tag = getClassHashCode(env, klass); | ||
error = jvmti->IterateOverInstancesOfClass(klass, JVMTI_HEAP_OBJECT_EITHER, | ||
HeapObjectCallback, NULL); | ||
HeapObjectCallback, &tag); | ||
if (error) { | ||
printf("ERROR: JVMTI IterateOverInstancesOfClass failed!%u\n", error); | ||
return JNI_FALSE; | ||
} | ||
|
||
jlong tag = 1; | ||
jint count = 0; | ||
error = jvmti->GetObjectsWithTags(1, &tag, &count, NULL, NULL); | ||
if (error) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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; 可能存在内存泄漏问题