RTTCache.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Paul Rovner, May 31, 1983 12:32 pm
Russ Atkinson (RRA) February 11, 1985 12:04:58 pm PST
This interface provides for caching information about types so we don't have to access symbols tables for the information (an expensive and nasty proposition). There is no provision for flushing entries once they are made, and no flushing should be added without changing implementations that depend on this fact! Also, the cache is fully protected against parallel access.
RTTCache:
CEDAR
DEFINITIONS =
BEGIN
OPEN Rope, SafeStorage;
ProcKey: TYPE = PROC ANY RETURNS ANY;
InvalidIndex: ERROR;
IntEntry: TYPE = REF IntEntryRep;
IntEntryRep:
TYPE =
RECORD [
next: IntEntry ← NIL,
valid: BOOL ← FALSE,
type: Type ← nullType,
proc: ProcKey ← NIL,
int: INT ← -1];
RefEntry: TYPE = REF RefEntryRep;
RefEntryRep:
TYPE =
RECORD [
next: RefEntry ← NIL,
valid: BOOL ← FALSE,
type: Type ← nullType,
proc: ProcKey ← NIL,
ref: REF ← NIL];
ComponentMap: TYPE = REF ComponentMapRep;
ComponentMapRep:
TYPE =
RECORD [
filledTypes, filledNames: CARDINAL ← 0,
comps: SEQUENCE len: CARDINAL OF ComponentEntry];
ComponentEntry:
TYPE =
RECORD [
validType, validName: BOOL ← FALSE,
type: Type ← nullType,
name: ROPE ← NIL];
NullComponentEntry: ComponentEntry = [FALSE, FALSE, nullType, NIL];
LookupInt:
PROC [type: Type, proc: ProcKey]
RETURNS [entry: IntEntry];
looks up the entry corresponding to the type and proc; entry.valid => entry.int is OK
FillIntEntry:
PROC [entry: IntEntry, value:
INT]
RETURNS [alreadyFull:
BOOL];
fills the entry acquired by LookupInt
will not overwrite an already full entry
ClearIntEntry:
PROC [entry: IntEntry];
atomically invalidates the value in the entry
an invalid entry always has entry.valid = -1
GetInt:
PROC [entry: IntEntry]
RETURNS [value:
INT, valid:
BOOL];
atomically retrieves the value in the entry
LookupRef:
PROC [type: Type, proc: ProcKey]
RETURNS [entry: RefEntry];
looks up the entry corresponding to the type and proc
entry.valid => entry.ref is OK
FillRefEntry:
PROC [entry: RefEntry, value:
REF]
RETURNS [alreadyFull:
BOOL];
fills the entry acquired by LookupRef
will not overwrite an already full entry
ClearRefEntry:
PROC [entry: RefEntry];
atomically invalidates the value in the entry
an invalid entry always has entry.ref = NIL
GetRef:
PROC [entry: RefEntry]
RETURNS [value:
REF, valid:
BOOL];
atomically retrieves the value in the entry
GetStats:
PROC RETURNS [intProbes, intMisses, intFilled, refProbes, refMisses, refFilled:
INT];
Gets the statistics for this cache usage.
NewComponentMap:
PROC [len:
NAT]
RETURNS [map: ComponentMap];
generates a new (empty) component map of the given size
FillNameComponent:
PROC [map: ComponentMap, index:
INT, name:
ROPE]
RETURNS [alreadyFull:
BOOL];
fills in a name component in the component map
will not overwrite an already full component
will ERROR InvalidIndex if index NOT IN [0..map.len)
FillTypeComponent:
PROC [map: ComponentMap, index:
INT, type: Type]
RETURNS [alreadyFull:
BOOL];
fills in a type component in the component map
will not overwrite an already full component
will ERROR InvalidIndex if index NOT IN [0..map.len)
GetComponentAtIndex:
PROC [map: ComponentMap, index:
INT]
RETURNS [comp: ComponentEntry];
atomically returns the given component entry
will ERROR InvalidIndex if index NOT IN [0..map.len)
GetComponentForName:
PROC [map: ComponentMap, name:
ROPE, case:
BOOL ←
TRUE]
RETURNS [index:
INT, comp: ComponentEntry];
atomically returns the given component entry for the given name
IF case = TRUE, then name search is case-sensitive (Rope convention)
will return [-1, NullComponentEntry] if no such name
END.