Last active
January 28, 2019 17:53
-
-
Save xeioex/ab35a00b4a6993b38d2d22b053439369 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # HG changeset patch | |
| # User Dmitry Volyntsev <[email protected]> | |
| # Date 1548697937 -10800 | |
| # Mon Jan 28 20:52:17 2019 +0300 | |
| # Node ID 7343520d774cfae37f686f9d3995eca756f1db5a | |
| # Parent 23df46c40a53170972500ee902cfa9850dc3ca2e | |
| Renaming nxt_mem_cache_pool_t related structures and fields. | |
| nxt_mem_cache_pool_t -> nxt_mp_t. | |
| nxt_mem_cache_* -> nxt_mp_*. | |
| vm->mem_cache_pool -> vm->mem_pool. | |
| diff --git a/Makefile b/Makefile | |
| --- a/Makefile | |
| +++ b/Makefile | |
| @@ -50,7 +50,7 @@ NXT_BUILDDIR = build | |
| $(NXT_BUILDDIR)/nxt_pcre.o \ | |
| $(NXT_BUILDDIR)/nxt_time.o \ | |
| $(NXT_BUILDDIR)/nxt_malloc.o \ | |
| - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ | |
| + $(NXT_BUILDDIR)/nxt_mp.o \ | |
| ar -r -c $(NXT_BUILDDIR)/libnjs.a \ | |
| $(NXT_BUILDDIR)/njs_shell.o \ | |
| @@ -96,7 +96,7 @@ NXT_BUILDDIR = build | |
| $(NXT_BUILDDIR)/nxt_pcre.o \ | |
| $(NXT_BUILDDIR)/nxt_time.o \ | |
| $(NXT_BUILDDIR)/nxt_malloc.o \ | |
| - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ | |
| + $(NXT_BUILDDIR)/nxt_mp.o \ | |
| all: test lib_test | |
| diff --git a/njs/njs.c b/njs/njs.c | |
| --- a/njs/njs.c | |
| +++ b/njs/njs.c | |
| @@ -49,7 +49,7 @@ njs_free(void *mem, void *p) | |
| } | |
| -const nxt_mem_proto_t njs_vm_mem_cache_pool_proto = { | |
| +const nxt_mem_proto_t njs_vm_mp_proto = { | |
| njs_alloc, | |
| njs_zalloc, | |
| njs_align, | |
| @@ -63,14 +63,14 @@ const nxt_mem_proto_t njs_vm_mem_cache_ | |
| static void * | |
| njs_array_mem_alloc(void *mem, size_t size) | |
| { | |
| - return nxt_mem_cache_alloc(mem, size); | |
| + return nxt_mp_alloc(mem, size); | |
| } | |
| static void | |
| njs_array_mem_free(void *mem, void *p) | |
| { | |
| - nxt_mem_cache_free(mem, p); | |
| + nxt_mp_free(mem, p); | |
| } | |
| @@ -88,22 +88,22 @@ const nxt_mem_proto_t njs_array_mem_pro | |
| njs_vm_t * | |
| njs_vm_create(njs_vm_opt_t *options) | |
| { | |
| + nxt_mp_t *mp; | |
| njs_vm_t *vm; | |
| nxt_int_t ret; | |
| nxt_array_t *debug; | |
| - nxt_mem_cache_pool_t *mcp; | |
| njs_regexp_pattern_t *pattern; | |
| - mcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, | |
| - NULL, 2 * nxt_pagesize(), 128, 512, 16); | |
| - if (nxt_slow_path(mcp == NULL)) { | |
| + mp = nxt_mp_create(&njs_vm_mp_proto, NULL, NULL, 2 * nxt_pagesize(), | |
| + 128, 512, 16); | |
| + if (nxt_slow_path(mp == NULL)) { | |
| return NULL; | |
| } | |
| - vm = nxt_mem_cache_zalign(mcp, sizeof(njs_value_t), sizeof(njs_vm_t)); | |
| + vm = nxt_mp_zalign(mp, sizeof(njs_value_t), sizeof(njs_vm_t)); | |
| if (nxt_fast_path(vm != NULL)) { | |
| - vm->mem_cache_pool = mcp; | |
| + vm->mem_pool = mp; | |
| ret = njs_regexp_init(vm); | |
| if (nxt_slow_path(ret != NXT_OK)) { | |
| @@ -116,7 +116,7 @@ njs_vm_create(njs_vm_opt_t *options) | |
| vm->shared = options->shared; | |
| } else { | |
| - vm->shared = nxt_mem_cache_zalloc(mcp, sizeof(njs_vm_shared_t)); | |
| + vm->shared = nxt_mp_zalloc(mp, sizeof(njs_vm_shared_t)); | |
| if (nxt_slow_path(vm->shared == NULL)) { | |
| return NULL; | |
| } | |
| @@ -125,7 +125,7 @@ njs_vm_create(njs_vm_opt_t *options) | |
| nxt_lvlhsh_init(&vm->shared->keywords_hash); | |
| - ret = njs_lexer_keywords_init(mcp, &vm->shared->keywords_hash); | |
| + ret = njs_lexer_keywords_init(mp, &vm->shared->keywords_hash); | |
| if (nxt_slow_path(ret != NXT_OK)) { | |
| return NULL; | |
| } | |
| @@ -154,7 +154,7 @@ njs_vm_create(njs_vm_opt_t *options) | |
| vm->external_objects = nxt_array_create(4, sizeof(void *), | |
| &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + vm->mem_pool); | |
| if (nxt_slow_path(vm->external_objects == NULL)) { | |
| return NULL; | |
| } | |
| @@ -169,8 +169,7 @@ njs_vm_create(njs_vm_opt_t *options) | |
| if (options->backtrace) { | |
| debug = nxt_array_create(4, sizeof(njs_function_debug_t), | |
| - &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(debug == NULL)) { | |
| return NULL; | |
| } | |
| @@ -210,7 +209,7 @@ njs_vm_destroy(njs_vm_t *vm) | |
| } | |
| } | |
| - nxt_mem_cache_pool_destroy(vm->mem_cache_pool); | |
| + nxt_mp_destroy(vm->mem_pool); | |
| } | |
| @@ -222,7 +221,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st | |
| njs_parser_t *parser, *prev; | |
| njs_generator_t *generator; | |
| - parser = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_parser_t)); | |
| + parser = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_parser_t)); | |
| if (nxt_slow_path(parser == NULL)) { | |
| return NJS_ERROR; | |
| } | |
| @@ -234,7 +233,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st | |
| prev = vm->parser; | |
| vm->parser = parser; | |
| - lexer = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_lexer_t)); | |
| + lexer = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_lexer_t)); | |
| if (nxt_slow_path(lexer == NULL)) { | |
| return NJS_ERROR; | |
| } | |
| @@ -269,8 +268,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **st | |
| */ | |
| vm->code = NULL; | |
| - generator = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - sizeof(njs_generator_t)); | |
| + generator = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + sizeof(njs_generator_t)); | |
| if (nxt_slow_path(generator == NULL)) { | |
| goto fail; | |
| @@ -310,11 +309,11 @@ fail: | |
| njs_vm_t * | |
| njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) | |
| { | |
| - njs_vm_t *nvm; | |
| - uint32_t items; | |
| - nxt_int_t ret; | |
| - nxt_array_t *externals; | |
| - nxt_mem_cache_pool_t *nmcp; | |
| + nxt_mp_t *nmp; | |
| + njs_vm_t *nvm; | |
| + uint32_t items; | |
| + nxt_int_t ret; | |
| + nxt_array_t *externals; | |
| nxt_thread_log_debug("CLONE:"); | |
| @@ -322,16 +321,16 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ | |
| return NULL; | |
| } | |
| - nmcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, | |
| - NULL, 2 * nxt_pagesize(), 128, 512, 16); | |
| - if (nxt_slow_path(nmcp == NULL)) { | |
| + nmp = nxt_mp_create(&njs_vm_mp_proto, NULL, NULL, 2 * nxt_pagesize(), | |
| + 128, 512, 16); | |
| + if (nxt_slow_path(nmp == NULL)) { | |
| return NULL; | |
| } | |
| - nvm = nxt_mem_cache_zalign(nmcp, sizeof(njs_value_t), sizeof(njs_vm_t)); | |
| + nvm = nxt_mp_zalign(nmp, sizeof(njs_value_t), sizeof(njs_vm_t)); | |
| if (nxt_fast_path(nvm != NULL)) { | |
| - nvm->mem_cache_pool = nmcp; | |
| + nvm->mem_pool = nmp; | |
| nvm->shared = vm->shared; | |
| nvm->trace = vm->trace; | |
| @@ -345,7 +344,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ | |
| items = vm->external_objects->items; | |
| externals = nxt_array_create(items + 4, sizeof(void *), | |
| - &njs_array_mem_proto, nvm->mem_cache_pool); | |
| + &njs_array_mem_proto, nvm->mem_pool); | |
| if (nxt_slow_path(externals == NULL)) { | |
| return NULL; | |
| @@ -380,7 +379,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ | |
| fail: | |
| - nxt_mem_cache_pool_destroy(nmcp); | |
| + nxt_mp_destroy(nmp); | |
| return NULL; | |
| } | |
| @@ -400,7 +399,7 @@ njs_vm_init(njs_vm_t *vm) | |
| size = NJS_GLOBAL_FRAME_SIZE + scope_size + NJS_FRAME_SPARE_SIZE; | |
| size = nxt_align_size(size, NJS_FRAME_SPARE_SIZE); | |
| - frame = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), size); | |
| + frame = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), size); | |
| if (nxt_slow_path(frame == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -436,7 +435,7 @@ njs_vm_init(njs_vm_t *vm) | |
| if (vm->debug != NULL) { | |
| backtrace = nxt_array_create(4, sizeof(njs_backtrace_entry_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(backtrace == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -486,7 +485,7 @@ njs_vm_add_event(njs_vm_t *vm, njs_funct | |
| { | |
| njs_event_t *event; | |
| - event = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_event_t)); | |
| + event = nxt_mp_alloc(vm->mem_pool, sizeof(njs_event_t)); | |
| if (nxt_slow_path(event == NULL)) { | |
| return NULL; | |
| } | |
| @@ -542,8 +541,7 @@ njs_vm_post_event(njs_vm_t *vm, njs_vm_e | |
| if (nargs != 0 && !event->posted) { | |
| event->nargs = nargs; | |
| - event->args = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_value_t) * nargs); | |
| + event->args = nxt_mp_alloc(vm->mem_pool, sizeof(njs_value_t) * nargs); | |
| if (nxt_slow_path(event->args == NULL)) { | |
| return NJS_ERROR; | |
| } | |
| @@ -709,7 +707,7 @@ njs_vm_object_alloc(njs_vm_t *vm, njs_va | |
| } | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.proto = &njs_object_hash_proto; | |
| njs_string_get(name, &lhq.key); | |
| diff --git a/njs/njs.h b/njs/njs.h | |
| --- a/njs/njs.h | |
| +++ b/njs/njs.h | |
| @@ -273,6 +273,6 @@ NXT_EXPORT njs_ret_t njs_vm_object_alloc | |
| NXT_EXPORT njs_value_t *njs_vm_object_prop(njs_vm_t *vm, | |
| const njs_value_t *value, const nxt_str_t *key); | |
| -extern const nxt_mem_proto_t njs_vm_mem_cache_pool_proto; | |
| +extern const nxt_mem_proto_t njs_vm_mp_proto; | |
| #endif /* _NJS_H_INCLUDED_ */ | |
| diff --git a/njs/njs_array.c b/njs/njs_array.c | |
| --- a/njs/njs_array.c | |
| +++ b/njs/njs_array.c | |
| @@ -130,7 +130,7 @@ njs_array_alloc(njs_vm_t *vm, uint32_t l | |
| uint64_t size; | |
| njs_array_t *array; | |
| - array = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_array_t)); | |
| + array = nxt_mp_alloc(vm->mem_pool, sizeof(njs_array_t)); | |
| if (nxt_slow_path(array == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -141,8 +141,8 @@ njs_array_alloc(njs_vm_t *vm, uint32_t l | |
| goto memory_error; | |
| } | |
| - array->data = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - size * sizeof(njs_value_t)); | |
| + array->data = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + size * sizeof(njs_value_t)); | |
| if (nxt_slow_path(array->data == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -224,8 +224,8 @@ njs_array_expand(njs_vm_t *vm, njs_array | |
| goto memory_error; | |
| } | |
| - start = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - (prepend + size) * sizeof(njs_value_t)); | |
| + start = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + (prepend + size) * sizeof(njs_value_t)); | |
| if (nxt_slow_path(start == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -240,7 +240,7 @@ njs_array_expand(njs_vm_t *vm, njs_array | |
| array->start = start; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, old); | |
| + nxt_mp_free(vm->mem_pool, old); | |
| return NXT_OK; | |
| @@ -970,8 +970,8 @@ njs_array_prototype_join(njs_vm_t *vm, n | |
| } | |
| if (max != 0) { | |
| - values = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - sizeof(njs_value_t) * max); | |
| + values = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + sizeof(njs_value_t) * max); | |
| if (nxt_slow_path(values == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -1105,7 +1105,7 @@ njs_array_prototype_join_continuation(nj | |
| njs_release(vm, &values[i]); | |
| } | |
| - nxt_mem_cache_free(vm->mem_cache_pool, values); | |
| + nxt_mp_free(vm->mem_pool, values); | |
| return NXT_OK; | |
| } | |
| diff --git a/njs/njs_builtin.c b/njs/njs_builtin.c | |
| --- a/njs/njs_builtin.c | |
| +++ b/njs/njs_builtin.c | |
| @@ -284,12 +284,12 @@ njs_builtin_objects_create(njs_vm_t *vm) | |
| } | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| for (p = njs_module_init; *p != NULL; p++) { | |
| obj = *p; | |
| - module = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_module_t)); | |
| + module = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_module_t)); | |
| if (nxt_slow_path(module == NULL)) { | |
| return NJS_ERROR; | |
| } | |
| @@ -629,7 +629,7 @@ njs_builtin_completions(njs_vm_t *vm, nx | |
| njs_string_get(&prop->name, &string); | |
| len = obj->name.length + string.length + 2; | |
| - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + compl = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (compl == NULL) { | |
| return NULL; | |
| } | |
| @@ -649,7 +649,7 @@ njs_builtin_completions(njs_vm_t *vm, nx | |
| njs_string_get(&prop->name, &string); | |
| len = string.length + 2; | |
| - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + compl = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (compl == NULL) { | |
| return NULL; | |
| } | |
| @@ -679,7 +679,7 @@ njs_builtin_completions(njs_vm_t *vm, nx | |
| njs_string_get(&prop->name, &string); | |
| len = obj->name.length + string.length + 2; | |
| - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + compl = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (compl == NULL) { | |
| return NULL; | |
| } | |
| @@ -705,7 +705,7 @@ njs_builtin_completions(njs_vm_t *vm, nx | |
| nxt_lvlhsh_each_init(&lhe_prop, &njs_extern_hash_proto); | |
| len = ev->name.length + 1; | |
| - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + compl = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (compl == NULL) { | |
| return NULL; | |
| } | |
| @@ -723,7 +723,7 @@ njs_builtin_completions(njs_vm_t *vm, nx | |
| } | |
| len = ev->name.length + ev->name.length + 2; | |
| - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + compl = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (compl == NULL) { | |
| return NULL; | |
| } | |
| @@ -753,8 +753,7 @@ njs_vm_completions(njs_vm_t *vm, nxt_str | |
| size = njs_builtin_completions_size(vm); | |
| completions = nxt_array_create(size, sizeof(nxt_str_t), | |
| - &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(completions == NULL)) { | |
| return NULL; | |
| @@ -879,7 +878,7 @@ njs_object_completions(njs_vm_t *vm, njs | |
| } while (o != NULL); | |
| completions = nxt_array_create(size, sizeof(nxt_str_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(completions == NULL)) { | |
| return NULL; | |
| @@ -993,7 +992,7 @@ njs_builtin_match_native_function(njs_vm | |
| njs_string_get(&prop->name, &string); | |
| len = obj->name.length + string.length + sizeof("."); | |
| - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + buf = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (buf == NULL) { | |
| return NXT_ERROR; | |
| } | |
| @@ -1012,7 +1011,7 @@ njs_builtin_match_native_function(njs_vm | |
| njs_string_get(&prop->name, &string); | |
| len = obj->name.length + string.length + sizeof(".prototype."); | |
| - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + buf = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (buf == NULL) { | |
| return NXT_ERROR; | |
| } | |
| @@ -1031,7 +1030,7 @@ njs_builtin_match_native_function(njs_vm | |
| njs_string_get(&prop->name, &string); | |
| len = obj->name.length + string.length + sizeof("."); | |
| - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + buf = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (buf == NULL) { | |
| return NXT_ERROR; | |
| } | |
| @@ -1060,7 +1059,7 @@ njs_builtin_match_native_function(njs_vm | |
| njs_string_get(&prop->name, &string); | |
| len = obj->name.length + string.length + sizeof("."); | |
| - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + buf = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (buf == NULL) { | |
| return NXT_ERROR; | |
| } | |
| diff --git a/njs/njs_core.h b/njs/njs_core.h | |
| --- a/njs/njs_core.h | |
| +++ b/njs/njs_core.h | |
| @@ -26,7 +26,7 @@ | |
| #include <nxt_random.h> | |
| #include <nxt_time.h> | |
| #include <nxt_malloc.h> | |
| -#include <nxt_mem_cache_pool.h> | |
| +#include <nxt_mp.h> | |
| #include <njs.h> | |
| #include <njs_vm.h> | |
| diff --git a/njs/njs_crypto.c b/njs/njs_crypto.c | |
| --- a/njs/njs_crypto.c | |
| +++ b/njs/njs_crypto.c | |
| @@ -132,7 +132,7 @@ njs_crypto_object_value_alloc(njs_vm_t * | |
| { | |
| njs_object_value_t *ov; | |
| - ov = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_value_t)); | |
| + ov = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_value_t)); | |
| if (nxt_fast_path(ov != NULL)) { | |
| nxt_lvlhsh_init(&ov->object.hash); | |
| @@ -177,7 +177,7 @@ njs_crypto_create_hash(njs_vm_t *vm, njs | |
| return NJS_ERROR; | |
| } | |
| - dgst = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_digest_t)); | |
| + dgst = nxt_mp_alloc(vm->mem_pool, sizeof(njs_digest_t)); | |
| if (nxt_slow_path(dgst == NULL)) { | |
| njs_memory_error(vm); | |
| return NJS_ERROR; | |
| @@ -408,7 +408,7 @@ njs_crypto_create_hmac(njs_vm_t *vm, njs | |
| njs_string_get(&args[2], &key); | |
| - ctx = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_hmac_t)); | |
| + ctx = nxt_mp_alloc(vm->mem_pool, sizeof(njs_hmac_t)); | |
| if (nxt_slow_path(ctx == NULL)) { | |
| njs_memory_error(vm); | |
| return NJS_ERROR; | |
| diff --git a/njs/njs_date.c b/njs/njs_date.c | |
| --- a/njs/njs_date.c | |
| +++ b/njs/njs_date.c | |
| @@ -127,7 +127,7 @@ njs_date_constructor(njs_vm_t *vm, njs_v | |
| done: | |
| - date = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_date_t)); | |
| + date = nxt_mp_alloc(vm->mem_pool, sizeof(njs_date_t)); | |
| if (nxt_slow_path(date == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| diff --git a/njs/njs_error.c b/njs/njs_error.c | |
| --- a/njs/njs_error.c | |
| +++ b/njs/njs_error.c | |
| @@ -57,7 +57,7 @@ njs_error_alloc(njs_vm_t *vm, njs_value_ | |
| njs_object_prop_t *prop; | |
| nxt_lvlhsh_query_t lhq; | |
| - error = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_t)); | |
| + error = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_t)); | |
| if (nxt_slow_path(error == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -71,7 +71,7 @@ njs_error_alloc(njs_vm_t *vm, njs_value_ | |
| error->__proto__ = &vm->prototypes[njs_error_prototype_index(type)].object; | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| if (name != NULL) { | |
| lhq.key = nxt_string_value("name"); | |
| diff --git a/njs/njs_event.c b/njs/njs_event.c | |
| --- a/njs/njs_event.c | |
| +++ b/njs/njs_event.c | |
| @@ -52,7 +52,7 @@ njs_add_event(njs_vm_t *vm, njs_event_t | |
| lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); | |
| lhq.value = event; | |
| lhq.proto = &njs_event_hash_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_insert(&vm->events_hash, &lhq); | |
| if (nxt_slow_path(ret != NXT_OK)) { | |
| @@ -86,7 +86,7 @@ njs_del_event(njs_vm_t *vm, njs_event_t | |
| njs_string_get(&ev->id, &lhq.key); | |
| lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); | |
| lhq.proto = &njs_event_hash_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| if (ev->posted) { | |
| ev->posted = 0; | |
| diff --git a/njs/njs_extern.c b/njs/njs_extern.c | |
| --- a/njs/njs_extern.c | |
| +++ b/njs/njs_extern.c | |
| @@ -79,7 +79,7 @@ njs_vm_external_add(njs_vm_t *vm, nxt_lv | |
| nxt_lvlhsh_query_t lhq; | |
| do { | |
| - ext = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_extern_t)); | |
| + ext = nxt_mp_alloc(vm->mem_pool, sizeof(njs_extern_t)); | |
| if (nxt_slow_path(ext == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -97,14 +97,13 @@ njs_vm_external_add(njs_vm_t *vm, nxt_lv | |
| ext->data = external->data; | |
| if (external->method != NULL) { | |
| - function = nxt_mem_cache_zalloc(vm->mem_cache_pool, | |
| - sizeof(njs_function_t)); | |
| + function = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_function_t)); | |
| if (nxt_slow_path(function == NULL)) { | |
| goto memory_error; | |
| } | |
| /* | |
| - * nxt_mem_cache_zalloc() does also: | |
| + * nxt_mp_zalloc() does also: | |
| * nxt_lvlhsh_init(&function->object.hash); | |
| * function->object.__proto__ = NULL; | |
| */ | |
| @@ -139,7 +138,7 @@ njs_vm_external_add(njs_vm_t *vm, nxt_lv | |
| lhq.key = ext->name; | |
| lhq.replace = 0; | |
| lhq.value = ext; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.proto = &njs_extern_hash_proto; | |
| ret = nxt_lvlhsh_insert(hash, &lhq); | |
| @@ -182,7 +181,7 @@ njs_vm_external_create(njs_vm_t *vm, njs | |
| } | |
| obj = nxt_array_add(vm->external_objects, &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + vm->mem_pool); | |
| if (nxt_slow_path(obj == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -210,8 +209,8 @@ njs_vm_external_bind(njs_vm_t *vm, const | |
| return NXT_ERROR; | |
| } | |
| - ev = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - sizeof(njs_extern_value_t)); | |
| + ev = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + sizeof(njs_extern_value_t)); | |
| if (nxt_slow_path(ev == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -225,7 +224,7 @@ njs_vm_external_bind(njs_vm_t *vm, const | |
| lhq.proto = &njs_extern_value_hash_proto; | |
| lhq.value = ev; | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_insert(&vm->externals_hash, &lhq); | |
| if (nxt_slow_path(ret != NXT_OK)) { | |
| @@ -367,7 +366,7 @@ found: | |
| len += pr->str.length + nxt_length("."); | |
| } | |
| - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); | |
| + buf = nxt_mp_zalloc(vm->mem_pool, len); | |
| if (buf == NULL) { | |
| return NXT_ERROR; | |
| } | |
| diff --git a/njs/njs_fs.c b/njs/njs_fs.c | |
| --- a/njs/njs_fs.c | |
| +++ b/njs/njs_fs.c | |
| @@ -903,7 +903,7 @@ static njs_ret_t njs_fs_error(njs_vm_t * | |
| } | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| if (errn != 0) { | |
| lhq.key = nxt_string_value("errno"); | |
| diff --git a/njs/njs_function.c b/njs/njs_function.c | |
| --- a/njs/njs_function.c | |
| +++ b/njs/njs_function.c | |
| @@ -18,11 +18,11 @@ njs_function_alloc(njs_vm_t *vm) | |
| { | |
| njs_function_t *function; | |
| - function = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_function_t)); | |
| + function = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_function_t)); | |
| if (nxt_fast_path(function != NULL)) { | |
| /* | |
| - * nxt_mem_cache_zalloc() does also: | |
| + * nxt_mp_zalloc() does also: | |
| * nxt_lvlhsh_init(&function->object.hash); | |
| * function->object.__proto__ = NULL; | |
| */ | |
| @@ -33,8 +33,8 @@ njs_function_alloc(njs_vm_t *vm) | |
| function->object.extensible = 1; | |
| function->args_offset = 1; | |
| - function->u.lambda = nxt_mem_cache_zalloc(vm->mem_cache_pool, | |
| - sizeof(njs_function_lambda_t)); | |
| + function->u.lambda = nxt_mp_zalloc(vm->mem_pool, | |
| + sizeof(njs_function_lambda_t)); | |
| if (nxt_slow_path(function->u.lambda == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -66,7 +66,7 @@ njs_function_value_copy(njs_vm_t *vm, nj | |
| size = sizeof(njs_function_t) + nesting * sizeof(njs_closure_t *); | |
| - copy = nxt_mem_cache_alloc(vm->mem_cache_pool, size); | |
| + copy = nxt_mp_alloc(vm->mem_pool, size); | |
| if (nxt_slow_path(copy == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -134,7 +134,7 @@ njs_function_arguments_object_init(njs_v | |
| njs_string_get(&prop->name, &lhq.key); | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.proto = &njs_object_hash_proto; | |
| ret = nxt_lvlhsh_insert(&arguments->hash, &lhq); | |
| @@ -369,8 +369,7 @@ njs_function_frame_alloc(njs_vm_t *vm, s | |
| return NULL; | |
| } | |
| - frame = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - spare_size); | |
| + frame = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), spare_size); | |
| if (nxt_slow_path(frame == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -454,8 +453,7 @@ njs_function_lambda_call(njs_vm_t *vm, n | |
| size = lambda->closure_size; | |
| if (size != 0) { | |
| - closure = nxt_mem_cache_align(vm->mem_cache_pool, | |
| - sizeof(njs_value_t), size); | |
| + closure = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), size); | |
| if (nxt_slow_path(closure == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -706,7 +704,7 @@ njs_function_frame_free(njs_vm_t *vm, nj | |
| if (frame->size != 0) { | |
| vm->stack_size -= frame->size; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, frame); | |
| + nxt_mp_free(vm->mem_pool, frame); | |
| } | |
| frame = previous; | |
| @@ -994,7 +992,7 @@ njs_function_prototype_bind(njs_vm_t *vm | |
| return NXT_ERROR; | |
| } | |
| - function = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_function_t)); | |
| + function = nxt_mp_alloc(vm->mem_pool, sizeof(njs_function_t)); | |
| if (nxt_slow_path(function == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -1017,10 +1015,10 @@ njs_function_prototype_bind(njs_vm_t *vm | |
| function->args_offset = nargs; | |
| size = nargs * sizeof(njs_value_t); | |
| - values = nxt_mem_cache_alloc(vm->mem_cache_pool, size); | |
| + values = nxt_mp_alloc(vm->mem_pool, size); | |
| if (nxt_slow_path(values == NULL)) { | |
| njs_memory_error(vm); | |
| - nxt_mem_cache_free(vm->mem_cache_pool, function); | |
| + nxt_mp_free(vm->mem_pool, function); | |
| return NXT_ERROR; | |
| } | |
| diff --git a/njs/njs_generator.c b/njs/njs_generator.c | |
| --- a/njs/njs_generator.c | |
| +++ b/njs/njs_generator.c | |
| @@ -461,7 +461,7 @@ njs_generate_reserve(njs_vm_t *vm, njs_g | |
| size += size / 2; | |
| } | |
| - p = nxt_mem_cache_alloc(vm->mem_cache_pool, size); | |
| + p = nxt_mp_alloc(vm->mem_pool, size); | |
| if (nxt_slow_path(p == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -472,7 +472,7 @@ njs_generate_reserve(njs_vm_t *vm, njs_g | |
| size = generator->code_end - generator->code_start; | |
| memcpy(p, generator->code_start, size); | |
| - nxt_mem_cache_free(vm->mem_cache_pool, generator->code_start); | |
| + nxt_mp_free(vm->mem_pool, generator->code_start); | |
| generator->code_start = p; | |
| generator->code_end = p + size; | |
| @@ -880,8 +880,7 @@ njs_generate_switch_statement(njs_vm_t * | |
| return ret; | |
| } | |
| - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_generator_patch_t)); | |
| + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); | |
| if (nxt_slow_path(patch == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -921,7 +920,7 @@ njs_generate_switch_statement(njs_vm_t * | |
| next = patch->next; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, patch); | |
| + nxt_mp_free(vm->mem_pool, patch); | |
| patch = next; | |
| node = branch->right; | |
| @@ -1259,8 +1258,7 @@ njs_generate_start_block(njs_vm_t *vm, n | |
| { | |
| njs_generator_block_t *block; | |
| - block = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_generator_block_t)); | |
| + block = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_block_t)); | |
| if (nxt_fast_path(block != NULL)) { | |
| block->next = generator->block; | |
| @@ -1301,8 +1299,7 @@ njs_generate_make_continuation_patch(njs | |
| { | |
| njs_generator_patch_t *patch; | |
| - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_generator_patch_t)); | |
| + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); | |
| if (nxt_slow_path(patch == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -1327,7 +1324,7 @@ njs_generate_patch_block(njs_vm_t *vm, n | |
| njs_code_update_offset(generator, patch); | |
| next = patch->next; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, patch); | |
| + nxt_mp_free(vm->mem_pool, patch); | |
| } | |
| } | |
| @@ -1338,8 +1335,7 @@ njs_generate_make_exit_patch(njs_vm_t *v | |
| { | |
| njs_generator_patch_t *patch; | |
| - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_generator_patch_t)); | |
| + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); | |
| if (nxt_slow_path(patch == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -1364,7 +1360,7 @@ njs_generate_patch_block_exit(njs_vm_t * | |
| njs_generate_patch_block(vm, generator, block->exit); | |
| - nxt_mem_cache_free(vm->mem_cache_pool, block); | |
| + nxt_mp_free(vm->mem_pool, block); | |
| } | |
| @@ -1391,8 +1387,7 @@ njs_generate_continue_statement(njs_vm_t | |
| /* TODO: LABEL */ | |
| - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_generator_patch_t)); | |
| + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); | |
| if (nxt_fast_path(patch != NULL)) { | |
| patch->next = block->continuation; | |
| @@ -1441,8 +1436,7 @@ njs_generate_break_statement(njs_vm_t *v | |
| /* TODO: LABEL: loop and switch may have label, block must have label. */ | |
| - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_generator_patch_t)); | |
| + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); | |
| if (nxt_fast_path(patch != NULL)) { | |
| patch->next = block->exit; | |
| @@ -2293,8 +2287,8 @@ njs_generate_function_scope(njs_vm_t *vm | |
| nxt_array_t *closure; | |
| njs_generator_t *generator; | |
| - generator = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - sizeof(njs_generator_t)); | |
| + generator = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + sizeof(njs_generator_t)); | |
| if (nxt_slow_path(generator == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -2326,7 +2320,7 @@ njs_generate_function_scope(njs_vm_t *vm | |
| lambda->start = generator->code_start; | |
| } | |
| - nxt_mem_cache_free(vm->mem_cache_pool, generator); | |
| + nxt_mp_free(vm->mem_pool, generator); | |
| return ret; | |
| } | |
| @@ -2346,7 +2340,7 @@ njs_generate_scope(njs_vm_t *vm, njs_gen | |
| generator->code_size = 128; | |
| - p = nxt_mem_cache_alloc(vm->mem_cache_pool, generator->code_size); | |
| + p = nxt_mp_alloc(vm->mem_pool, generator->code_size); | |
| if (nxt_slow_path(p == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -2371,8 +2365,7 @@ njs_generate_scope(njs_vm_t *vm, njs_gen | |
| scope_size -= NJS_INDEX_GLOBAL_OFFSET; | |
| } | |
| - generator->local_scope = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - scope_size); | |
| + generator->local_scope = nxt_mp_alloc(vm->mem_pool, scope_size); | |
| if (nxt_slow_path(generator->local_scope == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -2392,13 +2385,13 @@ njs_generate_scope(njs_vm_t *vm, njs_gen | |
| if (vm->code == NULL) { | |
| vm->code = nxt_array_create(4, sizeof(njs_vm_code_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(vm->code == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| } | |
| - code = nxt_array_add(vm->code, &njs_array_mem_proto, vm->mem_cache_pool); | |
| + code = nxt_array_add(vm->code, &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(code == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -2489,8 +2482,7 @@ njs_generate_return_statement(njs_vm_t * | |
| return NXT_OK; | |
| } | |
| - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_generator_patch_t)); | |
| + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); | |
| if (nxt_slow_path(patch == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3087,8 +3079,8 @@ njs_generate_temp_index_get(njs_vm_t *vm | |
| * all global variables are allocated in absolute scope | |
| * to simplify global scope handling. | |
| */ | |
| - value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - sizeof(njs_value_t)); | |
| + value = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + sizeof(njs_value_t)); | |
| if (nxt_slow_path(value == NULL)) { | |
| return NJS_INDEX_ERROR; | |
| } | |
| @@ -3097,7 +3089,7 @@ njs_generate_temp_index_get(njs_vm_t *vm | |
| } else { | |
| value = nxt_array_add(scope->values[0], &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + vm->mem_pool); | |
| if (nxt_slow_path(value == NULL)) { | |
| return NJS_INDEX_ERROR; | |
| } | |
| @@ -3153,7 +3145,7 @@ njs_generate_index_release(njs_vm_t *vm, | |
| if (cache == NULL) { | |
| cache = nxt_array_create(4, sizeof(njs_value_t *), | |
| - &njs_array_mem_proto, vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(cache == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3161,7 +3153,7 @@ njs_generate_index_release(njs_vm_t *vm, | |
| generator->index_cache = cache; | |
| } | |
| - last = nxt_array_add(cache, &njs_array_mem_proto, vm->mem_cache_pool); | |
| + last = nxt_array_add(cache, &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_fast_path(last != NULL)) { | |
| *last = index; | |
| return NXT_OK; | |
| @@ -3177,7 +3169,7 @@ njs_generate_function_debug(njs_vm_t *vm | |
| { | |
| njs_function_debug_t *debug; | |
| - debug = nxt_array_add(vm->debug, &njs_array_mem_proto, vm->mem_cache_pool); | |
| + debug = nxt_array_add(vm->debug, &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(debug == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| diff --git a/njs/njs_json.c b/njs/njs_json.c | |
| --- a/njs/njs_json.c | |
| +++ b/njs/njs_json.c | |
| @@ -13,7 +13,7 @@ | |
| typedef struct { | |
| njs_vm_t *vm; | |
| - nxt_mem_cache_pool_t *pool; | |
| + nxt_mp_t *pool; | |
| nxt_uint_t depth; | |
| const u_char *start; | |
| const u_char *end; | |
| @@ -82,7 +82,7 @@ typedef struct { | |
| njs_value_t key; | |
| njs_vm_t *vm; | |
| - nxt_mem_cache_pool_t *pool; | |
| + nxt_mp_t *pool; | |
| njs_chb_node_t *nodes; | |
| njs_chb_node_t *last; | |
| nxt_array_t stack; | |
| @@ -169,7 +169,7 @@ njs_json_parse(njs_vm_t *vm, njs_value_t | |
| njs_string_prop_t string; | |
| njs_json_parse_ctx_t ctx; | |
| - value = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_value_t)); | |
| + value = nxt_mp_alloc(vm->mem_pool, sizeof(njs_value_t)); | |
| if (nxt_slow_path(value == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -187,7 +187,7 @@ njs_json_parse(njs_vm_t *vm, njs_value_t | |
| end = p + string.size; | |
| ctx.vm = vm; | |
| - ctx.pool = vm->mem_cache_pool; | |
| + ctx.pool = vm->mem_pool; | |
| ctx.depth = 32; | |
| ctx.start = string.start; | |
| ctx.end = end; | |
| @@ -220,7 +220,7 @@ njs_json_parse(njs_vm_t *vm, njs_value_t | |
| parse->function = args[2].data.u.function; | |
| if (nxt_array_init(&parse->stack, NULL, 4, sizeof(njs_json_state_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool) | |
| + &njs_array_mem_proto, vm->mem_pool) | |
| == NULL) | |
| { | |
| goto memory_error; | |
| @@ -262,7 +262,7 @@ njs_json_stringify(njs_vm_t *vm, njs_val | |
| stringify = njs_vm_continuation(vm); | |
| stringify->vm = vm; | |
| - stringify->pool = vm->mem_cache_pool; | |
| + stringify->pool = vm->mem_pool; | |
| stringify->u.cont.function = njs_json_stringify_continuation; | |
| stringify->nodes = NULL; | |
| stringify->last = NULL; | |
| @@ -293,8 +293,8 @@ njs_json_stringify(njs_vm_t *vm, njs_val | |
| num = nxt_min(num, 10); | |
| stringify->space.length = (size_t) num; | |
| - stringify->space.start = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - (size_t) num + 1); | |
| + stringify->space.start = nxt_mp_alloc(vm->mem_pool, | |
| + (size_t) num + 1); | |
| if (nxt_slow_path(stringify->space.start == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -307,7 +307,7 @@ njs_json_stringify(njs_vm_t *vm, njs_val | |
| } | |
| if (nxt_array_init(&stringify->stack, NULL, 4, sizeof(njs_json_state_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool) | |
| + &njs_array_mem_proto, vm->mem_pool) | |
| == NULL) | |
| { | |
| goto memory_error; | |
| @@ -427,7 +427,7 @@ njs_json_parse_object(njs_json_parse_ctx | |
| goto error_token; | |
| } | |
| - prop_name = nxt_mem_cache_alloc(ctx->pool, sizeof(njs_value_t)); | |
| + prop_name = nxt_mp_alloc(ctx->pool, sizeof(njs_value_t)); | |
| if (nxt_slow_path(prop_name == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -448,7 +448,7 @@ njs_json_parse_object(njs_json_parse_ctx | |
| goto error_end; | |
| } | |
| - prop_value = nxt_mem_cache_alloc(ctx->pool, sizeof(njs_value_t)); | |
| + prop_value = nxt_mp_alloc(ctx->pool, sizeof(njs_value_t)); | |
| if (nxt_slow_path(prop_value == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -554,7 +554,7 @@ njs_json_parse_array(njs_json_parse_ctx_ | |
| break; | |
| } | |
| - element = nxt_mem_cache_alloc(ctx->pool, sizeof(njs_value_t)); | |
| + element = nxt_mp_alloc(ctx->pool, sizeof(njs_value_t)); | |
| if (nxt_slow_path(element == NULL)) { | |
| njs_memory_error(ctx->vm); | |
| return NULL; | |
| @@ -721,7 +721,7 @@ njs_json_parse_string(njs_json_parse_ctx | |
| if (surplus != 0) { | |
| p = start; | |
| - dst = nxt_mem_cache_alloc(ctx->pool, size); | |
| + dst = nxt_mp_alloc(ctx->pool, size); | |
| if (nxt_slow_path(dst == NULL)) { | |
| njs_memory_error(ctx->vm);; | |
| return NULL; | |
| @@ -968,7 +968,7 @@ njs_json_parse_continuation(njs_vm_t *vm | |
| lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); | |
| lhq.replace = 1; | |
| lhq.proto = &njs_object_hash_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| if (njs_is_void(&parse->retval)) { | |
| ret = nxt_lvlhsh_delete(&state->value.data.u.object->hash, | |
| @@ -1082,8 +1082,7 @@ njs_json_push_parse_state(njs_vm_t *vm, | |
| { | |
| njs_json_state_t *state; | |
| - state = nxt_array_add(&parse->stack, &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + state = nxt_array_add(&parse->stack, &njs_array_mem_proto, vm->mem_pool); | |
| if (state != NULL) { | |
| state = nxt_array_last(&parse->stack); | |
| state->value = *value; | |
| @@ -1633,7 +1632,7 @@ njs_json_push_stringify_state(njs_vm_t * | |
| } | |
| state = nxt_array_add(&stringify->stack, &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + vm->mem_pool); | |
| if (nxt_slow_path(state == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -1873,7 +1872,7 @@ njs_json_wrap_value(njs_vm_t *vm, njs_va | |
| njs_object_prop_t *prop; | |
| nxt_lvlhsh_query_t lhq; | |
| - wrapper = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_value_t)); | |
| + wrapper = nxt_mp_alloc(vm->mem_pool, sizeof(njs_value_t)); | |
| if (nxt_slow_path(wrapper == NULL)) { | |
| return NULL; | |
| } | |
| @@ -1888,7 +1887,7 @@ njs_json_wrap_value(njs_vm_t *vm, njs_va | |
| lhq.replace = 0; | |
| lhq.proto = &njs_object_hash_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.key = nxt_string_value(""); | |
| lhq.key_hash = NXT_DJB_HASH_INIT; | |
| @@ -1946,7 +1945,7 @@ njs_json_buf_reserve(njs_json_stringify_ | |
| size = NJS_JSON_BUF_MIN_SIZE; | |
| } | |
| - n = nxt_mem_cache_alloc(stringify->pool, sizeof(njs_chb_node_t) + size); | |
| + n = nxt_mp_alloc(stringify->pool, sizeof(njs_chb_node_t) + size); | |
| if (nxt_slow_path(n == NULL)) { | |
| return NULL; | |
| } | |
| @@ -1997,7 +1996,7 @@ njs_json_buf_pullup(njs_json_stringify_t | |
| n = n->next; | |
| } | |
| - start = nxt_mem_cache_alloc(stringify->pool, size); | |
| + start = nxt_mp_alloc(stringify->pool, size); | |
| if (nxt_slow_path(start == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -2296,15 +2295,14 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_ | |
| goto exception; | |
| } | |
| - stringify = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_json_stringify_t)); | |
| + stringify = nxt_mp_alloc(vm->mem_pool, sizeof(njs_json_stringify_t)); | |
| if (nxt_slow_path(stringify == NULL)) { | |
| goto memory_error; | |
| } | |
| stringify->vm = vm; | |
| - stringify->pool = vm->mem_cache_pool; | |
| + stringify->pool = vm->mem_pool; | |
| stringify->nodes = NULL; | |
| stringify->last = NULL; | |
| @@ -2318,7 +2316,7 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_ | |
| } | |
| stringify->space.length = indent; | |
| - stringify->space.start = nxt_mem_cache_alloc(vm->mem_cache_pool, indent); | |
| + stringify->space.start = nxt_mp_alloc(vm->mem_pool, indent); | |
| if (nxt_slow_path(stringify->space.start == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -2326,7 +2324,7 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_ | |
| nxt_memset(stringify->space.start, ' ', indent); | |
| if (nxt_array_init(&stringify->stack, NULL, 4, sizeof(njs_json_state_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool) | |
| + &njs_array_mem_proto, vm->mem_pool) | |
| == NULL) | |
| { | |
| goto memory_error; | |
| diff --git a/njs/njs_lexer_keyword.c b/njs/njs_lexer_keyword.c | |
| --- a/njs/njs_lexer_keyword.c | |
| +++ b/njs/njs_lexer_keyword.c | |
| @@ -156,7 +156,7 @@ const nxt_lvlhsh_proto_t njs_keyword_ha | |
| nxt_int_t | |
| -njs_lexer_keywords_init(nxt_mem_cache_pool_t *mcp, nxt_lvlhsh_t *hash) | |
| +njs_lexer_keywords_init(nxt_mp_t *mcp, nxt_lvlhsh_t *hash) | |
| { | |
| nxt_uint_t n; | |
| nxt_lvlhsh_query_t lhq; | |
| diff --git a/njs/njs_object.c b/njs/njs_object.c | |
| --- a/njs/njs_object.c | |
| +++ b/njs/njs_object.c | |
| @@ -33,7 +33,7 @@ njs_object_alloc(njs_vm_t *vm) | |
| { | |
| njs_object_t *object; | |
| - object = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_t)); | |
| + object = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_t)); | |
| if (nxt_fast_path(object != NULL)) { | |
| nxt_lvlhsh_init(&object->hash); | |
| @@ -62,7 +62,7 @@ njs_object_value_copy(njs_vm_t *vm, njs_ | |
| return object; | |
| } | |
| - object = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_t)); | |
| + object = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_t)); | |
| if (nxt_fast_path(object != NULL)) { | |
| *object = *value->data.u.object; | |
| @@ -84,7 +84,7 @@ njs_object_value_alloc(njs_vm_t *vm, con | |
| nxt_uint_t index; | |
| njs_object_value_t *ov; | |
| - ov = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_value_t)); | |
| + ov = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_value_t)); | |
| if (nxt_fast_path(ov != NULL)) { | |
| nxt_lvlhsh_init(&ov->object.hash); | |
| @@ -116,7 +116,7 @@ njs_object_hash_create(njs_vm_t *vm, nxt | |
| lhq.replace = 0; | |
| lhq.proto = &njs_object_hash_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| while (n != 0) { | |
| njs_string_get(&prop->name, &lhq.key); | |
| @@ -188,8 +188,8 @@ njs_object_prop_alloc(njs_vm_t *vm, cons | |
| { | |
| njs_object_prop_t *prop; | |
| - prop = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - sizeof(njs_object_prop_t)); | |
| + prop = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + sizeof(njs_object_prop_t)); | |
| if (nxt_fast_path(prop != NULL)) { | |
| /* GC: retain. */ | |
| @@ -743,7 +743,7 @@ njs_method_private_copy(njs_vm_t *vm, nj | |
| njs_function_t *function; | |
| njs_object_prop_t *prop, *shared; | |
| - prop = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_prop_t)); | |
| + prop = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_prop_t)); | |
| if (nxt_slow_path(prop == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -759,7 +759,7 @@ njs_method_private_copy(njs_vm_t *vm, nj | |
| pq->lhq.replace = 0; | |
| pq->lhq.value = prop; | |
| - pq->lhq.pool = vm->mem_cache_pool; | |
| + pq->lhq.pool = vm->mem_pool; | |
| return nxt_lvlhsh_insert(&pq->prototype->hash, &pq->lhq); | |
| } | |
| @@ -1441,7 +1441,7 @@ njs_define_property(njs_vm_t *vm, njs_va | |
| } else { | |
| pq.lhq.value = desc; | |
| pq.lhq.replace = 0; | |
| - pq.lhq.pool = vm->mem_cache_pool; | |
| + pq.lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_insert(&object->data.u.object->hash, &pq.lhq); | |
| if (nxt_slow_path(ret != NXT_OK)) { | |
| @@ -1633,7 +1633,7 @@ njs_object_get_own_property_descriptor(n | |
| lhq.proto = &njs_object_hash_proto; | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.proto = &njs_object_hash_proto; | |
| lhq.key = nxt_string_value("value"); | |
| @@ -2050,7 +2050,7 @@ njs_property_prototype_create(njs_vm_t * | |
| lhq.key_hash = NJS_PROTOTYPE_HASH; | |
| lhq.key = nxt_string_value("prototype"); | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.proto = &njs_object_hash_proto; | |
| ret = nxt_lvlhsh_insert(hash, &lhq); | |
| @@ -2308,7 +2308,7 @@ njs_property_constructor_create(njs_vm_t | |
| lhq.key_hash = NJS_CONSTRUCTOR_HASH; | |
| lhq.key = nxt_string_value("constructor"); | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.proto = &njs_object_hash_proto; | |
| ret = nxt_lvlhsh_insert(hash, &lhq); | |
| diff --git a/njs/njs_parser.c b/njs/njs_parser.c | |
| --- a/njs/njs_parser.c | |
| +++ b/njs/njs_parser.c | |
| @@ -91,7 +91,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p | |
| lhq.proto = &njs_variables_hash_proto; | |
| lhq.replace = 0; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| variables = &parser->scope->variables; | |
| prev_variables = &prev->scope->variables; | |
| @@ -178,7 +178,7 @@ njs_parser_scope_begin(njs_vm_t *vm, njs | |
| } | |
| } | |
| - scope = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_parser_scope_t)); | |
| + scope = nxt_mp_alloc(vm->mem_pool, sizeof(njs_parser_scope_t)); | |
| if (nxt_slow_path(scope == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -210,7 +210,7 @@ njs_parser_scope_begin(njs_vm_t *vm, njs | |
| if (scope->type < NJS_SCOPE_BLOCK) { | |
| values = nxt_array_create(4, sizeof(njs_value_t), &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + vm->mem_pool); | |
| if (nxt_slow_path(values == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -450,7 +450,7 @@ njs_parser_block(njs_vm_t *vm, njs_parse | |
| if (node != NULL && node->token == NJS_TOKEN_BLOCK) { | |
| parser->node = node->left; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, node); | |
| + nxt_mp_free(vm->mem_pool, node); | |
| } | |
| return token; | |
| @@ -609,8 +609,7 @@ njs_parser_function_expression(njs_vm_t | |
| } else { | |
| /* Anonymous function. */ | |
| - lambda = nxt_mem_cache_zalloc(vm->mem_cache_pool, | |
| - sizeof(njs_function_lambda_t)); | |
| + lambda = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_function_lambda_t)); | |
| if (nxt_slow_path(lambda == NULL)) { | |
| return NJS_TOKEN_ERROR; | |
| } | |
| @@ -1706,7 +1705,7 @@ njs_parser_try_block(njs_vm_t *vm, njs_p | |
| if (node != NULL && node->token == NJS_TOKEN_BLOCK) { | |
| parser->node = node->left; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, node); | |
| + nxt_mp_free(vm->mem_pool, node); | |
| } | |
| return token; | |
| diff --git a/njs/njs_parser.h b/njs/njs_parser.h | |
| --- a/njs/njs_parser.h | |
| +++ b/njs/njs_parser.h | |
| @@ -284,7 +284,7 @@ struct njs_parser_node_s { | |
| #define njs_parser_node_alloc(vm) \ | |
| - nxt_mem_cache_zalloc((vm)->mem_cache_pool, sizeof(njs_parser_node_t)) | |
| + nxt_mp_zalloc((vm)->mem_pool, sizeof(njs_parser_node_t)) | |
| struct njs_parser_s { | |
| @@ -303,8 +303,7 @@ typedef struct { | |
| njs_token_t njs_lexer_token(njs_lexer_t *lexer); | |
| void njs_lexer_rollback(njs_lexer_t *lexer); | |
| -nxt_int_t njs_lexer_keywords_init(nxt_mem_cache_pool_t *mcp, | |
| - nxt_lvlhsh_t *hash); | |
| +nxt_int_t njs_lexer_keywords_init(nxt_mp_t *mcp, nxt_lvlhsh_t *hash); | |
| njs_token_t njs_lexer_keyword(njs_lexer_t *lexer); | |
| njs_value_t *njs_parser_external(njs_vm_t *vm, njs_parser_t *parser); | |
| diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c | |
| --- a/njs/njs_regexp.c | |
| +++ b/njs/njs_regexp.c | |
| @@ -32,7 +32,7 @@ njs_ret_t | |
| njs_regexp_init(njs_vm_t *vm) | |
| { | |
| vm->regex_context = nxt_regex_context_create(njs_regexp_malloc, | |
| - njs_regexp_free, vm->mem_cache_pool); | |
| + njs_regexp_free, vm->mem_pool); | |
| if (nxt_slow_path(vm->regex_context == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -53,14 +53,14 @@ njs_regexp_init(njs_vm_t *vm) | |
| static void * | |
| njs_regexp_malloc(size_t size, void *memory_data) | |
| { | |
| - return nxt_mem_cache_alloc(memory_data, size); | |
| + return nxt_mp_alloc(memory_data, size); | |
| } | |
| static void | |
| njs_regexp_free(void *p, void *memory_data) | |
| { | |
| - nxt_mem_cache_free(memory_data, p); | |
| + nxt_mp_free(memory_data, p); | |
| } | |
| @@ -269,9 +269,9 @@ njs_regexp_pattern_create(njs_vm_t *vm, | |
| size += ((flags & NJS_REGEXP_IGNORE_CASE) != 0); | |
| size += ((flags & NJS_REGEXP_MULTILINE) != 0); | |
| - pattern = nxt_mem_cache_zalloc(vm->mem_cache_pool, | |
| - sizeof(njs_regexp_pattern_t) | |
| - + 1 + length + size + 1); | |
| + pattern = nxt_mp_zalloc(vm->mem_pool, | |
| + sizeof(njs_regexp_pattern_t) | |
| + + 1 + length + size + 1); | |
| if (nxt_slow_path(pattern == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -328,12 +328,12 @@ njs_regexp_pattern_create(njs_vm_t *vm, | |
| if (nxt_slow_path((u_int) ret != pattern->ncaptures)) { | |
| njs_internal_error(vm, "regexp pattern compile failed"); | |
| - nxt_mem_cache_free(vm->mem_cache_pool, pattern); | |
| + nxt_mp_free(vm->mem_pool, pattern); | |
| return NULL; | |
| } | |
| } else if (ret != NXT_DECLINED) { | |
| - nxt_mem_cache_free(vm->mem_cache_pool, pattern); | |
| + nxt_mp_free(vm->mem_pool, pattern); | |
| return NULL; | |
| } | |
| @@ -430,7 +430,7 @@ njs_regexp_alloc(njs_vm_t *vm, njs_regex | |
| { | |
| njs_regexp_t *regexp; | |
| - regexp = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_regexp_t)); | |
| + regexp = nxt_mp_alloc(vm->mem_pool, sizeof(njs_regexp_t)); | |
| if (nxt_fast_path(regexp != NULL)) { | |
| nxt_lvlhsh_init(®exp->object.hash); | |
| @@ -752,7 +752,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs | |
| lhq.key = nxt_string_value("index"); | |
| lhq.replace = 0; | |
| lhq.value = prop; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| lhq.proto = &njs_object_hash_proto; | |
| ret = nxt_lvlhsh_insert(&array->object.hash, &lhq); | |
| diff --git a/njs/njs_shell.c b/njs/njs_shell.c | |
| --- a/njs/njs_shell.c | |
| +++ b/njs/njs_shell.c | |
| @@ -331,8 +331,7 @@ njs_externals_init(njs_vm_t *vm, njs_con | |
| return NXT_ERROR; | |
| } | |
| - value = nxt_mem_cache_zalloc(vm->mem_cache_pool, | |
| - sizeof(njs_opaque_value_t)); | |
| + value = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_opaque_value_t)); | |
| if (value == NULL) { | |
| return NXT_ERROR; | |
| } | |
| @@ -981,7 +980,7 @@ njs_console_set_timer(njs_external_ptr_t | |
| console = external; | |
| vm = console->vm; | |
| - ev = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_ev_t)); | |
| + ev = nxt_mp_alloc(vm->mem_pool, sizeof(njs_ev_t)); | |
| if (nxt_slow_path(ev == NULL)) { | |
| return NULL; | |
| } | |
| @@ -995,7 +994,7 @@ njs_console_set_timer(njs_external_ptr_t | |
| lhq.replace = 0; | |
| lhq.value = ev; | |
| lhq.proto = &lvlhsh_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_insert(&console->events, &lhq); | |
| if (nxt_slow_path(ret != NXT_OK)) { | |
| @@ -1026,7 +1025,7 @@ njs_console_clear_timer(njs_external_ptr | |
| lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); | |
| lhq.proto = &lvlhsh_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| if (ev->link.prev != NULL) { | |
| nxt_queue_remove(&ev->link); | |
| @@ -1037,7 +1036,7 @@ njs_console_clear_timer(njs_external_ptr | |
| fprintf(stderr, "nxt_lvlhsh_delete() failed\n"); | |
| } | |
| - nxt_mem_cache_free(vm->mem_cache_pool, ev); | |
| + nxt_mp_free(vm->mem_pool, ev); | |
| } | |
| @@ -1059,13 +1058,13 @@ lvlhsh_key_test(nxt_lvlhsh_query_t *lhq, | |
| static void * | |
| lvlhsh_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc) | |
| { | |
| - return nxt_mem_cache_align(pool, size, size); | |
| + return nxt_mp_align(pool, size, size); | |
| } | |
| static void | |
| lvlhsh_pool_free(void *pool, void *p, size_t size) | |
| { | |
| - nxt_mem_cache_free(pool, p); | |
| + nxt_mp_free(pool, p); | |
| } | |
| diff --git a/njs/njs_string.c b/njs/njs_string.c | |
| --- a/njs/njs_string.c | |
| +++ b/njs/njs_string.c | |
| @@ -145,7 +145,7 @@ njs_string_create(njs_vm_t *vm, njs_valu | |
| value->long_string.external = 0xff; | |
| value->long_string.size = size; | |
| - string = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_string_t)); | |
| + string = nxt_mp_alloc(vm->mem_pool, sizeof(njs_string_t)); | |
| if (nxt_slow_path(string == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -214,8 +214,7 @@ njs_string_alloc(njs_vm_t *vm, njs_value | |
| total = size; | |
| } | |
| - string = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_string_t) + total); | |
| + string = nxt_mp_alloc(vm->mem_pool, sizeof(njs_string_t) + total); | |
| if (nxt_fast_path(string != NULL)) { | |
| value->long_string.data = string; | |
| @@ -484,7 +483,7 @@ njs_string_validate(njs_vm_t *vm, njs_st | |
| map_offset = njs_string_map_offset(size); | |
| new_size = map_offset + njs_string_map_size(length); | |
| - start = nxt_mem_cache_alloc(vm->mem_cache_pool, new_size); | |
| + start = nxt_mp_alloc(vm->mem_pool, new_size); | |
| if (nxt_slow_path(start == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -2955,7 +2954,7 @@ njs_string_prototype_replace(njs_vm_t *v | |
| /* This cannot fail. */ | |
| r->part = nxt_array_init(&r->parts, &r->array, | |
| 3, sizeof(njs_string_replace_part_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| r->substitutions = NULL; | |
| r->function = NULL; | |
| @@ -3050,13 +3049,13 @@ njs_string_replace_regexp(njs_vm_t *vm, | |
| } else { | |
| if (r->part != r->parts.start) { | |
| r->part = nxt_array_add(&r->parts, &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + vm->mem_pool); | |
| if (nxt_slow_path(r->part == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| r->part = nxt_array_add(&r->parts, &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + vm->mem_pool); | |
| if (nxt_slow_path(r->part == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3101,7 +3100,7 @@ njs_string_replace_regexp(njs_vm_t *vm, | |
| nxt_regex_match_data_free(r->match_data, vm->regex_context); | |
| - nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_cache_pool); | |
| + nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_pool); | |
| njs_string_copy(&vm->retval, &args[0]); | |
| @@ -3122,8 +3121,7 @@ njs_string_replace_regexp_function(njs_v | |
| r->u.cont.function = njs_string_replace_regexp_continuation; | |
| njs_set_invalid(&r->retval); | |
| - arguments = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - (n + 3) * sizeof(njs_value_t)); | |
| + arguments = nxt_mp_alloc(vm->mem_pool, (n + 3) * sizeof(njs_value_t)); | |
| if (nxt_slow_path(arguments == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3315,7 +3313,7 @@ njs_string_replace_parse(njs_vm_t *vm, n | |
| njs_string_subst_t *s; | |
| r->substitutions = nxt_array_create(4, sizeof(njs_string_subst_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(r->substitutions == NULL)) { | |
| return NXT_ERROR; | |
| @@ -3330,8 +3328,7 @@ njs_string_replace_parse(njs_vm_t *vm, n | |
| copy: | |
| if (s == NULL) { | |
| - s = nxt_array_add(r->substitutions, &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + s = nxt_array_add(r->substitutions, &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(s == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3395,8 +3392,7 @@ skip: | |
| goto copy; | |
| } | |
| - s = nxt_array_add(r->substitutions, &njs_array_mem_proto, | |
| - vm->mem_cache_pool); | |
| + s = nxt_array_add(r->substitutions, &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(s == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3419,8 +3415,8 @@ njs_string_replace_substitute(njs_vm_t * | |
| last = r->substitutions->items; | |
| - part = nxt_array_add_multiple(&r->parts, &njs_array_mem_proto, | |
| - vm->mem_cache_pool, last + 1); | |
| + part = nxt_array_add_multiple(&r->parts, &njs_array_mem_proto, vm->mem_pool, | |
| + last + 1); | |
| if (nxt_slow_path(part == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3528,7 +3524,7 @@ njs_string_replace_join(njs_vm_t *vm, nj | |
| /* GC: release valid values. */ | |
| } | |
| - nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_cache_pool); | |
| + nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_pool); | |
| return NXT_OK; | |
| } | |
| @@ -3744,7 +3740,7 @@ njs_string_to_c_string(njs_vm_t *vm, njs | |
| } | |
| } | |
| - data = nxt_mem_cache_alloc(vm->mem_cache_pool, size + 1); | |
| + data = nxt_mp_alloc(vm->mem_pool, size + 1); | |
| if (nxt_slow_path(data == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -4406,8 +4402,8 @@ njs_value_index(njs_vm_t *vm, const njs_ | |
| } | |
| } | |
| - value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - value_size + size); | |
| + value = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + value_size + size); | |
| if (nxt_slow_path(value == NULL)) { | |
| return NJS_INDEX_NONE; | |
| } | |
| @@ -4427,7 +4423,7 @@ njs_value_index(njs_vm_t *vm, const njs_ | |
| lhq.replace = 0; | |
| lhq.value = value; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| values_hash = runtime ? &vm->values_hash : &vm->shared->values_hash; | |
| diff --git a/njs/njs_time.c b/njs/njs_time.c | |
| --- a/njs/njs_time.c | |
| +++ b/njs/njs_time.c | |
| @@ -41,7 +41,7 @@ njs_set_timer(njs_vm_t *vm, njs_value_t | |
| delay = args[2].data.u.number; | |
| } | |
| - event = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_event_t)); | |
| + event = nxt_mp_alloc(vm->mem_pool, sizeof(njs_event_t)); | |
| if (nxt_slow_path(event == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -55,8 +55,8 @@ njs_set_timer(njs_vm_t *vm, njs_value_t | |
| event->posted = 0; | |
| if (event->nargs != 0) { | |
| - event->args = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_value_t) * event->nargs); | |
| + event->args = nxt_mp_alloc(vm->mem_pool, | |
| + sizeof(njs_value_t) * event->nargs); | |
| if (nxt_slow_path(event->args == NULL)) { | |
| goto memory_error; | |
| } | |
| @@ -115,7 +115,7 @@ njs_clear_timeout(njs_vm_t *vm, njs_valu | |
| (unsigned) args[1].data.u.number); | |
| lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); | |
| lhq.proto = &njs_event_hash_proto; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_find(&vm->events_hash, &lhq); | |
| if (ret == NXT_OK) { | |
| diff --git a/njs/njs_variable.c b/njs/njs_variable.c | |
| --- a/njs/njs_variable.c | |
| +++ b/njs/njs_variable.c | |
| @@ -75,7 +75,7 @@ njs_variable_add(njs_vm_t *vm, njs_parse | |
| lhq.replace = 0; | |
| lhq.value = var; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_insert(&scope->variables, &lhq); | |
| @@ -83,8 +83,8 @@ njs_variable_add(njs_vm_t *vm, njs_parse | |
| return var; | |
| } | |
| - nxt_mem_cache_free(vm->mem_cache_pool, var->name.start); | |
| - nxt_mem_cache_free(vm->mem_cache_pool, var); | |
| + nxt_mp_free(vm->mem_pool, var->name.start); | |
| + nxt_mp_free(vm->mem_pool, var); | |
| njs_type_error(vm, "lvlhsh insert failed"); | |
| @@ -141,7 +141,7 @@ njs_variable_reference(njs_vm_t *vm, njs | |
| lhq.proto = &njs_reference_hash_proto; | |
| lhq.replace = 0; | |
| lhq.value = node; | |
| - lhq.pool = vm->mem_cache_pool; | |
| + lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_insert(&scope->references, &lhq); | |
| @@ -337,8 +337,8 @@ njs_variable_resolve(njs_vm_t *vm, njs_p | |
| * global variables should be allocated in absolute scope | |
| * to share them among consecutive VM invocations. | |
| */ | |
| - value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), | |
| - sizeof(njs_value_t)); | |
| + value = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), | |
| + sizeof(njs_value_t)); | |
| if (nxt_slow_path(value == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -351,7 +351,7 @@ njs_variable_resolve(njs_vm_t *vm, njs_p | |
| if (values == NULL) { | |
| values = nxt_array_create(4, sizeof(njs_value_t), | |
| - &njs_array_mem_proto, vm->mem_cache_pool); | |
| + &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(values == NULL)) { | |
| return NULL; | |
| } | |
| @@ -359,7 +359,7 @@ njs_variable_resolve(njs_vm_t *vm, njs_p | |
| vr->scope->values[scope_index] = values; | |
| } | |
| - value = nxt_array_add(values, &njs_array_mem_proto, vm->mem_cache_pool); | |
| + value = nxt_array_add(values, &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(value == NULL)) { | |
| return NULL; | |
| } | |
| @@ -454,7 +454,7 @@ njs_variable_alloc(njs_vm_t *vm, nxt_str | |
| njs_ret_t ret; | |
| njs_variable_t *var; | |
| - var = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_variable_t)); | |
| + var = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_variable_t)); | |
| if (nxt_slow_path(var == NULL)) { | |
| njs_memory_error(vm); | |
| return NULL; | |
| @@ -468,7 +468,7 @@ njs_variable_alloc(njs_vm_t *vm, nxt_str | |
| return var; | |
| } | |
| - nxt_mem_cache_free(vm->mem_cache_pool, var); | |
| + nxt_mp_free(vm->mem_pool, var); | |
| njs_memory_error(vm); | |
| @@ -481,7 +481,7 @@ njs_name_copy(njs_vm_t *vm, nxt_str_t *d | |
| { | |
| dst->length = src->length; | |
| - dst->start = nxt_mem_cache_alloc(vm->mem_cache_pool, src->length); | |
| + dst->start = nxt_mp_alloc(vm->mem_pool, src->length); | |
| if (nxt_slow_path(dst->start != NULL)) { | |
| (void) memcpy(dst->start, src->start, src->length); | |
| diff --git a/njs/njs_vm.c b/njs/njs_vm.c | |
| --- a/njs/njs_vm.c | |
| +++ b/njs/njs_vm.c | |
| @@ -236,7 +236,7 @@ start: | |
| if (frame->native.size != 0) { | |
| vm->stack_size -= frame->native.size; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, frame); | |
| + nxt_mp_free(vm->mem_pool, frame); | |
| } | |
| } | |
| } | |
| @@ -289,11 +289,11 @@ njs_value_release(njs_vm_t *vm, njs_valu | |
| if ((u_char *) string + sizeof(njs_string_t) | |
| != string->start) | |
| { | |
| - nxt_memcache_pool_free(vm->mem_cache_pool, | |
| + nxt_memcache_pool_free(vm->mem_pool, | |
| string->start); | |
| } | |
| - nxt_memcache_pool_free(vm->mem_cache_pool, string); | |
| + nxt_memcache_pool_free(vm->mem_pool, string); | |
| } | |
| #endif | |
| } | |
| @@ -377,7 +377,7 @@ njs_vmcode_function(njs_vm_t *vm, njs_va | |
| size = sizeof(njs_function_t) + nesting * sizeof(njs_closure_t *); | |
| - function = nxt_mem_cache_zalloc(vm->mem_cache_pool, size); | |
| + function = nxt_mp_zalloc(vm->mem_pool, size); | |
| if (nxt_slow_path(function == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -592,7 +592,7 @@ njs_vmcode_property_set(njs_vm_t *vm, nj | |
| pq.lhq.replace = 0; | |
| pq.lhq.value = prop; | |
| - pq.lhq.pool = vm->mem_cache_pool; | |
| + pq.lhq.pool = vm->mem_pool; | |
| ret = nxt_lvlhsh_insert(&object->data.u.object->hash, &pq.lhq); | |
| if (nxt_slow_path(ret != NXT_OK)) { | |
| @@ -765,8 +765,7 @@ njs_vmcode_property_foreach(njs_vm_t *vm | |
| njs_vmcode_prop_foreach_t *code; | |
| if (njs_is_object(object)) { | |
| - next = nxt_mem_cache_alloc(vm->mem_cache_pool, | |
| - sizeof(njs_property_next_t)); | |
| + next = nxt_mp_alloc(vm->mem_pool, sizeof(njs_property_next_t)); | |
| if (nxt_slow_path(next == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -849,7 +848,7 @@ njs_vmcode_property_next(njs_vm_t *vm, n | |
| } | |
| } | |
| - nxt_mem_cache_free(vm->mem_cache_pool, next); | |
| + nxt_mp_free(vm->mem_pool, next); | |
| } else if (njs_is_external(object)) { | |
| ext_proto = object->external.proto; | |
| @@ -2343,7 +2342,7 @@ njs_vmcode_try_start(njs_vm_t *vm, njs_v | |
| njs_vmcode_try_start_t *try_start; | |
| if (vm->top_frame->exception.catch != NULL) { | |
| - e = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_exception_t)); | |
| + e = nxt_mp_alloc(vm->mem_pool, sizeof(njs_exception_t)); | |
| if (nxt_slow_path(e == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -2436,7 +2435,7 @@ njs_vmcode_try_end(njs_vm_t *vm, njs_val | |
| } else { | |
| vm->top_frame->exception = *e; | |
| - nxt_mem_cache_free(vm->mem_cache_pool, e); | |
| + nxt_mp_free(vm->mem_pool, e); | |
| } | |
| return (njs_ret_t) offset; | |
| @@ -3104,7 +3103,7 @@ again: | |
| size = value.short_string.size; | |
| if (size != NJS_STRING_LONG) { | |
| - start = nxt_mem_cache_alloc(vm->mem_cache_pool, size); | |
| + start = nxt_mp_alloc(vm->mem_pool, size); | |
| if (nxt_slow_path(start == NULL)) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -3157,7 +3156,7 @@ again: | |
| prev = &be[i]; | |
| } | |
| - p = nxt_mem_cache_alloc(vm->mem_cache_pool, len); | |
| + p = nxt_mp_alloc(vm->mem_pool, len); | |
| if (p == NULL) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -3513,7 +3512,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm, | |
| native_frame = &frame->native; | |
| function = native_frame->function; | |
| - be = nxt_array_add(vm->backtrace, &njs_array_mem_proto, vm->mem_cache_pool); | |
| + be = nxt_array_add(vm->backtrace, &njs_array_mem_proto, vm->mem_pool); | |
| if (nxt_slow_path(be == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| @@ -3631,12 +3630,12 @@ njs_debug(njs_index_t index, njs_value_t | |
| void * | |
| njs_lvlhsh_alloc(void *data, size_t size, nxt_uint_t nalloc) | |
| { | |
| - return nxt_mem_cache_align(data, size, size); | |
| + return nxt_mp_align(data, size, size); | |
| } | |
| void | |
| njs_lvlhsh_free(void *data, void *p, size_t size) | |
| { | |
| - nxt_mem_cache_free(data, p); | |
| + nxt_mp_free(data, p); | |
| } | |
| diff --git a/njs/njs_vm.h b/njs/njs_vm.h | |
| --- a/njs/njs_vm.h | |
| +++ b/njs/njs_vm.h | |
| @@ -13,7 +13,7 @@ | |
| #include <nxt_regex.h> | |
| #include <nxt_random.h> | |
| #include <nxt_djb_hash.h> | |
| -#include <nxt_mem_cache_pool.h> | |
| +#include <nxt_mp.h> | |
| #define NJS_MAX_STACK_SIZE (16 * 1024 * 1024) | |
| @@ -1053,7 +1053,7 @@ struct njs_vm_s { | |
| njs_object_prototype_t prototypes[NJS_PROTOTYPE_MAX]; | |
| njs_function_t constructors[NJS_CONSTRUCTOR_MAX]; | |
| - nxt_mem_cache_pool_t *mem_cache_pool; | |
| + nxt_mp_t *mem_pool; | |
| njs_value_t *global_scope; | |
| size_t scope_size; | |
| diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c | |
| --- a/njs/test/njs_unit_test.c | |
| +++ b/njs/test/njs_unit_test.c | |
| @@ -11099,7 +11099,7 @@ static njs_unit_test_t njs_tz_test[] = | |
| typedef struct { | |
| nxt_lvlhsh_t hash; | |
| const njs_extern_t *proto; | |
| - nxt_mem_cache_pool_t *mem_cache_pool; | |
| + nxt_mp_t *pool; | |
| uint32_t a; | |
| nxt_str_t uri; | |
| @@ -11138,14 +11138,14 @@ lvlhsh_unit_test_key_test(nxt_lvlhsh_que | |
| static void * | |
| lvlhsh_unit_test_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc) | |
| { | |
| - return nxt_mem_cache_align(pool, size, size); | |
| + return nxt_mp_align(pool, size, size); | |
| } | |
| static void | |
| lvlhsh_unit_test_pool_free(void *pool, void *p, size_t size) | |
| { | |
| - nxt_mem_cache_free(pool, p); | |
| + nxt_mp_free(pool, p); | |
| } | |
| @@ -11159,12 +11159,12 @@ static const nxt_lvlhsh_proto_t lvlhsh_ | |
| static njs_unit_test_prop_t * | |
| -lvlhsh_unit_test_alloc(nxt_mem_cache_pool_t *pool, const njs_value_t *name, | |
| +lvlhsh_unit_test_alloc(nxt_mp_t *pool, const njs_value_t *name, | |
| const njs_value_t *value) | |
| { | |
| njs_unit_test_prop_t *prop; | |
| - prop = nxt_mem_cache_alloc(pool, sizeof(njs_unit_test_prop_t)); | |
| + prop = nxt_mp_alloc(pool, sizeof(njs_unit_test_prop_t)); | |
| if (prop == NULL) { | |
| return NULL; | |
| } | |
| @@ -11187,7 +11187,7 @@ lvlhsh_unit_test_add(njs_unit_test_req_t | |
| lhq.replace = 1; | |
| lhq.value = (void *) prop; | |
| lhq.proto = &lvlhsh_proto; | |
| - lhq.pool = r->mem_cache_pool; | |
| + lhq.pool = r->pool; | |
| switch (nxt_lvlhsh_insert(&r->hash, &lhq)) { | |
| @@ -11318,7 +11318,7 @@ njs_unit_test_r_set_vars(njs_vm_t *vm, v | |
| njs_string_create(vm, &name, key->start, key->length, 0); | |
| njs_string_create(vm, &val, value->start, value->length, 0); | |
| - prop = lvlhsh_unit_test_alloc(vm->mem_cache_pool, &name, &val); | |
| + prop = lvlhsh_unit_test_alloc(vm->mem_pool, &name, &val); | |
| if (prop == NULL) { | |
| njs_memory_error(vm); | |
| return NXT_ERROR; | |
| @@ -11468,18 +11468,18 @@ njs_unit_test_create_external(njs_vm_t * | |
| return NJS_ERROR; | |
| } | |
| - value = nxt_mem_cache_zalloc(r->mem_cache_pool, sizeof(njs_opaque_value_t)); | |
| + value = nxt_mp_zalloc(r->pool, sizeof(njs_opaque_value_t)); | |
| if (value == NULL) { | |
| goto memory_error; | |
| } | |
| - sr = nxt_mem_cache_zalloc(r->mem_cache_pool, sizeof(njs_unit_test_req_t)); | |
| + sr = nxt_mp_zalloc(r->pool, sizeof(njs_unit_test_req_t)); | |
| if (sr == NULL) { | |
| goto memory_error; | |
| } | |
| sr->uri = uri; | |
| - sr->mem_cache_pool = r->mem_cache_pool; | |
| + sr->pool = r->pool; | |
| sr->proto = r->proto; | |
| ret = njs_vm_external_create(vm, value, sr->proto, sr); | |
| @@ -11704,9 +11704,9 @@ njs_externals_init(njs_vm_t *vm) | |
| return NXT_ERROR; | |
| } | |
| - requests = nxt_mem_cache_zalloc(vm->mem_cache_pool, | |
| - nxt_nitems(nxt_test_requests) | |
| - * sizeof(njs_unit_test_req_t)); | |
| + requests = nxt_mp_zalloc(vm->mem_pool, | |
| + nxt_nitems(nxt_test_requests) | |
| + * sizeof(njs_unit_test_req_t)); | |
| if (requests == NULL) { | |
| return NXT_ERROR; | |
| } | |
| @@ -11714,7 +11714,7 @@ njs_externals_init(njs_vm_t *vm) | |
| for (i = 0; i < nxt_nitems(nxt_test_requests); i++) { | |
| requests[i] = nxt_test_requests[i].request; | |
| - requests[i].mem_cache_pool = vm->mem_cache_pool; | |
| + requests[i].pool = vm->mem_pool; | |
| requests[i].proto = proto; | |
| ret = njs_vm_external_create(vm, njs_value_arg(&requests[i].value), | |
| @@ -11732,7 +11732,7 @@ njs_externals_init(njs_vm_t *vm) | |
| } | |
| for (j = 0; j < nxt_nitems(nxt_test_requests[i].props); j++) { | |
| - prop = lvlhsh_unit_test_alloc(vm->mem_cache_pool, | |
| + prop = lvlhsh_unit_test_alloc(vm->mem_pool, | |
| &nxt_test_requests[i].props[j].name, | |
| &nxt_test_requests[i].props[j].value); | |
| diff --git a/nxt/Makefile b/nxt/Makefile | |
| --- a/nxt/Makefile | |
| +++ b/nxt/Makefile | |
| @@ -21,7 +21,7 @@ NXT_LIB = nxt | |
| $(NXT_BUILDDIR)/nxt_malloc.o \ | |
| $(NXT_BUILDDIR)/nxt_trace.o \ | |
| $(NXT_BUILDDIR)/nxt_time.o \ | |
| - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ | |
| + $(NXT_BUILDDIR)/nxt_mp.o \ | |
| ar -r -c $(NXT_BUILDDIR)/libnxt.a \ | |
| $(NXT_BUILDDIR)/nxt_diyfp.o \ | |
| @@ -40,7 +40,7 @@ NXT_LIB = nxt | |
| $(NXT_BUILDDIR)/nxt_malloc.o \ | |
| $(NXT_BUILDDIR)/nxt_time.o \ | |
| $(NXT_BUILDDIR)/nxt_trace.o \ | |
| - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ | |
| + $(NXT_BUILDDIR)/nxt_mp.o \ | |
| $(NXT_BUILDDIR)/nxt_diyfp.o: \ | |
| $(NXT_LIB)/nxt_types.h \ | |
| @@ -231,17 +231,17 @@ NXT_LIB = nxt | |
| -I$(NXT_LIB) \ | |
| $(NXT_LIB)/nxt_trace.c | |
| -$(NXT_BUILDDIR)/nxt_mem_cache_pool.o: \ | |
| +$(NXT_BUILDDIR)/nxt_mp.o: \ | |
| $(NXT_LIB)/nxt_types.h \ | |
| $(NXT_LIB)/nxt_clang.h \ | |
| $(NXT_LIB)/nxt_alignment.h \ | |
| $(NXT_LIB)/nxt_queue.h \ | |
| $(NXT_LIB)/nxt_rbtree.h \ | |
| - $(NXT_LIB)/nxt_mem_cache_pool.h \ | |
| - $(NXT_LIB)/nxt_mem_cache_pool.c \ | |
| + $(NXT_LIB)/nxt_mp.h \ | |
| + $(NXT_LIB)/nxt_mp.c \ | |
| - $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_mem_cache_pool.o $(NXT_CFLAGS) \ | |
| + $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_mp.o $(NXT_CFLAGS) \ | |
| -I$(NXT_LIB) \ | |
| - $(NXT_LIB)/nxt_mem_cache_pool.c | |
| + $(NXT_LIB)/nxt_mp.c | |
| include $(NXT_LIB)/test/Makefile | |
| diff --git a/nxt/nxt_mem_cache_pool.c b/nxt/nxt_mp.c | |
| rename from nxt/nxt_mem_cache_pool.c | |
| rename to nxt/nxt_mp.c | |
| --- a/nxt/nxt_mem_cache_pool.c | |
| +++ b/nxt/nxt_mp.c | |
| @@ -12,7 +12,7 @@ | |
| #include <nxt_string.h> | |
| #include <nxt_queue.h> | |
| #include <nxt_rbtree.h> | |
| -#include <nxt_mem_cache_pool.h> | |
| +#include <nxt_mp.h> | |
| #include <string.h> | |
| #include <stdint.h> | |
| @@ -39,7 +39,7 @@ typedef struct { | |
| nxt_queue_link_t link; | |
| /* | |
| - * Size of chunks or page shifted by pool->chunk_size_shift. | |
| + * Size of chunks or page shifted by mp->chunk_size_shift. | |
| * Zero means that page is free. | |
| */ | |
| uint8_t size; | |
| @@ -57,35 +57,35 @@ typedef struct { | |
| /* Chunk bitmap. There can be no more than 32 chunks in a page. */ | |
| uint8_t map[4]; | |
| -} nxt_mem_cache_page_t; | |
| +} nxt_mp_page_t; | |
| typedef enum { | |
| /* Block of cluster. The block is allocated apart of the cluster. */ | |
| - NXT_MEM_CACHE_CLUSTER_BLOCK = 0, | |
| + NXT_MP_CLUSTER_BLOCK = 0, | |
| /* | |
| * Block of large allocation. | |
| * The block is allocated apart of the allocation. | |
| */ | |
| - NXT_MEM_CACHE_DISCRETE_BLOCK, | |
| + NXT_MP_DISCRETE_BLOCK, | |
| /* | |
| * Block of large allocation. | |
| * The block is allocated just after of the allocation. | |
| */ | |
| - NXT_MEM_CACHE_EMBEDDED_BLOCK, | |
| -} nxt_mem_cache_block_type_t; | |
| + NXT_MP_EMBEDDED_BLOCK, | |
| +} nxt_mp_block_type_t; | |
| typedef struct { | |
| NXT_RBTREE_NODE (node); | |
| - nxt_mem_cache_block_type_t type:8; | |
| + nxt_mp_block_type_t type:8; | |
| /* Block size must be less than 4G. */ | |
| uint32_t size; | |
| u_char *start; | |
| - nxt_mem_cache_page_t pages[]; | |
| -} nxt_mem_cache_block_t; | |
| + nxt_mp_page_t pages[]; | |
| +} nxt_mp_block_t; | |
| typedef struct { | |
| @@ -100,11 +100,11 @@ typedef struct { | |
| /* Maximum number of free chunks in chunked page. */ | |
| uint8_t chunks; | |
| -} nxt_mem_cache_slot_t; | |
| +} nxt_mp_slot_t; | |
| -struct nxt_mem_cache_pool_s { | |
| - /* rbtree of nxt_mem_cache_block_t. */ | |
| +struct nxt_mp_s { | |
| + /* rbtree of nxt_mp_block_t. */ | |
| nxt_rbtree_t blocks; | |
| nxt_queue_t free_pages; | |
| @@ -119,19 +119,19 @@ struct nxt_mem_cache_pool_s { | |
| void *mem; | |
| void *trace; | |
| - nxt_mem_cache_slot_t slots[]; | |
| + nxt_mp_slot_t slots[]; | |
| }; | |
| -#define nxt_mem_cache_chunk_is_free(map, chunk) \ | |
| +#define nxt_mp_chunk_is_free(map, chunk) \ | |
| ((map[chunk / 8] & (0x80 >> (chunk & 7))) == 0) | |
| -#define nxt_mem_cache_chunk_set_free(map, chunk) \ | |
| +#define nxt_mp_chunk_set_free(map, chunk) \ | |
| map[chunk / 8] &= ~(0x80 >> (chunk & 7)) | |
| -#define nxt_mem_cache_free_junk(p, size) \ | |
| +#define nxt_mp_free_junk(p, size) \ | |
| nxt_memset((p), 0x5A, size) | |
| @@ -139,27 +139,24 @@ struct nxt_mem_cache_pool_s { | |
| ((((value) - 1) & (value)) == 0) | |
| -static nxt_uint_t nxt_mem_cache_shift(nxt_uint_t n); | |
| +static nxt_uint_t nxt_mp_shift(nxt_uint_t n); | |
| #if !(NXT_DEBUG_MEMORY) | |
| -static void *nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size); | |
| -static nxt_uint_t nxt_mem_cache_alloc_chunk(u_char *map, nxt_uint_t size); | |
| -static nxt_mem_cache_page_t * | |
| - nxt_mem_cache_alloc_page(nxt_mem_cache_pool_t *pool); | |
| -static nxt_mem_cache_block_t * | |
| - nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool); | |
| +static void *nxt_mp_alloc_small(nxt_mp_t *mp, size_t size); | |
| +static nxt_uint_t nxt_mp_alloc_chunk(u_char *map, nxt_uint_t size); | |
| +static nxt_mp_page_t *nxt_mp_alloc_page(nxt_mp_t *mp); | |
| +static nxt_mp_block_t *nxt_mp_alloc_cluster(nxt_mp_t *mp); | |
| #endif | |
| -static void *nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool, | |
| - size_t alignment, size_t size); | |
| -static intptr_t nxt_mem_cache_rbtree_compare(nxt_rbtree_node_t *node1, | |
| +static void *nxt_mp_alloc_large(nxt_mp_t *mp, size_t alignment, size_t size); | |
| +static intptr_t nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1, | |
| nxt_rbtree_node_t *node2); | |
| -static nxt_mem_cache_block_t *nxt_mem_cache_find_block(nxt_rbtree_t *tree, | |
| +static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, | |
| u_char *p); | |
| -static const char *nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, | |
| - nxt_mem_cache_block_t *cluster, u_char *p); | |
| +static const char *nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster, | |
| + u_char *p); | |
| -nxt_mem_cache_pool_t * | |
| -nxt_mem_cache_pool_create(const nxt_mem_proto_t *proto, void *mem, | |
| +nxt_mp_t * | |
| +nxt_mp_create(const nxt_mem_proto_t *proto, void *mem, | |
| void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, | |
| size_t min_chunk_size) | |
| { | |
| @@ -185,20 +182,19 @@ nxt_mem_cache_pool_create(const nxt_mem_ | |
| return NULL; | |
| } | |
| - return nxt_mem_cache_pool_fast_create(proto, mem, trace, | |
| - cluster_size, page_alignment, | |
| - page_size, min_chunk_size); | |
| + return nxt_mp_fast_create(proto, mem, trace, cluster_size, page_alignment, | |
| + page_size, min_chunk_size); | |
| } | |
| -nxt_mem_cache_pool_t * | |
| -nxt_mem_cache_pool_fast_create(const nxt_mem_proto_t *proto, void *mem, | |
| +nxt_mp_t * | |
| +nxt_mp_fast_create(const nxt_mem_proto_t *proto, void *mem, | |
| void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, | |
| size_t min_chunk_size) | |
| { | |
| - nxt_uint_t slots, chunk_size; | |
| - nxt_mem_cache_slot_t *slot; | |
| - nxt_mem_cache_pool_t *pool; | |
| + nxt_mp_t *mp; | |
| + nxt_uint_t slots, chunk_size; | |
| + nxt_mp_slot_t *slot; | |
| slots = 0; | |
| chunk_size = page_size; | |
| @@ -208,19 +204,18 @@ nxt_mem_cache_pool_fast_create(const nxt | |
| chunk_size /= 2; | |
| } while (chunk_size > min_chunk_size); | |
| - pool = proto->zalloc(mem, sizeof(nxt_mem_cache_pool_t) | |
| - + slots * sizeof(nxt_mem_cache_slot_t)); | |
| + mp = proto->zalloc(mem, sizeof(nxt_mp_t) + slots * sizeof(nxt_mp_slot_t)); | |
| - if (nxt_fast_path(pool != NULL)) { | |
| - pool->proto = proto; | |
| - pool->mem = mem; | |
| - pool->trace = trace; | |
| + if (nxt_fast_path(mp != NULL)) { | |
| + mp->proto = proto; | |
| + mp->mem = mem; | |
| + mp->trace = trace; | |
| - pool->page_size = page_size; | |
| - pool->page_alignment = nxt_max(page_alignment, NXT_MAX_ALIGNMENT); | |
| - pool->cluster_size = cluster_size; | |
| + mp->page_size = page_size; | |
| + mp->page_alignment = nxt_max(page_alignment, NXT_MAX_ALIGNMENT); | |
| + mp->cluster_size = cluster_size; | |
| - slot = pool->slots; | |
| + slot = mp->slots; | |
| do { | |
| nxt_queue_init(&slot->pages); | |
| @@ -233,20 +228,20 @@ nxt_mem_cache_pool_fast_create(const nxt | |
| chunk_size *= 2; | |
| } while (chunk_size < page_size); | |
| - pool->chunk_size_shift = nxt_mem_cache_shift(min_chunk_size); | |
| - pool->page_size_shift = nxt_mem_cache_shift(page_size); | |
| + mp->chunk_size_shift = nxt_mp_shift(min_chunk_size); | |
| + mp->page_size_shift = nxt_mp_shift(page_size); | |
| - nxt_rbtree_init(&pool->blocks, nxt_mem_cache_rbtree_compare); | |
| + nxt_rbtree_init(&mp->blocks, nxt_mp_rbtree_compare); | |
| - nxt_queue_init(&pool->free_pages); | |
| + nxt_queue_init(&mp->free_pages); | |
| } | |
| - return pool; | |
| + return mp; | |
| } | |
| static nxt_uint_t | |
| -nxt_mem_cache_shift(nxt_uint_t n) | |
| +nxt_mp_shift(nxt_uint_t n) | |
| { | |
| nxt_uint_t shift; | |
| @@ -263,65 +258,65 @@ nxt_mem_cache_shift(nxt_uint_t n) | |
| nxt_bool_t | |
| -nxt_mem_cache_pool_is_empty(nxt_mem_cache_pool_t *pool) | |
| +nxt_mp_is_empty(nxt_mp_t *mp) | |
| { | |
| - return (nxt_rbtree_is_empty(&pool->blocks) | |
| - && nxt_queue_is_empty(&pool->free_pages)); | |
| + return (nxt_rbtree_is_empty(&mp->blocks) | |
| + && nxt_queue_is_empty(&mp->free_pages)); | |
| } | |
| void | |
| -nxt_mem_cache_pool_destroy(nxt_mem_cache_pool_t *pool) | |
| +nxt_mp_destroy(nxt_mp_t *mp) | |
| { | |
| - void *p; | |
| - nxt_rbtree_node_t *node, *next; | |
| - nxt_mem_cache_block_t *block; | |
| + void *p; | |
| + nxt_mp_block_t *block; | |
| + nxt_rbtree_node_t *node, *next; | |
| - next = nxt_rbtree_root(&pool->blocks); | |
| + next = nxt_rbtree_root(&mp->blocks); | |
| - while (next != nxt_rbtree_sentinel(&pool->blocks)) { | |
| + while (next != nxt_rbtree_sentinel(&mp->blocks)) { | |
| - node = nxt_rbtree_destroy_next(&pool->blocks, &next); | |
| - block = (nxt_mem_cache_block_t *) node; | |
| + node = nxt_rbtree_destroy_next(&mp->blocks, &next); | |
| + block = (nxt_mp_block_t *) node; | |
| p = block->start; | |
| - if (block->type != NXT_MEM_CACHE_EMBEDDED_BLOCK) { | |
| - pool->proto->free(pool->mem, block); | |
| + if (block->type != NXT_MP_EMBEDDED_BLOCK) { | |
| + mp->proto->free(mp->mem, block); | |
| } | |
| - pool->proto->free(pool->mem, p); | |
| + mp->proto->free(mp->mem, p); | |
| } | |
| - pool->proto->free(pool->mem, pool); | |
| + mp->proto->free(mp->mem, mp); | |
| } | |
| void * | |
| -nxt_mem_cache_alloc(nxt_mem_cache_pool_t *pool, size_t size) | |
| +nxt_mp_alloc(nxt_mp_t *mp, size_t size) | |
| { | |
| - if (pool->proto->trace != NULL) { | |
| - pool->proto->trace(pool->trace, "mem cache alloc: %zd", size); | |
| + if (mp->proto->trace != NULL) { | |
| + mp->proto->trace(mp->trace, "mem cache alloc: %zd", size); | |
| } | |
| #if !(NXT_DEBUG_MEMORY) | |
| - if (size <= pool->page_size) { | |
| - return nxt_mem_cache_alloc_small(pool, size); | |
| + if (size <= mp->page_size) { | |
| + return nxt_mp_alloc_small(mp, size); | |
| } | |
| #endif | |
| - return nxt_mem_cache_alloc_large(pool, NXT_MAX_ALIGNMENT, size); | |
| + return nxt_mp_alloc_large(mp, NXT_MAX_ALIGNMENT, size); | |
| } | |
| void * | |
| -nxt_mem_cache_zalloc(nxt_mem_cache_pool_t *pool, size_t size) | |
| +nxt_mp_zalloc(nxt_mp_t *mp, size_t size) | |
| { | |
| void *p; | |
| - p = nxt_mem_cache_alloc(pool, size); | |
| + p = nxt_mp_alloc(mp, size); | |
| if (nxt_fast_path(p != NULL)) { | |
| nxt_memzero(p, size); | |
| @@ -332,11 +327,11 @@ nxt_mem_cache_zalloc(nxt_mem_cache_pool_ | |
| void * | |
| -nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size) | |
| +nxt_mp_align(nxt_mp_t *mp, size_t alignment, size_t size) | |
| { | |
| - if (pool->proto->trace != NULL) { | |
| - pool->proto->trace(pool->trace, | |
| - "mem cache align: @%zd:%zd", alignment, size); | |
| + if (mp->proto->trace != NULL) { | |
| + mp->proto->trace(mp->trace, | |
| + "mem cache align: @%zd:%zd", alignment, size); | |
| } | |
| /* Alignment must be a power of 2. */ | |
| @@ -345,17 +340,17 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t | |
| #if !(NXT_DEBUG_MEMORY) | |
| - if (size <= pool->page_size && alignment <= pool->page_alignment) { | |
| + if (size <= mp->page_size && alignment <= mp->page_alignment) { | |
| size = nxt_max(size, alignment); | |
| - if (size <= pool->page_size) { | |
| - return nxt_mem_cache_alloc_small(pool, size); | |
| + if (size <= mp->page_size) { | |
| + return nxt_mp_alloc_small(mp, size); | |
| } | |
| } | |
| #endif | |
| - return nxt_mem_cache_alloc_large(pool, alignment, size); | |
| + return nxt_mp_alloc_large(mp, alignment, size); | |
| } | |
| return NULL; | |
| @@ -363,11 +358,11 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t | |
| void * | |
| -nxt_mem_cache_zalign(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size) | |
| +nxt_mp_zalign(nxt_mp_t *mp, size_t alignment, size_t size) | |
| { | |
| void *p; | |
| - p = nxt_mem_cache_align(pool, alignment, size); | |
| + p = nxt_mp_align(mp, alignment, size); | |
| if (nxt_fast_path(p != NULL)) { | |
| nxt_memzero(p, size); | |
| @@ -380,55 +375,55 @@ nxt_mem_cache_zalign(nxt_mem_cache_pool_ | |
| #if !(NXT_DEBUG_MEMORY) | |
| nxt_inline u_char * | |
| -nxt_mem_cache_page_addr(nxt_mem_cache_pool_t *pool, nxt_mem_cache_page_t *page) | |
| +nxt_mp_page_addr(nxt_mp_t *mp, nxt_mp_page_t *page) | |
| { | |
| - nxt_mem_cache_block_t *block; | |
| + nxt_mp_block_t *block; | |
| - block = (nxt_mem_cache_block_t *) | |
| - ((u_char *) page - page->number * sizeof(nxt_mem_cache_page_t) | |
| - - offsetof(nxt_mem_cache_block_t, pages)); | |
| + block = (nxt_mp_block_t *) | |
| + ((u_char *) page - page->number * sizeof(nxt_mp_page_t) | |
| + - offsetof(nxt_mp_block_t, pages)); | |
| - return block->start + (page->number << pool->page_size_shift); | |
| + return block->start + (page->number << mp->page_size_shift); | |
| } | |
| static void * | |
| -nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size) | |
| +nxt_mp_alloc_small(nxt_mp_t *mp, size_t size) | |
| { | |
| - u_char *p; | |
| - nxt_queue_link_t *link; | |
| - nxt_mem_cache_page_t *page; | |
| - nxt_mem_cache_slot_t *slot; | |
| + u_char *p; | |
| + nxt_mp_page_t *page; | |
| + nxt_mp_slot_t *slot; | |
| + nxt_queue_link_t *link; | |
| p = NULL; | |
| - if (size <= pool->page_size / 2) { | |
| + if (size <= mp->page_size / 2) { | |
| /* Find a slot with appropriate chunk size. */ | |
| - for (slot = pool->slots; slot->size < size; slot++) { /* void */ } | |
| + for (slot = mp->slots; slot->size < size; slot++) { /* void */ } | |
| size = slot->size; | |
| if (nxt_fast_path(!nxt_queue_is_empty(&slot->pages))) { | |
| link = nxt_queue_first(&slot->pages); | |
| - page = nxt_queue_link_data(link, nxt_mem_cache_page_t, link); | |
| + page = nxt_queue_link_data(link, nxt_mp_page_t, link); | |
| - p = nxt_mem_cache_page_addr(pool, page); | |
| - p += nxt_mem_cache_alloc_chunk(page->map, size); | |
| + p = nxt_mp_page_addr(mp, page); | |
| + p += nxt_mp_alloc_chunk(page->map, size); | |
| page->chunks--; | |
| if (page->chunks == 0) { | |
| /* | |
| - * Remove full page from the pool chunk slot list | |
| + * Remove full page from the mp chunk slot list | |
| * of pages with free chunks. | |
| */ | |
| nxt_queue_remove(&page->link); | |
| } | |
| } else { | |
| - page = nxt_mem_cache_alloc_page(pool); | |
| + page = nxt_mp_alloc_page(mp); | |
| if (nxt_fast_path(page != NULL)) { | |
| @@ -442,28 +437,28 @@ nxt_mem_cache_alloc_small(nxt_mem_cache_ | |
| /* slot->chunks are already one less. */ | |
| page->chunks = slot->chunks; | |
| - page->size = size >> pool->chunk_size_shift; | |
| + page->size = size >> mp->chunk_size_shift; | |
| - p = nxt_mem_cache_page_addr(pool, page); | |
| + p = nxt_mp_page_addr(mp, page); | |
| } | |
| } | |
| } else { | |
| - page = nxt_mem_cache_alloc_page(pool); | |
| + page = nxt_mp_alloc_page(mp); | |
| if (nxt_fast_path(page != NULL)) { | |
| - page->size = pool->page_size >> pool->chunk_size_shift; | |
| + page->size = mp->page_size >> mp->chunk_size_shift; | |
| - p = nxt_mem_cache_page_addr(pool, page); | |
| + p = nxt_mp_page_addr(mp, page); | |
| } | |
| #if (NXT_DEBUG) | |
| - size = pool->page_size; | |
| + size = mp->page_size; | |
| #endif | |
| } | |
| - if (pool->proto->trace != NULL) { | |
| - pool->proto->trace(pool->trace, "mem cache chunk:%uz alloc: %p", | |
| + if (mp->proto->trace != NULL) { | |
| + mp->proto->trace(mp->trace, "mem cache chunk:%uz alloc: %p", | |
| size, p); | |
| } | |
| @@ -472,7 +467,7 @@ nxt_mem_cache_alloc_small(nxt_mem_cache_ | |
| static nxt_uint_t | |
| -nxt_mem_cache_alloc_chunk(uint8_t *map, nxt_uint_t size) | |
| +nxt_mp_alloc_chunk(uint8_t *map, nxt_uint_t size) | |
| { | |
| uint8_t mask; | |
| nxt_uint_t n, offset; | |
| @@ -509,58 +504,59 @@ nxt_mem_cache_alloc_chunk(uint8_t *map, | |
| } | |
| -static nxt_mem_cache_page_t * | |
| -nxt_mem_cache_alloc_page(nxt_mem_cache_pool_t *pool) | |
| +static nxt_mp_page_t * | |
| +nxt_mp_alloc_page(nxt_mp_t *mp) | |
| { | |
| - nxt_queue_link_t *link; | |
| - nxt_mem_cache_page_t *page; | |
| - nxt_mem_cache_block_t *cluster; | |
| + nxt_mp_page_t *page; | |
| + nxt_mp_block_t *cluster; | |
| + nxt_queue_link_t *link; | |
| - if (nxt_queue_is_empty(&pool->free_pages)) { | |
| - cluster = nxt_mem_cache_alloc_cluster(pool); | |
| + if (nxt_queue_is_empty(&mp->free_pages)) { | |
| + cluster = nxt_mp_alloc_cluster(mp); | |
| if (nxt_slow_path(cluster == NULL)) { | |
| return NULL; | |
| } | |
| } | |
| - link = nxt_queue_first(&pool->free_pages); | |
| + link = nxt_queue_first(&mp->free_pages); | |
| nxt_queue_remove(link); | |
| - page = nxt_queue_link_data(link, nxt_mem_cache_page_t, link); | |
| + page = nxt_queue_link_data(link, nxt_mp_page_t, link); | |
| return page; | |
| } | |
| -static nxt_mem_cache_block_t * | |
| -nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool) | |
| +static nxt_mp_block_t * | |
| +nxt_mp_alloc_cluster(nxt_mp_t *mp) | |
| { | |
| - nxt_uint_t n; | |
| - nxt_mem_cache_block_t *cluster; | |
| + nxt_uint_t n; | |
| + nxt_mp_block_t *cluster; | |
| - n = pool->cluster_size >> pool->page_size_shift; | |
| + n = mp->cluster_size >> mp->page_size_shift; | |
| - cluster = pool->proto->zalloc(pool->mem, sizeof(nxt_mem_cache_block_t) | |
| - + n * sizeof(nxt_mem_cache_page_t)); | |
| + cluster = mp->proto->zalloc(mp->mem, | |
| + sizeof(nxt_mp_block_t) | |
| + + n * sizeof(nxt_mp_page_t)); | |
| if (nxt_slow_path(cluster == NULL)) { | |
| return NULL; | |
| } | |
| - /* NXT_MEM_CACHE_CLUSTER_BLOCK type is zero. */ | |
| + /* NXT_MP_CLUSTER_BLOCK type is zero. */ | |
| - cluster->size = pool->cluster_size; | |
| + cluster->size = mp->cluster_size; | |
| - cluster->start = pool->proto->align(pool->mem, pool->page_alignment, | |
| - pool->cluster_size); | |
| + cluster->start = mp->proto->align(mp->mem, mp->page_alignment, | |
| + mp->cluster_size); | |
| if (nxt_slow_path(cluster->start == NULL)) { | |
| - pool->proto->free(pool->mem, cluster); | |
| + mp->proto->free(mp->mem, cluster); | |
| return NULL; | |
| } | |
| n--; | |
| cluster->pages[n].number = n; | |
| - nxt_queue_insert_head(&pool->free_pages, &cluster->pages[n].link); | |
| + nxt_queue_insert_head(&mp->free_pages, &cluster->pages[n].link); | |
| while (n != 0) { | |
| n--; | |
| @@ -569,7 +565,7 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cach | |
| &cluster->pages[n].link); | |
| } | |
| - nxt_rbtree_insert(&pool->blocks, &cluster->node); | |
| + nxt_rbtree_insert(&mp->blocks, &cluster->node); | |
| return cluster; | |
| } | |
| @@ -578,13 +574,12 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cach | |
| static void * | |
| -nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool, size_t alignment, | |
| - size_t size) | |
| +nxt_mp_alloc_large(nxt_mp_t *mp, size_t alignment, size_t size) | |
| { | |
| - u_char *p; | |
| - size_t aligned_size; | |
| - uint8_t type; | |
| - nxt_mem_cache_block_t *block; | |
| + u_char *p; | |
| + size_t aligned_size; | |
| + uint8_t type; | |
| + nxt_mp_block_t *block; | |
| /* Allocation must be less than 4G. */ | |
| if (nxt_slow_path(size >= UINT32_MAX)) { | |
| @@ -592,84 +587,84 @@ nxt_mem_cache_alloc_large(nxt_mem_cache_ | |
| } | |
| if (nxt_is_power_of_two(size)) { | |
| - block = pool->proto->alloc(pool->mem, sizeof(nxt_mem_cache_block_t)); | |
| + block = mp->proto->alloc(mp->mem, sizeof(nxt_mp_block_t)); | |
| if (nxt_slow_path(block == NULL)) { | |
| return NULL; | |
| } | |
| - p = pool->proto->align(pool->mem, alignment, size); | |
| + p = mp->proto->align(mp->mem, alignment, size); | |
| if (nxt_slow_path(p == NULL)) { | |
| - pool->proto->free(pool->mem, block); | |
| + mp->proto->free(mp->mem, block); | |
| return NULL; | |
| } | |
| - type = NXT_MEM_CACHE_DISCRETE_BLOCK; | |
| + type = NXT_MP_DISCRETE_BLOCK; | |
| } else { | |
| aligned_size = nxt_align_size(size, sizeof(uintptr_t)); | |
| - p = pool->proto->align(pool->mem, alignment, | |
| - aligned_size + sizeof(nxt_mem_cache_block_t)); | |
| + p = mp->proto->align(mp->mem, alignment, | |
| + aligned_size + sizeof(nxt_mp_block_t)); | |
| if (nxt_slow_path(p == NULL)) { | |
| return NULL; | |
| } | |
| - block = (nxt_mem_cache_block_t *) (p + aligned_size); | |
| - type = NXT_MEM_CACHE_EMBEDDED_BLOCK; | |
| + block = (nxt_mp_block_t *) (p + aligned_size); | |
| + type = NXT_MP_EMBEDDED_BLOCK; | |
| } | |
| block->type = type; | |
| block->size = size; | |
| block->start = p; | |
| - nxt_rbtree_insert(&pool->blocks, &block->node); | |
| + nxt_rbtree_insert(&mp->blocks, &block->node); | |
| return p; | |
| } | |
| static intptr_t | |
| -nxt_mem_cache_rbtree_compare(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2) | |
| +nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2) | |
| { | |
| - nxt_mem_cache_block_t *block1, *block2; | |
| + nxt_mp_block_t *block1, *block2; | |
| - block1 = (nxt_mem_cache_block_t *) node1; | |
| - block2 = (nxt_mem_cache_block_t *) node2; | |
| + block1 = (nxt_mp_block_t *) node1; | |
| + block2 = (nxt_mp_block_t *) node2; | |
| return (uintptr_t) block1->start - (uintptr_t) block2->start; | |
| } | |
| void | |
| -nxt_mem_cache_free(nxt_mem_cache_pool_t *pool, void *p) | |
| +nxt_mp_free(nxt_mp_t *mp, void *p) | |
| { | |
| - const char *err; | |
| - nxt_mem_cache_block_t *block; | |
| + const char *err; | |
| + nxt_mp_block_t *block; | |
| - if (pool->proto->trace != NULL) { | |
| - pool->proto->trace(pool->trace, "mem cache free %p", p); | |
| + if (mp->proto->trace != NULL) { | |
| + mp->proto->trace(mp->trace, "mem cache free %p", p); | |
| } | |
| - block = nxt_mem_cache_find_block(&pool->blocks, p); | |
| + block = nxt_mp_find_block(&mp->blocks, p); | |
| if (nxt_fast_path(block != NULL)) { | |
| - if (block->type == NXT_MEM_CACHE_CLUSTER_BLOCK) { | |
| - err = nxt_mem_cache_chunk_free(pool, block, p); | |
| + if (block->type == NXT_MP_CLUSTER_BLOCK) { | |
| + err = nxt_mp_chunk_free(mp, block, p); | |
| if (nxt_fast_path(err == NULL)) { | |
| return; | |
| } | |
| } else if (nxt_fast_path(p == block->start)) { | |
| - nxt_rbtree_delete(&pool->blocks, &block->node); | |
| + nxt_rbtree_delete(&mp->blocks, &block->node); | |
| - if (block->type == NXT_MEM_CACHE_DISCRETE_BLOCK) { | |
| - pool->proto->free(pool->mem, block); | |
| + if (block->type == NXT_MP_DISCRETE_BLOCK) { | |
| + mp->proto->free(mp->mem, block); | |
| } | |
| - pool->proto->free(pool->mem, p); | |
| + mp->proto->free(mp->mem, p); | |
| return; | |
| @@ -678,27 +673,27 @@ nxt_mem_cache_free(nxt_mem_cache_pool_t | |
| } | |
| } else { | |
| - err = "freed pointer is out of pool: %p"; | |
| + err = "freed pointer is out of mp: %p"; | |
| } | |
| - if (pool->proto->alert != NULL) { | |
| - pool->proto->alert(pool->trace, err, p); | |
| + if (mp->proto->alert != NULL) { | |
| + mp->proto->alert(mp->trace, err, p); | |
| } | |
| } | |
| -static nxt_mem_cache_block_t * | |
| -nxt_mem_cache_find_block(nxt_rbtree_t *tree, u_char *p) | |
| +static nxt_mp_block_t * | |
| +nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p) | |
| { | |
| - nxt_rbtree_node_t *node, *sentinel; | |
| - nxt_mem_cache_block_t *block; | |
| + nxt_mp_block_t *block; | |
| + nxt_rbtree_node_t *node, *sentinel; | |
| node = nxt_rbtree_root(tree); | |
| sentinel = nxt_rbtree_sentinel(tree); | |
| while (node != sentinel) { | |
| - block = (nxt_mem_cache_block_t *) node; | |
| + block = (nxt_mp_block_t *) node; | |
| if (p < block->start) { | |
| node = node->left; | |
| @@ -716,17 +711,17 @@ nxt_mem_cache_find_block(nxt_rbtree_t *t | |
| static const char * | |
| -nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, | |
| - nxt_mem_cache_block_t *cluster, u_char *p) | |
| +nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster, | |
| + u_char *p) | |
| { | |
| - u_char *start; | |
| - uintptr_t offset; | |
| - nxt_uint_t n, size, chunk; | |
| - nxt_mem_cache_page_t *page; | |
| - nxt_mem_cache_slot_t *slot; | |
| + u_char *start; | |
| + uintptr_t offset; | |
| + nxt_uint_t n, size, chunk; | |
| + nxt_mp_page_t *page; | |
| + nxt_mp_slot_t *slot; | |
| - n = (p - cluster->start) >> pool->page_size_shift; | |
| - start = cluster->start + (n << pool->page_size_shift); | |
| + n = (p - cluster->start) >> mp->page_size_shift; | |
| + start = cluster->start + (n << mp->page_size_shift); | |
| page = &cluster->pages[n]; | |
| @@ -734,44 +729,44 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_p | |
| return "freed pointer points to already free page: %p"; | |
| } | |
| - size = page->size << pool->chunk_size_shift; | |
| + size = page->size << mp->chunk_size_shift; | |
| - if (size != pool->page_size) { | |
| + if (size != mp->page_size) { | |
| - offset = (uintptr_t) (p - start) & (pool->page_size - 1); | |
| + offset = (uintptr_t) (p - start) & (mp->page_size - 1); | |
| chunk = offset / size; | |
| if (nxt_slow_path(offset != chunk * size)) { | |
| return "freed pointer points to wrong chunk: %p"; | |
| } | |
| - if (nxt_slow_path(nxt_mem_cache_chunk_is_free(page->map, chunk))) { | |
| + if (nxt_slow_path(nxt_mp_chunk_is_free(page->map, chunk))) { | |
| return "freed pointer points to already free chunk: %p"; | |
| } | |
| - nxt_mem_cache_chunk_set_free(page->map, chunk); | |
| + nxt_mp_chunk_set_free(page->map, chunk); | |
| /* Find a slot with appropriate chunk size. */ | |
| - for (slot = pool->slots; slot->size < size; slot++) { /* void */ } | |
| + for (slot = mp->slots; slot->size < size; slot++) { /* void */ } | |
| if (page->chunks != slot->chunks) { | |
| page->chunks++; | |
| if (page->chunks == 1) { | |
| /* | |
| - * Add the page to the head of pool chunk slot list | |
| + * Add the page to the head of mp chunk slot list | |
| * of pages with free chunks. | |
| */ | |
| nxt_queue_insert_head(&slot->pages, &page->link); | |
| } | |
| - nxt_mem_cache_free_junk(p, size); | |
| + nxt_mp_free_junk(p, size); | |
| return NULL; | |
| } else { | |
| /* | |
| - * All chunks are free, remove the page from pool chunk slot | |
| + * All chunks are free, remove the page from mp chunk slot | |
| * list of pages with free chunks. | |
| */ | |
| nxt_queue_remove(&page->link); | |
| @@ -781,17 +776,17 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_p | |
| return "invalid pointer to chunk: %p"; | |
| } | |
| - /* Add the free page to the pool's free pages tree. */ | |
| + /* Add the free page to the mp's free pages tree. */ | |
| page->size = 0; | |
| - nxt_queue_insert_head(&pool->free_pages, &page->link); | |
| + nxt_queue_insert_head(&mp->free_pages, &page->link); | |
| - nxt_mem_cache_free_junk(p, size); | |
| + nxt_mp_free_junk(p, size); | |
| /* Test if all pages in the cluster are free. */ | |
| page = cluster->pages; | |
| - n = pool->cluster_size >> pool->page_size_shift; | |
| + n = mp->cluster_size >> mp->page_size_shift; | |
| do { | |
| if (page->size != 0) { | |
| @@ -805,7 +800,7 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_p | |
| /* Free cluster. */ | |
| page = cluster->pages; | |
| - n = pool->cluster_size >> pool->page_size_shift; | |
| + n = mp->cluster_size >> mp->page_size_shift; | |
| do { | |
| nxt_queue_remove(&page->link); | |
| @@ -813,12 +808,12 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_p | |
| n--; | |
| } while (n != 0); | |
| - nxt_rbtree_delete(&pool->blocks, &cluster->node); | |
| + nxt_rbtree_delete(&mp->blocks, &cluster->node); | |
| p = cluster->start; | |
| - pool->proto->free(pool->mem, cluster); | |
| - pool->proto->free(pool->mem, p); | |
| + mp->proto->free(mp->mem, cluster); | |
| + mp->proto->free(mp->mem, p); | |
| return NULL; | |
| } | |
| diff --git a/nxt/nxt_mem_cache_pool.h b/nxt/nxt_mp.h | |
| rename from nxt/nxt_mem_cache_pool.h | |
| rename to nxt/nxt_mp.h | |
| --- a/nxt/nxt_mem_cache_pool.h | |
| +++ b/nxt/nxt_mp.h | |
| @@ -4,37 +4,34 @@ | |
| * Copyright (C) NGINX, Inc. | |
| */ | |
| -#ifndef _NXT_MEM_CACHE_POOL_H_INCLUDED_ | |
| -#define _NXT_MEM_CACHE_POOL_H_INCLUDED_ | |
| +#ifndef _NXT_MP_H_INCLUDED_ | |
| +#define _NXT_MP_H_INCLUDED_ | |
| -typedef struct nxt_mem_cache_pool_s nxt_mem_cache_pool_t; | |
| +typedef struct nxt_mp_s nxt_mp_t; | |
| -NXT_EXPORT nxt_mem_cache_pool_t * | |
| - nxt_mem_cache_pool_create(const nxt_mem_proto_t *proto, void *mem, | |
| +NXT_EXPORT nxt_mp_t *nxt_mp_create(const nxt_mem_proto_t *proto, void *mem, | |
| void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, | |
| size_t min_chunk_size) | |
| NXT_MALLOC_LIKE; | |
| -NXT_EXPORT nxt_mem_cache_pool_t * | |
| - nxt_mem_cache_pool_fast_create(const nxt_mem_proto_t *proto, void *mem, | |
| - void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, | |
| - size_t min_chunk_size) | |
| +NXT_EXPORT nxt_mp_t * nxt_mp_fast_create(const nxt_mem_proto_t *proto, | |
| + void *mem, void *trace, size_t cluster_size, size_t page_alignment, | |
| + size_t page_size, size_t min_chunk_size) | |
| NXT_MALLOC_LIKE; | |
| -NXT_EXPORT nxt_bool_t nxt_mem_cache_pool_is_empty(nxt_mem_cache_pool_t *pool); | |
| -NXT_EXPORT void nxt_mem_cache_pool_destroy(nxt_mem_cache_pool_t *pool); | |
| +NXT_EXPORT nxt_bool_t nxt_mp_is_empty(nxt_mp_t *mp); | |
| +NXT_EXPORT void nxt_mp_destroy(nxt_mp_t *mp); | |
| -NXT_EXPORT void *nxt_mem_cache_alloc(nxt_mem_cache_pool_t *pool, size_t size) | |
| +NXT_EXPORT void *nxt_mp_alloc(nxt_mp_t *mp, size_t size) | |
| NXT_MALLOC_LIKE; | |
| -NXT_EXPORT void *nxt_mem_cache_zalloc(nxt_mem_cache_pool_t *pool, size_t size) | |
| +NXT_EXPORT void *nxt_mp_zalloc(nxt_mp_t *mp, size_t size) | |
| NXT_MALLOC_LIKE; | |
| -NXT_EXPORT void *nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, | |
| +NXT_EXPORT void *nxt_mp_align(nxt_mp_t *mp, size_t alignment, size_t size) | |
| + NXT_MALLOC_LIKE; | |
| +NXT_EXPORT void *nxt_mp_zalign(nxt_mp_t *mp, | |
| size_t alignment, size_t size) | |
| NXT_MALLOC_LIKE; | |
| -NXT_EXPORT void *nxt_mem_cache_zalign(nxt_mem_cache_pool_t *pool, | |
| - size_t alignment, size_t size) | |
| - NXT_MALLOC_LIKE; | |
| -NXT_EXPORT void nxt_mem_cache_free(nxt_mem_cache_pool_t *pool, void *p); | |
| +NXT_EXPORT void nxt_mp_free(nxt_mp_t *mp, void *p); | |
| -#endif /* _NXT_MEM_CACHE_POOL_H_INCLUDED_ */ | |
| +#endif /* _NXT_MP_H_INCLUDED_ */ | |
| diff --git a/nxt/test/Makefile b/nxt/test/Makefile | |
| --- a/nxt/test/Makefile | |
| +++ b/nxt/test/Makefile | |
| @@ -34,7 +34,7 @@ lib_test: \ | |
| $(NXT_BUILDDIR)/lvlhsh_unit_test: \ | |
| $(NXT_BUILDDIR)/nxt_lvlhsh.o \ | |
| $(NXT_BUILDDIR)/nxt_murmur_hash.o \ | |
| - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ | |
| + $(NXT_BUILDDIR)/nxt_mp.o \ | |
| $(NXT_BUILDDIR)/nxt_malloc.o \ | |
| $(NXT_LIB)/test/lvlhsh_unit_test.c \ | |
| @@ -44,7 +44,7 @@ lib_test: \ | |
| $(NXT_BUILDDIR)/nxt_lvlhsh.o \ | |
| $(NXT_BUILDDIR)/nxt_rbtree.o \ | |
| $(NXT_BUILDDIR)/nxt_murmur_hash.o \ | |
| - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ | |
| + $(NXT_BUILDDIR)/nxt_mp.o \ | |
| $(NXT_BUILDDIR)/nxt_malloc.o | |
| $(NXT_BUILDDIR)/random_unit_test: \ | |
| diff --git a/nxt/test/lvlhsh_unit_test.c b/nxt/test/lvlhsh_unit_test.c | |
| --- a/nxt/test/lvlhsh_unit_test.c | |
| +++ b/nxt/test/lvlhsh_unit_test.c | |
| @@ -12,7 +12,7 @@ | |
| #include <nxt_malloc.h> | |
| #include <nxt_lvlhsh.h> | |
| #include <nxt_murmur_hash.h> | |
| -#include <nxt_mem_cache_pool.h> | |
| +#include <nxt_mp.h> | |
| #include <stdio.h> | |
| #include <stdarg.h> | |
| #include <string.h> | |
| @@ -32,14 +32,14 @@ lvlhsh_unit_test_key_test(nxt_lvlhsh_que | |
| static void * | |
| lvlhsh_unit_test_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc) | |
| { | |
| - return nxt_mem_cache_align(pool, size, size); | |
| + return nxt_mp_align(pool, size, size); | |
| } | |
| static void | |
| lvlhsh_unit_test_pool_free(void *pool, void *p, size_t size) | |
| { | |
| - nxt_mem_cache_free(pool, p); | |
| + nxt_mp_free(pool, p); | |
| } | |
| @@ -182,7 +182,7 @@ lvlhsh_alert(void *mem, const char *fmt, | |
| } | |
| -static const nxt_mem_proto_t mem_cache_pool_proto = { | |
| +static const nxt_mem_proto_t lvl_mp_proto = { | |
| lvlhsh_malloc, | |
| lvlhsh_zalloc, | |
| lvlhsh_align, | |
| @@ -196,20 +196,19 @@ static const nxt_mem_proto_t mem_cache_ | |
| static nxt_int_t | |
| lvlhsh_unit_test(nxt_uint_t n) | |
| { | |
| - uint32_t key; | |
| - nxt_uint_t i; | |
| - nxt_lvlhsh_t lh; | |
| - nxt_lvlhsh_each_t lhe; | |
| - nxt_mem_cache_pool_t *pool; | |
| + nxt_mp_t *pool; | |
| + uint32_t key; | |
| + nxt_uint_t i; | |
| + nxt_lvlhsh_t lh; | |
| + nxt_lvlhsh_each_t lhe; | |
| - const size_t min_chunk_size = 32; | |
| - const size_t page_size = 1024; | |
| - const size_t page_alignment = 128; | |
| - const size_t cluster_size = 4096; | |
| + const size_t min_chunk_size = 32; | |
| + const size_t page_size = 1024; | |
| + const size_t page_alignment = 128; | |
| + const size_t cluster_size = 4096; | |
| - pool = nxt_mem_cache_pool_create(&mem_cache_pool_proto, NULL, NULL, | |
| - cluster_size, page_alignment, | |
| - page_size, min_chunk_size); | |
| + pool = nxt_mp_create(&lvl_mp_proto, NULL, NULL, cluster_size, | |
| + page_alignment, page_size, min_chunk_size); | |
| if (pool == NULL) { | |
| return NXT_ERROR; | |
| } | |
| @@ -260,12 +259,12 @@ lvlhsh_unit_test(nxt_uint_t n) | |
| } | |
| } | |
| - if (!nxt_mem_cache_pool_is_empty(pool)) { | |
| + if (!nxt_mp_is_empty(pool)) { | |
| printf("mem cache pool is not empty\n"); | |
| return NXT_ERROR; | |
| } | |
| - nxt_mem_cache_pool_destroy(pool); | |
| + nxt_mp_destroy(pool); | |
| printf("lvlhsh unit test passed\n"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment