Skip to content

Commit 02aaab1

Browse files
committedJun 19, 2023
8310126: C1: Missing receiver null check in Reference::get intrinsic
Reviewed-by: roland, shade
1 parent 492d25c commit 02aaab1

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
 

‎src/hotspot/share/c1/c1_LIRGenerator.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,8 @@ void LIRGenerator::do_Reference_get(Intrinsic* x) {
12071207

12081208
LIR_Opr result = rlock_result(x, T_OBJECT);
12091209
access_load_at(IN_HEAP | ON_WEAK_OOP_REF, T_OBJECT,
1210-
reference, LIR_OprFact::intConst(referent_offset), result);
1210+
reference, LIR_OprFact::intConst(referent_offset), result,
1211+
nullptr, info);
12111212
}
12121213

12131214
// Example: clazz.isInstance(object)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2023, 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 8310126
27+
* @summary Test that the Reference::get intrinsic works with a null argument.
28+
* @run main/othervm -XX:TieredStopAtLevel=1 -XX:CompileCommand=compileonly,*TestReferenceGetWithNull::test -Xbatch
29+
* compiler.intrinsics.TestReferenceGetWithNull
30+
*/
31+
32+
package compiler.intrinsics;
33+
34+
import java.lang.ref.WeakReference;
35+
36+
public class TestReferenceGetWithNull {
37+
38+
// Declare final such that static binding at the call site is possible
39+
static final class MyReference<T> extends WeakReference<T> {
40+
public MyReference(T referent) {
41+
super(referent);
42+
}
43+
}
44+
45+
static void test(MyReference r) {
46+
try {
47+
r.get();
48+
} catch (Exception e) {
49+
// Ignore
50+
}
51+
}
52+
53+
public static void main(String[] args) {
54+
// Make sure MyReference is loaded
55+
MyReference<String[]> obj = new MyReference<>(args);
56+
// Trigger compilation
57+
for (int i = 0; i < 50_000; ++i) {
58+
test(null);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)
Please sign in to comment.