ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "accessors.h" |
| 31 | #include "api.h" |
| 32 | #include "bootstrapper.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 34 | #include "compilation-cache.h" |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 35 | #include "cpu-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "debug.h" |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 37 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | #include "global-handles.h" |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 39 | #include "heap-profiler.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 40 | #include "incremental-marking.h" |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 41 | #include "isolate-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | #include "mark-compact.h" |
| 43 | #include "natives.h" |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 44 | #include "objects-visiting.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 45 | #include "objects-visiting-inl.h" |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 46 | #include "once.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 47 | #include "runtime-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | #include "scopeinfo.h" |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 49 | #include "snapshot.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 50 | #include "store-buffer.h" |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 51 | #include "utils/random-number-generator.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | #include "v8threads.h" |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 53 | #include "v8utils.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 54 | #include "vm-state-inl.h" |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 55 | #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 56 | #include "regexp-macro-assembler.h" |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 57 | #include "arm/regexp-macro-assembler-arm.h" |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 58 | #endif |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 59 | #if V8_TARGET_ARCH_MIPS && !V8_INTERPRETED_REGEXP |
| 60 | #include "regexp-macro-assembler.h" |
| 61 | #include "mips/regexp-macro-assembler-mips.h" |
| 62 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 64 | namespace v8 { |
| 65 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 67 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 68 | Heap::Heap() |
| 69 | : isolate_(NULL), |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 70 | code_range_size_(kIs64BitArch ? 512 * MB : 0), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | // semispace_size_ should be a power of 2 and old_generation_size_ should be |
| 72 | // a multiple of Page::kPageSize. |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 73 | reserved_semispace_size_(8 * (kPointerSize / 4) * MB), |
| 74 | max_semispace_size_(8 * (kPointerSize / 4) * MB), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 75 | initial_semispace_size_(Page::kPageSize), |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 76 | max_old_generation_size_(700ul * (kPointerSize / 4) * MB), |
| 77 | max_executable_size_(256ul * (kPointerSize / 4) * MB), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | // Variables set based on semispace_size_ and old_generation_size_ in |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 79 | // ConfigureHeap (survived_since_last_expansion_, external_allocation_limit_) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 80 | // Will be 4 * reserved_semispace_size_ to ensure that young |
| 81 | // generation can be aligned to its size. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 82 | maximum_committed_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 83 | survived_since_last_expansion_(0), |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 84 | sweep_generation_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 85 | always_allocate_scope_depth_(0), |
| 86 | linear_allocation_scope_depth_(0), |
| 87 | contexts_disposed_(0), |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 88 | global_ic_age_(0), |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 89 | flush_monomorphic_ics_(false), |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 90 | allocation_mementos_found_(0), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 91 | scan_on_scavenge_pages_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 92 | new_space_(this), |
| 93 | old_pointer_space_(NULL), |
| 94 | old_data_space_(NULL), |
| 95 | code_space_(NULL), |
| 96 | map_space_(NULL), |
| 97 | cell_space_(NULL), |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 98 | property_cell_space_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 99 | lo_space_(NULL), |
| 100 | gc_state_(NOT_IN_GC), |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 101 | gc_post_processing_depth_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 102 | ms_count_(0), |
| 103 | gc_count_(0), |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 104 | remembered_unmapped_pages_index_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 105 | unflattened_strings_length_(0), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 106 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 107 | allocation_timeout_(0), |
| 108 | disallow_allocation_failure_(false), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | #endif // DEBUG |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 110 | new_space_high_promotion_mode_active_(false), |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 111 | old_generation_allocation_limit_(kMinimumOldGenerationAllocationLimit), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 112 | size_of_old_gen_at_last_old_space_gc_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 113 | external_allocation_limit_(0), |
| 114 | amount_of_external_allocated_memory_(0), |
| 115 | amount_of_external_allocated_memory_at_last_global_gc_(0), |
| 116 | old_gen_exhausted_(false), |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 117 | inline_allocation_disabled_(false), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 118 | store_buffer_rebuilder_(store_buffer()), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 119 | hidden_string_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 120 | gc_safe_size_of_old_object_(NULL), |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 121 | total_regexp_code_generated_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 122 | tracer_(NULL), |
| 123 | young_survivors_after_last_gc_(0), |
| 124 | high_survival_rate_period_length_(0), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 125 | low_survival_rate_period_length_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 126 | survival_rate_(0), |
| 127 | previous_survival_rate_trend_(Heap::STABLE), |
| 128 | survival_rate_trend_(Heap::STABLE), |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 129 | max_gc_pause_(0.0), |
| 130 | total_gc_time_ms_(0.0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 131 | max_alive_after_gc_(0), |
| 132 | min_in_mutator_(kMaxInt), |
| 133 | alive_after_last_gc_(0), |
| 134 | last_gc_end_timestamp_(0.0), |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 135 | marking_time_(0.0), |
| 136 | sweeping_time_(0.0), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 137 | store_buffer_(this), |
| 138 | marking_(this), |
| 139 | incremental_marking_(this), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 140 | number_idle_notifications_(0), |
| 141 | last_idle_notification_gc_count_(0), |
| 142 | last_idle_notification_gc_count_init_(false), |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 143 | mark_sweeps_since_idle_round_started_(0), |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 144 | gc_count_at_last_idle_gc_(0), |
| 145 | scavenges_since_last_idle_round_(kIdleScavengeThreshold), |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 146 | full_codegen_bytes_generated_(0), |
| 147 | crankshaft_codegen_bytes_generated_(0), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 148 | gcs_since_last_deopt_(0), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 149 | #ifdef VERIFY_HEAP |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 150 | no_weak_object_verification_scope_depth_(0), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 151 | #endif |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 152 | promotion_queue_(this), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 153 | configured_(false), |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 154 | chunks_queued_for_free_(NULL), |
| 155 | relocation_mutex_(NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 156 | // Allow build-time customization of the max semispace size. Building |
| 157 | // V8 with snapshots and a non-default max semispace size is much |
| 158 | // easier if you can define it as part of the build environment. |
| 159 | #if defined(V8_MAX_SEMISPACE_SIZE) |
| 160 | max_semispace_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
| 161 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 163 | // Ensure old_generation_size_ is a multiple of kPageSize. |
| 164 | ASSERT(MB >= Page::kPageSize); |
| 165 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 166 | intptr_t max_virtual = OS::MaxVirtualMemory(); |
| 167 | |
| 168 | if (max_virtual > 0) { |
| 169 | if (code_range_size_ > 0) { |
| 170 | // Reserve no more than 1/8 of the memory for the code range. |
| 171 | code_range_size_ = Min(code_range_size_, max_virtual >> 3); |
| 172 | } |
| 173 | } |
| 174 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 175 | memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 176 | native_contexts_list_ = NULL; |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 177 | array_buffers_list_ = Smi::FromInt(0); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 178 | allocation_sites_list_ = Smi::FromInt(0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 179 | mark_compact_collector_.heap_ = this; |
| 180 | external_string_table_.heap_ = this; |
yangguo@chromium.org | cb9affa | 2012-05-15 12:16:38 +0000 | [diff] [blame] | 181 | // Put a dummy entry in the remembered pages so we can find the list the |
| 182 | // minidump even if there are no real unmapped pages. |
| 183 | RememberUnmappedPage(NULL, false); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 184 | |
| 185 | ClearObjectStats(true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 186 | } |
| 187 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 189 | intptr_t Heap::Capacity() { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 190 | if (!HasBeenSetUp()) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 192 | return new_space_.Capacity() + |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 193 | old_pointer_space_->Capacity() + |
| 194 | old_data_space_->Capacity() + |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | code_space_->Capacity() + |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 196 | map_space_->Capacity() + |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 197 | cell_space_->Capacity() + |
| 198 | property_cell_space_->Capacity(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 202 | intptr_t Heap::CommittedMemory() { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 203 | if (!HasBeenSetUp()) return 0; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 204 | |
| 205 | return new_space_.CommittedMemory() + |
| 206 | old_pointer_space_->CommittedMemory() + |
| 207 | old_data_space_->CommittedMemory() + |
| 208 | code_space_->CommittedMemory() + |
| 209 | map_space_->CommittedMemory() + |
| 210 | cell_space_->CommittedMemory() + |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 211 | property_cell_space_->CommittedMemory() + |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 212 | lo_space_->Size(); |
| 213 | } |
| 214 | |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 215 | |
| 216 | size_t Heap::CommittedPhysicalMemory() { |
| 217 | if (!HasBeenSetUp()) return 0; |
| 218 | |
| 219 | return new_space_.CommittedPhysicalMemory() + |
| 220 | old_pointer_space_->CommittedPhysicalMemory() + |
| 221 | old_data_space_->CommittedPhysicalMemory() + |
| 222 | code_space_->CommittedPhysicalMemory() + |
| 223 | map_space_->CommittedPhysicalMemory() + |
| 224 | cell_space_->CommittedPhysicalMemory() + |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 225 | property_cell_space_->CommittedPhysicalMemory() + |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 226 | lo_space_->CommittedPhysicalMemory(); |
| 227 | } |
| 228 | |
| 229 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 230 | intptr_t Heap::CommittedMemoryExecutable() { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 231 | if (!HasBeenSetUp()) return 0; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 232 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 233 | return isolate()->memory_allocator()->SizeExecutable(); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 234 | } |
| 235 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 236 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 237 | void Heap::UpdateMaximumCommitted() { |
| 238 | if (!HasBeenSetUp()) return; |
| 239 | |
| 240 | intptr_t current_committed_memory = CommittedMemory(); |
| 241 | if (current_committed_memory > maximum_committed_) { |
| 242 | maximum_committed_ = current_committed_memory; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 247 | intptr_t Heap::Available() { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 248 | if (!HasBeenSetUp()) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 250 | return new_space_.Available() + |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 251 | old_pointer_space_->Available() + |
| 252 | old_data_space_->Available() + |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | code_space_->Available() + |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 254 | map_space_->Available() + |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 255 | cell_space_->Available() + |
| 256 | property_cell_space_->Available(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 260 | bool Heap::HasBeenSetUp() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 261 | return old_pointer_space_ != NULL && |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 262 | old_data_space_ != NULL && |
| 263 | code_space_ != NULL && |
| 264 | map_space_ != NULL && |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 265 | cell_space_ != NULL && |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 266 | property_cell_space_ != NULL && |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 267 | lo_space_ != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 271 | int Heap::GcSafeSizeOfOldObject(HeapObject* object) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 272 | if (IntrusiveMarking::IsMarked(object)) { |
| 273 | return IntrusiveMarking::SizeOfMarkedObject(object); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 274 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 275 | return object->SizeFromMap(object->map()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 279 | GarbageCollector Heap::SelectGarbageCollector(AllocationSpace space, |
| 280 | const char** reason) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | // Is global GC requested? |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 282 | if (space != NEW_SPACE) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 283 | isolate_->counters()->gc_compactor_caused_by_request()->Increment(); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 284 | *reason = "GC in old space requested"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 285 | return MARK_COMPACTOR; |
| 286 | } |
| 287 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 288 | if (FLAG_gc_global || (FLAG_stress_compaction && (gc_count_ & 1) != 0)) { |
| 289 | *reason = "GC in old space forced by flags"; |
| 290 | return MARK_COMPACTOR; |
| 291 | } |
| 292 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | // Is enough data promoted to justify a global GC? |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 294 | if (OldGenerationAllocationLimitReached()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 295 | isolate_->counters()->gc_compactor_caused_by_promoted_data()->Increment(); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 296 | *reason = "promotion limit reached"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 297 | return MARK_COMPACTOR; |
| 298 | } |
| 299 | |
| 300 | // Have allocation in OLD and LO failed? |
| 301 | if (old_gen_exhausted_) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 302 | isolate_->counters()-> |
| 303 | gc_compactor_caused_by_oldspace_exhaustion()->Increment(); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 304 | *reason = "old generations exhausted"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | return MARK_COMPACTOR; |
| 306 | } |
| 307 | |
| 308 | // Is there enough space left in OLD to guarantee that a scavenge can |
| 309 | // succeed? |
| 310 | // |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 311 | // Note that MemoryAllocator->MaxAvailable() undercounts the memory available |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 312 | // for object promotion. It counts only the bytes that the memory |
| 313 | // allocator has not yet allocated from the OS and assigned to any space, |
| 314 | // and does not count available bytes already in the old space or code |
| 315 | // space. Undercounting is safe---we may get an unrequested full GC when |
| 316 | // a scavenge would have succeeded. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 317 | if (isolate_->memory_allocator()->MaxAvailable() <= new_space_.Size()) { |
| 318 | isolate_->counters()-> |
| 319 | gc_compactor_caused_by_oldspace_exhaustion()->Increment(); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 320 | *reason = "scavenge might not succeed"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 321 | return MARK_COMPACTOR; |
| 322 | } |
| 323 | |
| 324 | // Default |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 325 | *reason = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | return SCAVENGER; |
| 327 | } |
| 328 | |
| 329 | |
| 330 | // TODO(1238405): Combine the infrastructure for --heap-stats and |
| 331 | // --log-gc to avoid the complicated preprocessor and flag testing. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | void Heap::ReportStatisticsBeforeGC() { |
| 333 | // Heap::ReportHeapStatistics will also log NewSpace statistics when |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 334 | // compiled --log-gc is set. The following logic is used to avoid |
| 335 | // double logging. |
| 336 | #ifdef DEBUG |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 337 | if (FLAG_heap_stats || FLAG_log_gc) new_space_.CollectStatistics(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 338 | if (FLAG_heap_stats) { |
| 339 | ReportHeapStatistics("Before GC"); |
| 340 | } else if (FLAG_log_gc) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 341 | new_space_.ReportStatistics(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 342 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 343 | if (FLAG_heap_stats || FLAG_log_gc) new_space_.ClearHistograms(); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 344 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | if (FLAG_log_gc) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 346 | new_space_.CollectStatistics(); |
| 347 | new_space_.ReportStatistics(); |
| 348 | new_space_.ClearHistograms(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 350 | #endif // DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 354 | void Heap::PrintShortHeapStatistics() { |
| 355 | if (!FLAG_trace_gc_verbose) return; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 356 | PrintPID("Memory allocator, used: %6" V8_PTR_PREFIX "d KB" |
| 357 | ", available: %6" V8_PTR_PREFIX "d KB\n", |
| 358 | isolate_->memory_allocator()->Size() / KB, |
| 359 | isolate_->memory_allocator()->Available() / KB); |
| 360 | PrintPID("New space, used: %6" V8_PTR_PREFIX "d KB" |
| 361 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 362 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 363 | new_space_.Size() / KB, |
| 364 | new_space_.Available() / KB, |
| 365 | new_space_.CommittedMemory() / KB); |
| 366 | PrintPID("Old pointers, used: %6" V8_PTR_PREFIX "d KB" |
| 367 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 368 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 369 | old_pointer_space_->SizeOfObjects() / KB, |
| 370 | old_pointer_space_->Available() / KB, |
| 371 | old_pointer_space_->CommittedMemory() / KB); |
| 372 | PrintPID("Old data space, used: %6" V8_PTR_PREFIX "d KB" |
| 373 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 374 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 375 | old_data_space_->SizeOfObjects() / KB, |
| 376 | old_data_space_->Available() / KB, |
| 377 | old_data_space_->CommittedMemory() / KB); |
| 378 | PrintPID("Code space, used: %6" V8_PTR_PREFIX "d KB" |
| 379 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 380 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 381 | code_space_->SizeOfObjects() / KB, |
| 382 | code_space_->Available() / KB, |
| 383 | code_space_->CommittedMemory() / KB); |
| 384 | PrintPID("Map space, used: %6" V8_PTR_PREFIX "d KB" |
| 385 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 386 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 387 | map_space_->SizeOfObjects() / KB, |
| 388 | map_space_->Available() / KB, |
| 389 | map_space_->CommittedMemory() / KB); |
| 390 | PrintPID("Cell space, used: %6" V8_PTR_PREFIX "d KB" |
| 391 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 392 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 393 | cell_space_->SizeOfObjects() / KB, |
| 394 | cell_space_->Available() / KB, |
| 395 | cell_space_->CommittedMemory() / KB); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 396 | PrintPID("PropertyCell space, used: %6" V8_PTR_PREFIX "d KB" |
| 397 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 398 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 399 | property_cell_space_->SizeOfObjects() / KB, |
| 400 | property_cell_space_->Available() / KB, |
| 401 | property_cell_space_->CommittedMemory() / KB); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 402 | PrintPID("Large object space, used: %6" V8_PTR_PREFIX "d KB" |
| 403 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 404 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 405 | lo_space_->SizeOfObjects() / KB, |
| 406 | lo_space_->Available() / KB, |
| 407 | lo_space_->CommittedMemory() / KB); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 408 | PrintPID("All spaces, used: %6" V8_PTR_PREFIX "d KB" |
| 409 | ", available: %6" V8_PTR_PREFIX "d KB" |
| 410 | ", committed: %6" V8_PTR_PREFIX "d KB\n", |
| 411 | this->SizeOfObjects() / KB, |
| 412 | this->Available() / KB, |
| 413 | this->CommittedMemory() / KB); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 414 | PrintPID("External memory reported: %6" V8_PTR_PREFIX "d KB\n", |
| 415 | amount_of_external_allocated_memory_ / KB); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 416 | PrintPID("Total time spent in GC : %.1f ms\n", total_gc_time_ms_); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 417 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 418 | |
| 419 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 420 | // TODO(1238405): Combine the infrastructure for --heap-stats and |
| 421 | // --log-gc to avoid the complicated preprocessor and flag testing. |
| 422 | void Heap::ReportStatisticsAfterGC() { |
| 423 | // Similar to the before GC, we use some complicated logic to ensure that |
| 424 | // NewSpace statistics are logged exactly once when --log-gc is turned on. |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 425 | #if defined(DEBUG) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 426 | if (FLAG_heap_stats) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 427 | new_space_.CollectStatistics(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 428 | ReportHeapStatistics("After GC"); |
| 429 | } else if (FLAG_log_gc) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 430 | new_space_.ReportStatistics(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 432 | #else |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 433 | if (FLAG_log_gc) new_space_.ReportStatistics(); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 434 | #endif // DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 435 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 436 | |
| 437 | |
| 438 | void Heap::GarbageCollectionPrologue() { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 439 | { AllowHeapAllocation for_the_first_part_of_prologue; |
| 440 | isolate_->transcendental_cache()->Clear(); |
| 441 | ClearJSFunctionResultCaches(); |
| 442 | gc_count_++; |
| 443 | unflattened_strings_length_ = 0; |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 444 | |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 445 | if (FLAG_flush_code && FLAG_flush_code_incrementally) { |
| 446 | mark_compact_collector()->EnableCodeFlushing(true); |
| 447 | } |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 448 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 449 | #ifdef VERIFY_HEAP |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 450 | if (FLAG_verify_heap) { |
| 451 | Verify(); |
| 452 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 453 | #endif |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 454 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 455 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 456 | UpdateMaximumCommitted(); |
| 457 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | #ifdef DEBUG |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 459 | ASSERT(!AllowHeapAllocation::IsAllowed() && gc_state_ == NOT_IN_GC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | if (FLAG_gc_verbose) Print(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 462 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | ReportStatisticsBeforeGC(); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 464 | #endif // DEBUG |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 465 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 466 | store_buffer()->GCPrologue(); |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 467 | |
| 468 | if (FLAG_concurrent_osr) { |
| 469 | isolate()->optimizing_compiler_thread()->AgeBufferedOsrJobs(); |
| 470 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | } |
| 472 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 473 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 474 | intptr_t Heap::SizeOfObjects() { |
| 475 | intptr_t total = 0; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 476 | AllSpaces spaces(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 477 | for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 478 | total += space->SizeOfObjects(); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 479 | } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 480 | return total; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 481 | } |
| 482 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 483 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 484 | void Heap::ClearAllICsByKind(Code::Kind kind) { |
| 485 | HeapObjectIterator it(code_space()); |
| 486 | |
| 487 | for (Object* object = it.Next(); object != NULL; object = it.Next()) { |
| 488 | Code* code = Code::cast(object); |
| 489 | Code::Kind current_kind = code->kind(); |
| 490 | if (current_kind == Code::FUNCTION || |
| 491 | current_kind == Code::OPTIMIZED_FUNCTION) { |
| 492 | code->ClearInlineCaches(kind); |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 498 | void Heap::RepairFreeListsAfterBoot() { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 499 | PagedSpaces spaces(this); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 500 | for (PagedSpace* space = spaces.next(); |
| 501 | space != NULL; |
| 502 | space = spaces.next()) { |
| 503 | space->RepairFreeListsAfterBoot(); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 508 | void Heap::GarbageCollectionEpilogue() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 509 | store_buffer()->GCEpilogue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 511 | // In release mode, we only zap the from space under heap verification. |
| 512 | if (Heap::ShouldZapGarbage()) { |
| 513 | ZapFromSpace(); |
| 514 | } |
| 515 | |
| 516 | #ifdef VERIFY_HEAP |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | if (FLAG_verify_heap) { |
| 518 | Verify(); |
| 519 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 520 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 522 | AllowHeapAllocation for_the_rest_of_the_epilogue; |
| 523 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 524 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 525 | if (FLAG_print_global_handles) isolate_->global_handles()->Print(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | if (FLAG_print_handles) PrintHandles(); |
| 527 | if (FLAG_gc_verbose) Print(); |
| 528 | if (FLAG_code_stats) ReportCodeStatistics("After GC"); |
| 529 | #endif |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 530 | if (FLAG_deopt_every_n_garbage_collections > 0) { |
| 531 | if (++gcs_since_last_deopt_ == FLAG_deopt_every_n_garbage_collections) { |
| 532 | Deoptimizer::DeoptimizeAll(isolate()); |
| 533 | gcs_since_last_deopt_ = 0; |
| 534 | } |
| 535 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 537 | UpdateMaximumCommitted(); |
| 538 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 539 | isolate_->counters()->alive_after_last_gc()->Set( |
| 540 | static_cast<int>(SizeOfObjects())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 541 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 542 | isolate_->counters()->string_table_capacity()->Set( |
| 543 | string_table()->Capacity()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 544 | isolate_->counters()->number_of_symbols()->Set( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 545 | string_table()->NumberOfElements()); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 546 | |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 547 | if (full_codegen_bytes_generated_ + crankshaft_codegen_bytes_generated_ > 0) { |
| 548 | isolate_->counters()->codegen_fraction_crankshaft()->AddSample( |
| 549 | static_cast<int>((crankshaft_codegen_bytes_generated_ * 100.0) / |
| 550 | (crankshaft_codegen_bytes_generated_ |
| 551 | + full_codegen_bytes_generated_))); |
| 552 | } |
| 553 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 554 | if (CommittedMemory() > 0) { |
| 555 | isolate_->counters()->external_fragmentation_total()->AddSample( |
| 556 | static_cast<int>(100 - (SizeOfObjects() * 100.0) / CommittedMemory())); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 557 | |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 558 | isolate_->counters()->heap_fraction_new_space()-> |
| 559 | AddSample(static_cast<int>( |
| 560 | (new_space()->CommittedMemory() * 100.0) / CommittedMemory())); |
| 561 | isolate_->counters()->heap_fraction_old_pointer_space()->AddSample( |
| 562 | static_cast<int>( |
| 563 | (old_pointer_space()->CommittedMemory() * 100.0) / |
| 564 | CommittedMemory())); |
| 565 | isolate_->counters()->heap_fraction_old_data_space()->AddSample( |
| 566 | static_cast<int>( |
| 567 | (old_data_space()->CommittedMemory() * 100.0) / |
| 568 | CommittedMemory())); |
| 569 | isolate_->counters()->heap_fraction_code_space()-> |
| 570 | AddSample(static_cast<int>( |
| 571 | (code_space()->CommittedMemory() * 100.0) / CommittedMemory())); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 572 | isolate_->counters()->heap_fraction_map_space()->AddSample( |
| 573 | static_cast<int>( |
| 574 | (map_space()->CommittedMemory() * 100.0) / CommittedMemory())); |
| 575 | isolate_->counters()->heap_fraction_cell_space()->AddSample( |
| 576 | static_cast<int>( |
| 577 | (cell_space()->CommittedMemory() * 100.0) / CommittedMemory())); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 578 | isolate_->counters()->heap_fraction_property_cell_space()-> |
| 579 | AddSample(static_cast<int>( |
| 580 | (property_cell_space()->CommittedMemory() * 100.0) / |
| 581 | CommittedMemory())); |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 582 | isolate_->counters()->heap_fraction_lo_space()-> |
| 583 | AddSample(static_cast<int>( |
| 584 | (lo_space()->CommittedMemory() * 100.0) / CommittedMemory())); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 585 | |
| 586 | isolate_->counters()->heap_sample_total_committed()->AddSample( |
| 587 | static_cast<int>(CommittedMemory() / KB)); |
| 588 | isolate_->counters()->heap_sample_total_used()->AddSample( |
| 589 | static_cast<int>(SizeOfObjects() / KB)); |
| 590 | isolate_->counters()->heap_sample_map_space_committed()->AddSample( |
| 591 | static_cast<int>(map_space()->CommittedMemory() / KB)); |
| 592 | isolate_->counters()->heap_sample_cell_space_committed()->AddSample( |
| 593 | static_cast<int>(cell_space()->CommittedMemory() / KB)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 594 | isolate_->counters()-> |
| 595 | heap_sample_property_cell_space_committed()-> |
| 596 | AddSample(static_cast<int>( |
| 597 | property_cell_space()->CommittedMemory() / KB)); |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 598 | isolate_->counters()->heap_sample_code_space_committed()->AddSample( |
| 599 | static_cast<int>(code_space()->CommittedMemory() / KB)); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 600 | |
| 601 | isolate_->counters()->heap_sample_maximum_committed()->AddSample( |
| 602 | static_cast<int>(MaximumCommittedMemory() / KB)); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 603 | } |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 604 | |
| 605 | #define UPDATE_COUNTERS_FOR_SPACE(space) \ |
| 606 | isolate_->counters()->space##_bytes_available()->Set( \ |
| 607 | static_cast<int>(space()->Available())); \ |
| 608 | isolate_->counters()->space##_bytes_committed()->Set( \ |
| 609 | static_cast<int>(space()->CommittedMemory())); \ |
| 610 | isolate_->counters()->space##_bytes_used()->Set( \ |
| 611 | static_cast<int>(space()->SizeOfObjects())); |
| 612 | #define UPDATE_FRAGMENTATION_FOR_SPACE(space) \ |
| 613 | if (space()->CommittedMemory() > 0) { \ |
| 614 | isolate_->counters()->external_fragmentation_##space()->AddSample( \ |
| 615 | static_cast<int>(100 - \ |
| 616 | (space()->SizeOfObjects() * 100.0) / space()->CommittedMemory())); \ |
| 617 | } |
| 618 | #define UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(space) \ |
| 619 | UPDATE_COUNTERS_FOR_SPACE(space) \ |
| 620 | UPDATE_FRAGMENTATION_FOR_SPACE(space) |
| 621 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 622 | UPDATE_COUNTERS_FOR_SPACE(new_space) |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 623 | UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(old_pointer_space) |
| 624 | UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(old_data_space) |
| 625 | UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(code_space) |
| 626 | UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(map_space) |
| 627 | UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(cell_space) |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 628 | UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(property_cell_space) |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 629 | UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE(lo_space) |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 630 | #undef UPDATE_COUNTERS_FOR_SPACE |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 631 | #undef UPDATE_FRAGMENTATION_FOR_SPACE |
| 632 | #undef UPDATE_COUNTERS_AND_FRAGMENTATION_FOR_SPACE |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 633 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 634 | #if defined(DEBUG) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | ReportStatisticsAfterGC(); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 636 | #endif // DEBUG |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 637 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 638 | isolate_->debug()->AfterGarbageCollection(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 639 | #endif // ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 643 | void Heap::CollectAllGarbage(int flags, const char* gc_reason) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 644 | // Since we are ignoring the return value, the exact choice of space does |
| 645 | // not matter, so long as we do not specify NEW_SPACE, which would not |
| 646 | // cause a full GC. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 647 | mark_compact_collector_.SetFlags(flags); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 648 | CollectGarbage(OLD_POINTER_SPACE, gc_reason); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 649 | mark_compact_collector_.SetFlags(kNoGCFlags); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 653 | void Heap::CollectAllAvailableGarbage(const char* gc_reason) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 654 | // Since we are ignoring the return value, the exact choice of space does |
| 655 | // not matter, so long as we do not specify NEW_SPACE, which would not |
| 656 | // cause a full GC. |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 657 | // Major GC would invoke weak handle callbacks on weakly reachable |
| 658 | // handles, but won't collect weakly reachable objects until next |
| 659 | // major GC. Therefore if we collect aggressively and weak handle callback |
| 660 | // has been invoked, we rerun major GC to release objects which become |
| 661 | // garbage. |
| 662 | // Note: as weak callbacks can execute arbitrary code, we cannot |
| 663 | // hope that eventually there will be no weak callbacks invocations. |
| 664 | // Therefore stop recollecting after several attempts. |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 665 | if (FLAG_concurrent_recompilation) { |
| 666 | // The optimizing compiler may be unnecessarily holding on to memory. |
| 667 | DisallowHeapAllocation no_recursive_gc; |
| 668 | isolate()->optimizing_compiler_thread()->Flush(); |
| 669 | } |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 670 | mark_compact_collector()->SetFlags(kMakeHeapIterableMask | |
| 671 | kReduceMemoryFootprintMask); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 672 | isolate_->compilation_cache()->Clear(); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 673 | const int kMaxNumberOfAttempts = 7; |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 674 | const int kMinNumberOfAttempts = 2; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 675 | for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 676 | if (!CollectGarbage(OLD_POINTER_SPACE, MARK_COMPACTOR, gc_reason, NULL) && |
| 677 | attempt + 1 >= kMinNumberOfAttempts) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 678 | break; |
| 679 | } |
| 680 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 681 | mark_compact_collector()->SetFlags(kNoGCFlags); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 682 | new_space_.Shrink(); |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 683 | UncommitFromSpace(); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 684 | incremental_marking()->UncommitMarkingDeque(); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 688 | bool Heap::CollectGarbage(AllocationSpace space, |
| 689 | GarbageCollector collector, |
| 690 | const char* gc_reason, |
| 691 | const char* collector_reason) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 692 | // The VM is in the GC state until exiting this function. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 693 | VMState<GC> state(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 694 | |
| 695 | #ifdef DEBUG |
| 696 | // Reset the allocation timeout to the GC interval, but make sure to |
| 697 | // allow at least a few allocations after a collection. The reason |
| 698 | // for this is that we have a lot of allocation sequences and we |
| 699 | // assume that a garbage collection will allow the subsequent |
| 700 | // allocation attempts to go through. |
| 701 | allocation_timeout_ = Max(6, FLAG_gc_interval); |
| 702 | #endif |
| 703 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 704 | if (collector == SCAVENGER && !incremental_marking()->IsStopped()) { |
| 705 | if (FLAG_trace_incremental_marking) { |
| 706 | PrintF("[IncrementalMarking] Scavenge during marking.\n"); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | if (collector == MARK_COMPACTOR && |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 711 | !mark_compact_collector()->abort_incremental_marking() && |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 712 | !incremental_marking()->IsStopped() && |
| 713 | !incremental_marking()->should_hurry() && |
| 714 | FLAG_incremental_marking_steps) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 715 | // Make progress in incremental marking. |
| 716 | const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; |
| 717 | incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, |
| 718 | IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 719 | if (!incremental_marking()->IsComplete()) { |
| 720 | if (FLAG_trace_incremental_marking) { |
| 721 | PrintF("[IncrementalMarking] Delaying MarkSweep.\n"); |
| 722 | } |
| 723 | collector = SCAVENGER; |
| 724 | collector_reason = "incremental marking delaying mark-sweep"; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 725 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 726 | } |
| 727 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 728 | bool next_gc_likely_to_collect_more = false; |
| 729 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 730 | { GCTracer tracer(this, gc_reason, collector_reason); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 731 | ASSERT(AllowHeapAllocation::IsAllowed()); |
| 732 | DisallowHeapAllocation no_allocation_during_gc; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 733 | GarbageCollectionPrologue(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 734 | // The GC count was incremented in the prologue. Tell the tracer about |
| 735 | // it. |
| 736 | tracer.set_gc_count(gc_count_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 737 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 738 | // Tell the tracer which collector we've selected. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 739 | tracer.set_collector(collector); |
| 740 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 741 | { |
| 742 | HistogramTimerScope histogram_timer_scope( |
| 743 | (collector == SCAVENGER) ? isolate_->counters()->gc_scavenger() |
| 744 | : isolate_->counters()->gc_compactor()); |
| 745 | next_gc_likely_to_collect_more = |
| 746 | PerformGarbageCollection(collector, &tracer); |
| 747 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 748 | |
| 749 | GarbageCollectionEpilogue(); |
| 750 | } |
| 751 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 752 | // Start incremental marking for the next cycle. The heap snapshot |
| 753 | // generator needs incremental marking to stay off after it aborted. |
| 754 | if (!mark_compact_collector()->abort_incremental_marking() && |
| 755 | incremental_marking()->IsStopped() && |
| 756 | incremental_marking()->WorthActivating() && |
| 757 | NextGCIsLikelyToBeFull()) { |
| 758 | incremental_marking()->Start(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 759 | } |
| 760 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 761 | return next_gc_likely_to_collect_more; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 765 | int Heap::NotifyContextDisposed() { |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 766 | if (FLAG_concurrent_recompilation) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 767 | // Flush the queued recompilation tasks. |
| 768 | isolate()->optimizing_compiler_thread()->Flush(); |
| 769 | } |
| 770 | flush_monomorphic_ics_ = true; |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 771 | AgeInlineCaches(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 772 | return ++contexts_disposed_; |
| 773 | } |
| 774 | |
| 775 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 776 | void Heap::PerformScavenge() { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 777 | GCTracer tracer(this, NULL, NULL); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 778 | if (incremental_marking()->IsStopped()) { |
| 779 | PerformGarbageCollection(SCAVENGER, &tracer); |
| 780 | } else { |
| 781 | PerformGarbageCollection(MARK_COMPACTOR, &tracer); |
| 782 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 786 | void Heap::MoveElements(FixedArray* array, |
| 787 | int dst_index, |
| 788 | int src_index, |
| 789 | int len) { |
| 790 | if (len == 0) return; |
| 791 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 792 | ASSERT(array->map() != fixed_cow_array_map()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 793 | Object** dst_objects = array->data_start() + dst_index; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 794 | OS::MemMove(dst_objects, |
| 795 | array->data_start() + src_index, |
| 796 | len * kPointerSize); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 797 | if (!InNewSpace(array)) { |
| 798 | for (int i = 0; i < len; i++) { |
| 799 | // TODO(hpayer): check store buffer for entries |
| 800 | if (InNewSpace(dst_objects[i])) { |
| 801 | RecordWrite(array->address(), array->OffsetOfElementAt(dst_index + i)); |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | incremental_marking()->RecordWrites(array); |
| 806 | } |
| 807 | |
| 808 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 809 | #ifdef VERIFY_HEAP |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 810 | // Helper class for verifying the string table. |
| 811 | class StringTableVerifier : public ObjectVisitor { |
kasperl@chromium.org | 416c5b0 | 2009-04-14 14:03:52 +0000 | [diff] [blame] | 812 | public: |
kasperl@chromium.org | 416c5b0 | 2009-04-14 14:03:52 +0000 | [diff] [blame] | 813 | void VisitPointers(Object** start, Object** end) { |
| 814 | // Visit all HeapObject pointers in [start, end). |
| 815 | for (Object** p = start; p < end; p++) { |
| 816 | if ((*p)->IsHeapObject()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 817 | // Check that the string is actually internalized. |
| 818 | CHECK((*p)->IsTheHole() || (*p)->IsUndefined() || |
| 819 | (*p)->IsInternalizedString()); |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 820 | } |
| 821 | } |
kasperl@chromium.org | 416c5b0 | 2009-04-14 14:03:52 +0000 | [diff] [blame] | 822 | } |
| 823 | }; |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 824 | |
kasperl@chromium.org | 416c5b0 | 2009-04-14 14:03:52 +0000 | [diff] [blame] | 825 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 826 | static void VerifyStringTable(Heap* heap) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 827 | StringTableVerifier verifier; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 828 | heap->string_table()->IterateElements(&verifier); |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 829 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 830 | #endif // VERIFY_HEAP |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 831 | |
| 832 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 833 | static bool AbortIncrementalMarkingAndCollectGarbage( |
| 834 | Heap* heap, |
| 835 | AllocationSpace space, |
| 836 | const char* gc_reason = NULL) { |
| 837 | heap->mark_compact_collector()->SetFlags(Heap::kAbortIncrementalMarkingMask); |
| 838 | bool result = heap->CollectGarbage(space, gc_reason); |
| 839 | heap->mark_compact_collector()->SetFlags(Heap::kNoGCFlags); |
| 840 | return result; |
| 841 | } |
| 842 | |
| 843 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 844 | void Heap::ReserveSpace(int *sizes, Address *locations_out) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 845 | bool gc_performed = true; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 846 | int counter = 0; |
| 847 | static const int kThreshold = 20; |
| 848 | while (gc_performed && counter++ < kThreshold) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 849 | gc_performed = false; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 850 | ASSERT(NEW_SPACE == FIRST_PAGED_SPACE - 1); |
| 851 | for (int space = NEW_SPACE; space <= LAST_PAGED_SPACE; space++) { |
| 852 | if (sizes[space] != 0) { |
| 853 | MaybeObject* allocation; |
| 854 | if (space == NEW_SPACE) { |
| 855 | allocation = new_space()->AllocateRaw(sizes[space]); |
| 856 | } else { |
| 857 | allocation = paged_space(space)->AllocateRaw(sizes[space]); |
| 858 | } |
| 859 | FreeListNode* node; |
| 860 | if (!allocation->To<FreeListNode>(&node)) { |
| 861 | if (space == NEW_SPACE) { |
| 862 | Heap::CollectGarbage(NEW_SPACE, |
| 863 | "failed to reserve space in the new space"); |
| 864 | } else { |
| 865 | AbortIncrementalMarkingAndCollectGarbage( |
| 866 | this, |
| 867 | static_cast<AllocationSpace>(space), |
| 868 | "failed to reserve space in paged space"); |
| 869 | } |
| 870 | gc_performed = true; |
| 871 | break; |
| 872 | } else { |
| 873 | // Mark with a free list node, in case we have a GC before |
| 874 | // deserializing. |
| 875 | node->set_size(this, sizes[space]); |
| 876 | locations_out[space] = node->address(); |
| 877 | } |
| 878 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 881 | |
| 882 | if (gc_performed) { |
| 883 | // Failed to reserve the space after several attempts. |
| 884 | V8::FatalProcessOutOfMemory("Heap::ReserveSpace"); |
| 885 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 889 | void Heap::EnsureFromSpaceIsCommitted() { |
| 890 | if (new_space_.CommitFromSpaceIfNeeded()) return; |
| 891 | |
| 892 | // Committing memory to from space failed. |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 893 | // Memory is exhausted and we will die. |
| 894 | V8::FatalProcessOutOfMemory("Committing semi space failed."); |
| 895 | } |
| 896 | |
| 897 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 898 | void Heap::ClearJSFunctionResultCaches() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 899 | if (isolate_->bootstrapper()->IsActive()) return; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 900 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 901 | Object* context = native_contexts_list_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 902 | while (!context->IsUndefined()) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 903 | // Get the caches for this context. GC can happen when the context |
| 904 | // is not fully initialized, so the caches can be undefined. |
| 905 | Object* caches_or_undefined = |
| 906 | Context::cast(context)->get(Context::JSFUNCTION_RESULT_CACHES_INDEX); |
| 907 | if (!caches_or_undefined->IsUndefined()) { |
| 908 | FixedArray* caches = FixedArray::cast(caches_or_undefined); |
| 909 | // Clear the caches: |
| 910 | int length = caches->length(); |
| 911 | for (int i = 0; i < length; i++) { |
| 912 | JSFunctionResultCache::cast(caches->get(i))->Clear(); |
| 913 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 914 | } |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 915 | // Get the next context: |
| 916 | context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 917 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 921 | void Heap::ClearNormalizedMapCaches() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 922 | if (isolate_->bootstrapper()->IsActive() && |
| 923 | !incremental_marking()->IsMarking()) { |
| 924 | return; |
| 925 | } |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 926 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 927 | Object* context = native_contexts_list_; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 928 | while (!context->IsUndefined()) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 929 | // GC can happen when the context is not fully initialized, |
| 930 | // so the cache can be undefined. |
| 931 | Object* cache = |
| 932 | Context::cast(context)->get(Context::NORMALIZED_MAP_CACHE_INDEX); |
| 933 | if (!cache->IsUndefined()) { |
| 934 | NormalizedMapCache::cast(cache)->Clear(); |
| 935 | } |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 936 | context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); |
| 937 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 941 | void Heap::UpdateSurvivalRateTrend(int start_new_space_size) { |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 942 | if (start_new_space_size == 0) return; |
| 943 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 944 | double survival_rate = |
| 945 | (static_cast<double>(young_survivors_after_last_gc_) * 100) / |
| 946 | start_new_space_size; |
| 947 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 948 | if (survival_rate > kYoungSurvivalRateHighThreshold) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 949 | high_survival_rate_period_length_++; |
| 950 | } else { |
| 951 | high_survival_rate_period_length_ = 0; |
| 952 | } |
| 953 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 954 | if (survival_rate < kYoungSurvivalRateLowThreshold) { |
| 955 | low_survival_rate_period_length_++; |
| 956 | } else { |
| 957 | low_survival_rate_period_length_ = 0; |
| 958 | } |
| 959 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 960 | double survival_rate_diff = survival_rate_ - survival_rate; |
| 961 | |
| 962 | if (survival_rate_diff > kYoungSurvivalRateAllowedDeviation) { |
| 963 | set_survival_rate_trend(DECREASING); |
| 964 | } else if (survival_rate_diff < -kYoungSurvivalRateAllowedDeviation) { |
| 965 | set_survival_rate_trend(INCREASING); |
| 966 | } else { |
| 967 | set_survival_rate_trend(STABLE); |
| 968 | } |
| 969 | |
| 970 | survival_rate_ = survival_rate; |
| 971 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 972 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 973 | bool Heap::PerformGarbageCollection(GarbageCollector collector, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 974 | GCTracer* tracer) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 975 | bool next_gc_likely_to_collect_more = false; |
| 976 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 977 | if (collector != SCAVENGER) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 978 | PROFILE(isolate_, CodeMovingGCEvent()); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 979 | } |
| 980 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 981 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 982 | if (FLAG_verify_heap) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 983 | VerifyStringTable(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 984 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 985 | #endif |
| 986 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 987 | GCType gc_type = |
| 988 | collector == MARK_COMPACTOR ? kGCTypeMarkSweepCompact : kGCTypeScavenge; |
| 989 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 990 | { |
| 991 | GCTracer::Scope scope(tracer, GCTracer::Scope::EXTERNAL); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 992 | VMState<EXTERNAL> state(isolate_); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 993 | HandleScope handle_scope(isolate_); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 994 | CallGCPrologueCallbacks(gc_type, kNoGCCallbackFlags); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 995 | } |
| 996 | |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 997 | EnsureFromSpaceIsCommitted(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 998 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 999 | int start_new_space_size = Heap::new_space()->SizeAsInt(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1000 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1001 | if (IsHighSurvivalRate()) { |
| 1002 | // We speed up the incremental marker if it is running so that it |
| 1003 | // does not fall behind the rate of promotion, which would cause a |
| 1004 | // constantly growing old space. |
| 1005 | incremental_marking()->NotifyOfHighPromotionRate(); |
| 1006 | } |
| 1007 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1008 | if (collector == MARK_COMPACTOR) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1009 | // Perform mark-sweep with optional compaction. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1010 | MarkCompact(tracer); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1011 | sweep_generation_++; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1012 | |
| 1013 | UpdateSurvivalRateTrend(start_new_space_size); |
| 1014 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 1015 | size_of_old_gen_at_last_old_space_gc_ = PromotedSpaceSizeOfObjects(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1016 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1017 | old_generation_allocation_limit_ = |
| 1018 | OldGenerationAllocationLimit(size_of_old_gen_at_last_old_space_gc_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1019 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1020 | old_gen_exhausted_ = false; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1021 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1022 | tracer_ = tracer; |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1023 | Scavenge(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1024 | tracer_ = NULL; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1025 | |
| 1026 | UpdateSurvivalRateTrend(start_new_space_size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1027 | } |
ager@chromium.org | 439e85a | 2009-08-26 13:15:29 +0000 | [diff] [blame] | 1028 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1029 | if (!new_space_high_promotion_mode_active_ && |
| 1030 | new_space_.Capacity() == new_space_.MaximumCapacity() && |
| 1031 | IsStableOrIncreasingSurvivalTrend() && |
| 1032 | IsHighSurvivalRate()) { |
| 1033 | // Stable high survival rates even though young generation is at |
| 1034 | // maximum capacity indicates that most objects will be promoted. |
| 1035 | // To decrease scavenger pauses and final mark-sweep pauses, we |
| 1036 | // have to limit maximal capacity of the young generation. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1037 | SetNewSpaceHighPromotionModeActive(true); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1038 | if (FLAG_trace_gc) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 1039 | PrintPID("Limited new space size due to high promotion rate: %d MB\n", |
| 1040 | new_space_.InitialCapacity() / MB); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1041 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1042 | // Support for global pre-tenuring uses the high promotion mode as a |
| 1043 | // heuristic indicator of whether to pretenure or not, we trigger |
| 1044 | // deoptimization here to take advantage of pre-tenuring as soon as |
| 1045 | // possible. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1046 | if (FLAG_pretenuring) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1047 | isolate_->stack_guard()->FullDeopt(); |
| 1048 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1049 | } else if (new_space_high_promotion_mode_active_ && |
| 1050 | IsStableOrDecreasingSurvivalTrend() && |
| 1051 | IsLowSurvivalRate()) { |
| 1052 | // Decreasing low survival rates might indicate that the above high |
| 1053 | // promotion mode is over and we should allow the young generation |
| 1054 | // to grow again. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1055 | SetNewSpaceHighPromotionModeActive(false); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1056 | if (FLAG_trace_gc) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 1057 | PrintPID("Unlimited new space size due to low promotion rate: %d MB\n", |
| 1058 | new_space_.MaximumCapacity() / MB); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1059 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1060 | // Trigger deoptimization here to turn off pre-tenuring as soon as |
| 1061 | // possible. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1062 | if (FLAG_pretenuring) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1063 | isolate_->stack_guard()->FullDeopt(); |
| 1064 | } |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1067 | if (new_space_high_promotion_mode_active_ && |
| 1068 | new_space_.Capacity() > new_space_.InitialCapacity()) { |
| 1069 | new_space_.Shrink(); |
| 1070 | } |
| 1071 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1072 | isolate_->counters()->objs_since_last_young()->Set(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1073 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1074 | // Callbacks that fire after this point might trigger nested GCs and |
| 1075 | // restart incremental marking, the assertion can't be moved down. |
| 1076 | ASSERT(collector == SCAVENGER || incremental_marking()->IsStopped()); |
| 1077 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1078 | gc_post_processing_depth_++; |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1079 | { AllowHeapAllocation allow_allocation; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1080 | GCTracer::Scope scope(tracer, GCTracer::Scope::EXTERNAL); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1081 | next_gc_likely_to_collect_more = |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1082 | isolate_->global_handles()->PostGarbageCollectionProcessing( |
| 1083 | collector, tracer); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1084 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1085 | gc_post_processing_depth_--; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1086 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1087 | isolate_->eternal_handles()->PostGarbageCollectionProcessing(this); |
| 1088 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1089 | // Update relocatables. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1090 | Relocatable::PostGarbageCollectionProcessing(isolate_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1091 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1092 | if (collector == MARK_COMPACTOR) { |
| 1093 | // Register the amount of external allocated memory. |
| 1094 | amount_of_external_allocated_memory_at_last_global_gc_ = |
| 1095 | amount_of_external_allocated_memory_; |
| 1096 | } |
| 1097 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1098 | { |
| 1099 | GCTracer::Scope scope(tracer, GCTracer::Scope::EXTERNAL); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1100 | VMState<EXTERNAL> state(isolate_); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1101 | HandleScope handle_scope(isolate_); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1102 | CallGCEpilogueCallbacks(gc_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1103 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1104 | |
| 1105 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1106 | if (FLAG_verify_heap) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1107 | VerifyStringTable(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1108 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1109 | #endif |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1110 | |
| 1111 | return next_gc_likely_to_collect_more; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1115 | void Heap::CallGCPrologueCallbacks(GCType gc_type, GCCallbackFlags flags) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1116 | for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { |
| 1117 | if (gc_type & gc_prologue_callbacks_[i].gc_type) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1118 | if (!gc_prologue_callbacks_[i].pass_isolate_) { |
| 1119 | v8::GCPrologueCallback callback = |
| 1120 | reinterpret_cast<v8::GCPrologueCallback>( |
| 1121 | gc_prologue_callbacks_[i].callback); |
| 1122 | callback(gc_type, flags); |
| 1123 | } else { |
| 1124 | v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate()); |
| 1125 | gc_prologue_callbacks_[i].callback(isolate, gc_type, flags); |
| 1126 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | void Heap::CallGCEpilogueCallbacks(GCType gc_type) { |
| 1133 | for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { |
| 1134 | if (gc_type & gc_epilogue_callbacks_[i].gc_type) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1135 | if (!gc_epilogue_callbacks_[i].pass_isolate_) { |
| 1136 | v8::GCPrologueCallback callback = |
| 1137 | reinterpret_cast<v8::GCPrologueCallback>( |
| 1138 | gc_epilogue_callbacks_[i].callback); |
| 1139 | callback(gc_type, kNoGCCallbackFlags); |
| 1140 | } else { |
| 1141 | v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this->isolate()); |
| 1142 | gc_epilogue_callbacks_[i].callback( |
| 1143 | isolate, gc_type, kNoGCCallbackFlags); |
| 1144 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1145 | } |
| 1146 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1150 | void Heap::MarkCompact(GCTracer* tracer) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1151 | gc_state_ = MARK_COMPACT; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1152 | LOG(isolate_, ResourceEvent("markcompact", "begin")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1153 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1154 | mark_compact_collector_.Prepare(tracer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1155 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1156 | ms_count_++; |
| 1157 | tracer->set_full_gc_count(ms_count_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1158 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1159 | MarkCompactPrologue(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1160 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1161 | mark_compact_collector_.CollectGarbage(); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1162 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1163 | LOG(isolate_, ResourceEvent("markcompact", "end")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1164 | |
| 1165 | gc_state_ = NOT_IN_GC; |
| 1166 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1167 | isolate_->counters()->objs_since_last_full()->Set(0); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 1168 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1169 | flush_monomorphic_ics_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1173 | void Heap::MarkCompactPrologue() { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1174 | // At any old GC clear the keyed lookup cache to enable collection of unused |
| 1175 | // maps. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1176 | isolate_->keyed_lookup_cache()->Clear(); |
| 1177 | isolate_->context_slot_cache()->Clear(); |
| 1178 | isolate_->descriptor_lookup_cache()->Clear(); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1179 | RegExpResultsCache::Clear(string_split_cache()); |
| 1180 | RegExpResultsCache::Clear(regexp_multiple_cache()); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1181 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1182 | isolate_->compilation_cache()->MarkCompactPrologue(); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1183 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1184 | CompletelyClearInstanceofCache(); |
| 1185 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1186 | FlushNumberStringCache(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1187 | if (FLAG_cleanup_code_caches_at_gc) { |
| 1188 | polymorphic_code_cache()->set_cache(undefined_value()); |
| 1189 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1190 | |
| 1191 | ClearNormalizedMapCaches(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1195 | // Helper class for copying HeapObjects |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1196 | class ScavengeVisitor: public ObjectVisitor { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1197 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1198 | explicit ScavengeVisitor(Heap* heap) : heap_(heap) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1199 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1200 | void VisitPointer(Object** p) { ScavengePointer(p); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1201 | |
| 1202 | void VisitPointers(Object** start, Object** end) { |
| 1203 | // Copy all HeapObject pointers in [start, end) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1204 | for (Object** p = start; p < end; p++) ScavengePointer(p); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | private: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1208 | void ScavengePointer(Object** p) { |
| 1209 | Object* object = *p; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1210 | if (!heap_->InNewSpace(object)) return; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1211 | Heap::ScavengeObject(reinterpret_cast<HeapObject**>(p), |
| 1212 | reinterpret_cast<HeapObject*>(object)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1213 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1214 | |
| 1215 | Heap* heap_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1216 | }; |
| 1217 | |
| 1218 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1219 | #ifdef VERIFY_HEAP |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1220 | // Visitor class to verify pointers in code or data space do not point into |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1221 | // new space. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1222 | class VerifyNonPointerSpacePointersVisitor: public ObjectVisitor { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1223 | public: |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1224 | explicit VerifyNonPointerSpacePointersVisitor(Heap* heap) : heap_(heap) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1225 | void VisitPointers(Object** start, Object**end) { |
| 1226 | for (Object** current = start; current < end; current++) { |
| 1227 | if ((*current)->IsHeapObject()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1228 | CHECK(!heap_->InNewSpace(HeapObject::cast(*current))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | } |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1232 | |
| 1233 | private: |
| 1234 | Heap* heap_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1235 | }; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1236 | |
| 1237 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1238 | static void VerifyNonPointerSpacePointers(Heap* heap) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1239 | // Verify that there are no pointers to new space in spaces where we |
| 1240 | // do not expect them. |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1241 | VerifyNonPointerSpacePointersVisitor v(heap); |
| 1242 | HeapObjectIterator code_it(heap->code_space()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1243 | for (HeapObject* object = code_it.Next(); |
| 1244 | object != NULL; object = code_it.Next()) |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1245 | object->Iterate(&v); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1246 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1247 | // The old data space was normally swept conservatively so that the iterator |
| 1248 | // doesn't work, so we normally skip the next bit. |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1249 | if (!heap->old_data_space()->was_swept_conservatively()) { |
| 1250 | HeapObjectIterator data_it(heap->old_data_space()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1251 | for (HeapObject* object = data_it.Next(); |
| 1252 | object != NULL; object = data_it.Next()) |
| 1253 | object->Iterate(&v); |
| 1254 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1255 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1256 | #endif // VERIFY_HEAP |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1257 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1258 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1259 | void Heap::CheckNewSpaceExpansionCriteria() { |
| 1260 | if (new_space_.Capacity() < new_space_.MaximumCapacity() && |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1261 | survived_since_last_expansion_ > new_space_.Capacity() && |
| 1262 | !new_space_high_promotion_mode_active_) { |
| 1263 | // Grow the size of new space if there is room to grow, enough data |
| 1264 | // has survived scavenge since the last expansion and we are not in |
| 1265 | // high promotion mode. |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1266 | new_space_.Grow(); |
| 1267 | survived_since_last_expansion_ = 0; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1272 | static bool IsUnscavengedHeapObject(Heap* heap, Object** p) { |
| 1273 | return heap->InNewSpace(*p) && |
| 1274 | !HeapObject::cast(*p)->map_word().IsForwardingAddress(); |
| 1275 | } |
| 1276 | |
| 1277 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1278 | void Heap::ScavengeStoreBufferCallback( |
| 1279 | Heap* heap, |
| 1280 | MemoryChunk* page, |
| 1281 | StoreBufferEvent event) { |
| 1282 | heap->store_buffer_rebuilder_.Callback(page, event); |
| 1283 | } |
| 1284 | |
| 1285 | |
| 1286 | void StoreBufferRebuilder::Callback(MemoryChunk* page, StoreBufferEvent event) { |
| 1287 | if (event == kStoreBufferStartScanningPagesEvent) { |
| 1288 | start_of_current_page_ = NULL; |
| 1289 | current_page_ = NULL; |
| 1290 | } else if (event == kStoreBufferScanningPageEvent) { |
| 1291 | if (current_page_ != NULL) { |
| 1292 | // If this page already overflowed the store buffer during this iteration. |
| 1293 | if (current_page_->scan_on_scavenge()) { |
| 1294 | // Then we should wipe out the entries that have been added for it. |
| 1295 | store_buffer_->SetTop(start_of_current_page_); |
| 1296 | } else if (store_buffer_->Top() - start_of_current_page_ >= |
| 1297 | (store_buffer_->Limit() - store_buffer_->Top()) >> 2) { |
| 1298 | // Did we find too many pointers in the previous page? The heuristic is |
| 1299 | // that no page can take more then 1/5 the remaining slots in the store |
| 1300 | // buffer. |
| 1301 | current_page_->set_scan_on_scavenge(true); |
| 1302 | store_buffer_->SetTop(start_of_current_page_); |
| 1303 | } else { |
| 1304 | // In this case the page we scanned took a reasonable number of slots in |
| 1305 | // the store buffer. It has now been rehabilitated and is no longer |
| 1306 | // marked scan_on_scavenge. |
| 1307 | ASSERT(!current_page_->scan_on_scavenge()); |
| 1308 | } |
| 1309 | } |
| 1310 | start_of_current_page_ = store_buffer_->Top(); |
| 1311 | current_page_ = page; |
| 1312 | } else if (event == kStoreBufferFullEvent) { |
| 1313 | // The current page overflowed the store buffer again. Wipe out its entries |
| 1314 | // in the store buffer and mark it scan-on-scavenge again. This may happen |
| 1315 | // several times while scanning. |
| 1316 | if (current_page_ == NULL) { |
| 1317 | // Store Buffer overflowed while scanning promoted objects. These are not |
| 1318 | // in any particular page, though they are likely to be clustered by the |
| 1319 | // allocation routines. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1320 | store_buffer_->EnsureSpace(StoreBuffer::kStoreBufferSize / 2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1321 | } else { |
| 1322 | // Store Buffer overflowed while scanning a particular old space page for |
| 1323 | // pointers to new space. |
| 1324 | ASSERT(current_page_ == page); |
| 1325 | ASSERT(page != NULL); |
| 1326 | current_page_->set_scan_on_scavenge(true); |
| 1327 | ASSERT(start_of_current_page_ != store_buffer_->Top()); |
| 1328 | store_buffer_->SetTop(start_of_current_page_); |
| 1329 | } |
| 1330 | } else { |
| 1331 | UNREACHABLE(); |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1336 | void PromotionQueue::Initialize() { |
| 1337 | // Assumes that a NewSpacePage exactly fits a number of promotion queue |
| 1338 | // entries (where each is a pair of intptr_t). This allows us to simplify |
| 1339 | // the test fpr when to switch pages. |
| 1340 | ASSERT((Page::kPageSize - MemoryChunk::kBodyOffset) % (2 * kPointerSize) |
| 1341 | == 0); |
| 1342 | limit_ = reinterpret_cast<intptr_t*>(heap_->new_space()->ToSpaceStart()); |
| 1343 | front_ = rear_ = |
| 1344 | reinterpret_cast<intptr_t*>(heap_->new_space()->ToSpaceEnd()); |
| 1345 | emergency_stack_ = NULL; |
| 1346 | guard_ = false; |
| 1347 | } |
| 1348 | |
| 1349 | |
| 1350 | void PromotionQueue::RelocateQueueHead() { |
| 1351 | ASSERT(emergency_stack_ == NULL); |
| 1352 | |
| 1353 | Page* p = Page::FromAllocationTop(reinterpret_cast<Address>(rear_)); |
| 1354 | intptr_t* head_start = rear_; |
| 1355 | intptr_t* head_end = |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1356 | Min(front_, reinterpret_cast<intptr_t*>(p->area_end())); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1357 | |
| 1358 | int entries_count = |
| 1359 | static_cast<int>(head_end - head_start) / kEntrySizeInWords; |
| 1360 | |
| 1361 | emergency_stack_ = new List<Entry>(2 * entries_count); |
| 1362 | |
| 1363 | while (head_start != head_end) { |
| 1364 | int size = static_cast<int>(*(head_start++)); |
| 1365 | HeapObject* obj = reinterpret_cast<HeapObject*>(*(head_start++)); |
| 1366 | emergency_stack_->Add(Entry(obj, size)); |
| 1367 | } |
| 1368 | rear_ = head_end; |
| 1369 | } |
| 1370 | |
| 1371 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1372 | class ScavengeWeakObjectRetainer : public WeakObjectRetainer { |
| 1373 | public: |
| 1374 | explicit ScavengeWeakObjectRetainer(Heap* heap) : heap_(heap) { } |
| 1375 | |
| 1376 | virtual Object* RetainAs(Object* object) { |
| 1377 | if (!heap_->InFromSpace(object)) { |
| 1378 | return object; |
| 1379 | } |
| 1380 | |
| 1381 | MapWord map_word = HeapObject::cast(object)->map_word(); |
| 1382 | if (map_word.IsForwardingAddress()) { |
| 1383 | return map_word.ToForwardingAddress(); |
| 1384 | } |
| 1385 | return NULL; |
| 1386 | } |
| 1387 | |
| 1388 | private: |
| 1389 | Heap* heap_; |
| 1390 | }; |
| 1391 | |
| 1392 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1393 | void Heap::Scavenge() { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1394 | RelocationLock relocation_lock(this); |
| 1395 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1396 | allocation_mementos_found_ = 0; |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1397 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1398 | #ifdef VERIFY_HEAP |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 1399 | if (FLAG_verify_heap) VerifyNonPointerSpacePointers(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1400 | #endif |
| 1401 | |
| 1402 | gc_state_ = SCAVENGE; |
| 1403 | |
| 1404 | // Implements Cheney's copying algorithm |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1405 | LOG(isolate_, ResourceEvent("scavenge", "begin")); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1406 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1407 | // Clear descriptor cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1408 | isolate_->descriptor_lookup_cache()->Clear(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1409 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1410 | // Used for updating survived_since_last_expansion_ at function end. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1411 | intptr_t survived_watermark = PromotedSpaceSizeOfObjects(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1412 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1413 | CheckNewSpaceExpansionCriteria(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1414 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1415 | SelectScavengingVisitorsTable(); |
| 1416 | |
| 1417 | incremental_marking()->PrepareForScavenge(); |
| 1418 | |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 1419 | paged_space(OLD_DATA_SPACE)->EnsureSweeperProgress(new_space_.Size()); |
| 1420 | paged_space(OLD_POINTER_SPACE)->EnsureSweeperProgress(new_space_.Size()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1421 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1422 | // Flip the semispaces. After flipping, to space is empty, from space has |
| 1423 | // live objects. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1424 | new_space_.Flip(); |
| 1425 | new_space_.ResetAllocationInfo(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1426 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1427 | // We need to sweep newly copied objects which can be either in the |
| 1428 | // to space or promoted to the old generation. For to-space |
| 1429 | // objects, we treat the bottom of the to space as a queue. Newly |
| 1430 | // copied and unswept objects lie between a 'front' mark and the |
| 1431 | // allocation pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1432 | // |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1433 | // Promoted objects can go into various old-generation spaces, and |
| 1434 | // can be allocated internally in the spaces (from the free list). |
| 1435 | // We treat the top of the to space as a queue of addresses of |
| 1436 | // promoted objects. The addresses of newly promoted and unswept |
| 1437 | // objects lie between a 'front' mark and a 'rear' mark that is |
| 1438 | // updated as a side effect of promoting an object. |
| 1439 | // |
| 1440 | // There is guaranteed to be enough room at the top of the to space |
| 1441 | // for the addresses of promoted objects: every object promoted |
| 1442 | // frees up its size in bytes from the top of the new space, and |
| 1443 | // objects are at least one pointer in size. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1444 | Address new_space_front = new_space_.ToSpaceStart(); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1445 | promotion_queue_.Initialize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1446 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1447 | #ifdef DEBUG |
| 1448 | store_buffer()->Clean(); |
| 1449 | #endif |
| 1450 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1451 | ScavengeVisitor scavenge_visitor(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1452 | // Copy roots. |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1453 | IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1454 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1455 | // Copy objects reachable from the old generation. |
| 1456 | { |
| 1457 | StoreBufferRebuildScope scope(this, |
| 1458 | store_buffer(), |
| 1459 | &ScavengeStoreBufferCallback); |
| 1460 | store_buffer()->IteratePointersToNewSpace(&ScavengeObject); |
| 1461 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1462 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1463 | // Copy objects reachable from simple cells by scavenging cell values |
| 1464 | // directly. |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1465 | HeapObjectIterator cell_iterator(cell_space_); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1466 | for (HeapObject* heap_object = cell_iterator.Next(); |
| 1467 | heap_object != NULL; |
| 1468 | heap_object = cell_iterator.Next()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1469 | if (heap_object->IsCell()) { |
| 1470 | Cell* cell = Cell::cast(heap_object); |
| 1471 | Address value_address = cell->ValueAddress(); |
| 1472 | scavenge_visitor.VisitPointer(reinterpret_cast<Object**>(value_address)); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | // Copy objects reachable from global property cells by scavenging global |
| 1477 | // property cell values directly. |
| 1478 | HeapObjectIterator js_global_property_cell_iterator(property_cell_space_); |
| 1479 | for (HeapObject* heap_object = js_global_property_cell_iterator.Next(); |
| 1480 | heap_object != NULL; |
| 1481 | heap_object = js_global_property_cell_iterator.Next()) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1482 | if (heap_object->IsPropertyCell()) { |
| 1483 | PropertyCell* cell = PropertyCell::cast(heap_object); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1484 | Address value_address = cell->ValueAddress(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1485 | scavenge_visitor.VisitPointer(reinterpret_cast<Object**>(value_address)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1486 | Address type_address = cell->TypeAddress(); |
| 1487 | scavenge_visitor.VisitPointer(reinterpret_cast<Object**>(type_address)); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1488 | } |
| 1489 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1490 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1491 | // Copy objects reachable from the code flushing candidates list. |
| 1492 | MarkCompactCollector* collector = mark_compact_collector(); |
| 1493 | if (collector->is_code_flushing_enabled()) { |
| 1494 | collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor); |
| 1495 | } |
| 1496 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1497 | // Scavenge object reachable from the native contexts list directly. |
| 1498 | scavenge_visitor.VisitPointer(BitCast<Object**>(&native_contexts_list_)); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1499 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1500 | new_space_front = DoScavenge(&scavenge_visitor, new_space_front); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1501 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1502 | while (isolate()->global_handles()->IterateObjectGroups( |
| 1503 | &scavenge_visitor, &IsUnscavengedHeapObject)) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1504 | new_space_front = DoScavenge(&scavenge_visitor, new_space_front); |
| 1505 | } |
| 1506 | isolate()->global_handles()->RemoveObjectGroups(); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1507 | isolate()->global_handles()->RemoveImplicitRefGroups(); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1508 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1509 | isolate_->global_handles()->IdentifyNewSpaceWeakIndependentHandles( |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1510 | &IsUnscavengedHeapObject); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1511 | isolate_->global_handles()->IterateNewSpaceWeakIndependentRoots( |
| 1512 | &scavenge_visitor); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1513 | new_space_front = DoScavenge(&scavenge_visitor, new_space_front); |
| 1514 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1515 | UpdateNewSpaceReferencesInExternalStringTable( |
| 1516 | &UpdateNewSpaceReferenceInExternalStringTableEntry); |
| 1517 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1518 | promotion_queue_.Destroy(); |
| 1519 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1520 | if (!FLAG_watch_ic_patching) { |
| 1521 | isolate()->runtime_profiler()->UpdateSamplesAfterScavenge(); |
| 1522 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1523 | incremental_marking()->UpdateMarkingDequeAfterScavenge(); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1524 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1525 | ScavengeWeakObjectRetainer weak_object_retainer(this); |
| 1526 | ProcessWeakReferences(&weak_object_retainer); |
| 1527 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1528 | ASSERT(new_space_front == new_space_.top()); |
| 1529 | |
| 1530 | // Set age mark. |
| 1531 | new_space_.set_age_mark(new_space_.top()); |
| 1532 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1533 | new_space_.LowerInlineAllocationLimit( |
| 1534 | new_space_.inline_allocation_limit_step()); |
| 1535 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1536 | // Update how much has survived scavenge. |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1537 | IncrementYoungSurvivorsCounter(static_cast<int>( |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1538 | (PromotedSpaceSizeOfObjects() - survived_watermark) + new_space_.Size())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1539 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1540 | LOG(isolate_, ResourceEvent("scavenge", "end")); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1541 | |
| 1542 | gc_state_ = NOT_IN_GC; |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 1543 | |
| 1544 | scavenges_since_last_idle_round_++; |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1545 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1546 | if (FLAG_trace_track_allocation_sites && allocation_mementos_found_ > 0) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1547 | PrintF("AllocationMementos found during scavenge = %d\n", |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1548 | allocation_mementos_found_); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1549 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1553 | String* Heap::UpdateNewSpaceReferenceInExternalStringTableEntry(Heap* heap, |
| 1554 | Object** p) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1555 | MapWord first_word = HeapObject::cast(*p)->map_word(); |
| 1556 | |
| 1557 | if (!first_word.IsForwardingAddress()) { |
| 1558 | // Unreachable external string can be finalized. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1559 | heap->FinalizeExternalString(String::cast(*p)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1560 | return NULL; |
| 1561 | } |
| 1562 | |
| 1563 | // String is still reachable. |
| 1564 | return String::cast(first_word.ToForwardingAddress()); |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | void Heap::UpdateNewSpaceReferencesInExternalStringTable( |
| 1569 | ExternalStringTableUpdaterCallback updater_func) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1570 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1571 | if (FLAG_verify_heap) { |
| 1572 | external_string_table_.Verify(); |
| 1573 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1574 | #endif |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1575 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1576 | if (external_string_table_.new_space_strings_.is_empty()) return; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1577 | |
danno@chromium.org | 2ab0c3b | 2012-10-05 08:50:56 +0000 | [diff] [blame] | 1578 | Object** start = &external_string_table_.new_space_strings_[0]; |
| 1579 | Object** end = start + external_string_table_.new_space_strings_.length(); |
| 1580 | Object** last = start; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1581 | |
danno@chromium.org | 2ab0c3b | 2012-10-05 08:50:56 +0000 | [diff] [blame] | 1582 | for (Object** p = start; p < end; ++p) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1583 | ASSERT(InFromSpace(*p)); |
| 1584 | String* target = updater_func(this, p); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1585 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 1586 | if (target == NULL) continue; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1587 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1588 | ASSERT(target->IsExternalString()); |
| 1589 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1590 | if (InNewSpace(target)) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1591 | // String is still in new space. Update the table entry. |
| 1592 | *last = target; |
| 1593 | ++last; |
| 1594 | } else { |
| 1595 | // String got promoted. Move it to the old string list. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1596 | external_string_table_.AddOldString(target); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1597 | } |
| 1598 | } |
| 1599 | |
danno@chromium.org | 2ab0c3b | 2012-10-05 08:50:56 +0000 | [diff] [blame] | 1600 | ASSERT(last <= end); |
| 1601 | external_string_table_.ShrinkNewStrings(static_cast<int>(last - start)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1605 | void Heap::UpdateReferencesInExternalStringTable( |
| 1606 | ExternalStringTableUpdaterCallback updater_func) { |
| 1607 | |
| 1608 | // Update old space string references. |
| 1609 | if (external_string_table_.old_space_strings_.length() > 0) { |
danno@chromium.org | 2ab0c3b | 2012-10-05 08:50:56 +0000 | [diff] [blame] | 1610 | Object** start = &external_string_table_.old_space_strings_[0]; |
| 1611 | Object** end = start + external_string_table_.old_space_strings_.length(); |
| 1612 | for (Object** p = start; p < end; ++p) *p = updater_func(this, p); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | UpdateNewSpaceReferencesInExternalStringTable(updater_func); |
| 1616 | } |
| 1617 | |
| 1618 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1619 | template <class T> |
| 1620 | struct WeakListVisitor; |
| 1621 | |
| 1622 | |
| 1623 | template <class T> |
| 1624 | static Object* VisitWeakList(Heap* heap, |
| 1625 | Object* list, |
| 1626 | WeakObjectRetainer* retainer, |
| 1627 | bool record_slots) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1628 | Object* undefined = heap->undefined_value(); |
| 1629 | Object* head = undefined; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1630 | T* tail = NULL; |
| 1631 | MarkCompactCollector* collector = heap->mark_compact_collector(); |
| 1632 | while (list != undefined) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1633 | // Check whether to keep the candidate in the list. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1634 | T* candidate = reinterpret_cast<T*>(list); |
| 1635 | Object* retained = retainer->RetainAs(list); |
| 1636 | if (retained != NULL) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1637 | if (head == undefined) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1638 | // First element in the list. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1639 | head = retained; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1640 | } else { |
| 1641 | // Subsequent elements in the list. |
| 1642 | ASSERT(tail != NULL); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1643 | WeakListVisitor<T>::SetWeakNext(tail, retained); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1644 | if (record_slots) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1645 | Object** next_slot = |
| 1646 | HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset()); |
| 1647 | collector->RecordSlot(next_slot, next_slot, retained); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1648 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1649 | } |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1650 | // Retained object is new tail. |
| 1651 | ASSERT(!retained->IsUndefined()); |
| 1652 | candidate = reinterpret_cast<T*>(retained); |
| 1653 | tail = candidate; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1654 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1655 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1656 | // tail is a live object, visit it. |
| 1657 | WeakListVisitor<T>::VisitLiveObject( |
| 1658 | heap, tail, retainer, record_slots); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1659 | } else { |
| 1660 | WeakListVisitor<T>::VisitPhantomObject(heap, candidate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1661 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1662 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1663 | // Move to next element in the list. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1664 | list = WeakListVisitor<T>::WeakNext(candidate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | // Terminate the list if there is one or more elements. |
| 1668 | if (tail != NULL) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1669 | WeakListVisitor<T>::SetWeakNext(tail, undefined); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1670 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1671 | return head; |
| 1672 | } |
| 1673 | |
| 1674 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1675 | template<> |
| 1676 | struct WeakListVisitor<JSFunction> { |
| 1677 | static void SetWeakNext(JSFunction* function, Object* next) { |
| 1678 | function->set_next_function_link(next); |
| 1679 | } |
| 1680 | |
| 1681 | static Object* WeakNext(JSFunction* function) { |
| 1682 | return function->next_function_link(); |
| 1683 | } |
| 1684 | |
| 1685 | static int WeakNextOffset() { |
| 1686 | return JSFunction::kNextFunctionLinkOffset; |
| 1687 | } |
| 1688 | |
| 1689 | static void VisitLiveObject(Heap*, JSFunction*, |
| 1690 | WeakObjectRetainer*, bool) { |
| 1691 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1692 | |
| 1693 | static void VisitPhantomObject(Heap*, JSFunction*) { |
| 1694 | } |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1695 | }; |
| 1696 | |
| 1697 | |
| 1698 | template<> |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1699 | struct WeakListVisitor<Code> { |
| 1700 | static void SetWeakNext(Code* code, Object* next) { |
| 1701 | code->set_next_code_link(next); |
| 1702 | } |
| 1703 | |
| 1704 | static Object* WeakNext(Code* code) { |
| 1705 | return code->next_code_link(); |
| 1706 | } |
| 1707 | |
| 1708 | static int WeakNextOffset() { |
| 1709 | return Code::kNextCodeLinkOffset; |
| 1710 | } |
| 1711 | |
| 1712 | static void VisitLiveObject(Heap*, Code*, |
| 1713 | WeakObjectRetainer*, bool) { |
| 1714 | } |
| 1715 | |
| 1716 | static void VisitPhantomObject(Heap*, Code*) { |
| 1717 | } |
| 1718 | }; |
| 1719 | |
| 1720 | |
| 1721 | template<> |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1722 | struct WeakListVisitor<Context> { |
| 1723 | static void SetWeakNext(Context* context, Object* next) { |
| 1724 | context->set(Context::NEXT_CONTEXT_LINK, |
| 1725 | next, |
| 1726 | UPDATE_WRITE_BARRIER); |
| 1727 | } |
| 1728 | |
| 1729 | static Object* WeakNext(Context* context) { |
| 1730 | return context->get(Context::NEXT_CONTEXT_LINK); |
| 1731 | } |
| 1732 | |
| 1733 | static void VisitLiveObject(Heap* heap, |
| 1734 | Context* context, |
| 1735 | WeakObjectRetainer* retainer, |
| 1736 | bool record_slots) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1737 | // Process the three weak lists linked off the context. |
| 1738 | DoWeakList<JSFunction>(heap, context, retainer, record_slots, |
| 1739 | Context::OPTIMIZED_FUNCTIONS_LIST); |
| 1740 | DoWeakList<Code>(heap, context, retainer, record_slots, |
| 1741 | Context::OPTIMIZED_CODE_LIST); |
| 1742 | DoWeakList<Code>(heap, context, retainer, record_slots, |
| 1743 | Context::DEOPTIMIZED_CODE_LIST); |
| 1744 | } |
| 1745 | |
| 1746 | template<class T> |
| 1747 | static void DoWeakList(Heap* heap, |
| 1748 | Context* context, |
| 1749 | WeakObjectRetainer* retainer, |
| 1750 | bool record_slots, |
| 1751 | int index) { |
| 1752 | // Visit the weak list, removing dead intermediate elements. |
| 1753 | Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer, |
| 1754 | record_slots); |
| 1755 | |
| 1756 | // Update the list head. |
| 1757 | context->set(index, list_head, UPDATE_WRITE_BARRIER); |
| 1758 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1759 | if (record_slots) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1760 | // Record the updated slot if necessary. |
| 1761 | Object** head_slot = HeapObject::RawField( |
| 1762 | context, FixedArray::SizeFor(index)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1763 | heap->mark_compact_collector()->RecordSlot( |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1764 | head_slot, head_slot, list_head); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1768 | static void VisitPhantomObject(Heap*, Context*) { |
| 1769 | } |
| 1770 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1771 | static int WeakNextOffset() { |
| 1772 | return FixedArray::SizeFor(Context::NEXT_CONTEXT_LINK); |
| 1773 | } |
| 1774 | }; |
| 1775 | |
| 1776 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1777 | void Heap::ProcessWeakReferences(WeakObjectRetainer* retainer) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1778 | // We don't record weak slots during marking or scavenges. |
| 1779 | // Instead we do it once when we complete mark-compact cycle. |
| 1780 | // Note that write barrier has no effect if we are already in the middle of |
| 1781 | // compacting mark-sweep cycle and we have to record slots manually. |
| 1782 | bool record_slots = |
| 1783 | gc_state() == MARK_COMPACT && |
| 1784 | mark_compact_collector()->is_compacting(); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1785 | ProcessArrayBuffers(retainer, record_slots); |
| 1786 | ProcessNativeContexts(retainer, record_slots); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1787 | ProcessAllocationSites(retainer, record_slots); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer, |
| 1791 | bool record_slots) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1792 | Object* head = |
| 1793 | VisitWeakList<Context>( |
| 1794 | this, native_contexts_list(), retainer, record_slots); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1795 | // Update the head of the list of contexts. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1796 | native_contexts_list_ = head; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1800 | template<> |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1801 | struct WeakListVisitor<JSArrayBufferView> { |
| 1802 | static void SetWeakNext(JSArrayBufferView* obj, Object* next) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1803 | obj->set_weak_next(next); |
| 1804 | } |
| 1805 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1806 | static Object* WeakNext(JSArrayBufferView* obj) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1807 | return obj->weak_next(); |
| 1808 | } |
| 1809 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1810 | static void VisitLiveObject(Heap*, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1811 | JSArrayBufferView* obj, |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1812 | WeakObjectRetainer* retainer, |
| 1813 | bool record_slots) {} |
| 1814 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1815 | static void VisitPhantomObject(Heap*, JSArrayBufferView*) {} |
| 1816 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1817 | static int WeakNextOffset() { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1818 | return JSArrayBufferView::kWeakNextOffset; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1819 | } |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1820 | }; |
| 1821 | |
| 1822 | |
| 1823 | template<> |
| 1824 | struct WeakListVisitor<JSArrayBuffer> { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1825 | static void SetWeakNext(JSArrayBuffer* obj, Object* next) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1826 | obj->set_weak_next(next); |
| 1827 | } |
| 1828 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1829 | static Object* WeakNext(JSArrayBuffer* obj) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1830 | return obj->weak_next(); |
| 1831 | } |
| 1832 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1833 | static void VisitLiveObject(Heap* heap, |
| 1834 | JSArrayBuffer* array_buffer, |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1835 | WeakObjectRetainer* retainer, |
| 1836 | bool record_slots) { |
| 1837 | Object* typed_array_obj = |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1838 | VisitWeakList<JSArrayBufferView>( |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1839 | heap, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1840 | array_buffer->weak_first_view(), |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1841 | retainer, record_slots); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1842 | array_buffer->set_weak_first_view(typed_array_obj); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1843 | if (typed_array_obj != heap->undefined_value() && record_slots) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1844 | Object** slot = HeapObject::RawField( |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1845 | array_buffer, JSArrayBuffer::kWeakFirstViewOffset); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1846 | heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1850 | static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { |
| 1851 | Runtime::FreeArrayBuffer(heap->isolate(), phantom); |
| 1852 | } |
| 1853 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1854 | static int WeakNextOffset() { |
| 1855 | return JSArrayBuffer::kWeakNextOffset; |
| 1856 | } |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1857 | }; |
| 1858 | |
| 1859 | |
| 1860 | void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer, |
| 1861 | bool record_slots) { |
| 1862 | Object* array_buffer_obj = |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1863 | VisitWeakList<JSArrayBuffer>(this, |
| 1864 | array_buffers_list(), |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1865 | retainer, record_slots); |
| 1866 | set_array_buffers_list(array_buffer_obj); |
| 1867 | } |
| 1868 | |
| 1869 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1870 | void Heap::TearDownArrayBuffers() { |
| 1871 | Object* undefined = undefined_value(); |
| 1872 | for (Object* o = array_buffers_list(); o != undefined;) { |
| 1873 | JSArrayBuffer* buffer = JSArrayBuffer::cast(o); |
| 1874 | Runtime::FreeArrayBuffer(isolate(), buffer); |
| 1875 | o = buffer->weak_next(); |
| 1876 | } |
| 1877 | array_buffers_list_ = undefined; |
| 1878 | } |
| 1879 | |
| 1880 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1881 | template<> |
| 1882 | struct WeakListVisitor<AllocationSite> { |
| 1883 | static void SetWeakNext(AllocationSite* obj, Object* next) { |
| 1884 | obj->set_weak_next(next); |
| 1885 | } |
| 1886 | |
| 1887 | static Object* WeakNext(AllocationSite* obj) { |
| 1888 | return obj->weak_next(); |
| 1889 | } |
| 1890 | |
| 1891 | static void VisitLiveObject(Heap* heap, |
| 1892 | AllocationSite* array_buffer, |
| 1893 | WeakObjectRetainer* retainer, |
| 1894 | bool record_slots) {} |
| 1895 | |
| 1896 | static void VisitPhantomObject(Heap* heap, AllocationSite* phantom) {} |
| 1897 | |
| 1898 | static int WeakNextOffset() { |
| 1899 | return AllocationSite::kWeakNextOffset; |
| 1900 | } |
| 1901 | }; |
| 1902 | |
| 1903 | |
| 1904 | void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer, |
| 1905 | bool record_slots) { |
| 1906 | Object* allocation_site_obj = |
| 1907 | VisitWeakList<AllocationSite>(this, |
| 1908 | allocation_sites_list(), |
| 1909 | retainer, record_slots); |
| 1910 | set_allocation_sites_list(allocation_site_obj); |
| 1911 | } |
| 1912 | |
| 1913 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1914 | void Heap::VisitExternalResources(v8::ExternalResourceVisitor* visitor) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 1915 | DisallowHeapAllocation no_allocation; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1916 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1917 | // Both the external string table and the string table may contain |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1918 | // external strings, but neither lists them exhaustively, nor is the |
| 1919 | // intersection set empty. Therefore we iterate over the external string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1920 | // table first, ignoring internalized strings, and then over the |
| 1921 | // internalized string table. |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1922 | |
| 1923 | class ExternalStringTableVisitorAdapter : public ObjectVisitor { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1924 | public: |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1925 | explicit ExternalStringTableVisitorAdapter( |
| 1926 | v8::ExternalResourceVisitor* visitor) : visitor_(visitor) {} |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1927 | virtual void VisitPointers(Object** start, Object** end) { |
| 1928 | for (Object** p = start; p < end; p++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1929 | // Visit non-internalized external strings, |
| 1930 | // since internalized strings are listed in the string table. |
| 1931 | if (!(*p)->IsInternalizedString()) { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1932 | ASSERT((*p)->IsExternalString()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1933 | visitor_->VisitExternalString(Utils::ToLocal( |
| 1934 | Handle<String>(String::cast(*p)))); |
| 1935 | } |
| 1936 | } |
| 1937 | } |
| 1938 | private: |
| 1939 | v8::ExternalResourceVisitor* visitor_; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1940 | } external_string_table_visitor(visitor); |
| 1941 | |
| 1942 | external_string_table_.Iterate(&external_string_table_visitor); |
| 1943 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1944 | class StringTableVisitorAdapter : public ObjectVisitor { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1945 | public: |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1946 | explicit StringTableVisitorAdapter( |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1947 | v8::ExternalResourceVisitor* visitor) : visitor_(visitor) {} |
| 1948 | virtual void VisitPointers(Object** start, Object** end) { |
| 1949 | for (Object** p = start; p < end; p++) { |
| 1950 | if ((*p)->IsExternalString()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1951 | ASSERT((*p)->IsInternalizedString()); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1952 | visitor_->VisitExternalString(Utils::ToLocal( |
| 1953 | Handle<String>(String::cast(*p)))); |
| 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | private: |
| 1958 | v8::ExternalResourceVisitor* visitor_; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1959 | } string_table_visitor(visitor); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1960 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1961 | string_table()->IterateElements(&string_table_visitor); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1965 | class NewSpaceScavenger : public StaticNewSpaceVisitor<NewSpaceScavenger> { |
| 1966 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1967 | static inline void VisitPointer(Heap* heap, Object** p) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1968 | Object* object = *p; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1969 | if (!heap->InNewSpace(object)) return; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1970 | Heap::ScavengeObject(reinterpret_cast<HeapObject**>(p), |
| 1971 | reinterpret_cast<HeapObject*>(object)); |
| 1972 | } |
| 1973 | }; |
| 1974 | |
| 1975 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1976 | Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor, |
| 1977 | Address new_space_front) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1978 | do { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1979 | SemiSpace::AssertValidRange(new_space_front, new_space_.top()); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1980 | // The addresses new_space_front and new_space_.top() define a |
| 1981 | // queue of unprocessed copied objects. Process them until the |
| 1982 | // queue is empty. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1983 | while (new_space_front != new_space_.top()) { |
| 1984 | if (!NewSpacePage::IsAtEnd(new_space_front)) { |
| 1985 | HeapObject* object = HeapObject::FromAddress(new_space_front); |
| 1986 | new_space_front += |
| 1987 | NewSpaceScavenger::IterateBody(object->map(), object); |
| 1988 | } else { |
| 1989 | new_space_front = |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1990 | NewSpacePage::FromLimit(new_space_front)->next_page()->area_start(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1991 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1994 | // Promote and process all the to-be-promoted objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1995 | { |
| 1996 | StoreBufferRebuildScope scope(this, |
| 1997 | store_buffer(), |
| 1998 | &ScavengeStoreBufferCallback); |
| 1999 | while (!promotion_queue()->is_empty()) { |
| 2000 | HeapObject* target; |
| 2001 | int size; |
| 2002 | promotion_queue()->remove(&target, &size); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2003 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2004 | // Promoted object might be already partially visited |
| 2005 | // during old space pointer iteration. Thus we search specificly |
| 2006 | // for pointers to from semispace instead of looking for pointers |
| 2007 | // to new space. |
| 2008 | ASSERT(!target->IsMap()); |
| 2009 | IterateAndMarkPointersToFromSpace(target->address(), |
| 2010 | target->address() + size, |
| 2011 | &ScavengeObject); |
| 2012 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | // Take another spin if there are now unswept objects in new space |
| 2016 | // (there are currently no more unswept promoted objects). |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2017 | } while (new_space_front != new_space_.top()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2018 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2019 | return new_space_front; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2023 | STATIC_ASSERT((FixedDoubleArray::kHeaderSize & kDoubleAlignmentMask) == 0); |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 2024 | STATIC_ASSERT((ConstantPoolArray::kHeaderSize & kDoubleAlignmentMask) == 0); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2025 | |
| 2026 | |
| 2027 | INLINE(static HeapObject* EnsureDoubleAligned(Heap* heap, |
| 2028 | HeapObject* object, |
| 2029 | int size)); |
| 2030 | |
| 2031 | static HeapObject* EnsureDoubleAligned(Heap* heap, |
| 2032 | HeapObject* object, |
| 2033 | int size) { |
| 2034 | if ((OffsetFrom(object->address()) & kDoubleAlignmentMask) != 0) { |
| 2035 | heap->CreateFillerObjectAt(object->address(), kPointerSize); |
| 2036 | return HeapObject::FromAddress(object->address() + kPointerSize); |
| 2037 | } else { |
| 2038 | heap->CreateFillerObjectAt(object->address() + size - kPointerSize, |
| 2039 | kPointerSize); |
| 2040 | return object; |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2045 | enum LoggingAndProfiling { |
| 2046 | LOGGING_AND_PROFILING_ENABLED, |
| 2047 | LOGGING_AND_PROFILING_DISABLED |
| 2048 | }; |
| 2049 | |
| 2050 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2051 | enum MarksHandling { TRANSFER_MARKS, IGNORE_MARKS }; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2052 | |
| 2053 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2054 | template<MarksHandling marks_handling, |
| 2055 | LoggingAndProfiling logging_and_profiling_mode> |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2056 | class ScavengingVisitor : public StaticVisitorBase { |
| 2057 | public: |
| 2058 | static void Initialize() { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2059 | table_.Register(kVisitSeqOneByteString, &EvacuateSeqOneByteString); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2060 | table_.Register(kVisitSeqTwoByteString, &EvacuateSeqTwoByteString); |
| 2061 | table_.Register(kVisitShortcutCandidate, &EvacuateShortcutCandidate); |
| 2062 | table_.Register(kVisitByteArray, &EvacuateByteArray); |
| 2063 | table_.Register(kVisitFixedArray, &EvacuateFixedArray); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2064 | table_.Register(kVisitFixedDoubleArray, &EvacuateFixedDoubleArray); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2065 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2066 | table_.Register(kVisitNativeContext, |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 2067 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2068 | template VisitSpecialized<Context::kSize>); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2069 | |
| 2070 | table_.Register(kVisitConsString, |
| 2071 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2072 | template VisitSpecialized<ConsString::kSize>); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2073 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2074 | table_.Register(kVisitSlicedString, |
| 2075 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2076 | template VisitSpecialized<SlicedString::kSize>); |
| 2077 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2078 | table_.Register(kVisitSymbol, |
| 2079 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2080 | template VisitSpecialized<Symbol::kSize>); |
| 2081 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2082 | table_.Register(kVisitSharedFunctionInfo, |
| 2083 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2084 | template VisitSpecialized<SharedFunctionInfo::kSize>); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2085 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2086 | table_.Register(kVisitJSWeakMap, |
| 2087 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2088 | Visit); |
| 2089 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 2090 | table_.Register(kVisitJSWeakSet, |
| 2091 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2092 | Visit); |
| 2093 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 2094 | table_.Register(kVisitJSArrayBuffer, |
| 2095 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2096 | Visit); |
| 2097 | |
| 2098 | table_.Register(kVisitJSTypedArray, |
| 2099 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2100 | Visit); |
| 2101 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2102 | table_.Register(kVisitJSDataView, |
| 2103 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2104 | Visit); |
| 2105 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 2106 | table_.Register(kVisitJSRegExp, |
| 2107 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2108 | Visit); |
| 2109 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2110 | if (marks_handling == IGNORE_MARKS) { |
| 2111 | table_.Register(kVisitJSFunction, |
| 2112 | &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2113 | template VisitSpecialized<JSFunction::kSize>); |
| 2114 | } else { |
| 2115 | table_.Register(kVisitJSFunction, &EvacuateJSFunction); |
| 2116 | } |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2117 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2118 | table_.RegisterSpecializations<ObjectEvacuationStrategy<DATA_OBJECT>, |
| 2119 | kVisitDataObject, |
| 2120 | kVisitDataObjectGeneric>(); |
| 2121 | |
| 2122 | table_.RegisterSpecializations<ObjectEvacuationStrategy<POINTER_OBJECT>, |
| 2123 | kVisitJSObject, |
| 2124 | kVisitJSObjectGeneric>(); |
| 2125 | |
| 2126 | table_.RegisterSpecializations<ObjectEvacuationStrategy<POINTER_OBJECT>, |
| 2127 | kVisitStruct, |
| 2128 | kVisitStructGeneric>(); |
| 2129 | } |
| 2130 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2131 | static VisitorDispatchTable<ScavengingCallback>* GetTable() { |
| 2132 | return &table_; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2135 | private: |
| 2136 | enum ObjectContents { DATA_OBJECT, POINTER_OBJECT }; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2137 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2138 | static void RecordCopiedObject(Heap* heap, HeapObject* obj) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2139 | bool should_record = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2140 | #ifdef DEBUG |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2141 | should_record = FLAG_heap_stats; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2142 | #endif |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2143 | should_record = should_record || FLAG_log_gc; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2144 | if (should_record) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2145 | if (heap->new_space()->Contains(obj)) { |
| 2146 | heap->new_space()->RecordAllocation(obj); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2147 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2148 | heap->new_space()->RecordPromotion(obj); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2149 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2150 | } |
| 2151 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2152 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2153 | // Helper function used by CopyObject to copy a source object to an |
| 2154 | // allocated target object and update the forwarding pointer in the source |
| 2155 | // object. Returns the target object. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2156 | INLINE(static void MigrateObject(Heap* heap, |
| 2157 | HeapObject* source, |
| 2158 | HeapObject* target, |
| 2159 | int size)) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2160 | // Copy the content of source to target. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2161 | heap->CopyBlock(target->address(), source->address(), size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2162 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2163 | // Set the forwarding address. |
| 2164 | source->set_map_word(MapWord::FromForwardingAddress(target)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2165 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2166 | if (logging_and_profiling_mode == LOGGING_AND_PROFILING_ENABLED) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2167 | // Update NewSpace stats if necessary. |
| 2168 | RecordCopiedObject(heap, target); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2169 | Isolate* isolate = heap->isolate(); |
mstarzinger@chromium.org | 2ed0d02 | 2013-10-17 08:06:21 +0000 | [diff] [blame] | 2170 | HeapProfiler* heap_profiler = isolate->heap_profiler(); |
| 2171 | if (heap_profiler->is_profiling()) { |
| 2172 | heap_profiler->ObjectMoveEvent(source->address(), target->address(), |
| 2173 | size); |
| 2174 | } |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2175 | if (isolate->logger()->is_logging_code_events() || |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2176 | isolate->cpu_profiler()->is_profiling()) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2177 | if (target->IsSharedFunctionInfo()) { |
| 2178 | PROFILE(isolate, SharedFunctionInfoMoveEvent( |
| 2179 | source->address(), target->address())); |
| 2180 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2181 | } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2184 | if (marks_handling == TRANSFER_MARKS) { |
| 2185 | if (Marking::TransferColor(source, target)) { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2186 | MemoryChunk::IncrementLiveBytesFromGC(target->address(), size); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2187 | } |
| 2188 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2189 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2190 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2191 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2192 | template<ObjectContents object_contents, int alignment> |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2193 | static inline void EvacuateObject(Map* map, |
| 2194 | HeapObject** slot, |
| 2195 | HeapObject* object, |
| 2196 | int object_size) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2197 | SLOW_ASSERT(object_size <= Page::kMaxNonCodeHeapObjectSize); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2198 | SLOW_ASSERT(object->Size() == object_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2199 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2200 | int allocation_size = object_size; |
| 2201 | if (alignment != kObjectAlignment) { |
| 2202 | ASSERT(alignment == kDoubleAlignment); |
| 2203 | allocation_size += kPointerSize; |
| 2204 | } |
| 2205 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2206 | Heap* heap = map->GetHeap(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2207 | if (heap->ShouldBePromoted(object->address(), object_size)) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2208 | MaybeObject* maybe_result; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2209 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2210 | if (object_contents == DATA_OBJECT) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2211 | ASSERT(heap->AllowedToBeMigrated(object, OLD_DATA_SPACE)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2212 | maybe_result = heap->old_data_space()->AllocateRaw(allocation_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2213 | } else { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2214 | ASSERT(heap->AllowedToBeMigrated(object, OLD_POINTER_SPACE)); |
verwaest@chromium.org | ec6855e | 2013-08-22 12:26:58 +0000 | [diff] [blame] | 2215 | maybe_result = heap->old_pointer_space()->AllocateRaw(allocation_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2218 | Object* result = NULL; // Initialization to please compiler. |
| 2219 | if (maybe_result->ToObject(&result)) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2220 | HeapObject* target = HeapObject::cast(result); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2221 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2222 | if (alignment != kObjectAlignment) { |
| 2223 | target = EnsureDoubleAligned(heap, target, allocation_size); |
| 2224 | } |
| 2225 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2226 | // Order is important: slot might be inside of the target if target |
| 2227 | // was allocated over a dead object and slot comes from the store |
| 2228 | // buffer. |
| 2229 | *slot = target; |
| 2230 | MigrateObject(heap, object, target, object_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2231 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2232 | if (object_contents == POINTER_OBJECT) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2233 | if (map->instance_type() == JS_FUNCTION_TYPE) { |
| 2234 | heap->promotion_queue()->insert( |
| 2235 | target, JSFunction::kNonWeakFieldsEndOffset); |
| 2236 | } else { |
| 2237 | heap->promotion_queue()->insert(target, object_size); |
| 2238 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2239 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2240 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2241 | heap->tracer()->increment_promoted_objects_size(object_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2242 | return; |
| 2243 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2244 | } |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 2245 | ASSERT(heap->AllowedToBeMigrated(object, NEW_SPACE)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2246 | MaybeObject* allocation = heap->new_space()->AllocateRaw(allocation_size); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2247 | heap->promotion_queue()->SetNewLimit(heap->new_space()->top()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2248 | Object* result = allocation->ToObjectUnchecked(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2249 | HeapObject* target = HeapObject::cast(result); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2250 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2251 | if (alignment != kObjectAlignment) { |
| 2252 | target = EnsureDoubleAligned(heap, target, allocation_size); |
| 2253 | } |
| 2254 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2255 | // Order is important: slot might be inside of the target if target |
| 2256 | // was allocated over a dead object and slot comes from the store |
| 2257 | // buffer. |
| 2258 | *slot = target; |
| 2259 | MigrateObject(heap, object, target, object_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2260 | return; |
| 2261 | } |
| 2262 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2263 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2264 | static inline void EvacuateJSFunction(Map* map, |
| 2265 | HeapObject** slot, |
| 2266 | HeapObject* object) { |
| 2267 | ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 2268 | template VisitSpecialized<JSFunction::kSize>(map, slot, object); |
| 2269 | |
| 2270 | HeapObject* target = *slot; |
| 2271 | MarkBit mark_bit = Marking::MarkBitFrom(target); |
| 2272 | if (Marking::IsBlack(mark_bit)) { |
| 2273 | // This object is black and it might not be rescanned by marker. |
| 2274 | // We should explicitly record code entry slot for compaction because |
| 2275 | // promotion queue processing (IterateAndMarkPointersToFromSpace) will |
| 2276 | // miss it as it is not HeapObject-tagged. |
| 2277 | Address code_entry_slot = |
| 2278 | target->address() + JSFunction::kCodeEntryOffset; |
| 2279 | Code* code = Code::cast(Code::GetObjectFromEntryAddress(code_entry_slot)); |
| 2280 | map->GetHeap()->mark_compact_collector()-> |
| 2281 | RecordCodeEntrySlot(code_entry_slot, code); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2286 | static inline void EvacuateFixedArray(Map* map, |
| 2287 | HeapObject** slot, |
| 2288 | HeapObject* object) { |
| 2289 | int object_size = FixedArray::BodyDescriptor::SizeOf(map, object); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2290 | EvacuateObject<POINTER_OBJECT, kObjectAlignment>( |
| 2291 | map, slot, object, object_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2292 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2293 | |
| 2294 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2295 | static inline void EvacuateFixedDoubleArray(Map* map, |
| 2296 | HeapObject** slot, |
| 2297 | HeapObject* object) { |
| 2298 | int length = reinterpret_cast<FixedDoubleArray*>(object)->length(); |
| 2299 | int object_size = FixedDoubleArray::SizeFor(length); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2300 | EvacuateObject<DATA_OBJECT, kDoubleAlignment>( |
| 2301 | map, slot, object, object_size); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2305 | static inline void EvacuateByteArray(Map* map, |
| 2306 | HeapObject** slot, |
| 2307 | HeapObject* object) { |
| 2308 | int object_size = reinterpret_cast<ByteArray*>(object)->ByteArraySize(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2309 | EvacuateObject<DATA_OBJECT, kObjectAlignment>( |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2310 | map, slot, object, object_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2311 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2312 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2313 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2314 | static inline void EvacuateSeqOneByteString(Map* map, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2315 | HeapObject** slot, |
| 2316 | HeapObject* object) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2317 | int object_size = SeqOneByteString::cast(object)-> |
| 2318 | SeqOneByteStringSize(map->instance_type()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2319 | EvacuateObject<DATA_OBJECT, kObjectAlignment>( |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2320 | map, slot, object, object_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | |
| 2324 | static inline void EvacuateSeqTwoByteString(Map* map, |
| 2325 | HeapObject** slot, |
| 2326 | HeapObject* object) { |
| 2327 | int object_size = SeqTwoByteString::cast(object)-> |
| 2328 | SeqTwoByteStringSize(map->instance_type()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2329 | EvacuateObject<DATA_OBJECT, kObjectAlignment>( |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2330 | map, slot, object, object_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | static inline bool IsShortcutCandidate(int type) { |
| 2335 | return ((type & kShortcutTypeMask) == kShortcutTypeTag); |
| 2336 | } |
| 2337 | |
| 2338 | static inline void EvacuateShortcutCandidate(Map* map, |
| 2339 | HeapObject** slot, |
| 2340 | HeapObject* object) { |
| 2341 | ASSERT(IsShortcutCandidate(map->instance_type())); |
| 2342 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2343 | Heap* heap = map->GetHeap(); |
| 2344 | |
| 2345 | if (marks_handling == IGNORE_MARKS && |
| 2346 | ConsString::cast(object)->unchecked_second() == |
| 2347 | heap->empty_string()) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2348 | HeapObject* first = |
| 2349 | HeapObject::cast(ConsString::cast(object)->unchecked_first()); |
| 2350 | |
| 2351 | *slot = first; |
| 2352 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2353 | if (!heap->InNewSpace(first)) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2354 | object->set_map_word(MapWord::FromForwardingAddress(first)); |
| 2355 | return; |
| 2356 | } |
| 2357 | |
| 2358 | MapWord first_word = first->map_word(); |
| 2359 | if (first_word.IsForwardingAddress()) { |
| 2360 | HeapObject* target = first_word.ToForwardingAddress(); |
| 2361 | |
| 2362 | *slot = target; |
| 2363 | object->set_map_word(MapWord::FromForwardingAddress(target)); |
| 2364 | return; |
| 2365 | } |
| 2366 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2367 | heap->DoScavengeObject(first->map(), slot, first); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2368 | object->set_map_word(MapWord::FromForwardingAddress(*slot)); |
| 2369 | return; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2370 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2371 | |
| 2372 | int object_size = ConsString::kSize; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2373 | EvacuateObject<POINTER_OBJECT, kObjectAlignment>( |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2374 | map, slot, object, object_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2377 | template<ObjectContents object_contents> |
| 2378 | class ObjectEvacuationStrategy { |
| 2379 | public: |
| 2380 | template<int object_size> |
| 2381 | static inline void VisitSpecialized(Map* map, |
| 2382 | HeapObject** slot, |
| 2383 | HeapObject* object) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2384 | EvacuateObject<object_contents, kObjectAlignment>( |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2385 | map, slot, object, object_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2386 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2387 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2388 | static inline void Visit(Map* map, |
| 2389 | HeapObject** slot, |
| 2390 | HeapObject* object) { |
| 2391 | int object_size = map->instance_size(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2392 | EvacuateObject<object_contents, kObjectAlignment>( |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2393 | map, slot, object, object_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2394 | } |
| 2395 | }; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2396 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2397 | static VisitorDispatchTable<ScavengingCallback> table_; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2398 | }; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2399 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2400 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2401 | template<MarksHandling marks_handling, |
| 2402 | LoggingAndProfiling logging_and_profiling_mode> |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2403 | VisitorDispatchTable<ScavengingCallback> |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2404 | ScavengingVisitor<marks_handling, logging_and_profiling_mode>::table_; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2405 | |
| 2406 | |
| 2407 | static void InitializeScavengingVisitorsTables() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2408 | ScavengingVisitor<TRANSFER_MARKS, |
| 2409 | LOGGING_AND_PROFILING_DISABLED>::Initialize(); |
| 2410 | ScavengingVisitor<IGNORE_MARKS, LOGGING_AND_PROFILING_DISABLED>::Initialize(); |
| 2411 | ScavengingVisitor<TRANSFER_MARKS, |
| 2412 | LOGGING_AND_PROFILING_ENABLED>::Initialize(); |
| 2413 | ScavengingVisitor<IGNORE_MARKS, LOGGING_AND_PROFILING_ENABLED>::Initialize(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2417 | void Heap::SelectScavengingVisitorsTable() { |
| 2418 | bool logging_and_profiling = |
| 2419 | isolate()->logger()->is_logging() || |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2420 | isolate()->cpu_profiler()->is_profiling() || |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2421 | (isolate()->heap_profiler() != NULL && |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2422 | isolate()->heap_profiler()->is_profiling()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2423 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2424 | if (!incremental_marking()->IsMarking()) { |
| 2425 | if (!logging_and_profiling) { |
| 2426 | scavenging_visitors_table_.CopyFrom( |
| 2427 | ScavengingVisitor<IGNORE_MARKS, |
| 2428 | LOGGING_AND_PROFILING_DISABLED>::GetTable()); |
| 2429 | } else { |
| 2430 | scavenging_visitors_table_.CopyFrom( |
| 2431 | ScavengingVisitor<IGNORE_MARKS, |
| 2432 | LOGGING_AND_PROFILING_ENABLED>::GetTable()); |
| 2433 | } |
| 2434 | } else { |
| 2435 | if (!logging_and_profiling) { |
| 2436 | scavenging_visitors_table_.CopyFrom( |
| 2437 | ScavengingVisitor<TRANSFER_MARKS, |
| 2438 | LOGGING_AND_PROFILING_DISABLED>::GetTable()); |
| 2439 | } else { |
| 2440 | scavenging_visitors_table_.CopyFrom( |
| 2441 | ScavengingVisitor<TRANSFER_MARKS, |
| 2442 | LOGGING_AND_PROFILING_ENABLED>::GetTable()); |
| 2443 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2444 | |
| 2445 | if (incremental_marking()->IsCompacting()) { |
| 2446 | // When compacting forbid short-circuiting of cons-strings. |
| 2447 | // Scavenging code relies on the fact that new space object |
| 2448 | // can't be evacuated into evacuation candidate but |
| 2449 | // short-circuiting violates this assumption. |
| 2450 | scavenging_visitors_table_.Register( |
| 2451 | StaticVisitorBase::kVisitShortcutCandidate, |
| 2452 | scavenging_visitors_table_.GetVisitorById( |
| 2453 | StaticVisitorBase::kVisitConsString)); |
| 2454 | } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2455 | } |
| 2456 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2457 | |
| 2458 | |
| 2459 | void Heap::ScavengeObjectSlow(HeapObject** p, HeapObject* object) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2460 | SLOW_ASSERT(object->GetIsolate()->heap()->InFromSpace(object)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2461 | MapWord first_word = object->map_word(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2462 | SLOW_ASSERT(!first_word.IsForwardingAddress()); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2463 | Map* map = first_word.ToMap(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2464 | map->GetHeap()->DoScavengeObject(map, p, object); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2468 | MaybeObject* Heap::AllocatePartialMap(InstanceType instance_type, |
| 2469 | int instance_size) { |
| 2470 | Object* result; |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 2471 | MaybeObject* maybe_result = AllocateRaw(Map::kSize, MAP_SPACE, MAP_SPACE); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2472 | if (!maybe_result->ToObject(&result)) return maybe_result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2473 | |
| 2474 | // Map::cast cannot be used due to uninitialized map field. |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2475 | reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2476 | reinterpret_cast<Map*>(result)->set_instance_type(instance_type); |
| 2477 | reinterpret_cast<Map*>(result)->set_instance_size(instance_size); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2478 | reinterpret_cast<Map*>(result)->set_visitor_id( |
| 2479 | StaticVisitorBase::GetVisitorId(instance_type, instance_size)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2480 | reinterpret_cast<Map*>(result)->set_inobject_properties(0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2481 | reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2482 | reinterpret_cast<Map*>(result)->set_unused_property_fields(0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2483 | reinterpret_cast<Map*>(result)->set_bit_field(0); |
| 2484 | reinterpret_cast<Map*>(result)->set_bit_field2(0); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2485 | int bit_field3 = Map::EnumLengthBits::encode(Map::kInvalidEnumCache) | |
| 2486 | Map::OwnsDescriptors::encode(true); |
| 2487 | reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2488 | return result; |
| 2489 | } |
| 2490 | |
| 2491 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2492 | MaybeObject* Heap::AllocateMap(InstanceType instance_type, |
| 2493 | int instance_size, |
| 2494 | ElementsKind elements_kind) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2495 | Object* result; |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 2496 | MaybeObject* maybe_result = AllocateRaw(Map::kSize, MAP_SPACE, MAP_SPACE); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2497 | if (!maybe_result->To(&result)) return maybe_result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2498 | |
| 2499 | Map* map = reinterpret_cast<Map*>(result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2500 | map->set_map_no_write_barrier(meta_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2501 | map->set_instance_type(instance_type); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2502 | map->set_visitor_id( |
| 2503 | StaticVisitorBase::GetVisitorId(instance_type, instance_size)); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2504 | map->set_prototype(null_value(), SKIP_WRITE_BARRIER); |
| 2505 | map->set_constructor(null_value(), SKIP_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2506 | map->set_instance_size(instance_size); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2507 | map->set_inobject_properties(0); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2508 | map->set_pre_allocated_property_fields(0); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2509 | map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 2510 | map->set_dependent_code(DependentCode::cast(empty_fixed_array()), |
| 2511 | SKIP_WRITE_BARRIER); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 2512 | map->init_back_pointer(undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2513 | map->set_unused_property_fields(0); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2514 | map->set_instance_descriptors(empty_descriptor_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2515 | map->set_bit_field(0); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2516 | map->set_bit_field2(1 << Map::kIsExtensible); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2517 | int bit_field3 = Map::EnumLengthBits::encode(Map::kInvalidEnumCache) | |
| 2518 | Map::OwnsDescriptors::encode(true); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2519 | map->set_bit_field3(bit_field3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2520 | map->set_elements_kind(elements_kind); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2521 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2522 | return map; |
| 2523 | } |
| 2524 | |
| 2525 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2526 | MaybeObject* Heap::AllocateCodeCache() { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2527 | CodeCache* code_cache; |
| 2528 | { MaybeObject* maybe_code_cache = AllocateStruct(CODE_CACHE_TYPE); |
| 2529 | if (!maybe_code_cache->To(&code_cache)) return maybe_code_cache; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2530 | } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 2531 | code_cache->set_default_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 2532 | code_cache->set_normal_type_cache(undefined_value(), SKIP_WRITE_BARRIER); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2533 | return code_cache; |
| 2534 | } |
| 2535 | |
| 2536 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2537 | MaybeObject* Heap::AllocatePolymorphicCodeCache() { |
| 2538 | return AllocateStruct(POLYMORPHIC_CODE_CACHE_TYPE); |
| 2539 | } |
| 2540 | |
| 2541 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2542 | MaybeObject* Heap::AllocateAccessorPair() { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2543 | AccessorPair* accessors; |
| 2544 | { MaybeObject* maybe_accessors = AllocateStruct(ACCESSOR_PAIR_TYPE); |
| 2545 | if (!maybe_accessors->To(&accessors)) return maybe_accessors; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2546 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2547 | accessors->set_getter(the_hole_value(), SKIP_WRITE_BARRIER); |
| 2548 | accessors->set_setter(the_hole_value(), SKIP_WRITE_BARRIER); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 2549 | accessors->set_access_flags(Smi::FromInt(0), SKIP_WRITE_BARRIER); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2550 | return accessors; |
| 2551 | } |
| 2552 | |
| 2553 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2554 | MaybeObject* Heap::AllocateTypeFeedbackInfo() { |
| 2555 | TypeFeedbackInfo* info; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2556 | { MaybeObject* maybe_info = AllocateStruct(TYPE_FEEDBACK_INFO_TYPE); |
| 2557 | if (!maybe_info->To(&info)) return maybe_info; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2558 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2559 | info->initialize_storage(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2560 | info->set_type_feedback_cells(TypeFeedbackCells::cast(empty_fixed_array()), |
| 2561 | SKIP_WRITE_BARRIER); |
| 2562 | return info; |
| 2563 | } |
| 2564 | |
| 2565 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2566 | MaybeObject* Heap::AllocateAliasedArgumentsEntry(int aliased_context_slot) { |
| 2567 | AliasedArgumentsEntry* entry; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2568 | { MaybeObject* maybe_entry = AllocateStruct(ALIASED_ARGUMENTS_ENTRY_TYPE); |
| 2569 | if (!maybe_entry->To(&entry)) return maybe_entry; |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2570 | } |
| 2571 | entry->set_aliased_context_slot(aliased_context_slot); |
| 2572 | return entry; |
| 2573 | } |
| 2574 | |
| 2575 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2576 | const Heap::StringTypeTable Heap::string_type_table[] = { |
| 2577 | #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \ |
| 2578 | {type, size, k##camel_name##MapRootIndex}, |
| 2579 | STRING_TYPE_LIST(STRING_TYPE_ELEMENT) |
| 2580 | #undef STRING_TYPE_ELEMENT |
| 2581 | }; |
| 2582 | |
| 2583 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2584 | const Heap::ConstantStringTable Heap::constant_string_table[] = { |
| 2585 | #define CONSTANT_STRING_ELEMENT(name, contents) \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2586 | {contents, k##name##RootIndex}, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2587 | INTERNALIZED_STRING_LIST(CONSTANT_STRING_ELEMENT) |
| 2588 | #undef CONSTANT_STRING_ELEMENT |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2589 | }; |
| 2590 | |
| 2591 | |
| 2592 | const Heap::StructTable Heap::struct_table[] = { |
| 2593 | #define STRUCT_TABLE_ELEMENT(NAME, Name, name) \ |
| 2594 | { NAME##_TYPE, Name::kSize, k##Name##MapRootIndex }, |
| 2595 | STRUCT_LIST(STRUCT_TABLE_ELEMENT) |
| 2596 | #undef STRUCT_TABLE_ELEMENT |
| 2597 | }; |
| 2598 | |
| 2599 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2600 | bool Heap::CreateInitialMaps() { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2601 | Object* obj; |
| 2602 | { MaybeObject* maybe_obj = AllocatePartialMap(MAP_TYPE, Map::kSize); |
| 2603 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2604 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2605 | // Map::cast cannot be used due to uninitialized map field. |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2606 | Map* new_meta_map = reinterpret_cast<Map*>(obj); |
| 2607 | set_meta_map(new_meta_map); |
| 2608 | new_meta_map->set_map(new_meta_map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2609 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2610 | { MaybeObject* maybe_obj = |
| 2611 | AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2612 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2613 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2614 | set_fixed_array_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2615 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2616 | { MaybeObject* maybe_obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize); |
| 2617 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2618 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2619 | set_oddball_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2620 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2621 | // Allocate the empty array. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2622 | { MaybeObject* maybe_obj = AllocateEmptyFixedArray(); |
| 2623 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2624 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2625 | set_empty_fixed_array(FixedArray::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2626 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2627 | { MaybeObject* maybe_obj = Allocate(oddball_map(), OLD_POINTER_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2628 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2629 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2630 | set_null_value(Oddball::cast(obj)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2631 | Oddball::cast(obj)->set_kind(Oddball::kNull); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2632 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2633 | { MaybeObject* maybe_obj = Allocate(oddball_map(), OLD_POINTER_SPACE); |
| 2634 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2635 | } |
| 2636 | set_undefined_value(Oddball::cast(obj)); |
| 2637 | Oddball::cast(obj)->set_kind(Oddball::kUndefined); |
| 2638 | ASSERT(!InNewSpace(undefined_value())); |
| 2639 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2640 | // Allocate the empty descriptor array. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2641 | { MaybeObject* maybe_obj = AllocateEmptyFixedArray(); |
| 2642 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2643 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2644 | set_empty_descriptor_array(DescriptorArray::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2645 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2646 | // Fix the instance_descriptors for the existing maps. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2647 | meta_map()->set_code_cache(empty_fixed_array()); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 2648 | meta_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 2649 | meta_map()->init_back_pointer(undefined_value()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2650 | meta_map()->set_instance_descriptors(empty_descriptor_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2651 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2652 | fixed_array_map()->set_code_cache(empty_fixed_array()); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 2653 | fixed_array_map()->set_dependent_code( |
| 2654 | DependentCode::cast(empty_fixed_array())); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 2655 | fixed_array_map()->init_back_pointer(undefined_value()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2656 | fixed_array_map()->set_instance_descriptors(empty_descriptor_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2657 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2658 | oddball_map()->set_code_cache(empty_fixed_array()); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 2659 | oddball_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 2660 | oddball_map()->init_back_pointer(undefined_value()); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 2661 | oddball_map()->set_instance_descriptors(empty_descriptor_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2662 | |
| 2663 | // Fix prototype object for existing maps. |
| 2664 | meta_map()->set_prototype(null_value()); |
| 2665 | meta_map()->set_constructor(null_value()); |
| 2666 | |
| 2667 | fixed_array_map()->set_prototype(null_value()); |
| 2668 | fixed_array_map()->set_constructor(null_value()); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2669 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2670 | oddball_map()->set_prototype(null_value()); |
| 2671 | oddball_map()->set_constructor(null_value()); |
| 2672 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2673 | { MaybeObject* maybe_obj = |
| 2674 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2675 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2676 | } |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2677 | set_fixed_cow_array_map(Map::cast(obj)); |
| 2678 | ASSERT(fixed_array_map() != fixed_cow_array_map()); |
| 2679 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2680 | { MaybeObject* maybe_obj = |
| 2681 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2682 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2683 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2684 | set_scope_info_map(Map::cast(obj)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2685 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2686 | { MaybeObject* maybe_obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize); |
| 2687 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2688 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2689 | set_heap_number_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2690 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2691 | { MaybeObject* maybe_obj = AllocateMap(SYMBOL_TYPE, Symbol::kSize); |
| 2692 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2693 | } |
| 2694 | set_symbol_map(Map::cast(obj)); |
| 2695 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2696 | { MaybeObject* maybe_obj = AllocateMap(FOREIGN_TYPE, Foreign::kSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2697 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2698 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2699 | set_foreign_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2700 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2701 | for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { |
| 2702 | const StringTypeTable& entry = string_type_table[i]; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2703 | { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); |
| 2704 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2705 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2706 | roots_[entry.index] = Map::cast(obj); |
| 2707 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2708 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2709 | { MaybeObject* maybe_obj = AllocateMap(STRING_TYPE, kVariableSizeSentinel); |
| 2710 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2711 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2712 | set_undetectable_string_map(Map::cast(obj)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2713 | Map::cast(obj)->set_is_undetectable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2714 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2715 | { MaybeObject* maybe_obj = |
| 2716 | AllocateMap(ASCII_STRING_TYPE, kVariableSizeSentinel); |
| 2717 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2718 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2719 | set_undetectable_ascii_string_map(Map::cast(obj)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2720 | Map::cast(obj)->set_is_undetectable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2721 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2722 | { MaybeObject* maybe_obj = |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2723 | AllocateMap(FIXED_DOUBLE_ARRAY_TYPE, kVariableSizeSentinel); |
| 2724 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2725 | } |
| 2726 | set_fixed_double_array_map(Map::cast(obj)); |
| 2727 | |
| 2728 | { MaybeObject* maybe_obj = |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 2729 | AllocateMap(CONSTANT_POOL_ARRAY_TYPE, kVariableSizeSentinel); |
| 2730 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2731 | } |
| 2732 | set_constant_pool_array_map(Map::cast(obj)); |
| 2733 | |
| 2734 | { MaybeObject* maybe_obj = |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2735 | AllocateMap(BYTE_ARRAY_TYPE, kVariableSizeSentinel); |
| 2736 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2737 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2738 | set_byte_array_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2739 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2740 | { MaybeObject* maybe_obj = |
| 2741 | AllocateMap(FREE_SPACE_TYPE, kVariableSizeSentinel); |
| 2742 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2743 | } |
| 2744 | set_free_space_map(Map::cast(obj)); |
| 2745 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2746 | { MaybeObject* maybe_obj = AllocateByteArray(0, TENURED); |
| 2747 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2748 | } |
| 2749 | set_empty_byte_array(ByteArray::cast(obj)); |
| 2750 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2751 | { MaybeObject* maybe_obj = |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2752 | AllocateMap(EXTERNAL_PIXEL_ARRAY_TYPE, ExternalArray::kAlignedSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2753 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2754 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2755 | set_external_pixel_array_map(Map::cast(obj)); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2756 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2757 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE, |
| 2758 | ExternalArray::kAlignedSize); |
| 2759 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2760 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2761 | set_external_byte_array_map(Map::cast(obj)); |
| 2762 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2763 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 2764 | ExternalArray::kAlignedSize); |
| 2765 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2766 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2767 | set_external_unsigned_byte_array_map(Map::cast(obj)); |
| 2768 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2769 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_SHORT_ARRAY_TYPE, |
| 2770 | ExternalArray::kAlignedSize); |
| 2771 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2772 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2773 | set_external_short_array_map(Map::cast(obj)); |
| 2774 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2775 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 2776 | ExternalArray::kAlignedSize); |
| 2777 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2778 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2779 | set_external_unsigned_short_array_map(Map::cast(obj)); |
| 2780 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2781 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_INT_ARRAY_TYPE, |
| 2782 | ExternalArray::kAlignedSize); |
| 2783 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2784 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2785 | set_external_int_array_map(Map::cast(obj)); |
| 2786 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2787 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
| 2788 | ExternalArray::kAlignedSize); |
| 2789 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2790 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2791 | set_external_unsigned_int_array_map(Map::cast(obj)); |
| 2792 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2793 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE, |
| 2794 | ExternalArray::kAlignedSize); |
| 2795 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2796 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2797 | set_external_float_array_map(Map::cast(obj)); |
| 2798 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2799 | { MaybeObject* maybe_obj = |
| 2800 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2801 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2802 | } |
| 2803 | set_non_strict_arguments_elements_map(Map::cast(obj)); |
| 2804 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2805 | { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_DOUBLE_ARRAY_TYPE, |
| 2806 | ExternalArray::kAlignedSize); |
| 2807 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2808 | } |
| 2809 | set_external_double_array_map(Map::cast(obj)); |
| 2810 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2811 | { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalByteArray); |
| 2812 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2813 | } |
| 2814 | set_empty_external_byte_array(ExternalArray::cast(obj)); |
| 2815 | |
| 2816 | { MaybeObject* maybe_obj = |
| 2817 | AllocateEmptyExternalArray(kExternalUnsignedByteArray); |
| 2818 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2819 | } |
| 2820 | set_empty_external_unsigned_byte_array(ExternalArray::cast(obj)); |
| 2821 | |
| 2822 | { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalShortArray); |
| 2823 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2824 | } |
| 2825 | set_empty_external_short_array(ExternalArray::cast(obj)); |
| 2826 | |
| 2827 | { MaybeObject* maybe_obj = AllocateEmptyExternalArray( |
| 2828 | kExternalUnsignedShortArray); |
| 2829 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2830 | } |
| 2831 | set_empty_external_unsigned_short_array(ExternalArray::cast(obj)); |
| 2832 | |
| 2833 | { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalIntArray); |
| 2834 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2835 | } |
| 2836 | set_empty_external_int_array(ExternalArray::cast(obj)); |
| 2837 | |
| 2838 | { MaybeObject* maybe_obj = |
| 2839 | AllocateEmptyExternalArray(kExternalUnsignedIntArray); |
| 2840 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2841 | } |
| 2842 | set_empty_external_unsigned_int_array(ExternalArray::cast(obj)); |
| 2843 | |
| 2844 | { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalFloatArray); |
| 2845 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2846 | } |
| 2847 | set_empty_external_float_array(ExternalArray::cast(obj)); |
| 2848 | |
| 2849 | { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalDoubleArray); |
| 2850 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2851 | } |
| 2852 | set_empty_external_double_array(ExternalArray::cast(obj)); |
| 2853 | |
| 2854 | { MaybeObject* maybe_obj = AllocateEmptyExternalArray(kExternalPixelArray); |
| 2855 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2856 | } |
| 2857 | set_empty_external_pixel_array(ExternalArray::cast(obj)); |
| 2858 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2859 | { MaybeObject* maybe_obj = AllocateMap(CODE_TYPE, kVariableSizeSentinel); |
| 2860 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2861 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2862 | set_code_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2863 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2864 | { MaybeObject* maybe_obj = AllocateMap(CELL_TYPE, Cell::kSize); |
| 2865 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2866 | } |
| 2867 | set_cell_map(Map::cast(obj)); |
| 2868 | |
| 2869 | { MaybeObject* maybe_obj = AllocateMap(PROPERTY_CELL_TYPE, |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2870 | PropertyCell::kSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2871 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2872 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2873 | set_global_property_cell_map(Map::cast(obj)); |
| 2874 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2875 | { MaybeObject* maybe_obj = AllocateMap(FILLER_TYPE, kPointerSize); |
| 2876 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2877 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2878 | set_one_pointer_filler_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2879 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2880 | { MaybeObject* maybe_obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize); |
| 2881 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2882 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2883 | set_two_pointer_filler_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2884 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2885 | for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) { |
| 2886 | const StructTable& entry = struct_table[i]; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2887 | { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); |
| 2888 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2889 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2890 | roots_[entry.index] = Map::cast(obj); |
| 2891 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2892 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2893 | { MaybeObject* maybe_obj = |
| 2894 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2895 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2896 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2897 | set_hash_table_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2898 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2899 | { MaybeObject* maybe_obj = |
| 2900 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2901 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2902 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2903 | set_function_context_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2904 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2905 | { MaybeObject* maybe_obj = |
| 2906 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2907 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2908 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2909 | set_catch_context_map(Map::cast(obj)); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2910 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2911 | { MaybeObject* maybe_obj = |
| 2912 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2913 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2914 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2915 | set_with_context_map(Map::cast(obj)); |
| 2916 | |
| 2917 | { MaybeObject* maybe_obj = |
| 2918 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2919 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2920 | } |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2921 | set_block_context_map(Map::cast(obj)); |
| 2922 | |
| 2923 | { MaybeObject* maybe_obj = |
| 2924 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2925 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2926 | } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2927 | set_module_context_map(Map::cast(obj)); |
| 2928 | |
| 2929 | { MaybeObject* maybe_obj = |
| 2930 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2931 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2932 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2933 | set_global_context_map(Map::cast(obj)); |
| 2934 | |
| 2935 | { MaybeObject* maybe_obj = |
| 2936 | AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2937 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2938 | } |
| 2939 | Map* native_context_map = Map::cast(obj); |
| 2940 | native_context_map->set_dictionary_map(true); |
| 2941 | native_context_map->set_visitor_id(StaticVisitorBase::kVisitNativeContext); |
| 2942 | set_native_context_map(native_context_map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2943 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2944 | { MaybeObject* maybe_obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE, |
| 2945 | SharedFunctionInfo::kAlignedSize); |
| 2946 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2947 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2948 | set_shared_function_info_map(Map::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2949 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2950 | { MaybeObject* maybe_obj = AllocateMap(JS_MESSAGE_OBJECT_TYPE, |
| 2951 | JSMessageObject::kSize); |
| 2952 | if (!maybe_obj->ToObject(&obj)) return false; |
| 2953 | } |
| 2954 | set_message_object_map(Map::cast(obj)); |
| 2955 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2956 | Map* external_map; |
| 2957 | { MaybeObject* maybe_obj = |
| 2958 | AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize); |
| 2959 | if (!maybe_obj->To(&external_map)) return false; |
| 2960 | } |
| 2961 | external_map->set_is_extensible(false); |
| 2962 | set_external_map(external_map); |
| 2963 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2964 | ASSERT(!InNewSpace(empty_fixed_array())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2965 | return true; |
| 2966 | } |
| 2967 | |
| 2968 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2969 | MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | // Statically ensure that it is safe to allocate heap numbers in paged |
| 2971 | // spaces. |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2972 | int size = HeapNumber::kSize; |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2973 | STATIC_ASSERT(HeapNumber::kSize <= Page::kNonCodeObjectAreaSize); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2974 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2975 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2976 | Object* result; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 2977 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2978 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2979 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2980 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2981 | HeapObject::cast(result)->set_map_no_write_barrier(heap_number_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2982 | HeapNumber::cast(result)->set_value(value); |
| 2983 | return result; |
| 2984 | } |
| 2985 | |
| 2986 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2987 | MaybeObject* Heap::AllocateCell(Object* value) { |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 2988 | int size = Cell::kSize; |
| 2989 | STATIC_ASSERT(Cell::kSize <= Page::kNonCodeObjectAreaSize); |
| 2990 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2991 | Object* result; |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 2992 | { MaybeObject* maybe_result = AllocateRaw(size, CELL_SPACE, CELL_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2993 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2994 | } |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2995 | HeapObject::cast(result)->set_map_no_write_barrier(cell_map()); |
| 2996 | Cell::cast(result)->set_value(value); |
| 2997 | return result; |
| 2998 | } |
| 2999 | |
| 3000 | |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 3001 | MaybeObject* Heap::AllocatePropertyCell() { |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3002 | int size = PropertyCell::kSize; |
| 3003 | STATIC_ASSERT(PropertyCell::kSize <= Page::kNonCodeObjectAreaSize); |
| 3004 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 3005 | Object* result; |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3006 | MaybeObject* maybe_result = |
| 3007 | AllocateRaw(size, PROPERTY_CELL_SPACE, PROPERTY_CELL_SPACE); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 3008 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3009 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3010 | HeapObject::cast(result)->set_map_no_write_barrier( |
| 3011 | global_property_cell_map()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3012 | PropertyCell* cell = PropertyCell::cast(result); |
| 3013 | cell->set_dependent_code(DependentCode::cast(empty_fixed_array()), |
| 3014 | SKIP_WRITE_BARRIER); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 3015 | cell->set_value(the_hole_value()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3016 | cell->set_type(Type::None()); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3017 | return result; |
| 3018 | } |
| 3019 | |
| 3020 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 3021 | MaybeObject* Heap::AllocateBox(Object* value, PretenureFlag pretenure) { |
| 3022 | Box* result; |
| 3023 | MaybeObject* maybe_result = AllocateStruct(BOX_TYPE); |
| 3024 | if (!maybe_result->To(&result)) return maybe_result; |
| 3025 | result->set_value(value); |
| 3026 | return result; |
| 3027 | } |
| 3028 | |
| 3029 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 3030 | MaybeObject* Heap::AllocateAllocationSite() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3031 | AllocationSite* site; |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 3032 | MaybeObject* maybe_result = Allocate(allocation_site_map(), |
| 3033 | OLD_POINTER_SPACE); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3034 | if (!maybe_result->To(&site)) return maybe_result; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3035 | site->Initialize(); |
| 3036 | |
| 3037 | // Link the site |
| 3038 | site->set_weak_next(allocation_sites_list()); |
| 3039 | set_allocation_sites_list(site); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3040 | return site; |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3044 | MaybeObject* Heap::CreateOddball(const char* to_string, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3045 | Object* to_number, |
| 3046 | byte kind) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3047 | Object* result; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3048 | { MaybeObject* maybe_result = Allocate(oddball_map(), OLD_POINTER_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3049 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3050 | } |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3051 | return Oddball::cast(result)->Initialize(this, to_string, to_number, kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | |
| 3055 | bool Heap::CreateApiObjects() { |
| 3056 | Object* obj; |
| 3057 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3058 | { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 3059 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3060 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3061 | // Don't use Smi-only elements optimizations for objects with the neander |
| 3062 | // map. There are too many cases where element values are set directly with a |
| 3063 | // bottleneck to trap the Smi-only -> fast elements transition, and there |
| 3064 | // appears to be no benefit for optimize this case. |
| 3065 | Map* new_neander_map = Map::cast(obj); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3066 | new_neander_map->set_elements_kind(TERMINAL_FAST_ELEMENTS_KIND); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3067 | set_neander_map(new_neander_map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3068 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3069 | { MaybeObject* maybe_obj = AllocateJSObjectFromMap(neander_map()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3070 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3071 | } |
| 3072 | Object* elements; |
| 3073 | { MaybeObject* maybe_elements = AllocateFixedArray(2); |
| 3074 | if (!maybe_elements->ToObject(&elements)) return false; |
| 3075 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3076 | FixedArray::cast(elements)->set(0, Smi::FromInt(0)); |
| 3077 | JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3078 | set_message_listeners(JSObject::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3079 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3080 | return true; |
| 3081 | } |
| 3082 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3083 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3084 | void Heap::CreateJSEntryStub() { |
| 3085 | JSEntryStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3086 | set_js_entry_code(*stub.GetCode(isolate())); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | |
| 3090 | void Heap::CreateJSConstructEntryStub() { |
| 3091 | JSConstructEntryStub stub; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3092 | set_js_construct_entry_code(*stub.GetCode(isolate())); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3096 | void Heap::CreateFixedStubs() { |
| 3097 | // Here we create roots for fixed stubs. They are needed at GC |
| 3098 | // for cooking and uncooking (check out frames.cc). |
| 3099 | // The eliminates the need for doing dictionary lookup in the |
| 3100 | // stub cache for these stubs. |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 3101 | HandleScope scope(isolate()); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3102 | // gcc-4.4 has problem generating correct code of following snippet: |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3103 | // { JSEntryStub stub; |
| 3104 | // js_entry_code_ = *stub.GetCode(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3105 | // } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3106 | // { JSConstructEntryStub stub; |
| 3107 | // js_construct_entry_code_ = *stub.GetCode(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3108 | // } |
| 3109 | // To workaround the problem, make separate functions without inlining. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3110 | Heap::CreateJSEntryStub(); |
| 3111 | Heap::CreateJSConstructEntryStub(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3112 | |
| 3113 | // Create stubs that should be there, so we don't unexpectedly have to |
| 3114 | // create them if we need them during the creation of another stub. |
| 3115 | // Stub creation mixes raw pointers and handles in an unsafe manner so |
| 3116 | // we cannot create stubs while we are creating stubs. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3117 | CodeStub::GenerateStubsAheadOfTime(isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame^] | 3121 | void Heap::CreateStubsRequiringBuiltins() { |
| 3122 | HandleScope scope(isolate()); |
| 3123 | CodeStub::GenerateStubsRequiringBuiltinsAheadOfTime(isolate()); |
| 3124 | } |
| 3125 | |
| 3126 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3127 | bool Heap::CreateInitialObjects() { |
| 3128 | Object* obj; |
| 3129 | |
| 3130 | // The -0 value must be set before NumberFromDouble works. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3131 | { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED); |
| 3132 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3133 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3134 | set_minus_zero_value(HeapNumber::cast(obj)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3135 | ASSERT(std::signbit(minus_zero_value()->Number()) != 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3136 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3137 | { MaybeObject* maybe_obj = AllocateHeapNumber(OS::nan_value(), TENURED); |
| 3138 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3139 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3140 | set_nan_value(HeapNumber::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3141 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3142 | { MaybeObject* maybe_obj = AllocateHeapNumber(V8_INFINITY, TENURED); |
| 3143 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3144 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3145 | set_infinity_value(HeapNumber::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3146 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3147 | // The hole has not been created yet, but we want to put something |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3148 | // predictable in the gaps in the string table, so lets make that Smi zero. |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3149 | set_the_hole_value(reinterpret_cast<Oddball*>(Smi::FromInt(0))); |
| 3150 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3151 | // Allocate initial string table. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3152 | { MaybeObject* maybe_obj = |
| 3153 | StringTable::Allocate(this, kInitialStringTableSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3154 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3155 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3156 | // Don't use set_string_table() due to asserts. |
| 3157 | roots_[kStringTableRootIndex] = obj; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3158 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3159 | // Finish initializing oddballs after creating the string table. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3160 | { MaybeObject* maybe_obj = |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3161 | undefined_value()->Initialize(this, |
| 3162 | "undefined", |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3163 | nan_value(), |
| 3164 | Oddball::kUndefined); |
| 3165 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3166 | } |
| 3167 | |
| 3168 | // Initialize the null_value. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3169 | { MaybeObject* maybe_obj = null_value()->Initialize( |
| 3170 | this, "null", Smi::FromInt(0), Oddball::kNull); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3171 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3172 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3173 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3174 | { MaybeObject* maybe_obj = CreateOddball("true", |
| 3175 | Smi::FromInt(1), |
| 3176 | Oddball::kTrue); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3177 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3178 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3179 | set_true_value(Oddball::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3180 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3181 | { MaybeObject* maybe_obj = CreateOddball("false", |
| 3182 | Smi::FromInt(0), |
| 3183 | Oddball::kFalse); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3184 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3185 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3186 | set_false_value(Oddball::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3187 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3188 | { MaybeObject* maybe_obj = CreateOddball("hole", |
| 3189 | Smi::FromInt(-1), |
| 3190 | Oddball::kTheHole); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3191 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3192 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3193 | set_the_hole_value(Oddball::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3194 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 3195 | { MaybeObject* maybe_obj = CreateOddball("uninitialized", |
| 3196 | Smi::FromInt(-1), |
| 3197 | Oddball::kUninitialized); |
| 3198 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3199 | } |
| 3200 | set_uninitialized_value(Oddball::cast(obj)); |
| 3201 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3202 | { MaybeObject* maybe_obj = CreateOddball("arguments_marker", |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3203 | Smi::FromInt(-4), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3204 | Oddball::kArgumentMarker); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3205 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3206 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3207 | set_arguments_marker(Oddball::cast(obj)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3208 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3209 | { MaybeObject* maybe_obj = CreateOddball("no_interceptor_result_sentinel", |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3210 | Smi::FromInt(-2), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3211 | Oddball::kOther); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3212 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3213 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3214 | set_no_interceptor_result_sentinel(obj); |
| 3215 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3216 | { MaybeObject* maybe_obj = CreateOddball("termination_exception", |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3217 | Smi::FromInt(-3), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3218 | Oddball::kOther); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3219 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3220 | } |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3221 | set_termination_exception(obj); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3222 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3223 | for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3224 | { MaybeObject* maybe_obj = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3225 | InternalizeUtf8String(constant_string_table[i].contents); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3226 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3227 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3228 | roots_[constant_string_table[i].index] = String::cast(obj); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3229 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3230 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3231 | // Allocate the hidden string which is used to identify the hidden properties |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3232 | // in JSObjects. The hash code has a special value so that it will not match |
| 3233 | // the empty string when searching for the property. It cannot be part of the |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3234 | // loop above because it needs to be allocated manually with the special |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3235 | // hash code in place. The hash code for the hidden_string is zero to ensure |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3236 | // that it will always be at the first entry in property descriptors. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3237 | { MaybeObject* maybe_obj = AllocateOneByteInternalizedString( |
| 3238 | OneByteVector("", 0), String::kEmptyStringHash); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3239 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3240 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3241 | hidden_string_ = String::cast(obj); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3242 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3243 | // Allocate the code_stubs dictionary. The initial size is set to avoid |
| 3244 | // expanding the dictionary during bootstrapping. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3245 | { MaybeObject* maybe_obj = UnseededNumberDictionary::Allocate(this, 128); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3246 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3247 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3248 | set_code_stubs(UnseededNumberDictionary::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3249 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3250 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3251 | // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size |
| 3252 | // is set to avoid expanding the dictionary during bootstrapping. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3253 | { MaybeObject* maybe_obj = UnseededNumberDictionary::Allocate(this, 64); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3254 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3255 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3256 | set_non_monomorphic_cache(UnseededNumberDictionary::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3257 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3258 | { MaybeObject* maybe_obj = AllocatePolymorphicCodeCache(); |
| 3259 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3260 | } |
| 3261 | set_polymorphic_code_cache(PolymorphicCodeCache::cast(obj)); |
| 3262 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3263 | set_instanceof_cache_function(Smi::FromInt(0)); |
| 3264 | set_instanceof_cache_map(Smi::FromInt(0)); |
| 3265 | set_instanceof_cache_answer(Smi::FromInt(0)); |
| 3266 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3267 | CreateFixedStubs(); |
| 3268 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3269 | // Allocate the dictionary of intrinsic function names. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 3270 | { MaybeObject* maybe_obj = |
| 3271 | NameDictionary::Allocate(this, Runtime::kNumFunctions); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3272 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3273 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3274 | { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, |
| 3275 | obj); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3276 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3277 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3278 | set_intrinsic_function_names(NameDictionary::cast(obj)); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3279 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3280 | { MaybeObject* maybe_obj = AllocateInitialNumberStringCache(); |
| 3281 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3282 | } |
| 3283 | set_number_string_cache(FixedArray::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3284 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3285 | // Allocate cache for single character one byte strings. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3286 | { MaybeObject* maybe_obj = |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3287 | AllocateFixedArray(String::kMaxOneByteCharCode + 1, TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3288 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3289 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3290 | set_single_character_string_cache(FixedArray::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3291 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3292 | // Allocate cache for string split. |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3293 | { MaybeObject* maybe_obj = AllocateFixedArray( |
| 3294 | RegExpResultsCache::kRegExpResultsCacheSize, TENURED); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3295 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3296 | } |
| 3297 | set_string_split_cache(FixedArray::cast(obj)); |
| 3298 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3299 | { MaybeObject* maybe_obj = AllocateFixedArray( |
| 3300 | RegExpResultsCache::kRegExpResultsCacheSize, TENURED); |
| 3301 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3302 | } |
| 3303 | set_regexp_multiple_cache(FixedArray::cast(obj)); |
| 3304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3305 | // Allocate cache for external strings pointing to native source code. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3306 | { MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount()); |
| 3307 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3308 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3309 | set_natives_source_cache(FixedArray::cast(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3310 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3311 | // Allocate object to hold object observation state. |
| 3312 | { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 3313 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3314 | } |
| 3315 | { MaybeObject* maybe_obj = AllocateJSObjectFromMap(Map::cast(obj)); |
| 3316 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3317 | } |
| 3318 | set_observation_state(JSObject::cast(obj)); |
| 3319 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3320 | { MaybeObject* maybe_obj = AllocateSymbol(); |
| 3321 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3322 | } |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3323 | Symbol::cast(obj)->set_is_private(true); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3324 | set_frozen_symbol(Symbol::cast(obj)); |
| 3325 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3326 | { MaybeObject* maybe_obj = AllocateSymbol(); |
| 3327 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3328 | } |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3329 | Symbol::cast(obj)->set_is_private(true); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 3330 | set_elements_transition_symbol(Symbol::cast(obj)); |
| 3331 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3332 | { MaybeObject* maybe_obj = SeededNumberDictionary::Allocate(this, 0, TENURED); |
| 3333 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3334 | } |
| 3335 | SeededNumberDictionary::cast(obj)->set_requires_slow_elements(); |
| 3336 | set_empty_slow_element_dictionary(SeededNumberDictionary::cast(obj)); |
| 3337 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3338 | { MaybeObject* maybe_obj = AllocateSymbol(); |
| 3339 | if (!maybe_obj->ToObject(&obj)) return false; |
| 3340 | } |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3341 | Symbol::cast(obj)->set_is_private(true); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 3342 | set_observed_symbol(Symbol::cast(obj)); |
| 3343 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3344 | // Handling of script id generation is in Factory::NewScript. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3345 | set_last_script_id(Smi::FromInt(v8::Script::kNoScriptId)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3346 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3347 | // Initialize keyed lookup cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3348 | isolate_->keyed_lookup_cache()->Clear(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 3349 | |
| 3350 | // Initialize context slot cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3351 | isolate_->context_slot_cache()->Clear(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 3352 | |
| 3353 | // Initialize descriptor cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3354 | isolate_->descriptor_lookup_cache()->Clear(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3355 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3356 | // Initialize compilation cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3357 | isolate_->compilation_cache()->Clear(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3358 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3359 | return true; |
| 3360 | } |
| 3361 | |
| 3362 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3363 | bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) { |
| 3364 | RootListIndex writable_roots[] = { |
| 3365 | kStoreBufferTopRootIndex, |
| 3366 | kStackLimitRootIndex, |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 3367 | kNumberStringCacheRootIndex, |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3368 | kInstanceofCacheFunctionRootIndex, |
| 3369 | kInstanceofCacheMapRootIndex, |
| 3370 | kInstanceofCacheAnswerRootIndex, |
| 3371 | kCodeStubsRootIndex, |
| 3372 | kNonMonomorphicCacheRootIndex, |
| 3373 | kPolymorphicCodeCacheRootIndex, |
| 3374 | kLastScriptIdRootIndex, |
| 3375 | kEmptyScriptRootIndex, |
| 3376 | kRealStackLimitRootIndex, |
| 3377 | kArgumentsAdaptorDeoptPCOffsetRootIndex, |
| 3378 | kConstructStubDeoptPCOffsetRootIndex, |
| 3379 | kGetterStubDeoptPCOffsetRootIndex, |
| 3380 | kSetterStubDeoptPCOffsetRootIndex, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3381 | kStringTableRootIndex, |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3382 | }; |
| 3383 | |
| 3384 | for (unsigned int i = 0; i < ARRAY_SIZE(writable_roots); i++) { |
| 3385 | if (root_index == writable_roots[i]) |
| 3386 | return true; |
| 3387 | } |
| 3388 | return false; |
| 3389 | } |
| 3390 | |
| 3391 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3392 | bool Heap::RootCanBeTreatedAsConstant(RootListIndex root_index) { |
| 3393 | return !RootCanBeWrittenAfterInitialization(root_index) && |
| 3394 | !InNewSpace(roots_array_start()[root_index]); |
| 3395 | } |
| 3396 | |
| 3397 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3398 | Object* RegExpResultsCache::Lookup(Heap* heap, |
| 3399 | String* key_string, |
| 3400 | Object* key_pattern, |
| 3401 | ResultsCacheType type) { |
| 3402 | FixedArray* cache; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3403 | if (!key_string->IsInternalizedString()) return Smi::FromInt(0); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3404 | if (type == STRING_SPLIT_SUBSTRINGS) { |
| 3405 | ASSERT(key_pattern->IsString()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3406 | if (!key_pattern->IsInternalizedString()) return Smi::FromInt(0); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3407 | cache = heap->string_split_cache(); |
| 3408 | } else { |
| 3409 | ASSERT(type == REGEXP_MULTIPLE_INDICES); |
| 3410 | ASSERT(key_pattern->IsFixedArray()); |
| 3411 | cache = heap->regexp_multiple_cache(); |
| 3412 | } |
| 3413 | |
| 3414 | uint32_t hash = key_string->Hash(); |
| 3415 | uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3416 | ~(kArrayEntriesPerCacheEntry - 1)); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3417 | if (cache->get(index + kStringOffset) == key_string && |
| 3418 | cache->get(index + kPatternOffset) == key_pattern) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3419 | return cache->get(index + kArrayOffset); |
| 3420 | } |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3421 | index = |
| 3422 | ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
| 3423 | if (cache->get(index + kStringOffset) == key_string && |
| 3424 | cache->get(index + kPatternOffset) == key_pattern) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3425 | return cache->get(index + kArrayOffset); |
| 3426 | } |
| 3427 | return Smi::FromInt(0); |
| 3428 | } |
| 3429 | |
| 3430 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3431 | void RegExpResultsCache::Enter(Heap* heap, |
| 3432 | String* key_string, |
| 3433 | Object* key_pattern, |
| 3434 | FixedArray* value_array, |
| 3435 | ResultsCacheType type) { |
| 3436 | FixedArray* cache; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3437 | if (!key_string->IsInternalizedString()) return; |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3438 | if (type == STRING_SPLIT_SUBSTRINGS) { |
| 3439 | ASSERT(key_pattern->IsString()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3440 | if (!key_pattern->IsInternalizedString()) return; |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3441 | cache = heap->string_split_cache(); |
| 3442 | } else { |
| 3443 | ASSERT(type == REGEXP_MULTIPLE_INDICES); |
| 3444 | ASSERT(key_pattern->IsFixedArray()); |
| 3445 | cache = heap->regexp_multiple_cache(); |
| 3446 | } |
| 3447 | |
| 3448 | uint32_t hash = key_string->Hash(); |
| 3449 | uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3450 | ~(kArrayEntriesPerCacheEntry - 1)); |
| 3451 | if (cache->get(index + kStringOffset) == Smi::FromInt(0)) { |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3452 | cache->set(index + kStringOffset, key_string); |
| 3453 | cache->set(index + kPatternOffset, key_pattern); |
| 3454 | cache->set(index + kArrayOffset, value_array); |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 3455 | } else { |
| 3456 | uint32_t index2 = |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3457 | ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 3458 | if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) { |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3459 | cache->set(index2 + kStringOffset, key_string); |
| 3460 | cache->set(index2 + kPatternOffset, key_pattern); |
| 3461 | cache->set(index2 + kArrayOffset, value_array); |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 3462 | } else { |
| 3463 | cache->set(index2 + kStringOffset, Smi::FromInt(0)); |
| 3464 | cache->set(index2 + kPatternOffset, Smi::FromInt(0)); |
| 3465 | cache->set(index2 + kArrayOffset, Smi::FromInt(0)); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3466 | cache->set(index + kStringOffset, key_string); |
| 3467 | cache->set(index + kPatternOffset, key_pattern); |
| 3468 | cache->set(index + kArrayOffset, value_array); |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 3469 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3470 | } |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3471 | // If the array is a reasonably short list of substrings, convert it into a |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3472 | // list of internalized strings. |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3473 | if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) { |
| 3474 | for (int i = 0; i < value_array->length(); i++) { |
| 3475 | String* str = String::cast(value_array->get(i)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3476 | Object* internalized_str; |
| 3477 | MaybeObject* maybe_string = heap->InternalizeString(str); |
| 3478 | if (maybe_string->ToObject(&internalized_str)) { |
| 3479 | value_array->set(i, internalized_str); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3480 | } |
| 3481 | } |
| 3482 | } |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3483 | // Convert backing store to a copy-on-write array. |
| 3484 | value_array->set_map_no_write_barrier(heap->fixed_cow_array_map()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 3488 | void RegExpResultsCache::Clear(FixedArray* cache) { |
| 3489 | for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3490 | cache->set(i, Smi::FromInt(0)); |
| 3491 | } |
| 3492 | } |
| 3493 | |
| 3494 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3495 | MaybeObject* Heap::AllocateInitialNumberStringCache() { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3496 | MaybeObject* maybe_obj = |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3497 | AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3498 | return maybe_obj; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3502 | int Heap::FullSizeNumberStringCacheLength() { |
| 3503 | // Compute the size of the number string cache based on the max newspace size. |
| 3504 | // The number string cache has a minimum size based on twice the initial cache |
| 3505 | // size to ensure that it is bigger after being made 'full size'. |
| 3506 | int number_string_cache_size = max_semispace_size_ / 512; |
| 3507 | number_string_cache_size = Max(kInitialNumberStringCacheSize * 2, |
| 3508 | Min(0x4000, number_string_cache_size)); |
| 3509 | // There is a string and a number per entry so the length is twice the number |
| 3510 | // of entries. |
| 3511 | return number_string_cache_size * 2; |
| 3512 | } |
| 3513 | |
| 3514 | |
| 3515 | void Heap::AllocateFullSizeNumberStringCache() { |
| 3516 | // The idea is to have a small number string cache in the snapshot to keep |
| 3517 | // boot-time memory usage down. If we expand the number string cache already |
| 3518 | // while creating the snapshot then that didn't work out. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3519 | ASSERT(!Serializer::enabled() || FLAG_extra_code != NULL); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3520 | MaybeObject* maybe_obj = |
| 3521 | AllocateFixedArray(FullSizeNumberStringCacheLength(), TENURED); |
| 3522 | Object* new_cache; |
| 3523 | if (maybe_obj->ToObject(&new_cache)) { |
| 3524 | // We don't bother to repopulate the cache with entries from the old cache. |
| 3525 | // It will be repopulated soon enough with new strings. |
| 3526 | set_number_string_cache(FixedArray::cast(new_cache)); |
| 3527 | } |
| 3528 | // If allocation fails then we just return without doing anything. It is only |
| 3529 | // a cache, so best effort is OK here. |
| 3530 | } |
| 3531 | |
| 3532 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3533 | void Heap::FlushNumberStringCache() { |
| 3534 | // Flush the number to string cache. |
| 3535 | int len = number_string_cache()->length(); |
| 3536 | for (int i = 0; i < len; i++) { |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 3537 | number_string_cache()->set_undefined(i); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3538 | } |
| 3539 | } |
| 3540 | |
| 3541 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3542 | static inline int double_get_hash(double d) { |
| 3543 | DoubleRepresentation rep(d); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3544 | return static_cast<int>(rep.bits) ^ static_cast<int>(rep.bits >> 32); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | |
| 3548 | static inline int smi_get_hash(Smi* smi) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3549 | return smi->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3553 | Object* Heap::GetNumberStringCache(Object* number) { |
| 3554 | int hash; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3555 | int mask = (number_string_cache()->length() >> 1) - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3556 | if (number->IsSmi()) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3557 | hash = smi_get_hash(Smi::cast(number)) & mask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3558 | } else { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3559 | hash = double_get_hash(number->Number()) & mask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3560 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3561 | Object* key = number_string_cache()->get(hash * 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3562 | if (key == number) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3563 | return String::cast(number_string_cache()->get(hash * 2 + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3564 | } else if (key->IsHeapNumber() && |
| 3565 | number->IsHeapNumber() && |
| 3566 | key->Number() == number->Number()) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3567 | return String::cast(number_string_cache()->get(hash * 2 + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3568 | } |
| 3569 | return undefined_value(); |
| 3570 | } |
| 3571 | |
| 3572 | |
| 3573 | void Heap::SetNumberStringCache(Object* number, String* string) { |
| 3574 | int hash; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3575 | int mask = (number_string_cache()->length() >> 1) - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3576 | if (number->IsSmi()) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3577 | hash = smi_get_hash(Smi::cast(number)) & mask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3578 | } else { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3579 | hash = double_get_hash(number->Number()) & mask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3580 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3581 | if (number_string_cache()->get(hash * 2) != undefined_value() && |
| 3582 | number_string_cache()->length() != FullSizeNumberStringCacheLength()) { |
| 3583 | // The first time we have a hash collision, we move to the full sized |
| 3584 | // number string cache. |
| 3585 | AllocateFullSizeNumberStringCache(); |
| 3586 | return; |
| 3587 | } |
| 3588 | number_string_cache()->set(hash * 2, number); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 3589 | number_string_cache()->set(hash * 2 + 1, string); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3593 | MaybeObject* Heap::NumberToString(Object* number, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3594 | bool check_number_string_cache, |
| 3595 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3596 | isolate_->counters()->number_to_string_runtime()->Increment(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3597 | if (check_number_string_cache) { |
| 3598 | Object* cached = GetNumberStringCache(number); |
| 3599 | if (cached != undefined_value()) { |
| 3600 | return cached; |
| 3601 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | char arr[100]; |
| 3605 | Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
| 3606 | const char* str; |
| 3607 | if (number->IsSmi()) { |
| 3608 | int num = Smi::cast(number)->value(); |
| 3609 | str = IntToCString(num, buffer); |
| 3610 | } else { |
| 3611 | double num = HeapNumber::cast(number)->value(); |
| 3612 | str = DoubleToCString(num, buffer); |
| 3613 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3614 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3615 | Object* js_string; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3616 | MaybeObject* maybe_js_string = |
| 3617 | AllocateStringFromOneByte(CStrVector(str), pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3618 | if (maybe_js_string->ToObject(&js_string)) { |
| 3619 | SetNumberStringCache(number, String::cast(js_string)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3620 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3621 | return maybe_js_string; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3625 | MaybeObject* Heap::Uint32ToString(uint32_t value, |
| 3626 | bool check_number_string_cache) { |
| 3627 | Object* number; |
| 3628 | MaybeObject* maybe = NumberFromUint32(value); |
| 3629 | if (!maybe->To<Object>(&number)) return maybe; |
| 3630 | return NumberToString(number, check_number_string_cache); |
| 3631 | } |
| 3632 | |
| 3633 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3634 | Map* Heap::MapForExternalArrayType(ExternalArrayType array_type) { |
| 3635 | return Map::cast(roots_[RootIndexForExternalArrayType(array_type)]); |
| 3636 | } |
| 3637 | |
| 3638 | |
| 3639 | Heap::RootListIndex Heap::RootIndexForExternalArrayType( |
| 3640 | ExternalArrayType array_type) { |
| 3641 | switch (array_type) { |
| 3642 | case kExternalByteArray: |
| 3643 | return kExternalByteArrayMapRootIndex; |
| 3644 | case kExternalUnsignedByteArray: |
| 3645 | return kExternalUnsignedByteArrayMapRootIndex; |
| 3646 | case kExternalShortArray: |
| 3647 | return kExternalShortArrayMapRootIndex; |
| 3648 | case kExternalUnsignedShortArray: |
| 3649 | return kExternalUnsignedShortArrayMapRootIndex; |
| 3650 | case kExternalIntArray: |
| 3651 | return kExternalIntArrayMapRootIndex; |
| 3652 | case kExternalUnsignedIntArray: |
| 3653 | return kExternalUnsignedIntArrayMapRootIndex; |
| 3654 | case kExternalFloatArray: |
| 3655 | return kExternalFloatArrayMapRootIndex; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3656 | case kExternalDoubleArray: |
| 3657 | return kExternalDoubleArrayMapRootIndex; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3658 | case kExternalPixelArray: |
| 3659 | return kExternalPixelArrayMapRootIndex; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3660 | default: |
| 3661 | UNREACHABLE(); |
| 3662 | return kUndefinedValueRootIndex; |
| 3663 | } |
| 3664 | } |
| 3665 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3666 | Heap::RootListIndex Heap::RootIndexForEmptyExternalArray( |
| 3667 | ElementsKind elementsKind) { |
| 3668 | switch (elementsKind) { |
| 3669 | case EXTERNAL_BYTE_ELEMENTS: |
| 3670 | return kEmptyExternalByteArrayRootIndex; |
| 3671 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 3672 | return kEmptyExternalUnsignedByteArrayRootIndex; |
| 3673 | case EXTERNAL_SHORT_ELEMENTS: |
| 3674 | return kEmptyExternalShortArrayRootIndex; |
| 3675 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 3676 | return kEmptyExternalUnsignedShortArrayRootIndex; |
| 3677 | case EXTERNAL_INT_ELEMENTS: |
| 3678 | return kEmptyExternalIntArrayRootIndex; |
| 3679 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 3680 | return kEmptyExternalUnsignedIntArrayRootIndex; |
| 3681 | case EXTERNAL_FLOAT_ELEMENTS: |
| 3682 | return kEmptyExternalFloatArrayRootIndex; |
| 3683 | case EXTERNAL_DOUBLE_ELEMENTS: |
| 3684 | return kEmptyExternalDoubleArrayRootIndex; |
| 3685 | case EXTERNAL_PIXEL_ELEMENTS: |
| 3686 | return kEmptyExternalPixelArrayRootIndex; |
| 3687 | default: |
| 3688 | UNREACHABLE(); |
| 3689 | return kUndefinedValueRootIndex; |
| 3690 | } |
| 3691 | } |
| 3692 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 3693 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3694 | ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { |
| 3695 | return ExternalArray::cast( |
| 3696 | roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); |
| 3697 | } |
| 3698 | |
| 3699 | |
| 3700 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3701 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3702 | MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 3703 | // We need to distinguish the minus zero value and this cannot be |
| 3704 | // done after conversion to int. Doing this by comparing bit |
| 3705 | // patterns is faster than using fpclassify() et al. |
| 3706 | static const DoubleRepresentation minus_zero(-0.0); |
| 3707 | |
| 3708 | DoubleRepresentation rep(value); |
| 3709 | if (rep.bits == minus_zero.bits) { |
| 3710 | return AllocateHeapNumber(-0.0, pretenure); |
| 3711 | } |
| 3712 | |
| 3713 | int int_value = FastD2I(value); |
| 3714 | if (value == int_value && Smi::IsValid(int_value)) { |
| 3715 | return Smi::FromInt(int_value); |
| 3716 | } |
| 3717 | |
| 3718 | // Materialize the value in the heap. |
| 3719 | return AllocateHeapNumber(value, pretenure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3723 | MaybeObject* Heap::AllocateForeign(Address address, PretenureFlag pretenure) { |
| 3724 | // Statically ensure that it is safe to allocate foreigns in paged spaces. |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 3725 | STATIC_ASSERT(Foreign::kSize <= Page::kMaxNonCodeHeapObjectSize); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3726 | AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3727 | Foreign* result; |
| 3728 | MaybeObject* maybe_result = Allocate(foreign_map(), space); |
| 3729 | if (!maybe_result->To(&result)) return maybe_result; |
| 3730 | result->set_foreign_address(address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3731 | return result; |
| 3732 | } |
| 3733 | |
| 3734 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3735 | MaybeObject* Heap::AllocateSharedFunctionInfo(Object* name) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3736 | SharedFunctionInfo* share; |
| 3737 | MaybeObject* maybe = Allocate(shared_function_info_map(), OLD_POINTER_SPACE); |
| 3738 | if (!maybe->To<SharedFunctionInfo>(&share)) return maybe; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3739 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3740 | // Set pointer fields. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3741 | share->set_name(name); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3742 | Code* illegal = isolate_->builtins()->builtin(Builtins::kIllegal); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3743 | share->set_code(illegal); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 3744 | share->set_optimized_code_map(Smi::FromInt(0)); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3745 | share->set_scope_info(ScopeInfo::Empty(isolate_)); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3746 | Code* construct_stub = |
| 3747 | isolate_->builtins()->builtin(Builtins::kJSConstructStubGeneric); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 3748 | share->set_construct_stub(construct_stub); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3749 | share->set_instance_class_name(Object_string()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3750 | share->set_function_data(undefined_value(), SKIP_WRITE_BARRIER); |
| 3751 | share->set_script(undefined_value(), SKIP_WRITE_BARRIER); |
| 3752 | share->set_debug_info(undefined_value(), SKIP_WRITE_BARRIER); |
| 3753 | share->set_inferred_name(empty_string(), SKIP_WRITE_BARRIER); |
| 3754 | share->set_initial_map(undefined_value(), SKIP_WRITE_BARRIER); |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 3755 | share->set_ast_node_count(0); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3756 | share->set_counters(0); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3757 | |
| 3758 | // Set integer fields (smi or int, depending on the architecture). |
| 3759 | share->set_length(0); |
| 3760 | share->set_formal_parameter_count(0); |
| 3761 | share->set_expected_nof_properties(0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3762 | share->set_num_literals(0); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3763 | share->set_start_position_and_type(0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3764 | share->set_end_position(0); |
| 3765 | share->set_function_token_position(0); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3766 | // All compiler hints default to false or 0. |
| 3767 | share->set_compiler_hints(0); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 3768 | share->set_opt_count_and_bailout_reason(0); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3769 | |
| 3770 | return share; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3774 | MaybeObject* Heap::AllocateJSMessageObject(String* type, |
| 3775 | JSArray* arguments, |
| 3776 | int start_position, |
| 3777 | int end_position, |
| 3778 | Object* script, |
| 3779 | Object* stack_trace, |
| 3780 | Object* stack_frames) { |
| 3781 | Object* result; |
| 3782 | { MaybeObject* maybe_result = Allocate(message_object_map(), NEW_SPACE); |
| 3783 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3784 | } |
| 3785 | JSMessageObject* message = JSMessageObject::cast(result); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3786 | message->set_properties(Heap::empty_fixed_array(), SKIP_WRITE_BARRIER); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3787 | message->initialize_elements(); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 3788 | message->set_elements(Heap::empty_fixed_array(), SKIP_WRITE_BARRIER); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3789 | message->set_type(type); |
| 3790 | message->set_arguments(arguments); |
| 3791 | message->set_start_position(start_position); |
| 3792 | message->set_end_position(end_position); |
| 3793 | message->set_script(script); |
| 3794 | message->set_stack_trace(stack_trace); |
| 3795 | message->set_stack_frames(stack_frames); |
| 3796 | return result; |
| 3797 | } |
| 3798 | |
| 3799 | |
| 3800 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3801 | // Returns true for a character in a range. Both limits are inclusive. |
| 3802 | static inline bool Between(uint32_t character, uint32_t from, uint32_t to) { |
| 3803 | // This makes uses of the the unsigned wraparound. |
| 3804 | return character - from <= to - from; |
| 3805 | } |
| 3806 | |
| 3807 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3808 | MUST_USE_RESULT static inline MaybeObject* MakeOrFindTwoCharacterString( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3809 | Heap* heap, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3810 | uint16_t c1, |
| 3811 | uint16_t c2) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3812 | String* result; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3813 | // Numeric strings have a different hash algorithm not known by |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3814 | // LookupTwoCharsStringIfExists, so we skip this step for such strings. |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3815 | if ((!Between(c1, '0', '9') || !Between(c2, '0', '9')) && |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3816 | heap->string_table()->LookupTwoCharsStringIfExists(c1, c2, &result)) { |
| 3817 | return result; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3818 | // Now we know the length is 2, we might as well make use of that fact |
| 3819 | // when building the new string. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3820 | } else if (static_cast<unsigned>(c1 | c2) <= String::kMaxOneByteCharCodeU) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3821 | // We can do this. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3822 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCodeU + 1)); // because of this. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3823 | Object* result; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3824 | { MaybeObject* maybe_result = heap->AllocateRawOneByteString(2); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3825 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3826 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3827 | uint8_t* dest = SeqOneByteString::cast(result)->GetChars(); |
| 3828 | dest[0] = static_cast<uint8_t>(c1); |
| 3829 | dest[1] = static_cast<uint8_t>(c2); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3830 | return result; |
| 3831 | } else { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3832 | Object* result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3833 | { MaybeObject* maybe_result = heap->AllocateRawTwoByteString(2); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3834 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3835 | } |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3836 | uc16* dest = SeqTwoByteString::cast(result)->GetChars(); |
| 3837 | dest[0] = c1; |
| 3838 | dest[1] = c2; |
| 3839 | return result; |
| 3840 | } |
| 3841 | } |
| 3842 | |
| 3843 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3844 | MaybeObject* Heap::AllocateConsString(String* first, String* second) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3845 | int first_length = first->length(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3846 | if (first_length == 0) { |
| 3847 | return second; |
| 3848 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3849 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3850 | int second_length = second->length(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3851 | if (second_length == 0) { |
| 3852 | return first; |
| 3853 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3854 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3855 | int length = first_length + second_length; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3856 | |
| 3857 | // Optimization for 2-byte strings often used as keys in a decompression |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3858 | // dictionary. Check whether we already have the string in the string |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3859 | // table to prevent creation of many unneccesary strings. |
| 3860 | if (length == 2) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3861 | uint16_t c1 = first->Get(0); |
| 3862 | uint16_t c2 = second->Get(0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3863 | return MakeOrFindTwoCharacterString(this, c1, c2); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3866 | bool first_is_one_byte = first->IsOneByteRepresentation(); |
| 3867 | bool second_is_one_byte = second->IsOneByteRepresentation(); |
| 3868 | bool is_one_byte = first_is_one_byte && second_is_one_byte; |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3869 | // Make sure that an out of memory exception is thrown if the length |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3870 | // of the new cons string is too large. |
| 3871 | if (length > String::kMaxLength || length < 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3872 | isolate()->context()->mark_out_of_memory(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3873 | return Failure::OutOfMemoryException(0x4); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3874 | } |
| 3875 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3876 | bool is_one_byte_data_in_two_byte_string = false; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3877 | if (!is_one_byte) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3878 | // At least one of the strings uses two-byte representation so we |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3879 | // can't use the fast case code for short ASCII strings below, but |
| 3880 | // we can try to save memory if all chars actually fit in ASCII. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3881 | is_one_byte_data_in_two_byte_string = |
| 3882 | first->HasOnlyOneByteChars() && second->HasOnlyOneByteChars(); |
| 3883 | if (is_one_byte_data_in_two_byte_string) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3884 | isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3888 | // If the resulting string is small make a flat string. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3889 | if (length < ConsString::kMinLength) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3890 | // Note that neither of the two inputs can be a slice because: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3891 | STATIC_ASSERT(ConsString::kMinLength <= SlicedString::kMinLength); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3892 | ASSERT(first->IsFlat()); |
| 3893 | ASSERT(second->IsFlat()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3894 | if (is_one_byte) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3895 | Object* result; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3896 | { MaybeObject* maybe_result = AllocateRawOneByteString(length); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3897 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3898 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3899 | // Copy the characters into the new object. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3900 | uint8_t* dest = SeqOneByteString::cast(result)->GetChars(); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3901 | // Copy first part. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3902 | const uint8_t* src; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3903 | if (first->IsExternalString()) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3904 | src = ExternalAsciiString::cast(first)->GetChars(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3905 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3906 | src = SeqOneByteString::cast(first)->GetChars(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3907 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3908 | for (int i = 0; i < first_length; i++) *dest++ = src[i]; |
| 3909 | // Copy second part. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3910 | if (second->IsExternalString()) { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3911 | src = ExternalAsciiString::cast(second)->GetChars(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3912 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3913 | src = SeqOneByteString::cast(second)->GetChars(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3914 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3915 | for (int i = 0; i < second_length; i++) *dest++ = src[i]; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3916 | return result; |
| 3917 | } else { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3918 | if (is_one_byte_data_in_two_byte_string) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3919 | Object* result; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3920 | { MaybeObject* maybe_result = AllocateRawOneByteString(length); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3921 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3922 | } |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 3923 | // Copy the characters into the new object. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3924 | uint8_t* dest = SeqOneByteString::cast(result)->GetChars(); |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 3925 | String::WriteToFlat(first, dest, 0, first_length); |
| 3926 | String::WriteToFlat(second, dest + first_length, 0, second_length); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3927 | isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 3928 | return result; |
| 3929 | } |
| 3930 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3931 | Object* result; |
| 3932 | { MaybeObject* maybe_result = AllocateRawTwoByteString(length); |
| 3933 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3934 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3935 | // Copy the characters into the new object. |
| 3936 | uc16* dest = SeqTwoByteString::cast(result)->GetChars(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3937 | String::WriteToFlat(first, dest, 0, first_length); |
| 3938 | String::WriteToFlat(second, dest + first_length, 0, second_length); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3939 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3940 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3941 | } |
| 3942 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3943 | Map* map = (is_one_byte || is_one_byte_data_in_two_byte_string) ? |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3944 | cons_ascii_string_map() : cons_string_map(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3945 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3946 | Object* result; |
| 3947 | { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 3948 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3949 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3950 | |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 3951 | DisallowHeapAllocation no_gc; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3952 | ConsString* cons_string = ConsString::cast(result); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3953 | WriteBarrierMode mode = cons_string->GetWriteBarrierMode(no_gc); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3954 | cons_string->set_length(length); |
| 3955 | cons_string->set_hash_field(String::kEmptyHashField); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3956 | cons_string->set_first(first, mode); |
| 3957 | cons_string->set_second(second, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3958 | return result; |
| 3959 | } |
| 3960 | |
| 3961 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3962 | MaybeObject* Heap::AllocateSubString(String* buffer, |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3963 | int start, |
| 3964 | int end, |
| 3965 | PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3966 | int length = end - start; |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3967 | if (length <= 0) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3968 | return empty_string(); |
| 3969 | } else if (length == 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3970 | return LookupSingleCharacterStringFromCode(buffer->Get(start)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3971 | } else if (length == 2) { |
| 3972 | // Optimization for 2-byte strings often used as keys in a decompression |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3973 | // dictionary. Check whether we already have the string in the string |
| 3974 | // table to prevent creation of many unnecessary strings. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3975 | uint16_t c1 = buffer->Get(start); |
| 3976 | uint16_t c2 = buffer->Get(start + 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3977 | return MakeOrFindTwoCharacterString(this, c1, c2); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3978 | } |
| 3979 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3980 | // Make an attempt to flatten the buffer to reduce access time. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3981 | buffer = buffer->TryFlattenGetString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3982 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3983 | if (!FLAG_string_slices || |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3984 | !buffer->IsFlat() || |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3985 | length < SlicedString::kMinLength || |
| 3986 | pretenure == TENURED) { |
| 3987 | Object* result; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3988 | // WriteToFlat takes care of the case when an indirect string has a |
| 3989 | // different encoding from its underlying string. These encodings may |
| 3990 | // differ because of externalization. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3991 | bool is_one_byte = buffer->IsOneByteRepresentation(); |
| 3992 | { MaybeObject* maybe_result = is_one_byte |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3993 | ? AllocateRawOneByteString(length, pretenure) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3994 | : AllocateRawTwoByteString(length, pretenure); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3995 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3996 | } |
| 3997 | String* string_result = String::cast(result); |
| 3998 | // Copy the characters into the new object. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3999 | if (is_one_byte) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4000 | ASSERT(string_result->IsOneByteRepresentation()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4001 | uint8_t* dest = SeqOneByteString::cast(string_result)->GetChars(); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4002 | String::WriteToFlat(buffer, dest, start, end); |
| 4003 | } else { |
| 4004 | ASSERT(string_result->IsTwoByteRepresentation()); |
| 4005 | uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); |
| 4006 | String::WriteToFlat(buffer, dest, start, end); |
| 4007 | } |
| 4008 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4009 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4010 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4011 | ASSERT(buffer->IsFlat()); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4012 | #if VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4013 | if (FLAG_verify_heap) { |
| 4014 | buffer->StringVerify(); |
| 4015 | } |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4016 | #endif |
| 4017 | |
| 4018 | Object* result; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4019 | // When slicing an indirect string we use its encoding for a newly created |
| 4020 | // slice and don't check the encoding of the underlying string. This is safe |
| 4021 | // even if the encodings are different because of externalization. If an |
| 4022 | // indirect ASCII string is pointing to a two-byte string, the two-byte char |
| 4023 | // codes of the underlying string must still fit into ASCII (because |
| 4024 | // externalization must not change char codes). |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4025 | { Map* map = buffer->IsOneByteRepresentation() |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4026 | ? sliced_ascii_string_map() |
| 4027 | : sliced_string_map(); |
| 4028 | MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 4029 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4030 | } |
| 4031 | |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 4032 | DisallowHeapAllocation no_gc; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4033 | SlicedString* sliced_string = SlicedString::cast(result); |
| 4034 | sliced_string->set_length(length); |
| 4035 | sliced_string->set_hash_field(String::kEmptyHashField); |
| 4036 | if (buffer->IsConsString()) { |
| 4037 | ConsString* cons = ConsString::cast(buffer); |
| 4038 | ASSERT(cons->second()->length() == 0); |
| 4039 | sliced_string->set_parent(cons->first()); |
| 4040 | sliced_string->set_offset(start); |
| 4041 | } else if (buffer->IsSlicedString()) { |
| 4042 | // Prevent nesting sliced strings. |
| 4043 | SlicedString* parent_slice = SlicedString::cast(buffer); |
| 4044 | sliced_string->set_parent(parent_slice->parent()); |
| 4045 | sliced_string->set_offset(start + parent_slice->offset()); |
| 4046 | } else { |
| 4047 | sliced_string->set_parent(buffer); |
| 4048 | sliced_string->set_offset(start); |
| 4049 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4050 | ASSERT(sliced_string->parent()->IsSeqString() || |
| 4051 | sliced_string->parent()->IsExternalString()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4052 | return result; |
| 4053 | } |
| 4054 | |
| 4055 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4056 | MaybeObject* Heap::AllocateExternalStringFromAscii( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4057 | const ExternalAsciiString::Resource* resource) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4058 | size_t length = resource->length(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4059 | if (length > static_cast<size_t>(String::kMaxLength)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4060 | isolate()->context()->mark_out_of_memory(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4061 | return Failure::OutOfMemoryException(0x5); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4064 | Map* map = external_ascii_string_map(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4065 | Object* result; |
| 4066 | { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 4067 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4068 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4069 | |
| 4070 | ExternalAsciiString* external_string = ExternalAsciiString::cast(result); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4071 | external_string->set_length(static_cast<int>(length)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4072 | external_string->set_hash_field(String::kEmptyHashField); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4073 | external_string->set_resource(resource); |
| 4074 | |
| 4075 | return result; |
| 4076 | } |
| 4077 | |
| 4078 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4079 | MaybeObject* Heap::AllocateExternalStringFromTwoByte( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4080 | const ExternalTwoByteString::Resource* resource) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4081 | size_t length = resource->length(); |
| 4082 | if (length > static_cast<size_t>(String::kMaxLength)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4083 | isolate()->context()->mark_out_of_memory(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4084 | return Failure::OutOfMemoryException(0x6); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4085 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4086 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 4087 | // For small strings we check whether the resource contains only |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4088 | // one byte characters. If yes, we use a different string map. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4089 | static const size_t kOneByteCheckLengthLimit = 32; |
| 4090 | bool is_one_byte = length <= kOneByteCheckLengthLimit && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4091 | String::IsOneByte(resource->data(), static_cast<int>(length)); |
| 4092 | Map* map = is_one_byte ? |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4093 | external_string_with_one_byte_data_map() : external_string_map(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4094 | Object* result; |
| 4095 | { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 4096 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4097 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4098 | |
| 4099 | ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4100 | external_string->set_length(static_cast<int>(length)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4101 | external_string->set_hash_field(String::kEmptyHashField); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4102 | external_string->set_resource(resource); |
| 4103 | |
| 4104 | return result; |
| 4105 | } |
| 4106 | |
| 4107 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4108 | MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4109 | if (code <= String::kMaxOneByteCharCode) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4110 | Object* value = single_character_string_cache()->get(code); |
| 4111 | if (value != undefined_value()) return value; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4112 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4113 | uint8_t buffer[1]; |
| 4114 | buffer[0] = static_cast<uint8_t>(code); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4115 | Object* result; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4116 | MaybeObject* maybe_result = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4117 | InternalizeOneByteString(Vector<const uint8_t>(buffer, 1)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4118 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4119 | if (!maybe_result->ToObject(&result)) return maybe_result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4120 | single_character_string_cache()->set(code, result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4121 | return result; |
| 4122 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4123 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4124 | SeqTwoByteString* result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4125 | { MaybeObject* maybe_result = AllocateRawTwoByteString(1); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4126 | if (!maybe_result->To<SeqTwoByteString>(&result)) return maybe_result; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4127 | } |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4128 | result->SeqTwoByteStringSet(0, code); |
| 4129 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4133 | MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4134 | if (length < 0 || length > ByteArray::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4135 | return Failure::OutOfMemoryException(0x7); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4136 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4137 | int size = ByteArray::SizeFor(length); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 4138 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4139 | Object* result; |
| 4140 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 4141 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4142 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4143 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4144 | reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier( |
| 4145 | byte_array_map()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4146 | reinterpret_cast<ByteArray*>(result)->set_length(length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4147 | return result; |
| 4148 | } |
| 4149 | |
| 4150 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4151 | void Heap::CreateFillerObjectAt(Address addr, int size) { |
| 4152 | if (size == 0) return; |
| 4153 | HeapObject* filler = HeapObject::FromAddress(addr); |
| 4154 | if (size == kPointerSize) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4155 | filler->set_map_no_write_barrier(one_pointer_filler_map()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4156 | } else if (size == 2 * kPointerSize) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4157 | filler->set_map_no_write_barrier(two_pointer_filler_map()); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4158 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4159 | filler->set_map_no_write_barrier(free_space_map()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4160 | FreeSpace::cast(filler)->set_size(size); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | |
| 4164 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4165 | MaybeObject* Heap::AllocateExternalArray(int length, |
| 4166 | ExternalArrayType array_type, |
| 4167 | void* external_pointer, |
| 4168 | PretenureFlag pretenure) { |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 4169 | int size = ExternalArray::kAlignedSize; |
| 4170 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4171 | Object* result; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 4172 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4173 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4174 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4175 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4176 | reinterpret_cast<ExternalArray*>(result)->set_map_no_write_barrier( |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4177 | MapForExternalArrayType(array_type)); |
| 4178 | reinterpret_cast<ExternalArray*>(result)->set_length(length); |
| 4179 | reinterpret_cast<ExternalArray*>(result)->set_external_pointer( |
| 4180 | external_pointer); |
| 4181 | |
| 4182 | return result; |
| 4183 | } |
| 4184 | |
| 4185 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4186 | MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
| 4187 | Code::Flags flags, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4188 | Handle<Object> self_reference, |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 4189 | bool immovable, |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 4190 | bool crankshafted, |
| 4191 | int prologue_offset) { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4192 | // Allocate ByteArray before the Code object, so that we do not risk |
| 4193 | // leaving uninitialized Code object (and breaking the heap). |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4194 | ByteArray* reloc_info; |
| 4195 | MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED); |
| 4196 | if (!maybe_reloc_info->To(&reloc_info)) return maybe_reloc_info; |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4197 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4198 | // Compute size. |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4199 | int body_size = RoundUp(desc.instr_size, kObjectAlignment); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4200 | int obj_size = Code::SizeFor(body_size); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4201 | ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4202 | MaybeObject* maybe_result; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4203 | // Large code objects and code objects which should stay at a fixed address |
| 4204 | // are allocated in large object space. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4205 | HeapObject* result; |
| 4206 | bool force_lo_space = obj_size > code_space()->AreaSize(); |
| 4207 | if (force_lo_space) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4208 | maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4209 | } else { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4210 | maybe_result = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4211 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4212 | if (!maybe_result->To<HeapObject>(&result)) return maybe_result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4213 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4214 | if (immovable && !force_lo_space && |
| 4215 | // Objects on the first page of each space are never moved. |
| 4216 | !code_space_->FirstPage()->Contains(result->address())) { |
| 4217 | // Discard the first code allocation, which was on a page where it could be |
| 4218 | // moved. |
| 4219 | CreateFillerObjectAt(result->address(), obj_size); |
| 4220 | maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
| 4221 | if (!maybe_result->To<HeapObject>(&result)) return maybe_result; |
| 4222 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4223 | |
| 4224 | // Initialize the object |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4225 | result->set_map_no_write_barrier(code_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4226 | Code* code = Code::cast(result); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4227 | ASSERT(!isolate_->code_range()->exists() || |
| 4228 | isolate_->code_range()->contains(code->address())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4229 | code->set_instruction_size(desc.instr_size); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4230 | code->set_relocation_info(reloc_info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4231 | code->set_flags(flags); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4232 | if (code->is_call_stub() || code->is_keyed_call_stub()) { |
| 4233 | code->set_check_type(RECEIVER_MAP_CHECK); |
| 4234 | } |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 4235 | code->set_is_crankshafted(crankshafted); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4236 | code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 4237 | code->set_raw_type_feedback_info(undefined_value()); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4238 | code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4239 | code->set_gc_metadata(Smi::FromInt(0)); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4240 | code->set_ic_age(global_ic_age_); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 4241 | code->set_prologue_offset(prologue_offset); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4242 | if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 4243 | code->set_marked_for_deoptimization(false); |
| 4244 | } |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 4245 | |
| 4246 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 4247 | if (code->kind() == Code::FUNCTION) { |
| 4248 | code->set_has_debug_break_slots( |
| 4249 | isolate_->debugger()->IsDebuggerActive()); |
| 4250 | } |
| 4251 | #endif |
| 4252 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 4253 | // Allow self references to created code object by patching the handle to |
| 4254 | // point to the newly allocated Code object. |
| 4255 | if (!self_reference.is_null()) { |
| 4256 | *(self_reference.location()) = code; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4257 | } |
| 4258 | // Migrate generated code. |
| 4259 | // The generated code can contain Object** values (typically from handles) |
| 4260 | // that are dereferenced during the copy to point directly to the actual heap |
| 4261 | // objects. These pointers can include references to the code object itself, |
| 4262 | // through the self_reference parameter. |
| 4263 | code->CopyFrom(desc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4264 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4265 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4266 | if (FLAG_verify_heap) { |
| 4267 | code->Verify(); |
| 4268 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4269 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4270 | return code; |
| 4271 | } |
| 4272 | |
| 4273 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4274 | MaybeObject* Heap::CopyCode(Code* code) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4275 | // Allocate an object the same size as the code object. |
| 4276 | int obj_size = code->Size(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4277 | MaybeObject* maybe_result; |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 4278 | if (obj_size > code_space()->AreaSize()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4279 | maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4280 | } else { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4281 | maybe_result = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4284 | Object* result; |
| 4285 | if (!maybe_result->ToObject(&result)) return maybe_result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4286 | |
| 4287 | // Copy code object. |
| 4288 | Address old_addr = code->address(); |
| 4289 | Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4290 | CopyBlock(new_addr, old_addr, obj_size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4291 | // Relocate the copy. |
| 4292 | Code* new_code = Code::cast(result); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4293 | ASSERT(!isolate_->code_range()->exists() || |
| 4294 | isolate_->code_range()->contains(code->address())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4295 | new_code->Relocate(new_addr - old_addr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4296 | return new_code; |
| 4297 | } |
| 4298 | |
| 4299 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4300 | MaybeObject* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4301 | // Allocate ByteArray before the Code object, so that we do not risk |
| 4302 | // leaving uninitialized Code object (and breaking the heap). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4303 | Object* reloc_info_array; |
| 4304 | { MaybeObject* maybe_reloc_info_array = |
| 4305 | AllocateByteArray(reloc_info.length(), TENURED); |
| 4306 | if (!maybe_reloc_info_array->ToObject(&reloc_info_array)) { |
| 4307 | return maybe_reloc_info_array; |
| 4308 | } |
| 4309 | } |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4310 | |
| 4311 | int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4312 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4313 | int new_obj_size = Code::SizeFor(new_body_size); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4314 | |
| 4315 | Address old_addr = code->address(); |
| 4316 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 4317 | size_t relocation_offset = |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4318 | static_cast<size_t>(code->instruction_end() - old_addr); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4319 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4320 | MaybeObject* maybe_result; |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 4321 | if (new_obj_size > code_space()->AreaSize()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4322 | maybe_result = lo_space_->AllocateRaw(new_obj_size, EXECUTABLE); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4323 | } else { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4324 | maybe_result = AllocateRaw(new_obj_size, CODE_SPACE, CODE_SPACE); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4327 | Object* result; |
| 4328 | if (!maybe_result->ToObject(&result)) return maybe_result; |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4329 | |
| 4330 | // Copy code object. |
| 4331 | Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
| 4332 | |
| 4333 | // Copy header and instructions. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4334 | CopyBytes(new_addr, old_addr, relocation_offset); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4335 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4336 | Code* new_code = Code::cast(result); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4337 | new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4338 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4339 | // Copy patched rinfo. |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 4340 | CopyBytes(new_code->relocation_start(), |
| 4341 | reloc_info.start(), |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4342 | static_cast<size_t>(reloc_info.length())); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4343 | |
| 4344 | // Relocate the copy. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4345 | ASSERT(!isolate_->code_range()->exists() || |
| 4346 | isolate_->code_range()->contains(code->address())); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4347 | new_code->Relocate(new_addr - old_addr); |
| 4348 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4349 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4350 | if (FLAG_verify_heap) { |
| 4351 | code->Verify(); |
| 4352 | } |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 4353 | #endif |
| 4354 | return new_code; |
| 4355 | } |
| 4356 | |
| 4357 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4358 | MaybeObject* Heap::AllocateWithAllocationSite(Map* map, AllocationSpace space, |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4359 | Handle<AllocationSite> allocation_site) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4360 | ASSERT(gc_state_ == NOT_IN_GC); |
| 4361 | ASSERT(map->instance_type() != MAP_TYPE); |
| 4362 | // If allocation failures are disallowed, we may allocate in a different |
| 4363 | // space when new space is full and the object is not a large object. |
| 4364 | AllocationSpace retry_space = |
| 4365 | (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type()); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4366 | int size = map->instance_size() + AllocationMemento::kSize; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4367 | Object* result; |
| 4368 | MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); |
| 4369 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4370 | // No need for write barrier since object is white and map is in old space. |
| 4371 | HeapObject::cast(result)->set_map_no_write_barrier(map); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4372 | AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4373 | reinterpret_cast<Address>(result) + map->instance_size()); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4374 | alloc_memento->set_map_no_write_barrier(allocation_memento_map()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4375 | ASSERT(allocation_site->map() == allocation_site_map()); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4376 | alloc_memento->set_allocation_site(*allocation_site, SKIP_WRITE_BARRIER); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4377 | return result; |
| 4378 | } |
| 4379 | |
| 4380 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4381 | MaybeObject* Heap::Allocate(Map* map, AllocationSpace space) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4382 | ASSERT(gc_state_ == NOT_IN_GC); |
| 4383 | ASSERT(map->instance_type() != MAP_TYPE); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4384 | // If allocation failures are disallowed, we may allocate in a different |
| 4385 | // space when new space is full and the object is not a large object. |
| 4386 | AllocationSpace retry_space = |
| 4387 | (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4388 | int size = map->instance_size(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4389 | Object* result; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4390 | MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); |
| 4391 | if (!maybe_result->ToObject(&result)) return maybe_result; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4392 | // No need for write barrier since object is white and map is in old space. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4393 | HeapObject::cast(result)->set_map_no_write_barrier(map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4394 | return result; |
| 4395 | } |
| 4396 | |
| 4397 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4398 | void Heap::InitializeFunction(JSFunction* function, |
| 4399 | SharedFunctionInfo* shared, |
| 4400 | Object* prototype) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4401 | ASSERT(!prototype->IsMap()); |
| 4402 | function->initialize_properties(); |
| 4403 | function->initialize_elements(); |
| 4404 | function->set_shared(shared); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4405 | function->set_code(shared->code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4406 | function->set_prototype_or_initial_map(prototype); |
| 4407 | function->set_context(undefined_value()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4408 | function->set_literals_or_bindings(empty_fixed_array()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4409 | function->set_next_function_link(undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4413 | MaybeObject* Heap::AllocateFunction(Map* function_map, |
| 4414 | SharedFunctionInfo* shared, |
| 4415 | Object* prototype, |
| 4416 | PretenureFlag pretenure) { |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 4417 | AllocationSpace space = |
| 4418 | (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4419 | Object* result; |
| 4420 | { MaybeObject* maybe_result = Allocate(function_map, space); |
| 4421 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4422 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4423 | InitializeFunction(JSFunction::cast(result), shared, prototype); |
| 4424 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4428 | MaybeObject* Heap::AllocateArgumentsObject(Object* callee, int length) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4429 | // To get fast allocation and map sharing for arguments objects we |
| 4430 | // allocate them based on an arguments boilerplate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4431 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4432 | JSObject* boilerplate; |
| 4433 | int arguments_object_size; |
| 4434 | bool strict_mode_callee = callee->IsJSFunction() && |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4435 | !JSFunction::cast(callee)->shared()->is_classic_mode(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4436 | if (strict_mode_callee) { |
| 4437 | boilerplate = |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4438 | isolate()->context()->native_context()-> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4439 | strict_mode_arguments_boilerplate(); |
| 4440 | arguments_object_size = kArgumentsObjectSizeStrict; |
| 4441 | } else { |
| 4442 | boilerplate = |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4443 | isolate()->context()->native_context()->arguments_boilerplate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4444 | arguments_object_size = kArgumentsObjectSize; |
| 4445 | } |
| 4446 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 4447 | // Check that the size of the boilerplate matches our |
| 4448 | // expectations. The ArgumentsAccessStub::GenerateNewObject relies |
| 4449 | // on the size being a known constant. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4450 | ASSERT(arguments_object_size == boilerplate->map()->instance_size()); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 4451 | |
| 4452 | // Do the allocation. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4453 | Object* result; |
| 4454 | { MaybeObject* maybe_result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4455 | AllocateRaw(arguments_object_size, NEW_SPACE, OLD_POINTER_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4456 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4457 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4458 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4459 | // Copy the content. The arguments boilerplate doesn't have any |
| 4460 | // fields that point to new space so it's safe to skip the write |
| 4461 | // barrier here. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4462 | CopyBlock(HeapObject::cast(result)->address(), |
| 4463 | boilerplate->address(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4464 | JSObject::kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4465 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4466 | // Set the length property. |
| 4467 | JSObject::cast(result)->InObjectPropertyAtPut(kArgumentsLengthIndex, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4468 | Smi::FromInt(length), |
| 4469 | SKIP_WRITE_BARRIER); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4470 | // Set the callee property for non-strict mode arguments object only. |
| 4471 | if (!strict_mode_callee) { |
| 4472 | JSObject::cast(result)->InObjectPropertyAtPut(kArgumentsCalleeIndex, |
| 4473 | callee); |
| 4474 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4475 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4476 | // Check the state of the object |
| 4477 | ASSERT(JSObject::cast(result)->HasFastProperties()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4478 | ASSERT(JSObject::cast(result)->HasFastObjectElements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4479 | |
| 4480 | return result; |
| 4481 | } |
| 4482 | |
| 4483 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4484 | void Heap::InitializeJSObjectFromMap(JSObject* obj, |
| 4485 | FixedArray* properties, |
| 4486 | Map* map) { |
| 4487 | obj->set_properties(properties); |
| 4488 | obj->initialize_elements(); |
| 4489 | // TODO(1240798): Initialize the object's body using valid initial values |
| 4490 | // according to the object's initial map. For example, if the map's |
| 4491 | // instance type is JS_ARRAY_TYPE, the length field should be initialized |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4492 | // to a number (e.g. Smi::FromInt(0)) and the elements initialized to a |
| 4493 | // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4494 | // verification code has to cope with (temporarily) invalid objects. See |
| 4495 | // for example, JSArray::JSArrayVerify). |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4496 | Object* filler; |
| 4497 | // We cannot always fill with one_pointer_filler_map because objects |
| 4498 | // created from API functions expect their internal fields to be initialized |
| 4499 | // with undefined_value. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4500 | // Pre-allocated fields need to be initialized with undefined_value as well |
| 4501 | // so that object accesses before the constructor completes (e.g. in the |
| 4502 | // debugger) will not cause a crash. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4503 | if (map->constructor()->IsJSFunction() && |
| 4504 | JSFunction::cast(map->constructor())->shared()-> |
| 4505 | IsInobjectSlackTrackingInProgress()) { |
| 4506 | // We might want to shrink the object later. |
| 4507 | ASSERT(obj->GetInternalFieldCount() == 0); |
| 4508 | filler = Heap::one_pointer_filler_map(); |
| 4509 | } else { |
| 4510 | filler = Heap::undefined_value(); |
| 4511 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4512 | obj->InitializeBody(map, Heap::undefined_value(), filler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4516 | MaybeObject* Heap::AllocateJSObjectFromMap( |
| 4517 | Map* map, PretenureFlag pretenure, bool allocate_properties) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4518 | // JSFunctions should be allocated using AllocateFunction to be |
| 4519 | // properly initialized. |
| 4520 | ASSERT(map->instance_type() != JS_FUNCTION_TYPE); |
| 4521 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4522 | // Both types of global objects should be allocated using |
| 4523 | // AllocateGlobalObject to be properly initialized. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4524 | ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); |
| 4525 | ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); |
| 4526 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4527 | // Allocate the backing storage for the properties. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4528 | FixedArray* properties; |
| 4529 | if (allocate_properties) { |
| 4530 | int prop_size = map->InitialPropertiesLength(); |
| 4531 | ASSERT(prop_size >= 0); |
| 4532 | { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, pretenure); |
| 4533 | if (!maybe_properties->To(&properties)) return maybe_properties; |
| 4534 | } |
| 4535 | } else { |
| 4536 | properties = empty_fixed_array(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4537 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4538 | |
| 4539 | // Allocate the JSObject. |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 4540 | int size = map->instance_size(); |
| 4541 | AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4542 | Object* obj; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4543 | MaybeObject* maybe_obj = Allocate(map, space); |
| 4544 | if (!maybe_obj->To(&obj)) return maybe_obj; |
| 4545 | |
| 4546 | // Initialize the JSObject. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4547 | InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 4548 | ASSERT(JSObject::cast(obj)->HasFastElements() || |
| 4549 | JSObject::cast(obj)->HasExternalArrayElements()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4550 | return obj; |
| 4551 | } |
| 4552 | |
| 4553 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4554 | MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite( |
| 4555 | Map* map, Handle<AllocationSite> allocation_site) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4556 | // JSFunctions should be allocated using AllocateFunction to be |
| 4557 | // properly initialized. |
| 4558 | ASSERT(map->instance_type() != JS_FUNCTION_TYPE); |
| 4559 | |
| 4560 | // Both types of global objects should be allocated using |
| 4561 | // AllocateGlobalObject to be properly initialized. |
| 4562 | ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); |
| 4563 | ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); |
| 4564 | |
| 4565 | // Allocate the backing storage for the properties. |
jkummerow@chromium.org | 1048047 | 2013-07-17 08:22:15 +0000 | [diff] [blame] | 4566 | int prop_size = map->InitialPropertiesLength(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4567 | ASSERT(prop_size >= 0); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4568 | FixedArray* properties; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4569 | { MaybeObject* maybe_properties = AllocateFixedArray(prop_size); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4570 | if (!maybe_properties->To(&properties)) return maybe_properties; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4571 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4572 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4573 | // Allocate the JSObject. |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 4574 | int size = map->instance_size(); |
| 4575 | AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, NOT_TENURED); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4576 | Object* obj; |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4577 | MaybeObject* maybe_obj = |
| 4578 | AllocateWithAllocationSite(map, space, allocation_site); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4579 | if (!maybe_obj->To(&obj)) return maybe_obj; |
| 4580 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4581 | // Initialize the JSObject. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4582 | InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4583 | ASSERT(JSObject::cast(obj)->HasFastElements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4584 | return obj; |
| 4585 | } |
| 4586 | |
| 4587 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4588 | MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, |
| 4589 | PretenureFlag pretenure) { |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 4590 | ASSERT(constructor->has_initial_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4591 | // Allocate the object based on the constructors initial map. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4592 | MaybeObject* result = AllocateJSObjectFromMap( |
| 4593 | constructor->initial_map(), pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4594 | #ifdef DEBUG |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4595 | // Make sure result is NOT a global object if valid. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4596 | Object* non_failure; |
| 4597 | ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); |
| 4598 | #endif |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4599 | return result; |
| 4600 | } |
| 4601 | |
| 4602 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4603 | MaybeObject* Heap::AllocateJSObjectWithAllocationSite(JSFunction* constructor, |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4604 | Handle<AllocationSite> allocation_site) { |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 4605 | ASSERT(constructor->has_initial_map()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4606 | // Allocate the object based on the constructors initial map, or the payload |
| 4607 | // advice |
| 4608 | Map* initial_map = constructor->initial_map(); |
| 4609 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 4610 | ElementsKind to_kind = allocation_site->GetElementsKind(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4611 | AllocationSiteMode mode = TRACK_ALLOCATION_SITE; |
| 4612 | if (to_kind != initial_map->elements_kind()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4613 | MaybeObject* maybe_new_map = initial_map->AsElementsKind(to_kind); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4614 | if (!maybe_new_map->To(&initial_map)) return maybe_new_map; |
| 4615 | // Possibly alter the mode, since we found an updated elements kind |
| 4616 | // in the type info cell. |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4617 | mode = AllocationSite::GetMode(to_kind); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | MaybeObject* result; |
| 4621 | if (mode == TRACK_ALLOCATION_SITE) { |
| 4622 | result = AllocateJSObjectFromMapWithAllocationSite(initial_map, |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4623 | allocation_site); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4624 | } else { |
| 4625 | result = AllocateJSObjectFromMap(initial_map, NOT_TENURED); |
| 4626 | } |
| 4627 | #ifdef DEBUG |
| 4628 | // Make sure result is NOT a global object if valid. |
| 4629 | Object* non_failure; |
| 4630 | ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); |
| 4631 | #endif |
| 4632 | return result; |
| 4633 | } |
| 4634 | |
| 4635 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4636 | MaybeObject* Heap::AllocateJSModule(Context* context, ScopeInfo* scope_info) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4637 | // Allocate a fresh map. Modules do not have a prototype. |
| 4638 | Map* map; |
| 4639 | MaybeObject* maybe_map = AllocateMap(JS_MODULE_TYPE, JSModule::kSize); |
| 4640 | if (!maybe_map->To(&map)) return maybe_map; |
| 4641 | // Allocate the object based on the map. |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4642 | JSModule* module; |
| 4643 | MaybeObject* maybe_module = AllocateJSObjectFromMap(map, TENURED); |
| 4644 | if (!maybe_module->To(&module)) return maybe_module; |
| 4645 | module->set_context(context); |
| 4646 | module->set_scope_info(scope_info); |
| 4647 | return module; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4651 | MaybeObject* Heap::AllocateJSArrayAndStorage( |
| 4652 | ElementsKind elements_kind, |
| 4653 | int length, |
| 4654 | int capacity, |
| 4655 | ArrayStorageAllocationMode mode, |
| 4656 | PretenureFlag pretenure) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4657 | MaybeObject* maybe_array = AllocateJSArray(elements_kind, pretenure); |
| 4658 | JSArray* array; |
| 4659 | if (!maybe_array->To(&array)) return maybe_array; |
| 4660 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4661 | // TODO(mvstanton): this body of code is duplicate with AllocateJSArrayStorage |
| 4662 | // for performance reasons. |
| 4663 | ASSERT(capacity >= length); |
| 4664 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4665 | if (capacity == 0) { |
| 4666 | array->set_length(Smi::FromInt(0)); |
| 4667 | array->set_elements(empty_fixed_array()); |
| 4668 | return array; |
| 4669 | } |
| 4670 | |
| 4671 | FixedArrayBase* elms; |
| 4672 | MaybeObject* maybe_elms = NULL; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4673 | if (IsFastDoubleElementsKind(elements_kind)) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4674 | if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
| 4675 | maybe_elms = AllocateUninitializedFixedDoubleArray(capacity); |
| 4676 | } else { |
| 4677 | ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| 4678 | maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity); |
| 4679 | } |
| 4680 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4681 | ASSERT(IsFastSmiOrObjectElementsKind(elements_kind)); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4682 | if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
| 4683 | maybe_elms = AllocateUninitializedFixedArray(capacity); |
| 4684 | } else { |
| 4685 | ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| 4686 | maybe_elms = AllocateFixedArrayWithHoles(capacity); |
| 4687 | } |
| 4688 | } |
| 4689 | if (!maybe_elms->To(&elms)) return maybe_elms; |
| 4690 | |
| 4691 | array->set_elements(elms); |
| 4692 | array->set_length(Smi::FromInt(length)); |
| 4693 | return array; |
| 4694 | } |
| 4695 | |
| 4696 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4697 | MaybeObject* Heap::AllocateJSArrayStorage( |
| 4698 | JSArray* array, |
| 4699 | int length, |
| 4700 | int capacity, |
| 4701 | ArrayStorageAllocationMode mode) { |
| 4702 | ASSERT(capacity >= length); |
| 4703 | |
| 4704 | if (capacity == 0) { |
| 4705 | array->set_length(Smi::FromInt(0)); |
| 4706 | array->set_elements(empty_fixed_array()); |
| 4707 | return array; |
| 4708 | } |
| 4709 | |
| 4710 | FixedArrayBase* elms; |
| 4711 | MaybeObject* maybe_elms = NULL; |
| 4712 | ElementsKind elements_kind = array->GetElementsKind(); |
| 4713 | if (IsFastDoubleElementsKind(elements_kind)) { |
| 4714 | if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
| 4715 | maybe_elms = AllocateUninitializedFixedDoubleArray(capacity); |
| 4716 | } else { |
| 4717 | ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| 4718 | maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity); |
| 4719 | } |
| 4720 | } else { |
| 4721 | ASSERT(IsFastSmiOrObjectElementsKind(elements_kind)); |
| 4722 | if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
| 4723 | maybe_elms = AllocateUninitializedFixedArray(capacity); |
| 4724 | } else { |
| 4725 | ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| 4726 | maybe_elms = AllocateFixedArrayWithHoles(capacity); |
| 4727 | } |
| 4728 | } |
| 4729 | if (!maybe_elms->To(&elms)) return maybe_elms; |
| 4730 | |
| 4731 | array->set_elements(elms); |
| 4732 | array->set_length(Smi::FromInt(length)); |
| 4733 | return array; |
| 4734 | } |
| 4735 | |
| 4736 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4737 | MaybeObject* Heap::AllocateJSArrayWithElements( |
| 4738 | FixedArrayBase* elements, |
| 4739 | ElementsKind elements_kind, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4740 | int length, |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4741 | PretenureFlag pretenure) { |
| 4742 | MaybeObject* maybe_array = AllocateJSArray(elements_kind, pretenure); |
| 4743 | JSArray* array; |
| 4744 | if (!maybe_array->To(&array)) return maybe_array; |
| 4745 | |
| 4746 | array->set_elements(elements); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4747 | array->set_length(Smi::FromInt(length)); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4748 | array->ValidateElements(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4749 | return array; |
| 4750 | } |
| 4751 | |
| 4752 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4753 | MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { |
| 4754 | // Allocate map. |
| 4755 | // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
| 4756 | // maps. Will probably depend on the identity of the handler object, too. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4757 | Map* map; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4758 | MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4759 | if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4760 | map->set_prototype(prototype); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4761 | |
| 4762 | // Allocate the proxy object. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4763 | JSProxy* result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4764 | MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4765 | if (!maybe_result->To<JSProxy>(&result)) return maybe_result; |
| 4766 | result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
| 4767 | result->set_handler(handler); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4768 | result->set_hash(undefined_value(), SKIP_WRITE_BARRIER); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4769 | return result; |
| 4770 | } |
| 4771 | |
| 4772 | |
| 4773 | MaybeObject* Heap::AllocateJSFunctionProxy(Object* handler, |
| 4774 | Object* call_trap, |
| 4775 | Object* construct_trap, |
| 4776 | Object* prototype) { |
| 4777 | // Allocate map. |
| 4778 | // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
| 4779 | // maps. Will probably depend on the identity of the handler object, too. |
| 4780 | Map* map; |
| 4781 | MaybeObject* maybe_map_obj = |
| 4782 | AllocateMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); |
| 4783 | if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
| 4784 | map->set_prototype(prototype); |
| 4785 | |
| 4786 | // Allocate the proxy object. |
| 4787 | JSFunctionProxy* result; |
| 4788 | MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 4789 | if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; |
| 4790 | result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
| 4791 | result->set_handler(handler); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4792 | result->set_hash(undefined_value(), SKIP_WRITE_BARRIER); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4793 | result->set_call_trap(call_trap); |
| 4794 | result->set_construct_trap(construct_trap); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4795 | return result; |
| 4796 | } |
| 4797 | |
| 4798 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4799 | MaybeObject* Heap::CopyJSObject(JSObject* source, AllocationSite* site) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4800 | // Never used to copy functions. If functions need to be copied we |
| 4801 | // have to be careful to clear the literals array. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4802 | SLOW_ASSERT(!source->IsJSFunction()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4803 | |
| 4804 | // Make the clone. |
| 4805 | Map* map = source->map(); |
| 4806 | int object_size = map->instance_size(); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4807 | Object* clone; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4808 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4809 | ASSERT(site == NULL || (AllocationSite::CanTrack(map->instance_type()) && |
| 4810 | map->instance_type() == JS_ARRAY_TYPE)); |
| 4811 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4812 | WriteBarrierMode wb_mode = UPDATE_WRITE_BARRIER; |
| 4813 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4814 | // If we're forced to always allocate, we use the general allocation |
| 4815 | // functions which may leave us with an object in old space. |
| 4816 | if (always_allocate()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4817 | { MaybeObject* maybe_clone = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4818 | AllocateRaw(object_size, NEW_SPACE, OLD_POINTER_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4819 | if (!maybe_clone->ToObject(&clone)) return maybe_clone; |
| 4820 | } |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4821 | Address clone_address = HeapObject::cast(clone)->address(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4822 | CopyBlock(clone_address, |
| 4823 | source->address(), |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4824 | object_size); |
| 4825 | // Update write barrier for all fields that lie beyond the header. |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4826 | RecordWrites(clone_address, |
| 4827 | JSObject::kHeaderSize, |
antonm@chromium.org | 8e5e338 | 2010-03-24 09:56:30 +0000 | [diff] [blame] | 4828 | (object_size - JSObject::kHeaderSize) / kPointerSize); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4829 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4830 | wb_mode = SKIP_WRITE_BARRIER; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4831 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4832 | { int adjusted_object_size = site != NULL |
| 4833 | ? object_size + AllocationMemento::kSize |
| 4834 | : object_size; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 4835 | MaybeObject* maybe_clone = |
| 4836 | AllocateRaw(adjusted_object_size, NEW_SPACE, NEW_SPACE); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4837 | if (!maybe_clone->ToObject(&clone)) return maybe_clone; |
| 4838 | } |
| 4839 | SLOW_ASSERT(InNewSpace(clone)); |
| 4840 | // Since we know the clone is allocated in new space, we can copy |
| 4841 | // the contents without worrying about updating the write barrier. |
| 4842 | CopyBlock(HeapObject::cast(clone)->address(), |
| 4843 | source->address(), |
| 4844 | object_size); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4845 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4846 | if (site != NULL) { |
| 4847 | AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>( |
| 4848 | reinterpret_cast<Address>(clone) + object_size); |
| 4849 | alloc_memento->set_map_no_write_barrier(allocation_memento_map()); |
| 4850 | ASSERT(site->map() == allocation_site_map()); |
| 4851 | alloc_memento->set_allocation_site(site, SKIP_WRITE_BARRIER); |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 4852 | HeapProfiler* profiler = isolate()->heap_profiler(); |
| 4853 | if (profiler->is_tracking_allocations()) { |
| 4854 | profiler->UpdateObjectSizeEvent(HeapObject::cast(clone)->address(), |
| 4855 | object_size); |
| 4856 | profiler->NewObjectEvent(alloc_memento->address(), |
| 4857 | AllocationMemento::kSize); |
| 4858 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4859 | } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4860 | } |
| 4861 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4862 | SLOW_ASSERT( |
| 4863 | JSObject::cast(clone)->GetElementsKind() == source->GetElementsKind()); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 4864 | FixedArrayBase* elements = FixedArrayBase::cast(source->elements()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4865 | FixedArray* properties = FixedArray::cast(source->properties()); |
| 4866 | // Update elements if necessary. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 4867 | if (elements->length() > 0) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4868 | Object* elem; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 4869 | { MaybeObject* maybe_elem; |
| 4870 | if (elements->map() == fixed_cow_array_map()) { |
| 4871 | maybe_elem = FixedArray::cast(elements); |
| 4872 | } else if (source->HasFastDoubleElements()) { |
| 4873 | maybe_elem = CopyFixedDoubleArray(FixedDoubleArray::cast(elements)); |
| 4874 | } else { |
| 4875 | maybe_elem = CopyFixedArray(FixedArray::cast(elements)); |
| 4876 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4877 | if (!maybe_elem->ToObject(&elem)) return maybe_elem; |
| 4878 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4879 | JSObject::cast(clone)->set_elements(FixedArrayBase::cast(elem), wb_mode); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4880 | } |
| 4881 | // Update properties if necessary. |
| 4882 | if (properties->length() > 0) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4883 | Object* prop; |
| 4884 | { MaybeObject* maybe_prop = CopyFixedArray(properties); |
| 4885 | if (!maybe_prop->ToObject(&prop)) return maybe_prop; |
| 4886 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4887 | JSObject::cast(clone)->set_properties(FixedArray::cast(prop), wb_mode); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4888 | } |
| 4889 | // Return the new clone. |
| 4890 | return clone; |
| 4891 | } |
| 4892 | |
| 4893 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4894 | MaybeObject* Heap::ReinitializeJSReceiver( |
| 4895 | JSReceiver* object, InstanceType type, int size) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4896 | ASSERT(type >= FIRST_JS_OBJECT_TYPE); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4897 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4898 | // Allocate fresh map. |
| 4899 | // TODO(rossberg): Once we optimize proxies, cache these maps. |
| 4900 | Map* map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4901 | MaybeObject* maybe = AllocateMap(type, size); |
| 4902 | if (!maybe->To<Map>(&map)) return maybe; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4903 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4904 | // Check that the receiver has at least the size of the fresh object. |
| 4905 | int size_difference = object->map()->instance_size() - map->instance_size(); |
| 4906 | ASSERT(size_difference >= 0); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4907 | |
| 4908 | map->set_prototype(object->map()->prototype()); |
| 4909 | |
| 4910 | // Allocate the backing storage for the properties. |
| 4911 | int prop_size = map->unused_property_fields() - map->inobject_properties(); |
| 4912 | Object* properties; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4913 | maybe = AllocateFixedArray(prop_size, TENURED); |
| 4914 | if (!maybe->ToObject(&properties)) return maybe; |
| 4915 | |
| 4916 | // Functions require some allocation, which might fail here. |
| 4917 | SharedFunctionInfo* shared = NULL; |
| 4918 | if (type == JS_FUNCTION_TYPE) { |
| 4919 | String* name; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4920 | maybe = |
| 4921 | InternalizeOneByteString(STATIC_ASCII_VECTOR("<freezing call trap>")); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4922 | if (!maybe->To<String>(&name)) return maybe; |
| 4923 | maybe = AllocateSharedFunctionInfo(name); |
| 4924 | if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4927 | // Because of possible retries of this function after failure, |
| 4928 | // we must NOT fail after this point, where we have changed the type! |
| 4929 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4930 | // Reset the map for the object. |
| 4931 | object->set_map(map); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4932 | JSObject* jsobj = JSObject::cast(object); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4933 | |
| 4934 | // Reinitialize the object from the constructor map. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4935 | InitializeJSObjectFromMap(jsobj, FixedArray::cast(properties), map); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4936 | |
| 4937 | // Functions require some minimal initialization. |
| 4938 | if (type == JS_FUNCTION_TYPE) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4939 | map->set_function_with_prototype(true); |
| 4940 | InitializeFunction(JSFunction::cast(object), shared, the_hole_value()); |
| 4941 | JSFunction::cast(object)->set_context( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4942 | isolate()->context()->native_context()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | // Put in filler if the new object is smaller than the old. |
| 4946 | if (size_difference > 0) { |
| 4947 | CreateFillerObjectAt( |
| 4948 | object->address() + map->instance_size(), size_difference); |
| 4949 | } |
| 4950 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4951 | return object; |
| 4952 | } |
| 4953 | |
| 4954 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4955 | MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, |
| 4956 | JSGlobalProxy* object) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4957 | ASSERT(constructor->has_initial_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4958 | Map* map = constructor->initial_map(); |
| 4959 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4960 | // Check that the already allocated object has the same size and type as |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4961 | // objects allocated using the constructor. |
| 4962 | ASSERT(map->instance_size() == object->map()->instance_size()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4963 | ASSERT(map->instance_type() == object->map()->instance_type()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4964 | |
| 4965 | // Allocate the backing storage for the properties. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4966 | int prop_size = map->unused_property_fields() - map->inobject_properties(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4967 | Object* properties; |
| 4968 | { MaybeObject* maybe_properties = AllocateFixedArray(prop_size, TENURED); |
| 4969 | if (!maybe_properties->ToObject(&properties)) return maybe_properties; |
| 4970 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4971 | |
| 4972 | // Reset the map for the object. |
| 4973 | object->set_map(constructor->initial_map()); |
| 4974 | |
| 4975 | // Reinitialize the object from the constructor map. |
| 4976 | InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); |
| 4977 | return object; |
| 4978 | } |
| 4979 | |
| 4980 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4981 | MaybeObject* Heap::AllocateStringFromOneByte(Vector<const uint8_t> string, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4982 | PretenureFlag pretenure) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4983 | int length = string.length(); |
| 4984 | if (length == 1) { |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 4985 | return Heap::LookupSingleCharacterStringFromCode(string[0]); |
| 4986 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4987 | Object* result; |
| 4988 | { MaybeObject* maybe_result = |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4989 | AllocateRawOneByteString(string.length(), pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4990 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4991 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4992 | |
| 4993 | // Copy the characters into the new object. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4994 | CopyChars(SeqOneByteString::cast(result)->GetChars(), |
| 4995 | string.start(), |
| 4996 | length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4997 | return result; |
| 4998 | } |
| 4999 | |
| 5000 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 5001 | MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5002 | int non_ascii_start, |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 5003 | PretenureFlag pretenure) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5004 | // Continue counting the number of characters in the UTF-8 string, starting |
| 5005 | // from the first non-ascii character or word. |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5006 | Access<UnicodeCache::Utf8Decoder> |
| 5007 | decoder(isolate_->unicode_cache()->utf8_decoder()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5008 | decoder->Reset(string.start() + non_ascii_start, |
| 5009 | string.length() - non_ascii_start); |
| 5010 | int utf16_length = decoder->Utf16Length(); |
| 5011 | ASSERT(utf16_length > 0); |
| 5012 | // Allocate string. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5013 | Object* result; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5014 | { |
| 5015 | int chars = non_ascii_start + utf16_length; |
| 5016 | MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5017 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5018 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5019 | // Convert and copy the characters into the new object. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5020 | SeqTwoByteString* twobyte = SeqTwoByteString::cast(result); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5021 | // Copy ascii portion. |
| 5022 | uint16_t* data = twobyte->GetChars(); |
| 5023 | if (non_ascii_start != 0) { |
| 5024 | const char* ascii_data = string.start(); |
| 5025 | for (int i = 0; i < non_ascii_start; i++) { |
| 5026 | *data++ = *ascii_data++; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 5027 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5028 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5029 | // Now write the remainder. |
| 5030 | decoder->WriteUtf16(data, utf16_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5031 | return result; |
| 5032 | } |
| 5033 | |
| 5034 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5035 | MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, |
| 5036 | PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5037 | // Check if the string is an ASCII string. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5038 | Object* result; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5039 | int length = string.length(); |
| 5040 | const uc16* start = string.start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5041 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5042 | if (String::IsOneByte(start, length)) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5043 | MaybeObject* maybe_result = AllocateRawOneByteString(length, pretenure); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5044 | if (!maybe_result->ToObject(&result)) return maybe_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5045 | CopyChars(SeqOneByteString::cast(result)->GetChars(), start, length); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5046 | } else { // It's not a one byte string. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5047 | MaybeObject* maybe_result = AllocateRawTwoByteString(length, pretenure); |
| 5048 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5049 | CopyChars(SeqTwoByteString::cast(result)->GetChars(), start, length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5050 | } |
| 5051 | return result; |
| 5052 | } |
| 5053 | |
| 5054 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5055 | Map* Heap::InternalizedStringMapForString(String* string) { |
| 5056 | // If the string is in new space it cannot be used as internalized. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5057 | if (InNewSpace(string)) return NULL; |
| 5058 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5059 | // Find the corresponding internalized string map for strings. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5060 | switch (string->map()->instance_type()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5061 | case STRING_TYPE: return internalized_string_map(); |
| 5062 | case ASCII_STRING_TYPE: return ascii_internalized_string_map(); |
| 5063 | case CONS_STRING_TYPE: return cons_internalized_string_map(); |
| 5064 | case CONS_ASCII_STRING_TYPE: return cons_ascii_internalized_string_map(); |
| 5065 | case EXTERNAL_STRING_TYPE: return external_internalized_string_map(); |
| 5066 | case EXTERNAL_ASCII_STRING_TYPE: |
| 5067 | return external_ascii_internalized_string_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5068 | case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE: |
| 5069 | return external_internalized_string_with_one_byte_data_map(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5070 | case SHORT_EXTERNAL_STRING_TYPE: |
| 5071 | return short_external_internalized_string_map(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5072 | case SHORT_EXTERNAL_ASCII_STRING_TYPE: |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5073 | return short_external_ascii_internalized_string_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5074 | case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE: |
| 5075 | return short_external_internalized_string_with_one_byte_data_map(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5076 | default: return NULL; // No match found. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5077 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5081 | static inline void WriteOneByteData(Vector<const char> vector, |
| 5082 | uint8_t* chars, |
| 5083 | int len) { |
| 5084 | // Only works for ascii. |
| 5085 | ASSERT(vector.length() == len); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5086 | OS::MemCopy(chars, vector.start(), len); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5087 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5088 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5089 | static inline void WriteTwoByteData(Vector<const char> vector, |
| 5090 | uint16_t* chars, |
| 5091 | int len) { |
| 5092 | const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start()); |
| 5093 | unsigned stream_length = vector.length(); |
| 5094 | while (stream_length != 0) { |
| 5095 | unsigned consumed = 0; |
| 5096 | uint32_t c = unibrow::Utf8::ValueOf(stream, stream_length, &consumed); |
| 5097 | ASSERT(c != unibrow::Utf8::kBadChar); |
| 5098 | ASSERT(consumed <= stream_length); |
| 5099 | stream_length -= consumed; |
| 5100 | stream += consumed; |
| 5101 | if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 5102 | len -= 2; |
| 5103 | if (len < 0) break; |
| 5104 | *chars++ = unibrow::Utf16::LeadSurrogate(c); |
| 5105 | *chars++ = unibrow::Utf16::TrailSurrogate(c); |
| 5106 | } else { |
| 5107 | len -= 1; |
| 5108 | if (len < 0) break; |
| 5109 | *chars++ = c; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5110 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5111 | } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5112 | ASSERT(stream_length == 0); |
| 5113 | ASSERT(len == 0); |
| 5114 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5115 | |
| 5116 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5117 | static inline void WriteOneByteData(String* s, uint8_t* chars, int len) { |
| 5118 | ASSERT(s->length() == len); |
| 5119 | String::WriteToFlat(s, chars, 0, len); |
| 5120 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5121 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 5122 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5123 | static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) { |
| 5124 | ASSERT(s->length() == len); |
| 5125 | String::WriteToFlat(s, chars, 0, len); |
| 5126 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5127 | |
| 5128 | |
| 5129 | template<bool is_one_byte, typename T> |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5130 | MaybeObject* Heap::AllocateInternalizedStringImpl( |
| 5131 | T t, int chars, uint32_t hash_field) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5132 | ASSERT(chars >= 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5133 | // Compute map and object size. |
| 5134 | int size; |
| 5135 | Map* map; |
| 5136 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5137 | if (is_one_byte) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5138 | if (chars > SeqOneByteString::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5139 | return Failure::OutOfMemoryException(0x9); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5140 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5141 | map = ascii_internalized_string_map(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5142 | size = SeqOneByteString::SizeFor(chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5143 | } else { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5144 | if (chars > SeqTwoByteString::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5145 | return Failure::OutOfMemoryException(0xa); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5146 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5147 | map = internalized_string_map(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5148 | size = SeqTwoByteString::SizeFor(chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5149 | } |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5150 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5151 | |
| 5152 | // Allocate string. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5153 | Object* result; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5154 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5155 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5156 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5157 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5158 | reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5159 | // Set length and hash fields of the allocated string. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5160 | String* answer = String::cast(result); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5161 | answer->set_length(chars); |
| 5162 | answer->set_hash_field(hash_field); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5163 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5164 | ASSERT_EQ(size, answer->Size()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5165 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5166 | if (is_one_byte) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5167 | WriteOneByteData(t, SeqOneByteString::cast(answer)->GetChars(), chars); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5168 | } else { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5169 | WriteTwoByteData(t, SeqTwoByteString::cast(answer)->GetChars(), chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5170 | } |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5171 | return answer; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5172 | } |
| 5173 | |
| 5174 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5175 | // Need explicit instantiations. |
| 5176 | template |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5177 | MaybeObject* Heap::AllocateInternalizedStringImpl<true>(String*, int, uint32_t); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5178 | template |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5179 | MaybeObject* Heap::AllocateInternalizedStringImpl<false>( |
| 5180 | String*, int, uint32_t); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5181 | template |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5182 | MaybeObject* Heap::AllocateInternalizedStringImpl<false>( |
| 5183 | Vector<const char>, int, uint32_t); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5184 | |
| 5185 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5186 | MaybeObject* Heap::AllocateRawOneByteString(int length, |
| 5187 | PretenureFlag pretenure) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5188 | if (length < 0 || length > SeqOneByteString::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5189 | return Failure::OutOfMemoryException(0xb); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5190 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5191 | int size = SeqOneByteString::SizeFor(length); |
| 5192 | ASSERT(size <= SeqOneByteString::kMaxSize); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5193 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5194 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5195 | Object* result; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5196 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5197 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5198 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5199 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5200 | // Partially initialize the object. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5201 | HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5202 | String::cast(result)->set_length(length); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5203 | String::cast(result)->set_hash_field(String::kEmptyHashField); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5204 | ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 5205 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5206 | return result; |
| 5207 | } |
| 5208 | |
| 5209 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5210 | MaybeObject* Heap::AllocateRawTwoByteString(int length, |
| 5211 | PretenureFlag pretenure) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5212 | if (length < 0 || length > SeqTwoByteString::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5213 | return Failure::OutOfMemoryException(0xc); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 5214 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5215 | int size = SeqTwoByteString::SizeFor(length); |
| 5216 | ASSERT(size <= SeqTwoByteString::kMaxSize); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5217 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5218 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5219 | Object* result; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5220 | { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5221 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5222 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5223 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5224 | // Partially initialize the object. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5225 | HeapObject::cast(result)->set_map_no_write_barrier(string_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5226 | String::cast(result)->set_length(length); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5227 | String::cast(result)->set_hash_field(String::kEmptyHashField); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5228 | ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
| 5229 | return result; |
| 5230 | } |
| 5231 | |
| 5232 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5233 | MaybeObject* Heap::AllocateJSArray( |
| 5234 | ElementsKind elements_kind, |
| 5235 | PretenureFlag pretenure) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5236 | Context* native_context = isolate()->context()->native_context(); |
| 5237 | JSFunction* array_function = native_context->array_function(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5238 | Map* map = array_function->initial_map(); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 5239 | Map* transition_map = isolate()->get_initial_js_array_map(elements_kind); |
| 5240 | if (transition_map != NULL) map = transition_map; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5241 | return AllocateJSObjectFromMap(map, pretenure); |
| 5242 | } |
| 5243 | |
| 5244 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5245 | MaybeObject* Heap::AllocateEmptyFixedArray() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5246 | int size = FixedArray::SizeFor(0); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5247 | Object* result; |
| 5248 | { MaybeObject* maybe_result = |
| 5249 | AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
| 5250 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5251 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5252 | // Initialize the object. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5253 | reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier( |
| 5254 | fixed_array_map()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5255 | reinterpret_cast<FixedArray*>(result)->set_length(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5256 | return result; |
| 5257 | } |
| 5258 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 5259 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5260 | MaybeObject* Heap::AllocateEmptyExternalArray(ExternalArrayType array_type) { |
| 5261 | return AllocateExternalArray(0, array_type, NULL, TENURED); |
| 5262 | } |
| 5263 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5264 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5265 | MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5266 | int len = src->length(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5267 | Object* obj; |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5268 | { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5269 | if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 5270 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5271 | if (InNewSpace(obj)) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5272 | HeapObject* dst = HeapObject::cast(obj); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5273 | dst->set_map_no_write_barrier(map); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5274 | CopyBlock(dst->address() + kPointerSize, |
| 5275 | src->address() + kPointerSize, |
| 5276 | FixedArray::SizeFor(len) - kPointerSize); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5277 | return obj; |
| 5278 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5279 | HeapObject::cast(obj)->set_map_no_write_barrier(map); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5280 | FixedArray* result = FixedArray::cast(obj); |
| 5281 | result->set_length(len); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5282 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5283 | // Copy the content |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5284 | DisallowHeapAllocation no_gc; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5285 | WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5286 | for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); |
| 5287 | return result; |
| 5288 | } |
| 5289 | |
| 5290 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 5291 | MaybeObject* Heap::CopyFixedDoubleArrayWithMap(FixedDoubleArray* src, |
| 5292 | Map* map) { |
| 5293 | int len = src->length(); |
| 5294 | Object* obj; |
| 5295 | { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(len, NOT_TENURED); |
| 5296 | if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 5297 | } |
| 5298 | HeapObject* dst = HeapObject::cast(obj); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5299 | dst->set_map_no_write_barrier(map); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 5300 | CopyBlock( |
| 5301 | dst->address() + FixedDoubleArray::kLengthOffset, |
| 5302 | src->address() + FixedDoubleArray::kLengthOffset, |
| 5303 | FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); |
| 5304 | return obj; |
| 5305 | } |
| 5306 | |
| 5307 | |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 5308 | MaybeObject* Heap::CopyConstantPoolArrayWithMap(ConstantPoolArray* src, |
| 5309 | Map* map) { |
| 5310 | int int64_entries = src->count_of_int64_entries(); |
| 5311 | int ptr_entries = src->count_of_ptr_entries(); |
| 5312 | int int32_entries = src->count_of_int32_entries(); |
| 5313 | Object* obj; |
| 5314 | { MaybeObject* maybe_obj = |
| 5315 | AllocateConstantPoolArray(int64_entries, ptr_entries, int32_entries); |
| 5316 | if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 5317 | } |
| 5318 | HeapObject* dst = HeapObject::cast(obj); |
| 5319 | dst->set_map_no_write_barrier(map); |
| 5320 | CopyBlock( |
| 5321 | dst->address() + ConstantPoolArray::kLengthOffset, |
| 5322 | src->address() + ConstantPoolArray::kLengthOffset, |
| 5323 | ConstantPoolArray::SizeFor(int64_entries, ptr_entries, int32_entries) |
| 5324 | - ConstantPoolArray::kLengthOffset); |
| 5325 | return obj; |
| 5326 | } |
| 5327 | |
| 5328 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5329 | MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5330 | if (length < 0 || length > FixedArray::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5331 | return Failure::OutOfMemoryException(0xe); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5332 | } |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5333 | int size = FixedArray::SizeFor(length); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5334 | AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 5335 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5336 | return AllocateRaw(size, space, OLD_POINTER_SPACE); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5340 | MaybeObject* Heap::AllocateFixedArrayWithFiller(int length, |
| 5341 | PretenureFlag pretenure, |
| 5342 | Object* filler) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5343 | ASSERT(length >= 0); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5344 | ASSERT(empty_fixed_array()->IsFixedArray()); |
| 5345 | if (length == 0) return empty_fixed_array(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5346 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5347 | ASSERT(!InNewSpace(filler)); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5348 | Object* result; |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5349 | { MaybeObject* maybe_result = AllocateRawFixedArray(length, pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5350 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5351 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5352 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5353 | HeapObject::cast(result)->set_map_no_write_barrier(fixed_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5354 | FixedArray* array = FixedArray::cast(result); |
| 5355 | array->set_length(length); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5356 | MemsetPointer(array->data_start(), filler, length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5357 | return array; |
| 5358 | } |
| 5359 | |
| 5360 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5361 | MaybeObject* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5362 | return AllocateFixedArrayWithFiller(length, pretenure, undefined_value()); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5366 | MaybeObject* Heap::AllocateFixedArrayWithHoles(int length, |
| 5367 | PretenureFlag pretenure) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5368 | return AllocateFixedArrayWithFiller(length, pretenure, the_hole_value()); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5372 | MaybeObject* Heap::AllocateUninitializedFixedArray(int length) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5373 | if (length == 0) return empty_fixed_array(); |
| 5374 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5375 | Object* obj; |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 5376 | { MaybeObject* maybe_obj = AllocateRawFixedArray(length, NOT_TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5377 | if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 5378 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5379 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5380 | reinterpret_cast<FixedArray*>(obj)->set_map_no_write_barrier( |
| 5381 | fixed_array_map()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5382 | FixedArray::cast(obj)->set_length(length); |
| 5383 | return obj; |
| 5384 | } |
| 5385 | |
| 5386 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5387 | MaybeObject* Heap::AllocateEmptyFixedDoubleArray() { |
| 5388 | int size = FixedDoubleArray::SizeFor(0); |
| 5389 | Object* result; |
| 5390 | { MaybeObject* maybe_result = |
| 5391 | AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
| 5392 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5393 | } |
| 5394 | // Initialize the object. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5395 | reinterpret_cast<FixedDoubleArray*>(result)->set_map_no_write_barrier( |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5396 | fixed_double_array_map()); |
| 5397 | reinterpret_cast<FixedDoubleArray*>(result)->set_length(0); |
| 5398 | return result; |
| 5399 | } |
| 5400 | |
| 5401 | |
| 5402 | MaybeObject* Heap::AllocateUninitializedFixedDoubleArray( |
| 5403 | int length, |
| 5404 | PretenureFlag pretenure) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5405 | if (length == 0) return empty_fixed_array(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5406 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5407 | Object* elements_object; |
| 5408 | MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); |
| 5409 | if (!maybe_obj->ToObject(&elements_object)) return maybe_obj; |
| 5410 | FixedDoubleArray* elements = |
| 5411 | reinterpret_cast<FixedDoubleArray*>(elements_object); |
| 5412 | |
| 5413 | elements->set_map_no_write_barrier(fixed_double_array_map()); |
| 5414 | elements->set_length(length); |
| 5415 | return elements; |
| 5416 | } |
| 5417 | |
| 5418 | |
| 5419 | MaybeObject* Heap::AllocateFixedDoubleArrayWithHoles( |
| 5420 | int length, |
| 5421 | PretenureFlag pretenure) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5422 | if (length == 0) return empty_fixed_array(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5423 | |
| 5424 | Object* elements_object; |
| 5425 | MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); |
| 5426 | if (!maybe_obj->ToObject(&elements_object)) return maybe_obj; |
| 5427 | FixedDoubleArray* elements = |
| 5428 | reinterpret_cast<FixedDoubleArray*>(elements_object); |
| 5429 | |
| 5430 | for (int i = 0; i < length; ++i) { |
| 5431 | elements->set_the_hole(i); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5432 | } |
| 5433 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5434 | elements->set_map_no_write_barrier(fixed_double_array_map()); |
| 5435 | elements->set_length(length); |
| 5436 | return elements; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | |
| 5440 | MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, |
| 5441 | PretenureFlag pretenure) { |
| 5442 | if (length < 0 || length > FixedDoubleArray::kMaxLength) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5443 | return Failure::OutOfMemoryException(0xf); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5444 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5445 | int size = FixedDoubleArray::SizeFor(length); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5446 | #ifndef V8_HOST_ARCH_64_BIT |
| 5447 | size += kPointerSize; |
| 5448 | #endif |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5449 | AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5450 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5451 | HeapObject* object; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5452 | { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_DATA_SPACE); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5453 | if (!maybe_object->To<HeapObject>(&object)) return maybe_object; |
| 5454 | } |
| 5455 | |
| 5456 | return EnsureDoubleAligned(this, object, size); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 5460 | MaybeObject* Heap::AllocateConstantPoolArray(int number_of_int64_entries, |
| 5461 | int number_of_ptr_entries, |
| 5462 | int number_of_int32_entries) { |
| 5463 | ASSERT(number_of_int64_entries > 0 || number_of_ptr_entries > 0 || |
| 5464 | number_of_int32_entries > 0); |
| 5465 | int size = ConstantPoolArray::SizeFor(number_of_int64_entries, |
| 5466 | number_of_ptr_entries, |
| 5467 | number_of_int32_entries); |
| 5468 | #ifndef V8_HOST_ARCH_64_BIT |
| 5469 | size += kPointerSize; |
| 5470 | #endif |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 5471 | AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED); |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 5472 | |
| 5473 | HeapObject* object; |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 5474 | { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_POINTER_SPACE); |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 5475 | if (!maybe_object->To<HeapObject>(&object)) return maybe_object; |
| 5476 | } |
| 5477 | object = EnsureDoubleAligned(this, object, size); |
| 5478 | HeapObject::cast(object)->set_map_no_write_barrier(constant_pool_array_map()); |
| 5479 | |
| 5480 | ConstantPoolArray* constant_pool = |
| 5481 | reinterpret_cast<ConstantPoolArray*>(object); |
| 5482 | constant_pool->SetEntryCounts(number_of_int64_entries, |
| 5483 | number_of_ptr_entries, |
| 5484 | number_of_int32_entries); |
| 5485 | MemsetPointer( |
| 5486 | HeapObject::RawField( |
| 5487 | constant_pool, |
| 5488 | constant_pool->OffsetOfElementAt(constant_pool->first_ptr_index())), |
| 5489 | undefined_value(), |
| 5490 | number_of_ptr_entries); |
| 5491 | return constant_pool; |
| 5492 | } |
| 5493 | |
| 5494 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5495 | MaybeObject* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { |
| 5496 | Object* result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5497 | { MaybeObject* maybe_result = AllocateFixedArray(length, pretenure); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5498 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5499 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5500 | reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier( |
| 5501 | hash_table_map()); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5502 | ASSERT(result->IsHashTable()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5503 | return result; |
| 5504 | } |
| 5505 | |
| 5506 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5507 | MaybeObject* Heap::AllocateSymbol() { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5508 | // Statically ensure that it is safe to allocate symbols in paged spaces. |
| 5509 | STATIC_ASSERT(Symbol::kSize <= Page::kNonCodeObjectAreaSize); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5510 | |
| 5511 | Object* result; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5512 | MaybeObject* maybe = |
| 5513 | AllocateRaw(Symbol::kSize, OLD_POINTER_SPACE, OLD_POINTER_SPACE); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5514 | if (!maybe->ToObject(&result)) return maybe; |
| 5515 | |
| 5516 | HeapObject::cast(result)->set_map_no_write_barrier(symbol_map()); |
| 5517 | |
| 5518 | // Generate a random hash value. |
| 5519 | int hash; |
| 5520 | int attempts = 0; |
| 5521 | do { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 5522 | hash = isolate()->random_number_generator()->NextInt() & Name::kHashBitMask; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5523 | attempts++; |
| 5524 | } while (hash == 0 && attempts < 30); |
| 5525 | if (hash == 0) hash = 1; // never return 0 |
| 5526 | |
| 5527 | Symbol::cast(result)->set_hash_field( |
| 5528 | Name::kIsNotArrayIndexMask | (hash << Name::kHashShift)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5529 | Symbol::cast(result)->set_name(undefined_value()); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 5530 | Symbol::cast(result)->set_flags(Smi::FromInt(0)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5531 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 5532 | ASSERT(!Symbol::cast(result)->is_private()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5533 | return result; |
| 5534 | } |
| 5535 | |
| 5536 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 5537 | MaybeObject* Heap::AllocatePrivateSymbol() { |
| 5538 | MaybeObject* maybe = AllocateSymbol(); |
| 5539 | Symbol* symbol; |
| 5540 | if (!maybe->To(&symbol)) return maybe; |
| 5541 | symbol->set_is_private(true); |
| 5542 | return symbol; |
| 5543 | } |
| 5544 | |
| 5545 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5546 | MaybeObject* Heap::AllocateNativeContext() { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5547 | Object* result; |
| 5548 | { MaybeObject* maybe_result = |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5549 | AllocateFixedArray(Context::NATIVE_CONTEXT_SLOTS); |
| 5550 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5551 | } |
| 5552 | Context* context = reinterpret_cast<Context*>(result); |
| 5553 | context->set_map_no_write_barrier(native_context_map()); |
| 5554 | context->set_js_array_maps(undefined_value()); |
| 5555 | ASSERT(context->IsNativeContext()); |
| 5556 | ASSERT(result->IsContext()); |
| 5557 | return result; |
| 5558 | } |
| 5559 | |
| 5560 | |
| 5561 | MaybeObject* Heap::AllocateGlobalContext(JSFunction* function, |
| 5562 | ScopeInfo* scope_info) { |
| 5563 | Object* result; |
| 5564 | { MaybeObject* maybe_result = |
| 5565 | AllocateFixedArray(scope_info->ContextLength(), TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5566 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5567 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5568 | Context* context = reinterpret_cast<Context*>(result); |
danno@chromium.org | eb83146 | 2012-08-24 11:57:08 +0000 | [diff] [blame] | 5569 | context->set_map_no_write_barrier(global_context_map()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5570 | context->set_closure(function); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5571 | context->set_previous(function->context()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5572 | context->set_extension(scope_info); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5573 | context->set_global_object(function->context()->global_object()); |
danno@chromium.org | eb83146 | 2012-08-24 11:57:08 +0000 | [diff] [blame] | 5574 | ASSERT(context->IsGlobalContext()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5575 | ASSERT(result->IsContext()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5576 | return context; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5580 | MaybeObject* Heap::AllocateModuleContext(ScopeInfo* scope_info) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5581 | Object* result; |
| 5582 | { MaybeObject* maybe_result = |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5583 | AllocateFixedArray(scope_info->ContextLength(), TENURED); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5584 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5585 | } |
| 5586 | Context* context = reinterpret_cast<Context*>(result); |
| 5587 | context->set_map_no_write_barrier(module_context_map()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5588 | // Instance link will be set later. |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5589 | context->set_extension(Smi::FromInt(0)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5590 | return context; |
| 5591 | } |
| 5592 | |
| 5593 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5594 | MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5595 | ASSERT(length >= Context::MIN_CONTEXT_SLOTS); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5596 | Object* result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5597 | { MaybeObject* maybe_result = AllocateFixedArray(length); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5598 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5599 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5600 | Context* context = reinterpret_cast<Context*>(result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5601 | context->set_map_no_write_barrier(function_context_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5602 | context->set_closure(function); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5603 | context->set_previous(function->context()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5604 | context->set_extension(Smi::FromInt(0)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5605 | context->set_global_object(function->context()->global_object()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5606 | return context; |
| 5607 | } |
| 5608 | |
| 5609 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 5610 | MaybeObject* Heap::AllocateCatchContext(JSFunction* function, |
| 5611 | Context* previous, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5612 | String* name, |
| 5613 | Object* thrown_object) { |
| 5614 | STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == Context::THROWN_OBJECT_INDEX); |
| 5615 | Object* result; |
| 5616 | { MaybeObject* maybe_result = |
| 5617 | AllocateFixedArray(Context::MIN_CONTEXT_SLOTS + 1); |
| 5618 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5619 | } |
| 5620 | Context* context = reinterpret_cast<Context*>(result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5621 | context->set_map_no_write_barrier(catch_context_map()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 5622 | context->set_closure(function); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5623 | context->set_previous(previous); |
| 5624 | context->set_extension(name); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5625 | context->set_global_object(previous->global_object()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5626 | context->set(Context::THROWN_OBJECT_INDEX, thrown_object); |
| 5627 | return context; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 5631 | MaybeObject* Heap::AllocateWithContext(JSFunction* function, |
| 5632 | Context* previous, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5633 | JSReceiver* extension) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5634 | Object* result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5635 | { MaybeObject* maybe_result = AllocateFixedArray(Context::MIN_CONTEXT_SLOTS); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5636 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5637 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5638 | Context* context = reinterpret_cast<Context*>(result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5639 | context->set_map_no_write_barrier(with_context_map()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 5640 | context->set_closure(function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5641 | context->set_previous(previous); |
| 5642 | context->set_extension(extension); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5643 | context->set_global_object(previous->global_object()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5644 | return context; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5648 | MaybeObject* Heap::AllocateBlockContext(JSFunction* function, |
| 5649 | Context* previous, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5650 | ScopeInfo* scope_info) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5651 | Object* result; |
| 5652 | { MaybeObject* maybe_result = |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5653 | AllocateFixedArrayWithHoles(scope_info->ContextLength()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5654 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5655 | } |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5656 | Context* context = reinterpret_cast<Context*>(result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5657 | context->set_map_no_write_barrier(block_context_map()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5658 | context->set_closure(function); |
| 5659 | context->set_previous(previous); |
| 5660 | context->set_extension(scope_info); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5661 | context->set_global_object(previous->global_object()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5662 | return context; |
| 5663 | } |
| 5664 | |
| 5665 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5666 | MaybeObject* Heap::AllocateScopeInfo(int length) { |
| 5667 | FixedArray* scope_info; |
| 5668 | MaybeObject* maybe_scope_info = AllocateFixedArray(length, TENURED); |
| 5669 | if (!maybe_scope_info->To(&scope_info)) return maybe_scope_info; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5670 | scope_info->set_map_no_write_barrier(scope_info_map()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5671 | return scope_info; |
| 5672 | } |
| 5673 | |
| 5674 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5675 | MaybeObject* Heap::AllocateExternal(void* value) { |
| 5676 | Foreign* foreign; |
| 5677 | { MaybeObject* maybe_result = AllocateForeign(static_cast<Address>(value)); |
| 5678 | if (!maybe_result->To(&foreign)) return maybe_result; |
| 5679 | } |
| 5680 | JSObject* external; |
| 5681 | { MaybeObject* maybe_result = AllocateJSObjectFromMap(external_map()); |
| 5682 | if (!maybe_result->To(&external)) return maybe_result; |
| 5683 | } |
| 5684 | external->SetInternalField(0, foreign); |
| 5685 | return external; |
| 5686 | } |
| 5687 | |
| 5688 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5689 | MaybeObject* Heap::AllocateStruct(InstanceType type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5690 | Map* map; |
| 5691 | switch (type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5692 | #define MAKE_CASE(NAME, Name, name) \ |
| 5693 | case NAME##_TYPE: map = name##_map(); break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5694 | STRUCT_LIST(MAKE_CASE) |
| 5695 | #undef MAKE_CASE |
| 5696 | default: |
| 5697 | UNREACHABLE(); |
| 5698 | return Failure::InternalError(); |
| 5699 | } |
| 5700 | int size = map->instance_size(); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 5701 | AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5702 | Object* result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5703 | { MaybeObject* maybe_result = Allocate(map, space); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5704 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5705 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5706 | Struct::cast(result)->InitializeBody(size); |
| 5707 | return result; |
| 5708 | } |
| 5709 | |
| 5710 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5711 | bool Heap::IsHeapIterable() { |
| 5712 | return (!old_pointer_space()->was_swept_conservatively() && |
| 5713 | !old_data_space()->was_swept_conservatively()); |
| 5714 | } |
| 5715 | |
| 5716 | |
| 5717 | void Heap::EnsureHeapIsIterable() { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5718 | ASSERT(AllowHeapAllocation::IsAllowed()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5719 | if (!IsHeapIterable()) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 5720 | CollectAllGarbage(kMakeHeapIterableMask, "Heap::EnsureHeapIsIterable"); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5721 | } |
| 5722 | ASSERT(IsHeapIterable()); |
| 5723 | } |
| 5724 | |
| 5725 | |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5726 | void Heap::AdvanceIdleIncrementalMarking(intptr_t step_size) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5727 | incremental_marking()->Step(step_size, |
| 5728 | IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5729 | |
| 5730 | if (incremental_marking()->IsComplete()) { |
| 5731 | bool uncommit = false; |
| 5732 | if (gc_count_at_last_idle_gc_ == gc_count_) { |
| 5733 | // No GC since the last full GC, the mutator is probably not active. |
| 5734 | isolate_->compilation_cache()->Clear(); |
| 5735 | uncommit = true; |
| 5736 | } |
| 5737 | CollectAllGarbage(kNoGCFlags, "idle notification: finalize incremental"); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5738 | mark_sweeps_since_idle_round_started_++; |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5739 | gc_count_at_last_idle_gc_ = gc_count_; |
| 5740 | if (uncommit) { |
| 5741 | new_space_.Shrink(); |
| 5742 | UncommitFromSpace(); |
| 5743 | } |
| 5744 | } |
| 5745 | } |
| 5746 | |
| 5747 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5748 | bool Heap::IdleNotification(int hint) { |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 5749 | // Hints greater than this value indicate that |
| 5750 | // the embedder is requesting a lot of GC work. |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 5751 | const int kMaxHint = 1000; |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5752 | const int kMinHintForIncrementalMarking = 10; |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 5753 | // Minimal hint that allows to do full GC. |
| 5754 | const int kMinHintForFullGC = 100; |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5755 | intptr_t size_factor = Min(Max(hint, 20), kMaxHint) / 4; |
| 5756 | // The size factor is in range [5..250]. The numbers here are chosen from |
| 5757 | // experiments. If you changes them, make sure to test with |
| 5758 | // chrome/performance_ui_tests --gtest_filter="GeneralMixMemoryTest.* |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5759 | intptr_t step_size = |
| 5760 | size_factor * IncrementalMarking::kAllocatedThreshold; |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5761 | |
| 5762 | if (contexts_disposed_ > 0) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 5763 | contexts_disposed_ = 0; |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5764 | int mark_sweep_time = Min(TimeMarkSweepWouldTakeInMs(), 1000); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 5765 | if (hint >= mark_sweep_time && !FLAG_expose_gc && |
| 5766 | incremental_marking()->IsStopped()) { |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5767 | HistogramTimerScope scope(isolate_->counters()->gc_context()); |
| 5768 | CollectAllGarbage(kReduceMemoryFootprintMask, |
| 5769 | "idle notification: contexts disposed"); |
| 5770 | } else { |
| 5771 | AdvanceIdleIncrementalMarking(step_size); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5772 | } |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 5773 | |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5774 | // After context disposal there is likely a lot of garbage remaining, reset |
| 5775 | // the idle notification counters in order to trigger more incremental GCs |
| 5776 | // on subsequent idle notifications. |
| 5777 | StartIdleRound(); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5778 | return false; |
| 5779 | } |
| 5780 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 5781 | if (!FLAG_incremental_marking || FLAG_expose_gc || Serializer::enabled()) { |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5782 | return IdleGlobalGC(); |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | // By doing small chunks of GC work in each IdleNotification, |
| 5786 | // perform a round of incremental GCs and after that wait until |
| 5787 | // the mutator creates enough garbage to justify a new round. |
| 5788 | // An incremental GC progresses as follows: |
| 5789 | // 1. many incremental marking steps, |
| 5790 | // 2. one old space mark-sweep-compact, |
| 5791 | // 3. many lazy sweep steps. |
| 5792 | // Use mark-sweep-compact events to count incremental GCs in a round. |
| 5793 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5794 | if (incremental_marking()->IsStopped()) { |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 5795 | if (!mark_compact_collector()->AreSweeperThreadsActivated() && |
| 5796 | !IsSweepingComplete() && |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5797 | !AdvanceSweepers(static_cast<int>(step_size))) { |
| 5798 | return false; |
| 5799 | } |
| 5800 | } |
| 5801 | |
| 5802 | if (mark_sweeps_since_idle_round_started_ >= kMaxMarkSweepsInIdleRound) { |
| 5803 | if (EnoughGarbageSinceLastIdleRound()) { |
| 5804 | StartIdleRound(); |
| 5805 | } else { |
| 5806 | return true; |
| 5807 | } |
| 5808 | } |
| 5809 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 5810 | int remaining_mark_sweeps = kMaxMarkSweepsInIdleRound - |
| 5811 | mark_sweeps_since_idle_round_started_; |
| 5812 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5813 | if (incremental_marking()->IsStopped()) { |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 5814 | // If there are no more than two GCs left in this idle round and we are |
| 5815 | // allowed to do a full GC, then make those GCs full in order to compact |
| 5816 | // the code space. |
| 5817 | // TODO(ulan): Once we enable code compaction for incremental marking, |
| 5818 | // we can get rid of this special case and always start incremental marking. |
| 5819 | if (remaining_mark_sweeps <= 2 && hint >= kMinHintForFullGC) { |
| 5820 | CollectAllGarbage(kReduceMemoryFootprintMask, |
| 5821 | "idle notification: finalize idle round"); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5822 | mark_sweeps_since_idle_round_started_++; |
| 5823 | } else if (hint > kMinHintForIncrementalMarking) { |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 5824 | incremental_marking()->Start(); |
| 5825 | } |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5826 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5827 | if (!incremental_marking()->IsStopped() && |
| 5828 | hint > kMinHintForIncrementalMarking) { |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 5829 | AdvanceIdleIncrementalMarking(step_size); |
| 5830 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5831 | |
| 5832 | if (mark_sweeps_since_idle_round_started_ >= kMaxMarkSweepsInIdleRound) { |
| 5833 | FinishIdleRound(); |
| 5834 | return true; |
| 5835 | } |
| 5836 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5837 | return false; |
| 5838 | } |
| 5839 | |
| 5840 | |
| 5841 | bool Heap::IdleGlobalGC() { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5842 | static const int kIdlesBeforeScavenge = 4; |
| 5843 | static const int kIdlesBeforeMarkSweep = 7; |
| 5844 | static const int kIdlesBeforeMarkCompact = 8; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5845 | static const int kMaxIdleCount = kIdlesBeforeMarkCompact + 1; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 5846 | static const unsigned int kGCsBetweenCleanup = 4; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5847 | |
| 5848 | if (!last_idle_notification_gc_count_init_) { |
| 5849 | last_idle_notification_gc_count_ = gc_count_; |
| 5850 | last_idle_notification_gc_count_init_ = true; |
| 5851 | } |
ager@chromium.org | 96c75b5 | 2009-08-26 09:13:16 +0000 | [diff] [blame] | 5852 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5853 | bool uncommit = true; |
ager@chromium.org | 96c75b5 | 2009-08-26 09:13:16 +0000 | [diff] [blame] | 5854 | bool finished = false; |
| 5855 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5856 | // Reset the number of idle notifications received when a number of |
| 5857 | // GCs have taken place. This allows another round of cleanup based |
| 5858 | // on idle notifications if enough work has been carried out to |
| 5859 | // provoke a number of garbage collections. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5860 | if (gc_count_ - last_idle_notification_gc_count_ < kGCsBetweenCleanup) { |
| 5861 | number_idle_notifications_ = |
| 5862 | Min(number_idle_notifications_ + 1, kMaxIdleCount); |
ager@chromium.org | 96c75b5 | 2009-08-26 09:13:16 +0000 | [diff] [blame] | 5863 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5864 | number_idle_notifications_ = 0; |
| 5865 | last_idle_notification_gc_count_ = gc_count_; |
ager@chromium.org | 96c75b5 | 2009-08-26 09:13:16 +0000 | [diff] [blame] | 5866 | } |
| 5867 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5868 | if (number_idle_notifications_ == kIdlesBeforeScavenge) { |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 5869 | CollectGarbage(NEW_SPACE, "idle notification"); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5870 | new_space_.Shrink(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5871 | last_idle_notification_gc_count_ = gc_count_; |
| 5872 | } else if (number_idle_notifications_ == kIdlesBeforeMarkSweep) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5873 | // Before doing the mark-sweep collections we clear the |
| 5874 | // compilation cache to avoid hanging on to source code and |
| 5875 | // generated code for cached functions. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5876 | isolate_->compilation_cache()->Clear(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5877 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 5878 | CollectAllGarbage(kReduceMemoryFootprintMask, "idle notification"); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5879 | new_space_.Shrink(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5880 | last_idle_notification_gc_count_ = gc_count_; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5881 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5882 | } else if (number_idle_notifications_ == kIdlesBeforeMarkCompact) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 5883 | CollectAllGarbage(kReduceMemoryFootprintMask, "idle notification"); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5884 | new_space_.Shrink(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5885 | last_idle_notification_gc_count_ = gc_count_; |
| 5886 | number_idle_notifications_ = 0; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5887 | finished = true; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5888 | } else if (number_idle_notifications_ > kIdlesBeforeMarkCompact) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5889 | // If we have received more than kIdlesBeforeMarkCompact idle |
| 5890 | // notifications we do not perform any cleanup because we don't |
| 5891 | // expect to gain much by doing so. |
| 5892 | finished = true; |
ager@chromium.org | 96c75b5 | 2009-08-26 09:13:16 +0000 | [diff] [blame] | 5893 | } |
| 5894 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5895 | if (uncommit) UncommitFromSpace(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5896 | |
ager@chromium.org | 96c75b5 | 2009-08-26 09:13:16 +0000 | [diff] [blame] | 5897 | return finished; |
| 5898 | } |
| 5899 | |
| 5900 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5901 | #ifdef DEBUG |
| 5902 | |
| 5903 | void Heap::Print() { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5904 | if (!HasBeenSetUp()) return; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 5905 | isolate()->PrintStack(stdout); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5906 | AllSpaces spaces(this); |
| 5907 | for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5908 | space->Print(); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5909 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | |
| 5913 | void Heap::ReportCodeStatistics(const char* title) { |
| 5914 | PrintF(">>>>>> Code Stats (%s) >>>>>>\n", title); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 5915 | PagedSpace::ResetCodeStatistics(isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5916 | // We do not look for code in new space, map space, or old space. If code |
| 5917 | // somehow ends up in those spaces, we would miss it here. |
| 5918 | code_space_->CollectCodeStatistics(); |
| 5919 | lo_space_->CollectCodeStatistics(); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 5920 | PagedSpace::ReportCodeStatistics(isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | |
| 5924 | // This function expects that NewSpace's allocated objects histogram is |
| 5925 | // populated (via a call to CollectStatistics or else as a side effect of a |
| 5926 | // just-completed scavenge collection). |
| 5927 | void Heap::ReportHeapStatistics(const char* title) { |
| 5928 | USE(title); |
| 5929 | PrintF(">>>>>> =============== %s (%d) =============== >>>>>>\n", |
| 5930 | title, gc_count_); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5931 | PrintF("old_generation_allocation_limit_ %" V8_PTR_PREFIX "d\n", |
| 5932 | old_generation_allocation_limit_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5933 | |
| 5934 | PrintF("\n"); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5935 | PrintF("Number of handles : %d\n", HandleScope::NumberOfHandles(isolate_)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5936 | isolate_->global_handles()->PrintStats(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5937 | PrintF("\n"); |
| 5938 | |
| 5939 | PrintF("Heap statistics : "); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5940 | isolate_->memory_allocator()->ReportStatistics(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5941 | PrintF("To space : "); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5942 | new_space_.ReportStatistics(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5943 | PrintF("Old pointer space : "); |
| 5944 | old_pointer_space_->ReportStatistics(); |
| 5945 | PrintF("Old data space : "); |
| 5946 | old_data_space_->ReportStatistics(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5947 | PrintF("Code space : "); |
| 5948 | code_space_->ReportStatistics(); |
| 5949 | PrintF("Map space : "); |
| 5950 | map_space_->ReportStatistics(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 5951 | PrintF("Cell space : "); |
| 5952 | cell_space_->ReportStatistics(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5953 | PrintF("PropertyCell space : "); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5954 | property_cell_space_->ReportStatistics(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5955 | PrintF("Large object space : "); |
| 5956 | lo_space_->ReportStatistics(); |
| 5957 | PrintF(">>>>>> ========================================= >>>>>>\n"); |
| 5958 | } |
| 5959 | |
| 5960 | #endif // DEBUG |
| 5961 | |
| 5962 | bool Heap::Contains(HeapObject* value) { |
| 5963 | return Contains(value->address()); |
| 5964 | } |
| 5965 | |
| 5966 | |
| 5967 | bool Heap::Contains(Address addr) { |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 5968 | if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(addr)) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5969 | return HasBeenSetUp() && |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5970 | (new_space_.ToSpaceContains(addr) || |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5971 | old_pointer_space_->Contains(addr) || |
| 5972 | old_data_space_->Contains(addr) || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5973 | code_space_->Contains(addr) || |
| 5974 | map_space_->Contains(addr) || |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 5975 | cell_space_->Contains(addr) || |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5976 | property_cell_space_->Contains(addr) || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5977 | lo_space_->SlowContains(addr)); |
| 5978 | } |
| 5979 | |
| 5980 | |
| 5981 | bool Heap::InSpace(HeapObject* value, AllocationSpace space) { |
| 5982 | return InSpace(value->address(), space); |
| 5983 | } |
| 5984 | |
| 5985 | |
| 5986 | bool Heap::InSpace(Address addr, AllocationSpace space) { |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 5987 | if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(addr)) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5988 | if (!HasBeenSetUp()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5989 | |
| 5990 | switch (space) { |
| 5991 | case NEW_SPACE: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5992 | return new_space_.ToSpaceContains(addr); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5993 | case OLD_POINTER_SPACE: |
| 5994 | return old_pointer_space_->Contains(addr); |
| 5995 | case OLD_DATA_SPACE: |
| 5996 | return old_data_space_->Contains(addr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5997 | case CODE_SPACE: |
| 5998 | return code_space_->Contains(addr); |
| 5999 | case MAP_SPACE: |
| 6000 | return map_space_->Contains(addr); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6001 | case CELL_SPACE: |
| 6002 | return cell_space_->Contains(addr); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6003 | case PROPERTY_CELL_SPACE: |
| 6004 | return property_cell_space_->Contains(addr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6005 | case LO_SPACE: |
| 6006 | return lo_space_->SlowContains(addr); |
| 6007 | } |
| 6008 | |
| 6009 | return false; |
| 6010 | } |
| 6011 | |
| 6012 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 6013 | #ifdef VERIFY_HEAP |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6014 | void Heap::Verify() { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 6015 | CHECK(HasBeenSetUp()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6016 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6017 | store_buffer()->Verify(); |
| 6018 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6019 | VerifyPointersVisitor visitor; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6020 | IterateRoots(&visitor, VISIT_ONLY_STRONG); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6021 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6022 | new_space_.Verify(); |
| 6023 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6024 | old_pointer_space_->Verify(&visitor); |
| 6025 | map_space_->Verify(&visitor); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6026 | |
| 6027 | VerifyPointersVisitor no_dirty_regions_visitor; |
| 6028 | old_data_space_->Verify(&no_dirty_regions_visitor); |
| 6029 | code_space_->Verify(&no_dirty_regions_visitor); |
| 6030 | cell_space_->Verify(&no_dirty_regions_visitor); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6031 | property_cell_space_->Verify(&no_dirty_regions_visitor); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6032 | |
| 6033 | lo_space_->Verify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6034 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 6035 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6036 | |
| 6037 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6038 | MaybeObject* Heap::InternalizeUtf8String(Vector<const char> string) { |
| 6039 | Object* result = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6040 | Object* new_table; |
| 6041 | { MaybeObject* maybe_new_table = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6042 | string_table()->LookupUtf8String(string, &result); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6043 | if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 6044 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6045 | // Can't use set_string_table because StringTable::cast knows that |
| 6046 | // StringTable is a singleton and checks for identity. |
| 6047 | roots_[kStringTableRootIndex] = new_table; |
| 6048 | ASSERT(result != NULL); |
| 6049 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6053 | MaybeObject* Heap::InternalizeOneByteString(Vector<const uint8_t> string) { |
| 6054 | Object* result = NULL; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 6055 | Object* new_table; |
| 6056 | { MaybeObject* maybe_new_table = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6057 | string_table()->LookupOneByteString(string, &result); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 6058 | if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 6059 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6060 | // Can't use set_string_table because StringTable::cast knows that |
| 6061 | // StringTable is a singleton and checks for identity. |
| 6062 | roots_[kStringTableRootIndex] = new_table; |
| 6063 | ASSERT(result != NULL); |
| 6064 | return result; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6068 | MaybeObject* Heap::InternalizeOneByteString(Handle<SeqOneByteString> string, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 6069 | int from, |
| 6070 | int length) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6071 | Object* result = NULL; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 6072 | Object* new_table; |
| 6073 | { MaybeObject* maybe_new_table = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6074 | string_table()->LookupSubStringOneByteString(string, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 6075 | from, |
| 6076 | length, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6077 | &result); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 6078 | if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 6079 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6080 | // Can't use set_string_table because StringTable::cast knows that |
| 6081 | // StringTable is a singleton and checks for identity. |
| 6082 | roots_[kStringTableRootIndex] = new_table; |
| 6083 | ASSERT(result != NULL); |
| 6084 | return result; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6088 | MaybeObject* Heap::InternalizeTwoByteString(Vector<const uc16> string) { |
| 6089 | Object* result = NULL; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 6090 | Object* new_table; |
| 6091 | { MaybeObject* maybe_new_table = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6092 | string_table()->LookupTwoByteString(string, &result); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 6093 | if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 6094 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6095 | // Can't use set_string_table because StringTable::cast knows that |
| 6096 | // StringTable is a singleton and checks for identity. |
| 6097 | roots_[kStringTableRootIndex] = new_table; |
| 6098 | ASSERT(result != NULL); |
| 6099 | return result; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6103 | MaybeObject* Heap::InternalizeString(String* string) { |
| 6104 | if (string->IsInternalizedString()) return string; |
| 6105 | Object* result = NULL; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6106 | Object* new_table; |
| 6107 | { MaybeObject* maybe_new_table = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6108 | string_table()->LookupString(string, &result); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6109 | if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table; |
| 6110 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6111 | // Can't use set_string_table because StringTable::cast knows that |
| 6112 | // StringTable is a singleton and checks for identity. |
| 6113 | roots_[kStringTableRootIndex] = new_table; |
| 6114 | ASSERT(result != NULL); |
| 6115 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6119 | bool Heap::InternalizeStringIfExists(String* string, String** result) { |
| 6120 | if (string->IsInternalizedString()) { |
| 6121 | *result = string; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6122 | return true; |
| 6123 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6124 | return string_table()->LookupStringIfExists(string, result); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 6127 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6128 | void Heap::ZapFromSpace() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6129 | NewSpacePageIterator it(new_space_.FromSpaceStart(), |
| 6130 | new_space_.FromSpaceEnd()); |
| 6131 | while (it.has_next()) { |
| 6132 | NewSpacePage* page = it.next(); |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 6133 | for (Address cursor = page->area_start(), limit = page->area_end(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6134 | cursor < limit; |
| 6135 | cursor += kPointerSize) { |
| 6136 | Memory::Address_at(cursor) = kFromSpaceZapValue; |
| 6137 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6138 | } |
| 6139 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6140 | |
| 6141 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 6142 | void Heap::IterateAndMarkPointersToFromSpace(Address start, |
| 6143 | Address end, |
| 6144 | ObjectSlotCallback callback) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6145 | Address slot_address = start; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6146 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6147 | // We are not collecting slots on new space objects during mutation |
| 6148 | // thus we have to scan for pointers to evacuation candidates when we |
| 6149 | // promote objects. But we should not record any slots in non-black |
| 6150 | // objects. Grey object's slots would be rescanned. |
| 6151 | // White object might not survive until the end of collection |
| 6152 | // it would be a violation of the invariant to record it's slots. |
| 6153 | bool record_slots = false; |
| 6154 | if (incremental_marking()->IsCompacting()) { |
| 6155 | MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::FromAddress(start)); |
| 6156 | record_slots = Marking::IsBlack(mark_bit); |
| 6157 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6158 | |
| 6159 | while (slot_address < end) { |
| 6160 | Object** slot = reinterpret_cast<Object**>(slot_address); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6161 | Object* object = *slot; |
| 6162 | // If the store buffer becomes overfull we mark pages as being exempt from |
| 6163 | // the store buffer. These pages are scanned to find pointers that point |
| 6164 | // to the new space. In that case we may hit newly promoted objects and |
| 6165 | // fix the pointers before the promotion queue gets to them. Thus the 'if'. |
| 6166 | if (object->IsHeapObject()) { |
| 6167 | if (Heap::InFromSpace(object)) { |
| 6168 | callback(reinterpret_cast<HeapObject**>(slot), |
| 6169 | HeapObject::cast(object)); |
| 6170 | Object* new_object = *slot; |
| 6171 | if (InNewSpace(new_object)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6172 | SLOW_ASSERT(Heap::InToSpace(new_object)); |
| 6173 | SLOW_ASSERT(new_object->IsHeapObject()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6174 | store_buffer_.EnterDirectlyIntoStoreBuffer( |
| 6175 | reinterpret_cast<Address>(slot)); |
| 6176 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6177 | SLOW_ASSERT(!MarkCompactCollector::IsOnEvacuationCandidate(new_object)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6178 | } else if (record_slots && |
| 6179 | MarkCompactCollector::IsOnEvacuationCandidate(object)) { |
| 6180 | mark_compact_collector()->RecordSlot(slot, slot, object); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6181 | } |
| 6182 | } |
| 6183 | slot_address += kPointerSize; |
| 6184 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6188 | #ifdef DEBUG |
| 6189 | typedef bool (*CheckStoreBufferFilter)(Object** addr); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6190 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6191 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6192 | bool IsAMapPointerAddress(Object** addr) { |
| 6193 | uintptr_t a = reinterpret_cast<uintptr_t>(addr); |
| 6194 | int mod = a % Map::kSize; |
| 6195 | return mod >= Map::kPointerFieldsBeginOffset && |
| 6196 | mod < Map::kPointerFieldsEndOffset; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6200 | bool EverythingsAPointer(Object** addr) { |
| 6201 | return true; |
| 6202 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6203 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6204 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6205 | static void CheckStoreBuffer(Heap* heap, |
| 6206 | Object** current, |
| 6207 | Object** limit, |
| 6208 | Object**** store_buffer_position, |
| 6209 | Object*** store_buffer_top, |
| 6210 | CheckStoreBufferFilter filter, |
| 6211 | Address special_garbage_start, |
| 6212 | Address special_garbage_end) { |
| 6213 | Map* free_space_map = heap->free_space_map(); |
| 6214 | for ( ; current < limit; current++) { |
| 6215 | Object* o = *current; |
| 6216 | Address current_address = reinterpret_cast<Address>(current); |
| 6217 | // Skip free space. |
| 6218 | if (o == free_space_map) { |
| 6219 | Address current_address = reinterpret_cast<Address>(current); |
| 6220 | FreeSpace* free_space = |
| 6221 | FreeSpace::cast(HeapObject::FromAddress(current_address)); |
| 6222 | int skip = free_space->Size(); |
| 6223 | ASSERT(current_address + skip <= reinterpret_cast<Address>(limit)); |
| 6224 | ASSERT(skip > 0); |
| 6225 | current_address += skip - kPointerSize; |
| 6226 | current = reinterpret_cast<Object**>(current_address); |
| 6227 | continue; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6228 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6229 | // Skip the current linear allocation space between top and limit which is |
| 6230 | // unmarked with the free space map, but can contain junk. |
| 6231 | if (current_address == special_garbage_start && |
| 6232 | special_garbage_end != special_garbage_start) { |
| 6233 | current_address = special_garbage_end - kPointerSize; |
| 6234 | current = reinterpret_cast<Object**>(current_address); |
| 6235 | continue; |
| 6236 | } |
| 6237 | if (!(*filter)(current)) continue; |
| 6238 | ASSERT(current_address < special_garbage_start || |
| 6239 | current_address >= special_garbage_end); |
| 6240 | ASSERT(reinterpret_cast<uintptr_t>(o) != kFreeListZapValue); |
| 6241 | // We have to check that the pointer does not point into new space |
| 6242 | // without trying to cast it to a heap object since the hash field of |
| 6243 | // a string can contain values like 1 and 3 which are tagged null |
| 6244 | // pointers. |
| 6245 | if (!heap->InNewSpace(o)) continue; |
| 6246 | while (**store_buffer_position < current && |
| 6247 | *store_buffer_position < store_buffer_top) { |
| 6248 | (*store_buffer_position)++; |
| 6249 | } |
| 6250 | if (**store_buffer_position != current || |
| 6251 | *store_buffer_position == store_buffer_top) { |
| 6252 | Object** obj_start = current; |
| 6253 | while (!(*obj_start)->IsMap()) obj_start--; |
| 6254 | UNREACHABLE(); |
| 6255 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6260 | // Check that the store buffer contains all intergenerational pointers by |
| 6261 | // scanning a page and ensuring that all pointers to young space are in the |
| 6262 | // store buffer. |
| 6263 | void Heap::OldPointerSpaceCheckStoreBuffer() { |
| 6264 | OldSpace* space = old_pointer_space(); |
| 6265 | PageIterator pages(space); |
| 6266 | |
| 6267 | store_buffer()->SortUniq(); |
| 6268 | |
| 6269 | while (pages.has_next()) { |
| 6270 | Page* page = pages.next(); |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 6271 | Object** current = reinterpret_cast<Object**>(page->area_start()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6272 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 6273 | Address end = page->area_end(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6274 | |
| 6275 | Object*** store_buffer_position = store_buffer()->Start(); |
| 6276 | Object*** store_buffer_top = store_buffer()->Top(); |
| 6277 | |
| 6278 | Object** limit = reinterpret_cast<Object**>(end); |
| 6279 | CheckStoreBuffer(this, |
| 6280 | current, |
| 6281 | limit, |
| 6282 | &store_buffer_position, |
| 6283 | store_buffer_top, |
| 6284 | &EverythingsAPointer, |
| 6285 | space->top(), |
| 6286 | space->limit()); |
| 6287 | } |
| 6288 | } |
| 6289 | |
| 6290 | |
| 6291 | void Heap::MapSpaceCheckStoreBuffer() { |
| 6292 | MapSpace* space = map_space(); |
| 6293 | PageIterator pages(space); |
| 6294 | |
| 6295 | store_buffer()->SortUniq(); |
| 6296 | |
| 6297 | while (pages.has_next()) { |
| 6298 | Page* page = pages.next(); |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 6299 | Object** current = reinterpret_cast<Object**>(page->area_start()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6300 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 6301 | Address end = page->area_end(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6302 | |
| 6303 | Object*** store_buffer_position = store_buffer()->Start(); |
| 6304 | Object*** store_buffer_top = store_buffer()->Top(); |
| 6305 | |
| 6306 | Object** limit = reinterpret_cast<Object**>(end); |
| 6307 | CheckStoreBuffer(this, |
| 6308 | current, |
| 6309 | limit, |
| 6310 | &store_buffer_position, |
| 6311 | store_buffer_top, |
| 6312 | &IsAMapPointerAddress, |
| 6313 | space->top(), |
| 6314 | space->limit()); |
| 6315 | } |
| 6316 | } |
| 6317 | |
| 6318 | |
| 6319 | void Heap::LargeObjectSpaceCheckStoreBuffer() { |
| 6320 | LargeObjectIterator it(lo_space()); |
| 6321 | for (HeapObject* object = it.Next(); object != NULL; object = it.Next()) { |
| 6322 | // We only have code, sequential strings, or fixed arrays in large |
| 6323 | // object space, and only fixed arrays can possibly contain pointers to |
| 6324 | // the young generation. |
| 6325 | if (object->IsFixedArray()) { |
| 6326 | Object*** store_buffer_position = store_buffer()->Start(); |
| 6327 | Object*** store_buffer_top = store_buffer()->Top(); |
| 6328 | Object** current = reinterpret_cast<Object**>(object->address()); |
| 6329 | Object** limit = |
| 6330 | reinterpret_cast<Object**>(object->address() + object->Size()); |
| 6331 | CheckStoreBuffer(this, |
| 6332 | current, |
| 6333 | limit, |
| 6334 | &store_buffer_position, |
| 6335 | store_buffer_top, |
| 6336 | &EverythingsAPointer, |
| 6337 | NULL, |
| 6338 | NULL); |
| 6339 | } |
| 6340 | } |
| 6341 | } |
| 6342 | #endif |
| 6343 | |
| 6344 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6345 | void Heap::IterateRoots(ObjectVisitor* v, VisitMode mode) { |
| 6346 | IterateStrongRoots(v, mode); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6347 | IterateWeakRoots(v, mode); |
| 6348 | } |
| 6349 | |
| 6350 | |
| 6351 | void Heap::IterateWeakRoots(ObjectVisitor* v, VisitMode mode) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6352 | v->VisitPointer(reinterpret_cast<Object**>(&roots_[kStringTableRootIndex])); |
| 6353 | v->Synchronize(VisitorSynchronization::kStringTable); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 6354 | if (mode != VISIT_ALL_IN_SCAVENGE && |
| 6355 | mode != VISIT_ALL_IN_SWEEP_NEWSPACE) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6356 | // Scavenge collections have special processing for this. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6357 | external_string_table_.Iterate(v); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6358 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6359 | v->Synchronize(VisitorSynchronization::kExternalStringsTable); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6360 | } |
| 6361 | |
| 6362 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6363 | void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 6364 | v->VisitPointers(&roots_[0], &roots_[kStrongRootListLength]); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6365 | v->Synchronize(VisitorSynchronization::kStrongRootList); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6366 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6367 | v->VisitPointer(BitCast<Object**>(&hidden_string_)); |
| 6368 | v->Synchronize(VisitorSynchronization::kInternalizedString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6369 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6370 | isolate_->bootstrapper()->Iterate(v); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6371 | v->Synchronize(VisitorSynchronization::kBootstrapper); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6372 | isolate_->Iterate(v); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6373 | v->Synchronize(VisitorSynchronization::kTop); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 6374 | Relocatable::Iterate(isolate_, v); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6375 | v->Synchronize(VisitorSynchronization::kRelocatable); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6376 | |
| 6377 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6378 | isolate_->debug()->Iterate(v); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 6379 | if (isolate_->deoptimizer_data() != NULL) { |
| 6380 | isolate_->deoptimizer_data()->Iterate(v); |
| 6381 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6382 | #endif |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6383 | v->Synchronize(VisitorSynchronization::kDebug); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6384 | isolate_->compilation_cache()->Iterate(v); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6385 | v->Synchronize(VisitorSynchronization::kCompilationCache); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6386 | |
| 6387 | // Iterate over local handles in handle scopes. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6388 | isolate_->handle_scope_implementer()->Iterate(v); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 6389 | isolate_->IterateDeferredHandles(v); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6390 | v->Synchronize(VisitorSynchronization::kHandleScope); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6391 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6392 | // Iterate over the builtin code objects and code stubs in the |
| 6393 | // heap. Note that it is not necessary to iterate over code objects |
| 6394 | // on scavenge collections. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6395 | if (mode != VISIT_ALL_IN_SCAVENGE) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6396 | isolate_->builtins()->IterateBuiltins(v); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6397 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6398 | v->Synchronize(VisitorSynchronization::kBuiltins); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6399 | |
| 6400 | // Iterate over global handles. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 6401 | switch (mode) { |
| 6402 | case VISIT_ONLY_STRONG: |
| 6403 | isolate_->global_handles()->IterateStrongRoots(v); |
| 6404 | break; |
| 6405 | case VISIT_ALL_IN_SCAVENGE: |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6406 | isolate_->global_handles()->IterateNewSpaceStrongAndDependentRoots(v); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 6407 | break; |
| 6408 | case VISIT_ALL_IN_SWEEP_NEWSPACE: |
| 6409 | case VISIT_ALL: |
| 6410 | isolate_->global_handles()->IterateAllRoots(v); |
| 6411 | break; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6412 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6413 | v->Synchronize(VisitorSynchronization::kGlobalHandles); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6414 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 6415 | // Iterate over eternal handles. |
| 6416 | if (mode == VISIT_ALL_IN_SCAVENGE) { |
| 6417 | isolate_->eternal_handles()->IterateNewSpaceRoots(v); |
| 6418 | } else { |
| 6419 | isolate_->eternal_handles()->IterateAllRoots(v); |
| 6420 | } |
| 6421 | v->Synchronize(VisitorSynchronization::kEternalHandles); |
| 6422 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6423 | // Iterate over pointers being held by inactive threads. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6424 | isolate_->thread_manager()->Iterate(v); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6425 | v->Synchronize(VisitorSynchronization::kThreadManager); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6426 | |
| 6427 | // Iterate over the pointers the Serialization/Deserialization code is |
| 6428 | // holding. |
| 6429 | // During garbage collection this keeps the partial snapshot cache alive. |
| 6430 | // During deserialization of the startup snapshot this creates the partial |
| 6431 | // snapshot cache and deserializes the objects it refers to. During |
| 6432 | // serialization this does nothing, since the partial snapshot cache is |
| 6433 | // empty. However the next thing we do is create the partial snapshot, |
| 6434 | // filling up the partial snapshot cache with objects it needs as we go. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 6435 | SerializerDeserializer::Iterate(isolate_, v); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6436 | // We don't do a v->Synchronize call here, because in debug mode that will |
| 6437 | // output a flag to the snapshot. However at this point the serializer and |
| 6438 | // deserializer are deliberately a little unsynchronized (see above) so the |
| 6439 | // checking of the sync flag in the snapshot would fail. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6440 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6441 | |
| 6442 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6443 | // TODO(1236194): Since the heap size is configurable on the command line |
| 6444 | // and through the API, we should gracefully handle the case that the heap |
| 6445 | // size is not big enough to fit all the initial objects. |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 6446 | bool Heap::ConfigureHeap(int max_semispace_size, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6447 | intptr_t max_old_gen_size, |
| 6448 | intptr_t max_executable_size) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6449 | if (HasBeenSetUp()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6450 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 6451 | if (FLAG_stress_compaction) { |
| 6452 | // This will cause more frequent GCs when stressing. |
| 6453 | max_semispace_size_ = Page::kPageSize; |
| 6454 | } |
| 6455 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6456 | if (max_semispace_size > 0) { |
| 6457 | if (max_semispace_size < Page::kPageSize) { |
| 6458 | max_semispace_size = Page::kPageSize; |
| 6459 | if (FLAG_trace_gc) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 6460 | PrintPID("Max semispace size cannot be less than %dkbytes\n", |
| 6461 | Page::kPageSize >> 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6462 | } |
| 6463 | } |
| 6464 | max_semispace_size_ = max_semispace_size; |
| 6465 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6466 | |
| 6467 | if (Snapshot::IsEnabled()) { |
| 6468 | // If we are using a snapshot we always reserve the default amount |
| 6469 | // of memory for each semispace because code in the snapshot has |
| 6470 | // write-barrier code that relies on the size and alignment of new |
| 6471 | // space. We therefore cannot use a larger max semispace size |
| 6472 | // than the default reserved semispace size. |
| 6473 | if (max_semispace_size_ > reserved_semispace_size_) { |
| 6474 | max_semispace_size_ = reserved_semispace_size_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6475 | if (FLAG_trace_gc) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 6476 | PrintPID("Max semispace size cannot be more than %dkbytes\n", |
| 6477 | reserved_semispace_size_ >> 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6478 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6479 | } |
| 6480 | } else { |
| 6481 | // If we are not using snapshots we reserve space for the actual |
| 6482 | // max semispace size. |
| 6483 | reserved_semispace_size_ = max_semispace_size_; |
| 6484 | } |
| 6485 | |
| 6486 | if (max_old_gen_size > 0) max_old_generation_size_ = max_old_gen_size; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 6487 | if (max_executable_size > 0) { |
| 6488 | max_executable_size_ = RoundUp(max_executable_size, Page::kPageSize); |
| 6489 | } |
| 6490 | |
| 6491 | // The max executable size must be less than or equal to the max old |
| 6492 | // generation size. |
| 6493 | if (max_executable_size_ > max_old_generation_size_) { |
| 6494 | max_executable_size_ = max_old_generation_size_; |
| 6495 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6496 | |
| 6497 | // The new space size must be a power of two to support single-bit testing |
| 6498 | // for containment. |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6499 | max_semispace_size_ = RoundUpToPowerOf2(max_semispace_size_); |
| 6500 | reserved_semispace_size_ = RoundUpToPowerOf2(reserved_semispace_size_); |
| 6501 | initial_semispace_size_ = Min(initial_semispace_size_, max_semispace_size_); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6502 | |
| 6503 | // The external allocation limit should be below 256 MB on all architectures |
| 6504 | // to avoid unnecessary low memory notifications, as that is the threshold |
| 6505 | // for some embedders. |
| 6506 | external_allocation_limit_ = 12 * max_semispace_size_; |
| 6507 | ASSERT(external_allocation_limit_ <= 256 * MB); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6508 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6509 | // The old generation is paged and needs at least one page for each space. |
| 6510 | int paged_space_count = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1; |
| 6511 | max_old_generation_size_ = Max(static_cast<intptr_t>(paged_space_count * |
| 6512 | Page::kPageSize), |
| 6513 | RoundUp(max_old_generation_size_, |
| 6514 | Page::kPageSize)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6515 | |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 6516 | // We rely on being able to allocate new arrays in paged spaces. |
| 6517 | ASSERT(MaxRegularSpaceAllocationSize() >= |
| 6518 | (JSArray::kSize + |
| 6519 | FixedArray::SizeFor(JSObject::kInitialMaxFastElementArray) + |
| 6520 | AllocationMemento::kSize)); |
| 6521 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6522 | configured_ = true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6523 | return true; |
| 6524 | } |
| 6525 | |
| 6526 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 6527 | bool Heap::ConfigureHeapDefault() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6528 | return ConfigureHeap(static_cast<intptr_t>(FLAG_max_new_space_size / 2) * KB, |
| 6529 | static_cast<intptr_t>(FLAG_max_old_space_size) * MB, |
| 6530 | static_cast<intptr_t>(FLAG_max_executable_size) * MB); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 6531 | } |
| 6532 | |
| 6533 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 6534 | void Heap::RecordStats(HeapStats* stats, bool take_snapshot) { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 6535 | *stats->start_marker = HeapStats::kStartMarker; |
| 6536 | *stats->end_marker = HeapStats::kEndMarker; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 6537 | *stats->new_space_size = new_space_.SizeAsInt(); |
| 6538 | *stats->new_space_capacity = static_cast<int>(new_space_.Capacity()); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 6539 | *stats->old_pointer_space_size = old_pointer_space_->SizeOfObjects(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6540 | *stats->old_pointer_space_capacity = old_pointer_space_->Capacity(); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 6541 | *stats->old_data_space_size = old_data_space_->SizeOfObjects(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6542 | *stats->old_data_space_capacity = old_data_space_->Capacity(); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 6543 | *stats->code_space_size = code_space_->SizeOfObjects(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6544 | *stats->code_space_capacity = code_space_->Capacity(); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 6545 | *stats->map_space_size = map_space_->SizeOfObjects(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6546 | *stats->map_space_capacity = map_space_->Capacity(); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 6547 | *stats->cell_space_size = cell_space_->SizeOfObjects(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6548 | *stats->cell_space_capacity = cell_space_->Capacity(); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6549 | *stats->property_cell_space_size = property_cell_space_->SizeOfObjects(); |
| 6550 | *stats->property_cell_space_capacity = property_cell_space_->Capacity(); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6551 | *stats->lo_space_size = lo_space_->Size(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6552 | isolate_->global_handles()->RecordStats(stats); |
| 6553 | *stats->memory_allocator_size = isolate()->memory_allocator()->Size(); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 6554 | *stats->memory_allocator_capacity = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6555 | isolate()->memory_allocator()->Size() + |
| 6556 | isolate()->memory_allocator()->Available(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6557 | *stats->os_error = OS::GetLastError(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6558 | isolate()->memory_allocator()->Available(); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 6559 | if (take_snapshot) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6560 | HeapIterator iterator(this); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 6561 | for (HeapObject* obj = iterator.next(); |
| 6562 | obj != NULL; |
| 6563 | obj = iterator.next()) { |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 6564 | InstanceType type = obj->map()->instance_type(); |
| 6565 | ASSERT(0 <= type && type <= LAST_TYPE); |
| 6566 | stats->objects_per_type[type]++; |
| 6567 | stats->size_per_type[type] += obj->Size(); |
| 6568 | } |
| 6569 | } |
ager@chromium.org | 6012123 | 2009-12-03 11:25:37 +0000 | [diff] [blame] | 6570 | } |
| 6571 | |
| 6572 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 6573 | intptr_t Heap::PromotedSpaceSizeOfObjects() { |
| 6574 | return old_pointer_space_->SizeOfObjects() |
| 6575 | + old_data_space_->SizeOfObjects() |
| 6576 | + code_space_->SizeOfObjects() |
| 6577 | + map_space_->SizeOfObjects() |
| 6578 | + cell_space_->SizeOfObjects() |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6579 | + property_cell_space_->SizeOfObjects() |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 6580 | + lo_space_->SizeOfObjects(); |
| 6581 | } |
| 6582 | |
| 6583 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6584 | intptr_t Heap::PromotedExternalMemorySize() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 6585 | if (amount_of_external_allocated_memory_ |
| 6586 | <= amount_of_external_allocated_memory_at_last_global_gc_) return 0; |
| 6587 | return amount_of_external_allocated_memory_ |
| 6588 | - amount_of_external_allocated_memory_at_last_global_gc_; |
| 6589 | } |
| 6590 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 6591 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 6592 | void Heap::EnableInlineAllocation() { |
| 6593 | ASSERT(inline_allocation_disabled_); |
| 6594 | inline_allocation_disabled_ = false; |
| 6595 | |
| 6596 | // Update inline allocation limit for new space. |
| 6597 | new_space()->UpdateInlineAllocationLimit(0); |
| 6598 | } |
| 6599 | |
| 6600 | |
| 6601 | void Heap::DisableInlineAllocation() { |
| 6602 | ASSERT(!inline_allocation_disabled_); |
| 6603 | inline_allocation_disabled_ = true; |
| 6604 | |
| 6605 | // Update inline allocation limit for new space. |
| 6606 | new_space()->UpdateInlineAllocationLimit(0); |
| 6607 | |
| 6608 | // Update inline allocation limit for old spaces. |
| 6609 | PagedSpaces spaces(this); |
| 6610 | for (PagedSpace* space = spaces.next(); |
| 6611 | space != NULL; |
| 6612 | space = spaces.next()) { |
| 6613 | space->EmptyAllocationInfo(); |
| 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 6618 | V8_DECLARE_ONCE(initialize_gc_once); |
| 6619 | |
| 6620 | static void InitializeGCOnce() { |
| 6621 | InitializeScavengingVisitorsTables(); |
| 6622 | NewSpaceScavenger::Initialize(); |
| 6623 | MarkCompactCollector::Initialize(); |
| 6624 | } |
| 6625 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6626 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6627 | bool Heap::SetUp() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6628 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6629 | allocation_timeout_ = FLAG_gc_interval; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6630 | #endif |
| 6631 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6632 | // Initialize heap spaces and initial maps and objects. Whenever something |
| 6633 | // goes wrong, just return false. The caller should check the results and |
| 6634 | // call Heap::TearDown() to release allocated memory. |
| 6635 | // |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6636 | // If the heap is not yet configured (e.g. through the API), configure it. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6637 | // Configuration is based on the flags new-space-size (really the semispace |
| 6638 | // size) and old-space-size if set or the initial values of semispace_size_ |
| 6639 | // and old_generation_size_ otherwise. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6640 | if (!configured_) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 6641 | if (!ConfigureHeapDefault()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6642 | } |
| 6643 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 6644 | CallOnce(&initialize_gc_once, &InitializeGCOnce); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6645 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 6646 | MarkMapPointersAsEncoded(false); |
| 6647 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6648 | // Set up memory allocator. |
| 6649 | if (!isolate_->memory_allocator()->SetUp(MaxReserved(), MaxExecutableSize())) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6650 | return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6651 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6652 | // Set up new space. |
| 6653 | if (!new_space_.SetUp(reserved_semispace_size_, max_semispace_size_)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6654 | return false; |
| 6655 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6656 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6657 | // Initialize old pointer space. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6658 | old_pointer_space_ = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6659 | new OldSpace(this, |
| 6660 | max_old_generation_size_, |
| 6661 | OLD_POINTER_SPACE, |
| 6662 | NOT_EXECUTABLE); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6663 | if (old_pointer_space_ == NULL) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6664 | if (!old_pointer_space_->SetUp()) return false; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6665 | |
| 6666 | // Initialize old data space. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6667 | old_data_space_ = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6668 | new OldSpace(this, |
| 6669 | max_old_generation_size_, |
| 6670 | OLD_DATA_SPACE, |
| 6671 | NOT_EXECUTABLE); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6672 | if (old_data_space_ == NULL) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6673 | if (!old_data_space_->SetUp()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6674 | |
| 6675 | // Initialize the code space, set its maximum capacity to the old |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 6676 | // generation size. It needs executable memory. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6677 | // On 64-bit platform(s), we put all code objects in a 2 GB range of |
| 6678 | // virtual address space, so that they can call each other with near calls. |
| 6679 | if (code_range_size_ > 0) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6680 | if (!isolate_->code_range()->SetUp(code_range_size_)) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6681 | return false; |
| 6682 | } |
| 6683 | } |
| 6684 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6685 | code_space_ = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6686 | new OldSpace(this, max_old_generation_size_, CODE_SPACE, EXECUTABLE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6687 | if (code_space_ == NULL) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6688 | if (!code_space_->SetUp()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6689 | |
| 6690 | // Initialize map space. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 6691 | map_space_ = new MapSpace(this, max_old_generation_size_, MAP_SPACE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6692 | if (map_space_ == NULL) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6693 | if (!map_space_->SetUp()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6694 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6695 | // Initialize simple cell space. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6696 | cell_space_ = new CellSpace(this, max_old_generation_size_, CELL_SPACE); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6697 | if (cell_space_ == NULL) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6698 | if (!cell_space_->SetUp()) return false; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6699 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6700 | // Initialize global property cell space. |
| 6701 | property_cell_space_ = new PropertyCellSpace(this, max_old_generation_size_, |
| 6702 | PROPERTY_CELL_SPACE); |
| 6703 | if (property_cell_space_ == NULL) return false; |
| 6704 | if (!property_cell_space_->SetUp()) return false; |
| 6705 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6706 | // The large object code space may contain code or data. We set the memory |
| 6707 | // to be non-executable here for safety, but this means we need to enable it |
| 6708 | // explicitly when allocating large code objects. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6709 | lo_space_ = new LargeObjectSpace(this, max_old_generation_size_, LO_SPACE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6710 | if (lo_space_ == NULL) return false; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6711 | if (!lo_space_->SetUp()) return false; |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6712 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6713 | // Set up the seed that is used to randomize the string hash function. |
| 6714 | ASSERT(hash_seed() == 0); |
| 6715 | if (FLAG_randomize_hashes) { |
| 6716 | if (FLAG_hash_seed == 0) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 6717 | int rnd = isolate()->random_number_generator()->NextInt(); |
| 6718 | set_hash_seed(Smi::FromInt(rnd & Name::kHashBitMask)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6719 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6720 | set_hash_seed(Smi::FromInt(FLAG_hash_seed)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6721 | } |
| 6722 | } |
| 6723 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6724 | LOG(isolate_, IntPtrTEvent("heap-capacity", Capacity())); |
| 6725 | LOG(isolate_, IntPtrTEvent("heap-available", Available())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6726 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6727 | store_buffer()->SetUp(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6728 | |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 6729 | if (FLAG_concurrent_recompilation) relocation_mutex_ = new Mutex; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6730 | #ifdef DEBUG |
| 6731 | relocation_mutex_locked_by_optimizer_thread_ = false; |
| 6732 | #endif // DEBUG |
| 6733 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6734 | return true; |
| 6735 | } |
| 6736 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6737 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6738 | bool Heap::CreateHeapObjects() { |
| 6739 | // Create initial maps. |
| 6740 | if (!CreateInitialMaps()) return false; |
| 6741 | if (!CreateApiObjects()) return false; |
| 6742 | |
| 6743 | // Create initial objects |
| 6744 | if (!CreateInitialObjects()) return false; |
| 6745 | |
| 6746 | native_contexts_list_ = undefined_value(); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6747 | array_buffers_list_ = undefined_value(); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6748 | allocation_sites_list_ = undefined_value(); |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 6749 | weak_object_to_code_table_ = undefined_value(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6750 | return true; |
| 6751 | } |
| 6752 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6753 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6754 | void Heap::SetStackLimits() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6755 | ASSERT(isolate_ != NULL); |
| 6756 | ASSERT(isolate_ == isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6757 | // On 64 bit machines, pointers are generally out of range of Smis. We write |
| 6758 | // something that looks like an out of range Smi to the GC. |
| 6759 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6760 | // Set up the special root array entries containing the stack limits. |
| 6761 | // These are actually addresses, but the tag makes the GC ignore it. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6762 | roots_[kStackLimitRootIndex] = |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6763 | reinterpret_cast<Object*>( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6764 | (isolate_->stack_guard()->jslimit() & ~kSmiTagMask) | kSmiTag); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6765 | roots_[kRealStackLimitRootIndex] = |
| 6766 | reinterpret_cast<Object*>( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6767 | (isolate_->stack_guard()->real_jslimit() & ~kSmiTagMask) | kSmiTag); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6768 | } |
| 6769 | |
| 6770 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6771 | void Heap::TearDown() { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 6772 | #ifdef VERIFY_HEAP |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 6773 | if (FLAG_verify_heap) { |
| 6774 | Verify(); |
| 6775 | } |
| 6776 | #endif |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 6777 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 6778 | UpdateMaximumCommitted(); |
| 6779 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6780 | if (FLAG_print_cumulative_gc_stat) { |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 6781 | PrintF("\n"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6782 | PrintF("gc_count=%d ", gc_count_); |
| 6783 | PrintF("mark_sweep_count=%d ", ms_count_); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 6784 | PrintF("max_gc_pause=%.1f ", get_max_gc_pause()); |
| 6785 | PrintF("total_gc_time=%.1f ", total_gc_time_ms_); |
| 6786 | PrintF("min_in_mutator=%.1f ", get_min_in_mutator()); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 6787 | PrintF("max_alive_after_gc=%" V8_PTR_PREFIX "d ", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6788 | get_max_alive_after_gc()); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 6789 | PrintF("total_marking_time=%.1f ", marking_time()); |
| 6790 | PrintF("total_sweeping_time=%.1f ", sweeping_time()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6791 | PrintF("\n\n"); |
| 6792 | } |
| 6793 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 6794 | if (FLAG_print_max_heap_committed) { |
| 6795 | PrintF("\n"); |
| 6796 | PrintF("maximum_committed_by_heap=%" V8_PTR_PREFIX "d ", |
| 6797 | MaximumCommittedMemory()); |
| 6798 | PrintF("maximum_committed_by_new_space=%" V8_PTR_PREFIX "d ", |
| 6799 | new_space_.MaximumCommittedMemory()); |
| 6800 | PrintF("maximum_committed_by_old_pointer_space=%" V8_PTR_PREFIX "d ", |
| 6801 | old_data_space_->MaximumCommittedMemory()); |
| 6802 | PrintF("maximum_committed_by_old_data_space=%" V8_PTR_PREFIX "d ", |
| 6803 | old_pointer_space_->MaximumCommittedMemory()); |
| 6804 | PrintF("maximum_committed_by_old_data_space=%" V8_PTR_PREFIX "d ", |
| 6805 | old_pointer_space_->MaximumCommittedMemory()); |
| 6806 | PrintF("maximum_committed_by_code_space=%" V8_PTR_PREFIX "d ", |
| 6807 | code_space_->MaximumCommittedMemory()); |
| 6808 | PrintF("maximum_committed_by_map_space=%" V8_PTR_PREFIX "d ", |
| 6809 | map_space_->MaximumCommittedMemory()); |
| 6810 | PrintF("maximum_committed_by_cell_space=%" V8_PTR_PREFIX "d ", |
| 6811 | cell_space_->MaximumCommittedMemory()); |
| 6812 | PrintF("maximum_committed_by_property_space=%" V8_PTR_PREFIX "d ", |
| 6813 | property_cell_space_->MaximumCommittedMemory()); |
| 6814 | PrintF("maximum_committed_by_lo_space=%" V8_PTR_PREFIX "d ", |
| 6815 | lo_space_->MaximumCommittedMemory()); |
| 6816 | PrintF("\n\n"); |
| 6817 | } |
| 6818 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6819 | TearDownArrayBuffers(); |
| 6820 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6821 | isolate_->global_handles()->TearDown(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6822 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6823 | external_string_table_.TearDown(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6824 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 6825 | mark_compact_collector()->TearDown(); |
| 6826 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6827 | new_space_.TearDown(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6828 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6829 | if (old_pointer_space_ != NULL) { |
| 6830 | old_pointer_space_->TearDown(); |
| 6831 | delete old_pointer_space_; |
| 6832 | old_pointer_space_ = NULL; |
| 6833 | } |
| 6834 | |
| 6835 | if (old_data_space_ != NULL) { |
| 6836 | old_data_space_->TearDown(); |
| 6837 | delete old_data_space_; |
| 6838 | old_data_space_ = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6839 | } |
| 6840 | |
| 6841 | if (code_space_ != NULL) { |
| 6842 | code_space_->TearDown(); |
| 6843 | delete code_space_; |
| 6844 | code_space_ = NULL; |
| 6845 | } |
| 6846 | |
| 6847 | if (map_space_ != NULL) { |
| 6848 | map_space_->TearDown(); |
| 6849 | delete map_space_; |
| 6850 | map_space_ = NULL; |
| 6851 | } |
| 6852 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6853 | if (cell_space_ != NULL) { |
| 6854 | cell_space_->TearDown(); |
| 6855 | delete cell_space_; |
| 6856 | cell_space_ = NULL; |
| 6857 | } |
| 6858 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6859 | if (property_cell_space_ != NULL) { |
| 6860 | property_cell_space_->TearDown(); |
| 6861 | delete property_cell_space_; |
| 6862 | property_cell_space_ = NULL; |
| 6863 | } |
| 6864 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6865 | if (lo_space_ != NULL) { |
| 6866 | lo_space_->TearDown(); |
| 6867 | delete lo_space_; |
| 6868 | lo_space_ = NULL; |
| 6869 | } |
| 6870 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6871 | store_buffer()->TearDown(); |
| 6872 | incremental_marking()->TearDown(); |
| 6873 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6874 | isolate_->memory_allocator()->TearDown(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6875 | |
| 6876 | delete relocation_mutex_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6877 | } |
| 6878 | |
| 6879 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6880 | void Heap::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback callback, |
| 6881 | GCType gc_type, |
| 6882 | bool pass_isolate) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6883 | ASSERT(callback != NULL); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6884 | GCPrologueCallbackPair pair(callback, gc_type, pass_isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6885 | ASSERT(!gc_prologue_callbacks_.Contains(pair)); |
| 6886 | return gc_prologue_callbacks_.Add(pair); |
| 6887 | } |
| 6888 | |
| 6889 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6890 | void Heap::RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6891 | ASSERT(callback != NULL); |
| 6892 | for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { |
| 6893 | if (gc_prologue_callbacks_[i].callback == callback) { |
| 6894 | gc_prologue_callbacks_.Remove(i); |
| 6895 | return; |
| 6896 | } |
| 6897 | } |
| 6898 | UNREACHABLE(); |
| 6899 | } |
| 6900 | |
| 6901 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6902 | void Heap::AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback, |
| 6903 | GCType gc_type, |
| 6904 | bool pass_isolate) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6905 | ASSERT(callback != NULL); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6906 | GCEpilogueCallbackPair pair(callback, gc_type, pass_isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6907 | ASSERT(!gc_epilogue_callbacks_.Contains(pair)); |
| 6908 | return gc_epilogue_callbacks_.Add(pair); |
| 6909 | } |
| 6910 | |
| 6911 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6912 | void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6913 | ASSERT(callback != NULL); |
| 6914 | for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { |
| 6915 | if (gc_epilogue_callbacks_[i].callback == callback) { |
| 6916 | gc_epilogue_callbacks_.Remove(i); |
| 6917 | return; |
| 6918 | } |
| 6919 | } |
| 6920 | UNREACHABLE(); |
| 6921 | } |
| 6922 | |
| 6923 | |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 6924 | MaybeObject* Heap::AddWeakObjectToCodeDependency(Object* obj, |
| 6925 | DependentCode* dep) { |
| 6926 | ASSERT(!InNewSpace(obj)); |
| 6927 | ASSERT(!InNewSpace(dep)); |
| 6928 | MaybeObject* maybe_obj = |
| 6929 | WeakHashTable::cast(weak_object_to_code_table_)->Put(obj, dep); |
| 6930 | WeakHashTable* table; |
| 6931 | if (!maybe_obj->To(&table)) return maybe_obj; |
mvstanton@chromium.org | dd6d9ee | 2013-10-11 10:35:37 +0000 | [diff] [blame] | 6932 | if (ShouldZapGarbage() && weak_object_to_code_table_ != table) { |
| 6933 | WeakHashTable::cast(weak_object_to_code_table_)->Zap(the_hole_value()); |
| 6934 | } |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 6935 | set_weak_object_to_code_table(table); |
| 6936 | ASSERT_EQ(dep, WeakHashTable::cast(weak_object_to_code_table_)->Lookup(obj)); |
| 6937 | return weak_object_to_code_table_; |
| 6938 | } |
| 6939 | |
| 6940 | |
| 6941 | DependentCode* Heap::LookupWeakObjectToCodeDependency(Object* obj) { |
| 6942 | Object* dep = WeakHashTable::cast(weak_object_to_code_table_)->Lookup(obj); |
| 6943 | if (dep->IsDependentCode()) return DependentCode::cast(dep); |
| 6944 | return DependentCode::cast(empty_fixed_array()); |
| 6945 | } |
| 6946 | |
| 6947 | |
| 6948 | void Heap::EnsureWeakObjectToCodeTable() { |
| 6949 | if (!weak_object_to_code_table()->IsHashTable()) { |
| 6950 | set_weak_object_to_code_table(*isolate()->factory()->NewWeakHashTable(16)); |
| 6951 | } |
| 6952 | } |
| 6953 | |
| 6954 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6955 | #ifdef DEBUG |
| 6956 | |
| 6957 | class PrintHandleVisitor: public ObjectVisitor { |
| 6958 | public: |
| 6959 | void VisitPointers(Object** start, Object** end) { |
| 6960 | for (Object** p = start; p < end; p++) |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 6961 | PrintF(" handle %p to %p\n", |
| 6962 | reinterpret_cast<void*>(p), |
| 6963 | reinterpret_cast<void*>(*p)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6964 | } |
| 6965 | }; |
| 6966 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6967 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6968 | void Heap::PrintHandles() { |
| 6969 | PrintF("Handles:\n"); |
| 6970 | PrintHandleVisitor v; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6971 | isolate_->handle_scope_implementer()->Iterate(&v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | #endif |
| 6975 | |
| 6976 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6977 | Space* AllSpaces::next() { |
| 6978 | switch (counter_++) { |
| 6979 | case NEW_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6980 | return heap_->new_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6981 | case OLD_POINTER_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6982 | return heap_->old_pointer_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6983 | case OLD_DATA_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6984 | return heap_->old_data_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6985 | case CODE_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6986 | return heap_->code_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6987 | case MAP_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6988 | return heap_->map_space(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6989 | case CELL_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6990 | return heap_->cell_space(); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 6991 | case PROPERTY_CELL_SPACE: |
| 6992 | return heap_->property_cell_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6993 | case LO_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6994 | return heap_->lo_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6995 | default: |
| 6996 | return NULL; |
| 6997 | } |
| 6998 | } |
| 6999 | |
| 7000 | |
| 7001 | PagedSpace* PagedSpaces::next() { |
| 7002 | switch (counter_++) { |
| 7003 | case OLD_POINTER_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7004 | return heap_->old_pointer_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7005 | case OLD_DATA_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7006 | return heap_->old_data_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7007 | case CODE_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7008 | return heap_->code_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7009 | case MAP_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7010 | return heap_->map_space(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 7011 | case CELL_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7012 | return heap_->cell_space(); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7013 | case PROPERTY_CELL_SPACE: |
| 7014 | return heap_->property_cell_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7015 | default: |
| 7016 | return NULL; |
| 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | |
| 7021 | |
| 7022 | OldSpace* OldSpaces::next() { |
| 7023 | switch (counter_++) { |
| 7024 | case OLD_POINTER_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7025 | return heap_->old_pointer_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7026 | case OLD_DATA_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7027 | return heap_->old_data_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7028 | case CODE_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7029 | return heap_->code_space(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7030 | default: |
| 7031 | return NULL; |
| 7032 | } |
| 7033 | } |
| 7034 | |
| 7035 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7036 | SpaceIterator::SpaceIterator(Heap* heap) |
| 7037 | : heap_(heap), |
| 7038 | current_space_(FIRST_SPACE), |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7039 | iterator_(NULL), |
| 7040 | size_func_(NULL) { |
| 7041 | } |
| 7042 | |
| 7043 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7044 | SpaceIterator::SpaceIterator(Heap* heap, HeapObjectCallback size_func) |
| 7045 | : heap_(heap), |
| 7046 | current_space_(FIRST_SPACE), |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7047 | iterator_(NULL), |
| 7048 | size_func_(size_func) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | |
| 7052 | SpaceIterator::~SpaceIterator() { |
| 7053 | // Delete active iterator if any. |
| 7054 | delete iterator_; |
| 7055 | } |
| 7056 | |
| 7057 | |
| 7058 | bool SpaceIterator::has_next() { |
| 7059 | // Iterate until no more spaces. |
| 7060 | return current_space_ != LAST_SPACE; |
| 7061 | } |
| 7062 | |
| 7063 | |
| 7064 | ObjectIterator* SpaceIterator::next() { |
| 7065 | if (iterator_ != NULL) { |
| 7066 | delete iterator_; |
| 7067 | iterator_ = NULL; |
| 7068 | // Move to the next space |
| 7069 | current_space_++; |
| 7070 | if (current_space_ > LAST_SPACE) { |
| 7071 | return NULL; |
| 7072 | } |
| 7073 | } |
| 7074 | |
| 7075 | // Return iterator for the new current space. |
| 7076 | return CreateIterator(); |
| 7077 | } |
| 7078 | |
| 7079 | |
| 7080 | // Create an iterator for the space to iterate. |
| 7081 | ObjectIterator* SpaceIterator::CreateIterator() { |
| 7082 | ASSERT(iterator_ == NULL); |
| 7083 | |
| 7084 | switch (current_space_) { |
| 7085 | case NEW_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7086 | iterator_ = new SemiSpaceIterator(heap_->new_space(), size_func_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7087 | break; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7088 | case OLD_POINTER_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7089 | iterator_ = |
| 7090 | new HeapObjectIterator(heap_->old_pointer_space(), size_func_); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 7091 | break; |
| 7092 | case OLD_DATA_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7093 | iterator_ = new HeapObjectIterator(heap_->old_data_space(), size_func_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7094 | break; |
| 7095 | case CODE_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7096 | iterator_ = new HeapObjectIterator(heap_->code_space(), size_func_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7097 | break; |
| 7098 | case MAP_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7099 | iterator_ = new HeapObjectIterator(heap_->map_space(), size_func_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7100 | break; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 7101 | case CELL_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7102 | iterator_ = new HeapObjectIterator(heap_->cell_space(), size_func_); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 7103 | break; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7104 | case PROPERTY_CELL_SPACE: |
| 7105 | iterator_ = new HeapObjectIterator(heap_->property_cell_space(), |
| 7106 | size_func_); |
| 7107 | break; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7108 | case LO_SPACE: |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7109 | iterator_ = new LargeObjectIterator(heap_->lo_space(), size_func_); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7110 | break; |
| 7111 | } |
| 7112 | |
| 7113 | // Return the newly allocated iterator; |
| 7114 | ASSERT(iterator_ != NULL); |
| 7115 | return iterator_; |
| 7116 | } |
| 7117 | |
| 7118 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7119 | class HeapObjectsFilter { |
| 7120 | public: |
| 7121 | virtual ~HeapObjectsFilter() {} |
| 7122 | virtual bool SkipObject(HeapObject* object) = 0; |
| 7123 | }; |
| 7124 | |
| 7125 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7126 | class UnreachableObjectsFilter : public HeapObjectsFilter { |
| 7127 | public: |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7128 | explicit UnreachableObjectsFilter(Heap* heap) : heap_(heap) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7129 | MarkReachableObjects(); |
| 7130 | } |
| 7131 | |
| 7132 | ~UnreachableObjectsFilter() { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7133 | heap_->mark_compact_collector()->ClearMarkbits(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | bool SkipObject(HeapObject* object) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7137 | MarkBit mark_bit = Marking::MarkBitFrom(object); |
| 7138 | return !mark_bit.Get(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7139 | } |
| 7140 | |
| 7141 | private: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7142 | class MarkingVisitor : public ObjectVisitor { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7143 | public: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7144 | MarkingVisitor() : marking_stack_(10) {} |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7145 | |
| 7146 | void VisitPointers(Object** start, Object** end) { |
| 7147 | for (Object** p = start; p < end; p++) { |
| 7148 | if (!(*p)->IsHeapObject()) continue; |
| 7149 | HeapObject* obj = HeapObject::cast(*p); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7150 | MarkBit mark_bit = Marking::MarkBitFrom(obj); |
| 7151 | if (!mark_bit.Get()) { |
| 7152 | mark_bit.Set(); |
| 7153 | marking_stack_.Add(obj); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7154 | } |
| 7155 | } |
| 7156 | } |
| 7157 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7158 | void TransitiveClosure() { |
| 7159 | while (!marking_stack_.is_empty()) { |
| 7160 | HeapObject* obj = marking_stack_.RemoveLast(); |
| 7161 | obj->Iterate(this); |
| 7162 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7163 | } |
| 7164 | |
| 7165 | private: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7166 | List<HeapObject*> marking_stack_; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7167 | }; |
| 7168 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7169 | void MarkReachableObjects() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7170 | MarkingVisitor visitor; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7171 | heap_->IterateRoots(&visitor, VISIT_ALL); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7172 | visitor.TransitiveClosure(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7173 | } |
| 7174 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7175 | Heap* heap_; |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 7176 | DisallowHeapAllocation no_allocation_; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7177 | }; |
| 7178 | |
| 7179 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7180 | HeapIterator::HeapIterator(Heap* heap) |
| 7181 | : heap_(heap), |
| 7182 | filtering_(HeapIterator::kNoFiltering), |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7183 | filter_(NULL) { |
| 7184 | Init(); |
| 7185 | } |
| 7186 | |
| 7187 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7188 | HeapIterator::HeapIterator(Heap* heap, |
| 7189 | HeapIterator::HeapObjectsFiltering filtering) |
| 7190 | : heap_(heap), |
| 7191 | filtering_(filtering), |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7192 | filter_(NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7193 | Init(); |
| 7194 | } |
| 7195 | |
| 7196 | |
| 7197 | HeapIterator::~HeapIterator() { |
| 7198 | Shutdown(); |
| 7199 | } |
| 7200 | |
| 7201 | |
| 7202 | void HeapIterator::Init() { |
| 7203 | // Start the iteration. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7204 | space_iterator_ = new SpaceIterator(heap_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7205 | switch (filtering_) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7206 | case kFilterUnreachable: |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7207 | filter_ = new UnreachableObjectsFilter(heap_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7208 | break; |
| 7209 | default: |
| 7210 | break; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7211 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7212 | object_iterator_ = space_iterator_->next(); |
| 7213 | } |
| 7214 | |
| 7215 | |
| 7216 | void HeapIterator::Shutdown() { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7217 | #ifdef DEBUG |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7218 | // Assert that in filtering mode we have iterated through all |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7219 | // objects. Otherwise, heap will be left in an inconsistent state. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7220 | if (filtering_ != kNoFiltering) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7221 | ASSERT(object_iterator_ == NULL); |
| 7222 | } |
| 7223 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7224 | // Make sure the last iterator is deallocated. |
| 7225 | delete space_iterator_; |
| 7226 | space_iterator_ = NULL; |
| 7227 | object_iterator_ = NULL; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7228 | delete filter_; |
| 7229 | filter_ = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7230 | } |
| 7231 | |
| 7232 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7233 | HeapObject* HeapIterator::next() { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7234 | if (filter_ == NULL) return NextObject(); |
| 7235 | |
| 7236 | HeapObject* obj = NextObject(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7237 | while (obj != NULL && filter_->SkipObject(obj)) obj = NextObject(); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 7238 | return obj; |
| 7239 | } |
| 7240 | |
| 7241 | |
| 7242 | HeapObject* HeapIterator::NextObject() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7243 | // No iterator means we are done. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7244 | if (object_iterator_ == NULL) return NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7245 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7246 | if (HeapObject* obj = object_iterator_->next_object()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7247 | // If the current iterator has more objects we are fine. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7248 | return obj; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7249 | } else { |
| 7250 | // Go though the spaces looking for one that has objects. |
| 7251 | while (space_iterator_->has_next()) { |
| 7252 | object_iterator_ = space_iterator_->next(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7253 | if (HeapObject* obj = object_iterator_->next_object()) { |
| 7254 | return obj; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7255 | } |
| 7256 | } |
| 7257 | } |
| 7258 | // Done with the last space. |
| 7259 | object_iterator_ = NULL; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7260 | return NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
| 7263 | |
| 7264 | void HeapIterator::reset() { |
| 7265 | // Restart the iterator. |
| 7266 | Shutdown(); |
| 7267 | Init(); |
| 7268 | } |
| 7269 | |
| 7270 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 7271 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7272 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 7273 | Object* const PathTracer::kAnyGlobalObject = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7274 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7275 | class PathTracer::MarkVisitor: public ObjectVisitor { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7276 | public: |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7277 | explicit MarkVisitor(PathTracer* tracer) : tracer_(tracer) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7278 | void VisitPointers(Object** start, Object** end) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7279 | // Scan all HeapObject pointers in [start, end) |
| 7280 | for (Object** p = start; !tracer_->found() && (p < end); p++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7281 | if ((*p)->IsHeapObject()) |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7282 | tracer_->MarkRecursively(p, this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7283 | } |
| 7284 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7285 | |
| 7286 | private: |
| 7287 | PathTracer* tracer_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7288 | }; |
| 7289 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7290 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7291 | class PathTracer::UnmarkVisitor: public ObjectVisitor { |
| 7292 | public: |
| 7293 | explicit UnmarkVisitor(PathTracer* tracer) : tracer_(tracer) {} |
| 7294 | void VisitPointers(Object** start, Object** end) { |
| 7295 | // Scan all HeapObject pointers in [start, end) |
| 7296 | for (Object** p = start; p < end; p++) { |
| 7297 | if ((*p)->IsHeapObject()) |
| 7298 | tracer_->UnmarkRecursively(p, this); |
| 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | private: |
| 7303 | PathTracer* tracer_; |
| 7304 | }; |
| 7305 | |
| 7306 | |
| 7307 | void PathTracer::VisitPointers(Object** start, Object** end) { |
| 7308 | bool done = ((what_to_find_ == FIND_FIRST) && found_target_); |
| 7309 | // Visit all HeapObject pointers in [start, end) |
| 7310 | for (Object** p = start; !done && (p < end); p++) { |
| 7311 | if ((*p)->IsHeapObject()) { |
| 7312 | TracePathFrom(p); |
| 7313 | done = ((what_to_find_ == FIND_FIRST) && found_target_); |
| 7314 | } |
| 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | |
| 7319 | void PathTracer::Reset() { |
| 7320 | found_target_ = false; |
| 7321 | object_stack_.Clear(); |
| 7322 | } |
| 7323 | |
| 7324 | |
| 7325 | void PathTracer::TracePathFrom(Object** root) { |
| 7326 | ASSERT((search_target_ == kAnyGlobalObject) || |
| 7327 | search_target_->IsHeapObject()); |
| 7328 | found_target_in_trace_ = false; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7329 | Reset(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7330 | |
| 7331 | MarkVisitor mark_visitor(this); |
| 7332 | MarkRecursively(root, &mark_visitor); |
| 7333 | |
| 7334 | UnmarkVisitor unmark_visitor(this); |
| 7335 | UnmarkRecursively(root, &unmark_visitor); |
| 7336 | |
| 7337 | ProcessResults(); |
| 7338 | } |
| 7339 | |
| 7340 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 7341 | static bool SafeIsNativeContext(HeapObject* obj) { |
| 7342 | return obj->map() == obj->GetHeap()->raw_unchecked_native_context_map(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7343 | } |
| 7344 | |
| 7345 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7346 | void PathTracer::MarkRecursively(Object** p, MarkVisitor* mark_visitor) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7347 | if (!(*p)->IsHeapObject()) return; |
| 7348 | |
| 7349 | HeapObject* obj = HeapObject::cast(*p); |
| 7350 | |
| 7351 | Object* map = obj->map(); |
| 7352 | |
| 7353 | if (!map->IsHeapObject()) return; // visited before |
| 7354 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7355 | if (found_target_in_trace_) return; // stop if target found |
| 7356 | object_stack_.Add(obj); |
| 7357 | if (((search_target_ == kAnyGlobalObject) && obj->IsJSGlobalObject()) || |
| 7358 | (obj == search_target_)) { |
| 7359 | found_target_in_trace_ = true; |
| 7360 | found_target_ = true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7361 | return; |
| 7362 | } |
| 7363 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 7364 | bool is_native_context = SafeIsNativeContext(obj); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7365 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7366 | // not visited yet |
| 7367 | Map* map_p = reinterpret_cast<Map*>(HeapObject::cast(map)); |
| 7368 | |
| 7369 | Address map_addr = map_p->address(); |
| 7370 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7371 | obj->set_map_no_write_barrier(reinterpret_cast<Map*>(map_addr + kMarkTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7372 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7373 | // Scan the object body. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 7374 | if (is_native_context && (visit_mode_ == VISIT_ONLY_STRONG)) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7375 | // This is specialized to scan Context's properly. |
danno@chromium.org | 2ab0c3b | 2012-10-05 08:50:56 +0000 | [diff] [blame] | 7376 | Object** start = reinterpret_cast<Object**>(obj->address() + |
| 7377 | Context::kHeaderSize); |
| 7378 | Object** end = reinterpret_cast<Object**>(obj->address() + |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7379 | Context::kHeaderSize + Context::FIRST_WEAK_SLOT * kPointerSize); |
danno@chromium.org | 2ab0c3b | 2012-10-05 08:50:56 +0000 | [diff] [blame] | 7380 | mark_visitor->VisitPointers(start, end); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7381 | } else { |
| 7382 | obj->IterateBody(map_p->instance_type(), |
| 7383 | obj->SizeFromMap(map_p), |
| 7384 | mark_visitor); |
| 7385 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7386 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7387 | // Scan the map after the body because the body is a lot more interesting |
| 7388 | // when doing leak detection. |
| 7389 | MarkRecursively(&map, mark_visitor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7390 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7391 | if (!found_target_in_trace_) // don't pop if found the target |
| 7392 | object_stack_.RemoveLast(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7393 | } |
| 7394 | |
| 7395 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7396 | void PathTracer::UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7397 | if (!(*p)->IsHeapObject()) return; |
| 7398 | |
| 7399 | HeapObject* obj = HeapObject::cast(*p); |
| 7400 | |
| 7401 | Object* map = obj->map(); |
| 7402 | |
| 7403 | if (map->IsHeapObject()) return; // unmarked already |
| 7404 | |
| 7405 | Address map_addr = reinterpret_cast<Address>(map); |
| 7406 | |
| 7407 | map_addr -= kMarkTag; |
| 7408 | |
| 7409 | ASSERT_TAG_ALIGNED(map_addr); |
| 7410 | |
| 7411 | HeapObject* map_p = HeapObject::FromAddress(map_addr); |
| 7412 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7413 | obj->set_map_no_write_barrier(reinterpret_cast<Map*>(map_p)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7414 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7415 | UnmarkRecursively(reinterpret_cast<Object**>(&map_p), unmark_visitor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7416 | |
| 7417 | obj->IterateBody(Map::cast(map_p)->instance_type(), |
| 7418 | obj->SizeFromMap(Map::cast(map_p)), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7419 | unmark_visitor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7420 | } |
| 7421 | |
| 7422 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7423 | void PathTracer::ProcessResults() { |
| 7424 | if (found_target_) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7425 | PrintF("=====================================\n"); |
| 7426 | PrintF("==== Path to object ====\n"); |
| 7427 | PrintF("=====================================\n\n"); |
| 7428 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7429 | ASSERT(!object_stack_.is_empty()); |
| 7430 | for (int i = 0; i < object_stack_.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7431 | if (i > 0) PrintF("\n |\n |\n V\n\n"); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7432 | Object* obj = object_stack_[i]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7433 | obj->Print(); |
| 7434 | } |
| 7435 | PrintF("=====================================\n"); |
| 7436 | } |
| 7437 | } |
| 7438 | |
| 7439 | |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 7440 | // Triggers a depth-first traversal of reachable objects from one |
| 7441 | // given root object and finds a path to a specific heap object and |
| 7442 | // prints it. |
| 7443 | void Heap::TracePathToObjectFrom(Object* target, Object* root) { |
| 7444 | PathTracer tracer(target, PathTracer::FIND_ALL, VISIT_ALL); |
| 7445 | tracer.VisitPointer(&root); |
| 7446 | } |
| 7447 | |
| 7448 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7449 | // Triggers a depth-first traversal of reachable objects from roots |
| 7450 | // and finds a path to a specific heap object and prints it. |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7451 | void Heap::TracePathToObject(Object* target) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7452 | PathTracer tracer(target, PathTracer::FIND_ALL, VISIT_ALL); |
| 7453 | IterateRoots(&tracer, VISIT_ONLY_STRONG); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7454 | } |
| 7455 | |
| 7456 | |
| 7457 | // Triggers a depth-first traversal of reachable objects from roots |
| 7458 | // and finds a path to any global object and prints it. Useful for |
| 7459 | // determining the source for leaks of global objects. |
| 7460 | void Heap::TracePathToGlobal() { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 7461 | PathTracer tracer(PathTracer::kAnyGlobalObject, |
| 7462 | PathTracer::FIND_ALL, |
| 7463 | VISIT_ALL); |
| 7464 | IterateRoots(&tracer, VISIT_ONLY_STRONG); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7465 | } |
| 7466 | #endif |
| 7467 | |
| 7468 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7469 | static intptr_t CountTotalHolesSize(Heap* heap) { |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 7470 | intptr_t holes_size = 0; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7471 | OldSpaces spaces(heap); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7472 | for (OldSpace* space = spaces.next(); |
| 7473 | space != NULL; |
| 7474 | space = spaces.next()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7475 | holes_size += space->Waste() + space->Available(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7476 | } |
| 7477 | return holes_size; |
| 7478 | } |
| 7479 | |
| 7480 | |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 7481 | GCTracer::GCTracer(Heap* heap, |
| 7482 | const char* gc_reason, |
| 7483 | const char* collector_reason) |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7484 | : start_time_(0.0), |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 7485 | start_object_size_(0), |
| 7486 | start_memory_size_(0), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7487 | gc_count_(0), |
| 7488 | full_gc_count_(0), |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7489 | allocated_since_last_gc_(0), |
| 7490 | spent_in_mutator_(0), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7491 | promoted_objects_size_(0), |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 7492 | nodes_died_in_new_space_(0), |
| 7493 | nodes_copied_in_new_space_(0), |
| 7494 | nodes_promoted_(0), |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 7495 | heap_(heap), |
| 7496 | gc_reason_(gc_reason), |
| 7497 | collector_reason_(collector_reason) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7498 | if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7499 | start_time_ = OS::TimeCurrentMillis(); |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 7500 | start_object_size_ = heap_->SizeOfObjects(); |
| 7501 | start_memory_size_ = heap_->isolate()->memory_allocator()->Size(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7502 | |
| 7503 | for (int i = 0; i < Scope::kNumberOfScopes; i++) { |
| 7504 | scopes_[i] = 0; |
| 7505 | } |
| 7506 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7507 | in_free_list_or_wasted_before_gc_ = CountTotalHolesSize(heap); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7508 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7509 | allocated_since_last_gc_ = |
| 7510 | heap_->SizeOfObjects() - heap_->alive_after_last_gc_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7511 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7512 | if (heap_->last_gc_end_timestamp_ > 0) { |
| 7513 | spent_in_mutator_ = Max(start_time_ - heap_->last_gc_end_timestamp_, 0.0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7514 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7515 | |
| 7516 | steps_count_ = heap_->incremental_marking()->steps_count(); |
| 7517 | steps_took_ = heap_->incremental_marking()->steps_took(); |
| 7518 | longest_step_ = heap_->incremental_marking()->longest_step(); |
| 7519 | steps_count_since_last_gc_ = |
| 7520 | heap_->incremental_marking()->steps_count_since_last_gc(); |
| 7521 | steps_took_since_last_gc_ = |
| 7522 | heap_->incremental_marking()->steps_took_since_last_gc(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7523 | } |
| 7524 | |
| 7525 | |
| 7526 | GCTracer::~GCTracer() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7527 | // Printf ONE line iff flag is set. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7528 | if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; |
| 7529 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7530 | bool first_gc = (heap_->last_gc_end_timestamp_ == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7531 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7532 | heap_->alive_after_last_gc_ = heap_->SizeOfObjects(); |
| 7533 | heap_->last_gc_end_timestamp_ = OS::TimeCurrentMillis(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7534 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7535 | double time = heap_->last_gc_end_timestamp_ - start_time_; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7536 | |
| 7537 | // Update cumulative GC statistics if required. |
| 7538 | if (FLAG_print_cumulative_gc_stat) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 7539 | heap_->total_gc_time_ms_ += time; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7540 | heap_->max_gc_pause_ = Max(heap_->max_gc_pause_, time); |
| 7541 | heap_->max_alive_after_gc_ = Max(heap_->max_alive_after_gc_, |
| 7542 | heap_->alive_after_last_gc_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7543 | if (!first_gc) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7544 | heap_->min_in_mutator_ = Min(heap_->min_in_mutator_, |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7545 | spent_in_mutator_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7546 | } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 7547 | } else if (FLAG_trace_gc_verbose) { |
| 7548 | heap_->total_gc_time_ms_ += time; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7549 | } |
| 7550 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 7551 | if (collector_ == SCAVENGER && FLAG_trace_gc_ignore_scavenger) return; |
| 7552 | |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 7553 | heap_->AddMarkingTime(scopes_[Scope::MC_MARK]); |
| 7554 | |
| 7555 | if (FLAG_print_cumulative_gc_stat && !FLAG_trace_gc) return; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 7556 | PrintPID("%8.0f ms: ", heap_->isolate()->time_millis_since_init()); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 7557 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7558 | if (!FLAG_trace_gc_nvp) { |
| 7559 | int external_time = static_cast<int>(scopes_[Scope::EXTERNAL]); |
| 7560 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 7561 | double end_memory_size_mb = |
| 7562 | static_cast<double>(heap_->isolate()->memory_allocator()->Size()) / MB; |
| 7563 | |
| 7564 | PrintF("%s %.1f (%.1f) -> %.1f (%.1f) MB, ", |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7565 | CollectorString(), |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 7566 | static_cast<double>(start_object_size_) / MB, |
| 7567 | static_cast<double>(start_memory_size_) / MB, |
| 7568 | SizeOfHeapObjects(), |
| 7569 | end_memory_size_mb); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7570 | |
| 7571 | if (external_time > 0) PrintF("%d / ", external_time); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7572 | PrintF("%.1f ms", time); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7573 | if (steps_count_ > 0) { |
| 7574 | if (collector_ == SCAVENGER) { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7575 | PrintF(" (+ %.1f ms in %d steps since last GC)", |
| 7576 | steps_took_since_last_gc_, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7577 | steps_count_since_last_gc_); |
| 7578 | } else { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7579 | PrintF(" (+ %.1f ms in %d steps since start of marking, " |
| 7580 | "biggest step %.1f ms)", |
| 7581 | steps_took_, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7582 | steps_count_, |
| 7583 | longest_step_); |
| 7584 | } |
| 7585 | } |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 7586 | |
| 7587 | if (gc_reason_ != NULL) { |
| 7588 | PrintF(" [%s]", gc_reason_); |
| 7589 | } |
| 7590 | |
| 7591 | if (collector_reason_ != NULL) { |
| 7592 | PrintF(" [%s]", collector_reason_); |
| 7593 | } |
| 7594 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7595 | PrintF(".\n"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7596 | } else { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7597 | PrintF("pause=%.1f ", time); |
| 7598 | PrintF("mutator=%.1f ", spent_in_mutator_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7599 | PrintF("gc="); |
| 7600 | switch (collector_) { |
| 7601 | case SCAVENGER: |
| 7602 | PrintF("s"); |
| 7603 | break; |
| 7604 | case MARK_COMPACTOR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7605 | PrintF("ms"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7606 | break; |
| 7607 | default: |
| 7608 | UNREACHABLE(); |
| 7609 | } |
| 7610 | PrintF(" "); |
| 7611 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7612 | PrintF("external=%.1f ", scopes_[Scope::EXTERNAL]); |
| 7613 | PrintF("mark=%.1f ", scopes_[Scope::MC_MARK]); |
| 7614 | PrintF("sweep=%.1f ", scopes_[Scope::MC_SWEEP]); |
| 7615 | PrintF("sweepns=%.1f ", scopes_[Scope::MC_SWEEP_NEWSPACE]); |
| 7616 | PrintF("evacuate=%.1f ", scopes_[Scope::MC_EVACUATE_PAGES]); |
| 7617 | PrintF("new_new=%.1f ", scopes_[Scope::MC_UPDATE_NEW_TO_NEW_POINTERS]); |
| 7618 | PrintF("root_new=%.1f ", scopes_[Scope::MC_UPDATE_ROOT_TO_NEW_POINTERS]); |
| 7619 | PrintF("old_new=%.1f ", scopes_[Scope::MC_UPDATE_OLD_TO_NEW_POINTERS]); |
| 7620 | PrintF("compaction_ptrs=%.1f ", |
| 7621 | scopes_[Scope::MC_UPDATE_POINTERS_TO_EVACUATED]); |
| 7622 | PrintF("intracompaction_ptrs=%.1f ", |
| 7623 | scopes_[Scope::MC_UPDATE_POINTERS_BETWEEN_EVACUATED]); |
| 7624 | PrintF("misc_compaction=%.1f ", scopes_[Scope::MC_UPDATE_MISC_POINTERS]); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 7625 | PrintF("weakcollection_process=%.1f ", |
| 7626 | scopes_[Scope::MC_WEAKCOLLECTION_PROCESS]); |
| 7627 | PrintF("weakcollection_clear=%.1f ", |
| 7628 | scopes_[Scope::MC_WEAKCOLLECTION_CLEAR]); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7629 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 7630 | PrintF("total_size_before=%" V8_PTR_PREFIX "d ", start_object_size_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7631 | PrintF("total_size_after=%" V8_PTR_PREFIX "d ", heap_->SizeOfObjects()); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 7632 | PrintF("holes_size_before=%" V8_PTR_PREFIX "d ", |
| 7633 | in_free_list_or_wasted_before_gc_); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 7634 | PrintF("holes_size_after=%" V8_PTR_PREFIX "d ", CountTotalHolesSize(heap_)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7635 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 7636 | PrintF("allocated=%" V8_PTR_PREFIX "d ", allocated_since_last_gc_); |
| 7637 | PrintF("promoted=%" V8_PTR_PREFIX "d ", promoted_objects_size_); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 7638 | PrintF("nodes_died_in_new=%d ", nodes_died_in_new_space_); |
| 7639 | PrintF("nodes_copied_in_new=%d ", nodes_copied_in_new_space_); |
| 7640 | PrintF("nodes_promoted=%d ", nodes_promoted_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7641 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7642 | if (collector_ == SCAVENGER) { |
| 7643 | PrintF("stepscount=%d ", steps_count_since_last_gc_); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7644 | PrintF("stepstook=%.1f ", steps_took_since_last_gc_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7645 | } else { |
| 7646 | PrintF("stepscount=%d ", steps_count_); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7647 | PrintF("stepstook=%.1f ", steps_took_); |
| 7648 | PrintF("longeststep=%.1f ", longest_step_); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7649 | } |
| 7650 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7651 | PrintF("\n"); |
| 7652 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 7653 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7654 | heap_->PrintShortHeapStatistics(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7655 | } |
| 7656 | |
| 7657 | |
| 7658 | const char* GCTracer::CollectorString() { |
| 7659 | switch (collector_) { |
| 7660 | case SCAVENGER: |
| 7661 | return "Scavenge"; |
| 7662 | case MARK_COMPACTOR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7663 | return "Mark-sweep"; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7664 | } |
| 7665 | return "Unknown GC"; |
| 7666 | } |
| 7667 | |
| 7668 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7669 | int KeyedLookupCache::Hash(Map* map, Name* name) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 7670 | // Uses only lower 32 bits if pointers are larger. |
| 7671 | uintptr_t addr_hash = |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7672 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map)) >> kMapHashShift; |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 7673 | return static_cast<uint32_t>((addr_hash ^ name->Hash()) & kCapacityMask); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 7674 | } |
| 7675 | |
| 7676 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7677 | int KeyedLookupCache::Lookup(Map* map, Name* name) { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 7678 | int index = (Hash(map, name) & kHashMask); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 7679 | for (int i = 0; i < kEntriesPerBucket; i++) { |
| 7680 | Key& key = keys_[index + i]; |
| 7681 | if ((key.map == map) && key.name->Equals(name)) { |
| 7682 | return field_offsets_[index + i]; |
| 7683 | } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 7684 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7685 | return kNotFound; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 7686 | } |
| 7687 | |
| 7688 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7689 | void KeyedLookupCache::Update(Map* map, Name* name, int field_offset) { |
| 7690 | if (!name->IsUniqueName()) { |
| 7691 | String* internalized_string; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 7692 | if (!map->GetIsolate()->heap()->InternalizeStringIfExists( |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7693 | String::cast(name), &internalized_string)) { |
| 7694 | return; |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 7695 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7696 | name = internalized_string; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 7697 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7698 | // This cache is cleared only between mark compact passes, so we expect the |
| 7699 | // cache to only contain old space names. |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 7700 | ASSERT(!map->GetIsolate()->heap()->InNewSpace(name)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7701 | |
| 7702 | int index = (Hash(map, name) & kHashMask); |
| 7703 | // After a GC there will be free slots, so we use them in order (this may |
| 7704 | // help to get the most frequently used one in position 0). |
| 7705 | for (int i = 0; i< kEntriesPerBucket; i++) { |
| 7706 | Key& key = keys_[index]; |
| 7707 | Object* free_entry_indicator = NULL; |
| 7708 | if (key.map == free_entry_indicator) { |
| 7709 | key.map = map; |
| 7710 | key.name = name; |
| 7711 | field_offsets_[index + i] = field_offset; |
| 7712 | return; |
| 7713 | } |
| 7714 | } |
| 7715 | // No free entry found in this bucket, so we move them all down one and |
| 7716 | // put the new entry at position zero. |
| 7717 | for (int i = kEntriesPerBucket - 1; i > 0; i--) { |
| 7718 | Key& key = keys_[index + i]; |
| 7719 | Key& key2 = keys_[index + i - 1]; |
| 7720 | key = key2; |
| 7721 | field_offsets_[index + i] = field_offsets_[index + i - 1]; |
| 7722 | } |
| 7723 | |
| 7724 | // Write the new first entry. |
| 7725 | Key& key = keys_[index]; |
| 7726 | key.map = map; |
| 7727 | key.name = name; |
| 7728 | field_offsets_[index] = field_offset; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 7729 | } |
| 7730 | |
| 7731 | |
| 7732 | void KeyedLookupCache::Clear() { |
| 7733 | for (int index = 0; index < kLength; index++) keys_[index].map = NULL; |
| 7734 | } |
| 7735 | |
| 7736 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 7737 | void DescriptorLookupCache::Clear() { |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 7738 | for (int index = 0; index < kLength; index++) keys_[index].source = NULL; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 7739 | } |
| 7740 | |
| 7741 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7742 | #ifdef DEBUG |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 7743 | void Heap::GarbageCollectionGreedyCheck() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7744 | ASSERT(FLAG_gc_greedy); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7745 | if (isolate_->bootstrapper()->IsActive()) return; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 7746 | if (disallow_allocation_failure()) return; |
| 7747 | CollectGarbage(NEW_SPACE); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7748 | } |
| 7749 | #endif |
| 7750 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 7751 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7752 | TranscendentalCache::SubCache::SubCache(Isolate* isolate, Type t) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7753 | : type_(t), |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7754 | isolate_(isolate) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 7755 | uint32_t in0 = 0xffffffffu; // Bit-pattern for a NaN that isn't |
| 7756 | uint32_t in1 = 0xffffffffu; // generated by the FPU. |
| 7757 | for (int i = 0; i < kCacheSize; i++) { |
| 7758 | elements_[i].in[0] = in0; |
| 7759 | elements_[i].in[1] = in1; |
| 7760 | elements_[i].output = NULL; |
| 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 7765 | void TranscendentalCache::Clear() { |
| 7766 | for (int i = 0; i < kNumberOfCaches; i++) { |
| 7767 | if (caches_[i] != NULL) { |
| 7768 | delete caches_[i]; |
| 7769 | caches_[i] = NULL; |
| 7770 | } |
| 7771 | } |
| 7772 | } |
| 7773 | |
| 7774 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7775 | void ExternalStringTable::CleanUp() { |
| 7776 | int last = 0; |
| 7777 | for (int i = 0; i < new_space_strings_.length(); ++i) { |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 7778 | if (new_space_strings_[i] == heap_->the_hole_value()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7779 | continue; |
| 7780 | } |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 7781 | ASSERT(new_space_strings_[i]->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7782 | if (heap_->InNewSpace(new_space_strings_[i])) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7783 | new_space_strings_[last++] = new_space_strings_[i]; |
| 7784 | } else { |
| 7785 | old_space_strings_.Add(new_space_strings_[i]); |
| 7786 | } |
| 7787 | } |
| 7788 | new_space_strings_.Rewind(last); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 7789 | new_space_strings_.Trim(); |
| 7790 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7791 | last = 0; |
| 7792 | for (int i = 0; i < old_space_strings_.length(); ++i) { |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 7793 | if (old_space_strings_[i] == heap_->the_hole_value()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7794 | continue; |
| 7795 | } |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 7796 | ASSERT(old_space_strings_[i]->IsExternalString()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7797 | ASSERT(!heap_->InNewSpace(old_space_strings_[i])); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7798 | old_space_strings_[last++] = old_space_strings_[i]; |
| 7799 | } |
| 7800 | old_space_strings_.Rewind(last); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 7801 | old_space_strings_.Trim(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 7802 | #ifdef VERIFY_HEAP |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7803 | if (FLAG_verify_heap) { |
| 7804 | Verify(); |
| 7805 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 7806 | #endif |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7807 | } |
| 7808 | |
| 7809 | |
| 7810 | void ExternalStringTable::TearDown() { |
| 7811 | new_space_strings_.Free(); |
| 7812 | old_space_strings_.Free(); |
| 7813 | } |
| 7814 | |
| 7815 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7816 | void Heap::QueueMemoryChunkForFree(MemoryChunk* chunk) { |
| 7817 | chunk->set_next_chunk(chunks_queued_for_free_); |
| 7818 | chunks_queued_for_free_ = chunk; |
| 7819 | } |
| 7820 | |
| 7821 | |
| 7822 | void Heap::FreeQueuedChunks() { |
| 7823 | if (chunks_queued_for_free_ == NULL) return; |
| 7824 | MemoryChunk* next; |
| 7825 | MemoryChunk* chunk; |
| 7826 | for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
| 7827 | next = chunk->next_chunk(); |
| 7828 | chunk->SetFlag(MemoryChunk::ABOUT_TO_BE_FREED); |
| 7829 | |
| 7830 | if (chunk->owner()->identity() == LO_SPACE) { |
| 7831 | // StoreBuffer::Filter relies on MemoryChunk::FromAnyPointerAddress. |
| 7832 | // If FromAnyPointerAddress encounters a slot that belongs to a large |
| 7833 | // chunk queued for deletion it will fail to find the chunk because |
| 7834 | // it try to perform a search in the list of pages owned by of the large |
| 7835 | // object space and queued chunks were detached from that list. |
| 7836 | // To work around this we split large chunk into normal kPageSize aligned |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 7837 | // pieces and initialize size, owner and flags field of every piece. |
| 7838 | // If FromAnyPointerAddress encounters a slot that belongs to one of |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7839 | // these smaller pieces it will treat it as a slot on a normal Page. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 7840 | Address chunk_end = chunk->address() + chunk->size(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7841 | MemoryChunk* inner = MemoryChunk::FromAddress( |
| 7842 | chunk->address() + Page::kPageSize); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 7843 | MemoryChunk* inner_last = MemoryChunk::FromAddress(chunk_end - 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7844 | while (inner <= inner_last) { |
| 7845 | // Size of a large chunk is always a multiple of |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7846 | // OS::AllocateAlignment() so there is always |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7847 | // enough space for a fake MemoryChunk header. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 7848 | Address area_end = Min(inner->address() + Page::kPageSize, chunk_end); |
| 7849 | // Guard against overflow. |
| 7850 | if (area_end < inner->address()) area_end = chunk_end; |
| 7851 | inner->SetArea(inner->address(), area_end); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 7852 | inner->set_size(Page::kPageSize); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7853 | inner->set_owner(lo_space()); |
| 7854 | inner->SetFlag(MemoryChunk::ABOUT_TO_BE_FREED); |
| 7855 | inner = MemoryChunk::FromAddress( |
| 7856 | inner->address() + Page::kPageSize); |
| 7857 | } |
| 7858 | } |
| 7859 | } |
| 7860 | isolate_->heap()->store_buffer()->Compact(); |
| 7861 | isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
| 7862 | for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
| 7863 | next = chunk->next_chunk(); |
| 7864 | isolate_->memory_allocator()->Free(chunk); |
| 7865 | } |
| 7866 | chunks_queued_for_free_ = NULL; |
| 7867 | } |
| 7868 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 7869 | |
| 7870 | void Heap::RememberUnmappedPage(Address page, bool compacted) { |
| 7871 | uintptr_t p = reinterpret_cast<uintptr_t>(page); |
| 7872 | // Tag the page pointer to make it findable in the dump file. |
| 7873 | if (compacted) { |
| 7874 | p ^= 0xc1ead & (Page::kPageSize - 1); // Cleared. |
| 7875 | } else { |
| 7876 | p ^= 0x1d1ed & (Page::kPageSize - 1); // I died. |
| 7877 | } |
| 7878 | remembered_unmapped_pages_[remembered_unmapped_pages_index_] = |
| 7879 | reinterpret_cast<Address>(p); |
| 7880 | remembered_unmapped_pages_index_++; |
| 7881 | remembered_unmapped_pages_index_ %= kRememberedUnmappedPages; |
| 7882 | } |
| 7883 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 7884 | |
| 7885 | void Heap::ClearObjectStats(bool clear_last_time_stats) { |
| 7886 | memset(object_counts_, 0, sizeof(object_counts_)); |
| 7887 | memset(object_sizes_, 0, sizeof(object_sizes_)); |
| 7888 | if (clear_last_time_stats) { |
| 7889 | memset(object_counts_last_time_, 0, sizeof(object_counts_last_time_)); |
| 7890 | memset(object_sizes_last_time_, 0, sizeof(object_sizes_last_time_)); |
| 7891 | } |
| 7892 | } |
| 7893 | |
| 7894 | |
| 7895 | static LazyMutex checkpoint_object_stats_mutex = LAZY_MUTEX_INITIALIZER; |
| 7896 | |
| 7897 | |
| 7898 | void Heap::CheckpointObjectStats() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 7899 | LockGuard<Mutex> lock_guard(checkpoint_object_stats_mutex.Pointer()); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 7900 | Counters* counters = isolate()->counters(); |
| 7901 | #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 7902 | counters->count_of_##name()->Increment( \ |
| 7903 | static_cast<int>(object_counts_[name])); \ |
| 7904 | counters->count_of_##name()->Decrement( \ |
| 7905 | static_cast<int>(object_counts_last_time_[name])); \ |
| 7906 | counters->size_of_##name()->Increment( \ |
| 7907 | static_cast<int>(object_sizes_[name])); \ |
| 7908 | counters->size_of_##name()->Decrement( \ |
| 7909 | static_cast<int>(object_sizes_last_time_[name])); |
| 7910 | INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7911 | #undef ADJUST_LAST_TIME_OBJECT_COUNT |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7912 | int index; |
| 7913 | #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 7914 | index = FIRST_CODE_KIND_SUB_TYPE + Code::name; \ |
| 7915 | counters->count_of_CODE_TYPE_##name()->Increment( \ |
| 7916 | static_cast<int>(object_counts_[index])); \ |
| 7917 | counters->count_of_CODE_TYPE_##name()->Decrement( \ |
| 7918 | static_cast<int>(object_counts_last_time_[index])); \ |
| 7919 | counters->size_of_CODE_TYPE_##name()->Increment( \ |
| 7920 | static_cast<int>(object_sizes_[index])); \ |
| 7921 | counters->size_of_CODE_TYPE_##name()->Decrement( \ |
| 7922 | static_cast<int>(object_sizes_last_time_[index])); |
| 7923 | CODE_KIND_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7924 | #undef ADJUST_LAST_TIME_OBJECT_COUNT |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 7925 | #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 7926 | index = FIRST_FIXED_ARRAY_SUB_TYPE + name; \ |
| 7927 | counters->count_of_FIXED_ARRAY_##name()->Increment( \ |
| 7928 | static_cast<int>(object_counts_[index])); \ |
| 7929 | counters->count_of_FIXED_ARRAY_##name()->Decrement( \ |
| 7930 | static_cast<int>(object_counts_last_time_[index])); \ |
| 7931 | counters->size_of_FIXED_ARRAY_##name()->Increment( \ |
| 7932 | static_cast<int>(object_sizes_[index])); \ |
| 7933 | counters->size_of_FIXED_ARRAY_##name()->Decrement( \ |
| 7934 | static_cast<int>(object_sizes_last_time_[index])); |
| 7935 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7936 | #undef ADJUST_LAST_TIME_OBJECT_COUNT |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 7937 | #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \ |
| 7938 | index = \ |
| 7939 | FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge; \ |
| 7940 | counters->count_of_CODE_AGE_##name()->Increment( \ |
| 7941 | static_cast<int>(object_counts_[index])); \ |
| 7942 | counters->count_of_CODE_AGE_##name()->Decrement( \ |
| 7943 | static_cast<int>(object_counts_last_time_[index])); \ |
| 7944 | counters->size_of_CODE_AGE_##name()->Increment( \ |
| 7945 | static_cast<int>(object_sizes_[index])); \ |
| 7946 | counters->size_of_CODE_AGE_##name()->Decrement( \ |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 7947 | static_cast<int>(object_sizes_last_time_[index])); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 7948 | CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 7949 | #undef ADJUST_LAST_TIME_OBJECT_COUNT |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7950 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7951 | OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7952 | OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 7953 | ClearObjectStats(); |
| 7954 | } |
| 7955 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7956 | |
| 7957 | Heap::RelocationLock::RelocationLock(Heap* heap) : heap_(heap) { |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 7958 | if (FLAG_concurrent_recompilation) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7959 | heap_->relocation_mutex_->Lock(); |
| 7960 | #ifdef DEBUG |
| 7961 | heap_->relocation_mutex_locked_by_optimizer_thread_ = |
| 7962 | heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); |
| 7963 | #endif // DEBUG |
| 7964 | } |
| 7965 | } |
| 7966 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7967 | } } // namespace v8::internal |