Title: [219506] trunk/Source
Revision
219506
Author
[email protected]
Date
2017-07-14 09:03:47 -0700 (Fri, 14 Jul 2017)

Log Message

[WTF] Use std::unique_ptr for StackTrace
https://bugs.webkit.org/show_bug.cgi?id=174495

Reviewed by Alex Christensen.

Source/_javascript_Core:

* runtime/ExceptionScope.cpp:
(JSC::ExceptionScope::unexpectedExceptionMessage):
* runtime/VM.cpp:
(JSC::VM::throwException):

Source/WTF:

Instead of returning pointer to heap allocated StackTrace,
we should return std::unique_ptr<StackTrace>.
And we also move WTFGetBackTrace from Assertions.cpp to
StackTrace.cpp to consolidate stack trace related operations
into StackTrace.cpp.

* wtf/Assertions.cpp:
* wtf/StackTrace.cpp:
(WTFGetBacktrace):
(WTF::StackTrace::captureStackTrace):
* wtf/StackTrace.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (219505 => 219506)


--- trunk/Source/_javascript_Core/ChangeLog	2017-07-14 15:58:47 UTC (rev 219505)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-07-14 16:03:47 UTC (rev 219506)
@@ -1,5 +1,17 @@
 2017-07-14  Yusuke Suzuki  <[email protected]>
 
+        [WTF] Use std::unique_ptr for StackTrace
+        https://bugs.webkit.org/show_bug.cgi?id=174495
+
+        Reviewed by Alex Christensen.
+
+        * runtime/ExceptionScope.cpp:
+        (JSC::ExceptionScope::unexpectedExceptionMessage):
+        * runtime/VM.cpp:
+        (JSC::VM::throwException):
+
+2017-07-14  Yusuke Suzuki  <[email protected]>
+
         [JSC] Use WTFMove to prune liveness in DFGAvailabilityMap
         https://bugs.webkit.org/show_bug.cgi?id=174423
 

Modified: trunk/Source/_javascript_Core/runtime/ExceptionScope.cpp (219505 => 219506)


--- trunk/Source/_javascript_Core/runtime/ExceptionScope.cpp	2017-07-14 15:58:47 UTC (rev 219505)
+++ trunk/Source/_javascript_Core/runtime/ExceptionScope.cpp	2017-07-14 16:03:47 UTC (rev 219506)
@@ -56,7 +56,7 @@
     StringPrintStream out;
 
     out.println("Unexpected exception observed on thread ", currentThread(), " at:");
-    auto currentStack = std::unique_ptr<StackTrace>(StackTrace::captureStackTrace(Options::unexpectedExceptionStackTraceLimit(), 1));
+    auto currentStack = StackTrace::captureStackTrace(Options::unexpectedExceptionStackTraceLimit(), 1);
     currentStack->dump(out, "    ");
 
     if (!m_vm.nativeStackTraceOfLastThrow())

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (219505 => 219506)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2017-07-14 15:58:47 UTC (rev 219505)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2017-07-14 16:03:47 UTC (rev 219506)
@@ -600,7 +600,7 @@
     setException(exception);
 
 #if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
-    m_nativeStackTraceOfLastThrow = std::unique_ptr<StackTrace>(StackTrace::captureStackTrace(Options::unexpectedExceptionStackTraceLimit()));
+    m_nativeStackTraceOfLastThrow = StackTrace::captureStackTrace(Options::unexpectedExceptionStackTraceLimit());
     m_throwingThread = currentThread();
 #endif
 }

Modified: trunk/Source/WTF/ChangeLog (219505 => 219506)


--- trunk/Source/WTF/ChangeLog	2017-07-14 15:58:47 UTC (rev 219505)
+++ trunk/Source/WTF/ChangeLog	2017-07-14 16:03:47 UTC (rev 219506)
@@ -1,3 +1,22 @@
+2017-07-14  Yusuke Suzuki  <[email protected]>
+
+        [WTF] Use std::unique_ptr for StackTrace
+        https://bugs.webkit.org/show_bug.cgi?id=174495
+
+        Reviewed by Alex Christensen.
+
+        Instead of returning pointer to heap allocated StackTrace,
+        we should return std::unique_ptr<StackTrace>.
+        And we also move WTFGetBackTrace from Assertions.cpp to
+        StackTrace.cpp to consolidate stack trace related operations
+        into StackTrace.cpp.
+
+        * wtf/Assertions.cpp:
+        * wtf/StackTrace.cpp:
+        (WTFGetBacktrace):
+        (WTF::StackTrace::captureStackTrace):
+        * wtf/StackTrace.h:
+
 2017-07-13  Yusuke Suzuki  <[email protected]>
 
         Unreviewed, annotate inline for operator==/!= for FastAllocator

