| 1 | /* |
| 2 | * Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>. |
| 3 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | #include "InByIdVariant.h" |
| 29 | |
| 30 | #include "JSCInlines.h" |
| 31 | #include <wtf/ListDump.h> |
| 32 | |
| 33 | namespace JSC { |
| 34 | |
| 35 | InByIdVariant::InByIdVariant(const StructureSet& structureSet, PropertyOffset offset, const ObjectPropertyConditionSet& conditionSet) |
| 36 | : m_structureSet(structureSet) |
| 37 | , m_conditionSet(conditionSet) |
| 38 | , m_offset(offset) |
| 39 | { |
| 40 | if (!structureSet.size()) { |
| 41 | ASSERT(offset == invalidOffset); |
| 42 | ASSERT(conditionSet.isEmpty()); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | bool InByIdVariant::attemptToMerge(const InByIdVariant& other) |
| 47 | { |
| 48 | if (m_offset != other.m_offset) |
| 49 | return false; |
| 50 | |
| 51 | if (m_conditionSet.isEmpty() != other.m_conditionSet.isEmpty()) |
| 52 | return false; |
| 53 | |
| 54 | ObjectPropertyConditionSet mergedConditionSet; |
| 55 | if (!m_conditionSet.isEmpty()) { |
| 56 | mergedConditionSet = m_conditionSet.mergedWith(other.m_conditionSet); |
| 57 | if (!mergedConditionSet.isValid()) |
| 58 | return false; |
| 59 | // If this is a hit variant, one slot base should exist. If this is not a hit variant, the slot base is not necessary. |
| 60 | if (isHit() && !mergedConditionSet.hasOneSlotBaseCondition()) |
| 61 | return false; |
| 62 | } |
| 63 | m_conditionSet = mergedConditionSet; |
| 64 | |
| 65 | m_structureSet.merge(other.m_structureSet); |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | void InByIdVariant::markIfCheap(SlotVisitor& visitor) |
| 71 | { |
| 72 | m_structureSet.markIfCheap(visitor); |
| 73 | } |
| 74 | |
| 75 | bool InByIdVariant::finalize(VM& vm) |
| 76 | { |
| 77 | if (!m_structureSet.isStillAlive(vm)) |
| 78 | return false; |
| 79 | if (!m_conditionSet.areStillLive(vm)) |
| 80 | return false; |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | void InByIdVariant::dump(PrintStream& out) const |
| 85 | { |
| 86 | dumpInContext(out, 0); |
| 87 | } |
| 88 | |
| 89 | void InByIdVariant::dumpInContext(PrintStream& out, DumpContext* context) const |
| 90 | { |
| 91 | if (!isSet()) { |
| 92 | out.print("<empty>" ); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | out.print( |
| 97 | "<" , inContext(structureSet(), context), ", " , inContext(m_conditionSet, context)); |
| 98 | out.print(", offset = " , offset()); |
| 99 | out.print(">" ); |
| 100 | } |
| 101 | |
| 102 | } // namespace JSC |
| 103 | |
| 104 | |