mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-14 01:30:19 +02:00
Add heap validation to gcbench
* GCBench.c (ValidateTree): New function.
This commit is contained in:
parent
7b60164cac
commit
e492da2d2b
1 changed files with 23 additions and 0 deletions
23
GCBench.c
23
GCBench.c
|
@ -42,6 +42,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include "assert.h"
|
||||||
|
|
||||||
#if defined(GC_BDW)
|
#if defined(GC_BDW)
|
||||||
#include "bdw.h"
|
#include "bdw.h"
|
||||||
#elif defined(GC_SEMI)
|
#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) {
|
static void TimeConstruction(struct context *cx, int depth) {
|
||||||
int iNumIters = NumIters(depth);
|
int iNumIters = NumIters(depth);
|
||||||
NodeHandle tempTree = { NULL };
|
NodeHandle tempTree = { NULL };
|
||||||
|
@ -182,6 +200,7 @@ static void TimeConstruction(struct context *cx, int depth) {
|
||||||
for (int i = 0; i < iNumIters; ++i) {
|
for (int i = 0; i < iNumIters; ++i) {
|
||||||
HANDLE_SET(tempTree, allocate_node(cx));
|
HANDLE_SET(tempTree, allocate_node(cx));
|
||||||
Populate(cx, depth, HANDLE_REF(tempTree));
|
Populate(cx, depth, HANDLE_REF(tempTree));
|
||||||
|
ValidateTree(HANDLE_REF(tempTree), depth);
|
||||||
HANDLE_SET(tempTree, NULL);
|
HANDLE_SET(tempTree, NULL);
|
||||||
}
|
}
|
||||||
long tFinish = currentTime();
|
long tFinish = currentTime();
|
||||||
|
@ -193,6 +212,7 @@ static void TimeConstruction(struct context *cx, int depth) {
|
||||||
long tStart = currentTime();
|
long tStart = currentTime();
|
||||||
for (int i = 0; i < iNumIters; ++i) {
|
for (int i = 0; i < iNumIters; ++i) {
|
||||||
HANDLE_SET(tempTree, MakeTree(cx, depth));
|
HANDLE_SET(tempTree, MakeTree(cx, depth));
|
||||||
|
ValidateTree(HANDLE_REF(tempTree), depth);
|
||||||
HANDLE_SET(tempTree, NULL);
|
HANDLE_SET(tempTree, NULL);
|
||||||
}
|
}
|
||||||
long tFinish = currentTime();
|
long tFinish = currentTime();
|
||||||
|
@ -234,6 +254,7 @@ int main() {
|
||||||
|
|
||||||
// Stretch the memory space quickly
|
// Stretch the memory space quickly
|
||||||
HANDLE_SET(tempTree, MakeTree(cx, kStretchTreeDepth));
|
HANDLE_SET(tempTree, MakeTree(cx, kStretchTreeDepth));
|
||||||
|
ValidateTree(HANDLE_REF(tempTree), kStretchTreeDepth);
|
||||||
HANDLE_SET(tempTree, NULL);
|
HANDLE_SET(tempTree, NULL);
|
||||||
|
|
||||||
// Create a long lived object
|
// Create a long lived object
|
||||||
|
@ -253,6 +274,8 @@ int main() {
|
||||||
TimeConstruction(cx, d);
|
TimeConstruction(cx, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValidateTree(HANDLE_REF(longLivedTree), kLongLivedTreeDepth);
|
||||||
|
|
||||||
if (HANDLE_REF(longLivedTree) == 0
|
if (HANDLE_REF(longLivedTree) == 0
|
||||||
|| HANDLE_REF(array)->values[1000] != 1.0/1000)
|
|| HANDLE_REF(array)->values[1000] != 1.0/1000)
|
||||||
fprintf(stderr, "Failed\n");
|
fprintf(stderr, "Failed\n");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue