Commit graph

39 commits

Author SHA1 Message Date
Daco Harkes e151a81108 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
Daco Harkes 37526fc8d7 Revert "[vm] Implement Finalizer"
This reverts commit 7dca34c235.

Reason for revert: b/226085355 dart_vm_test crashing. Unclear what
the cause is. Reverting so we can triage the issue.

TEST=This is a revert.

Original change's description:
> [vm] Implement `Finalizer`
>
> This CL implements the `Finalizer` in the GC.
>
> (This CL does not yet implement `NativeFinalizer`.)
>
> 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: I03e6b4a46212316254bf46ba3f2df333abaa686c
> 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/+/229544
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Daco Harkes <dacoharkes@google.com>

TBR=lrn@google.com,vegorov@google.com,kustermann@google.com,rmacnak@google.com,dacoharkes@google.com

Change-Id: I991f6e49896d18a8d70210cf315d858b462d66c9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/47777
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/+/238080
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-22 11:55:38 +00:00
Daco Harkes 7dca34c235 [vm] Implement Finalizer
This CL implements the `Finalizer` in the GC.

(This CL does not yet implement `NativeFinalizer`.)

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: I03e6b4a46212316254bf46ba3f2df333abaa686c
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/+/229544
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-03-22 10:30:18 +00:00
Ryan Macnak 6da3725698 [vm] Remove unused failure delivery port mechanism.
TEST=ci
Change-Id: If8cf1c484b79b8a8410315c28b7c3f8b7f98a5a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221880
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-12-01 23:40:06 +00:00
Martin Kustermann b3b2abb9eb [vm/concurrency] Store persistent handle in [Message]s instead of [Bequest] object
Storing a persistent handle in [Message] objects instead of the
[Bequest] (which is just a wrapper around a persistent handle) will
allow us to use the same mechanism for sending copies of transitive
object graphs.

Since messages can have maps inside them that need rehashing, we'll
make the persistent handle point to an array of length 2 of the format:

    array = [<message>, <array-of-objects-in-message-to-rehash>]

The sendAndExit doesn't use the second part atm (since it preserves
identities and therefore avoids the need for rehashing).

Though sending transitive copies of object graphs will require this
functionality (a follow-up CL which will land with this one).

For ease of reviewing this CL was split out.

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

TEST=Refactoring, relying on existing test coverage.

Change-Id: I2afa78b42ef82d46477579623fd54f027136333f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203769
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2021-06-18 06:55:11 +00:00
Ryan Macnak b1c09ecd8f [vm] Make naming more consistent when converting between handles, tagged and untagged pointers.
Currently we have things called XPtr which are not what you get from ptr().

Old world:
handle->raw() returns RawObject* (tagged)
raw_obj->ptr() returns RawObject* (untagged)

After 6fe15f6df9:
handle->raw() returns ObjectPtr
obj_ptr->ptr() returns ObjectLayout*

New world:
handle->ptr() returns ObjectPtr
obj_ptr->untag() returns UntaggedObject*

TEST=ci
Change-Id: I6c7f34014cf20737607caaf84979838300d12df2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149367
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-01-15 23:32:02 +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
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
Samir Jindel 8cbb11cc55 [vm/ffi] FFI callbacks on ARM32.
Please see go/dart-ffi-callbacks for design context and motivation.

Change-Id: Ie5edcb8837157c679954a670fb19d545e22fec69
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-simdbc64-try, vm-kernel-linux-release-simdbc64-try, vm-kernel-mac-debug-simdbc64-try, vm-kernel-mac-release-simdbc64-try, vm-kernel-reload-mac-debug-simdbc64-try, vm-kernel-reload-mac-release-simdbc64-try, vm-kernel-linux-debug-ia32-try, vm-dartkb-linux-debug-simarm64-try, vm-kernel-win-debug-ia32-try, vm-ffi-android-debug-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101828
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2019-06-03 14:36:04 +00:00
Matthew Dempsky b1f6c1d092 [vm] Fix -O0 build after CL 101222
const objects that are declared in .h files are supposed to have
out-of-line definitions in their corresponding .cc file. It seems like
CL 101222 happened to expose this for Message::kIllegalPort.

