Commit Graph

50 Commits

Author SHA1 Message Date
Ben Konyi b729693cb9 [ VM ] Allow for Timer to set its ReceivePort as active / inactive to
prevent repeated port allocations

Flutter makes heavy use of short-lived Timers which currently causes
repeated opening/closing of the Timer port. This change allows for
RawReceivePorts to be set active / inactive, allowing for a port to be
kept open but not considered alive.

Flutter benchmark changes:

Before dart-lang/sdk@d5118d5: "notifyListener2_iteration": 545.0
After dart-lang/sdk@d5118d5: "notifyListener2_iteration": 1639.0
With fix: "notifyListener2_iteration": 629.0

Fixes https://github.com/flutter/flutter/issues/69583

TEST=Updated port state tests and verified change against Flutter's microbenchmarks

Change-Id: I50ff1a1b0f1f29bcdac958e41c66429e9586fba2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171628
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-11-11 23:42:12 +00:00
Ryan Macnak 6fe15f6df9 [vm] Represent tagged pointers as C++ value types instead of C++ pointer types.
This works around bugs in UndefinedBehaviorSanitizer and Clang.

Bug: b/28638298
Change-Id: I6be595f9664516019d28017d24559583a1ae3a21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144354
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-04-25 05:21:27 +00:00
Alexander Aprelev 17654b70d7 [vm/isolates] Introduce sendAndExit.
sendAndExit allows for fast data passing from worker isolate back to
parent.

```
                                              | linux x64  | spawnIsolate | sendAndExit |
                                              |us per iter | over sync    | over send   |
                                              +------------+--------------+-------------+
IsolateJson.Decode50KBx1(RunTime):               43,175.000   339.83%
IsolateJson.SendAndExit_Decode50KBx1(RunTime):   22,070.000   124.83%        -48.88%
IsolateJson.SyncDecode50KBx1(RunTime):            9,816.284

IsolateJson.Decode50KBx4(RunTime):               77,630.000   104.56%
IsolateJson.SendAndExit_Decode50KBx4(RunTime):   46,307.000   22.02%         -40.35%
IsolateJson.SyncDecode50KBx4(RunTime):           37,949.528

IsolateJson.Decode100KBx1(RunTime):              71,035.000   270.42%
IsolateJson.SendAndExit_Decode100KBx1(RunTime):  43,056.000   124.52%        -39.39%
IsolateJson.SyncDecode100KBx1(RunTime):          19,176.733

IsolateJson.Decode100KBx4(RunTime):             120,915.000   54.66%
IsolateJson.SendAndExit_Decode100KBx4(RunTime):  67,101.000  -14.17%         -44.51%
IsolateJson.SyncDecode100KBx4(RunTime):          78,179.731

IsolateJson.Decode250KBx1(RunTime):             173,574.000  202.52%
IsolateJson.SendAndExit_Decode250KBx1(RunTime): 103,334.000   80.10%         -40.47%
IsolateJson.SyncDecode250KBx1(RunTime):          57,375.314

IsolateJson.Decode250KBx4(RunTime):             292,118.000   20.30%
IsolateJson.SendAndExit_Decode250KBx4(RunTime): 168,444.000  -30.63%         -42.34%
IsolateJson.SyncDecode250KBx4(RunTime):         242,831.000

IsolateJson.Decode1MBx1(RunTime):               631,578.000  166.34%
IsolateJson.SendAndExit_Decode1MBx1(RunTime):   371,127.000   56.50%         -41.24%
IsolateJson.SyncDecode1MBx1(RunTime):           237,135.778

IsolateJson.Decode1MBx4(RunTime):             1,322,789.000   36.16%
IsolateJson.SendAndExit_Decode1MBx4(RunTime):   657,179.000  -32.35%         -50.32%
IsolateJson.SyncDecode1MBx4(RunTime):           971,473.333

```

Bug: https://github.com/dart-lang/sdk/issues/37835
Bug: https://github.com/dart-lang/sdk/issues/36097
Change-Id: I386641e1431ed9f2e34fac36f562607a666ee4a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142823
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-04-22 17:34:09 +00:00
Martin Kustermann b53ea77e6b [vm/gc] Take new space lock when donating TLABs after scavenge, avoid leaks with double Dart_Initialize
This is a follow-up to [0] and fixes TSAN.
This is a follow-up to [1] and fixes ASAN (restored old code with comment)

