2012-02-14 14:14:51 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_COMPILER_H_
|
|
|
|
#define V8_COMPILER_H_
|
|
|
|
|
2017-11-14 16:29:43 +00:00
|
|
|
#include <forward_list>
|
2016-07-25 10:24:45 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
2014-09-24 07:08:27 +00:00
|
|
|
#include "src/bailout-reason.h"
|
2017-10-30 13:18:12 +00:00
|
|
|
#include "src/code-events.h"
|
2016-08-18 10:26:19 +00:00
|
|
|
#include "src/contexts.h"
|
|
|
|
#include "src/isolate.h"
|
2018-02-15 16:05:21 +00:00
|
|
|
#include "src/unicode-cache.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/zone/zone.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2016-01-15 12:11:35 +00:00
|
|
|
// Forward declarations.
|
2015-07-06 11:11:15 +00:00
|
|
|
class JavaScriptFrame;
|
2018-04-04 20:30:34 +00:00
|
|
|
class OptimizedCompilationInfo;
|
|
|
|
class OptimizedCompilationJob;
|
2015-03-09 14:51:13 +00:00
|
|
|
class ParseInfo;
|
2018-02-15 16:05:21 +00:00
|
|
|
class Parser;
|
2015-03-09 14:51:13 +00:00
|
|
|
class ScriptData;
|
2018-02-15 16:05:21 +00:00
|
|
|
struct ScriptStreamingData;
|
2018-04-04 20:30:34 +00:00
|
|
|
class UnoptimizedCompilationInfo;
|
|
|
|
class UnoptimizedCompilationJob;
|
2016-12-16 12:38:17 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
typedef std::forward_list<std::unique_ptr<UnoptimizedCompilationJob>>
|
|
|
|
UnoptimizedCompilationJobList;
|
2017-11-14 16:29:43 +00:00
|
|
|
|
2016-03-08 12:07:27 +00:00
|
|
|
// The V8 compiler API.
|
|
|
|
//
|
|
|
|
// This is the central hub for dispatching to the various compilers within V8.
|
|
|
|
// Logic for which compiler to choose and how to wire compilation results into
|
|
|
|
// the object heap should be kept inside this class.
|
|
|
|
//
|
|
|
|
// General strategy: Scripts are translated into anonymous functions w/o
|
|
|
|
// parameters which then can be executed. If the source code contains other
|
|
|
|
// functions, they might be compiled and allocated as part of the compilation
|
|
|
|
// of the source code or deferred for lazy compilation at a later point.
|
2017-01-25 22:41:57 +00:00
|
|
|
class V8_EXPORT_PRIVATE Compiler : public AllStatic {
|
2016-03-08 12:07:27 +00:00
|
|
|
public:
|
|
|
|
enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION };
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// The following family of methods ensures a given function is compiled. The
|
|
|
|
// general contract is that failures will be reported by returning {false},
|
|
|
|
// whereas successful compilation ensures the {is_compiled} predicate on the
|
|
|
|
// given function holds (except for live-edit, which compiles the world).
|
|
|
|
|
2017-08-17 12:40:24 +00:00
|
|
|
static bool Compile(Handle<SharedFunctionInfo> shared,
|
|
|
|
ClearExceptionFlag flag);
|
2016-03-08 12:07:27 +00:00
|
|
|
static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag);
|
|
|
|
static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode);
|
Reland "[debug] liveedit in native"
This is a reland of 3dfaf8264f8abd3e101d5f2e72739c4e8475ff78
Original change's description:
> [debug] liveedit in native
>
> Liveedit step-by-step:
> 1. calculate diff between old source and new source,
> 2. map function literals from old source to new source,
> 3. create new script for new_source,
> 4. mark literals with changed code as changed, all others as unchanged,
> 5. check that for changed literals there are no:
> - running generators in the heap,
> - non droppable frames (e.g. running generator) above them on stack.
> 6. mark the bottom most frame with changed function as scheduled for
> restart if any.
> 7. for unchanged functions:
> - deoptimize,
> - remove from cache,
> - update source positions,
> - move to new script,
> - reset feedback information and preparsed scope information if any,
> - replace any sfi in constant pool with changed one if any.
> 8. for changed functions:
> - deoptimize
> - remove from cache,
> - reset feedback information,
> - update all links from js functions to old shared with new one.
> 9. swap scripts.
>
> TBR=ulan@chromium.org
>
> Bug: v8:7862,v8:5713
> Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
> Change-Id: I8f6f6156318cc82d6f36d7ebc1c9f7d5f3aa1461
> Reviewed-on: https://chromium-review.googlesource.com/1105493
> Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
> Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#54146}
TBR=dgozman@chromium.org
Bug: v8:7862, v8:5713
Change-Id: I163ed2fd2ca3115ba0de74cb35a6fac9e40fdd94
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Reviewed-on: https://chromium-review.googlesource.com/1124879
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54187}
2018-07-03 17:16:35 +00:00
|
|
|
|
|
|
|
V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo>
|
|
|
|
CompileForLiveEdit(ParseInfo* parse_info, Isolate* isolate);
|
2016-03-08 12:07:27 +00:00
|
|
|
|
2018-02-15 16:05:21 +00:00
|
|
|
// Creates a new task that when run will parse and compile the streamed
|
|
|
|
// script associated with |streaming_data| and can be finalized with
|
|
|
|
// Compiler::GetSharedFunctionInfoForStreamedScript.
|
|
|
|
// Note: does not take ownership of streaming_data.
|
|
|
|
static ScriptCompiler::ScriptStreamingTask* NewBackgroundCompileTask(
|
|
|
|
ScriptStreamingData* streaming_data, Isolate* isolate);
|
2016-08-25 10:24:53 +00:00
|
|
|
|
2016-04-27 17:54:16 +00:00
|
|
|
// Generate and install code from previously queued compilation job.
|
2018-04-04 20:30:34 +00:00
|
|
|
static bool FinalizeCompilationJob(UnoptimizedCompilationJob* job,
|
|
|
|
Handle<SharedFunctionInfo> shared_info,
|
|
|
|
Isolate* isolate);
|
|
|
|
static bool FinalizeCompilationJob(OptimizedCompilationJob* job,
|
|
|
|
Isolate* isolate);
|
2016-03-08 12:07:27 +00:00
|
|
|
|
|
|
|
// Give the compiler a chance to perform low-latency initialization tasks of
|
|
|
|
// the given {function} on its instantiation. Note that only the runtime will
|
|
|
|
// offer this chance, optimized closure instantiation will not call this.
|
|
|
|
static void PostInstantiation(Handle<JSFunction> function, PretenureFlag);
|
|
|
|
|
|
|
|
// Parser::Parse, then Compiler::Analyze.
|
2017-08-03 11:00:57 +00:00
|
|
|
static bool ParseAndAnalyze(ParseInfo* parse_info,
|
2017-07-21 09:32:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_info,
|
|
|
|
Isolate* isolate);
|
2018-01-24 16:40:24 +00:00
|
|
|
// Rewrite and analyze scopes.
|
2018-01-24 16:14:38 +00:00
|
|
|
static bool Analyze(ParseInfo* parse_info);
|
2016-07-25 09:42:48 +00:00
|
|
|
|
2016-03-08 12:07:27 +00:00
|
|
|
// ===========================================================================
|
|
|
|
// The following family of methods instantiates new functions for scripts or
|
|
|
|
// function literals. The decision whether those functions will be compiled,
|
|
|
|
// is left to the discretion of the compiler.
|
|
|
|
//
|
|
|
|
// Please note this interface returns shared function infos. This means you
|
|
|
|
// need to call Factory::NewFunctionFromSharedFunctionInfo before you have a
|
|
|
|
// real function with a context.
|
|
|
|
|
|
|
|
// Create a (bound) function for a String source within a context for eval.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval(
|
2016-03-08 12:07:27 +00:00
|
|
|
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
|
|
|
|
Handle<Context> context, LanguageMode language_mode,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
ParseRestriction restriction, int parameters_end_pos,
|
|
|
|
int eval_scope_position, int eval_position, int line_offset = 0,
|
|
|
|
int column_offset = 0, Handle<Object> script_name = Handle<Object>(),
|
2016-03-08 12:07:27 +00:00
|
|
|
ScriptOriginOptions options = ScriptOriginOptions());
|
|
|
|
|
2018-03-27 10:44:13 +00:00
|
|
|
struct ScriptDetails {
|
|
|
|
ScriptDetails() : line_offset(0), column_offset(0) {}
|
|
|
|
explicit ScriptDetails(Handle<Object> script_name)
|
|
|
|
: line_offset(0), column_offset(0), name_obj(script_name) {}
|
|
|
|
|
|
|
|
int line_offset;
|
|
|
|
int column_offset;
|
|
|
|
i::MaybeHandle<i::Object> name_obj;
|
|
|
|
i::MaybeHandle<i::Object> source_map_url;
|
|
|
|
i::MaybeHandle<i::FixedArray> host_defined_options;
|
|
|
|
};
|
|
|
|
|
2017-12-18 08:10:06 +00:00
|
|
|
// Create a function that results from wrapping |source| in a function,
|
|
|
|
// with |arguments| being a list of parameters for that function.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetWrappedFunction(
|
2017-12-18 08:10:06 +00:00
|
|
|
Handle<String> source, Handle<FixedArray> arguments,
|
2018-03-27 10:44:13 +00:00
|
|
|
Handle<Context> context, const ScriptDetails& script_details,
|
|
|
|
ScriptOriginOptions origin_options, ScriptData* cached_data,
|
|
|
|
v8::ScriptCompiler::CompileOptions compile_options,
|
|
|
|
v8::ScriptCompiler::NoCacheReason no_cache_reason);
|
2017-12-18 08:10:06 +00:00
|
|
|
|
2017-06-13 12:43:18 +00:00
|
|
|
// Returns true if the embedder permits compiling the given source string in
|
|
|
|
// the given context.
|
|
|
|
static bool CodeGenerationFromStringsAllowed(Isolate* isolate,
|
|
|
|
Handle<Context> context,
|
|
|
|
Handle<String> source);
|
|
|
|
|
2016-07-20 13:29:04 +00:00
|
|
|
// Create a (bound) function for a String source within a context for eval.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetFunctionFromString(
|
2016-07-20 13:29:04 +00:00
|
|
|
Handle<Context> context, Handle<String> source,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
ParseRestriction restriction, int parameters_end_pos);
|
2016-07-20 13:29:04 +00:00
|
|
|
|
2018-02-21 14:35:23 +00:00
|
|
|
// Create a shared function info object for a String source.
|
2017-10-04 22:48:12 +00:00
|
|
|
static MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScript(
|
2018-07-17 15:08:58 +00:00
|
|
|
Isolate* isolate, Handle<String> source,
|
|
|
|
const ScriptDetails& script_details, ScriptOriginOptions origin_options,
|
|
|
|
v8::Extension* extension, ScriptData* cached_data,
|
|
|
|
ScriptCompiler::CompileOptions compile_options,
|
2017-11-01 16:16:35 +00:00
|
|
|
ScriptCompiler::NoCacheReason no_cache_reason,
|
2018-02-21 14:35:23 +00:00
|
|
|
NativesFlag is_natives_code);
|
|
|
|
|
|
|
|
// Create a shared function info object for a Script source that has already
|
|
|
|
// been parsed and possibly compiled on a background thread while being loaded
|
|
|
|
// from a streamed source. On return, the data held by |streaming_data| will
|
|
|
|
// have been released, however the object itself isn't freed and is still
|
|
|
|
// owned by the caller.
|
2018-02-15 16:05:21 +00:00
|
|
|
static MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForStreamedScript(
|
2018-07-17 15:08:58 +00:00
|
|
|
Isolate* isolate, Handle<String> source,
|
|
|
|
const ScriptDetails& script_details, ScriptOriginOptions origin_options,
|
|
|
|
ScriptStreamingData* streaming_data);
|
2017-11-14 16:29:43 +00:00
|
|
|
|
2017-11-29 16:17:41 +00:00
|
|
|
// Create a shared function info object for the given function literal
|
|
|
|
// node (the code may be lazily compiled).
|
|
|
|
static Handle<SharedFunctionInfo> GetSharedFunctionInfo(FunctionLiteral* node,
|
|
|
|
Handle<Script> script,
|
|
|
|
Isolate* isolate);
|
|
|
|
|
2016-03-08 12:07:27 +00:00
|
|
|
// ===========================================================================
|
|
|
|
// The following family of methods provides support for OSR. Code generated
|
|
|
|
// for entry via OSR might not be suitable for normal entry, hence will be
|
|
|
|
// returned directly to the caller.
|
|
|
|
//
|
|
|
|
// Please note this interface is the only part dealing with {Code} objects
|
|
|
|
// directly. Other methods are agnostic to {Code} and can use an interpreter
|
|
|
|
// instead of generating JIT code for a function at all.
|
|
|
|
|
|
|
|
// Generate and return optimized code for OSR, or empty handle on failure.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT static MaybeHandle<Code> GetOptimizedCodeForOSR(
|
2017-08-18 15:25:01 +00:00
|
|
|
Handle<JSFunction> function, BailoutId osr_offset,
|
2016-03-08 12:07:27 +00:00
|
|
|
JavaScriptFrame* osr_frame);
|
|
|
|
};
|
2014-07-10 10:28:05 +00:00
|
|
|
|
2016-04-11 10:01:09 +00:00
|
|
|
// A base class for compilation jobs intended to run concurrent to the main
|
2018-04-04 20:30:34 +00:00
|
|
|
// thread. The current state of the job can be checked using {state()}.
|
2017-01-30 19:27:00 +00:00
|
|
|
class V8_EXPORT_PRIVATE CompilationJob {
|
2012-07-17 16:24:40 +00:00
|
|
|
public:
|
2016-08-22 11:48:59 +00:00
|
|
|
enum Status { SUCCEEDED, FAILED };
|
|
|
|
enum class State {
|
|
|
|
kReadyToPrepare,
|
|
|
|
kReadyToExecute,
|
|
|
|
kReadyToFinalize,
|
|
|
|
kSucceeded,
|
|
|
|
kFailed,
|
|
|
|
};
|
2018-04-04 20:30:34 +00:00
|
|
|
|
|
|
|
CompilationJob(uintptr_t stack_limit, State initial_state)
|
|
|
|
: state_(initial_state), stack_limit_(stack_limit) {}
|
2016-04-27 17:54:16 +00:00
|
|
|
virtual ~CompilationJob() {}
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
|
|
|
|
uintptr_t stack_limit() const { return stack_limit_; }
|
|
|
|
|
|
|
|
State state() const { return state_; }
|
|
|
|
|
|
|
|
protected:
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT Status UpdateState(Status status, State next_state) {
|
2018-04-04 20:30:34 +00:00
|
|
|
if (status == SUCCEEDED) {
|
|
|
|
state_ = next_state;
|
|
|
|
} else {
|
|
|
|
state_ = State::kFailed;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
State state_;
|
|
|
|
uintptr_t stack_limit_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A base class for unoptimized compilation jobs.
|
|
|
|
//
|
|
|
|
// The job is split into two phases which are called in sequence on
|
|
|
|
// different threads and with different limitations:
|
|
|
|
// 1) ExecuteJob: Runs concurrently. No heap allocation or handle derefs.
|
|
|
|
// 2) FinalizeJob: Runs on main thread. No dependency changes.
|
|
|
|
//
|
|
|
|
// Either of phases can either fail or succeed.
|
|
|
|
class UnoptimizedCompilationJob : public CompilationJob {
|
|
|
|
public:
|
|
|
|
UnoptimizedCompilationJob(intptr_t stack_limit, ParseInfo* parse_info,
|
|
|
|
UnoptimizedCompilationInfo* compilation_info)
|
|
|
|
: CompilationJob(stack_limit, State::kReadyToExecute),
|
|
|
|
parse_info_(parse_info),
|
|
|
|
compilation_info_(compilation_info) {}
|
|
|
|
|
|
|
|
// Executes the compile job. Can be called on a background thread.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT Status ExecuteJob();
|
2018-04-04 20:30:34 +00:00
|
|
|
|
|
|
|
// Finalizes the compile job. Must be called on the main thread.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT Status
|
|
|
|
FinalizeJob(Handle<SharedFunctionInfo> shared_info, Isolate* isolate);
|
2018-04-04 20:30:34 +00:00
|
|
|
|
|
|
|
void RecordCompilationStats(Isolate* isolate) const;
|
|
|
|
void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
|
|
|
|
Handle<SharedFunctionInfo> shared,
|
|
|
|
Isolate* isolate) const;
|
|
|
|
|
|
|
|
ParseInfo* parse_info() const { return parse_info_; }
|
|
|
|
UnoptimizedCompilationInfo* compilation_info() const {
|
|
|
|
return compilation_info_;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Overridden by the actual implementation.
|
|
|
|
virtual Status ExecuteJobImpl() = 0;
|
|
|
|
virtual Status FinalizeJobImpl(Handle<SharedFunctionInfo> shared_info,
|
|
|
|
Isolate* isolate) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ParseInfo* parse_info_;
|
|
|
|
UnoptimizedCompilationInfo* compilation_info_;
|
|
|
|
base::TimeDelta time_taken_to_execute_;
|
|
|
|
base::TimeDelta time_taken_to_finalize_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A base class for optimized compilation jobs.
|
|
|
|
//
|
|
|
|
// The job is split into three phases which are called in sequence on
|
|
|
|
// different threads and with different limitations:
|
|
|
|
// 1) PrepareJob: Runs on main thread. No major limitations.
|
|
|
|
// 2) ExecuteJob: Runs concurrently. No heap allocation or handle derefs.
|
|
|
|
// 3) FinalizeJob: Runs on main thread. No dependency changes.
|
|
|
|
//
|
|
|
|
// Each of the three phases can either fail or succeed.
|
|
|
|
class OptimizedCompilationJob : public CompilationJob {
|
|
|
|
public:
|
2018-04-06 11:49:15 +00:00
|
|
|
OptimizedCompilationJob(uintptr_t stack_limit,
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo* compilation_info,
|
|
|
|
const char* compiler_name,
|
|
|
|
State initial_state = State::kReadyToPrepare)
|
|
|
|
: CompilationJob(stack_limit, initial_state),
|
|
|
|
compilation_info_(compilation_info),
|
|
|
|
compiler_name_(compiler_name) {}
|
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Prepare the compile job. Must be called on the main thread.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT Status PrepareJob(Isolate* isolate);
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2016-08-25 10:24:53 +00:00
|
|
|
// Executes the compile job. Can be called on a background thread if
|
|
|
|
// can_execute_on_background_thread() returns true.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT Status ExecuteJob();
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Finalizes the compile job. Must be called on the main thread.
|
2018-04-09 15:12:07 +00:00
|
|
|
V8_WARN_UNUSED_RESULT Status FinalizeJob(Isolate* isolate);
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Report a transient failure, try again next time. Should only be called on
|
|
|
|
// optimization compilation jobs.
|
2016-08-31 08:49:14 +00:00
|
|
|
Status RetryOptimization(BailoutReason reason);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Report a persistent failure, disable future optimization on the function.
|
|
|
|
// Should only be called on optimization compilation jobs.
|
2016-08-31 08:49:14 +00:00
|
|
|
Status AbortOptimization(BailoutReason reason);
|
2012-07-19 18:58:23 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
void RecordCompilationStats() const;
|
2017-11-15 14:36:57 +00:00
|
|
|
void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
|
|
|
|
Isolate* isolate) const;
|
2016-08-25 10:24:53 +00:00
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo* compilation_info() const {
|
|
|
|
return compilation_info_;
|
|
|
|
}
|
2016-04-11 10:01:09 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
protected:
|
2016-08-18 17:06:37 +00:00
|
|
|
// Overridden by the actual implementation.
|
2017-11-15 14:36:57 +00:00
|
|
|
virtual Status PrepareJobImpl(Isolate* isolate) = 0;
|
2016-08-22 11:48:59 +00:00
|
|
|
virtual Status ExecuteJobImpl() = 0;
|
2017-11-15 14:36:57 +00:00
|
|
|
virtual Status FinalizeJobImpl(Isolate* isolate) = 0;
|
2016-08-22 11:48:59 +00:00
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
private:
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo* compilation_info_;
|
2016-08-22 11:48:59 +00:00
|
|
|
base::TimeDelta time_taken_to_prepare_;
|
|
|
|
base::TimeDelta time_taken_to_execute_;
|
|
|
|
base::TimeDelta time_taken_to_finalize_;
|
2016-04-11 12:06:41 +00:00
|
|
|
const char* compiler_name_;
|
2012-07-17 16:24:40 +00:00
|
|
|
};
|
|
|
|
|
2018-02-15 16:05:21 +00:00
|
|
|
// Contains all data which needs to be transmitted between threads for
|
|
|
|
// background parsing and compiling and finalizing it on the main thread.
|
|
|
|
struct ScriptStreamingData {
|
|
|
|
ScriptStreamingData(ScriptCompiler::ExternalSourceStream* source_stream,
|
|
|
|
ScriptCompiler::StreamedSource::Encoding encoding);
|
|
|
|
~ScriptStreamingData();
|
|
|
|
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
// Internal implementation of v8::ScriptCompiler::StreamedSource.
|
|
|
|
std::unique_ptr<ScriptCompiler::ExternalSourceStream> source_stream;
|
|
|
|
ScriptCompiler::StreamedSource::Encoding encoding;
|
|
|
|
std::unique_ptr<ScriptCompiler::CachedData> cached_data;
|
|
|
|
|
|
|
|
// Data needed for parsing, and data needed to to be passed between thread
|
|
|
|
// between parsing and compilation. These need to be initialized before the
|
|
|
|
// compilation starts.
|
|
|
|
UnicodeCache unicode_cache;
|
|
|
|
std::unique_ptr<ParseInfo> info;
|
|
|
|
std::unique_ptr<Parser> parser;
|
|
|
|
|
|
|
|
// Data needed for finalizing compilation after background compilation.
|
2018-04-04 20:30:34 +00:00
|
|
|
std::unique_ptr<UnoptimizedCompilationJob> outer_function_job;
|
|
|
|
UnoptimizedCompilationJobList inner_function_jobs;
|
2018-02-15 16:05:21 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ScriptStreamingData);
|
|
|
|
};
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#endif // V8_COMPILER_H_
|