1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_CODEGEN_PENDING_OPTIMIZATION_TABLE_H_
6#define V8_CODEGEN_PENDING_OPTIMIZATION_TABLE_H_
7
8#include "src/common/globals.h"
9
10namespace v8 {
11namespace internal {
12
13// This class adds the functionality to properly test the optimized code. This
14// is only for use in tests. All these functions should only be called when
15// testing_d8_flag_for_tests is set.
16class PendingOptimizationTable {
17 public:
18  // This function should be called before we mark the function for
19  // optimization. Calling this function ensures that |function| is compiled and
20  // has a feedback vector allocated. This also holds on to the bytecode
21  // strongly in pending optimization table preventing the bytecode to be
22  // flushed.
23  static void PreparedForOptimization(Isolate* isolate,
24                                      Handle<JSFunction> function,
25                                      bool allow_heuristic_optimization);
26
27  // This function should be called when the function is marked for optimization
28  // via the intrinsics. This will update the state of the bytecode array in the
29  // pending optimization table, so that the entry can be removed once the
30  // function is optimized. If the function is already optimized it removes the
31  // entry from the table.
32  static void MarkedForOptimization(Isolate* isolate,
33                                    Handle<JSFunction> function);
34
35  // This function should be called once the function is optimized. If there is
36  // an entry in the pending optimization table and it is marked for removal
37  // then this function removes the entry from pending optimization table.
38  static void FunctionWasOptimized(Isolate* isolate,
39                                   Handle<JSFunction> function);
40
41  // This function returns whether a heuristic is allowed to trigger
42  // optimization the function. This mechanism is used in tests to prevent
43  // heuristics from interfering with manually triggered optimization.
44  static bool IsHeuristicOptimizationAllowed(Isolate* isolate,
45                                             JSFunction function);
46};
47
48}  // namespace internal
49}  // namespace v8
50
51#endif  // V8_CODEGEN_PENDING_OPTIMIZATION_TABLE_H_
52