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

Unified Diff: runtime/vm/snapshot_test.cc

Issue 1191443008: Assert no VM handles are created in the zone that belongs to a ApiNativeScopes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix null isolate. Created 5 years, 6 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
« no previous file with comments | « runtime/vm/handles.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/snapshot_test.cc
diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc
index e4f682946d0553ee858af6341da86e6c9d4adf35..2604914235b0c463aa9a1c9a802a6b88f46d4013 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);
@@ -1588,7 +1595,8 @@ 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) {
+ const char* dart_function,
+ Object* tmp_handle) {
siva 2015/06/19 23:30:46 Why is it not Ok to allocate the StackZone here in
koda 2015/06/22 17:18:51 That would make the return value a dangling pointe
Dart_Handle result;
result = Dart_Invoke(lib, NewString(dart_function), 0, NULL);
EXPECT_VALID(result);
@@ -1596,8 +1604,8 @@ static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib,
// Serialize the list into a message.
uint8_t* buffer;
MessageWriter writer(&buffer, &zone_allocator, false);
- const Object& list = Object::Handle(Api::UnwrapHandle(result));
- writer.WriteMessage(list);
+ *tmp_handle = Api::UnwrapHandle(result);
+ writer.WriteMessage(*tmp_handle);
intptr_t buffer_len = writer.BytesWritten();
// Read object back from the snapshot into a C structure.
@@ -1827,10 +1835,12 @@ UNIT_TEST_CASE(DartGeneratedListMessages) {
{
DARTSCOPE(isolate);
+ StackZone zone(isolate);
+ Object& tmp = Object::Handle();
{
// Generate a list of nulls from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getList");
+ Dart_CObject* root = GetDeserializedDartMessage(lib, "getList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -1842,7 +1852,7 @@ UNIT_TEST_CASE(DartGeneratedListMessages) {
{
// Generate a list of ints from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList");
+ Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -1855,7 +1865,8 @@ UNIT_TEST_CASE(DartGeneratedListMessages) {
{
// Generate a list of strings from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getStringList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -1869,7 +1880,8 @@ UNIT_TEST_CASE(DartGeneratedListMessages) {
{
// Generate a list of objects of different types from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getMixedList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -1945,10 +1957,12 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) {
{
DARTSCOPE(isolate);
+ StackZone zone(isolate);
+ Object& tmp = Object::Handle();
{
// Generate a list of nulls from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getList");
+ Dart_CObject* root = GetDeserializedDartMessage(lib, "getList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -1960,7 +1974,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) {
{
// Generate a list of ints from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getIntList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -1973,7 +1988,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) {
{
// Generate a list of strings from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getStringList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -1987,7 +2003,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) {
{
// Generate a list of lists from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getListList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getListList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2005,7 +2022,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) {
{
// Generate a list of objects of different types from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getMixedList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2177,11 +2195,13 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
{
DARTSCOPE(isolate);
-
+ StackZone zone(isolate);
+ Object& tmp = Object::Handle();
{
// Generate a list of strings from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getStringList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2195,7 +2215,8 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
{
// Generate a list of medium ints from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getMintList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2209,7 +2230,8 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
{
// Generate a list of bigints from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getBigintList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2225,7 +2247,8 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
{
// Generate a list of doubles from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getDoubleList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2243,7 +2266,8 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
{
// Generate a list of Uint8Lists from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getTypedDataList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2259,7 +2283,7 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
// Generate a list of Uint8List views from Dart code.
ApiNativeScope scope;
Dart_CObject* root =
- GetDeserializedDartMessage(lib, "getTypedDataViewList");
+ GetDeserializedDartMessage(lib, "getTypedDataViewList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2276,7 +2300,8 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
{
// Generate a list of objects of different types from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getMixedList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2303,7 +2328,8 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
{
// Generate a list of objects of different types from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getSelfRefList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2394,10 +2420,13 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
{
DARTSCOPE(isolate);
+ StackZone zone(isolate);
+ Object& tmp = Object::Handle();
{
// Generate a list of strings from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getStringList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2411,7 +2440,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
{
// Generate a list of medium ints from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getMintList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2425,7 +2455,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
{
// Generate a list of bigints from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getBigintList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2441,7 +2472,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
{
// Generate a list of doubles from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getDoubleList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2460,7 +2492,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
{
// Generate a list of Uint8Lists from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getTypedDataList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2476,7 +2509,7 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
// Generate a list of Uint8List views from Dart code.
ApiNativeScope scope;
Dart_CObject* root =
- GetDeserializedDartMessage(lib, "getTypedDataViewList");
+ GetDeserializedDartMessage(lib, "getTypedDataViewList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2493,7 +2526,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
{
// Generate a list of objects of different types from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getMixedList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2520,7 +2554,8 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
{
// Generate a list of objects of different types from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getSelfRefList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
EXPECT_EQ(kArrayLength, root->value.as_array.length);
@@ -2626,10 +2661,13 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) {
{
DARTSCOPE(isolate);
+ StackZone zone(isolate);
+ Object& tmp = Object::Handle();
{
// Generate a list of Uint8Lists from Dart code.
ApiNativeScope scope;
- Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList");
+ Dart_CObject* root =
+ GetDeserializedDartMessage(lib, "getTypedDataList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
struct {
@@ -2663,7 +2701,7 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) {
ApiNativeScope scope;
Dart_CObject* root =
- GetDeserializedDartMessage(lib, "getTypedDataViewList");
+ GetDeserializedDartMessage(lib, "getTypedDataViewList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
struct {
@@ -2719,7 +2757,7 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) {
// Generate a list of Uint8Lists from Dart code.
ApiNativeScope scope;
Dart_CObject* root =
- GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList");
+ GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList", &tmp);
EXPECT_NOTNULL(root);
EXPECT_EQ(Dart_CObject_kArray, root->type);
struct {
« no previous file with comments | « runtime/vm/handles.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698