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

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

Issue 21986002: Add Dart_GetNativeReceiver to special case access to the native field (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
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl.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 "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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(); 109 Dart_EnterScope();
110 int count = Dart_GetNativeArgumentCount(args); 110 int count = Dart_GetNativeArgumentCount(args);
111 EXPECT_EQ(3, count); 111 EXPECT_EQ(3, count);
112 112
113 // Get the receiver. 113 // Get native field from receiver.
114 Dart_Handle recv = Dart_GetNativeArgument(args, 0); 114 intptr_t receiver_value;
115 EXPECT_VALID(recv); 115 Dart_Handle result = Dart_GetNativeReceiver(args, &receiver_value);
116 EXPECT_VALID(result);
117 EXPECT_EQ(7, receiver_value);
116 118
117 // Get param1. 119 // Get param1.
118 Dart_Handle param1 = Dart_GetNativeArgument(args, 1); 120 Dart_Handle param1 = Dart_GetNativeArgument(args, 1);
119 EXPECT_VALID(param1); 121 EXPECT_VALID(param1);
120 EXPECT(Dart_IsInteger(param1)); 122 EXPECT(Dart_IsInteger(param1));
121 bool fits = false; 123 bool fits = false;
122 Dart_Handle result = Dart_IntegerFitsIntoInt64(param1, &fits); 124 result = Dart_IntegerFitsIntoInt64(param1, &fits);
123 EXPECT_VALID(result); 125 EXPECT_VALID(result);
124 EXPECT(fits); 126 EXPECT(fits);
125 int64_t value1; 127 int64_t value1;
126 result = Dart_IntegerToInt64(param1, &value1); 128 result = Dart_IntegerToInt64(param1, &value1);
127 EXPECT_VALID(result); 129 EXPECT_VALID(result);
128 EXPECT_LE(0, value1); 130 EXPECT_LE(0, value1);
129 EXPECT_LE(value1, 1000000); 131 EXPECT_LE(value1, 1000000);
130 132
131 // Get native field from receiver.
132 intptr_t value2;
133 result = Dart_GetNativeInstanceField(recv, 0, &value2);
134 EXPECT_VALID(result);
135 EXPECT_EQ(7, value2);
136
137 // Return param + receiver.field. 133 // Return param + receiver.field.
138 Dart_SetReturnValue(args, Dart_NewInteger(value1 * value2)); 134 Dart_SetReturnValue(args, Dart_NewInteger(value1 * receiver_value));
139 Dart_ExitScope(); 135 Dart_ExitScope();
140 } 136 }
141 137
142 138
143 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, int argument_count) { 139 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, int argument_count) {
144 const char* cstr = NULL; 140 const char* cstr = NULL;
145 Dart_Handle result = Dart_StringToCString(name, &cstr); 141 Dart_Handle result = Dart_StringToCString(name, &cstr);
146 EXPECT_VALID(result); 142 EXPECT_VALID(result);
147 if (strcmp(cstr, "init") == 0) { 143 if (strcmp(cstr, "init") == 0) {
148 return InitNativeFields; 144 return InitNativeFields;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 464
469 Timer timer(true, "currentMirrorSystem() benchmark"); 465 Timer timer(true, "currentMirrorSystem() benchmark");
470 timer.Start(); 466 timer.Start();
471 Dart_Invoke(lib, NewString("benchmark"), 0, NULL); 467 Dart_Invoke(lib, NewString("benchmark"), 0, NULL);
472 timer.Stop(); 468 timer.Stop();
473 int64_t elapsed_time = timer.TotalElapsedTime(); 469 int64_t elapsed_time = timer.TotalElapsedTime();
474 benchmark->set_score(elapsed_time); 470 benchmark->set_score(elapsed_time);
475 } 471 }
476 472
477 } // namespace dart 473 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698