Fixed alignment issues of ProfilerEventsProcessor.

R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/131393002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18526 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a660f31d
......@@ -32,6 +32,10 @@
#include "platform.h"
#include "utils.h"
#if V8_LIBC_BIONIC
#include <malloc.h> // NOLINT
#endif
namespace v8 {
namespace internal {
......@@ -100,4 +104,33 @@ char* StrNDup(const char* str, int n) {
return result;
}
void* AlignedAlloc(size_t size, size_t alignment) {
ASSERT(IsPowerOf2(alignment) && alignment >= V8_ALIGNOF(void*)); // NOLINT
void* ptr;
#if V8_OS_WIN
ptr = _aligned_malloc(size, alignment);
#elif V8_LIBC_BIONIC
// posix_memalign is not exposed in some Android versions, so we fall back to
// memalign. See http://code.google.com/p/android/issues/detail?id=35391.
ptr = memalign(alignment, size);
#else
if (posix_memalign(&ptr, alignment, size)) ptr = NULL;
#endif
if (ptr == NULL) FatalProcessOutOfMemory("AlignedAlloc");
return ptr;
}
void AlignedFree(void *ptr) {
#if V8_OS_WIN
_aligned_free(ptr);
#elif V8_LIBC_BIONIC
// Using free is not correct in general, but for V8_LIBC_BIONIC it is.
free(ptr);
#else
free(ptr);
#endif
}
} } // namespace v8::internal
......@@ -109,6 +109,9 @@ class FreeStoreAllocationPolicy {
};
void* AlignedAlloc(size_t size, size_t alignment);
void AlignedFree(void *ptr);
} } // namespace v8::internal
#endif // V8_ALLOCATION_H_
......@@ -156,6 +156,16 @@ void ProfilerEventsProcessor::Run() {
}
void* ProfilerEventsProcessor::operator new(size_t size) {
return AlignedAlloc(size, V8_ALIGNOF(ProfilerEventsProcessor));
}
void ProfilerEventsProcessor::operator delete(void* ptr) {
AlignedFree(ptr);
}
int CpuProfiler::GetProfilesCount() {
// The count of profiles doesn't depend on a security token.
return profiles_->profiles()->length();
......@@ -439,18 +449,8 @@ void CpuProfiler::StartProcessorIfNotStarted() {
logger->is_logging_ = false;
generator_ = new ProfileGenerator(profiles_);
Sampler* sampler = logger->sampler();
#if V8_CC_MSVC && (_MSC_VER >= 1800)
// VS2013 reports "warning C4316: 'v8::internal::ProfilerEventsProcessor'
// : object allocated on the heap may not be aligned 64". We need to
// figure out if this is a legitimate warning or a compiler bug.
#pragma warning(push)
#pragma warning(disable:4316)
#endif
processor_ = new ProfilerEventsProcessor(
generator_, sampler, sampling_interval_);
#if V8_CC_MSVC && (_MSC_VER >= 1800)
#pragma warning(pop)
#endif
is_profiling_ = true;
// Enumerate stuff we already have in the heap.
ASSERT(isolate_->heap()->HasBeenSetUp());
......
......@@ -158,6 +158,11 @@ class ProfilerEventsProcessor : public Thread {
inline TickSample* StartTickSample();
inline void FinishTickSample();
// SamplingCircularQueue has stricter alignment requirements than a normal new
// can fulfil, so we need to provide our own new/delete here.
void* operator new(size_t size);
void operator delete(void* ptr);
private:
// Called from events processing thread (Run() method.)
bool ProcessCodeEvent();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment