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

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

Issue 9395016: First part of new ICData infrastructure: use a wrapper object instead of an array. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5 #include "vm/ic_data.h"
6 #include "vm/code_index_table.h"
7 #include "vm/unit_test.h"
8
9 namespace dart {
10
11 static RawFunction* GetDummyTarget(const char* name) {
12 const String& function_name = String::Handle(String::NewSymbol(name));
13 const bool is_static = false;
14 const bool is_const = false;
15 return Function::New(function_name,
16 RawFunction::kFunction,
17 is_static,
18 is_const,
19 0);
20 }
21
22
23 static bool SameClassArrays(const GrowableArray<const Class*>& a,
24 const GrowableArray<const Class*>& b) {
25 if (a.length() != b.length()) {
26 return false;
27 }
28 for (int i = 0; i < a.length(); i++) {
29 if (a[i]->raw() != b[i]->raw()) {
30 return false;
31 }
32 }
33 return true;
34 }
35
36
37 TEST_CASE(ICDataTest) {
38 const String& name = String::Handle(String::New("Luxemburgerli"));
39 ICData ic_data(name, 1);
40 EXPECT_EQ(1, ic_data.NumberOfArgumentsChecked());
41 EXPECT_EQ(0, ic_data.NumberOfChecks());
42 EXPECT_EQ(name.raw(), ic_data.FunctionName());
43 GrowableArray<const Class*> classes;
44 const Function& target = Function::Handle(GetDummyTarget(name.ToCString()));
45 ObjectStore* object_store = Isolate::Current()->object_store();
46 const Class& smi_class = Class::ZoneHandle(object_store->smi_class());
47 classes.Add(&smi_class);
48 ic_data.AddCheck(classes, target);
49
50 EXPECT_EQ(1, ic_data.NumberOfArgumentsChecked());
51 EXPECT_EQ(1, ic_data.NumberOfChecks());
52 EXPECT_EQ(name.raw(), ic_data.FunctionName());
53
54 GrowableArray<const Class*> test_classes;
55 Function& test_target = Function::Handle();
56 ic_data.GetCheckAt(0, &test_classes, &test_target);
57 Class& test_class_1 = Class::Handle();
58 Function& test_target_1 = Function::Handle();
59 ic_data.GetOneClassCheckAt(0, &test_class_1, &test_target_1);
60
61 EXPECT(SameClassArrays(classes, test_classes));
62 EXPECT_EQ(test_classes[0]->raw(), test_class_1.raw());
63 EXPECT_EQ(target.raw(), test_target.raw());
64 EXPECT_EQ(test_target.raw(), test_target_1.raw());
65
66 const Function& new_target =
67 Function::Handle(GetDummyTarget(name.ToCString()));
68 ic_data.SetCheckAt(0, classes, new_target);
69 ic_data.GetCheckAt(0, &test_classes, &test_target);
70
71 EXPECT(SameClassArrays(classes, test_classes));
72 EXPECT_EQ(new_target.raw(), test_target.raw());
73 }
74
75 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698