-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JSC] DFG constant property load should check the validity at the mai…
…n thread https://bugs.webkit.org/show_bug.cgi?id=267134 rdar://120443399 Reviewed by Mark Lam. Consider the following case, CheckStructure O, S1 | S3 GetByOffset O, offset And S1 -> S2 -> S3 structure transition happens. By changing object concurrently with the compiler, it is possible that we will constant fold the property with O + S2. While we insert watchpoints into S1 and S3, we cannot notice the change of the property in S2. If we change O to S3 before running code, CheckStructure passes and we can use a value loaded from O + S2. 1. If S1 and S3 transitions are both already watched by DFG / FTL, then we do not need to care about the issue. CheckStructure ensures that O is S1 or S3. And both has watchpoints which fires when transition happens. So, if we are transitioning from S1 to S2 while compiling, it already invalidates the code. 2. If there is only one Structure (S1), then we can keep the current optimization by checking this condition at the main thread. CheckStructure ensures that O is S1. And this means that if the assumption is met at the main thread, then we can continue using this code safely. To check this condition, we added DesiredObjectProperties, which records JSObject*, offset, value, and structure. And at the end of compilation, in the main thread, we check this assumption is still met. * Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj: * Source/JavaScriptCore/Sources.txt: * Source/JavaScriptCore/dfg/DFGDesiredObjectProperties.cpp: Added. (JSC::DFG::DesiredObjectProperties::addLazily): (JSC::DFG::DesiredObjectProperties::areStillValidOnMainThread): * Source/JavaScriptCore/dfg/DFGDesiredObjectProperties.h: Added. * Source/JavaScriptCore/dfg/DFGGraph.cpp: (JSC::DFG::Graph::tryGetConstantProperty): * Source/JavaScriptCore/dfg/DFGPlan.cpp: (JSC::DFG::Plan::cancel): (JSC::DFG::Plan::isStillValidOnMainThread): * Source/JavaScriptCore/dfg/DFGPlan.h: Originally-landed-as: 272448.7@safari-7618-branch (3160120). rdar://121477582 Canonical link: https://commits.webkit.org/273486@main
- Loading branch information
1 parent
77a6809
commit 6471469
Showing
7 changed files
with
180 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "DFGDesiredObjectProperties.h" | ||
|
||
#if ENABLE(DFG_JIT) | ||
|
||
#include "JSObjectInlines.h" | ||
|
||
namespace JSC { namespace DFG { | ||
|
||
bool DesiredObjectProperties::addLazily(JSObject* object, PropertyOffset offset, JSValue value, Structure* structure) | ||
{ | ||
auto result = m_properties.add(std::tuple { object, offset }, std::tuple { value, structure }); | ||
if (result.isNewEntry) | ||
return true; | ||
auto [expectedValue, expectedStructure] = result.iterator->value; | ||
return expectedValue == value && expectedStructure == structure; | ||
} | ||
|
||
// Ultimately, we can use the code when | ||
// 1. the main thread's object is holding an expected structure. | ||
// 2. the main thread's object's property is expected one. | ||
bool DesiredObjectProperties::areStillValidOnMainThread(VM&) | ||
{ | ||
for (auto& [key, values] : m_properties) { | ||
auto [object, offset] = key; | ||
auto [expectedValue, expectedStructure] = values; | ||
|
||
Structure* structure = object->structure(); | ||
|
||
if (UNLIKELY(structure != expectedStructure)) | ||
return false; | ||
|
||
if (UNLIKELY(!structure->isValidOffset(offset))) | ||
return false; | ||
|
||
JSValue value = object->getDirect(offset); | ||
if (UNLIKELY(value != expectedValue)) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} } // namespace JSC::DFG | ||
|
||
#endif // ENABLE(DFG_JIT) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2023 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if ENABLE(DFG_JIT) | ||
|
||
#include "DFGFrozenValue.h" | ||
#include "DFGStructureAbstractValue.h" | ||
#include <wtf/HashMap.h> | ||
|
||
namespace JSC { | ||
|
||
class CodeBlock; | ||
class VM; | ||
|
||
namespace DFG { | ||
|
||
class CommonData; | ||
class WatchpointCollector; | ||
|
||
class DesiredObjectProperties { | ||
public: | ||
bool addLazily(JSObject*, PropertyOffset, JSValue, Structure*); | ||
bool areStillValidOnMainThread(VM&); | ||
|
||
private: | ||
HashMap<std::tuple<JSObject*, PropertyOffset>, std::tuple<JSValue, Structure*>> m_properties; | ||
}; | ||
|
||
} } // namespace JSC::DFG | ||
|
||
#endif // ENABLE(DFG_JIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters