Commit 20db0ff3 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Next base/macros.h cleanup step.

R=svenpanne@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23760 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 880110ae
...@@ -1852,7 +1852,7 @@ v8::TryCatch::TryCatch() ...@@ -1852,7 +1852,7 @@ v8::TryCatch::TryCatch()
// Special handling for simulators which have a separate JS stack. // Special handling for simulators which have a separate JS stack.
js_stack_comparable_address_ = js_stack_comparable_address_ =
reinterpret_cast<void*>(v8::internal::SimulatorStack::RegisterCTryCatch( reinterpret_cast<void*>(v8::internal::SimulatorStack::RegisterCTryCatch(
GetCurrentStackPosition())); v8::internal::GetCurrentStackPosition()));
isolate_->RegisterTryCatchHandler(this); isolate_->RegisterTryCatchHandler(this);
} }
......
...@@ -271,20 +271,4 @@ inline T RoundUp(T x, intptr_t m) { ...@@ -271,20 +271,4 @@ inline T RoundUp(T x, intptr_t m) {
return RoundDown<T>(static_cast<T>(x + m - 1), m); return RoundDown<T>(static_cast<T>(x + m - 1), m);
} }
template <typename T, typename U>
inline bool IsAligned(T value, U alignment) {
return (value & (alignment - 1)) == 0;
}
// Returns current value of top of the stack. Works correctly with ASAN.
DISABLE_ASAN
inline uintptr_t GetCurrentStackPosition() {
// Takes the address of the limit variable in order to find out where
// the top of stack is right now.
uintptr_t limit = reinterpret_cast<uintptr_t>(&limit);
return limit;
}
#endif // V8_BASE_MACROS_H_ #endif // V8_BASE_MACROS_H_
...@@ -205,7 +205,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -205,7 +205,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* address = ReserveRegion(request_size); void* address = ReserveRegion(request_size);
......
...@@ -182,7 +182,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -182,7 +182,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* reservation = mmap(OS::GetRandomMmapAddr(), void* reservation = mmap(OS::GetRandomMmapAddr(),
......
...@@ -306,7 +306,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -306,7 +306,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* reservation = mmap(OS::GetRandomMmapAddr(), void* reservation = mmap(OS::GetRandomMmapAddr(),
......
...@@ -184,7 +184,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -184,7 +184,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* reservation = mmap(OS::GetRandomMmapAddr(), void* reservation = mmap(OS::GetRandomMmapAddr(),
......
...@@ -213,7 +213,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -213,7 +213,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* reservation = mmap(OS::GetRandomMmapAddr(), void* reservation = mmap(OS::GetRandomMmapAddr(),
......
...@@ -249,7 +249,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -249,7 +249,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* reservation = mmap(OS::GetRandomMmapAddr(), void* reservation = mmap(OS::GetRandomMmapAddr(),
......
...@@ -154,7 +154,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -154,7 +154,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* reservation = mmap(OS::GetRandomMmapAddr(), void* reservation = mmap(OS::GetRandomMmapAddr(),
......
...@@ -786,7 +786,7 @@ void* OS::Allocate(const size_t requested, ...@@ -786,7 +786,7 @@ void* OS::Allocate(const size_t requested,
if (mbase == NULL) return NULL; if (mbase == NULL) return NULL;
DCHECK(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); DCHECK((static_cast<uintptr_t>(mbase) % OS::AllocateAlignment()) == 0);
*allocated = msize; *allocated = msize;
return mbase; return mbase;
...@@ -1205,7 +1205,7 @@ VirtualMemory::VirtualMemory(size_t size) ...@@ -1205,7 +1205,7 @@ VirtualMemory::VirtualMemory(size_t size)
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0) { : address_(NULL), size_(0) {
DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); DCHECK((alignment % OS::AllocateAlignment()) == 0);
size_t request_size = RoundUp(size + alignment, size_t request_size = RoundUp(size + alignment,
static_cast<intptr_t>(OS::AllocateAlignment())); static_cast<intptr_t>(OS::AllocateAlignment()));
void* address = ReserveRegion(request_size); void* address = ReserveRegion(request_size);
......
...@@ -112,6 +112,12 @@ int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) { ...@@ -112,6 +112,12 @@ int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) {
} }
template <typename T, typename U>
inline bool IsAligned(T value, U alignment) {
return (value & (alignment - 1)) == 0;
}
// Returns true if (addr + offset) is aligned. // Returns true if (addr + offset) is aligned.
inline bool IsAddressAligned(Address addr, inline bool IsAddressAligned(Address addr,
intptr_t alignment, intptr_t alignment,
...@@ -1536,6 +1542,16 @@ bool StringToArrayIndex(Stream* stream, uint32_t* index) { ...@@ -1536,6 +1542,16 @@ bool StringToArrayIndex(Stream* stream, uint32_t* index) {
} }
} } // namespace v8::internal // Returns current value of top of the stack. Works correctly with ASAN.
DISABLE_ASAN
inline uintptr_t GetCurrentStackPosition() {
// Takes the address of the limit variable in order to find out where
// the top of stack is right now.
uintptr_t limit = reinterpret_cast<uintptr_t>(&limit);
return limit;
}
} // namespace internal
} // namespace v8
#endif // V8_UTILS_H_ #endif // V8_UTILS_H_
...@@ -145,8 +145,8 @@ TEST(ScanHTMLEndComments) { ...@@ -145,8 +145,8 @@ TEST(ScanHTMLEndComments) {
}; };
// Parser/Scanner needs a stack limit. // Parser/Scanner needs a stack limit.
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
for (int i = 0; tests[i]; i++) { for (int i = 0; tests[i]; i++) {
const i::byte* source = const i::byte* source =
...@@ -198,8 +198,8 @@ TEST(UsingCachedData) { ...@@ -198,8 +198,8 @@ TEST(UsingCachedData) {
v8::HandleScope handles(isolate); v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
// Source containing functions that might be lazily compiled and all types // Source containing functions that might be lazily compiled and all types
// of symbols (string, propertyName, regexp). // of symbols (string, propertyName, regexp).
...@@ -251,8 +251,8 @@ TEST(PreparseFunctionDataIsUsed) { ...@@ -251,8 +251,8 @@ TEST(PreparseFunctionDataIsUsed) {
v8::HandleScope handles(isolate); v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
const char* good_code[] = { const char* good_code[] = {
"function this_is_lazy() { var a; } function foo() { return 25; } foo();", "function this_is_lazy() { var a; } function foo() { return 25; } foo();",
...@@ -292,8 +292,8 @@ TEST(PreparseFunctionDataIsUsed) { ...@@ -292,8 +292,8 @@ TEST(PreparseFunctionDataIsUsed) {
TEST(StandAlonePreParser) { TEST(StandAlonePreParser) {
v8::V8::Initialize(); v8::V8::Initialize();
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
const char* programs[] = { const char* programs[] = {
"{label: 42}", "{label: 42}",
...@@ -329,8 +329,8 @@ TEST(StandAlonePreParser) { ...@@ -329,8 +329,8 @@ TEST(StandAlonePreParser) {
TEST(StandAlonePreParserNoNatives) { TEST(StandAlonePreParserNoNatives) {
v8::V8::Initialize(); v8::V8::Initialize();
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
const char* programs[] = { const char* programs[] = {
"%ArgleBargle(glop);", "%ArgleBargle(glop);",
...@@ -365,8 +365,8 @@ TEST(PreparsingObjectLiterals) { ...@@ -365,8 +365,8 @@ TEST(PreparsingObjectLiterals) {
v8::HandleScope handles(isolate); v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
{ {
const char* source = "var myo = {if: \"foo\"}; myo.if;"; const char* source = "var myo = {if: \"foo\"}; myo.if;";
...@@ -398,7 +398,8 @@ TEST(RegressChromium62639) { ...@@ -398,7 +398,8 @@ TEST(RegressChromium62639) {
v8::V8::Initialize(); v8::V8::Initialize();
i::Isolate* isolate = CcTest::i_isolate(); i::Isolate* isolate = CcTest::i_isolate();
isolate->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
128 * 1024);
const char* program = "var x = 'something';\n" const char* program = "var x = 'something';\n"
"escape: function() {}"; "escape: function() {}";
...@@ -432,7 +433,8 @@ TEST(Regress928) { ...@@ -432,7 +433,8 @@ TEST(Regress928) {
// as with-content, which made it assume that a function inside // as with-content, which made it assume that a function inside
// the block could be lazily compiled, and an extra, unexpected, // the block could be lazily compiled, and an extra, unexpected,
// entry was added to the data. // entry was added to the data.
isolate->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
128 * 1024);
const char* program = const char* program =
"try { } catch (e) { var foo = function () { /* first */ } }" "try { } catch (e) { var foo = function () { /* first */ } }"
...@@ -475,8 +477,8 @@ TEST(Regress928) { ...@@ -475,8 +477,8 @@ TEST(Regress928) {
TEST(PreParseOverflow) { TEST(PreParseOverflow) {
v8::V8::Initialize(); v8::V8::Initialize();
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
size_t kProgramSize = 1024 * 1024; size_t kProgramSize = 1024 * 1024;
i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1)); i::SmartArrayPointer<char> program(i::NewArray<char>(kProgramSize + 1));
...@@ -1105,7 +1107,8 @@ TEST(ScopePositions) { ...@@ -1105,7 +1107,8 @@ TEST(ScopePositions) {
v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
isolate->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 128 * 1024); isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
128 * 1024);
for (int i = 0; source_data[i].outer_prefix; i++) { for (int i = 0; source_data[i].outer_prefix; i++) {
int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix); int kPrefixLen = Utf8LengthHelper(source_data[i].outer_prefix);
...@@ -1440,8 +1443,8 @@ TEST(ParserSync) { ...@@ -1440,8 +1443,8 @@ TEST(ParserSync) {
v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
static const ParserFlag flags1[] = {kAllowLazy, kAllowHarmonyScoping, static const ParserFlag flags1[] = {kAllowLazy, kAllowHarmonyScoping,
kAllowModules, kAllowGenerators, kAllowModules, kAllowGenerators,
...@@ -1516,8 +1519,8 @@ void RunParserSyncTest(const char* context_data[][2], ...@@ -1516,8 +1519,8 @@ void RunParserSyncTest(const char* context_data[][2],
v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
static const ParserFlag default_flags[] = { static const ParserFlag default_flags[] = {
kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowLazy, kAllowHarmonyScoping, kAllowModules,
...@@ -2251,8 +2254,8 @@ TEST(DontRegressPreParserDataSizes) { ...@@ -2251,8 +2254,8 @@ TEST(DontRegressPreParserDataSizes) {
v8::Isolate* isolate = CcTest::isolate(); v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handles(isolate); v8::HandleScope handles(isolate);
CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - CcTest::i_isolate()->stack_guard()->SetStackLimit(
128 * 1024); i::GetCurrentStackPosition() - 128 * 1024);
struct TestCase { struct TestCase {
const char* program; const char* program;
......
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