Commit graph

24 commits

Author SHA1 Message Date
Vyacheslav Egorov a2ab7ccea4 [vm] Avoid UB in FinalizeHash(hash)
FinalizeHash(hash) was trying to avoid UB in expression 1 << 32
by casting 1 to uintptr_t. This type however is not wide enough
on 32-bit platforms.

Instead just use explicit comparison hashbits < kBitsPerInt32 to
avoid overflow in left shift.

This bug went unnoticed for a while because it the only place
where we call FinalizeHash(hash) is in the snapshot profile
writer code and it only triggers when gen_snapshot is a
32-bit binary - which is only true on Windows, as Mac and Linux
seem to use simarm_x64 configuration instead.

This UB was explicitly affecting the code behavior because C++
compiler would either optimize out or change behavior of any
code that consumed value produced by FinalizeHash(hash).

Fixes https://github.com/flutter/flutter/issues/97764

TEST=vm/cc/DirectChainedHashMap

Change-Id: I39f2b09e7516c875b765e5a065d1c1331f89fa33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250741
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2022-07-06 12:48:16 +00:00
Tess Strickland b9b1ea6b5d [vm] Refactor hash maps with T* keys where T <: Object.
Rename PointerKeyValueTrait<T>, which is used to create sets of pointers
to T instances where T <: Object and T has appropriate Hash and Equals
instance methods, to the more specific name PointerSetKeyValueTrait.

Create a PointerSet<T> alias for using this trait with
DirectChainedHashMap and use that alias in other code as a shorthand.

Remove PointerSetKeyValueTrait<const char> as a superclass of
CStringKeyValueTrait, as the only reuse from the former are the two
methods KeyOf and ValueOf which just return their argument, and having
this relationship is odd since const char is not a subtype of Object.

TEST=Renaming/refactoring, so existing tests.

Change-Id: I0274b16cb9fcb3939a28fb109fb8626c1ac8c0e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215761
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-10-07 06:43:53 +00:00
Tess Strickland 6c8f4aa190 Reland "[vm] Fix V8 snapshot profile handling of the dispatch table."
This is a reland of 5909fd111d

Does a large refactoring on the V8 snapshot profile writer
to clean things up, add more debugging support, and to fix
the problems that surfaced during the original landing.

Other changes:

Changes Serializer::CreateArtificialNodeIfNeeded() to create
artificial nodes for Code objects and immutable arrays.

Fixes CodeSerializationCluster::Trace() to only push needed parts of
discarded code objects, instead of tracing them like full code objects.

Adds test cases to v8_snapshot_profile_writer_test that exercise
the following situations (both separately and together):

* Non-symbolic stack traces are enabled and code and function objects
  are dropped when not needed at runtime.

* Creation of the dispatch table is disabled.

TEST=vm/dart{,_2}/v8_snapshot_profile_writer_test

Original change's description:
> [vm] Fix V8 snapshot profile handling of the dispatch table.
>
> Fixes https://github.com/dart-lang/sdk/issues/45702.
>
> TEST=Tests listed in the issue above.
>
> Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
> Change-Id: Ibf5e3ccf3828c01f9dda47de360314dabe8cb8a9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195272
> Reviewed-by: Daco Harkes <dacoharkes@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

Change-Id: I8e7030267fe190079a8f68d00fe20bf7170e5719
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-obfuscate-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195513
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2021-04-20 11:17:36 +00:00
Tess Strickland e0bfa18c7c [vm] Standardize equality instance methods in C++.
In the codebase, we have several different interfaces for equality
instance methods on a type T:

- bool Equals(const T&) const;
- bool Equals(const T*) const;
- bool Equals(T*) const;

This CL standardizes on `bool Equals(const T&) const;`, and adjusts any
related functions to match.

TEST=Existing test suites, as this is an internal refactoring.

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Change-Id: I2ebcf2b861732ce65c6f1c673b2df2a2c7f5dd4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195071
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2021-04-14 16:20:25 +00:00
Tess Strickland 0f8861e3ba [vm] Standardize hashing instance methods in C++.
In the codebase, we have several different interfaces for instance
methods that return a hash:

- uword Hash() const;
- intptr_t Hash() const;
- uint32_t Hash() const;
- intptr_t Hashcode() const;

This CL standardizes on `uword Hash() const` and adjusts any related
functions to match.

