Commit 2e856d2c authored by dcarney@chromium.org's avatar dcarney@chromium.org

expose AssertNoAllocation to api

R=svenpanne@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14531 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent cf5ff5a1
......@@ -3876,6 +3876,24 @@ class V8EXPORT PersistentHandleVisitor { // NOLINT
};
/**
* Asserts that no action is performed that could cause a handle's value
* to be modified. Useful when otherwise unsafe handle operations need to
* be performed.
*/
class V8EXPORT AssertNoGCScope {
#ifndef DEBUG
V8_INLINE(AssertNoGCScope(Isolate* isolate)) {}
#else
AssertNoGCScope(Isolate* isolate);
~AssertNoGCScope();
private:
Isolate* isolate_;
bool last_state_;
#endif
};
/**
* Container class for static utility functions.
*/
......
......@@ -6077,6 +6077,19 @@ Local<Integer> v8::Integer::NewFromUnsigned(uint32_t value, Isolate* isolate) {
}
#ifdef DEBUG
v8::AssertNoGCScope::AssertNoGCScope(v8::Isolate* isolate)
: isolate_(isolate),
last_state_(i::EnterAllocationScope(
reinterpret_cast<i::Isolate*>(isolate), false)) {
}
v8::AssertNoGCScope::~AssertNoGCScope() {
i::ExitAllocationScope(reinterpret_cast<i::Isolate*>(isolate_), last_state_);
}
#endif
void V8::IgnoreOutOfMemoryException() {
EnterIsolateIfNeeded()->set_ignore_out_of_memory(true);
}
......
......@@ -650,6 +650,10 @@ inline bool Heap::allow_allocation(bool new_state) {
return old;
}
inline void Heap::set_allow_allocation(bool allocation_allowed) {
allocation_allowed_ = allocation_allowed;
}
#endif
......@@ -864,33 +868,36 @@ DisallowAllocationFailure::~DisallowAllocationFailure() {
#ifdef DEBUG
AssertNoAllocation::AssertNoAllocation() {
Isolate* isolate = ISOLATE;
active_ = !isolate->optimizing_compiler_thread()->IsOptimizerThread();
if (active_) {
old_state_ = isolate->heap()->allow_allocation(false);
bool EnterAllocationScope(Isolate* isolate, bool allow_allocation) {
bool active = !isolate->optimizing_compiler_thread()->IsOptimizerThread();
bool last_state = isolate->heap()->IsAllocationAllowed();
if (active) {
isolate->heap()->set_allow_allocation(allow_allocation);
}
return last_state;
}
AssertNoAllocation::~AssertNoAllocation() {
if (active_) HEAP->allow_allocation(old_state_);
void ExitAllocationScope(Isolate* isolate, bool last_state) {
isolate->heap()->set_allow_allocation(last_state);
}
DisableAssertNoAllocation::DisableAssertNoAllocation() {
Isolate* isolate = ISOLATE;
active_ = !isolate->optimizing_compiler_thread()->IsOptimizerThread();
if (active_) {
old_state_ = isolate->heap()->allow_allocation(true);
}
AssertNoAllocation::AssertNoAllocation()
: last_state_(EnterAllocationScope(ISOLATE, false)) {
}
AssertNoAllocation::~AssertNoAllocation() {
ExitAllocationScope(ISOLATE, last_state_);
}
DisableAssertNoAllocation::~DisableAssertNoAllocation() {
if (active_) HEAP->allow_allocation(old_state_);
DisableAssertNoAllocation::DisableAssertNoAllocation()
: last_state_(EnterAllocationScope(ISOLATE, true)) {
}
DisableAssertNoAllocation::~DisableAssertNoAllocation() {
ExitAllocationScope(ISOLATE, last_state_);
}
#else
AssertNoAllocation::AssertNoAllocation() { }
......
......@@ -1476,6 +1476,7 @@ class Heap {
#ifdef DEBUG
bool IsAllocationAllowed() { return allocation_allowed_; }
inline void set_allow_allocation(bool allocation_allowed);
inline bool allow_allocation(bool enable);
bool disallow_allocation_failure() {
......@@ -2691,6 +2692,13 @@ class DescriptorLookupCache {
// { AssertNoAllocation nogc;
// ...
// }
#ifdef DEBUG
inline bool EnterAllocationScope(Isolate* isolate, bool allow_allocation);
inline void ExitAllocationScope(Isolate* isolate, bool last_state);
#endif
class AssertNoAllocation {
public:
inline AssertNoAllocation();
......@@ -2698,8 +2706,7 @@ class AssertNoAllocation {
#ifdef DEBUG
private:
bool old_state_;
bool active_;
bool last_state_;
#endif
};
......@@ -2711,8 +2718,7 @@ class DisableAssertNoAllocation {
#ifdef DEBUG
private:
bool old_state_;
bool active_;
bool last_state_;
#endif
};
......
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