Index: src/d8.cc |
diff --git a/src/d8.cc b/src/d8.cc |
index f4c7846f5273e6dc5106e047febf4814ad6693ae..2286d20c36f638dd727b7cff9a13912ad53c398b 100644 |
--- a/src/d8.cc |
+++ b/src/d8.cc |
@@ -268,6 +268,7 @@ Handle<Value> Shell::Uint16Array(const Arguments& args) { |
sizeof(uint16_t)); |
} |
+ |
Handle<Value> Shell::Int32Array(const Arguments& args) { |
return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t)); |
} |
@@ -485,6 +486,33 @@ void Shell::AddHistogramSample(void* histogram, int sample) { |
counter->AddSample(sample); |
} |
+void Shell::InstallUtilityScript() { |
+ 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(); |
+ |
+ // 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)); |
+} |
#ifdef COMPRESS_STARTUP_DATA_BZ2 |
class BZip2Decompressor : public v8::StartupDataDecompressor { |
@@ -513,29 +541,7 @@ 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)); |
@@ -576,22 +582,49 @@ void Shell::Initialize() { |
AddOSMethods(os_templ); |
global_template->Set(String::New("os"), os_templ); |
+ return global_template; |
+} |
+ |
+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> global_template = CreateGlobalTemplate(); |
+ |
utility_context_ = Context::New(NULL, global_template); |
utility_context_->SetSecurityToken(Undefined()); |
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()); |
+ FACTORY->NewFixedArray(js_args.argc()); |
for (int j = 0; j < js_args.argc(); j++) { |
Søren Thygesen Gjesse
2011/06/09 13:16:18
Something happened to the intention here.
|
- i::Handle<i::String> arg = |
- FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
- arguments_array->set(j, *arg); |
+ i::Handle<i::String> arg = |
+ FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
+ arguments_array->set(j, *arg); |
} |
i::Handle<i::JSArray> arguments_jsarray = |
Søren Thygesen Gjesse
2011/06/09 13:16:18
Ditto.
|
- FACTORY->NewJSArrayWithElements(arguments_array); |
+ FACTORY->NewJSArrayWithElements(arguments_array); |
global_template->Set(String::New("arguments"), |
Søren Thygesen Gjesse
2011/06/09 13:16:18
Ditto.
|
- Utils::ToLocal(arguments_jsarray)); |
+ Utils::ToLocal(arguments_jsarray)); |
#ifdef ENABLE_DEBUGGER_SUPPORT |
// Install the debugger object in the utility scope |
@@ -602,35 +635,25 @@ void Shell::Initialize() { |
utility_context_->Global()->Set(String::New("$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(); |
- // 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)); |
+void Shell::RenewEvaluationContext() { |
+ // Initialize the global objects |
+ HandleScope scope; |
+ Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
- // 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()); |
@@ -762,23 +785,9 @@ 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,15 +825,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,16 +836,14 @@ 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; |
+ RenewEvaluationContext(); |
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; |
@@ -859,7 +858,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,12 +869,11 @@ 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); |
@@ -907,16 +905,8 @@ 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(); |
@@ -927,7 +917,70 @@ int Shell::Main(int argc, char* argv[]) { |
} |
-} // namespace v8 |
+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) { |
+ InstallUtilityScript(); |
+ RunShell(); |
+ } |
+ |
+ v8::V8::Dispose(); |
+ |
+ return result; |
+} |
+ |
+} // namespace v8 |
#ifndef GOOGLE3 |