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

Add an object sampling hook #4618

Merged
merged 1 commit into from
Feb 26, 2019
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
16 changes: 15 additions & 1 deletion runtime/gc_include/j9mm.hdf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010, 2018 IBM Corp. and others
Copyright (c) 2010, 2019 IBM Corp. and others

This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -60,5 +60,19 @@ struct J9VMThread;
<struct>MM_InterruptCompilationEvent</struct>
<data type="struct J9VMThread*" name="currentThread" description="current thread" />
</event>

<event>
<name>J9HOOK_MM_OBJECT_ALLOCATION_SAMPLING</name>
<description>
Triggered when the object allocations sampling threshold is reached
</description>
<struct>MM_ObjectAllocationSamplingEvent</struct>
<data type="struct J9VMThread*" name="currentThread" description="current thread" />
<data type="U_64" name="timestamp" description="time of event" />
<data type="UDATA" name="eventid" description="unique identifier for event" />
<data type="j9object_t" name="object" description="the object which has been allocated." />
<data type="struct J9Class*" name="clazz" description="the class of the object just allocated" />
<data type="uintptr_t" name="objectSize" description="the size of the object just allocated" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @charliegracie , this looks good to me. Just note that this JEP doesn't require timestamp and eventid, clazz could be derived from object however it is nice to receive it since traceAllocateObject already has it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamp and eventID are added because the GC hooks all add them.

</event>

</interface>
21 changes: 16 additions & 5 deletions runtime/gc_modron_startup/mgcalloc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*******************************************************************************
* Copyright (c) 1991, 2018 IBM Corp. and others
* Copyright (c) 1991, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -62,7 +62,7 @@ extern "C" {
static uintptr_t stackIterator(J9VMThread *currentThread, J9StackWalkState *walkState);
static void dumpStackFrames(J9VMThread *currentThread);
static void traceAllocateIndexableObject(J9VMThread *vmThread, J9Class* clazz, uintptr_t objSize, uintptr_t numberOfIndexedFields);
static void traceAllocateObject(J9VMThread *vmThread, J9Class* clazz, uintptr_t objSize, uintptr_t numberOfIndexedFields=0);
static void traceAllocateObject(J9VMThread *vmThread, J9Object * object, J9Class* clazz, uintptr_t objSize, uintptr_t numberOfIndexedFields=0);
static bool traceObjectCheck(J9VMThread *vmThread);

#define STACK_FRAMES_TO_DUMP 8
Expand Down Expand Up @@ -217,9 +217,10 @@ traceAllocateIndexableObject(J9VMThread *vmThread, J9Class* clazz, uintptr_t obj
}

static void
traceAllocateObject(J9VMThread *vmThread, J9Class* clazz, uintptr_t objSize, uintptr_t numberOfIndexedFields)
traceAllocateObject(J9VMThread *vmThread, J9Object * object, J9Class* clazz, uintptr_t objSize, uintptr_t numberOfIndexedFields)
{
if(traceObjectCheck(vmThread)){
PORT_ACCESS_FROM_VMC(vmThread);
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(vmThread->omrVMThread);
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);
uintptr_t byteGranularity = extensions->oolObjectSamplingBytesGranularity;
Expand All @@ -231,6 +232,16 @@ traceAllocateObject(J9VMThread *vmThread, J9Class* clazz, uintptr_t objSize, uin
Trc_MM_J9AllocateObject_outOfLineObjectAllocation(
vmThread, clazz, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(romClass)), objSize);
}

TRIGGER_J9HOOK_MM_OBJECT_ALLOCATION_SAMPLING(
extensions->hookInterface,
vmThread,
j9time_hires_clock(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need PORT_ACCESS_FROM_VMC(vmThread); for this port library call.

J9HOOK_MM_OBJECT_ALLOCATION_SAMPLING,
object,
clazz,
objSize);

/* Keep the remainder, want this to happen so that we don't miss objects
* after seeing large objects
*/
Expand Down Expand Up @@ -426,7 +437,7 @@ J9AllocateObject(J9VMThread *vmThread, J9Class *clazz, uintptr_t allocateFlags)
dumpStackFrames(vmThread);
TRIGGER_J9HOOK_MM_PRIVATE_OUT_OF_MEMORY(extensions->privateHookInterface, vmThread->omrVMThread, j9time_hires_clock(), J9HOOK_MM_PRIVATE_OUT_OF_MEMORY, memorySpace, memorySpace->getName());
} else {
traceAllocateObject(vmThread, clazz, sizeInBytesRequired);
traceAllocateObject(vmThread, objectPtr, clazz, sizeInBytesRequired);
if (extensions->isStandardGC()) {
if (OMR_GC_ALLOCATE_OBJECT_TENURED == (allocateFlags & OMR_GC_ALLOCATE_OBJECT_TENURED)) {
/* Object must be allocated in Tenure if it is requested */
Expand Down Expand Up @@ -549,7 +560,7 @@ J9AllocateIndexableObject(J9VMThread *vmThread, J9Class *clazz, uint32_t numberO
highThreshold);
}

traceAllocateObject(vmThread, clazz, sizeInBytesRequired, (uintptr_t)numberOfIndexedFields);
traceAllocateObject(vmThread, objectPtr, clazz, sizeInBytesRequired, (uintptr_t)numberOfIndexedFields);
if (extensions->isStandardGC()) {
if (OMR_GC_ALLOCATE_OBJECT_TENURED == (allocateFlags & OMR_GC_ALLOCATE_OBJECT_TENURED)) {
/* Object must be allocated in Tenure if it is requested */
Expand Down