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

Side by Side Diff: src/d8.h

Issue 1191373005: Revert of 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: 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"
12 #include "src/smart-pointers.h" 11 #include "src/smart-pointers.h"
13 #include "src/v8.h" 12 #include "src/v8.h"
14 #else 13 #else
15 #include "include/v8.h" 14 #include "include/v8.h"
16 #include "src/base/compiler-specific.h" 15 #include "src/base/compiler-specific.h"
17 #endif // !V8_SHARED 16 #endif // !V8_SHARED
18 17
19 namespace v8 { 18 namespace v8 {
20 19
21 20
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 #endif // !V8_SHARED 160 #endif // !V8_SHARED
162 161
163 void ExitShell(int exit_code); 162 void ExitShell(int exit_code);
164 Handle<String> ReadFile(Isolate* isolate, const char* name); 163 Handle<String> ReadFile(Isolate* isolate, const char* name);
165 164
166 const char** argv_; 165 const char** argv_;
167 int begin_offset_; 166 int begin_offset_;
168 int end_offset_; 167 int end_offset_;
169 }; 168 };
170 169
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
273 170
274 class ShellOptions { 171 class ShellOptions {
275 public: 172 public:
276 ShellOptions() 173 ShellOptions()
277 : script_executed(false), 174 : script_executed(false),
278 last_run(true), 175 last_run(true),
279 send_idle_notification(false), 176 send_idle_notification(false),
280 invoke_weak_callbacks(false), 177 invoke_weak_callbacks(false),
281 omit_quit(false), 178 omit_quit(false),
282 stress_opt(false), 179 stress_opt(false),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 static void ReportException(Isolate* isolate, TryCatch* try_catch); 239 static void ReportException(Isolate* isolate, TryCatch* try_catch);
343 static Handle<String> ReadFile(Isolate* isolate, const char* name); 240 static Handle<String> ReadFile(Isolate* isolate, const char* name);
344 static Local<Context> CreateEvaluationContext(Isolate* isolate); 241 static Local<Context> CreateEvaluationContext(Isolate* isolate);
345 static int RunMain(Isolate* isolate, int argc, char* argv[]); 242 static int RunMain(Isolate* isolate, int argc, char* argv[]);
346 static int Main(int argc, char* argv[]); 243 static int Main(int argc, char* argv[]);
347 static void Exit(int exit_code); 244 static void Exit(int exit_code);
348 static void OnExit(Isolate* isolate); 245 static void OnExit(Isolate* isolate);
349 static void CollectGarbage(Isolate* isolate); 246 static void CollectGarbage(Isolate* isolate);
350 247
351 #ifndef V8_SHARED 248 #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();
363 static Handle<Array> GetCompletions(Isolate* isolate, 249 static Handle<Array> GetCompletions(Isolate* isolate,
364 Handle<String> text, 250 Handle<String> text,
365 Handle<String> full); 251 Handle<String> full);
366 static int* LookupCounter(const char* name); 252 static int* LookupCounter(const char* name);
367 static void* CreateHistogram(const char* name, 253 static void* CreateHistogram(const char* name,
368 int min, 254 int min,
369 int max, 255 int max,
370 size_t buckets); 256 size_t buckets);
371 static void AddHistogramSample(void* histogram, int sample); 257 static void AddHistogramSample(void* histogram, int sample);
372 static void MapCounters(v8::Isolate* isolate, const char* name); 258 static void MapCounters(v8::Isolate* isolate, const char* name);
(...skipping 23 matching lines...) Expand all
396 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args); 282 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
397 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); 283 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
398 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); 284 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
399 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args); 285 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
400 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); 286 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
401 static Handle<String> ReadFromStdin(Isolate* isolate); 287 static Handle<String> ReadFromStdin(Isolate* isolate);
402 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { 288 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
403 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate())); 289 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
404 } 290 }
405 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args); 291 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);
411 // The OS object on the global object contains methods for performing 292 // The OS object on the global object contains methods for performing
412 // operating system calls: 293 // operating system calls:
413 // 294 //
414 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will 295 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will
415 // run the command, passing the arguments to the program. The standard output 296 // run the command, passing the arguments to the program. The standard output
416 // of the program will be picked up and returned as a multiline string. If 297 // of the program will be picked up and returned as a multiline string. If
417 // timeout1 is present then it should be a number. -1 indicates no timeout 298 // timeout1 is present then it should be a number. -1 indicates no timeout
418 // and a positive number is used as a timeout in milliseconds that limits the 299 // and a positive number is used as a timeout in milliseconds that limits the
419 // time spent waiting between receiving output characters from the program. 300 // time spent waiting between receiving output characters from the program.
420 // timeout2, if present, should be a number indicating the limit in 301 // timeout2, if present, should be a number indicating the limit in
(...skipping 19 matching lines...) Expand all
440 static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args); 321 static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
441 static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args); 322 static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args);
442 static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); 323 static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
443 static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); 324 static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
444 325
445 static void AddOSMethods(v8::Isolate* isolate, 326 static void AddOSMethods(v8::Isolate* isolate,
446 Handle<ObjectTemplate> os_template); 327 Handle<ObjectTemplate> os_template);
447 328
448 static const char* kPrompt; 329 static const char* kPrompt;
449 static ShellOptions options; 330 static ShellOptions options;
450 static ArrayBuffer::Allocator* array_buffer_allocator;
451 331
452 private: 332 private:
453 static Persistent<Context> evaluation_context_; 333 static Persistent<Context> evaluation_context_;
454 #ifndef V8_SHARED 334 #ifndef V8_SHARED
455 static Persistent<Context> utility_context_; 335 static Persistent<Context> utility_context_;
456 static CounterMap* counter_map_; 336 static CounterMap* counter_map_;
457 // We statically allocate a set of local counters to be used if we 337 // We statically allocate a set of local counters to be used if we
458 // don't want to store the stats in a memory-mapped file 338 // don't want to store the stats in a memory-mapped file
459 static CounterCollection local_counters_; 339 static CounterCollection local_counters_;
460 static CounterCollection* counters_; 340 static CounterCollection* counters_;
461 static base::OS::MemoryMappedFile* counters_file_; 341 static base::OS::MemoryMappedFile* counters_file_;
462 static base::Mutex context_mutex_; 342 static base::Mutex context_mutex_;
463 static const base::TimeTicks kInitialTicks; 343 static const base::TimeTicks kInitialTicks;
464 static Worker worker_;
465 static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_;
466 344
467 static Counter* GetCounter(const char* name, bool is_histogram); 345 static Counter* GetCounter(const char* name, bool is_histogram);
468 static void InstallUtilityScript(Isolate* isolate); 346 static void InstallUtilityScript(Isolate* isolate);
469 #endif // !V8_SHARED 347 #endif // !V8_SHARED
470 static void Initialize(Isolate* isolate); 348 static void Initialize(Isolate* isolate);
471 static void InitializeDebugger(Isolate* isolate); 349 static void InitializeDebugger(Isolate* isolate);
472 static void RunShell(Isolate* isolate); 350 static void RunShell(Isolate* isolate);
473 static bool SetOptions(int argc, char* argv[]); 351 static bool SetOptions(int argc, char* argv[]);
474 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); 352 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
475 }; 353 };
476 354
477 355
478 } // namespace v8 356 } // namespace v8
479 357
480 358
481 #endif // V8_D8_H_ 359 #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