Files
sdk/runtime/vm/weak_code.h
T
Vyacheslav Egorov 65f2e015ca VM: Fix race between background compiler and guarded cid update.
Rework how we check guarded state consistency in background compiler.

Background compiler was storing original fields inside guarded fields list. This caused a race during inlining when inliner would copy guarded fields one by one from the callee function into the caller, because ParsedFunction::AddToGuardedFields looks at the guarded_cid to filter out those fields that should not be guarded.

As a result if some guarded field transitioned to unguarded (kDynamicCid) after callee graph construction but before list of guarded fields were copied then AddToGuardedFields would simply skip that field because it now has guarded_cid() == kDynamicCid.

We fix this race by always placing copies into the list of guarded fields and unwrapping them only in FinalizeCode.

Placing the copies also allows us to simplify a lot of code that was trying to verify guarded state consistency before committing the generated optimized code - now that we store copies in the list we can just compare their state to the originals and abort if the state is different.

Additionally fix deduplication check that was comparing original fields with copies - resulting in adding the same field into the list multiple times.

Add an assertion that verifies that we are not trying to access guarded_cid of original field from background compiler.

R=fschneider@google.com
BUG=

Review URL: https://codereview.chromium.org/2006793002 .
2016-05-24 14:52:02 +02:00

43 lines
1.1 KiB
C++

// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef VM_WEAK_CODE_H_
#define VM_WEAK_CODE_H_
#include "vm/allocation.h"
#include "vm/globals.h"
namespace dart {
class Array;
class Code;
// Helper class to handle an array of code weak properties. Implements
// registration and disabling of stored code objects.
class WeakCodeReferences : public ValueObject {
public:
explicit WeakCodeReferences(const Array& value) : array_(value) {}
virtual ~WeakCodeReferences() {}
void Register(const Code& value);
virtual void UpdateArrayTo(const Array& array) = 0;
virtual void ReportDeoptimization(const Code& code) = 0;
virtual void ReportSwitchingCode(const Code& code) = 0;
static bool IsOptimizedCode(const Array& dependent_code, const Code& code);
void DisableCode();
bool HasCodes() const;
private:
const Array& array_; // Array of Code objects.
DISALLOW_COPY_AND_ASSIGN(WeakCodeReferences);
};
} // namespace dart
#endif // VM_WEAK_CODE_H_