Index: runtime/vm/snapshot_test.cc |
diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc |
index 58ec2950b9ae348973d385223aaa271d09c1eb21..3933f3dc526c486ee24e71d9f97b597e0c6c30cd 100644 |
--- a/runtime/vm/snapshot_test.cc |
+++ b/runtime/vm/snapshot_test.cc |
@@ -241,13 +241,17 @@ Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { |
writer.WriteMessage(mint); |
intptr_t buffer_len = writer.BytesWritten(); |
- // Read object back from the snapshot. |
- MessageSnapshotReader reader(buffer, |
- buffer_len, |
- Isolate::Current(), |
- Thread::Current()->zone()); |
- const Object& serialized_object = Object::Handle(reader.ReadObject()); |
- EXPECT(serialized_object.IsMint()); |
+ { |
+ // Switch to a regular zone, where VM handle allocation is allowed. |
+ StackZone zone(Isolate::Current()); |
+ // Read object back from the snapshot. |
+ MessageSnapshotReader reader(buffer, |
+ buffer_len, |
+ Isolate::Current(), |
+ Thread::Current()->zone()); |
+ const Object& serialized_object = Object::Handle(reader.ReadObject()); |
+ EXPECT(serialized_object.IsMint()); |
+ } |
// Read object back from the snapshot into a C structure. |
ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
@@ -441,18 +445,22 @@ Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
writer.WriteMessage(bigint); |
intptr_t buffer_len = writer.BytesWritten(); |
- // Read object back from the snapshot. |
- MessageSnapshotReader reader(buffer, |
- buffer_len, |
- Isolate::Current(), |
- Thread::Current()->zone()); |
- Bigint& serialized_bigint = Bigint::Handle(); |
- serialized_bigint ^= reader.ReadObject(); |
- const char* str1 = bigint.ToHexCString(allocator); |
- const char* str2 = serialized_bigint.ToHexCString(allocator); |
- EXPECT_STREQ(str1, str2); |
- free(const_cast<char*>(str1)); |
- free(const_cast<char*>(str2)); |
+ { |
+ // Switch to a regular zone, where VM handle allocation is allowed. |
+ StackZone zone(Isolate::Current()); |
+ // Read object back from the snapshot. |
+ MessageSnapshotReader reader(buffer, |
+ buffer_len, |
+ Isolate::Current(), |
+ Thread::Current()->zone()); |
+ Bigint& serialized_bigint = Bigint::Handle(); |
+ serialized_bigint ^= reader.ReadObject(); |
+ const char* str1 = bigint.ToHexCString(allocator); |
+ const char* str2 = serialized_bigint.ToHexCString(allocator); |
+ EXPECT_STREQ(str1, str2); |
+ free(const_cast<char*>(str1)); |
+ free(const_cast<char*>(str2)); |
+ } |
// Read object back from the snapshot into a C structure. |
ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
@@ -466,10 +474,9 @@ Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
void CheckBigint(const char* bigint_value) { |
StackZone zone(Isolate::Current()); |
- ApiNativeScope scope; |
- |
Bigint& bigint = Bigint::Handle(); |
bigint ^= Bigint::NewFromCString(bigint_value); |
+ ApiNativeScope scope; |
Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); |
EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type); |
char* hex_value = TestCase::BigintToHexValue(bigint_cobject); |
@@ -1589,21 +1596,26 @@ TEST_CASE(IntArrayMessage) { |
} |
-// Helper function to call a top level Dart function, serialize the |
-// result and deserialize the result into a Dart_CObject structure. |
-static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, |
- const char* dart_function) { |
+// Helper function to call a top level Dart function and serialize the result. |
+static uint8_t* GetSerialized(Dart_Handle lib, |
+ const char* dart_function, |
+ intptr_t* buffer_len) { |
Dart_Handle result; |
result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); |
EXPECT_VALID(result); |
+ Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
- // Serialize the list into a message. |
- const Object& list = Object::Handle(Api::UnwrapHandle(result)); |
+ // Serialize the object into a message. |
uint8_t* buffer; |
MessageWriter writer(&buffer, &zone_allocator, false); |
- writer.WriteMessage(list); |
- intptr_t buffer_len = writer.BytesWritten(); |
+ writer.WriteMessage(obj); |
+ *buffer_len = writer.BytesWritten(); |
+ return buffer; |
+} |
+ |
+// Helper function to deserialize the result into a Dart_CObject structure. |
+static Dart_CObject* GetDeserialized(uint8_t* buffer, intptr_t buffer_len) { |
// Read object back from the snapshot into a C structure. |
ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
return api_reader.ReadMessage(); |
@@ -1831,10 +1843,13 @@ UNIT_TEST_CASE(DartGeneratedListMessages) { |
{ |
DARTSCOPE(isolate); |
+ StackZone zone(isolate); |
+ intptr_t buf_len = 0; |
{ |
// Generate a list of nulls from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -1845,8 +1860,9 @@ UNIT_TEST_CASE(DartGeneratedListMessages) { |
} |
{ |
// Generate a list of ints from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getIntList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -1858,8 +1874,9 @@ UNIT_TEST_CASE(DartGeneratedListMessages) { |
} |
{ |
// Generate a list of strings from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -1872,8 +1889,9 @@ UNIT_TEST_CASE(DartGeneratedListMessages) { |
} |
{ |
// Generate a list of objects of different types from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -1949,10 +1967,13 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { |
{ |
DARTSCOPE(isolate); |
+ StackZone zone(isolate); |
+ intptr_t buf_len = 0; |
{ |
// Generate a list of nulls from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -1963,8 +1984,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { |
} |
{ |
// Generate a list of ints from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getIntList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -1976,8 +1998,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { |
} |
{ |
// Generate a list of strings from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -1990,8 +2013,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { |
} |
{ |
// Generate a list of lists from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getListList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getListList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2008,8 +2032,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { |
} |
{ |
// Generate a list of objects of different types from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2181,11 +2206,13 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
{ |
DARTSCOPE(isolate); |
- |
+ StackZone zone(isolate); |
+ intptr_t buf_len = 0; |
{ |
// Generate a list of strings from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2198,8 +2225,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
} |
{ |
// Generate a list of medium ints from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getMintList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2212,8 +2240,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
} |
{ |
// Generate a list of bigints from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getBigintList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2228,8 +2257,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
} |
{ |
// Generate a list of doubles from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getDoubleList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2246,8 +2276,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
} |
{ |
// Generate a list of Uint8Lists from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2261,9 +2292,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
} |
{ |
// Generate a list of Uint8List views from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = |
- GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2279,8 +2310,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
} |
{ |
// Generate a list of objects of different types from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2306,8 +2338,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { |
} |
{ |
// Generate a list of objects of different types from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getSelfRefList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2398,10 +2431,13 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
{ |
DARTSCOPE(isolate); |
+ StackZone zone(isolate); |
+ intptr_t buf_len = 0; |
{ |
// Generate a list of strings from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2414,8 +2450,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
} |
{ |
// Generate a list of medium ints from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getMintList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2428,8 +2465,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
} |
{ |
// Generate a list of bigints from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getBigintList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2444,8 +2482,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
} |
{ |
// Generate a list of doubles from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getDoubleList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2463,8 +2502,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
} |
{ |
// Generate a list of Uint8Lists from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2478,9 +2518,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
} |
{ |
// Generate a list of Uint8List views from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = |
- GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2496,8 +2536,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
} |
{ |
// Generate a list of objects of different types from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2523,8 +2564,9 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { |
} |
{ |
// Generate a list of objects of different types from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getSelfRefList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
EXPECT_EQ(kArrayLength, root->value.as_array.length); |
@@ -2630,10 +2672,13 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { |
{ |
DARTSCOPE(isolate); |
+ StackZone zone(isolate); |
+ intptr_t buf_len = 0; |
{ |
// Generate a list of Uint8Lists from Dart code. |
+ uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
struct { |
@@ -2664,10 +2709,9 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { |
} |
{ |
// Generate a list of Uint8List views from Dart code. |
- |
+ uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = |
- GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
struct { |
@@ -2721,9 +2765,10 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { |
} |
{ |
// Generate a list of Uint8Lists from Dart code. |
+ uint8_t* buf = |
+ GetSerialized(lib, "getMultipleTypedDataViewList", &buf_len); |
ApiNativeScope scope; |
- Dart_CObject* root = |
- GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList"); |
+ Dart_CObject* root = GetDeserialized(buf, buf_len); |
EXPECT_NOTNULL(root); |
EXPECT_EQ(Dart_CObject_kArray, root->type); |
struct { |