Change-Id: I9656037581eb6406eaf3289dfcf705db90862a26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102122
Commit-Queue: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-05-10 18:47:28 +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
Alexander Aprelev 59b8a9c4bb [vm] Free readonly header bit so it can be used for other uses.
This is reland of https://dart-review.googlesource.com/c/sdk/+/97340 rebased on top of removal of GraphMarked bit, which was not compatible with this ReadOnly->InVMIsolateHeap change(due to how write-pages are not covered by Contains check)

Change-Id: I34c6421afb4baeafa5a449787020dab9fa800d05
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97545
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2019-03-22 23:46:51 +00:00
Alexander Aprelev 34af8b95e5 Revert "[vm] Free readonly header bit so it can be used for other uses."
This reverts commit 59931e3340 as it
breaks jitk and optcounter bots.

Change-Id: If87ce52ac3d4015608436bfd7ee661ea1414dc7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97480
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2019-03-21 06:23:50 +00:00
Alexander Aprelev 59931e3340 [vm] Free readonly header bit so it can be used for other uses.
Rely on vm_isolate()->heap()->Contains() instead of header bit check.

Change-Id: Ibf66b9910aea5003dd3dee539704deeb72c61ada
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97340
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2019-03-21 00:02:56 +00:00
Ryan Macnak 980e5c7b57 [vm] Mark VM isolate objects at heap finalization instead of allocation.
Avoids unnecessary branching in allocation.

Also, rename the VMHeap bit to ReadOnly to reflect its current usage.

Change-Id: Ic6060eec263cef0a3fc92f253dff976cea45bdb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95063
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-03-07 00:20:30 +00:00
Ryan Macnak afdbce7b13 [vm, isolate] Send large TypedData as ExternalTypedData in isolate messages.
Be careful to free external data when reading or writing a message is interrupted, or releasing messaging without reading on shutdown.

Bug: https://github.com/dart-lang/sdk/issues/31959
Change-Id: Ia39acb9ca0e27cf9e8b83961741e5949b5930266
Reviewed-on: https://dart-review.googlesource.com/41561
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2018-02-21 18:57:14 +00:00
Ryan Macnak 3f40488ec4 [vm, isolate] Refactor isolate message snapshotting to centralize construction of the Message.
Remove unused special case in ApiMessageWriter for lists of int.

This is in preparation for ensuring we always free any external data that ends up in an isolate message.

Bug: https://github.com/dart-lang/sdk/issues/31959
Change-Id: I999656fc11d2aee9aebe70852be5bb075f234b4d
Reviewed-on: https://dart-review.googlesource.com/41020
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2018-02-14 00:28:01 +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
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 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
Regis Crelier 7f57ebcfa1 Remove signature classes from the VM.
They were used as the class of closure instances and as the type class of
function types.
All closure instances now have class _Closure and function types are represented
by a new class FunctionType extending AbstractType.
Fix issue 24567 and add regression test.

R=asiva@google.com, rmacnak@google.com

Review URL: https://codereview.chromium.org/1584223006 .
2016-01-19 16:32:59 -08:00
John McCutchan 9c4d06a4f2 Make sure that Dart_Ports are printed safely in the service protocol
- A Dart_Port is a random 64-bit integer.
- On 32-bit architectures we were silently truncating the isolate id when printing.
- Parsing in JavaScript would also have issues.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1411083007 .
2015-10-20 09:47:35 -07:00
Srdjan Mitrovic 8d618766a8 Remove isolate argument from handle allocation: Part II
BUG=
R=regis@google.com

Review URL: https://codereview.chromium.org/1389353004 .
2015-10-12 14:06:50 -07:00
Todd Turnidge 6c2ebfcc60 Switch to using SourceLocation universally in service protocol.
Add <location-link> and <location-inset> to provide links and insets
for a location.

Make Frame, Message, and SourceLocation first class in service lib.

BUG=
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org//1150303004
2015-06-03 09:02:40 -07:00
Todd Turnidge 563083696c Sundry service protocol cleanups before version 1.0.
Frame.depth -> Frame.index
Message.depth -> Message.index
Remove Message.type
Message.priority becomes private
frame -> frameIndex for evaluateInFrame
Class.finalized, Class.implemented, Class.patch Class.allocationStats become private
Instance.nativeFields becomes private
Field.value moves out of "ref" into full object
Field.value -> Field.staticValue
Move Function.static, Function.const to "ref"
Make Script.kind private in docs
Make Function.kind private

