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>
It relies on flutter copy of clang distribution, same one that is used to build flutter/engine.
It addressed several deprecated warnings from clang compiler for functions like strdup, unlink, etc.
It allows few warnings still since they are triggered in third_party sources.
Change-Id: Ieb13792c011438d46dbbc0fa030e1b5e4ea14315
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142704
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
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>
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>
This change add the ability to restart the vm through the service
protocol. All isolates are killed, and then the main isolate is
restarted cooperatively by the embedder.
This change also fixes the message handler to prevent it from
accidentally ignoring vm shutdown messages.
Previously, we would stop handling messages whenever we hit an error
(such as a compile error or an unhandled exception). This would leave
shutdown requests sitting the oob queue, neglected.
We now process *all* oob requests, up to the first shutdown request.
When we hit a shutdown request, we clear the oob queue and process no
more messages.
To make all of this work, we had to change the return value of
HandleMessage from bool to a new enum type, allowing the message
handler to distinguish *normal* error cases from the more rarified
shutdown and restart cases.
R=johnmccutchan@google.com, zra@google.com
Review URL: https://codereview.chromium.org/1371193005 .
external length available. We now pass a length with all messages in
the vm and verify that there is no mismatch with the length from the
Snapshot.
Fixed a bug in the use of ApiMessageReader. We were always manually
adding Snapshot::kHeaderSize to the data, but neglecting to subtract
kHeaderSize from the message length.
Added FullSnapshotWriter and MessageWriter classes.
Review URL: https://chromiumcodereview.appspot.com//10829444
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11413 260f80e4-7a28-3924-810f-c04153c831b5
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
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
(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
The purpose of this change is twofold:
1. Source in the bin directory can now use the same assertions as
source in the vm directory. The ASSERT macro used by the code
in runtime/bin was just defined to use assert from the standard
C library.
2. Moving other implementation parts from runtime/vm to
runtime/platform (e.g. classes Monitor and Mutex) for sharing
between runtime/bin and runtime/vm will be easier as these
implementations rely on these assertion macros.
Created two gypi files for the platform directory. One for the
headers and one for the source. The source one is only included
when building the VM library and will be present in libdart.a
when the dart executable is linked.
All the code for asserts is still in the dart namespace.
Also re-arranged the order of includes to be alphabetically in
the files touched.
R=ager@google.com, iposva@google.com
BUG=
TEST=
Review URL: http://codereview.chromium.org//9189003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3335 260f80e4-7a28-3924-810f-c04153c831b5
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
==============
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