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

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

Issue 9325022: Decode the Dart message into a Dart_CMessage structure before calling the native port callback (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Undo unneeded changes Created 8 years, 10 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) 2011, 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 #ifndef VM_DART_API_STATE_H_ 5 #ifndef VM_DART_API_STATE_H_
6 #define VM_DART_API_STATE_H_ 6 #define VM_DART_API_STATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "platform/thread.h"
10 #include "vm/dart_api_impl.h" 11 #include "vm/dart_api_impl.h"
11 #include "vm/flags.h" 12 #include "vm/flags.h"
13 #include "vm/growable_array.h"
12 #include "vm/handles.h" 14 #include "vm/handles.h"
13 #include "vm/object.h" 15 #include "vm/object.h"
14 #include "vm/os.h" 16 #include "vm/os.h"
15 #include "vm/raw_object.h" 17 #include "vm/raw_object.h"
16 #include "vm/visitor.h" 18 #include "vm/visitor.h"
17 19
18 #include "vm/handles_impl.h" 20 #include "vm/handles_impl.h"
19 21
20 namespace dart { 22 namespace dart {
21 23
(...skipping 17 matching lines...) Expand all
39 // 'data' into new allocated memory. Uses current zone. 41 // 'data' into new allocated memory. Uses current zone.
40 uword Reallocate(uword data, intptr_t old_size, intptr_t new_size) { 42 uword Reallocate(uword data, intptr_t old_size, intptr_t new_size) {
41 return zone_.Reallocate(data, old_size, new_size); 43 return zone_.Reallocate(data, old_size, new_size);
42 } 44 }
43 45
44 // Compute the total size of this zone. This includes wasted space that is 46 // Compute the total size of this zone. This includes wasted space that is
45 // due to internal fragmentation in the segments. 47 // due to internal fragmentation in the segments.
46 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } 48 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); }
47 49
48 private: 50 private:
51 BaseZone* GetBaseZone() { return &zone_; }
52
49 BaseZone zone_; 53 BaseZone zone_;
50 54
55 template<typename T> friend class ApiGrowableArray;
51 DISALLOW_COPY_AND_ASSIGN(ApiZone); 56 DISALLOW_COPY_AND_ASSIGN(ApiZone);
52 }; 57 };
53 58
54 59
55 // Implementation of local handles which are handed out from every 60 // Implementation of local handles which are handed out from every
56 // dart API call, these handles are valid only in the present scope 61 // dart API call, these handles are valid only in the present scope
57 // and are destroyed when a Dart_ExitScope() is called. 62 // and are destroyed when a Dart_ExitScope() is called.
58 class LocalHandle { 63 class LocalHandle {
59 public: 64 public:
60 // Accessors. 65 // Accessors.
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 ApiLocalScope* top_scope_; 505 ApiLocalScope* top_scope_;
501 506
502 // Persistent handles to important objects. 507 // Persistent handles to important objects.
503 PersistentHandle* null_; 508 PersistentHandle* null_;
504 PersistentHandle* true_; 509 PersistentHandle* true_;
505 PersistentHandle* false_; 510 PersistentHandle* false_;
506 511
507 DISALLOW_COPY_AND_ASSIGN(ApiState); 512 DISALLOW_COPY_AND_ASSIGN(ApiState);
508 }; 513 };
509 514
515
516 class ApiNativeScope {
517 public:
518 ApiNativeScope() {
519 // Currently no support for nesting native scopes.
520 ASSERT(Current() == NULL);
521 Thread::SetThreadLocal(api_native_key_, reinterpret_cast<uword>(this));
522 }
523
524 ~ApiNativeScope() {
525 ASSERT(Current() == this);
526 Thread::SetThreadLocal(api_native_key_, NULL);
527 }
528
529 static inline ApiNativeScope* Current() {
530 return reinterpret_cast<ApiNativeScope*>(
531 Thread::GetThreadLocal(api_native_key_));
532 }
533
534 ApiZone* zone() { return &zone_; }
535
536 static void InitOnce();
537
538 private:
539 static ThreadLocalKey api_native_key_;
540 ApiZone zone_;
541 ThreadLocalKey key_;
542 };
543
544
545 // Api growable arrays use a zone for allocation. The constructor
546 // picks the zone from the current isolate if in an isolate
547 // environment. When outside an isolate environment it picks the zone
548 // from the current native scope.
549 template<typename T>
550 class ApiGrowableArray : public BaseGrowableArray<T, ValueObject> {
551 public:
552 explicit ApiGrowableArray(int initial_capacity)
553 : BaseGrowableArray<T, ValueObject>(
554 initial_capacity,
555 Isolate::Current() != NULL
siva 2012/02/09 00:45:29 Do you want to allow use of this data structure ev
Søren Gjesse 2012/02/09 08:44:01 It was only used in the tests where the decoding i
556 ? Isolate::Current()->current_zone()->GetBaseZone()
557 : ApiNativeScope::Current()->zone()->GetBaseZone()) {}
558 ApiGrowableArray()
559 : BaseGrowableArray<T, ValueObject>(
560 Isolate::Current() != NULL
561 ? Isolate::Current()->current_zone()->GetBaseZone()
562 : ApiNativeScope::Current()->zone()->GetBaseZone()) {}
563 };
564
565
510 } // namespace dart 566 } // namespace dart
511 567
512 #endif // VM_DART_API_STATE_H_ 568 #endif // VM_DART_API_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698