v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
local-handles.cc
Go to the documentation of this file.
1// Copyright 2012 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include "src/api/api.h"
10#include "src/handles/handles.h"
11#include "src/heap/heap-inl.h"
12
13namespace v8 {
14namespace internal {
15
17 Address value) {
18 Isolate* isolate = local_heap->heap()->isolate();
19 return HandleScope::CreateHandle(isolate, value);
20}
21
23 Isolate* isolate = local_heap->heap()->isolate();
24 HandleScopeData* data = isolate->handle_scope_data();
25 local_heap_ = local_heap;
26 prev_next_ = data->next;
27 prev_limit_ = data->limit;
28 data->level++;
29#ifdef V8_ENABLE_CHECKS
30 scope_level_ = data->level;
31#endif
32}
33
35 Address* prev_next,
36 Address* prev_limit) {
37 Isolate* isolate = local_heap->heap()->isolate();
38 HandleScope::CloseScope(isolate, prev_next, prev_limit);
39}
40
41#ifdef V8_ENABLE_CHECKS
42void LocalHandleScope::VerifyMainThreadScope() const {
43 Isolate* isolate = local_heap_->heap()->isolate();
44 CHECK_EQ(scope_level_, isolate->handle_scope_data()->level);
45}
46#endif // V8_ENABLE_CHECKS
47
54
56 for (int i = 0; i < static_cast<int>(blocks_.size()) - 1; i++) {
57 Address* block = blocks_[i];
58 visitor->VisitRootPointers(Root::kHandleScope, nullptr,
59 FullObjectSlot(block),
61 }
62
63 if (!blocks_.empty()) {
64 Address* block = blocks_.back();
65 visitor->VisitRootPointers(Root::kHandleScope, nullptr,
66 FullObjectSlot(block),
68 }
69}
70
71#ifdef DEBUG
72bool LocalHandles::Contains(Address* location) {
73 // We have to search in all blocks since they have no guarantee of order.
74 for (auto it = blocks_.begin(); it != blocks_.end(); ++it) {
75 Address* lower_bound = *it;
76 // The last block is a special case because it may have less than
77 // block_size_ handles.
78 Address* upper_bound = lower_bound != blocks_.back()
79 ? lower_bound + kHandleBlockSize
80 : scope_.next;
81 if (lower_bound <= location && location < upper_bound) {
82 return true;
83 }
84 }
85 return false;
86}
87#endif
88
97
99 while (!blocks_.empty()) {
100 Address* block_start = blocks_.back();
101 Address* block_limit = block_start + kHandleBlockSize;
102
103 if (block_limit == scope_.limit) {
104 break;
105 }
106
107 blocks_.pop_back();
108
109#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
110 ZapRange(block_start, block_limit);
111#endif
112
113 DeleteArray(block_start);
114 }
115}
116
117#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
118void LocalHandles::ZapRange(Address* start, Address* end) {
119 HandleScope::ZapRange(start, end);
120}
121#endif
122
123} // namespace internal
124} // namespace v8
static V8_INLINE void CloseScope(Isolate *isolate, Address *prev_next, Address *prev_limit)
static V8_INLINE Address * CreateHandle(Isolate *isolate, Address value)
Isolate * isolate() const
Definition heap-inl.h:61
V8_EXPORT_PRIVATE void OpenMainThreadScope(LocalHeap *local_heap)
static V8_EXPORT_PRIVATE void CloseMainThreadScope(LocalHeap *local_heap, Address *prev_next, Address *prev_limit)
static V8_EXPORT_PRIVATE Address * GetMainThreadHandle(LocalHeap *local_heap, Address value)
std::vector< Address * > blocks_
V8_EXPORT_PRIVATE Address * AddBlock()
V8_EXPORT_PRIVATE void RemoveUnusedBlocks()
void Iterate(RootVisitor *visitor)
Heap * heap() const
Definition local-heap.h:122
virtual void VisitRootPointers(Root root, const char *description, FullObjectSlot start, FullObjectSlot end)=0
int start
int end
RpoNumber block
void DeleteArray(T *array)
Definition allocation.h:63
const int kHandleBlockSize
Definition api.h:444
T * NewArray(size_t size)
Definition allocation.h:43
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485