field-representation-tracking.js 2.26 KB
Newer Older
1 2 3 4
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
// Flags: --allow-natives-syntax
6 7 8 9 10 11 12 13 14
// Flags: --no-always-opt --opt

// Test that code embedding accesses to a Smi field gets properly
// deoptimized if s->t field representation changes are done in-place.
(function() {
  function O(x) { this.x = x; }

  function foo(o) { return o.x; }
  %PrepareFunctionForOptimization(foo);
15 16 17
  // We need to keep an instance around to make the GC stress testing work.
  const o1 = new O(1);
  foo(o1);
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  foo(new O(2));
  %OptimizeFunctionOnNextCall(foo);
  foo(new O(3));
  assertOptimized(foo);

  new O(null);
  assertUnoptimized(foo);
})();

// Test that code embedding assignments to a Smi field gets properly
// deoptimized if s->t field representation changes are done in-place.
(function() {
  function O(x) { this.x = x; }

  function foo(o) { o.x = 0; }
  %PrepareFunctionForOptimization(foo);
34 35 36
  // We need to keep an instance around to make the GC stress testing work.
  const o1 = new O(1);
  foo(o1);
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  foo(new O(2));
  %OptimizeFunctionOnNextCall(foo);
  foo(new O(3));
  assertOptimized(foo);

  new O(null);
  assertUnoptimized(foo);
})();

// Test that code embedding accesses to a HeapObject field gets properly
// deoptimized if h->t field representation changes are done in-place.
(function() {
  function O(x) { this.x = x; }

  function foo(o) { return o.x; }
  %PrepareFunctionForOptimization(foo);
53 54 55
  // We need to keep an instance around to make the GC stress testing work.
  const onull = new O(null);
  foo(onull);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  foo(new O("Hello"));
  %OptimizeFunctionOnNextCall(foo);
  foo(new O({}));
  assertOptimized(foo);

  new O(1);
  assertUnoptimized(foo);
})();

// Test that code embedding assignments to a Smi field gets properly
// deoptimized if s->t field representation changes are done in-place.
(function() {
  function O(x) { this.x = x; }

  function foo(o) { o.x = true; }
  %PrepareFunctionForOptimization(foo);
72 73 74
  // We need to keep an instance around to make the GC stress testing work.
  const onull = new O(null);
  foo(onull);
75 76 77 78 79 80 81 82
  foo(new O("Hello"));
  %OptimizeFunctionOnNextCall(foo);
  foo(new O({}));
  assertOptimized(foo);

  new O(1);
  assertUnoptimized(foo);
})();