V8 Project
v8::internal::HandleScope Class Reference

#include <handles.h>

+ Collaboration diagram for v8::internal::HandleScope:

Public Member Functions

 HandleScope (Isolate *isolate)
 
 ~HandleScope ()
 
template<typename T >
Handle< TCloseAndEscape (Handle< T > handle_value)
 
Isolateisolate ()
 

Static Public Member Functions

static int NumberOfHandles (Isolate *isolate)
 
template<typename T >
static T ** CreateHandle (Isolate *isolate, T *value)
 
static void DeleteExtensions (Isolate *isolate)
 
static Address current_next_address (Isolate *isolate)
 
static Address current_limit_address (Isolate *isolate)
 
static Address current_level_address (Isolate *isolate)
 

Private Member Functions

 HandleScope (const HandleScope &)
 
void operator= (const HandleScope &)
 
void * operator new (size_t size)
 
void operator delete (void *size_t)
 

Static Private Member Functions

static void CloseScope (Isolate *isolate, Object **prev_next, Object **prev_limit)
 
static internal::Object ** Extend (Isolate *isolate)
 

Private Attributes

Isolateisolate_
 
Object ** prev_next_
 
Object ** prev_limit_
 

Friends

class v8::HandleScope
 
class v8::internal::DeferredHandles
 
class v8::internal::HandleScopeImplementer
 
class v8::internal::Isolate
 

Detailed Description

Definition at line 181 of file handles.h.

Constructor & Destructor Documentation

◆ HandleScope() [1/2]

v8::internal::HandleScope::HandleScope ( Isolate isolate)
inlineexplicit

Definition at line 85 of file handles-inl.h.

85  {
86  HandleScopeData* current = isolate->handle_scope_data();
87  isolate_ = isolate;
88  prev_next_ = current->next;
89  prev_limit_ = current->limit;
90  current->level++;
91 }
HandleScopeData * handle_scope_data()
Definition: isolate.h:899

References v8::internal::Isolate::handle_scope_data(), isolate(), isolate_, v8::internal::HandleScopeData::level, v8::internal::HandleScopeData::limit, v8::internal::HandleScopeData::next, prev_limit_, and prev_next_.

+ Here is the call graph for this function:

◆ ~HandleScope()

v8::internal::HandleScope::~HandleScope ( )
inline

Definition at line 94 of file handles-inl.h.

94  {
96 }
static void CloseScope(Isolate *isolate, Object **prev_next, Object **prev_limit)
Definition: handles-inl.h:99

References CloseScope(), isolate_, prev_limit_, and prev_next_.

+ Here is the call graph for this function:

◆ HandleScope() [2/2]

v8::internal::HandleScope::HandleScope ( const HandleScope )
private

Member Function Documentation

◆ CloseAndEscape()

template<typename T >
Handle< T > v8::internal::HandleScope::CloseAndEscape ( Handle< T handle_value)

Definition at line 119 of file handles-inl.h.

119  {
120  HandleScopeData* current = isolate_->handle_scope_data();
121 
122  T* value = *handle_value;
123  // Throw away all handles in the current scope.
125  // Allocate one handle in the parent scope.
126  DCHECK(current->level > 0);
127  Handle<T> result(CreateHandle<T>(isolate_, value));
128  // Reinitialize the current scope (so that it's ready
129  // to be used or closed again).
130  prev_next_ = current->next;
131  prev_limit_ = current->limit;
132  current->level++;
133  return result;
134 }
#define DCHECK(condition)
Definition: logging.h:205
#define T(name, string, precedence)
Definition: token.cc:25

References CloseScope(), DCHECK, v8::internal::Isolate::handle_scope_data(), isolate_, v8::internal::HandleScopeData::level, v8::internal::HandleScopeData::limit, v8::internal::HandleScopeData::next, prev_limit_, prev_next_, and T.

Referenced by v8::internal::TypeFeedbackOracle::BuildDictionary(), v8::Function::Call(), v8::Object::CallAsConstructor(), v8::Object::CallAsFunction(), v8::Object::GetOwnPropertyNames(), v8::Object::GetPropertyNames(), v8::internal::CompilationCacheEval::Lookup(), v8::internal::CompilationCacheRegExp::Lookup(), v8::Context::New(), v8::JSON::Parse(), v8::Script::Run(), v8::internal::ArrayConcatVisitor::SetDictionaryMode(), and v8::TryCatch::StackTrace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CloseScope()

void v8::internal::HandleScope::CloseScope ( Isolate isolate,
Object **  prev_next,
Object **  prev_limit 
)
inlinestaticprivate

