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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 9655011: Implement prologue weak persistent handles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: minor pre-review changes Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 ref->set_raw(object); 99 ref->set_raw(object);
100 return reinterpret_cast<Dart_Handle>(ref); 100 return reinterpret_cast<Dart_Handle>(ref);
101 } 101 }
102 102
103 RawObject* Api::UnwrapHandle(Dart_Handle object) { 103 RawObject* Api::UnwrapHandle(Dart_Handle object) {
104 #ifdef DEBUG 104 #ifdef DEBUG
105 Isolate* isolate = Isolate::Current(); 105 Isolate* isolate = Isolate::Current();
106 ASSERT(isolate != NULL); 106 ASSERT(isolate != NULL);
107 ApiState* state = isolate->api_state(); 107 ApiState* state = isolate->api_state();
108 ASSERT(state != NULL); 108 ASSERT(state != NULL);
109 ASSERT(state->IsValidWeakPersistentHandle(object) || 109 ASSERT(state->IsValidPrologueWeakPersistentHandle(object) ||
110 state->IsValidWeakPersistentHandle(object) ||
110 state->IsValidPersistentHandle(object) || 111 state->IsValidPersistentHandle(object) ||
111 state->IsValidLocalHandle(object)); 112 state->IsValidLocalHandle(object));
112 ASSERT(WeakPersistentHandle::raw_offset() == 0 && 113 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 &&
113 PersistentHandle::raw_offset() == 0 && 114 PersistentHandle::raw_offset() == 0 &&
114 LocalHandle::raw_offset() == 0); 115 LocalHandle::raw_offset() == 0);
115 #endif 116 #endif
116 return *(reinterpret_cast<RawObject**>(object)); 117 return *(reinterpret_cast<RawObject**>(object));
117 } 118 }
118 119
119 #define DEFINE_UNWRAP(Type) \ 120 #define DEFINE_UNWRAP(Type) \
120 const Type& Api::Unwrap##Type##Handle(Dart_Handle dart_handle) { \ 121 const Type& Api::Unwrap##Type##Handle(Dart_Handle dart_handle) { \
121 const Object& tmp = Object::Handle(Api::UnwrapHandle(dart_handle)); \ 122 const Object& tmp = Object::Handle(Api::UnwrapHandle(dart_handle)); \
122 Type& typed_handle = Type::Handle(); \ 123 Type& typed_handle = Type::Handle(); \
(...skipping 13 matching lines...) Expand all
136 } 137 }
137 138
138 139
139 PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state, 140 PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state,
140 Dart_Handle object) { 141 Dart_Handle object) {
141 ASSERT(state.IsValidPersistentHandle(object)); 142 ASSERT(state.IsValidPersistentHandle(object));
142 return reinterpret_cast<PersistentHandle*>(object); 143 return reinterpret_cast<PersistentHandle*>(object);
143 } 144 }
144 145
145 146
146 WeakPersistentHandle* Api::UnwrapAsWeakPersistentHandle(const ApiState& state, 147 FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle(
147 Dart_Handle object) { 148 const ApiState& state,
149 Dart_Handle object) {
148 ASSERT(state.IsValidWeakPersistentHandle(object)); 150 ASSERT(state.IsValidWeakPersistentHandle(object));
149 return reinterpret_cast<WeakPersistentHandle*>(object); 151 return reinterpret_cast<FinalizablePersistentHandle*>(object);
150 } 152 }
151 153
152 154
155 FinalizablePersistentHandle* Api::UnwrapAsPrologueWeakPersistentHandle(
156 const ApiState& state,
157 Dart_Handle object) {
158 ASSERT(state.IsValidPrologueWeakPersistentHandle(object));
159 return reinterpret_cast<FinalizablePersistentHandle*>(object);
160 }
161
162
153 Dart_Isolate Api::CastIsolate(Isolate* isolate) { 163 Dart_Isolate Api::CastIsolate(Isolate* isolate) {
154 return reinterpret_cast<Dart_Isolate>(isolate); 164 return reinterpret_cast<Dart_Isolate>(isolate);
155 } 165 }
156 166
157 167
158 Dart_Handle Api::Success() { 168 Dart_Handle Api::Success() {
159 Isolate* isolate = Isolate::Current(); 169 Isolate* isolate = Isolate::Current();
160 ASSERT(isolate != NULL); 170 ASSERT(isolate != NULL);
161 ApiState* state = isolate->api_state(); 171 ApiState* state = isolate->api_state();
162 ASSERT(state != NULL); 172 ASSERT(state != NULL);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( 423 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle(
414 Dart_Handle object, 424 Dart_Handle object,
415 void* peer, 425 void* peer,
416 Dart_WeakPersistentHandleFinalizer callback) { 426 Dart_WeakPersistentHandleFinalizer callback) {
417 Isolate* isolate = Isolate::Current(); 427 Isolate* isolate = Isolate::Current();
418 CHECK_ISOLATE(isolate); 428 CHECK_ISOLATE(isolate);
419 DARTSCOPE_NOCHECKS(isolate); 429 DARTSCOPE_NOCHECKS(isolate);
420 ApiState* state = isolate->api_state(); 430 ApiState* state = isolate->api_state();
421 ASSERT(state != NULL); 431 ASSERT(state != NULL);
422 const Object& ref = Object::Handle(Api::UnwrapHandle(object)); 432 const Object& ref = Object::Handle(Api::UnwrapHandle(object));
423 WeakPersistentHandle* weak_ref = 433 FinalizablePersistentHandle* weak_ref =
424 state->weak_persistent_handles().AllocateHandle(); 434 state->weak_persistent_handles().AllocateHandle();
425 weak_ref->set_raw(ref); 435 weak_ref->set_raw(ref);
426 weak_ref->set_peer(peer); 436 weak_ref->set_peer(peer);
427 weak_ref->set_callback(callback); 437 weak_ref->set_callback(callback);
428 return reinterpret_cast<Dart_Handle>(weak_ref); 438 return reinterpret_cast<Dart_Handle>(weak_ref);
429 } 439 }
430 440
431 441
442 DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle(
443 Dart_Handle object,
444 void* peer,
445 Dart_WeakPersistentHandleFinalizer callback) {
446 Isolate* isolate = Isolate::Current();
447 CHECK_ISOLATE(isolate);
448 DARTSCOPE_NOCHECKS(isolate);
449 ApiState* state = isolate->api_state();
450 ASSERT(state != NULL);
451 const Object& ref = Object::Handle(Api::UnwrapHandle(object));
452 FinalizablePersistentHandle* prologue_weak_ref =
453 state->prologue_weak_persistent_handles().AllocateHandle();
454 prologue_weak_ref->set_raw(ref);
455 prologue_weak_ref->set_peer(peer);
456 prologue_weak_ref->set_callback(callback);
457 return reinterpret_cast<Dart_Handle>(prologue_weak_ref);
siva 2012/03/09 21:48:41 This seems identical to Dart_NewWeakPersistentHand
cshapiro 2012/03/13 23:06:43 Yes, it is pretty close. I have factored out the
458 }
459
460
432 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { 461 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
433 Isolate* isolate = Isolate::Current(); 462 Isolate* isolate = Isolate::Current();
434 CHECK_ISOLATE(isolate); 463 CHECK_ISOLATE(isolate);
435 ApiState* state = isolate->api_state(); 464 ApiState* state = isolate->api_state();
436 ASSERT(state != NULL); 465 ASSERT(state != NULL);
466 if (state->IsValidPrologueWeakPersistentHandle(object)) {
467 FinalizablePersistentHandle* prologue_weak_ref =
468 Api::UnwrapAsPrologueWeakPersistentHandle(*state, object);
469 state->prologue_weak_persistent_handles().FreeHandle(prologue_weak_ref);
470 return;
471 }
437 if (state->IsValidWeakPersistentHandle(object)) { 472 if (state->IsValidWeakPersistentHandle(object)) {
438 WeakPersistentHandle* weak_ref = 473 FinalizablePersistentHandle* weak_ref =
439 Api::UnwrapAsWeakPersistentHandle(*state, object); 474 Api::UnwrapAsWeakPersistentHandle(*state, object);
440 state->weak_persistent_handles().FreeHandle(weak_ref); 475 state->weak_persistent_handles().FreeHandle(weak_ref);
441 } else { 476 return;
442 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); 477 }
443 ASSERT(!state->IsProtectedHandle(ref)); 478 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
444 if (!state->IsProtectedHandle(ref)) { 479 ASSERT(!state->IsProtectedHandle(ref));
445 state->persistent_handles().FreeHandle(ref); 480 if (!state->IsProtectedHandle(ref)) {
446 } 481 state->persistent_handles().FreeHandle(ref);
447 } 482 }
448 } 483 }
449 484
450 485
451 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) { 486 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) {
452 Isolate* isolate = Isolate::Current(); 487 Isolate* isolate = Isolate::Current();
453 CHECK_ISOLATE(isolate); 488 CHECK_ISOLATE(isolate);
454 ApiState* state = isolate->api_state(); 489 ApiState* state = isolate->api_state();
455 ASSERT(state != NULL); 490 ASSERT(state != NULL);
456 return state->IsValidWeakPersistentHandle(object); 491 return state->IsValidWeakPersistentHandle(object);
457 } 492 }
458 493
459 494
495 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_Handle object) {
496 Isolate* isolate = Isolate::Current();
497 CHECK_ISOLATE(isolate);
498 ApiState* state = isolate->api_state();
499 ASSERT(state != NULL);
500 return state->IsValidPrologueWeakPersistentHandle(object);
501 }
502
503
460 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(Dart_Handle* keys, 504 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(Dart_Handle* keys,
461 intptr_t num_keys, 505 intptr_t num_keys,
462 Dart_Handle* values, 506 Dart_Handle* values,
463 intptr_t num_values) { 507 intptr_t num_values) {
464 Isolate* isolate = Isolate::Current(); 508 Isolate* isolate = Isolate::Current();
465 CHECK_ISOLATE(isolate); 509 CHECK_ISOLATE(isolate);
466 ApiState* state = isolate->api_state(); 510 ApiState* state = isolate->api_state();
467 ASSERT(state != NULL); 511 ASSERT(state != NULL);
468 if (keys == NULL) { 512 if (keys == NULL) {
469 return Api::NewError("%s expects argument 'keys' to be non-null.", 513 return Api::NewError("%s expects argument 'keys' to be non-null.",
(...skipping 2616 matching lines...) Expand 10 before | Expand all | Expand 10 after
3086 *buffer = NULL; 3130 *buffer = NULL;
3087 } 3131 }
3088 delete debug_region; 3132 delete debug_region;
3089 } else { 3133 } else {
3090 *buffer = NULL; 3134 *buffer = NULL;
3091 *buffer_size = 0; 3135 *buffer_size = 0;
3092 } 3136 }
3093 } 3137 }
3094 3138
3095 } // namespace dart 3139 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698