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

Unified Diff: src/d8.cc

Issue 7134040: added --stress-opt option to d8 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
« src/d8.h ('K') | « src/d8.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index f4c7846f5273e6dc5106e047febf4814ad6693ae..31765f1c16313419c9c779b145eb695c376e5e94 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -41,25 +41,18 @@
#include "natives.h"
#include "platform.h"
-
namespace v8 {
-
const char* Shell::kHistoryFileName = ".d8_history";
const char* Shell::kPrompt = "d8> ";
-
LineEditor *LineEditor::first_ = NULL;
-
-LineEditor::LineEditor(Type type, const char* name)
- : type_(type),
- name_(name),
- next_(first_) {
+LineEditor::LineEditor(Type type, const char* name) :
+ type_(type), name_(name), next_(first_) {
first_ = this;
}
-
LineEditor* LineEditor::Get() {
LineEditor* current = first_;
LineEditor* best = current;
@@ -71,17 +64,16 @@ LineEditor* LineEditor::Get() {
return best;
}
-
class DumbLineEditor: public LineEditor {
- public:
- DumbLineEditor() : LineEditor(LineEditor::DUMB, "dumb") { }
+public:
+ DumbLineEditor() :
+ LineEditor(LineEditor::DUMB, "dumb") {
+ }
virtual i::SmartPointer<char> Prompt(const char* prompt);
};
-
static DumbLineEditor dumb_line_editor;
-
i::SmartPointer<char> DumbLineEditor::Prompt(const char* prompt) {
static const int kBufferSize = 256;
char buffer[kBufferSize];
@@ -90,7 +82,6 @@ i::SmartPointer<char> DumbLineEditor::Prompt(const char* prompt) {
return i::SmartPointer<char>(str ? i::StrDup(str) : str);
}
-
CounterMap* Shell::counter_map_;
i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
CounterCollection Shell::local_counters_;
@@ -98,25 +89,20 @@ CounterCollection* Shell::counters_ = &local_counters_;
Persistent<Context> Shell::utility_context_;
Persistent<Context> Shell::evaluation_context_;
-
bool CounterMap::Match(void* key1, void* key2) {
- const char* name1 = reinterpret_cast<const char*>(key1);
- const char* name2 = reinterpret_cast<const char*>(key2);
+ const char* name1 = reinterpret_cast<const char*> (key1);
+ const char* name2 = reinterpret_cast<const char*> (key2);
return strcmp(name1, name2) == 0;
}
-
// Converts a V8 value to a C string.
const char* Shell::ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
}
-
// Executes a string within the current v8 context.
-bool Shell::ExecuteString(Handle<String> source,
- Handle<Value> name,
- bool print_result,
- bool report_exceptions) {
+bool Shell::ExecuteString(Handle<String> source, Handle<Value> name,
+ bool print_result, bool report_exceptions) {
HandleScope handle_scope;
TryCatch try_catch;
if (i::FLAG_debugger) {
@@ -151,14 +137,12 @@ bool Shell::ExecuteString(Handle<String> source,
}
}
-
Handle<Value> Shell::Print(const Arguments& args) {
Handle<Value> val = Write(args);
printf("\n");
return val;
}
-
Søren Thygesen Gjesse 2011/06/09 10:05:48 We always try to keep two blank lines between func
Handle<Value> Shell::Write(const Arguments& args) {
for (int i = 0; i < args.Length(); i++) {
HandleScope handle_scope;
@@ -175,7 +159,6 @@ Handle<Value> Shell::Write(const Arguments& args) {
return Undefined();
}
-
Handle<Value> Shell::Read(const Arguments& args) {
String::Utf8Value file(args[0]);
if (*file == NULL) {
@@ -188,7 +171,6 @@ Handle<Value> Shell::Read(const Arguments& args) {
return source;
}
-
Handle<Value> Shell::ReadLine(const Arguments& args) {
i::SmartPointer<char> line(i::ReadLine(""));
if (*line == NULL) {
@@ -201,7 +183,6 @@ Handle<Value> Shell::ReadLine(const Arguments& args) {
return String::New(*line, len);
}
-
Handle<Value> Shell::Load(const Arguments& args) {
for (int i = 0; i < args.Length(); i++) {
HandleScope handle_scope;
@@ -220,13 +201,10 @@ Handle<Value> Shell::Load(const Arguments& args) {
return Undefined();
}
-
Handle<Value> Shell::CreateExternalArray(const Arguments& args,
- ExternalArrayType type,
- int element_size) {
+ ExternalArrayType type, int element_size) {
if (args.Length() != 1) {
- return ThrowException(
- String::New("Array constructor needs one parameter."));
+ return ThrowException(String::New("Array constructor needs one parameter."));
}
int length = args[0]->Int32Value();
void* data = malloc(length * element_size);
@@ -241,66 +219,53 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args,
return array;
}
-
void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) {
free(data);
object.Dispose();
}
-
Handle<Value> Shell::Int8Array(const Arguments& args) {
return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t));
}
-
Handle<Value> Shell::Uint8Array(const Arguments& args) {
return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t));
}
-
Handle<Value> Shell::Int16Array(const Arguments& args) {
return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t));
}
-
Handle<Value> Shell::Uint16Array(const Arguments& args) {
return CreateExternalArray(args, kExternalUnsignedShortArray,
- sizeof(uint16_t));
+ sizeof(uint16_t));
}
Handle<Value> Shell::Int32Array(const Arguments& args) {
return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t));
}
-
Handle<Value> Shell::Uint32Array(const Arguments& args) {
return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t));
}
-
Handle<Value> Shell::Float32Array(const Arguments& args) {
- return CreateExternalArray(args, kExternalFloatArray,
- sizeof(float)); // NOLINT
+ return CreateExternalArray(args, kExternalFloatArray, sizeof(float)); // NOLINT
}
-
Handle<Value> Shell::Float64Array(const Arguments& args) {
- return CreateExternalArray(args, kExternalDoubleArray,
- sizeof(double)); // NOLINT
+ return CreateExternalArray(args, kExternalDoubleArray, sizeof(double)); // NOLINT
}
-
Handle<Value> Shell::PixelArray(const Arguments& args) {
return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t));
}
-
Handle<Value> Shell::Yield(const Arguments& args) {
v8::Unlocker unlocker;
return Undefined();
}
-
Handle<Value> Shell::Quit(const Arguments& args) {
int exit_code = args[0]->Int32Value();
OnExit();
@@ -308,12 +273,10 @@ Handle<Value> Shell::Quit(const Arguments& args) {
return Undefined();
}
-
Handle<Value> Shell::Version(const Arguments& args) {
return String::New(V8::GetVersion());
}
-
void Shell::ReportException(v8::TryCatch* try_catch) {
HandleScope handle_scope;
v8::String::Utf8Value exception(try_catch->Exception());
@@ -351,7 +314,6 @@ void Shell::ReportException(v8::TryCatch* try_catch) {
}
}
-
Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) {
HandleScope handle_scope;
Context::Scope context_scope(utility_context_);
@@ -363,47 +325,42 @@ Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) {
return handle_scope.Close(Handle<Array>::Cast(val));
}
-
#ifdef ENABLE_DEBUGGER_SUPPORT
Handle<Object> Shell::DebugMessageDetails(Handle<String> message) {
Context::Scope context_scope(utility_context_);
Handle<Object> global = utility_context_->Global();
Handle<Value> fun = global->Get(String::New("DebugMessageDetails"));
static const int kArgc = 1;
- Handle<Value> argv[kArgc] = { message };
+ Handle<Value> argv[kArgc] = {message};
Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
return Handle<Object>::Cast(val);
}
-
Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) {
Context::Scope context_scope(utility_context_);
Handle<Object> global = utility_context_->Global();
Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest"));
static const int kArgc = 1;
- Handle<Value> argv[kArgc] = { command };
+ Handle<Value> argv[kArgc] = {command};
Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
return val;
}
#endif
-
int32_t* Counter::Bind(const char* name, bool is_histogram) {
int i;
for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
- name_[i] = static_cast<char>(name[i]);
+ name_[i] = static_cast<char> (name[i]);
name_[i] = '\0';
is_histogram_ = is_histogram;
return ptr();
}
-
void Counter::AddSample(int32_t sample) {
count_++;
sample_total_ += sample;
}
-
CounterCollection::CounterCollection() {
magic_number_ = 0xDEADFACE;
max_counters_ = kMaxCounters;
@@ -411,29 +368,26 @@ CounterCollection::CounterCollection() {
counters_in_use_ = 0;
}
-
Counter* CounterCollection::GetNextCounter() {
- if (counters_in_use_ == kMaxCounters) return NULL;
+ if (counters_in_use_ == kMaxCounters)
+ return NULL;
return &counters_[counters_in_use_++];
}
-
void Shell::MapCounters(const char* name) {
counters_file_ = i::OS::MemoryMappedFile::create(name,
- sizeof(CounterCollection), &local_counters_);
- void* memory = (counters_file_ == NULL) ?
- NULL : counters_file_->memory();
+ sizeof(CounterCollection), &local_counters_);
+ void* memory = (counters_file_ == NULL) ? NULL : counters_file_->memory();
if (memory == NULL) {
printf("Could not map counters file %s\n", name);
exit(1);
}
- counters_ = static_cast<CounterCollection*>(memory);
+ counters_ = static_cast<CounterCollection*> (memory);
V8::SetCounterFunction(LookupCounter);
V8::SetCreateHistogramFunction(CreateHistogram);
V8::SetAddHistogramSampleFunction(AddHistogramSample);
}
-
int CounterMap::Hash(const char* name) {
int h = 0;
int c;
@@ -444,7 +398,6 @@ int CounterMap::Hash(const char* name) {
return h;
}
-
Counter* Shell::GetCounter(const char* name, bool is_histogram) {
Counter* counter = counter_map_->Lookup(name);
@@ -460,7 +413,6 @@ Counter* Shell::GetCounter(const char* name, bool is_histogram) {
return counter;
}
-
int* Shell::LookupCounter(const char* name) {
Counter* counter = GetCounter(name, false);
@@ -471,40 +423,52 @@ int* Shell::LookupCounter(const char* name) {
}
}
-
-void* Shell::CreateHistogram(const char* name,
- int min,
- int max,
- size_t buckets) {
+void* Shell::CreateHistogram(const char* name, int min, int max, size_t buckets) {
return GetCounter(name, true);
}
-
void Shell::AddHistogramSample(void* histogram, int sample) {
- Counter* counter = reinterpret_cast<Counter*>(histogram);
+ Counter* counter = reinterpret_cast<Counter*> (histogram);
counter->AddSample(sample);
}
+void Shell::InstallUtilScript() {
+ Locker lock;
+ HandleScope scope;
+ Context::Scope utility_scope(utility_context_);
+ // Run the d8 shell utility script in the utility context
+ int source_index = i::NativesCollection<i::D8>::GetIndex("d8");
+ i::Vector<const char> shell_source =
+ i::NativesCollection<i::D8>::GetRawScriptSource(source_index);
+ i::Vector<const char> shell_source_name =
+ i::NativesCollection<i::D8>::GetScriptName(source_index);
+ Handle<String> source = String::New(shell_source.start(),
+ shell_source.length());
+ Handle<String> name = String::New(shell_source_name.start(),
+ shell_source_name.length());
+ Handle<Script> script = Script::Compile(source, name);
+ script->Run();
+}
#ifdef COMPRESS_STARTUP_DATA_BZ2
class BZip2Decompressor : public v8::StartupDataDecompressor {
- public:
- virtual ~BZip2Decompressor() { }
+public:
+ virtual ~BZip2Decompressor() {}
- protected:
+protected:
virtual int DecompressData(char* raw_data,
- int* raw_data_size,
- const char* compressed_data,
- int compressed_data_size) {
+ int* raw_data_size,
+ const char* compressed_data,
+ int compressed_data_size) {
ASSERT_EQ(v8::StartupData::kBZip2,
- v8::V8::GetCompressedStartupDataAlgorithm());
+ v8::V8::GetCompressedStartupDataAlgorithm());
unsigned int decompressed_size = *raw_data_size;
int result =
- BZ2_bzBuffToBuffDecompress(raw_data,
- &decompressed_size,
- const_cast<char*>(compressed_data),
- compressed_data_size,
- 0, 1);
+ BZ2_bzBuffToBuffDecompress(raw_data,
+ &decompressed_size,
+ const_cast<char*>(compressed_data),
+ compressed_data_size,
+ 0, 1);
if (result == BZ_OK) {
*raw_data_size = decompressed_size;
}
@@ -513,64 +477,67 @@ class BZip2Decompressor : public v8::StartupDataDecompressor {
};
#endif
-
-void Shell::Initialize() {
-#ifdef COMPRESS_STARTUP_DATA_BZ2
- BZip2Decompressor startup_data_decompressor;
- int bz2_result = startup_data_decompressor.Decompress();
- if (bz2_result != BZ_OK) {
- fprintf(stderr, "bzip error code: %d\n", bz2_result);
- exit(1);
- }
-#endif
-
- Shell::counter_map_ = new CounterMap();
- // Set up counters
- if (i::StrLength(i::FLAG_map_counters) != 0)
- MapCounters(i::FLAG_map_counters);
- if (i::FLAG_dump_counters) {
- V8::SetCounterFunction(LookupCounter);
- V8::SetCreateHistogramFunction(CreateHistogram);
- V8::SetAddHistogramSampleFunction(AddHistogramSample);
- }
-
- // Initialize the global objects
- HandleScope scope;
+Handle<ObjectTemplate> Shell::CreateGlobalTemplate() {
Handle<ObjectTemplate> global_template = ObjectTemplate::New();
global_template->Set(String::New("print"), FunctionTemplate::New(Print));
global_template->Set(String::New("write"), FunctionTemplate::New(Write));
global_template->Set(String::New("read"), FunctionTemplate::New(Read));
- global_template->Set(String::New("readline"),
- FunctionTemplate::New(ReadLine));
+ global_template->Set(String::New("readline"), FunctionTemplate::New(ReadLine));
global_template->Set(String::New("load"), FunctionTemplate::New(Load));
global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
global_template->Set(String::New("version"), FunctionTemplate::New(Version));
// Bind the handlers for external arrays.
global_template->Set(String::New("Int8Array"),
- FunctionTemplate::New(Int8Array));
+ FunctionTemplate::New(Int8Array));
global_template->Set(String::New("Uint8Array"),
- FunctionTemplate::New(Uint8Array));
+ FunctionTemplate::New(Uint8Array));
global_template->Set(String::New("Int16Array"),
- FunctionTemplate::New(Int16Array));
+ FunctionTemplate::New(Int16Array));
global_template->Set(String::New("Uint16Array"),
- FunctionTemplate::New(Uint16Array));
+ FunctionTemplate::New(Uint16Array));
global_template->Set(String::New("Int32Array"),
- FunctionTemplate::New(Int32Array));
+ FunctionTemplate::New(Int32Array));
global_template->Set(String::New("Uint32Array"),
- FunctionTemplate::New(Uint32Array));
+ FunctionTemplate::New(Uint32Array));
global_template->Set(String::New("Float32Array"),
- FunctionTemplate::New(Float32Array));
+ FunctionTemplate::New(Float32Array));
global_template->Set(String::New("Float64Array"),
- FunctionTemplate::New(Float64Array));
+ FunctionTemplate::New(Float64Array));
global_template->Set(String::New("PixelArray"),
- FunctionTemplate::New(PixelArray));
+ FunctionTemplate::New(PixelArray));
#ifdef LIVE_OBJECT_LIST
global_template->Set(String::New("lol_is_enabled"), Boolean::New(true));
#else
global_template->Set(String::New("lol_is_enabled"), Boolean::New(false));
#endif
+ return global_template;
+}
+
+void Shell::Initialize() {
+ Shell::counter_map_ = new CounterMap();
+ // Set up counters
+ if (i::StrLength(i::FLAG_map_counters) != 0)
+ MapCounters(i::FLAG_map_counters);
+ if (i::FLAG_dump_counters) {
+ V8::SetCounterFunction(LookupCounter);
+ V8::SetCreateHistogramFunction(CreateHistogram);
+ V8::SetAddHistogramSampleFunction(AddHistogramSample);
+ }
+
+#ifdef COMPRESS_STARTUP_DATA_BZ2
+ BZip2Decompressor startup_data_decompressor;
+ int bz2_result = startup_data_decompressor.Decompress();
+ if (bz2_result != BZ_OK) {
+ fprintf(stderr, "bzip error code: %d\n", bz2_result);
+ exit(1);
+ }
+#endif
+
+ // Initialize the global objects
+ HandleScope scope;
+ Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
AddOSMethods(os_templ);
@@ -581,56 +548,45 @@ void Shell::Initialize() {
Context::Scope utility_scope(utility_context_);
i::JSArguments js_args = i::FLAG_js_arguments;
- i::Handle<i::FixedArray> arguments_array =
- FACTORY->NewFixedArray(js_args.argc());
+ i::Handle<i::FixedArray> arguments_array = FACTORY->NewFixedArray(
+ js_args.argc());
for (int j = 0; j < js_args.argc(); j++) {
- i::Handle<i::String> arg =
- FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j]));
+ i::Handle<i::String> arg = FACTORY->NewStringFromUtf8(
+ i::CStrVector(js_args[j]));
arguments_array->set(j, *arg);
}
- i::Handle<i::JSArray> arguments_jsarray =
- FACTORY->NewJSArrayWithElements(arguments_array);
+ i::Handle<i::JSArray> arguments_jsarray = FACTORY->NewJSArrayWithElements(
+ arguments_array);
global_template->Set(String::New("arguments"),
- Utils::ToLocal(arguments_jsarray));
+ Utils::ToLocal(arguments_jsarray));
#ifdef ENABLE_DEBUGGER_SUPPORT
// Install the debugger object in the utility scope
i::Debug* debug = i::Isolate::Current()->debug();
debug->Load();
i::Handle<i::JSObject> js_debug
- = i::Handle<i::JSObject>(debug->debug_context()->global());
+ = i::Handle<i::JSObject>(debug->debug_context()->global());
utility_context_->Global()->Set(String::New("$debug"),
- Utils::ToLocal(js_debug));
+ Utils::ToLocal(js_debug));
#endif
+}
- // Run the d8 shell utility script in the utility context
- int source_index = i::NativesCollection<i::D8>::GetIndex("d8");
- i::Vector<const char> shell_source
- = i::NativesCollection<i::D8>::GetRawScriptSource(source_index);
- i::Vector<const char> shell_source_name
- = i::NativesCollection<i::D8>::GetScriptName(source_index);
- Handle<String> source = String::New(shell_source.start(),
- shell_source.length());
- Handle<String> name = String::New(shell_source_name.start(),
- shell_source_name.length());
- Handle<Script> script = Script::Compile(source, name);
- script->Run();
+void Shell::RenewEvalContext() {
+ // Initialize the global objects
+ HandleScope scope;
+ Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
- // Mark the d8 shell script as native to avoid it showing up as normal source
- // in the debugger.
- i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script);
- i::Handle<i::Script> script_object = compiled_script->IsJSFunction()
- ? i::Handle<i::Script>(i::Script::cast(
- i::JSFunction::cast(*compiled_script)->shared()->script()))
- : i::Handle<i::Script>(i::Script::cast(
- i::SharedFunctionInfo::cast(*compiled_script)->script()));
- script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
-
- // Create the evaluation context
+ // (Re-)create the evaluation context
+ if (!evaluation_context_.IsEmpty()) {
+ evaluation_context_.Dispose();
+ }
evaluation_context_ = Context::New(NULL, global_template);
evaluation_context_->SetSecurityToken(Undefined());
#ifdef ENABLE_DEBUGGER_SUPPORT
+ i::Debug* debug = i::Isolate::Current()->debug();
+ debug->Load();
+
// Set the security token of the debug context to allow access.
debug->debug_context()->set_security_token(HEAP->undefined_value());
@@ -646,7 +602,6 @@ void Shell::Initialize() {
#endif
}
-
void Shell::OnExit() {
if (i::FLAG_dump_counters) {
::printf("+----------------------------------------+-------------+\n");
@@ -656,9 +611,8 @@ void Shell::OnExit() {
Counter* counter = i.CurrentValue();
if (counter->is_histogram()) {
::printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
- ::printf("| t:%-36s | %11i |\n",
- i.CurrentKey(),
- counter->sample_total());
+ ::printf("| t:%-36s | %11i |\n", i.CurrentKey(),
+ counter->sample_total());
} else {
::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count());
}
@@ -669,11 +623,11 @@ void Shell::OnExit() {
delete counters_file_;
}
-
static char* ReadChars(const char* name, int* size_out) {
- v8::Unlocker unlocker; // Release the V8 lock while reading files.
+ v8::Unlocker unlocker; // Release the V8 lock while reading files.
FILE* file = i::OS::FOpen(name, "rb");
- if (file == NULL) return NULL;
+ if (file == NULL)
+ return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
@@ -690,7 +644,6 @@ static char* ReadChars(const char* name, int* size_out) {
return chars;
}
-
static char* ReadToken(char* data, char token) {
char* next = i::OS::StrChr(data, token);
if (next != NULL) {
@@ -701,35 +654,34 @@ static char* ReadToken(char* data, char token) {
return NULL;
}
-
static char* ReadLine(char* data) {
return ReadToken(data, '\n');
}
-
static char* ReadWord(char* data) {
return ReadToken(data, ' ');
}
-
// Reads a file into a v8 string.
Handle<String> Shell::ReadFile(const char* name) {
int size = 0;
char* chars = ReadChars(name, &size);
- if (chars == NULL) return Handle<String>();
+ if (chars == NULL)
+ return Handle<String> ();
Handle<String> result = String::New(chars);
delete[] chars;
return result;
}
-
void Shell::RunShell() {
+
LineEditor* editor = LineEditor::Get();
printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name());
if (i::FLAG_debugger) {
printf("JavaScript debugger enabled\n");
}
editor->Open();
+
while (true) {
Locker locker;
HandleScope handle_scope;
@@ -745,40 +697,24 @@ void Shell::RunShell() {
printf("\n");
}
-
-class ShellThread : public i::Thread {
- public:
- ShellThread(i::Isolate* isolate, int no, i::Vector<const char> files)
- : Thread(isolate, "d8:ShellThread"),
- no_(no), files_(files) { }
+class ShellThread: public i::Thread {
+public:
+ ShellThread(i::Isolate* isolate, int no, i::Vector<const char> files) :
+ Thread(isolate, "d8:ShellThread"), no_(no), files_(files) {
+ }
virtual void Run();
- private:
+private:
int no_;
i::Vector<const char> files_;
};
-
void ShellThread::Run() {
// Prepare the context for this thread.
Locker locker;
HandleScope scope;
- Handle<ObjectTemplate> global_template = ObjectTemplate::New();
- global_template->Set(String::New("print"),
- FunctionTemplate::New(Shell::Print));
- global_template->Set(String::New("write"),
- FunctionTemplate::New(Shell::Write));
- global_template->Set(String::New("read"),
- FunctionTemplate::New(Shell::Read));
- global_template->Set(String::New("readline"),
- FunctionTemplate::New(Shell::ReadLine));
- global_template->Set(String::New("load"),
- FunctionTemplate::New(Shell::Load));
- global_template->Set(String::New("yield"),
- FunctionTemplate::New(Shell::Yield));
- global_template->Set(String::New("version"),
- FunctionTemplate::New(Shell::Version));
-
- char* ptr = const_cast<char*>(files_.start());
+ Handle<ObjectTemplate> global_template = Shell::CreateGlobalTemplate();
+
+ char* ptr = const_cast<char*> (files_.start());
while ((ptr != NULL) && (*ptr != '\0')) {
// For each newline-separated line.
char* next_line = ReadLine(ptr);
@@ -816,14 +752,7 @@ void ShellThread::Run() {
}
}
-
-int Shell::Main(int argc, char* argv[]) {
- i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
- if (i::FLAG_help) {
- return 1;
- }
- Initialize();
- bool run_shell = (argc == 1);
+int Shell::RunMain(int argc, char* argv[]) {
// Default use preemption if threads are created.
bool use_preemption = true;
@@ -835,23 +764,22 @@ int Shell::Main(int argc, char* argv[]) {
i::List<i::Thread*> threads(1);
{
- // Acquire the V8 lock once initialization has finished. Since the thread
- // below may spawn new threads accessing V8 holding the V8 lock here is
- // mandatory.
+ // Since the thread below may spawn new threads accessing V8 holding the
+ // V8 lock here is mandatory.
Locker locker;
+
+ RenewEvalContext();
Context::Scope context_scope(evaluation_context_);
for (int i = 1; i < argc; i++) {
char* str = argv[i];
- if (strcmp(str, "--shell") == 0) {
- run_shell = true;
- } else if (strcmp(str, "--preemption") == 0) {
+ if (strcmp(str, "--preemption") == 0) {
use_preemption = true;
} else if (strcmp(str, "--no-preemption") == 0) {
use_preemption = false;
} else if (strcmp(str, "--preemption-interval") == 0) {
if (i + 1 < argc) {
char* end = NULL;
- preemption_interval = strtol(argv[++i], &end, 10); // NOLINT
+ preemption_interval = strtol(argv[++i], &end, 10); // NOLINT
if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) {
printf("Invalid value for --preemption-interval '%s'\n", argv[i]);
return 1;
@@ -859,7 +787,7 @@ int Shell::Main(int argc, char* argv[]) {
} else {
printf("Missing value for --preemption-interval\n");
return 1;
- }
+ }
} else if (strcmp(str, "-f") == 0) {
// Ignore any -f flags for compatibility with other stand-alone
// JavaScript engines.
@@ -870,20 +798,18 @@ int Shell::Main(int argc, char* argv[]) {
// Execute argument given to -e option directly.
v8::HandleScope handle_scope;
v8::Handle<v8::String> file_name = v8::String::New("unnamed");
- v8::Handle<v8::String> source = v8::String::New(argv[i + 1]);
+ v8::Handle<v8::String> source = v8::String::New(argv[++i]);
if (!ExecuteString(source, file_name, false, true)) {
OnExit();
return 1;
}
- i++;
} else if (strcmp(str, "-p") == 0 && i + 1 < argc) {
int size = 0;
const char* files = ReadChars(argv[++i], &size);
- if (files == NULL) return 1;
- ShellThread* thread =
- new ShellThread(i::Isolate::Current(),
- threads.length(),
- i::Vector<const char>(files, size));
+ if (files == NULL)
+ return 1;
+ ShellThread* thread = new ShellThread(i::Isolate::Current(),
+ threads.length(), i::Vector<const char>(files, size));
thread->Start();
threads.Add(thread);
} else {
@@ -907,27 +833,84 @@ int Shell::Main(int argc, char* argv[]) {
Locker::StartPreemption(preemption_interval);
}
-#ifdef ENABLE_DEBUGGER_SUPPORT
- // Run the remote debugger if requested.
- if (i::FLAG_remote_debugger) {
- RunRemoteDebugger(i::FLAG_debugger_port);
- return 0;
- }
-#endif
}
- if (run_shell)
- RunShell();
+
for (int i = 0; i < threads.length(); i++) {
i::Thread* thread = threads[i];
thread->Join();
delete thread;
}
+
OnExit();
return 0;
+
}
+int Shell::Main(int argc, char* argv[]) {
+ // Figure out if we're requested to stress the optimization
+ // infrastructure by running tests multiple times and forcing
+ // optimization in the last run.
+ bool FLAG_stress_opt = false;
+ bool FLAG_stress_deopt = false;
+ bool run_shell = (argc == 1);
+
+ for (int i = 0; i < argc; i++) {
+ if (strcmp(argv[i], "--stress-opt") == 0) {
+ FLAG_stress_opt = true;
+ argv[i] = NULL;
+ } else if (strcmp(argv[i], "--stress-deopt") == 0) {
+ FLAG_stress_deopt = true;
+ argv[i] = NULL;
+ } else if (strcmp(argv[i], "--noalways-opt") == 0) {
+ // No support for stressing if we can't use --always-opt.
+ FLAG_stress_opt = false;
+ FLAG_stress_deopt = false;
+ } else if (strcmp(argv[i], "--shell") == 0) {
+ run_shell = true;
+ argv[i] = NULL;
+ }
+ }
+
+ v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+
+ Initialize();
+
+ int result = 0;
+ if (FLAG_stress_opt || FLAG_stress_deopt) {
+ v8::Testing::SetStressRunType(
+ FLAG_stress_opt ? v8::Testing::kStressTypeOpt
+ : v8::Testing::kStressTypeDeopt);
+ int stress_runs = v8::Testing::GetStressRuns();
+ for (int i = 0; i < stress_runs && result == 0; i++) {
+ printf("============ Stress %d/%d ============\n", i + 1, stress_runs);
+ v8::Testing::PrepareStressRun(i);
+ result = RunMain(argc, argv);
+ }
+ printf("======== Full Deoptimization =======\n");
+ v8::Testing::DeoptimizeAll();
+ } else {
+ result = RunMain(argc, argv);
+ }
+
+#ifdef ENABLE_DEBUGGER_SUPPORT
+ if (i::FLAG_remote_debugger) {
+ RunRemoteDebugger(i::FLAG_debugger_port);
+ return 0;
+ }
+#endif
+
+ if (run_shell) {
+ InstallUtilScript();
+ RunShell();
+ }
+
+ v8::V8::Dispose();
+
+ return result;
+
+}
-} // namespace v8
+} // namespace v8
#ifndef GOOGLE3
« src/d8.h ('K') | « src/d8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698