NewScObject-InlineSlotCapacityLocking.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. (function testInlineSlotCapacityLocking1() {
  6. WScript.Echo("Test: testInlineSlotCapacityLocking1...");
  7. // Wrap the constructors into an object literal with PathTypeHandler to make sure we get fixed functions.
  8. // Note that scope slot arrays don't get fixed functions.
  9. var Namespace = {
  10. // This constructor creates objects with 8 inline slots and uses them all.
  11. ConstructedObject1: function () {
  12. this.a = 0;
  13. this.b = 0;
  14. this.c = 0;
  15. this.d = 0;
  16. this.e = 0;
  17. this.f = 0;
  18. this.g = 0;
  19. this.h = 0;
  20. },
  21. // This constructor creates objects with 8 inline slots, but leaves the last two slots empty.
  22. // We need the same number of inline slots to follow the same type path.
  23. ConstructedObject2: function () {
  24. this.a = 0;
  25. this.b = 0;
  26. this.c = 0;
  27. this.d = 0;
  28. this.e = 0;
  29. this.f = 0;
  30. }
  31. };
  32. // To follow the same type path the objects must be constructed from the same prototype.
  33. Namespace.ConstructedObject2.prototype = Namespace.ConstructedObject1.prototype;
  34. var construct1 = function () {
  35. // After the first call to this constructor we attempt to shrink inline slot capacity,
  36. // but no shrinking takes place, because we actually use all the slots.
  37. return new Namespace.ConstructedObject1();
  38. }
  39. // Let's construct the first object to populate the constructor cache.
  40. var o1 = construct1();
  41. // Running with -maxInterpretCount:1 will ensure we JIT before calling construct1 again.
  42. // Upon JIT-ing we will try to ensure that the inline slot capacity of the type handlers
  43. // on the type path to the final type is locked.
  44. var o2 = construct1();
  45. // Now let's construct an object from the other constructor, which will send it down the
  46. // same type path, but land on an earlier type handler.
  47. var o3 = new Namespace.ConstructedObject2();
  48. // If we now add more properties to reach the same type handler as o1 and o2, we shouldn't
  49. // hit any surprises with locked or unlocked inline slot capacity.
  50. // Bug 170326: EnsureInlineSlotCapacityLocked called when JIT-ing construct1
  51. // would lock inline slot capacity from the given type handler down the successor tree -
  52. // without starting at the root.
  53. o3.g = 1;
  54. o3.h = 1;
  55. WScript.Echo("Passed");
  56. })();