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

Side by Side Diff: src/natives-external.cc

Issue 960883003: Fix memory leak in natives-external. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/natives.h ('k') | src/snapshot-empty.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/natives.h" 5 #include "src/natives.h"
6 6
7 #include "src/base/logging.h" 7 #include "src/base/logging.h"
8 #include "src/list.h" 8 #include "src/list.h"
9 #include "src/list-inl.h" 9 #include "src/list-inl.h"
10 #include "src/snapshot-source-sink.h" 10 #include "src/snapshot-source-sink.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 class NativesHolder { 125 class NativesHolder {
126 public: 126 public:
127 static NativesStore* get() { 127 static NativesStore* get() {
128 DCHECK(holder_); 128 DCHECK(holder_);
129 return holder_; 129 return holder_;
130 } 130 }
131 static void set(NativesStore* store) { 131 static void set(NativesStore* store) {
132 DCHECK(store); 132 DCHECK(store);
133 holder_ = store; 133 holder_ = store;
134 } 134 }
135 static void Dispose() {
136 DCHECK(holder_);
137 delete holder_;
138 }
135 139
136 private: 140 private:
137 static NativesStore* holder_; 141 static NativesStore* holder_;
138 }; 142 };
139 143
140 template<NativeType type> 144 template<NativeType type>
141 NativesStore* NativesHolder<type>::holder_ = NULL; 145 NativesStore* NativesHolder<type>::holder_ = NULL;
142 146
143 147
144 /** 148 /**
145 * Read the Natives (library sources) blob, as generated by js2c + the build 149 * Read the Natives (library sources) blob, as generated by js2c + the build
146 * system. 150 * system.
147 */ 151 */
148 void SetNativesFromFile(StartupData* natives_blob) { 152 void SetNativesFromFile(StartupData* natives_blob) {
149 DCHECK(natives_blob); 153 DCHECK(natives_blob);
150 DCHECK(natives_blob->data); 154 DCHECK(natives_blob->data);
151 DCHECK(natives_blob->raw_size > 0); 155 DCHECK(natives_blob->raw_size > 0);
152 156
153 SnapshotByteSource bytes(natives_blob->data, natives_blob->raw_size); 157 SnapshotByteSource bytes(natives_blob->data, natives_blob->raw_size);
154 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); 158 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes));
155 NativesHolder<EXPERIMENTAL>::set(NativesStore::MakeFromScriptsSource(&bytes)); 159 NativesHolder<EXPERIMENTAL>::set(NativesStore::MakeFromScriptsSource(&bytes));
156 DCHECK(!bytes.HasMore()); 160 DCHECK(!bytes.HasMore());
157 } 161 }
158 162
159 163
164 /**
165 * Release memory allocated by SetNativesFromFile.
166 */
167 void DisposeNatives() {
168 NativesHolder<CORE>::Dispose();
169 NativesHolder<EXPERIMENTAL>::Dispose();
170 }
171
172
160 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. 173 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore.
161 // 174 //
162 // (The callers expect a purely static interface, since this is how the 175 // (The callers expect a purely static interface, since this is how the
163 // natives are usually compiled in. Since we implement them based on 176 // natives are usually compiled in. Since we implement them based on
164 // runtime content, we have to implement this indirection to offer 177 // runtime content, we have to implement this indirection to offer
165 // a static interface.) 178 // a static interface.)
166 template<NativeType type> 179 template<NativeType type>
167 int NativesCollection<type>::GetBuiltinsCount() { 180 int NativesCollection<type>::GetBuiltinsCount() {
168 return NativesHolder<type>::get()->GetBuiltinsCount(); 181 return NativesHolder<type>::get()->GetBuiltinsCount();
169 } 182 }
(...skipping 24 matching lines...) Expand all
194 } 207 }
195 208
196 209
197 // The compiler can't 'see' all uses of the static methods and hence 210 // The compiler can't 'see' all uses of the static methods and hence
198 // my choice to elide them. This we'll explicitly instantiate these. 211 // my choice to elide them. This we'll explicitly instantiate these.
199 template class NativesCollection<CORE>; 212 template class NativesCollection<CORE>;
200 template class NativesCollection<EXPERIMENTAL>; 213 template class NativesCollection<EXPERIMENTAL>;
201 214
202 } // namespace v8::internal 215 } // namespace v8::internal
203 } // namespace v8 216 } // namespace v8
OLDNEW
« no previous file with comments | « src/natives.h ('k') | src/snapshot-empty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698