Path: blob/master/runtime/gc_base/ReferenceObjectBuffer.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 "j9.h"23#include "j9cfg.h"24#include "ModronAssertions.h"2526#include "ReferenceObjectBuffer.hpp"2728#include "EnvironmentBase.hpp"29#include "GCExtensions.hpp"30#include "HeapRegionDescriptor.hpp"31#include "HeapRegionManager.hpp"32#include "ObjectAccessBarrier.hpp"33#include "ReferenceObjectList.hpp"3435MM_ReferenceObjectBuffer::MM_ReferenceObjectBuffer(UDATA maxObjectCount)36: MM_BaseVirtual()37, _maxObjectCount(maxObjectCount)38{39_typeId = __FUNCTION__;40reset();41}4243void44MM_ReferenceObjectBuffer::kill(MM_EnvironmentBase *env)45{46tearDown(env);47env->getForge()->free(this);48}4950void51MM_ReferenceObjectBuffer::reset()52{53_head = NULL;54_tail = NULL;55_region = NULL;56_referenceObjectType = 0;57/* set object count to appear full so that we force initialization on the next add */58_objectCount = _maxObjectCount;59}6061void62MM_ReferenceObjectBuffer::flush(MM_EnvironmentBase* env)63{64if (NULL != _head) {65flushImpl(env);66reset();67}68}6970UDATA71MM_ReferenceObjectBuffer::getReferenceObjectType(MM_EnvironmentBase* env, j9object_t object)72{73return J9CLASS_FLAGS(J9GC_J9OBJECT_CLAZZ(object, env)) & J9AccClassReferenceMask;74}7576void77MM_ReferenceObjectBuffer::add(MM_EnvironmentBase* env, j9object_t object)78{79MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);8081if ( (_objectCount < _maxObjectCount) && _region->isAddressInRegion(object) && (getReferenceObjectType(env, object) == _referenceObjectType)) {82/* object is permitted in this buffer */83Assert_MM_true(NULL != _head);84Assert_MM_true(NULL != _tail);8586extensions->accessBarrier->setReferenceLink(object, _head);87_head = object;88_objectCount += 1;89} else {90MM_HeapRegionDescriptor *region = _region;9192/* flush the buffer and start fresh */93flush(env);9495extensions->accessBarrier->setReferenceLink(object, NULL);96_head = object;97_tail = object;98_objectCount = 1;99if (NULL == region || !region->isAddressInRegion(object)) {100/* record the type of object and the region which contains this object. Other objects will be permitted in the buffer if they match */101MM_HeapRegionManager *regionManager = extensions->getHeap()->getHeapRegionManager();102region = regionManager->regionDescriptorForAddress(object);103Assert_MM_true(NULL != region);104}105_region = region;106_referenceObjectType = getReferenceObjectType(env, object);107108}109}110111112113