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 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1923 PrintF("Isolate %p (id %d)" #tag "\n", \ | 1923 PrintF("Isolate %p (id %d)" #tag "\n", \ |
1924 reinterpret_cast<void*>(this), id()); \ | 1924 reinterpret_cast<void*>(this), id()); \ |
1925 } \ | 1925 } \ |
1926 } while (false) | 1926 } while (false) |
1927 #else | 1927 #else |
1928 #define TRACE_ISOLATE(tag) | 1928 #define TRACE_ISOLATE(tag) |
1929 #endif | 1929 #endif |
1930 | 1930 |
1931 class VerboseAccountingAllocator : public AccountingAllocator { | 1931 class VerboseAccountingAllocator : public AccountingAllocator { |
1932 public: | 1932 public: |
1933 VerboseAccountingAllocator(Heap* heap, size_t sample_bytes) | 1933 VerboseAccountingAllocator(Heap* heap, size_t allocation_sample_bytes, |
1934 : heap_(heap), last_memory_usage_(0), sample_bytes_(sample_bytes) {} | 1934 size_t pool_sample_bytes) |
1935 : heap_(heap), | |
1936 last_memory_usage_(0), | |
Michael Lippautz
2016/10/06 12:41:18
Initialize last_pool_size_.
| |
1937 allocation_sample_bytes_(allocation_sample_bytes), | |
1938 pool_sample_bytes_(pool_sample_bytes) {} | |
1935 | 1939 |
1936 v8::internal::Segment* GetSegment(size_t size) override { | 1940 v8::internal::Segment* GetSegment(size_t size) override { |
1937 v8::internal::Segment* memory = AccountingAllocator::GetSegment(size); | 1941 v8::internal::Segment* memory = AccountingAllocator::GetSegment(size); |
1938 if (memory) { | 1942 if (memory) { |
1939 size_t current = GetCurrentMemoryUsage(); | 1943 size_t malloced_current = GetCurrentMemoryUsage(); |
1940 if (last_memory_usage_.Value() + sample_bytes_ < current) { | 1944 size_t pooled_current = GetCurrentPoolSize(); |
1941 PrintJSON(current); | 1945 |
1942 last_memory_usage_.SetValue(current); | 1946 if (last_memory_usage_.Value() + allocation_sample_bytes_ < |
1947 malloced_current || | |
1948 last_pool_size_.Value() + pool_sample_bytes_ < pooled_current) { | |
1949 PrintJSON(malloced_current, pooled_current); | |
1950 last_memory_usage_.SetValue(malloced_current); | |
1951 last_pool_size_.SetValue(pooled_current); | |
1943 } | 1952 } |
1944 } | 1953 } |
1945 return memory; | 1954 return memory; |
1946 } | 1955 } |
1947 | 1956 |
1948 void ReturnSegment(v8::internal::Segment* memory) override { | 1957 void ReturnSegment(v8::internal::Segment* memory) override { |
1949 AccountingAllocator::ReturnSegment(memory); | 1958 AccountingAllocator::ReturnSegment(memory); |
1950 size_t current = GetCurrentMemoryUsage(); | 1959 size_t malloced_current = GetCurrentMemoryUsage(); |
1951 if (current + sample_bytes_ < last_memory_usage_.Value()) { | 1960 size_t pooled_current = GetCurrentPoolSize(); |
1952 PrintJSON(current); | 1961 |
1953 last_memory_usage_.SetValue(current); | 1962 if (malloced_current + allocation_sample_bytes_ < |
1963 last_memory_usage_.Value() || | |
1964 pooled_current + pool_sample_bytes_ < last_pool_size_.Value()) { | |
1965 PrintJSON(malloced_current, pooled_current); | |
1966 last_memory_usage_.SetValue(malloced_current); | |
1967 last_pool_size_.SetValue(pooled_current); | |
1954 } | 1968 } |
1955 } | 1969 } |
1956 | 1970 |
1957 private: | 1971 private: |
1958 void PrintJSON(size_t sample) { | 1972 void PrintJSON(size_t malloced, size_t pooled) { |
1959 // Note: Neither isolate, nor heap is locked, so be careful with accesses | 1973 // Note: Neither isolate, nor heap is locked, so be careful with accesses |
1960 // as the allocator is potentially used on a concurrent thread. | 1974 // as the allocator is potentially used on a concurrent thread. |
1961 double time = heap_->isolate()->time_millis_since_init(); | 1975 double time = heap_->isolate()->time_millis_since_init(); |
1962 PrintF( | 1976 PrintF( |
1963 "{" | 1977 "{" |
1964 "\"type\": \"malloced\", " | 1978 "\"type\": \"zone\", " |
1965 "\"isolate\": \"%p\", " | 1979 "\"isolate\": \"%p\", " |
1966 "\"time\": %f, " | 1980 "\"time\": %f, " |
1967 "\"value\": %zu" | 1981 "\"allocated\": %zu," |
1982 "\"pooled\": %zu" | |
1968 "}\n", | 1983 "}\n", |
1969 reinterpret_cast<void*>(heap_->isolate()), time, sample); | 1984 reinterpret_cast<void*>(heap_->isolate()), time, malloced, pooled); |
1970 } | 1985 } |
1971 | 1986 |
1972 Heap* heap_; | 1987 Heap* heap_; |
1973 base::AtomicNumber<size_t> last_memory_usage_; | 1988 base::AtomicNumber<size_t> last_memory_usage_; |
1974 size_t sample_bytes_; | 1989 base::AtomicNumber<size_t> last_pool_size_; |
1990 size_t allocation_sample_bytes_, pool_sample_bytes_; | |
1975 }; | 1991 }; |
1976 | 1992 |
1977 Isolate::Isolate(bool enable_serializer) | 1993 Isolate::Isolate(bool enable_serializer) |
1978 : embedder_data_(), | 1994 : embedder_data_(), |
1979 entry_stack_(NULL), | 1995 entry_stack_(NULL), |
1980 stack_trace_nesting_level_(0), | 1996 stack_trace_nesting_level_(0), |
1981 incomplete_message_(NULL), | 1997 incomplete_message_(NULL), |
1982 bootstrapper_(NULL), | 1998 bootstrapper_(NULL), |
1983 runtime_profiler_(NULL), | 1999 runtime_profiler_(NULL), |
1984 compilation_cache_(NULL), | 2000 compilation_cache_(NULL), |
1985 counters_(NULL), | 2001 counters_(NULL), |
1986 logger_(NULL), | 2002 logger_(NULL), |
1987 stats_table_(NULL), | 2003 stats_table_(NULL), |
1988 load_stub_cache_(NULL), | 2004 load_stub_cache_(NULL), |
1989 store_stub_cache_(NULL), | 2005 store_stub_cache_(NULL), |
1990 code_aging_helper_(NULL), | 2006 code_aging_helper_(NULL), |
1991 deoptimizer_data_(NULL), | 2007 deoptimizer_data_(NULL), |
1992 deoptimizer_lazy_throw_(false), | 2008 deoptimizer_lazy_throw_(false), |
1993 materialized_object_store_(NULL), | 2009 materialized_object_store_(NULL), |
1994 capture_stack_trace_for_uncaught_exceptions_(false), | 2010 capture_stack_trace_for_uncaught_exceptions_(false), |
1995 stack_trace_for_uncaught_exceptions_frame_limit_(0), | 2011 stack_trace_for_uncaught_exceptions_frame_limit_(0), |
1996 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), | 2012 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), |
1997 keyed_lookup_cache_(NULL), | 2013 keyed_lookup_cache_(NULL), |
1998 context_slot_cache_(NULL), | 2014 context_slot_cache_(NULL), |
1999 descriptor_lookup_cache_(NULL), | 2015 descriptor_lookup_cache_(NULL), |
2000 handle_scope_implementer_(NULL), | 2016 handle_scope_implementer_(NULL), |
2001 unicode_cache_(NULL), | 2017 unicode_cache_(NULL), |
2002 allocator_(FLAG_trace_gc_object_stats | 2018 allocator_(FLAG_trace_gc_object_stats ? new VerboseAccountingAllocator( |
2003 ? new VerboseAccountingAllocator(&heap_, 256 * KB) | 2019 &heap_, 256 * KB, 128 * KB) |
2004 : new AccountingAllocator()), | 2020 : new AccountingAllocator()), |
2005 inner_pointer_to_code_cache_(NULL), | 2021 inner_pointer_to_code_cache_(NULL), |
2006 global_handles_(NULL), | 2022 global_handles_(NULL), |
2007 eternal_handles_(NULL), | 2023 eternal_handles_(NULL), |
2008 thread_manager_(NULL), | 2024 thread_manager_(NULL), |
2009 has_installed_extensions_(false), | 2025 has_installed_extensions_(false), |
2010 regexp_stack_(NULL), | 2026 regexp_stack_(NULL), |
2011 date_cache_(NULL), | 2027 date_cache_(NULL), |
2012 call_descriptor_data_(NULL), | 2028 call_descriptor_data_(NULL), |
2013 // TODO(bmeurer) Initialized lazily because it depends on flags; can | 2029 // TODO(bmeurer) Initialized lazily because it depends on flags; can |
2014 // be fixed once the default isolate cleanup is done. | 2030 // be fixed once the default isolate cleanup is done. |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3310 // Then check whether this scope intercepts. | 3326 // Then check whether this scope intercepts. |
3311 if ((flag & intercept_mask_)) { | 3327 if ((flag & intercept_mask_)) { |
3312 intercepted_flags_ |= flag; | 3328 intercepted_flags_ |= flag; |
3313 return true; | 3329 return true; |
3314 } | 3330 } |
3315 return false; | 3331 return false; |
3316 } | 3332 } |
3317 | 3333 |
3318 } // namespace internal | 3334 } // namespace internal |
3319 } // namespace v8 | 3335 } // namespace v8 |
OLD | NEW |