Path: blob/master/runtime/gc_base/ReferenceObjectList.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#ifndef REFERENCEOBJECTLIST_HPP_24#define REFERENCEOBJECTLIST_HPP_2526#include "j9.h"27#include "j9cfg.h"2829#include "BaseNonVirtual.hpp"3031class MM_EnvironmentBase;3233/**34* A global list of reference objects.35*/36class MM_ReferenceObjectList : public MM_BaseNonVirtual37{38/* data members */39private:40volatile j9object_t _weakHead; /**< the head of the linked list of weak reference objects */41volatile j9object_t _softHead; /**< the head of the linked list of soft reference objects */42volatile j9object_t _phantomHead; /**< the head of the linked list of phantom reference objects */43j9object_t _priorWeakHead; /**< the head of the weak linked list before reference object processing */44j9object_t _priorSoftHead; /**< the head of the soft linked list before reference object processing */45j9object_t _priorPhantomHead; /**< the head of the phantom linked list before reference object processing */46protected:47public:4849/* function members */50private:51protected:52public:53/**54* Add the specified linked list of objects to the buffer.55* The objects are expected to be in a NULL terminated linked56* list, starting from head and end at tail.57* This call is thread safe.58*59* @param env[in] the current thread60* @param referenceObjectType the type of objects being added (weak/soft/phantom)61* @param head[in] the first object in the list to add62* @param tail[in] the last object in the list to add63*/64void addAll(MM_EnvironmentBase* env, UDATA referenceObjectType, j9object_t head, j9object_t tail);6566/**67* Move the list to the prior list and reset the current list to empty.68* The prior list may be examined with wasEmpty() and getPriorList().69*/70void startWeakReferenceProcessing() {71_priorWeakHead = _weakHead;72_weakHead = NULL;73}7475/**76* Move the list to the prior list and reset the current list to empty.77* The prior list may be examined with wasEmpty() and getPriorList().78*/79void startSoftReferenceProcessing() {80_priorSoftHead = _softHead;81_softHead = NULL;82}8384/**85* Move the list to the prior list and reset the current list to empty.86* The prior list may be examined with wasEmpty() and getPriorList().87*/88void startPhantomReferenceProcessing() {89_priorPhantomHead = _phantomHead;90_phantomHead = NULL;91}9293/**94* Determine if the list was empty at the beginning of reference object processing.95* @return true if the list was empty, false otherwise96*/97bool wasWeakListEmpty() { return NULL == _priorWeakHead; }9899/**100* Determine if the list was empty at the beginning of reference object processing.101* @return true if the list was empty, false otherwise102*/103bool wasSoftListEmpty() { return NULL == _priorSoftHead; }104105/**106* Determine if the list was empty at the beginning of reference object processing.107* @return true if the list was empty, false otherwise108*/109bool wasPhantomListEmpty() { return NULL == _priorPhantomHead; }110111bool isWeakListEmpty() { return NULL == _weakHead; }112bool isSoftListEmpty() { return NULL == _softHead; }113bool isPhantomListEmpty() { return NULL == _phantomHead; }114115/**116* Fetch the head of the linked list, as it appeared at the beginning of reference object processing.117* @return the head object, or NULL if the list is empty118*/119j9object_t getPriorWeakList() { return _priorWeakHead; }120121/**122* Fetch the head of the linked list, as it appeared at the beginning of reference object processing.123* @return the head object, or NULL if the list is empty124*/125j9object_t getPriorSoftList() { return _priorSoftHead; }126127/**128* Fetch the head of the linked list, as it appeared at the beginning of reference object processing.129* @return the head object, or NULL if the list is empty130*/131j9object_t getPriorPhantomList() { return _priorPhantomHead; }132133/**134* Clear all of the prior lists.135* After this call, was{Weak|Soft|Phantom}ListEmpty() will return true.136*/137void resetPriorLists() {138_priorWeakHead = NULL;139_priorSoftHead = NULL;140_priorPhantomHead = NULL;141}142143/**144* Clear all lists, head or prior.145* After this call, was{Weak|Soft|Phantom}ListEmpty() will return true.146*/147void resetLists() {148resetPriorLists();149_weakHead = NULL;150_softHead = NULL;151_phantomHead = NULL;152}153154/**155* Construct a new list.156*/157MM_ReferenceObjectList();158};159160#endif /* REFERENCEOBJECTLIST_HPP_ */161162163