Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: src/allocation.h

Issue 6759025: Version 3.2.6 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/accessors.cc ('k') | src/allocation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 #include "globals.h" 32 #include "globals.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 // Called when allocation routines fail to allocate. 37 // Called when allocation routines fail to allocate.
38 // This function should not return, but should terminate the current 38 // This function should not return, but should terminate the current
39 // processing. 39 // processing.
40 void FatalProcessOutOfMemory(const char* message); 40 void FatalProcessOutOfMemory(const char* message);
41 41
42 // A class that controls whether allocation is allowed. This is for
43 // the C++ heap only!
44 class NativeAllocationChecker {
45 public:
46 enum NativeAllocationAllowed { ALLOW, DISALLOW };
47 #ifdef DEBUG
48 explicit NativeAllocationChecker(NativeAllocationAllowed allowed);
49 ~NativeAllocationChecker();
50 static bool allocation_allowed();
51 private:
52 // This flag applies to this particular instance.
53 NativeAllocationAllowed allowed_;
54 #else
55 explicit inline NativeAllocationChecker(NativeAllocationAllowed allowed) {}
56 static inline bool allocation_allowed() { return true; }
57 #endif
58 };
59
60
61 // Superclass for classes managed with new & delete. 42 // Superclass for classes managed with new & delete.
62 class Malloced { 43 class Malloced {
63 public: 44 public:
64 void* operator new(size_t size) { return New(size); } 45 void* operator new(size_t size) { return New(size); }
65 void operator delete(void* p) { Delete(p); } 46 void operator delete(void* p) { Delete(p); }
66 47
67 static void FatalProcessOutOfMemory(); 48 static void FatalProcessOutOfMemory();
68 static void* New(size_t size); 49 static void* New(size_t size);
69 static void Delete(void* p); 50 static void Delete(void* p);
70 }; 51 };
(...skipping 23 matching lines...) Expand all
94 #ifdef DEBUG 75 #ifdef DEBUG
95 public: 76 public:
96 void* operator new(size_t size); 77 void* operator new(size_t size);
97 void operator delete(void* p); 78 void operator delete(void* p);
98 #endif 79 #endif
99 }; 80 };
100 81
101 82
102 template <typename T> 83 template <typename T>
103 static T* NewArray(int size) { 84 static T* NewArray(int size) {
104 ASSERT(NativeAllocationChecker::allocation_allowed());
105 T* result = new T[size]; 85 T* result = new T[size];
106 if (result == NULL) Malloced::FatalProcessOutOfMemory(); 86 if (result == NULL) Malloced::FatalProcessOutOfMemory();
107 return result; 87 return result;
108 } 88 }
109 89
110 90
111 template <typename T> 91 template <typename T>
112 static void DeleteArray(T* array) { 92 static void DeleteArray(T* array) {
113 delete[] array; 93 delete[] array;
114 } 94 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 134
155 friend class Isolate; 135 friend class Isolate;
156 136
157 DISALLOW_IMPLICIT_CONSTRUCTORS(PreallocatedStorage); 137 DISALLOW_IMPLICIT_CONSTRUCTORS(PreallocatedStorage);
158 }; 138 };
159 139
160 140
161 } } // namespace v8::internal 141 } } // namespace v8::internal
162 142
163 #endif // V8_ALLOCATION_H_ 143 #endif // V8_ALLOCATION_H_
OLDNEW
« no previous file with comments | « src/accessors.cc ('k') | src/allocation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698