| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/interpreter/constant-array-builder.h" | 5 #include "src/interpreter/constant-array-builder.h" |
| 6 | 6 |
| 7 #include "src/isolate.h" | 7 #include "src/isolate.h" |
| 8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 Handle<Object> ConstantArrayBuilder::At(size_t index) const { | 78 Handle<Object> ConstantArrayBuilder::At(size_t index) const { |
| 79 if (index >= idx16_slice_.start_index()) { | 79 if (index >= idx16_slice_.start_index()) { |
| 80 return idx16_slice_.At(index); | 80 return idx16_slice_.At(index); |
| 81 } else if (index < idx8_slice_.size()) { | 81 } else if (index < idx8_slice_.size()) { |
| 82 return idx8_slice_.At(index); | 82 return idx8_slice_.At(index); |
| 83 } else { | 83 } else { |
| 84 return isolate_->factory()->the_hole_value(); | 84 return isolate_->factory()->the_hole_value(); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 | 88 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray() { |
| 89 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray() const { | |
| 90 Handle<FixedArray> fixed_array = isolate_->factory()->NewFixedArray( | 89 Handle<FixedArray> fixed_array = isolate_->factory()->NewFixedArray( |
| 91 static_cast<int>(size()), PretenureFlag::TENURED); | 90 static_cast<int>(size()), PretenureFlag::TENURED); |
| 92 for (int i = 0; i < fixed_array->length(); i++) { | 91 for (int i = 0; i < fixed_array->length(); i++) { |
| 93 fixed_array->set(i, *At(static_cast<size_t>(i))); | 92 fixed_array->set(i, *At(static_cast<size_t>(i))); |
| 94 } | 93 } |
| 94 constants_map()->Clear(); |
| 95 return fixed_array; | 95 return fixed_array; |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { | 99 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { |
| 100 index_t* entry = constants_map_.Find(object); | 100 index_t* entry = constants_map()->Find(object); |
| 101 return (entry == nullptr) ? AllocateEntry(object) : *entry; | 101 return (entry == nullptr) ? AllocateEntry(object) : *entry; |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateEntry( | 105 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateEntry( |
| 106 Handle<Object> object) { | 106 Handle<Object> object) { |
| 107 DCHECK(!object->IsOddball()); | 107 DCHECK(!object->IsOddball()); |
| 108 size_t index; | 108 size_t index; |
| 109 index_t* entry = constants_map_.Get(object); | 109 index_t* entry = constants_map()->Get(object); |
| 110 if (idx8_slice_.available() > 0) { | 110 if (idx8_slice_.available() > 0) { |
| 111 index = idx8_slice_.Allocate(object); | 111 index = idx8_slice_.Allocate(object); |
| 112 } else { | 112 } else { |
| 113 index = idx16_slice_.Allocate(object); | 113 index = idx16_slice_.Allocate(object); |
| 114 } | 114 } |
| 115 CHECK_LT(index, kMaxCapacity); | 115 CHECK_LT(index, kMaxCapacity); |
| 116 *entry = static_cast<index_t>(index); | 116 *entry = static_cast<index_t>(index); |
| 117 return *entry; | 117 return *entry; |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 OperandSize ConstantArrayBuilder::CreateReservedEntry() { | 121 OperandSize ConstantArrayBuilder::CreateReservedEntry() { |
| 122 if (idx8_slice_.available() > 0) { | 122 if (idx8_slice_.available() > 0) { |
| 123 idx8_slice_.Reserve(); | 123 idx8_slice_.Reserve(); |
| 124 return OperandSize::kByte; | 124 return OperandSize::kByte; |
| 125 } else if (idx16_slice_.available() > 0) { | 125 } else if (idx16_slice_.available() > 0) { |
| 126 idx16_slice_.Reserve(); | 126 idx16_slice_.Reserve(); |
| 127 return OperandSize::kShort; | 127 return OperandSize::kShort; |
| 128 } else { | 128 } else { |
| 129 UNREACHABLE(); | 129 UNREACHABLE(); |
| 130 return OperandSize::kNone; | 130 return OperandSize::kNone; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 size_t ConstantArrayBuilder::CommitReservedEntry(OperandSize operand_size, | 135 size_t ConstantArrayBuilder::CommitReservedEntry(OperandSize operand_size, |
| 136 Handle<Object> object) { | 136 Handle<Object> object) { |
| 137 DiscardReservedEntry(operand_size); | 137 DiscardReservedEntry(operand_size); |
| 138 size_t index; | 138 size_t index; |
| 139 index_t* entry = constants_map_.Find(object); | 139 index_t* entry = constants_map()->Find(object); |
| 140 if (nullptr == entry) { | 140 if (nullptr == entry) { |
| 141 index = AllocateEntry(object); | 141 index = AllocateEntry(object); |
| 142 } else { | 142 } else { |
| 143 if (operand_size == OperandSize::kByte && | 143 if (operand_size == OperandSize::kByte && |
| 144 *entry >= idx8_slice_.capacity()) { | 144 *entry >= idx8_slice_.capacity()) { |
| 145 // The object is already in the constant array, but has an index | 145 // The object is already in the constant array, but has an index |
| 146 // outside the range of an idx8 operand so we need to create a | 146 // outside the range of an idx8 operand so we need to create a |
| 147 // duplicate entry in the idx8 operand range to satisfy the | 147 // duplicate entry in the idx8 operand range to satisfy the |
| 148 // commitment. | 148 // commitment. |
| 149 *entry = static_cast<index_t>(idx8_slice_.Allocate(object)); | 149 *entry = static_cast<index_t>(idx8_slice_.Allocate(object)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 165 idx16_slice_.Unreserve(); | 165 idx16_slice_.Unreserve(); |
| 166 return; | 166 return; |
| 167 default: | 167 default: |
| 168 UNREACHABLE(); | 168 UNREACHABLE(); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 } // namespace interpreter | 172 } // namespace interpreter |
| 173 } // namespace internal | 173 } // namespace internal |
| 174 } // namespace v8 | 174 } // namespace v8 |
| OLD | NEW |