Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: hashcach.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | \ hashcach.fth 3.6 01/05/18 | |
43 | \ Copyright 1985-1994 Bradley Forthware | |
44 | \ Copyright 1994-2001 Sun Microsystems, Inc. All Rights Reserved | |
45 | ||
46 | \ Dictionary cache to speed up "find". Only the Forth vocabulary is | |
47 | \ cached; this eliminates a lot of cache flushing and is simpler than | |
48 | \ caching all vocabularies. | |
49 | ||
50 | hex | |
51 | ||
52 | headerless | |
53 | 100 /link * constant /hashcache | |
54 | /hashcache buffer: hashcache | |
55 | ||
56 | ||
57 | : link+ ( adr index -- adr' ) | |
58 | \t16 wa+ | |
59 | \t32 la+ | |
60 | ; | |
61 | : vhash ( adr,len -- cache-adr ) | |
62 | 7 and swap c@ 1f and 3 << + hashcache swap link+ | |
63 | ; | |
64 | : match? ( adr len cache-adr -- flag ) | |
65 | another-link? if ( adr len acf ) | |
66 | >name name>string ( adr len adr2,len2 ) | |
67 | 2swap ( nameadr,len stradr,len ) | |
68 | rot ( nameadr stradr slen nlen ) | |
69 | over = if ( nadr sadr slen ) | |
70 | comp 0= | |
71 | else ( nadr sadr slen ) | |
72 | 3drop false | |
73 | then | |
74 | else ( adr len ) | |
75 | 2drop false | |
76 | then | |
77 | ; | |
78 | ||
79 | headers | |
80 | : clear-hashcache ( -- ) | |
81 | hashcache /hashcache bounds ?do i !null-link /link +loop | |
82 | ; | |
83 | headerless | |
84 | clear-hashcache | |
85 | chain: init ( -- ) clear-hashcache ; | |
86 | ||
87 | : probe-cache ( adr len voc-acf -- find-results ) | |
88 | dup ['] forth = if ( adr len voc-acf ) | |
89 | drop 2dup vhash ( adr len cache-adr ) | |
90 | 3dup match? if ( adr len cache-adr ) | |
91 | link@ >link true ( adr len alf true ) | |
92 | else ( adr len adr2 ) | |
93 | >r ( adr len ) | |
94 | ['] forth >threads $find-next if ( adr len alf ) | |
95 | r> over link> swap link! true ( adr len alf true) | |
96 | else ( adr len ) | |
97 | r> drop false ( adr len false ) | |
98 | then ( adr len false | adr len alf true ) | |
99 | then | |
100 | find-fixup ( find-results ) | |
101 | r> drop exit | |
102 | then | |
103 | >first ( find-results ) | |
104 | ; | |
105 | ||
106 | : forth? ( -- flag ) current-voc ['] forth = ; | |
107 | ||
108 | : replace-entry ( -- ) last @ name> last @ name>string vhash link! ; | |
109 | : clear-entry ( -- ) last @ name>string vhash !null-link ; | |
110 | ||
111 | : cached-make ( adr len voc-acf -- ) | |
112 | $create-word forth? if replace-entry then | |
113 | ; | |
114 | ||
115 | : cached-hide ( -- voc-acf ) forth? if clear-entry then current-voc ; | |
116 | ||
117 | : cached-reveal ( -- ) | |
118 | hidden-voc get-token? if drop forth? if replace-entry then then | |
119 | hidden-voc | |
120 | ; | |
121 | ||
122 | : cached-remove ( alf acf -- alf prev-link ) | |
123 | over l>name name>string vhash !null-link >threads | |
124 | ; | |
125 | ||
126 | ||
127 | [ifexist] patch | |
128 | patch cached-hide current-voc hide \ fm/kernel/voccom | |
129 | patch cached-reveal hidden-voc reveal \ fm/kernel/voccom | |
130 | patch cached-make $create-word ($header) \ fm/kernel/voccom | |
131 | patch cached-remove >threads remove-word \ fm/kernel/tagvoc | |
132 | patch probe-cache >first $find-word \ fm/kernel/tagvoc | |
133 | [else] | |
134 | where ." WARNING: Falling back to unsafe code patching" cr | |
135 | ' cached-hide ' hide >body token! | |
136 | ' cached-reveal ' reveal >body token! | |
137 | ' cached-make ' ($header) >body /token + token! | |
138 | ' cached-remove ' remove-word >body token! | |
139 | ' probe-cache ' $find-word >body token! | |
140 | [then] | |
141 | ||
142 | headers |