yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 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 "objects.h" |
| 31 | #include "transitions-inl.h" |
| 32 | #include "utils.h" |
| 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
| 37 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 38 | static MaybeObject* AllocateRaw(Isolate* isolate, int length) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 39 | // Use FixedArray to not use TransitionArray::cast on incomplete object. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 40 | FixedArray* array; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 41 | MaybeObject* maybe_array = isolate->heap()->AllocateFixedArray(length); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 42 | if (!maybe_array->To(&array)) return maybe_array; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 43 | return array; |
| 44 | } |
| 45 | |
| 46 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 47 | MaybeObject* TransitionArray::Allocate(Isolate* isolate, |
| 48 | int number_of_transitions) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 49 | FixedArray* array; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 50 | MaybeObject* maybe_array = |
| 51 | AllocateRaw(isolate, ToKeyIndex(number_of_transitions)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 52 | if (!maybe_array->To(&array)) return maybe_array; |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 53 | array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 54 | return array; |
| 55 | } |
| 56 | |
| 57 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 58 | void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
| 59 | int origin_transition, |
| 60 | int target_transition) { |
| 61 | NoIncrementalWriteBarrierSet(target_transition, |
| 62 | origin->GetKey(origin_transition), |
| 63 | origin->GetTarget(origin_transition)); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 67 | static bool InsertionPointFound(Name* key1, Name* key2) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 68 | return key1->Hash() > key2->Hash(); |
| 69 | } |
| 70 | |
| 71 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 72 | MaybeObject* TransitionArray::NewWith(SimpleTransitionFlag flag, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 73 | Name* key, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 74 | Map* target, |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 75 | Object* back_pointer) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 76 | TransitionArray* result; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 77 | MaybeObject* maybe_result; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 78 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 79 | if (flag == SIMPLE_TRANSITION) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 80 | maybe_result = AllocateRaw(target->GetIsolate(), kSimpleTransitionSize); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 81 | if (!maybe_result->To(&result)) return maybe_result; |
| 82 | result->set(kSimpleTransitionTarget, target); |
| 83 | } else { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 84 | maybe_result = Allocate(target->GetIsolate(), 1); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 85 | if (!maybe_result->To(&result)) return maybe_result; |
| 86 | result->NoIncrementalWriteBarrierSet(0, key, target); |
| 87 | } |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 88 | result->set_back_pointer_storage(back_pointer); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 89 | return result; |
| 90 | } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 91 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 92 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 93 | MaybeObject* TransitionArray::ExtendToFullTransitionArray() { |
| 94 | ASSERT(!IsFullTransitionArray()); |
| 95 | int nof = number_of_transitions(); |
| 96 | TransitionArray* result; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 97 | MaybeObject* maybe_result = Allocate(GetIsolate(), nof); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 98 | if (!maybe_result->To(&result)) return maybe_result; |
| 99 | |
| 100 | if (nof == 1) { |
| 101 | result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); |
| 102 | } |
| 103 | |
| 104 | result->set_back_pointer_storage(back_pointer_storage()); |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 109 | MaybeObject* TransitionArray::CopyInsert(Name* name, Map* target) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 110 | TransitionArray* result; |
| 111 | |
| 112 | int number_of_transitions = this->number_of_transitions(); |
| 113 | int new_size = number_of_transitions; |
| 114 | |
| 115 | int insertion_index = this->Search(name); |
| 116 | if (insertion_index == kNotFound) ++new_size; |
| 117 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 118 | MaybeObject* maybe_array; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 119 | maybe_array = TransitionArray::Allocate(GetIsolate(), new_size); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 120 | if (!maybe_array->To(&result)) return maybe_array; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 121 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 122 | if (HasPrototypeTransitions()) { |
| 123 | result->SetPrototypeTransitions(GetPrototypeTransitions()); |
| 124 | } |
| 125 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 126 | if (insertion_index != kNotFound) { |
| 127 | for (int i = 0; i < number_of_transitions; ++i) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 128 | if (i != insertion_index) { |
| 129 | result->NoIncrementalWriteBarrierCopyFrom(this, i, i); |
| 130 | } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 131 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 132 | result->NoIncrementalWriteBarrierSet(insertion_index, name, target); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 133 | result->set_back_pointer_storage(back_pointer_storage()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 134 | return result; |
| 135 | } |
| 136 | |
| 137 | insertion_index = 0; |
| 138 | for (; insertion_index < number_of_transitions; ++insertion_index) { |
| 139 | if (InsertionPointFound(GetKey(insertion_index), name)) break; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 140 | result->NoIncrementalWriteBarrierCopyFrom( |
| 141 | this, insertion_index, insertion_index); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 142 | } |
| 143 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 144 | result->NoIncrementalWriteBarrierSet(insertion_index, name, target); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 145 | |
| 146 | for (; insertion_index < number_of_transitions; ++insertion_index) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 147 | result->NoIncrementalWriteBarrierCopyFrom( |
| 148 | this, insertion_index, insertion_index + 1); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 149 | } |
| 150 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 151 | result->set_back_pointer_storage(back_pointer_storage()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 152 | return result; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | } } // namespace v8::internal |