Commit Graph

26 Commits

Author SHA1 Message Date
Alexander Markov b97f885d1d Revert "[vm] Deep clone context when cloning closure"
This reverts commit 61b5ba7ecf.

Reason for revert: found a counter-example for deep cloning: https://dart-review.googlesource.com/c/sdk/+/70681

Original change's description:
> [vm] Deep clone context when cloning closure
> 
> _SyncIterable::iterator clones unerlying sync* closure to create a new
> Iterator using _Closure._clone(). _Closure._clone() was cloning only
> 1 level of context, relying on a particular context structure.
> 
> In bytecode, contexts are allocated in a different way, so sync*
> functions could have more then 1 level of contexts. In such case,
> parent contexts were not cloned in _Closure._clone() and were shared
> between Iterator instances.
> 
> This CL adds deep cloning of contexts into _Closure._clone() native method
> in order to handle arbitrary number of levels of contexts in a closure.
> 
> Fixes language_2/syncstar_yield_test test in bytecode mode.
> 
> Change-Id: Ic5ced4c32fc2e21726db76608cd3a7db7e553472
> Reviewed-on: https://dart-review.googlesource.com/70600
> Reviewed-by: Régis Crelier <regis@google.com>
> Commit-Queue: Alexander Markov <alexmarkov@google.com>

TBR=rmacnak@google.com,alexmarkov@google.com,regis@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I9f6116069cbec022ad86ef4cbf6801c603b4ab15
Reviewed-on: https://dart-review.googlesource.com/70700
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2018-08-20 18:30:12 +00:00
Alexander Markov 61b5ba7ecf [vm] Deep clone context when cloning closure
_SyncIterable::iterator clones unerlying sync* closure to create a new
Iterator using _Closure._clone(). _Closure._clone() was cloning only
1 level of context, relying on a particular context structure.

In bytecode, contexts are allocated in a different way, so sync*
functions could have more then 1 level of contexts. In such case,
parent contexts were not cloned in _Closure._clone() and were shared
between Iterator instances.

This CL adds deep cloning of contexts into _Closure._clone() native method
in order to handle arbitrary number of levels of contexts in a closure.

Fixes language_2/syncstar_yield_test test in bytecode mode.

Change-Id: Ic5ced4c32fc2e21726db76608cd3a7db7e553472
Reviewed-on: https://dart-review.googlesource.com/70600
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2018-08-17 22:28:51 +00:00
Martin Kustermann cf1de7d46c [VM] Replace hand-written assembly prologues with IR
As part of the prologue changes we get rid of the empty context as well.

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

Change-Id: I707e23c631bcfbbad6c91c4963d0c10f7a0be625
Reviewed-on: https://dart-review.googlesource.com/25320
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-12-13 16:04:34 +00:00
Vyacheslav Egorov 8a179fb953 [VM, Compiler] Move compiler to a separate folder.
New folder structure (nested under vm/):

- compiler/
-   jit/         - JIT specific code
-   aot/         - AOT specific code
-   backend/     - all middle-end and back-end code (IL, flow graph)
-   assembler/   - assemblers and disassemblers
-   frontend/    - front ends (AST -> IL, Kernel -> IL)

compiler/README.md would be the documentation root for the compiler
pipeline

Bug: https://github.com/dart-lang/sdk/issues/30575
Change-Id: I2dfd9688793bff737f7632ddc77fca766875ce36
Reviewed-on: https://dart-review.googlesource.com/2940
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
2017-09-04 15:15:18 +00:00
Alexander Markov bda3c9c2b2 Simplify and fix implicit closure check, speed up Closure_equals, v2
This is the re-application of 44e8da3ecd
with fixes:
* Dartanalyzer error is fixed in the new test isolate/message4_test
* The new test is skipped in the status file in dart2j/non-d8 modes,
  issue #30247 is created.
* Minor tweak of Closure_equals: other.IsClosure() is tested earlier.

Original CL review:

https://codereview.chromium.org/2989493002/

Original CL description:

This CL introduces a new Function kind, kImplicitClosureFunction, in
order to simplify check for implicit closures and make it more
efficient.

This CL also fixes Function::IsImplicitStaticClosureFunction(RawFunction*)
to correctly handle implicit closures created from static native
functions.

Closes #30203.

As the result of a faster check for implicit closures and slight
refactoring of Closure_equals, micro-benchmark exercising Closure_equals
speeds up from 9618ms to 6700ms for implicit closures case and
insignificantly for other cases.

R=zra@google.com

Review-Url: https://codereview.chromium.org/2987703002 .
2017-07-24 09:43:52 -07:00
Alexander Markov 45dddb2807 Revert "Simplify and fix implicit closure check, speed up Closure_equals"
This reverts commit 44e8da3ecd.

R=zra@google.com

