The image is created by
void RexxMemory::createImage()
(memory/setup.cpp)

      RexxString *symb = getGlobalName(BASEIMAGELOAD);   /* get a name version of the string  */
                                           /* go resolve the program name       */
      RexxString *programName = ActivityManager::currentActivity->resolveProgramName(symb, OREF_NULL, OREF_NULL);


PlatformDefinitions.h (same for Windows & Unix)
    // name of the image file that is saved and restored.
    #define BASEIMAGE     "rexx.img"

    // name of the program called to load create the saved image file.                                                                */
    #define BASEIMAGELOAD "CoreClasses.orx"

================================================================================
interpreter\runtime\RexxCore.h
// this one is special, and is truly global.
EXTERNMEM RexxMemory  memoryObject;   /* memory object                     */

interpreter\memory\RexxMemory.cpp
/* NOTE:  There is just a single memory object in global storage.  We'll define      */
/* memobj to be the direct address of this memory object.                            */
RexxMemory memoryObject;


Attention :
RexxMemory::RexxMemory
n'initialise pas image_buffer à NULL, mais cette valeur est testée dans RexxMemory::restore

Initialisation bizarre dans RexxMemory::initialize :
    new (this) RexxMemory;  --> ça rappelle le constructeur RexxMemory::RexxMemory sur lui-même
    new (&newSpaceNormalSegments) NormalSegmentSet(this);
    new (&newSpaceLargeSegments) LargeSegmentSet(this);

    /* and the new/old Space segments    */
    new (&oldSpaceSegments) OldSpaceSegmentSet(this);


ClassTypeCodes.xsl
Ce fichier est généré

interpreter\behaviour\ClassTypeCodes.h
Ce fichier est généré

interpreter\behaviour\VirtualFunctionTable.cpp
Ce fichier est généré



interpreter\memory\Setup.cpp
RexxMemory::createImage
RexxMemory::restoreImage


interpreter\memory\RexxMemory.cpp
RexxMemory::create
RexxMemory::restore


SystemInterpreter::loadImage    Charge rexx.img (déclaré dans PlatformDefinitions.h)
    RexxMemory::restoreImage
        RexxMemory::initialize
            ...


RexxMemory::restore                                 interpreter\memory\RexxMemory.cpp
    RexxMemory::initialize                          interpreter\memory\RexxMemory.cpp
        Interpreter::startInterpreter               interpreter\runtime\Interpreter.cpp
            Interpreter::createInterpreterInstance  interpreter\runtime\Interpreter.cpp
                InstanceBlock::InstanceBlock        interpreter\runtime\Interpreter.cpp
                    ActivityDispatcher::invoke      interpreter\concurrency\ActivityDispatcher.cpp
                        RexxStart                   interpreter\api\InterpreterAPI.cpp
                            main                    utilities\rexx\platform\windows\rexx.cpp


