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

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

Issue 974943003: Fix Initialize & Dispose for external snapshot. (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 bool empty() { return holder_ == NULL; }
135 static void Dispose() { 136 static void Dispose() {
136 DCHECK(holder_);
137 delete holder_; 137 delete holder_;
138 holder_ = NULL;
138 } 139 }
139 140
140 private: 141 private:
141 static NativesStore* holder_; 142 static NativesStore* holder_;
142 }; 143 };
143 144
144 template<NativeType type> 145 template<NativeType type>
145 NativesStore* NativesHolder<type>::holder_ = NULL; 146 NativesStore* NativesHolder<type>::holder_ = NULL;
146 147
147 148
149 // The natives blob. Memory is owned by caller.
150 static StartupData* natives_blob_ = NULL;
151
152
148 /** 153 /**
149 * Read the Natives (library sources) blob, as generated by js2c + the build 154 * Read the Natives blob, as previously set by SetNativesFromFile.
155 */
156 void ReadNatives() {
157 if (natives_blob_ && NativesHolder<CORE>::empty()) {
158 SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size);
159 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes));
160 NativesHolder<EXPERIMENTAL>::set(
161 NativesStore::MakeFromScriptsSource(&bytes));
162 DCHECK(!bytes.HasMore());
163 }
164 }
165
166
167 /**
168 * Set the Natives (library sources) blob, as generated by js2c + the build
150 * system. 169 * system.
151 */ 170 */
152 void SetNativesFromFile(StartupData* natives_blob) { 171 void SetNativesFromFile(StartupData* natives_blob) {
172 DCHECK(!natives_blob_);
153 DCHECK(natives_blob); 173 DCHECK(natives_blob);
154 DCHECK(natives_blob->data); 174 DCHECK(natives_blob->data);
155 DCHECK(natives_blob->raw_size > 0); 175 DCHECK(natives_blob->raw_size > 0);
156 176
157 SnapshotByteSource bytes(natives_blob->data, natives_blob->raw_size); 177 natives_blob_ = natives_blob;
158 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); 178 ReadNatives();
159 NativesHolder<EXPERIMENTAL>::set(NativesStore::MakeFromScriptsSource(&bytes));
160 DCHECK(!bytes.HasMore());
161 } 179 }
162 180
163 181
164 /** 182 /**
165 * Release memory allocated by SetNativesFromFile. 183 * Release memory allocated by SetNativesFromFile.
166 */ 184 */
167 void DisposeNatives() { 185 void DisposeNatives() {
168 NativesHolder<CORE>::Dispose(); 186 NativesHolder<CORE>::Dispose();
169 NativesHolder<EXPERIMENTAL>::Dispose(); 187 NativesHolder<EXPERIMENTAL>::Dispose();
170 } 188 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 225 }
208 226
209 227
210 // The compiler can't 'see' all uses of the static methods and hence 228 // The compiler can't 'see' all uses of the static methods and hence
211 // my choice to elide them. This we'll explicitly instantiate these. 229 // my choice to elide them. This we'll explicitly instantiate these.
212 template class NativesCollection<CORE>; 230 template class NativesCollection<CORE>;
213 template class NativesCollection<EXPERIMENTAL>; 231 template class NativesCollection<EXPERIMENTAL>;
214 232
215 } // namespace v8::internal 233 } // namespace v8::internal
216 } // namespace v8 234 } // 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