omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / omc / tests / pools / srv.om
| 1 | note gate-pools S (design section 11): 2000 requests of growing and shrinking sizes (a fixed 64-bit LCG, |
| 2 | note 1 byte .. 64 MiB; the first 8 ramp to the 64 MiB high-water mark) served from one pool that is enlarged |
| 3 | note only past its high-water mark and reused. Prints the high-water mark, enlarge calls, new marks, VmRSS (kB) |
| 4 | note after the high-water point (request 8) and at the end, and a checksum of the bytes served. |
| 5 | note Control: with the byte L on stdin, requests 8..23 are served from fresh memory past the old end (a |
| 6 | note server that enlarges per request); its VmRSS must rise past the high-water mark. |
| 7 | global P uchar * |
| 8 | global sb uchar 4096 |
| 9 | global mb uchar 1 |
| 10 | global ob uchar 24 |
| 11 | text pth "/proc/self/status" |
| 12 | fn pnum v ulong to void |
| 13 | put ob 23 10 |
| 14 | i = ulong 23 |
| 15 | x = v |
| 16 | go = true |
| 17 | while go bound 21 |
| 18 | i = sub i 1 |
| 19 | put ob i uchar add rem x 10 48 |
| 20 | x = div x 10 |
| 21 | go = ne x 0 |
| 22 | end |
| 23 | k = write 1 ob i sub 24 i |
| 24 | end |
| 25 | fn plong v long to void |
| 26 | if lt v 0 |
| 27 | put ob 0 uchar 45 |
| 28 | k = write 1 ob 0 1 |
| 29 | pnum ulong neg v |
| 30 | else |
| 31 | pnum ulong v |
| 32 | end |
| 33 | end |
| 34 | fn hit i ulong to bool |
| 35 | a = and eq get sb i 86 eq get sb add i 1 109 |
| 36 | b = and eq get sb add i 2 82 eq get sb add i 5 58 |
| 37 | ret and a b |
| 38 | end |
| 39 | fn rss to ulong |
| 40 | fd = fopen pth 0 len pth 0 0 |
| 41 | if lt fd 0 |
| 42 | ret 0 |
| 43 | end |
| 44 | n = read int fd sb 0 4096 |
| 45 | fd = fclose int fd |
| 46 | if le n 0 |
| 47 | ret 0 |
| 48 | end |
| 49 | lim = ulong n |
| 50 | i = ulong 0 |
| 51 | while lt add i 6 lim bound 4096 |
| 52 | if hit i |
| 53 | break |
| 54 | end |
| 55 | i = add i 1 |
| 56 | end |
| 57 | i = add i 6 |
| 58 | v = ulong 0 |
| 59 | while lt i lim bound 4096 |
| 60 | ch = get sb i |
| 61 | if and ge ch 48 le ch 57 |
| 62 | v = add mul v 10 ulong sub ch 48 |
| 63 | else |
| 64 | if and ne ch 32 ne ch 9 |
| 65 | break |
| 66 | end |
| 67 | end |
| 68 | i = add i 1 |
| 69 | end |
| 70 | ret v |
| 71 | end |
| 72 | fn serve q ulong b ulong sz ulong to ulong |
| 73 | cs = ulong 0 |
| 74 | o = ulong 0 |
| 75 | while lt o sz bound 20000 |
| 76 | put P add b o uchar and add q o 255 |
| 77 | cs = add cs ulong get P add b o |
| 78 | o = add o 4096 |
| 79 | end |
| 80 | ret cs |
| 81 | end |
| 82 | fn main to int |
| 83 | leak = false |
| 84 | k = read 0 mb 0 1 |
| 85 | if gt k 0 |
| 86 | leak = eq get mb 0 76 |
| 87 | end |
| 88 | x = ulong 12345 |
| 89 | hw = ulong 0 |
| 90 | calls = ulong 0 |
| 91 | marks = ulong 0 |
| 92 | rhw = ulong 0 |
| 93 | cs = ulong 0 |
| 94 | q = ulong 0 |
| 95 | while lt q 2000 |
| 96 | x = add mul x 6364136223846793005 1442695040888963407 |
| 97 | sz = add rem shr x 33 67108864 1 |
| 98 | if lt q 8 |
| 99 | sz = mul add q 1 8388608 |
| 100 | end |
| 101 | b = ulong 0 |
| 102 | if and leak ge q 8 |
| 103 | if eq q 24 |
| 104 | break |
| 105 | end |
| 106 | sz = add rem sz 4194304 1 |
| 107 | b = len P |
| 108 | r = enlarge P add b sz |
| 109 | calls = add calls 1 |
| 110 | if ne r 0 |
| 111 | ret 4 |
| 112 | end |
| 113 | end |
| 114 | if gt sz hw |
| 115 | r = enlarge P sz |
| 116 | calls = add calls 1 |
| 117 | if ne r 0 |
| 118 | ret 3 |
| 119 | end |
| 120 | hw = sz |
| 121 | marks = add marks 1 |
| 122 | end |
| 123 | cs = add cs serve q b sz |
| 124 | if eq q 8 |
| 125 | rhw = rss |
| 126 | end |
| 127 | q = add q 1 |
| 128 | end |
| 129 | pnum hw |
| 130 | pnum calls |
| 131 | pnum marks |
| 132 | pnum rhw |
| 133 | pnum rss |
| 134 | pnum cs |
| 135 | ret 0 |
| 136 | end |