This is the next step towards preventing compiler from directly peeking
into runtime and instead interact with runtime through a well defined
surface. The goal of the refactoring to locate all places where compiler
accesses some runtime information and partion those accesses into two
categories:
- creating objects in the host runtime (e.g. allocating strings, numbers, etc)
during compilation;
- accessing properties of the target runtime (e.g. offsets of fields) to
embed those into the generated code;
This change introduces dart::compiler and dart::compiler::target namespaces.
All code in the compiler will gradually be moved into dart::compiler namespace.
One of the motivations for this change is to be able to prevent access to
globally defined host constants like kWordSize by shadowing them in the
dart::compiler namespace.
The nested namespace dart::compiler::target hosts all information about
target runtime that compiler could access, e.g. compiler::target::kWordSize
defines word size of the target which will eventually be made different
from the host kWordSize (defined by dart::kWordSize).
The API for compiler to runtime interaction is placed into compiler_api.h.
Note that we still permit runtime to access compiler internals directly -
this is not going to be decoupled as part of this work.
Issue https://github.com/dart-lang/sdk/issues/31709
Change-Id: If4396d295879391becfa6c38d4802bbff81f5b20
Reviewed-on: https://dart-review.googlesource.com/c/90242
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Directly referencing VM isolate instructions from an isolate snapshot causes the instructions to be copied into the isolate's image page because instructions do not use the indirection of the ref array. Duplicating the instructions caused TypeTestingStubFinder::LookupByAddresss to be unable to identity the duplicate copies of the VM isolate type testing stubs.
Fixes identity of StubCode::*TypeTest broken by duplication in snapshot.
Fixes generating AppJIT snapshots after loading from AppJIT snapshots.
Fixes attribution of ticks for type test stubs in the AOT profiler.
Change-Id: I9879a85bd548e694ee36e14f795898582ccdddb0
Reviewed-on: https://dart-review.googlesource.com/c/90501
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
This reverts commit 0203243381.
Reason for revert: breaking several bots
Original change's description:
> [vm] Prevent access to non-annotated members through native API.
>
> We will issue warnings and throw an API error when the native API is used to access members which were not appropriately
> annotated as entry-points, if the flag "--verify-entry-points" is passed.
>
> Also, fixes Class::Invoke against fields (isn't allowed through native API but
> could be allowed with mirrors, and is inconsistent with Library::Invoke behavior).
>
> I've checked locally that this would have caught the bug in
> "Wrap the user entrypoint function in a zone with native exception callback. (#7512)".
>
> Change-Id: I617c71e1965457c956c97761359765bb9bb18c1c
> Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-mac-release-simarm64-try, vm-kernel-precomp-win-release-x64-try
> Reviewed-on: https://dart-review.googlesource.com/c/90060
> Commit-Queue: Samir Jindel <sjindel@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
TBR=alexmarkov@google.com,sjindel@google.com
Change-Id: I554b389780e4ba652183c044b040b0c524beb5c2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-mac-release-simarm64-try, vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/90841
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
We will issue warnings and throw an API error when the native API is used to access members which were not appropriately
annotated as entry-points, if the flag "--verify-entry-points" is passed.
Also, fixes Class::Invoke against fields (isn't allowed through native API but
could be allowed with mirrors, and is inconsistent with Library::Invoke behavior).
I've checked locally that this would have caught the bug in
"Wrap the user entrypoint function in a zone with native exception callback. (#7512)".
Change-Id: I617c71e1965457c956c97761359765bb9bb18c1c
Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-mac-release-simarm64-try, vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/90060
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Bare-metal relocation processing was removing the static call table, which is needed at runtime for JIT code.
Change-Id: Iab9a5a9256afd5f3985e8311a0131471cd04932d
Reviewed-on: https://dart-review.googlesource.com/c/88762
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Remove ValidatePostFinalizePatch and SetRefinalizeAfterPatch which are
not used anymore
Remove RawClass::kRefinalizeAfterPatch bit
Change-Id: I289df7ffe3e3017335510b5c14331254ca73c503
Reviewed-on: https://dart-review.googlesource.com/c/88621
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
The interpreter only build of the Dart VM should not be including any
sources from the 'compiler' directory.
First part of restructuring sources to enable an interpreter only build
of the VM
- Move CompileClass from compiler.cc file to class_finalizer.cc
Change-Id: I8743c6537ed2d63e6991d78949f858a1ae506121
Reviewed-on: https://dart-review.googlesource.com/c/87987
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
All application of patches is now done in the front end there
are no callers to Class::ApplyPatch, deleting it.
Change-Id: I84857ea49463faea8df6ce1ce88c0f704a893e65
Reviewed-on: https://dart-review.googlesource.com/c/88426
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
In Dart2, the type relation "is more specific than" is no different than "is
subtype of". Since Dart1 is not supported anymore, type checking in the runtime
can be simplified and cleaned up.
Change-Id: I8e95b9e47146315c9a6f6c29b732ecbeb4e9ae97
Reviewed-on: https://dart-review.googlesource.com/c/88221
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
CanonicalType is a leftover method/field from the time classes were keeping
track of their own canonical types and is still used for non-generic classes.
DeclarationType is more general and can be used where CanonicalType is used.
The field canonical_type_ is renamed to declaration_type_ and now caches the
DeclarationType.
Change-Id: I585c7bc2d3ae760a4a0e783bc77fb8d8efdbf682
Reviewed-on: https://dart-review.googlesource.com/c/87482
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Previous the test was accessing this array without any synchronization
meaning that stores of new ICData objects into this array could
be observed too early, before ICData object itself is initialized.
Also add release/acquire in the code that attaches ICData map to
the function - to ensure that if compiler thread sees ICData map
then it is guaranteed to be fully initialized.
Closes#34999
Change-Id: I95ba857122e2a5afed90b1518d591282e8255002
Reviewed-on: https://dart-review.googlesource.com/c/87583
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Auto-Submit: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
If the --use-bare-instructions flag is enabled we will:
* Not load CODE_REG inside CallThroughCode (polymorphic case)
* Not load CODE_REG inside CallThroughFunction (megamorphic case)
* Store the EntryPoint of the function in the MegamorphicCache tables
(instead of a Function pointer)
Issue https://github.com/dart-lang/sdk/issues/33274
Change-Id: I8aca689dc4e92ece897972da4ae202338527ac62
Reviewed-on: https://dart-review.googlesource.com/c/86928
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
If the --use-bare-instructions flag is enabled we will:
* Make call sites load the target directly from the pool (instead of
the code object) - this saves one instruction (and an indirect load)
* Ensure the object pool will have direct entry addresses by:
- Letting the clustered snapshot reader change any StubCode::UnlinkedCall()
in the object pool by it's monomorphic entry
- Change the code patcher to patch SwitchableCalls by writing the
monomorphic entry into the pool (instead of the code object)
Issue https://github.com/dart-lang/sdk/issues/33274
Change-Id: I4e41fc8e4461bde477cc559a6a4fccaaf3a350b5
Reviewed-on: https://dart-review.googlesource.com/c/86160
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This is the final CL which adds a new --use-bare-instructions flag to
the VM.
If this flag is set during AOT compilation, we will:
* Build one global object pool (abbr: GOP) which all code objects
share. This gop will be stored in the object store. The PP register
is populated in the enter dart stub and it is restored when
returning from native calls.
* Gets rid of the CODE_REG/PP slots from the dart frames. Instead the
compiled code uses the global object pool, which is always in PP.
* Starts emitting pc-relative calls for calls between two dart
functions or when invoking a stub.
Limitation: We only emit pc-relative calls between two code objects
in the same isolate (this is because the image writer is writing
instruction objects for vm-isolate/main-isolate seperately)
* We do compile-time relocation of those static calls after the
precompiler has finished its work, but before writing the snapshot.
This patches all the instruction objects with pc-relative calls to
have the right .text distance.
* We emit a sorted list of code objects in ObjectStore::reverse_code_table,
which will be used by the AOT runtime to go back from PC to Code
objects (where all metadata, e.g. stack maps, catch entry moves, pc
descriptors are available).
Issue https://github.com/dart-lang/sdk/issues/33274
Change-Id: I6c5dd2b1571e3a889b27e804a24c2986c71e03b6
Reviewed-on: https://dart-review.googlesource.com/c/85769
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
In Dart2, mixin application classes are generated by kernel and type resolution
is performed by kernel. In Dart1, using the VM parser, these tasks were done
during class and type finalization.
Change-Id: I927b1446d906ffd76ed9591c96e0d974df09f3bf
Reviewed-on: https://dart-review.googlesource.com/c/87025
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This CL adds a [ReversePcLookupCache] which, based on a list of code
objects, builds up a binary searchable table for mapping PCs to Code
objects (where all the metadata is available, like stackmaps, ...).
This CL also adds stack walking support for "bare instruction" frames.
In a later part we will start emitting the sorted list of code objects
(via the new field in the object store) under a flag.
Issue https://github.com/dart-lang/sdk/issues/33274
Change-Id: I3c06c12bc0fb266dc1bd843a4a11b5208773151d
Reviewed-on: https://dart-review.googlesource.com/c/85746
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
In Dart2, type bounds checking is either performed by the common front-end or
by explicitly generated code, but not by type finalization or runtime anymore,
as it was done in Dart1.
Consequently, the class BoundedType is not needed anymore, and malbounded or
malformed types are not seen by the runtime either.
Change-Id: I5d6e4c68d153d6730fa7ff7f6d9dcfa611299c16
Reviewed-on: https://dart-review.googlesource.com/c/86687
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Samir Jindel <sjindel@google.com>
To do this, we create a new Truncate() methods for Arrays, truncate
the ICData array to either 1 (just sentinel) or 2 (SMI + sentinel)
entries in Reset(), and change FindFreeIndex() to instead be
GrowFreeIndex() (which always copies).
Closes#35010.
Change-Id: Ia30f4b490cf9420caef843d7fcde9f461d15a206
Reviewed-on: https://dart-review.googlesource.com/c/86563
Commit-Queue: Stevie Strickland <sstrickl@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This is a major revamp of bytecode metadata format. Now bytecode has
its own serialization mechanisms.
This CL adds 'bytecode component' metadata, which contains bytecode
object table and string table. All references from bytecode (constant
pools) to libraries, classes, members, types and strings now have a new
format. References to frequently used objects are represented as indices
in object table, while rarely used objects are written inline.
This allows VM to cache frequently used objects while reading bytecode.
Representation of strings is aligned with VM - string characters are
stored in separate pools of one-byte and two-byte strings. This allows
VM to avoid UTF-8 decoding and extra copying.
Closure declarations are now explicit. Type parameters no longer require
enslosing scopes when reading/writing them.
Benchmarks:
GenKernelKernelReadAllBytecode (Intel Core i5) +29.84%
GenKernelKernelReadAllBytecode (Intel Xeon) +28.74%
Change-Id: I4b80009733a8f8c038264af74f97c4e094b9e311
Reviewed-on: https://dart-review.googlesource.com/c/85469
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Currently the @pramga('vm:exact-result-type') annotation only works if
the function is a recognized method. This change changes that to make
the VM just look if a function has the annotation (no matter if it's
also in the list of recognized methods or not).
Furthermore this CL lets the type propgagator use
@pragma('vm:exact-result-type') annotations to narrow the [CompileType]
set on [LoadFieldInstr]s.
Since the @pragma is a general feature, this CL moves the
`Function::FindPragma()` to `Library::FindPragma` (which is where any
other metadata lookup happens). We also let the `FindPragma` accept any
of Class/Function/Field objects.
Furthermore the `FindPragma()` function is fixed to handle the case
when the evaluation of the metadata results in an error.
In this case we simply claim to not have found a pragma annotation.
Issue https://github.com/dart-lang/sdk/issues/31954
Change-Id: If03f566e334cd53549985823ee3dd6b5e9672969
Reviewed-on: https://dart-review.googlesource.com/c/85163
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This is a reland of 1a4cff1bd4
Original change's description:
> [VM] Remove unused flags
>
> Remove the following flags which are always ON
> --strong
> --reify_generic_functions
>
> and these flags which are not applicable anymore
> --error-on-bad-override
> --error-on-bad-type
> --enable-type-checks
>
> Change-Id: I6e1aeb68e663953f4ae49ca94ea0daa87b661900
> Reviewed-on: https://dart-review.googlesource.com/c/79431
> Commit-Queue: Siva Annamalai <asiva@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Régis Crelier <regis@google.com>
Change-Id: Ib4452c22fb05eed38820708abb648939e03b1df0
Reviewed-on: https://dart-review.googlesource.com/c/84923
Reviewed-by: Siva Annamalai <asiva@google.com>
Remove the following flags which are always ON
--strong
--reify_generic_functions
and these flags which are not applicable anymore
--error-on-bad-override
--error-on-bad-type
--enable-type-checks
Change-Id: I6e1aeb68e663953f4ae49ca94ea0daa87b661900
Reviewed-on: https://dart-review.googlesource.com/c/79431
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
This reverts commit 2de63ac01c.
Reason for revert: This triggers shutdown deadlocks for some reason:
#0 0xf7782cd9 __kernel_vsyscall
#1 0xf7753d0b pthread_cond_wait@@GLIBC_2.3.2
#2 0x0108a515 dart::Monitor::WaitMicros(long long)
#3 0x0108a467 dart::Monitor::Wait(long long)
#4 0x00fe9048 dart::KernelIsolate::Shutdown()
#5 0x00f99ae4 dart::Dart::Cleanup()
#6 0x01278fce Dart_Cleanup
#7 0x00dd347e dart::bin::main(int, char**)
#8 0x00dd3d64 main
#9 0xf745caf3 __libc_start_main
#10 0x00dd2021 _start
TID 30443:
#0 0xf7782cd9 __kernel_vsyscall
#1 0xf7531ee6 epoll_wait
#2 0x00ddab61 dart::bin::EventHandlerImplementation::Poll(unsigned int)
#3 0x00dfb2d4 dart::bin::ThreadStart(void*)
#4 0xf774ff72 start_thread
#5 0xf753143e __clone
TID 30444:
#0 0xf7782cd9 __kernel_vsyscall
#1 0xf7753d0b pthread_cond_wait@@GLIBC_2.3.2
#2 0x0108a515 dart::Monitor::WaitMicros(long long)
#3 0x0108a467 dart::Monitor::Wait(long long)
#4 0x012484d8 dart::BackgroundCompiler::Run()
#5 0x01248a37 dart::BackgroundCompilerTask::Run()
#6 0x0112203a dart::ThreadPool::Worker::Loop()
#7 0x01121efe dart::ThreadPool::Worker::Main(unsigned int)
#8 0x01089e73 dart::ThreadStart(void*)
#9 0xf774ff72 start_thread
#10 0xf753143e __clone
Original change's description:
> [VM] Add @pragma annotations on Field, make @pragma annotations work generally
>
> Currently the @pramga('vm:exact-result-type') annotation only works if
> the function is a recognized method. This change changes that to make
> the VM just look if a function has the annotation (no matter if it's
> also in the list of recognized methods or not).
>
> Furthermore this CL adds a "has_pragma" bit to [Field] objects, similar
> to how we have it on [Function]/[Class]es. This allows annotating
> fields with types, as we do with function return types.
>
> Furthermore this CL lets the type propgagator use
> @pragma('vm:exact-result-type') annotations to narrow the [CompileType]
> set on [LoadFieldInstr]s.
>
> Since the @pragma is a general feature, this CL moves the
> `Function::FindPragma()` to `Library::FindPragma` (which is where any
> other metadata lookup happens). We also let the `FindPragma` accept any
> of Class/Function/Field objects.
>
> Furthermore this CL adds a bailout if we try to evaluate metadata in
> the background compiler, since the background compiler is not allowed
> to execute generated code. The bailout should trigger a re-compilation
> on the mutator thread.
>
> Furthermore the `FindPragma()` function is fixed to handle the case
> when the evaluation of the metadata results in e.g. a language error.
> In this case we simply claim to not have found a pragma annotation.
>
> Issue https://github.com/dart-lang/sdk/issues/31954
>
> Change-Id: I0900a80d5ae0f3e8d09baf13cba1b20dd974df31
> Reviewed-on: https://dart-review.googlesource.com/c/84037
> Commit-Queue: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
TBR=vegorov@google.com,kustermann@google.com,alexmarkov@google.com,sjindel@google.com
Change-Id: Ic0d22d32b0eea3a76ec245cabab0006f97ca1b05
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/84622
Reviewed-by: Martin Kustermann <kustermann@google.com>
Currently the @pramga('vm:exact-result-type') annotation only works if
the function is a recognized method. This change changes that to make
the VM just look if a function has the annotation (no matter if it's
also in the list of recognized methods or not).
Furthermore this CL adds a "has_pragma" bit to [Field] objects, similar
to how we have it on [Function]/[Class]es. This allows annotating
fields with types, as we do with function return types.
Furthermore this CL lets the type propgagator use
@pragma('vm:exact-result-type') annotations to narrow the [CompileType]
set on [LoadFieldInstr]s.
Since the @pragma is a general feature, this CL moves the
`Function::FindPragma()` to `Library::FindPragma` (which is where any
other metadata lookup happens). We also let the `FindPragma` accept any
of Class/Function/Field objects.
Furthermore this CL adds a bailout if we try to evaluate metadata in
the background compiler, since the background compiler is not allowed
to execute generated code. The bailout should trigger a re-compilation
on the mutator thread.
Furthermore the `FindPragma()` function is fixed to handle the case
when the evaluation of the metadata results in e.g. a language error.
In this case we simply claim to not have found a pragma annotation.
Issue https://github.com/dart-lang/sdk/issues/31954
Change-Id: I0900a80d5ae0f3e8d09baf13cba1b20dd974df31
Reviewed-on: https://dart-review.googlesource.com/c/84037
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Also, remove paranoid checks from ProfilerDartStackWalker by
- setting the VM tag to Dart only after initializing the exit slot
- setting the VM tag to Runtime for leaf runtime function
- bailing out when in the prologue of the invocation stub's callee
Change-Id: Ifd1caee2203f8863b17fc7d0072de32290fd0e60
Reviewed-on: https://dart-review.googlesource.com/c/84140
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Régis Crelier <regis@google.com>