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

Side by Side Diff: src/d8.h

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/cpu-profiler-inl.h ('k') | 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 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 14 matching lines...) Expand all
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 #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 #ifdef COMPRESS_STARTUP_DATA_BZ2
36 #error Using compressed startup data is not supported for D8
37 #endif
38
39 namespace v8 { 35 namespace v8 {
40 36
41 37
42 namespace i = v8::internal; 38 namespace i = v8::internal;
43 39
44 40
45 // A single counter in a counter collection. 41 // A single counter in a counter collection.
46 class Counter { 42 class Counter {
47 public: 43 public:
48 static const int kMaxNameSize = 64; 44 static const int kMaxNameSize = 64;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 explicit Iterator(CounterMap* map) 97 explicit Iterator(CounterMap* map)
102 : map_(&map->hash_map_), entry_(map_->Start()) { } 98 : map_(&map->hash_map_), entry_(map_->Start()) { }
103 void Next() { entry_ = map_->Next(entry_); } 99 void Next() { entry_ = map_->Next(entry_); }
104 bool More() { return entry_ != NULL; } 100 bool More() { return entry_ != NULL; }
105 const char* CurrentKey() { return static_cast<const char*>(entry_->key); } 101 const char* CurrentKey() { return static_cast<const char*>(entry_->key); }
106 Counter* CurrentValue() { return static_cast<Counter*>(entry_->value); } 102 Counter* CurrentValue() { return static_cast<Counter*>(entry_->value); }
107 private: 103 private:
108 i::HashMap* map_; 104 i::HashMap* map_;
109 i::HashMap::Entry* entry_; 105 i::HashMap::Entry* entry_;
110 }; 106 };
107
111 private: 108 private:
112 static int Hash(const char* name); 109 static int Hash(const char* name);
113 static bool Match(void* key1, void* key2); 110 static bool Match(void* key1, void* key2);
114 i::HashMap hash_map_; 111 i::HashMap hash_map_;
115 }; 112 };
116 113
117 114
115 class SourceGroup {
116 public:
117 SourceGroup()
118 : next_semaphore_(v8::internal::OS::CreateSemaphore(0)),
119 done_semaphore_(v8::internal::OS::CreateSemaphore(0)),
120 thread_(NULL),
121 argv_(NULL),
122 begin_offset_(0),
123 end_offset_(0) { }
124
125 void Begin(char** argv, int offset) {
126 argv_ = const_cast<const char**>(argv);
127 begin_offset_ = offset;
128 }
129
130 void End(int offset) { end_offset_ = offset; }
131
132 void Execute();
133
134 void StartExecuteInThread();
135 void WaitForThread();
136
137 private:
138 class IsolateThread : public i::Thread {
139 public:
140 explicit IsolateThread(SourceGroup* group)
141 : i::Thread(GetThreadOptions()), group_(group) {}
142
143 virtual void Run() {
144 group_->ExecuteInThread();
145 }
146
147 private:
148 SourceGroup* group_;
149 };
150
151 static i::Thread::Options GetThreadOptions();
152 void ExecuteInThread();
153
154 i::Semaphore* next_semaphore_;
155 i::Semaphore* done_semaphore_;
156 i::Thread* thread_;
157
158 void ExitShell(int exit_code);
159 Handle<String> ReadFile(const char* name);
160
161 const char** argv_;
162 int begin_offset_;
163 int end_offset_;
164 };
165
166
167 class ShellOptions {
168 public:
169 ShellOptions()
170 : script_executed(false),
171 last_run(true),
172 stress_opt(false),
173 stress_deopt(false),
174 interactive_shell(false),
175 test_shell(false),
176 use_preemption(true),
177 preemption_interval(10),
178 num_isolates(1),
179 isolate_sources(NULL),
180 parallel_files(NULL) { }
181
182 bool script_executed;
183 bool last_run;
184 bool stress_opt;
185 bool stress_deopt;
186 bool interactive_shell;
187 bool test_shell;
188 bool use_preemption;
189 int preemption_interval;
190 int num_isolates;
191 SourceGroup* isolate_sources;
192 i::List< i::Vector<const char> >* parallel_files;
193 };
194
195
118 class Shell: public i::AllStatic { 196 class Shell: public i::AllStatic {
119 public: 197 public:
120 static bool ExecuteString(Handle<String> source, 198 static bool ExecuteString(Handle<String> source,
121 Handle<Value> name, 199 Handle<Value> name,
122 bool print_result, 200 bool print_result,
123 bool report_exceptions); 201 bool report_exceptions);
124 static const char* ToCString(const v8::String::Utf8Value& value); 202 static const char* ToCString(const v8::String::Utf8Value& value);
125 static void ReportException(TryCatch* try_catch); 203 static void ReportException(TryCatch* try_catch);
126 static void Initialize();
127 static void OnExit(); 204 static void OnExit();
128 static int* LookupCounter(const char* name); 205 static int* LookupCounter(const char* name);
129 static void* CreateHistogram(const char* name, 206 static void* CreateHistogram(const char* name,
130 int min, 207 int min,
131 int max, 208 int max,
132 size_t buckets); 209 size_t buckets);
133 static void AddHistogramSample(void* histogram, int sample); 210 static void AddHistogramSample(void* histogram, int sample);
134 static void MapCounters(const char* name); 211 static void MapCounters(const char* name);
135 static Handle<String> ReadFile(const char* name); 212 static Handle<String> ReadFile(const char* name);
213 static void Initialize();
214 static Persistent<Context> CreateEvaluationContext();
215 static void InstallUtilityScript();
136 static void RunShell(); 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[]);
137 static int Main(int argc, char* argv[]); 220 static int Main(int argc, char* argv[]);
221 static Handle<ObjectTemplate> CreateGlobalTemplate();
138 static Handle<Array> GetCompletions(Handle<String> text, 222 static Handle<Array> GetCompletions(Handle<String> text,
139 Handle<String> full); 223 Handle<String> full);
140 #ifdef ENABLE_DEBUGGER_SUPPORT 224 #ifdef ENABLE_DEBUGGER_SUPPORT
141 static Handle<Object> DebugMessageDetails(Handle<String> message); 225 static Handle<Object> DebugMessageDetails(Handle<String> message);
142 static Handle<Value> DebugCommandToJSONRequest(Handle<String> command); 226 static Handle<Value> DebugCommandToJSONRequest(Handle<String> command);
143 #endif 227 #endif
144 228
145 #ifdef WIN32 229 #ifdef WIN32
146 #undef Yield 230 #undef Yield
147 #endif 231 #endif
148 232
149 static Handle<Value> Print(const Arguments& args); 233 static Handle<Value> Print(const Arguments& args);
150 static Handle<Value> Write(const Arguments& args); 234 static Handle<Value> Write(const Arguments& args);
151 static Handle<Value> Yield(const Arguments& args); 235 static Handle<Value> Yield(const Arguments& args);
152 static Handle<Value> Quit(const Arguments& args); 236 static Handle<Value> Quit(const Arguments& args);
153 static Handle<Value> Version(const Arguments& args); 237 static Handle<Value> Version(const Arguments& args);
154 static Handle<Value> Read(const Arguments& args); 238 static Handle<Value> Read(const Arguments& args);
155 static Handle<Value> ReadLine(const Arguments& args); 239 static Handle<Value> ReadLine(const Arguments& args);
156 static Handle<Value> Load(const Arguments& args); 240 static Handle<Value> Load(const Arguments& args);
241 static Handle<Value> Int8Array(const Arguments& args);
242 static Handle<Value> Uint8Array(const Arguments& args);
243 static Handle<Value> Int16Array(const Arguments& args);
244 static Handle<Value> Uint16Array(const Arguments& args);
245 static Handle<Value> Int32Array(const Arguments& args);
246 static Handle<Value> Uint32Array(const Arguments& args);
247 static Handle<Value> Float32Array(const Arguments& args);
248 static Handle<Value> Float64Array(const Arguments& args);
249 static Handle<Value> PixelArray(const Arguments& args);
157 // The OS object on the global object contains methods for performing 250 // The OS object on the global object contains methods for performing
158 // operating system calls: 251 // operating system calls:
159 // 252 //
160 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will 253 // os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will
161 // run the command, passing the arguments to the program. The standard output 254 // run the command, passing the arguments to the program. The standard output
162 // of the program will be picked up and returned as a multiline string. If 255 // of the program will be picked up and returned as a multiline string. If
163 // timeout1 is present then it should be a number. -1 indicates no timeout 256 // timeout1 is present then it should be a number. -1 indicates no timeout
164 // and a positive number is used as a timeout in milliseconds that limits the 257 // and a positive number is used as a timeout in milliseconds that limits the
165 // time spent waiting between receiving output characters from the program. 258 // time spent waiting between receiving output characters from the program.
166 // timeout2, if present, should be a number indicating the limit in 259 // timeout2, if present, should be a number indicating the limit in
(...skipping 17 matching lines...) Expand all
184 static Handle<Value> System(const Arguments& args); 277 static Handle<Value> System(const Arguments& args);
185 static Handle<Value> ChangeDirectory(const Arguments& args); 278 static Handle<Value> ChangeDirectory(const Arguments& args);
186 static Handle<Value> SetEnvironment(const Arguments& args); 279 static Handle<Value> SetEnvironment(const Arguments& args);
187 static Handle<Value> UnsetEnvironment(const Arguments& args); 280 static Handle<Value> UnsetEnvironment(const Arguments& args);
188 static Handle<Value> SetUMask(const Arguments& args); 281 static Handle<Value> SetUMask(const Arguments& args);
189 static Handle<Value> MakeDirectory(const Arguments& args); 282 static Handle<Value> MakeDirectory(const Arguments& args);
190 static Handle<Value> RemoveDirectory(const Arguments& args); 283 static Handle<Value> RemoveDirectory(const Arguments& args);
191 284
192 static void AddOSMethods(Handle<ObjectTemplate> os_template); 285 static void AddOSMethods(Handle<ObjectTemplate> os_template);
193 286
194 static Handle<Context> utility_context() { return utility_context_; }
195
196 static const char* kHistoryFileName; 287 static const char* kHistoryFileName;
197 static const char* kPrompt; 288 static const char* kPrompt;
289
290 static ShellOptions options;
291
198 private: 292 private:
199 static Persistent<Context> utility_context_; 293 static Persistent<Context> utility_context_;
200 static Persistent<Context> evaluation_context_; 294 static Persistent<Context> evaluation_context_;
201 static CounterMap* counter_map_; 295 static CounterMap* counter_map_;
202 // We statically allocate a set of local counters to be used if we 296 // We statically allocate a set of local counters to be used if we
203 // don't want to store the stats in a memory-mapped file 297 // don't want to store the stats in a memory-mapped file
204 static CounterCollection local_counters_; 298 static CounterCollection local_counters_;
205 static CounterCollection* counters_; 299 static CounterCollection* counters_;
206 static i::OS::MemoryMappedFile* counters_file_; 300 static i::OS::MemoryMappedFile* counters_file_;
301 static i::Mutex* context_mutex_;
207 static Counter* GetCounter(const char* name, bool is_histogram); 302 static Counter* GetCounter(const char* name, bool is_histogram);
303 static Handle<Value> CreateExternalArray(const Arguments& args,
304 ExternalArrayType type,
305 size_t element_size);
306 static void ExternalArrayWeakCallback(Persistent<Value> object, void* data);
208 }; 307 };
209 308
210 309
211 class LineEditor { 310 class LineEditor {
212 public: 311 public:
213 enum Type { DUMB = 0, READLINE = 1 }; 312 enum Type { DUMB = 0, READLINE = 1 };
214 LineEditor(Type type, const char* name); 313 LineEditor(Type type, const char* name);
215 virtual ~LineEditor() { } 314 virtual ~LineEditor() { }
216 315
217 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0; 316 virtual i::SmartPointer<char> Prompt(const char* prompt) = 0;
218 virtual bool Open() { return true; } 317 virtual bool Open() { return true; }
219 virtual bool Close() { return true; } 318 virtual bool Close() { return true; }
220 virtual void AddHistory(const char* str) { } 319 virtual void AddHistory(const char* str) { }
221 320
222 const char* name() { return name_; } 321 const char* name() { return name_; }
223 static LineEditor* Get(); 322 static LineEditor* Get();
224 private: 323 private:
225 Type type_; 324 Type type_;
226 const char* name_; 325 const char* name_;
227 LineEditor* next_; 326 LineEditor* next_;
228 static LineEditor* first_; 327 static LineEditor* first_;
229 }; 328 };
230 329
231 330
232 } // namespace v8 331 } // namespace v8
233 332
234 333
235 #endif // V8_D8_H_ 334 #endif // V8_D8_H_
OLDNEW
« no previous file with comments | « src/cpu-profiler-inl.h ('k') | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698