CUBRID Engine  latest
memory_alloc.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * memory_alloc.c - Memory allocation module
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <stdlib.h>
28 #include <string.h>
29 #include <assert.h>
30 
31 #include "set_object.h"
32 #include "misc_string.h"
33 #include "object_domain.h"
34 #include "dbtype.h"
35 #include "memory_alloc.h"
36 #include "util_func.h"
37 #include "error_manager.h"
38 #include "intl_support.h"
39 #include "resource_tracker.hpp"
40 #include "customheaps.h"
41 #if !defined (SERVER_MODE)
42 #include "quick_fit.h"
43 #endif /* SERVER_MODE */
44 #if defined (SERVER_MODE)
45 #include "thread_entry.hpp"
46 #endif // SERVER_MODE
47 #if defined (SERVER_MODE)
48 #include "thread_manager.hpp" // for thread_get_thread_entry_info
49 #endif // SERVER_MODE
50 
51 #define DEFAULT_OBSTACK_CHUNK_SIZE 32768 /* 1024 x 32 */
52 
53 #if !defined (SERVER_MODE)
54 extern unsigned int db_on_server;
55 HL_HEAPID private_heap_id = 0;
56 #endif /* SERVER_MODE */
57 
58 #if defined (SERVER_MODE)
59 static HL_HEAPID db_private_get_heapid_from_thread (REFPTR (THREAD_ENTRY, thread_p));
60 #endif // SERVER_MODE
61 
62 /*
63  * ansisql_strcmp - String comparison according to ANSI SQL
64  * return: an integer value which is less than zero
65  * if s is lexicographically less than t,
66  * equal to zero if s is equal to t,
67  * and greater than zero if s is greater than zero.
68  * s(in): first string to be compared
69  * t(in): second string to be compared
70  *
71  * Note: The contents of the null-terminated string s are compared with
72  * the contents of the null-terminated string t, using the ANSI
73  * SQL semantics. That is, if the lengths of the strings are not
74  * the same, the shorter string is considered to be extended
75  * with the blanks on the right, so that both strings have the
76  * same length.
77  */
78 int
79 ansisql_strcmp (const char *s, const char *t)
80 {
81  for (; *s == *t; s++, t++)
82  {
83  if (*s == '\0')
84  {
85  return 0;
86  }
87  }
88 
89  if (*s == '\0')
90  {
91  while (*t != '\0')
92  {
93  if (*t++ != ' ')
94  {
95  return -1;
96  }
97  }
98  return 0;
99  }
100  else if (*t == '\0')
101  {
102  while (*s != '\0')
103  {
104  if (*s++ != ' ')
105  {
106  return 1;
107  }
108  }
109  return 0;
110  }
111  else
112  {
113  return (*(unsigned const char *) s < *(unsigned const char *) t) ? -1 : 1;
114  }
115 }
116 
117 /*
118  * ansisql_strcasecmp - Case-insensitive string comparison according to ANSI SQL
119  * return: an integer value which is less than zero
120  * if s is lexicographically less than t,
121  * equal to zero if s is equal to t,
122  * and greater than zero if s is greater than zero.
123  * s(in): first string to be compared
124  * t(in): second string to be compared
125  *
126  * Note: The contents of the null-terminated string s are compared with
127  * the contents of the null-terminated string t, using the ANSI
128  * SQL semantics. That is, if the lengths of the strings are not
129  * the same, the shorter string is considered to be extended
130  * with the blanks on the right, so that both strings have the
131  * same length.
132  */
133 int
134 ansisql_strcasecmp (const char *s, const char *t)
135 {
136  size_t s_length, t_length, min_length;
137  int cmp_val;
138 
139  s_length = strlen (s);
140  t_length = strlen (t);
141 
142  min_length = s_length < t_length ? s_length : t_length;
143 
144  cmp_val = intl_identifier_ncasecmp (s, t, (int) min_length);
145 
146  /* If not equal for shorter length, return */
147  if (cmp_val)
148  {
149  return cmp_val;
150  }
151 
152  /* If equal and same size, return */
153  if (s_length == t_length)
154  {
155  return 0;
156  }
157 
158  /* If equal for shorter length and not same size, look for trailing blanks */
159  s += min_length;
160  t += min_length;
161 
162  if (*s == '\0')
163  {
164  while (*t != '\0')
165  {
166  if (*t++ != ' ')
167  {
168  return -1;
169  }
170  }
171  return 0;
172  }
173  else
174  {
175  while (*s != '\0')
176  {
177  if (*s++ != ' ')
178  {
179  return 1;
180  }
181  }
182  return 0;
183  }
184 }
185 
186 /*
187  * db_alignment () -
188  * return:
189  * n(in):
190  */
191 int
193 {
194  if (n >= (int) sizeof (double))
195  {
196  return (int) sizeof (double);
197  }
198  else if (n >= (int) sizeof (void *))
199  {
200  return (int) sizeof (void *);
201  }
202  else if (n >= (int) sizeof (int))
203  {
204  return (int) sizeof (int);
205  }
206  else if (n >= (int) sizeof (short))
207  {
208  return (int) sizeof (short);
209  }
210  else
211  {
212  return 1;
213  }
214 }
215 
216 /*
217  * db_align_to () - Return the least multiple of 'alignment' that is greater
218  * than or equal to 'n'.
219  * return:
220  * n(in):
221  * alignment(in):
222  */
223 int
224 db_align_to (int n, int alignment)
225 {
226  /*
227  * Return the least multiple of 'alignment' that is greater than or
228  * equal to 'n'. 'alignment' must be a power of 2.
229  */
230  return (n + alignment - 1) & ~(alignment - 1);
231 }
232 
233 /*
234  * db_create_ostk_heap () - create an obstack heap
235  * return: memory heap identifier
236  * chunk_size(in):
237  */
238 HL_HEAPID
239 db_create_ostk_heap (int chunk_size)
240 {
241  return hl_register_ostk_heap (chunk_size);
242 }
243 
244 /*
245  * db_destroy_ostk_heap () - destroy an obstack heap
246  * return:
247  * heap_id(in): memory heap identifier to destroy
248  */
249 void
250 db_destroy_ostk_heap (HL_HEAPID heap_id)
251 {
252  hl_unregister_ostk_heap (heap_id);
253 }
254 
255 /*
256  * db_ostk_alloc () - call allocation function for the obstack heap
257  * return: allocated memory pointer
258  * heap_id(in): memory heap identifier
259  * size(in): size to allocate
260  */
261 void *
262 db_ostk_alloc (HL_HEAPID heap_id, size_t size)
263 {
264  void *ptr = NULL;
265  if (heap_id && size > 0)
266  {
267  ptr = hl_ostk_alloc (heap_id, size);
268  }
269  return ptr;
270 }
271 
272 #if defined (ENABLE_UNUSED_FUNCTION)
273 /*
274  * db_ostk_free () - call free function for the ostk heap
275  * return:
276  * heap_id(in): memory heap identifier
277  * ptr(in): memory pointer to free
278  */
279 void
280 db_ostk_free (HL_HEAPID heap_id, void *ptr)
281 {
282  if (heap_id && ptr)
283  {
284  hl_ostk_free (heap_id, ptr);
285  }
286 }
287 #endif /* ENABLE_UNUSED_FUNCTION */
288 
289 /*
290  * db_create_private_heap () - create a thread specific heap
291  * return: memory heap identifier
292  */
293 HL_HEAPID
295 {
296  HL_HEAPID heap_id = 0;
297 #if defined (SERVER_MODE)
298  heap_id = hl_register_lea_heap ();
299 #else /* SERVER_MODE */
300  if (db_on_server)
301  {
302  heap_id = hl_register_lea_heap ();
303  }
304 #endif /* SERVER_MODE */
305  return heap_id;
306 }
307 
308 /*
309  * db_clear_private_heap () - clear a thread specific heap
310  * return:
311  * heap_id(in): memory heap identifier to clear
312  */
313 void
314 db_clear_private_heap (THREAD_ENTRY * thread_p, HL_HEAPID heap_id)
315 {
316  if (heap_id == 0)
317  {
318 #if defined (SERVER_MODE)
319  heap_id = db_private_get_heapid_from_thread (thread_p);
320 #else /* SERVER_MODE */
321  heap_id = private_heap_id;
322 #endif /* SERVER_MODE */
323  }
324 
325  if (heap_id)
326  {
327  hl_clear_lea_heap (heap_id);
328  }
329 }
330 
331 /*
332  * db_change_private_heap () - change private heap
333  * return: old private heap id
334  * heap_id(in): heap id
335  */
336 HL_HEAPID
337 db_change_private_heap (THREAD_ENTRY * thread_p, HL_HEAPID heap_id)
338 {
339  HL_HEAPID old_heap_id;
340 
341 #if defined (SERVER_MODE)
342  old_heap_id = db_private_set_heapid_to_thread (thread_p, heap_id);
343 #else /* SERVER_MODE */
344  old_heap_id = private_heap_id;
345  if (db_on_server)
346  {
347  private_heap_id = heap_id;
348  }
349 #endif
350  return old_heap_id;
351 }
352 
353 /*
354  * db_replace_private_heap () - replace a thread specific heap
355  * return: old memory heap identifier
356  *
357  */
358 HL_HEAPID
360 {
361  HL_HEAPID old_heap_id, heap_id;
362 
363 #if defined (SERVER_MODE)
364  old_heap_id = db_private_get_heapid_from_thread (thread_p);
365 #else /* SERVER_MODE */
366  old_heap_id = private_heap_id;
367 #endif /* SERVER_MODE */
368 
369 #if defined (SERVER_MODE)
370  heap_id = db_create_private_heap ();
371  db_private_set_heapid_to_thread (thread_p, heap_id);
372 #else /* SERVER_MODE */
373  if (db_on_server)
374  {
375  heap_id = db_create_private_heap ();
376  private_heap_id = heap_id;
377  }
378 #endif /* SERVER_MODE */
379  return old_heap_id;
380 }
381 
382 /*
383  * db_destroy_private_heap () - destroy a thread specific heap
384  * return:
385  * heap_id(in): memory heap identifier to destroy
386  */
387 void
388 db_destroy_private_heap (THREAD_ENTRY * thread_p, HL_HEAPID heap_id)
389 {
390  if (heap_id == 0)
391  {
392 #if defined (SERVER_MODE)
393  heap_id = db_private_get_heapid_from_thread (thread_p);
394 #else /* SERVER_MODE */
395  heap_id = private_heap_id;
396 #endif /* SERVER_MODE */
397  }
398 
399  if (heap_id)
400  {
401  hl_unregister_lea_heap (heap_id);
402  }
403 }
404 
405 /*
406  * db_private_alloc () - call allocation function for current private heap
407  * return: allocated memory pointer
408  * thrd(in): thread context if it is available, otherwise NULL; if called
409  * on the server and this parameter is NULL, the function will
410  * determine the appropriate thread context
411  * size(in): size to allocate
412  */
413 
414 /* dummy definition for Windows */
415 #if defined(WINDOWS)
416 #if !defined(NDEBUG)
417 void *
418 db_private_alloc_release (THREAD_ENTRY * thrd, size_t size, bool rc_track)
419 {
420  return NULL;
421 }
422 #else
423 void *
424 db_private_alloc_debug (THREAD_ENTRY * thrd, size_t size, bool rc_track, const char *caller_file, int caller_line)
425 {
426  return NULL;
427 }
428 #endif
429 #endif
430 
431 #if !defined(NDEBUG)
432 void *
433 db_private_alloc_debug (THREAD_ENTRY * thrd, size_t size, bool rc_track, const char *caller_file, int caller_line)
434 #else /* NDEBUG */
435 void *
436 db_private_alloc_release (THREAD_ENTRY * thrd, size_t size, bool rc_track)
437 #endif /* NDEBUG */
438 {
439 #if !defined (CS_MODE)
440  void *ptr = NULL;
441 #endif /* !CS_MODE */
442 
443 #if defined (SERVER_MODE)
444  HL_HEAPID heap_id;
445 #endif
446 
447  assert (size > 0);
448 
449 #if defined (CS_MODE)
450  return db_ws_alloc (size);
451 #elif defined (SERVER_MODE)
452  if (size <= 0)
453  {
454  return NULL;
455  }
456 
457  heap_id = db_private_get_heapid_from_thread (thrd);
458 
459  if (heap_id)
460  {
461  ptr = hl_lea_alloc (heap_id, size);
462  }
463  else
464  {
465  ptr = malloc (size);
466  if (ptr == NULL)
467  {
469  }
470  }
471 
472 #if !defined (NDEBUG)
473  if (rc_track && heap_id != 0)
474  {
475  if (ptr != NULL)
476  {
477  thread_get_thread_entry_info ()->get_alloc_tracker ().increment (caller_file, caller_line, ptr);
478  }
479  }
480 #endif /* !NDEBUG */
481 
482  return ptr;
483 #else /* SA_MODE */
484  if (!db_on_server)
485  {
486  return db_ws_alloc (size);
487  }
488  else
489  {
490  if (size <= 0)
491  {
492  return NULL;
493  }
494 
495  if (private_heap_id)
496  {
497  PRIVATE_MALLOC_HEADER *h = NULL;
498  size_t req_sz;
499 
500  req_sz = private_request_size (size);
501  h = (PRIVATE_MALLOC_HEADER *) hl_lea_alloc (private_heap_id, req_sz);
502 
503  if (h != NULL)
504  {
505  h->magic = PRIVATE_MALLOC_HEADER_MAGIC;
506  h->alloc_type = PRIVATE_ALLOC_TYPE_LEA;
507  return private_hl2user_ptr (h);
508  }
509  else
510  {
511  return NULL;
512  }
513  }
514  else
515  {
516  ptr = malloc (size);
517  if (ptr == NULL)
518  {
520  }
521  return ptr;
522  }
523  }
524 #endif /* SA_MODE */
525 }
526 
527 
528 /*
529  * db_private_realloc () - call re-allocation function for current private heap
530  * return: allocated memory pointer
531  * thrd(in): thread conext if it is server, otherwise NULL
532  * ptr(in): memory pointer to reallocate
533  * size(in): size to allocate
534  */
535 /* dummy definition for Windows */
536 #if defined(WINDOWS)
537 #if !defined(NDEBUG)
538 void *
539 db_private_realloc_release (THREAD_ENTRY * thrd, void *ptr, size_t size, bool rc_track)
540 {
541  return NULL;
542 }
543 #else
544 void *
545 db_private_realloc_debug (THREAD_ENTRY * thrd, void *ptr, size_t size, bool rc_track, const char *caller_file,
546  int caller_line)
547 {
548  return NULL;
549 }
550 #endif
551 #endif
552 
553 #if !defined(NDEBUG)
554 void *
555 db_private_realloc_debug (THREAD_ENTRY * thrd, void *ptr, size_t size, bool rc_track, const char *caller_file,
556  int caller_line)
557 #else /* NDEBUG */
558 void *
559 db_private_realloc_release (THREAD_ENTRY * thrd, void *ptr, size_t size, bool rc_track)
560 #endif /* NDEBUG */
561 {
562 #if !defined (CS_MODE)
563  void *new_ptr = NULL;
564 #endif /* !CS_MODE */
565 
566 #if defined (SERVER_MODE)
567  HL_HEAPID heap_id;
568 #endif
569 
570 #if defined (CS_MODE)
571  return db_ws_realloc (ptr, size);
572 #elif defined (SERVER_MODE)
573  if (size <= 0)
574  {
575  return NULL;
576  }
577 
578  heap_id = db_private_get_heapid_from_thread (thrd);
579 
580  if (heap_id)
581  {
582  new_ptr = hl_lea_realloc (heap_id, ptr, size);
583  }
584  else
585  {
586  new_ptr = realloc (ptr, size);
587  if (new_ptr == NULL)
588  {
590  }
591  }
592 
593 #if !defined (NDEBUG)
594  if (rc_track && heap_id != 0 && new_ptr != ptr)
595  {
596  /* remove old pointer from track meter */
597  if (ptr != NULL)
598  {
600  }
601  /* add new pointer to track meter */
602  if (new_ptr != NULL)
603  {
604  thread_get_thread_entry_info ()->get_alloc_tracker ().increment (caller_file, caller_line, new_ptr);
605  }
606  }
607 #endif /* !NDEBUG */
608 
609  return new_ptr;
610 #else /* SA_MODE */
611  if (ptr == NULL)
612  {
613  return db_private_alloc (thrd, size);
614  }
615 
616  if (!db_on_server)
617  {
618  return db_ws_realloc (ptr, size);
619  }
620  else
621  {
622  if (private_heap_id)
623  {
624  PRIVATE_MALLOC_HEADER *h;
625 
626  h = private_user2hl_ptr (ptr);
627  if (h->magic != PRIVATE_MALLOC_HEADER_MAGIC)
628  {
629  return NULL;
630  }
631 
632  if (h->alloc_type == PRIVATE_ALLOC_TYPE_LEA)
633  {
634  PRIVATE_MALLOC_HEADER *new_h;
635  size_t req_sz;
636 
637  req_sz = private_request_size (size);
638  new_h = (PRIVATE_MALLOC_HEADER *) hl_lea_realloc (private_heap_id, h, req_sz);
639  if (new_h == NULL)
640  {
641  return NULL;
642  }
643  return private_hl2user_ptr (new_h);
644  }
645  else if (h->alloc_type == PRIVATE_ALLOC_TYPE_WS)
646  {
647  return db_ws_realloc (ptr, size);
648  }
649  else
650  {
651  return NULL;
652  }
653  }
654  else
655  {
656  new_ptr = realloc (ptr, size);
657  if (new_ptr == NULL)
658  {
660  }
661  return new_ptr;
662  }
663  }
664 #endif /* SA_MODE */
665 }
666 
667 /*
668  * db_private_private_strdup () - duplicate string. memory for the duplicated
669  * string is obtanined by db_private_alloc
670  * return: pointer to duplicated str
671  * thrd(in): thread conext if it is server, otherwise NULL
672  * size(s): source string
673  */
674 char *
675 db_private_strdup (THREAD_ENTRY * thrd, const char *s)
676 {
677  char *cp;
678  int len;
679 
680  /* fast return */
681  if (s == NULL)
682  {
683  return NULL;
684  }
685 
686  len = (int) strlen (s);
687  cp = (char *) db_private_alloc (thrd, len + 1);
688 
689  if (cp != NULL)
690  {
691  memcpy (cp, s, len);
692  cp[len] = '\0';
693  }
694 
695  return cp;
696 }
697 
698 /*
699  * db_private_free () - call free function for current private heap
700  * return:
701  * thrd(in): thread conext if it is server, otherwise NULL
702  * ptr(in): memory pointer to free
703  */
704 
705 /* dummy definition for Windows */
706 #if defined(WINDOWS)
707 #if !defined(NDEBUG)
708 void
709 db_private_free_release (THREAD_ENTRY * thrd, void *ptr, bool rc_track)
710 {
711  return;
712 }
713 #else
714 void
715 db_private_free_debug (THREAD_ENTRY * thrd, void *ptr, bool rc_track, const char *caller_file, int caller_line)
716 {
717  return;
718 }
719 #endif
720 #endif
721 
722 #if !defined(NDEBUG)
723 void
724 db_private_free_debug (THREAD_ENTRY * thrd, void *ptr, bool rc_track, const char *caller_file, int caller_line)
725 #else /* NDEBUG */
726 void
727 db_private_free_release (THREAD_ENTRY * thrd, void *ptr, bool rc_track)
728 #endif /* NDEBUG */
729 {
730 #if defined (SERVER_MODE)
731  HL_HEAPID heap_id;
732 #endif
733 
734  if (ptr == NULL)
735  {
736  return;
737  }
738 
739 #if defined (CS_MODE)
740  db_ws_free (ptr);
741 #elif defined (SERVER_MODE)
742  heap_id = db_private_get_heapid_from_thread (thrd);
743 
744  if (heap_id)
745  {
746  hl_lea_free (heap_id, ptr);
747  }
748  else
749  {
750  free (ptr);
751  }
752 
753 #if !defined (NDEBUG)
754  if (rc_track && heap_id != 0)
755  {
756  if (ptr != NULL)
757  {
758  thrd->get_alloc_tracker ().decrement (ptr);
759  }
760  }
761 #endif /* !NDEBUG */
762 
763 #else /* SA_MODE */
764 
765  if (!db_on_server)
766  {
767  db_ws_free (ptr);
768  return;
769  }
770 
771  if (private_heap_id == 0)
772  {
773  free (ptr);
774  }
775  else
776  {
777  PRIVATE_MALLOC_HEADER *h;
778 
779  h = private_user2hl_ptr (ptr);
780  if (h->magic != PRIVATE_MALLOC_HEADER_MAGIC)
781  {
782  /* assertion point */
783  return;
784  }
785 
786  if (h->alloc_type == PRIVATE_ALLOC_TYPE_LEA)
787  {
789  }
790  else if (h->alloc_type == PRIVATE_ALLOC_TYPE_WS)
791  {
792  db_ws_free (ptr); /* not h */
793  }
794  else
795  {
796  return;
797  }
798  }
799 #endif /* SA_MODE */
800 }
801 
802 
803 void *
805 {
806 #if !defined(NDEBUG)
807  return db_private_alloc_debug (thrd, size, true, __FILE__, __LINE__);
808 #else /* NDEBUG */
809  return db_private_alloc_release (thrd, size, false);
810 #endif /* NDEBUG */
811 }
812 
813 
814 void
816 {
817 #if !defined(NDEBUG)
818  db_private_free_debug (thrd, ptr, true, __FILE__, __LINE__);
819 #else /* NDEBUG */
820  db_private_free_release (thrd, ptr, false);
821 #endif /* NDEBUG */
822 }
823 
824 
825 void *
826 db_private_realloc_external (THREAD_ENTRY * thrd, void *ptr, size_t size)
827 {
828 #if !defined(NDEBUG)
829  return db_private_realloc_debug (thrd, ptr, size, true, __FILE__, __LINE__);
830 #else /* NDEBUG */
831  return db_private_realloc_release (thrd, ptr, size, false);
832 #endif /* NDEBUG */
833 }
834 
835 #if defined (SERVER_MODE)
836 /*
837  * os_malloc () -
838  * return: allocated memory pointer
839  * size(in): size to allocate
840  */
841 #if !defined(NDEBUG)
842 void *
843 os_malloc_debug (size_t size, bool rc_track, const char *caller_file, int caller_line)
844 #else /* NDEBUG */
845 void *
846 os_malloc_release (size_t size, bool rc_track)
847 #endif /* NDEBUG */
848 {
849  void *ptr = NULL;
850 
851  assert (size > 0);
852 
853  ptr = malloc (size);
854  if (ptr == NULL)
855  {
857  }
858 
859 #if !defined (NDEBUG)
860  if (rc_track)
861  {
862  if (ptr != NULL)
863  {
864  thread_get_thread_entry_info ()->get_alloc_tracker ().increment (caller_file, caller_line, ptr);
865  }
866  }
867 #endif /* !NDEBUG */
868 
869  return ptr;
870 }
871 
872 
873 /*
874  * os_calloc () -
875  * return: allocated memory pointer
876  * size(in): size to allocate
877  */
878 #if !defined(NDEBUG)
879 void *
880 os_calloc_debug (size_t n, size_t size, bool rc_track, const char *caller_file, int caller_line)
881 #else /* NDEBUG */
882 void *
883 os_calloc_release (size_t n, size_t size, bool rc_track)
884 #endif /* NDEBUG */
885 {
886  void *ptr = NULL;
887 
888  assert (size > 0);
889 
890  ptr = calloc (n, size);
891  if (ptr == NULL)
892  {
894  }
895 
896 #if !defined (NDEBUG)
897  if (rc_track)
898  {
899  if (ptr != NULL)
900  {
901  thread_get_thread_entry_info ()->get_alloc_tracker ().increment (caller_file, caller_line, ptr);
902  }
903  }
904 #endif /* !NDEBUG */
905 
906  return ptr;
907 }
908 
909 /*
910  * os_free () -
911  * return:
912  * ptr(in): memory pointer to free
913  */
914 #if !defined(NDEBUG)
915 void
916 os_free_debug (void *ptr, bool rc_track, const char *caller_file, int caller_line)
917 #else /* NDEBUG */
918 void
919 os_free_release (void *ptr, bool rc_track)
920 #endif /* NDEBUG */
921 {
922  free (ptr);
923 
924 #if !defined (NDEBUG)
925  if (rc_track)
926  {
927  if (ptr != NULL)
928  {
930  }
931  }
932 #endif /* !NDEBUG */
933 }
934 
935 #if defined (SERVER_MODE)
936 /*
937  * db_private_get_heapid_from_thread () -
938  * return: heap id
939  * thread_p(in/out): thread local entry; output is never nil
940  */
941 static HL_HEAPID
942 db_private_get_heapid_from_thread (REFPTR (THREAD_ENTRY, thread_p))
943 {
944  if (thread_p == NULL)
945  {
946  thread_p = thread_get_thread_entry_info ();
947  }
948  assert (thread_p != NULL);
949 
950  return thread_p->private_heap_id;
951 }
952 
953 /*
954  * css_set_private_heap() -
955  * return:
956  * thread_p(in):
957  * heap_id(in):
958  */
959 HL_HEAPID
960 db_private_set_heapid_to_thread (THREAD_ENTRY * thread_p, HL_HEAPID heap_id)
961 {
962  HL_HEAPID old_heap_id = 0;
963 
964  if (thread_p == NULL)
965  {
966  thread_p = thread_get_thread_entry_info ();
967  }
968 
969  assert (thread_p != NULL);
970 
971  old_heap_id = thread_p->private_heap_id;
972  thread_p->private_heap_id = heap_id;
973 
974  return old_heap_id;
975 }
976 #endif // SERVER_MODE
977 
978 #endif
int intl_identifier_ncasecmp(const char *str1, const char *str2, const int len)
void * db_private_realloc_external(THREAD_ENTRY *thrd, void *ptr, size_t size)
Definition: memory_alloc.c:826
cubthread::entry * thread_get_thread_entry_info(void)
void * hl_lea_realloc(UINTPTR heap_id, void *ptr, size_t sz)
Definition: lea_heap.c:361
UINTPTR hl_register_lea_heap(void)
Definition: lea_heap.c:213
void * db_private_alloc_debug(THREAD_ENTRY *thrd, size_t size, bool rc_track, const char *caller_file, int caller_line)
Definition: memory_alloc.c:433
void hl_clear_lea_heap(UINTPTR heap_id)
Definition: lea_heap.c:272
void hl_unregister_ostk_heap(UINTPTR heap_id)
int ansisql_strcmp(const char *s, const char *t)
Definition: memory_alloc.c:79
void * db_ws_realloc(void *ptr, size_t size)
Definition: quick_fit.c:123
HL_HEAPID db_change_private_heap(THREAD_ENTRY *thread_p, HL_HEAPID heap_id)
Definition: memory_alloc.c:337
void db_ws_free(void *ptr)
Definition: quick_fit.c:194
cubbase::alloc_tracker & get_alloc_tracker(void)
void THREAD_ENTRY
void increment(const char *filename, const int line, const res_type &res, unsigned use_count=1)
void db_destroy_private_heap(THREAD_ENTRY *thread_p, HL_HEAPID heap_id)
Definition: memory_alloc.c:388
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
void * db_ostk_alloc(HL_HEAPID heap_id, size_t size)
Definition: memory_alloc.c:262
void db_clear_private_heap(THREAD_ENTRY *thread_p, HL_HEAPID heap_id)
Definition: memory_alloc.c:314
#define assert(x)
HL_HEAPID db_create_private_heap(void)
Definition: memory_alloc.c:294
char * db_private_strdup(THREAD_ENTRY *thrd, const char *s)
Definition: memory_alloc.c:675
#define ER_OUT_OF_VIRTUAL_MEMORY
Definition: error_code.h:50
#define REFPTR(T, name)
Definition: porting.h:1089
HL_HEAPID private_heap_id
Definition: memory_alloc.c:55
void * db_private_realloc_debug(THREAD_ENTRY *thrd, void *ptr, size_t size, bool rc_track, const char *caller_file, int caller_line)
Definition: memory_alloc.c:555
HL_HEAPID db_create_ostk_heap(int chunk_size)
Definition: memory_alloc.c:239
void db_private_free_external(THREAD_ENTRY *thrd, void *ptr)
Definition: memory_alloc.c:815
#define NULL
Definition: freelistheap.h:34
void db_private_free_debug(THREAD_ENTRY *thrd, void *ptr, bool rc_track, const char *caller_file, int caller_line)
Definition: memory_alloc.c:724
void hl_unregister_lea_heap(UINTPTR heap_id)
Definition: lea_heap.c:299
#define db_private_alloc(thrd, size)
Definition: memory_alloc.h:227
unsigned int db_on_server
int db_alignment(int n)
Definition: memory_alloc.c:192
#define ARG_FILE_LINE
Definition: error_manager.h:44
#define strlen(s1)
Definition: intl_support.c:43
void hl_ostk_free(UINTPTR heap_id, void *ptr)
void decrement(const res_type &res, unsigned use_count=1)
void * hl_ostk_alloc(UINTPTR heap_id, size_t sz)
void * db_ws_alloc(size_t size)
Definition: quick_fit.c:73
void * hl_lea_alloc(UINTPTR heap_id, size_t sz)
Definition: lea_heap.c:326
UINTPTR hl_register_ostk_heap(int chunk_size)
Definition: customheaps.cpp:96
void * db_private_alloc_external(THREAD_ENTRY *thrd, size_t size)
Definition: memory_alloc.c:804
HL_HEAPID db_replace_private_heap(THREAD_ENTRY *thread_p)
Definition: memory_alloc.c:359
void db_destroy_ostk_heap(HL_HEAPID heap_id)
Definition: memory_alloc.c:250
int db_align_to(int n, int alignment)
Definition: memory_alloc.c:224
void hl_lea_free(UINTPTR heap_id, void *ptr)
Definition: lea_heap.c:395
int ansisql_strcasecmp(const char *s, const char *t)
Definition: memory_alloc.c:134