1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "BaseProfilingStack.h"
11 #include "mozilla/IntegerRange.h"
12 #include "mozilla/UniquePtr.h"
13 #include "mozilla/UniquePtrExtensions.h"
15 #include "BaseProfiler.h"
18 namespace baseprofiler
{
20 ProfilingStack::~ProfilingStack() {
21 // The label macros keep a reference to the ProfilingStack to avoid a TLS
22 // access. If these are somehow not all cleared we will get a
23 // use-after-free so better to crash now.
24 MOZ_RELEASE_ASSERT(stackPointer
== 0);
29 void ProfilingStack::ensureCapacitySlow() {
30 MOZ_ASSERT(stackPointer
>= capacity
);
31 const uint32_t kInitialCapacity
= 128;
33 uint32_t sp
= stackPointer
;
35 std::max(sp
+ 1, capacity
? capacity
* 2 : kInitialCapacity
);
37 auto* newFrames
= new ProfilingStackFrame
[newCapacity
];
39 // It's important that `frames` / `capacity` / `stackPointer` remain
40 // consistent here at all times.
41 for (auto i
: IntegerRange(capacity
)) {
42 newFrames
[i
] = frames
[i
];
45 ProfilingStackFrame
* oldFrames
= frames
;
47 capacity
= newCapacity
;
51 } // namespace baseprofiler
52 } // namespace mozilla