interpreter\interpreter.mak
    Génération de fichiers à partir de rexxmsg.xml :
    $(INT_PLATFORM)\winmsgtb.rc: $(INT_PLATFORM)\WinMessageResource.xsl $(INTERPRETER_MESSAGES)\rexxmsg.xml
    $(INTERPRETER_MESSAGES)\RexxErrorCodes.h: $(INTERPRETER_MESSAGES)\RexxErrorCodes.xsl $(INTERPRETER_MESSAGES)\rexxmsg.xml
    $(INTERPRETER_MESSAGES)\DocErrorMessages.sgml: $(INTERPRETER_MESSAGES)\DocBookErrors.xsl $(INTERPRETER_MESSAGES)\rexxmsg.xml
    $(INTERPRETER_MESSAGES)\RexxMessageNumbers.h: $(INTERPRETER_MESSAGES)\RexxMessageNumbers.xsl $(INTERPRETER_MESSAGES)\rexxmsg.xml
    $(INTERPRETER_MESSAGES)\RexxMessageTable.h: $(INTERPRETER_MESSAGES)\RexxMessageTable.xsl $(INTERPRETER_MESSAGES)\rexxmsg.xml
    $(OR_APISRC)\oorexxerrors.h: $(INTERPRETER_MESSAGES)\ApiErrorCodes.xsl $(INTERPRETER_MESSAGES)\rexxmsg.xml

    Génération de fichiers à partir de PrimitiveClasses.xml :
    $(BEHAVIOUR)\PrimitiveBehaviourNames.h: $(BEHAVIOUR)\PrimitiveBehaviourNames.xsl $(BEHAVIOUR)\PrimitiveClasses.xml
    $(BEHAVIOUR)\PrimitiveBehaviours.cpp: $(BEHAVIOUR)\PrimitiveBehaviours.xsl $(BEHAVIOUR)\PrimitiveClasses.xml
    $(BEHAVIOUR)\VirtualFunctionTable.cpp: $(BEHAVIOUR)\VirtualFunctionTable.xsl $(BEHAVIOUR)\PrimitiveClasses.xml
    $(BEHAVIOUR)\ClassTypeCodes.h: $(BEHAVIOUR)\ClassTypeCodes.xsl $(BEHAVIOUR)\PrimitiveClasses.xml


Dans RexxMemory::restore, il n'y a que les classes Exported qui sont restaurées.


================================================================================
RexxMemory::virtualFunctionTable est utilisé dans :
ObjectClass.cpp
    RexxNilObject::operator new : setVirtualFunctions
RexxEnvelope.cpp
    RexxEnvelope::puff : setVirtualFunctions
RexxMemory.cpp
    RexxMemory::initialize : crée la table des vtables
    RexxMemory::restoreImage : affecte sa vtable à chaque objet de l'image
    RexxMemory::oldObject : initializeNewObject
    RexxMemory::newObject : initializeNewObject
    RexxMemory::newObjects : initializeNewObject
    RexxMemory::temporaryObject : initializeNewObject
RexxHashTable.cpp
    RexxHashTable::newInstance : initializeNewObject
RexxListTable.cpp
    RexxListTable::operator new : initializeNewObject
VirtualFunctionTable.cpp

================================================================================

RexxCore.h
    #define TheFunctionsDirectory RexxMemory::functionsDir


