Path: blob/master/runtime/gc_vlhgc/CopyForwardDelegate.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"2425#include "CopyForwardDelegate.hpp"2627#include "ClassLoaderManager.hpp"28#include "CompactGroupManager.hpp"29#include "CompactGroupPersistentStats.hpp"30#include "CycleState.hpp"31#include "FinalizerSupport.hpp"32#include "HeapRegionIteratorVLHGC.hpp"33#include "HeapRegionManager.hpp"34#include "MarkMap.hpp"35#include "MemorySubSpace.hpp"36#include "ObjectAllocationInterface.hpp"3738MM_CopyForwardDelegate::MM_CopyForwardDelegate(MM_EnvironmentVLHGC *env)39: _javaVM((J9JavaVM *)env->getLanguageVM())40, _extensions(MM_GCExtensions::getExtensions(env))41, _breadthFirstCopyForwardScheme(NULL)42{43_typeId = __FUNCTION__;44}4546bool47MM_CopyForwardDelegate::initialize(MM_EnvironmentVLHGC *env)48{49MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);50_breadthFirstCopyForwardScheme = MM_CopyForwardScheme::newInstance(env, extensions->heapRegionManager);5152return (NULL != _breadthFirstCopyForwardScheme);53}5455void56MM_CopyForwardDelegate::tearDown(MM_EnvironmentVLHGC *env)57{58if (NULL != _breadthFirstCopyForwardScheme) {59_breadthFirstCopyForwardScheme->kill(env);60_breadthFirstCopyForwardScheme = NULL;61}62}6364void65MM_CopyForwardDelegate::performCopyForwardForPartialGC(MM_EnvironmentVLHGC *env)66{67#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)68if (_extensions->isConcurrentCopyForwardEnabled())69{70_breadthFirstCopyForwardScheme->concurrentCopyForwardCollectionSet(env);71} else72#endif /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */73{74_breadthFirstCopyForwardScheme->copyForwardCollectionSet(env);75}76}7778void79MM_CopyForwardDelegate::preCopyForwardSetup(MM_EnvironmentVLHGC *env)80{81}8283void84MM_CopyForwardDelegate::postCopyForwardCleanup(MM_EnvironmentVLHGC *env)85{86/* Restart the allocation caches associated to all threads */87{88GC_VMThreadListIterator vmThreadListIterator(_javaVM);89J9VMThread *walkThread;90while((walkThread = vmThreadListIterator.nextVMThread()) != NULL) {91MM_EnvironmentBase *walkEnv = MM_EnvironmentBase::getEnvironment(walkThread->omrVMThread);92walkEnv->_objectAllocationInterface->restartCache(env);93}94}95}969798UDATA99MM_CopyForwardDelegate::estimateRequiredSurvivorBytes(MM_EnvironmentVLHGC *env)100{101UDATA estimatedSurvivorRequired = 0;102MM_HeapRegionManager *const regionManager = _extensions->heapRegionManager;103MM_CompactGroupPersistentStats *const persistentStats = _extensions->compactGroupPersistentStats;104GC_HeapRegionIteratorVLHGC regionIterator(regionManager, MM_HeapRegionDescriptor::MANAGED);105MM_HeapRegionDescriptorVLHGC *region = NULL;106while (NULL != (region = regionIterator.nextRegion())) {107if (region->_markData._shouldMark) {108UDATA compactGroup = MM_CompactGroupManager::getCompactGroupNumber(env, region);109double survivalRate = persistentStats[compactGroup]._historicalSurvivalRate;110UDATA freeMemory = region->getMemoryPool()->getFreeMemoryAndDarkMatterBytes();111estimatedSurvivorRequired += (UDATA)((double)(region->getSize() - freeMemory) * survivalRate);112}113}114return estimatedSurvivorRequired;115}116117118