core_block_avail += size;
}
#endif
+
+void core_hash_init(int process, int core_base, int base, int limit) {
+ for (int i = base; i < limit; ++i) {
+ long long hash = process * 17 + i * 29;
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+#ifdef INDIRECT_CORE
+ int core_block = core_table_mem[core_base + i];
+#else
+ int core_block = core_base + i;
+#endif
+ rassert(core_block_mem[core_block] == 0xaaaaaaaa);
+ core_block_mem[core_block] = (int)hash;
+ }
+}
+
+void core_hash_verify(int process, int core_base, int base, int limit) {
+ for (int i = base; i < limit; ++i) {
+ long long hash = process * 17 + i * 29;
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+#ifdef INDIRECT_CORE
+ int core_block = core_table_mem[core_base + i];
+#else
+ int core_block = core_base + i;
+#endif
+ rassert(core_block_mem[core_block] == (int)hash);
+ core_block_mem[core_block] = 0xaaaaaaaa;
+ }
+}
#else
void core_init(int n_table);
#endif
+void core_hash_init(int process, int core_base, int base, int limit);
+void core_hash_verify(int process, int core_base, int base, int limit);
#endif
}
}
+void hash_init(int item, int item_base, int base, int limit) {
+ for (int i = base; i < limit; ++i) {
+ long long hash = item * 17 + i * 29;
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+ rassert(mem[item_base + i] == 0xaaaaaaaa);
+ mem[item_base + i] = (int)hash;
+ }
+}
+
+void hash_verify(int item, int item_base, int base, int limit) {
+ for (int i = base; i < limit; ++i) {
+ long long hash = item * 17 + i * 29;
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+ rassert(mem[item_base + i] == (int)hash);
+ mem[item_base + i] = 0xaaaaaaaa;
+ }
+}
+
int main(int argc, char **argv) {
if (argc < 3) {
printf("usage: %s n_items pool_size [moveable]\n", argv[0]);
int base = items[item].base;
rassert(items[item].limit == base + size);
printf("new region [%d,%d)\n", base, base + size);
- for (int i = 0; i < size; ++i) {
- rassert(mem[base + i] == 0xaaaaaaaa);
- long long hash = item * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- mem[base + i] = (int)hash;
- }
+ hash_init(item, base, 0, size);
}
}
}
rassert(actual_old_size <= old_size);
}
printf("old region [%d,%d)\n", base, base + actual_old_size);
- for (int i = size; i < actual_old_size; ++i) {
- long long hash = item * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- rassert(mem[base + i] == (int)hash);
- mem[base + i] = 0xaaaaaaaa;
- }
+ hash_verify(item, base, size, actual_old_size);
bool result =
moveable ?
pool_realloc_moveable(&head, items + item, size) :
base = items[item].base;
rassert(items[item].limit == base + size);
printf("new region [%d,%d)\n", base, base + size);
- for (int i = actual_old_size; i < size; ++i) {
- rassert(mem[base + i] == 0xaaaaaaaa);
- long long hash = item * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- mem[base + i] = (int)hash;
- }
+ hash_init(item, base, actual_old_size, size);
}
}
}
rassert(actual_old_size <= old_size);
}
printf("old region [%d,%d)\n", base, base + actual_old_size);
- for (int i = 0; i < actual_old_size; ++i) {
- long long hash = item * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- rassert(mem[base + i] == (int)hash);
- mem[base + i] = 0xaaaaaaaa;
- }
+ hash_verify(item, base, 0, actual_old_size);
pool_free(&head, items + item);
items[item].prev = NULL;
printf("... ok\n");
int base = items[i].base;
int size = items[i].limit - base;
printf("item %d: region [%d,%d)\n", i, base, base + size);
- for (int j = 0; j < size; ++j) {
- long long hash = i * 17 + j * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- rassert(mem[base + j] == (int)hash);
- mem[base + j] = 0xaaaaaaaa;
- }
+ hash_verify(i, base, 0, size);
}
}
assert(processes[process].pool_item.limit == core_base + size);
#endif
printf("new core [%d,%d)\n", core_base, core_base + size);
- for (int i = 0; i < size; ++i) {
- long long hash = process * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-#ifdef INDIRECT_CORE
- int core_block = core_table_mem[core_base + i];
-#else
- int core_block = core_base + i;
-#endif
- rassert(core_block_mem[core_block] == 0xaaaaaaaa);
- core_block_mem[core_block] = (int)hash;
- }
+ core_hash_init(process, core_base, 0, size);
#ifdef PREALLOCATE_SWAP
printf("new swap [%d,%d)\n", ~processes[process].swap_item.limit, ~processes[process].swap_item.base);
#endif
#else
printf("old core [%d,%d)\n", core_base, core_base + actual_old_size);
#endif
- for (int i = size; i < actual_old_size; ++i) {
- long long hash = process * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-#ifdef INDIRECT_CORE
- int core_block = core_table_mem[core_base + i];
-#else
- int core_block = core_base + i;
-#endif
- rassert(core_block_mem[core_block] == (int)hash);
- core_block_mem[core_block] = 0xaaaaaaaa;
- }
+ core_hash_verify(process, core_base, size, actual_old_size);
bool result = process_realloc(processes + process, size);
printf(
"... %s\n",
#else
printf("new core [%d,%d)\n", core_base, core_base + size);
#endif
- for (int i = actual_old_size; i < size; ++i) {
- long long hash = process * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-#ifdef INDIRECT_CORE
- int core_block = core_table_mem[core_base + i];
-#else
- int core_block = core_base + i;
-#endif
- rassert(core_block_mem[core_block] == 0xaaaaaaaa);
- core_block_mem[core_block] = (int)hash;
- }
+ core_hash_init(process, core_base, actual_old_size, size);
}
}
}
swap_limit - victim_swap_item.base :
!in_core ? swap_limit - processes[process].pool_item.base : 0;
#endif
+ rassert(core_size + swap_size == actual_old_size);
int swap_base = ~swap_limit;
printf("old core [%d,%d) swap [%d,%d)\n", core_base, core_base + core_size, swap_base, swap_base + swap_size);
- for (int i = 0; i < core_size; ++i) {
- long long hash = process * 17 + i * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-#ifdef INDIRECT_CORE
- int core_block = core_table_mem[core_base + i];
-#else
- int core_block = core_base + i;
-#endif
- rassert(core_block_mem[core_block] == (int)hash);
- core_block_mem[core_block] = 0xaaaaaaaa;
- }
- for (int i = 0; i < swap_size; ++i) {
- long long hash = process * 17 + (core_size + i) * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-#ifdef INDIRECT_SWAP
- int swap_block = swap_table_mem[swap_base + i];
-#else
- int swap_block = swap_base + i;
-#endif
- rassert(swap_block_mem[swap_block] == (int)hash);
- swap_block_mem[swap_block] = 0xaaaaaaaa;
- }
- rassert(core_size + swap_size == actual_old_size);
+ core_hash_verify(process, core_base, 0, core_size);
+ swap_hash_verify(process, swap_base, 0, swap_size, core_size);
process_free(processes + process);
processes[process].size = -1;
printf("... ok\n");
swap_limit - victim_swap_item.base :
!in_core ? swap_limit - processes[i].pool_item.base : 0;
#endif
+ rassert(core_size + swap_size == processes[i].size);
int swap_base = ~swap_limit;
printf(
"process %d: core [%d,%d) swap [%d,%d)\n",
swap_base,
swap_base + swap_size
);
- for (int j = 0; j < core_size; ++j) {
- long long hash = i * 17 + j * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-#ifdef INDIRECT_CORE
- int core_block = core_table_mem[core_base + j];
- core_table_mem[core_base + j] = 0x55555555;
-#else
- int core_block = core_base + j;
-#endif
- rassert(core_block_mem[core_block] == (int)hash);
- core_block_mem[core_block] = 0xaaaaaaaa;
- }
- for (int j = 0; j < swap_size; ++j) {
- long long hash = i * 17 + (core_size + j) * 29;
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-#ifdef INDIRECT_SWAP
- int swap_block = swap_table_mem[swap_base + j];
- swap_table_mem[swap_base + j] = 0x55555555;
-#else
- int swap_block = swap_base + j;
-#endif
- rassert(swap_block_mem[swap_block] == (int)hash);
- swap_block_mem[swap_block] = 0xaaaaaaaa;
- }
+ core_hash_verify(i, core_base, 0, core_size);
+ swap_hash_verify(i, swap_base, 0, swap_size, core_size);
}
}
printf("\n");
#endif
}
+
+void swap_hash_verify(
+ int process,
+ int swap_base,
+ int base,
+ int limit,
+ int offset
+) {
+ for (int i = base; i < limit; ++i) {
+ long long hash = process * 17 + (i + offset) * 29;
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+#ifdef INDIRECT_SWAP
+ int swap_block = swap_table_mem[swap_base + i];
+#else
+ int swap_block = swap_base + i;
+#endif
+ rassert(swap_block_mem[swap_block] == (int)hash);
+ swap_block_mem[swap_block] = 0xaaaaaaaa;
+ }
+}
#endif
void swap_read(int swap_base, int core_base, int size);
void swap_write(int swap_base, int core_base, int size);
+void swap_hash_verify(
+ int process,
+ int swap_base,
+ int base,
+ int limit,
+ int offset
+);
#endif