Skip to content

Conversation

@Karina5005
Copy link

No description provided.

@bibaev bibaev requested review from bibaev and nikita-nazarov May 13, 2022 15:03
}

jlongArray RetainedSizeByClassLoadersAction::executeOperation(jobjectArray classLoadersArray) {
std::vector <jlong> result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra space

handleError(jvmti, err, "Could not estimate retained size by classLoaders");
return env->NewLongArray(0);
}
std::cout << "HEAP SIZE: " << getHeapSize() << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since memory agent is a library, it would be better not to pollute stdout, but instead return the result in the format of nested arrays: [[class loaders sizes as jlongs], [other classes size]]

private:
jlongArray executeOperation(jobjectArray classLoadersArray) override;
jvmtiError getRetainedSizeByClassLoaders(jobjectArray classLoadersArray, std::vector<jlong> &result);
jvmtiError tagObjectsByClassLoader(jclass *classes, jint* cnt, jobject classLoader, jsize classLoaderIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asterisks should stick to the variable name

jvmtiError getRetainedSizeByClassLoaders(jobjectArray classLoadersArray, std::vector<jlong> &result);
jvmtiError tagObjectsByClassLoader(jclass *classes, jint* cnt, jobject classLoader, jsize classLoaderIndex);
jlong getHeapSize();
jlong tagOtherObjects(jclass *classes, jint* cnt, jobjectArray classLoadersArray);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asterisks should stick to the variable name

return res;
}

jobjectArray toJavaArray(JNIEnv *env, std::vector <jclass> &objects) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra space

return resultArray;
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting is a little off here

result.resize(env->GetArrayLength(classLoadersArray) + 1);
err = IterateThroughHeap(JVMTI_HEAP_FILTER_UNTAGGED, nullptr, visitObject, result.data(),
"calculate retained size");
return err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return IterateThroughHeap(JVMTI_HEAP_FILTER_UNTAGGED, nullptr, visitObject, result.data(),
                             "calculate retained size");

err = jvmti->GetLoadedClasses(&cnt, &classes);
std::cout << cnt << std::endl;
for (jsize i = 0; i < env->GetArrayLength(classLoadersArray); i++) {
jvmtiError err = tagObjectsByClassLoader(classes, &cnt, env->GetObjectArrayElement(classLoadersArray, i), i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!isOk(err)) return err

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there's no need to declare a new variable here

for (jsize i = 0; i < env->GetArrayLength(classLoadersArray); i++) {
jvmtiError err = tagObjectsByClassLoader(classes, &cnt, env->GetObjectArrayElement(classLoadersArray, i), i);
}
tagOtherObjects(classes, &cnt, classLoadersArray);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err = tagOtherObjects(classes, &cnt, classLoadersArray);
if (!isOk(err)) return err

jlong tagOtherObjects(jclass *classes, jint* cnt, jobjectArray classLoadersArray);
};

jint JNICALL visitObject(jlong classTag, jlong size, jlong *tagPtr, jint length, void *userData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should not be declared here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants