1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-13 17:20:21 +02:00

Add heap validation to gcbench

* GCBench.c (ValidateTree): New function.
This commit is contained in:
Andy Wingo 2022-03-10 16:42:06 +01:00
parent 7b60164cac
commit e492da2d2b

View file

@ -42,6 +42,8 @@
#include <stdlib.h>
#include <sys/time.h>
#include "assert.h"
#if defined(GC_BDW)
#include "bdw.h"
#elif defined(GC_SEMI)
@ -170,6 +172,22 @@ static Node* MakeTree(struct context *cx, int iDepth) {
}
}
static void ValidateTree(Node *tree, int depth) {
#ifndef NDEBUG
ASSERT_EQ(tree->i, 0);
ASSERT_EQ(tree->j, 0);
if (depth == 0) {
ASSERT(!tree->left);
ASSERT(!tree->right);
} else {
ASSERT(tree->left);
ASSERT(tree->right);
ValidateTree(tree->left, depth - 1);
ValidateTree(tree->right, depth - 1);
}
#endif
}
static void TimeConstruction(struct context *cx, int depth) {
int iNumIters = NumIters(depth);
NodeHandle tempTree = { NULL };
@ -182,6 +200,7 @@ static void TimeConstruction(struct context *cx, int depth) {
for (int i = 0; i < iNumIters; ++i) {
HANDLE_SET(tempTree, allocate_node(cx));
Populate(cx, depth, HANDLE_REF(tempTree));
ValidateTree(HANDLE_REF(tempTree), depth);
HANDLE_SET(tempTree, NULL);
}
long tFinish = currentTime();
@ -193,6 +212,7 @@ static void TimeConstruction(struct context *cx, int depth) {
long tStart = currentTime();
for (int i = 0; i < iNumIters; ++i) {
HANDLE_SET(tempTree, MakeTree(cx, depth));
ValidateTree(HANDLE_REF(tempTree), depth);
HANDLE_SET(tempTree, NULL);
}
long tFinish = currentTime();
@ -234,6 +254,7 @@ int main() {
// Stretch the memory space quickly
HANDLE_SET(tempTree, MakeTree(cx, kStretchTreeDepth));
ValidateTree(HANDLE_REF(tempTree), kStretchTreeDepth);
HANDLE_SET(tempTree, NULL);
// Create a long lived object
@ -253,6 +274,8 @@ int main() {
TimeConstruction(cx, d);
}
ValidateTree(HANDLE_REF(longLivedTree), kLongLivedTreeDepth);
if (HANDLE_REF(longLivedTree) == 0
|| HANDLE_REF(array)->values[1000] != 1.0/1000)
fprintf(stderr, "Failed\n");