Skip to content
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

Limit the number of startup hints in SCC #20366

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions runtime/nls/shrc/j9shr.nls
Original file line number Diff line number Diff line change
Expand Up @@ -6957,3 +6957,36 @@ J9NLS_SHRC_SHRINIT_FAILURE_CREATE_ROMTORAMMUTEX.explanation=The system is unable
J9NLS_SHRC_SHRINIT_FAILURE_CREATE_ROMTORAMMUTEX.system_action=The JVM terminates, unless you have specified the nonfatal option with "-Xshareclasses:nonfatal", in which case the JVM attempts to start up without using Shared Classes.
J9NLS_SHRC_SHRINIT_FAILURE_CREATE_ROMTORAMMUTEX.user_response=System is running low on memory resource for the JVM to start up properly. Check system memory configuration. If the situation persists, contact your service representative.
# END NON-TRANSLATABLE

J9NLS_SHRC_SHRINIT_HELPTEXT_EXTRA_STARTUPHINTS_EQUALS=Adjust the number of additional startup hints allowed to be stored into the shared classes cache to <number>.
# START NON-TRANSLATABLE
J9NLS_SHRC_SHRINIT_HELPTEXT_EXTRA_STARTUPHINTS_EQUALS.explanation=NOTAG
J9NLS_SHRC_SHRINIT_HELPTEXT_EXTRA_STARTUPHINTS_EQUALS.system_action=
J9NLS_SHRC_SHRINIT_HELPTEXT_EXTRA_STARTUPHINTS_EQUALS.user_response=
# END NON-TRANSLATABLE

J9NLS_SHRC_SHRINIT_OPTION_INVALID_PARAM=Invalid parameter passed to option \"%s\".
# START NON-TRANSLATABLE
J9NLS_SHRC_SHRINIT_OPTION_INVALID_PARAM.sample_input_1=extraStartupHints=
J9NLS_SHRC_SHRINIT_OPTION_INVALID_PARAM.explanation=An incorrect parameter has been used in the command-line option
J9NLS_SHRC_SHRINIT_OPTION_INVALID_PARAM.system_action=The JVM terminates.
J9NLS_SHRC_SHRINIT_OPTION_INVALID_PARAM.user_response=Correct or remove the invalid command-line option and rerun.
# END NON-TRANSLATABLE

J9NLS_SHRC_CC_EXTRA_STARTUPHINTS_SET=The number of additional startup hints that can be stored into the shared cache is set to %u.
# START NON-TRANSLATABLE
J9NLS_SHRC_CC_EXTRA_STARTUPHINTS_SET.sample_input_1=64
J9NLS_SHRC_CC_EXTRA_STARTUPHINTS_SET.explanation=The number of additional startup hints allowed to be stored to the shared classes cache has been adjusted.
J9NLS_SHRC_CC_EXTRA_STARTUPHINTS_SET.system_action=The JVM continues.
J9NLS_SHRC_CC_EXTRA_STARTUPHINTS_SET.user_response=No action required. This message is for information only.
# END NON-TRANSLATABLE

J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS=additional startup hints allowed %*.c= %u
# START NON-TRANSLATABLE
J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS.sample_input_1=0
J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS.sample_input_2=
J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS.sample_input_3=8
J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS.explanation=NOTAG
J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS.system_action=
J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS.user_response=
# END NON-TRANSLATABLE
4 changes: 3 additions & 1 deletion runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ typedef struct J9SharedClassJavacoreDataDescriptor {
UDATA startupHintBytes;
UDATA nattach;
UDATA currentOSPageSize; /* memory page size of the current running OS */
U_32 extraStartupHints;
} J9SharedClassJavacoreDataDescriptor;

