2016-12-12 15:35:41 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-04-18 14:01:12 +00:00
|
|
|
#include "test/unittests/test-helpers.h"
|
2016-12-12 15:35:41 +00:00
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/handles.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
|
|
|
#include "src/objects/objects.h"
|
2018-09-20 13:18:16 +00:00
|
|
|
#include "src/parsing/scanner-character-streams.h"
|
|
|
|
#include "src/parsing/scanner.h"
|
2016-12-12 15:35:41 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-04-06 13:59:07 +00:00
|
|
|
namespace test {
|
2016-12-12 15:35:41 +00:00
|
|
|
|
2017-04-06 13:59:07 +00:00
|
|
|
Handle<String> CreateSource(Isolate* isolate,
|
|
|
|
ExternalOneByteString::Resource* maybe_resource) {
|
2018-09-20 13:18:16 +00:00
|
|
|
if (!maybe_resource) {
|
|
|
|
static const char test_script[] = "(x) { x*x; }";
|
|
|
|
maybe_resource = new test::ScriptResource(test_script, strlen(test_script));
|
2017-04-06 13:59:07 +00:00
|
|
|
}
|
2018-09-20 13:18:16 +00:00
|
|
|
return isolate->factory()
|
|
|
|
->NewExternalStringFromOneByte(maybe_resource)
|
|
|
|
.ToHandleChecked();
|
2017-04-06 13:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> CreateSharedFunctionInfo(
|
|
|
|
Isolate* isolate,
|
|
|
|
v8::String::ExternalOneByteStringResource* maybe_resource) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<String> source = CreateSource(isolate, maybe_resource);
|
|
|
|
Handle<Script> script = isolate->factory()->NewScript(source);
|
2018-03-19 10:38:06 +00:00
|
|
|
Handle<WeakFixedArray> infos = isolate->factory()->NewWeakFixedArray(3);
|
2017-04-06 13:59:07 +00:00
|
|
|
script->set_shared_function_infos(*infos);
|
2018-03-22 16:09:55 +00:00
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
isolate->factory()->NewSharedFunctionInfoForBuiltin(
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked("f"),
|
2021-06-07 15:24:12 +00:00
|
|
|
Builtin::kCompileLazy);
|
[sfi] Remove SFI function literal id field (reland^2)
SharedFunctionInfos store their original function literal's id. This is
also their index in the Script's SFI list.
The function literal id is only needed for lazy compilation and live edit,
and access only has to be fast in the former. So, we can move the SFI
function literal id field to UncompiledData, and if patching with live
edit, or discarding compiled code, we can perform a slower linear search
through the Script's SFI list.
This is a reland of
1) https://chromium-review.googlesource.com/1082480 and
2) https://chromium-review.googlesource.com/1128854
the differences being:
1) caching the literal id on UncompiledData rather than always linearly
searching the SFI list, and removing the unused runtime-liveedit.cc
file instead of fixing it to support this change.
2) clearing padding on UncompiledData now that it has 3 int32 fields,
making its end unaligned on x64.
TBR=yangguo@chromium.org,marja@chromium.org,ulan@chromium.org,cbruni@chromium.org
Bug: chromium:818642
Change-Id: I58dcb12a2a60a680f662568da428e01189c62638
Reviewed-on: https://chromium-review.googlesource.com/1138325
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54473}
2018-07-16 15:56:10 +00:00
|
|
|
int function_literal_id = 1;
|
2019-06-21 15:43:35 +00:00
|
|
|
shared->set_function_literal_id(function_literal_id);
|
2018-07-09 09:34:34 +00:00
|
|
|
// Ensure that the function can be compiled lazily.
|
|
|
|
shared->set_uncompiled_data(
|
2019-01-07 14:09:18 +00:00
|
|
|
*isolate->factory()->NewUncompiledDataWithoutPreparseData(
|
2019-06-21 15:43:35 +00:00
|
|
|
ReadOnlyRoots(isolate).empty_string_handle(), 0, source->length()));
|
2018-04-06 11:49:15 +00:00
|
|
|
// Make sure we have an outer scope info, even though it's empty
|
|
|
|
shared->set_raw_outer_scope_info_or_feedback_metadata(
|
|
|
|
ScopeInfo::Empty(isolate));
|
2020-01-08 16:47:38 +00:00
|
|
|
shared->SetScript(ReadOnlyRoots(isolate), *script, function_literal_id);
|
2017-04-06 13:59:07 +00:00
|
|
|
return scope.CloseAndEscape(shared);
|
|
|
|
}
|
|
|
|
|
2018-09-20 13:18:16 +00:00
|
|
|
std::unique_ptr<ParseInfo> OuterParseInfoForShared(
|
2020-04-22 10:47:32 +00:00
|
|
|
Isolate* isolate, Handle<SharedFunctionInfo> shared,
|
|
|
|
UnoptimizedCompileState* state) {
|
2020-01-07 10:44:20 +00:00
|
|
|
Script script = Script::cast(shared->script());
|
2020-04-22 10:45:31 +00:00
|
|
|
std::unique_ptr<ParseInfo> result = std::make_unique<ParseInfo>(
|
2020-04-22 10:47:32 +00:00
|
|
|
isolate, i::UnoptimizedCompileFlags::ForScriptCompile(isolate, script),
|
|
|
|
state);
|
2018-09-20 13:18:16 +00:00
|
|
|
|
|
|
|
// Create a character stream to simulate the parser having done so for the
|
2020-04-22 10:47:32 +00:00
|
|
|
// top-level ParseProgram.
|
2020-01-07 10:44:20 +00:00
|
|
|
Handle<String> source(String::cast(script.source()), isolate);
|
2018-09-20 13:18:16 +00:00
|
|
|
std::unique_ptr<Utf16CharacterStream> stream(
|
|
|
|
ScannerStream::For(isolate, source));
|
|
|
|
result->set_character_stream(std::move(stream));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-04-06 13:59:07 +00:00
|
|
|
} // namespace test
|
2016-12-12 15:35:41 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|