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

Unified Diff: runtime/vm/snapshot.cc

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: Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/snapshot.cc
diff --git a/runtime/vm/snapshot.cc b/runtime/vm/snapshot.cc
index 78fe6a70d2f910f8ec6c74c601e35cd268f996ad..3006984692476b84d6c5c2159ccf39f3d19591ba 100644
--- a/runtime/vm/snapshot.cc
+++ b/runtime/vm/snapshot.cc
@@ -441,8 +441,31 @@ CMessageReader::CMessageReader(const uint8_t* buffer,
intptr_t length,
ReAlloc alloc)
: BaseReader(buffer, length),
+ zone_(NULL),
alloc_(alloc),
backward_references_(kNumInitialReferences) {
+ // When no explicit zone is used ensure that there is a current
+ // isolate zone as backward_references_ needs an isolate zone for
+ // allocation.
+ ASSERT(Isolate::Current() != NULL);
+ ASSERT(Isolate::Current()->current_zone() != NULL);
+ Init();
+}
+
+
+CMessageReader::CMessageReader(const uint8_t* buffer,
+ intptr_t length,
+ Zone* zone)
+ : BaseReader(buffer, length),
+ zone_(zone),
+ alloc_(NULL),
+ backward_references_(kNumInitialReferences, zone) {
+ ASSERT(zone != NULL);
+ Init();
+}
+
+
+void CMessageReader::Init() {
// Initialize marker objects used to handle Lists.
// TODO(sjesse): Remove this when message serialization format is
// updated.
@@ -460,7 +483,8 @@ Dart_CMessage* CMessageReader::ReadMessage() {
Dart_CObject* object = ReadObject();
Dart_CMessage* message =
- reinterpret_cast<Dart_CMessage*>(alloc_(NULL, 0, sizeof(Dart_CMessage)));
+ reinterpret_cast<Dart_CMessage*>(
+ Allocate(NULL, 0, sizeof(Dart_CMessage)));
if (message == NULL) return NULL;
message->root = object;
return message;
@@ -473,11 +497,21 @@ intptr_t CMessageReader::LookupInternalClass(intptr_t class_header) {
return header_value;
}
+uint8_t* CMessageReader::Allocate(uint8_t* ptr,
+ intptr_t old_size,
+ intptr_t new_size) {
+ if (alloc_ != NULL) {
+ return alloc_(ptr, old_size, new_size);
+ } else {
+ return reinterpret_cast<uint8_t*>(
+ zone_->Reallocate(reinterpret_cast<uword>(ptr), old_size, new_size));
+ }
+}
Dart_CObject* CMessageReader::AllocateDartCObject(Dart_CObject::Type type) {
Dart_CObject* value =
reinterpret_cast<Dart_CObject*>(
- alloc_(NULL, 0, sizeof(Dart_CObject)));
+ Allocate(NULL, 0, sizeof(Dart_CObject)));
value->type = type;
return value;
}
@@ -515,7 +549,7 @@ Dart_CObject* CMessageReader::AllocateDartCObjectString(intptr_t length) {
// up to this area.
Dart_CObject* value =
reinterpret_cast<Dart_CObject*>(
- alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1));
+ Allocate(NULL, 0, sizeof(Dart_CObject) + length + 1));
value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value);
value->type = Dart_CObject::kString;
return value;
@@ -528,7 +562,7 @@ Dart_CObject* CMessageReader::AllocateDartCObjectArray(intptr_t length) {
// content is set up to this area.
Dart_CObject* value =
reinterpret_cast<Dart_CObject*>(
- alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value)));
+ Allocate(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value)));
value->type = Dart_CObject::kArray;
value->value.as_array.length = length;
if (length > 0) {

Powered by Google App Engine
This is Rietveld 408576698