OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include <stdarg.h> | 28 #include <stdarg.h> |
29 | 29 |
30 #include "v8.h" | 30 #include "v8.h" |
31 | 31 |
32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
33 #include "code-stubs.h" | 33 #include "code-stubs.h" |
34 #include "deoptimizer.h" | 34 #include "deoptimizer.h" |
35 #include "global-handles.h" | 35 #include "global-handles.h" |
36 #include "log.h" | 36 #include "log.h" |
37 #include "macro-assembler.h" | 37 #include "macro-assembler.h" |
38 #include "platform.h" | |
39 #include "runtime-profiler.h" | 38 #include "runtime-profiler.h" |
40 #include "serialize.h" | 39 #include "serialize.h" |
41 #include "string-stream.h" | 40 #include "string-stream.h" |
42 #include "vm-state-inl.h" | 41 #include "vm-state-inl.h" |
43 | 42 |
44 namespace v8 { | 43 namespace v8 { |
45 namespace internal { | 44 namespace internal { |
46 | 45 |
47 // | 46 // |
48 // Sliding state window. Updates counters to keep track of the last | 47 // Sliding state window. Updates counters to keep track of the last |
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 FLAG_sliding_state_window = true; | 1721 FLAG_sliding_state_window = true; |
1723 return; | 1722 return; |
1724 } | 1723 } |
1725 // Otherwise, if the sliding state window computation has not been | 1724 // Otherwise, if the sliding state window computation has not been |
1726 // started we do it now. | 1725 // started we do it now. |
1727 if (sliding_state_window_ == NULL) { | 1726 if (sliding_state_window_ == NULL) { |
1728 sliding_state_window_ = new SlidingStateWindow(Isolate::Current()); | 1727 sliding_state_window_ = new SlidingStateWindow(Isolate::Current()); |
1729 } | 1728 } |
1730 } | 1729 } |
1731 | 1730 |
1732 // Protects the state below. | |
1733 static LazyMutex active_samplers_mutex = LAZY_MUTEX_INITIALIZER; | |
1734 | 1731 |
| 1732 Mutex* SamplerRegistry::mutex_ = OS::CreateMutex(); |
1735 List<Sampler*>* SamplerRegistry::active_samplers_ = NULL; | 1733 List<Sampler*>* SamplerRegistry::active_samplers_ = NULL; |
1736 | 1734 |
1737 | 1735 |
1738 bool SamplerRegistry::IterateActiveSamplers(VisitSampler func, void* param) { | 1736 bool SamplerRegistry::IterateActiveSamplers(VisitSampler func, void* param) { |
1739 ScopedLock lock(active_samplers_mutex.Pointer()); | 1737 ScopedLock lock(mutex_); |
1740 for (int i = 0; | 1738 for (int i = 0; |
1741 ActiveSamplersExist() && i < active_samplers_->length(); | 1739 ActiveSamplersExist() && i < active_samplers_->length(); |
1742 ++i) { | 1740 ++i) { |
1743 func(active_samplers_->at(i), param); | 1741 func(active_samplers_->at(i), param); |
1744 } | 1742 } |
1745 return ActiveSamplersExist(); | 1743 return ActiveSamplersExist(); |
1746 } | 1744 } |
1747 | 1745 |
1748 | 1746 |
1749 static void ComputeCpuProfiling(Sampler* sampler, void* flag_ptr) { | 1747 static void ComputeCpuProfiling(Sampler* sampler, void* flag_ptr) { |
1750 bool* flag = reinterpret_cast<bool*>(flag_ptr); | 1748 bool* flag = reinterpret_cast<bool*>(flag_ptr); |
1751 *flag |= sampler->IsProfiling(); | 1749 *flag |= sampler->IsProfiling(); |
1752 } | 1750 } |
1753 | 1751 |
1754 | 1752 |
1755 SamplerRegistry::State SamplerRegistry::GetState() { | 1753 SamplerRegistry::State SamplerRegistry::GetState() { |
1756 bool flag = false; | 1754 bool flag = false; |
1757 if (!IterateActiveSamplers(&ComputeCpuProfiling, &flag)) { | 1755 if (!IterateActiveSamplers(&ComputeCpuProfiling, &flag)) { |
1758 return HAS_NO_SAMPLERS; | 1756 return HAS_NO_SAMPLERS; |
1759 } | 1757 } |
1760 return flag ? HAS_CPU_PROFILING_SAMPLERS : HAS_SAMPLERS; | 1758 return flag ? HAS_CPU_PROFILING_SAMPLERS : HAS_SAMPLERS; |
1761 } | 1759 } |
1762 | 1760 |
1763 | 1761 |
1764 void SamplerRegistry::AddActiveSampler(Sampler* sampler) { | 1762 void SamplerRegistry::AddActiveSampler(Sampler* sampler) { |
1765 ASSERT(sampler->IsActive()); | 1763 ASSERT(sampler->IsActive()); |
1766 ScopedLock lock(active_samplers_mutex.Pointer()); | 1764 ScopedLock lock(mutex_); |
1767 if (active_samplers_ == NULL) { | 1765 if (active_samplers_ == NULL) { |
1768 active_samplers_ = new List<Sampler*>; | 1766 active_samplers_ = new List<Sampler*>; |
1769 } else { | 1767 } else { |
1770 ASSERT(!active_samplers_->Contains(sampler)); | 1768 ASSERT(!active_samplers_->Contains(sampler)); |
1771 } | 1769 } |
1772 active_samplers_->Add(sampler); | 1770 active_samplers_->Add(sampler); |
1773 } | 1771 } |
1774 | 1772 |
1775 | 1773 |
1776 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) { | 1774 void SamplerRegistry::RemoveActiveSampler(Sampler* sampler) { |
1777 ASSERT(sampler->IsActive()); | 1775 ASSERT(sampler->IsActive()); |
1778 ScopedLock lock(active_samplers_mutex.Pointer()); | 1776 ScopedLock lock(mutex_); |
1779 ASSERT(active_samplers_ != NULL); | 1777 ASSERT(active_samplers_ != NULL); |
1780 bool removed = active_samplers_->RemoveElement(sampler); | 1778 bool removed = active_samplers_->RemoveElement(sampler); |
1781 ASSERT(removed); | 1779 ASSERT(removed); |
1782 USE(removed); | 1780 USE(removed); |
1783 } | 1781 } |
1784 | 1782 |
1785 } } // namespace v8::internal | 1783 } } // namespace v8::internal |
OLD | NEW |