aslcache.c revision 1.1.1.2 1 /******************************************************************************
2 *
3 * Module Name: aslcache -- Local cache support for iASL
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2018, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "aslcompiler.h"
45
46 /*
47 * Local caches. The caches are fully deleted after the compilation/disassembly
48 * of each individual input file. Thus, individual allocations from the cache
49 * memory do not need to be freed or even released back into the cache.
50 *
51 * See aslallocate.c for standard heap allocations.
52 */
53
54
55 /*******************************************************************************
56 *
57 * FUNCTION: UtLocalCacheCalloc
58 *
59 * PARAMETERS: Length - Size of buffer requested
60 *
61 * RETURN: Pointer to the buffer. Aborts compiler on allocation failure
62 *
63 * DESCRIPTION: Allocate a string buffer. Bypass the local
64 * dynamic memory manager for performance reasons (This has a
65 * major impact on the speed of the compiler.)
66 *
67 ******************************************************************************/
68
69 char *
70 UtLocalCacheCalloc (
71 UINT32 Length)
72 {
73 char *Buffer;
74 ASL_CACHE_INFO *Cache;
75 UINT32 CacheSize = ASL_STRING_CACHE_SIZE;
76
77
78 if (Length > CacheSize)
79 {
80 CacheSize = Length;
81
82 if (Gbl_StringCacheList)
83 {
84 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
85
86 /* Link new cache buffer just following head of list */
87
88 Cache->Next = Gbl_StringCacheList->Next;
89 Gbl_StringCacheList->Next = Cache;
90
91 /* Leave cache management pointers alone as they pertain to head */
92
93 Gbl_StringCount++;
94 Gbl_StringSize += Length;
95
96 return (Cache->Buffer);
97 }
98 }
99
100 if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast)
101 {
102 /* Allocate a new buffer */
103
104 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
105
106 /* Link new cache buffer to head of list */
107
108 Cache->Next = Gbl_StringCacheList;
109 Gbl_StringCacheList = Cache;
110
111 /* Setup cache management pointers */
112
113 Gbl_StringCacheNext = Cache->Buffer;
114 Gbl_StringCacheLast = Gbl_StringCacheNext + CacheSize;
115 }
116
117 Gbl_StringCount++;
118 Gbl_StringSize += Length;
119
120 Buffer = Gbl_StringCacheNext;
121 Gbl_StringCacheNext += Length;
122 return (Buffer);
123 }
124
125
126 /*******************************************************************************
127 *
128 * FUNCTION: UtParseOpCacheCalloc
129 *
130 * PARAMETERS: None
131 *
132 * RETURN: New parse op. Aborts on allocation failure
133 *
134 * DESCRIPTION: Allocate a new parse op for the parse tree. Bypass the local
135 * dynamic memory manager for performance reasons (This has a
136 * major impact on the speed of the compiler.)
137 *
138 ******************************************************************************/
139
140 ACPI_PARSE_OBJECT *
141 UtParseOpCacheCalloc (
142 void)
143 {
144 ASL_CACHE_INFO *Cache;
145
146
147 if (Gbl_ParseOpCacheNext >= Gbl_ParseOpCacheLast)
148 {
149 /* Allocate a new buffer */
150
151 Cache = UtLocalCalloc (sizeof (Cache->Next) +
152 (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE));
153
154 /* Link new cache buffer to head of list */
155
156 Cache->Next = Gbl_ParseOpCacheList;
157 Gbl_ParseOpCacheList = Cache;
158
159 /* Setup cache management pointers */
160
161 Gbl_ParseOpCacheNext = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, Cache->Buffer);
162 Gbl_ParseOpCacheLast = Gbl_ParseOpCacheNext + ASL_PARSEOP_CACHE_SIZE;
163 }
164
165 Gbl_ParseOpCount++;
166 return (Gbl_ParseOpCacheNext++);
167 }
168
169
170 /*******************************************************************************
171 *
172 * FUNCTION: UtSubtableCacheCalloc - Data Table compiler
173 *
174 * PARAMETERS: None
175 *
176 * RETURN: Pointer to the buffer. Aborts on allocation failure
177 *
178 * DESCRIPTION: Allocate a subtable object buffer. Bypass the local
179 * dynamic memory manager for performance reasons (This has a
180 * major impact on the speed of the compiler.)
181 *
182 ******************************************************************************/
183
184 DT_SUBTABLE *
185 UtSubtableCacheCalloc (
186 void)
187 {
188 ASL_CACHE_INFO *Cache;
189
190
191 if (Gbl_SubtableCacheNext >= Gbl_SubtableCacheLast)
192 {
193 /* Allocate a new buffer */
194
195 Cache = UtLocalCalloc (sizeof (Cache->Next) +
196 (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE));
197
198 /* Link new cache buffer to head of list */
199
200 Cache->Next = Gbl_SubtableCacheList;
201 Gbl_SubtableCacheList = Cache;
202
203 /* Setup cache management pointers */
204
205 Gbl_SubtableCacheNext = ACPI_CAST_PTR (DT_SUBTABLE, Cache->Buffer);
206 Gbl_SubtableCacheLast = Gbl_SubtableCacheNext + ASL_SUBTABLE_CACHE_SIZE;
207 }
208
209 Gbl_SubtableCount++;
210 return (Gbl_SubtableCacheNext++);
211 }
212
213
214 /*******************************************************************************
215 *
216 * FUNCTION: UtFieldCacheCalloc - Data Table compiler
217 *
218 * PARAMETERS: None
219 *
220 * RETURN: Pointer to the buffer. Aborts on allocation failure
221 *
222 * DESCRIPTION: Allocate a field object buffer. Bypass the local
223 * dynamic memory manager for performance reasons (This has a
224 * major impact on the speed of the compiler.)
225 *
226 ******************************************************************************/
227
228 DT_FIELD *
229 UtFieldCacheCalloc (
230 void)
231 {
232 ASL_CACHE_INFO *Cache;
233
234
235 if (Gbl_FieldCacheNext >= Gbl_FieldCacheLast)
236 {
237 /* Allocate a new buffer */
238
239 Cache = UtLocalCalloc (sizeof (Cache->Next) +
240 (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE));
241
242 /* Link new cache buffer to head of list */
243
244 Cache->Next = Gbl_FieldCacheList;
245 Gbl_FieldCacheList = Cache;
246
247 /* Setup cache management pointers */
248
249 Gbl_FieldCacheNext = ACPI_CAST_PTR (DT_FIELD, Cache->Buffer);
250 Gbl_FieldCacheLast = Gbl_FieldCacheNext + ASL_FIELD_CACHE_SIZE;
251 }
252
253 Gbl_FieldCount++;
254 return (Gbl_FieldCacheNext++);
255 }
256
257
258 /*******************************************************************************
259 *
260 * FUNCTION: UtDeleteLocalCaches
261 *
262 * PARAMETERS: None
263 *
264 * RETURN: None
265 *
266 * DESCRIPTION: Delete all local cache buffer blocks
267 *
268 ******************************************************************************/
269
270 void
271 UtDeleteLocalCaches (
272 void)
273 {
274 UINT32 BufferCount;
275 ASL_CACHE_INFO *Next;
276
277
278 /*
279 * Generic cache, arbitrary size allocations
280 */
281 BufferCount = 0;
282 while (Gbl_StringCacheList)
283 {
284 Next = Gbl_StringCacheList->Next;
285 ACPI_FREE (Gbl_StringCacheList);
286 Gbl_StringCacheList = Next;
287 BufferCount++;
288 }
289
290 DbgPrint (ASL_DEBUG_OUTPUT,
291 "%u Strings (%u bytes), Buffer size: %u bytes, %u Buffers\n",
292 Gbl_StringCount, Gbl_StringSize, ASL_STRING_CACHE_SIZE, BufferCount);
293
294 /* Reset cache globals */
295
296 Gbl_StringSize = 0;
297 Gbl_StringCount = 0;
298 Gbl_StringCacheNext = NULL;
299 Gbl_StringCacheLast = NULL;
300
301
302 /*
303 * Parse Op cache
304 */
305 BufferCount = 0;
306 while (Gbl_ParseOpCacheList)
307 {
308 Next = Gbl_ParseOpCacheList->Next;
309 ACPI_FREE (Gbl_ParseOpCacheList);
310 Gbl_ParseOpCacheList = Next;
311 BufferCount++;
312 }
313
314 DbgPrint (ASL_DEBUG_OUTPUT,
315 "%u ParseOps, Buffer size: %u ops (%u bytes), %u Buffers\n",
316 Gbl_ParseOpCount, ASL_PARSEOP_CACHE_SIZE,
317 (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE), BufferCount);
318
319 /* Reset cache globals */
320
321 Gbl_ParseOpCount = 0;
322 Gbl_ParseOpCacheNext = NULL;
323 Gbl_ParseOpCacheLast = NULL;
324 Gbl_ParseTreeRoot = NULL;
325
326
327 /*
328 * Table Compiler - Field cache
329 */
330 BufferCount = 0;
331 while (Gbl_FieldCacheList)
332 {
333 Next = Gbl_FieldCacheList->Next;
334 ACPI_FREE (Gbl_FieldCacheList);
335 Gbl_FieldCacheList = Next;
336 BufferCount++;
337 }
338
339 DbgPrint (ASL_DEBUG_OUTPUT,
340 "%u Fields, Buffer size: %u fields (%u bytes), %u Buffers\n",
341 Gbl_FieldCount, ASL_FIELD_CACHE_SIZE,
342 (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE), BufferCount);
343
344 /* Reset cache globals */
345
346 Gbl_FieldCount = 0;
347 Gbl_FieldCacheNext = NULL;
348 Gbl_FieldCacheLast = NULL;
349
350
351 /*
352 * Table Compiler - Subtable cache
353 */
354 BufferCount = 0;
355 while (Gbl_SubtableCacheList)
356 {
357 Next = Gbl_SubtableCacheList->Next;
358 ACPI_FREE (Gbl_SubtableCacheList);
359 Gbl_SubtableCacheList = Next;
360 BufferCount++;
361 }
362
363 DbgPrint (ASL_DEBUG_OUTPUT,
364 "%u Subtables, Buffer size: %u subtables (%u bytes), %u Buffers\n",
365 Gbl_SubtableCount, ASL_SUBTABLE_CACHE_SIZE,
366 (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE), BufferCount);
367
368 /* Reset cache globals */
369
370 Gbl_SubtableCount = 0;
371 Gbl_SubtableCacheNext = NULL;
372 Gbl_SubtableCacheLast = NULL;
373 }
374