Path: blob/master/runtime/gc_realtime/RealtimeAccessBarrier.hpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2021 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*******************************************************************************/212223#if !defined(REALTIMEACCESSBARRIER_HPP_)24#define REALTIMEACCESSBARRIER_HPP_2526#include "j9.h"27#include "j9cfg.h"2829#if defined(J9VM_GC_REALTIME)3031#include "Metronome.hpp"32#include "ObjectAccessBarrier.hpp"33#include "RememberedSetSATB.hpp"3435class MM_EnvironmentBase;36class MM_EnvironmentRealtime;37class MM_RealtimeMarkingScheme;38class MM_RealtimeGC;3940/**41* Base access barrier for the realtime collectors.42* The realtime collectors may use objects during a GC phase, and relies on the43* access barrier to ensure that mutator threads only ever see objects in their44* new location. This is implemented using a forwarding pointer in each object45* that normally points to the object itself, but after an object has been46* moved, points to the new location. This class also implements the snapshot47* at the beginning barrier that remembers overwritten values.48*/4950class MM_RealtimeAccessBarrier : public MM_ObjectAccessBarrier51{52/* Data members & types */53public:54protected:55MM_RealtimeMarkingScheme *_markingScheme;56MM_RealtimeGC *_realtimeGC;5758private:59bool _doubleBarrierActive; /**< Global indicator that the double barrier is active. New threads will be set to double barrier mode if this falg is true. */6061/* Methods */62public:63/* Constructors & destructors */64MM_RealtimeAccessBarrier(MM_EnvironmentBase *env) :65MM_ObjectAccessBarrier(env),66_markingScheme(NULL),67_realtimeGC(NULL)68{69_typeId = __FUNCTION__;70}7172/* Inherited from MM_ObjectAccessBarrier */73virtual J9Object* referenceGet(J9VMThread *vmThread, J9Object *refObject);74virtual void referenceReprocess(J9VMThread *vmThread, J9Object *refObject);7576virtual void jniDeleteGlobalReference(J9VMThread *vmThread, J9Object *reference);77virtual void stringConstantEscaped(J9VMThread *vmThread, J9Object *stringConst);78virtual void deleteHeapReference(MM_EnvironmentBase *env, J9Object *object);7980virtual void storeObjectToInternalVMSlot(J9VMThread *vmThread, J9Object** destSlot, J9Object *value);8182virtual void* jniGetPrimitiveArrayCritical(J9VMThread* vmThread, jarray array, jboolean *isCopy);83virtual void jniReleasePrimitiveArrayCritical(J9VMThread* vmThread, jarray array, void * elems, jint mode);84virtual const jchar* jniGetStringCritical(J9VMThread* vmThread, jstring str, jboolean *isCopy);85virtual void jniReleaseStringCritical(J9VMThread* vmThread, jstring str, const jchar* elems);8687#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)88/**89* Check is class alive90* Required to prevent visibility of dead classes in incremental GC policies91* Check is J9_GC_CLASS_LOADER_DEAD flag set for classloader and try to mark92* class loader object if bit is not set to force class to be alive93* @param javaVM pointer to J9JavaVM94* @param classPtr class to check95* @return true if class is alive96*/97virtual bool checkClassLive(J9JavaVM *javaVM, J9Class *classPtr);98#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */99100protected:101/* Constructors & destructors */102virtual bool initialize(MM_EnvironmentBase *env);103virtual void tearDown(MM_EnvironmentBase *env);104virtual void kill(MM_EnvironmentBase *env);105106/* Inherited from MM_ObjectAccessBarrier */107virtual mm_j9object_t readObjectFromInternalVMSlotImpl(J9VMThread *vmThread, j9object_t *srcAddress, bool isVolatile=false);108109/* New methods */110void validateWriteBarrier(J9VMThread *vmThread, J9Object *dstObject, fj9object_t *dstAddress, J9Object *srcObject);111virtual void rememberObjectImpl(MM_EnvironmentBase *env, J9Object *object);112113private:114/* New methods */115void rememberObject(MM_EnvironmentBase *env, J9Object *object);116void rememberObjectIfBarrierEnabled(J9VMThread *vmThread, J9Object* object);117118bool preObjectStoreInternal(J9VMThread *vmThread, J9Object *destClass, J9Object **destAddress, J9Object *value, bool isVolatile);119bool preObjectStoreInternal(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *value, bool isVolatile);120bool preObjectStoreInternal(J9VMThread *vmThread, J9Object **destAddress, J9Object *value, bool isVolatile);121122MMINLINE bool isBarrierActive(MM_EnvironmentBase* env)123{124MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);125return !extensions->sATBBarrierRememberedSet->isGlobalFragmentIndexPreserved();126}127128MMINLINE bool isDoubleBarrierActiveOnThread(J9VMThread *vmThread)129{130/* The double barrier is enabled in realtime by setting the threads remembered set fragment index131* to the special value, this ensures the JIT will go out-of line. We can determine if the double132* barrier is active simply by checking if the fragment index corresponds to the special value.133*/134return (J9GC_REMEMBERED_SET_RESERVED_INDEX == vmThread->sATBBarrierRememberedSetFragment.localFragmentIndex);135}136137bool markAndScanContiguousArray(MM_EnvironmentRealtime *env, J9IndexableObject *objectPtr);138void scanContiguousArray(MM_EnvironmentRealtime *env, J9IndexableObject *objectPtr);139140public:141static MM_RealtimeAccessBarrier *newInstance(MM_EnvironmentBase *env);142MMINLINE void setDoubleBarrierActive() { _doubleBarrierActive = true; }143MMINLINE void setDoubleBarrierInactive() { _doubleBarrierActive = false; }144MMINLINE bool isDoubleBarrierActive() { return _doubleBarrierActive; }145void setDoubleBarrierActiveOnThread(MM_EnvironmentBase* env);146void setDoubleBarrierInactiveOnThread(MM_EnvironmentBase* env);147virtual void initializeForNewThread(MM_EnvironmentBase* env);148149virtual bool preObjectStore(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *value, bool isVolatile=false);150virtual bool preObjectStore(J9VMThread *vmThread, J9Object *destClass, J9Object **destAddress, J9Object *value, bool isVolatile=false);151virtual bool preObjectStore(J9VMThread *vmThread, J9Object **destAddress, J9Object *value, bool isVolatile=false);152153virtual I_32 backwardReferenceArrayCopyIndex(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots);154virtual I_32 forwardReferenceArrayCopyIndex(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots);155156virtual bool checkStringConstantsLive(J9JavaVM *javaVM, j9object_t stringOne, j9object_t stringTwo);157virtual bool checkStringConstantLive(J9JavaVM *javaVM, j9object_t string);158159/**160* Remember objects that are forced onto the finalizable list at shutdown.161* Called from FinalizerSupport finalizeForcedUnfinalizedToFinalizable162*163* @param vmThread current J9VMThread (aka JNIEnv)164* @param object object forced onto the finalizable list165*/166virtual void forcedToFinalizableObject(J9VMThread* vmThread, J9Object *object);167168private:169void printClass(J9JavaVM *javaVM, J9Class* clazz);170};171172#endif /* J9VM_GC_REALTIME */173174#endif /*REALTIMEACCESSBARRIER_HPP_*/175176177