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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/once.h" | 9 #include "src/base/once.h" |
| 10 #include "src/base/utils/random-number-generator.h" |
10 #include "src/bootstrapper.h" | 11 #include "src/bootstrapper.h" |
11 #include "src/codegen.h" | 12 #include "src/codegen.h" |
12 #include "src/compilation-cache.h" | 13 #include "src/compilation-cache.h" |
13 #include "src/conversions.h" | 14 #include "src/conversions.h" |
14 #include "src/cpu-profiler.h" | 15 #include "src/cpu-profiler.h" |
15 #include "src/debug.h" | 16 #include "src/debug.h" |
16 #include "src/deoptimizer.h" | 17 #include "src/deoptimizer.h" |
17 #include "src/global-handles.h" | 18 #include "src/global-handles.h" |
18 #include "src/heap-profiler.h" | 19 #include "src/heap-profiler.h" |
19 #include "src/incremental-marking.h" | 20 #include "src/incremental-marking.h" |
20 #include "src/isolate-inl.h" | 21 #include "src/isolate-inl.h" |
21 #include "src/mark-compact.h" | 22 #include "src/mark-compact.h" |
22 #include "src/natives.h" | 23 #include "src/natives.h" |
23 #include "src/objects-visiting-inl.h" | 24 #include "src/objects-visiting-inl.h" |
24 #include "src/objects-visiting.h" | 25 #include "src/objects-visiting.h" |
25 #include "src/runtime-profiler.h" | 26 #include "src/runtime-profiler.h" |
26 #include "src/scopeinfo.h" | 27 #include "src/scopeinfo.h" |
27 #include "src/snapshot.h" | 28 #include "src/snapshot.h" |
28 #include "src/store-buffer.h" | 29 #include "src/store-buffer.h" |
29 #include "src/utils.h" | 30 #include "src/utils.h" |
30 #include "src/utils/random-number-generator.h" | |
31 #include "src/v8threads.h" | 31 #include "src/v8threads.h" |
32 #include "src/vm-state-inl.h" | 32 #include "src/vm-state-inl.h" |
33 | 33 |
34 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP | 34 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP |
35 #include "src/regexp-macro-assembler.h" // NOLINT | 35 #include "src/regexp-macro-assembler.h" // NOLINT |
36 #include "src/arm/regexp-macro-assembler-arm.h" // NOLINT | 36 #include "src/arm/regexp-macro-assembler-arm.h" // NOLINT |
37 #endif | 37 #endif |
38 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP | 38 #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP |
39 #include "src/regexp-macro-assembler.h" // NOLINT | 39 #include "src/regexp-macro-assembler.h" // NOLINT |
40 #include "src/mips/regexp-macro-assembler-mips.h" // NOLINT | 40 #include "src/mips/regexp-macro-assembler-mips.h" // NOLINT |
(...skipping 2727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2768 | 2768 |
2769 | 2769 |
2770 void Heap::CreateInitialObjects() { | 2770 void Heap::CreateInitialObjects() { |
2771 HandleScope scope(isolate()); | 2771 HandleScope scope(isolate()); |
2772 Factory* factory = isolate()->factory(); | 2772 Factory* factory = isolate()->factory(); |
2773 | 2773 |
2774 // The -0 value must be set before NumberFromDouble works. | 2774 // The -0 value must be set before NumberFromDouble works. |
2775 set_minus_zero_value(*factory->NewHeapNumber(-0.0, TENURED)); | 2775 set_minus_zero_value(*factory->NewHeapNumber(-0.0, TENURED)); |
2776 ASSERT(std::signbit(minus_zero_value()->Number()) != 0); | 2776 ASSERT(std::signbit(minus_zero_value()->Number()) != 0); |
2777 | 2777 |
2778 set_nan_value(*factory->NewHeapNumber(OS::nan_value(), TENURED)); | 2778 set_nan_value(*factory->NewHeapNumber(base::OS::nan_value(), TENURED)); |
2779 set_infinity_value(*factory->NewHeapNumber(V8_INFINITY, TENURED)); | 2779 set_infinity_value(*factory->NewHeapNumber(V8_INFINITY, TENURED)); |
2780 | 2780 |
2781 // The hole has not been created yet, but we want to put something | 2781 // The hole has not been created yet, but we want to put something |
2782 // predictable in the gaps in the string table, so lets make that Smi zero. | 2782 // predictable in the gaps in the string table, so lets make that Smi zero. |
2783 set_the_hole_value(reinterpret_cast<Oddball*>(Smi::FromInt(0))); | 2783 set_the_hole_value(reinterpret_cast<Oddball*>(Smi::FromInt(0))); |
2784 | 2784 |
2785 // Allocate initial string table. | 2785 // Allocate initial string table. |
2786 set_string_table(*StringTable::New(isolate(), kInitialStringTableSize)); | 2786 set_string_table(*StringTable::New(isolate(), kInitialStringTableSize)); |
2787 | 2787 |
2788 // Finish initializing oddballs after creating the string table. | 2788 // Finish initializing oddballs after creating the string table. |
(...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5019 *stats->cell_space_size = cell_space_->SizeOfObjects(); | 5019 *stats->cell_space_size = cell_space_->SizeOfObjects(); |
5020 *stats->cell_space_capacity = cell_space_->Capacity(); | 5020 *stats->cell_space_capacity = cell_space_->Capacity(); |
5021 *stats->property_cell_space_size = property_cell_space_->SizeOfObjects(); | 5021 *stats->property_cell_space_size = property_cell_space_->SizeOfObjects(); |
5022 *stats->property_cell_space_capacity = property_cell_space_->Capacity(); | 5022 *stats->property_cell_space_capacity = property_cell_space_->Capacity(); |
5023 *stats->lo_space_size = lo_space_->Size(); | 5023 *stats->lo_space_size = lo_space_->Size(); |
5024 isolate_->global_handles()->RecordStats(stats); | 5024 isolate_->global_handles()->RecordStats(stats); |
5025 *stats->memory_allocator_size = isolate()->memory_allocator()->Size(); | 5025 *stats->memory_allocator_size = isolate()->memory_allocator()->Size(); |
5026 *stats->memory_allocator_capacity = | 5026 *stats->memory_allocator_capacity = |
5027 isolate()->memory_allocator()->Size() + | 5027 isolate()->memory_allocator()->Size() + |
5028 isolate()->memory_allocator()->Available(); | 5028 isolate()->memory_allocator()->Available(); |
5029 *stats->os_error = OS::GetLastError(); | 5029 *stats->os_error = base::OS::GetLastError(); |
5030 isolate()->memory_allocator()->Available(); | 5030 isolate()->memory_allocator()->Available(); |
5031 if (take_snapshot) { | 5031 if (take_snapshot) { |
5032 HeapIterator iterator(this); | 5032 HeapIterator iterator(this); |
5033 for (HeapObject* obj = iterator.next(); | 5033 for (HeapObject* obj = iterator.next(); |
5034 obj != NULL; | 5034 obj != NULL; |
5035 obj = iterator.next()) { | 5035 obj = iterator.next()) { |
5036 InstanceType type = obj->map()->instance_type(); | 5036 InstanceType type = obj->map()->instance_type(); |
5037 ASSERT(0 <= type && type <= LAST_TYPE); | 5037 ASSERT(0 <= type && type <= LAST_TYPE); |
5038 stats->objects_per_type[type]++; | 5038 stats->objects_per_type[type]++; |
5039 stats->size_per_type[type] += obj->Size(); | 5039 stats->size_per_type[type] += obj->Size(); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5999 full_gc_count_(0), | 5999 full_gc_count_(0), |
6000 allocated_since_last_gc_(0), | 6000 allocated_since_last_gc_(0), |
6001 spent_in_mutator_(0), | 6001 spent_in_mutator_(0), |
6002 nodes_died_in_new_space_(0), | 6002 nodes_died_in_new_space_(0), |
6003 nodes_copied_in_new_space_(0), | 6003 nodes_copied_in_new_space_(0), |
6004 nodes_promoted_(0), | 6004 nodes_promoted_(0), |
6005 heap_(heap), | 6005 heap_(heap), |
6006 gc_reason_(gc_reason), | 6006 gc_reason_(gc_reason), |
6007 collector_reason_(collector_reason) { | 6007 collector_reason_(collector_reason) { |
6008 if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; | 6008 if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; |
6009 start_time_ = OS::TimeCurrentMillis(); | 6009 start_time_ = base::OS::TimeCurrentMillis(); |
6010 start_object_size_ = heap_->SizeOfObjects(); | 6010 start_object_size_ = heap_->SizeOfObjects(); |
6011 start_memory_size_ = heap_->isolate()->memory_allocator()->Size(); | 6011 start_memory_size_ = heap_->isolate()->memory_allocator()->Size(); |
6012 | 6012 |
6013 for (int i = 0; i < Scope::kNumberOfScopes; i++) { | 6013 for (int i = 0; i < Scope::kNumberOfScopes; i++) { |
6014 scopes_[i] = 0; | 6014 scopes_[i] = 0; |
6015 } | 6015 } |
6016 | 6016 |
6017 in_free_list_or_wasted_before_gc_ = CountTotalHolesSize(heap); | 6017 in_free_list_or_wasted_before_gc_ = CountTotalHolesSize(heap); |
6018 | 6018 |
6019 allocated_since_last_gc_ = | 6019 allocated_since_last_gc_ = |
(...skipping 13 matching lines...) Expand all Loading... |
6033 } | 6033 } |
6034 | 6034 |
6035 | 6035 |
6036 GCTracer::~GCTracer() { | 6036 GCTracer::~GCTracer() { |
6037 // Printf ONE line iff flag is set. | 6037 // Printf ONE line iff flag is set. |
6038 if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; | 6038 if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; |
6039 | 6039 |
6040 bool first_gc = (heap_->last_gc_end_timestamp_ == 0); | 6040 bool first_gc = (heap_->last_gc_end_timestamp_ == 0); |
6041 | 6041 |
6042 heap_->alive_after_last_gc_ = heap_->SizeOfObjects(); | 6042 heap_->alive_after_last_gc_ = heap_->SizeOfObjects(); |
6043 heap_->last_gc_end_timestamp_ = OS::TimeCurrentMillis(); | 6043 heap_->last_gc_end_timestamp_ = base::OS::TimeCurrentMillis(); |
6044 | 6044 |
6045 double time = heap_->last_gc_end_timestamp_ - start_time_; | 6045 double time = heap_->last_gc_end_timestamp_ - start_time_; |
6046 | 6046 |
6047 // Update cumulative GC statistics if required. | 6047 // Update cumulative GC statistics if required. |
6048 if (FLAG_print_cumulative_gc_stat) { | 6048 if (FLAG_print_cumulative_gc_stat) { |
6049 heap_->total_gc_time_ms_ += time; | 6049 heap_->total_gc_time_ms_ += time; |
6050 heap_->max_gc_pause_ = Max(heap_->max_gc_pause_, time); | 6050 heap_->max_gc_pause_ = Max(heap_->max_gc_pause_, time); |
6051 heap_->max_alive_after_gc_ = Max(heap_->max_alive_after_gc_, | 6051 heap_->max_alive_after_gc_ = Max(heap_->max_alive_after_gc_, |
6052 heap_->alive_after_last_gc_); | 6052 heap_->alive_after_last_gc_); |
6053 if (!first_gc) { | 6053 if (!first_gc) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6380 void Heap::ClearObjectStats(bool clear_last_time_stats) { | 6380 void Heap::ClearObjectStats(bool clear_last_time_stats) { |
6381 memset(object_counts_, 0, sizeof(object_counts_)); | 6381 memset(object_counts_, 0, sizeof(object_counts_)); |
6382 memset(object_sizes_, 0, sizeof(object_sizes_)); | 6382 memset(object_sizes_, 0, sizeof(object_sizes_)); |
6383 if (clear_last_time_stats) { | 6383 if (clear_last_time_stats) { |
6384 memset(object_counts_last_time_, 0, sizeof(object_counts_last_time_)); | 6384 memset(object_counts_last_time_, 0, sizeof(object_counts_last_time_)); |
6385 memset(object_sizes_last_time_, 0, sizeof(object_sizes_last_time_)); | 6385 memset(object_sizes_last_time_, 0, sizeof(object_sizes_last_time_)); |
6386 } | 6386 } |
6387 } | 6387 } |
6388 | 6388 |
6389 | 6389 |
6390 static LazyMutex checkpoint_object_stats_mutex = LAZY_MUTEX_INITIALIZER; | 6390 static base::LazyMutex checkpoint_object_stats_mutex = LAZY_MUTEX_INITIALIZER; |
6391 | 6391 |
6392 | 6392 |
6393 void Heap::CheckpointObjectStats() { | 6393 void Heap::CheckpointObjectStats() { |
6394 LockGuard<Mutex> lock_guard(checkpoint_object_stats_mutex.Pointer()); | 6394 base::LockGuard<base::Mutex> lock_guard( |
| 6395 checkpoint_object_stats_mutex.Pointer()); |
6395 Counters* counters = isolate()->counters(); | 6396 Counters* counters = isolate()->counters(); |
6396 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ | 6397 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
6397 counters->count_of_##name()->Increment( \ | 6398 counters->count_of_##name()->Increment( \ |
6398 static_cast<int>(object_counts_[name])); \ | 6399 static_cast<int>(object_counts_[name])); \ |
6399 counters->count_of_##name()->Decrement( \ | 6400 counters->count_of_##name()->Decrement( \ |
6400 static_cast<int>(object_counts_last_time_[name])); \ | 6401 static_cast<int>(object_counts_last_time_[name])); \ |
6401 counters->size_of_##name()->Increment( \ | 6402 counters->size_of_##name()->Increment( \ |
6402 static_cast<int>(object_sizes_[name])); \ | 6403 static_cast<int>(object_sizes_[name])); \ |
6403 counters->size_of_##name()->Decrement( \ | 6404 counters->size_of_##name()->Decrement( \ |
6404 static_cast<int>(object_sizes_last_time_[name])); | 6405 static_cast<int>(object_sizes_last_time_[name])); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6442 static_cast<int>(object_sizes_last_time_[index])); | 6443 static_cast<int>(object_sizes_last_time_[index])); |
6443 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6444 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
6444 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6445 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
6445 | 6446 |
6446 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6447 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
6447 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6448 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
6448 ClearObjectStats(); | 6449 ClearObjectStats(); |
6449 } | 6450 } |
6450 | 6451 |
6451 } } // namespace v8::internal | 6452 } } // namespace v8::internal |
OLD | NEW |