1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-05 06:50:21 +02:00
guile/lib/jit_memory.c
pcpa b768fab8b1 Add code to calculate code buffer size based on devel time information.
* lib/jit_aarch64-sz.c, lib/jit_arm-sz.c, lib/jit_hppa-sz.c,
	lib/jit_ia64-sz.c, lib/jit_mips-sz.c, lib/jit_ppc-sz.c,
	lib/jit_s390x-sz.c, lib/jit_size.c, lib/jit_sparc-sz.c,
	lib/jit_x86-sz.c: New files implementing static tables
	with longest known instructions length generated to match
	a lightning instruction. These tables should make it easier
	to make it very unlikely to ever miscalculate, or by too
	much, the size of a code buffer.

	* lib/jit_size.c: New file that aids to either collect
	jit code size information, or use the information depending
	on build options.

	* size.c: New helper file that parses input for, and create
	an initial jit_$arch-sz.c file, that needs some minor edit
	for arches with multiple configurations.

	* configure.ac, Makefile.am: Add the new, devel mode only
	--enable-devel-get-jit-size configure option, that sets
	compile time flags to collect jit code size information,
	that will be used as input for the "noinst size program".

	* lib/jit_aarch64.c, lib/jit_arm.c, lib/jit_disasm.c,
	lib/jit_hppa.c, lib/jit_ia64.c, lib/jit_memory.c,
	lib/jit_mips.c, lib/jit_ppc.c, lib/jit_s390x.c,
	lib/jit_sparc.c, lib/jit_x86.c, lib/lightning.c: Minor
	changes for the --enable-devel-get-jit-size build mode,
	as well as the "production build mode" with jit code
	size information.
2013-09-24 03:31:54 -03:00

105 lines
2.4 KiB
C

/*
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* This file is part of GNU lightning.
*
* GNU lightning is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU lightning is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* Authors:
* Paulo Cesar Pereira de Andrade
*/
#include <lightning.h>
#include <lightning/jit_private.h>
#include <sys/mman.h>
/*
* Prototypes
*/
static void *jit_default_alloc_func(size_t);
static void *jit_default_realloc_func(void*, size_t);
static void jit_default_free_func(void *);
/*
* Initialization
*/
static jit_alloc_func_ptr jit_alloc_ptr = jit_default_alloc_func;
static jit_realloc_func_ptr jit_realloc_ptr = jit_default_realloc_func;
static jit_free_func_ptr jit_free_ptr = jit_default_free_func;
/*
* Implementation
*/
void
jit_set_memory_functions(jit_alloc_func_ptr alloc_ptr,
jit_realloc_func_ptr realloc_ptr,
jit_free_func_ptr free_ptr)
{
if (alloc_ptr == NULL)
alloc_ptr = jit_default_alloc_func;
if (realloc_ptr == NULL)
realloc_ptr = jit_default_realloc_func;
if (free_ptr == NULL)
free_ptr = jit_default_free_func;
jit_alloc_ptr = alloc_ptr;
jit_realloc_ptr = realloc_ptr;
jit_free_ptr = free_ptr;
}
void
jit_get_memory_functions(jit_alloc_func_ptr *alloc_ptr,
jit_realloc_func_ptr *realloc_ptr,
jit_free_func_ptr *free_ptr)
{
*alloc_ptr = jit_alloc_ptr;
*realloc_ptr = jit_realloc_ptr;
*free_ptr = jit_free_ptr;
}
void
jit_alloc(jit_pointer_t *ptr, jit_word_t size)
{
*ptr = (*jit_alloc_ptr)(size);
memset(*ptr, 0, size);
}
void
jit_realloc(jit_pointer_t *ptr, jit_word_t old_size, jit_word_t new_size)
{
*ptr = (*jit_realloc_ptr)(*ptr, new_size);
if (old_size < new_size)
memset((jit_int8_t*)*ptr + old_size, 0, new_size - old_size);
}
void
jit_free(jit_pointer_t *ptr)
{
(*jit_free_ptr)(*ptr);
*ptr = NULL;
}
static void *
jit_default_alloc_func(size_t size)
{
return (malloc(size));
}
static void *
jit_default_realloc_func(void *ptr, size_t size)
{
return (realloc(ptr, size));
}
static void
jit_default_free_func(void *ptr)
{
free(ptr);
}