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

Side by Side Diff: src/allocation.h

Issue 7374002: Refactor allocation policies. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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 | « no previous file | src/allocation-inl.h » ('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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 // The normal strdup functions use malloc. These versions of StrDup 97 // The normal strdup functions use malloc. These versions of StrDup
98 // and StrNDup uses new and calls the FatalProcessOutOfMemory handler 98 // and StrNDup uses new and calls the FatalProcessOutOfMemory handler
99 // if allocation fails. 99 // if allocation fails.
100 char* StrDup(const char* str); 100 char* StrDup(const char* str);
101 char* StrNDup(const char* str, int n); 101 char* StrNDup(const char* str, int n);
102 102
103 103
104 // Allocation policy for allocating in the C free store using malloc 104 // Allocation policy for allocating in the C free store using malloc
105 // and free. Used as the default policy for lists. 105 // and free. Used as the default policy for lists.
106 class FreeStoreAllocationPolicy { 106 class FreeStoreAllocator {
107 public: 107 public:
108 INLINE(static void* New(size_t size)) { return Malloced::New(size); } 108 INLINE(void* New(size_t size)) { return Malloced::New(size); }
109 INLINE(static void Delete(void* p)) { Malloced::Delete(p); } 109 INLINE(void Delete(void* p)) { Malloced::Delete(p); }
110 }; 110 };
111 111
112 112
113 // Allocation policy for allocating in preallocated space. 113 // Allocation policy for allocating in preallocated space.
114 // Used as an allocation policy for ScopeInfo when generating 114 // Used as an allocation policy for ScopeInfo when generating
115 // stack traces. 115 // stack traces.
116 class PreallocatedStorage { 116 class PreallocatedStorage {
117 public: 117 public:
118 explicit PreallocatedStorage(size_t size); 118 explicit PreallocatedStorage(size_t size);
119 size_t size() { return size_; } 119 size_t size() { return size_; }
120 120
121 // TODO(isolates): Get rid of these-- we'll have to change the allocator
122 // interface to include a pointer to an isolate to do this
123 // efficiently.
124 static inline void* New(size_t size);
125 static inline void Delete(void* p);
126
127 private: 121 private:
128 size_t size_; 122 size_t size_;
129 PreallocatedStorage* previous_; 123 PreallocatedStorage* previous_;
130 PreallocatedStorage* next_; 124 PreallocatedStorage* next_;
131 125
132 void LinkTo(PreallocatedStorage* other); 126 void LinkTo(PreallocatedStorage* other);
133 void Unlink(); 127 void Unlink();
134 128
135 friend class Isolate; 129 friend class Isolate;
136
137 DISALLOW_IMPLICIT_CONSTRUCTORS(PreallocatedStorage);
138 }; 130 };
139 131
140 132
133 class Isolate;
134
135
136 class PreallocatedStorageAllocator {
137 public:
138 inline PreallocatedStorageAllocator();
139
140 inline void* New(size_t size);
141 inline void Delete(void* p);
142
143 private:
144 Isolate* isolate_;
145 };
146
141 } } // namespace v8::internal 147 } } // namespace v8::internal
142 148
143 #endif // V8_ALLOCATION_H_ 149 #endif // V8_ALLOCATION_H_
OLDNEW
« no previous file with comments | « no previous file | src/allocation-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698