}
}
-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;
+void hash_init(int item, int base, int size, int offset) {
+ for (int i = 0; i < size; ++i) {
+ long long hash = item * 17 + (i + offset) * 29;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffffffLL) + (hash >> 32);
- rassert(mem[item_base + i] == 0xaaaaaaaa);
- mem[item_base + i] = (int)hash;
+ rassert(mem[base + i] == 0xaaaaaaaa);
+ mem[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;
+void hash_verify(int item, int base, int size, int offset) {
+ for (int i = 0; i < size; ++i) {
+ long long hash = item * 17 + (i + offset) * 29;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffffffLL) + (hash >> 32);
- rassert(mem[item_base + i] == (int)hash);
- mem[item_base + i] = 0xaaaaaaaa;
+ rassert(mem[base + i] == (int)hash);
+ mem[base + i] = 0xaaaaaaaa;
}
}
int base = items[item].base;
rassert(items[item].limit == base + size);
printf("new region [%d,%d)\n", base, base + size);
- hash_init(item, base, 0, size);
+ hash_init(item, base, size, 0);
}
}
}
rassert(actual_old_size <= old_size);
}
printf("old region [%d,%d)\n", base, base + actual_old_size);
- hash_verify(item, base, size, actual_old_size);
+ hash_verify(
+ item,
+ base + size,
+ actual_old_size - size,
+ 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);
- hash_init(item, base, actual_old_size, size);
+ hash_init(
+ item,
+ base + actual_old_size,
+ size - actual_old_size,
+ actual_old_size
+ );
}
}
}
rassert(actual_old_size <= old_size);
}
printf("old region [%d,%d)\n", base, base + actual_old_size);
- hash_verify(item, base, 0, actual_old_size - size);
+ hash_verify(item, base, actual_old_size - size, 0);
bool result =
moveable ?
pool_realloc_base_moveable(&head, items + item, size) :
base = items[item].base;
rassert(items[item].limit == base + size);
printf("new region [%d,%d)\n", base, base + size);
- hash_verify(
- item,
- base + size - actual_old_size,
- size >= actual_old_size ? 0 : actual_old_size - size,
- actual_old_size
- );
- hash_init(item, base, 0, size);
+ if (size >= actual_old_size)
+ hash_verify(
+ item,
+ base + size - actual_old_size,
+ actual_old_size,
+ 0
+ );
+ else
+ hash_verify(
+ item,
+ base,
+ size,
+ actual_old_size - size
+ );
+ hash_init(item, base, size, 0);
}
}
}
rassert(actual_old_size <= old_size);
}
printf("old region [%d,%d)\n", base, base + actual_old_size);
- hash_verify(item, base, 0, actual_old_size);
+ hash_verify(item, base, actual_old_size, 0);
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);
- hash_verify(i, base, 0, size);
+ hash_verify(i, base, size, 0);
}
}
#include "rassert.h"
#include "swap.h"
-void core_hash_init(int process, int core_base, int base, int limit) {
- for (int i = base; i < limit; ++i) {
+void core_hash_init(int process, int base, int blocks, int offset) {
+ for (int i = 0; i < blocks; ++i) {
#ifdef INDIRECT_CORE
- int core_block = core_table_mem[core_base + i];
+ int core_block = core_table_mem[base + i];
#else
- int core_block = core_base + i;
+ int core_block = base + i;
#endif
for (int j = 0; j < BLOCK_SIZE; ++j) {
- long long hash = process * 17 + i * 29 + j * 37;
+ long long hash = process * 17 + (i + offset) * 29 + j * 37;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffLL) + (hash >> 16);
hash = (hash & 0xffLL) + (hash >> 8);
}
}
-void core_hash_verify(int process, int core_base, int base, int limit) {
- for (int i = base; i < limit; ++i) {
+void core_hash_verify(int process, int base, int blocks, int offset) {
+ for (int i = 0; i < blocks; ++i) {
#ifdef INDIRECT_CORE
- int core_block = core_table_mem[core_base + i];
+ int core_block = core_table_mem[base + i];
#else
- int core_block = core_base + i;
+ int core_block = base + i;
#endif
for (int j = 0; j < BLOCK_SIZE; ++j) {
- long long hash = process * 17 + i * 29 + j * 37;
+ long long hash = process * 17 + (i + offset) * 29 + j * 37;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffLL) + (hash >> 16);
hash = (hash & 0xffLL) + (hash >> 8);
}
}
-void swap_hash_verify(int process, int swap_base, int base, int limit) {
- for (int i = base; i < limit; ++i) {
+void swap_hash_verify(int process, int base, int blocks, int offset) {
+ for (int i = 0; i < blocks; ++i) {
#ifdef INDIRECT_SWAP
- int swap_block = swap_table_mem[swap_base + i];
+ int swap_block = swap_table_mem[base + i];
#else
- int swap_block = swap_base + i;
+ int swap_block = base + i;
#endif
for (int j = 0; j < BLOCK_SIZE; ++j) {
- long long hash = process * 17 + i * 29 + j * 37;
+ long long hash = process * 17 + (i + offset) * 29 + j * 37;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffLL) + (hash >> 16);
hash = (hash & 0xffLL) + (hash >> 8);
core_base + blocks
);
printf("new core [%d,%d)\n", core_base, core_base + blocks);
- core_hash_init(process, core_base, 0, blocks);
+ core_hash_init(process, core_base, blocks, 0);
#ifdef PREALLOCATE_SWAP
printf("new swap [%d,%d)\n", PER_PROCESS_SWAP_ITEM(processes + process).base, PER_PROCESS_SWAP_ITEM(processes + process).limit);
#endif
printf("old core [%d,%d)\n", core_base, core_base + actual_old_blocks);
#endif
int blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
- core_hash_verify(process, core_base, blocks, actual_old_blocks);
+ core_hash_verify(
+ process,
+ core_base + blocks,
+ actual_old_blocks - blocks,
+ blocks
+ );
bool result = process_realloc(processes + process, size);
printf(
"... %s\n",
#else
printf("new core [%d,%d)\n", core_base, core_base + blocks);
#endif
- core_hash_init(process, core_base, actual_old_blocks, blocks);
+ core_hash_init(
+ process,
+ core_base + actual_old_blocks,
+ blocks - actual_old_blocks,
+ actual_old_blocks
+ );
}
}
}
rassert(core_blocks + swap_blocks == actual_old_blocks);
printf("old core [%d,%d) swap [%d,%d)\n", core_base, core_base + core_blocks, swap_base, swap_base + swap_blocks);
fflush(stdout);
- core_hash_verify(
- process,
- core_base - swap_blocks,
- swap_blocks,
- swap_blocks + core_blocks
- );
- swap_hash_verify(process, swap_base, 0, swap_blocks);
+ core_hash_verify(process, core_base, core_blocks, swap_blocks);
+ swap_hash_verify(process, swap_base, swap_blocks, 0);
process_free(processes + process);
processes[process].size = -1L;
printf("... ok\n");
swap_base,
swap_base + swap_blocks
);
- core_hash_verify(
- i,
- core_base - swap_blocks,
- swap_blocks,
- swap_blocks + core_blocks
- );
+ core_hash_verify(i, core_base, core_blocks, swap_blocks);
#ifdef INDIRECT_CORE
core_block_free(core_table_mem + core_base, core_blocks);
#endif
- swap_hash_verify(i, swap_base, 0, swap_blocks);
+ swap_hash_verify(i, swap_base, swap_blocks, 0);
#ifdef INDIRECT_SWAP
swap_block_free(swap_table_mem + swap_base, swap_blocks);
#endif