BUG=
R=rmacnak@google.com

Review URL: https://codereview.chromium.org//1160873002
2015-05-28 09:30:55 -07:00
johnmccutchan@google.com 2f7cff7170 Display isolate message queue in Observatory debugger
- Log the parameters to RPCs
- Display messages like stack frames
    - handler function and script visible
    - message preview instead of local variables
- Expanded and previewed messages do not collapse when stepping within the existing message
- Mark patch classes as finalized to avoid ASSERT on class_finalizer.cc:2358 **
- Support iterating over message queues
- Support printing the message queue as JSON
- Inhibit OOB messages from being handled if we are iterating over the message queue
    - avoids dead lock when looking up port handler (done in Dart code with message handler locked) and a stack overflow trigger to handle OOB messages
- make getObject understand message ids
- Fix dartbug.com/23355

** Need to discuss with Ivan and Matthias (reviewed code differs from committed code but matches my fix):
https://codereview.chromium.org//828353002
https://code.google.com/p/dart/source/detail?r=42612

R=turnidge@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45505 260f80e4-7a28-3924-810f-c04153c831b5
2015-05-04 20:20:44 +00:00
iposva@google.com 602aad28a1 - Implement Isolate.ping.
- Allow isolate library messages to be enqueued at the beginning
  of the message queue.

R=asiva@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42193 260f80e4-7a28-3924-810f-c04153c831b5
2014-12-08 22:45:10 +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
ager@google.com 08b1e44502 Reapply "Optimize the message queue for many active ports with few messages."
BUG=

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16394 260f80e4-7a28-3924-810f-c04153c831b5
2012-12-20 20:03:07 +00:00
ager@google.com c3c47bbc98 Revert "Optimize the message queue for many active ports with few messages."
No failures locally. I'll investigate tomorrow.

R=iposva@google.com
BUG=

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16392 260f80e4-7a28-3924-810f-c04153c831b5
2012-12-20 19:40:29 +00:00
ager@google.com 6e945a2578 Optimize the message queue for many active ports with few messages.
The current message queue implementation is very inefficient if you are using
many active ports with few messages. This happens when you use 'call' a lot
on ports which is currently done in dart:io.

This patch does not remove messages from the queue when closing a port. Instead
it drops messages for closed ports when it processes them. This dramatically
speeds up dart:io benchmarks that enqueue tons of writes on a file output
stream.

R=iposva@google.com
BUG=http://dartbug.com/6911

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16388 260f80e4-7a28-3924-810f-c04153c831b5
2012-12-20 19:20:44 +00:00
kmillikin@google.com 3d684dcc70 Compress deoptimization information by sharing common suffixes.
For all the deoptimization entries in a function, build a suffix trie.  Add
a new deoptimization instruction that indicates the rest of the translation
is a fixed-length suffix of another entry.

BUG=

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14252 260f80e4-7a28-3924-810f-c04153c831b5
2012-10-30 09:50:35 +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
turnidge@google.com ff26341fd6 Heartbeat implementation of dart:mirrors.
Add the skeleton for the dart:mirrors library in all the appropriate
places.  The only thing we can do right now is ask an Isolate for its
debugName.  Add a few tests.
Review URL: https://chromiumcodereview.appspot.com//9420038

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@5370 260f80e4-7a28-3924-810f-c04153c831b5
2012-03-12 23:51:03 +00:00
turnidge@google.com e2a88a357a Revert my last change. Odd test failures that I will investigate tomorrow.
Review URL: https://chromiumcodereview.appspot.com//9570051

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4846 260f80e4-7a28-3924-810f-c04153c831b5
2012-03-02 00:38:18 +00:00
turnidge@google.com cdf40e7b15 Make the message queue private in the message handler.
Move locking up from the message queue to the message handler.
Review URL: https://chromiumcodereview.appspot.com//9570046

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4842 260f80e4-7a28-3924-810f-c04153c831b5
2012-03-01 23:57:49 +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
Renamed from runtime/vm/message_queue.cc (Browse further)