test_jit-model-02.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests that JITOptimizations create OptimizationSites, and the underlying
  6. * hasSuccessfulOutcome/isSuccessfulOutcome work as intended.
  7. */
  8. function run_test() {
  9. run_next_test();
  10. }
  11. add_task(function test() {
  12. let {
  13. JITOptimizations, hasSuccessfulOutcome, isSuccessfulOutcome, SUCCESSFUL_OUTCOMES
  14. } = require("devtools/client/performance/modules/logic/jit");
  15. let rawSites = [];
  16. rawSites.push(gRawSite2);
  17. rawSites.push(gRawSite2);
  18. rawSites.push(gRawSite1);
  19. rawSites.push(gRawSite1);
  20. rawSites.push(gRawSite2);
  21. rawSites.push(gRawSite3);
  22. let jit = new JITOptimizations(rawSites, gStringTable.stringTable);
  23. let sites = jit.optimizationSites;
  24. let [first, second, third] = sites;
  25. /* hasSuccessfulOutcome */
  26. equal(hasSuccessfulOutcome(first), false,
  27. "hasSuccessfulOutcome() returns expected (1)");
  28. equal(hasSuccessfulOutcome(second), true,
  29. "hasSuccessfulOutcome() returns expected (2)");
  30. equal(hasSuccessfulOutcome(third), true,
  31. "hasSuccessfulOutcome() returns expected (3)");
  32. /* .data.attempts */
  33. equal(first.data.attempts.length, 2,
  34. "optSite.data.attempts has the correct amount of attempts (1)");
  35. equal(second.data.attempts.length, 5,
  36. "optSite.data.attempts has the correct amount of attempts (2)");
  37. equal(third.data.attempts.length, 3,
  38. "optSite.data.attempts has the correct amount of attempts (3)");
  39. /* .data.types */
  40. equal(first.data.types.length, 1,
  41. "optSite.data.types has the correct amount of IonTypes (1)");
  42. equal(second.data.types.length, 2,
  43. "optSite.data.types has the correct amount of IonTypes (2)");
  44. equal(third.data.types.length, 1,
  45. "optSite.data.types has the correct amount of IonTypes (3)");
  46. /* isSuccessfulOutcome */
  47. ok(SUCCESSFUL_OUTCOMES.length, "Have some successful outcomes in SUCCESSFUL_OUTCOMES");
  48. SUCCESSFUL_OUTCOMES.forEach(outcome =>
  49. ok(isSuccessfulOutcome(outcome),
  50. `${outcome} considered a successful outcome via isSuccessfulOutcome()`));
  51. });
  52. var gStringTable = new RecordingUtils.UniqueStrings();
  53. function uniqStr(s) {
  54. return gStringTable.getOrAddStringIndex(s);
  55. }
  56. var gRawSite1 = {
  57. line: 12,
  58. column: 2,
  59. types: [{
  60. mirType: uniqStr("Object"),
  61. site: uniqStr("A (http://foo/bar/bar:12)"),
  62. typeset: [{
  63. keyedBy: uniqStr("constructor"),
  64. name: uniqStr("Foo"),
  65. location: uniqStr("A (http://foo/bar/baz:12)")
  66. }, {
  67. keyedBy: uniqStr("constructor"),
  68. location: uniqStr("A (http://foo/bar/baz:12)")
  69. }]
  70. }, {
  71. mirType: uniqStr("Int32"),
  72. site: uniqStr("A (http://foo/bar/bar:12)"),
  73. typeset: [{
  74. keyedBy: uniqStr("primitive"),
  75. location: uniqStr("self-hosted")
  76. }]
  77. }],
  78. attempts: {
  79. schema: {
  80. outcome: 0,
  81. strategy: 1
  82. },
  83. data: [
  84. [uniqStr("Failure1"), uniqStr("SomeGetter1")],
  85. [uniqStr("Failure1"), uniqStr("SomeGetter1")],
  86. [uniqStr("Failure1"), uniqStr("SomeGetter1")],
  87. [uniqStr("Failure2"), uniqStr("SomeGetter2")],
  88. [uniqStr("Inlined"), uniqStr("SomeGetter3")]
  89. ]
  90. }
  91. };
  92. var gRawSite2 = {
  93. line: 34,
  94. types: [{
  95. mirType: uniqStr("Int32"),
  96. site: uniqStr("Receiver")
  97. }],
  98. attempts: {
  99. schema: {
  100. outcome: 0,
  101. strategy: 1
  102. },
  103. data: [
  104. [uniqStr("Failure1"), uniqStr("SomeGetter1")],
  105. [uniqStr("Failure2"), uniqStr("SomeGetter2")]
  106. ]
  107. }
  108. };
  109. var gRawSite3 = {
  110. line: 78,
  111. types: [{
  112. mirType: uniqStr("Object"),
  113. site: uniqStr("A (http://foo/bar/bar:12)"),
  114. typeset: [{
  115. keyedBy: uniqStr("constructor"),
  116. name: uniqStr("Foo"),
  117. location: uniqStr("A (http://foo/bar/baz:12)")
  118. }, {
  119. keyedBy: uniqStr("primitive"),
  120. location: uniqStr("self-hosted")
  121. }]
  122. }],
  123. attempts: {
  124. schema: {
  125. outcome: 0,
  126. strategy: 1
  127. },
  128. data: [
  129. [uniqStr("Failure1"), uniqStr("SomeGetter1")],
  130. [uniqStr("Failure2"), uniqStr("SomeGetter2")],
  131. [uniqStr("GenericSuccess"), uniqStr("SomeGetter3")]
  132. ]
  133. }
  134. };