Skip to content

Commit 972112e

Browse files
Dongbo HeRealFYang
authored andcommitted
8233019: java.lang.Class.isPrimitive() (C1) returns wrong result if Klass* is aligned to 32bit
Reviewed-by: phh Backport-of: b67ca938f37f952e53f73d2e0b8ebcaf96139fda
1 parent e005185 commit 972112e

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

hotspot/src/cpu/aarch64/vm/c1_LIRAssembler_aarch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,9 @@ void LIR_Assembler::comp_op(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2,
19801980
case T_ADDRESS:
19811981
imm = opr2->as_constant_ptr()->as_jint();
19821982
break;
1983+
case T_METADATA:
1984+
imm = (intptr_t)(opr2->as_constant_ptr()->as_metadata());
1985+
break;
19831986
case T_OBJECT:
19841987
case T_ARRAY:
19851988
imm = jlong(opr2->as_constant_ptr()->as_jobject());

hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,18 @@ void LIR_Assembler::comp_op(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2,
16811681
}
16821682
break;
16831683

1684+
case T_METADATA:
1685+
// We only need, for now, comparison with NULL for metadata.
1686+
{ assert(condition == lir_cond_equal || condition == lir_cond_notEqual, "oops");
1687+
Metadata* m = opr2->as_constant_ptr()->as_metadata();
1688+
if (m == NULL) {
1689+
__ cmp(opr1->as_register(), 0);
1690+
} else {
1691+
ShouldNotReachHere();
1692+
}
1693+
}
1694+
break;
1695+
16841696
default:
16851697
ShouldNotReachHere();
16861698
break;

hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,15 @@ void LIR_Assembler::comp_op(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2,
27182718
LIR_Const* c = opr2->as_constant_ptr();
27192719
if (c->type() == T_INT) {
27202720
__ cmpl(reg1, c->as_jint());
2721+
} else if (c->type() == T_METADATA) {
2722+
// All we need for now is a comparison with NULL for equality.
2723+
assert(condition == lir_cond_equal || condition == lir_cond_notEqual, "oops");
2724+
Metadata* m = c->as_metadata();
2725+
if (m == NULL) {
2726+
__ cmpptr(reg1, (int32_t)0);
2727+
} else {
2728+
ShouldNotReachHere();
2729+
}
27212730
} else if (c->type() == T_OBJECT || c->type() == T_ARRAY) {
27222731
// In 64bit oops are single register
27232732
jobject o = c->as_jobject();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ void LIRGenerator::do_isPrimitive(Intrinsic* x) {
13051305
}
13061306

13071307
__ move(new LIR_Address(rcvr.result(), java_lang_Class::klass_offset_in_bytes(), T_ADDRESS), temp, info);
1308-
__ cmp(lir_cond_notEqual, temp, LIR_OprFact::intConst(0));
1308+
__ cmp(lir_cond_notEqual, temp, LIR_OprFact::metadataConst(0));
13091309
__ cmove(lir_cond_notEqual, LIR_OprFact::intConst(0), LIR_OprFact::intConst(1), result, T_BOOLEAN);
13101310
}
13111311

hotspot/test/compiler/intrinsics/klass/TestIsPrimitive.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
/*
2525
* @test
2626
* @bug 8150669
27+
* @bug 8233019
2728
* @summary C1 intrinsic for Class.isPrimitive
2829
*
2930
* @run main/othervm -ea -Diters=200 -Xint TestIsPrimitive
30-
* @run main/othervm -ea -Diters=30000 -XX:TieredStopAtLevel=1 TestIsPrimitive
31+
* @run main/othervm -ea -Diters=30000 -XX:-UseSharedSpaces
32+
-XX:TieredStopAtLevel=1 TestIsPrimitive
3133
* @run main/othervm -ea -Diters=30000 -XX:TieredStopAtLevel=4 TestIsPrimitive
3234
*/
3335
import java.lang.reflect.Field;
@@ -48,6 +50,7 @@ public static void main(String... args) throws Exception {
4850
testOK(true, InlineConstants::testDouble);
4951
testOK(false, InlineConstants::testObject);
5052
testOK(false, InlineConstants::testArray);
53+
testOK(false, InlineConstants::testBooleanArray);
5154

5255
testOK(true, StaticConstants::testBoolean);
5356
testOK(true, StaticConstants::testByte);
@@ -59,6 +62,7 @@ public static void main(String... args) throws Exception {
5962
testOK(true, StaticConstants::testDouble);
6063
testOK(false, StaticConstants::testObject);
6164
testOK(false, StaticConstants::testArray);
65+
testOK(false, StaticConstants::testBooleanArray);
6266
testNPE( StaticConstants::testNull);
6367

6468
testOK(true, NoConstants::testBoolean);
@@ -71,6 +75,7 @@ public static void main(String... args) throws Exception {
7175
testOK(true, NoConstants::testDouble);
7276
testOK(false, NoConstants::testObject);
7377
testOK(false, NoConstants::testArray);
78+
testOK(false, NoConstants::testBooleanArray);
7479
testNPE( NoConstants::testNull);
7580
}
7681

@@ -107,6 +112,7 @@ public static void testNPE(Callable<Object> test) throws Exception {
107112
static volatile Class<?> classObject = Object.class;
108113
static volatile Class<?> classArray = Object[].class;
109114
static volatile Class<?> classNull = null;
115+
static volatile Class<?> classBooleanArray = boolean[].class;
110116

111117
static final Class<?> staticClassBoolean = boolean.class;
112118
static final Class<?> staticClassByte = byte.class;
@@ -119,6 +125,7 @@ public static void testNPE(Callable<Object> test) throws Exception {
119125
static final Class<?> staticClassObject = Object.class;
120126
static final Class<?> staticClassArray = Object[].class;
121127
static final Class<?> staticClassNull = null;
128+
static final Class<?> staticClassBooleanArray = boolean[].class;
122129

123130
static class InlineConstants {
124131
static boolean testBoolean() { return boolean.class.isPrimitive(); }
@@ -131,6 +138,7 @@ static class InlineConstants {
131138
static boolean testDouble() { return double.class.isPrimitive(); }
132139
static boolean testObject() { return Object.class.isPrimitive(); }
133140
static boolean testArray() { return Object[].class.isPrimitive(); }
141+
static boolean testBooleanArray() { return boolean[].class.isPrimitive(); }
134142
}
135143

136144
static class StaticConstants {
@@ -145,6 +153,7 @@ static class StaticConstants {
145153
static boolean testObject() { return staticClassObject.isPrimitive(); }
146154
static boolean testArray() { return staticClassArray.isPrimitive(); }
147155
static boolean testNull() { return staticClassNull.isPrimitive(); }
156+
static boolean testBooleanArray() { return staticClassBooleanArray.isPrimitive(); }
148157
}
149158

150159
static class NoConstants {
@@ -159,6 +168,7 @@ static class NoConstants {
159168
static boolean testObject() { return classObject.isPrimitive(); }
160169
static boolean testArray() { return classArray.isPrimitive(); }
161170
static boolean testNull() { return classNull.isPrimitive(); }
171+
static boolean testBooleanArray() { return classBooleanArray.isPrimitive(); }
162172
}
163173

164174
}

0 commit comments

Comments
 (0)