HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Oreo
|
8.0.0_r4
下载
查看原文件
收藏
根目录
external
v8
src
d8.h
// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_D8_H_ #define V8_D8_H_ #include
#include "src/allocation.h" #include "src/base/hashmap.h" #include "src/base/platform/time.h" #include "src/list.h" #include "src/base/once.h" namespace v8 { // A single counter in a counter collection. class Counter { public: static const int kMaxNameSize = 64; int32_t* Bind(const char* name, bool histogram); int32_t* ptr() { return &count_; } int32_t count() { return count_; } int32_t sample_total() { return sample_total_; } bool is_histogram() { return is_histogram_; } void AddSample(int32_t sample); private: int32_t count_; int32_t sample_total_; bool is_histogram_; uint8_t name_[kMaxNameSize]; }; // A set of counters and associated information. An instance of this // class is stored directly in the memory-mapped counters file if // the --map-counters options is used class CounterCollection { public: CounterCollection(); Counter* GetNextCounter(); private: static const unsigned kMaxCounters = 512; uint32_t magic_number_; uint32_t max_counters_; uint32_t max_name_size_; uint32_t counters_in_use_; Counter counters_[kMaxCounters]; }; class CounterMap { public: CounterMap(): hash_map_(Match) { } Counter* Lookup(const char* name) { base::HashMap::Entry* answer = hash_map_.Lookup(const_cast
(name), Hash(name)); if (!answer) return NULL; return reinterpret_cast
(answer->value); } void Set(const char* name, Counter* value) { base::HashMap::Entry* answer = hash_map_.LookupOrInsert(const_cast
(name), Hash(name)); DCHECK(answer != NULL); answer->value = value; } class Iterator { public: explicit Iterator(CounterMap* map) : map_(&map->hash_map_), entry_(map_->Start()) { } void Next() { entry_ = map_->Next(entry_); } bool More() { return entry_ != NULL; } const char* CurrentKey() { return static_cast
(entry_->key); } Counter* CurrentValue() { return static_cast
(entry_->value); } private: base::CustomMatcherHashMap* map_; base::CustomMatcherHashMap::Entry* entry_; }; private: static int Hash(const char* name); static bool Match(void* key1, void* key2); base::CustomMatcherHashMap hash_map_; }; class SourceGroup { public: SourceGroup() : next_semaphore_(0), done_semaphore_(0), thread_(NULL), argv_(NULL), begin_offset_(0), end_offset_(0) {} ~SourceGroup(); void Begin(char** argv, int offset) { argv_ = const_cast
(argv); begin_offset_ = offset; } void End(int offset) { end_offset_ = offset; } void Execute(Isolate* isolate); void StartExecuteInThread(); void WaitForThread(); void JoinThread(); private: class IsolateThread : public base::Thread { public: explicit IsolateThread(SourceGroup* group) : base::Thread(GetThreadOptions()), group_(group) {} virtual void Run() { group_->ExecuteInThread(); } private: SourceGroup* group_; }; static base::Thread::Options GetThreadOptions(); void ExecuteInThread(); base::Semaphore next_semaphore_; base::Semaphore done_semaphore_; base::Thread* thread_; void ExitShell(int exit_code); Local
ReadFile(Isolate* isolate, const char* name); const char** argv_; int begin_offset_; int end_offset_; }; enum SerializationTag { kSerializationTagUndefined, kSerializationTagNull, kSerializationTagTrue, kSerializationTagFalse, kSerializationTagNumber, kSerializationTagString, kSerializationTagArray, kSerializationTagObject, kSerializationTagArrayBuffer, kSerializationTagTransferredArrayBuffer, kSerializationTagTransferredSharedArrayBuffer, }; class SerializationData { public: SerializationData() {} ~SerializationData(); void WriteTag(SerializationTag tag); void WriteMemory(const void* p, int length); void WriteArrayBufferContents(const ArrayBuffer::Contents& contents); void WriteSharedArrayBufferContents( const SharedArrayBuffer::Contents& contents); template
void Write(const T& data) { WriteMemory(&data, sizeof(data)); } SerializationTag ReadTag(int* offset) const; void ReadMemory(void* p, int length, int* offset) const; void ReadArrayBufferContents(ArrayBuffer::Contents* contents, int* offset) const; void ReadSharedArrayBufferContents(SharedArrayBuffer::Contents* contents, int* offset) const; template
T Read(int* offset) const { T value; ReadMemory(&value, sizeof(value), offset); return value; } private: i::List
data_; i::List
array_buffer_contents_; i::List
shared_array_buffer_contents_; }; class SerializationDataQueue { public: void Enqueue(SerializationData* data); bool Dequeue(SerializationData** data); bool IsEmpty(); void Clear(); private: base::Mutex mutex_; i::List
data_; }; class Worker { public: Worker(); ~Worker(); // Run the given script on this Worker. This function should only be called // once, and should only be called by the thread that created the Worker. void StartExecuteInThread(const char* script); // Post a message to the worker's incoming message queue. The worker will // take ownership of the SerializationData. // This function should only be called by the thread that created the Worker. void PostMessage(SerializationData* data); // Synchronously retrieve messages from the worker's outgoing message queue. // If there is no message in the queue, block until a message is available. // If there are no messages in the queue and the worker is no longer running, // return nullptr. // This function should only be called by the thread that created the Worker. SerializationData* GetMessage(); // Terminate the worker's event loop. Messages from the worker that have been // queued can still be read via GetMessage(). // This function can be called by any thread. void Terminate(); // Terminate and join the thread. // This function can be called by any thread. void WaitForThread(); private: class WorkerThread : public base::Thread { public: explicit WorkerThread(Worker* worker) : base::Thread(base::Thread::Options("WorkerThread")), worker_(worker) {} virtual void Run() { worker_->ExecuteInThread(); } private: Worker* worker_; }; void ExecuteInThread(); static void PostMessageOut(const v8::FunctionCallbackInfo
& args); base::Semaphore in_semaphore_; base::Semaphore out_semaphore_; SerializationDataQueue in_queue_; SerializationDataQueue out_queue_; base::Thread* thread_; char* script_; base::Atomic32 running_; }; class ShellOptions { public: ShellOptions() : script_executed(false), send_idle_notification(false), invoke_weak_callbacks(false), omit_quit(false), stress_opt(false), stress_deopt(false), stress_runs(1), interactive_shell(false), test_shell(false), dump_heap_constants(false), expected_to_throw(false), mock_arraybuffer_allocator(false), enable_inspector(false), num_isolates(1), compile_options(v8::ScriptCompiler::kNoCompileOptions), isolate_sources(NULL), icu_data_file(NULL), natives_blob(NULL), snapshot_blob(NULL), trace_enabled(false), trace_config(NULL) {} ~ShellOptions() { delete[] isolate_sources; } bool use_interactive_shell() { return (interactive_shell || !script_executed) && !test_shell; } bool script_executed; bool send_idle_notification; bool invoke_weak_callbacks; bool omit_quit; bool stress_opt; bool stress_deopt; int stress_runs; bool interactive_shell; bool test_shell; bool dump_heap_constants; bool expected_to_throw; bool mock_arraybuffer_allocator; bool enable_inspector; int num_isolates; v8::ScriptCompiler::CompileOptions compile_options; SourceGroup* isolate_sources; const char* icu_data_file; const char* natives_blob; const char* snapshot_blob; bool trace_enabled; const char* trace_config; }; class Shell : public i::AllStatic { public: static MaybeLocal
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册