Skip to content

Commit 9347bb7

Browse files
Cesar Soares LucasVladimir Kozlov
Cesar Soares Lucas
authored and
Vladimir Kozlov
committedMay 3, 2024
8330247: C2: CTW fail with assert(adr_t->is_known_instance_field()) failed: instance required
Reviewed-by: kvn
1 parent b20fa7b commit 9347bb7

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
 

‎src/hotspot/share/opto/macro.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ bool PhaseMacroExpand::can_eliminate_allocation(PhaseIterGVN* igvn, AllocateNode
573573
if (res_type == nullptr) {
574574
NOT_PRODUCT(fail_eliminate = "Neither instance or array allocation";)
575575
can_eliminate = false;
576+
} else if (!res_type->klass_is_exact()) {
577+
NOT_PRODUCT(fail_eliminate = "Not an exact type.";)
578+
can_eliminate = false;
576579
} else if (res_type->isa_aryptr()) {
577580
int length = alloc->in(AllocateNode::ALength)->find_int_con(-1);
578581
if (length < 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8330247
27+
* @summary Check that Reduce Allocation Merges doesn't try to reduce non-exact allocations.
28+
* @library /test/lib /
29+
* @modules java.base/jdk.internal.misc
30+
* @requires vm.debug & vm.flagless & vm.compiler2.enabled & vm.opt.final.EliminateAllocations
31+
* @run main/othervm -XX:CompileCommand=compileonly,*TestReduceAllocationAndNonExactAllocate*::test
32+
* -XX:CompileCommand=compileonly,*::allocateInstance
33+
* -XX:CompileCommand=dontinline,*TestReduceAllocationAndNonExactAllocate*::*
34+
* -XX:+UnlockDiagnosticVMOptions
35+
* -XX:+TraceReduceAllocationMerges
36+
* -XX:-TieredCompilation
37+
* -Xbatch
38+
* -Xcomp
39+
* -server
40+
* compiler.c2.TestReduceAllocationAndNonExactAllocate
41+
*/
42+
43+
package compiler.c2;
44+
45+
import jdk.internal.misc.Unsafe;
46+
47+
public class TestReduceAllocationAndNonExactAllocate {
48+
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
49+
50+
public static void main(String[] args) {
51+
try {
52+
if (test(20, Integer.class) != 2032) {
53+
throw new RuntimeException("Expected the value to be 2032.");
54+
}
55+
}
56+
catch (InstantiationException e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
61+
public static int test(int val, Class<?> c) throws InstantiationException {
62+
Object p = null;
63+
64+
if (val == 20) {
65+
p = UNSAFE.allocateInstance(c);
66+
}
67+
68+
dummy();
69+
return p != null ? 2032 : 3242;
70+
}
71+
72+
static int dummy() { return 42; }
73+
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on May 3, 2024

@openjdk-notifier[bot]
Please sign in to comment.