Path: blob/master/runtime/gc_realtime/SweepSchemeRealtime.cpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2019 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 "GCExtensionsBase.hpp"23#include "MarkMap.hpp"24#include "MemoryPoolSegregated.hpp"25#include "RealtimeGC.hpp"2627#include "SweepSchemeRealtime.hpp"2829/**30* Allocate and initialize a new instance of the receiver.31* @return a new instance of the receiver, or NULL on failure.32*/33MM_SweepSchemeRealtime *34MM_SweepSchemeRealtime::newInstance(MM_EnvironmentBase *env, MM_RealtimeGC *realtimeGC, MM_Scheduler *scheduler, MM_MarkMap *markMap)35{36MM_SweepSchemeRealtime *instance;3738instance = (MM_SweepSchemeRealtime *)env->getForge()->allocate(sizeof(MM_SweepSchemeRealtime), MM_AllocationCategory::FIXED, OMR_GET_CALLSITE());39if (NULL != instance) {40new(instance) MM_SweepSchemeRealtime(env, realtimeGC, scheduler, markMap);41if (!instance->initialize(env)) {42instance->kill(env);43instance = NULL;44}45}4647return instance;48}4950/**51* Free the receiver and all associated resources.52*/53void54MM_SweepSchemeRealtime::kill(MM_EnvironmentBase *env)55{56tearDown(env);57env->getForge()->free(this);58}5960void61MM_SweepSchemeRealtime::preSweep(MM_EnvironmentBase *env)62{63_realtimeGC->setCollectorSweeping();64_scheduler->condYieldFromGC(env, _scheduler->beatNanos);6566MM_GCExtensionsBase *ext = env->getExtensions();67MM_SweepSchemeSegregated::preSweep(env);6869_realtimeGC->allThreadsAllocateUnmarked(env);70if (ext->isConcurrentSweepEnabled()) {71_realtimeGC->setCollectorConcurrentSweeping();72_realtimeGC->getRealtimeDelegate()->releaseExclusiveVMAccess(env, _scheduler->_exclusiveVMAccessRequired);73}74}7576void77MM_SweepSchemeRealtime::postSweep(MM_EnvironmentBase *env)78{79MM_GCExtensionsBase *ext = env->getExtensions();80if (ext->isConcurrentSweepEnabled()) {81_realtimeGC->getRealtimeDelegate()->acquireExclusiveVMAccess(env, _scheduler->_exclusiveVMAccessRequired);82_realtimeGC->setCollectorSweeping(); /* It might have been in ConcurrentSweep mode before. */83}8485MM_SweepSchemeSegregated::postSweep(env);8687MM_MemoryPoolSegregated *memoryPool = _realtimeGC->_memoryPool;88ext->gcTrigger = OMR_MAX(ext->gcInitialTrigger, ext->headRoom + memoryPool->getBytesInUse());89}9091void92MM_SweepSchemeRealtime::incrementalSweepArraylet(MM_EnvironmentBase *env)93{94_realtimeGC->setCollectorSweepingArraylets(true);9596MM_SweepSchemeSegregated::incrementalSweepArraylet(env);9798_realtimeGC->setCollectorSweepingArraylets(false);99}100101102void103MM_SweepSchemeRealtime::yieldFromSweep(MM_EnvironmentBase *env, uintptr_t yieldSlackTime)104{105_scheduler->condYieldFromGC(env, yieldSlackTime);106}107108uintptr_t109MM_SweepSchemeRealtime::resetCoalesceFreeRegionCount(MM_EnvironmentBase *env)110{111_coalesceFreeRegionCount = 0;112return 100000;113}114115bool116MM_SweepSchemeRealtime::updateCoalesceFreeRegionCount(uintptr_t range)117{118bool mustYield = false;119_coalesceFreeRegionCount += range;120if (_coalesceFreeRegionCount > MAX_REGION_COALESCE) {121_coalesceFreeRegionCount = 0;122mustYield = true;123}124return mustYield;125}126127uintptr_t128MM_SweepSchemeRealtime::resetSweepSmallRegionCount(MM_EnvironmentBase *env, uintptr_t sweepSmallRegionsPerIteration)129{130_sweepSmallRegionCount = 0;131_yieldSmallRegionCount = sweepSmallRegionsPerIteration >> 3;132return 50000;133}134135bool136MM_SweepSchemeRealtime::updateSweepSmallRegionCount()137{138bool mustYield = false;139_sweepSmallRegionCount += 1;140if (_sweepSmallRegionCount >= _yieldSmallRegionCount) {141_sweepSmallRegionCount = 0;142mustYield = true;143}144return mustYield;145}146147148149