typedef struct J9SharedStringFarm {
Expand Down Expand Up @@ -1271,7 +1272,7 @@ typedef struct J9SharedCacheHeader {
J9WSRP corruptFlagPtr;
J9SRP sharedStringHead;
J9SRP sharedStringTail;
J9SRP unused1;
U_32 extraStartupHints; /* Number of addtional startup hints allowed to be stored into the shared cache */
U_32 totalSharedStringNodes;
U_32 totalSharedStringWeight;
U_32 readWriteFlags;
Expand Down Expand Up @@ -1354,6 +1355,7 @@ typedef struct J9SharedCacheAPI {
#if defined(J9VM_OPT_JITSERVER)
U_8 usingJITServerAOTCacheLayer;
#endif /* defined(J9VM_OPT_JITSERVER) */
I_32 newStartupHints;
} J9SharedCacheAPI;

typedef struct J9SharedClassConfig {
Expand Down
1 change: 1 addition & 0 deletions runtime/shared/shrclssup.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ IDATA J9VMDllMain(J9JavaVM* vm, IDATA stage, void* reserved)
vm->sharedCacheAPI->minJIT = -1;
vm->sharedCacheAPI->maxJIT = -1;
vm->sharedCacheAPI->layer = -1;
vm->sharedCacheAPI->newStartupHints = -1;
if (index >= 0) {
/* -Xshareclasses is specified */
char optionsBuffer[SHR_SUBOPT_BUFLEN];
Expand Down
34 changes: 34 additions & 0 deletions runtime/shared_common/CacheMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3890,6 +3890,7 @@ SH_CacheMap::storeSharedData(J9VMThread* currentThread, const char* key, UDATA k
UDATA dataNotIndexed = (data != NULL) ? (data->flags & J9SHRDATA_NOT_INDEXED) : 0;
SH_ByteDataManager* localBDM;
bool overwrite = false;
U_32 extraStartupHints = 0;

PORT_ACCESS_FROM_VMC(currentThread);

Expand Down Expand Up @@ -3989,6 +3990,14 @@ SH_CacheMap::storeSharedData(J9VMThread* currentThread, const char* key, UDATA k
}

_addData:
if (J9SHR_DATA_TYPE_STARTUP_HINTS == data->type) {
extraStartupHints = _ccHead->getExtraStartupHints();
if (0 == extraStartupHints) {
result = NULL;
Trc_SHR_CM_storeSharedData_NoMoreStartupHintsAllowed(currentThread);
goto _done;
}
}
/* If data is NULL or datalen <= 0, mark the original item(s) stale, but don't store anything */
if ((data != NULL) && (data->length > 0) && ((data->address != NULL) || (data->flags & J9SHRDATA_ALLOCATE_ZEROD_MEMORY))) {
const J9UTF8* tokenKey = NULL;
Expand Down Expand Up @@ -4021,6 +4030,12 @@ SH_CacheMap::storeSharedData(J9VMThread* currentThread, const char* key, UDATA k
}
}
result = (const U_8*)addByteDataToCache(currentThread, localBDM, tokenKey, data, NULL, false);
if (NULL != result) {
if (J9SHR_DATA_TYPE_STARTUP_HINTS == data->type) {
Trc_SHR_Assert_True(extraStartupHints > 0);
_ccHead->setExtraStartupHints(currentThread, extraStartupHints - 1);
}
}
}

_done:
Expand Down Expand Up @@ -5043,7 +5058,11 @@ SH_CacheMap::printCacheStatsTopLayerStatsHelper(J9VMThread* currentThread, UDATA
if (J9_ARE_ALL_BITS_SET(runtimeFlags, J9SHR_RUNTIMEFLAG_ENABLE_DETAILED_STATS)) {
CACHEMAP_FMTPRINT1(J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_SHRC_CM_PRINTSTATS_SUMMARY_METADATA_STARTADDRESS, javacoreData->metadataStart);
CACHEMAP_FMTPRINT1(J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_SHRC_CM_PRINTSTATS_RUNTIME_FLAGS, javacoreData->runtimeFlags);
CACHEMAP_FMTPRINT1(J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS, javacoreData->extraStartupHints);
CACHEMAP_FMTPRINT1(J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_SHRC_CM_PRINTSTATS_CACHE_GEN, javacoreData->cacheGen);
} else if (J9_ARE_ALL_BITS_SET(showFlags, PRINTSTATS_SHOW_STARTUPHINT)) {
CACHEMAP_FMTPRINT1(J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_SHRC_CM_PRINTSTATS_STARTUP_HINTS, javacoreData->extraStartupHints);
j9tty_printf(_portlib, "\n");
}

CACHEMAP_FMTPRINT1(J9NLS_DO_NOT_PRINT_MESSAGE_TAG, J9NLS_SHRC_CM_PRINTSTATS_CACHE_LAYER, javacoreData->topLayer);
Expand Down Expand Up @@ -7088,3 +7107,18 @@ SH_CacheMap::getDataFromByteDataWrapper(const ByteDataWrapper* bdw)
}
return ret;
}

void
SH_CacheMap::setExtraStartupHints(J9VMThread* currentThread)
{
PORT_ACCESS_FROM_PORT(_portlib);
const char* fnName = "setExtraStartupHints";
U_32 val = (U_32)currentThread->javaVM->sharedCacheAPI->newStartupHints;
if (_ccHead->enterWriteMutex(currentThread, false, fnName) != 0) {
CACHEMAP_TRACE(J9SHR_VERBOSEFLAG_ENABLE_VERBOSE_DEFAULT, J9NLS_ERROR, J9NLS_SHRC_CM_FAILED_ENTER_WRITE_MUTEX);
return;
}
_ccHead->setExtraStartupHints(currentThread, val);
CACHEMAP_TRACE1(J9SHR_VERBOSEFLAG_ENABLE_VERBOSE_DEFAULT, J9NLS_INFO, J9NLS_SHRC_CC_EXTRA_STARTUPHINTS_SET, val);
_ccHead->exitWriteMutex(currentThread, fnName);
}
2 changes: 2 additions & 0 deletions runtime/shared_common/CacheMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ class SH_CacheMap : public SH_SharedCache, public SH_CacheMapStats

bool isAddressInCache(const void *address, UDATA length, bool includeHeaderReadWriteArea, bool useCcHeadOnly) const;

void setExtraStartupHints(J9VMThread* currentThread);

private:
SH_CompositeCacheImpl* _cc; /* current cache */

Expand Down
29 changes: 29 additions & 0 deletions runtime/shared_common/CompositeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "CompositeCacheImpl.hpp"

#define SEMSUFFIX "SHSEM"
#define DEFAULT_STARTUPHINTS 64

/**
* CACHE AREAS
Expand Down Expand Up @@ -157,6 +158,7 @@ SH_CompositeCacheImpl::SH_SharedCacheHeaderInit::init(BlockPtr data, U_32 len, I
ca->writerCount = 0;
ca->softMaxBytes = softMaxBytes;
ca->cacheFullFlags = 0;
ca->extraStartupHints = DEFAULT_STARTUPHINTS;
ca->unused8 = 0;
ca->unused9 = 0;
ca->unused10 = 0;
Expand Down Expand Up @@ -4488,6 +4490,7 @@ SH_CompositeCacheImpl::getJavacoreData(J9JavaVM *vm, J9SharedClassJavacoreDataDe
descriptor->maxJIT = _theca->maxJIT;
descriptor->softMaxBytes = (UDATA)((U_32)-1 == _theca->softMaxBytes ? descriptor->cacheSize : _theca->softMaxBytes);
descriptor->currentOSPageSize = getOSPageSize();
descriptor->extraStartupHints = getExtraStartupHints();
#if defined(J9VM_OPT_JITSERVER)
descriptor->usingJITServerAOTCacheLayer = vm->sharedCacheAPI->usingJITServerAOTCacheLayer;
#endif /* defined(J9VM_OPT_JITSERVER) */
Expand Down Expand Up @@ -6784,3 +6787,29 @@ SH_CompositeCacheImpl::updateMsyncRuntimeFlags(void)
}
}
#endif /* defined(J9VM_OPT_SHR_MSYNC_SUPPORT) */

U_32
SH_CompositeCacheImpl::getExtraStartupHints(void) const
{
if (!_started) {
Trc_SHR_Assert_ShouldNeverHappen();
return 0;
}
return _theca->extraStartupHints;
}

void
SH_CompositeCacheImpl::setExtraStartupHints(J9VMThread* currentThread, U_32 val)
{
if (!_started) {
Trc_SHR_Assert_ShouldNeverHappen();
return;
}
if (_readOnlyOSCache) {
Trc_SHR_Assert_ShouldNeverHappen();
return;
}
Trc_SHR_Assert_True(hasWriteMutex(currentThread));
_theca->extraStartupHints = val;
Trc_SHR_CC_setExtraStartupHints_Event(currentThread, val);
}
5 changes: 4 additions & 1 deletion runtime/shared_common/CompositeCacheImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ class SH_CompositeCacheImpl : public SH_CompositeCache, public AbstractMemoryPer

bool hasReadMutex(J9VMThread* currentThread) const;

U_32 getExtraStartupHints(void) const;

void setExtraStartupHints(J9VMThread* currentThread, U_32 val);

private:
J9SharedClassConfig* _sharedClassConfig;
SH_OSCache* _oscache;
Expand Down Expand Up @@ -581,4 +585,3 @@ class SH_CompositeCacheImpl : public SH_CompositeCache, public AbstractMemoryPer
};

