Chromium Code Reviews| 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 1917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 allocation_sample_bytes, | 1933 VerboseAccountingAllocator(Heap* heap, size_t allocation_sample_bytes, |
| 1934 size_t pool_sample_bytes) | 1934 size_t pool_sample_bytes) |
| 1935 : heap_(heap), | 1935 : heap_(heap), |
| 1936 last_memory_usage_(0), | 1936 last_memory_usage_(0), |
| 1937 last_pool_size_(0), | 1937 last_pool_size_(0), |
| 1938 nesting_deepth_(0), | |
| 1938 allocation_sample_bytes_(allocation_sample_bytes), | 1939 allocation_sample_bytes_(allocation_sample_bytes), |
| 1939 pool_sample_bytes_(pool_sample_bytes) {} | 1940 pool_sample_bytes_(pool_sample_bytes) {} |
| 1940 | 1941 |
| 1941 v8::internal::Segment* GetSegment(size_t size) override { | 1942 v8::internal::Segment* GetSegment(size_t size) override { |
| 1942 v8::internal::Segment* memory = AccountingAllocator::GetSegment(size); | 1943 v8::internal::Segment* memory = AccountingAllocator::GetSegment(size); |
| 1943 if (memory) { | 1944 if (memory) { |
| 1944 size_t malloced_current = GetCurrentMemoryUsage(); | 1945 size_t malloced_current = GetCurrentMemoryUsage(); |
| 1945 size_t pooled_current = GetCurrentPoolSize(); | 1946 size_t pooled_current = GetCurrentPoolSize(); |
| 1946 | 1947 |
| 1947 if (last_memory_usage_.Value() + allocation_sample_bytes_ < | 1948 if (last_memory_usage_.Value() + allocation_sample_bytes_ < |
| 1948 malloced_current || | 1949 malloced_current || |
| 1949 last_pool_size_.Value() + pool_sample_bytes_ < pooled_current) { | 1950 last_pool_size_.Value() + pool_sample_bytes_ < pooled_current) { |
| 1950 PrintJSON(malloced_current, pooled_current); | 1951 PrintMemoryJSON(malloced_current, pooled_current); |
| 1951 last_memory_usage_.SetValue(malloced_current); | 1952 last_memory_usage_.SetValue(malloced_current); |
| 1952 last_pool_size_.SetValue(pooled_current); | 1953 last_pool_size_.SetValue(pooled_current); |
| 1953 } | 1954 } |
| 1954 } | 1955 } |
| 1955 return memory; | 1956 return memory; |
| 1956 } | 1957 } |
| 1957 | 1958 |
| 1958 void ReturnSegment(v8::internal::Segment* memory) override { | 1959 void ReturnSegment(v8::internal::Segment* memory) override { |
| 1959 AccountingAllocator::ReturnSegment(memory); | 1960 AccountingAllocator::ReturnSegment(memory); |
| 1960 size_t malloced_current = GetCurrentMemoryUsage(); | 1961 size_t malloced_current = GetCurrentMemoryUsage(); |
| 1961 size_t pooled_current = GetCurrentPoolSize(); | 1962 size_t pooled_current = GetCurrentPoolSize(); |
| 1962 | 1963 |
| 1963 if (malloced_current + allocation_sample_bytes_ < | 1964 if (malloced_current + allocation_sample_bytes_ < |
| 1964 last_memory_usage_.Value() || | 1965 last_memory_usage_.Value() || |
| 1965 pooled_current + pool_sample_bytes_ < last_pool_size_.Value()) { | 1966 pooled_current + pool_sample_bytes_ < last_pool_size_.Value()) { |
| 1966 PrintJSON(malloced_current, pooled_current); | 1967 PrintMemoryJSON(malloced_current, pooled_current); |
| 1967 last_memory_usage_.SetValue(malloced_current); | 1968 last_memory_usage_.SetValue(malloced_current); |
| 1968 last_pool_size_.SetValue(pooled_current); | 1969 last_pool_size_.SetValue(pooled_current); |
| 1969 } | 1970 } |
| 1970 } | 1971 } |
| 1971 | 1972 |
| 1973 void ZoneCreation(const Zone* zone) override { | |
| 1974 double time = heap_->isolate()->time_millis_since_init(); | |
| 1975 PrintF( | |
| 1976 "{" | |
| 1977 "\"type\": \"zonecreation\", " | |
| 1978 "\"isolate\": \"%p\", " | |
| 1979 "\"time\": %f, " | |
| 1980 "\"ptr\": \"%p\", " | |
| 1981 "\"name\": \"%s\"," | |
| 1982 "\"nesting\": %zu" | |
| 1983 "}\n", | |
| 1984 reinterpret_cast<void*>(heap_->isolate()), time, | |
| 1985 reinterpret_cast<const void*>(zone), zone->name(), | |
| 1986 base::NoBarrier_Load(&nesting_deepth_)); | |
| 1987 base::NoBarrier_AtomicIncrement(&nesting_deepth_, 1); | |
| 1988 } | |
| 1989 | |
| 1990 void ZoneDestruction(const Zone* zone) override { | |
| 1991 base::NoBarrier_AtomicIncrement(&nesting_deepth_, -1); | |
| 1992 double time = heap_->isolate()->time_millis_since_init(); | |
| 1993 PrintF( | |
| 1994 "{" | |
| 1995 "\"type\": \"zonedestruction\", " | |
| 1996 "\"isolate\": \"%p\", " | |
| 1997 "\"time\": %f, " | |
| 1998 "\"ptr\": \"%p\", " | |
| 1999 "\"name\": \"%s\", " | |
| 2000 "\"size\": %zu," | |
| 2001 "\"nesting\": %zu" | |
| 2002 "}\n", | |
| 2003 reinterpret_cast<void*>(heap_->isolate()), time, | |
| 2004 reinterpret_cast<const void*>(zone), zone->name(), | |
| 2005 zone->allocation_size(), base::NoBarrier_Load(&nesting_deepth_)); | |
| 2006 } | |
| 2007 | |
| 1972 private: | 2008 private: |
| 1973 void PrintJSON(size_t malloced, size_t pooled) { | 2009 void PrintMemoryJSON(size_t malloced, size_t pooled) { |
| 1974 // Note: Neither isolate, nor heap is locked, so be careful with accesses | 2010 // Note: Neither isolate, nor heap is locked, so be careful with accesses |
| 1975 // as the allocator is potentially used on a concurrent thread. | 2011 // as the allocator is potentially used on a concurrent thread. |
| 1976 double time = heap_->isolate()->time_millis_since_init(); | 2012 double time = heap_->isolate()->time_millis_since_init(); |
| 1977 PrintF( | 2013 PrintF( |
| 1978 "{" | 2014 "{" |
| 1979 "\"type\": \"zone\", " | 2015 "\"type\": \"zone\", " |
| 1980 "\"isolate\": \"%p\", " | 2016 "\"isolate\": \"%p\", " |
| 1981 "\"time\": %f, " | 2017 "\"time\": %f, " |
| 1982 "\"allocated\": %zu," | 2018 "\"allocated\": %zu," |
| 1983 "\"pooled\": %zu" | 2019 "\"pooled\": %zu" |
| 1984 "}\n", | 2020 "}\n", |
| 1985 reinterpret_cast<void*>(heap_->isolate()), time, malloced, pooled); | 2021 reinterpret_cast<void*>(heap_->isolate()), time, malloced, pooled); |
| 1986 } | 2022 } |
| 1987 | 2023 |
| 1988 Heap* heap_; | 2024 Heap* heap_; |
| 1989 base::AtomicNumber<size_t> last_memory_usage_; | 2025 base::AtomicNumber<size_t> last_memory_usage_; |
| 1990 base::AtomicNumber<size_t> last_pool_size_; | 2026 base::AtomicNumber<size_t> last_pool_size_; |
| 2027 base::AtomicWord nesting_deepth_; | |
|
Michael Lippautz
2016/10/11 11:25:19
You should use base::AtomicNumber<size_t/intptr_t>
| |
| 1991 size_t allocation_sample_bytes_, pool_sample_bytes_; | 2028 size_t allocation_sample_bytes_, pool_sample_bytes_; |
| 1992 }; | 2029 }; |
| 1993 | 2030 |
| 1994 Isolate::Isolate(bool enable_serializer) | 2031 Isolate::Isolate(bool enable_serializer) |
| 1995 : embedder_data_(), | 2032 : embedder_data_(), |
| 1996 entry_stack_(NULL), | 2033 entry_stack_(NULL), |
| 1997 stack_trace_nesting_level_(0), | 2034 stack_trace_nesting_level_(0), |
| 1998 incomplete_message_(NULL), | 2035 incomplete_message_(NULL), |
| 1999 bootstrapper_(NULL), | 2036 bootstrapper_(NULL), |
| 2000 runtime_profiler_(NULL), | 2037 runtime_profiler_(NULL), |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3327 // Then check whether this scope intercepts. | 3364 // Then check whether this scope intercepts. |
| 3328 if ((flag & intercept_mask_)) { | 3365 if ((flag & intercept_mask_)) { |
| 3329 intercepted_flags_ |= flag; | 3366 intercepted_flags_ |= flag; |
| 3330 return true; | 3367 return true; |
| 3331 } | 3368 } |
| 3332 return false; | 3369 return false; |
| 3333 } | 3370 } |
| 3334 | 3371 |
| 3335 } // namespace internal | 3372 } // namespace internal |
| 3336 } // namespace v8 | 3373 } // namespace v8 |
| OLD | NEW |