Path: blob/master/runtime/gc_base/OwnableSynchronizerObjectList.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 OWNABLESYNCHRONIZEROBJECTLIST_HPP_24#define OWNABLESYNCHRONIZEROBJECTLIST_HPP_2526#include "j9.h"27#include "j9cfg.h"28#include "modron.h"2930#include "BaseNonVirtual.hpp"31#include "ObjectAccessBarrier.hpp"3233class MM_EnvironmentBase;3435/**36* A global list of OwnableSynchronizer objects.37*/38class MM_OwnableSynchronizerObjectList : public MM_BaseNonVirtual39{40/* data members */41private:42volatile j9object_t _head; /**< the head of the linked list of OwnableSynchronizer objects */43j9object_t _priorHead; /**< the head of the linked list before OwnableSynchronizer object processing */44MM_OwnableSynchronizerObjectList *_nextList; /**< a pointer to the next OwnableSynchronizer list in the global linked list of lists */45MM_OwnableSynchronizerObjectList *_previousList; /**< a pointer to the previous OwnableSynchronizer list in the global linked list of lists */46#if defined(J9VM_GC_VLHGC)47UDATA _objectCount; /**< the number of objects in the list */48#endif /* defined(J9VM_GC_VLHGC) */49protected:50public:5152/* function members */53private:54protected:55public:56/**57* Add the specified linked list of objects to the buffer.58* The objects are expected to be in a NULL terminated linked59* list, starting from head and end at tail.60* This call is thread safe.61*62* @param env[in] the current thread63* @param head[in] the first object in the list to add64* @param tail[in] the last object in the list to add65*/66void addAll(MM_EnvironmentBase* env, j9object_t head, j9object_t tail);6768/**69* Fetch the head of the linked list, as it appeared at the beginning of OwnableSynchronizer object processing.70* @return the head object, or NULL if the list is empty71*/72MMINLINE j9object_t getHeadOfList() { return _head; }7374/**75* Move the list to the prior list and reset the current list to empty.76* The prior list may be examined with wasEmpty() and getPriorList().77*/78void startOwnableSynchronizerProcessing() {79_priorHead = _head;80_head = NULL;81#if defined(J9VM_GC_VLHGC)82clearObjectCount();83#endif /* defined(J9VM_GC_VLHGC) */84}8586/**87* copy the list to the prior list for backup, can be restored via calling backoutList()88*/89MMINLINE void backupList() {90_priorHead = _head;91}9293/**94* restore the list from the prior list, and reset the prior list to empty.95*/96MMINLINE void backoutList() {97_head = _priorHead;98_priorHead = NULL;99}100101/**102* Determine if the list was empty at the beginning of OwnableSynchronizer object processing.103* @return true if the list was empty, false otherwise104*/105bool wasEmpty() { return NULL == _priorHead; }106107/**108* Fetch the head of the linked list, as it appeared at the beginning of OwnableSynchronizer object processing.109* @return the head object, or NULL if the list is empty110*/111j9object_t getPriorList() { return _priorHead; }112113/**114* Return a pointer to the next OwnableSynchronizer object list in the global linked list of lists, or NULL if this is the last list.115* @return the next list in the global list116*/117MMINLINE MM_OwnableSynchronizerObjectList* getNextList() { return _nextList; }118119/**120* Set the link to the next OwnableSynchronizer object list in the global linked list of lists.121* @param nextList[in] the next list, or NULL122*/123void setNextList(MM_OwnableSynchronizerObjectList* nextList) { _nextList = nextList; }124125/**126* Return a pointer to the previous OwnableSynchronizer object list in the global linked list of lists, or NULL if this is the first list.127* @return the next list in the global list128*/129MMINLINE MM_OwnableSynchronizerObjectList* getPreviousList() { return _previousList; }130131/**132* Set the link to the previous OwnableSynchronizer object list in the global linked list of lists.133* @param nextList[in] the next list, or NULL134*/135void setPreviousList(MM_OwnableSynchronizerObjectList* previousList) { _previousList = previousList; }136137/**138* Construct a new list.139*/140MM_OwnableSynchronizerObjectList();141142#if defined(J9VM_GC_VLHGC)143MMINLINE UDATA getObjectCount() { return _objectCount; }144MMINLINE void clearObjectCount() { _objectCount = 0; }145MMINLINE void incrementObjectCount(UDATA count)146{147MM_AtomicOperations::add((volatile UDATA *)&_objectCount, count);148}149#endif /* defined(J9VM_GC_VLHGC) */150151};152153#endif /* OWNABLESYNCHRONIZEROBJECTLIST_HPP_ */154155156