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

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

Issue 1151523002: VM-internalize the default Map implementation. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add map serialization benchmark. Created 5 years, 7 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
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 "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 4445 matching lines...) Expand 10 before | Expand all | Expand 10 after
4456 elideSubstring("_GrowableList@", buffer, buffer); 4456 elideSubstring("_GrowableList@", buffer, buffer);
4457 EXPECT_STREQ( 4457 EXPECT_STREQ(
4458 "{\"type\":\"@List\",\"_vmType\":\"@GrowableObjectArray\"," 4458 "{\"type\":\"@List\",\"_vmType\":\"@GrowableObjectArray\","
4459 "\"class\":{\"type\":\"@Class\",\"id\":\"\",\"name\":\"_GrowableList\"," 4459 "\"class\":{\"type\":\"@Class\",\"id\":\"\",\"name\":\"_GrowableList\","
4460 "\"_vmName\":\"\"},\"id\":\"\",\"length\":0}", 4460 "\"_vmName\":\"\"},\"id\":\"\",\"length\":0}",
4461 buffer); 4461 buffer);
4462 } 4462 }
4463 // LinkedHashMap reference 4463 // LinkedHashMap reference
4464 { 4464 {
4465 JSONStream js; 4465 JSONStream js;
4466 const LinkedHashMap& array = LinkedHashMap::Handle(LinkedHashMap::New()); 4466 const LinkedHashMap& array =
4467 LinkedHashMap::Handle(LinkedHashMap::NewDefault());
4467 array.PrintJSON(&js, true); 4468 array.PrintJSON(&js, true);
4468 elideSubstring("classes", js.ToCString(), buffer); 4469 elideSubstring("classes", js.ToCString(), buffer);
4469 elideSubstring("objects", buffer, buffer); 4470 elideSubstring("objects", buffer, buffer);
4470 elideSubstring("_InternalLinkedHashMap@", buffer, buffer); 4471 elideSubstring("_InternalLinkedHashMap@", buffer, buffer);
4471 EXPECT_STREQ( 4472 EXPECT_STREQ(
4472 "{\"type\":\"@Instance\",\"_vmType\":\"@LinkedHashMap\"," 4473 "{\"type\":\"@Instance\",\"_vmType\":\"@LinkedHashMap\","
4473 "\"class\":{\"type\":\"@Class\",\"id\":\"\"," 4474 "\"class\":{\"type\":\"@Class\",\"id\":\"\","
4474 "\"name\":\"_InternalLinkedHashMap\",\"_vmName\":\"\"},\"id\":\"\"}", 4475 "\"name\":\"_InternalLinkedHashMap\",\"_vmName\":\"\"},\"id\":\"\"}",
4475 buffer); 4476 buffer);
4476 } 4477 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
4592 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("foo"), 0, NULL); 4593 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("foo"), 0, NULL);
4593 EXPECT_VALID(h_result); 4594 EXPECT_VALID(h_result);
4594 Integer& result = Integer::Handle(); 4595 Integer& result = Integer::Handle();
4595 result ^= Api::UnwrapHandle(h_result); 4596 result ^= Api::UnwrapHandle(h_result);
4596 String& foo = String::Handle(String::New("foo")); 4597 String& foo = String::Handle(String::New("foo"));
4597 Integer& expected = Integer::Handle(); 4598 Integer& expected = Integer::Handle();
4598 expected ^= foo.HashCode(); 4599 expected ^= foo.HashCode();
4599 EXPECT(result.IsIdenticalTo(expected)); 4600 EXPECT(result.IsIdenticalTo(expected));
4600 } 4601 }
4601 4602
4603
4604 static void CheckIdenticalHashStructure(const Instance& a, const Instance& b) {
4605 const char* kScript =
4606 "(a, b) {\n"
4607 " if (a._usedData != b._usedData ||\n"
4608 " a._deletedKeys != b._deletedKeys ||\n"
4609 " a._hashMask != b._hashMask ||\n"
4610 " a._index.length != b._index.length ||\n"
4611 " a._data.length != b._data.length) {\n"
4612 " return false;\n"
4613 " }\n"
4614 " for (var i = 0; i < a._index.length; ++i) {\n"
4615 " if (a._index[i] != b._index[i]) {\n"
4616 " return false;\n"
4617 " }\n"
4618 " }\n"
4619 " for (var i = 0; i < a._data.length; ++i) {\n"
4620 " var ad = a._data[i];\n"
4621 " var bd = b._data[i];\n"
4622 " if (!identical(ad, bd) && !(ad == a && bd == b)) {\n"
4623 " return false;\n"
4624 " }\n"
4625 " }\n"
4626 " return true;\n"
4627 "}(a, b)";
4628 String& name = String::Handle();
4629 Array& param_names = Array::Handle(Array::New(2));
4630 name = String::New("a");
4631 param_names.SetAt(0, name);
4632 name = String::New("b");
4633 param_names.SetAt(1, name);
4634 Array& param_values = Array::Handle(Array::New(2));
4635 param_values.SetAt(0, a);
4636 param_values.SetAt(1, b);
4637 name = String::New(kScript);
4638 Library& lib = Library::Handle(Library::CollectionLibrary());
4639 EXPECT(lib.Evaluate(name, param_names, param_values) == Bool::True().raw());
4640 }
4641
4642
4643 TEST_CASE(LinkedHashMap) {
4644 // Check that initial index size and hash mask match in Dart vs. C++.
4645 // 1. Create an empty custom linked hash map in Dart.
4646 const char* kScript =
4647 "import 'dart:collection';\n"
4648 "makeMap() {\n"
4649 " Function eq = (a, b) => true;\n"
4650 " Function hc = (a) => 42;\n"
4651 " return new LinkedHashMap(equals: eq, hashCode: hc);\n"
4652 "}";
4653 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
4654 EXPECT_VALID(h_lib);
4655 Library& lib = Library::Handle();
4656 lib ^= Api::UnwrapHandle(h_lib);
4657 EXPECT(!lib.IsNull());
4658 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL);
4659 EXPECT_VALID(h_result);
4660
4661 // 2. Create an empty internalized LinkedHashMap in C++.
4662 Instance& dart_map = Instance::Handle();
4663 dart_map ^= Api::UnwrapHandle(h_result);
4664 LinkedHashMap& cc_map = LinkedHashMap::Handle(LinkedHashMap::NewDefault());
4665
4666 // 3. Expect them to have identical structure.
4667 CheckIdenticalHashStructure(dart_map, cc_map);
4668 }
4669
4602 } // namespace dart 4670 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698