Path: blob/master/runtime/gc_base/GCObjectEvents.cpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#include "j9.h"23#include "j9cfg.h"24#include "j9consts.h"25#include "modronopt.h"2627#if defined(J9VM_PROF_EVENT_REPORTING)2829#include "mmhook_internal.h"30#include "mmomrhook_internal.h"3132#include "EnvironmentBase.hpp"33#include "ForwardedHeader.hpp"34#include "Heap.hpp"35#include "HeapMap.hpp"36#include "MemorySpace.hpp"37#include "MemorySubSpace.hpp"38#include "MemorySubSpaceSemiSpace.hpp"39#include "MemorySubSpaceRegionIterator.hpp"40#include "ObjectHeapBufferedIterator.hpp"41#include "ObjectModel.hpp"42#include "HeapRegionDescriptor.hpp"43#include "HeapRegionIterator.hpp"44#include "GCExtensions.hpp"45#include "HeapRegionManager.hpp"4647void48globalGCReportObjectEvents(MM_EnvironmentBase *env, MM_HeapMap *markMap)49{50MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);51MM_HeapRegionManager *regionManager = extensions->heap->getHeapRegionManager();52GC_HeapRegionIterator regionIterator(regionManager);53MM_HeapRegionDescriptor *region = NULL;54OMR_VMThread *vmThread = env->getOmrVMThread();55while((region = regionIterator.nextRegion()) != NULL) {56/* Iterate over live objects only */57MM_MemorySubSpace *memorySubSpace = region->getSubSpace();5859GC_ObjectHeapBufferedIterator objectHeapIterator(extensions, region);6061J9Object *objectPtr = NULL;62while( NULL != (objectPtr = objectHeapIterator.nextObject()) ) {63/* Check the mark state of each object. If it isn't marked, build a dead object. */64if(!markMap->isBitSet(objectPtr)) {6566UDATA deadObjectByteSize = extensions->objectModel.getConsumedSizeInBytesWithHeader(objectPtr);67memorySubSpace->abandonHeapChunk(objectPtr, ((U_8*)objectPtr) + deadObjectByteSize);6869TRIGGER_J9HOOK_MM_OMR_OBJECT_DELETE(env->getExtensions()->omrHookInterface, vmThread, objectPtr, memorySubSpace);70}71}72}73}7475void76localGCReportObjectEvents(MM_EnvironmentBase *env, MM_MemorySubSpaceSemiSpace *memorySubSpaceNew)77{78MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);79OMR_VMThread *vmThread = env->getOmrVMThread();8081/* Find the region associated with the evacuate allocate profile */82GC_MemorySubSpaceRegionIterator regionIterator(memorySubSpaceNew);83MM_HeapRegionDescriptor *evacuateRegion = NULL;84bool const compressed = extensions->compressObjectReferences();85while ((evacuateRegion = regionIterator.nextRegion()) != NULL) {86J9Object *objectPtr = (J9Object *)evacuateRegion->getLowAddress();87/* skip survivor regions */88if (memorySubSpaceNew->isObjectInEvacuateMemory(objectPtr)) {89MM_MemorySubSpace *evacuateMemorySubSpace = evacuateRegion->getSubSpace();90/* Use the object model helper to test for holes,91* otherwise use ForwardedHeader to test for forwarded objects.92*/93while(objectPtr < (J9Object *)evacuateRegion->getHighAddress()) {94if (extensions->objectModel.isDeadObject(objectPtr)) {95objectPtr = (J9Object *)((U_8 *)objectPtr + extensions->objectModel.getSizeInBytesDeadObject(objectPtr));96} else {97MM_ForwardedHeader forwardHeader(objectPtr, compressed);98if (forwardHeader.isForwardedPointer()) {99J9Object *forwardPtr = forwardHeader.getForwardedObject();100Assert_MM_true(NULL != forwardPtr);101TRIGGER_J9HOOK_MM_OMR_OBJECT_RENAME(env->getExtensions()->omrHookInterface, vmThread, objectPtr, forwardPtr);102objectPtr = (J9Object *)((U_8 *)objectPtr + extensions->objectModel.getConsumedSizeInBytesWithHeaderBeforeMove(forwardPtr));103} else {104TRIGGER_J9HOOK_MM_OMR_OBJECT_DELETE(env->getExtensions()->omrHookInterface, vmThread, objectPtr, evacuateMemorySubSpace);105objectPtr = (J9Object *)((U_8 *)objectPtr + extensions->objectModel.getConsumedSizeInBytesWithHeader(objectPtr));106}107}108}109}110}111}112113#endif /* J9VM_PROF_EVENT_REPORTING */114115116