| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_D8_H_ | 28 #ifndef V8_D8_H_ |
| 29 #define V8_D8_H_ | 29 #define V8_D8_H_ |
| 30 | 30 |
| 31 |
| 32 #ifndef D8_LIGHT |
| 33 #include "v8.h" |
| 31 #include "allocation.h" | 34 #include "allocation.h" |
| 32 #include "v8.h" | |
| 33 #include "hashmap.h" | 35 #include "hashmap.h" |
| 36 #else |
| 37 #include "../include/v8.h" |
| 38 #endif // D8_LIGHT |
| 34 | 39 |
| 35 namespace v8 { | 40 namespace v8 { |
| 36 | 41 |
| 37 | 42 #ifndef D8_LIGHT |
| 38 namespace i = v8::internal; | 43 namespace i = v8::internal; |
| 44 #endif // D8_LIGHT |
| 39 | 45 |
| 40 | 46 |
| 47 #ifndef D8_LIGHT |
| 41 // A single counter in a counter collection. | 48 // A single counter in a counter collection. |
| 42 class Counter { | 49 class Counter { |
| 43 public: | 50 public: |
| 44 static const int kMaxNameSize = 64; | 51 static const int kMaxNameSize = 64; |
| 45 int32_t* Bind(const char* name, bool histogram); | 52 int32_t* Bind(const char* name, bool histogram); |
| 46 int32_t* ptr() { return &count_; } | 53 int32_t* ptr() { return &count_; } |
| 47 int32_t count() { return count_; } | 54 int32_t count() { return count_; } |
| 48 int32_t sample_total() { return sample_total_; } | 55 int32_t sample_total() { return sample_total_; } |
| 49 bool is_histogram() { return is_histogram_; } | 56 bool is_histogram() { return is_histogram_; } |
| 50 void AddSample(int32_t sample); | 57 void AddSample(int32_t sample); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 private: | 110 private: |
| 104 i::HashMap* map_; | 111 i::HashMap* map_; |
| 105 i::HashMap::Entry* entry_; | 112 i::HashMap::Entry* entry_; |
| 106 }; | 113 }; |
| 107 | 114 |
| 108 private: | 115 private: |
| 109 static int Hash(const char* name); | 116 static int Hash(const char* name); |
| 110 static bool Match(void* key1, void* key2); | 117 static bool Match(void* key1, void* key2); |
| 111 i::HashMap hash_map_; | 118 i::HashMap hash_map_; |
| 112 }; | 119 }; |
| 120 #endif // D8_LIGHT |
| 113 | 121 |
| 114 | 122 |
| 115 class SourceGroup { | 123 class SourceGroup { |
| 116 public: | 124 public: |
| 117 SourceGroup() | 125 SourceGroup() : |
| 118 : next_semaphore_(v8::internal::OS::CreateSemaphore(0)), | 126 #ifndef D8_LIGHT |
| 119 done_semaphore_(v8::internal::OS::CreateSemaphore(0)), | 127 next_semaphore_(v8::internal::OS::CreateSemaphore(0)), |
| 120 thread_(NULL), | 128 done_semaphore_(v8::internal::OS::CreateSemaphore(0)), |
| 121 argv_(NULL), | 129 thread_(NULL), |
| 122 begin_offset_(0), | 130 #endif // D8_LIGHT |
| 123 end_offset_(0) { } | 131 argv_(NULL), |
| 132 begin_offset_(0), |
| 133 end_offset_(0) { } |
| 124 | 134 |
| 125 void Begin(char** argv, int offset) { | 135 void Begin(char** argv, int offset) { |
| 126 argv_ = const_cast<const char**>(argv); | 136 argv_ = const_cast<const char**>(argv); |
| 127 begin_offset_ = offset; | 137 begin_offset_ = offset; |
| 128 } | 138 } |
| 129 | 139 |
| 130 void End(int offset) { end_offset_ = offset; } | 140 void End(int offset) { end_offset_ = offset; } |
| 131 | 141 |
| 132 void Execute(); | 142 void Execute(); |
| 133 | 143 |
| 144 #ifndef D8_LIGHT |
| 134 void StartExecuteInThread(); | 145 void StartExecuteInThread(); |
| 135 void WaitForThread(); | 146 void WaitForThread(); |
| 136 | 147 |
| 137 private: | 148 private: |
| 138 class IsolateThread : public i::Thread { | 149 class IsolateThread : public i::Thread { |
| 139 public: | 150 public: |
| 140 explicit IsolateThread(SourceGroup* group) | 151 explicit IsolateThread(SourceGroup* group) |
| 141 : i::Thread(GetThreadOptions()), group_(group) {} | 152 : i::Thread(GetThreadOptions()), group_(group) {} |
| 142 | 153 |
| 143 virtual void Run() { | 154 virtual void Run() { |
| 144 group_->ExecuteInThread(); | 155 group_->ExecuteInThread(); |
| 145 } | 156 } |
| 146 | 157 |
| 147 private: | 158 private: |
| 148 SourceGroup* group_; | 159 SourceGroup* group_; |
| 149 }; | 160 }; |
| 150 | 161 |
| 151 static i::Thread::Options GetThreadOptions(); | 162 static i::Thread::Options GetThreadOptions(); |
| 152 void ExecuteInThread(); | 163 void ExecuteInThread(); |
| 153 | 164 |
| 154 i::Semaphore* next_semaphore_; | 165 i::Semaphore* next_semaphore_; |
| 155 i::Semaphore* done_semaphore_; | 166 i::Semaphore* done_semaphore_; |
| 156 i::Thread* thread_; | 167 i::Thread* thread_; |
| 168 #endif // D8_LIGHT |
| 157 | 169 |
| 158 void ExitShell(int exit_code); | 170 void ExitShell(int exit_code); |
| 159 Handle<String> ReadFile(const char* name); | 171 Handle<String> ReadFile(const char* name); |
| 160 | 172 |
| 161 const char** argv_; | 173 const char** argv_; |
| 162 int begin_offset_; | 174 int begin_offset_; |
| 163 int end_offset_; | 175 int end_offset_; |
| 164 }; | 176 }; |
| 165 | 177 |
| 166 | 178 |
| 167 class ShellOptions { | 179 class ShellOptions { |
| 168 public: | 180 public: |
| 169 ShellOptions() | 181 ShellOptions() : |
| 170 : script_executed(false), | 182 #ifndef D8_LIGHT |
| 171 last_run(true), | 183 use_preemption(true), |
| 172 stress_opt(false), | 184 preemption_interval(10), |
| 173 stress_deopt(false), | 185 parallel_files(NULL), |
| 174 interactive_shell(false), | 186 #endif // D8_LIGHT |
| 175 test_shell(false), | 187 script_executed(false), |
| 176 use_preemption(true), | 188 last_run(true), |
| 177 preemption_interval(10), | 189 stress_opt(false), |
| 178 num_isolates(1), | 190 stress_deopt(false), |
| 179 isolate_sources(NULL), | 191 interactive_shell(false), |
| 180 parallel_files(NULL) { } | 192 test_shell(false), |
| 193 num_isolates(1), |
| 194 isolate_sources(NULL) { } |
| 181 | 195 |
| 196 #ifndef D8_LIGHT |
| 197 bool use_preemption; |
| 198 int preemption_interval; |
| 199 i::List< i::Vector<const char> >* parallel_files; |
| 200 #endif // D8_LIGHT |
| 182 bool script_executed; | 201 bool script_executed; |
| 183 bool last_run; | 202 bool last_run; |
| 184 bool stress_opt; | 203 bool stress_opt; |
| 185 bool stress_deopt; | 204 bool stress_deopt; |
| 186 bool interactive_shell; | 205 bool interactive_shell; |
| 187 bool test_shell; | 206 bool test_shell; |
| 188 bool use_preemption; | |
| 189 int preemption_interval; | |
| 190 int num_isolates; | 207 int num_isolates; |
| 191 SourceGroup* isolate_sources; | 208 SourceGroup* isolate_sources; |
| 192 i::List< i::Vector<const char> >* parallel_files; | |
| 193 }; | 209 }; |
| 194 | 210 |
| 195 | 211 |
| 196 class Shell: public i::AllStatic { | 212 class Shell |
| 213 #ifndef D8_LIGHT |
| 214 : public i::AllStatic |
| 215 #endif // D8_LIGHT |
| 216 { |
| 197 public: | 217 public: |
| 198 static bool ExecuteString(Handle<String> source, | 218 static bool ExecuteString(Handle<String> source, |
| 199 Handle<Value> name, | 219 Handle<Value> name, |
| 200 bool print_result, | 220 bool print_result, |
| 201 bool report_exceptions); | 221 bool report_exceptions); |
| 202 static const char* ToCString(const v8::String::Utf8Value& value); | 222 static const char* ToCString(const v8::String::Utf8Value& value); |
| 203 static void ReportException(TryCatch* try_catch); | 223 static void ReportException(TryCatch* try_catch); |
| 224 static Handle<String> ReadFile(const char* name); |
| 225 static Persistent<Context> CreateEvaluationContext(); |
| 226 static int RunMain(int argc, char* argv[]); |
| 227 static int Main(int argc, char* argv[]); |
| 228 |
| 229 #ifndef D8_LIGHT |
| 230 static Handle<Array> GetCompletions(Handle<String> text, |
| 231 Handle<String> full); |
| 204 static void OnExit(); | 232 static void OnExit(); |
| 205 static int* LookupCounter(const char* name); | 233 static int* LookupCounter(const char* name); |
| 206 static void* CreateHistogram(const char* name, | 234 static void* CreateHistogram(const char* name, |
| 207 int min, | 235 int min, |
| 208 int max, | 236 int max, |
| 209 size_t buckets); | 237 size_t buckets); |
| 210 static void AddHistogramSample(void* histogram, int sample); | 238 static void AddHistogramSample(void* histogram, int sample); |
| 211 static void MapCounters(const char* name); | 239 static void MapCounters(const char* name); |
| 212 static Handle<String> ReadFile(const char* name); | 240 #endif // D8_LIGHT |
| 213 static void Initialize(); | 241 |
| 214 static Persistent<Context> CreateEvaluationContext(); | |
| 215 static void InstallUtilityScript(); | |
| 216 static void RunShell(); | |
| 217 static bool SetOptions(int argc, char* argv[]); | |
| 218 static int RunScript(char* filename); | |
| 219 static int RunMain(int argc, char* argv[]); | |
| 220 static int Main(int argc, char* argv[]); | |
| 221 static Handle<ObjectTemplate> CreateGlobalTemplate(); | |
| 222 static Handle<Array> GetCompletions(Handle<String> text, | |
| 223 Handle<String> full); | |
| 224 #ifdef ENABLE_DEBUGGER_SUPPORT | 242 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 225 static Handle<Object> DebugMessageDetails(Handle<String> message); | 243 static Handle<Object> DebugMessageDetails(Handle<String> message); |
| 226 static Handle<Value> DebugCommandToJSONRequest(Handle<String> command); | 244 static Handle<Value> DebugCommandToJSONRequest(Handle<String> command); |
| 227 #endif | 245 #endif |
| 228 | 246 |
| 229 #ifdef WIN32 | 247 #ifdef WIN32 |
| 230 #undef Yield | 248 #undef Yield |
| 231 #endif | 249 #endif |
| 232 | 250 |
| 233 static Handle<Value> Print(const Arguments& args); | 251 static Handle<Value> Print(const Arguments& args); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 static Handle<Value> OSObject(const Arguments& args); | 294 static Handle<Value> OSObject(const Arguments& args); |
| 277 static Handle<Value> System(const Arguments& args); | 295 static Handle<Value> System(const Arguments& args); |
| 278 static Handle<Value> ChangeDirectory(const Arguments& args); | 296 static Handle<Value> ChangeDirectory(const Arguments& args); |
| 279 static Handle<Value> SetEnvironment(const Arguments& args); | 297 static Handle<Value> SetEnvironment(const Arguments& args); |
| 280 static Handle<Value> UnsetEnvironment(const Arguments& args); | 298 static Handle<Value> UnsetEnvironment(const Arguments& args); |
| 281 static Handle<Value> SetUMask(const Arguments& args); | 299 static Handle<Value> SetUMask(const Arguments& args); |
| 282 static Handle<Value> MakeDirectory(const Arguments& args); | 300 static Handle<Value> MakeDirectory(const Arguments& args); |
| 283 static Handle<Value> RemoveDirectory(const Arguments& args); | 301 static Handle<Value> RemoveDirectory(const Arguments& args); |
| 284 | 302 |
| 285 static void AddOSMethods(Handle<ObjectTemplate> os_template); | 303 static void AddOSMethods(Handle<ObjectTemplate> os_template); |
| 286 | 304 #ifndef D8_LIGHT |
| 287 static const char* kHistoryFileName; | 305 static const char* kHistoryFileName; |
| 306 #endif // D8_LIGHT |
| 288 static const char* kPrompt; | 307 static const char* kPrompt; |
| 289 | |
| 290 static ShellOptions options; | 308 static ShellOptions options; |
| 291 | 309 |
| 292 private: | 310 private: |
| 311 static Persistent<Context> evaluation_context_; |
| 312 #ifndef D8_LIGHT |
| 293 static Persistent<Context> utility_context_; | 313 static Persistent<Context> utility_context_; |
| 294 static Persistent<Context> evaluation_context_; | |
| 295 static CounterMap* counter_map_; | 314 static CounterMap* counter_map_; |
| 296 // We statically allocate a set of local counters to be used if we | 315 // We statically allocate a set of local counters to be used if we |
| 297 // don't want to store the stats in a memory-mapped file | 316 // don't want to store the stats in a memory-mapped file |
| 298 static CounterCollection local_counters_; | 317 static CounterCollection local_counters_; |
| 299 static CounterCollection* counters_; | 318 static CounterCollection* counters_; |
| 300 static i::OS::MemoryMappedFile* counters_file_; | 319 static i::OS::MemoryMappedFile* counters_file_; |
| 301 static i::Mutex* context_mutex_; | 320 static i::Mutex* context_mutex_; |
| 321 |
| 302 static Counter* GetCounter(const char* name, bool is_histogram); | 322 static Counter* GetCounter(const char* name, bool is_histogram); |
| 323 static void InstallUtilityScript(); |
| 324 #endif // D8_LIGHT |
| 325 static void Initialize(); |
| 326 static void RunShell(); |
| 327 static bool SetOptions(int argc, char* argv[]); |
| 328 static Handle<ObjectTemplate> CreateGlobalTemplate(); |
| 303 static Handle<Value> CreateExternalArray(const Arguments& args, | 329 static Handle<Value> CreateExternalArray(const Arguments& args, |
| 304 ExternalArrayType type, | 330 ExternalArrayType type, |
| 305 size_t element_size); | 331 size_t element_size); |
| 306 static void ExternalArrayWeakCallback(Persistent<Value> object, void* data); | 332 static void ExternalArrayWeakCallback(Persistent<Value> object, void* data); |
| 307 }; | 333 }; |
| 308 | 334 |
| 309 | 335 |
| 336 #ifndef D8_LIGHT |
| 310 class LineEditor { | 337 class LineEditor { |
| 311 public: | 338 public: |
| 312 enum Type { DUMB = 0, READLINE = 1 }; | 339 enum Type { DUMB = 0, READLINE = 1 }; |
| 313 LineEditor(Type type, const char* name); | 340 LineEditor(Type type, const char* name); |
| 314 virtual ~LineEditor() { } | 341 virtual ~LineEditor() { } |
| 315 | 342 |
| 316 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0; | 343 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0; |
| 317 virtual bool Open() { return true; } | 344 virtual bool Open() { return true; } |
| 318 virtual bool Close() { return true; } | 345 virtual bool Close() { return true; } |
| 319 virtual void AddHistory(const char* str) { } | 346 virtual void AddHistory(const char* str) { } |
| 320 | 347 |
| 321 const char* name() { return name_; } | 348 const char* name() { return name_; } |
| 322 static LineEditor* Get(); | 349 static LineEditor* Get(); |
| 323 private: | 350 private: |
| 324 Type type_; | 351 Type type_; |
| 325 const char* name_; | 352 const char* name_; |
| 326 LineEditor* next_; | 353 LineEditor* next_; |
| 327 static LineEditor* first_; | 354 static LineEditor* first_; |
| 328 }; | 355 }; |
| 356 #endif // D8_LIGHT |
| 329 | 357 |
| 330 | 358 |
| 331 } // namespace v8 | 359 } // namespace v8 |
| 332 | 360 |
| 333 | 361 |
| 334 #endif // V8_D8_H_ | 362 #endif // V8_D8_H_ |
| OLD | NEW |