Skip to content

Commit f6e26f6

Browse files
Aleksei Voitylovadinn
authored andcommitted
8265756: AArch64: initialize memory allocated for locals according to Windows AArch64 stack page growth requirement in template interpreter
Reviewed-by: adinn, aph
1 parent 0a4c338 commit f6e26f6

File tree

3 files changed

+118
-7
lines changed

3 files changed

+118
-7
lines changed

src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,27 +1537,30 @@ address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) {
15371537
__ add(rlocals, esp, r2, ext::uxtx, 3);
15381538
__ sub(rlocals, rlocals, wordSize);
15391539

1540-
// Make room for locals
1541-
__ sub(rscratch1, esp, r3, ext::uxtx, 3);
1542-
1543-
// Padding between locals and fixed part of activation frame to ensure
1544-
// SP is always 16-byte aligned.
1545-
__ andr(sp, rscratch1, -16);
1540+
__ mov(rscratch1, esp);
15461541

15471542
// r3 - # of additional locals
15481543
// allocate space for locals
15491544
// explicitly initialize locals
1545+
// Initializing memory allocated for locals in the same direction as
1546+
// the stack grows to ensure page initialization order according
1547+
// to windows-aarch64 stack page growth requirement (see
1548+
// https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-160#stack)
15501549
{
15511550
Label exit, loop;
15521551
__ ands(zr, r3, r3);
15531552
__ br(Assembler::LE, exit); // do nothing if r3 <= 0
15541553
__ bind(loop);
1555-
__ str(zr, Address(__ post(rscratch1, wordSize)));
1554+
__ str(zr, Address(__ pre(rscratch1, -wordSize)));
15561555
__ sub(r3, r3, 1); // until everything initialized
15571556
__ cbnz(r3, loop);
15581557
__ bind(exit);
15591558
}
15601559

1560+
// Padding between locals and fixed part of activation frame to ensure
1561+
// SP is always 16-byte aligned.
1562+
__ andr(sp, rscratch1, -16);
1563+
15611564
// And the base dispatch table
15621565
__ get_dispatch();
15631566

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2021, BELLSOFT. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
/*
26+
* @test
27+
* @bug 8265756
28+
* @library /test/lib /
29+
* @compile TestLargeLocalVarsStackRegionHelper.jasm
30+
* @run main runtime.Locals.TestLargeLocalVarsStackRegion
31+
*/
32+
33+
package runtime.Locals;
34+
35+
import jdk.test.lib.Asserts;
36+
37+
public class TestLargeLocalVarsStackRegion {
38+
39+
// Some platforms (such as windows-aarch64) may have
40+
// stack page touch order restrictions.
41+
// Test calls method with large local vars stack region
42+
// to trigger usage of several stack memory pages and
43+
// check the validity of the touch order.
44+
//
45+
// Helper method is written in jasm as this allows to
46+
// specify local vars stack region size directly.
47+
public static void main(String args[]) {
48+
Asserts.assertEQ(TestLargeLocalVarsStackRegionHelper.tst(), 0);
49+
}
50+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2021, BELLSOFT. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
package runtime/Locals;
26+
27+
public class TestLargeLocalVarsStackRegionHelper
28+
{
29+
30+
// Method with large locals vars region.
31+
// Purpose: verify stack pages touch order (see TestLargeLocalVarsStackRegion.java)
32+
public static Method tst:"()I"
33+
stack 3 locals 65535
34+
{
35+
iconst_1;
36+
newarray int;
37+
dup;
38+
astore_w 65500;
39+
aload_w 65500;
40+
if_acmpne FAILED;
41+
42+
iconst_0;
43+
ireturn; // passed
44+
45+
FAILED:
46+
iconst_1; // failed
47+
ireturn;
48+
}
49+
50+
public Method <init>:"()V"
51+
stack 1 locals 1
52+
{
53+
aload_0;
54+
invokespecial Method java/lang/Object.<init>:"()V";
55+
return;
56+
}
57+
58+
}

0 commit comments

Comments
 (0)