From 3b65ecccf0a04390135d5bbb0e1c3cc98a5be9c4 Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Mon, 8 Apr 2013 15:16:55 +0000 Subject: [PATCH] Remove LOGGER macro Use already saved isolate pointer and avoid TLS lookup when retrieving Logger instance BUG=None Review URL: https://codereview.chromium.org/13529004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14168 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/isolate.h | 1 - src/log.cc | 16 ++++++++-------- src/log.h | 2 +- src/runtime.cc | 2 +- test/cctest/test-log.cc | 49 +++++++++++++++++++++++++++++-------------------- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/isolate.h b/src/isolate.h index f7a81d3..89b398b 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -1480,7 +1480,6 @@ class PostponeInterruptsScope BASE_EMBEDDED { #define HEAP (v8::internal::Isolate::Current()->heap()) #define FACTORY (v8::internal::Isolate::Current()->factory()) #define ISOLATE (v8::internal::Isolate::Current()) -#define LOGGER (v8::internal::Isolate::Current()->logger()) // Tells whether the native context is marked with out of memory. diff --git a/src/log.cc b/src/log.cc index 81fe19f..9a52d80 100644 --- a/src/log.cc +++ b/src/log.cc @@ -216,9 +216,10 @@ void Profiler::Engage() { Start(); // Register to get ticks. - LOGGER->ticker_->SetProfiler(this); + Logger* logger = isolate_->logger(); + logger->ticker_->SetProfiler(this); - LOGGER->ProfilerBeginEvent(); + logger->ProfilerBeginEvent(); } @@ -226,7 +227,7 @@ void Profiler::Disengage() { if (!engaged_) return; // Stop receiving ticks. - LOGGER->ticker_->ClearProfiler(); + isolate_->logger()->ticker_->ClearProfiler(); // Terminate the worker thread by setting running_ to false, // inserting a fake element in the queue and then wait for @@ -778,11 +779,10 @@ void Logger::RegExpCompileEvent(Handle regexp, bool in_cache) { } -void Logger::LogRuntime(Isolate* isolate, - Vector format, +void Logger::LogRuntime(Vector format, JSArray* args) { if (!log_->IsEnabled() || !FLAG_log_runtime) return; - HandleScope scope(isolate); + HandleScope scope(isolate_); LogMessageBuilder msg(this); for (int i = 0; i < format.length(); i++) { char c = format[i]; @@ -899,12 +899,12 @@ void Logger::DeleteEvent(const char* name, void* object) { void Logger::NewEventStatic(const char* name, void* object, size_t size) { - LOGGER->NewEvent(name, object, size); + Isolate::Current()->logger()->NewEvent(name, object, size); } void Logger::DeleteEventStatic(const char* name, void* object) { - LOGGER->DeleteEvent(name, object); + Isolate::Current()->logger()->DeleteEvent(name, object); } void Logger::CallbackEventInternal(const char* prefix, Name* name, diff --git a/src/log.h b/src/log.h index 03fd5bd..29bc8e8 100644 --- a/src/log.h +++ b/src/log.h @@ -324,7 +324,7 @@ class Logger { void RegExpCompileEvent(Handle regexp, bool in_cache); // Log an event reported from generated code - void LogRuntime(Isolate* isolate, Vector format, JSArray* args); + void LogRuntime(Vector format, JSArray* args); bool is_logging() { return logging_nesting_ > 0; diff --git a/src/runtime.cc b/src/runtime.cc index 3d9e99d..5ec3389 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -12838,7 +12838,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) { String::FlatContent format_content = format->GetFlatContent(); RUNTIME_ASSERT(format_content.IsAscii()); Vector chars = format_content.ToOneByteVector(); - LOGGER->LogRuntime(isolate, Vector::cast(chars), elms); + isolate->logger()->LogRuntime(Vector::cast(chars), elms); return isolate->heap()->undefined_value(); } diff --git a/test/cctest/test-log.cc b/test/cctest/test-log.cc index 53ccd3e..24e5db9 100644 --- a/test/cctest/test-log.cc +++ b/test/cctest/test-log.cc @@ -62,13 +62,14 @@ class ScopedLoggerInitializer { // Need to run this prior to creating the scope. trick_to_run_init_flags_(init_flags_(prof_lazy)), scope_(v8::Isolate::GetCurrent()), - env_(v8::Context::New()) { + env_(v8::Context::New()), + logger_(i::Isolate::Current()->logger()) { env_->Enter(); } ~ScopedLoggerInitializer() { env_->Exit(); - LOGGER->TearDown(); + logger_->TearDown(); if (temp_file_ != NULL) fclose(temp_file_); i::FLAG_prof_lazy = saved_prof_lazy_; i::FLAG_prof = saved_prof_; @@ -78,8 +79,10 @@ class ScopedLoggerInitializer { v8::Handle& env() { return env_; } + Logger* logger() { return logger_; } + FILE* StopLoggingGetTempFile() { - temp_file_ = LOGGER->TearDown(); + temp_file_ = logger_->TearDown(); CHECK_NE(NULL, temp_file_); fflush(temp_file_); rewind(temp_file_); @@ -104,6 +107,7 @@ class ScopedLoggerInitializer { const bool trick_to_run_init_flags_; v8::HandleScope scope_; v8::Handle env_; + Logger* logger_; DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); }; @@ -123,12 +127,13 @@ static const char* StrNStr(const char* s1, const char* s2, int n) { TEST(ProfLazyMode) { ScopedLoggerInitializer initialize_logger(true); + Logger* logger = initialize_logger.logger(); if (!i::V8::UseCrankshaft()) return; - LOGGER->StringEvent("test-start", ""); + logger->StringEvent("test-start", ""); CompileRun("var a = (function(x) { return x + 1; })(10);"); - LOGGER->StringEvent("test-profiler-start", ""); + logger->StringEvent("test-profiler-start", ""); v8::V8::ResumeProfiler(); CompileRun( "var b = (function(x) { return x + 2; })(10);\n" @@ -136,10 +141,10 @@ TEST(ProfLazyMode) { "var d = (function(x) { return x + 4; })(10);\n" "var e = (function(x) { return x + 5; })(10);"); v8::V8::PauseProfiler(); - LOGGER->StringEvent("test-profiler-stop", ""); + logger->StringEvent("test-profiler-stop", ""); CompileRun("var f = (function(x) { return x + 6; })(10);"); // Check that profiling can be resumed again. - LOGGER->StringEvent("test-profiler-start-2", ""); + logger->StringEvent("test-profiler-start-2", ""); v8::V8::ResumeProfiler(); CompileRun( "var g = (function(x) { return x + 7; })(10);\n" @@ -147,8 +152,8 @@ TEST(ProfLazyMode) { "var i = (function(x) { return x + 9; })(10);\n" "var j = (function(x) { return x + 10; })(10);"); v8::V8::PauseProfiler(); - LOGGER->StringEvent("test-profiler-stop-2", ""); - LOGGER->StringEvent("test-stop", ""); + logger->StringEvent("test-profiler-stop-2", ""); + logger->StringEvent("test-stop", ""); bool exists = false; i::Vector log( @@ -383,7 +388,7 @@ TEST(Issue23768) { i_source->set_resource(NULL); // Must not crash. - LOGGER->LogCompiledFunctions(); + i::Isolate::Current()->logger()->LogCompiledFunctions(); } @@ -393,6 +398,7 @@ static v8::Handle ObjMethod1(const v8::Arguments& args) { TEST(LogCallbacks) { ScopedLoggerInitializer initialize_logger(false); + Logger* logger = initialize_logger.logger(); v8::Persistent obj = v8::Persistent::New(v8::Isolate::GetCurrent(), @@ -409,7 +415,7 @@ TEST(LogCallbacks) { initialize_logger.env()->Global()->Set(v8_str("Obj"), obj->GetFunction()); CompileRun("Obj.prototype.method1.toString();"); - LOGGER->LogCompiledFunctions(); + logger->LogCompiledFunctions(); bool exists = false; i::Vector log( @@ -444,6 +450,7 @@ static v8::Handle Prop2Getter(v8::Local property, TEST(LogAccessorCallbacks) { ScopedLoggerInitializer initialize_logger(false); + Logger* logger = initialize_logger.logger(); v8::Persistent obj = v8::Persistent::New(v8::Isolate::GetCurrent(), @@ -453,7 +460,7 @@ TEST(LogAccessorCallbacks) { inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter); inst->SetAccessor(v8_str("prop2"), Prop2Getter); - LOGGER->LogAccessorCallbacks(); + logger->LogAccessorCallbacks(); bool exists = false; i::Vector log( @@ -487,12 +494,13 @@ TEST(LogAccessorCallbacks) { TEST(IsLoggingPreserved) { ScopedLoggerInitializer initialize_logger(false); + Logger* logger = initialize_logger.logger(); - CHECK(LOGGER->is_logging()); - LOGGER->ResumeProfiler(); - CHECK(LOGGER->is_logging()); - LOGGER->PauseProfiler(); - CHECK(LOGGER->is_logging()); + CHECK(logger->is_logging()); + logger->ResumeProfiler(); + CHECK(logger->is_logging()); + logger->PauseProfiler(); + CHECK(logger->is_logging()); } @@ -513,6 +521,7 @@ TEST(EquivalenceOfLoggingAndTraversal) { // Start with profiling to capture all code events from the beginning. ScopedLoggerInitializer initialize_logger(false); + Logger* logger = initialize_logger.logger(); // Compile and run a function that creates other functions. CompileRun( @@ -522,11 +531,11 @@ TEST(EquivalenceOfLoggingAndTraversal) { "})(this);"); v8::V8::PauseProfiler(); HEAP->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); - LOGGER->StringEvent("test-logging-done", ""); + logger->StringEvent("test-logging-done", ""); // Iterate heap to find compiled functions, will write to log. - LOGGER->LogCompiledFunctions(); - LOGGER->StringEvent("test-traversal-done", ""); + logger->LogCompiledFunctions(); + logger->StringEvent("test-traversal-done", ""); bool exists = false; i::Vector log( -- 2.7.4