beb7114861
This relands commit b0a71d364c
Cq-Include-Trybots: dart/try:vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-simarm-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: I1d32e5d0d44f4e422d188643b548ed81859f7d74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143807
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
// Copyright (c) 2012, 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 RUNTIME_VM_COMPILER_CHA_H_
|
|
#define RUNTIME_VM_COMPILER_CHA_H_
|
|
|
|
#if defined(DART_PRECOMPILED_RUNTIME)
|
|
#error "AOT runtime should not use compiler sources (including header files)"
|
|
#endif // defined(DART_PRECOMPILED_RUNTIME)
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/growable_array.h"
|
|
#include "vm/thread.h"
|
|
|
|
namespace dart {
|
|
|
|
class Class;
|
|
class CompileType;
|
|
class Function;
|
|
template <typename T>
|
|
class ZoneGrowableArray;
|
|
class String;
|
|
|
|
class CHA : public ValueObject {
|
|
public:
|
|
explicit CHA(Thread* thread)
|
|
: thread_(thread), guarded_classes_(thread->zone(), 1) {}
|
|
|
|
// Returns true if the class has subclasses.
|
|
static bool HasSubclasses(const Class& cls);
|
|
bool HasSubclasses(intptr_t cid) const;
|
|
|
|
// Collect the concrete subclasses of 'cls' into 'class_ids'. Return true if
|
|
// the result is valid (may be invalid because we don't track the subclasses
|
|
// of classes allocated in the VM isolate or class Object).
|
|
static bool ConcreteSubclasses(const Class& cls,
|
|
GrowableArray<intptr_t>* class_ids);
|
|
|
|
// Return true if the class is implemented by some other class.
|
|
static bool IsImplemented(const Class& cls);
|
|
|
|
// Returns true if any subclass of 'cls' contains the function.
|
|
// If no override was found subclass_count would contain total count of
|
|
// finalized subclasses that CHA looked at.
|
|
// This count will be used to validate CHA decision before installing
|
|
// optimized code compiled in background.
|
|
bool HasOverride(const Class& cls,
|
|
const String& function_name,
|
|
intptr_t* subclass_count);
|
|
|
|
// Adds class 'cls' to the list of guarded classes, deoptimization occurs
|
|
// if any of those classes gets subclassed through later loaded/finalized
|
|
// libraries. Only classes that were used for CHA optimizations are added.
|
|
void AddToGuardedClasses(const Class& cls, intptr_t subclass_count);
|
|
|
|
// When compiling in background we need to check that no new finalized
|
|
// subclasses were added to guarded classes.
|
|
bool IsConsistentWithCurrentHierarchy() const;
|
|
|
|
void RegisterDependencies(const Code& code) const;
|
|
|
|
// Used for testing.
|
|
bool IsGuardedClass(intptr_t cid) const;
|
|
|
|
private:
|
|
Thread* thread_;
|
|
|
|
struct GuardedClassInfo {
|
|
Class* cls;
|
|
|
|
// Number of finalized subclasses that this class had at the moment
|
|
// when CHA made the first decision based on this class.
|
|
// Used to validate correctness of background compilation: if
|
|
// any subclasses were added we will discard compiled code.
|
|
intptr_t subclass_count;
|
|
};
|
|
|
|
GrowableArray<GuardedClassInfo> guarded_classes_;
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_COMPILER_CHA_H_
|