Skip to content

Commit 9464ff3

Browse files
authored
Merge pull request #20593 from tajila/jfr3
Fix JFR synchronization issues
2 parents cd9396a + c6de472 commit 9464ff3

File tree

4 files changed

+117
-41
lines changed

4 files changed

+117
-41
lines changed

runtime/util/cphelp.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ getClassLocation(J9VMThread * currentThread, J9Class * clazz, UDATA *length)
6767

6868
if (NULL != classLoader->classLocationHashTable) {
6969
J9ClassLocation *classLocation = vmFuncs->findClassLocationForClass(currentThread, clazz);
70-
70+
7171
if (NULL != classLocation) {
7272
switch(classLocation->locationType) {
7373
case LOAD_LOCATION_PATCH_PATH_NON_GENERATED:
@@ -86,7 +86,7 @@ getClassLocation(J9VMThread * currentThread, J9Class * clazz, UDATA *length)
8686

8787
case LOAD_LOCATION_CLASSPATH_NON_GENERATED:
8888
case LOAD_LOCATION_CLASSPATH:
89-
rc = getClassPathEntry(currentThread, classLoader, classLocation->entryIndex, &entry);
89+
rc = getClassPathEntry(currentThread, classLoader, classLocation->entryIndex, &entry);
9090
if (0 == rc) {
9191
*length = entry.pathLength;
9292
path = entry.path;
@@ -149,7 +149,9 @@ getModuleJRTURL(J9VMThread *currentThread, J9ClassLoader *classLoader, J9Module
149149
if (NULL == jrtURL) {
150150
if (J9_ARE_ALL_BITS_SET(javaVM->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED)) {
151151
/* set jrt URL for the module */
152-
jrtURL = vmFuncs->copyStringToJ9UTF8WithMemAlloc(currentThread, module->moduleName, J9_STR_NONE, "jrt:/", 5, NULL, 0);
152+
if (NULL != module->moduleName) {
153+
jrtURL = vmFuncs->copyStringToJ9UTF8WithMemAlloc(currentThread, module->moduleName, J9_STR_NONE, "jrt:/", 5, NULL, 0);
154+
}
153155

154156
if (NULL == jrtURL) {
155157
goto _exit;
@@ -162,7 +164,7 @@ getModuleJRTURL(J9VMThread *currentThread, J9ClassLoader *classLoader, J9Module
162164
if (NULL == jrtURL) {
163165
goto _exit;
164166
}
165-
memcpy(J9UTF8_DATA(jrtURL), J9UTF8_DATA(&jrtJavaBaseUrl), length);
167+
memcpy(J9UTF8_DATA(jrtURL), J9UTF8_DATA(&jrtJavaBaseUrl), length);
166168
J9UTF8_SET_LENGTH(jrtURL, length);
167169
}
168170
moduleInfo->jrtURL = jrtURL;
@@ -219,9 +221,9 @@ addJarToSystemClassLoaderClassPathEntries(J9JavaVM *vm, const char *filename)
219221

220222
#if defined(J9VM_OPT_SHARED_CLASSES)
221223
if (J9_ARE_ALL_BITS_SET(classLoader->flags, J9CLASSLOADER_SHARED_CLASSES_ENABLED)) {
222-
/*
224+
/*
223225
* Warm up the classpath entry so that the Classpath stored in the cache has the correct info.
224-
* This is required because when we are finding classes in the cache, initializeClassPathEntry is not called
226+
* This is required because when we are finding classes in the cache, initializeClassPathEntry is not called
225227
* */
226228
if (vm->internalVMFunctions->initializeClassPathEntry(vm, cpEntry) != CPE_TYPE_JAR) {
227229
goto done;

runtime/vm/JFRConstantPoolTypes.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ VM_JFRConstantPoolTypes::jfrPackageHashFn(void *key, void *userData)
5050
{
5151
PackageEntry *packageEntry = (PackageEntry *) key;
5252

53-
return *(UDATA*)&packageEntry->pkgID;
53+
return *(UDATA*)&packageEntry->romClass;
5454
}
5555

5656
UDATA
@@ -59,7 +59,7 @@ VM_JFRConstantPoolTypes::jfrPackageHashEqualFn(void *tableNode, void *queryNode,
5959
PackageEntry *tableEntry = (PackageEntry *) tableNode;
6060
PackageEntry *queryEntry = (PackageEntry *) queryNode;
6161

62-
return tableEntry->pkgID == queryEntry->pkgID;
62+
return tableEntry->romClass == queryEntry->romClass;
6363
}
6464

6565
UDATA
@@ -308,17 +308,28 @@ VM_JFRConstantPoolTypes::walkStackTraceTablePrint(void *entry, void *userData)
308308
return FALSE;
309309
}
310310

311+
311312
UDATA
312-
VM_JFRConstantPoolTypes::fixupShallowEntries(void *entry, void *userData)
313+
VM_JFRConstantPoolTypes::findShallowEntries(void *entry, void *userData)
313314
{
314315
ClassEntry *tableEntry = (ClassEntry *) entry;
315-
VM_JFRConstantPoolTypes *cp = (VM_JFRConstantPoolTypes*) userData;
316+
J9Pool *shallowEntries = (J9Pool*) userData;
316317

317-
cp->getClassEntry(tableEntry->clazz);
318+
ClassEntry **newEntry = (ClassEntry**)pool_newElement(shallowEntries);
319+
*newEntry = tableEntry;
318320

319321
return FALSE;
320322
}
321323

324+
void
325+
VM_JFRConstantPoolTypes::fixupShallowEntries(void *entry, void *userData)
326+
{
327+
ClassEntry *tableEntry = *(ClassEntry **) entry;
328+
VM_JFRConstantPoolTypes *cp = (VM_JFRConstantPoolTypes*) userData;
329+
330+
cp->getClassEntry(tableEntry->clazz);
331+
}
332+
322333
UDATA
323334
VM_JFRConstantPoolTypes::mergeStringUTF8EntriesToGlobalTable(void *entry, void *userData)
324335
{
@@ -335,11 +346,9 @@ VM_JFRConstantPoolTypes::mergePackageEntriesToGlobalTable(void *entry, void *use
335346
{
336347
PackageEntry *tableEntry = (PackageEntry *) entry;
337348
VM_JFRConstantPoolTypes *cp = (VM_JFRConstantPoolTypes*) userData;
338-
UDATA packageNameLength = 0;
339349

340-
getPackageName(tableEntry->pkgID, &packageNameLength);
341350
cp->_globalStringTable[tableEntry->index + cp->_stringUTF8Count] = tableEntry;
342-
cp->_requiredBufferSize += packageNameLength;
351+
cp->_requiredBufferSize += tableEntry->packageNameLength;
343352
return FALSE;
344353
}
345354

@@ -472,7 +481,8 @@ VM_JFRConstantPoolTypes::addPackageEntry(J9Class *clazz)
472481
_buildResult = OK;
473482

474483
pkgID = hashPkgTableAt(clazz->classLoader, clazz->romClass);
475-
entry->pkgID = pkgID;
484+
entry->romClass = clazz->romClass;
485+
entry->ramClass = clazz;
476486

477487
if (NULL == pkgID) {
478488
/* default pacakge */
@@ -491,7 +501,7 @@ VM_JFRConstantPoolTypes::addPackageEntry(J9Class *clazz)
491501
entry->moduleIndex = addModuleEntry(clazz->module);
492502
if (isResultNotOKay()) goto done;
493503

494-
packageName = (const char *) getPackageName(entry->pkgID, &packageNameLength);
504+
packageName = (const char *) getPackageName(pkgID, &packageNameLength);
495505
if (NULL == packageName) {
496506
_buildResult = InternalVMError;
497507
goto done;

runtime/vm/JFRConstantPoolTypes.hpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ struct ClassEntry {
8787
};
8888

8989
struct PackageEntry {
90-
J9PackageIDTableEntry *pkgID;
90+
J9ROMClass *romClass;
91+
J9Class *ramClass;
9192
U_32 moduleIndex;
9293
BOOLEAN exported;
9394
U_32 packageNameLength;
@@ -406,7 +407,9 @@ class VM_JFRConstantPoolTypes {
406407

407408
static UDATA walkStackTraceTablePrint(void *entry, void *userData);
408409

409-
static UDATA fixupShallowEntries(void *entry, void *userData);
410+
static UDATA findShallowEntries(void *entry, void *userData);
411+
412+
static void fixupShallowEntries(void *anElement, void *userData);
410413

411414
static UDATA walkMethodTablePrint(void *entry, void *userData);
412415

@@ -750,6 +753,7 @@ class VM_JFRConstantPoolTypes {
750753
void loadEvents()
751754
{
752755
J9JFRBufferWalkState walkstate = {0};
756+
J9Pool *shallowEntries = NULL;
753757
J9JFREvent *event = jfrBufferStartDo(&_vm->jfrBuffer, &walkstate);
754758

755759
while (NULL != event) {
@@ -782,8 +786,25 @@ class VM_JFRConstantPoolTypes {
782786
event = jfrBufferNextDo(&walkstate);
783787
}
784788

785-
hashTableForEachDo(_classTable, &fixupShallowEntries, this);
789+
if (isResultNotOKay()) {
790+
goto done;
791+
}
792+
793+
shallowEntries = pool_new(sizeof(ClassEntry**), 0, sizeof(U_64), 0, J9_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT(privatePortLibrary));
794+
if (NULL == shallowEntries) {
795+
_buildResult = OutOfMemory;
796+
goto done;
797+
}
798+
799+
hashTableForEachDo(_classTable, findShallowEntries, shallowEntries);
800+
pool_do(shallowEntries, fixupShallowEntries, this);
801+
802+
pool_kill(shallowEntries);
803+
786804
mergeStringTables();
805+
806+
done:
807+
return;
787808
}
788809

789810
U_32 consumeStackTrace(J9VMThread *walkThread, UDATA *walkStateCache, UDATA numberOfFrames) {
@@ -1099,55 +1120,55 @@ class VM_JFRConstantPoolTypes {
10991120
, _firstPackageEntry(NULL)
11001121
, _requiredBufferSize(0)
11011122
{
1102-
_classTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ClassEntry), sizeof(ClassEntry *), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, jfrClassHashFn, jfrClassHashEqualFn, NULL, _vm);
1123+
_classTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ClassEntry), sizeof(ClassEntry *), 0, J9MEM_CATEGORY_CLASSES, jfrClassHashFn, jfrClassHashEqualFn, NULL, _vm);
11031124
if (NULL == _classTable) {
11041125
_buildResult = OutOfMemory;
11051126
goto done;
11061127
}
11071128

1108-
_packageTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(PackageEntry), sizeof(PackageEntry *), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, jfrPackageHashFn, jfrPackageHashEqualFn, NULL, _vm);
1129+
_packageTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(PackageEntry), sizeof(PackageEntry *), 0, J9MEM_CATEGORY_CLASSES, jfrPackageHashFn, jfrPackageHashEqualFn, NULL, _vm);
11091130
if (NULL == _packageTable) {
11101131
_buildResult = OutOfMemory;
11111132
goto done;
11121133
}
11131134

1114-
_classLoaderTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ClassloaderEntry), sizeof(J9ClassLoader*), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, classloaderNameHashFn, classloaderNameHashEqualFn, NULL, _vm);
1135+
_classLoaderTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ClassloaderEntry), sizeof(J9ClassLoader*), 0, J9MEM_CATEGORY_CLASSES, classloaderNameHashFn, classloaderNameHashEqualFn, NULL, _vm);
11151136
if (NULL == _classLoaderTable) {
11161137
_buildResult = OutOfMemory;
11171138
goto done;
11181139
}
11191140

1120-
_methodTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(MethodEntry), sizeof(J9ROMMethod*), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, methodNameHashFn, methodNameHashEqualFn, NULL, _vm);
1141+
_methodTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(MethodEntry), sizeof(J9ROMMethod*), 0, J9MEM_CATEGORY_CLASSES, methodNameHashFn, methodNameHashEqualFn, NULL, _vm);
11211142
if (NULL == _methodTable) {
11221143
_buildResult = OutOfMemory;
11231144
goto done;
11241145
}
11251146

1126-
_stringUTF8Table = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(StringUTF8Entry), sizeof(StringUTF8Entry*), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, jfrStringUTF8HashFn, jfrStringUTF8HashEqualFn, NULL, _vm);
1147+
_stringUTF8Table = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(StringUTF8Entry), sizeof(StringUTF8Entry*), 0, J9MEM_CATEGORY_CLASSES, jfrStringUTF8HashFn, jfrStringUTF8HashEqualFn, NULL, _vm);
11271148
if (NULL == _stringUTF8Table) {
11281149
_buildResult = OutOfMemory;
11291150
goto done;
11301151
}
11311152

1132-
_moduleTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ModuleEntry), sizeof(ModuleEntry*), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, jfrModuleHashFn, jfrModuleHashEqualFn, NULL, _vm);
1153+
_moduleTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ModuleEntry), sizeof(ModuleEntry*), 0, J9MEM_CATEGORY_CLASSES, jfrModuleHashFn, jfrModuleHashEqualFn, NULL, _vm);
11331154
if (NULL == _moduleTable) {
11341155
_buildResult = OutOfMemory;
11351156
goto done;
11361157
}
11371158

1138-
_threadTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ThreadEntry), sizeof(U_64), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, threadHashFn, threadHashEqualFn, NULL, _currentThread);
1159+
_threadTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ThreadEntry), sizeof(U_64), 0, J9MEM_CATEGORY_CLASSES, threadHashFn, threadHashEqualFn, NULL, _currentThread);
11391160
if (NULL == _threadTable) {
11401161
_buildResult = OutOfMemory;
11411162
goto done;
11421163
}
11431164

