Reviewers: Mikhail Naganov,
Message:
Misha,
There're two related TODOs in this file, but I want this change to be
separate
because it has effect on performance when profiler is enabled. The TODOs are
just refactorings.
Thanks,
Vitaly
Description:
Avoid hidden TLS access in CpuProfiler::is_profiling().
Please review this at http://codereview.chromium.org/6895014/
Affected files:
M src/codegen.cc
M src/compiler.cc
M src/cpu-profiler.h
M src/cpu-profiler.cc
M src/heap.cc
Index: src/codegen.cc
diff --git a/src/codegen.cc b/src/codegen.cc
index
4bbe6ae26b40262a3d5610942c90d95720cd4732..6abd0e39a0783215c796d3bb993efce940fc7c62
100644
--- a/src/codegen.cc
+++ b/src/codegen.cc
@@ -176,7 +176,10 @@ static Vector<const char> kRegexp =
CStrVector("regexp");
bool CodeGenerator::ShouldGenerateLog(Expression* type) {
ASSERT(type != NULL);
- if (!LOGGER->is_logging() && !CpuProfiler::is_profiling()) return false;
+ Isolate* isolate = Isolate::Current();
+ if (!isolate->logger()->is_logging()
&& !CpuProfiler::is_profiling(isolate)) {
+ return false;
+ }
Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());
if (FLAG_log_regexp) {
if (name->IsEqualTo(kRegexp))
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index
86d5de3aec6856acdddbaef03f2fef5e4100cb78..0efdeb2f57e9e0a9035af48e7c9bf1a65547118f
100755
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -767,7 +767,8 @@ void
Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
// Log the code generation. If source information is available include
// script name and line number. Check explicitly whether logging is
// enabled as finding the line number is not free.
- if (info->isolate()->logger()->is_logging() ||
CpuProfiler::is_profiling()) {
+ if (info->isolate()->logger()->is_logging() ||
+ CpuProfiler::is_profiling(info->isolate())) {
Handle<Script> script = info->script();
Handle<Code> code = info->code();
if (*code ==
info->isolate()->builtins()->builtin(Builtins::kLazyCompile))
Index: src/cpu-profiler.cc
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc
index
3894748174a98862121b1d471ec3a94337389d9a..8d11e7a00b7e60a6da6cac1c1a1a57e4b7b97740
100644
--- a/src/cpu-profiler.cc
+++ b/src/cpu-profiler.cc
@@ -288,14 +288,16 @@ void CpuProfiler::StartProfiling(String* title) {
CpuProfile* CpuProfiler::StopProfiling(const char* title) {
- return is_profiling() ?
- Isolate::Current()->cpu_profiler()->StopCollectingProfile(title) :
NULL;
+ Isolate* isolate = Isolate::Current();
+ return is_profiling(isolate) ?
+ isolate->cpu_profiler()->StopCollectingProfile(title) : NULL;
}
CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String*
title) {
- return is_profiling() ?
- Isolate::Current()->cpu_profiler()->StopCollectingProfile(
+ Isolate* isolate = Isolate::Current();
+ return is_profiling(isolate) ?
+ isolate->cpu_profiler()->StopCollectingProfile(
security_token, title) : NULL;
}
@@ -336,8 +338,9 @@ TickSample* CpuProfiler::TickSampleEvent(Isolate*
isolate) {
void CpuProfiler::DeleteAllProfiles() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate->cpu_profiler() != NULL);
- if (is_profiling())
+ if (is_profiling(isolate)) {
isolate->cpu_profiler()->StopProcessor();
+ }
isolate->cpu_profiler()->ResetProfiles();
}
Index: src/cpu-profiler.h
diff --git a/src/cpu-profiler.h b/src/cpu-profiler.h
index
e04cf855f61e4b28ad79e4abe95e584e4fd17f67..4e395271b4f952f22b3fb7ec65d51cebe78151e6
100644
--- a/src/cpu-profiler.h
+++ b/src/cpu-profiler.h
@@ -197,12 +197,12 @@ class ProfilerEventsProcessor : public Thread {
} } // namespace v8::internal
-#define PROFILE(isolate, Call) \
- LOG(isolate, Call); \
- do { \
- if (v8::internal::CpuProfiler::is_profiling()) { \
- v8::internal::CpuProfiler::Call; \
- } \
+#define PROFILE(isolate, Call) \
+ LOG(isolate, Call); \
+ do { \
+ if (v8::internal::CpuProfiler::is_profiling(isolate)) { \
+ v8::internal::CpuProfiler::Call; \
+ } \
} while (false)
#else
#define PROFILE(isolate, Call) LOG(isolate, Call)
@@ -261,10 +261,6 @@ class CpuProfiler {
// TODO(isolates): this doesn't have to use atomics anymore.
- static INLINE(bool is_profiling()) {
- return is_profiling(Isolate::Current());
- }
-
static INLINE(bool is_profiling(Isolate* isolate)) {
CpuProfiler* profiler = isolate->cpu_profiler();
return profiler != NULL && NoBarrier_Load(&profiler->is_profiling_);
@@ -292,7 +288,7 @@ class CpuProfiler {
Atomic32 is_profiling_;
#else
- static INLINE(bool is_profiling()) { return false; }
+ static INLINE(bool is_profiling(Isolate* isolate)) { return false; }
#endif // ENABLE_LOGGING_AND_PROFILING
private:
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index
518f4ab4d354848244dba977d28088013d20539e..b1b510974090c14afb79a1908493bdc5e19d75b8
100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -1347,7 +1347,7 @@ class ScavengingVisitor : public StaticVisitorBase {
#if defined(ENABLE_LOGGING_AND_PROFILING)
Isolate* isolate = heap->isolate();
if (isolate->logger()->is_logging() ||
- isolate->cpu_profiler()->is_profiling()) {
+ CpuProfiler::is_profiling(isolate)) {
if (target->IsSharedFunctionInfo()) {
PROFILE(isolate, SharedFunctionInfoMoveEvent(
source->address(), target->address()));
@@ -1522,8 +1522,8 @@ void
Heap::SwitchScavengingVisitorsTableIfProfilingWasEnabled() {
return;
}
- if (isolate()->logger()->is_logging() ||
- isolate()->cpu_profiler()->is_profiling() ||
+ if (isolate()->logger()->is_logging() |
+ CpuProfiler::is_profiling(isolate()) ||
(isolate()->heap_profiler() != NULL &&
isolate()->heap_profiler()->is_profiling())) {
// If one of the isolates is doing scavenge at this moment of time
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev