Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: src/handles-inl.h

Issue 1235253007: Revert of [handles] Sanitize Handle and friends. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/handles.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 //
4 5
5 #ifndef V8_HANDLES_INL_H_ 6 #ifndef V8_HANDLES_INL_H_
6 #define V8_HANDLES_INL_H_ 7 #define V8_HANDLES_INL_H_
7 8
8 #include "src/api.h" 9 #include "src/api.h"
9 #include "src/handles.h" 10 #include "src/handles.h"
10 #include "src/heap/heap.h" 11 #include "src/heap/heap.h"
11 #include "src/isolate.h" 12 #include "src/isolate.h"
12 13
13 namespace v8 { 14 namespace v8 {
14 namespace internal { 15 namespace internal {
15 16
16 HandleBase::HandleBase(Object* object, Isolate* isolate) 17 template<typename T>
17 : location_(HandleScope::CreateHandle(isolate, object)) {} 18 Handle<T>::Handle(T* obj) {
19 location_ = HandleScope::CreateHandle(obj->GetIsolate(), obj);
20 }
21
22
23 template<typename T>
24 Handle<T>::Handle(T* obj, Isolate* isolate) {
25 location_ = HandleScope::CreateHandle(isolate, obj);
26 }
27
28
29 template <typename T>
30 inline bool Handle<T>::is_identical_to(const Handle<T> o) const {
31 // Dereferencing deferred handles to check object equality is safe.
32 SLOW_DCHECK(
33 (location_ == NULL || IsDereferenceAllowed(NO_DEFERRED_CHECK)) &&
34 (o.location_ == NULL || o.IsDereferenceAllowed(NO_DEFERRED_CHECK)));
35 if (location_ == o.location_) return true;
36 if (location_ == NULL || o.location_ == NULL) return false;
37 return *location_ == *o.location_;
38 }
39
40
41 template <typename T>
42 inline T* Handle<T>::operator*() const {
43 SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK));
44 return *bit_cast<T**>(location_);
45 }
46
47 template <typename T>
48 inline T** Handle<T>::location() const {
49 SLOW_DCHECK(location_ == NULL ||
50 IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK));
51 return location_;
52 }
53
54 #ifdef DEBUG
55 template <typename T>
56 bool Handle<T>::IsDereferenceAllowed(DereferenceCheckMode mode) const {
57 DCHECK(location_ != NULL);
58 Object* object = *bit_cast<T**>(location_);
59 if (object->IsSmi()) return true;
60 HeapObject* heap_object = HeapObject::cast(object);
61 Heap* heap = heap_object->GetHeap();
62 Object** handle = reinterpret_cast<Object**>(location_);
63 Object** roots_array_start = heap->roots_array_start();
64 if (roots_array_start <= handle &&
65 handle < roots_array_start + Heap::kStrongRootListLength &&
66 heap->RootCanBeTreatedAsConstant(
67 static_cast<Heap::RootListIndex>(handle - roots_array_start))) {
68 return true;
69 }
70 if (!AllowHandleDereference::IsAllowed()) return false;
71 if (mode == INCLUDE_DEFERRED_CHECK &&
72 !AllowDeferredHandleDereference::IsAllowed()) {
73 // Accessing cells, maps and internalized strings is safe.
74 if (heap_object->IsCell()) return true;
75 if (heap_object->IsMap()) return true;
76 if (heap_object->IsInternalizedString()) return true;
77 return !heap->isolate()->IsDeferredHandle(handle);
78 }
79 return true;
80 }
81 #endif
82
18 83
19 84
20 HandleScope::HandleScope(Isolate* isolate) { 85 HandleScope::HandleScope(Isolate* isolate) {
21 HandleScopeData* current = isolate->handle_scope_data(); 86 HandleScopeData* current = isolate->handle_scope_data();
22 isolate_ = isolate; 87 isolate_ = isolate;
23 prev_next_ = current->next; 88 prev_next_ = current->next;
24 prev_limit_ = current->limit; 89 prev_limit_ = current->limit;
25 current->level++; 90 current->level++;
26 } 91 }
27 92
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 129
65 template <typename T> 130 template <typename T>
66 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { 131 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) {
67 HandleScopeData* current = isolate_->handle_scope_data(); 132 HandleScopeData* current = isolate_->handle_scope_data();
68 133
69 T* value = *handle_value; 134 T* value = *handle_value;
70 // Throw away all handles in the current scope. 135 // Throw away all handles in the current scope.
71 CloseScope(isolate_, prev_next_, prev_limit_); 136 CloseScope(isolate_, prev_next_, prev_limit_);
72 // Allocate one handle in the parent scope. 137 // Allocate one handle in the parent scope.
73 DCHECK(current->level > 0); 138 DCHECK(current->level > 0);
74 Handle<T> result(value, isolate_); 139 Handle<T> result(CreateHandle<T>(isolate_, value));
75 // Reinitialize the current scope (so that it's ready 140 // Reinitialize the current scope (so that it's ready
76 // to be used or closed again). 141 // to be used or closed again).
77 prev_next_ = current->next; 142 prev_next_ = current->next;
78 prev_limit_ = current->limit; 143 prev_limit_ = current->limit;
79 current->level++; 144 current->level++;
80 return result; 145 return result;
81 } 146 }
82 147
83 148
84 template <typename T> 149 template <typename T>
85 T** HandleScope::CreateHandle(Isolate* isolate, T* value) { 150 T** HandleScope::CreateHandle(Isolate* isolate, T* value) {
86 DCHECK(AllowHandleAllocation::IsAllowed()); 151 DCHECK(AllowHandleAllocation::IsAllowed());
87 HandleScopeData* current = isolate->handle_scope_data(); 152 HandleScopeData* current = isolate->handle_scope_data();
88 153
89 Object** cur = current->next; 154 internal::Object** cur = current->next;
90 if (cur == current->limit) cur = Extend(isolate); 155 if (cur == current->limit) cur = Extend(isolate);
91 // Update the current next field, set the value in the created 156 // Update the current next field, set the value in the created
92 // handle, and return the result. 157 // handle, and return the result.
93 DCHECK(cur < current->limit); 158 DCHECK(cur < current->limit);
94 current->next = cur + 1; 159 current->next = cur + 1;
95 160
96 T** result = reinterpret_cast<T**>(cur); 161 T** result = reinterpret_cast<T**>(cur);
97 *result = value; 162 *result = value;
98 return result; 163 return result;
99 } 164 }
(...skipping 18 matching lines...) Expand all
118 // allocations. 183 // allocations.
119 HandleScopeData* current = isolate_->handle_scope_data(); 184 HandleScopeData* current = isolate_->handle_scope_data();
120 DCHECK_EQ(0, current->level); 185 DCHECK_EQ(0, current->level);
121 current->level = level_; 186 current->level = level_;
122 DCHECK_EQ(current->next, current->limit); 187 DCHECK_EQ(current->next, current->limit);
123 current->limit = limit_; 188 current->limit = limit_;
124 } 189 }
125 190
126 #endif 191 #endif
127 192
128 } // namespace internal 193 } } // namespace v8::internal
129 } // namespace v8
130 194
131 #endif // V8_HANDLES_INL_H_ 195 #endif // V8_HANDLES_INL_H_
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698