diff --git a/runtime/jcl/common/mgmtmemory.c b/runtime/jcl/common/mgmtmemory.c index 1d048dd51ee..c42afcbdcda 100644 --- a/runtime/jcl/common/mgmtmemory.c +++ b/runtime/jcl/common/mgmtmemory.c @@ -32,7 +32,7 @@ static UDATA getIndexFromGCID(J9JavaLangManagementData *mgmt, UDATA id); jobject JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getHeapMemoryUsageImpl(JNIEnv *env, jobject beanInstance, jclass memoryUsage, jobject memUsageConstructor) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; jlong used = 0; jlong committed = 0; jmethodID ctor = NULL; @@ -51,7 +51,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getHeapMemoryUsageIm jobject JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getNonHeapMemoryUsageImpl(JNIEnv *env, jobject beanInstance, jclass memoryUsage, jobject memUsageConstructor) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9JavaLangManagementData *mgmt = javaVM->managementData; jlong used = 0; jlong committed = 0; @@ -76,25 +76,77 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getNonHeapMemoryUsag omrthread_monitor_enter(javaVM->classTableMutex); classLoader = javaVM->internalVMFunctions->allClassLoadersStartDo(&walkState, javaVM, 0); while (NULL != classLoader) { - UDATA *udataFreeListBlock = classLoader->ramClassUDATABlockFreeList; - J9RAMClassFreeListBlock *tinyFreeListBlock = classLoader->ramClassTinyBlockFreeList; - J9RAMClassFreeListBlock *smallFreeListBlock = classLoader->ramClassSmallBlockFreeList; - J9RAMClassFreeListBlock *largeFreeListBlock = classLoader->ramClassLargeBlockFreeList; - while (NULL != udataFreeListBlock) { - used -= sizeof(UDATA); - udataFreeListBlock = *(UDATA **) udataFreeListBlock; + J9RAMClassUDATABlockFreeList *udataFreeListBlock = &classLoader->ramClassUDATABlocks; + J9RAMClassFreeLists *sub4gFreeListBlock = &classLoader->sub4gBlock; + J9RAMClassFreeLists *freqFreeListBlock = &classLoader->frequentlyAccessedBlock; + J9RAMClassFreeLists *InFreqFreeListBlock = &classLoader->inFrequentlyAccessedBlock; + if (NULL != udataFreeListBlock) { + UDATA *sub4gListBlock = udataFreeListBlock->ramClassSub4gUDATABlockFreeList; + UDATA *freqListBlock = udataFreeListBlock->ramClassFreqUDATABlockFreeList; + UDATA *inFreqListBlock = udataFreeListBlock->ramClassInFreqUDATABlockFreeList; + while (NULL != sub4gListBlock) { + used -= sizeof(UDATA); + sub4gListBlock = *(UDATA **)sub4gListBlock; + } + while (NULL != freqListBlock) { + used -= sizeof(UDATA); + freqListBlock = *(UDATA **)freqListBlock; + } + while (NULL != inFreqListBlock) { + used -= sizeof(UDATA); + inFreqListBlock = *(UDATA **)inFreqListBlock; + } } - while (NULL != tinyFreeListBlock) { - used -= tinyFreeListBlock->size; - tinyFreeListBlock = tinyFreeListBlock->nextFreeListBlock; + if (NULL != sub4gFreeListBlock) { + J9RAMClassFreeListBlock *tinyFreeListBlock = sub4gFreeListBlock->ramClassTinyBlockFreeList; + J9RAMClassFreeListBlock *smallFreeListBlock = sub4gFreeListBlock->ramClassSmallBlockFreeList; + J9RAMClassFreeListBlock *largeFreeListBlock = sub4gFreeListBlock->ramClassLargeBlockFreeList; + while (NULL != tinyFreeListBlock) { + used -= tinyFreeListBlock->size; + tinyFreeListBlock = tinyFreeListBlock->nextFreeListBlock; + } + while (NULL != smallFreeListBlock) { + used -= smallFreeListBlock->size; + smallFreeListBlock = smallFreeListBlock->nextFreeListBlock; + } + while (NULL != largeFreeListBlock) { + used -= largeFreeListBlock->size; + largeFreeListBlock = largeFreeListBlock->nextFreeListBlock; + } } - while (NULL != smallFreeListBlock) { - used -= smallFreeListBlock->size; - smallFreeListBlock = smallFreeListBlock->nextFreeListBlock; + if (NULL != freqFreeListBlock) { + J9RAMClassFreeListBlock *tinyFreeListBlock = freqFreeListBlock->ramClassTinyBlockFreeList; + J9RAMClassFreeListBlock *smallFreeListBlock = freqFreeListBlock->ramClassSmallBlockFreeList; + J9RAMClassFreeListBlock *largeFreeListBlock = freqFreeListBlock->ramClassLargeBlockFreeList; + while (NULL != tinyFreeListBlock) { + used -= tinyFreeListBlock->size; + tinyFreeListBlock = tinyFreeListBlock->nextFreeListBlock; + } + while (NULL != smallFreeListBlock) { + used -= smallFreeListBlock->size; + smallFreeListBlock = smallFreeListBlock->nextFreeListBlock; + } + while (NULL != largeFreeListBlock) { + used -= largeFreeListBlock->size; + largeFreeListBlock = largeFreeListBlock->nextFreeListBlock; + } } - while (NULL != largeFreeListBlock) { - used -= largeFreeListBlock->size; - largeFreeListBlock = largeFreeListBlock->nextFreeListBlock; + if (NULL != InFreqFreeListBlock) { + J9RAMClassFreeListBlock *tinyFreeListBlock = InFreqFreeListBlock->ramClassTinyBlockFreeList; + J9RAMClassFreeListBlock *smallFreeListBlock = InFreqFreeListBlock->ramClassSmallBlockFreeList; + J9RAMClassFreeListBlock *largeFreeListBlock = InFreqFreeListBlock->ramClassLargeBlockFreeList; + while (NULL != tinyFreeListBlock) { + used -= tinyFreeListBlock->size; + tinyFreeListBlock = tinyFreeListBlock->nextFreeListBlock; + } + while (NULL != smallFreeListBlock) { + used -= smallFreeListBlock->size; + smallFreeListBlock = smallFreeListBlock->nextFreeListBlock; + } + while (NULL != largeFreeListBlock) { + used -= largeFreeListBlock->size; + largeFreeListBlock = largeFreeListBlock->nextFreeListBlock; + } } classLoader = javaVM->internalVMFunctions->allClassLoadersNextDo(&walkState); } @@ -166,7 +218,7 @@ jint JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getObjectPendingFinalizationCountImpl(JNIEnv *env, jobject beanInstance) { #if defined(J9VM_GC_FINALIZATION) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; return (jint)javaVM->memoryManagerFunctions->j9gc_get_objects_pending_finalization_count(javaVM); #else return (jint)0; @@ -176,7 +228,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getObjectPendingFina jboolean JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_isVerboseImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; return VERBOSE_GC == (VERBOSE_GC & javaVM->verboseLevel) ; } @@ -184,7 +236,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_isVerboseImpl(JNIEnv void JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setVerboseImpl(JNIEnv *env, jobject beanInstance, jboolean flag) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9VerboseSettings verboseOptions; memset(&verboseOptions, 0, sizeof(J9VerboseSettings)); @@ -197,7 +249,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setVerboseImpl(JNIEn void JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_createMemoryManagers(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; jclass memBean = NULL; jstring childName = NULL; jmethodID helperID = NULL; @@ -234,7 +286,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_createMemoryManagers } for (idx = 0; idx < mgmt->supportedCollectors; ++idx) { - id = (jint) mgmt->garbageCollectors[idx].id; + id = (jint)mgmt->garbageCollectors[idx].id; childName = (*env)->NewStringUTF(env, mgmt->garbageCollectors[idx].name); if (NULL == childName) { return; @@ -247,7 +299,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_createMemoryManagers void JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_createMemoryPools(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; jclass memBean = NULL; jstring childName = NULL; jmethodID helperID = NULL; @@ -267,7 +319,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_createMemoryPools(JN /* Heap Memory Pools */ for (idx = 0; idx < mgmt->supportedMemoryPools; ++idx) { - id = (jint) mgmt->memoryPools[idx].id; + id = (jint)mgmt->memoryPools[idx].id; childName = (*env)->NewStringUTF(env, mgmt->memoryPools[idx].name); if (NULL == childName) { return; @@ -281,7 +333,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_createMemoryPools(JN /* NonHeap Memory Pools */ for (idx = 0; idx < mgmt->supportedNonHeapMemoryPools; ++idx) { - id = (jint) mgmt->nonHeapMemoryPools[idx].id; + id = (jint)mgmt->nonHeapMemoryPools[idx].id; childName = (*env)->NewStringUTF(env, mgmt->nonHeapMemoryPools[idx].name); if (NULL == childName) { return; @@ -297,7 +349,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_createMemoryPools(JN jlong JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMaxHeapSizeLimitImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; return javaVM->memoryManagerFunctions->j9gc_get_maximum_heap_size(javaVM); } @@ -305,7 +357,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMaxHeapSizeLimitI jlong JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMaxHeapSizeImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; UDATA softmx = javaVM->memoryManagerFunctions->j9gc_get_softmx(javaVM); /* if no softmx has been set, report -Xmx instead as it is the current max heap size */ @@ -318,7 +370,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMaxHeapSizeImpl(J jlong JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMinHeapSizeImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; return javaVM->memoryManagerFunctions->j9gc_get_initial_heap_size(javaVM); } @@ -326,7 +378,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMinHeapSizeImpl(J void JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setMaxHeapSizeImpl(JNIEnv *env, jobject beanInstance, jlong newsoftmx) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; javaVM->memoryManagerFunctions->j9gc_set_softmx(javaVM, (UDATA)newsoftmx); } @@ -337,7 +389,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setSharedClassCacheS jboolean ret = JNI_FALSE; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { if (0 != javaVM->sharedClassConfig->setMinMaxBytes(javaVM, (U_32)value, -1, -1, -1, -1)) { @@ -354,7 +406,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setSharedClassCacheM jboolean ret = JNI_FALSE; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { if (0 != javaVM->sharedClassConfig->setMinMaxBytes(javaVM, (U_32)-1, (I_32)value, -1, -1, -1)) { @@ -371,7 +423,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setSharedClassCacheM jboolean ret = JNI_FALSE; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { if (0 != javaVM->sharedClassConfig->setMinMaxBytes(javaVM, (U_32)-1, -1, (I_32)value, -1, -1)) { @@ -388,7 +440,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setSharedClassCacheM jboolean ret = JNI_FALSE; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { if (0 != javaVM->sharedClassConfig->setMinMaxBytes(javaVM, (U_32)-1, -1, -1, (I_32)value, -1)) { @@ -405,7 +457,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_setSharedClassCacheM jboolean ret = JNI_FALSE; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { if (0 != javaVM->sharedClassConfig->setMinMaxBytes(javaVM, (U_32)-1, -1, -1, -1, (I_32)value)) { @@ -422,7 +474,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getSharedClassCacheS U_32 ret = 0; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { javaVM->sharedClassConfig->getUnstoredBytes(javaVM, &ret, NULL, NULL); @@ -437,7 +489,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getSharedClassCacheM U_32 ret = 0; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { javaVM->sharedClassConfig->getUnstoredBytes(javaVM, NULL, &ret, NULL); @@ -452,7 +504,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getSharedClassCacheM U_32 ret = 0; #if defined(J9VM_OPT_SHARED_CLASSES) - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; if (javaVM->sharedClassConfig) { javaVM->sharedClassConfig->getUnstoredBytes(javaVM, NULL, NULL, &ret); @@ -470,7 +522,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_isSetMaxHeapSizeSupp jstring JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getGCModeImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; const char *gcMode = javaVM->memoryManagerFunctions->j9gc_get_gcmodestring(javaVM); if (NULL != gcMode) { @@ -483,7 +535,7 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getGCModeImpl(JNIEnv jlong JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getGCMainThreadCpuUsedImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9JavaLangManagementData *mgmt = javaVM->managementData; jlong result = 0; @@ -497,12 +549,12 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getGCMainThreadCpuUs jlong JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getGCWorkerThreadsCpuUsedImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9JavaLangManagementData *mgmt = javaVM->managementData; jlong result = 0; omrthread_rwmutex_enter_read(mgmt->managementDataLock); - result = (jlong) mgmt->gcWorkerCpuTime; + result = (jlong)mgmt->gcWorkerCpuTime; omrthread_rwmutex_exit_read(mgmt->managementDataLock); return result; @@ -511,12 +563,12 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getGCWorkerThreadsCp jint JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMaximumGCThreadsImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9JavaLangManagementData *mgmt = javaVM->managementData; jint result = 0; omrthread_rwmutex_enter_read(mgmt->managementDataLock); - result = (jint) mgmt->gcMaxThreads; + result = (jint)mgmt->gcMaxThreads; omrthread_rwmutex_exit_read(mgmt->managementDataLock); return result; @@ -525,12 +577,12 @@ Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getMaximumGCThreadsI jint JNICALL Java_com_ibm_java_lang_management_internal_MemoryMXBeanImpl_getCurrentGCThreadsImpl(JNIEnv *env, jobject beanInstance) { - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9JavaLangManagementData *mgmt = javaVM->managementData; jint result = 0; omrthread_rwmutex_enter_read(mgmt->managementDataLock); - result = (jint) mgmt->gcCurrentThreads; + result = (jint)mgmt->gcCurrentThreads; omrthread_rwmutex_exit_read(mgmt->managementDataLock); return result; @@ -541,7 +593,7 @@ void JNICALL Java_com_ibm_lang_management_internal_MemoryNotificationThread_processNotificationLoop(JNIEnv *env, jobject threadInstance) { /* currently, the only notification queue is for the heap */ - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9JavaLangManagementData *mgmt = javaVM->managementData; jclass threadClass = NULL; jclass stringClass = NULL; @@ -726,7 +778,7 @@ Java_com_ibm_lang_management_internal_MemoryNotificationThread_processNotificati } else { /* dispatch usage threshold Notification */ memoryPoolUsageThreshold *usageThreshold = notification->usageThreshold; - idx = (U_32) getIndexFromMemoryPoolID(mgmt, usageThreshold->poolID); + idx = (U_32)getIndexFromMemoryPoolID(mgmt, usageThreshold->poolID); pool = &mgmt->memoryPools[idx]; poolName = poolNames[idx]; if (THRESHOLD_EXCEEDED == notification->type) { @@ -788,7 +840,7 @@ void JNICALL Java_com_ibm_lang_management_internal_MemoryNotificationThreadShutdown_sendShutdownNotification(JNIEnv *env, jobject instance) { /* currently, the only queue is the heap usage notification queue */ - J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; + J9JavaVM *javaVM = ((J9VMThread *)env)->javaVM; J9JavaLangManagementData *mgmt = javaVM->managementData; J9MemoryNotification *notification = NULL; J9MemoryNotification *next = NULL; diff --git a/runtime/oti/j9nonbuilder.h b/runtime/oti/j9nonbuilder.h index b43c55a3aa3..bf7a881872c 100644 --- a/runtime/oti/j9nonbuilder.h +++ b/runtime/oti/j9nonbuilder.h @@ -3569,6 +3569,17 @@ typedef struct J9HookedNative { } J9HookedNative; /* @ddr_namespace: map_to_type=J9ClassLoader */ +typedef struct J9RAMClassFreeLists { + struct J9RAMClassFreeListBlock* ramClassTinyBlockFreeList; + struct J9RAMClassFreeListBlock* ramClassSmallBlockFreeList; + struct J9RAMClassFreeListBlock* ramClassLargeBlockFreeList; +} J9RAMClassFreeLists; + +typedef struct J9RAMClassUDATABlockFreeList { + UDATA *ramClassSub4gUDATABlockFreeList; + UDATA *ramClassFreqUDATABlockFreeList; + UDATA *ramClassInFreqUDATABlockFreeList; +} J9RAMClassUDATABlockFreeList; typedef struct J9ClassLoader { struct J9Pool* sharedLibraries; @@ -3589,10 +3600,10 @@ typedef struct J9ClassLoader { #endif /* defined(J9VM_NEEDS_JNI_REDIRECTION) */ struct J9JITExceptionTable* jitMetaDataList; struct J9MemorySegment* classSegments; - struct J9RAMClassFreeListBlock* ramClassLargeBlockFreeList; - struct J9RAMClassFreeListBlock* ramClassSmallBlockFreeList; - struct J9RAMClassFreeListBlock* ramClassTinyBlockFreeList; - UDATA* ramClassUDATABlockFreeList; + struct J9RAMClassFreeLists sub4gBlock; + struct J9RAMClassFreeLists frequentlyAccessedBlock; + struct J9RAMClassFreeLists inFrequentlyAccessedBlock; + struct J9RAMClassUDATABlockFreeList ramClassUDATABlocks; struct J9HashTable* redefinedClasses; struct J9NativeLibrary* librariesHead; struct J9NativeLibrary* librariesTail; diff --git a/runtime/vm/createramclass.cpp b/runtime/vm/createramclass.cpp index 50950788c96..b0e6efafc14 100644 --- a/runtime/vm/createramclass.cpp +++ b/runtime/vm/createramclass.cpp @@ -108,6 +108,12 @@ typedef struct J9RAMClassFreeListLargeBlock { UDATA maxSizeInList; } J9RAMClassFreeListLargeBlock; +enum SegmentKind { + SUB4G = 0, + FREQUENTLY_ACCESSED, + INFREQUENTLY_ACCESSED +}; + typedef struct RAMClassAllocationRequest { UDATA prefixSize; UDATA alignment; @@ -115,6 +121,7 @@ typedef struct RAMClassAllocationRequest { UDATA *address; UDATA index; UDATA fragmentSize; + SegmentKind segmentKind; struct RAMClassAllocationRequest *next; } RAMClassAllocationRequest; @@ -575,7 +582,7 @@ addInterfaceMethods(J9VMThread *vmStruct, J9ClassLoader *classLoader, J9Class *i const UDATA combinedModifiers = J9_ROM_METHOD_FROM_RAM_METHOD(interfaceMethod)->modifiers | vTableMethod->modifiers; if (J9_ARE_ANY_BITS_SET(combinedModifiers, J9AccAbstract)) { /* Convert to equivSet by adding the existing vtable method to the equivSet */ - J9EquivalentEntry *entry = (J9EquivalentEntry*) pool_newElement(equivalentSets); + J9EquivalentEntry *entry = (J9EquivalentEntry*)pool_newElement(equivalentSets); if (NULL == entry) { /* OOM will be thrown */ goto fail; @@ -608,7 +615,7 @@ addInterfaceMethods(J9VMThread *vmStruct, J9ClassLoader *classLoader, J9Class *i existing_entry = existing_entry->next; } existing_entry = previous_entry; - J9EquivalentEntry * new_entry = (J9EquivalentEntry*) pool_newElement(equivalentSets); + J9EquivalentEntry * new_entry = (J9EquivalentEntry*)pool_newElement(equivalentSets); if (NULL == new_entry) { /* OOM will be thrown */ goto fail; @@ -1495,9 +1502,9 @@ compareRomClassName(void *item, J9StackElement *currentElement) { J9UTF8 *currentRomName; BOOLEAN rc = FALSE; - J9UTF8 *className = J9ROMCLASS_CLASSNAME((J9ROMClass *) item); + J9UTF8 *className = J9ROMCLASS_CLASSNAME((J9ROMClass *)item); - currentRomName = J9ROMCLASS_CLASSNAME((J9ROMClass *) currentElement->element); + currentRomName = J9ROMCLASS_CLASSNAME((J9ROMClass *)currentElement->element); if (0 == compareUTF8Length(J9UTF8_DATA(currentRomName), J9UTF8_LENGTH(currentRomName), J9UTF8_DATA(className), J9UTF8_LENGTH(className))) { @@ -1574,7 +1581,7 @@ verifyLoadingOrLinkingStack(J9VMThread *vmThread, J9ClassLoader *classLoader, vo setNativeOutOfMemoryError(vmThread, 0, 0); return FALSE; } - newTopOfStack->element = (void *) clazz; + newTopOfStack->element = (void *)clazz; newTopOfStack->previous = *stack; newTopOfStack->classLoader = classLoader; *stack = newTopOfStack; @@ -2022,7 +2029,7 @@ loadFlattenableFieldValueClasses(J9VMThread *currentThread, J9ClassLoader *class } else { if (J9_ARE_ALL_BITS_SET(modifiers, J9FieldFlagIsNullRestricted)) { J9FlattenedClassCacheEntry *entry = J9_VM_FCC_ENTRY_FROM_FCC(flattenedClassCache, flattenableFieldCount); - entry->clazz = (J9Class *) J9_VM_FCC_CLASS_FLAGS_STATIC_FIELD; + entry->clazz = (J9Class *)J9_VM_FCC_CLASS_FLAGS_STATIC_FIELD; entry->field = field; entry->offset = UDATA_MAX; flattenableFieldCount += 1; @@ -2527,7 +2534,7 @@ trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader static void initializeClassLinks(J9Class *ramClass, J9Class *superclass, J9MemorySegment *segment, UDATA options) { - ramClass->nextClassInSegment = *(J9Class **) segment->heapBase; + ramClass->nextClassInSegment = *(J9Class **)segment->heapBase; *(J9Class **)segment->heapBase = ramClass; ramClass->subclassTraversalLink = ramClass; @@ -2864,9 +2871,9 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas omrthread_monitor_exit(bcvd->verifierMutex); #if JAVA_SPEC_VERSION >= 16 - setCurrentExceptionUTF(vmThread, J9VMCONSTANTPOOL_JAVALANGINCOMPATIBLECLASSCHANGEERROR, (char *) verifyErrorString); + setCurrentExceptionUTF(vmThread, J9VMCONSTANTPOOL_JAVALANGINCOMPATIBLECLASSCHANGEERROR, (char *)verifyErrorString); #else /* JAVA_SPEC_VERSION >= 16 */ - setCurrentExceptionUTF(vmThread, J9VMCONSTANTPOOL_JAVALANGVERIFYERROR, (char *) verifyErrorString); + setCurrentExceptionUTF(vmThread, J9VMCONSTANTPOOL_JAVALANGVERIFYERROR, (char *)verifyErrorString); #endif /* JAVA_SPEC_VERSION >= 16 */ j9mem_free_memory(verifyErrorString); @@ -2903,12 +2910,14 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas allocationRequests[RAM_CLASS_HEADER_FRAGMENT].alignment = J9_REQUIRED_CLASS_ALIGNMENT; allocationRequests[RAM_CLASS_HEADER_FRAGMENT].alignedSize = sizeof(J9Class) + vTableSlots * sizeof(UDATA); allocationRequests[RAM_CLASS_HEADER_FRAGMENT].address = NULL; + allocationRequests[RAM_CLASS_HEADER_FRAGMENT].segmentKind = SUB4G; /* RAM methods fragment */ allocationRequests[RAM_METHODS_FRAGMENT].prefixSize = extendedMethodBlockSize * sizeof(UDATA); allocationRequests[RAM_METHODS_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_METHODS_FRAGMENT].alignedSize = (romClass->romMethodCount + defaultConflictCount) * sizeof(J9Method); allocationRequests[RAM_METHODS_FRAGMENT].address = NULL; + allocationRequests[RAM_METHODS_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* superclasses fragment */ allocationRequests[RAM_SUPERCLASSES_FRAGMENT].prefixSize = 0; @@ -2920,36 +2929,42 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas } allocationRequests[RAM_SUPERCLASSES_FRAGMENT].alignedSize = OMR_MAX(superclassSizeBytes, minimumSuperclassArraySizeBytes); allocationRequests[RAM_SUPERCLASSES_FRAGMENT].address = NULL; + allocationRequests[RAM_SUPERCLASSES_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* instance description fragment */ allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].prefixSize = 0; allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].alignedSize = instanceDescriptionSlotCount * sizeof(UDATA); allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].address = NULL; + allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* iTable fragment */ allocationRequests[RAM_ITABLE_FRAGMENT].prefixSize = 0; allocationRequests[RAM_ITABLE_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_ITABLE_FRAGMENT].alignedSize = iTableSlotCount * sizeof(UDATA); allocationRequests[RAM_ITABLE_FRAGMENT].address = NULL; + allocationRequests[RAM_ITABLE_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* static slots fragment */ allocationRequests[RAM_STATICS_FRAGMENT].prefixSize = 0; allocationRequests[RAM_STATICS_FRAGMENT].alignment = sizeof(U_64); allocationRequests[RAM_STATICS_FRAGMENT].alignedSize = totalStaticSlots * sizeof(UDATA); allocationRequests[RAM_STATICS_FRAGMENT].address = NULL; + allocationRequests[RAM_STATICS_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* constant pool fragment */ allocationRequests[RAM_CONSTANT_POOL_FRAGMENT].prefixSize = 0; allocationRequests[RAM_CONSTANT_POOL_FRAGMENT].alignment = REQUIRED_CONSTANT_POOL_ALIGNMENT; allocationRequests[RAM_CONSTANT_POOL_FRAGMENT].alignedSize = romClass->ramConstantPoolCount * 2 * sizeof(UDATA); allocationRequests[RAM_CONSTANT_POOL_FRAGMENT].address = NULL; + allocationRequests[RAM_CONSTANT_POOL_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* call sites fragment */ allocationRequests[RAM_CALL_SITES_FRAGMENT].prefixSize = 0; allocationRequests[RAM_CALL_SITES_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_CALL_SITES_FRAGMENT].alignedSize = romClass->callSiteCount * sizeof(UDATA); allocationRequests[RAM_CALL_SITES_FRAGMENT].address = NULL; + allocationRequests[RAM_CALL_SITES_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; #if defined(J9VM_OPT_OPENJDK_METHODHANDLE) /* invoke cache fragment */ @@ -2957,17 +2972,20 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas allocationRequests[RAM_INVOKE_CACHE_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_INVOKE_CACHE_FRAGMENT].alignedSize = romClass->invokeCacheCount * sizeof(UDATA); allocationRequests[RAM_INVOKE_CACHE_FRAGMENT].address = NULL; + allocationRequests[RAM_INVOKE_CACHE_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; #else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ /* method types fragment */ allocationRequests[RAM_METHOD_TYPES_FRAGMENT].prefixSize = 0; allocationRequests[RAM_METHOD_TYPES_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_METHOD_TYPES_FRAGMENT].alignedSize = romClass->methodTypeCount * sizeof(UDATA); allocationRequests[RAM_METHOD_TYPES_FRAGMENT].address = NULL; + allocationRequests[RAM_METHOD_TYPES_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* varhandle method types fragment */ allocationRequests[RAM_VARHANDLE_METHOD_TYPES_FRAGMENT].prefixSize = 0; allocationRequests[RAM_VARHANDLE_METHOD_TYPES_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_VARHANDLE_METHOD_TYPES_FRAGMENT].alignedSize = romClass->varHandleMethodTypeCount * sizeof(UDATA); allocationRequests[RAM_VARHANDLE_METHOD_TYPES_FRAGMENT].address = NULL; + allocationRequests[RAM_VARHANDLE_METHOD_TYPES_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; #endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ /* static split table fragment */ @@ -2975,12 +2993,14 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas allocationRequests[RAM_STATIC_SPLIT_TABLE_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_STATIC_SPLIT_TABLE_FRAGMENT].alignedSize = romClass->staticSplitMethodRefCount * sizeof(J9Method *); allocationRequests[RAM_STATIC_SPLIT_TABLE_FRAGMENT].address = NULL; + allocationRequests[RAM_STATIC_SPLIT_TABLE_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* special split table fragment */ allocationRequests[RAM_SPECIAL_SPLIT_TABLE_FRAGMENT].prefixSize = 0; allocationRequests[RAM_SPECIAL_SPLIT_TABLE_FRAGMENT].alignment = sizeof(UDATA); allocationRequests[RAM_SPECIAL_SPLIT_TABLE_FRAGMENT].alignedSize = romClass->specialSplitMethodRefCount * sizeof(J9Method *); allocationRequests[RAM_SPECIAL_SPLIT_TABLE_FRAGMENT].address = NULL; + allocationRequests[RAM_SPECIAL_SPLIT_TABLE_FRAGMENT].segmentKind = FREQUENTLY_ACCESSED; /* flattened classes cache */ #if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) @@ -2992,17 +3012,18 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas allocationRequests[RAM_CLASS_FLATTENED_CLASS_CACHE].alignment = OMR_MAX(sizeof(J9Class *), sizeof(UDATA)); allocationRequests[RAM_CLASS_FLATTENED_CLASS_CACHE].alignedSize = flattenedClassCacheAllocSize; allocationRequests[RAM_CLASS_FLATTENED_CLASS_CACHE].address = NULL; + allocationRequests[RAM_CLASS_FLATTENED_CLASS_CACHE].segmentKind = FREQUENTLY_ACCESSED; #endif /* J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES */ if (fastHCR) { /* For shared fragments, set alignedSize and prefixSize to 0 to make internalAllocateRAMClass() ignore them. */ - allocationRequests[RAM_SUPERCLASSES_FRAGMENT].address = (UDATA *) classBeingRedefined->superclasses; + allocationRequests[RAM_SUPERCLASSES_FRAGMENT].address = (UDATA *)classBeingRedefined->superclasses; allocationRequests[RAM_SUPERCLASSES_FRAGMENT].prefixSize = 0; allocationRequests[RAM_SUPERCLASSES_FRAGMENT].alignedSize = 0; allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].address = classBeingRedefined->instanceDescription; allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].prefixSize = 0; allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].alignedSize = 0; - allocationRequests[RAM_ITABLE_FRAGMENT].address = (UDATA *) classBeingRedefined->iTable; + allocationRequests[RAM_ITABLE_FRAGMENT].address = (UDATA *)classBeingRedefined->iTable; allocationRequests[RAM_ITABLE_FRAGMENT].prefixSize = 0; allocationRequests[RAM_ITABLE_FRAGMENT].alignedSize = 0; allocationRequests[RAM_STATICS_FRAGMENT].address = classBeingRedefined->ramStatics; @@ -3012,9 +3033,9 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas segment = internalAllocateRAMClass(javaVM, classLoader, allocationRequests, RAM_CLASS_FRAGMENT_COUNT); if (NULL != segment) { - ramClass = (J9Class *) allocationRequests[RAM_CLASS_HEADER_FRAGMENT].address; + ramClass = (J9Class *)allocationRequests[RAM_CLASS_HEADER_FRAGMENT].address; state->ramClass = ramClass; - ramClass->ramMethods = (J9Method *) allocationRequests[RAM_METHODS_FRAGMENT].address; + ramClass->ramMethods = (J9Method *)allocationRequests[RAM_METHODS_FRAGMENT].address; if (fastHCR) { /* Share iTable and instanceDescription (and associated fields) with class being redefined. */ ramClass->iTable = classBeingRedefined->iTable; @@ -3030,26 +3051,26 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas instanceDescription = allocationRequests[RAM_INSTANCE_DESCRIPTION_FRAGMENT].address; iTable = allocationRequests[RAM_ITABLE_FRAGMENT].address; } - ramClass->superclasses = (J9Class **) allocationRequests[RAM_SUPERCLASSES_FRAGMENT].address; + ramClass->superclasses = (J9Class **)allocationRequests[RAM_SUPERCLASSES_FRAGMENT].address; ramClass->ramStatics = allocationRequests[RAM_STATICS_FRAGMENT].address; - ramClass->ramConstantPool = (J9ConstantPool *) allocationRequests[RAM_CONSTANT_POOL_FRAGMENT].address; - ramClass->callSites = (j9object_t *) allocationRequests[RAM_CALL_SITES_FRAGMENT].address; + ramClass->ramConstantPool = (J9ConstantPool *)allocationRequests[RAM_CONSTANT_POOL_FRAGMENT].address; + ramClass->callSites = (j9object_t *)allocationRequests[RAM_CALL_SITES_FRAGMENT].address; #if defined(J9VM_OPT_OPENJDK_METHODHANDLE) - ramClass->invokeCache = (j9object_t *) allocationRequests[RAM_INVOKE_CACHE_FRAGMENT].address; + ramClass->invokeCache = (j9object_t *)allocationRequests[RAM_INVOKE_CACHE_FRAGMENT].address; #else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ - ramClass->methodTypes = (j9object_t *) allocationRequests[RAM_METHOD_TYPES_FRAGMENT].address; - ramClass->varHandleMethodTypes = (j9object_t *) allocationRequests[RAM_VARHANDLE_METHOD_TYPES_FRAGMENT].address; + ramClass->methodTypes = (j9object_t *)allocationRequests[RAM_METHOD_TYPES_FRAGMENT].address; + ramClass->varHandleMethodTypes = (j9object_t *)allocationRequests[RAM_VARHANDLE_METHOD_TYPES_FRAGMENT].address; #endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ - ramClass->staticSplitMethodTable = (J9Method **) allocationRequests[RAM_STATIC_SPLIT_TABLE_FRAGMENT].address; + ramClass->staticSplitMethodTable = (J9Method **)allocationRequests[RAM_STATIC_SPLIT_TABLE_FRAGMENT].address; for (U_16 i = 0; i < romClass->staticSplitMethodRefCount; ++i) { ramClass->staticSplitMethodTable[i] = (J9Method*)javaVM->initialMethods.initialStaticMethod; } - ramClass->specialSplitMethodTable = (J9Method **) allocationRequests[RAM_SPECIAL_SPLIT_TABLE_FRAGMENT].address; + ramClass->specialSplitMethodTable = (J9Method **)allocationRequests[RAM_SPECIAL_SPLIT_TABLE_FRAGMENT].address; for (U_16 i = 0; i < romClass->specialSplitMethodRefCount; ++i) { ramClass->specialSplitMethodTable[i] = (J9Method*)javaVM->initialMethods.initialSpecialMethod; } #if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) - ramClass->flattenedClassCache = (J9FlattenedClassCache *) allocationRequests[RAM_CLASS_FLATTENED_CLASS_CACHE].address; + ramClass->flattenedClassCache = (J9FlattenedClassCache *)allocationRequests[RAM_CLASS_FLATTENED_CLASS_CACHE].address; if (0 != flattenedClassCacheAllocSize) { memcpy(ramClass->flattenedClassCache, flattenedClassCache, flattenedClassCacheAllocSize); } @@ -3316,7 +3337,7 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas initializeRAMClassITable(vmThread, ramClass, superclass, iTable, interfaceHead, maxInterfaceDepth); } /* Ensure that lastITable is never NULL */ - ramClass->lastITable = (J9ITable *) ramClass->iTable; + ramClass->lastITable = (J9ITable *)ramClass->iTable; if (NULL == ramClass->lastITable) { ramClass->lastITable = (J9ITable *) &invalidITable; } @@ -3538,7 +3559,7 @@ internalCreateRAMClassFromROMClass(J9VMThread *vmThread, J9ClassLoader *classLoa UDATA valueTypeFlags = 0; UDATA flattenedClassCacheAllocSize = sizeof(J9FlattenedClassCache) + (sizeof(J9FlattenedClassCacheEntry) * romFieldCount); U_8 flattenedClassCacheBuffer[sizeof(J9FlattenedClassCache) + (sizeof(J9FlattenedClassCacheEntry) * DEFAULT_NUMBER_OF_ENTRIES_IN_FLATTENED_CLASS_CACHE)] = {0}; - J9FlattenedClassCache *flattenedClassCache = (J9FlattenedClassCache *) flattenedClassCacheBuffer; + J9FlattenedClassCache *flattenedClassCache = (J9FlattenedClassCache *)flattenedClassCacheBuffer; PORT_ACCESS_FROM_VMC(vmThread); #endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */ @@ -3668,7 +3689,7 @@ internalCreateRAMClassFromROMClass(J9VMThread *vmThread, J9ClassLoader *classLoa } #if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) if (romFieldCount > DEFAULT_NUMBER_OF_ENTRIES_IN_FLATTENED_CLASS_CACHE) { - flattenedClassCache = (J9FlattenedClassCache *) j9mem_allocate_memory(flattenedClassCacheAllocSize, J9MEM_CATEGORY_CLASSES); + flattenedClassCache = (J9FlattenedClassCache *)j9mem_allocate_memory(flattenedClassCacheAllocSize, J9MEM_CATEGORY_CLASSES); if (NULL == flattenedClassCache) { setNativeOutOfMemoryError(vmThread, 0, 0); omrthread_monitor_enter(javaVM->classTableMutex); @@ -3698,7 +3719,7 @@ internalCreateRAMClassFromROMClass(J9VMThread *vmThread, J9ClassLoader *classLoa result = internalCreateRAMClassFromROMClassImpl(vmThread, classLoader, romClass, options, elementClass, methodRemapArray, entryIndex, locationType, classBeingRedefined, superclass, &state, hostClassLoader, hostClass, module, flattenedClassCache, &valueTypeFlags); - if (flattenedClassCache != (J9FlattenedClassCache *) flattenedClassCacheBuffer) { + if (flattenedClassCache != (J9FlattenedClassCache *)flattenedClassCacheBuffer) { j9mem_free_memory(flattenedClassCache); } #else @@ -3717,12 +3738,12 @@ internalCreateRAMClassFromROMClass(J9VMThread *vmThread, J9ClassLoader *classLoa } static VMINLINE void -addBlockToLargeFreeList(J9ClassLoader *classLoader, J9RAMClassFreeListLargeBlock *block) +addBlockToLargeFreeList(J9ClassLoader *classLoader, J9RAMClassFreeListLargeBlock *block, J9RAMClassFreeLists *blockFreeLists) { - J9RAMClassFreeListLargeBlock *tailBlock = (J9RAMClassFreeListLargeBlock *) classLoader->ramClassLargeBlockFreeList; + J9RAMClassFreeListLargeBlock *tailBlock = (J9RAMClassFreeListLargeBlock *)blockFreeLists->ramClassLargeBlockFreeList; block->nextFreeListBlock = tailBlock; - classLoader->ramClassLargeBlockFreeList = (J9RAMClassFreeListBlock *) block; + blockFreeLists->ramClassLargeBlockFreeList = (J9RAMClassFreeListBlock *)block; if ((NULL != tailBlock) && (tailBlock->maxSizeInList > block->size)) { block->maxSizeInList = tailBlock->maxSizeInList; @@ -3732,7 +3753,7 @@ addBlockToLargeFreeList(J9ClassLoader *classLoader, J9RAMClassFreeListLargeBlock } static void -addBlockToFreeList(J9ClassLoader *classLoader, UDATA address, UDATA size) +addBlockToFreeList(J9ClassLoader *classLoader, UDATA address, UDATA size, J9RAMClassFreeLists *blockFreeLists, UDATA *ramClassUDATABlockFreelist) { if (J9_ARE_ANY_BITS_SET(classLoader->flags, J9CLASSLOADER_ANON_CLASS_LOADER)) { /* We support individual class unloading for anonymous classes, so each anonymous class @@ -3741,20 +3762,20 @@ addBlockToFreeList(J9ClassLoader *classLoader, UDATA address, UDATA size) return; } if (sizeof(UDATA) == size) { - UDATA *block = (UDATA *) address; - *block = (UDATA) classLoader->ramClassUDATABlockFreeList; - classLoader->ramClassUDATABlockFreeList = block; + UDATA *block = (UDATA *)address; + *block = (UDATA)ramClassUDATABlockFreelist; + ramClassUDATABlockFreelist = block; } else if (sizeof(J9RAMClassFreeListBlock) <= size) { - J9RAMClassFreeListBlock *block = (J9RAMClassFreeListBlock *) address; + J9RAMClassFreeListBlock *block = (J9RAMClassFreeListBlock *)address; block->size = size; if (RAM_CLASS_SMALL_FRAGMENT_LIMIT > size) { - block->nextFreeListBlock = classLoader->ramClassTinyBlockFreeList; - classLoader->ramClassTinyBlockFreeList = block; + block->nextFreeListBlock = blockFreeLists->ramClassTinyBlockFreeList; + blockFreeLists->ramClassTinyBlockFreeList = block; } else if (RAM_CLASS_FRAGMENT_LIMIT > size) { - block->nextFreeListBlock = classLoader->ramClassSmallBlockFreeList; - classLoader->ramClassSmallBlockFreeList = block; + block->nextFreeListBlock = blockFreeLists->ramClassSmallBlockFreeList; + blockFreeLists->ramClassSmallBlockFreeList = block; } else { - addBlockToLargeFreeList(classLoader, (J9RAMClassFreeListLargeBlock *) block); + addBlockToLargeFreeList(classLoader, (J9RAMClassFreeListLargeBlock *)block, blockFreeLists); } } } @@ -3765,19 +3786,19 @@ addBlockToFreeList(J9ClassLoader *classLoader, UDATA address, UDATA size) * list to update their maxSizeInList values. */ static void -removeBlockFromLargeFreeList(J9ClassLoader *classLoader, J9RAMClassFreeListLargeBlock **freeListBlockPtr, J9RAMClassFreeListLargeBlock *freeListBlock) +removeBlockFromLargeFreeList(J9ClassLoader *classLoader, J9RAMClassFreeListLargeBlock **freeListBlockPtr, J9RAMClassFreeListLargeBlock *freeListBlock, J9RAMClassFreeLists *blockFreeLists) { J9RAMClassFreeListLargeBlock *nextBlock = freeListBlock->nextFreeListBlock; if ((NULL == nextBlock) || (freeListBlock->maxSizeInList != nextBlock->maxSizeInList)) { /* Re-compute the maxSizeInList values on earlier blocks by re-adding them to the list. */ - J9RAMClassFreeListLargeBlock *block = (J9RAMClassFreeListLargeBlock *) classLoader->ramClassLargeBlockFreeList; + J9RAMClassFreeListLargeBlock *block = (J9RAMClassFreeListLargeBlock *)blockFreeLists->ramClassLargeBlockFreeList; - classLoader->ramClassLargeBlockFreeList = (J9RAMClassFreeListBlock *) freeListBlock->nextFreeListBlock; + blockFreeLists->ramClassLargeBlockFreeList = (J9RAMClassFreeListBlock *)freeListBlock->nextFreeListBlock; while (block != freeListBlock) { J9RAMClassFreeListLargeBlock *nextBlock = block->nextFreeListBlock; - addBlockToLargeFreeList(classLoader, block); + addBlockToLargeFreeList(classLoader, block, blockFreeLists); block = nextBlock; } } else { @@ -3795,11 +3816,11 @@ removeBlockFromLargeFreeList(J9ClassLoader *classLoader, J9RAMClassFreeListLarge * Returns TRUE if the fragment was allocated. */ static BOOLEAN -allocateRAMClassFragmentFromFreeList(RAMClassAllocationRequest *request, J9RAMClassFreeListBlock **freeList, J9ClassLoader *classLoader) +allocateRAMClassFragmentFromFreeList(RAMClassAllocationRequest *request, J9RAMClassFreeListBlock **freeList, J9ClassLoader *classLoader, UDATA *ramClassUDATABlockFreelist, J9RAMClassFreeLists *blockFreeLists) { J9RAMClassFreeListBlock **freeListBlockPtr = freeList; J9RAMClassFreeListBlock *freeListBlock = *freeListBlockPtr; - const BOOLEAN islargeBlocksList = (freeList == &classLoader->ramClassLargeBlockFreeList); + const BOOLEAN islargeBlocksList = (freeList == &blockFreeLists->ramClassLargeBlockFreeList); const UDATA alignmentMask = (request->alignment == sizeof(UDATA)) ? 0 : (request->alignment - 1); const UDATA prefixSize = request->prefixSize; const UDATA fragmentSize = request->fragmentSize; @@ -3807,7 +3828,7 @@ allocateRAMClassFragmentFromFreeList(RAMClassAllocationRequest *request, J9RAMCl if (islargeBlocksList) { /* Fail fast if the requested size is larger than anything in the free list. */ - if (fragmentSize + alignmentMask > ((J9RAMClassFreeListLargeBlock *) freeListBlock)->maxSizeInList) { + if (fragmentSize + alignmentMask > ((J9RAMClassFreeListLargeBlock *)freeListBlock)->maxSizeInList) { return FALSE; } } @@ -3816,7 +3837,7 @@ allocateRAMClassFragmentFromFreeList(RAMClassAllocationRequest *request, J9RAMCl while (NULL != freeListBlock) { /* Allocate from the start of the block */ - UDATA addressForAlignedArea = ((UDATA) freeListBlock) + prefixSize; + UDATA addressForAlignedArea = ((UDATA)freeListBlock) + prefixSize; UDATA alignmentMod = addressForAlignedArea & alignmentMask; UDATA alignmentShift = (0 == alignmentMod) ? 0 : (alignment - alignmentMod); @@ -3828,7 +3849,7 @@ allocateRAMClassFragmentFromFreeList(RAMClassAllocationRequest *request, J9RAMCl Trc_VM_internalAllocateRAMClass_AllocatedFromFreeList(request->index, freeListBlock, freeListBlock->size, request->address, request->prefixSize, request->alignedSize, request->alignment); if (islargeBlocksList) { - removeBlockFromLargeFreeList(classLoader, (J9RAMClassFreeListLargeBlock **) freeListBlockPtr, (J9RAMClassFreeListLargeBlock *) freeListBlock); + removeBlockFromLargeFreeList(classLoader, (J9RAMClassFreeListLargeBlock **)freeListBlockPtr, (J9RAMClassFreeListLargeBlock *)freeListBlock, blockFreeLists); } else { *freeListBlockPtr = freeListBlock->nextFreeListBlock; freeListBlock->nextFreeListBlock = NULL; @@ -3836,12 +3857,12 @@ allocateRAMClassFragmentFromFreeList(RAMClassAllocationRequest *request, J9RAMCl /* Add a new block with the remaining space at the start of this block, if any, to an appropriate free list */ if (0 != alignmentShift) { - addBlockToFreeList(classLoader, (UDATA) freeListBlock, alignmentShift); + addBlockToFreeList(classLoader, (UDATA)freeListBlock, alignmentShift, blockFreeLists, ramClassUDATABlockFreelist); } /* Add a new block with the remaining space at the end of this block, if any, to an appropriate free list */ if (0 != newBlockSize) { - addBlockToFreeList(classLoader, ((UDATA) freeListBlock) + alignmentShift + request->fragmentSize, newBlockSize); + addBlockToFreeList(classLoader, ((UDATA)freeListBlock) + alignmentShift + request->fragmentSize, newBlockSize, blockFreeLists, ramClassUDATABlockFreelist); } return TRUE; @@ -3855,6 +3876,73 @@ allocateRAMClassFragmentFromFreeList(RAMClassAllocationRequest *request, J9RAMCl return FALSE; } +/** + * Allocates fragments from free list. + */ +static void +allocateFreeListBlock (RAMClassAllocationRequest *request, J9ClassLoader *classLoader, RAMClassAllocationRequest *prev, J9RAMClassFreeLists *blockFreeLists, UDATA *ramClassUDATABlockFreelist) +{ + if ((sizeof(UDATA) == request->fragmentSize) + && (NULL != ramClassUDATABlockFreelist) + ) { + UDATA *block = ramClassUDATABlockFreelist; + if (sizeof(UDATA) == request->alignment) { + request->address = ramClassUDATABlockFreelist; + ramClassUDATABlockFreelist = *(UDATA **)ramClassUDATABlockFreelist; + } else { + UDATA **blockPtr = &ramClassUDATABlockFreelist; + while (NULL != block) { + /* Check alignment constraint */ + if (0 == (((UDATA)block) & (request->alignment - 1))) { + /* Unhook block from list */ + *blockPtr = *(UDATA **)block; + *block = (UDATA)NULL; + + /* Record allocation & adjust for alignment */ + request->address = block; + break; + } + + /* Advance to next block */ + blockPtr = *(UDATA ***)block; + block = *blockPtr; + } + } + if (NULL != request->address) { + if (request->prefixSize != 0) { + request->address++; + } + Trc_VM_internalAllocateRAMClass_AllocatedFromFreeList(request->index, block, sizeof(UDATA), request->address, request->prefixSize, request->alignedSize, request->alignment); + prev->next = request->next; + return; + } + } + + if ((RAM_CLASS_SMALL_FRAGMENT_LIMIT > request->fragmentSize) + && (NULL != blockFreeLists->ramClassTinyBlockFreeList) + ) { + if (allocateRAMClassFragmentFromFreeList(request, &blockFreeLists->ramClassTinyBlockFreeList, classLoader, ramClassUDATABlockFreelist, blockFreeLists)) { + prev->next = request->next; + return; + } + } + /* Avoid scanning the small free block list to allocate RAM class headers. The alignment constraint will rarely be satisfied. */ + if ((RAM_CLASS_FRAGMENT_LIMIT > request->fragmentSize + request->alignment) + && (NULL != blockFreeLists->ramClassSmallBlockFreeList) + ) { + if (allocateRAMClassFragmentFromFreeList(request, &blockFreeLists->ramClassSmallBlockFreeList, classLoader, ramClassUDATABlockFreelist, blockFreeLists)) { + prev->next = request->next; + return; + } + } + if (NULL != blockFreeLists->ramClassLargeBlockFreeList) { + if (allocateRAMClassFragmentFromFreeList(request, &blockFreeLists->ramClassLargeBlockFreeList, classLoader, ramClassUDATABlockFreelist, blockFreeLists)) { + prev->next = request->next; + return; + } + } +} + /** * Allocates fragments for a RAM class. * @@ -3917,57 +4005,12 @@ internalAllocateRAMClass(J9JavaVM *javaVM, J9ClassLoader *classLoader, RAMClassA dummyHead.next = requests; prev = &dummyHead; for (request = requests; NULL != request; request = request->next) { - if ((sizeof(UDATA) == request->fragmentSize) && (NULL != classLoader->ramClassUDATABlockFreeList)) { - UDATA *block = classLoader->ramClassUDATABlockFreeList; - if (sizeof(UDATA) == request->alignment) { - request->address = classLoader->ramClassUDATABlockFreeList; - classLoader->ramClassUDATABlockFreeList = *(UDATA **) classLoader->ramClassUDATABlockFreeList; - } else { - UDATA **blockPtr = &classLoader->ramClassUDATABlockFreeList; - while (NULL != block) { - /* Check alignment constraint */ - if (0 == (((UDATA) block) & (request->alignment - 1))) { - /* Unhook block from list */ - *blockPtr = *(UDATA **) block; - *block = (UDATA) NULL; - - /* Record allocation & adjust for alignment */ - request->address = block; - break; - } - - /* Advance to next block */ - blockPtr = *(UDATA ***) block; - block = *blockPtr; - } - } - if (NULL != request->address) { - if (request->prefixSize != 0) { - request->address++; - } - Trc_VM_internalAllocateRAMClass_AllocatedFromFreeList(request->index, block, sizeof(UDATA), request->address, request->prefixSize, request->alignedSize, request->alignment); - prev->next = request->next; - continue; - } - } - if ((RAM_CLASS_SMALL_FRAGMENT_LIMIT > request->fragmentSize) && (NULL != classLoader->ramClassTinyBlockFreeList)) { - if (allocateRAMClassFragmentFromFreeList(request, &classLoader->ramClassTinyBlockFreeList, classLoader)) { - prev->next = request->next; - continue; - } - } - /* Avoid scanning the small free block list to allocate RAM class headers. The alignment constraint will rarely be satisfied. */ - if ((RAM_CLASS_FRAGMENT_LIMIT > request->fragmentSize + request->alignment) && (NULL != classLoader->ramClassSmallBlockFreeList)) { - if (allocateRAMClassFragmentFromFreeList(request, &classLoader->ramClassSmallBlockFreeList, classLoader)) { - prev->next = request->next; - continue; - } - } - if (NULL != classLoader->ramClassLargeBlockFreeList) { - if (allocateRAMClassFragmentFromFreeList(request, &classLoader->ramClassLargeBlockFreeList, classLoader)) { - prev->next = request->next; - continue; - } + if(SUB4G == request->segmentKind) { + allocateFreeListBlock (request, classLoader, prev, &classLoader->sub4gBlock, classLoader->ramClassUDATABlocks.ramClassSub4gUDATABlockFreeList); + } else if (FREQUENTLY_ACCESSED == request->segmentKind) { + allocateFreeListBlock (request, classLoader, prev, &classLoader->frequentlyAccessedBlock, classLoader->ramClassUDATABlocks.ramClassFreqUDATABlockFreeList); + } else if (INFREQUENTLY_ACCESSED == request->segmentKind) { + allocateFreeListBlock (request, classLoader, prev, &classLoader->inFrequentlyAccessedBlock, classLoader->ramClassUDATABlocks.ramClassInFreqUDATABlockFreeList); } prev = request; } @@ -4005,8 +4048,14 @@ internalAllocateRAMClass(J9JavaVM *javaVM, J9ClassLoader *classLoader, RAMClassA /* TODO attempt to coalesce free blocks? */ for (i = 0; i < allocationRequestCount; i++) { if (NULL != allocationRequests[i].address) { - UDATA fragmentAddress = ((UDATA) allocationRequests[i].address) - allocationRequests[i].prefixSize; - addBlockToFreeList(classLoader, fragmentAddress, allocationRequests[i].fragmentSize); + UDATA fragmentAddress = ((UDATA)allocationRequests[i].address) - allocationRequests[i].prefixSize; + if(SUB4G == allocationRequests[i].segmentKind) { + addBlockToFreeList(classLoader, fragmentAddress, allocationRequests[i].fragmentSize, &classLoader->sub4gBlock, classLoader->ramClassUDATABlocks.ramClassSub4gUDATABlockFreeList); + } else if (FREQUENTLY_ACCESSED == allocationRequests[i].segmentKind) { + addBlockToFreeList(classLoader, fragmentAddress, allocationRequests[i].fragmentSize, &classLoader->frequentlyAccessedBlock, classLoader->ramClassUDATABlocks.ramClassFreqUDATABlockFreeList); + } else if (INFREQUENTLY_ACCESSED == allocationRequests[i].segmentKind) { + addBlockToFreeList(classLoader, fragmentAddress, allocationRequests[i].fragmentSize, &classLoader->inFrequentlyAccessedBlock, classLoader->ramClassUDATABlocks.ramClassInFreqUDATABlockFreeList); + } allocationRequests[i].address = NULL; } } @@ -4016,13 +4065,13 @@ internalAllocateRAMClass(J9JavaVM *javaVM, J9ClassLoader *classLoader, RAMClassA Trc_VM_internalAllocateRAMClass_AllocatedClassMemorySegment(newSegment, newSegment->size, newSegment->heapBase, newSegment->heapTop); /* Initialize the "lastAllocatedClass" pointer */ - *(J9Class **) newSegment->heapBase = NULL; + *(J9Class **)newSegment->heapBase = NULL; /* Bump the heapAlloc pointer to the end - don't use it again */ newSegment->heapAlloc = newSegment->heapTop; /* Allocate the remaining fragments in the new segment, adding holes to the free list */ - allocAddress = ((UDATA) newSegment->heapBase) + sizeof(UDATA); + allocAddress = ((UDATA)newSegment->heapBase) + sizeof(UDATA); for (request = requests; NULL != request; request = request->next) { /* Allocate from the start of the segment */ UDATA addressForAlignedArea = allocAddress + request->prefixSize; @@ -4035,24 +4084,27 @@ internalAllocateRAMClass(J9JavaVM *javaVM, J9ClassLoader *classLoader, RAMClassA /* Add a new block with the remaining space at the start of this block, if any, to an appropriate free list */ if (0 != alignmentShift) { - addBlockToFreeList(classLoader, (UDATA) allocAddress, alignmentShift); + if(SUB4G == request->segmentKind) { + addBlockToFreeList(classLoader, (UDATA)allocAddress, alignmentShift, &classLoader->sub4gBlock, classLoader->ramClassUDATABlocks.ramClassSub4gUDATABlockFreeList); + } else if (FREQUENTLY_ACCESSED == request->segmentKind) { + addBlockToFreeList(classLoader, (UDATA)allocAddress, alignmentShift, &classLoader->frequentlyAccessedBlock, classLoader->ramClassUDATABlocks.ramClassFreqUDATABlockFreeList); + } else if (INFREQUENTLY_ACCESSED == request->segmentKind) { + addBlockToFreeList(classLoader, (UDATA)allocAddress, alignmentShift, &classLoader->inFrequentlyAccessedBlock, classLoader->ramClassUDATABlocks.ramClassInFreqUDATABlockFreeList); + } } - allocAddress += alignmentShift + request->fragmentSize; - fragmentsLeftToAllocate--; - } - + } /* Add a new block with the remaining space at the end of this segment, if any, to an appropriate free list */ - if (allocAddress != (UDATA) newSegment->heapTop) { - addBlockToFreeList(classLoader, allocAddress, ((UDATA) newSegment->heapTop) - allocAddress); + if (allocAddress != (UDATA)newSegment->heapTop) { + addBlockToFreeList(classLoader, (UDATA)allocAddress, ((UDATA)newSegment->heapTop) - allocAddress, &classLoader->inFrequentlyAccessedBlock, classLoader->ramClassUDATABlocks.ramClassInFreqUDATABlockFreeList); } } /* Clear all allocated fragments */ for (i = 0; i < allocationRequestCount; i++) { if (NULL != allocationRequests[i].address) { - memset((void *) (((UDATA) allocationRequests[i].address) - allocationRequests[i].prefixSize), 0, allocationRequests[i].fragmentSize); + memset((void *) (((UDATA)allocationRequests[i].address) - allocationRequests[i].prefixSize), 0, allocationRequests[i].fragmentSize); } }