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

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

Issue 22303002: Auto create ApiLocalScope before calling native functions, this ensures that (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 "vm/benchmark_test.h" 5 #include "vm/benchmark_test.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7); 99 Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7);
100 EXPECT_VALID(result); 100 EXPECT_VALID(result);
101 101
102 Dart_ExitScope(); 102 Dart_ExitScope();
103 } 103 }
104 104
105 105
106 // The specific api functions called here are a bit arbitrary. We are 106 // The specific api functions called here are a bit arbitrary. We are
107 // trying to get a sense of the overhead for using the dart api. 107 // trying to get a sense of the overhead for using the dart api.
108 static void UseDartApi(Dart_NativeArguments args) { 108 static void UseDartApi(Dart_NativeArguments args) {
109 Dart_EnterScope();
110 int count = Dart_GetNativeArgumentCount(args); 109 int count = Dart_GetNativeArgumentCount(args);
111 EXPECT_EQ(3, count); 110 EXPECT_EQ(3, count);
112 111
113 // Get native field from receiver. 112 // Get native field from receiver.
114 intptr_t receiver_value; 113 intptr_t receiver_value;
115 Dart_Handle result = Dart_GetNativeReceiver(args, &receiver_value); 114 Dart_Handle result = Dart_GetNativeReceiver(args, &receiver_value);
116 EXPECT_VALID(result); 115 EXPECT_VALID(result);
117 EXPECT_EQ(7, receiver_value); 116 EXPECT_EQ(7, receiver_value);
118 117
119 // Get param1. 118 // Get param1.
120 Dart_Handle param1 = Dart_GetNativeArgument(args, 1); 119 Dart_Handle param1 = Dart_GetNativeArgument(args, 1);
121 EXPECT_VALID(param1); 120 EXPECT_VALID(param1);
122 EXPECT(Dart_IsInteger(param1)); 121 EXPECT(Dart_IsInteger(param1));
123 bool fits = false; 122 bool fits = false;
124 result = Dart_IntegerFitsIntoInt64(param1, &fits); 123 result = Dart_IntegerFitsIntoInt64(param1, &fits);
125 EXPECT_VALID(result); 124 EXPECT_VALID(result);
126 EXPECT(fits); 125 EXPECT(fits);
127 int64_t value1; 126 int64_t value1;
128 result = Dart_IntegerToInt64(param1, &value1); 127 result = Dart_IntegerToInt64(param1, &value1);
129 EXPECT_VALID(result); 128 EXPECT_VALID(result);
130 EXPECT_LE(0, value1); 129 EXPECT_LE(0, value1);
131 EXPECT_LE(value1, 1000000); 130 EXPECT_LE(value1, 1000000);
132 131
133 // Return param + receiver.field. 132 // Return param + receiver.field.
134 Dart_SetReturnValue(args, Dart_NewInteger(value1 * receiver_value)); 133 Dart_SetReturnValue(args, Dart_NewInteger(value1 * receiver_value));
135 Dart_ExitScope();
136 } 134 }
137 135
138 136
139 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, int argument_count) { 137 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, int argument_count) {
140 const char* cstr = NULL; 138 const char* cstr = NULL;
141 Dart_Handle result = Dart_StringToCString(name, &cstr); 139 Dart_Handle result = Dart_StringToCString(name, &cstr);
142 EXPECT_VALID(result); 140 EXPECT_VALID(result);
143 if (strcmp(cstr, "init") == 0) { 141 if (strcmp(cstr, "init") == 0) {
144 return InitNativeFields; 142 return InitNativeFields;
145 } else { 143 } else {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 free(dart_root); 297 free(dart_root);
300 free(script); 298 free(script);
301 } 299 }
302 300
303 301
304 // 302 //
305 // Measure frame lookup during stack traversal. 303 // Measure frame lookup during stack traversal.
306 // 304 //
307 static void StackFrame_accessFrame(Dart_NativeArguments args) { 305 static void StackFrame_accessFrame(Dart_NativeArguments args) {
308 const int kNumIterations = 100; 306 const int kNumIterations = 100;
309 Dart_EnterScope();
310 Code& code = Code::Handle(); 307 Code& code = Code::Handle();
311 Timer timer(true, "LookupDartCode benchmark"); 308 Timer timer(true, "LookupDartCode benchmark");
312 timer.Start(); 309 timer.Start();
313 for (int i = 0; i < kNumIterations; i++) { 310 for (int i = 0; i < kNumIterations; i++) {
314 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); 311 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames);
315 StackFrame* frame = frames.NextFrame(); 312 StackFrame* frame = frames.NextFrame();
316 while (frame != NULL) { 313 while (frame != NULL) {
317 if (frame->IsStubFrame()) { 314 if (frame->IsStubFrame()) {
318 code = frame->LookupDartCode(); 315 code = frame->LookupDartCode();
319 EXPECT(code.function() == Function::null()); 316 EXPECT(code.function() == Function::null());
320 } else if (frame->IsDartFrame()) { 317 } else if (frame->IsDartFrame()) {
321 code = frame->LookupDartCode(); 318 code = frame->LookupDartCode();
322 EXPECT(code.function() != Function::null()); 319 EXPECT(code.function() != Function::null());
323 } 320 }
324 frame = frames.NextFrame(); 321 frame = frames.NextFrame();
325 } 322 }
326 } 323 }
327 timer.Stop(); 324 timer.Stop();
328 int64_t elapsed_time = timer.TotalElapsedTime(); 325 int64_t elapsed_time = timer.TotalElapsedTime();
329 Dart_SetReturnValue(args, Dart_NewInteger(elapsed_time)); 326 Dart_SetReturnValue(args, Dart_NewInteger(elapsed_time));
330 Dart_ExitScope();
331 } 327 }
332 328
333 329
334 static Dart_NativeFunction StackFrameNativeResolver(Dart_Handle name, 330 static Dart_NativeFunction StackFrameNativeResolver(Dart_Handle name,
335 int arg_count) { 331 int arg_count) {
336 return &StackFrame_accessFrame; 332 return &StackFrame_accessFrame;
337 } 333 }
338 334
339 335
340 // Unit test case to verify stack frame iteration. 336 // Unit test case to verify stack frame iteration.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 460
465 Timer timer(true, "currentMirrorSystem() benchmark"); 461 Timer timer(true, "currentMirrorSystem() benchmark");
466 timer.Start(); 462 timer.Start();
467 Dart_Invoke(lib, NewString("benchmark"), 0, NULL); 463 Dart_Invoke(lib, NewString("benchmark"), 0, NULL);
468 timer.Stop(); 464 timer.Stop();
469 int64_t elapsed_time = timer.TotalElapsedTime(); 465 int64_t elapsed_time = timer.TotalElapsedTime();
470 benchmark->set_score(elapsed_time); 466 benchmark->set_score(elapsed_time);
471 } 467 }
472 468
473 } // namespace dart 469 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698