summaryrefslogtreecommitdiff
path: root/innobase/mem
diff options
context:
space:
mode:
Diffstat (limited to 'innobase/mem')
-rw-r--r--innobase/mem/mem0dbg.c197
-rw-r--r--innobase/mem/mem0mem.c4
-rw-r--r--innobase/mem/mem0pool.c14
-rw-r--r--innobase/mem/ts/makefile12
-rw-r--r--innobase/mem/ts/tsmem.c497
5 files changed, 40 insertions, 684 deletions
diff --git a/innobase/mem/mem0dbg.c b/innobase/mem/mem0dbg.c
index 004197a5b8e..d521143eb47 100644
--- a/innobase/mem/mem0dbg.c
+++ b/innobase/mem/mem0dbg.c
@@ -7,6 +7,7 @@ but is included in mem0mem.* !
Created 6/9/1994 Heikki Tuuri
*************************************************************************/
+#ifdef UNIV_MEM_DEBUG
mutex_t mem_hash_mutex; /* The mutex which protects in the
debug version the hash table containing
the list of live memory heaps, and
@@ -16,12 +17,11 @@ mutex_t mem_hash_mutex; /* The mutex which protects in the
extent of memory allocations. Only used in the debug version.
Protected by mem_hash_mutex above. */
-ulint mem_n_created_heaps = 0;
-ulint mem_n_allocations = 0;
-ulint mem_total_allocated_memory = 0;
-ulint mem_current_allocated_memory = 0;
-ulint mem_max_allocated_memory = 0;
-ulint mem_last_print_info = 0;
+static ulint mem_n_created_heaps = 0;
+static ulint mem_n_allocations = 0;
+static ulint mem_total_allocated_memory = 0;
+ulint mem_current_allocated_memory = 0;
+static ulint mem_max_allocated_memory = 0;
/* Size of the hash table for memory management tracking */
#define MEM_HASH_SIZE 997
@@ -43,12 +43,12 @@ struct mem_hash_node_struct {
typedef UT_LIST_BASE_NODE_T(mem_hash_node_t) mem_hash_cell_t;
/* The hash table of allocated heaps */
-mem_hash_cell_t mem_hash_table[MEM_HASH_SIZE];
+static mem_hash_cell_t mem_hash_table[MEM_HASH_SIZE];
/* The base node of the list of all allocated heaps */
-mem_hash_cell_t mem_all_list_base;
+static mem_hash_cell_t mem_all_list_base;
-ibool mem_hash_initialized = FALSE;
+static ibool mem_hash_initialized = FALSE;
UNIV_INLINE
@@ -65,45 +65,44 @@ mem_hash_get_nth_cell(ulint i)
return(&(mem_hash_table[i]));
}
+#endif /* UNIV_MEM_DEBUG */
/* Accessor functions for a memory field in the debug version */
void
mem_field_header_set_len(byte* field, ulint len)
{
- ut_ad(len >= 0);
-
- mach_write(field - 2 * sizeof(ulint), len);
+ mach_write_to_4(field - 2 * sizeof(ulint), len);
}
ulint
mem_field_header_get_len(byte* field)
{
- return(mach_read(field - 2 * sizeof(ulint)));
+ return(mach_read_from_4(field - 2 * sizeof(ulint)));
}
void
mem_field_header_set_check(byte* field, ulint check)
{
- mach_write(field - sizeof(ulint), check);
+ mach_write_to_4(field - sizeof(ulint), check);
}
ulint
mem_field_header_get_check(byte* field)
{
- return(mach_read(field - sizeof(ulint)));
+ return(mach_read_from_4(field - sizeof(ulint)));
}
void
mem_field_trailer_set_check(byte* field, ulint check)
{
- mach_write(field + mem_field_header_get_len(field), check);
+ mach_write_to_4(field + mem_field_header_get_len(field), check);
}
ulint
mem_field_trailer_get_check(byte* field)
{
- return(mach_read(field +
+ return(mach_read_from_4(field +
mem_field_header_get_len(field)));
}
@@ -164,6 +163,7 @@ mem_field_init(
mem_field_header_set_check(usr_buf, rnd);
mem_field_trailer_set_check(usr_buf, rnd);
+#ifdef UNIV_MEM_DEBUG
/* Update the memory allocation information */
mutex_enter(&mem_hash_mutex);
@@ -182,6 +182,7 @@ mem_field_init(
combination of 0xBA and 0xBE */
mem_init_buf(usr_buf, n);
+#endif /* UNIV_MEM_DEBUG */
}
/**********************************************************************
@@ -191,12 +192,14 @@ void
mem_field_erase(
/*============*/
byte* buf, /* in: memory field */
- ulint n) /* in: how many bytes the user requested */
+ ulint n __attribute__((unused)))
+ /* in: how many bytes the user requested */
{
byte* usr_buf;
usr_buf = buf + MEM_FIELD_HEADER_SIZE;
-
+
+#ifdef UNIV_MEM_DEBUG
mutex_enter(&mem_hash_mutex);
mem_current_allocated_memory -= n;
mutex_exit(&mem_hash_mutex);
@@ -208,8 +211,10 @@ mem_field_erase(
combination of 0xDE and 0xAD */
mem_erase_buf(buf, MEM_SPACE_NEEDED(n));
+#endif /* UNIV_MEM_DEBUG */
}
+#ifdef UNIV_MEM_DEBUG
/*******************************************************************
Initializes a buffer to a random combination of hex BA and BE.
Used to initialize allocated memory. */
@@ -372,6 +377,7 @@ mem_hash_remove(
mutex_exit(&mem_hash_mutex);
}
+#endif /* UNIV_MEM_DEBUG */
/*******************************************************************
Checks a memory heap for consistency and prints the contents if requested.
@@ -408,12 +414,12 @@ mem_heap_validate_or_print(
ulint total_len = 0;
ulint block_count = 0;
ulint phys_len = 0;
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
ulint len;
byte* field;
byte* user_field;
ulint check_field;
- #endif
+#endif
/* Pessimistically, we set the parameters to error values */
if (us_size != NULL) {
@@ -451,7 +457,7 @@ mem_heap_validate_or_print(
return;
}
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
/* We can trace the fields of the block only in the debug
version */
if (print) {
@@ -518,7 +524,7 @@ mem_heap_validate_or_print(
return;
}
- #endif
+#endif
block = UT_LIST_GET_NEXT(list, block);
block_count++;
@@ -603,130 +609,7 @@ mem_heap_validate(
return(TRUE);
}
-/*********************************************************************
-Prints information of dynamic memory usage and currently allocated
-memory heaps or buffers. Can only be used in the debug version. */
-static
-void
-mem_print_info_low(
-/*===============*/
- ibool print_all __attribute__((unused)))
- /* in: if TRUE, all heaps are printed,
- else only the heaps allocated after the
- previous call of this function */
-{
#ifdef UNIV_MEM_DEBUG
- mem_hash_node_t* node;
- ulint n_heaps = 0;
- ulint allocated_mem;
- ulint ph_size;
- ulint total_allocated_mem = 0;
- ibool error;
- ulint n_blocks;
-#endif
- FILE* outfile;
-
- /* outfile = fopen("ibdebug", "a"); */
-
- outfile = stdout;
-
- fprintf(outfile, "\n");
- fprintf(outfile,
- "________________________________________________________\n");
- fprintf(outfile, "MEMORY ALLOCATION INFORMATION\n\n");
-
-#ifndef UNIV_MEM_DEBUG
-
- mem_pool_print_info(outfile, mem_comm_pool);
-
- fprintf(outfile,
- "Sorry, non-debug version cannot give more memory info\n");
-
- /* fclose(outfile); */
-
- return;
-#else
- mutex_enter(&mem_hash_mutex);
-
- fprintf(outfile, "LIST OF CREATED HEAPS AND ALLOCATED BUFFERS: \n\n");
-
- if (!print_all) {
- fprintf(outfile, "AFTER THE LAST PRINT INFO\n");
- }
-
- node = UT_LIST_GET_FIRST(mem_all_list_base);
-
- while (node != NULL) {
- n_heaps++;
-
- if (!print_all && node->nth_heap < mem_last_print_info) {
-
- goto next_heap;
- }
-
- mem_heap_validate_or_print(node->heap, NULL,
- FALSE, &error, &allocated_mem,
- &ph_size, &n_blocks);
- total_allocated_mem += allocated_mem;
-
- fprintf(outfile,
- "%lu: file %s line %lu of size %lu phys.size %lu with %lu blocks, type %lu\n",
- node->nth_heap, node->file_name, node->line,
- allocated_mem, ph_size, n_blocks,
- (node->heap)->type);
- next_heap:
- node = UT_LIST_GET_NEXT(all_list, node);
- }
-
- fprintf(outfile, "\n");
-
- fprintf(outfile, "Current allocated memory : %lu\n",
- mem_current_allocated_memory);
- fprintf(outfile, "Current allocated heaps and buffers : %lu\n",
- n_heaps);
- fprintf(outfile, "Cumulative allocated memory : %lu\n",
- mem_total_allocated_memory);
- fprintf(outfile, "Maximum allocated memory : %lu\n",
- mem_max_allocated_memory);
- fprintf(outfile, "Cumulative created heaps and buffers : %lu\n",
- mem_n_created_heaps);
- fprintf(outfile, "Cumulative number of allocations : %lu\n",
- mem_n_allocations);
-
- mem_last_print_info = mem_n_created_heaps;
-
- mutex_exit(&mem_hash_mutex);
-
- mem_pool_print_info(outfile, mem_comm_pool);
-
-/* mem_validate(); */
-
-/* fclose(outfile); */
-#endif
-}
-
-/*********************************************************************
-Prints information of dynamic memory usage and currently allocated memory
-heaps or buffers. Can only be used in the debug version. */
-
-void
-mem_print_info(void)
-/*================*/
-{
- mem_print_info_low(TRUE);
-}
-
-/*********************************************************************
-Prints information of dynamic memory usage and currently allocated memory
-heaps or buffers since the last ..._print_info or..._print_new_info. */
-
-void
-mem_print_new_info(void)
-/*====================*/
-{
- mem_print_info_low(FALSE);
-}
-
/*********************************************************************
TRUE if no memory is currently allocated. */
@@ -735,8 +618,6 @@ mem_all_freed(void)
/*===============*/
/* out: TRUE if no heaps exist */
{
- #ifdef UNIV_MEM_DEBUG
-
mem_hash_node_t* node;
ulint heap_count = 0;
ulint i;
@@ -764,15 +645,6 @@ mem_all_freed(void)
} else {
return(FALSE);
}
-
- #else
-
- printf(
- "Sorry, non-debug version cannot check if all memory is freed.\n");
-
- return(FALSE);
-
- #endif
}
/*********************************************************************
@@ -783,8 +655,6 @@ mem_validate_no_assert(void)
/*========================*/
/* out: TRUE if error */
{
- #ifdef UNIV_MEM_DEBUG
-
mem_hash_node_t* node;
ulint n_heaps = 0;
ulint allocated_mem;
@@ -843,14 +713,6 @@ mem_validate_no_assert(void)
mutex_exit(&mem_hash_mutex);
return(error);
-
- #else
-
- printf("Sorry, non-debug version cannot validate dynamic memory\n");
-
- return(FALSE);
-
- #endif
}
/****************************************************************
@@ -865,6 +727,7 @@ mem_validate(void)
return(TRUE);
}
+#endif /* UNIV_MEM_DEBUG */
/****************************************************************
Tries to find neigboring memory allocation blocks and dumps to stderr
diff --git a/innobase/mem/mem0mem.c b/innobase/mem/mem0mem.c
index 94cf85dfd63..6de8d0c5f20 100644
--- a/innobase/mem/mem0mem.c
+++ b/innobase/mem/mem0mem.c
@@ -294,13 +294,13 @@ mem_heap_block_free(
init_block = block->init_block;
block->magic_n = MEM_FREED_BLOCK_MAGIC_N;
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
/* In the debug version we set the memory to a random combination
of hex 0xDE and 0xAD. */
mem_erase_buf((byte*)block, len);
- #endif
+#endif
if (init_block) {
/* Do not have to free: do nothing */
diff --git a/innobase/mem/mem0pool.c b/innobase/mem/mem0pool.c
index 2817e1f12d4..4f1ac2bcd7c 100644
--- a/innobase/mem/mem0pool.c
+++ b/innobase/mem/mem0pool.c
@@ -259,7 +259,9 @@ mem_pool_fill_free_list(
mem_area_t* area2;
ibool ret;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (i >= 63) {
/* We come here when we have run out of space in the
@@ -296,7 +298,7 @@ mem_pool_fill_free_list(
if (UT_LIST_GET_LEN(pool->free_list[i + 1]) == 0) {
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
UT_LIST_REMOVE(free_list, pool->free_list[i + 1], area);
@@ -374,7 +376,7 @@ mem_area_alloc(
"InnoDB: Probably a race condition because now the area is marked free!\n");
}
- ut_a(0);
+ ut_error;
}
if (UT_LIST_GET_LEN(pool->free_list[n]) == 0) {
@@ -384,7 +386,7 @@ mem_area_alloc(
(ulong) n);
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
ut_ad(mem_area_get_size(area) == ut_2_exp(n));
@@ -480,7 +482,7 @@ mem_area_free(
"InnoDB: element is marked free!\n");
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
size = mem_area_get_size(area);
@@ -491,7 +493,7 @@ mem_area_free(
"InnoDB: previous allocated area!\n");
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
#ifdef UNIV_LIGHT_MEM_DEBUG
@@ -508,7 +510,7 @@ mem_area_free(
(ulong) size, (ulong) next_size);
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
}
#endif
diff --git a/innobase/mem/ts/makefile b/innobase/mem/ts/makefile
deleted file mode 100644
index 0f6855322ce..00000000000
--- a/innobase/mem/ts/makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-
-include ..\..\makefile.i
-
-tsmem: ..\mem.lib tsmem.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\mem.lib ..\..\btr.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\os.lib tsmem.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/mem/ts/tsmem.c b/innobase/mem/ts/tsmem.c
deleted file mode 100644
index 4a108251673..00000000000
--- a/innobase/mem/ts/tsmem.c
+++ /dev/null
@@ -1,497 +0,0 @@
-/************************************************************************
-The test module for the memory management of Innobase
-
-(c) 1994, 1995 Innobase Oy
-
-Created 6/10/1994 Heikki Tuuri
-*************************************************************************/
-
-#include "../mem0mem.h"
-#include "sync0sync.h"
-#include "ut0rnd.h"
-
-mem_heap_t* heap_arr[1200];
-
-byte* buf_arr[10000];
-ulint rnd_arr[10000];
-
-
-#ifdef UNIV_DEBUG
-/*********************************************************************
-Debug version test. */
-
-void
-test1(void)
-/*=======*/
-{
- mem_heap_t* heap_1, *heap_2;
- byte* buf_1, *buf_2, *buf_3;
- byte check;
- bool error;
- ulint i;
- ulint j;
- ulint sum;
- ulint user_size;
- ulint phys_size, phys_size_1, phys_size_2;
- ulint n_blocks;
- ulint p;
- byte block[1024];
- byte* top_1, *top_2;
-
- /* For this test to work the memory alignment must be
- even (presumably a reasonable assumption) */
- ut_a(0 == (UNIV_MEM_ALIGNMENT & 1));
-
- printf("-------------------------------------------\n");
- printf("TEST 1. Basic test \n");
-
- heap_1 = mem_heap_create(0);
-
- buf_1 = mem_heap_alloc(heap_1, 11);
-
- heap_2 = mem_heap_create(0);
-
- buf_2 = mem_heap_alloc(heap_1, 15);
-
- /* Test that the field is properly initialized */
- for (i = 0; i < 11; i++) {
- ut_a((*(buf_1 + i) == 0xBA) || (*(buf_1 + i) == 0xBE));
- }
-
- check = *(buf_1 + 11);
-
- mem_validate();
-
- /* Make an advertent error in the heap */
- (*(buf_1 + 11))++;
-
- error = mem_validate_no_assert();
-
- ut_a(error);
-
- /* Fix the error in heap before freeing */
- *(buf_1 + 11) = check;
-
- mem_print_info();
-
- /* Free the top buffer buf_2 */
- mem_heap_free_top(heap_1, 15);
-
- /* Test that the field is properly erased */
- for (i = 0; i < 15; i++) {
- ut_a((*(buf_2 + i) == 0xDE) || (*(buf_2 + i) == 0xAD));
- }
-
- /* Test that a new buffer is allocated from the same position
- as buf_2 */
- buf_3 = mem_heap_alloc(heap_1, 15);
-
- ut_a(buf_3 == buf_2);
-
- mem_heap_free(heap_1);
-
- /* Test that the field is properly erased */
- for (i = 0; i < 11; i++) {
- ut_a((*(buf_1 + i) == 0xDE) || (*(buf_1 + i) == 0xAD));
- }
-
- mem_validate();
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 2. Test of massive allocation and freeing\n");
-
- sum = 0;
- for (i = 0; i < 10000; i++) {
-
- j = ut_rnd_gen_ulint() % 16 + 15;
-
- sum = sum + j;
-
- buf_1 = mem_heap_alloc(heap_2, j);
- rnd_arr[i] = j;
-
- buf_arr[i] = buf_1;
-
- ut_a(buf_1 == mem_heap_get_top(heap_2, j));
- }
-
- mem_heap_validate_or_print(heap_2, NULL, FALSE, &error, &user_size,
- &phys_size_1,
- &n_blocks);
-
- ut_a(!error);
- ut_a(user_size == sum);
-
- (*(buf_1 - 1))++;
-
- ut_a(mem_validate_no_assert());
-
- (*(buf_1 - 1))--;
-
- mem_print_info();
-
-
- for (p = 10000; p > 0 ; p--) {
-
- j = rnd_arr[p - 1];
-
- ut_a(buf_arr[p - 1] == mem_heap_get_top(heap_2, j));
- mem_heap_free_top(heap_2, j);
- }
-
- mem_print_info();
-
- mem_heap_free(heap_2);
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 3. More tests on the validating \n");
-
- heap_1 = mem_heap_create(UNIV_MEM_ALIGNMENT * 20);
-
- buf_1 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT * 20);
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error, &user_size,
- &phys_size_1,
- &n_blocks);
-
- ut_a((ulint)(buf_1 - (byte*)heap_1) == (MEM_BLOCK_HEADER_SIZE
- + MEM_FIELD_HEADER_SIZE));
-
- mem_validate();
-
- mem_print_info();
-
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 20);
- ut_a(phys_size_1 == (ulint)(ut_calc_align(MEM_FIELD_HEADER_SIZE
- + UNIV_MEM_ALIGNMENT * 20
- + MEM_FIELD_TRAILER_SIZE,
- UNIV_MEM_ALIGNMENT)
- + MEM_BLOCK_HEADER_SIZE));
-
- ut_a(n_blocks == 1);
-
- buf_2 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT * 3 - 1);
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size_2,
- &n_blocks);
-
- printf("Physical size of the heap %ld\n", phys_size_2);
-
- ut_a(!error);
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 23 - 1);
- ut_a(phys_size_2 == (ulint) (phys_size_1
- + ut_calc_align(MEM_FIELD_HEADER_SIZE
- + phys_size_1 * 2
- + MEM_FIELD_TRAILER_SIZE,
- UNIV_MEM_ALIGNMENT)
- + MEM_BLOCK_HEADER_SIZE));
-
- ut_a(n_blocks == 2);
-
- buf_3 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT * 3 + 5);
-
- ut_a((ulint)(buf_3 - buf_2) == ut_calc_align(
- (UNIV_MEM_ALIGNMENT * 3
- + MEM_FIELD_TRAILER_SIZE),
- UNIV_MEM_ALIGNMENT)
- + MEM_FIELD_HEADER_SIZE);
-
-
- ut_memcpy(buf_3, buf_2, UNIV_MEM_ALIGNMENT * 3);
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(!error);
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 26 + 4);
- ut_a(phys_size == phys_size_2);
- ut_a(n_blocks == 2);
-
-
- /* Make an advertent error to buf_3 */
-
- (*(buf_3 - 1))++;
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(error);
- ut_a(user_size == 0);
- ut_a(phys_size == 0);
- ut_a(n_blocks == 0);
-
- /* Fix the error and make another */
-
- (*(buf_3 - 1))--;
- (*(buf_3 + UNIV_MEM_ALIGNMENT * 3 + 5))++;
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(error);
-
- (*(buf_3 + UNIV_MEM_ALIGNMENT * 3 + 5))--;
-
- buf_1 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT + 4);
-
- ut_a((ulint)(buf_1 - buf_3) == ut_calc_align(UNIV_MEM_ALIGNMENT * 3 + 5
- + MEM_FIELD_TRAILER_SIZE ,
- UNIV_MEM_ALIGNMENT)
- + MEM_FIELD_HEADER_SIZE);
-
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(!error);
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 27 + 8);
- ut_a(phys_size == phys_size_2);
- ut_a(n_blocks == 2);
-
-
- mem_print_info();
-
- mem_heap_free(heap_1);
-
- printf("-------------------------------------------\n");
- printf("TEST 4. Test of massive allocation \n");
- printf("of heaps to test the hash table\n");
-
- for (i = 0; i < 500; i++) {
- heap_arr[i] = mem_heap_create(i);
- buf_2 = mem_heap_alloc(heap_arr[i], 2 * i);
- }
-
- mem_validate();
-
- for (i = 0; i < 500; i++) {
- mem_heap_free(heap_arr[i]);
- }
-
- mem_validate();
-
- mem_print_info();
-
- /* Validating a freed heap should generate an error */
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- NULL, NULL, NULL);
-
- ut_a(error);
-
- printf("-------------------------------------------\n");
- printf("TEST 5. Test of mem_alloc and mem_free \n");
-
- buf_1 = mem_alloc(11100);
- buf_2 = mem_alloc(23);
-
- ut_memcpy(buf_2, buf_1, 23);
-
- mem_validate();
-
- mem_print_info();
-
- mem_free(buf_1);
- mem_free(buf_2);
-
- mem_validate();
-
- printf("-------------------------------------------\n");
- printf("TEST 6. Test of mem_heap_print \n");
-
- heap_1 = mem_heap_create(0);
-
- buf_1 = mem_heap_alloc(heap_1, 7);
-
- ut_memcpy(buf_1, "Pascal", 7);
-
- for (i = 0; i < 10; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- printf("A heap with 1 Pascal and 10 Cobol's\n");
- mem_heap_print(heap_1);
-
- for (i = 0; i < 10; i++) {
- mem_heap_free_top(heap_1, 6);
- }
-
- printf("A heap with 1 Pascal and 0 Cobol's\n");
- mem_heap_print(heap_1);
-
- ut_a(mem_all_freed() == FALSE);
-
- mem_heap_free(heap_1);
-
- ut_a(mem_all_freed() == TRUE);
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 7. Test of mem_heap_fast_create \n");
-
- heap_1 = mem_heap_fast_create(1024, block);
-
- buf_1 = mem_heap_alloc(heap_1, 7);
-
- ut_memcpy(buf_1, "Pascal", 7);
-
- for (i = 0; i < 1000; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- for (i = 0; i < 1000; i++) {
- mem_heap_free_top(heap_1, 6);
- }
-
- ut_a(mem_all_freed() == FALSE);
-
- mem_heap_free(heap_1);
-
- ut_a(mem_all_freed() == TRUE);
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 8. Test of heap top freeing \n");
-
- heap_1 = mem_heap_fast_create(1024, block);
-
- top_1 = mem_heap_get_heap_top(heap_1);
-
- buf_1 = mem_heap_alloc(heap_1, 7);
-
- ut_memcpy(buf_1, "Pascal", 7);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- top_2 = mem_heap_get_heap_top(heap_1);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- mem_heap_free_heap_top(heap_1, top_2);
-
- mem_heap_free_heap_top(heap_1, top_1);
-
- ut_a(mem_all_freed() == FALSE);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
-
- }
-
- mem_heap_empty(heap_1);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
-
- }
-
- mem_heap_free(heap_1);
-
- ut_a(mem_all_freed() == TRUE);
-
- mem_print_info();
-
-}
-#endif /* UNIV_DEBUG */
-
-/****************************************************************
-Allocation speed test. */
-
-void
-test2(void)
-/*=======*/
-{
- mem_heap_t* heap;
- ulint tm, oldtm;
- ulint i;
- byte* buf;
- byte block[512];
-
- printf("-------------------------------------------\n");
- printf("TEST B1. Test of speed \n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
- heap = mem_heap_create(500);
- mem_heap_free(heap);
- }
-
- tm = ut_clock();
-
- printf("Time for %ld heap create-free pairs %ld millisecs.\n",
- i, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
- heap = mem_heap_fast_create(512, block);
- mem_heap_free(heap);
- }
-
- tm = ut_clock();
-
- printf("Time for %ld heap fast-create-free pairs %ld millisecs.\n",
- i, tm - oldtm);
-
-
- heap = mem_heap_create(500);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
- buf = mem_heap_alloc(heap, 50);
- mem_heap_free_top(heap, 50);
- }
-
- tm = ut_clock();
-
- printf("Time for %ld heap alloc-free-top pairs %ld millisecs.\n",
- i, tm - oldtm);
-
- mem_heap_free(heap);
-}
-
-
-void
-main(void)
-{
- sync_init();
- mem_init(2500000);
-
- #ifdef UNIV_DEBUG
-
- test1();
-
- #endif
-
- test2();
-
- ut_ad(sync_all_freed());
-
- ut_ad(mem_all_freed());
-
- printf("TEST SUCCESSFULLY COMPLETED!\n");
-}