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

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

Issue 9605033: Implement a garbage collection prologue and epilogue callback mechanism. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix a comment 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 "%s expects argument 'num_values' to be greater than 0.", 483 "%s expects argument 'num_values' to be greater than 0.",
484 CURRENT_FUNC); 484 CURRENT_FUNC);
485 } 485 }
486 486
487 WeakReference* reference = new WeakReference(keys, num_keys, 487 WeakReference* reference = new WeakReference(keys, num_keys,
488 values, num_values); 488 values, num_values);
489 state->DelayWeakReference(reference); 489 state->DelayWeakReference(reference);
490 return Api::Success(); 490 return Api::Success();
491 } 491 }
492 492
493
494 // --- Garbage Collection Callbacks --
495
496
497 DART_EXPORT Dart_Handle Dart_NewGcPrologueCallback(
498 Dart_GcPrologueCallback callback) {
499 Isolate* isolate = Isolate::Current();
500 CHECK_ISOLATE(isolate);
501 ApiState* state = isolate->api_state();
turnidge 2012/03/07 00:25:16 You could permissibly move these callback lists to
cshapiro 2012/03/07 03:06:10 Done. I will move the weak references in a follow
502 ASSERT(state != NULL);
503 GcPrologueCallbacks& callbacks = state->gc_prologue_callbacks();
504 if (callbacks.Contains(callback)) {
505 return Api::NewError(
506 "%s permits only one instance of 'callback' to be present in the "
507 "prologue callback list.",
508 CURRENT_FUNC);
509 }
510 state->gc_prologue_callbacks().Add(callback);
511 return Api::Success();
512 }
513
514
515 DART_EXPORT Dart_Handle Dart_DeleteGcPrologueCallback(
516 Dart_GcPrologueCallback callback) {
517 Isolate* isolate = Isolate::Current();
518 CHECK_ISOLATE(isolate);
519 ApiState* state = isolate->api_state();
520 ASSERT(state != NULL);
521 GcPrologueCallbacks& callbacks = state->gc_prologue_callbacks();
522 if (!callbacks.Contains(callback)) {
523 return Api::NewError(
524 "%s expects 'callback' to be present in the prologue callback list.",
525 CURRENT_FUNC);
526 }
527 state->gc_prologue_callbacks().Remove(callback);
528 return Api::Success();
529 }
530
531
532 DART_EXPORT Dart_Handle Dart_NewGcEpilogueCallback(
533 Dart_GcEpilogueCallback callback) {
534 Isolate* isolate = Isolate::Current();
535 CHECK_ISOLATE(isolate);
536 ApiState* state = isolate->api_state();
537 ASSERT(state != NULL);
538 GcEpilogueCallbacks& callbacks = state->gc_epilogue_callbacks();
539 if (callbacks.Contains(callback)) {
540 return Api::NewError(
541 "%s permits only one instance of 'callback' to be present in the "
542 "epilogue callback list.",
543 CURRENT_FUNC);
544 }
545 callbacks.Add(callback);
546 return Api::Success();
547 }
548
549
550 DART_EXPORT Dart_Handle Dart_DeleteGcEpilogueCallback(
551 Dart_GcEpilogueCallback callback) {
552 Isolate* isolate = Isolate::Current();
553 CHECK_ISOLATE(isolate);
554 ApiState* state = isolate->api_state();
555 ASSERT(state != NULL);
556 GcEpilogueCallbacks& callbacks = state->gc_epilogue_callbacks();
557 if (!callbacks.Contains(callback)) {
558 return Api::NewError(
559 "%s expects 'callback' to be present in the epilogue callback list.",
560 CURRENT_FUNC);
561 }
562 callbacks.Remove(callback);
563 return Api::Success();
564 }
565
566
493 // --- Initialization and Globals --- 567 // --- Initialization and Globals ---
494 568
495 569
496 DART_EXPORT bool Dart_Initialize(Dart_IsolateCreateCallback create, 570 DART_EXPORT bool Dart_Initialize(Dart_IsolateCreateCallback create,
497 Dart_IsolateInterruptCallback interrupt) { 571 Dart_IsolateInterruptCallback interrupt) {
498 return Dart::InitOnce(create, interrupt); 572 return Dart::InitOnce(create, interrupt);
499 } 573 }
500 574
501 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { 575 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) {
502 return Flags::ProcessCommandLineFlags(argc, argv); 576 return Flags::ProcessCommandLineFlags(argc, argv);
(...skipping 2240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 *buffer = NULL; 2817 *buffer = NULL;
2744 } 2818 }
2745 delete debug_region; 2819 delete debug_region;
2746 } else { 2820 } else {
2747 *buffer = NULL; 2821 *buffer = NULL;
2748 *buffer_size = 0; 2822 *buffer_size = 0;
2749 } 2823 }
2750 } 2824 }
2751 2825
2752 } // namespace dart 2826 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698