There already exists a class named "Reader" in the "kernel" namespace
which reads bytes from a kernel binary. The class KernelLoader
(KernelReader before this change) creates VM heap objects and populates
them.
R=kmillikin@google.com
Review-Url: https://codereview.chromium.org/3010543002 .
Summary:
1. Previously, in 'BuildGraphOfConvertedClosureFunction', the VM was unable to
correctly forward parameters to converted closure functions when
they were captured in the converted function's body. This could happen when, for
example, a closure was introduced into it by async conversion.
Now, this is fixed by an approach that mirrors the technique in
'BuildGraphOfFunction'.
2. Previously, local variables declared inside loop bodies were being saved in
the loop's enclosing context, so closures within the loop would see new
values initialized to the variable in subsequent iterations.
Now, this is fixed by creating nested contexts for all loops, regardless of
whether the loop variables are captured.
3. Previously, arity checks were not being performed on converted closures, so
they could be called with too few or too many arguments. In the former case, the
missing arguments would be filled in with garbage on the stack.
Now, the assembly generation in 'CompileGraph' inserts argument count checks
for converted closures as well as regular closures.
Test Plan:
Introduced new tests in the closure conversion suite to test each bug:
1. syncstart.dart
2. loop2.dart, blocks.dart, updated for_in_closure.dart
3. arity.dart
With these changes, closure conversion passes all co19 tests in non-checked mode, except those that are not passed without it:
python tools/test.py -m release -c dartk --vm-options "--reify --reify_generic_functions" co19
BUG=
R=dmitryas@google.com
Review-Url: https://codereview.chromium.org/3000333002 .
The Kernel C++ implementation no longer has classes like Library,
Class, Field, or String, so it's no longer necessary to explicitly
write `dart::` in most places.
BUG=
R=jensj@google.com
Review-Url: https://codereview.chromium.org/3001103002 .
Summary:
Previously, there was no support for generic methods in kernel. This prevented
us from being able to pass captured type arguments to the target top-level
function in converted closures, so these type arguments were always instantiated
to 'dynamic'.
Now, we save the type arguments to the closure creation operation in the
context, and read them out and forward them appropriately in closure wrapper
function. Since fasta doesn't currently support generic methods (their type
parameters are replaced by 'dynamic'), only top-level generic functions can
surface in kernel, as they are generated by closure conversion of closures that
capture type parameters of a class.
My focus here is enabling closure conversion to work in only these cases, and as
such, the code has some temporary "hacks" in the VM that may not work for
generic member functions or generic closures when they are enabled in fasta.
Test Plan:
I ran all the tests in closures/, and those which were previously expected to
crash due to missing VM support now pass and produce correct results.
Further testing is paused until we understand why the recent commit "[kernel]
Insert kernel bodies into VM heap" has broken all these tests.
Reviewers: regis@google.com, jensj@google.com, dmitryas@google.com
BUG=
R=dmitryas@google.com, jensj@google.com
Review-Url: https://codereview.chromium.org/2998803002 .
Summary:
Previously, we had asserts in the kernel flowgraph builder than assumed
redirecting initializers were not accompanied by any other initializers. This
was to prevent the presence of field initializers alongside them.
Now, we allow (only) local initializers to appear with redirecting initializers
because it's safe and necessary for closure conversion.
Test Plan:
Re-ran pkg/kernel/test/closures_type_vars/suite.dart and
pkg/kernel/test/closures/suite.dart -- all tests pass again.
BUG=
R=jensj@google.com
Review-Url: https://codereview.chromium.org/2992323002 .
This CL copies the kernel bodies for all functions and
fields into the VM heap. The function bodies in the VM
heap are then used when compiling the flowgraphs.
This theoretically means that the malloc'd data can be
freed and that snapshotting from kernel could possibly
work, though it hasn't been tested.
R=kmillikin@google.com
Review-Url: https://codereview.chromium.org/2972343002 .
Prior to this CL we carried around information about the containing class
and member, both of which was fetched by reading out-of-line in the binary
(i.e. while reading the current member, start reading something from the
parent member etc).
It had also required the introduction of extra fields in the kernel
binary file (dill file).
This CL cleans that up, by
a) Setting type parameters on functions as needed (in kernel_reader.cc)
b) Using the VM Class and VM Function to get the required information
(with a above the information is all available).
(in kernel_binary_flowgraph.cc.) This means that
c) We don't have to read the binary out-of-line (for TypeParameterType
to work at least), and that
d) We can remove the previously introduced extra fields from the
kernel binary file (dill file).
R=dmitryas@google.com, kmillikin@google.com
Review-Url: https://codereview.chromium.org/2973633002 .
Attempt to use the helper functions to minimize the number of places
that would need updating should the binary file (the dill file) layout
change.
The changed code (in FieldHelper) makes assumptions about the layout of
the FunctionNode. Instead use FunctionNodeHelper to get the wanted data.
Also replaced an unconditional read-and-go-back with the usage of
AlternativeReadingScope.
BUG=
R=sivachandra@google.com
Review-Url: https://codereview.chromium.org/2991233002 .
The closure-conversion transformation is not enabled yet. This commit
only adds the support for it to FlowGraphBuilder and
StreamingFlowGraphBuilder. More work should be done before enabling the
transformation; most mportantly, the 'platform.dill' file that is used
in the Kernel isolate and is loaded by VM for linking with executed
programs should be separated. The former should receive a file not
touched by the transformation, and the latter should receive a
transformed one.
BUG=
R=jensj@google.com, karlklose@google.com, kustermann@google.com
Review-Url: https://codereview.chromium.org/2891053003 .
Currently we run execute "library.AddFieldMetadata",
"library.AddFunctionMetadata" etc for all fields and methods,
even if they do not contain any annotations
(which is what will eventually be extracted from it if ever used).
This CL changes that to only execute the "AddXMetadata" if there
are any annotations.
This saves the VM from creating strings and fields that aren't really
used anyway, while - as before - returning an empty array when
answering a request for metadata for something without any.
BUG=
R=kmillikin@google.com
Review-Url: https://codereview.chromium.org/2979653002 .
Currently some tests pass in checked mode but fails in non-checked mode
because we don't check the result of a constant-evaluation that should
be bool in non-checked mode.
This CL changes it so we always check the bool result in the constant-evaluator.
BUG=
R=kustermann@google.com
Review-Url: https://codereview.chromium.org/2956493003 .
Mostly stream kernel_reader, i.e. the code that sets up the libraries,
classes, methods etc.
Mostly because it still takes a "Program" ast node, and looks at the
"Library" ast nodes to get their kernel offset in the binary.
Currently the scripts (containing breakable points etc) are also created
from the ast nodes.
The rest is now streamed.
This also means that more ast visitors could be deleted.
R=kmillikin@google.com
Review-Url: https://codereview.chromium.org/2931813002 .
- Add TokenPosition to AllocateObject
meaning that kernel more often has a TokenPosition available.
This might influence profiling, especially it influences some
of the vm/cc/Profiler* tests.
- Update profiler_service to also be able to find the current token
via kernel (as opposed to either returning NULL or crashing).
This makes use of the source code included in the kernel file.
BUG=
R=kmillikin@google.com, vegorov@google.com
Review-Url: https://codereview.chromium.org/2944433003 .
Refactorings.
Mostly about only reading FunctionNode one place by introducing a
helper class that will read and skip what it is told.
For 'nested' things inside the function node (e.g. the body),
the caller for the helper still needs to handle it if it shouldn't
just be skipped.
'Non-nested' things (e.g. integers) are saved and can be fetched
by the caller.
R=kmillikin@google.com
Review-Url: https://codereview.chromium.org/2921613003 .
- Put pointer to kernel data into Script.
- Replace function.kernel_function pointer to AstNode with
kernel_offset():
- Replace field.kernel_field pointer to AstNode with kernel_offest().
- Stream the previously unstreamed AstNodes: FunctionDeclaration and
FunctionExpression.
- Move special handling for _buildin.getMainClosure into the streaming
flowgraph builder.
- Delete big parts of kernel_to_il.
R=kmillikin@google.com
Review-Url: https://codereview.chromium.org/2901533002 .
This CL allows for streaming big parts of the binary,
i.e. without using the AST nodes.
It is thus a stepping-stone in getting rid of the AST nodes in the VM.
Generally, all Expressions except "FunctionExpression",
and all Statements except "FunctionDeclaration" can be streamed.
There are currently not streamed because they create new functions,
which has a pointer to an AstNode (which we don't have when streaming).
Once we no longer need AstNodes at all these can be streamed as well.
This is, I think, mostly a matter of streaming the ScopeBuilder as well,
something that is not currently done.
The way the streaming is build, one has to stream an entire subtree.
That means, that if an expression (or statement), A, that is generally
streamable contains an expression or a statement, B, that is not streamable,
A cannot be streamed.
The way this is build is by marking AstNodes as streamable or not
("cannot_stream_" field). That way we know up front whether we can stream
a subtree or not.
The streaming is done via "kernel_binary_flowgraph".
In this file there are many obvious comments, e.g.
```
TokenPosition position = ReadPosition(); // read position.
```
This has been done in an attempt to add a comment to everything that
reads from the binary to make it stand out more.
All changes from kernel_to_il up to and including May 2nd 2017
should be included.
R=kmillikin@google.com
Review-Url: https://codereview.chromium.org/2854393002 .
In the VM's Kernel representation, introduce wrapper classes for
string and name indexes so it is obvious which one is which. For
convenience there is an implicit conversion so that they can each be
used where an int is allowed. However, there is no implicit
conversion _to_ either of these types.
BUG=
R=vegorov@google.com
Review-Url: https://codereview.chromium.org/2860823002 .
The canonical name table is copied into a typed data array in the VM's
heap. The encoding is the same as in the binary except that the
integer indexes are fixed-size.
Canonical names are now integer indexes instead of objects allocated
in the C++ heap.
BUG=
R=jensj@google.com, vegorov@google.com
Review-Url: https://codereview.chromium.org/2853423002 .
Copy the Kernel string offsets into a uint32 array in the VM's heap.
This avoids allocating small string objects with new and avoids having
a table of the canonical strings.
Instead of an offset and a size, strings are now represented as
indexes into the string table in the heap. The start offset of string
N is found at byte offset N*4 because it is a uint32, and the end
offset is found at byte offset (N+1)*4. The strings themselves are
just integer indexes instead of pointers.
In the stream flow graph builder, string access is all random access.
R=jensj@google.com, vegorov@google.com
Review-Url: https://codereview.chromium.org/2852943003 .
Instead of a list of strings given by their length and UTF-8 encoding,
restructure the string table to consist of a list of string ending
offsets followed by a blob of UTF-8 encoded strings without lengths.
This is a step toward copying the string blob into the VM's heap and
building a heap-allocated structure to give random access to them.
BUG=
R=asgerf@google.com, jensj@google.com
Review-Url: https://codereview.chromium.org/2790073004 .