Commit 93288524 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[no-wasm] Remove wasm information from Script

This removes the TYPE_WASM script type, and all fields on Script that
are only needed for WebAssembly.

R=jgruber@chromium.org

Bug: v8:11238
Change-Id: I233bfd3dec9b389bc74d926670310fd175c0c6d8
Cq-Include-Trybots: luci.v8.try:v8_linux64_no_wasm_compile_rel
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2757690Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73418}
parent 62c8ed19
......@@ -158,13 +158,16 @@ static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
i::Handle<i::FixedArray> host_defined_options(script->host_defined_options(),
isolate);
ScriptOriginOptions options(script->origin_options());
bool is_wasm = false;
#if V8_ENABLE_WEBASSEMBLY
is_wasm = script->type() == i::Script::TYPE_WASM;
#endif // V8_ENABLE_WEBASSEMBLY
v8::ScriptOrigin origin(
reinterpret_cast<v8::Isolate*>(isolate), Utils::ToLocal(scriptName),
script->line_offset(), script->column_offset(),
options.IsSharedCrossOrigin(), script->id(),
Utils::ToLocal(source_map_url), options.IsOpaque(),
script->type() == i::Script::TYPE_WASM, options.IsModule(),
Utils::PrimitiveArrayToLocal(host_defined_options));
Utils::ToLocal(source_map_url), options.IsOpaque(), is_wasm,
options.IsModule(), Utils::PrimitiveArrayToLocal(host_defined_options));
return origin;
}
......
......@@ -287,7 +287,9 @@ int Script::ColumnOffset() const {
std::vector<int> Script::LineEnds() const {
i::Handle<i::Script> script = Utils::OpenHandle(this);
if (script->type() == i::Script::TYPE_WASM) return std::vector<int>();
#if V8_ENABLE_WEBASSEMBLY
if (script->type() == i::Script::TYPE_WASM) return {};
#endif // V8_ENABLE_WEBASSEMBLY
i::Isolate* isolate = script->GetIsolate();
i::HandleScope scope(isolate);
......@@ -352,9 +354,11 @@ MaybeLocal<String> Script::Source() const {
handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
}
#if V8_ENABLE_WEBASSEMBLY
bool Script::IsWasm() const {
return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM;
}
#endif // V8_ENABLE_WEBASSEMBLY
bool Script::IsModule() const {
return Utils::OpenHandle(this)->origin_options().IsModule();
......@@ -430,10 +434,12 @@ bool Script::GetPossibleBreakpoints(
int Script::GetSourceOffset(const Location& location) const {
i::Handle<i::Script> script = Utils::OpenHandle(this);
#if V8_ENABLE_WEBASSEMBLY
if (script->type() == i::Script::TYPE_WASM) {
DCHECK_EQ(0, location.GetLineNumber());
return location.GetColumnNumber();
}
#endif // V8_ENABLE_WEBASSEMBLY
int line = std::max(location.GetLineNumber() - script->line_offset(), 0);
int column = location.GetColumnNumber();
......@@ -676,14 +682,18 @@ void GetLoadedScripts(Isolate* v8_isolate,
i::Script::Iterator iterator(isolate);
for (i::Script script = iterator.Next(); !script.is_null();
script = iterator.Next()) {
if (script.type() == i::Script::TYPE_NORMAL ||
script.type() == i::Script::TYPE_WASM) {
if (script.HasValidSource()) {
i::HandleScope handle_scope(isolate);
i::Handle<i::Script> script_handle(script, isolate);
scripts.Append(ToApiHandle<Script>(script_handle));
}
#if V8_ENABLE_WEBASSEMBLY
if (script.type() != i::Script::TYPE_NORMAL &&
script.type() != i::Script::TYPE_WASM) {
continue;
}
#else
if (script.type() != i::Script::TYPE_NORMAL) continue;
#endif // V8_ENABLE_WEBASSEMBLY
if (!script.HasValidSource()) continue;
i::HandleScope handle_scope(isolate);
i::Handle<i::Script> script_handle(script, isolate);
scripts.Append(ToApiHandle<Script>(script_handle));
}
}
}
......
......@@ -154,7 +154,6 @@ class V8_EXPORT_PRIVATE Script {
MaybeLocal<String> SourceMappingURL() const;
Maybe<int> ContextId() const;
MaybeLocal<String> Source() const;
bool IsWasm() const;
bool IsModule() const;
bool GetPossibleBreakpoints(
const debug::Location& start, const debug::Location& end,
......@@ -167,6 +166,7 @@ class V8_EXPORT_PRIVATE Script {
bool SetBreakpoint(v8::Local<v8::String> condition, debug::Location* location,
BreakpointId* id) const;
#if V8_ENABLE_WEBASSEMBLY
bool IsWasm() const;
void RemoveWasmBreakpoint(BreakpointId id);
#endif // V8_ENABLE_WEBASSEMBLY
bool SetBreakpointOnScriptEntry(BreakpointId* id) const;
......
......@@ -35,8 +35,10 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
}
context_ = Handle<Context>::cast(frame_inspector->GetContext());
#if V8_ENABLE_WEBASSEMBLY
// We should not instantiate a ScopeIterator for wasm frames.
DCHECK_NE(Script::TYPE_WASM, frame_inspector->GetScript()->type());
#endif // V8_ENABLE_WEBASSEMBLY
TryParseAndRetrieveScopes(strategy);
}
......
......@@ -2148,9 +2148,13 @@ void Debug::ProcessCompileEvent(bool has_compile_error, Handle<Script> script) {
// inspector to filter scripts by native context.
script->set_context_data(isolate_->native_context()->debug_context_id());
if (ignore_events()) return;
#if V8_ENABLE_WEBASSEMBLY
if (!script->IsUserJavaScript() && script->type() != i::Script::TYPE_WASM) {
return;
}
#else
if (!script->IsUserJavaScript()) return;
#endif // V8_ENABLE_WEBASSEMBLY
if (!debug_delegate_) return;
SuppressDebug while_processing(this);
DebugScope debug_scope(this);
......
......@@ -2158,11 +2158,15 @@ void Script::ScriptPrint(std::ostream& os) { // NOLINT
os << "\n - context data: " << Brief(context_data());
os << "\n - compilation type: " << compilation_type();
os << "\n - line ends: " << Brief(line_ends());
if (type() == TYPE_WASM) {
bool is_wasm = false;
#if V8_ENABLE_WEBASSEMBLY
if ((is_wasm = (type() == TYPE_WASM))) {
if (has_wasm_breakpoint_infos()) {
os << "\n - wasm_breakpoint_infos: " << Brief(wasm_breakpoint_infos());
}
} else {
}
#endif // V8_ENABLE_WEBASSEMBLY
if (!is_wasm) {
if (has_eval_from_shared()) {
os << "\n - eval from shared: " << Brief(eval_from_shared());
}
......
......@@ -73,9 +73,6 @@
#if V8_ENABLE_WEBASSEMBLY
#include "src/wasm/wasm-objects.h"
#endif // V8_ENABLE_WEBASSEMBLY
#if V8_ENABLE_WEBASSEMBLY
#include "src/debug/debug-wasm-objects.h"
#endif // V8_ENABLE_WEBASSEMBLY
......@@ -5326,9 +5323,11 @@ Handle<String> JSMessageObject::GetSourceLine() const {
Isolate* isolate = GetIsolate();
Handle<Script> the_script(script(), isolate);
#if V8_ENABLE_WEBASSEMBLY
if (the_script->type() == Script::TYPE_WASM) {
return isolate->factory()->empty_string();
}
#endif // V8_ENABLE_WEBASSEMBLY
Script::PositionInfo info;
const Script::OffsetFlag offset_flag = Script::WITH_OFFSET;
......
......@@ -4745,8 +4745,10 @@ template <typename LocalIsolate>
// static
void Script::InitLineEnds(LocalIsolate* isolate, Handle<Script> script) {
if (!script->line_ends().IsUndefined(isolate)) return;
#if V8_ENABLE_WEBASSEMBLY
DCHECK(script->type() != Script::TYPE_WASM ||
script->source_mapping_url().IsString());
#endif // V8_ENABLE_WEBASSEMBLY
Object src_obj = script->source();
if (!src_obj.IsString()) {
......@@ -4769,26 +4771,29 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Script::InitLineEnds(
bool Script::GetPositionInfo(Handle<Script> script, int position,
PositionInfo* info, OffsetFlag offset_flag) {
bool init_line_ends = true;
#if V8_ENABLE_WEBASSEMBLY
// For wasm, we do not create an artificial line_ends array, but do the
// translation directly.
if (script->type() != Script::TYPE_WASM)
InitLineEnds(script->GetIsolate(), script);
init_line_ends = script->type() != Script::TYPE_WASM;
#endif // V8_ENABLE_WEBASSEMBLY
if (init_line_ends) InitLineEnds(script->GetIsolate(), script);
return script->GetPositionInfo(position, info, offset_flag);
}
bool Script::IsUserJavaScript() const { return type() == Script::TYPE_NORMAL; }
bool Script::ContainsAsmModule() {
#if V8_ENABLE_WEBASSEMBLY
bool Script::ContainsAsmModule() {
DisallowGarbageCollection no_gc;
SharedFunctionInfo::ScriptIterator iter(this->GetIsolate(), *this);
for (SharedFunctionInfo info = iter.Next(); !info.is_null();
info = iter.Next()) {
if (info.HasAsmWasmData()) return true;
}
#endif // V8_ENABLE_WEBASSEMBLY
return false;
}
#endif // V8_ENABLE_WEBASSEMBLY
namespace {
......
......@@ -23,12 +23,7 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(Script)
NEVER_READ_ONLY_SPACE_IMPL(Script)
SMI_ACCESSORS(Script, type, kScriptTypeOffset)
ACCESSORS_CHECKED(Script, eval_from_shared_or_wrapped_arguments, Object,
kEvalFromSharedOrWrappedArgumentsOffset,
this->type() != TYPE_WASM)
SMI_ACCESSORS_CHECKED(Script, eval_from_position, kEvalFromPositionOffset,
this->type() != TYPE_WASM)
#if V8_ENABLE_WEBASSEMBLY
ACCESSORS_CHECKED(Script, wasm_breakpoint_infos, FixedArray,
kEvalFromSharedOrWrappedArgumentsOffset,
this->type() == TYPE_WASM)
......@@ -36,6 +31,18 @@ ACCESSORS_CHECKED(Script, wasm_managed_native_module, Object,
kEvalFromPositionOffset, this->type() == TYPE_WASM)
ACCESSORS_CHECKED(Script, wasm_weak_instance_list, WeakArrayList,
kSharedFunctionInfosOffset, this->type() == TYPE_WASM)
#define CHECK_SCRIPT_NOT_WASM this->type() != TYPE_WASM
#else
#define CHECK_SCRIPT_NOT_WASM true
#endif // V8_ENABLE_WEBASSEMBLY
SMI_ACCESSORS(Script, type, kScriptTypeOffset)
ACCESSORS_CHECKED(Script, eval_from_shared_or_wrapped_arguments, Object,
kEvalFromSharedOrWrappedArgumentsOffset,
CHECK_SCRIPT_NOT_WASM)
SMI_ACCESSORS_CHECKED(Script, eval_from_position, kEvalFromPositionOffset,
CHECK_SCRIPT_NOT_WASM)
#undef CHECK_SCRIPT_NOT_WASM
bool Script::is_wrapped() const {
return eval_from_shared_or_wrapped_arguments().IsFixedArray();
......@@ -67,19 +74,24 @@ FixedArray Script::wrapped_arguments() const {
}
DEF_GETTER(Script, shared_function_infos, WeakFixedArray) {
return type() == TYPE_WASM
? ReadOnlyRoots(GetHeap()).empty_weak_fixed_array()
: TaggedField<WeakFixedArray, kSharedFunctionInfosOffset>::load(
*this);
#if V8_ENABLE_WEBASSEMBLY
if (type() == TYPE_WASM) {
return ReadOnlyRoots(GetHeap()).empty_weak_fixed_array();
}
#endif // V8_ENABLE_WEBASSEMBLY
return TaggedField<WeakFixedArray, kSharedFunctionInfosOffset>::load(*this);
}
void Script::set_shared_function_infos(WeakFixedArray value,
WriteBarrierMode mode) {
#if V8_ENABLE_WEBASSEMBLY
DCHECK_NE(TYPE_WASM, type());
#endif // V8_ENABLE_WEBASSEMBLY
TaggedField<WeakFixedArray, kSharedFunctionInfosOffset>::store(*this, value);
CONDITIONAL_WRITE_BARRIER(*this, kSharedFunctionInfosOffset, value, mode);
}
#if V8_ENABLE_WEBASSEMBLY
bool Script::has_wasm_breakpoint_infos() const {
return type() == TYPE_WASM && wasm_breakpoint_infos().length() > 0;
}
......@@ -88,6 +100,13 @@ wasm::NativeModule* Script::wasm_native_module() const {
return Managed<wasm::NativeModule>::cast(wasm_managed_native_module()).raw();
}
bool Script::break_on_entry() const { return BreakOnEntryBit::decode(flags()); }
void Script::set_break_on_entry(bool value) {
set_flags(BreakOnEntryBit::update(flags(), value));
}
#endif // V8_ENABLE_WEBASSEMBLY
Script::CompilationType Script::compilation_type() {
return CompilationTypeBit::decode(flags());
}
......@@ -107,12 +126,6 @@ void Script::set_is_repl_mode(bool value) {
set_flags(IsReplModeBit::update(flags(), value));
}
bool Script::break_on_entry() const { return BreakOnEntryBit::decode(flags()); }
void Script::set_break_on_entry(bool value) {
set_flags(BreakOnEntryBit::update(flags(), value));
}
ScriptOriginOptions Script::origin_options() {
return ScriptOriginOptions(OriginOptionsBits::decode(flags()));
}
......
......@@ -35,7 +35,9 @@ class Script : public TorqueGeneratedScript<Script, Struct> {
TYPE_NATIVE = 0,
TYPE_EXTENSION = 1,
TYPE_NORMAL = 2,
#if V8_ENABLE_WEBASSEMBLY
TYPE_WASM = 3,
#endif // V8_ENABLE_WEBASSEMBLY
TYPE_INSPECTOR = 4
};
......@@ -76,6 +78,7 @@ class Script : public TorqueGeneratedScript<Script, Struct> {
// function infos created from this script.
DECL_ACCESSORS(shared_function_infos, WeakFixedArray)
#if V8_ENABLE_WEBASSEMBLY
// [wasm_breakpoint_infos]: the list of {BreakPointInfo} objects describing
// all WebAssembly breakpoints for modules/instances managed via this script.
// This must only be called if the type of this script is TYPE_WASM.
......@@ -92,6 +95,17 @@ class Script : public TorqueGeneratedScript<Script, Struct> {
// This must only be called if the type of this script is TYPE_WASM.
DECL_ACCESSORS(wasm_weak_instance_list, WeakArrayList)
// [break_on_entry] (wasm only): whether an instrumentation breakpoint is set
// for this script; this information will be transferred to existing and
// future instances to make sure that we stop before executing any code in
// this wasm module.
inline bool break_on_entry() const;
inline void set_break_on_entry(bool value);
// Check if the script contains any Asm modules.
bool ContainsAsmModule();
#endif // V8_ENABLE_WEBASSEMBLY
// [compilation_type]: how the the script was compiled. Encoded in the
// 'flags' field.
inline CompilationType compilation_type();
......@@ -107,13 +121,6 @@ class Script : public TorqueGeneratedScript<Script, Struct> {
inline bool is_repl_mode() const;
inline void set_is_repl_mode(bool value);
// [break_on_entry] (wasm only): whether an instrumentation breakpoint is set
// for this script; this information will be transferred to existing and
// future instances to make sure that we stop before executing any code in
// this wasm module.
inline bool break_on_entry() const;
inline void set_break_on_entry(bool value);
// [origin_options]: optional attributes set by the embedder via ScriptOrigin,
// and used by the embedder to make decisions about the script. V8 just passes
// this through. Encoded in the 'flags' field.
......@@ -129,9 +136,6 @@ class Script : public TorqueGeneratedScript<Script, Struct> {
// Retrieve source position from where eval was called.
static int GetEvalPosition(Isolate* isolate, Handle<Script> script);
// Check if the script contains any Asm modules.
bool ContainsAsmModule();
// Init line_ends array with source code positions of line ends.
template <typename LocalIsolate>
EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE)
......
......@@ -31,12 +31,9 @@
#include "src/snapshot/embedded/embedded-data.h"
#include "src/snapshot/snapshot.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/wasm/wasm-objects-inl.h"
#endif // V8_ENABLE_WEBASSEMBLY
#if V8_ENABLE_WEBASSEMBLY
#include "src/debug/debug-wasm-objects.h"
#include "src/wasm/wasm-objects-inl.h"
#endif // V8_ENABLE_WEBASSEMBLY
namespace v8 {
......@@ -583,10 +580,12 @@ namespace {
int ScriptLinePosition(Handle<Script> script, int line) {
if (line < 0) return -1;
#if V8_ENABLE_WEBASSEMBLY
if (script->type() == Script::TYPE_WASM) {
// Wasm positions are relative to the start of the module.
return 0;
}
#endif // V8_ENABLE_WEBASSEMBLY
Script::InitLineEnds(script->GetIsolate(), script);
......@@ -623,12 +622,16 @@ Handle<Object> GetJSPositionInfo(Handle<Script> script, int position,
return isolate->factory()->null_value();
}
#if V8_ENABLE_WEBASSEMBLY
const bool is_wasm_script = script->type() == Script::TYPE_WASM;
#else
const bool is_wasm_script = false;
#endif // V8_ENABLE_WEBASSEMBLY
Handle<String> sourceText =
script->type() == Script::TYPE_WASM
? isolate->factory()->empty_string()
: isolate->factory()->NewSubString(
handle(String::cast(script->source()), isolate),
info.line_start, info.line_end);
is_wasm_script ? isolate->factory()->empty_string()
: isolate->factory()->NewSubString(
handle(String::cast(script->source()), isolate),
info.line_start, info.line_end);
Handle<JSObject> jsinfo =
isolate->factory()->NewJSObject(isolate->object_function());
......
......@@ -56,9 +56,11 @@ ScriptCompiler::CachedData* CodeSerializer::Serialize(
script->name().ShortPrint();
PrintF("]\n");
}
#if V8_ENABLE_WEBASSEMBLY
// TODO(7110): Enable serialization of Asm modules once the AsmWasmData is
// context independent.
if (script->ContainsAsmModule()) return nullptr;
#endif // V8_ENABLE_WEBASSEMBLY
// Serialize code object.
Handle<String> source(String::cast(script->source()), isolate);
......
......@@ -4588,7 +4588,9 @@ UNINITIALIZED_TEST(LoadedAtStartupScripts) {
CHECK_EQ(count_by_type[i::Script::TYPE_NATIVE], 0);
CHECK_EQ(count_by_type[i::Script::TYPE_EXTENSION], 1);
CHECK_EQ(count_by_type[i::Script::TYPE_NORMAL], 1);
#if V8_ENABLE_WEBASSEMBLY
CHECK_EQ(count_by_type[i::Script::TYPE_WASM], 0);
#endif // V8_ENABLE_WEBASSEMBLY
CHECK_EQ(count_by_type[i::Script::TYPE_INSPECTOR], 0);
i::Handle<i::Script> gc_script =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment