xref: /aosp_15_r20/art/runtime/gc/allocator/art-dlmalloc.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "art-dlmalloc.h"
18 
19 #include <android-base/logging.h>
20 
21 #include "base/bit_utils.h"
22 #include "gc/space/dlmalloc_space.h"
23 
24 // ART specific morecore implementation defined in space.cc.
25 static void* art_heap_morecore(void* m, intptr_t increment);
26 #define MORECORE(x) art_heap_morecore(m, x)
27 
28 // Custom heap error handling.
29 #define PROCEED_ON_ERROR 0
30 static void art_heap_corruption(const char* function);
31 static void art_heap_usage_error(const char* function, void* p);
32 #define CORRUPTION_ERROR_ACTION(m) art_heap_corruption(__FUNCTION__)
33 #define USAGE_ERROR_ACTION(m, p) art_heap_usage_error(__FUNCTION__, p)
34 
35 // Ugly inclusion of C file so that ART specific #defines configure dlmalloc for our use for
36 // mspaces (regular dlmalloc is still declared in bionic).
37 #pragma GCC diagnostic push
38 #pragma GCC diagnostic ignored "-Wredundant-decls"
39 #pragma GCC diagnostic ignored "-Wempty-body"
40 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
41 #pragma GCC diagnostic ignored "-Wnull-pointer-arithmetic"
42 #pragma GCC diagnostic ignored "-Wexpansion-to-defined"
43 #include "dlmalloc.c"  // NOLINT
44 // Note: dlmalloc.c uses a DEBUG define to drive debug code. This interferes with the DEBUG severity
45 //       of libbase, so undefine it now.
46 #undef DEBUG
47 #pragma GCC diagnostic pop
48 
art_heap_morecore(void * m,intptr_t increment)49 static void* art_heap_morecore(void* m, intptr_t increment) {
50   return ::art::gc::allocator::ArtDlMallocMoreCore(m, increment);
51 }
52 
art_heap_corruption(const char * function)53 static void art_heap_corruption(const char* function) {
54   LOG(FATAL) << "Corrupt heap detected in: " << function;
55 }
56 
art_heap_usage_error(const char * function,void * p)57 static void art_heap_usage_error(const char* function, void* p) {
58   LOG(FATAL) << "Incorrect use of function '" << function << "' argument " << p
59       << " not expected";
60 }
61