OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/isolate.h" | 5 #include "src/isolate.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <fstream> // NOLINT(readability/streams) | 9 #include <fstream> // NOLINT(readability/streams) |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 do { \ | 1858 do { \ |
1859 if (FLAG_trace_isolates) { \ | 1859 if (FLAG_trace_isolates) { \ |
1860 PrintF("Isolate %p (id %d)" #tag "\n", \ | 1860 PrintF("Isolate %p (id %d)" #tag "\n", \ |
1861 reinterpret_cast<void*>(this), id()); \ | 1861 reinterpret_cast<void*>(this), id()); \ |
1862 } \ | 1862 } \ |
1863 } while (false) | 1863 } while (false) |
1864 #else | 1864 #else |
1865 #define TRACE_ISOLATE(tag) | 1865 #define TRACE_ISOLATE(tag) |
1866 #endif | 1866 #endif |
1867 | 1867 |
| 1868 class VerboseAccountingAllocator : public base::AccountingAllocator { |
| 1869 public: |
| 1870 VerboseAccountingAllocator(Heap* heap, size_t sample_bytes) |
| 1871 : heap_(heap), last_memory_usage_(0), sample_bytes_(sample_bytes) {} |
| 1872 |
| 1873 void* Allocate(size_t size) override { |
| 1874 void* memory = base::AccountingAllocator::Allocate(size); |
| 1875 if (memory) { |
| 1876 size_t current = GetCurrentMemoryUsage(); |
| 1877 if (last_memory_usage_.Value() + sample_bytes_ < current) { |
| 1878 PrintJSON(current); |
| 1879 last_memory_usage_.SetValue(current); |
| 1880 } |
| 1881 } |
| 1882 return memory; |
| 1883 } |
| 1884 |
| 1885 void Free(void* memory, size_t bytes) override { |
| 1886 base::AccountingAllocator::Free(memory, bytes); |
| 1887 size_t current = GetCurrentMemoryUsage(); |
| 1888 if (current + sample_bytes_ < last_memory_usage_.Value()) { |
| 1889 PrintJSON(current); |
| 1890 last_memory_usage_.SetValue(current); |
| 1891 } |
| 1892 } |
| 1893 |
| 1894 private: |
| 1895 void PrintJSON(size_t sample) { |
| 1896 // Note: Neither isolate, nor heap is locked, so be careful with accesses |
| 1897 // as the allocator is potentially used on a concurrent thread. |
| 1898 double time = heap_->isolate()->time_millis_since_init(); |
| 1899 PrintF( |
| 1900 "{" |
| 1901 "\"type\": \"malloced\", " |
| 1902 "\"isolate\": \"%p\", " |
| 1903 "\"time\": %f, " |
| 1904 "\"value\": %zu" |
| 1905 "}\n", |
| 1906 reinterpret_cast<void*>(heap_->isolate()), time, sample); |
| 1907 } |
| 1908 |
| 1909 Heap* heap_; |
| 1910 base::AtomicNumber<size_t> last_memory_usage_; |
| 1911 size_t sample_bytes_; |
| 1912 }; |
| 1913 |
1868 Isolate::Isolate(bool enable_serializer) | 1914 Isolate::Isolate(bool enable_serializer) |
1869 : embedder_data_(), | 1915 : embedder_data_(), |
1870 entry_stack_(NULL), | 1916 entry_stack_(NULL), |
1871 stack_trace_nesting_level_(0), | 1917 stack_trace_nesting_level_(0), |
1872 incomplete_message_(NULL), | 1918 incomplete_message_(NULL), |
1873 bootstrapper_(NULL), | 1919 bootstrapper_(NULL), |
1874 runtime_profiler_(NULL), | 1920 runtime_profiler_(NULL), |
1875 compilation_cache_(NULL), | 1921 compilation_cache_(NULL), |
1876 counters_(NULL), | 1922 counters_(NULL), |
1877 logger_(NULL), | 1923 logger_(NULL), |
1878 stats_table_(NULL), | 1924 stats_table_(NULL), |
1879 load_stub_cache_(NULL), | 1925 load_stub_cache_(NULL), |
1880 store_stub_cache_(NULL), | 1926 store_stub_cache_(NULL), |
1881 code_aging_helper_(NULL), | 1927 code_aging_helper_(NULL), |
1882 deoptimizer_data_(NULL), | 1928 deoptimizer_data_(NULL), |
1883 deoptimizer_lazy_throw_(false), | 1929 deoptimizer_lazy_throw_(false), |
1884 materialized_object_store_(NULL), | 1930 materialized_object_store_(NULL), |
1885 capture_stack_trace_for_uncaught_exceptions_(false), | 1931 capture_stack_trace_for_uncaught_exceptions_(false), |
1886 stack_trace_for_uncaught_exceptions_frame_limit_(0), | 1932 stack_trace_for_uncaught_exceptions_frame_limit_(0), |
1887 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), | 1933 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), |
1888 keyed_lookup_cache_(NULL), | 1934 keyed_lookup_cache_(NULL), |
1889 context_slot_cache_(NULL), | 1935 context_slot_cache_(NULL), |
1890 descriptor_lookup_cache_(NULL), | 1936 descriptor_lookup_cache_(NULL), |
1891 handle_scope_implementer_(NULL), | 1937 handle_scope_implementer_(NULL), |
1892 unicode_cache_(NULL), | 1938 unicode_cache_(NULL), |
1893 runtime_zone_(&allocator_), | 1939 allocator_(FLAG_trace_gc_object_stats |
1894 interface_descriptor_zone_(&allocator_), | 1940 ? new VerboseAccountingAllocator(&heap_, 256 * KB) |
| 1941 : new base::AccountingAllocator()), |
| 1942 runtime_zone_(new Zone(allocator_)), |
| 1943 interface_descriptor_zone_(new Zone(allocator_)), |
1895 inner_pointer_to_code_cache_(NULL), | 1944 inner_pointer_to_code_cache_(NULL), |
1896 global_handles_(NULL), | 1945 global_handles_(NULL), |
1897 eternal_handles_(NULL), | 1946 eternal_handles_(NULL), |
1898 thread_manager_(NULL), | 1947 thread_manager_(NULL), |
1899 has_installed_extensions_(false), | 1948 has_installed_extensions_(false), |
1900 regexp_stack_(NULL), | 1949 regexp_stack_(NULL), |
1901 date_cache_(NULL), | 1950 date_cache_(NULL), |
1902 call_descriptor_data_(NULL), | 1951 call_descriptor_data_(NULL), |
1903 // TODO(bmeurer) Initialized lazily because it depends on flags; can | 1952 // TODO(bmeurer) Initialized lazily because it depends on flags; can |
1904 // be fixed once the default isolate cleanup is done. | 1953 // be fixed once the default isolate cleanup is done. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2081 PerIsolateThreadData* data) { | 2130 PerIsolateThreadData* data) { |
2082 base::Thread::SetThreadLocal(isolate_key_, isolate); | 2131 base::Thread::SetThreadLocal(isolate_key_, isolate); |
2083 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); | 2132 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); |
2084 } | 2133 } |
2085 | 2134 |
2086 | 2135 |
2087 Isolate::~Isolate() { | 2136 Isolate::~Isolate() { |
2088 TRACE_ISOLATE(destructor); | 2137 TRACE_ISOLATE(destructor); |
2089 | 2138 |
2090 // Has to be called while counters_ are still alive | 2139 // Has to be called while counters_ are still alive |
2091 runtime_zone_.DeleteKeptSegment(); | 2140 runtime_zone_->DeleteKeptSegment(); |
2092 | 2141 |
2093 // The entry stack must be empty when we get here. | 2142 // The entry stack must be empty when we get here. |
2094 DCHECK(entry_stack_ == NULL || entry_stack_->previous_item == NULL); | 2143 DCHECK(entry_stack_ == NULL || entry_stack_->previous_item == NULL); |
2095 | 2144 |
2096 delete entry_stack_; | 2145 delete entry_stack_; |
2097 entry_stack_ = NULL; | 2146 entry_stack_ = NULL; |
2098 | 2147 |
2099 delete unicode_cache_; | 2148 delete unicode_cache_; |
2100 unicode_cache_ = NULL; | 2149 unicode_cache_ = NULL; |
2101 | 2150 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2159 | 2208 |
2160 delete random_number_generator_; | 2209 delete random_number_generator_; |
2161 random_number_generator_ = NULL; | 2210 random_number_generator_ = NULL; |
2162 | 2211 |
2163 delete debug_; | 2212 delete debug_; |
2164 debug_ = NULL; | 2213 debug_ = NULL; |
2165 | 2214 |
2166 delete cancelable_task_manager_; | 2215 delete cancelable_task_manager_; |
2167 cancelable_task_manager_ = nullptr; | 2216 cancelable_task_manager_ = nullptr; |
2168 | 2217 |
| 2218 delete runtime_zone_; |
| 2219 runtime_zone_ = nullptr; |
| 2220 |
| 2221 delete interface_descriptor_zone_; |
| 2222 interface_descriptor_zone_ = nullptr; |
| 2223 |
| 2224 delete allocator_; |
| 2225 allocator_ = nullptr; |
| 2226 |
2169 #if USE_SIMULATOR | 2227 #if USE_SIMULATOR |
2170 Simulator::TearDown(simulator_i_cache_, simulator_redirection_); | 2228 Simulator::TearDown(simulator_i_cache_, simulator_redirection_); |
2171 simulator_i_cache_ = nullptr; | 2229 simulator_i_cache_ = nullptr; |
2172 simulator_redirection_ = nullptr; | 2230 simulator_redirection_ = nullptr; |
2173 #endif | 2231 #endif |
2174 } | 2232 } |
2175 | 2233 |
2176 | 2234 |
2177 void Isolate::InitializeThreadLocal() { | 2235 void Isolate::InitializeThreadLocal() { |
2178 thread_local_top_.isolate_ = this; | 2236 thread_local_top_.isolate_ = this; |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3121 // Then check whether this scope intercepts. | 3179 // Then check whether this scope intercepts. |
3122 if ((flag & intercept_mask_)) { | 3180 if ((flag & intercept_mask_)) { |
3123 intercepted_flags_ |= flag; | 3181 intercepted_flags_ |= flag; |
3124 return true; | 3182 return true; |
3125 } | 3183 } |
3126 return false; | 3184 return false; |
3127 } | 3185 } |
3128 | 3186 |
3129 } // namespace internal | 3187 } // namespace internal |
3130 } // namespace v8 | 3188 } // namespace v8 |
OLD | NEW |