[0] https://dart-review.googlesource.com/c/sdk/+/143817
[1] https://dart-review.googlesource.com/c/sdk/+/144260

Change-Id: I30cf8409e742785a923b6e48ffb050fff1c808c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144295
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Martin Kustermann <kustermann@google.com>
2020-04-21 16:57:24 +00:00
Martin Kustermann 72320b6c9a [vm/concurrency] Avoid quadratic complexity when closing ports on isolate shutdown
When an isolate dies it has to close all it's open ports. Right now this
is done by walking all ports in the system.
  => O(#num-isolates x #num-ports) complexity

Instead we let each isolate remember it's own open ports: When the
isolate dies we iterate over those ports that particular isolate has
open and close them.
  => O(#num-isolates + #num-ports) complexity

On a many-isolate test of the form:

    foo(int n) {
      if (n == 1) return 1;
      return foo(n-1) + 1;
    }

for `foo(50k)` this reduces the runtime from 90 seconds to 30 seconds.

Issue https://github.com/dart-lang/sdk/issues/36097

Change-Id: I3ac68c5334a1d5e8cac47e89e15cbb50c26b65ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144261
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-04-21 14:05:53 +00:00
Martin Kustermann 4d3ae12d9f [vm/concurrency] Extract the hashset implementation out of PortMap into PortSet
This CL extracts the hashset implementation from PortMap into
it's own (template) class into port_set.h:PortSet.

This splits the functionality (a nice cleanup in itself) and will
make it re-usable (via template) for a follow-up CL which makes
each message handler aware of it's own open ports.

Issue https://github.com/dart-lang/sdk/issues/36097

Change-Id: I4a56c997414672a4efc9330077110ac5f54d03d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144260
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2020-04-21 12:43:12 +00:00
Ryan Macnak 467e82b668 [vm] Fix Dart_PostCObject to not run finalizers when a message fails to post.
Bug: https://github.com/dart-lang/sdk/issues/40627
Change-Id: I4a6d49008d8cf73b2bcaca512d52ddcbe7b41c05
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135796
Reviewed-by: Chinmay Garde <chinmaygarde@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-02-14 17:50:42 +00:00
Ryan Macnak 68d178f223 [vm] Remove FLAG_support_service and FLAG_support_reload, superseded by PRODUCT define.
When these were originally added, we thought we would be able to use them in place of ifdefs and rely on the compiler optimizations and linker GC to remove things. This turned out not to reliably remove what we wanted removed, so we ended up with the ifdefs anyway.

Change-Id: I62e74d60d92b18a688b9dffaf77b1440c10a07ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134402
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2020-02-04 23:31:17 +00:00
Ryan Macnak 523aa97ea1 [vm] Prevent reinterpreting object null as a send port capability.
Also ensure that allocated port ids and well-formed object pointers are disjoint.

Bug: https://github.com/dart-lang/sdk/issues/37234
Change-Id: I15328c1ba34f2995089f084e8889b110507c4dbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107223
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-06-26 00:17:04 +00:00
Matthew Dempsky a53c12d07a [vm] Use std::unique_ptr with Message
Message is a C++ type with a simple ownership model appropriate for
std::unique_ptr. This CL applies the following changes:

1. All uses of "new Message(...)" are replaced with
"Message::New(...)", which is effectively
"std::make_unique<Message>(...)". (The latter was only added in C++14,
but Dart still compiles in C++11 mode.)

2. All owning Message* are replaced with std::unique_ptr<Message>. The
notable exception is MessageQueue, which still uses raw Message*
internally to simplify the linked list handling.

3. All "delete message;" statements are removed.

4. Uses of "NULL" replaced with "nullptr" as necessary.

Change-Id: I05b5804289f2a225bfa05d3c1631129358fed373
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101222
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Matthew Dempsky <mdempsky@google.com>
2019-05-06 21:01:39 +00:00
Ryan Macnak ec27b09e68 [vm, service] Fix deferral of service extension invocation to not be mislead by other OOB messages.
This was the behavior intended in 7052bd6bed.

Bug: https://github.com/dart-lang/sdk/issues/24137
Bug: https://github.com/dart-lang/sdk/issues/36612
Change-Id: I2d0712d89ff45cd480580e73c4fd55ac4cf2ca59
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99360
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2019-04-17 17:34:46 +00:00
Ben Konyi 07852532e3 [ VM ] Additional cleanup in Dart_Initialize and Dart_Cleanup
Change-Id: I6dc02b3d9de16cc176eb97613bc0c7f0bb9b16eb
Reviewed-on: https://dart-review.googlesource.com/77013
Commit-Queue: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
2018-09-28 23:18:59 +00:00
Ben Konyi 3c4c62d79a Reland "[VM] Dart_Initialize no longer crashes after Dart_Cleanup"
This is a reland of 519ee905f9

Original change's description:
> [VM] Dart_Initialize no longer crashes after Dart_Cleanup
> 
> Change-Id: I3cfdab9553aad045f024b6f9aec0b40b08234007
> Reviewed-on: https://dart-review.googlesource.com/75786
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

Change-Id: Icdd901bf1ab0b675cc5f1497061a2b7b8a05d956
Reviewed-on: https://dart-review.googlesource.com/76561
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2018-09-26 17:54:45 +00:00
Ben Konyi b6284b41e3 Revert "[VM] Dart_Initialize no longer crashes after Dart_Cleanup"
This reverts commit 519ee905f9.

Reason for revert: Seeing multiple crashes on Windows

Original change's description:
> [VM] Dart_Initialize no longer crashes after Dart_Cleanup
> 
> Change-Id: I3cfdab9553aad045f024b6f9aec0b40b08234007
> Reviewed-on: https://dart-review.googlesource.com/75786
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

TBR=bkonyi@google.com,rmacnak@google.com,zra@google.com

Change-Id: I33ad79dbc3fcf44f93612ff63bd2d8431f6067c8
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/76342
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2018-09-25 02:17:37 +00:00
Ben Konyi 519ee905f9 [VM] Dart_Initialize no longer crashes after Dart_Cleanup
Change-Id: I3cfdab9553aad045f024b6f9aec0b40b08234007
Reviewed-on: https://dart-review.googlesource.com/75786
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2018-09-25 01:20:24 +00:00
Ryan Macnak 9b5a931b06 [vm] Replace most runtime/vm uses of OS::Print with OS::PrintErr.
Leave --print-snapshot-sizes on stdout because it is parsed by Flutter benchmarks.

Replace all runtime/bin uses of OS::Print with Log::Print.

Bug: https://github.com/dart-lang/sdk/issues/32134
Change-Id: I74aacfb410cdfa9270d06e7f6ab0534520c7c7ba
Reviewed-on: https://dart-review.googlesource.com/60021
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-06-13 19:51:40 +00:00
Zachary Anderson 6cd8a79078 VM: Re-format to use at most one newline between functions
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2974233002 .
2017-07-13 08:08:37 -07:00
Zachary Anderson a1bcf051d8 clang-format runtime/vm
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2481873005 .
2016-11-08 13:54:47 -08:00
Todd Turnidge f8ff7bd5c4 Delete NativeMessageHandler once a native port closes.
Closes #27002

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2217693002 .
2016-08-04 15:34:24 -07:00
Ryan Macnak 2d9087648d More ifndef PRODUCT.
R=asiva@google.com

Review URL: https://codereview.chromium.org/2153593002 .
2016-07-14 15:30:32 -07:00
John McCutchan 45e277a2cb Fix MacOS build
BUG=

Review URL: https://codereview.chromium.org/2035383004 .
2016-06-06 14:20:39 -07:00
John McCutchan 6fd8fd7987 Rework standalone to use a synchronous loader that does not invoke Dart code
- [x] The first caller of the tag handler blocks, recursive callers queue work and exit.
- [x] Use a NativeMessageHandler to receive I/O results from the service isolate.
- [x] Preserve load error message format.
- [x] Move packages map into service isolate.
- [x] Wire up Todd's native URI code.

R=turnidge@google.com

Review URL: https://codereview.chromium.org/1998963003 .
2016-06-06 14:15:01 -07:00
Ivan Posva 528baf2173 - Limit 32-bit platforms to 1.5GB of memory for old gen by default.
- Fixed documentation for Dart_NewWeakPersistentHandle.
- Add clarifying comment.

BUG=
R=fschneider@google.com

Review URL: https://codereview.chromium.org/1837803003 .
2016-03-28 17:37:52 -07:00
Siva Annamalai e83151cc77 - Add assertions in MutexLocker/MonitorLocker to ensure that the code enclosed
in these blocks will not have a safepoint operation
- changed boxed_field_list_monitor_ to boxed_field_list_mutex_ as we only
  need a mutex for guarding access to boxed_field_list_ as changed the
  lock to use SafepointMutexLocker as the list addition code could potentially
  allocate and result in GC (safepoint operation)
- Added a SafepointMonitorLocker as we have a function Isolate::VisitIsolates
  which could potentially have safepoints in the enclosed block.
- Make the lock around MegamorphicCacheTable::Lookup a SafepointMutexLocker
  as the look up code seems to be allocating memory while the lock is held.
- Changed the ThreadPool and MessageHandler code to account for the new
  MonitorLocker usage standard
- Fixed PortMap::PrintPortsForMessageHandler to use SafepointMutexLocker as
  the code it encloses calls into Dart
- Removed profiler_ field in class Profiler as it doesn't seem to be used.

R=johnmccutchan@google.com, srdjan@google.com

Review URL: https://codereview.chromium.org/1748953003 .
2016-03-01 12:33:50 -08:00
John McCutchan d295b9c311 Remove many features when building product mode
Move all JSON printing code from object.cc to object_service.cc.

Not compiled in:

- Service protocol
- Debugger
- Debugger API
- JSONStream
- ObjectIdRing
- Profiler service
- Object JSON printing

Size of dart_bootstrap before: 5670365 bytes
Size of dart_bootstrap after: 5287631 bytes

Reduction in size: 382734 bytes.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1660063002 .
2016-02-05 09:55:51 -08:00
John McCutchan 851ef4a4af Ports page for isolates
Per isolate list of open ports and their handler

R=rmacnak@google.com

Review URL: https://codereview.chromium.org//1189543003.
2015-06-18 10:24:28 -07:00
John McCutchan 51d8bae199 Revert "Hide Isolate pointer from embedder"
This reverts commit 014e694ba7.

Revert "Fix fall out from hide isolate pointer change"

This reverts commit 966aafbc81.

Revert "Fix build"

This reverts commit d7b03ba7b0.

BUG=

Review URL: https://codereview.chromium.org//1140263005
2015-05-19 11:41:42 -07:00
John McCutchan 014e694ba7 Hide Isolate pointer from embedder
BUG=
R=iposva@google.com

Review URL: https://codereview.chromium.org//1130753006
2015-05-18 14:06:10 -07:00
johnmccutchan@google.com 5c7d4bd9d3 Fix crash when posting a message to a send port with port id 0.
BUG=
R=zra@google.com

Review URL: https://codereview.chromium.org//1056223002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44906 260f80e4-7a28-3924-810f-c04153c831b5
2015-04-05 19:06:29 +00:00
koda@google.com c7e9e048ed Rename Thread -> OSThread.
It's a collection of static utility methods for primitive operations on OS threads.

Make room in the namespace for upcoming class that will represent all the complex state of a VM thread.

Review URL: https://codereview.chromium.org//796063006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42895 260f80e4-7a28-3924-810f-c04153c831b5
2015-01-15 02:30:07 +00:00
turnidge@google.com c48496b873 Refactor isolate startup code in preparation for making isolate spawning more truly non-blocking.
Instead of passing a startup message to the new isolate, pass all
necessary information in to _startIsolate directly.  The new isolate
sends its control port and capabilities back to the parent.

R=iposva@google.com

Review URL: https://codereview.chromium.org//456983002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39423 260f80e4-7a28-3924-810f-c04153c831b5
2014-08-20 19:57:09 +00:00
iposva@google.com 14ecdbd66a - Separate the thread implementation used in bin/ and vm/
to allow us to make VM specific changes.

R=asiva@google.com

Review URL: https://codereview.chromium.org//463993002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39172 260f80e4-7a28-3924-810f-c04153c831b5
2014-08-12 23:19:53 +00:00
iposva@google.com 651ded192e - Add possibility to redirect messages if they were not delivered.
- Prepare OOB handling for more than service messages.
- Do not use growable arrays when growing is not necessary.

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org//300223011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@36772 260f80e4-7a28-3924-810f-c04153c831b5
2014-05-28 21:58:33 +00:00
iposva@google.com e78cc1544d - Make ports be less predictable.
- Limit the range of port numbers to 30-bits.
- Parse the ports as 64-bit values when reading from the wire in the debugger protocol.

R=hausner@google.com

Review URL: https://codereview.chromium.org//217693002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34542 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-28 23:39:36 +00:00
kasperl@google.com 0d1c6ddec8 Revert "- Make ports be less predictable."
This reverts r34209 which is causing the x64 VM to hang when
running command-line applications from within the editor.

R=ricow@google.com, iposva@google.com
BUG=http://dartbug.com/17806

Review URL: https://codereview.chromium.org//212723002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34420 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-26 11:38:30 +00:00
iposva@google.com b98c628ee7 - Make ports be less predictable.
R=turnidge@google.com

Review URL: https://codereview.chromium.org//198463007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34209 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-20 21:48:35 +00:00
iposva@google.com 2ed438e40c Reland https://code.google.com/p/dart/source/detail?r=29315:
- Make sure to keep the main/control port opened until the
  isolate is finished.
- Account for the number of opened control ports to be able
  to determine whether there are live ports.
- Ensure that the spawned isolated is kept alive until the
  initial startup message can be handled.
- Add more isolate tracing output.
- Use the control port for the debugger id.

Review URL: https://codereview.chromium.org//47573002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29323 260f80e4-7a28-3924-810f-c04153c831b5
2013-10-27 14:34:23 +00:00
asiva@google.com 6076250adb 1. Create a port when a debugger object is created for an isolate, use this
port as the unique ID to represent an isolate in the debugger message
   format.

2. Switch the Event handler API to use an isolate id instead of the isolate
   object itself.

3. Add a unit test case for isolate debugger event handling with an
   interrupt of isolate to ensure that interrupting the isolate runs
   the interrupt event handler.
Review URL: https://codereview.chromium.org//11052006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@13207 260f80e4-7a28-3924-810f-c04153c831b5
2012-10-04 00:13:37 +00:00
turnidge@google.com ec36e02c28 Remove the partially completed code for remote IsolateMirrors and
replace it with the beginnings of a local (same isolate) IsolateMirror
implementation.

Removed old mirror tests and added two new mirror tests.

Even though mirrors.cc is part of the vm, I chose to implement most of
it using the dart embedding interface instead of our internal
interfaces because the embedding interface was more convenient.
mirrors.cc is basically all new in this CL -- don't pay any attention
to diffs for that file.

Added dart embedding functions required for the functionality in this
CL: Dart_DebugName, Dart_GetNativeInstanceFieldCount,
Dart_RootLibrary, Dart_RegisteredLibraryUrls, and Dart_LibraryName.

Extended or modified some existing dart api functions, primarily to
make them propagate error handles properly.

Added tests for new dart embedding api functionality.

Added the ability to determine if a port is local to the current isolate.

Extended NotImplementedException to accept an optional string
argument.  I wanted to give more descriptive error messages.
Review URL: https://chromiumcodereview.appspot.com//10416050

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@8117 260f80e4-7a28-3924-810f-c04153c831b5
2012-05-30 17:07:19 +00:00
turnidge@google.com 9d72035ce5 Use the ThreadPool for all isolates and native ports. Previously,
each isolate or native port had a dedicated thread.

Refactored the MessageHandler api...

- Added a Run function to allow a MessageHandler to run on a
  ThreadPool.  These functions take a start and end callback to allow for
  isolate initialization and shutdown.

- Made the queue private to the MessageHandler and moved all message
  processing code inside the MessageHandler (got rid of all of the
  different flavors of RunLoop).  This helps remove some code
  duplication and hides the details of how messages are handled.

- Moved all locking and notification out of MessageQueue and moved it
  up to MessageHandler.  Moved OOB support out of MessageQueue and up
  to MessageHandler.  These changes make the MessageQueue much
  simpler.

- Refactored native port and isolate MessageHandlers to share more code.

- Improved --trace_isolates output.

- Added tests for MessageHandler.

Refactored lib/isolate code...

- Use the new MessageHandler::Run api.

- Got rid of the LongJump stuff in RunIsolate.  No longer needed.

- Use the new StartIsolateScope/SwitchIsolateScope to make the code
  less verbose and less error-prone.

- Store top-level isolate errors in the sticky_error.

Added StartIsolateScope/SwitchIsolateScope classes.
Review URL: https://chromiumcodereview.appspot.com//9924015

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6762 260f80e4-7a28-3924-810f-c04153c831b5
2012-04-19 19:47:27 +00:00
iposva@google.com 5ac44be67f - Fix new/free mismatch.
Review URL: https://chromiumcodereview.appspot.com//9618034

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@5062 260f80e4-7a28-3924-810f-c04153c831b5
2012-03-07 00:28:36 +00:00
turnidge@google.com 1f5364cd3b Add support for native ports in the vm.
Dart_NewNativePort creates a port associated with a C handler
function.  When messages come in on this port, they are forwarded to
the C function for processing.

To support this, refactored PortMap so that it operates on a new
MessageHandler type instead of directly on Isolates.

For now, native ports have a dedicated single thread.  Eventually we
will back native ports (and possibly Isolates as well) by a shared
thread pool.
Review URL: https://chromiumcodereview.appspot.com//9169063

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3804 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-01 18:53:40 +00:00
turnidge@google.com 8920623dc5 OOB messages and general message refactor.
(1)
No longer give embedders direct access to inter-isolate messages.
Instead, keep these messages in an internal queue and rely on the
embedder only to provide notifications.  This simplifies the api in
numerous ways:

 - post message callback drops parameters and becomes message notify callback.
 - close port callback goes away
 - Dart_Message type goes away
 - Dart_HandleMessage gets a simpler signature

Updated the custom_isolate_test to show what use of the new apis looks like.

(2)
Begin to add support for out-of-band (OOB) messages.  These messages
supercede regular messages in the queue.  We will attempt to deliver
these messages even while code is running, by using the isolate
interrupt mechanism.  These messages are not user-visible.  They will
be used by the runtime internally to implement things like reflection.

Renamed PortMessage to Message.

Refactored message sending apis in PortMap and Isolate.

Modified MessageQueue to be aware of multiple priorities.

Modify Dart_HandleMessage to process multiple OOB messages
Review URL: https://chromiumcodereview.appspot.com//9182001

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3562 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-24 19:31:01 +00:00
turnidge@google.com e62f34ce77 Give isolates names to be used during debugging.
Implement --trace_isolates.

-------------

Sample output of --trace_isolates for the CrossIsolateMessageTest:

[+] Starting isolate:
    isolate:    CrossIsolateMessageTest.dart/main-7112
[+] Starting isolate:
    isolate:    CrossIsolateMessageTest.dart/CrossIsolate1.main-7114
[+] Starting isolate:
    isolate:    CrossIsolateMessageTest.dart/CrossIsolate2.main-7115
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/main-7112
    reply_port: 7117
    dest:       CrossIsolateMessageTest.dart/CrossIsolate2.main-7115
    dest_port:  7115
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/CrossIsolate2.main-7115
    reply_port: 7118
    dest:       CrossIsolateMessageTest.dart/main-7112
    dest_port:  7117
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/main-7112
    reply_port: 7119
    dest:       CrossIsolateMessageTest.dart/CrossIsolate1.main-7114
    dest_port:  7114
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/CrossIsolate1.main-7114
    reply_port: 7120
    dest:       CrossIsolateMessageTest.dart/main-7112
    dest_port:  7119
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/main-7112
    reply_port: 0
    dest:       CrossIsolateMessageTest.dart/CrossIsolate1.main-7114
    dest_port:  7120
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/CrossIsolate1.main-7114
    reply_port: 0
    dest:       CrossIsolateMessageTest.dart/CrossIsolate2.main-7115
    dest_port:  7118
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/CrossIsolate2.main-7115
    reply_port: 0
    dest:       CrossIsolateMessageTest.dart/main-7112
    dest_port:  7116
[>] Posting message:
    source:     CrossIsolateMessageTest.dart/main-7112
    reply_port: 0
    dest:       CrossIsolateMessageTest.dart/main-7112
    dest_port:  7113
[-] Stopping isolate:
    isolate:    CrossIsolateMessageTest.dart/CrossIsolate2.main-7115
[-] Stopping isolate:
    isolate:    CrossIsolateMessageTest.dart/CrossIsolate1.main-7114
[-] Stopping isolate:
    isolate:    CrossIsolateMessageTest.dart/main-7112
Review URL: https://chromiumcodereview.appspot.com//9242035

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3416 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-18 21:46:27 +00:00
sgjesse@google.com 65896148c9 Move utils.h and utils.cc from runtime/vm to runtime/platform
Moved additional parts of globals.h from vm/ to platform/ to support
types and constants used by utils.*.

R=ager@google.com, iposva@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//9209001

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3337 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-16 13:23:40 +00:00
turnidge@google.com 7c2a96158e Stop using void* types in the dart embedding api.
Review URL: http://codereview.chromium.org//8761007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1988 260f80e4-7a28-3924-810f-c04153c831b5
2011-12-01 18:18:06 +00:00
turnidge@google.com cf23dbad75 Add a mid-sized integration test for the Dart Embedding Api which
demonstrates how to create a custom isolate abstraction.  In this
test, we use an event queue to share a single thread among our custom
isolates.

Add a callback which allows embedders to see when a port is created.
Not sure if I should keep this or not.

New apis:
  Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping.
  Dart_IsolateHasActivePorts() -- does the current isolate have open ports?
  (this name a bit awkward...)

Bail out of PortMap::ClosePorts() early if there are no open ports.
This suppresses calls to the close_port_callback when there are no
open ports.

Use DART_CHECK_VALID to provide better error output when the test lib
has errors.

-------------------------
Sample output of the test:

-- (isolate=0x815600) Constructing isolate
-- Enter: CustomIsolateImpl_start --
-- Adding port (7111) -> isolate (0x830800) --
-- Adding StartEvent to queue --
-- Exit: CustomIsolateImpl_start --
-- Adding port (7112) -> isolate (0x815600) --
-- Posting message dest(7111) reply(0) --
-- Adding MessageEvent to queue --
-- Starting event loop --
>> StartEvent with isolate(0x830800)--
-- (isolate=0x830800) Running isolateMain
$$ MessageEvent with dest port 7111--
-- (isolate=0x830800) Received: 42
-- Posting message dest(7112) reply(0) --
-- Adding MessageEvent to queue --
$$ MessageEvent with dest port 7112--
-- Closing port (7112) --
-- Adding ShutdownEvent to queue --
-- (isolate=0x815600) Received: 43
<< ShutdownEvent with isolate(0x815600)--
-- Finished event loop --
Review URL: http://codereview.chromium.org//8588040

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
iposva@google.com 0c9902ca67 - Avoid allocating variable length arrays on the stack.
- Fix C++ warning about copying vtables.
- Use correct delete for PortMap entries.
Review URL: http://codereview.chromium.org//8555024

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1538 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-15 17:47:21 +00:00
turnidge@google.com 0e98d4ae64 Allow embedders to provide custom message delivery for an isolate.
==============

Added Dart_SetPostMessageCallback and Dart_SetClosePortCallback.
These allow the embedder to provide custom message/port behavior
for their application. The vm provides standard implementations
that work with the standard run loop.

Added Dart_HandleMessage, which processes one message on the
current isolate. Embedders can use this to write their own
message processing loops. Rewrote code to use this internally.

Added Isolate::StandardRunLoop() to share code between
Dart_RunLoop and lib/isolate.cc

Changed the interface to PortMap::PostMessage. PostMessage is
now agnostic to message delivery mechanism. Note that PortMap is
now out of the "ReceiveMessage" business entirely. Moved
MessageQueue and friends out to message_queue.cc/h.

Moved the monitor from the Isolate into the MessageQueue. No
need for outsiders to mess. Added MessageQueue::Wait. Moved
monitor locking from PortMap into MessageQueue itself, which was
easier for me to reason about. Wrote some tests.

Removed PortMessage::Handle. The code turned into Dart_HandleMessage.

Regularized the nomenclature around ports. Type is now always
Dart_Port instead of intptr_t. Variables end in _port instead of
_id. Use the term "dest" instead of "target" or "send".

Added a family of new tests to port_test.

Added EXPECT_NE to the test framework.
Review URL: http://codereview.chromium.org//8297004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@516 260f80e4-7a28-3924-810f-c04153c831b5
2011-10-18 17:54:07 +00:00
dgrove@google.com 4c0f559d23 Initial checkin.
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15 260f80e4-7a28-3924-810f-c04153c831b5
2011-10-05 05:20:07 +00:00