Modified: trunk/Source/WTF/wtf/Assertions.cpp (219505 => 219506)


--- trunk/Source/WTF/wtf/Assertions.cpp	2017-07-14 15:58:47 UTC (rev 219505)
+++ trunk/Source/WTF/wtf/Assertions.cpp	2017-07-14 16:03:47 UTC (rev 219506)
@@ -74,10 +74,6 @@
 #include <unistd.h>
 #endif
 
-#if HAVE(BACKTRACE)
-#include <execinfo.h>
-#endif
-
 extern "C" {
 
 static void logToStderr(const char* buffer)
@@ -247,17 +243,6 @@
     }
 };
 
-void WTFGetBacktrace(void** stack, int* size)
-{
-#if HAVE(BACKTRACE)
-    *size = backtrace(stack, *size);
-#elif OS(WINDOWS)
-    *size = RtlCaptureStackBackTrace(0, *size, stack, 0);
-#else
-    *size = 0;
-#endif
-}
-
 void WTFReportBacktrace()
 {
     static const int framesToShow = 31;

Modified: trunk/Source/WTF/wtf/StackTrace.cpp (219505 => 219506)


--- trunk/Source/WTF/wtf/StackTrace.cpp	2017-07-14 15:58:47 UTC (rev 219505)
+++ trunk/Source/WTF/wtf/StackTrace.cpp	2017-07-14 16:03:47 UTC (rev 219506)
@@ -30,7 +30,7 @@
 #include <wtf/Assertions.h>
 #include <wtf/PrintStream.h>
 
-#if HAVE(BACKTRACE_SYMBOLS)
+#if HAVE(BACKTRACE_SYMBOLS) || HAVE(BACKTRACE)
 #include <execinfo.h>
 #endif
 
@@ -39,6 +39,21 @@
 #include <dlfcn.h>
 #endif
 
+#if OS(WINDOWS)
+#include <windows.h>
+#endif
+
+void WTFGetBacktrace(void** stack, int* size)
+{
+#if HAVE(BACKTRACE)
+    *size = backtrace(stack, *size);
+#elif OS(WINDOWS)
+    *size = RtlCaptureStackBackTrace(0, *size, stack, 0);
+#else
+    *size = 0;
+#endif
+}
+
 namespace WTF {
 
 ALWAYS_INLINE size_t StackTrace::instanceSize(int capacity)
@@ -47,11 +62,11 @@
     return sizeof(StackTrace) + (capacity - 1) * sizeof(void*);
 }
 
-StackTrace* StackTrace::captureStackTrace(int maxFrames, int framesToSkip)
+std::unique_ptr<StackTrace> StackTrace::captureStackTrace(int maxFrames, int framesToSkip)
 {
     maxFrames = std::max(1, maxFrames);
     size_t sizeToAllocate = instanceSize(maxFrames);
-    StackTrace* trace = new (NotNull, fastMalloc(sizeToAllocate)) StackTrace();
+    std::unique_ptr<StackTrace> trace(new (NotNull, fastMalloc(sizeToAllocate)) StackTrace());
 
     // Skip 2 additional frames i.e. StackTrace::captureStackTrace and WTFGetBacktrace.
     framesToSkip += 2;

Modified: trunk/Source/WTF/wtf/StackTrace.h (219505 => 219506)


--- trunk/Source/WTF/wtf/StackTrace.h	2017-07-14 15:58:47 UTC (rev 219505)
+++ trunk/Source/WTF/wtf/StackTrace.h	2017-07-14 16:03:47 UTC (rev 219506)
@@ -36,7 +36,7 @@
 class StackTrace {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    WTF_EXPORT_PRIVATE static StackTrace* captureStackTrace(int maxFrames, int framesToSkip = 0);
+    WTF_EXPORT_PRIVATE static std::unique_ptr<StackTrace> captureStackTrace(int maxFrames, int framesToSkip = 0);
 
     // Borrowed stack trace.
     StackTrace(void** stack, int size)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to