#endif /* !defined(COMPOSITECACHEIMPL_H_INCLUDED) */

2 changes: 2 additions & 0 deletions runtime/shared_common/j9shr.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -3006,3 +3006,5 @@ TraceEvent=Trc_SHR_OSC_Mmap_startup_jitserverlayergooddelete NoEnv Overhead=1 Le
TraceException=Trc_SHR_OSC_Mmap_startup_jitserverlayerbaddelete NoEnv Overhead=1 Level=1 Template="SH_OSCachemmap::startup: deleteCacheFile failed for cache path name = %s, file handle %zd"

TraceEvent=Trc_SHR_CC_OSPAGE_SIZE_MISMATCH_V1 Overhead=1 Level=1 Template="Mismatch in layer %d composite cache osPageSize value. CompositeCache = %p, _theca->osPageSize = %zu, _osPageSize = %zu, _theca->roundedPagesFlag is %u, _readOnlyOSCache is %d"
TraceEvent=Trc_SHR_CC_setExtraStartupHints_Event Overhead=1 Level=6 Template="CC setExtraStartupHints: set extraStartupHints in the header to %u"
TraceEvent=Trc_SHR_CM_storeSharedData_NoMoreStartupHintsAllowed Overhead=1 Level=1 Template="CM storeSharedData: No more startup hints are allowed to be stored"
27 changes: 26 additions & 1 deletion runtime/shared_common/shrinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ J9SharedClassesHelpText J9SHAREDCLASSESHELPTEXT[] = {
{HELPTEXT_ADJUST_MAXAOT_EQUALS, J9NLS_SHRC_SHRINIT_HELPTEXT_ADJUST_MAXAOT_EQUALS, 0, 0},
{HELPTEXT_ADJUST_MINJITDATA_EQUALS, J9NLS_SHRC_SHRINIT_HELPTEXT_ADJUST_MINJIT_EQUALS, 0, 0},
{HELPTEXT_ADJUST_MAXJITDATA_EQUALS, J9NLS_SHRC_SHRINIT_HELPTEXT_ADJUST_MAXJIT_EQUALS, 0, 0},
{HELPTEXT_OPTION_EXTRA_STARTUPHINTS_EQUALS, J9NLS_SHRC_SHRINIT_HELPTEXT_EXTRA_STARTUPHINTS_EQUALS, 0, 0},
#if defined(J9VM_OPT_MULTI_LAYER_SHARED_CLASS_CACHE)
HELPTEXT_NEWLINE,
{HELPTEXT_LAYER_EQUALS,J9NLS_SHRC_SHRINIT_HELPTEXT_LAYER_EQUALS, 0, 0},
Expand Down Expand Up @@ -385,6 +386,7 @@ J9SharedClassesOptions J9SHAREDCLASSESOPTIONS[] = {
#endif /* defined(J9ZOS39064) */
{ OPTION_TEST_DOUBLE_PAGESIZE, PARSE_TYPE_EXACT, RESULT_DO_ADD_RUNTIMEFLAG2, J9SHR_RUNTIMEFLAG2_TEST_DOUBLE_PAGESIZE},
{ OPTION_TEST_HALF_PAGESIZE, PARSE_TYPE_EXACT, RESULT_DO_ADD_RUNTIMEFLAG2, J9SHR_RUNTIMEFLAG2_TEST_HALF_PAGESIZE},
{ OPTION_EXTRA_STARTUPHINTS_EQUALS, PARSE_TYPE_STARTSWITH, RESULT_DO_SET_EXTRA_STARTUPHINTS, 0},
{ NULL, 0, 0 }
};

Expand Down Expand Up @@ -707,6 +709,26 @@ parseArgs(J9JavaVM* vm, char* options, U_64* runtimeFlags, U_64* runtimeFlags2,
options += strlen(OPTION_LAYER_EQUALS)+ (cursor - layerString) +1;
continue;
}
case RESULT_DO_SET_EXTRA_STARTUPHINTS:
{
UDATA temp = 0;
char* optString = options + strlen(OPTION_EXTRA_STARTUPHINTS_EQUALS);
char* cursor = optString;
if (J9_ARE_ALL_BITS_SET(*runtimeFlags, J9SHR_RUNTIMEFLAG_ENABLE_READONLY)) {
*runtimeFlags &= ~J9SHR_RUNTIMEFLAG_ENABLE_READONLY;
SHRINIT_WARNING_TRACE3(verboseFlags, J9NLS_SHRC_SHRINIT_OPTION_IGNORED_WARNING, OPTION_READONLY, OPTION_EXTRA_STARTUPHINTS_EQUALS, OPTION_READONLY);
}
if (scan_udata(&cursor, &temp) == 0) {
vm->sharedCacheAPI->newStartupHints = (I_32)temp;
} else {
SHRINIT_ERR_TRACE1(1, J9NLS_SHRC_SHRINIT_OPTION_INVALID_PARAM, OPTION_EXTRA_STARTUPHINTS_EQUALS);
return RESULT_PARSE_FAILED;
}
options += strlen(OPTION_EXTRA_STARTUPHINTS_EQUALS) + (cursor - optString) + 1;
returnAction = J9SHAREDCLASSESOPTIONS[i].action;
*runtimeFlags |= J9SHR_RUNTIMEFLAG_DO_NOT_CREATE_CACHE;
continue;
}
case RESULT_DO_CREATE_LAYER:
{
vm->sharedCacheAPI->layer = SHRINIT_CREATE_NEW_LAYER;
Expand Down Expand Up @@ -2641,6 +2663,7 @@ performSharedClassesCommandLineAction(J9JavaVM* vm, J9SharedClassConfig* sharedC
case RESULT_DO_ADJUST_MAXAOT_EQUALS:
case RESULT_DO_ADJUST_MINJITDATA_EQUALS:
case RESULT_DO_ADJUST_MAXJITDATA_EQUALS:
case RESULT_DO_SET_EXTRA_STARTUPHINTS:
if (1 == checkIfCacheExists(vm, sharedClassConfig->ctrlDirName, cacheDirName, cacheName, &versionData, cacheType, layer)) {
return J9VMDLLMAIN_OK;
}
Expand Down Expand Up @@ -3869,10 +3892,12 @@ j9shr_init(J9JavaVM *vm, UDATA loadFlags, UDATA* nonfatal)
* will be printed out inside tryAdjustMinMaxSizes() no matter whether the softmx/minAOT/maxAOT/minJIT/maxJIT has been adjusted as requested */
cm->tryAdjustMinMaxSizes(currentThread);
returnVal = J9VMDLLMAIN_SILENT_EXIT_VM;
} else if (RESULT_DO_SET_EXTRA_STARTUPHINTS == parseResult) {
cm->setExtraStartupHints(currentThread);
returnVal = J9VMDLLMAIN_SILENT_EXIT_VM;
}

return returnVal;

_error:
/* This needs to be done before freeing vm->sharedClassConfig */
if ((doPrintStats) && (-2 == rcStartup)) {
Expand Down
3 changes: 3 additions & 0 deletions runtime/shared_common/shrinit.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ typedef struct J9SharedClassesOptions {
#define OPTION_MAP31 "map31"
#define OPTION_TEST_DOUBLE_PAGESIZE "testDoublePageSize"
#define OPTION_TEST_HALF_PAGESIZE "testHalfPageSize"
#define OPTION_EXTRA_STARTUPHINTS_EQUALS "extraStartupHints="

/* public options for printallstats= and printstats= */
#define SUB_OPTION_PRINTSTATS_ALL "all"
Expand Down Expand Up @@ -279,6 +280,7 @@ typedef struct J9SharedClassesOptions {
#define RESULT_DO_PRINT_TOP_LAYER_STATS 53
#define RESULT_DO_PRINT_TOP_LAYER_STATS_EQUALS 54
#define RESULT_DO_ADD_RUNTIMEFLAG2 55
#define RESULT_DO_SET_EXTRA_STARTUPHINTS 56

#define PARSE_TYPE_EXACT 1
#define PARSE_TYPE_STARTSWITH 2
Expand Down Expand Up @@ -311,6 +313,7 @@ typedef struct J9SharedClassesOptions {
#define HELPTEXT_ADJUST_MINJITDATA_EQUALS OPTION_ADJUST_MINJITDATA_EQUALS"<size>"
#define HELPTEXT_ADJUST_MAXJITDATA_EQUALS OPTION_ADJUST_MAXJITDATA_EQUALS"<size>"
#define HELPTEXT_LAYER_EQUALS OPTION_LAYER_EQUALS "<number>"
#define HELPTEXT_OPTION_EXTRA_STARTUPHINTS_EQUALS OPTION_EXTRA_STARTUPHINTS_EQUALS"<number>"

#define HELPTEXT_NEWLINE {"", 0, 0, 0, 0}

Expand Down
Loading