Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created April 14, 2016 07:23
Show Gist options
  • Save mraleph/ad0f453ddb97ba3f26e2c1395e7e97b0 to your computer and use it in GitHub Desktop.
Save mraleph/ad0f453ddb97ba3f26e2c1395e7e97b0 to your computer and use it in GitHub Desktop.
// d8 --allow-natives-syntax --trace-opt --trace-deopt test.js
var o = { x: 0, y: 0 };
print(%HasFastProperties(o)); // => true
Object.setPrototypeOf(o, { random: 'stuff', stuff: function() { } });
print(%HasFastProperties(o)); // => true
function foo (o) {
return o.x;
}
function bar (o) {
return o.random;
}
function baz (o) {
return o.stuff();
}
function opt(f, o) {
f(o); f(o); f(o);
%OptimizeFunctionOnNextCall(f);
f(o);
}
opt(foo, o);
opt(bar, o);
opt(baz, o);
// No deoptimization below
print('{{{')
Object.setPrototypeOf(o, { emptiness: 'is form', form: 'is emptiness', stuff: function ( ) { } });
print('}}}')
print(%HasFastProperties(o)); // => true
// Eager deopts in each call below
foo(o);
bar(o);
baz(o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment