Commit 073d0d5e authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

Reland "[Compile] Ensure we don't access the native context during bytecode finalization."

This is a reland of 9cde8808 now the the underlying
problem in Chromium is fixed by:
   https://chromium-review.googlesource.com/c/chromium/src/+/1301459

Original change's description:
> [Compile] Ensure we don't access the native context during bytecode finalization.
>
> Resets the isolate's context to nullptr in debug builds during bytecode finalization
> to ensure that we don't rely on the native context during context independent
> unoptimized compilation.
>
> BUG=chromium:898076, v8:8041
>
> Change-Id: Ifaa5006a7a3d31d7fbd535ebb63f8889c75526c4
> Reviewed-on: https://chromium-review.googlesource.com/c/1297961
> Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#56979}

TBR=leszeks@chromium.org

Bug: chromium:898076, v8:8041
Change-Id: I11904e19e843b0eadab698196ac1ef9c7aeec766
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel; luci.chromium.try:linux_chromium_dbg_ng
Reviewed-on: https://chromium-review.googlesource.com/c/1301480Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57048}
parent fb9659fa
......@@ -504,6 +504,9 @@ bool FinalizeUnoptimizedCode(
UnoptimizedCompilationJobList* inner_function_jobs) {
DCHECK(AllowCompilation::IsAllowed(isolate));
// TODO(rmcilroy): Clear native context in debug once AsmJS generates doesn't
// rely on accessing native context during finalization.
// Allocate scope infos for the literal.
DeclarationScope::AllocateScopeInfos(parse_info, isolate);
......
......@@ -923,6 +923,12 @@ BytecodeGenerator::BytecodeGenerator(
Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(
Isolate* isolate, Handle<Script> script) {
DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
#ifdef DEBUG
// Unoptimized compilation should be context-independent. Verify that we don't
// access the native context by nulling it out during finalization.
SaveContext save(isolate);
isolate->set_context(nullptr);
#endif
AllocateDeferredConstants(isolate, script);
......
......@@ -42,15 +42,14 @@ const char* ProfilerExtension::kSource =
v8::Local<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) {
v8::Local<v8::Context> context = isolate->GetCurrentContext();
if (name->Equals(context, v8_str(isolate, "startProfiling")).FromJust()) {
if (name->StrictEquals(v8_str(isolate, "startProfiling"))) {
return v8::FunctionTemplate::New(isolate,
ProfilerExtension::StartProfiling);
}
if (name->Equals(context, v8_str(isolate, "stopProfiling")).FromJust()) {
if (name->StrictEquals(v8_str(isolate, "stopProfiling"))) {
return v8::FunctionTemplate::New(isolate, ProfilerExtension::StopProfiling);
}
if (name->Equals(context, v8_str(isolate, "collectSample")).FromJust()) {
if (name->StrictEquals(v8_str(isolate, "collectSample"))) {
return v8::FunctionTemplate::New(isolate, ProfilerExtension::CollectSample);
}
UNREACHABLE();
......
......@@ -7728,15 +7728,13 @@ static int lookup_count = 0;
v8::Local<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<String> name) {
lookup_count++;
if (name->Equals(isolate->GetCurrentContext(), v8_str("A")).FromJust()) {
if (name->StrictEquals(v8_str("A"))) {
return v8::FunctionTemplate::New(isolate, CallFun,
v8::Integer::New(isolate, 8));
} else if (name->Equals(isolate->GetCurrentContext(), v8_str("B"))
.FromJust()) {
} else if (name->StrictEquals(v8_str("B"))) {
return v8::FunctionTemplate::New(isolate, CallFun,
v8::Integer::New(isolate, 7));
} else if (name->Equals(isolate->GetCurrentContext(), v8_str("C"))
.FromJust()) {
} else if (name->StrictEquals(v8_str("C"))) {
return v8::FunctionTemplate::New(isolate, CallFun,
v8::Integer::New(isolate, 6));
} else {
......
......@@ -43,29 +43,24 @@ const char* TraceExtension::kSource =
v8::Local<v8::FunctionTemplate> TraceExtension::GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) {
v8::Local<v8::Context> context = isolate->GetCurrentContext();
if (name->Equals(context, v8::String::NewFromUtf8(isolate, "trace",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
if (name->StrictEquals(
v8::String::NewFromUtf8(isolate, "trace", v8::NewStringType::kNormal)
.ToLocalChecked())) {
return v8::FunctionTemplate::New(isolate, TraceExtension::Trace);
} else if (name->Equals(context,
v8::String::NewFromUtf8(isolate, "js_trace",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
} else if (name->StrictEquals(
v8::String::NewFromUtf8(isolate, "js_trace",
v8::NewStringType::kNormal)
.ToLocalChecked())) {
return v8::FunctionTemplate::New(isolate, TraceExtension::JSTrace);
} else if (name->Equals(context,
v8::String::NewFromUtf8(isolate, "js_entry_sp",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
} else if (name->StrictEquals(
v8::String::NewFromUtf8(isolate, "js_entry_sp",
v8::NewStringType::kNormal)
.ToLocalChecked())) {
return v8::FunctionTemplate::New(isolate, TraceExtension::JSEntrySP);
} else if (name->Equals(context,
v8::String::NewFromUtf8(isolate, "js_entry_sp_level2",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
} else if (name->StrictEquals(
v8::String::NewFromUtf8(isolate, "js_entry_sp_level2",
v8::NewStringType::kNormal)
.ToLocalChecked())) {
return v8::FunctionTemplate::New(isolate, TraceExtension::JSEntrySPLevel2);
}
UNREACHABLE();
......
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