|
| 1 | +/* Copyright 2016 Samsung Electronics Co., Ltd. |
| 2 | + * Copyright 2016 University of Szeged. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * Memory context for JerryScript |
| 19 | + */ |
| 20 | +#ifndef JCONTEXT_H |
| 21 | +#define JCONTEXT_H |
| 22 | + |
| 23 | +#include "jrt.h" |
| 24 | +#include "jmem-allocator.h" |
| 25 | +#include "jmem-config.h" |
| 26 | + |
| 27 | +/** \addtogroup context Jerry context |
| 28 | + * @{ |
| 29 | + * |
| 30 | + * \addtogroup context Context |
| 31 | + * @{ |
| 32 | + */ |
| 33 | + |
| 34 | +/** |
| 35 | + * Calculate heap area size, leaving space for a pointer to the free list |
| 36 | + */ |
| 37 | +#define JMEM_HEAP_AREA_SIZE (JMEM_HEAP_SIZE - JMEM_ALIGNMENT) |
| 38 | + |
| 39 | +/** |
| 40 | + * Heap structure |
| 41 | + */ |
| 42 | +typedef struct |
| 43 | +{ |
| 44 | + jmem_heap_free_t first; /**< first node in free region list */ |
| 45 | + uint8_t area[JMEM_HEAP_AREA_SIZE]; /**< heap area */ |
| 46 | +} jmem_heap_t; |
| 47 | + |
| 48 | +/** |
| 49 | + * JerryScript context |
| 50 | + * |
| 51 | + * The purpose of this header is storing |
| 52 | + * all global variables for Jerry |
| 53 | + */ |
| 54 | +typedef struct |
| 55 | +{ |
| 56 | + /** |
| 57 | + * Memory manager part. |
| 58 | + */ |
| 59 | + size_t jmem_heap_allocated_size; /**< size of allocated regions */ |
| 60 | + size_t jmem_heap_limit; /**< current limit of heap usage, that is upon being reached, |
| 61 | + * causes call of "try give memory back" callbacks */ |
| 62 | + jmem_heap_free_t *jmem_heap_list_skip_p; /**< This is used to speed up deallocation. */ |
| 63 | + jmem_pools_chunk_t *jmem_free_chunk_p; /**< list of free pool chunks */ |
| 64 | + jmem_free_unused_memory_callback_t jmem_free_unused_memory_callback; /**< Callback for freeing up memory. */ |
| 65 | + |
| 66 | +#ifdef JMEM_STATS |
| 67 | + jmem_heap_stats_t jmem_heap_stats; /**< heap's memory usage statistics */ |
| 68 | + jmem_pools_stats_t jmem_pools_stats; /**< pools' memory usage statistics */ |
| 69 | +#endif /* MEM_STATS */ |
| 70 | + |
| 71 | +#ifdef JERRY_VALGRIND_FREYA |
| 72 | + bool valgrind_freya_mempool_request; /**< Tells whether a pool manager |
| 73 | + * allocator request is in progress */ |
| 74 | +#endif /* JERRY_VALGRIND_FREYA */ |
| 75 | +} jerry_context_t; |
| 76 | + |
| 77 | +/** |
| 78 | + * Jerry global context. |
| 79 | + */ |
| 80 | +extern jerry_context_t jerry_global_context; |
| 81 | + |
| 82 | +/** |
| 83 | + * Jerry global heap. |
| 84 | + */ |
| 85 | +extern jmem_heap_t jerry_global_heap; |
| 86 | + |
| 87 | +/** |
| 88 | + * Provides a reference to a field in the current context. |
| 89 | + */ |
| 90 | +#define JERRY_CONTEXT(field) (jerry_global_context.field) |
| 91 | + |
| 92 | +/** |
| 93 | + * Provides a reference to the area field of the heap. |
| 94 | + */ |
| 95 | +#define JMEM_HEAP_CONTEXT(field) (jerry_global_heap.field) |
| 96 | + |
| 97 | +/** |
| 98 | + * @} |
| 99 | + * @} |
| 100 | + */ |
| 101 | + |
| 102 | +#endif /* !JCONTEXT_H */ |
0 commit comments