8294370: Fix allocation bug in java_lang_Thread::async_get_stack_trace()

Reviewed-by: dholmes, sspitsyn
This commit is contained in:
Patricio Chilano Mateo 2022-09-29 15:35:41 +00:00
parent ce85cac947
commit 5d48da4574

View File

@ -1934,11 +1934,12 @@ oop java_lang_Thread::async_get_stack_trace(oop java_thread, TRAPS) {
GrowableArray<int>* _bcis; GrowableArray<int>* _bcis;
GetStackTraceClosure(Handle java_thread) : GetStackTraceClosure(Handle java_thread) :
HandshakeClosure("GetStackTraceClosure"), _java_thread(java_thread), _depth(0), _retry_handshake(false) { HandshakeClosure("GetStackTraceClosure"), _java_thread(java_thread), _depth(0), _retry_handshake(false),
// Pick some initial length _methods(nullptr), _bcis(nullptr) {
int init_length = MaxJavaStackTraceDepth / 2; }
_methods = new GrowableArray<Method*>(init_length); ~GetStackTraceClosure() {
_bcis = new GrowableArray<int>(init_length); delete _methods;
delete _bcis;
} }
bool read_reset_retry() { bool read_reset_retry() {
@ -1975,6 +1976,11 @@ oop java_lang_Thread::async_get_stack_trace(oop java_thread, TRAPS) {
const int max_depth = MaxJavaStackTraceDepth; const int max_depth = MaxJavaStackTraceDepth;
const bool skip_hidden = !ShowHiddenFrames; const bool skip_hidden = !ShowHiddenFrames;
// Pick minimum length that will cover most cases
int init_length = 64;
_methods = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<Method*>(init_length, mtInternal);
_bcis = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(init_length, mtInternal);
int total_count = 0; int total_count = 0;
for (vframeStream vfst(thread, false, false, carrier); // we don't process frames as we don't care about oops for (vframeStream vfst(thread, false, false, carrier); // we don't process frames as we don't care about oops
!vfst.at_end() && (max_depth == 0 || max_depth != total_count); !vfst.at_end() && (max_depth == 0 || max_depth != total_count);