Skip to content

Commit bd9dc46

Browse files
committed
Fix JFR ModuleRequire and ModuleExport events
These two events are sampled events so we cannot use hooks. Instead, we iterate through classloaders and find reads and exports. Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
1 parent 15f9fbf commit bd9dc46

8 files changed

Lines changed: 90 additions & 166 deletions

File tree

runtime/j9vm/java11vmi.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,8 @@ exportPackageToModule(J9VMThread * currentThread, J9Module * fromModule, const c
791791
retval = ERRCODE_MODULE_WASNT_FOUND;
792792
}
793793
}
794-
if (ERRCODE_SUCCESS == retval) {
795-
TRIGGER_J9HOOK_PACKAGE_EXPORTED_TO_MODULE(currentThread->javaVM->hookInterface, currentThread, fromModule, j9package, toModule);
796-
if (TrcEnabled_Trc_MODULE_addModuleExports) {
797-
trcModulesAddModuleExports(currentThread, fromModule, package, toModule);
798-
}
794+
if ((ERRCODE_SUCCESS == retval) && TrcEnabled_Trc_MODULE_addModuleExports) {
795+
trcModulesAddModuleExports(currentThread, fromModule, package, toModule);
799796
}
800797

801798
return retval;
@@ -1311,11 +1308,8 @@ JVM_AddReadsModule(JNIEnv * env, jobject fromModule, jobject toModule)
13111308

13121309
if (ERRCODE_SUCCESS != rc) {
13131310
throwExceptionHelper(currentThread, rc);
1314-
} else {
1315-
TRIGGER_J9HOOK_READS_MODULE_ADDED(((J9JavaVM *)vm)->hookInterface, currentThread, j9FromMod, j9ToMod);
1316-
if (TrcEnabled_Trc_MODULE_addReadsModule) {
1317-
trcModulesAddReadsModule(currentThread, toModule, j9FromMod, j9ToMod);
1318-
}
1311+
} else if (TrcEnabled_Trc_MODULE_addReadsModule) {
1312+
trcModulesAddReadsModule(currentThread, toModule, j9FromMod, j9ToMod);
13191313
}
13201314
}
13211315
}