Review-Url: https://codereview.chromium.org/2984083002 .
2017-07-21 15:39:20 -07:00
Alexander Markov 44e8da3ecd Simplify and fix implicit closure check, speed up Closure_equals
This CL introduces a new Function kind, kImplicitClosureFunction, in
order to simplify check for implicit closures and make it more
efficient.

This CL also fixes Function::IsImplicitStaticClosureFunction(RawFunction*)
to correctly handle implicit closures created from static native
functions.

Closes #30203.

As the result of a faster check for implicit closures and slight
refactoring of Closure_equals, micro-benchmark exercising Closure_equals
speeds up from 9618ms to 6700ms for implicit closures case and
insignificantly for other cases.

R=zra@google.com

Review-Url: https://codereview.chromium.org/2989493002 .
2017-07-21 14:26:56 -07:00
Alexander Markov 203955bc48 Reapply "Improve hashCode for closure objects" with fixes.
This CL includes the following fixes:
* Fix for incorrect non-nullable assumption about _Closure._hash field.
* Add error handling into BecomeMapTraits::Hash.
* Correct assertions for validating layout of Closure objects.
* Add identityHashCode to the list of VM entry points in precompiler.

Closes #30211.

Original code review:

https://codereview.chromium.org/2983823002/

Original CL description:

This performance improvement is inspired by Flutter listeners stored in
the HashSet (see ObserverList) and frequently checked using
HashSet.contains(). If there are many such listeners and they are
implicit instance closures (for example, created by
'new Listenable.merge(...)'), HashSet.contains() becomes very slow.
It spends a lot of time in Closure_equals native method due to hash
collisions between closure objects with same function
but different receivers.

This CL improves hashCode() calculation for implicit instance closures
by mixing function hashcode with identity hashcode of the receiver.
For explicit closures and static implicit closures hashCode() is
improved by using identityHashCode() of a closure object.

Also, hashcode is calculated once and cached in each closure instance.
The size of a closure instance doesn't grow up because there was unused
word-size padding both on 32-bit and 64-bit architectures.

The execution time of the following micro-benchmark is reduced from
47665ms to 135ms on my Linux/x64 box.

-------------------------------------

import "dart:collection";

class Foo {
  int _a;
  Foo(this._a);
  void bar() {}
}

main() {
  HashSet hs = new HashSet();
  for (int i = 0; i < 1000; ++i) {
    hs.add(new Foo(i).bar);
  }

  var watch = new Stopwatch()..start();

  for (int i = 0; i < 1000; ++i) {
    for (var c in hs) {
      hs.contains(c);
    }
  }

  int time = watch.elapsedMilliseconds;
  print("Time: ${time}ms\n");
}

-------------------------------------

R=zra@google.com

Review-Url: https://codereview.chromium.org/2988493002 .
2017-07-20 15:22:18 -07:00
Alexander Markov 51d580d8bf Revert "Improve hashCode for closure objects"
This reverts commit b1197eb714.

Revert "Correct assertions for validating layout of Closure objects"

This reverts commit b1215faa59.

Revert "Add identityHashCode to the list of VM entry points in precompiler"

This reverts commit e1d04cc242.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2983973002 .
2017-07-20 08:34:28 -07:00
Alexander Markov b1197eb714 Improve hashCode for closure objects
This performance improvement is inspired by Flutter listeners stored in
the HashSet (see ObserverList) and frequently checked using
HashSet.contains(). If there are many such listeners and they are
implicit instance closures (for example, created by
'new Listenable.merge(...)'), HashSet.contains() becomes very slow.
It spends a lot of time in Closure_equals native method due to hash
collisions between closure objects with same function
but different receivers.

This CL improves hashCode() calculation for implicit instance closures
by mixing function hashcode with identity hashcode of the receiver.
For explicit closures and static implicit closures hashCode() is
improved by using identityHashCode() of a closure object.

Also, hashcode is calculated once and cached in each closure instance.
The size of a closure instance doesn't grow up because there was unused
word-size padding both on 32-bit and 64-bit architectures.

The execution time of the following micro-benchmark is reduced from
47665ms to 135ms on my Linux/x64 box.

-------------------------------------

import "dart:collection";

class Foo {
  int _a;
  Foo(this._a);
  void bar() {}
}

main() {
  HashSet hs = new HashSet();
  for (int i = 0; i < 1000; ++i) {
    hs.add(new Foo(i).bar);
  }

  var watch = new Stopwatch()..start();

  for (int i = 0; i < 1000; ++i) {
    for (var c in hs) {
      hs.contains(c);
    }
  }

  int time = watch.elapsedMilliseconds;
  print("Time: ${time}ms\n");
}

-------------------------------------

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

Review-Url: https://codereview.chromium.org/2983823002 .
2017-07-19 14:36:42 -07: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
Régis Crelier 9aafded095 Pass type argument vector to generic functions (if --reify-generic-functions is
true, still false per default).
Work in progress, not functional yet (passed vector is still ignored in callee).

