be/src/runtime/memory/jemalloc_hook.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "jemalloc/jemalloc.h" |
19 | | |
20 | | #ifndef __THROW |
21 | | #if __cplusplus |
22 | | #define __THROW noexcept |
23 | | #else |
24 | | #define __THROW |
25 | | #endif |
26 | | #endif |
27 | | |
28 | | extern "C" { |
29 | 3.44G | void* doris_malloc(size_t size) __THROW { |
30 | 3.44G | return jemalloc(size); |
31 | 3.44G | } |
32 | | |
33 | 3.93G | void doris_free(void* p) __THROW { |
34 | 3.93G | jefree(p); |
35 | 3.93G | } |
36 | | |
37 | 10.6M | void* doris_realloc(void* p, size_t size) __THROW { |
38 | 10.6M | return jerealloc(p, size); |
39 | 10.6M | } |
40 | | |
41 | 5.51M | void* doris_calloc(size_t n, size_t size) __THROW { |
42 | 5.51M | return jecalloc(n, size); |
43 | 5.51M | } |
44 | | |
45 | 0 | void doris_cfree(void* ptr) __THROW { |
46 | 0 | jefree(ptr); |
47 | 0 | } |
48 | | |
49 | 32 | void* doris_memalign(size_t align, size_t size) __THROW { |
50 | 32 | return jealigned_alloc(align, size); |
51 | 32 | } |
52 | | |
53 | 348 | void* doris_aligned_alloc(size_t align, size_t size) __THROW { |
54 | 348 | return jealigned_alloc(align, size); |
55 | 348 | } |
56 | | |
57 | 0 | void* doris_valloc(size_t size) __THROW { |
58 | 0 | return jevalloc(size); |
59 | 0 | } |
60 | | |
61 | 0 | void* doris_pvalloc(size_t size) __THROW { |
62 | 0 | return jevalloc(size); |
63 | 0 | } |
64 | | |
65 | 2.33M | int doris_posix_memalign(void** r, size_t align, size_t size) __THROW { |
66 | 2.33M | return jeposix_memalign(r, align, size); |
67 | 2.33M | } |
68 | | |
69 | 1.43M | size_t doris_malloc_usable_size(void* ptr) __THROW { |
70 | 1.43M | return jemalloc_usable_size(ptr); |
71 | 1.43M | } |
72 | | |
73 | | #define ALIAS(doris_fn) __attribute__((alias(#doris_fn), used)) |
74 | | void* malloc(size_t size) __THROW ALIAS(doris_malloc); |
75 | | void free(void* p) __THROW ALIAS(doris_free); |
76 | | void* realloc(void* p, size_t size) __THROW ALIAS(doris_realloc); |
77 | | void* calloc(size_t n, size_t size) __THROW ALIAS(doris_calloc); |
78 | | void cfree(void* ptr) __THROW ALIAS(doris_cfree); |
79 | | void* memalign(size_t align, size_t size) __THROW ALIAS(doris_memalign); |
80 | | void* aligned_alloc(size_t align, size_t size) __THROW ALIAS(doris_aligned_alloc); |
81 | | void* valloc(size_t size) __THROW ALIAS(doris_valloc); |
82 | | void* pvalloc(size_t size) __THROW ALIAS(doris_pvalloc); |
83 | | int posix_memalign(void** r, size_t a, size_t s) __THROW ALIAS(doris_posix_memalign); |
84 | | size_t malloc_usable_size(void* ptr) __THROW ALIAS(doris_malloc_usable_size); |
85 | | } |