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

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

Issue 566853005: Fix to allocation stub invalidation: we cannot just remove it as it will be collected even though c… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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
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/class_finalizer.h" 6 #include "vm/class_finalizer.h"
7 #include "vm/code_patcher.h" 7 #include "vm/code_patcher.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/symbols.h" 11 #include "vm/symbols.h"
12 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 DECLARE_FLAG(bool, enable_type_checks);
17
16 TEST_CASE(CompileScript) { 18 TEST_CASE(CompileScript) {
17 const char* kScriptChars = 19 const char* kScriptChars =
18 "class A {\n" 20 "class A {\n"
19 " static foo() { return 42; }\n" 21 " static foo() { return 42; }\n"
20 "}\n"; 22 "}\n";
21 String& url = String::Handle(String::New("dart-test:CompileScript")); 23 String& url = String::Handle(String::New("dart-test:CompileScript"));
22 String& source = String::Handle(String::New(kScriptChars)); 24 String& source = String::Handle(String::New(kScriptChars));
23 Script& script = Script::Handle(Script::New(url, 25 Script& script = Script::Handle(Script::New(url,
24 source, 26 source,
25 RawScript::kScriptTag)); 27 RawScript::kScriptTag));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 function_source.ToCString()); 70 function_source.ToCString());
69 } 71 }
70 72
71 73
72 TEST_CASE(RegenerateAllocStubs) { 74 TEST_CASE(RegenerateAllocStubs) {
73 const char* kScriptChars = 75 const char* kScriptChars =
74 "class A {\n" 76 "class A {\n"
75 "}\n" 77 "}\n"
76 "unOpt() => new A(); \n" 78 "unOpt() => new A(); \n"
77 "optIt() => new A(); \n" 79 "optIt() => new A(); \n"
78 "main() {\n" 80 "A main() {\n"
79 " return unOpt();\n" 81 " return unOpt();\n"
80 "}\n"; 82 "}\n";
81 83
84 bool old_enable_type_checks = FLAG_enable_type_checks;
85 FLAG_enable_type_checks = true;
82 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 86 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
83 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 87 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
84 EXPECT_VALID(result); 88 EXPECT_VALID(result);
85 RawLibrary* raw_library = Library::RawCast(Api::UnwrapHandle(lib)); 89 RawLibrary* raw_library = Library::RawCast(Api::UnwrapHandle(lib));
86 Library& lib_handle = Library::ZoneHandle(raw_library); 90 Library& lib_handle = Library::ZoneHandle(raw_library);
87 Class& cls = Class::Handle( 91 Class& cls = Class::Handle(
88 lib_handle.LookupClass(String::Handle(Symbols::New("A")))); 92 lib_handle.LookupClass(String::Handle(Symbols::New("A"))));
89 EXPECT(!cls.IsNull()); 93 EXPECT(!cls.IsNull());
90 94
91 Isolate* isolate = Isolate::Current(); 95 Isolate* isolate = Isolate::Current();
92 StubCode* stub_code = isolate->stub_code(); 96 StubCode* stub_code = isolate->stub_code();
93 const Code& stub = Code::Handle(isolate, 97 const Code& stub = Code::Handle(isolate,
94 stub_code->GetAllocationStubForClass(cls)); 98 stub_code->GetAllocationStubForClass(cls));
95 Class& owner = Class::Handle(); 99 Class& owner = Class::Handle();
96 owner ^= stub.owner(); 100 owner ^= stub.owner();
97 owner.DisableAllocationStub(); 101 owner.DisableAllocationStub();
98 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 102 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
99 EXPECT_VALID(result); 103 EXPECT_VALID(result);
104 FLAG_enable_type_checks = old_enable_type_checks;
100 } 105 }
101 106
102 107
103 TEST_CASE(EvalExpression) { 108 TEST_CASE(EvalExpression) {
104 const char* kScriptChars = 109 const char* kScriptChars =
105 "int ten = 2 * 5; \n" 110 "int ten = 2 * 5; \n"
106 "get dot => '.'; \n" 111 "get dot => '.'; \n"
107 "class A { \n" 112 "class A { \n"
108 " var apa = 'Herr Nilsson'; \n" 113 " var apa = 'Herr Nilsson'; \n"
109 " calc(x) => '${x*ten}'; \n" 114 " calc(x) => '${x*ten}'; \n"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 val = lib.Evaluate(expression, Array::empty_array(), Array::empty_array()); 164 val = lib.Evaluate(expression, Array::empty_array(), Array::empty_array());
160 } 165 }
161 166
162 EXPECT(!val.IsNull()); 167 EXPECT(!val.IsNull());
163 EXPECT(!val.IsError()); 168 EXPECT(!val.IsError());
164 EXPECT(val.IsInteger()); 169 EXPECT(val.IsInteger());
165 EXPECT_EQ(7, Integer::Cast(val).AsInt64Value()); 170 EXPECT_EQ(7, Integer::Cast(val).AsInt64Value());
166 } 171 }
167 172
168 } // namespace dart 173 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698