Commit d6f0905f authored by jgruber's avatar jgruber Committed by Commit Bot

[snapshot] Add helper to deserialize all builtins

Some tests need to ensure all builtins are deserialized. This adds a
helper to make that easier.

Drive-by-refactoring: Centralize lazy-deserialization tracing.

TBR=rmcilroy@chromium.org

Bug: v8:6624
Change-Id: I1f7caa6c539b12aabcba5b7b28c50ad40355848b
Reviewed-on: https://chromium-review.googlesource.com/891822
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50959}
parent 36d3ec46
......@@ -759,11 +759,6 @@ bool DebugEvaluate::FunctionHasNoSideEffect(Handle<SharedFunctionInfo> info) {
DCHECK(Builtins::IsLazy(builtin_index));
DCHECK_EQ(Builtins::TFJ, Builtins::KindOf(builtin_index));
if (FLAG_trace_lazy_deserialization) {
PrintF("Lazy-deserializing builtin %s\n",
Builtins::name(builtin_index));
}
code = Snapshot::DeserializeBuiltin(isolate, builtin_index);
DCHECK_NE(Builtins::kDeserializeLazy, code->builtin_index());
}
......
......@@ -67,11 +67,6 @@ Code* Interpreter::GetAndMaybeDeserializeBytecodeHandler(
if (!isolate_->heap()->IsDeserializeLazyHandler(code)) return code;
DCHECK(FLAG_lazy_handler_deserialization);
if (FLAG_trace_lazy_deserialization) {
PrintF("Lazy-deserializing handler %s\n",
Bytecodes::ToString(bytecode, operand_scale).c_str());
}
DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale));
code = Snapshot::DeserializeHandler(isolate_, bytecode, operand_scale);
......
......@@ -526,10 +526,6 @@ RUNTIME_FUNCTION(Runtime_DeserializeLazy) {
DCHECK(Builtins::IsLazy(builtin_id));
DCHECK_EQ(Builtins::TFJ, Builtins::KindOf(builtin_id));
if (FLAG_trace_lazy_deserialization) {
PrintF("Lazy-deserializing builtin %s\n", Builtins::name(builtin_id));
}
Code* code = Snapshot::DeserializeBuiltin(isolate, builtin_id);
DCHECK_EQ(builtin_id, code->builtin_index());
DCHECK_EQ(code, isolate->builtins()->builtin(builtin_id));
......
......@@ -89,6 +89,10 @@ MaybeHandle<Context> Snapshot::NewContextFromSnapshot(
// static
Code* Snapshot::DeserializeBuiltin(Isolate* isolate, int builtin_id) {
if (FLAG_trace_lazy_deserialization) {
PrintF("Lazy-deserializing builtin %s\n", Builtins::name(builtin_id));
}
base::ElapsedTimer timer;
if (FLAG_profile_deserialization) timer.Start();
......@@ -115,10 +119,34 @@ Code* Snapshot::DeserializeBuiltin(Isolate* isolate, int builtin_id) {
return code;
}
// static
void Snapshot::EnsureAllBuiltinsAreDeserialized(Isolate* isolate) {
if (!FLAG_lazy_deserialization) return;
Builtins* builtins = isolate->builtins();
for (int i = 0; i < Builtins::builtin_count; i++) {
if (!Builtins::IsLazy(i)) continue;
DCHECK_NE(Builtins::kDeserializeLazy, i);
Code* code = builtins->builtin(i);
if (code->builtin_index() == Builtins::kDeserializeLazy) {
code = Snapshot::DeserializeBuiltin(isolate, i);
}
DCHECK_EQ(i, code->builtin_index());
DCHECK_EQ(code, builtins->builtin(i));
}
}
// static
Code* Snapshot::DeserializeHandler(Isolate* isolate,
interpreter::Bytecode bytecode,
interpreter::OperandScale operand_scale) {
if (FLAG_trace_lazy_deserialization) {
PrintF("Lazy-deserializing handler %s\n",
interpreter::Bytecodes::ToString(bytecode, operand_scale).c_str());
}
base::ElapsedTimer timer;
if (FLAG_profile_deserialization) timer.Start();
......
......@@ -97,6 +97,7 @@ class Snapshot : public AllStatic {
// runtime after the isolate (and the builtins table) has been fully
// initialized.
static Code* DeserializeBuiltin(Isolate* isolate, int builtin_id);
static void EnsureAllBuiltinsAreDeserialized(Isolate* isolate);
// Deserializes a single given handler code object. Intended to be called at
// runtime after the isolate has been fully initialized.
......
......@@ -6720,17 +6720,13 @@ TEST(BuiltinsExceptionPrediction) {
v8::HandleScope handle_scope(isolate);
v8::Context::New(isolate);
i::Snapshot::EnsureAllBuiltinsAreDeserialized(iisolate);
i::Builtins* builtins = iisolate->builtins();
bool fail = false;
for (int i = 0; i < i::Builtins::builtin_count; i++) {
Code* builtin = builtins->builtin(i);
if (builtin->kind() != Code::BUILTIN) continue;
if (builtin->builtin_index() == i::Builtins::kDeserializeLazy &&
i::Builtins::IsLazy(i)) {
builtin = i::Snapshot::DeserializeBuiltin(iisolate, i);
}
auto prediction = builtin->GetBuiltinCatchPrediction();
USE(prediction);
}
......
......@@ -17,6 +17,8 @@ TEST(VerifyBuiltinsIsolateIndependence) {
Isolate* isolate = CcTest::i_isolate();
HandleScope handle_scope(isolate);
Snapshot::EnsureAllBuiltinsAreDeserialized(isolate);
// Build a white-list of all isolate-independent RelocInfo entry kinds.
constexpr int all_real_modes_mask =
(1 << (RelocInfo::LAST_REAL_RELOC_MODE + 1)) - 1;
......@@ -46,12 +48,6 @@ TEST(VerifyBuiltinsIsolateIndependence) {
for (int i = 0; i < Builtins::builtin_count; i++) {
Code* code = isolate->builtins()->builtin(i);
// Make sure the builtin is deserialized.
if (code->builtin_index() == Builtins::kDeserializeLazy &&
Builtins::IsLazy(i)) {
code = Snapshot::DeserializeBuiltin(isolate, i);
}
if (kVerbose) {
printf("%s %s\n", Builtins::KindNameOf(i), isolate->builtins()->name(i));
}
......
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