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