Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 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 #include "allocation.h" | 31 #include "allocation.h" |
| 32 #include "v8.h" | 32 #include "v8.h" |
| 33 #include "hashmap.h" | 33 #include "hashmap.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 | 36 |
| 37 | |
| 38 namespace i = v8::internal; | 37 namespace i = v8::internal; |
| 39 | 38 |
| 40 | |
| 41 // A single counter in a counter collection. | 39 // A single counter in a counter collection. |
| 42 class Counter { | 40 class Counter { |
| 43 public: | 41 public: |
|
Søren Thygesen Gjesse
2011/06/09 10:05:48
One space indent for public/private/protected (sev
| |
| 44 static const int kMaxNameSize = 64; | 42 static const int kMaxNameSize = 64; |
| 45 int32_t* Bind(const char* name, bool histogram); | 43 int32_t* Bind(const char* name, bool histogram); |
| 46 int32_t* ptr() { return &count_; } | 44 int32_t* ptr() { |
|
Søren Thygesen Gjesse
2011/06/09 10:05:48
Why did you re-format all these accessors?
| |
| 47 int32_t count() { return count_; } | 45 return &count_; |
| 48 int32_t sample_total() { return sample_total_; } | 46 } |
| 49 bool is_histogram() { return is_histogram_; } | 47 int32_t count() { |
| 48 return count_; | |
| 49 } | |
| 50 int32_t sample_total() { | |
| 51 return sample_total_; | |
| 52 } | |
| 53 bool is_histogram() { | |
| 54 return is_histogram_; | |
| 55 } | |
| 50 void AddSample(int32_t sample); | 56 void AddSample(int32_t sample); |
| 51 private: | 57 private: |
| 52 int32_t count_; | 58 int32_t count_; |
| 53 int32_t sample_total_; | 59 int32_t sample_total_; |
| 54 bool is_histogram_; | 60 bool is_histogram_; |
| 55 uint8_t name_[kMaxNameSize]; | 61 uint8_t name_[kMaxNameSize]; |
| 56 }; | 62 }; |
| 57 | 63 |
| 58 | |
| 59 // A set of counters and associated information. An instance of this | 64 // A set of counters and associated information. An instance of this |
| 60 // class is stored directly in the memory-mapped counters file if | 65 // class is stored directly in the memory-mapped counters file if |
| 61 // the --map-counters options is used | 66 // the --map-counters options is used |
| 62 class CounterCollection { | 67 class CounterCollection { |
| 63 public: | 68 public: |
| 64 CounterCollection(); | 69 CounterCollection(); |
| 65 Counter* GetNextCounter(); | 70 Counter* GetNextCounter(); |
| 66 private: | 71 private: |
| 67 static const unsigned kMaxCounters = 256; | 72 static const unsigned kMaxCounters = 256; |
| 68 uint32_t magic_number_; | 73 uint32_t magic_number_; |
| 69 uint32_t max_counters_; | 74 uint32_t max_counters_; |
| 70 uint32_t max_name_size_; | 75 uint32_t max_name_size_; |
| 71 uint32_t counters_in_use_; | 76 uint32_t counters_in_use_; |
| 72 Counter counters_[kMaxCounters]; | 77 Counter counters_[kMaxCounters]; |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 | |
| 76 class CounterMap { | 80 class CounterMap { |
| 77 public: | 81 public: |
| 78 CounterMap(): hash_map_(Match) { } | 82 CounterMap() : |
|
Søren Thygesen Gjesse
2011/06/09 10:05:48
If you want to format this on several lines the ':
| |
| 83 hash_map_(Match) { | |
| 84 } | |
| 79 Counter* Lookup(const char* name) { | 85 Counter* Lookup(const char* name) { |
| 80 i::HashMap::Entry* answer = hash_map_.Lookup( | 86 i::HashMap::Entry* answer = hash_map_.Lookup(const_cast<char*> (name), |
| 81 const_cast<char*>(name), | 87 Hash(name), false); |
| 82 Hash(name), | 88 if (!answer) |
| 83 false); | 89 return NULL; |
| 84 if (!answer) return NULL; | 90 return reinterpret_cast<Counter*> (answer->value); |
| 85 return reinterpret_cast<Counter*>(answer->value); | |
| 86 } | 91 } |
| 87 void Set(const char* name, Counter* value) { | 92 void Set(const char* name, Counter* value) { |
| 88 i::HashMap::Entry* answer = hash_map_.Lookup( | 93 i::HashMap::Entry* answer = hash_map_.Lookup(const_cast<char*> (name), |
| 89 const_cast<char*>(name), | 94 Hash(name), true); |
| 90 Hash(name), | |
| 91 true); | |
| 92 ASSERT(answer != NULL); | 95 ASSERT(answer != NULL); |
| 93 answer->value = value; | 96 answer->value = value; |
| 94 } | 97 } |
| 95 class Iterator { | 98 class Iterator { |
| 96 public: | 99 public: |
| 97 explicit Iterator(CounterMap* map) | 100 explicit Iterator(CounterMap* map) : |
| 98 : map_(&map->hash_map_), entry_(map_->Start()) { } | 101 map_(&map->hash_map_), entry_(map_->Start()) { |
| 99 void Next() { entry_ = map_->Next(entry_); } | 102 } |
| 100 bool More() { return entry_ != NULL; } | 103 void Next() { |
| 101 const char* CurrentKey() { return static_cast<const char*>(entry_->key); } | 104 entry_ = map_->Next(entry_); |
| 102 Counter* CurrentValue() { return static_cast<Counter*>(entry_->value); } | 105 } |
| 103 private: | 106 bool More() { |
| 107 return entry_ != NULL; | |
| 108 } | |
| 109 const char* CurrentKey() { | |
| 110 return static_cast<const char*> (entry_->key); | |
| 111 } | |
| 112 Counter* CurrentValue() { | |
| 113 return static_cast<Counter*> (entry_->value); | |
| 114 } | |
| 115 private: | |
| 104 i::HashMap* map_; | 116 i::HashMap* map_; |
| 105 i::HashMap::Entry* entry_; | 117 i::HashMap::Entry* entry_; |
| 106 }; | 118 }; |
| 107 | 119 |
| 108 private: | 120 private: |
| 109 static int Hash(const char* name); | 121 static int Hash(const char* name); |
| 110 static bool Match(void* key1, void* key2); | 122 static bool Match(void* key1, void* key2); |
| 111 i::HashMap hash_map_; | 123 i::HashMap hash_map_; |
| 112 }; | 124 }; |
| 113 | 125 |
| 114 | |
| 115 class Shell: public i::AllStatic { | 126 class Shell: public i::AllStatic { |
| 116 public: | 127 public: |
| 117 static bool ExecuteString(Handle<String> source, | 128 static bool ExecuteString(Handle<String> source, Handle<Value> name, |
|
Søren Thygesen Gjesse
2011/06/09 10:05:48
I think you should keep the original formatting of
| |
| 118 Handle<Value> name, | 129 bool print_result, bool report_exceptions); |
| 119 bool print_result, | |
| 120 bool report_exceptions); | |
| 121 static const char* ToCString(const v8::String::Utf8Value& value); | 130 static const char* ToCString(const v8::String::Utf8Value& value); |
| 122 static void ReportException(TryCatch* try_catch); | 131 static void ReportException(TryCatch* try_catch); |
| 123 static void Initialize(); | |
| 124 static void OnExit(); | 132 static void OnExit(); |
| 125 static int* LookupCounter(const char* name); | 133 static int* LookupCounter(const char* name); |
| 126 static void* CreateHistogram(const char* name, | 134 static void* CreateHistogram(const char* name, int min, int max, |
| 127 int min, | 135 size_t buckets); |
| 128 int max, | |
| 129 size_t buckets); | |
| 130 static void AddHistogramSample(void* histogram, int sample); | 136 static void AddHistogramSample(void* histogram, int sample); |
| 131 static void MapCounters(const char* name); | 137 static void MapCounters(const char* name); |
| 132 static Handle<String> ReadFile(const char* name); | 138 static Handle<String> ReadFile(const char* name); |
| 133 static void RunShell(); | 139 static void RunShell(); |
| 140 static void RenewEvalContext(); | |
| 141 static void Initialize(); | |
| 142 static void InstallUtilScript(); | |
| 143 static int RunMain(int argc, char* argv[]); | |
| 134 static int Main(int argc, char* argv[]); | 144 static int Main(int argc, char* argv[]); |
| 135 static Handle<Array> GetCompletions(Handle<String> text, | 145 static Handle<Array> GetCompletions(Handle<String> text, Handle<String> full); |
| 136 Handle<String> full); | 146 static Handle<ObjectTemplate> CreateGlobalTemplate(); |
| 137 #ifdef ENABLE_DEBUGGER_SUPPORT | 147 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 138 static Handle<Object> DebugMessageDetails(Handle<String> message); | 148 static Handle<Object> DebugMessageDetails(Handle<String> message); |
| 139 static Handle<Value> DebugCommandToJSONRequest(Handle<String> command); | 149 static Handle<Value> DebugCommandToJSONRequest(Handle<String> command); |
| 140 #endif | 150 #endif |
| 141 | 151 |
| 142 #ifdef WIN32 | 152 #ifdef WIN32 |
| 143 #undef Yield | 153 #undef Yield |
| 144 #endif | 154 #endif |
| 145 | 155 |
| 146 static Handle<Value> Print(const Arguments& args); | 156 static Handle<Value> Print(const Arguments& args); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 static Handle<Value> System(const Arguments& args); | 200 static Handle<Value> System(const Arguments& args); |
| 191 static Handle<Value> ChangeDirectory(const Arguments& args); | 201 static Handle<Value> ChangeDirectory(const Arguments& args); |
| 192 static Handle<Value> SetEnvironment(const Arguments& args); | 202 static Handle<Value> SetEnvironment(const Arguments& args); |
| 193 static Handle<Value> UnsetEnvironment(const Arguments& args); | 203 static Handle<Value> UnsetEnvironment(const Arguments& args); |
| 194 static Handle<Value> SetUMask(const Arguments& args); | 204 static Handle<Value> SetUMask(const Arguments& args); |
| 195 static Handle<Value> MakeDirectory(const Arguments& args); | 205 static Handle<Value> MakeDirectory(const Arguments& args); |
| 196 static Handle<Value> RemoveDirectory(const Arguments& args); | 206 static Handle<Value> RemoveDirectory(const Arguments& args); |
| 197 | 207 |
| 198 static void AddOSMethods(Handle<ObjectTemplate> os_template); | 208 static void AddOSMethods(Handle<ObjectTemplate> os_template); |
| 199 | 209 |
| 200 static Handle<Context> utility_context() { return utility_context_; } | 210 static Handle<Context> utility_context() { |
| 211 return utility_context_; | |
| 212 } | |
| 201 | 213 |
| 202 static const char* kHistoryFileName; | 214 static const char* kHistoryFileName; |
| 203 static const char* kPrompt; | 215 static const char* kPrompt; |
| 204 | 216 |
| 205 private: | 217 private: |
| 206 static Persistent<Context> utility_context_; | 218 static Persistent<Context> utility_context_; |
| 207 static Persistent<Context> evaluation_context_; | 219 static Persistent<Context> evaluation_context_; |
| 208 static CounterMap* counter_map_; | 220 static CounterMap* counter_map_; |
| 209 // We statically allocate a set of local counters to be used if we | 221 // We statically allocate a set of local counters to be used if we |
| 210 // don't want to store the stats in a memory-mapped file | 222 // don't want to store the stats in a memory-mapped file |
| 211 static CounterCollection local_counters_; | 223 static CounterCollection local_counters_; |
| 212 static CounterCollection* counters_; | 224 static CounterCollection* counters_; |
| 213 static i::OS::MemoryMappedFile* counters_file_; | 225 static i::OS::MemoryMappedFile* counters_file_; |
| 214 static Counter* GetCounter(const char* name, bool is_histogram); | 226 static Counter* GetCounter(const char* name, bool is_histogram); |
| 215 static Handle<Value> CreateExternalArray(const Arguments& args, | 227 static Handle<Value> CreateExternalArray(const Arguments& args, |
| 216 ExternalArrayType type, | 228 ExternalArrayType type, int element_size); |
| 217 int element_size); | |
| 218 static void ExternalArrayWeakCallback(Persistent<Value> object, void* data); | 229 static void ExternalArrayWeakCallback(Persistent<Value> object, void* data); |
| 219 }; | 230 }; |
| 220 | 231 |
| 221 | |
| 222 class LineEditor { | 232 class LineEditor { |
| 223 public: | 233 public: |
| 224 enum Type { DUMB = 0, READLINE = 1 }; | 234 enum Type { |
| 235 DUMB = 0, READLINE = 1 | |
| 236 }; | |
| 225 LineEditor(Type type, const char* name); | 237 LineEditor(Type type, const char* name); |
| 226 virtual ~LineEditor() { } | 238 virtual ~LineEditor() { |
| 239 } | |
| 227 | 240 |
| 228 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0; | 241 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0; |
| 229 virtual bool Open() { return true; } | 242 virtual bool Open() { |
| 230 virtual bool Close() { return true; } | 243 return true; |
| 231 virtual void AddHistory(const char* str) { } | 244 } |
| 245 virtual bool Close() { | |
| 246 return true; | |
| 247 } | |
| 248 virtual void AddHistory(const char* str) { | |
| 249 } | |
| 232 | 250 |
| 233 const char* name() { return name_; } | 251 const char* name() { |
| 252 return name_; | |
| 253 } | |
| 234 static LineEditor* Get(); | 254 static LineEditor* Get(); |
| 235 private: | 255 private: |
| 236 Type type_; | 256 Type type_; |
| 237 const char* name_; | 257 const char* name_; |
| 238 LineEditor* next_; | 258 LineEditor* next_; |
| 239 static LineEditor* first_; | 259 static LineEditor* first_; |
| 240 }; | 260 }; |
| 241 | 261 |
| 242 | 262 } // namespace v8 |
| 243 } // namespace v8 | |
| 244 | 263 |
| 245 | 264 |
| 246 #endif // V8_D8_H_ | 265 #endif // V8_D8_H_ |
| OLD | NEW |