Definition at line 99 of file handles-inl.h.

101  {
102  HandleScopeData* current = isolate->handle_scope_data();
103 
104  std::swap(current->next, prev_next);
105  current->level--;
106  if (current->limit != prev_limit) {
107  current->limit = prev_limit;
109 #ifdef ENABLE_HANDLE_ZAPPING
110  ZapRange(current->next, prev_limit);
111  } else {
112  ZapRange(current->next, prev_next);
113 #endif
114  }
115 }
static void DeleteExtensions(Isolate *isolate)
Definition: handles.cc:61

References DeleteExtensions(), v8::internal::Isolate::handle_scope_data(), isolate(), v8::internal::HandleScopeData::level, v8::internal::HandleScopeData::limit, and v8::internal::HandleScopeData::next.

Referenced by CloseAndEscape(), v8::HandleScope::~HandleScope(), and ~HandleScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateHandle()

template<typename T >
T ** v8::internal::HandleScope::CreateHandle ( Isolate isolate,
T value 
)
inlinestatic

Definition at line 138 of file handles-inl.h.

138  {
139  DCHECK(AllowHandleAllocation::IsAllowed());
140  HandleScopeData* current = isolate->handle_scope_data();
141 
142  internal::Object** cur = current->next;
143  if (cur == current->limit) cur = Extend(isolate);
144  // Update the current next field, set the value in the created
145  // handle, and return the result.
146  DCHECK(cur < current->limit);
147  current->next = cur + 1;
148 
149  T** result = reinterpret_cast<T**>(cur);
150  *result = value;
151  return result;
152 }
static internal::Object ** Extend(Isolate *isolate)
Definition: handles.cc:22
kSerializedDataOffset Object
Definition: objects-inl.h:5322

References DCHECK, Extend(), v8::internal::Isolate::handle_scope_data(), isolate(), v8::internal::HandleScopeData::limit, v8::internal::HandleScopeData::next, and T.

Referenced by v8::HandleScope::CreateHandle(), and v8::internal::Handle< T >::Handle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ current_level_address()

Address v8::internal::HandleScope::current_level_address ( Isolate isolate)
static

Definition at line 77 of file handles.cc.

77  {
78  return reinterpret_cast<Address>(&isolate->handle_scope_data()->level);
79 }
byte * Address
Definition: globals.h:101

References v8::internal::Isolate::handle_scope_data(), isolate(), and v8::internal::HandleScopeData::level.

+ Here is the call graph for this function:

◆ current_limit_address()

Address v8::internal::HandleScope::current_limit_address ( Isolate isolate)
static

Definition at line 87 of file handles.cc.

87  {
88  return reinterpret_cast<Address>(&isolate->handle_scope_data()->limit);
89 }
internal::Object ** limit
Definition: handles.h:286

References v8::internal::Isolate::handle_scope_data(), isolate(), and v8::internal::HandleScopeData::limit.

+ Here is the call graph for this function:

◆ current_next_address()

Address v8::internal::HandleScope::current_next_address ( Isolate isolate)
static

Definition at line 82 of file handles.cc.

82  {
83  return reinterpret_cast<Address>(&isolate->handle_scope_data()->next);
84 }
internal::Object ** next
Definition: handles.h:285

References v8::internal::Isolate::handle_scope_data(), isolate(), and v8::internal::HandleScopeData::next.

+ Here is the call graph for this function:

◆ DeleteExtensions()

void v8::internal::HandleScope::DeleteExtensions ( Isolate isolate)
static

Definition at line 61 of file handles.cc.

61  {
62  HandleScopeData* current = isolate->handle_scope_data();
64 }
void DeleteExtensions(internal::Object **prev_limit)
Definition: api.h:645
HandleScopeImplementer * handle_scope_implementer()
Definition: isolate.h:901

References v8::internal::HandleScopeImplementer::DeleteExtensions(), v8::internal::Isolate::handle_scope_data(), v8::internal::Isolate::handle_scope_implementer(), isolate(), and v8::internal::HandleScopeData::limit.

Referenced by CloseScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Extend()

Object ** v8::internal::HandleScope::Extend ( Isolate isolate)
staticprivate

Definition at line 22 of file handles.cc.

