dart-sdk/runtime/vm/message.h

210 lines
5.9 KiB
C
Raw Normal View History

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
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_VM_MESSAGE_H_
#define RUNTIME_VM_MESSAGE_H_
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
#include <memory>
#include <utility>
#include "platform/assert.h"
#include "vm/allocation.h"
#include "vm/finalizable_data.h"
#include "vm/globals.h"
#include "vm/tagged_pointer.h"
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
// Duplicated from dart_api.h to avoid including the whole header.
typedef int64_t Dart_Port;
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
namespace dart {
class JSONStream;
[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
class PersistentHandle;
class Message {
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
public:
typedef enum {
kNormalPriority = 0, // Deliver message when idle.
kOOBPriority = 1, // Deliver message asap.
// Iteration.
kFirstPriority = 0,
kNumPriorities = 2,
} Priority;
// Values defining the type of OOB messages. OOB messages can only be
// fixed length arrays where the first element is a Smi with one of the
// valid values below.
typedef enum {
kIllegalOOB = 0,
kServiceOOBMsg = 1,
kIsolateLibOOBMsg = 2,
kDelayedIsolateLibOOBMsg = 3,
} OOBMsgTag;
// A port number which is never used.
static const Dart_Port kIllegalPort;
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
// A new message to be sent between two isolates. The data handed to this
// message will be disposed by calling free() once the message object is
// being destructed (after delivery or when the receiving port is closed).
Message(Dart_Port dest_port,
uint8_t* snapshot,
intptr_t snapshot_length,
MessageFinalizableData* finalizable_data,
Priority priority);
// Message objects can also carry RawObject pointers for Smis and objects in
// the VM heap. This is indicated by setting the len_ field to 0.
Message(Dart_Port dest_port, ObjectPtr raw_obj, Priority priority);
Reland "[vm] Implement `Finalizer`" Original CL in patchset 1. Split-off https://dart-review.googlesource.com/c/sdk/+/238341 And pulled in fix https://dart-review.googlesource.com/c/sdk/+/238582 (Should merge cleanly when this lands later.) This CL implements the `Finalizer` in the GC. The GC is specially aware of two types of objects for the purposes of running finalizers. 1) `FinalizerEntry` 2) `Finalizer` (`FinalizerBase`, `_FinalizerImpl`) A `FinalizerEntry` contains the `value`, the optional `detach` key, and the `token`, and a reference to the `finalizer`. An entry only holds on weakly to the value, detach key, and finalizer. (Similar to how `WeakReference` only holds on weakly to target). A `Finalizer` contains all entries, a list of entries of which the value is collected, and a reference to the isolate. When a the value of an entry is GCed, the enry is added over to the collected list. If any entry is moved to the collected list, a message is sent that invokes the finalizer to call the callback on all entries in that list. When a finalizer is detached by the user, the entry token is set to the entry itself and is removed from the all entries set. This ensures that if the entry was already moved to the collected list, the finalizer is not executed. To speed up detaching, we use a weak map from detach keys to list of entries. This ensures entries can be GCed. Both the scavenger and marker tasks process finalizer entries in parallel. Parallel tasks use an atomic exchange on the head of the collected entries list, ensuring no entries get lost. The mutator thread is guaranteed to be stopped when processing entries. This ensures that we do not need barriers for moving entries into the finalizers collected list. Dart reads and replaces the collected entries list also with an atomic exchange, ensuring the GC doesn't run in between a load/store. When a finalizer gets posted a message to process finalized objects, it is being kept alive by the message. An alternative design would be to pre-allocate a `WeakReference` in the finalizer pointing to the finalizer, and send that itself. This would be at the cost of an extra object. Send and exit is not supported in this CL, support will be added in a follow up CL. Trying to send will throw. Bug: https://github.com/dart-lang/sdk/issues/47777 TEST=runtime/tests/vm/dart/finalizer/* TEST=runtime/tests/vm/dart_2/isolates/fast_object_copy_test.dart TEST=runtime/vm/object_test.cc Change-Id: Ibdfeadc16d5d69ade50aae5b9f794284c4c4dbab Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-ffi-android-debug-arm64c-try,dart-sdk-mac-arm64-try,vm-kernel-mac-release-arm64-try,pkg-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-nnbd-win-release-ia32-try,vm-ffi-android-debug-arm-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,benchmark-linux-try,flutter-analyze-try,flutter-frontend-try,pkg-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238086 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-25 10:29:30 +00:00
// A message sent from SendPort.send or SendPort.sendAndExit where sender and
// receiver are in the same isolate group.
Message(Dart_Port dest_port, PersistentHandle* handle, Priority priority);
[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
Reland "[vm] Implement `Finalizer`" Original CL in patchset 1. Split-off https://dart-review.googlesource.com/c/sdk/+/238341 And pulled in fix https://dart-review.googlesource.com/c/sdk/+/238582 (Should merge cleanly when this lands later.) This CL implements the `Finalizer` in the GC. The GC is specially aware of two types of objects for the purposes of running finalizers. 1) `FinalizerEntry` 2) `Finalizer` (`FinalizerBase`, `_FinalizerImpl`) A `FinalizerEntry` contains the `value`, the optional `detach` key, and the `token`, and a reference to the `finalizer`. An entry only holds on weakly to the value, detach key, and finalizer. (Similar to how `WeakReference` only holds on weakly to target). A `Finalizer` contains all entries, a list of entries of which the value is collected, and a reference to the isolate. When a the value of an entry is GCed, the enry is added over to the collected list. If any entry is moved to the collected list, a message is sent that invokes the finalizer to call the callback on all entries in that list. When a finalizer is detached by the user, the entry token is set to the entry itself and is removed from the all entries set. This ensures that if the entry was already moved to the collected list, the finalizer is not executed. To speed up detaching, we use a weak map from detach keys to list of entries. This ensures entries can be GCed. Both the scavenger and marker tasks process finalizer entries in parallel. Parallel tasks use an atomic exchange on the head of the collected entries list, ensuring no entries get lost. The mutator thread is guaranteed to be stopped when processing entries. This ensures that we do not need barriers for moving entries into the finalizers collected list. Dart reads and replaces the collected entries list also with an atomic exchange, ensuring the GC doesn't run in between a load/store. When a finalizer gets posted a message to process finalized objects, it is being kept alive by the message. An alternative design would be to pre-allocate a `WeakReference` in the finalizer pointing to the finalizer, and send that itself. This would be at the cost of an extra object. Send and exit is not supported in this CL, support will be added in a follow up CL. Trying to send will throw. Bug: https://github.com/dart-lang/sdk/issues/47777 TEST=runtime/tests/vm/dart/finalizer/* TEST=runtime/tests/vm/dart_2/isolates/fast_object_copy_test.dart TEST=runtime/vm/object_test.cc Change-Id: Ibdfeadc16d5d69ade50aae5b9f794284c4c4dbab Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-ffi-android-debug-arm64c-try,dart-sdk-mac-arm64-try,vm-kernel-mac-release-arm64-try,pkg-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-nnbd-win-release-ia32-try,vm-ffi-android-debug-arm-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,benchmark-linux-try,flutter-analyze-try,flutter-frontend-try,pkg-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238086 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-25 10:29:30 +00:00
// A message sent from GC to run a finalizer.
Message(PersistentHandle* handle, Priority priority);
~Message();
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
template <typename... Args>
static std::unique_ptr<Message> New(Args&&... args) {
return std::unique_ptr<Message>(new Message(std::forward<Args>(args)...));
}
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
Dart_Port dest_port() const { return dest_port_; }
uint8_t* snapshot() const {
[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
ASSERT(IsSnapshot());
return payload_.snapshot_;
}
intptr_t snapshot_length() const { return snapshot_length_; }
MessageFinalizableData* finalizable_data() { return finalizable_data_; }
intptr_t Size() const {
intptr_t size = snapshot_length_;
if (finalizable_data_ != nullptr) {
size += finalizable_data_->external_size();
}
return size;
}
ObjectPtr raw_obj() const {
ASSERT(IsRaw());
[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
return payload_.raw_obj_;
}
PersistentHandle* persistent_handle() const {
Reland "[vm] Implement `Finalizer`" Original CL in patchset 1. Split-off https://dart-review.googlesource.com/c/sdk/+/238341 And pulled in fix https://dart-review.googlesource.com/c/sdk/+/238582 (Should merge cleanly when this lands later.) This CL implements the `Finalizer` in the GC. The GC is specially aware of two types of objects for the purposes of running finalizers. 1) `FinalizerEntry` 2) `Finalizer` (`FinalizerBase`, `_FinalizerImpl`) A `FinalizerEntry` contains the `value`, the optional `detach` key, and the `token`, and a reference to the `finalizer`. An entry only holds on weakly to the value, detach key, and finalizer. (Similar to how `WeakReference` only holds on weakly to target). A `Finalizer` contains all entries, a list of entries of which the value is collected, and a reference to the isolate. When a the value of an entry is GCed, the enry is added over to the collected list. If any entry is moved to the collected list, a message is sent that invokes the finalizer to call the callback on all entries in that list. When a finalizer is detached by the user, the entry token is set to the entry itself and is removed from the all entries set. This ensures that if the entry was already moved to the collected list, the finalizer is not executed. To speed up detaching, we use a weak map from detach keys to list of entries. This ensures entries can be GCed. Both the scavenger and marker tasks process finalizer entries in parallel. Parallel tasks use an atomic exchange on the head of the collected entries list, ensuring no entries get lost. The mutator thread is guaranteed to be stopped when processing entries. This ensures that we do not need barriers for moving entries into the finalizers collected list. Dart reads and replaces the collected entries list also with an atomic exchange, ensuring the GC doesn't run in between a load/store. When a finalizer gets posted a message to process finalized objects, it is being kept alive by the message. An alternative design would be to pre-allocate a `WeakReference` in the finalizer pointing to the finalizer, and send that itself. This would be at the cost of an extra object. Send and exit is not supported in this CL, support will be added in a follow up CL. Trying to send will throw. Bug: https://github.com/dart-lang/sdk/issues/47777 TEST=runtime/tests/vm/dart/finalizer/* TEST=runtime/tests/vm/dart_2/isolates/fast_object_copy_test.dart TEST=runtime/vm/object_test.cc Change-Id: Ibdfeadc16d5d69ade50aae5b9f794284c4c4dbab Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-ffi-android-debug-arm64c-try,dart-sdk-mac-arm64-try,vm-kernel-mac-release-arm64-try,pkg-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-nnbd-win-release-ia32-try,vm-ffi-android-debug-arm-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,benchmark-linux-try,flutter-analyze-try,flutter-frontend-try,pkg-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238086 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-25 10:29:30 +00:00
ASSERT(IsPersistentHandle() || IsFinalizerInvocationRequest());
return payload_.persistent_handle_;
}
Priority priority() const { return priority_; }
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
[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
// A message processed at any interrupt point (stack overflow check) instead
// of at the top of the message loop. Control messages from dart:isolate or
// vm-service requests.
bool IsOOB() const { return priority_ == Message::kOOBPriority; }
Reland "[vm] Implement `Finalizer`" Original CL in patchset 1. Split-off https://dart-review.googlesource.com/c/sdk/+/238341 And pulled in fix https://dart-review.googlesource.com/c/sdk/+/238582 (Should merge cleanly when this lands later.) This CL implements the `Finalizer` in the GC. The GC is specially aware of two types of objects for the purposes of running finalizers. 1) `FinalizerEntry` 2) `Finalizer` (`FinalizerBase`, `_FinalizerImpl`) A `FinalizerEntry` contains the `value`, the optional `detach` key, and the `token`, and a reference to the `finalizer`. An entry only holds on weakly to the value, detach key, and finalizer. (Similar to how `WeakReference` only holds on weakly to target). A `Finalizer` contains all entries, a list of entries of which the value is collected, and a reference to the isolate. When a the value of an entry is GCed, the enry is added over to the collected list. If any entry is moved to the collected list, a message is sent that invokes the finalizer to call the callback on all entries in that list. When a finalizer is detached by the user, the entry token is set to the entry itself and is removed from the all entries set. This ensures that if the entry was already moved to the collected list, the finalizer is not executed. To speed up detaching, we use a weak map from detach keys to list of entries. This ensures entries can be GCed. Both the scavenger and marker tasks process finalizer entries in parallel. Parallel tasks use an atomic exchange on the head of the collected entries list, ensuring no entries get lost. The mutator thread is guaranteed to be stopped when processing entries. This ensures that we do not need barriers for moving entries into the finalizers collected list. Dart reads and replaces the collected entries list also with an atomic exchange, ensuring the GC doesn't run in between a load/store. When a finalizer gets posted a message to process finalized objects, it is being kept alive by the message. An alternative design would be to pre-allocate a `WeakReference` in the finalizer pointing to the finalizer, and send that itself. This would be at the cost of an extra object. Send and exit is not supported in this CL, support will be added in a follow up CL. Trying to send will throw. Bug: https://github.com/dart-lang/sdk/issues/47777 TEST=runtime/tests/vm/dart/finalizer/* TEST=runtime/tests/vm/dart_2/isolates/fast_object_copy_test.dart TEST=runtime/vm/object_test.cc Change-Id: Ibdfeadc16d5d69ade50aae5b9f794284c4c4dbab Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-ffi-android-debug-arm64c-try,dart-sdk-mac-arm64-try,vm-kernel-mac-release-arm64-try,pkg-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-nnbd-win-release-ia32-try,vm-ffi-android-debug-arm-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,benchmark-linux-try,flutter-analyze-try,flutter-frontend-try,pkg-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238086 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-25 10:29:30 +00:00
bool IsSnapshot() const {
return !IsRaw() && !IsPersistentHandle() && !IsFinalizerInvocationRequest();
}
[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
// A message whose object is an immortal object from the vm-isolate's heap.
bool IsRaw() const { return snapshot_length_ == 0; }
// A message sent from SendPort.send or SendPort.sendAndExit where sender and
// receiver are in the same isolate group.
bool IsPersistentHandle() const {
return snapshot_length_ == kPersistentHandleSnapshotLen;
}
Reland "[vm] Implement `Finalizer`" Original CL in patchset 1. Split-off https://dart-review.googlesource.com/c/sdk/+/238341 And pulled in fix https://dart-review.googlesource.com/c/sdk/+/238582 (Should merge cleanly when this lands later.) This CL implements the `Finalizer` in the GC. The GC is specially aware of two types of objects for the purposes of running finalizers. 1) `FinalizerEntry` 2) `Finalizer` (`FinalizerBase`, `_FinalizerImpl`) A `FinalizerEntry` contains the `value`, the optional `detach` key, and the `token`, and a reference to the `finalizer`. An entry only holds on weakly to the value, detach key, and finalizer. (Similar to how `WeakReference` only holds on weakly to target). A `Finalizer` contains all entries, a list of entries of which the value is collected, and a reference to the isolate. When a the value of an entry is GCed, the enry is added over to the collected list. If any entry is moved to the collected list, a message is sent that invokes the finalizer to call the callback on all entries in that list. When a finalizer is detached by the user, the entry token is set to the entry itself and is removed from the all entries set. This ensures that if the entry was already moved to the collected list, the finalizer is not executed. To speed up detaching, we use a weak map from detach keys to list of entries. This ensures entries can be GCed. Both the scavenger and marker tasks process finalizer entries in parallel. Parallel tasks use an atomic exchange on the head of the collected entries list, ensuring no entries get lost. The mutator thread is guaranteed to be stopped when processing entries. This ensures that we do not need barriers for moving entries into the finalizers collected list. Dart reads and replaces the collected entries list also with an atomic exchange, ensuring the GC doesn't run in between a load/store. When a finalizer gets posted a message to process finalized objects, it is being kept alive by the message. An alternative design would be to pre-allocate a `WeakReference` in the finalizer pointing to the finalizer, and send that itself. This would be at the cost of an extra object. Send and exit is not supported in this CL, support will be added in a follow up CL. Trying to send will throw. Bug: https://github.com/dart-lang/sdk/issues/47777 TEST=runtime/tests/vm/dart/finalizer/* TEST=runtime/tests/vm/dart_2/isolates/fast_object_copy_test.dart TEST=runtime/vm/object_test.cc Change-Id: Ibdfeadc16d5d69ade50aae5b9f794284c4c4dbab Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-ffi-android-debug-arm64c-try,dart-sdk-mac-arm64-try,vm-kernel-mac-release-arm64-try,pkg-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-nnbd-win-release-ia32-try,vm-ffi-android-debug-arm-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,benchmark-linux-try,flutter-analyze-try,flutter-frontend-try,pkg-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238086 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-25 10:29:30 +00:00
// A message sent from GC to run a finalizer.
bool IsFinalizerInvocationRequest() const {
return snapshot_length_ == kFinalizerSnapshotLen;
}
void DropFinalizers() {
if (finalizable_data_ != nullptr) {
finalizable_data_->DropFinalizers();
}
}
intptr_t Id() const;
static const char* PriorityAsString(Priority priority);
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
private:
static intptr_t const kPersistentHandleSnapshotLen = -1;
Reland "[vm] Implement `Finalizer`" Original CL in patchset 1. Split-off https://dart-review.googlesource.com/c/sdk/+/238341 And pulled in fix https://dart-review.googlesource.com/c/sdk/+/238582 (Should merge cleanly when this lands later.) This CL implements the `Finalizer` in the GC. The GC is specially aware of two types of objects for the purposes of running finalizers. 1) `FinalizerEntry` 2) `Finalizer` (`FinalizerBase`, `_FinalizerImpl`) A `FinalizerEntry` contains the `value`, the optional `detach` key, and the `token`, and a reference to the `finalizer`. An entry only holds on weakly to the value, detach key, and finalizer. (Similar to how `WeakReference` only holds on weakly to target). A `Finalizer` contains all entries, a list of entries of which the value is collected, and a reference to the isolate. When a the value of an entry is GCed, the enry is added over to the collected list. If any entry is moved to the collected list, a message is sent that invokes the finalizer to call the callback on all entries in that list. When a finalizer is detached by the user, the entry token is set to the entry itself and is removed from the all entries set. This ensures that if the entry was already moved to the collected list, the finalizer is not executed. To speed up detaching, we use a weak map from detach keys to list of entries. This ensures entries can be GCed. Both the scavenger and marker tasks process finalizer entries in parallel. Parallel tasks use an atomic exchange on the head of the collected entries list, ensuring no entries get lost. The mutator thread is guaranteed to be stopped when processing entries. This ensures that we do not need barriers for moving entries into the finalizers collected list. Dart reads and replaces the collected entries list also with an atomic exchange, ensuring the GC doesn't run in between a load/store. When a finalizer gets posted a message to process finalized objects, it is being kept alive by the message. An alternative design would be to pre-allocate a `WeakReference` in the finalizer pointing to the finalizer, and send that itself. This would be at the cost of an extra object. Send and exit is not supported in this CL, support will be added in a follow up CL. Trying to send will throw. Bug: https://github.com/dart-lang/sdk/issues/47777 TEST=runtime/tests/vm/dart/finalizer/* TEST=runtime/tests/vm/dart_2/isolates/fast_object_copy_test.dart TEST=runtime/vm/object_test.cc Change-Id: Ibdfeadc16d5d69ade50aae5b9f794284c4c4dbab Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-ffi-android-debug-arm64c-try,dart-sdk-mac-arm64-try,vm-kernel-mac-release-arm64-try,pkg-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-nnbd-win-release-ia32-try,vm-ffi-android-debug-arm-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,benchmark-linux-try,flutter-analyze-try,flutter-frontend-try,pkg-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238086 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-25 10:29:30 +00:00
static intptr_t const kFinalizerSnapshotLen = -2;
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
friend class MessageQueue;
Message* next_ = nullptr;
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
Dart_Port dest_port_;
[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
union Payload {
Payload(uint8_t* snapshot) : snapshot_(snapshot) {}
Payload(ObjectPtr raw_obj) : raw_obj_(raw_obj) {}
Payload(PersistentHandle* persistent_handle)
: persistent_handle_(persistent_handle) {}
[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
uint8_t* snapshot_;
ObjectPtr raw_obj_;
PersistentHandle* persistent_handle_;
[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
} payload_;
intptr_t snapshot_length_ = 0;
MessageFinalizableData* finalizable_data_ = nullptr;
Priority priority_;
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
DISALLOW_COPY_AND_ASSIGN(Message);
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
};
// There is a message queue per isolate.
class MessageQueue {
public:
MessageQueue();
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
~MessageQueue();
void Enqueue(std::unique_ptr<Message> msg, bool before_events);
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
// Gets the next message from the message queue or nullptr if no
// message is available. This function will not block.
std::unique_ptr<Message> Dequeue();
bool IsEmpty() { return head_ == nullptr; }
// Clear all messages from the message queue.
void Clear();
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
// Iterator class.
class Iterator : public ValueObject {
public:
explicit Iterator(const MessageQueue* queue);
virtual ~Iterator();
void Reset(const MessageQueue* queue);
// Returns false when there are no more messages left.
bool HasNext();
// Returns the current message and moves forward.
Message* Next();
private:
Message* next_;
};
intptr_t Length() const;
// Returns the message with id or nullptr.
Message* FindMessageById(intptr_t id);
void PrintJSON(JSONStream* stream);
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
private:
Message* head_;
Message* tail_;
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
DISALLOW_COPY_AND_ASSIGN(MessageQueue);
};
} // namespace dart
#endif // RUNTIME_VM_MESSAGE_H_