--- 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) { --- old/src/share/vm/c1/c1_LIRGenerator.hpp 2017-01-27 16:22:02.621664149 +0100 +++ new/src/share/vm/c1/c1_LIRGenerator.hpp 2017-01-27 16:22:02.533664146 +0100 @@ -383,7 +383,7 @@ } } void decrement_age(CodeEmitInfo* info); - CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false); + CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false, bool deoptimize_on_exception = false); CodeEmitInfo* state_for(Instruction* x); // allocates a virtual register for this instruction if --- old/src/share/vm/c1/c1_Runtime1.cpp 2017-01-27 16:22:02.925664158 +0100 +++ new/src/share/vm/c1/c1_Runtime1.cpp 2017-01-27 16:22:02.845664156 +0100 @@ -1489,8 +1489,6 @@ JRT_ENTRY(void, Runtime1::predicate_failed_trap(JavaThread* thread)) ResourceMark rm; - assert(!TieredCompilation, "incompatible with tiered compilation"); - RegisterMap reg_map(thread, false); frame runtime_frame = thread->last_frame(); frame caller_frame = runtime_frame.sender(®_map); --- /dev/null 2017-01-27 09:01:48.822771025 +0100 +++ new/test/compiler/c1/TestUnresolvedField.jasm 2017-01-27 16:22:03.161664165 +0100 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +public class compiler/c1/TestUnresolvedField version 52:0 { + public static Method test:"()V" stack 1 locals 1 { + aconst_null; + getfield Field T.f:I; // T does not exist + return; + } +} --- /dev/null 2017-01-27 09:01:48.822771025 +0100 +++ new/test/compiler/c1/TestUnresolvedFieldMain.java 2017-01-27 16:22:03.397664172 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8173373 + * @compile TestUnresolvedField.jasm + * @run main/othervm -XX:TieredStopAtLevel=1 -Xcomp + * -XX:CompileCommand=compileonly,compiler.c1.TestUnresolvedField::test + * compiler.c1.TestUnresolvedFieldMain + */ + +package compiler.c1; + +public class TestUnresolvedFieldMain { + public static void main(String[] args) { + try { + TestUnresolvedField.test(); + } catch (java.lang.NoClassDefFoundError error) { + // Expected + } + } +}