The previous implementation of SafepointRwLock has an issue (discovered
by Slava, see bug) with the following code pattern:
{
SafepointReadRwLocker locker(...);
return Foo(); // <-- Returns raw ptr.
}
After the return expression has been evaluated to a raw pointer
the destructor might enter safepoint and cause GC, which leaves
the raw pointer unchanged (since it's not in a handle).
This CL refactors the implementation to ensure we don't perform any
state transition in the destructor, therefore eliminate the
possibility of GC moving the object we return.
Issue https://github.com/dart-lang/sdk/issues/44998
TEST=Relying on existing SafepointRwLock.
Change-Id: Ib7a62b36838edd4b39ad67a8c58f048aa05aa144
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185062
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This reverts commit 9474c2355d.
Reason for revert: Doesn't compile (?)
Original change's description:
> [vm] Replaces fuchsia.deprecatedtimezone
>
> (prior attempt was rolled back as it had a regression which was not
> caught by tests. Tests are fixed now at:
> https://fuchsia-review.googlesource.com/c/fuchsia/+/409840)
>
> The FIDL library fuchsia.deprecatedtimezone is going away. There are
> different and better ways to obtain the same functionality. This change
> removes the dependency on fuchsia.deprecatedtimezone from the Dart SDK.
>
> Adds inspect metrics that allow whitebox testing of the runners. Here's
> a sample `fx iquery` excerpt from a running device, showing both a dart
> and a flutter runner exposing the same OS diagnostic metrics.
>
> Adds support for asynchronous timezone updates, which was missing from
> previous versions of this commit.
>
> ```
> /hub/c/dart_jit_runner.cmx/70981/out/diagnostics:
> /hub/c/dart_jit_runner.cmx/70981/out/diagnostics#os:
> dst_status = 0
> get_profile_status = 0
> timezone_content_status = 0
> tz_data_close_status = 0
> tz_data_status = 0
> /hub/c/flutter_jit_runner.cmx/29567/out/diagnostics:
> /hub/c/flutter_jit_runner.cmx/29567/out/diagnostics#os:
> dst_status = 0
> get_profile_status = 0
> timezone_content_status = 0
> tz_data_close_status = 0
> tz_data_status = 0
> ```
>
> Under nominal operation, all of the above values should be equal to 0.
> Nonzero values indicate an error.
>
> This functionality is guarded by Fuchsia integration tests at
> //src/tests/intl.
>
>
> Tested:
> (compile locally for Fuchsia and deploy)
> fx test //src/tests/intl
>
> See:
> - https://github.com/dart-lang/sdk/issues/42245
> - https://github.com/dart-lang/sdk/issues/39650
>
> Fixes#39650
> TEST=see Tested: above
> Change-Id: Icb72ddd554c263f970e18b9cbbaab7adf43c8710
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155582
> Auto-Submit: Filip Filmar <fmil@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Commit-Queue: Martin Kustermann <kustermann@google.com>
Change-Id: Ic45c09a49796f8fb8b21cfaa8005db4b57f5eb52
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185301
Auto-Submit: Filip Filmar <fmil@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
(prior attempt was rolled back as it had a regression which was not
caught by tests. Tests are fixed now at:
https://fuchsia-review.googlesource.com/c/fuchsia/+/409840)
The FIDL library fuchsia.deprecatedtimezone is going away. There are
different and better ways to obtain the same functionality. This change
removes the dependency on fuchsia.deprecatedtimezone from the Dart SDK.
Adds inspect metrics that allow whitebox testing of the runners. Here's
a sample `fx iquery` excerpt from a running device, showing both a dart
and a flutter runner exposing the same OS diagnostic metrics.
Adds support for asynchronous timezone updates, which was missing from
previous versions of this commit.
```
/hub/c/dart_jit_runner.cmx/70981/out/diagnostics:
/hub/c/dart_jit_runner.cmx/70981/out/diagnostics#os:
dst_status = 0
get_profile_status = 0
timezone_content_status = 0
tz_data_close_status = 0
tz_data_status = 0
/hub/c/flutter_jit_runner.cmx/29567/out/diagnostics:
/hub/c/flutter_jit_runner.cmx/29567/out/diagnostics#os:
dst_status = 0
get_profile_status = 0
timezone_content_status = 0
tz_data_close_status = 0
tz_data_status = 0
```
Under nominal operation, all of the above values should be equal to 0.
Nonzero values indicate an error.
This functionality is guarded by Fuchsia integration tests at
//src/tests/intl.
Tested:
(compile locally for Fuchsia and deploy)
fx test //src/tests/intl
See:
- https://github.com/dart-lang/sdk/issues/42245
- https://github.com/dart-lang/sdk/issues/39650Fixes#39650
TEST=see Tested: above
Change-Id: Icb72ddd554c263f970e18b9cbbaab7adf43c8710
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155582
Auto-Submit: Filip Filmar <fmil@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This change adds two new RPCs and various new properties:
- getAllocationTraces
- setTraceClassAllocation
- classId and identityHashCode properties in CpuSample
- traceAllocations property in Class
TEST=get_allocation_traces_test.dart
package:vm_service has been regenerated for 3.43 of the service protocol
and is ready for a 6.1.0 release.
Change-Id: Ia8ed055423798d7d17fe9f5fd74efb4239b875fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182666
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Since loading kernel will affect all isolates within a group, there
should be nothing isolate-specific inside the kernel loader. To ensure
we don't have (or introduce) any accidental uses, we add a
NoActiveIsolateScope to the main parts of kernel loading.
Only loading of native extensions - done by the kernel loader -
currently requires an active isolate. The reason for this is that
loading native extensions happen by calling out to embedder, which calls
back into the VM using the our embedding API (which currently requires
an active isolate)
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing implementation.
Change-Id: I96e64dbfe7148b76b8fa006fe5dbde8c1f904504
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184269
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Since the flag is now enabled by default, there should be no mention of it.
There are still some uses in front_end/testcases that are not just removable
(it also uses `no-non-nullable`). There migth be more uses that are not
as easily found as grepping for `--enable-experiment
Removes two VM tests where fixing them meant they were just duplicating
the corresponding non *_2/ tests.
Fixes#44941
TEST= Large number of tests chaged.=(no-)?non-nullable`.
Change-Id: Ief755981ccde9a5482fcdf408c2929c74433a710
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183688
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
The object store related fields in [Isolate] are not needed anymore:
Isolate::object_store_
Isolate::cached_object_store_
Isolate::object_store_shared_ptr_
and can be directly accessed from [IsolateGroup].
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing implementation.
Change-Id: Ia01da92cbb4e7cf5862c8419e27578ea07d4bdf2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184268
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
With --enable-isolate-groups we will start sharing JITed code. The JITed
code - which will be executed by all isolates - should therefore not
depend on a particular isolate's state, flags or any other
isolate-specific information.
To avoid accidental bugs where the compiler starts using
isolate-specific information, we ensure the compiler runs without a
current isolate.
This CL doesn't add NoActiveIsolateScope because on unoptimized compiles
of natives, the compiler calls out to embedder for eager native
resolution of native functions. This API forces embedder to callback
into VM atm.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Adds more checking.
Change-Id: I6c86674c010b74c15855652415706dbaa8749d33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183692
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This CL moves the [ProgramReloadContext] from [Isolate] to
[IsolateGroup] - since the program is shared across isolates. Amongst
other things, it also deoptimizes stacks of all isolate mutators.
There is still future work to do for hot-reloading multiple isolates
within a group, this is only the first change.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing implementation.
Change-Id: Ic394de265e3922f84657de2da25a46179b624647
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183693
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This CL changes `@pragma('vm:ffi:struct-fields', [...])` to
`@pragma('vm:ffi:struct-fields', _FfiStructLayout([...]))` which makes
it easier to add more data in subsequent CLs.
Extends `FindPragma` to allow returning multiple matched pragma's, so
that we can filter them. (In this case to avoid matching user-defined
pragma's that do not have an instance of the private class.)
Separated out from https://dart-review.googlesource.com/c/sdk/+/183640
because of the extra constant in existing expectation files.
Bug: https://github.com/dart-lang/sdk/issues/35763
Bug: https://github.com/dart-lang/sdk/issues/38158
TEST=tests/ffi(_2)/*_by_value_*_test.dart
Change-Id: Idef9f82e9b53c2a32dffabcec19669eae550fe2f
Cq-Include-Trybots: luci.dart.try:front-end-nnbd-mac-release-x64-try,front-end-linux-release-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-nnbd-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184181
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
This is to ensure that deferred library status is per isolate, rather than per isolate-group.
TEST=deferred_isolate_test.dart
Issue dartbug.com/36097
Change-Id: I1fb8b8f1830aac688a078fe0a82b06c7daa856fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184040
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
If the length was set longer than the backing store, on a call to
`Set(index, false)`, and subsequently a call `Set(index-1, true)` was
done, it would try to write outside the backing store.
Closes: https://github.com/dart-lang/sdk/issues/44946
TEST=runtime/vm/bitmap_test.cc
TEST=tests/ffi_2/function_structs_by_value_generated_test.dart/0
Change-Id: Ib636e90b0f6acace9ec8b71557370c281e9e4a99
Cq-Include-Trybots: luci.dart.try:app-kernel-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184423
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
This is done by simplifying the code looking for a type argument vector overlap between class and super class.
TEST=all existing ones
Change-Id: I96b11deb3450de380280c693d05e9b70a01e3383
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184202
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
The logic for background compiler can be simplified due to:
* we only have one bg compiler
* it always optimizes
* it is allocated at isolate startup and freed on isolate shutdown
* an existing check in the compiler for whether the BG compiler is
disabled is racy and therefore not helpful
* when a mutator communicates with BG compiler it will use
SafepointMutexLocker instead of MutexLocker
This CL also ecapsulates disabling the BG compiler via a
NoBackgroundCompilerScope object. It allows nested disabling and guards
against races.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing code.
Change-Id: I36ed6592c9a8b91e94181698b7de662b4ee984e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183400
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
During isolate shutdown we remove the isolate from the list of isolates
in a group in one step and decrement a counter in another. Those are not
done atomically.
To avoid races where we use one condition and later on assume the other
holds as well, consistently use the same condition.
Fixes https://github.com/dart-lang/sdk/issues/44939
TEST=Fixes flaky tsan hits of ASSERT.
Change-Id: I41eeb00cd3e341d07cba7571b29aeb4eacdfc458
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184260
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
The various ABIs lay out structs with inline arrays the same way as
they do with only nested structs and primitive values.
Most notably, homogenous structs (arm and arm64) and structs spread
over a CPU and FPU register in x64 Linux/MacOS will even be laid out
this way if irregular size nested arrays are involved.
These cases are covered in the unit tests.
This CL introduces the ByteRange to ease the ContainsOnlyFloats
calculation for x64.
Bug: https://github.com/dart-lang/sdk/issues/35763
tools/build.py run_ffi_unit_tests && tools/test.py ffi_unit
TEST=runtime/vm/compiler/ffi/native_calling_convention_test.cc
TEST=runtime/vm/compiler/ffi/native_type_test.cc
tools/test.py ffi ffi_2
TEST=tests/ffi(_2)/(.*)by_value_(*.)_test.dart
Change-Id: I4bbcbffd47eb8901a87db64e62aa5cbe67d03e18
Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-win-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-mac-debug-x64-try,vm-ffi-android-debug-arm64-try,vm-ffi-android-debug-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183682
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
When accessing the list of isolates in a group to get the first one we
only need a read-lock, not a write-lock.
This fixes hot-reload bot timeouts where a mutator hits a StackOverflow
slowpath that triggers a reload, which loops over all isolates in a
group to stop BG compiler (takes read lock). The BG compiler in return
will try to acquire write-lock for `FirstIsolate()`, which causes a
deadlock.
TEST=Existing reload timeouts.
Change-Id: Iba9264cc4990a4f00697844c44fad407cebf2e21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183003
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
As part of making the compiler as well as hot-reload independent of
a particular isolate we move this boolean to `IsolateGroup`.
For hot-reloading isolate groups there are more changes needed that
come in the future. This CL is preparation for making the compiler
independent of current isolate.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing code.
Change-Id: I434cf1180bc963462e2901dfa83e915df9dc1712
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182561
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
As part of making the compiler independent of the current isolate (since
JITed code will be shared across all isolate) we make the compiler not
depend on global field state, with one exception: we preserve an existing
optimization that utilizes knowledge whether a global final field was
already initialized (if --enable-isolate-groups is turned off) - we do
so by asking the isolate group for it's own isolate member.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing code.
Change-Id: I2f08d854af6102e05e5a1df8d5b66b514d6f3ce4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182540
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
The background compiler can cause finalization of classes which can
cause deoptimization of code.
Any deoptimization will iterate over all mutator threads and marks
frames on the stack to be deoptimized. This requires saving old
(fp, pc) state. This state is currently saved on the current isolate's
pending deopt array (via `Thread::Current()->isolate()->AddPendingDeopt()`)
instead of the isolate whose stack got walked.
As part of making the compiler independent of `Isolate::Current()` we
pass the isolate explicitly.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing code.
Change-Id: I9327f3b76981fc16c1879a873edf37df1cbdd8bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182380
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
When using reachability fence as an optimization barrier (e.g. to
prevent dead code elimination or allocation sinking) it is helpful
to reduce fence's impact on optimizations themselves.
TEST=ci
Change-Id: I4581c73e4704e94870a9942e05e16ab38ca2d864
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182625
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
As part of making the compiler independent of a particular isolate
(since all isolates in a group share the same JITed code) we move the
boxed field list to IsolateGroup.
Any isolate that hits the lazy compile stub will then drain the fields
to be deoptimized and performs that work.
A follow-up investigation can decide whether it's beneficial (or
hurtful) for single vs multi isolate scenarios to deoptimize the field
immediately in BG compiler (and interrupt mutator). It is possibly
disadvantagues for single isolate scenarios to do so, since it causes
more mutator interruptions.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=Refactoring of existing code.
Change-Id: I64b42ad99056b43a7264bcc30280b9ba39389a2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182505
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This is follow up to 6681bce565
the intent was always to perform a sign-extending 4 bytes load.
TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm64-try
Change-Id: Ie2b733c4de9bd564cb666d54c9e7b483dbfbeabb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182261
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
When handling hot reload via library tag handler's Kernel tag
VM must guarantee that external typed data it receives from the
embedder stays alive for as long as VM has any structures
referencing this kernel binary. This is achieved by attaching
original typed data to KernelProgramInfo objects containing
the views into it.
Unfortunately kernel::Reader APIs were somewhat unsafe: allowing
to construct reader object from Program's raw buffer and forget to
set the link betwen the reader and original typed data.
This created a situation where reloading using a multicomponent
Kernel binary would result in KernelProgramInfo objects without
link to the original typed data, which in turn leads to premature
finalization of external typed data and subsequent crashes
when trying to use delete kernel binary.
This CL reworks kernel::Reader API (by introducing kernel::ProgramBinary
wrapper) to make it safer and make sure that connection is preserved.
TEST=vm/cc/IsolateReload_RegressB179030011
Bug: b/179030011
Change-Id: I05f8c31c3cb8e67de6e94a20d9501a5f476b7e27
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182280
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>