/**
+ * 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.
*/
class V8EXPORT V8 {
}
+#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);
}
return old;
}
+inline void Heap::set_allow_allocation(bool allocation_allowed) {
+ allocation_allowed_ = allocation_allowed;
+}
+
#endif
#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() { }
#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() {
// { 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();
#ifdef DEBUG
private:
- bool old_state_;
- bool active_;
+ bool last_state_;
#endif
};
#ifdef DEBUG
private:
- bool old_state_;
- bool active_;
+ bool last_state_;
#endif
};