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

Side by Side Diff: src/d8.h

Issue 1195613003: Add d8 API for spawning function on a new thread (Second try) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove UnboundQueue Created 5 years, 6 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 | « no previous file | src/d8.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 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_D8_H_ 5 #ifndef V8_D8_H_
6 #define V8_D8_H_ 6 #define V8_D8_H_
7 7
8 #ifndef V8_SHARED 8 #ifndef V8_SHARED
9 #include "src/allocation.h" 9 #include "src/allocation.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
11 #include "src/list.h"
11 #include "src/smart-pointers.h" 12 #include "src/smart-pointers.h"
12 #include "src/v8.h" 13 #include "src/v8.h"
13 #else 14 #else
14 #include "include/v8.h" 15 #include "include/v8.h"
15 #include "src/base/compiler-specific.h" 16 #include "src/base/compiler-specific.h"
16 #endif // !V8_SHARED 17 #endif // !V8_SHARED
17 18
18 namespace v8 { 19 namespace v8 {
19 20
20 21
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 #endif // !V8_SHARED 161 #endif // !V8_SHARED
161 162
162 void ExitShell(int exit_code); 163 void ExitShell(int exit_code);
163 Handle<String> ReadFile(Isolate* isolate, const char* name); 164 Handle<String> ReadFile(Isolate* isolate, const char* name);
164 165
165 const char** argv_; 166 const char** argv_;
166 int begin_offset_; 167 int begin_offset_;
167 int end_offset_; 168 int end_offset_;
168 }; 169 };
169 170
171 #ifndef V8_SHARED
172 enum SerializationTag {
173 kSerializationTagUndefined,
174 kSerializationTagNull,
175 kSerializationTagTrue,
176 kSerializationTagFalse,
177 kSerializationTagNumber,
178 kSerializationTagString,
179 kSerializationTagArray,
180 kSerializationTagObject,
181 kSerializationTagArrayBuffer,
182 kSerializationTagTransferredArrayBuffer,
183 kSerializationTagTransferredSharedArrayBuffer,
184 };
185
186
187 class SerializationData {
188 public:
189 SerializationData() {}
190 ~SerializationData();
191
192 void WriteTag(SerializationTag tag);
193 void WriteMemory(const void* p, int length);
194 void WriteArrayBufferContents(const ArrayBuffer::Contents& contents);
195 void WriteSharedArrayBufferContents(
196 const SharedArrayBuffer::Contents& contents);
197
198 template <typename T>
199 void Write(const T& data) {
200 WriteMemory(&data, sizeof(data));
201 }
202
203 SerializationTag ReadTag(int* offset) const;
204 void ReadMemory(void* p, int length, int* offset) const;
205 void ReadArrayBufferContents(ArrayBuffer::Contents* contents,
206 int* offset) const;
207 void ReadSharedArrayBufferContents(SharedArrayBuffer::Contents* contents,
208 int* offset) const;
209
210 template <typename T>
211 T Read(int* offset) const {
212 T value;
213 ReadMemory(&value, sizeof(value), offset);
214 return value;
215 }
216
217 private:
218 i::List<uint8_t> data;
219 i::List<ArrayBuffer::Contents> array_buffer_contents;
220 i::List<SharedArrayBuffer::Contents> shared_array_buffer_contents;
221 };
222
223
224 class SerializationDataQueue {
225 public:
226 void Enqueue(SerializationData* data);
227 bool Dequeue(SerializationData** data);
228 bool IsEmpty();
229 void Clear();
230
231 private:
232 base::Mutex mutex_;
233 i::List<SerializationData*> data_;
234 };
235
236
237 class Worker {
238 public:
239 Worker();
240 ~Worker();
241
242 void StartExecuteInThread(Isolate* isolate, const char* function_string);
243 void PostMessage(SerializationData* data);
244 SerializationData* GetMessage();
245 void Terminate();
246
247 private:
248 class WorkerThread : public base::Thread {
249 public:
250 explicit WorkerThread(Worker* worker)
251 : base::Thread(base::Thread::Options("WorkerThread")),
252 worker_(worker) {}
253
254 virtual void Run() { worker_->ExecuteInThread(); }
255
256 private:
257 Worker* worker_;
258 };
259
260 void ExecuteInThread();
261 void Cleanup();
262 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args);
263
264 base::Semaphore in_semaphore_;
265 base::Semaphore out_semaphore_;
266 SerializationDataQueue in_queue_;
267 SerializationDataQueue out_queue_;
268 base::Thread* thread_;
269 char* script_;
270 };
271 #endif // !V8_SHARED
272
170 273
171 class ShellOptions { 274 class ShellOptions {
172 public: 275 public:
173 ShellOptions() 276 ShellOptions()
174 : script_executed(false), 277 : script_executed(false),
175 last_run(true), 278 last_run(true),
176 send_idle_notification(false), 279 send_idle_notification(false),
177 invoke_weak_callbacks(false), 280 invoke_weak_callbacks(false),
178 omit_quit(false), 281 omit_quit(false),
179 stress_opt(false), 282 stress_opt(false),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 static void ReportException(Isolate* isolate, TryCatch* try_catch); 342 static void ReportException(Isolate* isolate, TryCatch* try_catch);
240 static Handle<String> ReadFile(Isolate* isolate, const char* name); 343 static Handle<String> ReadFile(Isolate* isolate, const char* name);
241 static Local<Context> CreateEvaluationContext(Isolate* isolate); 344 static Local<Context> CreateEvaluationContext(Isolate* isolate);
242 static int RunMain(Isolate* isolate, int argc, char* argv[]); 345 static int RunMain(Isolate* isolate, int argc, char* argv[]);
243 static int Main(int argc, char* argv[]); 346 static int Main(int argc, char* argv[]);
244 static void Exit(int exit_code); 347 static void Exit(int exit_code);
245 static void OnExit(Isolate* isolate); 348 static void OnExit(Isolate* isolate);
246 static void CollectGarbage(Isolate* isolate); 349 static void CollectGarbage(Isolate* isolate);
247 350
248 #ifndef V8_SHARED 351 #ifndef V8_SHARED
352 // TODO(binji): stupid implementation for now. Is there an easy way to hash an
353 // object for use in i::HashMap? By pointer?
354 typedef i::List<Handle<Object>> ObjectList;
355 static bool SerializeValue(Isolate* isolate, Handle<Value> value,
356 const ObjectList& to_transfer,
357 ObjectList* seen_objects,
358 SerializationData* out_data);
359 static MaybeLocal<Value> DeserializeValue(Isolate* isolate,
360 const SerializationData& data,
361 int* offset);
362 static void CleanupWorkers();
249 static Handle<Array> GetCompletions(Isolate* isolate, 363 static Handle<Array> GetCompletions(Isolate* isolate,
250 Handle<String> text, 364 Handle<String> text,
251 Handle<String> full); 365 Handle<String> full);
252 static int* LookupCounter(const char* name); 366 static int* LookupCounter(const char* name);
253 static void* CreateHistogram(const char* name, 367 static void* CreateHistogram(const char* name,
254 int min, 368 int min,
255 int max, 369 int max,
256 size_t buckets); 370 size_t buckets);
257 static void AddHistogramSample(void* histogram, int sample); 371 static void AddHistogramSample(void* histogram, int sample);
258 static void MapCounters(v8::Isolate* isolate, const char* name); 372 static void MapCounters(v8::Isolate* isolate, const char* name);
(...skipping 23 matching lines...) Expand all
282 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args); 396 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
283 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); 397 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
284 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); 398 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
285 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args); 399 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
286 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); 400 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
287 static Handle<String> ReadFromStdin(Isolate* isolate); 401 static Handle<String> ReadFromStdin(Isolate* isolate);
288 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { 402 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
289 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate())); 403 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
290 } 404 }
291 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args); 405 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
406 static void WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args);
407 static void WorkerPostMessage(
408 const v8::FunctionCallbackInfo<v8::Value>& args);
409 static void WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args);
410 static void WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args);
292 // The OS object on the global object contains methods for performing 411 // The OS object on the global object contains methods for performing
293 // operating system calls: 412 // operating system calls:
294 // 413 //
295 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will 414 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will
296 // run the command, passing the arguments to the program. The standard output 415 // run the command, passing the arguments to the program. The standard output
297 // of the program will be picked up and returned as a multiline string. If 416 // of the program will be picked up and returned as a multiline string. If
298 // timeout1 is present then it should be a number. -1 indicates no timeout 417 // timeout1 is present then it should be a number. -1 indicates no timeout
299 // and a positive number is used as a timeout in milliseconds that limits the 418 // and a positive number is used as a timeout in milliseconds that limits the
300 // time spent waiting between receiving output characters from the program. 419 // time spent waiting between receiving output characters from the program.
301 // timeout2, if present, should be a number indicating the limit in 420 // timeout2, if present, should be a number indicating the limit in
(...skipping 19 matching lines...) Expand all
321 static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args); 440 static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
322 static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args); 441 static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args);
323 static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); 442 static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
324 static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); 443 static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
325 444
326 static void AddOSMethods(v8::Isolate* isolate, 445 static void AddOSMethods(v8::Isolate* isolate,
327 Handle<ObjectTemplate> os_template); 446 Handle<ObjectTemplate> os_template);
328 447
329 static const char* kPrompt; 448 static const char* kPrompt;
330 static ShellOptions options; 449 static ShellOptions options;
450 static ArrayBuffer::Allocator* array_buffer_allocator;
331 451
332 private: 452 private:
333 static Persistent<Context> evaluation_context_; 453 static Persistent<Context> evaluation_context_;
334 #ifndef V8_SHARED 454 #ifndef V8_SHARED
335 static Persistent<Context> utility_context_; 455 static Persistent<Context> utility_context_;
336 static CounterMap* counter_map_; 456 static CounterMap* counter_map_;
337 // We statically allocate a set of local counters to be used if we 457 // We statically allocate a set of local counters to be used if we
338 // don't want to store the stats in a memory-mapped file 458 // don't want to store the stats in a memory-mapped file
339 static CounterCollection local_counters_; 459 static CounterCollection local_counters_;
340 static CounterCollection* counters_; 460 static CounterCollection* counters_;
341 static base::OS::MemoryMappedFile* counters_file_; 461 static base::OS::MemoryMappedFile* counters_file_;
342 static base::Mutex context_mutex_; 462 static base::Mutex context_mutex_;
343 static const base::TimeTicks kInitialTicks; 463 static const base::TimeTicks kInitialTicks;
464 static Worker worker_;
465 static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_;
344 466
345 static Counter* GetCounter(const char* name, bool is_histogram); 467 static Counter* GetCounter(const char* name, bool is_histogram);
346 static void InstallUtilityScript(Isolate* isolate); 468 static void InstallUtilityScript(Isolate* isolate);
347 #endif // !V8_SHARED 469 #endif // !V8_SHARED
348 static void Initialize(Isolate* isolate); 470 static void Initialize(Isolate* isolate);
349 static void InitializeDebugger(Isolate* isolate); 471 static void InitializeDebugger(Isolate* isolate);
350 static void RunShell(Isolate* isolate); 472 static void RunShell(Isolate* isolate);
351 static bool SetOptions(int argc, char* argv[]); 473 static bool SetOptions(int argc, char* argv[]);
352 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); 474 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
353 }; 475 };
354 476
355 477
356 } // namespace v8 478 } // namespace v8
357 479
358 480
359 #endif // V8_D8_H_ 481 #endif // V8_D8_H_
OLDNEW
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698