OLD | NEW |
---|---|
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" |
13 #include "src/unbound-queue.h" | |
Benedikt Meurer
2015/06/19 05:00:12
Don't use the UnboundedQueue. It's only purpose is
binji
2015/06/19 06:02:04
Done. See fix in patch #3 here https://codereview.
| |
12 #include "src/v8.h" | 14 #include "src/v8.h" |
13 #else | 15 #else |
14 #include "include/v8.h" | 16 #include "include/v8.h" |
15 #include "src/base/compiler-specific.h" | 17 #include "src/base/compiler-specific.h" |
16 #endif // !V8_SHARED | 18 #endif // !V8_SHARED |
17 | 19 |
18 namespace v8 { | 20 namespace v8 { |
19 | 21 |
20 | 22 |
21 #ifndef V8_SHARED | 23 #ifndef V8_SHARED |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 #endif // !V8_SHARED | 162 #endif // !V8_SHARED |
161 | 163 |
162 void ExitShell(int exit_code); | 164 void ExitShell(int exit_code); |
163 Handle<String> ReadFile(Isolate* isolate, const char* name); | 165 Handle<String> ReadFile(Isolate* isolate, const char* name); |
164 | 166 |
165 const char** argv_; | 167 const char** argv_; |
166 int begin_offset_; | 168 int begin_offset_; |
167 int end_offset_; | 169 int end_offset_; |
168 }; | 170 }; |
169 | 171 |
172 #ifndef V8_SHARED | |
173 enum SerializationTag { | |
174 kSerializationTagUndefined, | |
175 kSerializationTagNull, | |
176 kSerializationTagTrue, | |
177 kSerializationTagFalse, | |
178 kSerializationTagNumber, | |
179 kSerializationTagString, | |
180 kSerializationTagArray, | |
181 kSerializationTagObject, | |
182 kSerializationTagArrayBuffer, | |
183 kSerializationTagTransferredArrayBuffer, | |
184 kSerializationTagTransferredSharedArrayBuffer, | |
185 }; | |
186 | |
187 | |
188 class SerializationData { | |
189 public: | |
190 SerializationData() {} | |
191 ~SerializationData(); | |
192 | |
193 void WriteTag(SerializationTag tag); | |
194 void WriteMemory(const void* p, int length); | |
195 void WriteArrayBufferContents(const ArrayBuffer::Contents& contents); | |
196 void WriteSharedArrayBufferContents( | |
197 const SharedArrayBuffer::Contents& contents); | |
198 | |
199 template <typename T> | |
200 void Write(const T& data) { | |
201 WriteMemory(&data, sizeof(data)); | |
202 } | |
203 | |
204 SerializationTag ReadTag(int* offset) const; | |
205 void ReadMemory(void* p, int length, int* offset) const; | |
206 void ReadArrayBufferContents(ArrayBuffer::Contents* contents, | |
207 int* offset) const; | |
208 void ReadSharedArrayBufferContents(SharedArrayBuffer::Contents* contents, | |
209 int* offset) const; | |
210 | |
211 template <typename T> | |
212 T Read(int* offset) const { | |
213 T value; | |
214 ReadMemory(&value, sizeof(value), offset); | |
215 return value; | |
216 } | |
217 | |
218 private: | |
219 i::List<uint8_t> data; | |
220 i::List<ArrayBuffer::Contents> array_buffer_contents; | |
221 i::List<SharedArrayBuffer::Contents> shared_array_buffer_contents; | |
222 }; | |
223 | |
224 | |
225 class Worker { | |
226 public: | |
227 Worker(); | |
228 ~Worker(); | |
229 | |
230 void StartExecuteInThread(Isolate* isolate, const char* function_string); | |
231 void PostMessage(SerializationData* data); | |
232 SerializationData* GetMessage(); | |
233 void Terminate(); | |
234 | |
235 private: | |
236 class WorkerThread : public base::Thread { | |
237 public: | |
238 explicit WorkerThread(Worker* worker) | |
239 : base::Thread(base::Thread::Options("WorkerThread")), | |
240 worker_(worker) {} | |
241 | |
242 virtual void Run() { worker_->ExecuteInThread(); } | |
243 | |
244 private: | |
245 Worker* worker_; | |
246 }; | |
247 | |
248 typedef i::UnboundQueue<SerializationData*> SerializationDataQueue; | |
249 | |
250 void ExecuteInThread(); | |
251 static void ClearQueue(SerializationDataQueue* queue); | |
252 void Cleanup(); | |
253 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args); | |
254 | |
255 base::Mutex mutex_; | |
256 base::Semaphore in_semaphore_; | |
257 base::Semaphore out_semaphore_; | |
258 SerializationDataQueue in_queue_; | |
259 SerializationDataQueue out_queue_; | |
260 base::Thread* thread_; | |
261 char* script_; | |
262 }; | |
263 #endif // !V8_SHARED | |
264 | |
170 | 265 |
171 class ShellOptions { | 266 class ShellOptions { |
172 public: | 267 public: |
173 ShellOptions() | 268 ShellOptions() |
174 : script_executed(false), | 269 : script_executed(false), |
175 last_run(true), | 270 last_run(true), |
176 send_idle_notification(false), | 271 send_idle_notification(false), |
177 invoke_weak_callbacks(false), | 272 invoke_weak_callbacks(false), |
178 omit_quit(false), | 273 omit_quit(false), |
179 stress_opt(false), | 274 stress_opt(false), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 static void ReportException(Isolate* isolate, TryCatch* try_catch); | 334 static void ReportException(Isolate* isolate, TryCatch* try_catch); |
240 static Handle<String> ReadFile(Isolate* isolate, const char* name); | 335 static Handle<String> ReadFile(Isolate* isolate, const char* name); |
241 static Local<Context> CreateEvaluationContext(Isolate* isolate); | 336 static Local<Context> CreateEvaluationContext(Isolate* isolate); |
242 static int RunMain(Isolate* isolate, int argc, char* argv[]); | 337 static int RunMain(Isolate* isolate, int argc, char* argv[]); |
243 static int Main(int argc, char* argv[]); | 338 static int Main(int argc, char* argv[]); |
244 static void Exit(int exit_code); | 339 static void Exit(int exit_code); |
245 static void OnExit(Isolate* isolate); | 340 static void OnExit(Isolate* isolate); |
246 static void CollectGarbage(Isolate* isolate); | 341 static void CollectGarbage(Isolate* isolate); |
247 | 342 |
248 #ifndef V8_SHARED | 343 #ifndef V8_SHARED |
344 // TODO(binji): stupid implementation for now. Is there an easy way to hash an | |
345 // object for use in i::HashMap? By pointer? | |
346 typedef i::List<Handle<Object>> ObjectList; | |
347 static bool SerializeValue(Isolate* isolate, Handle<Value> value, | |
348 const ObjectList& to_transfer, | |
349 ObjectList* seen_objects, | |
350 SerializationData* out_data); | |
351 static MaybeLocal<Value> DeserializeValue(Isolate* isolate, | |
352 const SerializationData& data, | |
353 int* offset); | |
354 static void CleanupWorkers(); | |
249 static Handle<Array> GetCompletions(Isolate* isolate, | 355 static Handle<Array> GetCompletions(Isolate* isolate, |
250 Handle<String> text, | 356 Handle<String> text, |
251 Handle<String> full); | 357 Handle<String> full); |
252 static int* LookupCounter(const char* name); | 358 static int* LookupCounter(const char* name); |
253 static void* CreateHistogram(const char* name, | 359 static void* CreateHistogram(const char* name, |
254 int min, | 360 int min, |
255 int max, | 361 int max, |
256 size_t buckets); | 362 size_t buckets); |
257 static void AddHistogramSample(void* histogram, int sample); | 363 static void AddHistogramSample(void* histogram, int sample); |
258 static void MapCounters(v8::Isolate* isolate, const char* name); | 364 static void MapCounters(v8::Isolate* isolate, const char* name); |
(...skipping 23 matching lines...) Expand all Loading... | |
282 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args); | 388 static void Write(const v8::FunctionCallbackInfo<v8::Value>& args); |
283 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); | 389 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); |
284 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); | 390 static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); |
285 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args); | 391 static void Read(const v8::FunctionCallbackInfo<v8::Value>& args); |
286 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); | 392 static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); |
287 static Handle<String> ReadFromStdin(Isolate* isolate); | 393 static Handle<String> ReadFromStdin(Isolate* isolate); |
288 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { | 394 static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { |
289 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate())); | 395 args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate())); |
290 } | 396 } |
291 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args); | 397 static void Load(const v8::FunctionCallbackInfo<v8::Value>& args); |
398 static void WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args); | |
399 static void WorkerPostMessage( | |
400 const v8::FunctionCallbackInfo<v8::Value>& args); | |
401 static void WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args); | |
402 static void WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args); | |
292 // The OS object on the global object contains methods for performing | 403 // The OS object on the global object contains methods for performing |
293 // operating system calls: | 404 // operating system calls: |
294 // | 405 // |
295 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will | 406 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will |
296 // run the command, passing the arguments to the program. The standard output | 407 // 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 | 408 // 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 | 409 // 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 | 410 // 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. | 411 // time spent waiting between receiving output characters from the program. |
301 // timeout2, if present, should be a number indicating the limit in | 412 // timeout2, if present, should be a number indicating the limit in |
(...skipping 19 matching lines...) Expand all Loading... | |
321 static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args); | 432 static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args); |
322 static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args); | 433 static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args); |
323 static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); | 434 static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); |
324 static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); | 435 static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); |
325 | 436 |
326 static void AddOSMethods(v8::Isolate* isolate, | 437 static void AddOSMethods(v8::Isolate* isolate, |
327 Handle<ObjectTemplate> os_template); | 438 Handle<ObjectTemplate> os_template); |
328 | 439 |
329 static const char* kPrompt; | 440 static const char* kPrompt; |
330 static ShellOptions options; | 441 static ShellOptions options; |
442 static ArrayBuffer::Allocator* array_buffer_allocator; | |
331 | 443 |
332 private: | 444 private: |
333 static Persistent<Context> evaluation_context_; | 445 static Persistent<Context> evaluation_context_; |
334 #ifndef V8_SHARED | 446 #ifndef V8_SHARED |
335 static Persistent<Context> utility_context_; | 447 static Persistent<Context> utility_context_; |
336 static CounterMap* counter_map_; | 448 static CounterMap* counter_map_; |
337 // We statically allocate a set of local counters to be used if we | 449 // 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 | 450 // don't want to store the stats in a memory-mapped file |
339 static CounterCollection local_counters_; | 451 static CounterCollection local_counters_; |
340 static CounterCollection* counters_; | 452 static CounterCollection* counters_; |
341 static base::OS::MemoryMappedFile* counters_file_; | 453 static base::OS::MemoryMappedFile* counters_file_; |
342 static base::Mutex context_mutex_; | 454 static base::Mutex context_mutex_; |
343 static const base::TimeTicks kInitialTicks; | 455 static const base::TimeTicks kInitialTicks; |
456 static Worker worker_; | |
457 static i::List<SharedArrayBuffer::Contents> externalized_shared_contents_; | |
344 | 458 |
345 static Counter* GetCounter(const char* name, bool is_histogram); | 459 static Counter* GetCounter(const char* name, bool is_histogram); |
346 static void InstallUtilityScript(Isolate* isolate); | 460 static void InstallUtilityScript(Isolate* isolate); |
347 #endif // !V8_SHARED | 461 #endif // !V8_SHARED |
348 static void Initialize(Isolate* isolate); | 462 static void Initialize(Isolate* isolate); |
349 static void InitializeDebugger(Isolate* isolate); | 463 static void InitializeDebugger(Isolate* isolate); |
350 static void RunShell(Isolate* isolate); | 464 static void RunShell(Isolate* isolate); |
351 static bool SetOptions(int argc, char* argv[]); | 465 static bool SetOptions(int argc, char* argv[]); |
352 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); | 466 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); |
353 }; | 467 }; |
354 | 468 |
355 | 469 |
356 } // namespace v8 | 470 } // namespace v8 |
357 | 471 |
358 | 472 |
359 #endif // V8_D8_H_ | 473 #endif // V8_D8_H_ |
OLD | NEW |