Index - All Packages - All Categories - All Classes

Class SnarfHandler

A SnarfHandler breaks a snarf into abstract subarrays of bytes into whic flocks are stored. These indexed flock storage areas are accessed through readStreams and writeStreams provided by the SnarfHandler. SnarfHandlers also provide the ability to resize these flock areas and associate a couple of flag bits with them. All access to the snarf goes through a single snarfHandler.

The beginning of the snarf is dedicated to a table that describes the locations and sizes of the contained flock areas. Currently, we allocate space between the flock nearest the front of the snarf and the end of the mapTable. When not enough space exists between the two, we compact the flock storage areas towards the back (highest address) of the snarf and try to allocate again.

An index in the snarfHAndler can be associated either with one of these flock storage areas or with a snarfID and index to look further for the storage of a given flock. Right now, the SnarfHAndler keeps the forwarding information in a flock storage area, but it will soon be put into the mapTable directly.

Forwarding pointers occur when a flock outgrows a snarf, and must be moved elsewhere. Eventually all other snarfs that have objects which point to the forwarding pointer are updated, and the forwarding pointer can be deallocated, but decisions about this must be made by objects external to the SnarfHandler.

The forwarded flag is stored on the snarfID. The forgotten flag is stored on the size. Both use the same Flag mask for accessing the flag, and the Value mask for accessing the value.

Package: Udanax-Gold
All Superclasses: Object Heaper
Protocols: Object
Categories: Xanadu-Snarf

Class Methods

fenceSize

The number of bytes for one fence (Each flock requires two).

linkTimeNonInherited


make: snarfHandle


mapCellOverhead

Return the number of bytes for a single map record, plus the space for the
fence. The fence will be just the index of the flock stored at the beginning and
the end of the flock's memory

mapCellSize

Return the number of bytes for a single map record.

mapOverhead

The map starts just after the basic header. The basic header currently has
the number of entries in the map and total amount of free space remaining.

quickSort: offsets with: indices with: first with: last


quickSort: offsets with: indices with: os with: first with: last


sort: offsets

Sort the offsets array in place, and return an array of the same size that maps from the new index of each element to its original index. The offsets array is *assumed* to be terminated with a guard element which is greater than or equal to all the other elements of the array according to descending order. If this isn't true, havoc may result.

sort: offsets with: os

Sort the offsets array in place, and return an array of the same size that maps from the new index of each element to its original index. The offsets array is *assumed* to be terminated with a guard element which is greater than or equal to all the other elements of the array according to the sorting order. If this isn't true, havoc may result.

sortTest: array

self sortTest: #(2 3 4 1).
self sortTest: #().
self sortTest: #(1000 1000 1000).
self sortTest: #(1 2 3 4).
self sortTest: #(1).
self sortTest: #(2 2 3 3 4 4 1 1).

sortTestDown: array

self sortTestDown: #(2 3 4 1).
self sortTestDown: #().
self sortTestDown: #(1000 1000 1000).
self sortTestDown: #(1 2 3 4).
self sortTestDown: #(1).
self sortTestDown: #(2 2 3 3 4 4 1 1).

swap: array with: i with: j



Instance Methods

actualHashForEqual


allocateCells: indices

Add more cells to the mapTable. Make sure that there is enough space for
those cells, then initialize. The size is initially 0 and the offset points past
the end of the snarf.

at: ind allocate: flockSize

Allocate flockSize bytes for the flock at the index ind.

at: index storeForget: flag

See the comment on isForgotten:. Set or clear the forgetFlag for the flock at index.

at: index storeIndex: offset

Store the offset as the starting location for the data of the flock at index.
Update the cache of nearestFlock. This also clears the forwarded flag.

at: index storeSize: size

Store size as the number of bytes for the flock at index. If the
space is at a 0, then change the corresponding pointer to past the end of
the snarf so that we don't find it in our searches.

checkFence: index

If we are using fences around flock storage areas, then return true only if the fences are still in place for the flock at index. Fences are extra storage at the front and back of a flock storage area that contains the index of that flock. These are used for runtime checks that one flock hasn't stepped into the space of another.

