OpenASIP
2.0
|
#include <SafePointer.hh>
Public Member Functions | |
virtual | ~SafePointer () |
SafePointable * | pointer () const |
void | setPointer (SafePointable *object) |
Static Public Member Functions | |
static bool | isAlive (SafePointer *pointerToCheck) |
static bool | isReferenced (const SafePointable *object) |
static void | addObjectReference (SectionIndexKey key, const SafePointable *obj) |
static void | addObjectReference (SectionOffsetKey key, const SafePointable *obj) |
static void | addObjectReference (FileOffsetKey key, const SafePointable *obj) |
static void | addObjectReference (SectionKey key, const SafePointable *obj) |
static SectionIndexKey | sectionIndexKeyFor (const SafePointable *obj) |
static SectionOffsetKey | sectionOffsetKeyFor (const SafePointable *obj) |
static FileOffsetKey | fileOffsetKeyFor (const SafePointable *obj) |
static SectionKey | sectionKeyFor (const SafePointable *obj) |
static void | notifyDeleted (const SafePointable *obj) |
static void | notifyDeleted (SafePointer *safePointer) |
static void | resolve () |
static void | cleanupKeyTables () |
static void | cleanup () |
template<typename MapType > | |
static bool | unresolvedReferences (const MapType &mapToCheck, const ReferenceKey **unresolvedKey) |
static const SafePointer * | replaceReference (const SafePointer *old, SafePointable *obj) |
static void | replaceAllReferences (SafePointable *newObj, SafePointable *oldObj) |
template<typename ObjType > | |
static SafePointer * | genericCreate (ObjType obj) |
Static Public Attributes | |
static const SafePointer | null |
The default SafePointer that is used in null references. More... | |
Protected Member Functions | |
SafePointer (SectionIndexKey key) | |
SafePointer (SectionOffsetKey key) | |
SafePointer (FileOffsetKey key) | |
SafePointer (SectionKey key) | |
SafePointer (SafePointable *object) | |
template<typename KeyType , typename MapType > | |
void | genericRegisterPointer (const KeyType &key, MapType &destinationMap, SafePointer *newSafePointer) |
Static Protected Member Functions | |
template<typename KeyType , typename MapType > | |
static void | genericAddObjectReference (const KeyType &key, MapType &destinationMap, const SafePointable *obj) |
template<typename KeyType , typename MapType > | |
static KeyType | genericKeyFor (const SafePointable *obj, MapType &sourceMap) |
template<typename MapType > | |
static void | safelyCleanupKeyTable (MapType &sourceMap, std::set< SafePointerList * > &listsToDelete) |
Private Types | |
typedef std::pair< const SafePointable *, void * > | KeyForCacheKey |
Key type for cache, void* is pointer to key map (sectioMap_, sectionOffsetMap, ...) More... | |
typedef std::map< KeyForCacheKey, const ReferenceKey * > | KeyForCacheMap |
Private Member Functions | |
SafePointer & | operator= (SafePointer &) |
Assignment not allowed. More... | |
SafePointer (SafePointer &) | |
Copying not allowed. More... | |
Private Attributes | |
SafePointable * | object_ |
The reference to the real object. More... | |
std::string | debugString_ |
Static Private Attributes | |
static SectionIndexMap * | sectionIndexMap_ = new SectionIndexMap |
Map of SafePointers that are requested using SectionIndexKeys. More... | |
static SectionOffsetMap * | sectionOffsetMap_ = new SectionOffsetMap |
Map of SafePointers that are requested using SectionOffsetKeys. More... | |
static FileOffsetMap * | fileOffsetMap_ = new FileOffsetMap |
Map of SafePointers that are requested using FileOffsetKeys. More... | |
static SectionMap * | sectionMap_ = new SectionMap |
Map of SafePointers that are requested using SectionKeys. More... | |
static ReferenceMap * | referenceMap_ = new ReferenceMap |
Map of SafePointers that have resolved references. More... | |
static SafePointerSet * | aliveSafePointers_ = new SafePointerSet |
Set that cointains all alive (not deleted) SafePointers for extra safety. More... | |
static KeyForCacheMap * | keyForCache_ |
Map for cache. More... | |
Indirection for object references.
Allows updating references later on, thus allows referencing objects that are created later. Helps with the dangling pointers problem, too.
References to objects that are not created yet are made with different kind of keys. These keys refer for example to sections and offsets in source binary file while reading the binary. After the binary is read and the object model of binary is constructed, these keys and keytables have no use.
Definition at line 188 of file SafePointer.hh.
|
private |
Key type for cache, void* is pointer to key map (sectioMap_, sectionOffsetMap, ...)
Definition at line 339 of file SafePointer.hh.
|
private |
Definition at line 340 of file SafePointer.hh.
|
virtual |
Destructor.
Informs of deletion of itself to the reference manager.
Definition at line 256 of file SafePointer.cc.
References notifyDeleted().
|
protected |
Construct a SafePointer using SectionIndexKey.
key | Key to use while requesting the reference. |
Definition at line 199 of file SafePointer.cc.
References genericRegisterPointer(), and sectionIndexMap_.
|
protected |
Construct a SafePointer using SectionOffsetKey.
key | Key to use while requesting the reference. |
Definition at line 210 of file SafePointer.cc.
References genericRegisterPointer(), and sectionOffsetMap_.
|
protected |
Construct a SafePointer using FileOffsetKey.
key | Key to use while requesting the reference. |
Definition at line 221 of file SafePointer.cc.
References fileOffsetMap_, and genericRegisterPointer().
|
protected |
Construct a SafePointer using section reference.
key | Key object to use while requesting the reference. |
Definition at line 232 of file SafePointer.cc.
References genericRegisterPointer(), and sectionMap_.
|
protected |
Construct a SafePointer using object reference.
object | Object to use while requesting the reference. |
Definition at line 243 of file SafePointer.cc.
References genericRegisterPointer(), and referenceMap_.
|
private |
Copying not allowed.
|
static |
Inform of a connection between a FileOffsetKey and an object.
Connects given key with object and sets possible old SafePointers connected with the key to point to this object.
key | Key that the object is connected to. |
obj | Pointer to the connected object. |
KeyAlreadyExists | If entry with given key already exists. |
Definition at line 337 of file SafePointer.cc.
References fileOffsetMap_, and genericAddObjectReference().
|
static |
Inform of a connection between a SectionIndexKey and an object.
Connects given key with object and sets possible old SafePointers connected with the key to point to this object.
key | Key that the object is connected to. |
obj | Pointer to the connected object. |
KeyAlreadyExists | If entry with given key already exists. |
Definition at line 306 of file SafePointer.cc.
References genericAddObjectReference(), and sectionIndexMap_.
Referenced by TPEF::TPEFLineNumSectionWriter::actualWriteData(), TPEF::TPEFStringSectionWriter::actualWriteData(), TPEF::TPEFResourceSectionWriter::actualWriteData(), TPEF::TPEFRelocSectionWriter::actualWriteData(), TPEF::TPEFASpaceSectionWriter::actualWriteData(), TPEF::TPEFCodeSectionWriter::actualWriteData(), TPEF::TPEFDataSectionWriter::actualWriteData(), TPEF::TPEFDebugSectionWriter::actualWriteData(), TPEF::TPEFSymbolSectionWriter::actualWriteData(), TPEF::TPEFSectionWriter::actualWriteHeader(), TPEF::TPEFUDataSectionWriter::createKeys(), TPEF::AOutSymbolSectionReader::initializeSymbol(), TPEF::TPEFASpaceSectionReader::readData(), TPEF::TPEFSymbolSectionReader::readData(), TPEF::TPEFCodeSectionReader::readData(), TPEF::TPEFRelocSectionReader::readData(), TPEF::TPEFSectionReader::readData(), TPEF::AOutSymbolSectionReader::readData(), TPEF::TPEFReader::readData(), TPEF::AOutReader::readData(), resolve(), TPEF::AOutTextSectionReader::setReference(), and TPEF::TPEFASpaceSectionWriter::writeElement().
|
static |
Inform of a connection between a SectionKey and an object.
Connects given key with object and sets possible old SafePointers connected with the key to point to this object.
key | Key that the object is connected to. |
obj | Pointer to the connected object. |
KeyAlreadyExists | If entry with given key already exists. |
Definition at line 352 of file SafePointer.cc.
References genericAddObjectReference(), and sectionMap_.
|
static |
Inform of a connection between a SectionOffsetKey and an object.
Connects given key with object and sets possible old SafePointers connected with the key to point to this object.
key | Key that the object is connected to. |
obj | Pointer to the connected object. |
KeyAlreadyExists | If entry with given key already exists. |
Definition at line 321 of file SafePointer.cc.
References genericAddObjectReference(), and sectionOffsetMap_.
|
static |
Frees all dynamically allocated memory consumed in reference managing.
Deletes all entires in all maps, safe pointer lists in them and all alive safe pointers. This method should be called in the destructor of Binary or in the end of the program.
Definition at line 667 of file SafePointer.cc.
References cleanupKeyTables(), MapTools::deleteAllValues(), and referenceMap_.
Referenced by TPEF::Binary::~Binary().
|
static |
Deletes all entries in all key maps, doesn't clean the ReferenceMap.
Deletes also the SafePointer lists found in the maps if they are not found in the reference map. Does not delete SafePointers. This can be called to free some needless resources after the object model of binary file is fully constructed, and resolve() is called without an exception.
Definition at line 644 of file SafePointer.cc.
References AssocTools::deleteAllItems(), fileOffsetMap_, keyForCache_, safelyCleanupKeyTable(), sectionIndexMap_, sectionMap_, and sectionOffsetMap_.
Referenced by cleanup(), TPEF::BinaryReader::readBinary(), and TPEF::BinaryWriter::writeBinary().
|
static |
Returns the FileOffsetKey connected to given object.
obj | Object to look the key for. |
KeyNotFound | If the key cannot be found for the object. |
Definition at line 394 of file SafePointer.cc.
References fileOffsetMap_.
Referenced by TPEF::FileOffsetReplacer::tryToReplace().
|
staticprotected |
Referenced by addObjectReference().
|
static |
|
staticprotected |
|
protected |
Referenced by SafePointer().
|
static |
Check if SafePointer is alive, that is it's not deleted yet.
pointerToCheck | The pointer to check. |
Definition at line 267 of file SafePointer.cc.
References aliveSafePointers_, and AssocTools::containsKey().
Referenced by TPEF::ReferenceManager::SafePointerList::cleanupDead(), and TPEF::ReferenceManager::SafePointerList::setReference().
|
static |
Check if object is referenced, that is reference manager is managing SafePointers that point to that object.
object | Object to check. |
Definition at line 282 of file SafePointer.cc.
References TPEF::ReferenceManager::SafePointerList::cleanupDead(), MapTools::containsKey(), TPEF::ReferenceManager::SafePointerList::length(), and referenceMap_.
Referenced by TPEF::TPEFStringSectionWriter::actualWriteData(), TPEF::TPEFDataSectionWriter::actualWriteData(), TPEF::TPEFCodeSectionWriter::actualWriteData(), and TPEF::TPEFUDataSectionWriter::createKeys().
|
static |
Inform of deletion of an object.
All SafePointers that are pointing to the deleted object are set to NULL and the object's entry is removed from the ReferenceMap.
obj | Deleted object. |
Definition at line 421 of file SafePointer.cc.
References assert, TPEF::ReferenceManager::SafePointerList::cleanup(), MapTools::containsKey(), MapTools::containsValue(), fileOffsetMap_, referenceMap_, sectionIndexMap_, sectionMap_, and sectionOffsetMap_.
Referenced by TPEF::SafePointable::~SafePointable(), and ~SafePointer().
|
static |
Inform of deletion of a SafePointer.
Removes SafePointer from the list of alive SafePointers.
safePointer | The deleted SafePointer. |
Definition at line 455 of file SafePointer.cc.
References assert.
|
private |
Assignment not allowed.
SafePointable* TPEF::ReferenceManager::SafePointer::pointer | ( | ) | const |
|
static |
Referenced by TPEF::AOutSymbolSectionReader::finalize().
|
static |
|
static |
Tries to resolve unresolved references.
Unreselved references are tried to be resolved by requesting a chunk with the section's chunk() method the reference points to. Chunks mean practically offset in the section and the size of the referenced data. If there's an unresolved reference to an offset in a section that can be chunked (section contains raw data), then we can create new elements using chunk() 'on demand'.
UnresolvedReference | If unresolvable references are found. |
Definition at line 480 of file SafePointer.cc.
References __func__, addObjectReference(), assert, TPEF::Section::chunk(), MapTools::containsKey(), TPEF::ReferenceManager::FileOffsetKey::fileOffset(), fileOffsetMap_, TPEF::ReferenceManager::SafePointerList::front(), TPEF::ReferenceManager::SectionIndexKey::index(), TPEF::ReferenceManager::SectionOffsetKey::offset(), TPEF::ReferenceManager::SafePointerList::reference(), referenceMap_, TPEF::ReferenceManager::SectionIndexKey::sectionId(), TPEF::ReferenceManager::SectionOffsetKey::sectionId(), TPEF::ReferenceManager::SectionKey::sectionId(), sectionIndexMap_, sectionMap_, sectionOffsetMap_, and unresolvedReferences().
Referenced by TPEF::BinaryReader::readBinary().
|
staticprotected |
Referenced by cleanupKeyTables().
|
static |
Returns the SectionIndexKey connected to given object.
obj | Object to look the key for. |
KeyNotFound | If the key cannot be found for the object. |
Definition at line 366 of file SafePointer.cc.
References sectionIndexMap_.
Referenced by TPEF::SectionIndexReplacer::tryToReplace().
|
static |
Returns the SectionKey connected to given object.
obj | Object to look the key for. |
KeyNotFound | If the key cannot be found for the object. |
Definition at line 408 of file SafePointer.cc.
References sectionMap_.
Referenced by TPEF::TPEFStringSectionWriter::actualWriteData(), TPEF::TPEFASpaceSectionWriter::actualWriteData(), TPEF::TPEFDataSectionWriter::actualWriteData(), TPEF::TPEFCodeSectionWriter::actualWriteData(), TPEF::TPEFSymbolSectionWriter::actualWriteData(), TPEF::TPEFUDataSectionWriter::createKeys(), TPEF::TPEFRelocSectionReader::finalize(), and TPEF::SectionIdReplacer::tryToReplace().
|
static |
Returns the SectionOffsetKey connected to given object.
obj | Object to look the key for. |
KeyNotFound | If the key cannot be found for the object. |
Definition at line 380 of file SafePointer.cc.
References sectionOffsetMap_.
Referenced by TPEF::SectionOffsetReplacer::tryToReplace().
void TPEF::ReferenceManager::SafePointer::setPointer | ( | SafePointable * | object | ) |
Referenced by TPEF::ReferenceManager::SafePointerList::append().
|
static |
Referenced by resolve().
|
staticprivate |
Set that cointains all alive (not deleted) SafePointers for extra safety.
Definition at line 332 of file SafePointer.hh.
Referenced by isAlive().
|
private |
Definition at line 352 of file SafePointer.hh.
|
staticprivate |
Map of SafePointers that are requested using FileOffsetKeys.
Definition at line 322 of file SafePointer.hh.
Referenced by addObjectReference(), cleanupKeyTables(), fileOffsetKeyFor(), notifyDeleted(), resolve(), and SafePointer().
|
staticprivate |
Map for cache.
Definition at line 343 of file SafePointer.hh.
Referenced by cleanupKeyTables().
|
static |
The default SafePointer that is used in null references.
Definition at line 229 of file SafePointer.hh.
Referenced by TPEF::ASpaceSection::isUndefined(), TPEF::TPEFSectionReader::readData(), TPEF::TPEFReader::readData(), and TPEF::TPEFLineNumSectionReader::readInfo().
|
private |
The reference to the real object.
Definition at line 313 of file SafePointer.hh.
|
staticprivate |
Map of SafePointers that have resolved references.
Definition at line 328 of file SafePointer.hh.
Referenced by cleanup(), isReferenced(), notifyDeleted(), resolve(), and SafePointer().
|
staticprivate |
Map of SafePointers that are requested using SectionIndexKeys.
Definition at line 316 of file SafePointer.hh.
Referenced by addObjectReference(), cleanupKeyTables(), notifyDeleted(), resolve(), SafePointer(), and sectionIndexKeyFor().
|
staticprivate |
Map of SafePointers that are requested using SectionKeys.
Definition at line 325 of file SafePointer.hh.
Referenced by addObjectReference(), cleanupKeyTables(), notifyDeleted(), resolve(), SafePointer(), and sectionKeyFor().
|
staticprivate |
Map of SafePointers that are requested using SectionOffsetKeys.
Definition at line 319 of file SafePointer.hh.
Referenced by addObjectReference(), cleanupKeyTables(), notifyDeleted(), resolve(), SafePointer(), and sectionOffsetKeyFor().