TEST=Existing test suites, as this is an internal refactoring.

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Change-Id: If2cbce57f3fae0f0d24031b6e324f0323c965f41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195067
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-04-14 10:04:48 +00:00
Tess Strickland 7ba7d65e5b [vm/compiler] Print retained functions when tracing precompiler.
To get this information, enable --trace-precompiler.

There are two version of the output: a human readable version
and a JSON version (preceded by 'JSON for function decisions:')
for easier tabulation. The JSON version is an array of objects,
where the fields of the object are as follows:

* name: a string, the function name
* kind: a string, the function kind
* retained: a boolean, whether the function was retained
* reasons: an array of strings, reasons for retaining
  (only for retained objects)

TEST=vm/dart{,_2}/use_trace_precompiler_flag_test.dart

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try
Change-Id: I9b006a49e1410a832950a1bd29a0abaabe9431f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190000
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-10 08:21:58 +00:00
Alexander Markov a170fc54b9 [vm] Fix DirectChainedHashMap iterator
BaseDirectChainedHashMap<KeyValueTrait, B, Allocator>::Iterator::Next()
was first checking if array_index_ is larger than the size of map's array,
and only then it was looking at remaining entries in the collision list.

So, when there is a collision in the last bucket, array_index_ was bumped
and the first entry in the list was returned. After that, Next() returned
NULL, skipping remaining entries in the collision list.

This caused incorrect stack state management in BytecodeFlowGraphBuilder
and BytecodeFlowGraphBuilder::DropUnusedValuesFromStack() was removing
too many entries from the stack, which caused crash in
BytecodeFlowGraphBuilder::BuildStoreIndexedTOS().

Issue: https://github.com/dart-lang/sdk/issues/38979
Change-Id: Ie073ca7014da5b04999b7984d508984b4c9743b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122176
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-21 18:30:54 +00:00
Teagan Strickland 7c6cab995a [vm] Adds Update method to hash maps.
The Insert method runs in constant time, but inserting multiple
pairs with the same key results in all pairs being added to the
map. Remove only removes the most recent pair with a key equal
to its argument, so this means calling Remove after an Insert
does not guarantee that Lookup for a key will fail.

The new Update method, when used instead of Insert, guarantees
that the map contains at most one pair for a set of equal keys.
This means that Lookup is guaranteed to fail after a Remove
call, but the Update method requires walking the existing
chain of entries for the key's hash value.

(In practice, our code tends to call Lookup before Insert to
avoid adding pairs with equal keys more than once, but this
practice does mean that updating the value returned by Lookup
cannot be done without first removing the old entry. This new
method simplifies that workflow if used consistently.)

Change-Id: I2944472a7fc74c1de41cb25eb9469a7c7e491ceb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114069
Commit-Queue: Teagan Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-08-27 10:00:18 +00:00
Teagan Strickland 6c67280e44 [vm] Move C-string-based hash maps to hash_map.h.
Fixes assumption about pointer equality of keys.

Adds comment to document current assumption that multiple pairs
with equivalent keys are not inserted.

Change-Id: Ieb17d1b357f903dcc09274ac648c1a97e7ee85d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113686
Commit-Queue: Teagan Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-08-27 09:52:13 +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
Ben Konyi f679b3c3e5 Reintroducing MallocHooks changes with fix for hooks being called when in execvpe after a fork while the MallocHooks lock is held by a thread that may no longer exist.
BUG=
R=zra@google.com

Review-Url: https://codereview.chromium.org/2647283004 .
2017-01-30 09:55:20 -08:00
Zach Anderson 7730809f36 Revert "Reintroducing MallocHooks changes with fix for infinite loop in MallocHooks on Platform::Exit."
This reverts commit 7bf5d87017.

The lock introduced by this change in MallocHooksState is held across
a fork(), which causes deadlock in the child when execvpe() fails and
tries to acquire the lock when freeing memory.

Review-Url: https://codereview.chromium.org/2647793005 .
2017-01-20 23:52:31 -08:00
Ben Konyi 7bf5d87017 Reintroducing MallocHooks changes with fix for infinite loop in MallocHooks on Platform::Exit.
BUG=
R=zra@google.com

Review-Url: https://codereview.chromium.org/2643303003 .
2017-01-20 15:26:58 -08:00
Ben Konyi c9a4374ed9 Revert "Implemented basic heap memory allocation tracking in MallocHooks using hooks registered with tcmalloc. Also updated BUILD.gn files to account for include paths within the tcmalloc project."
This reverts commit 5290052550.