checkFences

See checkFence: Check the fences for all flocks and blast if any are violated.

checkIndex: index

Blast if the index is not represented in the table. This is just simple bounds checking.

clearSpace: count

This checks for count bytes available at the end of the mapTable. If
there isn't enough, it compacts everything and tries again.

compact

Compress flock storage areas towards the end of the snarf, leaving all
freespace between the end of the mapTable and the nearest flock.

consistencyCheck

Generic checking hook to do slow runtime consistency checking when debugging. No checks are active currently.

create: handle


destruct

Write my internal constants to the snarf before I go away.

Overrides: Heaper

fetchForward: index

If the flock specified by index has been forwarded, return a FlockLocation with the SnarfID and index of its new location.

flockOffset: index

Return the index of the first byte of the actual data associated with flock number index. This is like indexOf: except that it leaves room for fencePosts on either side of the flock storage area.

flocksEnd

Return the index of the cell one greater than the size of the entire snarf. This is just past the end of the storage area for flocks.

flockSize: index

Return the number of bytes in the flock at index

forward: index to: newSnarfID with: newIndex

Associate a forwarder with index. Throw away whatever storage
was assigned to it and store the forwarder information in the mapCell.

getOffset: index

Return the index of the first byte of the actual data associated with
flock number index. This area includes space for fencePosts and whatever
other things we might dream up that go with the flock in its storage area.

getSize: index

Return the number of bytes in the flock at index. This includes space allocated internally for fencePosts and the like.

initializeSnarf

Put in the minimum necessary for a starting snarf.
All it needs is the number of objects and the spaceLeft.
This also writes the information to the real snarf.

inspect



Overrides: Object

isForgotten: index

The forgotten flag is the flag bit associated with each flock. It is set when the
flock has been forgotten, which means that there are no more persistent pointers
to the flock. When a flock is forgotten AND is not in RAM, the SnarfPacker is
free to bring the flock back into RAM and destroy it, which deletes it from the snarf.

Return true if the forgotten flag has been set for the flock at index.

isForwarded: index

Return the internal bit that says whether the flock at index is represented by forwarding information or by a flock area

isOccupied: index

Return true if there's a flock or forwarder at index.

isWritable

Return true if I represent a writable snarf.

makeWritable

Make the handle for the receiver writable.

mapCellOffset: index

Return the offset into the snarf for the mapCell that has the data for the flock at index.

mapCount

Return the number of slots allocated in the map table.

mapEnd

Return the index of the cell just after the end of the map. This is based on the number of entries in the map.

mendFences: index

Couldn't resist the name. Set up the fences for the flock at index. See checkFence:

nearestFlock

Return the location of the nearest flock. Everything between the
end of the map and the nearest flock is free space. We normally
allocate everything from the back of the snarf forward. When we
run out of enough contiguous space, we simply compact.

We keep a cache of the current nearest flock. The cache maintins the invariant that it
*must* point to an offset less than or equal to the nearestFlock. Thus it can be too close
to the mapTable, in which case we will recompute it from scratch.

readStream: index

Return a stream on the area of the snarf allocated to mapIndex.
This stream must be used immediately, then thrown away.

recomputeNearest

Recalculate the nearest flock by looking at the start of every flock and taking the min.

rewrite

Write out to the snarf any values held in instance variables (space
remaining, number of entries, etc.).

snarfID

Return the snarfID of the snarf this handle holds.

snarfMapCount

Actually get from the snarf the number of map slots currently allocated,
including ones that are free for reuse. This is stored as the first thing in the
snarf.

snarfSpaceLeft

Actually get from the snarf the amount of unallocated space remaining.

spaceLeft

Return the amount space left in the snarf.

wipeFlock: index

Deallocate all space for the flock at index. The slot for index remains however, and can be reused for another flock.

writeStream: index

Return a stream that can write into the bytes allocated to the flock at index.
The stream must be used immediately and thrown away.


Index - All Packages - All Categories - All Classes