R=vegorov@google.com, zra@google.com

Review-Url: https://codereview.chromium.org/2859673002 .
2017-05-18 14:03:47 -07:00
Régis Crelier fd5089c9e8 Remove parent_level field of function type parameters.
Add function_type_arguments field in closure instances.
Lots of other smaller changes, also related to generic function semantics.
This is still work in progress, with a change of direction in the design:
The type argument vector of a generic function will be prepended with the type
arguments of enclosing generic functions. The re-allocation and concatenation
will be done in nested generic function's prolog. This will greatly simplify
instantiation of types at run time without having to search the context for
parent function's type arguments. However, a closure instance now requires an
additional field. On the other hand, type parameters do not require a
parent_level field anymore.

R=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2818273002 .
2017-04-17 08:58:24 -07:00
Regis Crelier 269aaf0305 Properly handle instantiator when allocating or cloning closure instance.
This should fix the vm-kernel bots.

Review-Url: https://codereview.chromium.org/2723643002 .
2017-02-27 14:51:27 -08:00
Florian Schneider 7615e899be Cache hash code for closures.
Computing the hash code for closures is fairly expensive since
it involves the function name and signature strings.

This CL caches the hash code in the ClosureData object.

Fixes #28161.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2598623002 .
2016-12-23 11:39:23 +01:00
Zachary Anderson 2e4dfd3a2d clang-format runtime/lib
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2468093007 .
2016-11-04 12:14:41 -07:00
Ryan Macnak d37ea681f5 RELOAD: Check if an implicit closure needs rebinding at compile time and adjust closure equality.
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2187433006 .
2016-07-27 16:51:11 -07: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
koda@google.com 92a8c39d3c Keep zone cached in SnapshotReader to allow removing ZoneHandle(Isolate*) interface.
Add a StackZone around API snapshot reading call.
Also remove CheckedHandle(Isolate*) interface by migrating its users to Zone*.

R=asiva@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44580 260f80e4-7a28-3924-810f-c04153c831b5
2015-03-19 17:42:40 +00:00
hausner@google.com 2487c76886 Add support for sync* and yield and yield*
R=srdjan@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43516 260f80e4-7a28-3924-810f-c04153c831b5
2015-02-05 18:36:40 +00:00
fschneider@google.com b26ff22adf Allocation sinking for contexts.
Improved aliasing computation in presence of Redefinition and AssertAssignable.

Added possibility for inlining annotations via --enable-inlining-annotations flag.

R=vegorov@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@41713 260f80e4-7a28-3924-810f-c04153c831b5
2014-11-13 13:53:58 +00:00
fschneider@google.com a329b0e6bc Dart VM: Simplify code generation for equality operators.
By inserting the necessary checks for null inside the callee
at the AST level, the code generation of == operations can be
greatly simplified.

This is a performance-neutral change and a step for allowing
generic inlining of arbitrary == methods. So far we could only
inline them for a common set of types in the flow graph
optimizer.

R=srdjan@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@28084 260f80e4-7a28-3924-810f-c04153c831b5
2013-10-01 10:10:50 +00:00
fschneider@google.com 447ddebd68 Fix equality of implicit closures in the Dart VM.
This CL also lifts the restriction that classes could not
extends or implement 'Function'.

BUG=https://code.google.com/p/dart/issues/detail?id=10849
BUG=https://code.google.com/p/dart/issues/detail?id=12411

TEST=tests/language/bound_closure_equality_test.dart,
tests/language/black_listed_test.dart

R=iposva@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26114 260f80e4-7a28-3924-810f-c04153c831b5
2013-08-14 11:43:50 +00:00
regis@google.com 163db76189 Hook up simulator (if needed) when calling Dart code.
Merge identical InvokeDynamic and InvokeStatic to InvokeFunction.
Remove redundant argument from InvokeClosure.
Review URL: https://codereview.chromium.org//12315087

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@18994 260f80e4-7a28-3924-810f-c04153c831b5
2013-02-25 19:30:29 +00:00
asiva@google.com 2c6de68680 Changed the API in DartEntry for invoking dart code from C++ to make it more compatible with the requirements of the runtime.
Deleted all the code duplication that was added to circumvent the old DartEntry API requirements.
Review URL: https://codereview.chromium.org//11613009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16288 260f80e4-7a28-3924-810f-c04153c831b5
2012-12-18 21:36:01 +00:00
regis@google.com 849585ef7c Implement Function.apply in vm (issue 5670).
Fix a closure parameter count check bug (unveiled by an apply test).
Review URL: https://codereview.chromium.org//11564029

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16175 260f80e4-7a28-3924-810f-c04153c831b5
2012-12-14 19:04:01 +00:00