voidExceptionMessageBuilder::print_NPE_failed_action(outputStream *os, int bci){
// Get the bytecode. address code_base = _method->constMethod()->code_base(); Bytecodes::Code code = Bytecodes::java_code_at(_method, code_base + bci); int pos = bci + 1; if (code == Bytecodes::_wide) { code = Bytecodes::java_code_at(_method, code_base + bci + 1); pos += 1; }
switch (code) { case Bytecodes::_iaload: os->print("Cannot load from int array"); break; case Bytecodes::_faload: os->print("Cannot load from float array"); break; case Bytecodes::_aaload: os->print("Cannot load from object array"); break; case Bytecodes::_baload: os->print("Cannot load from byte/boolean array"); break; case Bytecodes::_caload: os->print("Cannot load from char array"); break; case Bytecodes::_saload: os->print("Cannot load from short array"); break; case Bytecodes::_laload: os->print("Cannot load from long array"); break; case Bytecodes::_daload: os->print("Cannot load from double array"); break;
case Bytecodes::_iastore: os->print("Cannot store to int array"); break; case Bytecodes::_fastore: os->print("Cannot store to float array"); break; case Bytecodes::_aastore: os->print("Cannot store to object array"); break; case Bytecodes::_bastore: os->print("Cannot store to byte/boolean array"); break; case Bytecodes::_castore: os->print("Cannot store to char array"); break; case Bytecodes::_sastore: os->print("Cannot store to short array"); break; case Bytecodes::_lastore: os->print("Cannot store to long array"); break; case Bytecodes::_dastore: os->print("Cannot store to double array"); break;
case Bytecodes::_arraylength: os->print("Cannot read the array length"); break; case Bytecodes::_athrow: os->print("Cannot throw exception"); break; case Bytecodes::_monitorenter: os->print("Cannot enter synchronized block"); break; case Bytecodes::_monitorexit: os->print("Cannot exit synchronized block"); break; case Bytecodes::_getfield: { int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG); ConstantPool* cp = _method->constants(); int name_and_type_index = cp->name_and_type_ref_index_at(cp_index); int name_index = cp->name_ref_index_at(name_and_type_index); Symbol* name = cp->symbol_at(name_index); os->print("Cannot read field "%s"", name->as_C_string()); } break; case Bytecodes::_putfield: { int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG); os->print("Cannot assign field "%s"", get_field_name(_method, cp_index)); } break; case Bytecodes::_invokevirtual: case Bytecodes::_invokespecial: case Bytecodes::_invokeinterface: { int cp_index = Bytes::get_native_u2(code_base+ pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG); os->print("Cannot invoke ""); print_method_name(os, _method, cp_index); os->print("""); } break;
default: assert(0, "We should have checked this bytecode in get_NPE_null_slot()."); break; } }
boolExceptionMessageBuilder::print_NPE_cause(outputStream* os, int bci, int slot){ if (print_NPE_cause0(os, bci, slot, _max_cause_detail, false, " because "")) { os->print("" is null"); returntrue; } returnfalse; }
print_NPE_cause调用print_NPE_cause0输出原因,并在前面添加because ",在其后添加" is null。