runtime/oti/j9consts.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,8 +960,6 @@ extern "C" {
960960
#define J9JFR_EVENT_TYPE_THREAD_STATISTICS 10
961961
#define J9JFR_EVENT_TYPE_MONITOR_ENTER 11
962962
#define J9JFR_EVENT_TYPE_SYSTEM_GC 12
963-
#define J9JFR_EVENT_TYPE_MODULE_REQUIRE 13
964-
#define J9JFR_EVENT_TYPE_MODULE_EXPORT 14
965963

966964
/* JFR thread states */
967965

runtime/oti/j9nonbuilder.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,6 @@ typedef struct J9JFRSystemGC {
504504
I_64 duration;
505505
} J9JFRSystemGC;
506506

507-
typedef struct J9JFRModuleRequire {
508-
J9JFR_EVENT_COMMON_FIELDS
509-
struct J9Module *source;
510-
struct J9Module *requiredModule;
511-
} J9JFRModuleRequire;
512-
513-
typedef struct J9JFRModuleExport {
514-
J9JFR_EVENT_COMMON_FIELDS
515-
struct J9Module *fromModule;
516-
struct J9Package *exportedPackage;
517-
struct J9Module *targetModule;
518-
} J9JFRModuleExport;
519-
520507
#define J9JFRSYSTEMGC_STACKTRACE(jfrEvent) ((UDATA *)(((J9JFRSystemGC *)(jfrEvent)) + 1))
521508

522509
#endif /* defined(J9VM_OPT_JFR) */

runtime/oti/j9vm.hdf

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,23 +1429,4 @@ typedef UDATA (* lookupNativeAddressCallback)(struct J9VMThread *currentThread,
14291429
<data type="struct J9VMThread*" name="currentThread" description="current thread" />
14301430
<data type="I_64" name="startTicks" description="current ticks when GC began" />
14311431
</event>
1432-
1433-
<event>
1434-
<name>J9HOOK_READS_MODULE_ADDED</name>
1435-
<description>Triggered after a module dependency is added (after allowReadAccessToModule() is called)</description>
1436-
<struct>J9VMReadsModuleAddedEvent</struct>
1437-
<data type="struct J9VMThread*" name="currentThread" description="current thread" />
1438-
<data type="struct J9Module*" name="fromModule" description="source module" />
1439-
<data type="struct J9Module*" name="toModule" description="required module" />
1440-
</event>
1441-
1442-
<event>
1443-
<name>J9HOOK_PACKAGE_EXPORTED_TO_MODULE</name>
1444-
<description>Triggered after a package is exported to a module (after exportPackageToModule() is called)</description>
1445-
<struct>J9VMPackageExportedToModuleEvent</struct>
1446-
<data type="struct J9VMThread*" name="currentThread" description="current thread" />
1447-
<data type="struct J9Module*" name="fromModule" description="from module" />
1448-
<data type="struct J9Package*" name="exportedPackage" description="exported package" />
1449-
<data type="struct J9Module*" name="targetModule" description="target module" />
1450-
</event>
14511432
</interface>

runtime/vm/JFRChunkWriter.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class VM_JFRChunkWriter {
195195
static constexpr int NATIVE_LIBRARY_ADDRESS_SIZE = (4 * sizeof(U_64)) + (2 * sizeof(UDATA)) + sizeof(U_8);
196196
static constexpr int SYSTEM_GC_EVENT_SIZE = (2 * LEB128_64_SIZE) + (3 * LEB128_32_SIZE) + sizeof(U_8);
197197
static constexpr int MODULE_REQUIRE_EVENT_SIZE = LEB128_64_SIZE + (4 * LEB128_32_SIZE);
198+
static constexpr int MODULE_EXPORT_EVENT_SIZE = LEB128_64_SIZE + (4 * LEB128_32_SIZE);
198199

199200
static constexpr int METADATA_ID = 1;
200201

@@ -941,6 +942,8 @@ class VM_JFRChunkWriter {
941942

942943
requiredBufferSize += (_constantPoolTypes.getModuleRequireCount() * MODULE_REQUIRE_EVENT_SIZE);
943944

945+
requiredBufferSize += (_constantPoolTypes.getModuleExportCount() * MODULE_EXPORT_EVENT_SIZE);
946+
944947
return requiredBufferSize;
945948
}
946949

runtime/vm/JFRConstantPoolTypes.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,59 +1385,6 @@ VM_JFRConstantPoolTypes::addSystemGCEntry(J9JFRSystemGC *systemGCData)
13851385

13861386
}
13871387

1388-
void
1389-
VM_JFRConstantPoolTypes::addModuleRequireEntry(J9JFRModuleRequire *moduleRequireData)
1390-
{
1391-
ModuleRequireEntry *entry = (ModuleRequireEntry *)pool_newElement(_moduleRequireTable);
1392-
1393-
if (NULL == entry) {
1394-
_buildResult = OutOfMemory;
1395-
goto done;
1396-
}
1397-
1398-
entry->ticks = moduleRequireData->startTicks;
1399-
entry->sourceModuleIndex = addModuleEntry(moduleRequireData->source);
1400-
if (isResultNotOKay()) goto done;
1401-
1402-
entry->requiredModuleIndex= addModuleEntry(moduleRequireData->requiredModule);
1403-
if (isResultNotOKay()) goto done;
1404-
1405-
_moduleRequireCount += 1;
1406-
1407-
done:
1408-
return;
1409-
1410-
}
1411-
1412-
void
1413-
VM_JFRConstantPoolTypes::addModuleExportEntry(J9JFRModuleExport *moduleExportData)
1414-
{
1415-
U_32 exportedPackageIndex = addPackageEntry(moduleExportData->fromModule, moduleExportData->exportedPackage, TRUE);
1416-
/* Skip this entry if no class from the package has been loaded. */
1417-
if (0 == exportedPackageIndex) {
1418-
return;
1419-
}
1420-
1421-
ModuleExportEntry *entry = (ModuleExportEntry *)pool_newElement(_moduleExportTable);
1422-
1423-
if (NULL == entry) {
1424-
_buildResult = OutOfMemory;
1425-
goto done;
1426-
}
1427-
1428-
entry->ticks = moduleExportData->startTicks;
1429-
entry->exportedPackageIndex = exportedPackageIndex;
1430-
if (isResultNotOKay()) goto done;
1431-
1432-
entry->targetModuleIndex = addModuleEntry(moduleExportData->targetModule);
1433-
if (isResultNotOKay()) goto done;
1434-
1435-
_moduleExportCount += 1;
1436-
1437-
done:
1438-
return;
1439-
}
1440-
14411388
void
14421389
VM_JFRConstantPoolTypes::printTables()
14431390
{

runtime/vm/JFRConstantPoolTypes.hpp

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,6 @@ class VM_JFRConstantPoolTypes {
707707

708708
void addSystemGCEntry(J9JFRSystemGC *systemGCData);
709709

710-
void addModuleRequireEntry(J9JFRModuleRequire *moduleRequireData);
711-
712-
void addModuleExportEntry(J9JFRModuleExport *moduleExportData);
713-
714710
J9Pool *getExecutionSampleTable()
715711
{
716712
return _executionSampleTable;
@@ -1060,12 +1056,6 @@ class VM_JFRConstantPoolTypes {
10601056
case J9JFR_EVENT_TYPE_SYSTEM_GC:
10611057
addSystemGCEntry((J9JFRSystemGC *)event);
10621058
break;
1063-
case J9JFR_EVENT_TYPE_MODULE_REQUIRE:
1064-
addModuleRequireEntry((J9JFRModuleRequire *)event);
1065-
break;
1066-
case J9JFR_EVENT_TYPE_MODULE_EXPORT:
1067-
addModuleExportEntry((J9JFRModuleExport *)event);
1068-
break;
10691059
default:
10701060
Assert_VM_unreachable();
10711061
break;
@@ -1080,6 +1070,7 @@ class VM_JFRConstantPoolTypes {
10801070
if (dumpCalled) {
10811071
loadSystemProcesses(_currentThread);
10821072
loadNativeLibraries(_currentThread);
1073+
loadModuleRequireAndModuleExportEvents();
10831074
}
10841075

10851076
shallowEntries = pool_new(sizeof(ClassEntry **), 0, sizeof(U_64), 0, J9_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT(privatePortLibrary));
@@ -1487,6 +1478,88 @@ class VM_JFRConstantPoolTypes {
14871478
omrsl_get_libraries(processNativeLibrariesCallback, this);
14881479
}
14891480

1481+
void loadModuleRequireAndModuleExportEvents()
1482+
{
1483+
J9InternalVMFunctions *vmFuncs = _vm->internalVMFunctions;
1484+
J9ClassLoaderWalkState walkState;
1485+
J9ClassLoader *classLoader = vmFuncs->allClassLoadersStartDo(&walkState, _vm, 0);
1486+
int64_t time = j9time_nano_time();
1487+
#ifdef J9VM_THR_PREEMPTIVE
1488+
omrthread_monitor_enter(_vm->classLoaderModuleAndLocationMutex);
1489+
#endif
1490+
1491+
while (NULL != classLoader) {
1492+
J9HashTableState moduleWalkState;
1493+
J9Module **modulePtr = (J9Module **)hashTableStartDo(classLoader->moduleHashTable, &moduleWalkState);
1494+
J9HashTableState packageWalkState;
1495+
J9Package **packagePtr = NULL;
1496+
1497+
while (NULL != modulePtr) {
1498+
J9HashTableState fromModuleWalkState;
1499+
J9Module **fromModulePtr = (J9Module **)hashTableStartDo((*modulePtr)->readAccessHashTable, &fromModuleWalkState);
1500+
while (NULL != fromModulePtr) {
1501+
ModuleRequireEntry *entry = (ModuleRequireEntry *)pool_newElement(_moduleRequireTable);
1502+
1503+
if (NULL == entry) {
1504+
_buildResult = OutOfMemory;
1505+
goto done;
1506+
}
1507+
1508+
entry->ticks = time;
1509+
entry->sourceModuleIndex = addModuleEntry(*fromModulePtr);
1510+
if (isResultNotOKay()) goto done;
1511+
1512+
entry->requiredModuleIndex= addModuleEntry(*modulePtr);
1513+
if (isResultNotOKay()) goto done;
1514+
1515+
_moduleRequireCount += 1;
1516+
1517+
fromModulePtr = (J9Module **)hashTableNextDo(&fromModuleWalkState);
1518+
}
1519+
1520+
modulePtr = (J9Module **)hashTableNextDo(&moduleWalkState);
1521+
}
1522+
1523+
packagePtr = (J9Package **)hashTableStartDo(classLoader->packageHashTable, &packageWalkState);
1524+
while (NULL != packagePtr) {
1525+
J9HashTableState toModuleWalkState;
1526+
J9Module **toModulePtr = (J9Module **)hashTableStartDo((*packagePtr)->exportsHashTable, &toModuleWalkState);
1527+
while (NULL != toModulePtr) {
1528+
U_32 exportedPackageIndex = addPackageEntry((*packagePtr)->module, *packagePtr, TRUE);
1529+
/* Skip this entry if no class from the package has been loaded. */
1530+
if (0 != exportedPackageIndex) {
1531+
ModuleExportEntry *entry = (ModuleExportEntry *)pool_newElement(_moduleExportTable);
1532+
1533+
if (NULL == entry) {
1534+
_buildResult = OutOfMemory;
1535+
goto done;
1536+
}
1537+
1538+
entry->ticks = time;
1539+
entry->exportedPackageIndex = exportedPackageIndex;
1540+
if (isResultNotOKay()) goto done;
1541+
1542+
entry->targetModuleIndex = addModuleEntry(*toModulePtr);
1543+
if (isResultNotOKay()) goto done;
1544+
1545+
_moduleExportCount += 1;
1546+
}
1547+
1548+
toModulePtr = (J9Module **)hashTableNextDo(&toModuleWalkState);
1549+
}
1550+
1551+
packagePtr = (J9Package **)hashTableNextDo(&packageWalkState);
1552+
}
1553+
1554+
classLoader = vmFuncs->allClassLoadersNextDo(&walkState);
1555+
}
1556+
done:
1557+
#ifdef J9VM_THR_PREEMPTIVE
1558+
omrthread_monitor_exit(_vm->classLoaderModuleAndLocationMutex);
1559+
#endif
1560+
vmFuncs->allClassLoadersEndDo(&walkState);
1561+
}
1562+
14901563
VM_JFRConstantPoolTypes(J9VMThread *currentThread)
14911564
: _currentThread(currentThread)
14921565
, _vm(currentThread->javaVM)

runtime/vm/jfr.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ jfrEventSize(J9JFREvent *jfrEvent)
117117
case J9JFR_EVENT_TYPE_SYSTEM_GC:
118118
size = sizeof(J9JFRSystemGC) + (((J9JFRSystemGC *)jfrEvent)->stackTraceSize * sizeof(UDATA));
119119
break;
120-
case J9JFR_EVENT_TYPE_MODULE_REQUIRE:
121-
size = sizeof(J9JFRModuleRequire);
122-
break;
123-
case J9JFR_EVENT_TYPE_MODULE_EXPORT:
124-
size = sizeof(J9JFRModuleExport);
125-
break;
126120
default:
127121
Assert_VM_unreachable();
128122
break;
@@ -745,51 +739,6 @@ jfrSystemGC(J9HookInterface **hook, UDATA eventNum, void *eventData, void* userD
745739
}
746740
}
747741

748-
/**
749-
* Hook for ReadsModuleAdded. Called without VM access.
750-
*
751-
* @param hook[in] the VM hook interface
752-
* @param eventNum[in] the event number
753-
* @param eventData[in] the event data
754-
* @param userData[in] the registered user data
755-
*/
756-
static void
757-
jfrReadsModuleAdded(J9HookInterface **hook, UDATA eventNum, void *eventData, void* userData)
758-
{
759-
J9VMReadsModuleAddedEvent *event = (J9VMReadsModuleAddedEvent *)eventData;
760-
J9VMThread *currentThread = event->currentThread;
761-
762-
J9JFRModuleRequire *jfrEvent = (J9JFRModuleRequire *)reserveBuffer(currentThread, sizeof(*jfrEvent));
763-
if (NULL != jfrEvent) {
764-
initializeEventFields(currentThread, (J9JFREvent *)jfrEvent, J9JFR_EVENT_TYPE_MODULE_REQUIRE);
765-
jfrEvent->source = event->fromModule;
766-
jfrEvent->requiredModule = event->toModule;
767-
}
768-
}
769-
770-
/**
771-
* Hook for PackageExportedToModule. Called without VM access.
772-
*
773-
* @param hook[in] the VM hook interface
774-
* @param eventNum[in] the event number
775-
* @param eventData[in] the event data
776-
* @param userData[in] the registered user data
777-
*/
778-
static void
779-
jfrPackageExportedToModule(J9HookInterface **hook, UDATA eventNum, void *eventData, void *userData)
780-
{
781-
J9VMPackageExportedToModuleEvent *event = (J9VMPackageExportedToModuleEvent *)eventData;
782-
J9VMThread *currentThread = event->currentThread;
783-
784-
J9JFRModuleExport *jfrEvent = (J9JFRModuleExport *)reserveBuffer(currentThread, sizeof(*jfrEvent));
785-
if (NULL != jfrEvent) {
786-
initializeEventFields(currentThread, (J9JFREvent *)jfrEvent, J9JFR_EVENT_TYPE_MODULE_EXPORT);
787-
jfrEvent->fromModule = event->fromModule;
788-
jfrEvent->targetModule = event->targetModule;
789-
jfrEvent->exportedPackage = event->exportedPackage;
790-
}
791-
}
792-
793742
jint
794743
initializeJFR(J9JavaVM *vm, BOOLEAN lateInit)
795744
{
@@ -851,12 +800,6 @@ initializeJFR(J9JavaVM *vm, BOOLEAN lateInit)
851800
if ((*vmHooks)->J9HookRegisterWithCallSite(vmHooks, J9HOOK_SYSTEM_GC_CALLED, jfrSystemGC, OMR_GET_CALLSITE(), NULL)) {
852801
goto fail;
853802
}
854-
if ((*vmHooks)->J9HookRegisterWithCallSite(vmHooks, J9HOOK_READS_MODULE_ADDED, jfrReadsModuleAdded, OMR_GET_CALLSITE(), NULL)) {
855-
goto fail;
856-
}
857-
if ((*vmHooks)->J9HookRegisterWithCallSite(vmHooks, J9HOOK_PACKAGE_EXPORTED_TO_MODULE, jfrPackageExportedToModule, OMR_GET_CALLSITE(), NULL)) {
858-
goto fail;
859-
}
860803

861804
/* Allocate constantEvents. */
862805
vm->jfrState.constantEvents = j9mem_allocate_memory(sizeof(JFRConstantEvents), J9MEM_CATEGORY_VM);
@@ -991,8 +934,6 @@ tearDownJFR(J9JavaVM *vm)
991934
(*vmHooks)->J9HookUnregister(vmHooks, J9HOOK_VM_MONITOR_CONTENDED_ENTERED, jfrVMMonitorEntered, NULL);
992935
(*vmHooks)->J9HookUnregister(vmHooks, J9HOOK_VM_UNPARKED, jfrVMThreadParked, NULL);
993936
(*vmHooks)->J9HookUnregister(vmHooks, J9HOOK_SYSTEM_GC_CALLED, jfrSystemGC, NULL);
994-
(*vmHooks)->J9HookUnregister(vmHooks, J9HOOK_READS_MODULE_ADDED, jfrReadsModuleAdded, NULL);
995-
(*vmHooks)->J9HookUnregister(vmHooks, J9HOOK_PACKAGE_EXPORTED_TO_MODULE, jfrPackageExportedToModule, NULL);
996937

997938
/* Free global data */
998939
VM_JFRConstantPoolTypes::freeJFRConstantEvents(vm);

0 commit comments

Comments
 (0)