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

Side by Side Diff: vm/code_generator_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/code_generator.cc ('k') | vm/code_patcher_ia32_test.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/globals.h" 6 #include "vm/globals.h"
7 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 7 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
8 8
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/assembler.h" 10 #include "vm/assembler.h"
11 #include "vm/class_finalizer.h" 11 #include "vm/class_finalizer.h"
12 #include "vm/code_generator.h" 12 #include "vm/code_generator.h"
13 #include "vm/compiler.h" 13 #include "vm/compiler.h"
14 #include "vm/dart_entry.h" 14 #include "vm/dart_entry.h"
15 #include "vm/native_entry.h" 15 #include "vm/native_entry.h"
16 #include "vm/native_entry_test.h" 16 #include "vm/native_entry_test.h"
17 #include "vm/symbols.h"
17 #include "vm/unit_test.h" 18 #include "vm/unit_test.h"
18 #include "vm/virtual_memory.h" 19 #include "vm/virtual_memory.h"
19 20
20 namespace dart { 21 namespace dart {
21 22
22 static const intptr_t kPos = Scanner::kDummyTokenIndex; 23 static const intptr_t kPos = Scanner::kDummyTokenIndex;
23 24
24 25
25 // Helper to allocate and return a LocalVariable. 26 // Helper to allocate and return a LocalVariable.
26 static LocalVariable* NewTestLocalVariable(const char* name) { 27 static LocalVariable* NewTestLocalVariable(const char* name) {
27 const String& variable_name = String::ZoneHandle(String::NewSymbol(name)); 28 const String& variable_name = String::ZoneHandle(Symbols::New(name));
28 const Type& variable_type = Type::ZoneHandle(Type::DynamicType()); 29 const Type& variable_type = Type::ZoneHandle(Type::DynamicType());
29 return new LocalVariable(kPos, variable_name, variable_type); 30 return new LocalVariable(kPos, variable_name, variable_type);
30 } 31 }
31 32
32 33
33 CODEGEN_TEST_GENERATE(SimpleReturnCodegen, test) { 34 CODEGEN_TEST_GENERATE(SimpleReturnCodegen, test) {
34 test->node_sequence()->Add(new ReturnNode(kPos)); 35 test->node_sequence()->Add(new ReturnNode(kPos));
35 } 36 }
36 CODEGEN_TEST_RUN(SimpleReturnCodegen, Instance::null()) 37 CODEGEN_TEST_RUN(SimpleReturnCodegen, Instance::null())
37 38
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 local_scope->AddVariable(NewTestLocalVariable("b")); 213 local_scope->AddVariable(NewTestLocalVariable("b"));
213 ASSERT(local_scope->num_variables() == num_params); 214 ASSERT(local_scope->num_variables() == num_params);
214 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params)); 215 const Array& default_values = Array::ZoneHandle(Array::New(num_opt_params));
215 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1. 216 default_values.SetAt(0, Smi::ZoneHandle(Smi::New(1))); // b = 1.
216 test->set_default_parameter_values(default_values); 217 test->set_default_parameter_values(default_values);
217 const Function& function = test->function(); 218 const Function& function = test->function();
218 function.set_num_fixed_parameters(num_fixed_params); 219 function.set_num_fixed_parameters(num_fixed_params);
219 function.set_num_optional_parameters(num_opt_params); 220 function.set_num_optional_parameters(num_opt_params);
220 const bool has_opt_params = true; 221 const bool has_opt_params = true;
221 const String& native_name = 222 const String& native_name =
222 String::ZoneHandle(String::NewSymbol("TestSmiSub")); 223 String::ZoneHandle(Symbols::New("TestSmiSub"));
223 NativeFunction native_function = 224 NativeFunction native_function =
224 reinterpret_cast<NativeFunction>(NATIVE_ENTRY_FUNCTION(TestSmiSub)); 225 reinterpret_cast<NativeFunction>(NATIVE_ENTRY_FUNCTION(TestSmiSub));
225 node_seq->Add(new ReturnNode(kPos, 226 node_seq->Add(new ReturnNode(kPos,
226 new NativeBodyNode(kPos, 227 new NativeBodyNode(kPos,
227 native_name, 228 native_name,
228 native_function, 229 native_function,
229 num_params, 230 num_params,
230 has_opt_params, 231 has_opt_params,
231 false))); 232 false)));
232 } 233 }
(...skipping 24 matching lines...) Expand all
257 SequenceNode* node_seq = test->node_sequence(); 258 SequenceNode* node_seq = test->node_sequence();
258 LiteralNode* a = 259 LiteralNode* a =
259 new LiteralNode(kPos, Double::ZoneHandle(Double::New(12.0, Heap::kOld))); 260 new LiteralNode(kPos, Double::ZoneHandle(Double::New(12.0, Heap::kOld)));
260 UnaryOpNode* neg_node = new UnaryOpNode(kPos, Token::kSUB, a); 261 UnaryOpNode* neg_node = new UnaryOpNode(kPos, Token::kSUB, a);
261 node_seq->Add(new ReturnNode(kPos, neg_node)); 262 node_seq->Add(new ReturnNode(kPos, neg_node));
262 } 263 }
263 CODEGEN_TEST_RUN(DoubleUnaryOpCodegen, Double::New(-12.0)) 264 CODEGEN_TEST_RUN(DoubleUnaryOpCodegen, Double::New(-12.0))
264 265
265 266
266 static Library& MakeTestLibrary(const char* url) { 267 static Library& MakeTestLibrary(const char* url) {
267 const String& lib_url = String::ZoneHandle(String::NewSymbol(url)); 268 const String& lib_url = String::ZoneHandle(Symbols::New(url));
268 Library& lib = Library::ZoneHandle(Library::New(lib_url)); 269 Library& lib = Library::ZoneHandle(Library::New(lib_url));
269 lib.Register(); 270 lib.Register();
270 return lib; 271 return lib;
271 } 272 }
272 273
273 274
274 static RawClass* LookupClass(const Library& lib, const char* name) { 275 static RawClass* LookupClass(const Library& lib, const char* name) {
275 const String& cls_name = String::ZoneHandle(String::NewSymbol(name)); 276 const String& cls_name = String::ZoneHandle(Symbols::New(name));
276 return lib.LookupClass(cls_name); 277 return lib.LookupClass(cls_name);
277 } 278 }
278 279
279 280
280 CODEGEN_TEST_GENERATE(StaticCallCodegen, test) { 281 CODEGEN_TEST_GENERATE(StaticCallCodegen, test) {
281 const char* kScriptChars = 282 const char* kScriptChars =
282 "class A {\n" 283 "class A {\n"
283 " static bar() { return 42; }\n" 284 " static bar() { return 42; }\n"
284 " static fly() { return 5; }\n" 285 " static fly() { return 5; }\n"
285 "}\n"; 286 "}\n";
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 EXPECT(ClassFinalizer::FinalizePendingClasses()); 342 EXPECT(ClassFinalizer::FinalizePendingClasses());
342 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); 343 Class& cls = Class::ZoneHandle(LookupClass(lib, "A"));
343 EXPECT(!cls.IsNull()); 344 EXPECT(!cls.IsNull());
344 345
345 String& constructor_name = String::Handle(String::New("A.")); 346 String& constructor_name = String::Handle(String::New("A."));
346 Function& constructor = 347 Function& constructor =
347 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); 348 Function::ZoneHandle(cls.LookupConstructor(constructor_name));
348 EXPECT(!constructor.IsNull()); 349 EXPECT(!constructor.IsNull());
349 350
350 // The unit test creates an instance of class A and calls function 'bar'. 351 // The unit test creates an instance of class A and calls function 'bar'.
351 String& function_bar_name = String::ZoneHandle(String::NewSymbol("bar")); 352 String& function_bar_name = String::ZoneHandle(Symbols::New("bar"));
352 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); 353 ArgumentListNode* no_arguments = new ArgumentListNode(kPos);
353 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); 354 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle();
354 const LocalVariable& allocated = *test->CreateTempConstVariable("alloc"); 355 const LocalVariable& allocated = *test->CreateTempConstVariable("alloc");
355 InstanceCallNode* call_bar = new InstanceCallNode( 356 InstanceCallNode* call_bar = new InstanceCallNode(
356 kPos, 357 kPos,
357 new ConstructorCallNode( 358 new ConstructorCallNode(
358 kPos, no_type_arguments, constructor, no_arguments, allocated), 359 kPos, no_type_arguments, constructor, no_arguments, allocated),
359 function_bar_name, 360 function_bar_name,
360 no_arguments); 361 no_arguments);
361 362
(...skipping 27 matching lines...) Expand all
389 function.set_num_fixed_parameters(num_fixed_params); 390 function.set_num_fixed_parameters(num_fixed_params);
390 function.set_num_optional_parameters(num_opt_params); 391 function.set_num_optional_parameters(num_opt_params);
391 function.set_parameter_types(Array::Handle(Array::New(num_params))); 392 function.set_parameter_types(Array::Handle(Array::New(num_params)));
392 function.set_parameter_names(Array::Handle(Array::New(num_params))); 393 function.set_parameter_names(Array::Handle(Array::New(num_params)));
393 const Type& param_type = Type::Handle(Type::DynamicType()); 394 const Type& param_type = Type::Handle(Type::DynamicType());
394 for (int i = 0; i < num_params - 1; i++) { 395 for (int i = 0; i < num_params - 1; i++) {
395 function.SetParameterTypeAt(i, param_type); 396 function.SetParameterTypeAt(i, param_type);
396 } 397 }
397 const bool has_opt_params = true; 398 const bool has_opt_params = true;
398 const String& native_name = 399 const String& native_name =
399 String::ZoneHandle(String::NewSymbol("TestSmiSum")); 400 String::ZoneHandle(Symbols::New("TestSmiSum"));
400 NativeFunction native_function = 401 NativeFunction native_function =
401 reinterpret_cast<NativeFunction>(NATIVE_ENTRY_FUNCTION(TestSmiSum)); 402 reinterpret_cast<NativeFunction>(NATIVE_ENTRY_FUNCTION(TestSmiSum));
402 node_seq->Add(new ReturnNode(kPos, 403 node_seq->Add(new ReturnNode(kPos,
403 new NativeBodyNode(kPos, 404 new NativeBodyNode(kPos,
404 native_name, 405 native_name,
405 native_function, 406 native_function,
406 num_params, 407 num_params,
407 has_opt_params, 408 has_opt_params,
408 false))); 409 false)));
409 } 410 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 EXPECT(!result.IsError()); 504 EXPECT(!result.IsError());
504 const GrowableObjectArray& libs = GrowableObjectArray::Handle( 505 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
505 Isolate::Current()->object_store()->libraries()); 506 Isolate::Current()->object_store()->libraries());
506 ASSERT(!libs.IsNull()); 507 ASSERT(!libs.IsNull());
507 // App lib is the last one that was loaded. 508 // App lib is the last one that was loaded.
508 intptr_t num_libs = libs.Length(); 509 intptr_t num_libs = libs.Length();
509 Library& app_lib = Library::Handle(); 510 Library& app_lib = Library::Handle();
510 app_lib ^= libs.At(num_libs - 1); 511 app_lib ^= libs.At(num_libs - 1);
511 ASSERT(!app_lib.IsNull()); 512 ASSERT(!app_lib.IsNull());
512 const Class& cls = Class::Handle( 513 const Class& cls = Class::Handle(
513 app_lib.LookupClass(String::Handle(String::NewSymbol("A")))); 514 app_lib.LookupClass(String::Handle(Symbols::New("A"))));
514 EXPECT_EQ(cls.raw(), result.clazz()); 515 EXPECT_EQ(cls.raw(), result.clazz());
515 } 516 }
516 517
517 } // namespace dart 518 } // namespace dart
518 519
519 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) 520 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64)
OLDNEW
« no previous file with comments | « vm/code_generator.cc ('k') | vm/code_patcher_ia32_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698