Path: blob/master/runtime/gc_base/FinalizableReferenceBuffer.hpp
5985 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/**24* @file25* @ingroup GC_Base26*/2728#if !defined(FINALIZABLEREFERENCEBUFFER_HPP_)29#define FINALIZABLEREFERENCEBUFFER_HPP_3031#include "j9.h"3233#include "ObjectAccessBarrier.hpp"34#include "FinalizeListManager.hpp"3536class GC_FinalizableReferenceBuffer37{38private:39j9object_t _head; /**< the head of the linked list of reference objects */40j9object_t _tail; /**< the tail of the linked list of reference objects */41UDATA _count; /**< the number of buffered objects */42MM_GCExtensions * const _extensions; /**< a cached pointer to the extensions structure */43protected:44public:4546private:47protected:48public:49/**50* Add the specified reference object to the buffer.51* @param env[in] the current thread52* @param object[in] the object to add53*/54void add(MM_EnvironmentBase* env, j9object_t object)55{56if (NULL == _head) {57Assert_MM_true(NULL == _tail);58Assert_MM_true(0 == _count);59_extensions->accessBarrier->setReferenceLink(object, NULL);60_head = object;61_tail = object;62_count = 1;63} else {64Assert_MM_true(NULL != _tail);65Assert_MM_true(0 != _count);66_extensions->accessBarrier->setReferenceLink(object, _head);67_head = object;68_count += 1;69}70}7172void flush(MM_EnvironmentBase* env)73{74if (NULL != _head) {75Assert_MM_true(NULL != _tail);76Assert_MM_true(0 != _count);77GC_FinalizeListManager *finalizeListManager = _extensions->finalizeListManager;78finalizeListManager->addReferenceObjects(_head, _tail, _count);79_head = NULL;80_tail = NULL;81_count = 0;82}83}8485/**86* Construct a new buffer.87* @param extensions[in] the GC extensions88*/89GC_FinalizableReferenceBuffer(MM_GCExtensions *extensions) :90_head(NULL)91,_tail(NULL)92,_count(0)93,_extensions(extensions)94{}95};96#endif /* FINALIZABLEREFERENCEBUFFER_HPP_ */979899