Skip to content

Commit

Permalink
[VM] Rehash constant tables after cid-renumbering during app-jit trai…
Browse files Browse the repository at this point in the history
…ning

When sorting classes during app-jit training we permute the class ids.

This makes canonical hash codes which depend directly (or indirectly) on
class ids change.  We already clear out the cached canonical hash codes
in type-related instances in the heap.

Though the cid renumbering makes the non-cached canonical hashcodes of
other objects, such as canonical Instance and Array objects, also change.

This means any data structures which use canonical hash codes of
type related objects or Instance/Array objects need to re-hash.

-> This CL makes us rehash the constant tables after cid renumbering.

Fixes dart-lang#34849

Change-Id: Icfb5add3f14e2c62c5bca94f296133121ad0bc55
Reviewed-on: https://dart-review.googlesource.com/c/80801
Commit-Queue: Martin Kustermann <[email protected]>
Reviewed-by: Vyacheslav Egorov <[email protected]>
  • Loading branch information
mkustermann authored and [email protected] committed Oct 19, 2018
1 parent cfbb70a commit 70d5cf8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions runtime/vm/class_finalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3603,6 +3603,45 @@ void ClassFinalizer::RemapClassIds(intptr_t* old_to_new_cid) {
#endif
}

// Clears the cached canonicalized hash codes for all instances which directly
// (or indirectly) depend on class ids.
//
// In the Dart VM heap the following instances directly use cids for the
// computation of canonical hash codes:
//
// * RawType (due to RawType::type_class_id_)
// * RawTypeParameter (due to RawTypeParameter::parameterized_class_id_)
//
// The following instances use cids for the computation of canonical hash codes
// indirectly:
//
// * RawTypeRef (due to RawTypeRef::type_->type_class_id)
// * RawType (due to RawType::signature_'s result/parameter types)
// * RawBoundedType (due to RawBoundedType::type_parameter_)
// * RawTypeArguments (due to type references)
// * RawInstance (due to instance fields)
// * RawArray (due to type arguments & array entries)
//
// Caching of the canonical hash codes happens for:
//
// * RawType::hash_
// * RawTypeParameter::hash_
// * RawBoundedType::hash_
// * RawTypeArguments::hash_
//
// No caching of canonical hash codes (i.e. it gets re-computed every time)
// happens for:
//
// * RawTypeRef (computed via RawTypeRef::type_->type_class_id)
// * RawInstance (computed via size & fields)
// * RawArray (computed via type arguments & array entries)
//
// Usages of canonical hash codes are:
//
// * ObjectStore::canonical_types()
// * ObjectStore::canonical_type_arguments()
// * Class::constants()
//
class ClearTypeHashVisitor : public ObjectVisitor {
public:
explicit ClearTypeHashVisitor(Zone* zone)
Expand Down Expand Up @@ -3688,6 +3727,10 @@ void ClassFinalizer::RehashTypes() {
typeargs_table.Release();
}

// The canonical constant tables use canonical hashcodes which can change
// due to cid-renumbering.
I->RehashConstants();

dict_size = Utils::RoundUpToPowerOfTwo(typeargs.Length() * 4 / 3);
typeargs_array =
HashTables::New<CanonicalTypeArgumentsSet>(dict_size, Heap::kOld);
Expand Down

0 comments on commit 70d5cf8

Please sign in to comment.