Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2395063002: [wasm] Fix wasm instantiation flakes (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "src/base/atomic-utils.h" 7 #include "src/base/atomic-utils.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 9
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 Handle<JSObject> owner; 1204 Handle<JSObject> owner;
1205 // If we don't clone, this will be null(). Otherwise, this will 1205 // If we don't clone, this will be null(). Otherwise, this will
1206 // be a weak link to the original. If we lose the original to GC, 1206 // be a weak link to the original. If we lose the original to GC,
1207 // this will be a cleared. We'll link the instances chain last. 1207 // this will be a cleared. We'll link the instances chain last.
1208 MaybeHandle<WeakCell> link_to_original; 1208 MaybeHandle<WeakCell> link_to_original;
1209 1209
1210 TRACE("Starting new module instantiation\n"); 1210 TRACE("Starting new module instantiation\n");
1211 { 1211 {
1212 Handle<WasmCompiledModule> original( 1212 Handle<WasmCompiledModule> original(
1213 WasmCompiledModule::cast(module_object->GetInternalField(0)), isolate); 1213 WasmCompiledModule::cast(module_object->GetInternalField(0)), isolate);
1214 // Always make a new copy of the code_table, since the old_code_table
1215 // may still have placeholders for imports.
1216 old_code_table = original->code_table();
1217 code_table = factory->CopyFixedArray(old_code_table);
1218
1219 if (original->has_weak_owning_instance()) { 1214 if (original->has_weak_owning_instance()) {
1220 WeakCell* tmp = original->ptr_to_weak_owning_instance(); 1215 WeakCell* tmp = original->ptr_to_weak_owning_instance();
titzer 2016/10/07 12:40:32 Why do we have a raw pointer here?
Mircea Trofin 2016/10/07 14:44:23 Not sure, I think this is from 0xC; it's immateria
1221 DCHECK(!tmp->cleared()); 1216 DCHECK(!tmp->cleared());
1222 // There is already an owner, clone everything. 1217 // There is already an owner, clone everything.
1223 owner = Handle<JSObject>(JSObject::cast(tmp->value()), isolate); 1218 owner = Handle<JSObject>(JSObject::cast(tmp->value()), isolate);
1219
1220 old_code_table = original->code_table();
1221 code_table = factory->CopyFixedArray(old_code_table);
titzer 2016/10/07 12:40:32 I don't understand how this fixes anything. As far
Mircea Trofin 2016/10/07 14:44:23 Consider the old code. Suppose the allocation on l
titzer 2016/10/07 15:37:42 Ok, until then can we have a switch to turn off th
1222
1224 // Insert the latest clone in front. 1223 // Insert the latest clone in front.
1225 TRACE("Cloning from %d\n", original->instance_id()); 1224 TRACE("Cloning from %d\n", original->instance_id());
1226 compiled_module = WasmCompiledModule::Clone(isolate, original); 1225 compiled_module = WasmCompiledModule::Clone(isolate, original);
1227 // Replace the strong reference to point to the new instance here. 1226 // Replace the strong reference to point to the new instance here.
1228 // This allows any of the other instances, including the original, 1227 // This allows any of the other instances, including the original,
1229 // to be collected. 1228 // to be collected.
1230 module_object->SetInternalField(0, *compiled_module); 1229 module_object->SetInternalField(0, *compiled_module);
1231 compiled_module->set_weak_module_object(original->weak_module_object()); 1230 compiled_module->set_weak_module_object(original->weak_module_object());
1232 link_to_original = factory->NewWeakCell(original); 1231 link_to_original = factory->NewWeakCell(original);
1233 // Don't link to original here. We remember the original 1232 // Don't link to original here. We remember the original
(...skipping 13 matching lines...) Expand all
1247 Handle<Code> code = factory->CopyCode(orig_code); 1246 Handle<Code> code = factory->CopyCode(orig_code);
1248 code_table->set(i, *code); 1247 code_table->set(i, *code);
1249 break; 1248 break;
1250 } 1249 }
1251 default: 1250 default:
1252 UNREACHABLE(); 1251 UNREACHABLE();
1253 } 1252 }
1254 } 1253 }
1255 RecordStats(isolate, code_table); 1254 RecordStats(isolate, code_table);
1256 } else { 1255 } else {
1256 // Always make a new copy of the code_table, since the old_code_table
1257 // may still have placeholders for imports.
1258 old_code_table = original->code_table();
1259 code_table = factory->CopyFixedArray(old_code_table);
1260
1257 // There was no owner, so we can reuse the original. 1261 // There was no owner, so we can reuse the original.
1258 compiled_module = original; 1262 compiled_module = original;
1259 TRACE("Reusing existing instance %d\n", compiled_module->instance_id()); 1263 TRACE("Reusing existing instance %d\n", compiled_module->instance_id());
1260 } 1264 }
1261 compiled_module->set_code_table(code_table); 1265 compiled_module->set_code_table(code_table);
1262 } 1266 }
1263 1267
1264 //-------------------------------------------------------------------------- 1268 //--------------------------------------------------------------------------
1265 // Allocate the instance object. 1269 // Allocate the instance object.
1266 //-------------------------------------------------------------------------- 1270 //--------------------------------------------------------------------------
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 WasmCompiledModule* compiled_module = 1917 WasmCompiledModule* compiled_module =
1914 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule)); 1918 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule));
1915 CHECK(compiled_module->has_weak_module_object()); 1919 CHECK(compiled_module->has_weak_module_object());
1916 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); 1920 CHECK(compiled_module->ptr_to_weak_module_object()->cleared());
1917 } 1921 }
1918 1922
1919 } // namespace testing 1923 } // namespace testing
1920 } // namespace wasm 1924 } // namespace wasm
1921 } // namespace internal 1925 } // namespace internal
1922 } // namespace v8 1926 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698