V8 Project
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 
5 #include "src/v8.h"
6 
7 #include "src/handles.h"
8 
9 namespace v8 {
10 namespace internal {
11 
12 
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 }
20 
21 
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  }
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 }
59 
60 
64 }
65 
66 
67 #ifdef ENABLE_HANDLE_ZAPPING
68 void HandleScope::ZapRange(Object** start, Object** end) {
69  DCHECK(end - start <= kHandleBlockSize);
70  for (Object** p = start; p != end; p++) {
71  *reinterpret_cast<Address*>(p) = v8::internal::kHandleZapValue;
72  }
73 }
74 #endif
75 
76 
78  return reinterpret_cast<Address>(&isolate->handle_scope_data()->level);
79 }
80 
81 
83  return reinterpret_cast<Address>(&isolate->handle_scope_data()->next);
84 }
85 
86 
88  return reinterpret_cast<Address>(&isolate->handle_scope_data()->limit);
89 }
90 
91 
93  : impl_(isolate->handle_scope_implementer()) {
96  Object** new_next = impl_->GetSpareOrNewBlock();
97  Object** new_limit = &new_next[kHandleBlockSize];
98  DCHECK(data->limit == &impl_->blocks()->last()[kHandleBlockSize]);
99  impl_->blocks()->Add(new_next);
100 
101 #ifdef DEBUG
102  prev_level_ = data->level;
103 #endif
104  data->level++;
105  prev_limit_ = data->limit;
106  prev_next_ = data->next;
107  data->next = new_next;
108  data->limit = new_limit;
109 }
110 
111 
114  DCHECK(handles_detached_);
115  DCHECK(impl_->isolate()->handle_scope_data()->level == prev_level_);
116 }
117 
118 
120  DeferredHandles* deferred = impl_->Detach(prev_limit_);
122  data->next = prev_next_;
123  data->limit = prev_limit_;
124 #ifdef DEBUG
125  handles_detached_ = true;
126 #endif
127  return deferred;
128 }
129 
130 } } // namespace v8::internal
static bool ApiCheck(bool condition, const char *location, const char *message)
Definition: api.h:177
DeferredHandleScope(Isolate *isolate)
Definition: handles.cc:92
HandleScopeImplementer * impl_
Definition: handles.h:256
DeferredHandles * Detach()
Definition: handles.cc:119
DeferredHandles * Detach(Object **prev_limit)
Definition: api.cc:7605
internal::Object ** GetSpareOrNewBlock()
Definition: api.h:636
Isolate * isolate() const
Definition: api.h:538
void DeleteExtensions(internal::Object **prev_limit)
Definition: api.h:645
List< internal::Object ** > * blocks()
Definition: api.h:537
static int NumberOfHandles(Isolate *isolate)
Definition: handles.cc:13
static Address current_limit_address(Isolate *isolate)
Definition: handles.cc:87
static void DeleteExtensions(Isolate *isolate)
Definition: handles.cc:61
static Address current_next_address(Isolate *isolate)
Definition: handles.cc:82
static Address current_level_address(Isolate *isolate)
Definition: handles.cc:77
static internal::Object ** Extend(Isolate *isolate)
Definition: handles.cc:22
HandleScopeImplementer * handle_scope_implementer()
Definition: isolate.h:901
HandleScopeData * handle_scope_data()
Definition: isolate.h:899
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
#define DCHECK(condition)
Definition: logging.h:205
const Address kHandleZapValue
Definition: globals.h:270
const int kHandleBlockSize
Definition: api.h:596
byte * Address
Definition: globals.h:101
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
internal::Object ** next
Definition: handles.h:285
internal::Object ** limit
Definition: handles.h:286