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

Side by Side Diff: runtime/vm/handles_impl.h

Issue 8984006: Implement weak persistent handles in the Dart API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_HANDLES_IMPL_H_ 5 #ifndef VM_HANDLES_IMPL_H_
6 #define VM_HANDLES_IMPL_H_ 6 #define VM_HANDLES_IMPL_H_
7 7
8 namespace dart { 8 namespace dart {
9 9
10 DECLARE_DEBUG_FLAG(bool, trace_handles_count); 10 DECLARE_DEBUG_FLAG(bool, trace_handles_count);
(...skipping 12 matching lines...) Expand all
23 23
24 // Visit all scoped handles. 24 // Visit all scoped handles.
25 block = &first_scoped_block_; 25 block = &first_scoped_block_;
26 do { 26 do {
27 block->VisitObjectPointers(visitor); 27 block->VisitObjectPointers(visitor);
28 block = block->next_block(); 28 block = block->next_block();
29 } while (block != NULL); 29 } while (block != NULL);
30 } 30 }
31 31
32 32
33 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr>
34 void Handles<kHandleSizeInWords,
35 kHandlesPerChunk,
36 kOffsetOfRawPtr>::Visit(HandleVisitor* visitor) {
37 // Visit all zone handles.
38 HandlesBlock* block = zone_blocks_;
39 while (block != NULL) {
40 block->Visit(visitor);
41 block = block->next_block();
42 }
43
44 // Visit all scoped handles.
45 block = &first_scoped_block_;
46 do {
47 block->Visit(visitor);
48 block = block->next_block();
49 } while (block != NULL);
50 }
51
52
33 // Figure out the current handle scope using the current Isolate and 53 // Figure out the current handle scope using the current Isolate and
34 // allocate a handle in that scope. The function assumes that a 54 // allocate a handle in that scope. The function assumes that a
35 // current Isolate, current zone and current handle scope exist. It 55 // current Isolate, current zone and current handle scope exist. It
36 // asserts for this appropriately. 56 // asserts for this appropriately.
37 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> 57 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr>
38 uword Handles<kHandleSizeInWords, 58 uword Handles<kHandleSizeInWords,
39 kHandlesPerChunk, 59 kHandlesPerChunk,
40 kOffsetOfRawPtr>::AllocateHandle() { 60 kOffsetOfRawPtr>::AllocateHandle() {
41 // TODO(5411412): Accessing the current isolate is a performance problem, 61 // TODO(5411412): Accessing the current isolate is a performance problem,
42 // consider passing it down as a parameter. 62 // consider passing it down as a parameter.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 kOffsetOfRawPtr>::HandlesBlock::VisitObjectPointers( 296 kOffsetOfRawPtr>::HandlesBlock::VisitObjectPointers(
277 ObjectPointerVisitor* visitor) { 297 ObjectPointerVisitor* visitor) {
278 ASSERT(visitor != NULL); 298 ASSERT(visitor != NULL);
279 for (intptr_t i = 0; i < next_handle_slot_; i += kHandleSizeInWords) { 299 for (intptr_t i = 0; i < next_handle_slot_; i += kHandleSizeInWords) {
280 visitor->VisitPointer( 300 visitor->VisitPointer(
281 reinterpret_cast<RawObject**>(&data_[i + kOffsetOfRawPtr/kWordSize])); 301 reinterpret_cast<RawObject**>(&data_[i + kOffsetOfRawPtr/kWordSize]));
282 } 302 }
283 } 303 }
284 304
285 305
306 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr>
307 void Handles<kHandleSizeInWords,
308 kHandlesPerChunk,
309 kOffsetOfRawPtr>::HandlesBlock::Visit(HandleVisitor* visitor) {
310 ASSERT(visitor != NULL);
311 for (intptr_t i = 0; i < next_handle_slot_; i += kHandleSizeInWords) {
312 visitor->Visit(&data_[i + kOffsetOfRawPtr/kWordSize]);
313 }
314 }
315
316
286 #if defined(DEBUG) 317 #if defined(DEBUG)
287 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> 318 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr>
288 void Handles<kHandleSizeInWords, 319 void Handles<kHandleSizeInWords,
289 kHandlesPerChunk, 320 kHandlesPerChunk,
290 kOffsetOfRawPtr>::HandlesBlock::ZapFreeHandles() { 321 kOffsetOfRawPtr>::HandlesBlock::ZapFreeHandles() {
291 // Reinitialize the handle area to some uninitialized value. 322 // Reinitialize the handle area to some uninitialized value.
292 for (intptr_t i = next_handle_slot_; 323 for (intptr_t i = next_handle_slot_;
293 i < (kHandleSizeInWords * kHandlesPerChunk); 324 i < (kHandleSizeInWords * kHandlesPerChunk);
294 i++) { 325 i++) {
295 data_[i] = kZapUninitializedWord; 326 data_[i] = kZapUninitializedWord;
296 } 327 }
297 } 328 }
298 #endif 329 #endif
299 330
300 331
301 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> 332 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr>
302 int Handles<kHandleSizeInWords, 333 int Handles<kHandleSizeInWords,
303 kHandlesPerChunk, 334 kHandlesPerChunk,
304 kOffsetOfRawPtr>::HandlesBlock::HandleCount() const { 335 kOffsetOfRawPtr>::HandlesBlock::HandleCount() const {
305 return (next_handle_slot_ / kHandleSizeInWords); 336 return (next_handle_slot_ / kHandleSizeInWords);
306 } 337 }
307 338
308 } // namespace dart 339 } // namespace dart
309 340
310 #endif // VM_HANDLES_IMPL_H_ 341 #endif // VM_HANDLES_IMPL_H_
OLDNEW
« runtime/include/dart_api.h ('K') | « runtime/vm/handles.h ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698