annotate libitm/alloc_cpp.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1 /* Copyright (C) 2009-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2 Contributed by Richard Henderson <rth@redhat.com>.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of the GNU Transactional Memory Library (libitm).
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 Libitm is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3 of the License, or
kono
parents:
diff changeset
9 (at your option) any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
kono
parents:
diff changeset
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
kono
parents:
diff changeset
14 more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "libitm_i.h"
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 using namespace GTM;
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 /* Mangling the names by hand requires that we know how size_t is handled.
kono
parents:
diff changeset
30 We've gotten the letter from autoconf, now substitute it into the names.
kono
parents:
diff changeset
31 Everything below uses X as a placeholder for clarity. */
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 #define S1(x,y) x##y
kono
parents:
diff changeset
34 #define S(x,y) S1(x,y)
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 #define _ZnwX S(_Znw,MANGLE_SIZE_T)
kono
parents:
diff changeset
37 #define _ZnaX S(_Zna,MANGLE_SIZE_T)
kono
parents:
diff changeset
38 #define _ZdlPvX S(_ZdlPv,MANGLE_SIZE_T)
kono
parents:
diff changeset
39 #define _ZnwXRKSt9nothrow_t S(S(_Znw,MANGLE_SIZE_T),RKSt9nothrow_t)
kono
parents:
diff changeset
40 #define _ZnaXRKSt9nothrow_t S(S(_Zna,MANGLE_SIZE_T),RKSt9nothrow_t)
kono
parents:
diff changeset
41 #define _ZdlPvXRKSt9nothrow_t S(S(_ZdlPv,MANGLE_SIZE_T),RKSt9nothrow_t)
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 #define _ZGTtnwX S(_ZGTtnw,MANGLE_SIZE_T)
kono
parents:
diff changeset
44 #define _ZGTtnaX S(_ZGTtna,MANGLE_SIZE_T)
kono
parents:
diff changeset
45 #define _ZGTtdlPvX S(_ZGTtdlPv,MANGLE_SIZE_T)
kono
parents:
diff changeset
46 #define _ZGTtnwXRKSt9nothrow_t S(S(_ZGTtnw,MANGLE_SIZE_T),RKSt9nothrow_t)
kono
parents:
diff changeset
47 #define _ZGTtnaXRKSt9nothrow_t S(S(_ZGTtna,MANGLE_SIZE_T),RKSt9nothrow_t)
kono
parents:
diff changeset
48 #define _ZGTtdlPvXRKSt9nothrow_t S(S(_ZGTtdlPv,MANGLE_SIZE_T),RKSt9nothrow_t)
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /* Everything from libstdc++ is weak, to avoid requiring that library
kono
parents:
diff changeset
51 to be linked into plain C applications using libitm.so. */
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 extern "C" {
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 extern void *_ZnwX (size_t) __attribute__((weak));
kono
parents:
diff changeset
56 extern void _ZdlPv (void *) __attribute__((weak));
kono
parents:
diff changeset
57 extern void _ZdlPvX (void *, size_t) __attribute__((weak));
kono
parents:
diff changeset
58 extern void *_ZnaX (size_t) __attribute__((weak));
kono
parents:
diff changeset
59 extern void _ZdaPv (void *) __attribute__((weak));
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 typedef const struct nothrow_t { } *c_nothrow_p;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 extern void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) __attribute__((weak));
kono
parents:
diff changeset
64 extern void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) __attribute__((weak));
kono
parents:
diff changeset
65 extern void _ZdlPvXRKSt9nothrow_t
kono
parents:
diff changeset
66 (void *, size_t, c_nothrow_p) __attribute__((weak));
kono
parents:
diff changeset
67 extern void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) __attribute__((weak));
kono
parents:
diff changeset
68 extern void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) __attribute__((weak));
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 #if !defined (HAVE_ELF_STYLE_WEAKREF)
kono
parents:
diff changeset
71 void *_ZnwX (size_t) { return NULL; }
kono
parents:
diff changeset
72 void _ZdlPv (void *) { return; }
kono
parents:
diff changeset
73 void _ZdlPvX (void *, size_t) { return; }
kono
parents:
diff changeset
74 void *_ZnaX (size_t) { return NULL; }
kono
parents:
diff changeset
75 void _ZdaPv (void *) { return; }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) { return NULL; }
kono
parents:
diff changeset
78 void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) { return; }
kono
parents:
diff changeset
79 void _ZdlPvXRKSt9nothrow_t (void *, size_t, c_nothrow_p) { return; }
kono
parents:
diff changeset
80 void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) { return NULL; }
kono
parents:
diff changeset
81 void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) { return; }
kono
parents:
diff changeset
82 #endif /* HAVE_ELF_STYLE_WEAKREF */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 /* Wrap the delete nothrow symbols for usage with a single argument.
kono
parents:
diff changeset
85 Perhaps should have a configure type check for this, because the
kono
parents:
diff changeset
86 std::nothrow_t reference argument is unused (empty class), and most
kono
parents:
diff changeset
87 targets don't actually need that second argument. So we _could_
kono
parents:
diff changeset
88 invoke these functions as if they were a single argument free. */
kono
parents:
diff changeset
89 static void
kono
parents:
diff changeset
90 del_opnt (void *ptr)
kono
parents:
diff changeset
91 {
kono
parents:
diff changeset
92 _ZdlPvRKSt9nothrow_t (ptr, NULL);
kono
parents:
diff changeset
93 }
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 static void
kono
parents:
diff changeset
96 del_opvnt (void *ptr)
kono
parents:
diff changeset
97 {
kono
parents:
diff changeset
98 _ZdaPvRKSt9nothrow_t (ptr, NULL);
kono
parents:
diff changeset
99 }
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 static void
kono
parents:
diff changeset
102 delsz_opnt (void *ptr, size_t sz)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 _ZdlPvXRKSt9nothrow_t (ptr, sz, NULL);
kono
parents:
diff changeset
105 }
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 /* Wrap: operator new (std::size_t sz) */
kono
parents:
diff changeset
108 void *
kono
parents:
diff changeset
109 _ZGTtnwX (size_t sz)
kono
parents:
diff changeset
110 {
kono
parents:
diff changeset
111 void *r = _ZnwX (sz);
kono
parents:
diff changeset
112 if (r)
kono
parents:
diff changeset
113 gtm_thr()->record_allocation (r, _ZdlPv);
kono
parents:
diff changeset
114 return r;
kono
parents:
diff changeset
115 }
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* Wrap: operator new (std::size_t sz, const std::nothrow_t&) */
kono
parents:
diff changeset
118 void *
kono
parents:
diff changeset
119 _ZGTtnwXRKSt9nothrow_t (size_t sz, c_nothrow_p nt)
kono
parents:
diff changeset
120 {
kono
parents:
diff changeset
121 void *r = _ZnwXRKSt9nothrow_t (sz, nt);
kono
parents:
diff changeset
122 if (r)
kono
parents:
diff changeset
123 gtm_thr()->record_allocation (r, del_opnt);
kono
parents:
diff changeset
124 return r;
kono
parents:
diff changeset
125 }
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 /* Wrap: operator new[] (std::size_t sz) */
kono
parents:
diff changeset
128 void *
kono
parents:
diff changeset
129 _ZGTtnaX (size_t sz)
kono
parents:
diff changeset
130 {
kono
parents:
diff changeset
131 void *r = _ZnaX (sz);
kono
parents:
diff changeset
132 if (r)
kono
parents:
diff changeset
133 gtm_thr()->record_allocation (r, _ZdaPv);
kono
parents:
diff changeset
134 return r;
kono
parents:
diff changeset
135 }
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 /* Wrap: operator new[] (std::size_t sz, const std::nothrow_t& nothrow) */
kono
parents:
diff changeset
138 void *
kono
parents:
diff changeset
139 _ZGTtnaXRKSt9nothrow_t (size_t sz, c_nothrow_p nt)
kono
parents:
diff changeset
140 {
kono
parents:
diff changeset
141 void *r = _ZnaXRKSt9nothrow_t (sz, nt);
kono
parents:
diff changeset
142 if (r)
kono
parents:
diff changeset
143 gtm_thr()->record_allocation (r, del_opvnt);
kono
parents:
diff changeset
144 return r;
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 /* Wrap: operator delete(void* ptr) */
kono
parents:
diff changeset
148 void
kono
parents:
diff changeset
149 _ZGTtdlPv (void *ptr)
kono
parents:
diff changeset
150 {
kono
parents:
diff changeset
151 if (ptr)
kono
parents:
diff changeset
152 gtm_thr()->forget_allocation (ptr, _ZdlPv);
kono
parents:
diff changeset
153 }
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 /* Wrap: operator delete (void *ptr, const std::nothrow_t&) */
kono
parents:
diff changeset
156 void
kono
parents:
diff changeset
157 _ZGTtdlPvRKSt9nothrow_t (void *ptr, c_nothrow_p nt UNUSED)
kono
parents:
diff changeset
158 {
kono
parents:
diff changeset
159 if (ptr)
kono
parents:
diff changeset
160 gtm_thr()->forget_allocation (ptr, del_opnt);
kono
parents:
diff changeset
161 }
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 /* Wrap: operator delete[] (void *ptr) */
kono
parents:
diff changeset
164 void
kono
parents:
diff changeset
165 _ZGTtdaPv (void *ptr)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 if (ptr)
kono
parents:
diff changeset
168 gtm_thr()->forget_allocation (ptr, _ZdaPv);
kono
parents:
diff changeset
169 }
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 /* Wrap: operator delete[] (void *ptr, const std::nothrow_t&) */
kono
parents:
diff changeset
172 void
kono
parents:
diff changeset
173 _ZGTtdaPvRKSt9nothrow_t (void *ptr, c_nothrow_p nt UNUSED)
kono
parents:
diff changeset
174 {
kono
parents:
diff changeset
175 if (ptr)
kono
parents:
diff changeset
176 gtm_thr()->forget_allocation (ptr, del_opvnt);
kono
parents:
diff changeset
177 }
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 /* Wrap: operator delete(void* ptr, std::size_t sz) */
kono
parents:
diff changeset
180 void
kono
parents:
diff changeset
181 _ZGTtdlPvX (void *ptr, size_t sz)
kono
parents:
diff changeset
182 {
kono
parents:
diff changeset
183 if (ptr)
kono
parents:
diff changeset
184 gtm_thr()->forget_allocation (ptr, sz, _ZdlPvX);
kono
parents:
diff changeset
185 }
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 /* Wrap: operator delete (void *ptr, std::size_t sz, const std::nothrow_t&) */
kono
parents:
diff changeset
188 void
kono
parents:
diff changeset
189 _ZGTtdlPvXRKSt9nothrow_t (void *ptr, size_t sz, c_nothrow_p nt UNUSED)
kono
parents:
diff changeset
190 {
kono
parents:
diff changeset
191 if (ptr)
kono
parents:
diff changeset
192 gtm_thr()->forget_allocation (ptr, sz, delsz_opnt);
kono
parents:
diff changeset
193 }
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 } // extern "C"