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"
|
|
|
|
#include "src/api.h"
|
2018-09-20 13:18:16 +00:00
|
|
|
#include "src/base/template-utils.h"
|
2017-04-06 13:59:07 +00:00
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/isolate.h"
|
2017-01-09 13:43:28 +00:00
|
|
|
#include "src/objects-inl.h"
|
2017-04-06 13:59:07 +00:00
|
|
|
#include "src/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;
|
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(
|
[sfi] Remove SFI function identifier field
Remove the function identifier field from SharedFunctionInfo. This field
would store one of a) the function's inferred name, b) the "builtin
function id", or c) debug info. We remove these in turn:
a) The function's inferred name is available on the ScopeInfo, so like
the start/end position we read it off either the ScopeInfo (for
compiled functions) or the UncompiledData (for uncompiled functions).
As a side-effect, now both UncompiledData and its subclass,
UncompiledDataWithPreparsedScope, contain a pointer field. To keep
BodyDescriptors manageable, we introduce a SubclassBodyDescriptor
which effectively appends two BodyDescriptors together.
b) The builtin function id is < 255, so we can steal a byte from
expected no. of properies (also <255) and store these together.
Eventually we want to get rid of this field and use the builtin ID,
but this is pending JS builtin removal.
As a side-effect, BuiltinFunctionId becomes an enum class (for better
storage size guarantees).
c) The debug info can hang off anything (since it stores the field it
replaces), so we can attach it to the script field instead.
This saves a word on compiled function (uncompiled functions
unfortunately still have to store it in UncompiledData).
Bug: chromium:818642
Change-Id: I8b4b3a070f0fe328aafcaeac58842d144d12d996
Reviewed-on: https://chromium-review.googlesource.com/1138328
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54543}
2018-07-18 15:11:31 +00:00
|
|
|
ReadOnlyRoots(isolate).empty_string_handle(), 0, source->length(),
|
|
|
|
function_literal_id));
|
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
|