Path: blob/master/runtime/gc_base/OwnableSynchronizerObjectBuffer.cpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2014 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* 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-exception21*******************************************************************************/2223#include "j9.h"24#include "j9cfg.h"25#include "ModronAssertions.h"2627#include "OwnableSynchronizerObjectBuffer.hpp"2829#include "EnvironmentBase.hpp"30#include "GCExtensions.hpp"31#include "HeapRegionDescriptor.hpp"32#include "HeapRegionManager.hpp"33#include "ObjectAccessBarrier.hpp"3435MM_OwnableSynchronizerObjectBuffer::MM_OwnableSynchronizerObjectBuffer(MM_GCExtensions *extensions, UDATA maxObjectCount)36: MM_BaseVirtual()37, _maxObjectCount(maxObjectCount)38, _extensions(extensions)39{40_typeId = __FUNCTION__;41reset();42}4344void45MM_OwnableSynchronizerObjectBuffer::kill(MM_EnvironmentBase *env)46{47tearDown(env);48env->getForge()->free(this);49}5051void52MM_OwnableSynchronizerObjectBuffer::reset()53{54_head = NULL;55_tail = NULL;56_region = NULL;57/* set object count to appear full so that we force initialization on the next add */58_objectCount = _maxObjectCount;59}6061void62MM_OwnableSynchronizerObjectBuffer::flush(MM_EnvironmentBase* env)63{64if (NULL != _head) {65/* call the virtual flush implementation function */66flushImpl(env);67reset();68}69}7071void72MM_OwnableSynchronizerObjectBuffer::add(MM_EnvironmentBase* env, j9object_t object)73{74Assert_MM_true(object != _head);75Assert_MM_true(object != _tail);7677if ( (_objectCount < _maxObjectCount) && _region->isAddressInRegion(object) ) {78/* object is permitted in this buffer */79Assert_MM_true(NULL != _head);80Assert_MM_true(NULL != _tail);8182_extensions->accessBarrier->setOwnableSynchronizerLink(object, _head);83_head = object;84_objectCount += 1;85} else {86MM_HeapRegionDescriptor *region = _region;8788/* flush the buffer and start fresh */89flush(env);90_extensions->accessBarrier->setOwnableSynchronizerLink(object, NULL);91_head = object;92_tail = object;93_objectCount = 1;94if (NULL == region || !region->isAddressInRegion(object)) {95/* record the region which contains this object. Other objects will be permitted in the buffer if they are in the same region */96MM_HeapRegionManager *regionManager = _extensions->getHeap()->getHeapRegionManager();97region = regionManager->regionDescriptorForAddress(object);9899Assert_GC_true_with_message(env, NULL != region, "Attempt to access ownable synchronizer object located outside of heap (stack allocated?) %p\n", object);100}101_region = region;102}103Assert_MM_true(_region->isAddressInRegion(object));104}105106/*107* temporary place holder implementation - just delegate to the old fragment code.108*/109void110MM_OwnableSynchronizerObjectBuffer::flushImpl(MM_EnvironmentBase* env)111{112Assert_MM_unreachable();113}114115116