Revert "Fixed segfault in Remove method."

This reverts commit 203f1ba222.

BUG=
TBR=zra@google.com

Review-Url: https://codereview.chromium.org/2647763003 .
2017-01-19 15:17:29 -08:00
Ben Konyi 5290052550 Implemented basic heap memory allocation tracking in MallocHooks using hooks registered with tcmalloc. Also updated BUILD.gn files to account for include paths within the tcmalloc project.
Fixed build issues from original submission.

BUG=
R=zra@google.com

Review-Url: https://codereview.chromium.org/2623613003 .
Review-Url: https://codereview.chromium.org/2644903003 .
2017-01-19 13:15:56 -08:00
Ben Konyi 10686766cd Revert "Implemented basic heap memory allocation tracking in MallocHooks using hooks registered with tcmalloc. Also updated BUILD.gn files to account for include paths within the tcmalloc project."
This reverts commit bcd7ba1056.

TBR=zra@google.com

BUG=

Review-Url: https://codereview.chromium.org/2645973002 .
2017-01-19 12:14:19 -08:00
Ben Konyi bcd7ba1056 Implemented basic heap memory allocation tracking in MallocHooks using hooks registered with tcmalloc. Also updated BUILD.gn files to account for include paths within the tcmalloc project.
BUG=
R=zra@google.com

Review-Url: https://codereview.chromium.org/2623613003 .
2017-01-19 12:09:07 -08: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
Zachary Anderson e933f28a18 Remove some uses of STL map.
This CL removes the use of STL map from freelist.cc by adding
MallocDirectChainedHashMap in hash_map.h and adding an iterator for
BaseDirectChainedHashMap there.

It also removes a use of STL map from hash_table.h that was dead code.

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2083103002 .
2016-06-22 08:32:37 -07:00
vegorov@google.com 55c9c6c444 Allow bound check elimination to eliminate checks when both array length and index boundaries are expressed through the same symbol.
For example:

var list = new List(n);
for (var i = 0; i < n; i++) list[i];

R=fschneider@google.com
BUG=

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14293 260f80e4-7a28-3924-810f-c04153c831b5
2012-10-30 16:26:46 +00:00
fschneider@google.com 323e06222e Reland "Add a simple dominator based redundancy elimination" and fix a register allocation bug.
Original CL: http://codereview.chromium.org/10872035/

It enables elimination of redundant expressions across
basic blocks.

Currently used for smi checks and class checks, but will
be extended to other expressions in a separate CL.


Additionally, this fixes a bug in the register allocator where
a blocked register was illegally assigned to an unallocated live range.

It also fixes a Mac compiler issue with the constructor of
DirectChainedHashMap.
Review URL: https://chromiumcodereview.appspot.com//10871060

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11302 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-24 11:10:36 +00:00
fschneider@google.com 212c5a4994 Revert my last change r11227.
TBR=kmillikin@google.com
Review URL: https://chromiumcodereview.appspot.com//10871040

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11229 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-23 13:39:24 +00:00
fschneider@google.com cd606f44f0 Add a simple dominator based redundancy elimination.
It enables elimination of redundant expressions across
basic blocks.

Currently used for smi checks and class checks, but will
be extended to other expressions in a separate CL.
Review URL: https://chromiumcodereview.appspot.com//10872035

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11227 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-23 13:17:16 +00:00
fschneider@google.com 253c3f8499 Implement class id checks as a separate instruction and add a local CSE optimization pass.
This CL contains:
A new CheckClassComp instruction. Currently it is used only for instance loads:
(LoadInstanceFieldComp)

A pass LocalCSE that performs block-local common subexpression elimination. To identify
redundant expressions I use a hash map per basic block. Computations that do not have
side effects can participate in CSE. For now, I only enabled it for CheckClass.
Any computation that participates in CSE must implement the AttributesEqual function.


Other smaller fixes:

Places where we can pass the correct initial size for GrowableArrays
that have a known size. We should consider having a FixedLengthArray for this purpose.

Made the accessors ic_data() and set_ic_data() use a const ICData*.
Review URL: https://chromiumcodereview.appspot.com//10824349

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10948 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-20 12:40:14 +00:00