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

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

Issue 1417013007: Revert of Canonicalize handles for optimized compilation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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') | src/ia32/macro-assembler-ia32.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 #ifndef V8_HANDLES_INL_H_ 5 #ifndef V8_HANDLES_INL_H_
6 #define V8_HANDLES_INL_H_ 6 #define V8_HANDLES_INL_H_
7 7
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/heap/heap.h" 10 #include "src/heap/heap.h"
11 #include "src/isolate.h" 11 #include "src/isolate.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 HandleBase::HandleBase(Object* object, Isolate* isolate) 16 HandleBase::HandleBase(Object* object, Isolate* isolate)
17 : location_(HandleScope::GetHandle(isolate, object)) {} 17 : location_(HandleScope::CreateHandle(isolate, object)) {}
18 18
19 19
20 template <typename T> 20 HandleScope::HandleScope(Isolate* isolate) {
21 // Allocate a new handle for the object, do not canonicalize. 21 HandleScopeData* current = isolate->handle_scope_data();
22 Handle<T> Handle<T>::New(T* object, Isolate* isolate) { 22 isolate_ = isolate;
23 return Handle( 23 prev_next_ = current->next;
24 reinterpret_cast<T**>(HandleScope::CreateHandle(isolate, object))); 24 prev_limit_ = current->limit;
25 current->level++;
25 } 26 }
26 27
27 28
28 HandleScope::HandleScope(Isolate* isolate) {
29 HandleScopeData* data = isolate->handle_scope_data();
30 isolate_ = isolate;
31 prev_next_ = data->next;
32 prev_limit_ = data->limit;
33 data->level++;
34 }
35
36
37 template <typename T> 29 template <typename T>
38 inline std::ostream& operator<<(std::ostream& os, Handle<T> handle) { 30 inline std::ostream& operator<<(std::ostream& os, Handle<T> handle) {
39 return os << Brief(*handle); 31 return os << Brief(*handle);
40 } 32 }
41 33
42 34
43 HandleScope::~HandleScope() { 35 HandleScope::~HandleScope() {
44 #ifdef DEBUG 36 #ifdef DEBUG
45 if (FLAG_check_handle_count) { 37 if (FLAG_check_handle_count) {
46 int before = NumberOfHandles(isolate_); 38 int before = NumberOfHandles(isolate_);
(...skipping 30 matching lines...) Expand all
77 69
78 70
79 template <typename T> 71 template <typename T>
80 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) { 72 Handle<T> HandleScope::CloseAndEscape(Handle<T> handle_value) {
81 HandleScopeData* current = isolate_->handle_scope_data(); 73 HandleScopeData* current = isolate_->handle_scope_data();
82 74
83 T* value = *handle_value; 75 T* value = *handle_value;
84 // Throw away all handles in the current scope. 76 // Throw away all handles in the current scope.
85 CloseScope(isolate_, prev_next_, prev_limit_); 77 CloseScope(isolate_, prev_next_, prev_limit_);
86 // Allocate one handle in the parent scope. 78 // Allocate one handle in the parent scope.
87 DCHECK(current->level > current->sealed_level); 79 DCHECK(current->level > 0);
88 Handle<T> result(value, isolate_); 80 Handle<T> result(value, isolate_);
89 // Reinitialize the current scope (so that it's ready 81 // Reinitialize the current scope (so that it's ready
90 // to be used or closed again). 82 // to be used or closed again).
91 prev_next_ = current->next; 83 prev_next_ = current->next;
92 prev_limit_ = current->limit; 84 prev_limit_ = current->limit;
93 current->level++; 85 current->level++;
94 return result; 86 return result;
95 } 87 }
96 88
97 89
98 Object** HandleScope::CreateHandle(Isolate* isolate, Object* value) { 90 template <typename T>
91 T** HandleScope::CreateHandle(Isolate* isolate, T* value) {
99 DCHECK(AllowHandleAllocation::IsAllowed()); 92 DCHECK(AllowHandleAllocation::IsAllowed());
100 HandleScopeData* data = isolate->handle_scope_data(); 93 HandleScopeData* current = isolate->handle_scope_data();
101 94
102 Object** result = data->next; 95 Object** cur = current->next;
103 if (result == data->limit) result = Extend(isolate); 96 if (cur == current->limit) cur = Extend(isolate);
104 // Update the current next field, set the value in the created 97 // Update the current next field, set the value in the created
105 // handle, and return the result. 98 // handle, and return the result.
106 DCHECK(result < data->limit); 99 DCHECK(cur < current->limit);
107 data->next = result + 1; 100 current->next = cur + 1;
108 101
102 T** result = reinterpret_cast<T**>(cur);
109 *result = value; 103 *result = value;
110 return result; 104 return result;
111 } 105 }
112 106
113 107
114 Object** HandleScope::GetHandle(Isolate* isolate, Object* value) {
115 DCHECK(AllowHandleAllocation::IsAllowed());
116 HandleScopeData* data = isolate->handle_scope_data();
117 CanonicalHandleScope* canonical = data->canonical_scope;
118 return canonical ? canonical->Lookup(value) : CreateHandle(isolate, value);
119 }
120
121
122 #ifdef DEBUG 108 #ifdef DEBUG
123 inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) { 109 inline SealHandleScope::SealHandleScope(Isolate* isolate) : isolate_(isolate) {
124 // Make sure the current thread is allowed to create handles to begin with. 110 // Make sure the current thread is allowed to create handles to begin with.
125 CHECK(AllowHandleAllocation::IsAllowed()); 111 CHECK(AllowHandleAllocation::IsAllowed());
126 HandleScopeData* current = isolate_->handle_scope_data(); 112 HandleScopeData* current = isolate_->handle_scope_data();
127 // Shrink the current handle scope to make it impossible to do 113 // Shrink the current handle scope to make it impossible to do
128 // handle allocations without an explicit handle scope. 114 // handle allocations without an explicit handle scope.
129 prev_limit_ = current->limit; 115 limit_ = current->limit;
130 current->limit = current->next; 116 current->limit = current->next;
131 prev_sealed_level_ = current->sealed_level; 117 level_ = current->level;
132 current->sealed_level = current->level; 118 current->level = 0;
133 } 119 }
134 120
135 121
136 inline SealHandleScope::~SealHandleScope() { 122 inline SealHandleScope::~SealHandleScope() {
137 // Restore state in current handle scope to re-enable handle 123 // Restore state in current handle scope to re-enable handle
138 // allocations. 124 // allocations.
139 HandleScopeData* current = isolate_->handle_scope_data(); 125 HandleScopeData* current = isolate_->handle_scope_data();
126 DCHECK_EQ(0, current->level);
127 current->level = level_;
140 DCHECK_EQ(current->next, current->limit); 128 DCHECK_EQ(current->next, current->limit);
141 current->limit = prev_limit_; 129 current->limit = limit_;
142 DCHECK_EQ(current->level, current->sealed_level);
143 current->sealed_level = prev_sealed_level_;
144 } 130 }
145 131
146 #endif 132 #endif
147 133
148 } // namespace internal 134 } // namespace internal
149 } // namespace v8 135 } // namespace v8
150 136
151 #endif // V8_HANDLES_INL_H_ 137 #endif // V8_HANDLES_INL_H_
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | src/ia32/macro-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698