Path: blob/master/runtime/gc_base/ReferenceObjectBuffer.hpp
5985 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#ifndef REFERENCEOBJECTBUFFER_HPP_23#define REFERENCEOBJECTBUFFER_HPP_2425#include "j9.h"26#include "j9cfg.h"27#include "BaseVirtual.hpp"2829class MM_EnvironmentBase;30class MM_HeapRegionDescriptor;31class MM_ReferenceObjectList;3233/**34* A per-thread buffer of reachable reference objects.35* The buffer is periodically flushed to the global list.36*/37class MM_ReferenceObjectBuffer : public MM_BaseVirtual38{39private:40protected:41j9object_t _head; /**< the head of the linked list of reference objects */42j9object_t _tail; /**< the tail of the linked list of reference objects */43MM_HeapRegionDescriptor* _region; /**< the region in which all buffered objects are located */44UDATA _referenceObjectType; /** the type of objects being buffered */45UDATA _objectCount; /**< the number of buffered objects */46const UDATA _maxObjectCount; /**< the maximum number of objects permitted before a forced flush */47public:4849private:5051/**52* Reset a flushed buffer to the empty state.53*/54void reset();5556/**57* Determine the type (weak/soft/phantom) of the specified reference object.58* @param object[in] the object to examine59* @return one of J9AccClassReferenceWeak, J9AccClassReferenceSoft or J9AccClassReferencePhantom60*/61UDATA getReferenceObjectType(MM_EnvironmentBase* env, j9object_t object);6263protected:6465virtual bool initialize(MM_EnvironmentBase *env) = 0;66virtual void tearDown(MM_EnvironmentBase *env) = 0;6768/**69* Flush the contents of the buffer to the appropriate global buffers.70* Subclasses must override.71* @param env[in] the current thread72*/73virtual void flushImpl(MM_EnvironmentBase* env) = 0;7475public:7677void kill(MM_EnvironmentBase *env);7879/**80* Add the specified reference object to the buffer.81* @param env[in] the current thread82* @param object[in] the object to add83* @return true if the addition succeeded, false if the list must be flushed first84*/85void add(MM_EnvironmentBase* env, j9object_t object);8687/**88* Flush the contents of the buffer to the appropriate global buffers.89* @param env[in] the current thread90*/91void flush(MM_EnvironmentBase* env);9293/**94* Determine if the buffer is empty.95* @return true if there are no objects in the buffer96*/97bool isEmpty() { return NULL == _head; }9899/**100* Construct a new buffer.101* @param maxObjectCount the maximum number of objects permitted before a forced flush102*/103MM_ReferenceObjectBuffer(UDATA maxObjectCount);104};105106#endif /* REFERENCEOBJECTBUFFER_HPP_ */107108109