Revision: 8241
Author: [email protected]
Date: Thu Jun 9 07:28:49 2011
Log: added --stress-opt option to d8
Review URL: http://codereview.chromium.org/7134040
http://code.google.com/p/v8/source/detail?r=8241
Modified:
/branches/bleeding_edge/src/d8.cc
/branches/bleeding_edge/src/d8.h
=======================================
--- /branches/bleeding_edge/src/d8.cc Wed Jun 8 02:00:25 2011
+++ /branches/bleeding_edge/src/d8.cc Thu Jun 9 07:28:49 2011
@@ -267,6 +267,7 @@
return CreateExternalArray(args, kExternalUnsignedShortArray,
sizeof(uint16_t));
}
+
Handle<Value> Shell::Int32Array(const Arguments& args) {
return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t));
@@ -485,6 +486,33 @@
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 @@
};
#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,6 +582,33 @@
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_);
@@ -602,35 +635,25 @@
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));
-
- // Create the evaluation context
+}
+
+
+void Shell::RenewEvaluationContext() {
+ // Initialize the global objects
+ HandleScope scope;
+ Handle<ObjectTemplate> global_template = CreateGlobalTemplate();
+
+ // (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,21 +785,7 @@
// 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));
+ Handle<ObjectTemplate> global_template = Shell::CreateGlobalTemplate();
char* ptr = const_cast<char*>(files_.start());
while ((ptr != NULL) && (*ptr != '\0')) {
@@ -816,15 +825,7 @@
}
}
-
-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 @@
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 @@
} 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 @@
// 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 @@
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 @@
}
-} // 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
=======================================
--- /branches/bleeding_edge/src/d8.h Wed Jun 8 02:00:25 2011
+++ /branches/bleeding_edge/src/d8.h Thu Jun 9 07:28:49 2011
@@ -120,7 +120,6 @@
bool report_exceptions);
static const char* ToCString(const v8::String::Utf8Value& value);
static void ReportException(TryCatch* try_catch);
- static void Initialize();
static void OnExit();
static int* LookupCounter(const char* name);
static void* CreateHistogram(const char* name,
@@ -130,8 +129,14 @@
static void AddHistogramSample(void* histogram, int sample);
static void MapCounters(const char* name);
static Handle<String> ReadFile(const char* name);
+ static void Initialize();
+ static void RenewEvaluationContext();
+ static void InstallUtilityScript();
static void RunShell();
+ static int RunScript(char* filename);
+ static int RunMain(int argc, char* argv[]);
static int Main(int argc, char* argv[]);
+ static Handle<ObjectTemplate> CreateGlobalTemplate();
static Handle<Array> GetCompletions(Handle<String> text,
Handle<String> full);
#ifdef ENABLE_DEBUGGER_SUPPORT
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev