Source/JavaScriptCore/ChangeLog

 12020-02-18 Keith Miller <keith_miller@apple.com>
 2
 3 Add an os_log PrintStream
 4 https://bugs.webkit.org/show_bug.cgi?id=207898
 5
 6 Reviewed by Mark Lam.
 7
 8 Add jsc option to write dataLogs to os_log.
 9
 10 * runtime/Options.cpp:
 11 (JSC::Options::initialize):
 12 * runtime/OptionsList.h:
 13
1142020-02-18 Paulo Matos <pmatos@igalia.com>
215
316 Fix order (in MIPS) under which CS-registers are saved/restored

Source/WTF/ChangeLog

 12020-02-18 Keith Miller <keith_miller@apple.com>
 2
 3 Add an os_log PrintStream
 4 https://bugs.webkit.org/show_bug.cgi?id=207898
 5
 6 Reviewed by Mark Lam.
 7
 8 When debugging on iOS writing to a file can be hard (thanks
 9 Sandboxing!) so logging our dataLogs to os_log would make things
 10 easier. This patch adds a new subclass of PrintStream,
 11 OSLogPrintStream, that converts our file writes to
 12 os_log. Unfortunately, os_log doesn't buffer writes so
 13 OSLogPrintStream needs to do its own buffering. e.g. if you call
 14 `dataLogLn("some text with a ", number, " and a ", string);`
 15 os_log will log that as 5 separate logs.
 16
 17 * WTF.xcodeproj/project.pbxproj:
 18 * wtf/CMakeLists.txt:
 19 * wtf/DataLog.cpp:
 20 (WTF::setDataFile):
 21 * wtf/DataLog.h:
 22 * wtf/OSLogPrintStream.cpp: Added.
 23 (WTF::OSLogPrintStream::OSLogPrintStream):
 24 (WTF::OSLogPrintStream::~OSLogPrintStream):
 25 (WTF::OSLogPrintStream::open):
 26 (WTF::OSLogPrintStream::vprintf):
 27 * wtf/OSLogPrintStream.h: Copied from Source/WTF/wtf/DataLog.h.
 28 * wtf/PrintStream.cpp:
 29 (WTF::printExpectedCStringHelper):
 30 (WTF::printInternal):
 31 * wtf/text/CString.cpp:
 32 (WTF::CString::grow):
 33 * wtf/text/CString.h:
 34
1352020-02-18 Simon Fraser <simon.fraser@apple.com>
236
337 Move from "layer flush" terminology to "rendering update"

Source/JavaScriptCore/runtime/Options.cpp

4242#include <wtf/DataLog.h>
4343#include <wtf/NumberOfCores.h>
4444#include <wtf/Optional.h>
 45#include <wtf/OSLogPrintStream.h>
4546#include <wtf/PointerPreparations.h>
4647#include <wtf/StdLibExtras.h>
4748#include <wtf/text/StringBuilder.h>

@@void Options::initialize()
613614 handleSignalsWithMach();
614615#endif
615616
 617#if OS(DARWIN)
 618 if (Options::useOSLog()) {
 619 WTF::setDataFile(OSLogPrintStream::open("com.apple.JavaScriptCore", "DataLog", OS_LOG_TYPE_INFO));
 620 // Make sure no one jumped here for nefarious reasons...
 621 RELEASE_ASSERT(useOSLog());
 622 }
 623#endif
 624
616625#if ASAN_ENABLED && OS(LINUX) && ENABLE(WEBASSEMBLY_FAST_MEMORY)
617626 if (Options::useWebAssemblyFastMemory()) {
618627 const char* asanOptions = getenv("ASAN_OPTIONS");

Source/JavaScriptCore/runtime/OptionsList.h

@@constexpr bool enableWebAssemblyStreamingApi = false;
119119 v(Unsigned, shadowChickenLogSize, 1000, Normal, nullptr) \
120120 v(Unsigned, shadowChickenMaxTailDeletedFramesSize, 128, Normal, nullptr) \
121121 \
 122 v(Bool, useOSLog, false, Normal, "Log dataLog()s to os_log instead of stderr") \
122123 /* dumpDisassembly implies dumpDFGDisassembly. */ \
123124 v(Bool, dumpDisassembly, false, Normal, "dumps disassembly of all JIT compiled code upon compilation") \
124125 v(Bool, asyncDisassembly, false, Normal, nullptr) \

Source/WTF/WTF.xcodeproj/project.pbxproj

7878 5311BD531EA71CAD00525281 /* Signals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5311BD511EA71CAD00525281 /* Signals.cpp */; };
7979 5311BD5C1EA822F900525281 /* ThreadMessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5311BD5B1EA822F900525281 /* ThreadMessage.cpp */; };
8080 53534F2A1EC0E10E00141B2F /* MachExceptions.defs in Sources */ = {isa = PBXBuildFile; fileRef = 53534F291EC0E10E00141B2F /* MachExceptions.defs */; settings = {ATTRIBUTES = (Client, Server, ); }; };
 81 53FC70D023FB950C005B1990 /* OSLogPrintStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FC70CF23FB950C005B1990 /* OSLogPrintStream.cpp */; };
8182 5C1F05932164356B0039302C /* CFURLExtras.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C1F05912164356B0039302C /* CFURLExtras.cpp */; };
8283 5C1F0595216437B30039302C /* URLCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C1F0594216437B30039302C /* URLCF.cpp */; };
8384 5CC0EE7521629F1900A1A842 /* URLParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5CC0EE7321629F1900A1A842 /* URLParser.cpp */; };

399400 53EC253C1E95AD30000831B9 /* PriorityQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PriorityQueue.h; sourceTree = "<group>"; };
400401 53F08A1BA39D49A8BAD369A1 /* StdSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdSet.h; sourceTree = "<group>"; };
401402 53F1D98620477B9800EBC6BF /* FunctionTraits.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = FunctionTraits.h; sourceTree = "<group>"; };
 403 53FC70CE23FB950C005B1990 /* OSLogPrintStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSLogPrintStream.h; sourceTree = "<group>"; };
 404 53FC70CF23FB950C005B1990 /* OSLogPrintStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OSLogPrintStream.cpp; sourceTree = "<group>"; };
402405 553071C91C40427200384898 /* TinyLRUCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TinyLRUCache.h; sourceTree = "<group>"; };
403406 5597F82C1D94B9970066BC21 /* SynchronizedFixedQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SynchronizedFixedQueue.h; sourceTree = "<group>"; };
404407 5B43383A5D0B463C9433D933 /* IndexMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexMap.h; sourceTree = "<group>"; };

11121115 275DFB6B238BDF72001230E2 /* OptionSetHash.h */,
11131116 0F9495831C571CC900413A48 /* OrderMaker.h */,
11141117 A8A472D7151A825B004123FF /* OSAllocator.h */,
 1118 53FC70CF23FB950C005B1990 /* OSLogPrintStream.cpp */,
 1119 53FC70CE23FB950C005B1990 /* OSLogPrintStream.h */,
11151120 7CBBA07319BB7FDC00BBF025 /* OSObjectPtr.h */,
11161121 A8A472DA151A825B004123FF /* OSRandomSource.cpp */,
11171122 A8A472DB151A825B004123FF /* OSRandomSource.h */,

16641669 A8A473F4151A825B004123FF /* NumberOfCores.cpp in Sources */,
16651670 8348BA0E21FBC0D500FD3054 /* ObjectIdentifier.cpp in Sources */,
16661671 A3EE5C3A21FFAC5F00FABD61 /* OSAllocatorPOSIX.cpp in Sources */,
 1672 53FC70D023FB950C005B1990 /* OSLogPrintStream.cpp in Sources */,
16671673 A8A473F9151A825B004123FF /* OSRandomSource.cpp in Sources */,
16681674 A8A47402151A825B004123FF /* PageBlock.cpp in Sources */,
16691675 0FFF19DC1BB334EB00886D91 /* ParallelHelperPool.cpp in Sources */,

Source/WTF/wtf/CMakeLists.txt

