< prev index next >
src/share/vm/c1/c1_LIRGenerator.cpp
Print this page
@@ -1751,11 +1751,21 @@
if (x->needs_null_check() &&
(needs_patching ||
MacroAssembler::needs_explicit_null_check(x->offset()))) {
// emit an explicit null check because the offset is too large
- __ null_check(object.result(), new CodeEmitInfo(info));
+ LIR_Opr obj = object.result();
+ if (needs_patching) {
+ // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
+ // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
+ CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check,
+ Deoptimization::Action_none);
+ __ cmp(lir_cond_equal, obj, LIR_OprFact::oopConst(NULL));
+ __ branch(lir_cond_equal, T_OBJECT, deopt);
+ } else {
+ __ null_check(obj, new CodeEmitInfo(info));
+ }
}
LIR_Address* address;
if (needs_patching) {
// we need to patch the offset in the instruction so don't allow
@@ -1837,12 +1847,21 @@
if (stress_deopt) {
obj = new_register(T_OBJECT);
__ move(LIR_OprFact::oopConst(NULL), obj);
}
// emit an explicit null check because the offset is too large
+ if (needs_patching) {
+ // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
+ // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
+ CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check,
+ Deoptimization::Action_none);
+ __ cmp(lir_cond_equal, obj, LIR_OprFact::oopConst(NULL));
+ __ branch(lir_cond_equal, T_OBJECT, deopt);
+ } else {
__ null_check(obj, new CodeEmitInfo(info));
}
+ }
LIR_Opr reg = rlock_result(x, field_type);
LIR_Address* address;
if (needs_patching) {
// we need to patch the offset in the instruction so don't allow
< prev index next >