1144-
_stackTraceTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(StackTraceEntry), sizeof(U_64), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, stackTraceHashFn, stackTraceHashEqualFn, NULL, _vm);
1165+
_stackTraceTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(StackTraceEntry), sizeof(U_64), 0, J9MEM_CATEGORY_CLASSES, stackTraceHashFn, stackTraceHashEqualFn, NULL, _vm);
11451166
if (NULL == _stackTraceTable) {
11461167
_buildResult = OutOfMemory;
11471168
goto done;
11481169
}
11491170

1150-
_threadGroupTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ThreadGroupEntry), sizeof(U_64), J9HASH_TABLE_ALLOW_SIZE_OPTIMIZATION, J9MEM_CATEGORY_CLASSES, threadGroupHashFn, threadGroupHashEqualFn, NULL, _vm);
1171+
_threadGroupTable = hashTableNew(OMRPORT_FROM_J9PORT(privatePortLibrary), J9_GET_CALLSITE(), 0, sizeof(ThreadGroupEntry), sizeof(U_64), 0, J9MEM_CATEGORY_CLASSES, threadGroupHashFn, threadGroupHashEqualFn, NULL, _vm);
11511172
if (NULL == _threadGroupTable) {
11521173
_buildResult = OutOfMemory;
11531174
goto done;

0 commit comments

Comments
 (0)