diff --git a/vm/include/open/hythread_ext.h b/vm/include/open/hythread_ext.h index f9fab3c..c49f0f8 100644 --- a/vm/include/open/hythread_ext.h +++ b/vm/include/open/hythread_ext.h @@ -508,7 +508,6 @@ #define TM_ERROR_START 1000 // possible values for tm_status_t #define TM_OS_ERROR (TM_ERROR_START+1) -#define TM_MAX_OWNED_MONITOR_NUMBER 200 //FIXME: switch to dynamic resize // if default stack size is not through -Xss parameter, it is 256kb #define TM_DEFAULT_STACKSIZE (512 * 1024) diff --git a/vm/vmcore/include/thread_manager.h b/vm/vmcore/include/thread_manager.h index 833fb70..c501f9a 100644 --- a/vm/vmcore/include/thread_manager.h +++ b/vm/vmcore/include/thread_manager.h @@ -25,6 +25,7 @@ #include "exceptions_type.h" #define GC_BYTES_IN_THREAD_LOCAL (20 * sizeof(void *)) #define CONVERT_ERROR(stat) (stat) #define TM_JVMTI_MAX_BUFFER_SIZE 50 +#define TM_INITIAL_OWNED_MONITOR_SIZE 32 #ifdef __cplusplus extern "C" @@ -96,6 +97,11 @@ struct JVMTIThread int owned_monitors_nmb; /** + * owned monitors array size. + */ + int owned_monitors_size; + + /** * For support of JVMTI events: EXCEPTION, EXCEPTION_CATCH * If p_exception_object is set and p_exception_object_ti is not * - EXCEPTION event should be generated diff --git a/vm/vmcore/src/thread/thread_generic.cpp b/vm/vmcore/src/thread/thread_generic.cpp index 72db6b6..e5a8c43 100644 --- a/vm/vmcore/src/thread/thread_generic.cpp +++ b/vm/vmcore/src/thread/thread_generic.cpp @@ -206,9 +206,10 @@ jint vm_attach(JavaVM * java_vm, JNIEnv gc_thread_init(&vm_thread->_gc_private_information); if (ti_is_enabled()) { - vm_thread->jvmti_thread.owned_monitors = - (jobject*)apr_palloc(vm_thread->pool, - sizeof(jobject) * TM_MAX_OWNED_MONITOR_NUMBER); + vm_thread->jvmti_thread.owned_monitors_size = TM_INITIAL_OWNED_MONITOR_SIZE; + vm_thread->jvmti_thread.owned_monitors = (jobject*)apr_palloc(vm_thread->pool, + TM_INITIAL_OWNED_MONITOR_SIZE * sizeof(jobject)); + vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer = (jbyte*)apr_palloc(vm_thread->pool, sizeof(jbyte) * TM_JVMTI_MAX_BUFFER_SIZE); diff --git a/vm/vmcore/src/thread/thread_java_monitors.cpp b/vm/vmcore/src/thread/thread_java_monitors.cpp index 48b2aa1..5e3eb54 100644 --- a/vm/vmcore/src/thread/thread_java_monitors.cpp +++ b/vm/vmcore/src/thread/thread_java_monitors.cpp @@ -398,7 +398,19 @@ static void jthread_add_owned_monitor(jo jvmti_thread->wait_monitor = NULL; } - assert(jvmti_thread->owned_monitors_nmb < TM_MAX_OWNED_MONITOR_NUMBER); + if (jvmti_thread->owned_monitors_nmb >= jvmti_thread->owned_monitors_size) { + int new_size = jvmti_thread->owned_monitors_size * 2; + + TRACE(("Increasing owned_monitors_size to: %d", new_size)); + jobject* new_monitors = (jobject*)apr_palloc(vm_thread->pool, + new_size * sizeof(jobject)); + assert(new_monitors); + memcpy(new_monitors, jvmti_thread->owned_monitors, + jvmti_thread->owned_monitors_size * sizeof(jobject)); + jvmti_thread->owned_monitors = new_monitors; + jvmti_thread->owned_monitors_size = new_size; + } + jvmti_thread->owned_monitors[jvmti_thread->owned_monitors_nmb] = vm_thread->jni_env->NewGlobalRef(monitor); jvmti_thread->owned_monitors_nmb++;