[turbofan] Create initial map on-demand for F.prototype.

When accessing the "prototype" property of a known JSFunction in
TurboFan, we can automatically create the initial map if it hasn't been
instantiated so far. This happens with hand-grown inheritance mechanisms
where the base classes might not be instantiated regularly at all, but
the base class constructors are only called via F.p.call from the
subclass constructors.

R=mstarzinger@chromium.org
BUG=v8:5267

Review-Url: https://codereview.chromium.org/2830633002
Cr-Commit-Position: refs/heads/master@{#44720}
This commit is contained in:
bmeurer 2017-04-19 04:26:28 -07:00 committed by Commit bot
parent b161581947
commit 4da9be30c7

View File

@ -826,11 +826,11 @@ Reduction JSNativeContextSpecialization::ReduceJSLoadNamed(Node* node) {
p.name().is_identical_to(factory()->prototype_string())) {
// Optimize "prototype" property of functions.
Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value());
if (function->has_initial_map()) {
if (function->IsConstructor()) {
// We need to add a code dependency on the initial map of the
// {function} in order to be notified about changes to the
// "prototype" of {function}, so it doesn't make sense to
// continue unless deoptimization is enabled.
// "prototype" of {function}.
JSFunction::EnsureHasInitialMap(function);
Handle<Map> initial_map(function->initial_map(), isolate());
dependencies()->AssumeInitialMapCantChange(initial_map);
Handle<Object> prototype(function->prototype(), isolate());