Bug 1338374 - Use alignas rather than AlignedStorage for public JS::ProfilingFrameIterator's internal storage of a private wasm or JIT profiling frame iterator. r=shu

--HG--
extra : rebase_source : e8dac94d34a0985c1abca87b6e017387b761a801
This commit is contained in:
Jeff Walden 2017-01-30 15:56:05 -08:00
parent e7199a3786
commit 42076c2649
2 changed files with 19 additions and 12 deletions

View File

@ -7,7 +7,7 @@
#ifndef js_ProfilingFrameIterator_h
#define js_ProfilingFrameIterator_h
#include "mozilla/Alignment.h"
#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
#include "jsbytecode.h"
@ -44,7 +44,7 @@ struct ForEachTrackedOptimizationTypeInfoOp;
// Note that the caller must not do anything that could cause GC to happen while
// the iterator is alive, since this could invalidate Ion code and cause its
// contents to become out of date.
class JS_PUBLIC_API(ProfilingFrameIterator)
class MOZ_NON_PARAM JS_PUBLIC_API(ProfilingFrameIterator)
{
JSContext* cx_;
uint32_t sampleBufferGen_;
@ -56,28 +56,32 @@ class JS_PUBLIC_API(ProfilingFrameIterator)
void* savedPrevJitTop_;
static const unsigned StorageSpace = 8 * sizeof(void*);
mozilla::AlignedStorage<StorageSpace> storage_;
alignas(void*) unsigned char storage_[StorageSpace];
void* storage() { return storage_; }
const void* storage() const { return storage_; }
js::wasm::ProfilingFrameIterator& wasmIter() {
MOZ_ASSERT(!done());
MOZ_ASSERT(isWasm());
return *reinterpret_cast<js::wasm::ProfilingFrameIterator*>(storage_.addr());
return *static_cast<js::wasm::ProfilingFrameIterator*>(storage());
}
const js::wasm::ProfilingFrameIterator& wasmIter() const {
MOZ_ASSERT(!done());
MOZ_ASSERT(isWasm());
return *reinterpret_cast<const js::wasm::ProfilingFrameIterator*>(storage_.addr());
return *static_cast<const js::wasm::ProfilingFrameIterator*>(storage());
}
js::jit::JitProfilingFrameIterator& jitIter() {
MOZ_ASSERT(!done());
MOZ_ASSERT(isJit());
return *reinterpret_cast<js::jit::JitProfilingFrameIterator*>(storage_.addr());
return *static_cast<js::jit::JitProfilingFrameIterator*>(storage());
}
const js::jit::JitProfilingFrameIterator& jitIter() const {
MOZ_ASSERT(!done());
MOZ_ASSERT(isJit());
return *reinterpret_cast<const js::jit::JitProfilingFrameIterator*>(storage_.addr());
return *static_cast<const js::jit::JitProfilingFrameIterator*>(storage());
}
void settle();

View File

@ -1781,7 +1781,10 @@ JS::ProfilingFrameIterator::ProfilingFrameIterator(JSContext* cx, const Register
static_assert(sizeof(wasm::ProfilingFrameIterator) <= StorageSpace &&
sizeof(jit::JitProfilingFrameIterator) <= StorageSpace,
"Need to increase storage");
"ProfilingFrameIterator::storage_ is too small");
static_assert(alignof(void*) >= alignof(wasm::ProfilingFrameIterator) &&
alignof(void*) >= alignof(jit::JitProfilingFrameIterator),
"ProfilingFrameIterator::storage_ is too weakly aligned");
iteratorConstruct(state);
settle();
@ -1835,14 +1838,14 @@ JS::ProfilingFrameIterator::iteratorConstruct(const RegisterState& state)
MOZ_ASSERT(activation_->isWasm() || activation_->isJit());
if (activation_->isWasm()) {
new (storage_.addr()) wasm::ProfilingFrameIterator(*activation_->asWasm(), state);
new (storage()) wasm::ProfilingFrameIterator(*activation_->asWasm(), state);
// Set savedPrevJitTop_ to the actual jitTop_ from the runtime.
savedPrevJitTop_ = activation_->cx()->jitTop;
return;
}
MOZ_ASSERT(activation_->asJit()->isActive());
new (storage_.addr()) jit::JitProfilingFrameIterator(cx_, state);
new (storage()) jit::JitProfilingFrameIterator(cx_, state);
}
void
@ -1852,13 +1855,13 @@ JS::ProfilingFrameIterator::iteratorConstruct()
MOZ_ASSERT(activation_->isWasm() || activation_->isJit());
if (activation_->isWasm()) {
new (storage_.addr()) wasm::ProfilingFrameIterator(*activation_->asWasm());
new (storage()) wasm::ProfilingFrameIterator(*activation_->asWasm());
return;
}
MOZ_ASSERT(activation_->asJit()->isActive());
MOZ_ASSERT(savedPrevJitTop_ != nullptr);
new (storage_.addr()) jit::JitProfilingFrameIterator(savedPrevJitTop_);
new (storage()) jit::JitProfilingFrameIterator(savedPrevJitTop_);
}
void