22  {
23  HandleScopeData* current = isolate->handle_scope_data();
24 
25  Object** result = current->next;
26 
27  DCHECK(result == current->limit);
28  // Make sure there's at least one scope on the stack and that the
29  // top of the scope stack isn't a barrier.
30  if (!Utils::ApiCheck(current->level != 0,
31  "v8::HandleScope::CreateHandle()",
32  "Cannot create a handle without a HandleScope")) {
33  return NULL;
34  }
35  HandleScopeImplementer* impl = isolate->handle_scope_implementer();
36  // If there's more room in the last block, we use that. This is used
37  // for fast creation of scopes after scope barriers.
38  if (!impl->blocks()->is_empty()) {
39  Object** limit = &impl->blocks()->last()[kHandleBlockSize];
40  if (current->limit != limit) {
41  current->limit = limit;
42  DCHECK(limit - current->next < kHandleBlockSize);
43  }
44  }
45 
46  // If we still haven't found a slot for the handle, we extend the
47  // current handle scope by allocating a new handle block.
48  if (result == current->limit) {
49  // If there's a spare block, use it for growing the current scope.
50  result = impl->GetSpareOrNewBlock();
51  // Add the extension to the global list of blocks, but count the
52  // extension as part of the current scope.
53  impl->blocks()->Add(result);
54  current->limit = &result[kHandleBlockSize];
55  }
56 
57  return result;
58 }
static bool ApiCheck(bool condition, const char *location, const char *message)
Definition: api.h:177
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
const int kHandleBlockSize
Definition: api.h:596

References v8::Utils::ApiCheck(), v8::internal::HandleScopeImplementer::blocks(), DCHECK, v8::internal::HandleScopeImplementer::GetSpareOrNewBlock(), v8::internal::Isolate::handle_scope_data(), v8::internal::Isolate::handle_scope_implementer(), isolate(), v8::internal::kHandleBlockSize, v8::internal::HandleScopeData::level, v8::internal::HandleScopeData::limit, v8::internal::HandleScopeData::next, and NULL.

Referenced by CreateHandle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isolate()

Isolate* v8::internal::HandleScope::isolate ( )
inline

Definition at line 208 of file handles.h.

208 { return isolate_; }

References isolate_.

Referenced by CloseScope(), CreateHandle(), current_level_address(), current_limit_address(), current_next_address(), DeleteExtensions(), Extend(), HandleScope(), and NumberOfHandles().

+ Here is the caller graph for this function:

◆ NumberOfHandles()

int v8::internal::HandleScope::NumberOfHandles ( Isolate isolate)
static

Definition at line 13 of file handles.cc.

13  {
14  HandleScopeImplementer* impl = isolate->handle_scope_implementer();
15  int n = impl->blocks()->length();
16  if (n == 0) return 0;
17  return ((n - 1) * kHandleBlockSize) + static_cast<int>(
18  (isolate->handle_scope_data()->next - impl->blocks()->last()));
19 }
List< internal::Object ** > * blocks()
Definition: api.h:537

References v8::internal::HandleScopeImplementer::blocks(), v8::internal::Isolate::handle_scope_data(), v8::internal::Isolate::handle_scope_implementer(), isolate(), v8::internal::kHandleBlockSize, and v8::internal::HandleScopeData::next.

Referenced by v8::HandleScope::NumberOfHandles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator delete()

void v8::internal::HandleScope::operator delete ( void *  size_t)
private

◆ operator new()

void* v8::internal::HandleScope::operator new ( size_t  size)
private

◆ operator=()

void v8::internal::HandleScope::operator= ( const HandleScope )
private

Friends And Related Function Documentation

◆ v8::HandleScope

friend class v8::HandleScope
friend

Definition at line 234 of file handles.h.

◆ v8::internal::DeferredHandles

friend class v8::internal::DeferredHandles
friend

Definition at line 235 of file handles.h.

◆ v8::internal::HandleScopeImplementer

Definition at line 236 of file handles.h.

◆ v8::internal::Isolate

friend class v8::internal::Isolate
friend

Definition at line 237 of file handles.h.

Member Data Documentation

◆ isolate_

Isolate* v8::internal::HandleScope::isolate_
private

Definition at line 217 of file handles.h.

Referenced by CloseAndEscape(), HandleScope(), isolate(), and ~HandleScope().

◆ prev_limit_

Object** v8::internal::HandleScope::prev_limit_
private

Definition at line 219 of file handles.h.

Referenced by CloseAndEscape(), HandleScope(), and ~HandleScope().

◆ prev_next_

Object** v8::internal::HandleScope::prev_next_
private

Definition at line 218 of file handles.h.

Referenced by CloseAndEscape(), HandleScope(), and ~HandleScope().


The documentation for this class was generated from the following files: