mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
deps: backport 1f8555 from v8's upstream
Original commit message:
api: introduce SealHandleScope
When debugging Handle leaks in io.js we found it very convenient to be
able to Seal some specific (root in our case) scope to prevent Handle
allocations in it, and easily find leakage.
R=yangguo
BUG=
Review URL: https://codereview.chromium.org/1079713002
Cr-Commit-Position: refs/heads/master@{#27766}
Should help us identify and fix Handle leaks in core and user-space code.
NOTE: Works only in Debug build now, but is still better than nothing.
PR-URL: https://github.com/iojs/io.js/pull/1395
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
a4d88475fa
commit
a5244d3a39
5 files changed
+73
-4
No files matched your search
Vendored
+18
@@ -1006,6 +1006,24 @@ class ScriptOrigin {
|
|||||||
Handle<Integer> script_id_;
|
Handle<Integer> script_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class V8_EXPORT SealHandleScope {
|
||||||
|
public:
|
||||||
|
SealHandleScope(Isolate* isolate);
|
||||||
|
~SealHandleScope();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Make it hard to create heap-allocated or illegal handle scopes by
|
||||||
|
// disallowing certain operations.
|
||||||
|
SealHandleScope(const SealHandleScope&);
|
||||||
|
void operator=(const SealHandleScope&);
|
||||||
|
void* operator new(size_t size);
|
||||||
|
void operator delete(void*, size_t);
|
||||||
|
|
||||||
|
internal::Isolate* isolate_;
|
||||||
|
int prev_level_;
|
||||||
|
internal::Object** prev_limit_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A compiled JavaScript script, not yet tied to a Context.
|
* A compiled JavaScript script, not yet tied to a Context.
|
||||||
|
|||||||
Vendored
+21
@@ -515,6 +515,27 @@ i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SealHandleScope::SealHandleScope(Isolate* isolate) {
|
||||||
|
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||||
|
|
||||||
|
isolate_ = internal_isolate;
|
||||||
|
i::HandleScopeData* current = internal_isolate->handle_scope_data();
|
||||||
|
prev_limit_ = current->limit;
|
||||||
|
current->limit = current->next;
|
||||||
|
prev_level_ = current->level;
|
||||||
|
current->level = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SealHandleScope::~SealHandleScope() {
|
||||||
|
i::HandleScopeData* current = isolate_->handle_scope_data();
|
||||||
|
DCHECK_EQ(0, current->level);
|
||||||
|
current->level = prev_level_;
|
||||||
|
DCHECK_EQ(current->next, current->limit);
|
||||||
|
current->limit = prev_limit_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Context::Enter() {
|
void Context::Enter() {
|
||||||
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
i::Handle<i::Context> env = Utils::OpenHandle(this);
|
||||||
i::Isolate* isolate = env->GetIsolate();
|
i::Isolate* isolate = env->GetIsolate();
|
||||||
|
|||||||
Vendored
+1
-4
@@ -650,7 +650,7 @@ void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) {
|
|||||||
while (!blocks_.is_empty()) {
|
while (!blocks_.is_empty()) {
|
||||||
internal::Object** block_start = blocks_.last();
|
internal::Object** block_start = blocks_.last();
|
||||||
internal::Object** block_limit = block_start + kHandleBlockSize;
|
internal::Object** block_limit = block_start + kHandleBlockSize;
|
||||||
#ifdef DEBUG
|
|
||||||
// SealHandleScope may make the prev_limit to point inside the block.
|
// SealHandleScope may make the prev_limit to point inside the block.
|
||||||
if (block_start <= prev_limit && prev_limit <= block_limit) {
|
if (block_start <= prev_limit && prev_limit <= block_limit) {
|
||||||
#ifdef ENABLE_HANDLE_ZAPPING
|
#ifdef ENABLE_HANDLE_ZAPPING
|
||||||
@@ -658,9 +658,6 @@ void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) {
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (prev_limit == block_limit) break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
blocks_.RemoveLast();
|
blocks_.RemoveLast();
|
||||||
#ifdef ENABLE_HANDLE_ZAPPING
|
#ifdef ENABLE_HANDLE_ZAPPING
|
||||||
|
|||||||
Vendored
+1
@@ -40,6 +40,7 @@
|
|||||||
# they don't fail then test.py has failed.
|
# they don't fail then test.py has failed.
|
||||||
'test-serialize/TestThatAlwaysFails': [FAIL],
|
'test-serialize/TestThatAlwaysFails': [FAIL],
|
||||||
'test-serialize/DependentTestThatAlwaysFails': [FAIL],
|
'test-serialize/DependentTestThatAlwaysFails': [FAIL],
|
||||||
|
'test-api/SealHandleScope': [FAIL],
|
||||||
|
|
||||||
# This test always fails. It tests that LiveEdit causes abort when turned off.
|
# This test always fails. It tests that LiveEdit causes abort when turned off.
|
||||||
'test-debug/LiveEditDisabled': [FAIL],
|
'test-debug/LiveEditDisabled': [FAIL],
|
||||||
|
|||||||
Vendored
+32
@@ -21895,6 +21895,38 @@ void CallCompletedCallbackException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(SealHandleScope) {
|
||||||
|
v8::Isolate* isolate = CcTest::isolate();
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
LocalContext env;
|
||||||
|
|
||||||
|
v8::SealHandleScope seal(isolate);
|
||||||
|
|
||||||
|
// Should fail
|
||||||
|
v8::Local<v8::Object> obj = v8::Object::New(isolate);
|
||||||
|
|
||||||
|
USE(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(SealHandleScopeNested) {
|
||||||
|
v8::Isolate* isolate = CcTest::isolate();
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
LocalContext env;
|
||||||
|
|
||||||
|
v8::SealHandleScope seal(isolate);
|
||||||
|
|
||||||
|
{
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
|
// Should work
|
||||||
|
v8::Local<v8::Object> obj = v8::Object::New(isolate);
|
||||||
|
|
||||||
|
USE(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(CallCompletedCallbackOneException) {
|
TEST(CallCompletedCallbackOneException) {
|
||||||
LocalContext env;
|
LocalContext env;
|
||||||
v8::HandleScope scope(env->GetIsolate());
|
v8::HandleScope scope(env->GetIsolate());
|
||||||
|
|||||||
Reference in new issue
Block a user