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

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

Issue 82713009: Fixes FindCodeObject test. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | « no previous file | no next file » | 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/class_finalizer.h" 6 #include "vm/class_finalizer.h"
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/pages.h" 9 #include "vm/pages.h"
10 #include "vm/stack_frame.h" 10 #include "vm/stack_frame.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 TEST_CASE(FindCodeObject) { 16 TEST_CASE(FindCodeObject) {
17 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) 17 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
18 const int kLoopCount = 50000; 18 const int kLoopCount = 50000;
19 #else 19 #else
20 const int kLoopCount = 25000; 20 const int kLoopCount = 25000;
21 #endif 21 #endif
22 const int kScriptSize = 512 * KB; 22 const int kScriptSize = 512 * KB;
23 const int kNumFunctions = 1024; 23 const int kNumFunctions = 1024;
24 char scriptChars[kScriptSize]; 24 char scriptChars[kScriptSize];
25
26 // Get access to the code index table.
27 Isolate* isolate = Isolate::Current();
28 ASSERT(isolate != NULL);
29
30 StackZone zone(isolate);
25 String& url = String::Handle(String::New("dart-test:FindCodeObject")); 31 String& url = String::Handle(String::New("dart-test:FindCodeObject"));
26 String& source = String::Handle(); 32 String& source = String::Handle();
27 Script& script = Script::Handle(); 33 Script& script = Script::Handle();
28 Library& lib = Library::Handle(); 34 Library& lib = Library::Handle();
29 Class& clsA = Class::Handle(); 35 Class& clsA = Class::Handle();
30 Class& clsB = Class::Handle(); 36 Class& clsB = Class::Handle();
31 String& function_name = String::Handle(); 37 String& function_name = String::Handle();
32 Function& function = Function::Handle(); 38 Function& function = Function::Handle();
33 char buffer[256]; 39 char buffer[256];
34 40
35 // Get access to the code index table.
36 Isolate* isolate = Isolate::Current();
37 ASSERT(isolate != NULL);
38
39 lib = Library::CoreLibrary(); 41 lib = Library::CoreLibrary();
40 42
41 // Load up class A with 1024 functions. 43 // Load up class A with 1024 functions.
42 int written = OS::SNPrint(scriptChars, kScriptSize, "class A {"); 44 int written = OS::SNPrint(scriptChars, kScriptSize, "class A {");
43 for (int i = 0; i < kNumFunctions; i++) { 45 for (int i = 0; i < kNumFunctions; i++) {
44 OS::SNPrint(buffer, 46 OS::SNPrint(buffer,
45 256, 47 256,
46 "static foo%d([int i=1,int j=2,int k=3]){return i+j+k;}", i); 48 "static foo%d([int i=1,int j=2,int k=3]){return i+j+k;}", i);
47 written += OS::SNPrint((scriptChars + written), 49 written += OS::SNPrint((scriptChars + written),
48 (kScriptSize - written), 50 (kScriptSize - written),
49 "%s", 51 "%s",
50 buffer); 52 buffer);
51 } 53 }
52 OS::SNPrint((scriptChars + written), (kScriptSize - written), "}"); 54 OS::SNPrint((scriptChars + written), (kScriptSize - written), "}");
53 source = String::New(scriptChars); 55 source = String::New(scriptChars);
54 script = Script::New(url, source, RawScript::kScriptTag); 56 script = Script::New(url, source, RawScript::kScriptTag);
55 EXPECT(CompilerTest::TestCompileScript(lib, script)); 57 EXPECT(CompilerTest::TestCompileScript(lib, script));
56 clsA = lib.LookupClass(String::Handle(Symbols::New("A"))); 58 clsA = lib.LookupClass(String::Handle(Symbols::New("A")));
57 EXPECT(!clsA.IsNull()); 59 EXPECT(!clsA.IsNull());
58 ClassFinalizer::FinalizeTypeHierarchy(); 60 ClassFinalizer::FinalizeTypeHierarchy();
59 for (int i = 0; i < kNumFunctions; i++) { 61 for (int i = 0; i < kNumFunctions; i++) {
60 OS::SNPrint(buffer, 256, "foo%d", i); 62 OS::SNPrint(buffer, 256, "foo%d", i);
61 function_name = String::New(buffer); 63 function_name = String::New(buffer);
62 function = clsA.LookupStaticFunction(function_name); 64 function = clsA.LookupStaticFunction(function_name);
63 EXPECT(!function.IsNull()); 65 EXPECT(!function.IsNull());
64 EXPECT(CompilerTest::TestCompileFunction(function)); 66 EXPECT(CompilerTest::TestCompileFunction(function));
67 const Code& code = Code::ZoneHandle(function.CurrentCode());
68 EXPECT(!code.IsNull())
65 EXPECT(function.HasCode()); 69 EXPECT(function.HasCode());
66 } 70 }
67 71
68 // Now load up class B with 1024 functions. 72 // Now load up class B with 1024 functions.
69 written = OS::SNPrint(scriptChars, kScriptSize, "class B {"); 73 written = OS::SNPrint(scriptChars, kScriptSize, "class B {");
70 // Create one large function. 74 // Create one large function.
71 OS::SNPrint(buffer, sizeof(buffer), "static moo0([var i=1]) { "); 75 OS::SNPrint(buffer, sizeof(buffer), "static moo0([var i=1]) { ");
72 written += OS::SNPrint((scriptChars + written), 76 written += OS::SNPrint((scriptChars + written),
73 (kScriptSize - written), 77 (kScriptSize - written),
74 "%s", 78 "%s",
(...skipping 28 matching lines...) Expand all
103 EXPECT(CompilerTest::TestCompileScript(lib, script)); 107 EXPECT(CompilerTest::TestCompileScript(lib, script));
104 clsB = lib.LookupClass(String::Handle(Symbols::New("B"))); 108 clsB = lib.LookupClass(String::Handle(Symbols::New("B")));
105 EXPECT(!clsB.IsNull()); 109 EXPECT(!clsB.IsNull());
106 ClassFinalizer::FinalizeTypeHierarchy(); 110 ClassFinalizer::FinalizeTypeHierarchy();
107 for (int i = 0; i < kNumFunctions; i++) { 111 for (int i = 0; i < kNumFunctions; i++) {
108 OS::SNPrint(buffer, 256, "moo%d", i); 112 OS::SNPrint(buffer, 256, "moo%d", i);
109 function_name = String::New(buffer); 113 function_name = String::New(buffer);
110 function = clsB.LookupStaticFunction(function_name); 114 function = clsB.LookupStaticFunction(function_name);
111 EXPECT(!function.IsNull()); 115 EXPECT(!function.IsNull());
112 EXPECT(CompilerTest::TestCompileFunction(function)); 116 EXPECT(CompilerTest::TestCompileFunction(function));
117 const Code& code = Code::ZoneHandle(function.CurrentCode());
118 EXPECT(!code.IsNull());
113 EXPECT(function.HasCode()); 119 EXPECT(function.HasCode());
114 } 120 }
115 121
116 // Now try and access these functions using the code index table. 122 // Now try and access these functions using the code index table.
117 Code& code = Code::Handle(); 123 Code& code = Code::Handle();
118 uword pc; 124 uword pc;
119 OS::SNPrint(buffer, 256, "foo%d", 123); 125 OS::SNPrint(buffer, 256, "foo%d", 123);
120 function_name = String::New(buffer); 126 function_name = String::New(buffer);
121 function = clsA.LookupStaticFunction(function_name); 127 function = clsA.LookupStaticFunction(function_name);
122 EXPECT(!function.IsNull()); 128 EXPECT(!function.IsNull());
(...skipping 20 matching lines...) Expand all
143 EXPECT(code.Size() > 16); 149 EXPECT(code.Size() > 16);
144 pc = code.EntryPoint() + 16; 150 pc = code.EntryPoint() + 16;
145 EXPECT(code.Size() > (PageSpace::kPageSizeInWords << kWordSizeLog2)); 151 EXPECT(code.Size() > (PageSpace::kPageSizeInWords << kWordSizeLog2));
146 EXPECT(Code::LookupCode(pc) == code.raw()); 152 EXPECT(Code::LookupCode(pc) == code.raw());
147 EXPECT(code.Size() > (1 * MB)); 153 EXPECT(code.Size() > (1 * MB));
148 pc = code.EntryPoint() + (1 * MB); 154 pc = code.EntryPoint() + (1 * MB);
149 EXPECT(Code::LookupCode(pc) == code.raw()); 155 EXPECT(Code::LookupCode(pc) == code.raw());
150 } 156 }
151 157
152 } // namespace dart 158 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698