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
|
|
|
|
|
|
|
#include "include/v8.h"
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api.h"
|
2018-09-20 13:18:16 +00:00
|
|
|
#include "src/base/template-utils.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"),
|
2018-03-23 14:24:03 +00:00
|
|
|
Builtins::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));
|
[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
|
|
|
SharedFunctionInfo::SetScript(shared, 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(
|
|
|
|
Isolate* isolate, Handle<SharedFunctionInfo> shared) {
|
|
|
|
Handle<Script> script =
|
|
|
|
Handle<Script>::cast(handle(shared->script(), isolate));
|
|
|
|
std::unique_ptr<ParseInfo> result =
|
|
|
|
base::make_unique<ParseInfo>(isolate, script);
|
|
|
|
|
|
|
|
// Create a character stream to simulate the parser having done so for the
|
|
|
|
// to-level ParseProgram.
|
|
|
|
Handle<String> source(String::cast(script->source()), isolate);
|
|
|
|
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
|