1052
|
1 |
|
|
2 |
# HG changeset patch
|
|
3 |
# User Lars T Hansen <lhansen@mozilla.com>
|
|
4 |
# Date 1519822672 -3600
|
|
5 |
# Node ID 800abe66894d6b07b24bccecbf6a65e2261076f6
|
1091
|
6 |
# Parent 6fbe9ec020d822b1deef5b0afe76b905b82308a1
|
1052
|
7 |
Bug 1375074 - Save and restore non-volatile x28 on ARM64 for generated unboxed object constructor. r=sstangl
|
|
8 |
|
|
9 |
diff --git a/js/src/jit-test/tests/bug1375074.js b/js/src/jit-test/tests/bug1375074.js
|
|
10 |
new file mode 100644
|
|
11 |
--- /dev/null
|
|
12 |
+++ b/js/src/jit-test/tests/bug1375074.js
|
|
13 |
@@ -0,0 +1,18 @@
|
|
14 |
+// This forces the VM to start creating unboxed objects and thus stresses a
|
|
15 |
+// particular path into generated code for a specialized unboxed object
|
|
16 |
+// constructor.
|
|
17 |
+
|
|
18 |
+var K = 2000; // 2000 should be plenty
|
|
19 |
+var s = "[";
|
|
20 |
+var i;
|
|
21 |
+for ( i=0; i < K-1; i++ )
|
|
22 |
+ s = s + `{"i":${i}},`;
|
|
23 |
+s += `{"i":${i}}]`;
|
|
24 |
+var v = JSON.parse(s);
|
|
25 |
+
|
|
26 |
+assertEq(v.length == K, true);
|
|
27 |
+
|
|
28 |
+for ( i=0; i < K; i++) {
|
|
29 |
+ assertEq(v[i] instanceof Object, true);
|
|
30 |
+ assertEq(v[i].i, i);
|
|
31 |
+}
|
|
32 |
diff --git a/js/src/vm/UnboxedObject.cpp b/js/src/vm/UnboxedObject.cpp
|
|
33 |
--- a/js/src/vm/UnboxedObject.cpp
|
|
34 |
+++ b/js/src/vm/UnboxedObject.cpp
|
1090
|
35 |
@@ -81,18 +81,25 @@ static const uintptr_t CLEAR_CONSTRUCTOR
|
|
36 |
masm.loadPtr(Address(masm.getStackPointer(), sizeof(void*)), propertiesReg);
|
|
37 |
masm.loadPtr(Address(masm.getStackPointer(), 2 * sizeof(void*)), newKindReg);
|
1052
|
38 |
#else
|
1090
|
39 |
propertiesReg = IntArgReg0;
|
|
40 |
newKindReg = IntArgReg1;
|
1052
|
41 |
#endif
|
|
42 |
|
|
43 |
#ifdef JS_CODEGEN_ARM64
|
1090
|
44 |
- // ARM64 communicates stack address via sp, but uses a pseudo-sp for
|
|
45 |
- // addressing.
|
|
46 |
+ // ARM64 communicates stack address via sp, but uses a pseudo-sp (PSP) for
|
|
47 |
+ // addressing. The register we use for PSP may however also be used by
|
|
48 |
+ // calling code, and it is nonvolatile, so save it. Do this as a special
|
|
49 |
+ // case first because the generic save/restore code needs the PSP to be
|
|
50 |
+ // initialized already.
|
|
51 |
+ MOZ_ASSERT(PseudoStackPointer64.Is(masm.GetStackPointer64()));
|
|
52 |
+ masm.Str(PseudoStackPointer64, vixl::MemOperand(sp, -16, vixl::PreIndex));
|
1052
|
53 |
+
|
1090
|
54 |
+ // Initialize the PSP from the SP.
|
|
55 |
masm.initStackPtr();
|
1052
|
56 |
#endif
|
|
57 |
|
1090
|
58 |
MOZ_ASSERT(propertiesReg.volatile_());
|
|
59 |
MOZ_ASSERT(newKindReg.volatile_());
|
1052
|
60 |
|
1090
|
61 |
AllocatableGeneralRegisterSet regs(GeneralRegisterSet::All());
|
|
62 |
regs.take(propertiesReg);
|
|
63 |
@@ -234,17 +241,32 @@ static const uintptr_t CLEAR_CONSTRUCTOR
|
|
64 |
masm.bind(&done);
|
1052
|
65 |
|
1090
|
66 |
if (object != ReturnReg) masm.movePtr(object, ReturnReg);
|
|
67 |
|
|
68 |
// Restore non-volatile registers which were saved on entry.
|
|
69 |
if (ScratchDoubleReg.volatile_()) masm.pop(ScratchDoubleReg);
|
|
70 |
masm.PopRegsInMask(savedNonVolatileRegisters);
|
1052
|
71 |
|
|
72 |
+#ifdef JS_CODEGEN_ARM64
|
1090
|
73 |
+ // Now restore the value that was in the PSP register on entry, and return.
|
1052
|
74 |
+
|
1090
|
75 |
+ // Obtain the correct SP from the PSP.
|
|
76 |
+ masm.Mov(sp, PseudoStackPointer64);
|
1052
|
77 |
+
|
1090
|
78 |
+ // Restore the saved value of the PSP register, this value is whatever the
|
|
79 |
+ // caller had saved in it, not any actual SP value, and it must not be
|
|
80 |
+ // overwritten subsequently.
|
|
81 |
+ masm.Ldr(PseudoStackPointer64, vixl::MemOperand(sp, 16, vixl::PostIndex));
|
1052
|
82 |
+
|
1090
|
83 |
+ // Perform a plain Ret(), as abiret() will move SP <- PSP and that is wrong.
|
|
84 |
+ masm.Ret(vixl::lr);
|
1052
|
85 |
+#else
|
1090
|
86 |
masm.abiret();
|
1052
|
87 |
+#endif
|
|
88 |
|
1090
|
89 |
masm.bind(&failureStoreOther);
|
1052
|
90 |
|
1090
|
91 |
// There was a failure while storing a value which cannot be stored at all
|
|
92 |
// in the unboxed object. Initialize the object so it is safe for GC and
|
|
93 |
// return null.
|
|
94 |
masm.initUnboxedObjectContents(object, templateObject);
|
1052
|
95 |
|