Setup.cpp
    void RexxMemory::createImage()
    {
      ...
      TheFunctionsDirectory = new_directory();
      ...
      kernel_public(CHAR_FUNCTIONS        ,TheFunctionsDirectory  ,TheKernel);


    void RexxMemory::restoreImage()
    {
        ...
        TheFunctionsDirectory = (RexxDirectory *)saveArray->get(saveArray_FUNCTIONS);


    void RexxMemory::saveImage(void)
    {
        ...
        saveArray->put((RexxObject *)TheFunctionsDirectory,  saveArray_FUNCTIONS);


RexxActivation.cpp
    RexxObject *RexxActivation::externalCall(RexxString *target, size_t _argcount, RexxExpressionStack *_stack,
        RexxString *calltype, ProtectedObject &resultObj)
    {
        // Step 1:  Check the global functions directory
        // this is actually considered part of the built-in functions, but these are
        // written in ooRexx.  The names are also case sensitive
        RoutineClass *routine = (RoutineClass *)TheFunctionsDirectory->get(target);


RexxMemory.hpp
    class RexxMemory : public RexxInternalObject
    {
      ...
      static RexxDirectory *environment;      // global environment
      static RexxDirectory *functionsDir;     // statically defined requires
      static RexxDirectory *commonRetrievers; // statically defined requires
      static RexxDirectory *kernel;           // the kernel directory
      static RexxDirectory *system;           // the system directory


RexxMemory.cpp
    RexxDirectory *RexxMemory::globalStrings = OREF_NULL;
    RexxDirectory *RexxMemory::environment = OREF_NULL;       // global environment
    RexxDirectory *RexxMemory::functionsDir = OREF_NULL;      // statically defined requires
    RexxDirectory *RexxMemory::commonRetrievers = OREF_NULL;
    RexxDirectory *RexxMemory::kernel = OREF_NULL;
    RexxDirectory *RexxMemory::system = OREF_NULL;


================================================================================
https://sourceforge.net/p/oorexx/bugs/1953/
================================================================================
#1953 Tracing in 5.1 can hang or crash method callbacks in BSF400Rexx850

Dom's patch
    Index: interpreter/execution/VariableDictionary.cpp
    ===================================================================
    --- interpreter/execution/VariableDictionary.cpp	(revision 12938)
    +++ interpreter/execution/VariableDictionary.cpp	(working copy)
    @@ -546,7 +546,8 @@
             // this one we need to use setField()
             if (waitingActivities == OREF_NULL)
             {
    -            setField(waitingActivities, new_array());              JLF: a GC can be triggered by setField!!!! new_array is not protected
    +            Protected<ArrayClass> arrActivities = new_array();
    +            setField(waitingActivities, arrActivities);
             }
             // add to the end of the queue
             waitingActivities->append(activity);

Code review:

RexxCore.h
    #define setField(r, v)  OrefSet(this, this->r, v)
    #define OrefSet(o,r,v) \
    {                      \
        if (o->isOldSpace()) \
        {                    \
            memoryObject.setOref(r, v); \

    // this one is special, and is truly global.
    extern MemoryObject memoryObject;


RexxMemory.hpp
    class MemoryObject : public RexxInternalObject
    {
        void        setOref(RexxInternalObject *variable, RexxInternalObject *value);
        MapTable         *old2new;           // the table for tracking old2new references.


RexxMemory.cpp
    void MemoryObject::setOref(RexxInternalObject *oldValue, RexxInternalObject *value)
    {
                old2new->decrement(oldValue);
                old2new->increment(value);


MapTable.hpp
    class MapTable : public RexxInternalObject
    {
               void   increment(RexxInternalObject *key);
        inline void   decrement(RexxInternalObject *key) { contents->decrement(key); }

        MapBucket *contents;     // the backing collection for this


MapTable.cpp
    /**
     * Increment the value associated with a key.  If the key does
     * not exist, it is inserted into the table with a value of 1.
     *
     * @param key    The target key.
     */
    void MapTable::increment(RexxInternalObject *index)
    {
        // try to insert in the existing hash tables...if this
        // fails, we're full and need to reallocate.
        if (!contents->increment(index))
        {
            // reallocate and try again
            reallocateContents();
            contents->increment(index);
        }
    }

================================================================================
Review code at risk with setField / OrefSet
================================================================================

Note: Rick provided a patch which is directly in setField.
    Index: interpreter/memory/RexxMemory.cpp
    ===================================================================
    --- interpreter/memory/RexxMemory.cpp	(revision 12943)
    +++ interpreter/memory/RexxMemory.cpp	(working copy)
    @@ -1638,6 +1638,8 @@
         // required then.
         if (old2new != OREF_NULL)
         {
    +        ProtectedObject p = value;   // because updating the table can trigger a GC, make sure this is protected.
    +
             // the index value is the one assigned there currently.  If this
             // is a newspace value, we should have a table entry with a reference
             // count for it in our table.

So this code review is useless, no need to fix individually the code at risk.


=====================
At risk with setField
=====================
ArrayClass.cpp
	ArrayClass::extend
BaseExecutable.cpp
	StringTable *BaseExecutable::getAnnotations()
ClassClass.cpp
	StringTable *RexxClass::getAnnotations()
	RexxObject *RexxClass::defineMethodsRexx(RexxObject *newMethods)
	void RexxClass::buildFinalClassBehaviour(RexxClass *superClass)
	RexxObject *RexxClass::defineMethod(RexxString *method_name, RexxObject *methodSource
	RexxObject *RexxClass::deleteMethod(RexxString  *method_name)
ClassDirective.cpp
	void ClassDirective::addConstantMethod(RexxString *name, MethodClass *method, RexxInstruction *directive, size_t maxStack, size_t variableIndex)
DirectoryClass.cpp
	RexxInternalObject *DirectoryClass::setMethodRexx(RexxString *name, MethodClass *methodobj)
IntegerClass.cpp
	RexxString *RexxInteger::primitiveMakeString()
LibraryPackage.cpp
	void LibraryPackage::loadRoutines(RexxRoutineEntry *table)
	NativeMethod *LibraryPackage::resolveMethod(RexxString *name)
MessageClass.cpp
	RexxObject *MessageClass::wait()
	RexxObject *MessageClass::sendRexx(RexxObject **arguments, size_t argCount)
	RexxObject *MessageClass::startRexx(RexxObject **arguments, size_t argCount)
	RexxObject *MessageClass::replyRexx(RexxObject **arguments, size_t argCount)
MethodDictionary.cpp
	void MethodDictionary::addInstanceMethod(RexxString *name, MethodClass *method)
MutableBufferClass.cpp
	void MutableBuffer::ensureCapacity(size_t addedLength)		maybe?
	RexxObject *MutableBuffer::setBufferSize(RexxInteger *size)
ObjectClass.cpp
	RexxObject *RexxObject::defineInstanceMethods(DirectoryClass *methods)
	RexxObject *RexxObject::defineInstanceMethod(RexxString *msgname, MethodClass *methobj, RexxClass *scope)
	RexxObject *RexxObject::deleteInstanceMethod(RexxString *msgname)
	VariableDictionary * RexxObject::getObjectVariables(RexxClass *scope)		maybe?
PackageClass.cpp
	void PackageClass::extractNameInformation()
	void PackageClass::mergeRequired(PackageClass *mergeSource)
	void PackageClass::mergeLibrary(LibraryPackage *mergeSource)
	void PackageClass::processInstall(RexxActivation *activation)
	void PackageClass::addInstalledClass(RexxString *name, RexxClass *classObject, bool publicClass)
	void PackageClass::addInstalledRoutine(RexxString *name, RoutineClass *routineObject, bool publicRoutine)
	StringTable *PackageClass::getAnnotations()
	void PackageClass::addNamespace(RexxString *name, PackageClass *package)
	DirectoryClass *PackageClass::getPackageLocal()
PackageClass.hpp
	void             setSecurityManager(RexxObject *manager) { setField(securityManager, new SecurityManager(manager)); }
RexxBehaviour.cpp
	void RexxBehaviour::copyBehaviour(RexxBehaviour *source)
	void RexxBehaviour::hideMethod(const char *name)
	void RexxBehaviour::replaceMethod(RexxString *methodName, MethodClass *method)
	void RexxBehaviour::inheritInstanceMethods(RexxBehaviour *source)
	void RexxBehaviour::defineMethod(RexxString *methodName, MethodClass *method)
	void RexxBehaviour::addInstanceMethod(RexxString *methodName, MethodClass *method)
	void RexxBehaviour::addScope(RexxClass *scope)
	void RexxBehaviour::mergeMethodDictionary(MethodDictionary *sourceDictionary)
RexxVariable.cpp
	void RexxVariable::inform(Activity *informee)
SmartBuffer.cpp
	size_t SmartBuffer::copyData(void *start, size_t length)	maybe?
StemClass.cpp
	RexxInternalObject *StemClass::remove(RexxObject **tailElements, size_t argCount)		maybe?
StringClass.cpp
	NumberString *RexxString::numberString()


is s protected?
BaseCode *BaseCode::setPackageObject(PackageClass *s)

is a protected?
void RexxClass::setAnnotations(StringTable *a)

is b protected?
void  RexxClass::setInstanceBehaviour(RexxBehaviour *b)


====================
at risk with OrefSet
====================
MutableBufferClass.cpp
	RexxObject *MutableBuffer::setBufferSize(RexxInteger *size)

