Skip to content

Commit fc88d51

Browse files
SendaoYangnu-andrew
authored andcommitted
8255466: C2 crashes at ciObject::get_oop() const+0x0
Reviewed-by: phh, andrew Backport-of: bb3f1238cb12c45ed85936d3b06eced0730d588f
1 parent 88a7829 commit fc88d51

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

hotspot/src/share/vm/opto/type.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,9 +2552,11 @@ TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int o
25522552
} else if (klass() == ciEnv::current()->Class_klass() &&
25532553
_offset >= InstanceMirrorKlass::offset_of_static_fields()) {
25542554
// Static fields
2555-
assert(o != NULL, "must be constant");
2556-
ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
2557-
ciField* field = k->get_field_by_offset(_offset, true);
2555+
ciField* field = NULL;
2556+
if (const_oop() != NULL) {
2557+
ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
2558+
field = k->get_field_by_offset(_offset, true);
2559+
}
25582560
if (field != NULL) {
25592561
BasicType basic_elem_type = field->layout_type();
25602562
_is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2020, 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 8255466
27+
* @summary unsafe access to static field causes crash
28+
*
29+
* @run main/bootclasspath/othervm -Xcomp -XX:CompileCommand=compileonly,TestUnsafeStaticFieldAccess::* TestUnsafeStaticFieldAccess
30+
*
31+
*/
32+
33+
import sun.misc.Unsafe;
34+
import java.lang.reflect.Field;
35+
36+
public class TestUnsafeStaticFieldAccess {
37+
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
38+
private static final long offset;
39+
private static volatile Class<?> clazz;
40+
41+
private static int field;
42+
43+
static {
44+
long o = 0;
45+
for (Field f : TestUnsafeStaticFieldAccess.class.getDeclaredFields()) {
46+
if (f.getName().equals("field")) {
47+
o = UNSAFE.staticFieldOffset(f);
48+
break;
49+
}
50+
}
51+
offset = o;
52+
clazz = TestUnsafeStaticFieldAccess.class;
53+
}
54+
55+
56+
public static void main(String[] args) {
57+
for (int i = 0; i < 12000; i++) {
58+
UNSAFE.getInt(clazz, offset);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)