From ddff63b2d6c22468cd413c16968558f77fd00bb3 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Fri, 24 May 2019 13:58:13 +0300 Subject: add main thread only cache for nsIAtoms to speed up atomization xpcom/ds add main thread only cache for nsIAtoms to speed up atomization --- xpcom/ds/nsAtomTable.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++-- xpcom/ds/nsIAtom.idl | 5 +++++ 2 files changed, 57 insertions(+), 2 deletions(-) (limited to 'xpcom') diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 3dd3bd36c..c63676455 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -364,17 +364,31 @@ static const PLDHashTableOps AtomTableOps = { //---------------------------------------------------------------------- +#define RECENTLY_USED_MAIN_THREAD_ATOM_CACHE_SIZE 31 +static nsIAtom* + sRecentlyUsedMainThreadAtoms[RECENTLY_USED_MAIN_THREAD_ATOM_CACHE_SIZE] = {}; + + void DynamicAtom::GCAtomTable() { - MutexAutoLock lock(*gAtomTableLock); - GCAtomTableLocked(lock, GCKind::RegularOperation); + if (NS_IsMainThread()) { + MutexAutoLock lock(*gAtomTableLock); + GCAtomTableLocked(lock, GCKind::RegularOperation); + } } void DynamicAtom::GCAtomTableLocked(const MutexAutoLock& aProofOfLock, GCKind aKind) { + + MOZ_ASSERT(NS_IsMainThread()); + for (uint32_t i = 0; i < RECENTLY_USED_MAIN_THREAD_ATOM_CACHE_SIZE; ++i) { + sRecentlyUsedMainThreadAtoms[i] = nullptr; + } + + uint32_t removedCount = 0; // Use a non-atomic temporary for cheaper increments. nsAutoCString nonZeroRefcountAtoms; uint32_t nonZeroRefcountAtomsCount = 0; @@ -673,6 +687,8 @@ NS_Atomize(const nsACString& aUTF8String) return atom.forget(); } + + // This results in an extra addref/release of the nsStringBuffer. // Unfortunately there doesn't seem to be any APIs to avoid that. // Actually, now there is, sort of: ForgetSharedBuffer. @@ -712,6 +728,40 @@ NS_Atomize(const nsAString& aUTF16String) return atom.forget(); } +already_AddRefed +NS_AtomizeMainThread(const nsAString& aUTF16String) +{ + MOZ_ASSERT(NS_IsMainThread()); + nsCOMPtr retVal; + uint32_t hash; + AtomTableKey key(aUTF16String.Data(), aUTF16String.Length(), &hash); + uint32_t index = hash % RECENTLY_USED_MAIN_THREAD_ATOM_CACHE_SIZE; + nsIAtom* atom = + sRecentlyUsedMainThreadAtoms[index]; + if (atom) { + uint32_t length = atom->GetLength(); + if (length == key.mLength && + (memcmp(atom->GetUTF16String(), + key.mUTF16String, length * sizeof(char16_t)) == 0)) { + retVal = atom; + return retVal.forget(); + } + } + + MutexAutoLock lock(*gAtomTableLock); + AtomTableEntry* he = static_cast(gAtomTable->Add(&key)); + + if (he->mAtom) { + retVal = he->mAtom; + } else { + retVal = DynamicAtom::Create(aUTF16String, hash); + he->mAtom = retVal; + } + + sRecentlyUsedMainThreadAtoms[index] = retVal; + return retVal.forget(); +} + nsrefcnt NS_GetNumberOfAtoms(void) { diff --git a/xpcom/ds/nsIAtom.idl b/xpcom/ds/nsIAtom.idl index c02540838..6e8602c42 100644 --- a/xpcom/ds/nsIAtom.idl +++ b/xpcom/ds/nsIAtom.idl @@ -119,6 +119,11 @@ extern already_AddRefed NS_Atomize(const char16_t* aUTF16String); */ extern already_AddRefed NS_Atomize(const nsAString& aUTF16String); +/** + * An optimized version of the method above for the main thread. + */ +extern already_AddRefed NS_AtomizeMainThread(const nsAString& aUTF16String); + /** * Return a count of the total number of atoms currently * alive in the system. -- cgit v1.2.3 From 58ff91d97e90094e18ec335a5e19bbd95fff0bd9 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Fri, 24 May 2019 14:02:32 +0300 Subject: remove unnecessary spaces --- xpcom/ds/nsAtomTable.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'xpcom') diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index c63676455..4c93625ae 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -368,7 +368,6 @@ static const PLDHashTableOps AtomTableOps = { static nsIAtom* sRecentlyUsedMainThreadAtoms[RECENTLY_USED_MAIN_THREAD_ATOM_CACHE_SIZE] = {}; - void DynamicAtom::GCAtomTable() { @@ -388,7 +387,6 @@ DynamicAtom::GCAtomTableLocked(const MutexAutoLock& aProofOfLock, sRecentlyUsedMainThreadAtoms[i] = nullptr; } - uint32_t removedCount = 0; // Use a non-atomic temporary for cheaper increments. nsAutoCString nonZeroRefcountAtoms; uint32_t nonZeroRefcountAtomsCount = 0; @@ -687,8 +685,6 @@ NS_Atomize(const nsACString& aUTF8String) return atom.forget(); } - - // This results in an extra addref/release of the nsStringBuffer. // Unfortunately there doesn't seem to be any APIs to avoid that. // Actually, now there is, sort of: ForgetSharedBuffer. -- cgit v1.2.3 From 57e5655e8a3157c4691bfab4a98af169a2aa11d5 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 25 May 2019 16:08:16 +0200 Subject: Avoid some useless ForgetSkippable handling while we're already dealing with snow-white objects. --- xpcom/base/nsCycleCollector.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'xpcom') diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 06ed42326..5dffa7409 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -2832,6 +2832,11 @@ nsCycleCollector::ForgetSkippable(bool aRemoveChildlessNodes, { CheckThreadSafety(); + // Avoid this when we're aleady dealing with snow-white objects. + if (mFreeingSnowWhite) { + return; + } + mozilla::Maybe marker; if (NS_IsMainThread()) { marker.emplace("nsCycleCollector::ForgetSkippable", MarkerStackRequest::NO_STACK); -- cgit v1.2.3 From 733f6b770fcd7c2e5577bfb1fc738dc6ae5c3920 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Sat, 25 May 2019 18:02:40 +0300 Subject: use memcmp for nsIAtom Equals to improve performance xpcom/ds issue #1113 Use memcmp and not slower string Equals in nsHtml5Portability::localEqualsBuffer --- xpcom/ds/nsAtomTable.cpp | 8 +------- xpcom/ds/nsIAtom.idl | 10 ++++++++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'xpcom') diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 4c93625ae..c2e77e31f 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -325,13 +325,7 @@ AtomTableMatchKey(const PLDHashEntryHdr* aEntry, const void* aKey) nsDependentAtomString(he->mAtom)) == 0; } - uint32_t length = he->mAtom->GetLength(); - if (length != k->mLength) { - return false; - } - - return memcmp(he->mAtom->GetUTF16String(), - k->mUTF16String, length * sizeof(char16_t)) == 0; + return he->mAtom->Equals(k->mUTF16String, k->mLength); } static void diff --git a/xpcom/ds/nsIAtom.idl b/xpcom/ds/nsIAtom.idl index 6e8602c42..ce4cff485 100644 --- a/xpcom/ds/nsIAtom.idl +++ b/xpcom/ds/nsIAtom.idl @@ -37,9 +37,15 @@ interface nsIAtom : nsISupports size_t SizeOfIncludingThis(in MallocSizeOf aMallocSizeOf); %{C++ - // note this is NOT virtual so this won't muck with the vtable! + // note these are NOT virtual so they won't muck with the vtable! + inline bool Equals(char16ptr_t aString, uint32_t aLength) const + { + return mLength == aLength && + memcmp(mString, aString, mLength * sizeof(char16_t)) == 0; + } + inline bool Equals(const nsAString& aString) const { - return aString.Equals(nsDependentString(mString, mLength)); + return Equals(aString.BeginReading(), aString.Length()); } inline bool IsStaticAtom() const { -- cgit v1.2.3 From 21495c58976e3cbbfe54d2e54d1fd67e36dff2a6 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 29 May 2019 09:45:22 +0200 Subject: Treat *.jnlp as an executable class file, like *.jar --- xpcom/io/nsLocalFileWin.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'xpcom') diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index e73e15950..23c283f95 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -3034,6 +3034,7 @@ nsLocalFile::IsExecutable(bool* aResult) "ins", "isp", "jar", // java application bundle + "jnlp", // java web start "js", "jse", "lnk", -- cgit v1.2.3 From 32e6b0f4711cd65ec513f3f3aa64779293b458be Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 28 Jun 2019 19:47:49 +0200 Subject: Revert "Treat *.jnlp as an executable class file, like *.jar" Rationale: This was a Mozilla oversight and/or error. This change has caused harm and is causing users to switch back to Chrome, Safari or Edge for their WebStart needs. JNLP is not an executable and should not be treated as such. JNLP should be treated the same as any (e.g. Word) document and allowed to be opened with the designated program. A JNLP file will not cause execution on a system unless it has a valid signature, and the user explicitly authorizes the launching based on information provided by the signature. Moreover, there will even be a check by the Java environment to see if the Java runtime (if there is one) is current, and prompt the user to update if required. This reverts commit 21495c58976e3cbbfe54d2e54d1fd67e36dff2a6 and modifies ApplicationReputation.cpp to keep the list in sync (was a discrepancy before). --- xpcom/io/nsLocalFileWin.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'xpcom') diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index 23c283f95..e73e15950 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -3034,7 +3034,6 @@ nsLocalFile::IsExecutable(bool* aResult) "ins", "isp", "jar", // java application bundle - "jnlp", // java web start "js", "jse", "lnk", -- cgit v1.2.3