Path: blob/master/runtime/gc_glue_java/CompactSchemeFixupRoots.cpp
5990 views
/*******************************************************************************1* Copyright (c) 2001, 2020 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*******************************************************************************/21#include "CompactSchemeFixupRoots.hpp"2223#include "objectdescription.h"2425#include "Base.hpp"26#include "ConfigurationDelegate.hpp"27#include "EnvironmentBase.hpp"28#include "FinalizableObjectBuffer.hpp"29#include "FinalizableReferenceBuffer.hpp"30#include "FinalizeListManager.hpp"31#include "GCExtensions.hpp"32#include "Heap.hpp"33#include "HeapRegionIteratorStandard.hpp"34#include "ObjectAccessBarrier.hpp"35#include "Task.hpp"36#include "UnfinalizedObjectBuffer.hpp"37#include "UnfinalizedObjectList.hpp"383940#if defined(J9VM_GC_FINALIZATION)41void42MM_CompactSchemeFixupRoots::fixupFinalizableObjects(MM_EnvironmentBase *env)43{44MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);45GC_FinalizeListManager * finalizeListManager = extensions->finalizeListManager;4647{48GC_FinalizableObjectBuffer objectBuffer(extensions);49/* walk finalizable objects loaded by the system class loader */50omrobjectptr_t systemObject = finalizeListManager->resetSystemFinalizableObjects();51while (NULL != systemObject) {52omrobjectptr_t forwardedPtr = _compactScheme->getForwardingPtr(systemObject);53/* read the next link out of the moved copy of the object before we add it to the buffer */54systemObject = extensions->accessBarrier->getFinalizeLink(forwardedPtr);55/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */56objectBuffer.add(env, forwardedPtr);57}58objectBuffer.flush(env);59}6061{62GC_FinalizableObjectBuffer objectBuffer(extensions);63/* walk finalizable objects loaded by the all other class loaders */64omrobjectptr_t defaultObject = finalizeListManager->resetDefaultFinalizableObjects();65while (NULL != defaultObject) {66omrobjectptr_t forwardedPtr = _compactScheme->getForwardingPtr(defaultObject);67/* read the next link out of the moved copy of the object before we add it to the buffer */68defaultObject = extensions->accessBarrier->getFinalizeLink(forwardedPtr);69/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */70objectBuffer.add(env, forwardedPtr);71}72objectBuffer.flush(env);73}7475{76/* walk reference objects */77GC_FinalizableReferenceBuffer referenceBuffer(_extensions);78omrobjectptr_t referenceObject = finalizeListManager->resetReferenceObjects();79while (NULL != referenceObject) {80omrobjectptr_t forwardedPtr = _compactScheme->getForwardingPtr(referenceObject);81/* read the next link out of the moved copy of the object before we add it to the buffer */82referenceObject = _extensions->accessBarrier->getReferenceLink(forwardedPtr);83/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */84referenceBuffer.add(env, forwardedPtr);85}86referenceBuffer.flush(env);87}88}8990void91MM_CompactSchemeFixupRoots::fixupUnfinalizedObjects(MM_EnvironmentBase *env)92{93MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);94if (env->_currentTask->synchronizeGCThreadsAndReleaseMain(env, UNIQUE_ID)) {95MM_HeapRegionDescriptorStandard *region = NULL;96GC_HeapRegionIteratorStandard regionIterator(extensions->getHeap()->getHeapRegionManager());97while(NULL != (region = regionIterator.nextRegion())) {98MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);99for (UDATA i = 0; i < regionExtension->_maxListIndex; i++) {100MM_UnfinalizedObjectList *list = ®ionExtension->_unfinalizedObjectLists[i];101list->startUnfinalizedProcessing();102}103}104env->_currentTask->releaseSynchronizedGCThreads(env);105}106MM_HeapRegionDescriptorStandard *region = NULL;107GC_HeapRegionIteratorStandard regionIterator(extensions->getHeap()->getHeapRegionManager());108while(NULL != (region = regionIterator.nextRegion())) {109MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);110for (UDATA i = 0; i < regionExtension->_maxListIndex; i++) {111MM_UnfinalizedObjectList *list = ®ionExtension->_unfinalizedObjectLists[i];112if (!list->wasEmpty()) {113if(J9MODRON_HANDLE_NEXT_WORK_UNIT(env)) {114omrobjectptr_t object = list->getPriorList();115while (NULL != object) {116omrobjectptr_t forwardedPtr = _compactScheme->getForwardingPtr(object);117/* read the next link out of the moved copy of the object before we add it to the buffer */118object = extensions->accessBarrier->getFinalizeLink(forwardedPtr);119/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */120env->getGCEnvironment()->_unfinalizedObjectBuffer->add(env, forwardedPtr);121}122}123}124}125}126127/* restore everything to a flushed state before exiting */128env->getGCEnvironment()->_unfinalizedObjectBuffer->flush(env);129}130#endif /* J9VM_GC_FINALIZATION */131132133