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

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

Issue 8357034: Transitioning to new IC structure: change IC data to include function name; pass IC data instead ... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « runtime/vm/ic_data.cc ('k') | runtime/vm/ic_stubs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Assembler assembler;
13 assembler.ret();
14 const Code& code =
15 Code::Handle(Code::FinalizeCode(name, &assembler));
16 const String& function_name =
17 String::ZoneHandle(String::NewSymbol(name));
18 const Function& function = Function::Handle(Function::New(
19 function_name, RawFunction::kFunction, true, false, 0));
20 function.SetCode(code);
21 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table();
22 ASSERT(code_index_table != NULL);
23 code_index_table->AddFunction(function);
24 return function.raw();
25 }
26
27
28 static bool SameClassArrays(const GrowableArray<const Class*>& a,
29 const GrowableArray<const Class*>& b) {
30 if (a.length() != b.length()) {
31 return false;
32 }
33 for (int i = 0; i < a.length(); i++) {
34 if (a[i]->raw() != b[i]->raw()) {
35 return false;
36 }
37 }
38 return true;
39 }
40
41
42 TEST_CASE(ICDataTest) {
43 const String& name = String::Handle(String::New("Luxemburgerli"));
44 ICData ic_data(name, 1);
45 EXPECT_EQ(1, ic_data.NumberOfArgumentsChecked());
46 EXPECT_EQ(0, ic_data.NumberOfChecks());
47 EXPECT_EQ(name.raw(), ic_data.FunctionName());
48 GrowableArray<const Class*> classes;
49 const Function& target = Function::Handle(GetDummyTarget(name.ToCString()));
50 ObjectStore* object_store = Isolate::Current()->object_store();
51 const Class& smi_class = Class::ZoneHandle(object_store->smi_class());
52 classes.Add(&smi_class);
53 ic_data.AddCheck(classes, target);
54
55 EXPECT_EQ(1, ic_data.NumberOfArgumentsChecked());
56 EXPECT_EQ(1, ic_data.NumberOfChecks());
57 EXPECT_EQ(name.raw(), ic_data.FunctionName());
58
59 GrowableArray<const Class*> test_classes;
60 Function& test_target = Function::Handle();
61 ic_data.GetCheckAt(0, &test_classes, &test_target);
62
63 EXPECT(SameClassArrays(classes, test_classes));
64 EXPECT_EQ(target.raw(), test_target.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
« no previous file with comments | « runtime/vm/ic_data.cc ('k') | runtime/vm/ic_stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698