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

Side by Side Diff: src/d8.cc

Issue 7351017: Introduces a light version of D8 that links against shared library. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added changes to gyp build files. 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/d8.h ('k') | src/d8.gyp » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
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 28
29 #ifdef V8_SHARED
30 #define USING_V8_SHARED
31 #endif
32
29 #ifdef COMPRESS_STARTUP_DATA_BZ2 33 #ifdef COMPRESS_STARTUP_DATA_BZ2
30 #include <bzlib.h> 34 #include <bzlib.h>
31 #endif 35 #endif
36
32 #include <errno.h> 37 #include <errno.h>
33 #include <stdlib.h> 38 #include <stdlib.h>
39 #include <string.h>
34 40
35 #include "v8.h" 41 #ifdef USING_V8_SHARED
42 #include <assert.h>
43 #include "../include/v8-testing.h"
44 #endif // USING_V8_SHARED
36 45
37 #include "d8.h" 46 #include "d8.h"
47
48 #ifndef USING_V8_SHARED
49 #include "api.h"
50 #include "checks.h"
38 #include "d8-debug.h" 51 #include "d8-debug.h"
39 #include "debug.h" 52 #include "debug.h"
40 #include "api.h"
41 #include "natives.h" 53 #include "natives.h"
42 #include "platform.h" 54 #include "platform.h"
55 #include "v8.h"
56 #endif // USING_V8_SHARED
43 57
44 #if !defined(_WIN32) && !defined(_WIN64) 58 #if !defined(_WIN32) && !defined(_WIN64)
45 #include <unistd.h> // NOLINT 59 #include <unistd.h> // NOLINT
46 #endif 60 #endif
47 61
62 #ifdef USING_V8_SHARED
63 #define ASSERT(condition) assert(condition)
64 #endif // USING_V8_SHARED
65
48 namespace v8 { 66 namespace v8 {
49 67
50 68
69 #ifndef USING_V8_SHARED
70 LineEditor *LineEditor::first_ = NULL;
51 const char* Shell::kHistoryFileName = ".d8_history"; 71 const char* Shell::kHistoryFileName = ".d8_history";
52 const char* Shell::kPrompt = "d8> ";
53
54
55 LineEditor *LineEditor::first_ = NULL;
56 72
57 73
58 LineEditor::LineEditor(Type type, const char* name) 74 LineEditor::LineEditor(Type type, const char* name)
59 : type_(type), 75 : type_(type),
60 name_(name), 76 name_(name),
61 next_(first_) { 77 next_(first_) {
62 first_ = this; 78 first_ = this;
63 } 79 }
64 80
65 81
(...skipping 25 matching lines...) Expand all
91 printf("%s", prompt); 107 printf("%s", prompt);
92 char* str = fgets(buffer, kBufferSize, stdin); 108 char* str = fgets(buffer, kBufferSize, stdin);
93 return i::SmartPointer<char>(str ? i::StrDup(str) : str); 109 return i::SmartPointer<char>(str ? i::StrDup(str) : str);
94 } 110 }
95 111
96 112
97 CounterMap* Shell::counter_map_; 113 CounterMap* Shell::counter_map_;
98 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; 114 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
99 CounterCollection Shell::local_counters_; 115 CounterCollection Shell::local_counters_;
100 CounterCollection* Shell::counters_ = &local_counters_; 116 CounterCollection* Shell::counters_ = &local_counters_;
117 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex());
101 Persistent<Context> Shell::utility_context_; 118 Persistent<Context> Shell::utility_context_;
119 #endif // USING_V8_SHARED
120
102 Persistent<Context> Shell::evaluation_context_; 121 Persistent<Context> Shell::evaluation_context_;
103 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex());
104 ShellOptions Shell::options; 122 ShellOptions Shell::options;
123 const char* Shell::kPrompt = "d8> ";
105 124
106 125
126 #ifndef USING_V8_SHARED
107 bool CounterMap::Match(void* key1, void* key2) { 127 bool CounterMap::Match(void* key1, void* key2) {
108 const char* name1 = reinterpret_cast<const char*>(key1); 128 const char* name1 = reinterpret_cast<const char*>(key1);
109 const char* name2 = reinterpret_cast<const char*>(key2); 129 const char* name2 = reinterpret_cast<const char*>(key2);
110 return strcmp(name1, name2) == 0; 130 return strcmp(name1, name2) == 0;
111 } 131 }
132 #endif // USING_V8_SHARED
112 133
113 134
114 // Converts a V8 value to a C string. 135 // Converts a V8 value to a C string.
115 const char* Shell::ToCString(const v8::String::Utf8Value& value) { 136 const char* Shell::ToCString(const v8::String::Utf8Value& value) {
116 return *value ? *value : "<string conversion failed>"; 137 return *value ? *value : "<string conversion failed>";
117 } 138 }
118 139
119 140
120 // Executes a string within the current v8 context. 141 // Executes a string within the current v8 context.
121 bool Shell::ExecuteString(Handle<String> source, 142 bool Shell::ExecuteString(Handle<String> source,
122 Handle<Value> name, 143 Handle<Value> name,
123 bool print_result, 144 bool print_result,
124 bool report_exceptions) { 145 bool report_exceptions) {
146 #ifndef USING_V8_SHARED
147 bool FLAG_debugger = i::FLAG_debugger;
148 #else
149 bool FLAG_debugger = false;
150 #endif // USING_V8_SHARED
125 HandleScope handle_scope; 151 HandleScope handle_scope;
126 TryCatch try_catch; 152 TryCatch try_catch;
127 options.script_executed = true; 153 options.script_executed = true;
128 if (i::FLAG_debugger) { 154 if (FLAG_debugger) {
129 // When debugging make exceptions appear to be uncaught. 155 // When debugging make exceptions appear to be uncaught.
130 try_catch.SetVerbose(true); 156 try_catch.SetVerbose(true);
131 } 157 }
132 Handle<Script> script = Script::Compile(source, name); 158 Handle<Script> script = Script::Compile(source, name);
133 if (script.IsEmpty()) { 159 if (script.IsEmpty()) {
134 // Print errors that happened during compilation. 160 // Print errors that happened during compilation.
135 if (report_exceptions && !i::FLAG_debugger) 161 if (report_exceptions && !FLAG_debugger)
136 ReportException(&try_catch); 162 ReportException(&try_catch);
137 return false; 163 return false;
138 } else { 164 } else {
139 Handle<Value> result = script->Run(); 165 Handle<Value> result = script->Run();
140 if (result.IsEmpty()) { 166 if (result.IsEmpty()) {
141 ASSERT(try_catch.HasCaught()); 167 ASSERT(try_catch.HasCaught());
142 // Print errors that happened during execution. 168 // Print errors that happened during execution.
143 if (report_exceptions && !i::FLAG_debugger) 169 if (report_exceptions && !FLAG_debugger)
144 ReportException(&try_catch); 170 ReportException(&try_catch);
145 return false; 171 return false;
146 } else { 172 } else {
147 ASSERT(!try_catch.HasCaught()); 173 ASSERT(!try_catch.HasCaught());
148 if (print_result && !result->IsUndefined()) { 174 if (print_result && !result->IsUndefined()) {
149 // If all went well and the result wasn't undefined then print 175 // If all went well and the result wasn't undefined then print
150 // the returned value. 176 // the returned value.
151 v8::String::Utf8Value str(result); 177 v8::String::Utf8Value str(result);
152 const char* cstr = ToCString(str); 178 const char* cstr = ToCString(str);
153 printf("%s\n", cstr); 179 printf("%s\n", cstr);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 215 }
190 Handle<String> source = ReadFile(*file); 216 Handle<String> source = ReadFile(*file);
191 if (source.IsEmpty()) { 217 if (source.IsEmpty()) {
192 return ThrowException(String::New("Error loading file")); 218 return ThrowException(String::New("Error loading file"));
193 } 219 }
194 return source; 220 return source;
195 } 221 }
196 222
197 223
198 Handle<Value> Shell::ReadLine(const Arguments& args) { 224 Handle<Value> Shell::ReadLine(const Arguments& args) {
199 i::SmartPointer<char> line(i::ReadLine("")); 225 static const int kBufferSize = 256;
200 if (*line == NULL) { 226 char buffer[kBufferSize];
201 return Null(); 227 Handle<String> accumulator = String::New("");
202 } 228 bool linebreak;
203 size_t len = strlen(*line); 229 int length;
204 if (len > 0 && line[len - 1] == '\n') { 230 do { // Repeat if the line ends with an escape '\'.
205 --len; 231 // fgets got an error. Just give up.
206 } 232 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null();
207 return String::New(*line, len); 233 length = strlen(buffer);
234 linebreak = (length > 1 && buffer[length-2] == '\\');
235 if (linebreak) buffer[length-2] = '\n';
236 accumulator = String::Concat(accumulator, String::New(buffer, length-1));
237 } while (linebreak);
238 return accumulator;
208 } 239 }
209 240
210 241
211 Handle<Value> Shell::Load(const Arguments& args) { 242 Handle<Value> Shell::Load(const Arguments& args) {
212 for (int i = 0; i < args.Length(); i++) { 243 for (int i = 0; i < args.Length(); i++) {
213 HandleScope handle_scope; 244 HandleScope handle_scope;
214 String::Utf8Value file(args[i]); 245 String::Utf8Value file(args[i]);
215 if (*file == NULL) { 246 if (*file == NULL) {
216 return ThrowException(String::New("Error loading file")); 247 return ThrowException(String::New("Error loading file"));
217 } 248 }
(...skipping 11 matching lines...) Expand all
229 260
230 Handle<Value> Shell::CreateExternalArray(const Arguments& args, 261 Handle<Value> Shell::CreateExternalArray(const Arguments& args,
231 ExternalArrayType type, 262 ExternalArrayType type,
232 size_t element_size) { 263 size_t element_size) {
233 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 || 264 ASSERT(element_size == 1 || element_size == 2 || element_size == 4 ||
234 element_size == 8); 265 element_size == 8);
235 if (args.Length() != 1) { 266 if (args.Length() != 1) {
236 return ThrowException( 267 return ThrowException(
237 String::New("Array constructor needs one parameter.")); 268 String::New("Array constructor needs one parameter."));
238 } 269 }
270 static const int kMaxLength = 0x3fffffff;
271 #ifndef USING_V8_SHARED
272 ASSERT(kMaxLength == i::ExternalArray::kMaxLength);
273 #endif // USING_V8_SHARED
239 size_t length = 0; 274 size_t length = 0;
240 if (args[0]->IsUint32()) { 275 if (args[0]->IsUint32()) {
241 length = args[0]->Uint32Value(); 276 length = args[0]->Uint32Value();
242 } else if (args[0]->IsNumber()) { 277 } else if (args[0]->IsNumber()) {
243 double raw_length = args[0]->NumberValue(); 278 double raw_length = args[0]->NumberValue();
244 if (raw_length < 0) { 279 if (raw_length < 0) {
245 return ThrowException(String::New("Array length must not be negative.")); 280 return ThrowException(String::New("Array length must not be negative."));
246 } 281 }
247 if (raw_length > i::ExternalArray::kMaxLength) { 282 if (raw_length > kMaxLength) {
248 return ThrowException( 283 return ThrowException(
249 String::New("Array length exceeds maximum length.")); 284 String::New("Array length exceeds maximum length."));
250 } 285 }
251 length = static_cast<size_t>(raw_length); 286 length = static_cast<size_t>(raw_length);
252 } else { 287 } else {
253 return ThrowException(String::New("Array length must be a number.")); 288 return ThrowException(String::New("Array length must be a number."));
254 } 289 }
255 if (length > static_cast<size_t>(i::ExternalArray::kMaxLength)) { 290 if (length > static_cast<size_t>(kMaxLength)) {
256 return ThrowException(String::New("Array length exceeds maximum length.")); 291 return ThrowException(String::New("Array length exceeds maximum length."));
257 } 292 }
258 void* data = calloc(length, element_size); 293 void* data = calloc(length, element_size);
259 if (data == NULL) { 294 if (data == NULL) {
260 return ThrowException(String::New("Memory allocation failed.")); 295 return ThrowException(String::New("Memory allocation failed."));
261 } 296 }
262 Handle<Object> array = Object::New(); 297 Handle<Object> array = Object::New();
263 Persistent<Object> persistent_array = Persistent<Object>::New(array); 298 Persistent<Object> persistent_array = Persistent<Object>::New(array);
264 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); 299 persistent_array.MakeWeak(data, ExternalArrayWeakCallback);
265 persistent_array.MarkIndependent(); 300 persistent_array.MarkIndependent();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 360
326 361
327 Handle<Value> Shell::Yield(const Arguments& args) { 362 Handle<Value> Shell::Yield(const Arguments& args) {
328 v8::Unlocker unlocker; 363 v8::Unlocker unlocker;
329 return Undefined(); 364 return Undefined();
330 } 365 }
331 366
332 367
333 Handle<Value> Shell::Quit(const Arguments& args) { 368 Handle<Value> Shell::Quit(const Arguments& args) {
334 int exit_code = args[0]->Int32Value(); 369 int exit_code = args[0]->Int32Value();
370 #ifndef USING_V8_SHARED
335 OnExit(); 371 OnExit();
372 #endif // USING_V8_SHARED
336 exit(exit_code); 373 exit(exit_code);
337 return Undefined(); 374 return Undefined();
338 } 375 }
339 376
340 377
341 Handle<Value> Shell::Version(const Arguments& args) { 378 Handle<Value> Shell::Version(const Arguments& args) {
342 return String::New(V8::GetVersion()); 379 return String::New(V8::GetVersion());
343 } 380 }
344 381
345 382
(...skipping 28 matching lines...) Expand all
374 printf("\n"); 411 printf("\n");
375 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); 412 v8::String::Utf8Value stack_trace(try_catch->StackTrace());
376 if (stack_trace.length() > 0) { 413 if (stack_trace.length() > 0) {
377 const char* stack_trace_string = ToCString(stack_trace); 414 const char* stack_trace_string = ToCString(stack_trace);
378 printf("%s\n", stack_trace_string); 415 printf("%s\n", stack_trace_string);
379 } 416 }
380 } 417 }
381 } 418 }
382 419
383 420
421 #ifndef USING_V8_SHARED
384 Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) { 422 Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) {
385 HandleScope handle_scope; 423 HandleScope handle_scope;
386 Context::Scope context_scope(utility_context_); 424 Context::Scope context_scope(utility_context_);
387 Handle<Object> global = utility_context_->Global(); 425 Handle<Object> global = utility_context_->Global();
388 Handle<Value> fun = global->Get(String::New("GetCompletions")); 426 Handle<Value> fun = global->Get(String::New("GetCompletions"));
389 static const int kArgc = 3; 427 static const int kArgc = 3;
390 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; 428 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full };
391 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 429 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
392 return handle_scope.Close(Handle<Array>::Cast(val)); 430 return handle_scope.Close(Handle<Array>::Cast(val));
393 } 431 }
(...skipping 13 matching lines...) Expand all
407 445
408 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { 446 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) {
409 Context::Scope context_scope(utility_context_); 447 Context::Scope context_scope(utility_context_);
410 Handle<Object> global = utility_context_->Global(); 448 Handle<Object> global = utility_context_->Global();
411 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); 449 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest"));
412 static const int kArgc = 1; 450 static const int kArgc = 1;
413 Handle<Value> argv[kArgc] = { command }; 451 Handle<Value> argv[kArgc] = { command };
414 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 452 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
415 return val; 453 return val;
416 } 454 }
417 #endif 455 #endif // ENABLE_DEBUGGER_SUPPORT
456 #endif // USING_V8_SHARED
418 457
419 458
459 #ifndef USING_V8_SHARED
420 int32_t* Counter::Bind(const char* name, bool is_histogram) { 460 int32_t* Counter::Bind(const char* name, bool is_histogram) {
421 int i; 461 int i;
422 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) 462 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
423 name_[i] = static_cast<char>(name[i]); 463 name_[i] = static_cast<char>(name[i]);
424 name_[i] = '\0'; 464 name_[i] = '\0';
425 is_histogram_ = is_histogram; 465 is_histogram_ = is_histogram;
426 return ptr(); 466 return ptr();
427 } 467 }
428 468
429 469
(...skipping 11 matching lines...) Expand all
441 } 481 }
442 482
443 483
444 Counter* CounterCollection::GetNextCounter() { 484 Counter* CounterCollection::GetNextCounter() {
445 if (counters_in_use_ == kMaxCounters) return NULL; 485 if (counters_in_use_ == kMaxCounters) return NULL;
446 return &counters_[counters_in_use_++]; 486 return &counters_[counters_in_use_++];
447 } 487 }
448 488
449 489
450 void Shell::MapCounters(const char* name) { 490 void Shell::MapCounters(const char* name) {
451 counters_file_ = i::OS::MemoryMappedFile::create(name, 491 counters_file_ = i::OS::MemoryMappedFile::create(
452 sizeof(CounterCollection), &local_counters_); 492 name, sizeof(CounterCollection), &local_counters_);
453 void* memory = (counters_file_ == NULL) ? 493 void* memory = (counters_file_ == NULL) ?
454 NULL : counters_file_->memory(); 494 NULL : counters_file_->memory();
455 if (memory == NULL) { 495 if (memory == NULL) {
456 printf("Could not map counters file %s\n", name); 496 printf("Could not map counters file %s\n", name);
457 exit(1); 497 exit(1);
458 } 498 }
459 counters_ = static_cast<CounterCollection*>(memory); 499 counters_ = static_cast<CounterCollection*>(memory);
460 V8::SetCounterFunction(LookupCounter); 500 V8::SetCounterFunction(LookupCounter);
461 V8::SetCreateHistogramFunction(CreateHistogram); 501 V8::SetCreateHistogramFunction(CreateHistogram);
462 V8::SetAddHistogramSampleFunction(AddHistogramSample); 502 V8::SetAddHistogramSampleFunction(AddHistogramSample);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 size_t buckets) { 547 size_t buckets) {
508 return GetCounter(name, true); 548 return GetCounter(name, true);
509 } 549 }
510 550
511 551
512 void Shell::AddHistogramSample(void* histogram, int sample) { 552 void Shell::AddHistogramSample(void* histogram, int sample) {
513 Counter* counter = reinterpret_cast<Counter*>(histogram); 553 Counter* counter = reinterpret_cast<Counter*>(histogram);
514 counter->AddSample(sample); 554 counter->AddSample(sample);
515 } 555 }
516 556
557
517 void Shell::InstallUtilityScript() { 558 void Shell::InstallUtilityScript() {
518 Locker lock; 559 Locker lock;
519 HandleScope scope; 560 HandleScope scope;
520 // If we use the utility context, we have to set the security tokens so that 561 // If we use the utility context, we have to set the security tokens so that
521 // utility, evaluation and debug context can all access each other. 562 // utility, evaluation and debug context can all access each other.
522 utility_context_->SetSecurityToken(Undefined()); 563 utility_context_->SetSecurityToken(Undefined());
523 evaluation_context_->SetSecurityToken(Undefined()); 564 evaluation_context_->SetSecurityToken(Undefined());
524 Context::Scope utility_scope(utility_context_); 565 Context::Scope utility_scope(utility_context_);
525 566
526 #ifdef ENABLE_DEBUGGER_SUPPORT 567 #ifdef ENABLE_DEBUGGER_SUPPORT
527 // Install the debugger object in the utility scope 568 // Install the debugger object in the utility scope
528 i::Debug* debug = i::Isolate::Current()->debug(); 569 i::Debug* debug = i::Isolate::Current()->debug();
529 debug->Load(); 570 debug->Load();
530 i::Handle<i::JSObject> js_debug 571 i::Handle<i::JSObject> js_debug
531 = i::Handle<i::JSObject>(debug->debug_context()->global()); 572 = i::Handle<i::JSObject>(debug->debug_context()->global());
532 utility_context_->Global()->Set(String::New("$debug"), 573 utility_context_->Global()->Set(String::New("$debug"),
533 Utils::ToLocal(js_debug)); 574 Utils::ToLocal(js_debug));
534 debug->debug_context()->set_security_token(HEAP->undefined_value()); 575 debug->debug_context()->set_security_token(HEAP->undefined_value());
535 #endif 576 #endif // ENABLE_DEBUGGER_SUPPORT
536 577
537 // Run the d8 shell utility script in the utility context 578 // Run the d8 shell utility script in the utility context
538 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); 579 int source_index = i::NativesCollection<i::D8>::GetIndex("d8");
539 i::Vector<const char> shell_source = 580 i::Vector<const char> shell_source =
540 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); 581 i::NativesCollection<i::D8>::GetRawScriptSource(source_index);
541 i::Vector<const char> shell_source_name = 582 i::Vector<const char> shell_source_name =
542 i::NativesCollection<i::D8>::GetScriptName(source_index); 583 i::NativesCollection<i::D8>::GetScriptName(source_index);
543 Handle<String> source = String::New(shell_source.start(), 584 Handle<String> source = String::New(shell_source.start(),
544 shell_source.length()); 585 shell_source.length());
545 Handle<String> name = String::New(shell_source_name.start(), 586 Handle<String> name = String::New(shell_source_name.start(),
546 shell_source_name.length()); 587 shell_source_name.length());
547 Handle<Script> script = Script::Compile(source, name); 588 Handle<Script> script = Script::Compile(source, name);
548 script->Run(); 589 script->Run();
549 // Mark the d8 shell script as native to avoid it showing up as normal source 590 // Mark the d8 shell script as native to avoid it showing up as normal source
550 // in the debugger. 591 // in the debugger.
551 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); 592 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script);
552 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() 593 i::Handle<i::Script> script_object = compiled_script->IsJSFunction()
553 ? i::Handle<i::Script>(i::Script::cast( 594 ? i::Handle<i::Script>(i::Script::cast(
554 i::JSFunction::cast(*compiled_script)->shared()->script())) 595 i::JSFunction::cast(*compiled_script)->shared()->script()))
555 : i::Handle<i::Script>(i::Script::cast( 596 : i::Handle<i::Script>(i::Script::cast(
556 i::SharedFunctionInfo::cast(*compiled_script)->script())); 597 i::SharedFunctionInfo::cast(*compiled_script)->script()));
557 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); 598 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
558 599
559 #ifdef ENABLE_DEBUGGER_SUPPORT 600 #ifdef ENABLE_DEBUGGER_SUPPORT
560 // Start the in-process debugger if requested. 601 // Start the in-process debugger if requested.
561 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { 602 if (i::FLAG_debugger && !i::FLAG_debugger_agent) {
562 v8::Debug::SetDebugEventListener(HandleDebugEvent); 603 v8::Debug::SetDebugEventListener(HandleDebugEvent);
563 } 604 }
564 #endif 605 #endif // ENABLE_DEBUGGER_SUPPORT
565 } 606 }
607 #endif // USING_V8_SHARED
566 608
567 609
568 #ifdef COMPRESS_STARTUP_DATA_BZ2 610 #ifdef COMPRESS_STARTUP_DATA_BZ2
569 class BZip2Decompressor : public v8::StartupDataDecompressor { 611 class BZip2Decompressor : public v8::StartupDataDecompressor {
570 public: 612 public:
571 virtual ~BZip2Decompressor() { } 613 virtual ~BZip2Decompressor() { }
572 614
573 protected: 615 protected:
574 virtual int DecompressData(char* raw_data, 616 virtual int DecompressData(char* raw_data,
575 int* raw_data_size, 617 int* raw_data_size,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 FunctionTemplate::New(Float64Array)); 664 FunctionTemplate::New(Float64Array));
623 global_template->Set(String::New("PixelArray"), 665 global_template->Set(String::New("PixelArray"),
624 FunctionTemplate::New(PixelArray)); 666 FunctionTemplate::New(PixelArray));
625 667
626 #ifdef LIVE_OBJECT_LIST 668 #ifdef LIVE_OBJECT_LIST
627 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); 669 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true));
628 #else 670 #else
629 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); 671 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false));
630 #endif 672 #endif
631 673
674 #ifndef USING_V8_SHARED
632 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); 675 Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
633 AddOSMethods(os_templ); 676 AddOSMethods(os_templ);
634 global_template->Set(String::New("os"), os_templ); 677 global_template->Set(String::New("os"), os_templ);
678 #endif // USING_V8_SHARED
635 679
636 return global_template; 680 return global_template;
637 } 681 }
638 682
639 683
640 void Shell::Initialize() { 684 void Shell::Initialize() {
641 #ifdef COMPRESS_STARTUP_DATA_BZ2 685 #ifdef COMPRESS_STARTUP_DATA_BZ2
642 BZip2Decompressor startup_data_decompressor; 686 BZip2Decompressor startup_data_decompressor;
643 int bz2_result = startup_data_decompressor.Decompress(); 687 int bz2_result = startup_data_decompressor.Decompress();
644 if (bz2_result != BZ_OK) { 688 if (bz2_result != BZ_OK) {
645 fprintf(stderr, "bzip error code: %d\n", bz2_result); 689 fprintf(stderr, "bzip error code: %d\n", bz2_result);
646 exit(1); 690 exit(1);
647 } 691 }
648 #endif 692 #endif
649 693
694 #ifndef USING_V8_SHARED
650 Shell::counter_map_ = new CounterMap(); 695 Shell::counter_map_ = new CounterMap();
651 // Set up counters 696 // Set up counters
652 if (i::StrLength(i::FLAG_map_counters) != 0) 697 if (i::StrLength(i::FLAG_map_counters) != 0)
653 MapCounters(i::FLAG_map_counters); 698 MapCounters(i::FLAG_map_counters);
654 if (i::FLAG_dump_counters) { 699 if (i::FLAG_dump_counters) {
655 V8::SetCounterFunction(LookupCounter); 700 V8::SetCounterFunction(LookupCounter);
656 V8::SetCreateHistogramFunction(CreateHistogram); 701 V8::SetCreateHistogramFunction(CreateHistogram);
657 V8::SetAddHistogramSampleFunction(AddHistogramSample); 702 V8::SetAddHistogramSampleFunction(AddHistogramSample);
658 } 703 }
659 704 #endif // USING_V8_SHARED
660 if (options.test_shell) return; 705 if (options.test_shell) return;
661 706
707 #ifndef USING_V8_SHARED
662 Locker lock; 708 Locker lock;
663 HandleScope scope; 709 HandleScope scope;
664 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); 710 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
665 utility_context_ = Context::New(NULL, global_template); 711 utility_context_ = Context::New(NULL, global_template);
666 712
667 #ifdef ENABLE_DEBUGGER_SUPPORT 713 #ifdef ENABLE_DEBUGGER_SUPPORT
668 // Start the debugger agent if requested. 714 // Start the debugger agent if requested.
669 if (i::FLAG_debugger_agent) { 715 if (i::FLAG_debugger_agent) {
670 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); 716 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true);
671 } 717 }
672 #endif 718 #endif // ENABLE_DEBUGGER_SUPPORT
719 #endif // USING_V8_SHARED
673 } 720 }
674 721
675 722
676 Persistent<Context> Shell::CreateEvaluationContext() { 723 Persistent<Context> Shell::CreateEvaluationContext() {
724 #ifndef USING_V8_SHARED
677 // This needs to be a critical section since this is not thread-safe 725 // This needs to be a critical section since this is not thread-safe
678 i::ScopedLock lock(context_mutex_); 726 i::ScopedLock lock(context_mutex_);
727 #endif // USING_V8_SHARED
679 // Initialize the global objects 728 // Initialize the global objects
680 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); 729 Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
681 Persistent<Context> context = Context::New(NULL, global_template); 730 Persistent<Context> context = Context::New(NULL, global_template);
682 Context::Scope scope(context); 731 Context::Scope scope(context);
683 732
733 #ifndef USING_V8_SHARED
684 i::JSArguments js_args = i::FLAG_js_arguments; 734 i::JSArguments js_args = i::FLAG_js_arguments;
685 i::Handle<i::FixedArray> arguments_array = 735 i::Handle<i::FixedArray> arguments_array =
686 FACTORY->NewFixedArray(js_args.argc()); 736 FACTORY->NewFixedArray(js_args.argc());
687 for (int j = 0; j < js_args.argc(); j++) { 737 for (int j = 0; j < js_args.argc(); j++) {
688 i::Handle<i::String> arg = 738 i::Handle<i::String> arg =
689 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); 739 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
690 arguments_array->set(j, *arg); 740 arguments_array->set(j, *arg);
691 } 741 }
692 i::Handle<i::JSArray> arguments_jsarray = 742 i::Handle<i::JSArray> arguments_jsarray =
693 FACTORY->NewJSArrayWithElements(arguments_array); 743 FACTORY->NewJSArrayWithElements(arguments_array);
694 context->Global()->Set(String::New("arguments"), 744 context->Global()->Set(String::New("arguments"),
695 Utils::ToLocal(arguments_jsarray)); 745 Utils::ToLocal(arguments_jsarray));
746 #endif // USING_V8_SHARED
696 return context; 747 return context;
697 } 748 }
698 749
699 750
751 #ifndef USING_V8_SHARED
700 void Shell::OnExit() { 752 void Shell::OnExit() {
701 if (i::FLAG_dump_counters) { 753 if (i::FLAG_dump_counters) {
702 printf("+----------------------------------------+-------------+\n"); 754 printf("+----------------------------------------+-------------+\n");
703 printf("| Name | Value |\n"); 755 printf("| Name | Value |\n");
704 printf("+----------------------------------------+-------------+\n"); 756 printf("+----------------------------------------+-------------+\n");
705 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { 757 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
706 Counter* counter = i.CurrentValue(); 758 Counter* counter = i.CurrentValue();
707 if (counter->is_histogram()) { 759 if (counter->is_histogram()) {
708 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); 760 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
709 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total()); 761 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total());
710 } else { 762 } else {
711 printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); 763 printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count());
712 } 764 }
713 } 765 }
714 printf("+----------------------------------------+-------------+\n"); 766 printf("+----------------------------------------+-------------+\n");
715 } 767 }
716 if (counters_file_ != NULL) 768 if (counters_file_ != NULL)
717 delete counters_file_; 769 delete counters_file_;
718 } 770 }
771 #endif // USING_V8_SHARED
719 772
720 773
721 static char* ReadChars(const char* name, int* size_out) { 774 static char* ReadChars(const char* name, int* size_out) {
722 // Release the V8 lock while reading files. 775 // Release the V8 lock while reading files.
723 v8::Unlocker unlocker(Isolate::GetCurrent()); 776 v8::Unlocker unlocker(Isolate::GetCurrent());
777 #ifndef USING_V8_SHARED
724 FILE* file = i::OS::FOpen(name, "rb"); 778 FILE* file = i::OS::FOpen(name, "rb");
779 #else
780 FILE* file = fopen(name, "rb"); // TODO: reading from a directory hangs!
781 #endif // USING_V8_SHARED
725 if (file == NULL) return NULL; 782 if (file == NULL) return NULL;
726 783
727 fseek(file, 0, SEEK_END); 784 fseek(file, 0, SEEK_END);
728 int size = ftell(file); 785 int size = ftell(file);
729 rewind(file); 786 rewind(file);
730 787
731 char* chars = new char[size + 1]; 788 char* chars = new char[size + 1];
732 chars[size] = '\0'; 789 chars[size] = '\0';
733 for (int i = 0; i < size;) { 790 for (int i = 0; i < size;) {
734 int read = fread(&chars[i], 1, size - i, file); 791 int read = fread(&chars[i], 1, size - i, file);
735 i += read; 792 i += read;
736 } 793 }
737 fclose(file); 794 fclose(file);
738 *size_out = size; 795 *size_out = size;
739 return chars; 796 return chars;
740 } 797 }
741 798
742 799
800 #ifndef USING_V8_SHARED
743 static char* ReadToken(char* data, char token) { 801 static char* ReadToken(char* data, char token) {
744 char* next = i::OS::StrChr(data, token); 802 char* next = i::OS::StrChr(data, token);
745 if (next != NULL) { 803 if (next != NULL) {
746 *next = '\0'; 804 *next = '\0';
747 return (next + 1); 805 return (next + 1);
748 } 806 }
749 807
750 return NULL; 808 return NULL;
751 } 809 }
752 810
753 811
754 static char* ReadLine(char* data) { 812 static char* ReadLine(char* data) {
755 return ReadToken(data, '\n'); 813 return ReadToken(data, '\n');
756 } 814 }
757 815
758 816
759 static char* ReadWord(char* data) { 817 static char* ReadWord(char* data) {
760 return ReadToken(data, ' '); 818 return ReadToken(data, ' ');
761 } 819 }
820 #endif // USING_V8_SHARED
762 821
763 822
764 // Reads a file into a v8 string. 823 // Reads a file into a v8 string.
765 Handle<String> Shell::ReadFile(const char* name) { 824 Handle<String> Shell::ReadFile(const char* name) {
766 int size = 0; 825 int size = 0;
767 char* chars = ReadChars(name, &size); 826 char* chars = ReadChars(name, &size);
768 if (chars == NULL) return Handle<String>(); 827 if (chars == NULL) return Handle<String>();
769 Handle<String> result = String::New(chars); 828 Handle<String> result = String::New(chars);
770 delete[] chars; 829 delete[] chars;
771 return result; 830 return result;
772 } 831 }
773 832
774 833
775 void Shell::RunShell() { 834 void Shell::RunShell() {
835 Locker locker;
836 Context::Scope context_scope(evaluation_context_);
837 HandleScope handle_scope;
838 Handle<String> name = String::New("(d8)");
839 #ifndef USING_V8_SHARED
776 LineEditor* editor = LineEditor::Get(); 840 LineEditor* editor = LineEditor::Get();
777 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); 841 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name());
778 if (i::FLAG_debugger) { 842 if (i::FLAG_debugger) {
779 printf("JavaScript debugger enabled\n"); 843 printf("JavaScript debugger enabled\n");
780 } 844 }
781
782 editor->Open(); 845 editor->Open();
783 while (true) { 846 while (true) {
784 Locker locker;
785 HandleScope handle_scope;
786 Context::Scope context_scope(evaluation_context_);
787 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); 847 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt);
788 if (input.is_empty()) 848 if (input.is_empty()) break;
789 break;
790 editor->AddHistory(*input); 849 editor->AddHistory(*input);
791 Handle<String> name = String::New("(d8)");
792 ExecuteString(String::New(*input), name, true, true); 850 ExecuteString(String::New(*input), name, true, true);
793 } 851 }
794 editor->Close(); 852 editor->Close();
853 #else
854 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion());
855 static const int kBufferSize = 256;
856 while (true) {
857 char buffer[kBufferSize];
858 printf("%s", Shell::kPrompt);
859 if (fgets(buffer, kBufferSize, stdin) == NULL) break;
860 ExecuteString(String::New(buffer), name, true, true);
861 }
862 #endif // USING_V8_SHARED
795 printf("\n"); 863 printf("\n");
796 } 864 }
797 865
798 866
867 #ifndef USING_V8_SHARED
799 class ShellThread : public i::Thread { 868 class ShellThread : public i::Thread {
800 public: 869 public:
801 ShellThread(int no, i::Vector<const char> files) 870 ShellThread(int no, i::Vector<const char> files)
802 : Thread("d8:ShellThread"), 871 : Thread("d8:ShellThread"),
803 no_(no), files_(files) { } 872 no_(no), files_(files) { }
804 virtual void Run(); 873 virtual void Run();
805 private: 874 private:
806 int no_; 875 int no_;
807 i::Vector<const char> files_; 876 i::Vector<const char> files_;
808 }; 877 };
809 878
810 879
811 void ShellThread::Run() { 880 void ShellThread::Run() {
812 char* ptr = const_cast<char*>(files_.start()); 881 char* ptr = const_cast<char*>(files_.start());
813 while ((ptr != NULL) && (*ptr != '\0')) { 882 while ((ptr != NULL) && (*ptr != '\0')) {
(...skipping 27 matching lines...) Expand all
841 break; 910 break;
842 } 911 }
843 912
844 Shell::ExecuteString(str, String::New(filename), false, false); 913 Shell::ExecuteString(str, String::New(filename), false, false);
845 } 914 }
846 915
847 thread_context.Dispose(); 916 thread_context.Dispose();
848 ptr = next_line; 917 ptr = next_line;
849 } 918 }
850 } 919 }
920 #endif // USING_V8_SHARED
851 921
852 922
853 void SourceGroup::ExitShell(int exit_code) { 923 void SourceGroup::ExitShell(int exit_code) {
854 // Use _exit instead of exit to avoid races between isolate 924 // Use _exit instead of exit to avoid races between isolate
855 // threads and static destructors. 925 // threads and static destructors.
856 fflush(stdout); 926 fflush(stdout);
857 fflush(stderr); 927 fflush(stderr);
858 _exit(exit_code); 928 _exit(exit_code);
859 } 929 }
860 930
(...skipping 26 matching lines...) Expand all
887 if (!Shell::ExecuteString(source, file_name, false, true)) { 957 if (!Shell::ExecuteString(source, file_name, false, true)) {
888 ExitShell(1); 958 ExitShell(1);
889 return; 959 return;
890 } 960 }
891 } 961 }
892 } 962 }
893 } 963 }
894 964
895 965
896 Handle<String> SourceGroup::ReadFile(const char* name) { 966 Handle<String> SourceGroup::ReadFile(const char* name) {
897 FILE* file = fopen(name, "rb"); 967 #ifndef USING_V8_SHARED
968 FILE* file = i::OS::FOpen(name, "rb");
969 #else
970 FILE* file = fopen(name, "rb"); // TODO: reading from a directory hangs!
971 #endif // USING_V8_SHARED
898 if (file == NULL) return Handle<String>(); 972 if (file == NULL) return Handle<String>();
899 973
900 fseek(file, 0, SEEK_END); 974 fseek(file, 0, SEEK_END);
901 int size = ftell(file); 975 int size = ftell(file);
902 rewind(file); 976 rewind(file);
903 977
904 char* chars = new char[size + 1]; 978 char* chars = new char[size + 1];
905 chars[size] = '\0'; 979 chars[size] = '\0';
906 for (int i = 0; i < size;) { 980 for (int i = 0; i < size;) {
907 int read = fread(&chars[i], 1, size - i, file); 981 int read = fread(&chars[i], 1, size - i, file);
908 i += read; 982 i += read;
909 } 983 }
910 fclose(file); 984 fclose(file);
911 Handle<String> result = String::New(chars, size); 985 Handle<String> result = String::New(chars, size);
912 delete[] chars; 986 delete[] chars;
913 return result; 987 return result;
914 } 988 }
915 989
916 990
991 #ifndef USING_V8_SHARED
917 i::Thread::Options SourceGroup::GetThreadOptions() { 992 i::Thread::Options SourceGroup::GetThreadOptions() {
918 i::Thread::Options options; 993 i::Thread::Options options;
919 options.name = "IsolateThread"; 994 options.name = "IsolateThread";
920 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less 995 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less
921 // which is not enough to parse the big literal expressions used in tests. 996 // which is not enough to parse the big literal expressions used in tests.
922 // The stack size should be at least StackGuard::kLimitSize + some 997 // The stack size should be at least StackGuard::kLimitSize + some
923 // OS-specific padding for thread startup code. 998 // OS-specific padding for thread startup code.
924 options.stack_size = 2 << 20; // 2 Mb seems to be enough 999 options.stack_size = 2 << 20; // 2 Mb seems to be enough
925 return options; 1000 return options;
926 } 1001 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 1033
959 void SourceGroup::WaitForThread() { 1034 void SourceGroup::WaitForThread() {
960 if (thread_ == NULL) return; 1035 if (thread_ == NULL) return;
961 if (Shell::options.last_run) { 1036 if (Shell::options.last_run) {
962 thread_->Join(); 1037 thread_->Join();
963 thread_ = NULL; 1038 thread_ = NULL;
964 } else { 1039 } else {
965 done_semaphore_->Wait(); 1040 done_semaphore_->Wait();
966 } 1041 }
967 } 1042 }
1043 #endif // USING_V8_SHARED
968 1044
969 1045
970 bool Shell::SetOptions(int argc, char* argv[]) { 1046 bool Shell::SetOptions(int argc, char* argv[]) {
971 for (int i = 0; i < argc; i++) { 1047 for (int i = 0; i < argc; i++) {
972 if (strcmp(argv[i], "--stress-opt") == 0) { 1048 if (strcmp(argv[i], "--stress-opt") == 0) {
973 options.stress_opt = true; 1049 options.stress_opt = true;
974 argv[i] = NULL; 1050 argv[i] = NULL;
975 } else if (strcmp(argv[i], "--stress-deopt") == 0) { 1051 } else if (strcmp(argv[i], "--stress-deopt") == 0) {
976 options.stress_deopt = true; 1052 options.stress_deopt = true;
977 argv[i] = NULL; 1053 argv[i] = NULL;
978 } else if (strcmp(argv[i], "--noalways-opt") == 0) { 1054 } else if (strcmp(argv[i], "--noalways-opt") == 0) {
979 // No support for stressing if we can't use --always-opt. 1055 // No support for stressing if we can't use --always-opt.
980 options.stress_opt = false; 1056 options.stress_opt = false;
981 options.stress_deopt = false; 1057 options.stress_deopt = false;
982 } else if (strcmp(argv[i], "--shell") == 0) { 1058 } else if (strcmp(argv[i], "--shell") == 0) {
983 options.interactive_shell = true; 1059 options.interactive_shell = true;
984 argv[i] = NULL; 1060 argv[i] = NULL;
985 } else if (strcmp(argv[i], "--test") == 0) { 1061 } else if (strcmp(argv[i], "--test") == 0) {
986 options.test_shell = true; 1062 options.test_shell = true;
987 argv[i] = NULL; 1063 argv[i] = NULL;
988 } else if (strcmp(argv[i], "--preemption") == 0) { 1064 } else if (strcmp(argv[i], "--preemption") == 0) {
1065 #ifdef USING_V8_SHARED
1066 printf("D8 with shared library does not support multi-threading\n");
1067 return false;
1068 #else
989 options.use_preemption = true; 1069 options.use_preemption = true;
990 argv[i] = NULL; 1070 argv[i] = NULL;
1071 #endif // USING_V8_SHARED
991 } else if (strcmp(argv[i], "--no-preemption") == 0) { 1072 } else if (strcmp(argv[i], "--no-preemption") == 0) {
1073 #ifdef USING_V8_SHARED
1074 printf("D8 with shared library does not support multi-threading\n");
1075 return false;
1076 #else
992 options.use_preemption = false; 1077 options.use_preemption = false;
993 argv[i] = NULL; 1078 argv[i] = NULL;
1079 #endif // USING_V8_SHARED
994 } else if (strcmp(argv[i], "--preemption-interval") == 0) { 1080 } else if (strcmp(argv[i], "--preemption-interval") == 0) {
1081 #ifdef USING_V8_SHARED
1082 printf("D8 with shared library does not support multi-threading\n");
1083 return false;
1084 #else
995 if (++i < argc) { 1085 if (++i < argc) {
996 argv[i-1] = NULL; 1086 argv[i-1] = NULL;
997 char* end = NULL; 1087 char* end = NULL;
998 options.preemption_interval = strtol(argv[i], &end, 10); // NOLINT 1088 options.preemption_interval = strtol(argv[i], &end, 10); // NOLINT
999 if (options.preemption_interval <= 0 1089 if (options.preemption_interval <= 0
1000 || *end != '\0' 1090 || *end != '\0'
1001 || errno == ERANGE) { 1091 || errno == ERANGE) {
1002 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); 1092 printf("Invalid value for --preemption-interval '%s'\n", argv[i]);
1003 return false; 1093 return false;
1004 } 1094 }
1005 argv[i] = NULL; 1095 argv[i] = NULL;
1006 } else { 1096 } else {
1007 printf("Missing value for --preemption-interval\n"); 1097 printf("Missing value for --preemption-interval\n");
1008 return false; 1098 return false;
1009 } 1099 }
1100 #endif // USING_V8_SHARED
1010 } else if (strcmp(argv[i], "-f") == 0) { 1101 } else if (strcmp(argv[i], "-f") == 0) {
1011 // Ignore any -f flags for compatibility with other stand-alone 1102 // Ignore any -f flags for compatibility with other stand-alone
1012 // JavaScript engines. 1103 // JavaScript engines.
1013 continue; 1104 continue;
1014 } else if (strcmp(argv[i], "--isolate") == 0) { 1105 } else if (strcmp(argv[i], "--isolate") == 0) {
1106 #ifdef USING_V8_SHARED
1107 printf("D8 with shared library does not support multi-threading\n");
1108 return false;
1109 #endif // USING_V8_SHARED
1015 options.num_isolates++; 1110 options.num_isolates++;
1016 } 1111 }
1112 #ifdef USING_V8_SHARED
1113 else if (strcmp(argv[i], "--dump-counters") == 0) {
1114 printf("D8 with shared library does not include counters\n");
1115 return false;
1116 } else if (strcmp(argv[i], "-p") == 0) {
1117 printf("D8 with shared library does not support multi-threading\n");
1118 return false;
1119 } else if (strcmp(argv[i], "--debugger") == 0) {
1120 printf("Javascript debugger not included\n");
1121 return false;
1122 }
1123 #endif // USING_V8_SHARED
1017 } 1124 }
1018 1125
1126 #ifndef USING_V8_SHARED
1019 // Run parallel threads if we are not using --isolate 1127 // Run parallel threads if we are not using --isolate
1020 for (int i = 1; i < argc; i++) { 1128 for (int i = 1; i < argc; i++) {
1021 if (argv[i] == NULL) continue; 1129 if (argv[i] == NULL) continue;
1022 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { 1130 if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
1023 if (options.num_isolates > 1) { 1131 if (options.num_isolates > 1) {
1024 printf("-p is not compatible with --isolate\n"); 1132 printf("-p is not compatible with --isolate\n");
1025 return false; 1133 return false;
1026 } 1134 }
1027 argv[i] = NULL; 1135 argv[i] = NULL;
1028 if (options.parallel_files == NULL) { 1136 if (options.parallel_files == NULL) {
1029 options.parallel_files = new i::List<i::Vector<const char> >(); 1137 options.parallel_files = new i::List<i::Vector<const char> >();
1030 } 1138 }
1031 int size = 0; 1139 int size = 0;
1032 const char* files = ReadChars(argv[++i], &size); 1140 const char* files = ReadChars(argv[++i], &size);
1033 if (files == NULL) { 1141 if (files == NULL) {
1034 printf("-p option incomplete\n"); 1142 printf("-p option incomplete\n");
1035 return false; 1143 return false;
1036 } 1144 }
1037 argv[i] = NULL; 1145 argv[i] = NULL;
1038 options.parallel_files->Add(i::Vector<const char>(files, size)); 1146 options.parallel_files->Add(i::Vector<const char>(files, size));
1039 } 1147 }
1040 } 1148 }
1149 #endif // USING_V8_SHARED
1041 1150
1042 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 1151 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
1043 1152
1044 // set up isolated source groups 1153 // set up isolated source groups
1045 options.isolate_sources = new SourceGroup[options.num_isolates]; 1154 options.isolate_sources = new SourceGroup[options.num_isolates];
1046 SourceGroup* current = options.isolate_sources; 1155 SourceGroup* current = options.isolate_sources;
1047 current->Begin(argv, 1); 1156 current->Begin(argv, 1);
1048 for (int i = 1; i < argc; i++) { 1157 for (int i = 1; i < argc; i++) {
1049 const char* str = argv[i]; 1158 const char* str = argv[i];
1050 if (strcmp(str, "--isolate") == 0) { 1159 if (strcmp(str, "--isolate") == 0) {
1051 current->End(i); 1160 current->End(i);
1052 current++; 1161 current++;
1053 current->Begin(argv, i + 1); 1162 current->Begin(argv, i + 1);
1054 } else if (strncmp(argv[i], "--", 2) == 0) { 1163 } else if (strncmp(argv[i], "--", 2) == 0) {
1055 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]); 1164 printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]);
1056 } 1165 }
1057 } 1166 }
1058 current->End(argc); 1167 current->End(argc);
1059 1168
1060 return true; 1169 return true;
1061 } 1170 }
1062 1171
1063 1172
1064 int Shell::RunMain(int argc, char* argv[]) { 1173 int Shell::RunMain(int argc, char* argv[]) {
1174 #ifndef USING_V8_SHARED
1065 i::List<i::Thread*> threads(1); 1175 i::List<i::Thread*> threads(1);
1066 1176 #endif // USING_V8_SHARED
1067 { 1177 {
1178 #ifndef USING_V8_SHARED
1068 if (options.parallel_files != NULL) 1179 if (options.parallel_files != NULL)
1069 for (int i = 0; i < options.parallel_files->length(); i++) { 1180 for (int i = 0; i < options.parallel_files->length(); i++) {
1070 i::Vector<const char> files = options.parallel_files->at(i); 1181 i::Vector<const char> files = options.parallel_files->at(i);
1071 ShellThread* thread = new ShellThread(threads.length(), files); 1182 ShellThread* thread = new ShellThread(threads.length(), files);
1072 thread->Start(); 1183 thread->Start();
1073 threads.Add(thread); 1184 threads.Add(thread);
1074 } 1185 }
1075 1186
1076 for (int i = 1; i < options.num_isolates; ++i) { 1187 for (int i = 1; i < options.num_isolates; ++i) {
1077 options.isolate_sources[i].StartExecuteInThread(); 1188 options.isolate_sources[i].StartExecuteInThread();
1078 } 1189 }
1190 #endif // USING_V8_SHARED
1079 1191
1080 Locker lock; 1192 Locker lock;
1081 HandleScope scope; 1193 HandleScope scope;
1082 Persistent<Context> context = CreateEvaluationContext(); 1194 Persistent<Context> context = CreateEvaluationContext();
1083 { 1195 {
1084 Context::Scope cscope(context); 1196 Context::Scope cscope(context);
1085 options.isolate_sources[0].Execute(); 1197 options.isolate_sources[0].Execute();
1086 } 1198 }
1087 if (options.last_run) { 1199 if (options.last_run) {
1088 // Keep using the same context in the interactive shell 1200 // Keep using the same context in the interactive shell
1089 evaluation_context_ = context; 1201 evaluation_context_ = context;
1090 } else { 1202 } else {
1091 context.Dispose(); 1203 context.Dispose();
1092 } 1204 }
1205
1206 #ifndef USING_V8_SHARED
1093 // Start preemption if threads have been created and preemption is enabled. 1207 // Start preemption if threads have been created and preemption is enabled.
1094 if (options.parallel_files != NULL 1208 if (options.parallel_files != NULL
1095 && threads.length() > 0 1209 && threads.length() > 0
1096 && options.use_preemption) { 1210 && options.use_preemption) {
1097 Locker::StartPreemption(options.preemption_interval); 1211 Locker::StartPreemption(options.preemption_interval);
1098 } 1212 }
1213 #endif // USING_V8_SHARED
1099 } 1214 }
1100 1215
1216 #ifndef USING_V8_SHARED
1101 for (int i = 1; i < options.num_isolates; ++i) { 1217 for (int i = 1; i < options.num_isolates; ++i) {
1102 options.isolate_sources[i].WaitForThread(); 1218 options.isolate_sources[i].WaitForThread();
1103 } 1219 }
1104 1220
1105 if (options.parallel_files != NULL) 1221 if (options.parallel_files != NULL)
1106 for (int i = 0; i < threads.length(); i++) { 1222 for (int i = 0; i < threads.length(); i++) {
1107 i::Thread* thread = threads[i]; 1223 i::Thread* thread = threads[i];
1108 thread->Join(); 1224 thread->Join();
1109 delete thread; 1225 delete thread;
1110 } 1226 }
1111 1227
1112 OnExit(); 1228 OnExit();
1229 #endif // USING_V8_SHARED
1113 return 0; 1230 return 0;
1114 } 1231 }
1115 1232
1116 1233
1117 int Shell::Main(int argc, char* argv[]) { 1234 int Shell::Main(int argc, char* argv[]) {
1118 if (!SetOptions(argc, argv)) return 1; 1235 if (!SetOptions(argc, argv)) return 1;
1119 Initialize(); 1236 Initialize();
1120 1237
1121 int result = 0; 1238 int result = 0;
1122 if (options.stress_opt || options.stress_deopt) { 1239 if (options.stress_opt || options.stress_deopt) {
1123 Testing::SetStressRunType( 1240 Testing::SetStressRunType(
1124 options.stress_opt ? Testing::kStressTypeOpt 1241 options.stress_opt ? Testing::kStressTypeOpt
1125 : Testing::kStressTypeDeopt); 1242 : Testing::kStressTypeDeopt);
1126 int stress_runs = Testing::GetStressRuns(); 1243 int stress_runs = Testing::GetStressRuns();
1127 for (int i = 0; i < stress_runs && result == 0; i++) { 1244 for (int i = 0; i < stress_runs && result == 0; i++) {
1128 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); 1245 printf("============ Stress %d/%d ============\n", i + 1, stress_runs);
1129 Testing::PrepareStressRun(i); 1246 Testing::PrepareStressRun(i);
1130 options.last_run = (i == stress_runs - 1); 1247 options.last_run = (i == stress_runs - 1);
1131 result = RunMain(argc, argv); 1248 result = RunMain(argc, argv);
1132 } 1249 }
1133 printf("======== Full Deoptimization =======\n"); 1250 printf("======== Full Deoptimization =======\n");
1134 Testing::DeoptimizeAll(); 1251 Testing::DeoptimizeAll();
1135 } else { 1252 } else {
1136 result = RunMain(argc, argv); 1253 result = RunMain(argc, argv);
1137 } 1254 }
1138 1255
1139 #ifdef ENABLE_DEBUGGER_SUPPORT 1256
1257 #if !defined(USING_V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
1140 // Run remote debugger if requested, but never on --test 1258 // Run remote debugger if requested, but never on --test
1141 if (i::FLAG_remote_debugger && !options.test_shell) { 1259 if (i::FLAG_remote_debugger && !options.test_shell) {
1142 InstallUtilityScript(); 1260 InstallUtilityScript();
1143 RunRemoteDebugger(i::FLAG_debugger_port); 1261 RunRemoteDebugger(i::FLAG_debugger_port);
1144 return 0; 1262 return 0;
1145 } 1263 }
1146 #endif 1264 #endif // !USING_V8_SHARED && ENABLE_DEBUGGER_SUPPORT
1147 1265
1148 // Run interactive shell if explicitly requested or if no script has been 1266 // Run interactive shell if explicitly requested or if no script has been
1149 // executed, but never on --test 1267 // executed, but never on --test
1150 1268
1151 if (( options.interactive_shell 1269 if (( options.interactive_shell
1152 || !options.script_executed ) 1270 || !options.script_executed )
1153 && !options.test_shell ) { 1271 && !options.test_shell ) {
1272 #ifndef USING_V8_SHARED
1154 InstallUtilityScript(); 1273 InstallUtilityScript();
1274 #endif // USING_V8_SHARED
1155 RunShell(); 1275 RunShell();
1156 } 1276 }
1157 1277
1158 V8::Dispose(); 1278 V8::Dispose();
1159 1279
1160 return result; 1280 return result;
1161 } 1281 }
1162 1282
1163 } // namespace v8 1283 } // namespace v8
1164 1284
1165 1285
1166 #ifndef GOOGLE3 1286 #ifndef GOOGLE3
1167 int main(int argc, char* argv[]) { 1287 int main(int argc, char* argv[]) {
1168 return v8::Shell::Main(argc, argv); 1288 return v8::Shell::Main(argc, argv);
1169 } 1289 }
1170 #endif 1290 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/d8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698