Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/operator_new.cpp
40949 views
1
/*
2
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "utilities/debug.hpp"
27
28
#include <new>
29
30
//--------------------------------------------------------------------------------------
31
// Non-product code
32
33
#ifndef PRODUCT
34
// The global operator new should never be called since it will usually indicate
35
// a memory leak. Use CHeapObj as the base class of such objects to make it explicit
36
// that they're allocated on the C heap.
37
// Commented out in product version to avoid conflicts with third-party C++ native code.
38
//
39
// In C++98/03 the throwing new operators are defined with the following signature:
40
//
41
// void* operator new(std::size_tsize) throw(std::bad_alloc);
42
// void* operator new[](std::size_tsize) throw(std::bad_alloc);
43
//
44
// while all the other (non-throwing) new and delete operators are defined with an empty
45
// throw clause (i.e. "operator delete(void* p) throw()") which means that they do not
46
// throw any exceptions (see section 18.4 of the C++ standard).
47
//
48
// In the new C++11/14 standard, the signature of the throwing new operators was changed
49
// by completely omitting the throw clause (which effectively means they could throw any
50
// exception) while all the other new/delete operators where changed to have a 'nothrow'
51
// clause instead of an empty throw clause.
52
//
53
// Unfortunately, the support for exception specifications among C++ compilers is still
54
// very fragile. While some more strict compilers like AIX xlC or HP aCC reject to
55
// override the default throwing new operator with a user operator with an empty throw()
56
// clause, the MS Visual C++ compiler warns for every non-empty throw clause like
57
// throw(std::bad_alloc) that it will ignore the exception specification. The following
58
// operator definitions have been checked to correctly work with all currently supported
59
// compilers and they should be upwards compatible with C++11/14. Therefore
60
// PLEASE BE CAREFUL if you change the signature of the following operators!
61
62
static void * zero = (void *) 0;
63
64
void* operator new(size_t size) /* throw(std::bad_alloc) */ {
65
fatal("Should not call global operator new");
66
return zero;
67
}
68
69
void* operator new [](size_t size) /* throw(std::bad_alloc) */ {
70
fatal("Should not call global operator new[]");
71
return zero;
72
}
73
74
void* operator new(size_t size, const std::nothrow_t& nothrow_constant) throw() {
75
fatal("Should not call global operator new");
76
return 0;
77
}
78
79
void* operator new [](size_t size, std::nothrow_t& nothrow_constant) throw() {
80
fatal("Should not call global operator new[]");
81
return 0;
82
}
83
84
void operator delete(void* p) throw() {
85
fatal("Should not call global delete");
86
}
87
88
void operator delete [](void* p) throw() {
89
fatal("Should not call global delete []");
90
}
91
92
#ifdef __GNUG__
93
// Warning disabled for gcc 5.4
94
PRAGMA_DIAG_PUSH
95
PRAGMA_DISABLE_GCC_WARNING("-Wc++14-compat")
96
#endif // __GNUG__
97
98
void operator delete(void* p, size_t size) throw() {
99
fatal("Should not call global sized delete");
100
}
101
102
void operator delete [](void* p, size_t size) throw() {
103
fatal("Should not call global sized delete []");
104
}
105
106
#ifdef __GNUG__
107
PRAGMA_DIAG_POP
108
#endif // __GNUG__
109
110
#endif // Non-product
111
112