9aca0086b9
Fixed doc comments issues:
* Fixed mistyped param doc comments (`/**<` is OK, `/** <` is not).
* Put special characters (e.g., pipe, backslash, etc.) in quotes, as they can
confuse doxygen and it will print lots of various warnings. For the sake of
completeness and consistent style, also quote some special characters in
re-bytecode.h
* Added missing `@{`s, removed extra `@}`s.
* Turned `/*` comments to `/**<` doc comments.
Ensured same style for doc groups everywhere:
* Where `\addtogroup`, `@{`, and `@}` doxygen commands are used, the order to be
followed is: license, `#ifndef` guards (in headers), includes, `\addtogroup`
and `@{`, main code content, `@}`, `#endif` guards (in headers).
* Multiple `\addtogroup`s or multiple `@}`s should be in the same doc comment.
* First `\addtogroup` should be on the very first line of a doc comment, i.e.,
`/** \addtogroup`.
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
150 lines
3.7 KiB
C
150 lines
3.7 KiB
C
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
|
* Copyright 2016 University of Szeged.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/**
|
|
* Allocator implementation
|
|
*/
|
|
|
|
#include "jrt.h"
|
|
#include "jrt-libc-includes.h"
|
|
#include "mem-allocator.h"
|
|
#include "mem-heap.h"
|
|
#include "mem-poolman.h"
|
|
|
|
#define MEM_ALLOCATOR_INTERNAL
|
|
#include "mem-allocator-internal.h"
|
|
|
|
/**
|
|
* The 'try to give memory back' callback
|
|
*/
|
|
static mem_try_give_memory_back_callback_t mem_try_give_memory_back_callback = NULL;
|
|
|
|
/**
|
|
* Initialize memory allocators.
|
|
*/
|
|
void
|
|
mem_init (void)
|
|
{
|
|
mem_heap_init ();
|
|
mem_pools_init ();
|
|
} /* mem_init */
|
|
|
|
/**
|
|
* Finalize memory allocators.
|
|
*/
|
|
void
|
|
mem_finalize (bool is_show_mem_stats) /**< show heap memory stats
|
|
before finalization? */
|
|
{
|
|
mem_pools_finalize ();
|
|
|
|
#ifdef MEM_STATS
|
|
if (is_show_mem_stats)
|
|
{
|
|
mem_stats_print ();
|
|
}
|
|
#else /* MEM_STATS */
|
|
(void) is_show_mem_stats;
|
|
#endif /* !MEM_STATS */
|
|
|
|
mem_heap_finalize ();
|
|
} /* mem_finalize */
|
|
|
|
/**
|
|
* Compress pointer
|
|
*
|
|
* @return packed pointer
|
|
*/
|
|
uintptr_t
|
|
mem_compress_pointer (const void *pointer_p) /**< pointer to compress */
|
|
{
|
|
JERRY_ASSERT (mem_is_heap_pointer (pointer_p));
|
|
|
|
return mem_heap_compress_pointer (pointer_p);
|
|
} /* mem_compress_pointer */
|
|
|
|
/**
|
|
* Decompress pointer
|
|
*
|
|
* @return unpacked pointer
|
|
*/
|
|
void *
|
|
mem_decompress_pointer (uintptr_t compressed_pointer) /**< pointer to decompress */
|
|
{
|
|
return mem_heap_decompress_pointer (compressed_pointer);
|
|
} /* mem_decompress_pointer */
|
|
|
|
/**
|
|
* Register specified 'try to give memory back' callback routine
|
|
*/
|
|
void
|
|
mem_register_a_try_give_memory_back_callback (mem_try_give_memory_back_callback_t callback) /* callback routine */
|
|
{
|
|
/* Currently only one callback is supported */
|
|
JERRY_ASSERT (mem_try_give_memory_back_callback == NULL);
|
|
|
|
mem_try_give_memory_back_callback = callback;
|
|
} /* mem_register_a_try_give_memory_back_callback */
|
|
|
|
/**
|
|
* Unregister specified 'try to give memory back' callback routine
|
|
*/
|
|
void
|
|
mem_unregister_a_try_give_memory_back_callback (mem_try_give_memory_back_callback_t callback) /* callback routine */
|
|
{
|
|
/* Currently only one callback is supported */
|
|
JERRY_ASSERT (mem_try_give_memory_back_callback == callback);
|
|
|
|
mem_try_give_memory_back_callback = NULL;
|
|
} /* mem_unregister_a_try_give_memory_back_callback */
|
|
|
|
/**
|
|
* Run 'try to give memory back' callbacks with specified severity
|
|
*/
|
|
void
|
|
mem_run_try_to_give_memory_back_callbacks (mem_try_give_memory_back_severity_t severity) /**< severity of
|
|
the request */
|
|
{
|
|
if (mem_try_give_memory_back_callback != NULL)
|
|
{
|
|
mem_try_give_memory_back_callback (severity);
|
|
}
|
|
|
|
mem_pools_collect_empty ();
|
|
} /* mem_run_try_to_give_memory_back_callbacks */
|
|
|
|
#ifdef MEM_STATS
|
|
/**
|
|
* Reset peak values in memory usage statistics
|
|
*/
|
|
void
|
|
mem_stats_reset_peak (void)
|
|
{
|
|
mem_heap_stats_reset_peak ();
|
|
mem_pools_stats_reset_peak ();
|
|
} /* mem_stats_reset_peak */
|
|
|
|
/**
|
|
* Print memory usage statistics
|
|
*/
|
|
void
|
|
mem_stats_print (void)
|
|
{
|
|
mem_heap_stats_print ();
|
|
mem_pools_stats_print ();
|
|
} /* mem_stats_print */
|
|
#endif /* MEM_STATS */
|