OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_ALLOCATION_H_ | 5 #ifndef V8_ALLOCATION_H_ |
6 #define V8_ALLOCATION_H_ | 6 #define V8_ALLOCATION_H_ |
7 | 7 |
8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
9 #include "src/globals.h" | 9 #include "src/globals.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 // Called when allocation routines fail to allocate. | 14 // Called when allocation routines fail to allocate. |
15 // This function should not return, but should terminate the current | 15 // This function should not return, but should terminate the current |
16 // processing. | 16 // processing. |
17 V8_EXPORT_PRIVATE void FatalProcessOutOfMemory(const char* message); | 17 V8_EXPORT_PRIVATE void FatalProcessOutOfMemory(const char* message); |
18 | 18 |
19 // Superclass for classes managed with new & delete. | 19 // Superclass for classes managed with new & delete. |
20 class V8_EXPORT_PRIVATE Malloced { | 20 class V8_EXPORT_PRIVATE Malloced { |
21 public: | 21 public: |
22 void* operator new(size_t size) { return New(size); } | 22 void* operator new(size_t size) { return New(size); } |
23 void operator delete(void* p) { Delete(p); } | 23 void operator delete(void* p) { Delete(p); } |
24 | 24 |
25 static void* New(size_t size); | 25 static void* New(size_t size); |
26 static void Delete(void* p); | 26 static void Delete(void* p); |
27 }; | 27 }; |
28 | 28 |
29 | 29 // DEPRECATED |
30 // A macro is used for defining the base class used for embedded instances. | 30 // TODO(leszeks): Delete this during a quiet period |
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 NON_EXPORTED_BASE(Embedded) | |
44 #else | |
45 #define BASE_EMBEDDED | 31 #define BASE_EMBEDDED |
46 #endif | |
47 | 32 |
48 | 33 |
49 // Superclass for classes only using static method functions. | 34 // Superclass for classes only using static method functions. |
50 // The subclass of AllStatic cannot be instantiated at all. | 35 // The subclass of AllStatic cannot be instantiated at all. |
51 class AllStatic { | 36 class AllStatic { |
52 #ifdef DEBUG | 37 #ifdef DEBUG |
53 public: | 38 public: |
54 AllStatic() = delete; | 39 AllStatic() = delete; |
55 #endif | 40 #endif |
56 }; | 41 }; |
(...skipping 29 matching lines...) Expand all Loading... |
86 }; | 71 }; |
87 | 72 |
88 | 73 |
89 void* AlignedAlloc(size_t size, size_t alignment); | 74 void* AlignedAlloc(size_t size, size_t alignment); |
90 void AlignedFree(void *ptr); | 75 void AlignedFree(void *ptr); |
91 | 76 |
92 } // namespace internal | 77 } // namespace internal |
93 } // namespace v8 | 78 } // namespace v8 |
94 | 79 |
95 #endif // V8_ALLOCATION_H_ | 80 #endif // V8_ALLOCATION_H_ |
OLD | NEW |