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

Side by Side Diff: vm/object_test.cc

Issue 10783035: Create frequently used symbols in the vm isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « vm/object.cc ('k') | vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/assert.h" 5 #include "platform/assert.h"
6 #include "vm/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
11 #include "vm/symbols.h"
11 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 TEST_CASE(Class) { 16 TEST_CASE(Class) {
16 // Allocate the class first. 17 // Allocate the class first.
17 const String& class_name = String::Handle(String::NewSymbol("MyClass")); 18 const String& class_name = String::Handle(Symbols::New("MyClass"));
18 const Script& script = Script::Handle(); 19 const Script& script = Script::Handle();
19 const Class& cls = Class::Handle( 20 const Class& cls = Class::Handle(
20 Class::New(class_name, script, Scanner::kDummyTokenIndex)); 21 Class::New(class_name, script, Scanner::kDummyTokenIndex));
21 22
22 // Class has no fields. 23 // Class has no fields.
23 const Array& no_fields = Array::Handle(Array::Empty()); 24 const Array& no_fields = Array::Handle(Array::Empty());
24 cls.SetFields(no_fields); 25 cls.SetFields(no_fields);
25 26
26 // Create and populate the function arrays. 27 // Create and populate the function arrays.
27 const Array& functions = Array::Handle(Array::New(6)); 28 const Array& functions = Array::Handle(Array::New(6));
28 Function& function = Function::Handle(); 29 Function& function = Function::Handle();
29 String& function_name = String::Handle(); 30 String& function_name = String::Handle();
30 function_name = String::NewSymbol("foo"); 31 function_name = Symbols::New("foo");
31 function = Function::New( 32 function = Function::New(
32 function_name, RawFunction::kRegularFunction, false, false, 0); 33 function_name, RawFunction::kRegularFunction, false, false, 0);
33 functions.SetAt(0, function); 34 functions.SetAt(0, function);
34 function_name = String::NewSymbol("bar"); 35 function_name = Symbols::New("bar");
35 function = Function::New( 36 function = Function::New(
36 function_name, RawFunction::kRegularFunction, false, false, 0); 37 function_name, RawFunction::kRegularFunction, false, false, 0);
37 38
38 const int kNumFixedParameters = 2; 39 const int kNumFixedParameters = 2;
39 const int kNumOptionalParameters = 3; 40 const int kNumOptionalParameters = 3;
40 function.set_num_fixed_parameters(kNumFixedParameters); 41 function.set_num_fixed_parameters(kNumFixedParameters);
41 function.set_num_optional_parameters(kNumOptionalParameters); 42 function.set_num_optional_parameters(kNumOptionalParameters);
42 functions.SetAt(1, function); 43 functions.SetAt(1, function);
43 44
44 function_name = String::NewSymbol("baz"); 45 function_name = Symbols::New("baz");
45 function = Function::New( 46 function = Function::New(
46 function_name, RawFunction::kRegularFunction, false, false, 0); 47 function_name, RawFunction::kRegularFunction, false, false, 0);
47 functions.SetAt(2, function); 48 functions.SetAt(2, function);
48 49
49 function_name = String::NewSymbol("Foo"); 50 function_name = Symbols::New("Foo");
50 function = Function::New( 51 function = Function::New(
51 function_name, RawFunction::kRegularFunction, true, false, 0); 52 function_name, RawFunction::kRegularFunction, true, false, 0);
52 functions.SetAt(3, function); 53 functions.SetAt(3, function);
53 function_name = String::NewSymbol("Bar"); 54 function_name = Symbols::New("Bar");
54 function = Function::New( 55 function = Function::New(
55 function_name, RawFunction::kRegularFunction, true, false, 0); 56 function_name, RawFunction::kRegularFunction, true, false, 0);
56 functions.SetAt(4, function); 57 functions.SetAt(4, function);
57 function_name = String::NewSymbol("BaZ"); 58 function_name = Symbols::New("BaZ");
58 function = Function::New( 59 function = Function::New(
59 function_name, RawFunction::kRegularFunction, true, false, 0); 60 function_name, RawFunction::kRegularFunction, true, false, 0);
60 functions.SetAt(5, function); 61 functions.SetAt(5, function);
61 62
62 // Setup the functions in the class. 63 // Setup the functions in the class.
63 cls.SetFunctions(functions); 64 cls.SetFunctions(functions);
64 65
65 function_name = String::New("Foo"); 66 function_name = String::New("Foo");
66 function = cls.LookupDynamicFunction(function_name); 67 function = cls.LookupDynamicFunction(function_name);
67 EXPECT(function.IsNull()); 68 EXPECT(function.IsNull());
(...skipping 19 matching lines...) Expand all
87 88
88 function_name = String::New("bar"); 89 function_name = String::New("bar");
89 function = cls.LookupDynamicFunction(function_name); 90 function = cls.LookupDynamicFunction(function_name);
90 EXPECT(!function.IsNull()); 91 EXPECT(!function.IsNull());
91 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters()); 92 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters());
92 EXPECT_EQ(kNumOptionalParameters, function.num_optional_parameters()); 93 EXPECT_EQ(kNumOptionalParameters, function.num_optional_parameters());
93 94
94 const Array& interfaces = Array::Handle(Array::New(2)); 95 const Array& interfaces = Array::Handle(Array::New(2));
95 Class& interface = Class::Handle(); 96 Class& interface = Class::Handle();
96 String& interface_name = String::Handle(); 97 String& interface_name = String::Handle();
97 interface_name = String::NewSymbol("Harley"); 98 interface_name = Symbols::New("Harley");
98 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex); 99 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex);
99 interfaces.SetAt(0, Type::Handle(Type::NewNonParameterizedType(interface))); 100 interfaces.SetAt(0, Type::Handle(Type::NewNonParameterizedType(interface)));
100 interface_name = String::NewSymbol("Norton"); 101 interface_name = Symbols::New("Norton");
101 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex); 102 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex);
102 interfaces.SetAt(1, Type::Handle(Type::NewNonParameterizedType(interface))); 103 interfaces.SetAt(1, Type::Handle(Type::NewNonParameterizedType(interface)));
103 cls.set_interfaces(interfaces); 104 cls.set_interfaces(interfaces);
104 cls.Finalize(); 105 cls.Finalize();
105 106
106 const Array& array = Array::Handle(cls.functions_cache()); 107 const Array& array = Array::Handle(cls.functions_cache());
107 array.SetAt(0, function_name); 108 array.SetAt(0, function_name);
108 cls.set_functions_cache(array); 109 cls.set_functions_cache(array);
109 String& test_name = String::Handle(); 110 String& test_name = String::Handle();
110 test_name ^= Array::Handle(cls.functions_cache()).At(0); 111 test_name ^= Array::Handle(cls.functions_cache()).At(0);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 iterator.Advance(); 151 iterator.Advance();
151 iterator.Advance(); // Advance to '.' token. 152 iterator.Advance(); // Advance to '.' token.
152 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); 153 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind());
153 iterator.Advance(); // Advance to end of stream. 154 iterator.Advance(); // Advance to end of stream.
154 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); 155 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind());
155 } 156 }
156 157
157 158
158 TEST_CASE(InstanceClass) { 159 TEST_CASE(InstanceClass) {
159 // Allocate the class first. 160 // Allocate the class first.
160 String& class_name = String::Handle(String::NewSymbol("EmptyClass")); 161 String& class_name = String::Handle(Symbols::New("EmptyClass"));
161 Script& script = Script::Handle(); 162 Script& script = Script::Handle();
162 const Class& empty_class = 163 const Class& empty_class =
163 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 164 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
164 165
165 // No functions and no super class for the EmptyClass. 166 // No functions and no super class for the EmptyClass.
166 const Array& no_fields = Array::Handle(Array::Empty()); 167 const Array& no_fields = Array::Handle(Array::Empty());
167 empty_class.SetFields(no_fields); 168 empty_class.SetFields(no_fields);
168 empty_class.Finalize(); 169 empty_class.Finalize();
169 EXPECT_EQ(kObjectAlignment, empty_class.instance_size()); 170 EXPECT_EQ(kObjectAlignment, empty_class.instance_size());
170 Instance& instance = Instance::Handle(Instance::New(empty_class)); 171 Instance& instance = Instance::Handle(Instance::New(empty_class));
171 EXPECT_EQ(empty_class.raw(), instance.clazz()); 172 EXPECT_EQ(empty_class.raw(), instance.clazz());
172 173
173 class_name = String::NewSymbol("OneFieldClass"); 174 class_name = Symbols::New("OneFieldClass");
174 const Class& one_field_class = 175 const Class& one_field_class =
175 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 176 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
176 177
177 // No functions and no super class for the OneFieldClass. 178 // No functions and no super class for the OneFieldClass.
178 const Array& one_fields = Array::Handle(Array::New(1)); 179 const Array& one_fields = Array::Handle(Array::New(1));
179 const String& field_name = String::Handle(String::NewSymbol("the_field")); 180 const String& field_name = String::Handle(Symbols::New("the_field"));
180 const Field& field = Field::Handle(Field::New(field_name, false, false, 0)); 181 const Field& field = Field::Handle(Field::New(field_name, false, false, 0));
181 one_fields.SetAt(0, field); 182 one_fields.SetAt(0, field);
182 one_field_class.SetFields(one_fields); 183 one_field_class.SetFields(one_fields);
183 one_field_class.Finalize(); 184 one_field_class.Finalize();
184 intptr_t header_size = sizeof(RawObject); 185 intptr_t header_size = sizeof(RawObject);
185 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment), 186 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment),
186 one_field_class.instance_size()); 187 one_field_class.instance_size());
187 EXPECT_EQ(header_size, field.Offset()); 188 EXPECT_EQ(header_size, field.Offset());
188 } 189 }
189 190
190 191
191 TEST_CASE(Interface) { 192 TEST_CASE(Interface) {
192 String& class_name = String::Handle(String::NewSymbol("EmptyClass")); 193 String& class_name = String::Handle(Symbols::New("EmptyClass"));
193 Script& script = Script::Handle(); 194 Script& script = Script::Handle();
194 const Class& factory_class = 195 const Class& factory_class =
195 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 196 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
196 const Array& no_fields = Array::Handle(Array::Empty()); 197 const Array& no_fields = Array::Handle(Array::Empty());
197 // Finalizes the class. 198 // Finalizes the class.
198 factory_class.SetFields(no_fields); 199 factory_class.SetFields(no_fields);
199 200
200 String& interface_name = String::Handle(String::NewSymbol("MyInterface")); 201 String& interface_name = String::Handle(Symbols::New("MyInterface"));
201 const Class& interface = Class::Handle( 202 const Class& interface = Class::Handle(
202 Class::NewInterface(interface_name, script, Scanner::kDummyTokenIndex)); 203 Class::NewInterface(interface_name, script, Scanner::kDummyTokenIndex));
203 EXPECT(interface.is_interface()); 204 EXPECT(interface.is_interface());
204 EXPECT(!factory_class.is_interface()); 205 EXPECT(!factory_class.is_interface());
205 EXPECT(!interface.HasFactoryClass()); 206 EXPECT(!interface.HasFactoryClass());
206 interface.set_factory_class(factory_class); 207 interface.set_factory_class(factory_class);
207 EXPECT_EQ(factory_class.raw(), interface.FactoryClass()); 208 EXPECT_EQ(factory_class.raw(), interface.FactoryClass());
208 } 209 }
209 210
210 211
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 1652
1652 const String& substr = String::Handle(String::SubString(str, 1, 2)); 1653 const String& substr = String::Handle(String::SubString(str, 1, 2));
1653 EXPECT(!substr.IsExternalFourByteString()); 1654 EXPECT(!substr.IsExternalFourByteString());
1654 EXPECT(substr.IsFourByteString()); 1655 EXPECT(substr.IsFourByteString());
1655 EXPECT_EQ(2, substr.Length()); 1656 EXPECT_EQ(2, substr.Length());
1656 EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E")); 1657 EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E"));
1657 } 1658 }
1658 1659
1659 1660
1660 TEST_CASE(Symbol) { 1661 TEST_CASE(Symbol) {
1661 const String& one = String::Handle(String::NewSymbol("Eins")); 1662 const String& one = String::Handle(Symbols::New("Eins"));
1662 EXPECT(one.IsSymbol()); 1663 EXPECT(one.IsSymbol());
1663 const String& two = String::Handle(String::NewSymbol("Zwei")); 1664 const String& two = String::Handle(Symbols::New("Zwei"));
1664 const String& three = String::Handle(String::NewSymbol("Drei")); 1665 const String& three = String::Handle(Symbols::New("Drei"));
1665 const String& four = String::Handle(String::NewSymbol("Vier")); 1666 const String& four = String::Handle(Symbols::New("Vier"));
1666 const String& five = String::Handle(String::NewSymbol("Fuenf")); 1667 const String& five = String::Handle(Symbols::New("Fuenf"));
1667 const String& six = String::Handle(String::NewSymbol("Sechs")); 1668 const String& six = String::Handle(Symbols::New("Sechs"));
1668 const String& seven = String::Handle(String::NewSymbol("Sieben")); 1669 const String& seven = String::Handle(Symbols::New("Sieben"));
1669 const String& eight = String::Handle(String::NewSymbol("Acht")); 1670 const String& eight = String::Handle(Symbols::New("Acht"));
1670 const String& nine = String::Handle(String::NewSymbol("Neun")); 1671 const String& nine = String::Handle(Symbols::New("Neun"));
1671 const String& ten = String::Handle(String::NewSymbol("Zehn")); 1672 const String& ten = String::Handle(Symbols::New("Zehn"));
1672 String& eins = String::Handle(String::NewSymbol("Eins")); 1673 String& eins = String::Handle(Symbols::New("Eins"));
1673 EXPECT_EQ(one.raw(), eins.raw()); 1674 EXPECT_EQ(one.raw(), eins.raw());
1674 EXPECT(one.raw() != two.raw()); 1675 EXPECT(one.raw() != two.raw());
1675 EXPECT(two.Equals(String::Handle(String::New("Zwei")))); 1676 EXPECT(two.Equals(String::Handle(String::New("Zwei"))));
1676 EXPECT_EQ(two.raw(), String::NewSymbol("Zwei")); 1677 EXPECT_EQ(two.raw(), Symbols::New("Zwei"));
1677 EXPECT_EQ(three.raw(), String::NewSymbol("Drei")); 1678 EXPECT_EQ(three.raw(), Symbols::New("Drei"));
1678 EXPECT_EQ(four.raw(), String::NewSymbol("Vier")); 1679 EXPECT_EQ(four.raw(), Symbols::New("Vier"));
1679 EXPECT_EQ(five.raw(), String::NewSymbol("Fuenf")); 1680 EXPECT_EQ(five.raw(), Symbols::New("Fuenf"));
1680 EXPECT_EQ(six.raw(), String::NewSymbol("Sechs")); 1681 EXPECT_EQ(six.raw(), Symbols::New("Sechs"));
1681 EXPECT_EQ(seven.raw(), String::NewSymbol("Sieben")); 1682 EXPECT_EQ(seven.raw(), Symbols::New("Sieben"));
1682 EXPECT_EQ(eight.raw(), String::NewSymbol("Acht")); 1683 EXPECT_EQ(eight.raw(), Symbols::New("Acht"));
1683 EXPECT_EQ(nine.raw(), String::NewSymbol("Neun")); 1684 EXPECT_EQ(nine.raw(), Symbols::New("Neun"));
1684 EXPECT_EQ(ten.raw(), String::NewSymbol("Zehn")); 1685 EXPECT_EQ(ten.raw(), Symbols::New("Zehn"));
1685 1686
1686 // Make sure to cause symbol table overflow. 1687 // Make sure to cause symbol table overflow.
1687 for (int i = 0; i < 1024; i++) { 1688 for (int i = 0; i < 1024; i++) {
1688 char buf[256]; 1689 char buf[256];
1689 OS::SNPrint(buf, sizeof(buf), "%d", i); 1690 OS::SNPrint(buf, sizeof(buf), "%d", i);
1690 String::NewSymbol(buf); 1691 Symbols::New(buf);
1691 } 1692 }
1692 eins = String::NewSymbol("Eins"); 1693 eins = Symbols::New("Eins");
1693 EXPECT_EQ(one.raw(), eins.raw()); 1694 EXPECT_EQ(one.raw(), eins.raw());
1694 EXPECT_EQ(two.raw(), String::NewSymbol("Zwei")); 1695 EXPECT_EQ(two.raw(), Symbols::New("Zwei"));
1695 EXPECT_EQ(three.raw(), String::NewSymbol("Drei")); 1696 EXPECT_EQ(three.raw(), Symbols::New("Drei"));
1696 EXPECT_EQ(four.raw(), String::NewSymbol("Vier")); 1697 EXPECT_EQ(four.raw(), Symbols::New("Vier"));
1697 EXPECT_EQ(five.raw(), String::NewSymbol("Fuenf")); 1698 EXPECT_EQ(five.raw(), Symbols::New("Fuenf"));
1698 EXPECT_EQ(six.raw(), String::NewSymbol("Sechs")); 1699 EXPECT_EQ(six.raw(), Symbols::New("Sechs"));
1699 EXPECT_EQ(seven.raw(), String::NewSymbol("Sieben")); 1700 EXPECT_EQ(seven.raw(), Symbols::New("Sieben"));
1700 EXPECT_EQ(eight.raw(), String::NewSymbol("Acht")); 1701 EXPECT_EQ(eight.raw(), Symbols::New("Acht"));
1701 EXPECT_EQ(nine.raw(), String::NewSymbol("Neun")); 1702 EXPECT_EQ(nine.raw(), Symbols::New("Neun"));
1702 EXPECT_EQ(ten.raw(), String::NewSymbol("Zehn")); 1703 EXPECT_EQ(ten.raw(), Symbols::New("Zehn"));
1703 1704
1704 // Symbols from Strings. 1705 // Symbols from Strings.
1705 eins = String::New("Eins"); 1706 eins = String::New("Eins");
1706 EXPECT(!eins.IsSymbol()); 1707 EXPECT(!eins.IsSymbol());
1707 String& ein_symbol = String::Handle(String::NewSymbol(eins)); 1708 String& ein_symbol = String::Handle(Symbols::New(eins));
1708 EXPECT_EQ(one.raw(), ein_symbol.raw()); 1709 EXPECT_EQ(one.raw(), ein_symbol.raw());
1709 EXPECT(one.raw() != eins.raw()); 1710 EXPECT(one.raw() != eins.raw());
1710 1711
1711 uint32_t char32[] = { 'E', 'l', 'f' }; 1712 uint32_t char32[] = { 'E', 'l', 'f' };
1712 String& elf = String::Handle(String::NewSymbol(char32, 3)); 1713 String& elf = String::Handle(Symbols::New(char32, 3));
1713 EXPECT(elf.IsSymbol()); 1714 EXPECT(elf.IsSymbol());
1714 EXPECT_EQ(elf.raw(), String::NewSymbol("Elf")); 1715 EXPECT_EQ(elf.raw(), Symbols::New("Elf"));
1715 } 1716 }
1716 1717
1717 1718
1718 TEST_CASE(Bool) { 1719 TEST_CASE(Bool) {
1719 const Bool& true_value = Bool::Handle(Bool::True()); 1720 const Bool& true_value = Bool::Handle(Bool::True());
1720 EXPECT(true_value.value()); 1721 EXPECT(true_value.value());
1721 const Bool& false_value = Bool::Handle(Bool::False()); 1722 const Bool& false_value = Bool::Handle(Bool::False());
1722 EXPECT(!false_value.value()); 1723 EXPECT(!false_value.value());
1723 } 1724 }
1724 1725
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 var_c = outer_scope->LocalLookupVariable(c); 2308 var_c = outer_scope->LocalLookupVariable(c);
2308 EXPECT(var_c->is_captured()); 2309 EXPECT(var_c->is_captured());
2309 EXPECT_EQ(1, var_c->index()); 2310 EXPECT_EQ(1, var_c->index());
2310 EXPECT_EQ(parent_scope_context_level - local_scope_context_level, 2311 EXPECT_EQ(parent_scope_context_level - local_scope_context_level,
2311 var_c->owner()->context_level()); // Adjusted context level. 2312 var_c->owner()->context_level()); // Adjusted context level.
2312 } 2313 }
2313 2314
2314 2315
2315 TEST_CASE(Closure) { 2316 TEST_CASE(Closure) {
2316 // Allocate the class first. 2317 // Allocate the class first.
2317 const String& class_name = String::Handle(String::NewSymbol("MyClass")); 2318 const String& class_name = String::Handle(Symbols::New("MyClass"));
2318 const Script& script = Script::Handle(); 2319 const Script& script = Script::Handle();
2319 const Class& cls = 2320 const Class& cls =
2320 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 2321 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
2321 const Array& functions = Array::Handle(Array::New(1)); 2322 const Array& functions = Array::Handle(Array::New(1));
2322 2323
2323 const Context& context = Context::Handle(Context::New(0)); 2324 const Context& context = Context::Handle(Context::New(0));
2324 Function& parent = Function::Handle(); 2325 Function& parent = Function::Handle();
2325 const String& parent_name = String::Handle(String::NewSymbol("foo_papa")); 2326 const String& parent_name = String::Handle(Symbols::New("foo_papa"));
2326 parent = Function::New(parent_name, RawFunction::kRegularFunction, 2327 parent = Function::New(parent_name, RawFunction::kRegularFunction,
2327 false, false, 0); 2328 false, false, 0);
2328 functions.SetAt(0, parent); 2329 functions.SetAt(0, parent);
2329 cls.SetFunctions(functions); 2330 cls.SetFunctions(functions);
2330 2331
2331 Function& function = Function::Handle(); 2332 Function& function = Function::Handle();
2332 const String& function_name = String::Handle(String::NewSymbol("foo")); 2333 const String& function_name = String::Handle(Symbols::New("foo"));
2333 function = Function::NewClosureFunction(function_name, parent, 0); 2334 function = Function::NewClosureFunction(function_name, parent, 0);
2334 const Class& signature_class = Class::Handle( 2335 const Class& signature_class = Class::Handle(
2335 Class::NewSignatureClass(function_name, function, script)); 2336 Class::NewSignatureClass(function_name, function, script));
2336 const Closure& closure = Closure::Handle(Closure::New(function, context)); 2337 const Closure& closure = Closure::Handle(Closure::New(function, context));
2337 const Class& closure_class = Class::Handle(closure.clazz()); 2338 const Class& closure_class = Class::Handle(closure.clazz());
2338 EXPECT(closure_class.IsSignatureClass()); 2339 EXPECT(closure_class.IsSignatureClass());
2339 EXPECT(closure_class.IsCanonicalSignatureClass()); 2340 EXPECT(closure_class.IsCanonicalSignatureClass());
2340 EXPECT_EQ(closure_class.raw(), signature_class.raw()); 2341 EXPECT_EQ(closure_class.raw(), signature_class.raw());
2341 const Function& signature_function = 2342 const Function& signature_function =
2342 Function::Handle(signature_class.signature_function()); 2343 Function::Handle(signature_class.signature_function());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 str3 = OneByteString::null(); 2385 str3 = OneByteString::null();
2385 EXPECT(str3.IsString()); 2386 EXPECT(str3.IsString());
2386 EXPECT(!str3.IsOneByteString()); 2387 EXPECT(!str3.IsOneByteString());
2387 } 2388 }
2388 2389
2389 2390
2390 // only ia32 and x64 can run execution tests. 2391 // only ia32 and x64 can run execution tests.
2391 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 2392 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
2392 2393
2393 static Function* CreateFunction(const char* name) { 2394 static Function* CreateFunction(const char* name) {
2394 const String& function_name = String::ZoneHandle(String::NewSymbol(name)); 2395 const String& function_name = String::ZoneHandle(Symbols::New(name));
2395 Function& function = Function::ZoneHandle( 2396 Function& function = Function::ZoneHandle(
2396 Function::New(function_name, RawFunction::kRegularFunction, 2397 Function::New(function_name, RawFunction::kRegularFunction,
2397 true, false, 0)); 2398 true, false, 0));
2398 return &function; 2399 return &function;
2399 } 2400 }
2400 2401
2401 // Test for Code and Instruction object creation. 2402 // Test for Code and Instruction object creation.
2402 TEST_CASE(Code) { 2403 TEST_CASE(Code) {
2403 extern void GenerateIncrement(Assembler* assembler); 2404 extern void GenerateIncrement(Assembler* assembler);
2404 Assembler _assembler_; 2405 Assembler _assembler_;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 EXPECT_EQ(20, pc_descs.TokenIndex(0)); 2528 EXPECT_EQ(20, pc_descs.TokenIndex(0));
2528 EXPECT_EQ(3, pc_descs.TryIndex(5)); 2529 EXPECT_EQ(3, pc_descs.TryIndex(5));
2529 EXPECT_EQ(static_cast<uword>(80), pc_descs.PC(5)); 2530 EXPECT_EQ(static_cast<uword>(80), pc_descs.PC(5));
2530 EXPECT_EQ(150, pc_descs.TokenIndex(5)); 2531 EXPECT_EQ(150, pc_descs.TokenIndex(5));
2531 EXPECT_EQ(PcDescriptors::kOther, pc_descs.DescriptorKind(0)); 2532 EXPECT_EQ(PcDescriptors::kOther, pc_descs.DescriptorKind(0));
2532 EXPECT_EQ(PcDescriptors::kDeopt, pc_descs.DescriptorKind(1)); 2533 EXPECT_EQ(PcDescriptors::kDeopt, pc_descs.DescriptorKind(1));
2533 } 2534 }
2534 2535
2535 2536
2536 static RawClass* CreateTestClass(const char* name) { 2537 static RawClass* CreateTestClass(const char* name) {
2537 const String& class_name = String::Handle(String::NewSymbol(name)); 2538 const String& class_name = String::Handle(Symbols::New(name));
2538 const Class& cls = Class::Handle( 2539 const Class& cls = Class::Handle(
2539 Class::New(class_name, Script::Handle(), Scanner::kDummyTokenIndex)); 2540 Class::New(class_name, Script::Handle(), Scanner::kDummyTokenIndex));
2540 return cls.raw(); 2541 return cls.raw();
2541 } 2542 }
2542 2543
2543 2544
2544 static RawField* CreateTestField(const char* name) { 2545 static RawField* CreateTestField(const char* name) {
2545 const Class& cls = Class::Handle(CreateTestClass("global:")); 2546 const Class& cls = Class::Handle(CreateTestClass("global:"));
2546 const String& field_name = String::Handle(String::NewSymbol(name)); 2547 const String& field_name = String::Handle(Symbols::New(name));
2547 const Field& field = Field::Handle(Field::New(field_name, true, false, 0)); 2548 const Field& field = Field::Handle(Field::New(field_name, true, false, 0));
2548 field.set_owner(cls); 2549 field.set_owner(cls);
2549 return field.raw(); 2550 return field.raw();
2550 } 2551 }
2551 2552
2552 2553
2553 TEST_CASE(ClassDictionaryIterator) { 2554 TEST_CASE(ClassDictionaryIterator) {
2554 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); 2555 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6"));
2555 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); 2556 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4"));
2556 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8")); 2557 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8"));
(...skipping 10 matching lines...) Expand all
2567 while (iterator.HasNext()) { 2568 while (iterator.HasNext()) {
2568 cls = iterator.GetNextClass(); 2569 cls = iterator.GetNextClass();
2569 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); 2570 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw()));
2570 count++; 2571 count++;
2571 } 2572 }
2572 ASSERT(count == 2); 2573 ASSERT(count == 2);
2573 } 2574 }
2574 2575
2575 2576
2576 static RawFunction* GetDummyTarget(const char* name) { 2577 static RawFunction* GetDummyTarget(const char* name) {
2577 const String& function_name = String::Handle(String::NewSymbol(name)); 2578 const String& function_name = String::Handle(Symbols::New(name));
2578 const bool is_static = false; 2579 const bool is_static = false;
2579 const bool is_const = false; 2580 const bool is_const = false;
2580 return Function::New(function_name, 2581 return Function::New(function_name,
2581 RawFunction::kRegularFunction, 2582 RawFunction::kRegularFunction,
2582 is_static, 2583 is_static,
2583 is_const, 2584 is_const,
2584 0); 2585 0);
2585 } 2586 }
2586 2587
2587 2588
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2632 EXPECT_EQ(1, o2.NumberOfChecks()); 2633 EXPECT_EQ(1, o2.NumberOfChecks());
2633 o2.GetCheckAt(0, &test_class_ids, &test_target); 2634 o2.GetCheckAt(0, &test_class_ids, &test_target);
2634 EXPECT_EQ(2, test_class_ids.length()); 2635 EXPECT_EQ(2, test_class_ids.length());
2635 EXPECT_EQ(kSmi, test_class_ids[0]); 2636 EXPECT_EQ(kSmi, test_class_ids[0]);
2636 EXPECT_EQ(kSmi, test_class_ids[1]); 2637 EXPECT_EQ(kSmi, test_class_ids[1]);
2637 EXPECT_EQ(target1.raw(), test_target.raw()); 2638 EXPECT_EQ(target1.raw(), test_target.raw());
2638 } 2639 }
2639 2640
2640 2641
2641 TEST_CASE(SubtypeTestCache) { 2642 TEST_CASE(SubtypeTestCache) {
2642 String& class_name = String::Handle(String::NewSymbol("EmptyClass")); 2643 String& class_name = String::Handle(Symbols::New("EmptyClass"));
2643 Script& script = Script::Handle(); 2644 Script& script = Script::Handle();
2644 const Class& empty_class = 2645 const Class& empty_class =
2645 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 2646 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
2646 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); 2647 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New());
2647 ASSERT(!cache.IsNull()); 2648 ASSERT(!cache.IsNull());
2648 EXPECT_EQ(0, cache.NumberOfChecks()); 2649 EXPECT_EQ(0, cache.NumberOfChecks());
2649 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); 2650 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2));
2650 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); 2651 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3));
2651 cache.AddCheck(empty_class.id(), targ_0, targ_1, Bool::Handle(Bool::True())); 2652 cache.AddCheck(empty_class.id(), targ_0, targ_1, Bool::Handle(Bool::True()));
2652 EXPECT_EQ(1, cache.NumberOfChecks()); 2653 EXPECT_EQ(1, cache.NumberOfChecks());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 // Named double-private constructor mismatch. 2780 // Named double-private constructor mismatch.
2780 mangled_name = OneByteString::New("foo@12345.named@12345"); 2781 mangled_name = OneByteString::New("foo@12345.named@12345");
2781 bare_name = OneByteString::New("foo.name"); 2782 bare_name = OneByteString::New("foo.name");
2782 EXPECT(!mangled_name.EqualsIgnoringPrivateKey(bare_name)); 2783 EXPECT(!mangled_name.EqualsIgnoringPrivateKey(bare_name));
2783 } 2784 }
2784 2785
2785 2786
2786 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 2787 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
2787 2788
2788 } // namespace dart 2789 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.cc ('k') | vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698