Skip to content

Commit ec1782c

Browse files
committed
8331194: NPE in ArrayCreationTree.java with -XX:-UseCompressedOops
Reviewed-by: kvn Backport-of: 005fb67
1 parent 024b39c commit ec1782c

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

src/hotspot/share/opto/machnode.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,10 @@ class MachSafePointNode : public MachReturnNode {
870870
assert(verify_jvms(jvms), "jvms must match");
871871
return in(_jvmadj + jvms->monitor_box_offset(idx));
872872
}
873+
Node* scalarized_obj(const JVMState* jvms, uint idx) const {
874+
assert(verify_jvms(jvms), "jvms must match");
875+
return in(_jvmadj + jvms->scloff() + idx);
876+
}
873877
void set_local(const JVMState* jvms, uint idx, Node *c) {
874878
assert(verify_jvms(jvms), "jvms must match");
875879
set_req(_jvmadj + jvms->locoff() + idx, c);

src/hotspot/share/opto/output.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,27 @@ bool PhaseOutput::contains_as_owner(GrowableArray<MonitorValue*> *monarray, Obje
974974
return false;
975975
}
976976

977+
// Determine if there is a scalar replaced object description represented by 'ov'.
978+
bool PhaseOutput::contains_as_scalarized_obj(JVMState* jvms, MachSafePointNode* sfn,
979+
GrowableArray<ScopeValue*>* objs,
980+
ObjectValue* ov) const {
981+
for (int i = 0; i < jvms->scl_size(); i++) {
982+
Node* n = sfn->scalarized_obj(jvms, i);
983+
// Other kinds of nodes that we may encounter here, for instance constants
984+
// representing values of fields of objects scalarized, aren't relevant for
985+
// us, since they don't map to ObjectValue.
986+
if (!n->is_SafePointScalarObject()) {
987+
continue;
988+
}
989+
990+
ObjectValue* other = (ObjectValue*) sv_for_node_id(objs, n->_idx);
991+
if (ov == other) {
992+
return true;
993+
}
994+
}
995+
return false;
996+
}
997+
977998
//--------------------------Process_OopMap_Node--------------------------------
978999
void PhaseOutput::Process_OopMap_Node(MachNode *mach, int current_offset) {
9791000
// Handle special safepoint nodes for synchronization
@@ -1137,7 +1158,10 @@ void PhaseOutput::Process_OopMap_Node(MachNode *mach, int current_offset) {
11371158

11381159
for (int j = 0; j< merge->possible_objects()->length(); j++) {
11391160
ObjectValue* ov = merge->possible_objects()->at(j)->as_ObjectValue();
1140-
bool is_root = locarray->contains(ov) || exparray->contains(ov) || contains_as_owner(monarray, ov);
1161+
bool is_root = locarray->contains(ov) ||
1162+
exparray->contains(ov) ||
1163+
contains_as_owner(monarray, ov) ||
1164+
contains_as_scalarized_obj(jvms, sfn, objs, ov);
11411165
ov->set_root(is_root);
11421166
}
11431167
}

src/hotspot/share/opto/output.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ class PhaseOutput : public Phase {
209209

210210
bool starts_bundle(const Node *n) const;
211211
bool contains_as_owner(GrowableArray<MonitorValue*> *monarray, ObjectValue *ov) const;
212+
bool contains_as_scalarized_obj(JVMState* jvms, MachSafePointNode* sfn,
213+
GrowableArray<ScopeValue*>* objs,
214+
ObjectValue* ov) const;
212215

213216
// Dump formatted assembly
214217
#if defined(SUPPORT_OPTO_ASSEMBLY)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 8331194
27+
* @summary Check that Reduce Allocation Merges doesn't crash when an input
28+
* of the Phi is not the _current_ output of the Phi but said input
29+
* needs to be rematerialized because it's used regardless of the
30+
* Phi output.
31+
* @run main/othervm -XX:CompileCommand=dontinline,*TestReduceAllocationAndNestedScalarized*::test
32+
* -XX:CompileCommand=compileonly,*TestReduceAllocationAndNestedScalarized*::test
33+
* -XX:CompileCommand=compileonly,*Picture*::*init*
34+
* -XX:CompileCommand=compileonly,*Point*::*init*
35+
* -XX:CompileCommand=exclude,*Unloaded*::*
36+
* -XX:+IgnoreUnrecognizedVMOptions
37+
* -XX:-TieredCompilation
38+
* -XX:-UseCompressedOops
39+
* -Xcomp
40+
* -server
41+
* compiler.escapeAnalysis.TestReduceAllocationAndNestedScalarized
42+
* @run main compiler.escapeAnalysis.TestReduceAllocationAndNestedScalarized
43+
*/
44+
45+
package compiler.escapeAnalysis;
46+
47+
public class TestReduceAllocationAndNestedScalarized {
48+
static class Picture {
49+
public Point first;
50+
public Point second;
51+
}
52+
53+
static class Point {
54+
int x;
55+
}
56+
57+
static class Unloaded {
58+
}
59+
60+
static int test(boolean cond) {
61+
Picture p = new Picture();
62+
p.first = new Point();
63+
Point p2 = p.first;
64+
65+
if (cond) p2 = new Point();
66+
67+
p.second = p2;
68+
69+
new Unloaded();
70+
71+
return p.first.x;
72+
}
73+
74+
public static void main(String[] args) {
75+
Picture pic = new Picture();
76+
Point pnt = new Point();
77+
int res = test(true);
78+
System.out.println("Result is: " + res);
79+
}
80+
}

0 commit comments

Comments
 (0)