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

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

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 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
« no previous file with comments | « runtime/vm/dart_entry.h ('k') | runtime/vm/dart_entry_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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/dart_entry.h" 5 #include "vm/dart_entry.h"
6 6
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/debugger.h" 9 #include "vm/debugger.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
11 #include "vm/resolver.h" 11 #include "vm/resolver.h"
12 #include "vm/runtime_entry.h" 12 #include "vm/runtime_entry.h"
13 #include "vm/safepoint.h" 13 #include "vm/safepoint.h"
14 #include "vm/simulator.h" 14 #include "vm/simulator.h"
15 #include "vm/stub_code.h" 15 #include "vm/stub_code.h"
16 #include "vm/symbols.h" 16 #include "vm/symbols.h"
17 17
18 namespace dart { 18 namespace dart {
19 19
20 // A cache of VM heap allocated arguments descriptors. 20 // A cache of VM heap allocated arguments descriptors.
21 RawArray* ArgumentsDescriptor::cached_args_descriptors_[kCachedDescriptorCount]; 21 RawArray* ArgumentsDescriptor::cached_args_descriptors_[kCachedDescriptorCount];
22 22
23
24 RawObject* DartEntry::InvokeFunction(const Function& function, 23 RawObject* DartEntry::InvokeFunction(const Function& function,
25 const Array& arguments) { 24 const Array& arguments) {
26 ASSERT(Thread::Current()->IsMutatorThread()); 25 ASSERT(Thread::Current()->IsMutatorThread());
27 const int kTypeArgsLen = 0; // No support to pass type args to generic func. 26 const int kTypeArgsLen = 0; // No support to pass type args to generic func.
28 const Array& arguments_descriptor = 27 const Array& arguments_descriptor =
29 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length())); 28 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length()));
30 return InvokeFunction(function, arguments, arguments_descriptor); 29 return InvokeFunction(function, arguments, arguments_descriptor);
31 } 30 }
32 31
33
34 class ScopedIsolateStackLimits : public ValueObject { 32 class ScopedIsolateStackLimits : public ValueObject {
35 public: 33 public:
36 explicit ScopedIsolateStackLimits(Thread* thread, uword current_sp) 34 explicit ScopedIsolateStackLimits(Thread* thread, uword current_sp)
37 : thread_(thread), saved_stack_limit_(0) { 35 : thread_(thread), saved_stack_limit_(0) {
38 ASSERT(thread != NULL); 36 ASSERT(thread != NULL);
39 // Set the thread's stack_base based on the current 37 // Set the thread's stack_base based on the current
40 // stack pointer, we keep refining this value as we 38 // stack pointer, we keep refining this value as we
41 // see higher stack pointers (Note: we assume the stack 39 // see higher stack pointers (Note: we assume the stack
42 // grows from high to low addresses). 40 // grows from high to low addresses).
43 OSThread* os_thread = thread->os_thread(); 41 OSThread* os_thread = thread->os_thread();
(...skipping 14 matching lines...) Expand all
58 // to a stack limit of 0 when all nested invocations are done and 56 // to a stack limit of 0 when all nested invocations are done and
59 // we have bottomed out. 57 // we have bottomed out.
60 thread_->SetStackLimit(saved_stack_limit_); 58 thread_->SetStackLimit(saved_stack_limit_);
61 } 59 }
62 60
63 private: 61 private:
64 Thread* thread_; 62 Thread* thread_;
65 uword saved_stack_limit_; 63 uword saved_stack_limit_;
66 }; 64 };
67 65
68
69 // Clears/restores Thread::long_jump_base on construction/destruction. 66 // Clears/restores Thread::long_jump_base on construction/destruction.
70 // Ensures that we do not attempt to long jump across Dart frames. 67 // Ensures that we do not attempt to long jump across Dart frames.
71 class SuspendLongJumpScope : public StackResource { 68 class SuspendLongJumpScope : public StackResource {
72 public: 69 public:
73 explicit SuspendLongJumpScope(Thread* thread) 70 explicit SuspendLongJumpScope(Thread* thread)
74 : StackResource(thread), saved_long_jump_base_(thread->long_jump_base()) { 71 : StackResource(thread), saved_long_jump_base_(thread->long_jump_base()) {
75 thread->set_long_jump_base(NULL); 72 thread->set_long_jump_base(NULL);
76 } 73 }
77 74
78 ~SuspendLongJumpScope() { 75 ~SuspendLongJumpScope() {
79 ASSERT(thread()->long_jump_base() == NULL); 76 ASSERT(thread()->long_jump_base() == NULL);
80 thread()->set_long_jump_base(saved_long_jump_base_); 77 thread()->set_long_jump_base(saved_long_jump_base_);
81 } 78 }
82 79
83 private: 80 private:
84 LongJumpScope* saved_long_jump_base_; 81 LongJumpScope* saved_long_jump_base_;
85 }; 82 };
86 83
87
88 RawObject* DartEntry::InvokeFunction(const Function& function, 84 RawObject* DartEntry::InvokeFunction(const Function& function,
89 const Array& arguments, 85 const Array& arguments,
90 const Array& arguments_descriptor, 86 const Array& arguments_descriptor,
91 uword current_sp) { 87 uword current_sp) {
92 // Get the entrypoint corresponding to the function specified, this 88 // Get the entrypoint corresponding to the function specified, this
93 // will result in a compilation of the function if it is not already 89 // will result in a compilation of the function if it is not already
94 // compiled. 90 // compiled.
95 Thread* thread = Thread::Current(); 91 Thread* thread = Thread::Current();
96 Zone* zone = thread->zone(); 92 Zone* zone = thread->zone();
97 ASSERT(thread->IsMutatorThread()); 93 ASSERT(thread->IsMutatorThread());
(...skipping 27 matching lines...) Expand all
125 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call( 121 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call(
126 reinterpret_cast<intptr_t>(entrypoint), reinterpret_cast<intptr_t>(&code), 122 reinterpret_cast<intptr_t>(entrypoint), reinterpret_cast<intptr_t>(&code),
127 reinterpret_cast<intptr_t>(&arguments_descriptor), 123 reinterpret_cast<intptr_t>(&arguments_descriptor),
128 reinterpret_cast<intptr_t>(&arguments), 124 reinterpret_cast<intptr_t>(&arguments),
129 reinterpret_cast<intptr_t>(thread))); 125 reinterpret_cast<intptr_t>(thread)));
130 #else 126 #else
131 return entrypoint(code, arguments_descriptor, arguments, thread); 127 return entrypoint(code, arguments_descriptor, arguments, thread);
132 #endif 128 #endif
133 } 129 }
134 130
135
136 RawObject* DartEntry::InvokeClosure(const Array& arguments) { 131 RawObject* DartEntry::InvokeClosure(const Array& arguments) {
137 const int kTypeArgsLen = 0; // No support to pass type args to generic func. 132 const int kTypeArgsLen = 0; // No support to pass type args to generic func.
138 const Array& arguments_descriptor = 133 const Array& arguments_descriptor =
139 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length())); 134 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length()));
140 return InvokeClosure(arguments, arguments_descriptor); 135 return InvokeClosure(arguments, arguments_descriptor);
141 } 136 }
142 137
143
144 RawObject* DartEntry::InvokeClosure(const Array& arguments, 138 RawObject* DartEntry::InvokeClosure(const Array& arguments,
145 const Array& arguments_descriptor) { 139 const Array& arguments_descriptor) {
146 Thread* thread = Thread::Current(); 140 Thread* thread = Thread::Current();
147 Zone* zone = thread->zone(); 141 Zone* zone = thread->zone();
148 const ArgumentsDescriptor args_desc(arguments_descriptor); 142 const ArgumentsDescriptor args_desc(arguments_descriptor);
149 const intptr_t instance_index = args_desc.TypeArgsLen() == 0 ? 0 : 1; 143 const intptr_t instance_index = args_desc.TypeArgsLen() == 0 ? 0 : 1;
150 Instance& instance = Instance::Handle(zone); 144 Instance& instance = Instance::Handle(zone);
151 instance ^= arguments.At(instance_index); 145 instance ^= arguments.At(instance_index);
152 // Get the entrypoint corresponding to the closure function or to the call 146 // Get the entrypoint corresponding to the closure function or to the call
153 // method of the instance. This will result in a compilation of the function 147 // method of the instance. This will result in a compilation of the function
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 202 }
209 cls = cls.SuperClass(); 203 cls = cls.SuperClass();
210 } 204 }
211 } 205 }
212 206
213 // No compatible method or getter so invoke noSuchMethod. 207 // No compatible method or getter so invoke noSuchMethod.
214 return InvokeNoSuchMethod(instance, Symbols::Call(), arguments, 208 return InvokeNoSuchMethod(instance, Symbols::Call(), arguments,
215 arguments_descriptor); 209 arguments_descriptor);
216 } 210 }
217 211
218
219 RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver, 212 RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver,
220 const String& target_name, 213 const String& target_name,
221 const Array& arguments, 214 const Array& arguments,
222 const Array& arguments_descriptor) { 215 const Array& arguments_descriptor) {
223 ASSERT(receiver.raw() == arguments.At(0)); 216 ASSERT(receiver.raw() == arguments.At(0));
224 // Allocate an Invocation object. 217 // Allocate an Invocation object.
225 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 218 const Library& core_lib = Library::Handle(Library::CoreLibrary());
226 219
227 Class& invocation_mirror_class = Class::Handle(core_lib.LookupClass( 220 Class& invocation_mirror_class = Class::Handle(core_lib.LookupClass(
228 String::Handle(core_lib.PrivateName(Symbols::InvocationMirror())))); 221 String::Handle(core_lib.PrivateName(Symbols::InvocationMirror()))));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 thread->isolate()->object_store()->object_class()), 254 thread->isolate()->object_store()->object_class()),
262 Symbols::NoSuchMethod(), args_desc); 255 Symbols::NoSuchMethod(), args_desc);
263 } 256 }
264 ASSERT(!function.IsNull()); 257 ASSERT(!function.IsNull());
265 const Array& args = Array::Handle(Array::New(kNumArguments)); 258 const Array& args = Array::Handle(Array::New(kNumArguments));
266 args.SetAt(0, receiver); 259 args.SetAt(0, receiver);
267 args.SetAt(1, invocation_mirror); 260 args.SetAt(1, invocation_mirror);
268 return InvokeFunction(function, args); 261 return InvokeFunction(function, args);
269 } 262 }
270 263
271
272 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) : array_(array) {} 264 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) : array_(array) {}
273 265
274 intptr_t ArgumentsDescriptor::TypeArgsLen() const { 266 intptr_t ArgumentsDescriptor::TypeArgsLen() const {
275 return Smi::Cast(Object::Handle(array_.At(kTypeArgsLenIndex))).Value(); 267 return Smi::Cast(Object::Handle(array_.At(kTypeArgsLenIndex))).Value();
276 } 268 }
277 269
278
279 intptr_t ArgumentsDescriptor::Count() const { 270 intptr_t ArgumentsDescriptor::Count() const {
280 return Smi::Cast(Object::Handle(array_.At(kCountIndex))).Value(); 271 return Smi::Cast(Object::Handle(array_.At(kCountIndex))).Value();
281 } 272 }
282 273
283
284 intptr_t ArgumentsDescriptor::PositionalCount() const { 274 intptr_t ArgumentsDescriptor::PositionalCount() const {
285 return Smi::Cast(Object::Handle(array_.At(kPositionalCountIndex))).Value(); 275 return Smi::Cast(Object::Handle(array_.At(kPositionalCountIndex))).Value();
286 } 276 }
287 277
288
289 RawString* ArgumentsDescriptor::NameAt(intptr_t index) const { 278 RawString* ArgumentsDescriptor::NameAt(intptr_t index) const {
290 const intptr_t offset = 279 const intptr_t offset =
291 kFirstNamedEntryIndex + (index * kNamedEntrySize) + kNameOffset; 280 kFirstNamedEntryIndex + (index * kNamedEntrySize) + kNameOffset;
292 String& result = String::Handle(); 281 String& result = String::Handle();
293 result ^= array_.At(offset); 282 result ^= array_.At(offset);
294 return result.raw(); 283 return result.raw();
295 } 284 }
296 285
297
298 intptr_t ArgumentsDescriptor::PositionAt(intptr_t index) const { 286 intptr_t ArgumentsDescriptor::PositionAt(intptr_t index) const {
299 const intptr_t offset = 287 const intptr_t offset =
300 kFirstNamedEntryIndex + (index * kNamedEntrySize) + kPositionOffset; 288 kFirstNamedEntryIndex + (index * kNamedEntrySize) + kPositionOffset;
301 return Smi::Value(Smi::RawCast(array_.At(offset))); 289 return Smi::Value(Smi::RawCast(array_.At(offset)));
302 } 290 }
303 291
304
305 bool ArgumentsDescriptor::MatchesNameAt(intptr_t index, 292 bool ArgumentsDescriptor::MatchesNameAt(intptr_t index,
306 const String& other) const { 293 const String& other) const {
307 return NameAt(index) == other.raw(); 294 return NameAt(index) == other.raw();
308 } 295 }
309 296
310
311 intptr_t ArgumentsDescriptor::type_args_len_offset() { 297 intptr_t ArgumentsDescriptor::type_args_len_offset() {
312 return Array::element_offset(kTypeArgsLenIndex); 298 return Array::element_offset(kTypeArgsLenIndex);
313 } 299 }
314 300
315
316 intptr_t ArgumentsDescriptor::count_offset() { 301 intptr_t ArgumentsDescriptor::count_offset() {
317 return Array::element_offset(kCountIndex); 302 return Array::element_offset(kCountIndex);
318 } 303 }
319 304
320
321 intptr_t ArgumentsDescriptor::positional_count_offset() { 305 intptr_t ArgumentsDescriptor::positional_count_offset() {
322 return Array::element_offset(kPositionalCountIndex); 306 return Array::element_offset(kPositionalCountIndex);
323 } 307 }
324 308
325
326 intptr_t ArgumentsDescriptor::first_named_entry_offset() { 309 intptr_t ArgumentsDescriptor::first_named_entry_offset() {
327 return Array::element_offset(kFirstNamedEntryIndex); 310 return Array::element_offset(kFirstNamedEntryIndex);
328 } 311 }
329 312
330
331 RawArray* ArgumentsDescriptor::New(intptr_t type_args_len, 313 RawArray* ArgumentsDescriptor::New(intptr_t type_args_len,
332 intptr_t num_arguments, 314 intptr_t num_arguments,
333 const Array& optional_arguments_names) { 315 const Array& optional_arguments_names) {
334 const intptr_t num_named_args = 316 const intptr_t num_named_args =
335 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); 317 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length();
336 if (num_named_args == 0) { 318 if (num_named_args == 0) {
337 return ArgumentsDescriptor::New(type_args_len, num_arguments); 319 return ArgumentsDescriptor::New(type_args_len, num_arguments);
338 } 320 }
339 ASSERT(type_args_len >= 0); 321 ASSERT(type_args_len >= 0);
340 ASSERT(num_arguments >= 0); 322 ASSERT(num_arguments >= 0);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // Set terminating null. 367 // Set terminating null.
386 descriptor.SetAt(descriptor_len - 1, Object::null_object()); 368 descriptor.SetAt(descriptor_len - 1, Object::null_object());
387 369
388 // Share the immutable descriptor when possible by canonicalizing it. 370 // Share the immutable descriptor when possible by canonicalizing it.
389 descriptor.MakeImmutable(); 371 descriptor.MakeImmutable();
390 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); 372 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL);
391 ASSERT(!descriptor.IsNull()); 373 ASSERT(!descriptor.IsNull());
392 return descriptor.raw(); 374 return descriptor.raw();
393 } 375 }
394 376
395
396 RawArray* ArgumentsDescriptor::New(intptr_t type_args_len, 377 RawArray* ArgumentsDescriptor::New(intptr_t type_args_len,
397 intptr_t num_arguments) { 378 intptr_t num_arguments) {
398 ASSERT(type_args_len >= 0); 379 ASSERT(type_args_len >= 0);
399 ASSERT(num_arguments >= 0); 380 ASSERT(num_arguments >= 0);
400 if ((type_args_len == 0) && (num_arguments < kCachedDescriptorCount)) { 381 if ((type_args_len == 0) && (num_arguments < kCachedDescriptorCount)) {
401 return cached_args_descriptors_[num_arguments]; 382 return cached_args_descriptors_[num_arguments];
402 } 383 }
403 return NewNonCached(type_args_len, num_arguments); 384 return NewNonCached(type_args_len, num_arguments);
404 } 385 }
405 386
406
407 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t type_args_len, 387 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t type_args_len,
408 intptr_t num_arguments, 388 intptr_t num_arguments,
409 bool canonicalize) { 389 bool canonicalize) {
410 // Build the arguments descriptor array, which consists of the length of the 390 // Build the arguments descriptor array, which consists of the length of the
411 // type argument vector, total argument count; the positional argument count; 391 // type argument vector, total argument count; the positional argument count;
412 // and a terminating null to simplify iterating in generated code. 392 // and a terminating null to simplify iterating in generated code.
413 Thread* thread = Thread::Current(); 393 Thread* thread = Thread::Current();
414 Zone* zone = thread->zone(); 394 Zone* zone = thread->zone();
415 const intptr_t descriptor_len = LengthFor(0); 395 const intptr_t descriptor_len = LengthFor(0);
416 Array& descriptor = 396 Array& descriptor =
(...skipping 15 matching lines...) Expand all
432 412
433 // Share the immutable descriptor when possible by canonicalizing it. 413 // Share the immutable descriptor when possible by canonicalizing it.
434 descriptor.MakeImmutable(); 414 descriptor.MakeImmutable();
435 if (canonicalize) { 415 if (canonicalize) {
436 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); 416 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL);
437 } 417 }
438 ASSERT(!descriptor.IsNull()); 418 ASSERT(!descriptor.IsNull());
439 return descriptor.raw(); 419 return descriptor.raw();
440 } 420 }
441 421
442
443 void ArgumentsDescriptor::InitOnce() { 422 void ArgumentsDescriptor::InitOnce() {
444 for (int i = 0; i < kCachedDescriptorCount; i++) { 423 for (int i = 0; i < kCachedDescriptorCount; i++) {
445 cached_args_descriptors_[i] = 424 cached_args_descriptors_[i] =
446 ArgumentsDescriptor::NewNonCached(/*type_args_len=*/0, i, false); 425 ArgumentsDescriptor::NewNonCached(/*type_args_len=*/0, i, false);
447 } 426 }
448 } 427 }
449 428
450
451 RawObject* DartLibraryCalls::InstanceCreate(const Library& lib, 429 RawObject* DartLibraryCalls::InstanceCreate(const Library& lib,
452 const String& class_name, 430 const String& class_name,
453 const String& constructor_name, 431 const String& constructor_name,
454 const Array& arguments) { 432 const Array& arguments) {
455 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name)); 433 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name));
456 ASSERT(!cls.IsNull()); 434 ASSERT(!cls.IsNull());
457 // For now, we only support a non-parameterized or raw type. 435 // For now, we only support a non-parameterized or raw type.
458 const int kNumExtraArgs = 1; // implicit rcvr arg. 436 const int kNumExtraArgs = 1; // implicit rcvr arg.
459 const Instance& exception_object = Instance::Handle(Instance::New(cls)); 437 const Instance& exception_object = Instance::Handle(Instance::New(cls));
460 const Array& constructor_arguments = 438 const Array& constructor_arguments =
(...skipping 12 matching lines...) Expand all
473 ASSERT(!constructor.IsNull()); 451 ASSERT(!constructor.IsNull());
474 const Object& retval = Object::Handle( 452 const Object& retval = Object::Handle(
475 DartEntry::InvokeFunction(constructor, constructor_arguments)); 453 DartEntry::InvokeFunction(constructor, constructor_arguments));
476 ASSERT(retval.IsNull() || retval.IsError()); 454 ASSERT(retval.IsNull() || retval.IsError());
477 if (retval.IsError()) { 455 if (retval.IsError()) {
478 return retval.raw(); 456 return retval.raw();
479 } 457 }
480 return exception_object.raw(); 458 return exception_object.raw();
481 } 459 }
482 460
483
484 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { 461 RawObject* DartLibraryCalls::ToString(const Instance& receiver) {
485 const int kTypeArgsLen = 0; 462 const int kTypeArgsLen = 0;
486 const int kNumArguments = 1; // Receiver. 463 const int kNumArguments = 1; // Receiver.
487 ArgumentsDescriptor args_desc( 464 ArgumentsDescriptor args_desc(
488 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); 465 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments)));
489 const Function& function = Function::Handle( 466 const Function& function = Function::Handle(
490 Resolver::ResolveDynamic(receiver, Symbols::toString(), args_desc)); 467 Resolver::ResolveDynamic(receiver, Symbols::toString(), args_desc));
491 ASSERT(!function.IsNull()); 468 ASSERT(!function.IsNull());
492 const Array& args = Array::Handle(Array::New(kNumArguments)); 469 const Array& args = Array::Handle(Array::New(kNumArguments));
493 args.SetAt(0, receiver); 470 args.SetAt(0, receiver);
494 const Object& result = 471 const Object& result =
495 Object::Handle(DartEntry::InvokeFunction(function, args)); 472 Object::Handle(DartEntry::InvokeFunction(function, args));
496 ASSERT(result.IsInstance() || result.IsError()); 473 ASSERT(result.IsInstance() || result.IsError());
497 return result.raw(); 474 return result.raw();
498 } 475 }
499 476
500
501 RawObject* DartLibraryCalls::HashCode(const Instance& receiver) { 477 RawObject* DartLibraryCalls::HashCode(const Instance& receiver) {
502 const int kTypeArgsLen = 0; 478 const int kTypeArgsLen = 0;
503 const int kNumArguments = 1; // Receiver. 479 const int kNumArguments = 1; // Receiver.
504 ArgumentsDescriptor args_desc( 480 ArgumentsDescriptor args_desc(
505 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); 481 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments)));
506 const Function& function = Function::Handle( 482 const Function& function = Function::Handle(
507 Resolver::ResolveDynamic(receiver, Symbols::hashCode(), args_desc)); 483 Resolver::ResolveDynamic(receiver, Symbols::hashCode(), args_desc));
508 ASSERT(!function.IsNull()); 484 ASSERT(!function.IsNull());
509 const Array& args = Array::Handle(Array::New(kNumArguments)); 485 const Array& args = Array::Handle(Array::New(kNumArguments));
510 args.SetAt(0, receiver); 486 args.SetAt(0, receiver);
511 const Object& result = 487 const Object& result =
512 Object::Handle(DartEntry::InvokeFunction(function, args)); 488 Object::Handle(DartEntry::InvokeFunction(function, args));
513 ASSERT(result.IsInstance() || result.IsError()); 489 ASSERT(result.IsInstance() || result.IsError());
514 return result.raw(); 490 return result.raw();
515 } 491 }
516 492
517
518 RawObject* DartLibraryCalls::Equals(const Instance& left, 493 RawObject* DartLibraryCalls::Equals(const Instance& left,
519 const Instance& right) { 494 const Instance& right) {
520 const int kTypeArgsLen = 0; 495 const int kTypeArgsLen = 0;
521 const int kNumArguments = 2; 496 const int kNumArguments = 2;
522 ArgumentsDescriptor args_desc( 497 ArgumentsDescriptor args_desc(
523 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); 498 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments)));
524 const Function& function = Function::Handle( 499 const Function& function = Function::Handle(
525 Resolver::ResolveDynamic(left, Symbols::EqualOperator(), args_desc)); 500 Resolver::ResolveDynamic(left, Symbols::EqualOperator(), args_desc));
526 ASSERT(!function.IsNull()); 501 ASSERT(!function.IsNull());
527 502
528 const Array& args = Array::Handle(Array::New(kNumArguments)); 503 const Array& args = Array::Handle(Array::New(kNumArguments));
529 args.SetAt(0, left); 504 args.SetAt(0, left);
530 args.SetAt(1, right); 505 args.SetAt(1, right);
531 const Object& result = 506 const Object& result =
532 Object::Handle(DartEntry::InvokeFunction(function, args)); 507 Object::Handle(DartEntry::InvokeFunction(function, args));
533 ASSERT(result.IsInstance() || result.IsError()); 508 ASSERT(result.IsInstance() || result.IsError());
534 return result.raw(); 509 return result.raw();
535 } 510 }
536 511
537
538 RawObject* DartLibraryCalls::LookupHandler(Dart_Port port_id) { 512 RawObject* DartLibraryCalls::LookupHandler(Dart_Port port_id) {
539 Thread* thread = Thread::Current(); 513 Thread* thread = Thread::Current();
540 Zone* zone = thread->zone(); 514 Zone* zone = thread->zone();
541 Function& function = Function::Handle( 515 Function& function = Function::Handle(
542 zone, thread->isolate()->object_store()->lookup_port_handler()); 516 zone, thread->isolate()->object_store()->lookup_port_handler());
543 const int kTypeArgsLen = 0; 517 const int kTypeArgsLen = 0;
544 const int kNumArguments = 1; 518 const int kNumArguments = 1;
545 if (function.IsNull()) { 519 if (function.IsNull()) {
546 Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary()); 520 Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary());
547 ASSERT(!isolate_lib.IsNull()); 521 ASSERT(!isolate_lib.IsNull());
548 const String& class_name = String::Handle( 522 const String& class_name = String::Handle(
549 zone, isolate_lib.PrivateName(Symbols::_RawReceivePortImpl())); 523 zone, isolate_lib.PrivateName(Symbols::_RawReceivePortImpl()));
550 const String& function_name = String::Handle( 524 const String& function_name = String::Handle(
551 zone, isolate_lib.PrivateName(Symbols::_lookupHandler())); 525 zone, isolate_lib.PrivateName(Symbols::_lookupHandler()));
552 function = Resolver::ResolveStatic(isolate_lib, class_name, function_name, 526 function = Resolver::ResolveStatic(isolate_lib, class_name, function_name,
553 kTypeArgsLen, kNumArguments, 527 kTypeArgsLen, kNumArguments,
554 Object::empty_array()); 528 Object::empty_array());
555 ASSERT(!function.IsNull()); 529 ASSERT(!function.IsNull());
556 thread->isolate()->object_store()->set_lookup_port_handler(function); 530 thread->isolate()->object_store()->set_lookup_port_handler(function);
557 } 531 }
558 const Array& args = Array::Handle(zone, Array::New(kNumArguments)); 532 const Array& args = Array::Handle(zone, Array::New(kNumArguments));
559 args.SetAt(0, Integer::Handle(zone, Integer::New(port_id))); 533 args.SetAt(0, Integer::Handle(zone, Integer::New(port_id)));
560 const Object& result = 534 const Object& result =
561 Object::Handle(zone, DartEntry::InvokeFunction(function, args)); 535 Object::Handle(zone, DartEntry::InvokeFunction(function, args));
562 return result.raw(); 536 return result.raw();
563 } 537 }
564 538
565
566 RawObject* DartLibraryCalls::HandleMessage(const Object& handler, 539 RawObject* DartLibraryCalls::HandleMessage(const Object& handler,
567 const Instance& message) { 540 const Instance& message) {
568 Thread* thread = Thread::Current(); 541 Thread* thread = Thread::Current();
569 Zone* zone = thread->zone(); 542 Zone* zone = thread->zone();
570 Isolate* isolate = thread->isolate(); 543 Isolate* isolate = thread->isolate();
571 Function& function = Function::Handle( 544 Function& function = Function::Handle(
572 zone, isolate->object_store()->handle_message_function()); 545 zone, isolate->object_store()->handle_message_function());
573 const int kTypeArgsLen = 0; 546 const int kTypeArgsLen = 0;
574 const int kNumArguments = 2; 547 const int kNumArguments = 2;
575 if (function.IsNull()) { 548 if (function.IsNull()) {
(...skipping 17 matching lines...) Expand all
593 // through code, enable single stepping so debugger will stop 566 // through code, enable single stepping so debugger will stop
594 // at the first location the user is interested in. 567 // at the first location the user is interested in.
595 isolate->debugger()->SetResumeAction(Debugger::kStepInto); 568 isolate->debugger()->SetResumeAction(Debugger::kStepInto);
596 } 569 }
597 const Object& result = 570 const Object& result =
598 Object::Handle(zone, DartEntry::InvokeFunction(function, args)); 571 Object::Handle(zone, DartEntry::InvokeFunction(function, args));
599 ASSERT(result.IsNull() || result.IsError()); 572 ASSERT(result.IsNull() || result.IsError());
600 return result.raw(); 573 return result.raw();
601 } 574 }
602 575
603
604 RawObject* DartLibraryCalls::DrainMicrotaskQueue() { 576 RawObject* DartLibraryCalls::DrainMicrotaskQueue() {
605 Zone* zone = Thread::Current()->zone(); 577 Zone* zone = Thread::Current()->zone();
606 Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary()); 578 Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary());
607 ASSERT(!isolate_lib.IsNull()); 579 ASSERT(!isolate_lib.IsNull());
608 Function& function = 580 Function& function =
609 Function::Handle(zone, isolate_lib.LookupFunctionAllowPrivate( 581 Function::Handle(zone, isolate_lib.LookupFunctionAllowPrivate(
610 Symbols::_runPendingImmediateCallback())); 582 Symbols::_runPendingImmediateCallback()));
611 const Object& result = Object::Handle( 583 const Object& result = Object::Handle(
612 zone, DartEntry::InvokeFunction(function, Object::empty_array())); 584 zone, DartEntry::InvokeFunction(function, Object::empty_array()));
613 ASSERT(result.IsNull() || result.IsError()); 585 ASSERT(result.IsNull() || result.IsError());
614 return result.raw(); 586 return result.raw();
615 } 587 }
616 588
617
618 RawObject* DartLibraryCalls::MapSetAt(const Instance& map, 589 RawObject* DartLibraryCalls::MapSetAt(const Instance& map,
619 const Instance& key, 590 const Instance& key,
620 const Instance& value) { 591 const Instance& value) {
621 const int kTypeArgsLen = 0; 592 const int kTypeArgsLen = 0;
622 const int kNumArguments = 3; 593 const int kNumArguments = 3;
623 ArgumentsDescriptor args_desc( 594 ArgumentsDescriptor args_desc(
624 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); 595 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments)));
625 const Function& function = Function::Handle( 596 const Function& function = Function::Handle(
626 Resolver::ResolveDynamic(map, Symbols::AssignIndexToken(), args_desc)); 597 Resolver::ResolveDynamic(map, Symbols::AssignIndexToken(), args_desc));
627 ASSERT(!function.IsNull()); 598 ASSERT(!function.IsNull());
628 const Array& args = Array::Handle(Array::New(kNumArguments)); 599 const Array& args = Array::Handle(Array::New(kNumArguments));
629 args.SetAt(0, map); 600 args.SetAt(0, map);
630 args.SetAt(1, key); 601 args.SetAt(1, key);
631 args.SetAt(2, value); 602 args.SetAt(2, value);
632 const Object& result = 603 const Object& result =
633 Object::Handle(DartEntry::InvokeFunction(function, args)); 604 Object::Handle(DartEntry::InvokeFunction(function, args));
634 return result.raw(); 605 return result.raw();
635 } 606 }
636 607
637 } // namespace dart 608 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_entry.h ('k') | runtime/vm/dart_entry_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698