expose AssertNoAllocation to api (issue 14625003)

3 views
Skip to first unread message

sven...@chromium.org

unread,
Apr 30, 2013, 8:21:30 AM4/30/13
to dca...@chromium.org, v8-...@googlegroups.com, ma...@chromium.org

https://codereview.chromium.org/14625003/diff/1/src/heap-inl.h
File src/heap-inl.h (right):

https://codereview.chromium.org/14625003/diff/1/src/heap-inl.h#newcode872
src/heap-inl.h:872: return 0x10 || old_state;
This is "a bit" obscure. Why don't we simply remember the previous state
(a bool)?

https://codereview.chromium.org/14625003/diff/1/src/heap-inl.h#newcode879
src/heap-inl.h:879: if (data) isolate->heap()->allow_allocation(data);
Passing a uint8_t as a bool looks wrong. Again, a simple (remembered)
bool should be less confusing.

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

ma...@chromium.org

unread,
Apr 30, 2013, 9:39:29 AM4/30/13
to dca...@chromium.org, sven...@chromium.org, v8-...@googlegroups.com
|| ? Maybe you meant |? Maybe something else?

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

ma...@chromium.org

unread,
Apr 30, 2013, 9:42:43 AM4/30/13
to dca...@chromium.org, sven...@chromium.org, v8-...@googlegroups.com

sven...@chromium.org

unread,
May 2, 2013, 7:46:43 AM5/2/13
to dca...@chromium.org, v8-...@googlegroups.com, ma...@chromium.org

dca...@chromium.org

unread,
May 2, 2013, 4:28:13 PM5/2/13
to sven...@chromium.org, v8-...@googlegroups.com, ma...@chromium.org
Reviewers: Sven Panne,

Message:
Committed patchset #2 manually as r14531 (presubmit successful).

Description:
expose AssertNoAllocation to api

R=sven...@chromium.org
BUG=

Committed: https://code.google.com/p/v8/source/detail?r=14531

Please review this at https://codereview.chromium.org/14625003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
M include/v8.h
M src/api.cc
M src/heap-inl.h
M src/heap.h


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
ee49ca4349d804a15020c98d5c573012d35f2e7e..2bfda9d7207689c28bdc0366c1cf0474813acbdb
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3604,6 +3604,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.
*/
class V8EXPORT V8 {
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
4352ef3301e2f56a44689bc27459219b8cf1961e..9e91d375410c6f04943039efb2c060bb44c7358f
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6039,6 +6039,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);
}
Index: src/heap-inl.h
diff --git a/src/heap-inl.h b/src/heap-inl.h
index
f937426186c8099fb9c2f5469f3c32eb4eb97355..18a2cf351b33f1eb2886fe8b8658519159a445b1
100644
--- a/src/heap-inl.h
+++ b/src/heap-inl.h
@@ -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() { }
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index
7722079e55049ef94f572b45d1593ec16787f6ae..b25aa7f612b645a8453f380025a258d5e927a88b
100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -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
};



Reply all
Reply to author
Forward
0 new messages