V8 Project
allocation.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_ALLOCATION_H_
6 #define V8_ALLOCATION_H_
7 
8 #include "src/globals.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 // Called when allocation routines fail to allocate.
14 // This function should not return, but should terminate the current
15 // processing.
16 void FatalProcessOutOfMemory(const char* message);
17 
18 // Superclass for classes managed with new & delete.
19 class Malloced {
20  public:
21  void* operator new(size_t size) { return New(size); }
22  void operator delete(void* p) { Delete(p); }
23 
24  static void FatalProcessOutOfMemory();
25  static void* New(size_t size);
26  static void Delete(void* p);
27 };
28 
29 
30 // A macro is used for defining the base class used for embedded instances.
31 // The reason is some compilers allocate a minimum of one word for the
32 // superclass. The macro prevents the use of new & delete in debug mode.
33 // In release mode we are not willing to pay this overhead.
34 
35 #ifdef DEBUG
36 // Superclass for classes with instances allocated inside stack
37 // activations or inside other objects.
38 class Embedded {
39  public:
40  void* operator new(size_t size);
41  void operator delete(void* p);
42 };
43 #define BASE_EMBEDDED : public Embedded
44 #else
45 #define BASE_EMBEDDED
46 #endif
47 
48 
49 // Superclass for classes only using statics.
50 class AllStatic {
51 #ifdef DEBUG
52  public:
53  void* operator new(size_t size);
54  void operator delete(void* p);
55 #endif
56 };
57 
58 
59 template <typename T>
60 T* NewArray(size_t size) {
61  T* result = new T[size];
62  if (result == NULL) Malloced::FatalProcessOutOfMemory();
63  return result;
64 }
65 
66 
67 template <typename T>
68 void DeleteArray(T* array) {
69  delete[] array;
70 }
71 
72 
73 // The normal strdup functions use malloc. These versions of StrDup
74 // and StrNDup uses new and calls the FatalProcessOutOfMemory handler
75 // if allocation fails.
76 char* StrDup(const char* str);
77 char* StrNDup(const char* str, int n);
78 
79 
80 // Allocation policy for allocating in the C free store using malloc
81 // and free. Used as the default policy for lists.
83  public:
84  INLINE(void* New(size_t size)) { return Malloced::New(size); }
85  INLINE(static void Delete(void* p)) { Malloced::Delete(p); }
86 };
87 
88 
89 void* AlignedAlloc(size_t size, size_t alignment);
90 void AlignedFree(void *ptr);
91 
92 } } // namespace v8::internal
93 
94 #endif // V8_ALLOCATION_H_
INLINE(void *New(size_t size))
Definition: allocation.h:84
INLINE(static void Delete(void *p))
Definition: allocation.h:85
static void * New(size_t size)
Definition: allocation.cc:20
static void FatalProcessOutOfMemory()
Definition: allocation.cc:34
static void Delete(void *p)
Definition: allocation.cc:29
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
void DeleteArray(T *array)
Definition: allocation.h:68
T * NewArray(size_t size)
Definition: allocation.h:60
void * AlignedAlloc(size_t size, size_t alignment)
Definition: allocation.cc:86
void FatalProcessOutOfMemory(const char *message)
char * StrNDup(const char *str, int n)
Definition: allocation.cc:76
void AlignedFree(void *ptr)
Definition: allocation.cc:104
char * StrDup(const char *str)
Definition: allocation.cc:67
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
#define T(name, string, precedence)
Definition: token.cc:25