Title: [290449] trunk/Source/_javascript_Core
- Revision
- 290449
- Author
- [email protected]
- Date
- 2022-02-24 12:08:49 -0800 (Thu, 24 Feb 2022)
Log Message
[Cocoa] Only clear ICU cache when time zone is changed
https://bugs.webkit.org/show_bug.cgi?id=236996
Reviewed by Yusuke Suzuki.
We used to unconditionally invalidate the VM's DateCache in VMEntryScope in order to
make sure we always used the latest time zone from the host machine (in case it changed).
This overly aggressive invalidation was causing us to repeatedly go to the disk in order
to determine the host time zone. On Cocoa ports, we now listen to the
kCFTimeZoneSystemTimeZoneDidChangeNotification notification and only invalidate the
VM's DateCache in VMEntryScope if the host time zone has actually changed since the
last time.
* runtime/JSDateMath.cpp:
(JSC::timeZoneChangeNotification):
(JSC::DateCache::DateCache):
(JSC::DateCache::resetIfNecessary):
(JSC::DateCache::reset): Deleted.
* runtime/JSDateMath.h:
* runtime/VM.h:
(JSC::VM::resetDateCacheIfNecessary):
(JSC::VM::resetDateCache): Deleted.
* runtime/VMEntryScope.cpp:
(JSC::VMEntryScope::VMEntryScope):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (290448 => 290449)
--- trunk/Source/_javascript_Core/ChangeLog 2022-02-24 19:58:41 UTC (rev 290448)
+++ trunk/Source/_javascript_Core/ChangeLog 2022-02-24 20:08:49 UTC (rev 290449)
@@ -1,3 +1,30 @@
+2022-02-24 Chris Dumez <[email protected]>
+
+ [Cocoa] Only clear ICU cache when time zone is changed
+ https://bugs.webkit.org/show_bug.cgi?id=236996
+
+ Reviewed by Yusuke Suzuki.
+
+ We used to unconditionally invalidate the VM's DateCache in VMEntryScope in order to
+ make sure we always used the latest time zone from the host machine (in case it changed).
+ This overly aggressive invalidation was causing us to repeatedly go to the disk in order
+ to determine the host time zone. On Cocoa ports, we now listen to the
+ kCFTimeZoneSystemTimeZoneDidChangeNotification notification and only invalidate the
+ VM's DateCache in VMEntryScope if the host time zone has actually changed since the
+ last time.
+
+ * runtime/JSDateMath.cpp:
+ (JSC::timeZoneChangeNotification):
+ (JSC::DateCache::DateCache):
+ (JSC::DateCache::resetIfNecessary):
+ (JSC::DateCache::reset): Deleted.
+ * runtime/JSDateMath.h:
+ * runtime/VM.h:
+ (JSC::VM::resetDateCacheIfNecessary):
+ (JSC::VM::resetDateCache): Deleted.
+ * runtime/VMEntryScope.cpp:
+ (JSC::VMEntryScope::VMEntryScope):
+
2022-02-24 Geza Lore <[email protected]>
[JSC] Respect bytecode alignment in BytecodeRewriter
Modified: trunk/Source/_javascript_Core/runtime/JSDateMath.cpp (290448 => 290449)
--- trunk/Source/_javascript_Core/runtime/JSDateMath.cpp 2022-02-24 19:58:41 UTC (rev 290448)
+++ trunk/Source/_javascript_Core/runtime/JSDateMath.cpp 2022-02-24 20:08:49 UTC (rev 290449)
@@ -97,6 +97,7 @@
namespace JSC {
+static std::atomic<uint64_t> lastTimeZoneID { 1 };
#if HAVE(ICU_C_TIMEZONE_API)
class OpaqueICUTimeZone {
@@ -351,8 +352,25 @@
#endif
}
+#if PLATFORM(COCOA)
+static void timeZoneChangeNotification(CFNotificationCenterRef, void*, CFStringRef, const void*, CFDictionaryRef)
+{
+ ASSERT(isMainThread());
+ ++lastTimeZoneID;
+}
+#endif
+
// To confine icu::TimeZone destructor invocation in this file.
-DateCache::DateCache() = default;
+DateCache::DateCache()
+{
+#if PLATFORM(COCOA)
+ static std::once_flag onceKey;
+ std::call_once(onceKey, [&] {
+ CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), nullptr, timeZoneChangeNotification, kCFTimeZoneSystemTimeZoneDidChangeNotification, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately);
+ });
+#endif
+}
+
DateCache::~DateCache() = default;
Ref<DateInstanceData> DateCache::cachedDateInstanceData(double millisecondsFromEpoch)
@@ -390,8 +408,16 @@
#endif
}
-void DateCache::reset()
+void DateCache::resetIfNecessary()
{
+#if PLATFORM(COCOA)
+ if (m_cachedTimezoneID == lastTimeZoneID)
+ return;
+ m_cachedTimezoneID = lastTimeZoneID;
+#endif
+
+ // FIXME: We should clear it only when we know the timezone has been changed on Non-Cocoa platforms.
+ // https://bugs.webkit.org/show_bug.cgi?id=218365
m_timeZoneCache.reset();
m_utcTimeOffsetCache = LocalTimeOffsetCache();
m_localTimeOffsetCache = LocalTimeOffsetCache();
Modified: trunk/Source/_javascript_Core/runtime/JSDateMath.h (290448 => 290449)
--- trunk/Source/_javascript_Core/runtime/JSDateMath.h 2022-02-24 19:58:41 UTC (rev 290448)
+++ trunk/Source/_javascript_Core/runtime/JSDateMath.h 2022-02-24 20:08:49 UTC (rev 290449)
@@ -77,7 +77,7 @@
DateCache();
~DateCache();
- JS_EXPORT_PRIVATE void reset();
+ JS_EXPORT_PRIVATE void resetIfNecessary();
String defaultTimeZone();
@@ -87,6 +87,8 @@
double gregorianDateTimeToMS(const GregorianDateTime&, double milliseconds, WTF::TimeType inputTimeType);
JS_EXPORT_PRIVATE double parseDate(JSGlobalObject*, VM&, const WTF::String&);
+ static void timeZoneChanged();
+
private:
void timeZoneCacheSlow();
LocalTimeOffset localTimeOffset(double millisecondsFromEpoch, WTF::TimeType inputTimeType = WTF::UTCTime);
@@ -105,6 +107,7 @@
String m_cachedDateString;
double m_cachedDateStringValue;
DateInstanceCache m_dateInstanceCache;
+ uint64_t m_cachedTimezoneID { 0 };
};
ALWAYS_INLINE bool isUTCEquivalent(StringView timeZone)
Modified: trunk/Source/_javascript_Core/runtime/VM.h (290448 => 290449)
--- trunk/Source/_javascript_Core/runtime/VM.h 2022-02-24 19:58:41 UTC (rev 290448)
+++ trunk/Source/_javascript_Core/runtime/VM.h 2022-02-24 20:08:49 UTC (rev 290449)
@@ -733,7 +733,7 @@
RTTraceList* m_rtTraceList;
#endif
- void resetDateCache() { dateCache.reset(); }
+ void resetDateCacheIfNecessary() { dateCache.resetIfNecessary(); }
RegExpCache* regExpCache() { return m_regExpCache; }
#if ENABLE(REGEXP_TRACING)
Modified: trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp (290448 => 290449)
--- trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp 2022-02-24 19:58:41 UTC (rev 290448)
+++ trunk/Source/_javascript_Core/runtime/VMEntryScope.cpp 2022-02-24 20:08:49 UTC (rev 290449)
@@ -56,9 +56,7 @@
// Reset the date cache between JS invocations to force the VM to
// observe time zone changes.
- // FIXME: We should clear it only when we know the timezone has been changed.
- // https://bugs.webkit.org/show_bug.cgi?id=218365
- vm.resetDateCache();
+ vm.resetDateCacheIfNecessary();
if (vm.watchdog())
vm.watchdog()->enteredVM();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes