V8 Project
assert-scope.cc
Go to the documentation of this file.
1 // Copyright 2014 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/assert-scope.h"
6 
9 #include "src/isolate-inl.h"
10 #include "src/utils.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 namespace {
16 
17 struct PerThreadAssertKeyConstructTrait FINAL {
20  }
21 };
22 
23 
25  PerThreadAssertKeyConstructTrait>::type
27 
28 
30 
31 } // namespace
32 
33 
34 class PerThreadAssertData FINAL {
35  public:
36  PerThreadAssertData() : nesting_level_(0) {
37  for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) {
38  assert_states_[i] = true;
39  }
40  }
41 
43  for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; ++i) {
44  DCHECK(assert_states_[i]);
45  }
46  }
47 
48  bool Get(PerThreadAssertType type) const { return assert_states_[type]; }
49  void Set(PerThreadAssertType type, bool x) { assert_states_[type] = x; }
50 
51  void IncrementLevel() { ++nesting_level_; }
52  bool DecrementLevel() { return --nesting_level_ == 0; }
53 
54  static PerThreadAssertData* GetCurrent() {
55  return reinterpret_cast<PerThreadAssertData*>(
57  }
58  static void SetCurrent(PerThreadAssertData* data) {
60  }
61 
62  private:
63  bool assert_states_[LAST_PER_THREAD_ASSERT_TYPE];
65 
66  DISALLOW_COPY_AND_ASSIGN(PerThreadAssertData);
67 };
68 
69 
70 template <PerThreadAssertType kType, bool kAllow>
72  : data_(PerThreadAssertData::GetCurrent()) {
73  if (data_ == NULL) {
74  data_ = new PerThreadAssertData();
75  PerThreadAssertData::SetCurrent(data_);
76  }
77  data_->IncrementLevel();
78  old_state_ = data_->Get(kType);
79  data_->Set(kType, kAllow);
80 }
81 
82 
83 template <PerThreadAssertType kType, bool kAllow>
85  DCHECK_NOT_NULL(data_);
86  data_->Set(kType, old_state_);
87  if (data_->DecrementLevel()) {
88  PerThreadAssertData::SetCurrent(NULL);
89  delete data_;
90  }
91 }
92 
93 
94 // static
95 template <PerThreadAssertType kType, bool kAllow>
97  PerThreadAssertData* data = PerThreadAssertData::GetCurrent();
98  return data == NULL || data->Get(kType);
99 }
100 
101 
102 template <PerIsolateAssertType kType, bool kAllow>
103 class PerIsolateAssertScope<kType, kAllow>::DataBit
104  : public BitField<bool, kType, 1> {};
105 
106 
107 template <PerIsolateAssertType kType, bool kAllow>
109  : isolate_(isolate), old_data_(isolate->per_isolate_assert_data()) {
110  DCHECK_NOT_NULL(isolate);
111  STATIC_ASSERT(kType < 32);
112  isolate_->set_per_isolate_assert_data(DataBit::update(old_data_, kAllow));
113 }
114 
115 
116 template <PerIsolateAssertType kType, bool kAllow>
118  isolate_->set_per_isolate_assert_data(old_data_);
119 }
120 
121 
122 // static
123 template <PerIsolateAssertType kType, bool kAllow>
125  return DataBit::decode(isolate->per_isolate_assert_data());
126 }
127 
128 
129 // -----------------------------------------------------------------------------
130 // Instantiations.
131 
142 
153 
154 } // namespace internal
155 } // namespace v8
int32_t LocalStorageKey
Definition: platform.h:416
static LocalStorageKey CreateThreadLocalKey()
static void * GetThreadLocal(LocalStorageKey key)
static void SetThreadLocal(LocalStorageKey key, void *value)
static U update(U previous, T value)
Definition: utils.h:223
Source to read snapshot and builtins files from.
Definition: lithium-arm.h:372
DISALLOW_COPY_AND_ASSIGN(PerThreadAssertData)
bool Get(PerThreadAssertType type) const
Definition: assert-scope.cc:48
static PerThreadAssertData * GetCurrent()
Definition: assert-scope.cc:54
static void SetCurrent(PerThreadAssertData *data)
Definition: assert-scope.cc:58
void Set(PerThreadAssertType type, bool x)
Definition: assert-scope.cc:49
static bool IsAllowed(Isolate *isolate)
PerThreadAssertData * data_
Definition: assert-scope.h:47
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_NOT_NULL(p)
Definition: logging.h:213
#define DCHECK(condition)
Definition: logging.h:205
base::LazyStaticInstance< base::Thread::LocalStorageKey, PerThreadAssertKeyConstructTrait >::type PerThreadAssertKey
Definition: assert-scope.cc:26
@ LAST_PER_THREAD_ASSERT_TYPE
Definition: assert-scope.h:25
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
static void Construct(base::Thread::LocalStorageKey *key)
Definition: assert-scope.cc:18