--- old/src/share/vm/c1/c1_LIRGenerator.cpp 2017-01-27 16:22:02.301664140 +0100 +++ new/src/share/vm/c1/c1_LIRGenerator.cpp 2017-01-27 16:22:02.213664137 +0100 @@ -404,7 +404,7 @@ } -CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) { +CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler, bool deoptimize_on_exception) { assert(state != NULL, "state must be defined"); #ifndef PRODUCT @@ -461,7 +461,7 @@ } } - return new CodeEmitInfo(state, ignore_xhandler ? NULL : x->exception_handlers(), x->check_flag(Instruction::DeoptimizeOnException)); + return new CodeEmitInfo(state, ignore_xhandler ? NULL : x->exception_handlers(), deoptimize_on_exception || x->check_flag(Instruction::DeoptimizeOnException)); } @@ -1807,7 +1807,10 @@ CodeEmitInfo* info = NULL; if (needs_patching) { assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access"); - info = state_for(x, x->state_before()); + // 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. + bool deoptimize_on_exception = x->needs_null_check(); + info = state_for(x, x->state_before(), false, deoptimize_on_exception); } else if (x->needs_null_check()) { NullCheck* nc = x->explicit_null_check(); if (nc == NULL) {