Path: blob/master/runtime/gc_base/FinalizableObjectBuffer.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(FINALIZABLEOBJECTBUFFER_HPP_)29#define FINALIZABLEOBJECTBUFFER_HPP_3031#include "j9.h"3233#include "FinalizeListManager.hpp"34#include "ObjectAccessBarrier.hpp"3536class GC_FinalizableObjectBuffer37{38private:39j9object_t _systemHead; /**< the head of the linked list of finalizable objects loaded by the system class loader */40j9object_t _systemTail; /**< the tail of the linked list of unfinalized objects loaded by the system class loader */41UDATA _systemObjectCount; /**< the number of buffered objects loaded by the system class loader */42j9object_t _defaultHead; /**< the head of the linked list of unfinalized objects not loaded by the system class loader */43j9object_t _defaultTail; /**< the tail of the linked list of unfinalized objects not loaded by the system class loader */44UDATA _defaultObjectCount; /**< the number of buffered objects not loaded by the system class loader */45MM_GCExtensions * const _extensions; /**< a cached pointer to the extensions structure */46J9ClassLoader* const _systemClassLoader;47protected:48public:4950private:51void addSystemObject(MM_EnvironmentBase* env, j9object_t object) {52if (NULL == _systemHead) {53Assert_MM_true(NULL == _systemTail);54Assert_MM_true(0 == _systemObjectCount);55_extensions->accessBarrier->setFinalizeLink(object, NULL);56_systemHead = object;57_systemTail = object;58_systemObjectCount = 1;59} else {60Assert_MM_true(NULL != _systemTail);61Assert_MM_true(0 != _systemObjectCount);62_extensions->accessBarrier->setFinalizeLink(object, _systemHead);63_systemHead = object;64_systemObjectCount += 1;65}66}6768void addDefaultObject(MM_EnvironmentBase* env, j9object_t object) {69if (NULL == _defaultHead) {70_extensions->accessBarrier->setFinalizeLink(object, NULL);71_defaultHead = object;72_defaultTail = object;73_defaultObjectCount = 1;74} else {75_extensions->accessBarrier->setFinalizeLink(object, _defaultHead);76_defaultHead = object;77_defaultObjectCount += 1;78}79}80protected:81public:82/**83* Add the specified unfinalized object to the buffer.84* @param env[in] the current thread85* @param object[in] the object to add86*/87virtual void add(MM_EnvironmentBase* env, j9object_t object)88{89if (_systemClassLoader == (J9OBJECT_CLAZZ((J9VMThread *)env->getOmrVMThread()->_language_vmthread, object)->classLoader)) {90addSystemObject(env, object);91} else {92addDefaultObject(env, object);93}94}9596void flush(MM_EnvironmentBase* env)97{98GC_FinalizeListManager *finalizeListManager = _extensions->finalizeListManager;99if (NULL != _systemHead) {100finalizeListManager->addSystemFinalizableObjects(_systemHead, _systemTail, _systemObjectCount);101_systemHead = NULL;102_systemTail = NULL;103_systemObjectCount = 0;104}105if (NULL != _defaultHead) {106finalizeListManager->addDefaultFinalizableObjects(_defaultHead, _defaultTail, _defaultObjectCount);107_defaultHead = NULL;108_defaultTail = NULL;109_defaultObjectCount = 0;110}111}112113/**114* Construct a new buffer.115* @param extensions[in] the GC extensions116*/117GC_FinalizableObjectBuffer(MM_GCExtensions *extensions) :118_systemHead(NULL)119,_systemTail(NULL)120,_systemObjectCount(0)121,_defaultHead(NULL)122,_defaultTail(NULL)123,_defaultObjectCount(0)124,_extensions(extensions)125,_systemClassLoader(((J9JavaVM *)extensions->getOmrVM()->_language_vm)->systemClassLoader)126{}127};128#endif /* FINALIZABLEOBJECTBUFFER_HPP_ */129130131