Skip to content

Commit

Permalink
Merge pull request #5770 from hangshao0/v14
Browse files Browse the repository at this point in the history
(v0.14.2) Fix the duplicated NLS messages when SH_OSCache::getCacheDir() failed.
  • Loading branch information
pshipton authored May 15, 2019
2 parents d1ad60c + 6c0e8ec commit 72298fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
19 changes: 12 additions & 7 deletions runtime/shared/shrclssup.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ IDATA J9VMDllMain(J9JavaVM* vm, IDATA stage, void* reserved)
#if !defined(WIN32) && !defined(WIN64)
char defaultCacheDir[J9SH_MAXPATH];
IDATA ret = 0;
BOOLEAN usingDefaultDir = TRUE;
#endif
IDATA argIndex1 = -1;
IDATA argIndex2 = -1;
Expand Down Expand Up @@ -184,18 +185,22 @@ IDATA J9VMDllMain(J9JavaVM* vm, IDATA stage, void* reserved)
} else {
vm->sharedCacheAPI->cacheType = J9PORT_SHR_CACHE_TYPE_NONPERSISTENT;
}
/* set runtimeFlags and verboseFlags here as they will be used later in SH_OSCache::getCacheDir() */
/* set runtimeFlags and verboseFlags here as they will be used later in j9shr_getCacheDir() */
vm->sharedCacheAPI->runtimeFlags = runtimeFlags;
vm->sharedCacheAPI->verboseFlags = verboseFlags;

#if !defined(WIN32) && !defined(WIN64)
/* Get platform default cache directory */
ret = j9shr_getCacheDir(vm, NULL, defaultCacheDir, J9SH_MAXPATH, vm->sharedCacheAPI->cacheType);
if (NULL != ctrlDirName) {
/* Get platform default cache directory */
ret = j9shr_getCacheDir(vm, NULL, defaultCacheDir, J9SH_MAXPATH, vm->sharedCacheAPI->cacheType);
if ((0 == ret)
&& (0 != strcmp(defaultCacheDir, ctrlDirName))
) {
usingDefaultDir = FALSE;
}
}

if ((NULL != ctrlDirName)
&& (0 == ret)
&& (0 != (strcmp(defaultCacheDir, ctrlDirName)))
) {
if (FALSE == usingDefaultDir) {
vm->sharedCacheAPI->cacheDirPerm = convertPermToDecimal(vm, cacheDirPermStr);
if ((UDATA)-1 == vm->sharedCacheAPI->cacheDirPerm) {
return J9VMDLLMAIN_FAILED;
Expand Down
9 changes: 6 additions & 3 deletions runtime/shared_common/OSCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ SH_OSCache::removeCacheVersionAndGen(char* buffer, UDATA bufferSize, UDATA versi
* @param [out] buffer The buffer to write the result into
* @param [in] bufferSize The size of the buffer in bytes
* @param [in] cacheType The Type of cache
* @param [in] allowVerbose Whether to allow verbose message.
*
* @return 0 on success or -1 for failure
*/
IDATA
SH_OSCache::getCacheDir(J9JavaVM* vm, const char* ctrlDirName, char* buffer, UDATA bufferSize, U_32 cacheType)
SH_OSCache::getCacheDir(J9JavaVM* vm, const char* ctrlDirName, char* buffer, UDATA bufferSize, U_32 cacheType, bool allowVerbose)
{
PORT_ACCESS_FROM_JAVAVM(vm);
IDATA rc;
Expand Down Expand Up @@ -212,8 +213,10 @@ SH_OSCache::getCacheDir(J9JavaVM* vm, const char* ctrlDirName, char* buffer, UDA
rc = j9shmem_getDir(ctrlDirName, flags, buffer, bufferSize);

if (rc < 0) {
if (0 != vm->sharedCacheAPI->verboseFlags) {
switch(rc) {
if (allowVerbose
&& J9_ARE_ANY_BITS_SET(vm->sharedCacheAPI->verboseFlags, J9SHR_VERBOSEFLAG_ENABLE_VERBOSE_DEFAULT | J9SHR_VERBOSEFLAG_ENABLE_VERBOSE)
) {
switch(rc) {
case J9PORT_ERROR_SHMEM_GET_DIR_BUF_OVERFLOW:
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_SHRC_GET_DIR_BUF_OVERFLOW);
break;
Expand Down
2 changes: 1 addition & 1 deletion runtime/shared_common/OSCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class SH_OSCache

static UDATA getRequiredConstrBytes(void);

static IDATA getCacheDir(J9JavaVM* vm, const char* ctrlDirName, char* buffer, UDATA bufferSize, U_32 cacheType);
static IDATA getCacheDir(J9JavaVM* vm, const char* ctrlDirName, char* buffer, UDATA bufferSize, U_32 cacheType, bool allowVerbose = true);

static IDATA createCacheDir(J9PortLibrary* portLibrary, char* cacheDirName, UDATA cacheDirPerm, bool cleanMemorySegments);

Expand Down
5 changes: 3 additions & 2 deletions runtime/shared_common/shrinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4908,7 +4908,8 @@ isFreeDiskSpaceLow(J9JavaVM *vm, U_64* maxsize)
bool ret = true;
PORT_ACCESS_FROM_JAVAVM(vm);

if (-1 == SH_OSCache::getCacheDir(vm, vm->sharedCacheAPI->ctrlDirName, cacheDirName, J9SH_MAXPATH, J9PORT_SHR_CACHE_TYPE_PERSISTENT)) {
if (-1 == j9shr_getCacheDir(vm, vm->sharedCacheAPI->ctrlDirName, cacheDirName, J9SH_MAXPATH, J9PORT_SHR_CACHE_TYPE_PERSISTENT)) {
/* use j9shr_getCacheDir() instead of SH_OSCache::getCacheDir() to avoid dupliated NLS message if SH_OSCache::getCacheDir() failed */
Trc_SHR_INIT_isFreeDiskSpaceLow_getDirFailed();
goto done;
}
Expand Down Expand Up @@ -5140,7 +5141,7 @@ j9shr_findGCHints(J9VMThread* currentThread, UDATA *heapSize1, UDATA *heapSize2)
IDATA
j9shr_getCacheDir(J9JavaVM* vm, const char* ctrlDirName, char* buffer, UDATA bufferSize, U_32 cacheType)
{
return SH_OSCache::getCacheDir(vm, ctrlDirName, buffer, bufferSize, cacheType);
return SH_OSCache::getCacheDir(vm, ctrlDirName, buffer, bufferSize, cacheType, false);
}

} /* extern "C" */

0 comments on commit 72298fc

Please sign in to comment.