Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JSC] Add VectorTraits for WriteBarrier #2492

Conversation

Constellation
Copy link
Member

@Constellation Constellation commented Jul 17, 2022

1eb3c9f

[JSC] Add VectorTraits for WriteBarrier
https://bugs.webkit.org/show_bug.cgi?id=196242

Reviewed by Darin Adler.

WriteBarrier<> is one of the most frequently used class for Vector etc. in JSC.
Let's add VectorTraits for that.

* Source/JavaScriptCore/runtime/WriteBarrier.h:

Canonical link: https://commits.webkit.org/252556@main

@Constellation Constellation requested a review from a team as a code owner July 17, 2022 00:26
@Constellation Constellation self-assigned this Jul 17, 2022
@Constellation Constellation added JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. WebKit Nightly Build labels Jul 17, 2022
@webkit-early-warning-system webkit-early-warning-system added the merging-blocked Applied to prevent a change from being merged label Jul 17, 2022

template<typename T> struct VectorTraits<JSC::WriteBarrier<T>> : public SimpleClassVectorTraits {
static_assert(std::is_trivially_destructible<JSC::WriteBarrier<T>>::value);
static const bool canInitializeWithMemset = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since canInitializeWithMemset is already true in the base class, I think we should omit this line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Fixed.

template<> struct VectorTraits<JSC::WriteBarrier<JSC::Unknown>> : public SimpleClassVectorTraits {
static_assert(std::is_trivially_destructible<JSC::WriteBarrier<JSC::Unknown>>::value);
#if USE(JSVALUE64)
// We can memset only in JSVALUE64 since empty value is zero. On the other hand, JSVALUE32_64's empty value is not zero.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is great but code should be #if !USE(JSVALUE64) and only include setting to false, rely on inheritance for the true case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed.

static const bool canInitializeWithMemset = false;
#endif
static const bool canCopyWithMemcpy = true;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also set canCompareWithMemcmp to true? Also seems like operator== for two WriteBarrier<Unknown> should not decode the two values, just compare them still encoded.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rigt, changed :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, canCompareWithMemcmp was true since SimpleClassVectorTraits is setting it to true :)

@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jul 18, 2022
@Constellation Constellation force-pushed the eng/JSC-Add-VectorTraits-for-WriteBarrier branch from b96371f to 61499f2 Compare July 18, 2022 01:02
@Constellation Constellation added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 18, 2022
https://bugs.webkit.org/show_bug.cgi?id=196242

Reviewed by Darin Adler.

WriteBarrier<> is one of the most frequently used class for Vector etc. in JSC.
Let's add VectorTraits for that.

* Source/JavaScriptCore/runtime/WriteBarrier.h:

Canonical link: https://commits.webkit.org/252556@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/JSC-Add-VectorTraits-for-WriteBarrier branch from 61499f2 to 1eb3c9f Compare July 18, 2022 02:59
@webkit-early-warning-system webkit-early-warning-system merged commit 1eb3c9f into WebKit:main Jul 18, 2022
@webkit-commit-queue
Copy link
Collaborator

Committed 252556@main (1eb3c9f): https://commits.webkit.org/252556@main

Reviewed commits have been landed. Closing PR #2492 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 18, 2022

template<typename T> struct VectorTraits<JSC::WriteBarrier<T>> : public SimpleClassVectorTraits {
static_assert(std::is_trivially_destructible<JSC::WriteBarrier<T>>::value);
static constexpr bool canCopyWithMemcpy = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Constellation Isn't this wrong? My understanding is that memcpy is free to use load/store instructions with fewer than 8 bytes, which would cause GC tearing. I know we do something special for some copies, what is the current state of that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.
Projects
None yet
5 participants