Skip to content

Commit 56eb5f5

Browse files
author
Vladimir Kozlov
committed
8255466: C2 crashes at ciObject::get_oop() const+0x0
Reviewed-by: vlivanov
1 parent 5782a2a commit 56eb5f5

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

src/hotspot/share/opto/type.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,9 +3046,11 @@ TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int o
30463046
} else if (klass() == ciEnv::current()->Class_klass() &&
30473047
_offset >= InstanceMirrorKlass::offset_of_static_fields()) {
30483048
// Static fields
3049-
assert(o != NULL, "must be constant");
3050-
ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3051-
ciField* field = k->get_field_by_offset(_offset, true);
3049+
ciField* field = NULL;
3050+
if (const_oop() != NULL) {
3051+
ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3052+
field = k->get_field_by_offset(_offset, true);
3053+
}
30523054
if (field != NULL) {
30533055
BasicType basic_elem_type = field->layout_type();
30543056
_is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);

src/hotspot/share/opto/vectorIntrinsics.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ static bool is_vector_shuffle(ciKlass* klass) {
100100
}
101101

102102
static bool is_klass_initialized(const TypeInstPtr* vec_klass) {
103-
assert(vec_klass->const_oop()->as_instance()->java_lang_Class_klass(), "klass instance expected");
103+
if (vec_klass->const_oop() == NULL) {
104+
return false; // uninitialized or some kind of unsafe access
105+
}
106+
assert(vec_klass->const_oop()->as_instance()->java_lang_Class_klass() != NULL, "klass instance expected");
104107
ciInstanceKlass* klass = vec_klass->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
105108
return klass->is_initialized();
106109
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
* @modules java.base/jdk.internal.misc
29+
*
30+
* @run main/othervm -Xcomp -XX:CompileCommand=compileonly,TestUnsafeStaticFieldAccess::* TestUnsafeStaticFieldAccess
31+
*
32+
*/
33+
34+
import jdk.internal.misc.Unsafe;
35+
import java.lang.reflect.Field;
36+
37+
public class TestUnsafeStaticFieldAccess {
38+
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
39+
private static final long offset;
40+
private static volatile Class<?> clazz;
41+
42+
private static int field;
43+
44+
static {
45+
long o = 0;
46+
for (Field f : TestUnsafeStaticFieldAccess.class.getDeclaredFields()) {
47+
if (f.getName().equals("field")) {
48+
o = UNSAFE.staticFieldOffset(f);
49+
break;
50+
}
51+
}
52+
offset = o;
53+
clazz = TestUnsafeStaticFieldAccess.class;
54+
}
55+
56+
57+
public static void main(String[] args) {
58+
for (int i = 0; i < 12000; i++) {
59+
UNSAFE.getInt(clazz, offset);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)