@@set(WTF_PUBLIC_HEADERS
148148 NotFound.h
149149 NumberOfCores.h
150150 OSAllocator.h
 151 OSLogPrintStream.h
151152 OSObjectPtr.h
152153 OSRandomSource.h
153154 ObjCRuntimeExtras.h

@@set(WTF_SOURCES
400401 MetaAllocator.cpp
401402 MonotonicTime.cpp
402403 NumberOfCores.cpp
 404 OSLogPrintStream.cpp
403405 OSRandomSource.cpp
404406 ObjectIdentifier.cpp
405407 PageBlock.cpp

Source/WTF/wtf/DataLog.cpp

@@void setDataFile(const char* path)
166166 s_file = new (s_lockedFileData) LockedPrintStream(std::unique_ptr<FilePrintStream>(file));
167167}
168168
 169void setDataFile(std::unique_ptr<PrintStream>&& file)
 170{
 171 s_file = file.release();
 172}
 173
169174PrintStream& dataFile()
170175{
171176 initializeLogFile();

Source/WTF/wtf/DataLog.h

@@namespace WTF {
3434
3535WTF_EXPORT_PRIVATE PrintStream& dataFile();
3636WTF_EXPORT_PRIVATE void setDataFile(const char* path);
 37WTF_EXPORT_PRIVATE void setDataFile(std::unique_ptr<PrintStream>&&);
3738
3839WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
3940WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);

Source/WTF/wtf/OSLogPrintStream.cpp

 1/*
 2 * Copyright (C) 2020 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include <wtf/OSLogPrintStream.h>
 28
 29#include <wtf/StringPrintStream.h>
 30
 31namespace WTF {
 32
 33#if OS(DARWIN)
 34
 35OSLogPrintStream::OSLogPrintStream(os_log_t log, os_log_type_t logType)
 36 : m_log(log)
 37 , m_logType(logType)
 38 , m_string("initial string... lol")
 39{
 40}
 41
 42OSLogPrintStream::~OSLogPrintStream()
 43{ }
 44
 45std::unique_ptr<OSLogPrintStream> OSLogPrintStream::open(const char* subsystem, const char* category, os_log_type_t logType)
 46{
 47 os_log_t log = os_log_create(subsystem, category);
 48 return makeUnique<OSLogPrintStream>(log, logType);
 49}
 50
 51void OSLogPrintStream::vprintf(const char* format, va_list argList)
 52{
 53 auto lock = holdLock(m_stringLock);
 54 size_t offset = m_offset;
 55 size_t freeBytes = m_string.length() - offset;
 56 va_list backup;
 57 va_copy(backup, argList);
 58 size_t bytesWritten = vsnprintf(m_string.mutableData() + offset, freeBytes, format, argList);
 59 if (UNLIKELY(bytesWritten >= freeBytes)) {
 60 size_t newLength = std::max(bytesWritten + m_string.length(), m_string.length() * 2);
 61 m_string.grow(newLength);
 62 freeBytes = newLength - offset;
 63 bytesWritten = vsnprintf(m_string.mutableData() + offset, freeBytes, format, backup);
 64 ASSERT(bytesWritten < freeBytes);
 65 }
 66
 67 size_t newOffset = offset + bytesWritten;
 68 char* buffer = m_string.mutableData();
 69 bool loggedText = false;
 70 do {
 71 if (buffer[offset] == '\n') {
 72 // Set the new line to a null character so os_log stops copying there.
 73 buffer[offset] = '\0';
 74 os_log_with_type(m_log, m_logType, "%{public}s", buffer);
 75 buffer += offset + 1;
 76 newOffset -= offset + 1;
 77 offset = 0;
 78 loggedText = true;
 79 } else
 80 offset++;
 81 } while (offset < newOffset);
 82
 83 if (loggedText)
 84 memmove(m_string.mutableData(), buffer, newOffset);
 85 m_offset = newOffset;
 86}
 87
 88#endif
 89
 90} // namespace WTF
 91

Source/WTF/wtf/OSLogPrintStream.h

 1/*
 2 * Copyright (C) 2020 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#if OS(DARWIN)
 29
 30#include <wtf/Lock.h>
 31#include <wtf/PrintStream.h>
 32#include <wtf/RecursiveLockAdapter.h>
 33#include <wtf/text/CString.h>
 34#include <wtf/Vector.h>
 35
 36#include <os/log.h>
 37
 38namespace WTF {
 39
 40class WTF_EXPORT_PRIVATE OSLogPrintStream final : public PrintStream {
 41public:
 42 OSLogPrintStream(os_log_t, os_log_type_t);
 43 virtual ~OSLogPrintStream();
 44
 45 static std::unique_ptr<OSLogPrintStream> open(const char* subsystem, const char* category, os_log_type_t = OS_LOG_TYPE_DEFAULT);
 46
 47 void vprintf(const char* format, va_list) override WTF_ATTRIBUTE_PRINTF(2, 0);
 48
 49private:
 50 os_log_t m_log;
 51 os_log_type_t m_logType;
 52 Lock m_stringLock;
 53 // We need a buffer because os_log doesn't wait for a new line to print the characters.
 54 CString m_string;
 55 size_t m_offset { 0 };
 56};
 57
 58} // namespace WTF
 59
 60using WTF::OSLogPrintStream;
 61
 62#endif

Source/WTF/wtf/PrintStream.cpp

@@void printInternal(PrintStream& out, const char* string)
7777static void printExpectedCStringHelper(PrintStream& out, const char* type, Expected<CString, UTF8ConversionError> expectedCString)
7878{
7979 if (UNLIKELY(!expectedCString)) {
80  if (expectedCString.error() == UTF8ConversionError::OutOfMemory)
81  out.print("(Out of memory while converting ", type, " to utf8)");
82  else
83  out.print("(failed to convert ", type, " to utf8)");
 80 if (expectedCString.error() == UTF8ConversionError::OutOfMemory) {
 81 printInternal(out, "(Out of memory while converting ");
 82 printInternal(out, type);
 83 printInternal(out, " to utf8)");
 84 } else {
 85 printInternal(out, "(failed to convert ");
 86 printInternal(out, type);
 87 printInternal(out, " to utf8)");
 88 }
8489 return;
8590 }
86  out.print(expectedCString.value());
 91 printInternal(out, expectedCString.value());
8792}
8893
8994void printInternal(PrintStream& out, const StringView& string)

@@void printInternal(PrintStream& out, const StringView& string)
9398
9499void printInternal(PrintStream& out, const CString& string)
95100{
96  out.print(string.data());
 101 printInternal(out, string.data());
97102}
98103
99104void printInternal(PrintStream& out, const String& string)

@@void printInternal(PrintStream& out, const String& string)
104109void printInternal(PrintStream& out, const StringImpl* string)
105110{
106111 if (!string) {
107  out.print("(null StringImpl*)");
 112 printInternal(out, "(null StringImpl*)");
108113 return;
109114 }
110115 printExpectedCStringHelper(out, "StringImpl*", string->tryGetUtf8());

@@void printInternal(PrintStream& out, unsigned long long value)
167172
168173void printInternal(PrintStream& out, float value)
169174{
170  out.print(static_cast<double>(value));
 175 printInternal(out, static_cast<double>(value));
171176}
172177
173178void printInternal(PrintStream& out, double value)

Source/WTF/wtf/text/CString.cpp

@@bool CString::isSafeToSendToAnotherThread() const
106106 return !m_buffer || m_buffer->hasOneRef();
107107}
108108
 109void CString::grow(size_t newLength)
 110{
 111 ASSERT(newLength > length());
 112
 113 auto newBuffer = CStringBuffer::createUninitialized(newLength);
 114 memcpy(newBuffer->mutableData(), m_buffer->data(), length() + 1);
 115 m_buffer = WTFMove(newBuffer);
 116}
 117
109118bool operator==(const CString& a, const CString& b)
110119{
111120 if (a.isNull() != b.isNull())

Source/WTF/wtf/text/CString.h

@@public:
8484
8585 WTF_EXPORT_PRIVATE unsigned hash() const;
8686
 87 // Useful if you want your CString to hold dynamic data.
 88 WTF_EXPORT_PRIVATE void grow(size_t newLength);
 89
8790private:
8891 void copyBufferIfNeeded();
8992 void init(const char*, size_t length);