< prev index next >

src/hotspot/share/interpreter/bytecodeUtils.cpp

Print this page

 963     case Bytecodes::_athrow:
 964       stack->pop(-Bytecodes::depth(code));
 965       flow_ended = true;
 966       break;
 967 
 968     case Bytecodes::_getstatic:
 969     case Bytecodes::_getfield: {
 970       // Find out the type of the field accessed.
 971       int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
 972       ConstantPool* cp = _method->constants();
 973       int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
 974       int type_index = cp->signature_ref_index_at(name_and_type_index);
 975       Symbol* signature = cp->symbol_at(type_index);
 976       // Simulate the bytecode: pop the address, push the 'value' loaded
 977       // from the field.
 978       stack->pop(1 - Bytecodes::depth(code));
 979       stack->push(bci, Signature::basic_type(signature));
 980       break;
 981     }
 982 

 983     case Bytecodes::_putstatic:
 984     case Bytecodes::_putfield: {
 985       int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
 986       ConstantPool* cp = _method->constants();
 987       int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
 988       int type_index = cp->signature_ref_index_at(name_and_type_index);
 989       Symbol* signature = cp->symbol_at(type_index);
 990       BasicType bt = Signature::basic_type(signature);
 991       stack->pop(type2size[bt] - Bytecodes::depth(code) - 1);
 992       break;
 993     }
 994 
 995     case Bytecodes::_invokevirtual:
 996     case Bytecodes::_invokespecial:
 997     case Bytecodes::_invokestatic:
 998     case Bytecodes::_invokeinterface:
 999     case Bytecodes::_invokedynamic: {
1000       ConstantPool* cp = _method->constants();
1001       int cp_index;
1002 

1095 }
1096 
1097 #define INVALID_BYTECODE_ENCOUNTERED -1
1098 #define NPE_EXPLICIT_CONSTRUCTED -2
1099 int ExceptionMessageBuilder::get_NPE_null_slot(int bci) {
1100   // Get the bytecode.
1101   address code_base = _method->constMethod()->code_base();
1102   Bytecodes::Code code = Bytecodes::java_code_at(_method, code_base + bci);
1103   int pos = bci + 1;  // Position of argument of the bytecode.
1104   if (code == Bytecodes::_wide) {
1105     code = Bytecodes::java_code_at(_method, code_base + bci + 1);
1106     pos += 1;
1107   }
1108 
1109   switch (code) {
1110     case Bytecodes::_getfield:
1111     case Bytecodes::_arraylength:
1112     case Bytecodes::_athrow:
1113     case Bytecodes::_monitorenter:
1114     case Bytecodes::_monitorexit:

1115       return 0;
1116     case Bytecodes::_iaload:
1117     case Bytecodes::_faload:
1118     case Bytecodes::_aaload:
1119     case Bytecodes::_baload:
1120     case Bytecodes::_caload:
1121     case Bytecodes::_saload:
1122     case Bytecodes::_laload:
1123     case Bytecodes::_daload:
1124       return 1;
1125     case Bytecodes::_iastore:
1126     case Bytecodes::_fastore:
1127     case Bytecodes::_aastore:
1128     case Bytecodes::_bastore:
1129     case Bytecodes::_castore:
1130     case Bytecodes::_sastore:
1131       return 2;
1132     case Bytecodes::_lastore:
1133     case Bytecodes::_dastore:
1134       return 3;

1135     case Bytecodes::_putfield: {
1136         int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1137         ConstantPool* cp = _method->constants();
1138         int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
1139         int type_index = cp->signature_ref_index_at(name_and_type_index);
1140         Symbol* signature = cp->symbol_at(type_index);
1141         BasicType bt = Signature::basic_type(signature);
1142         return type2size[bt];
1143       }
1144     case Bytecodes::_invokevirtual:
1145     case Bytecodes::_invokespecial:
1146     case Bytecodes::_invokeinterface: {
1147         int cp_index = Bytes::get_native_u2(code_base+ pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1148         ConstantPool* cp = _method->constants();
1149         int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
1150         int name_index = cp->name_ref_index_at(name_and_type_index);
1151         Symbol* name = cp->symbol_at(name_index);
1152 
1153         // Assume the the call of a constructor can never cause a NullPointerException
1154         // (which is true in Java). This is mainly used to avoid generating wrong
1155         // messages for NullPointerExceptions created explicitly by new in Java code.
1156         if (name != vmSymbols::object_initializer_name()) {
1157           int     type_index = cp->signature_ref_index_at(name_and_type_index);
1158           Symbol* signature  = cp->symbol_at(type_index);
1159           // The 'this' parameter was null. Return the slot of it.
1160           return ArgumentSizeComputer(signature).size();
1161         } else {
1162           return NPE_EXPLICIT_CONSTRUCTED;
1163         }
1164       }
1165 
1166     default:
1167       break;
1168   }
1169 
1170   return INVALID_BYTECODE_ENCOUNTERED;
1171 }
1172 
1173 bool ExceptionMessageBuilder::print_NPE_cause(outputStream* os, int bci, int slot) {
1174   if (print_NPE_cause0(os, bci, slot, _max_cause_detail, false, " because \"")) {
1175     os->print("\" is null");






1176     return true;
1177   }
1178   return false;
1179 }
1180 
1181 // Recursively print what was null.
1182 //
1183 // Go to the bytecode that pushed slot 'slot' on the operand stack
1184 // at bytecode 'bci'. Compute a message for that bytecode. If
1185 // necessary (array, field), recur further.
1186 // At most do max_detail recursions.
1187 // Prefix is used to print a proper beginning of the whole
1188 // sentence.
1189 // inner_expr is used to omit some text, like 'static' in
1190 // inner expressions like array subscripts.
1191 //
1192 // Returns true if something was printed.
1193 //
1194 bool ExceptionMessageBuilder::print_NPE_cause0(outputStream* os, int bci, int slot,
1195                                                int max_detail,

1405       os->print("Cannot store to long array"); break;
1406     case Bytecodes::_dastore:
1407       os->print("Cannot store to double array"); break;
1408 
1409     case Bytecodes::_arraylength:
1410       os->print("Cannot read the array length"); break;
1411     case Bytecodes::_athrow:
1412       os->print("Cannot throw exception"); break;
1413     case Bytecodes::_monitorenter:
1414       os->print("Cannot enter synchronized block"); break;
1415     case Bytecodes::_monitorexit:
1416       os->print("Cannot exit synchronized block"); break;
1417     case Bytecodes::_getfield: {
1418         int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1419         ConstantPool* cp = _method->constants();
1420         int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
1421         int name_index = cp->name_ref_index_at(name_and_type_index);
1422         Symbol* name = cp->symbol_at(name_index);
1423         os->print("Cannot read field \"%s\"", name->as_C_string());
1424       } break;

1425     case Bytecodes::_putfield: {
1426         int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1427         os->print("Cannot assign field \"%s\"", get_field_name(_method, cp_index));
1428       } break;
1429     case Bytecodes::_invokevirtual:
1430     case Bytecodes::_invokespecial:
1431     case Bytecodes::_invokeinterface: {
1432         int cp_index = Bytes::get_native_u2(code_base+ pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1433         os->print("Cannot invoke \"");
1434         print_method_name(os, _method, cp_index);
1435         os->print("\"");
1436       } break;





1437 
1438     default:
1439       assert(0, "We should have checked this bytecode in get_NPE_null_slot().");
1440       break;
1441   }
1442 }
1443 
1444 // Main API
1445 bool BytecodeUtils::get_NPE_message_at(outputStream* ss, Method* method, int bci) {
1446 
1447   NoSafepointVerifier _nsv;   // Cannot use this object over a safepoint.
1448 
1449   // If this NPE was created via reflection, we have no real NPE.
1450   if (method->method_holder() ==
1451       vmClasses::reflect_NativeConstructorAccessorImpl_klass()) {
1452     return false;
1453   }
1454 
1455   // Analyse the bytecodes.
1456   ResourceMark rm;

 963     case Bytecodes::_athrow:
 964       stack->pop(-Bytecodes::depth(code));
 965       flow_ended = true;
 966       break;
 967 
 968     case Bytecodes::_getstatic:
 969     case Bytecodes::_getfield: {
 970       // Find out the type of the field accessed.
 971       int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
 972       ConstantPool* cp = _method->constants();
 973       int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
 974       int type_index = cp->signature_ref_index_at(name_and_type_index);
 975       Symbol* signature = cp->symbol_at(type_index);
 976       // Simulate the bytecode: pop the address, push the 'value' loaded
 977       // from the field.
 978       stack->pop(1 - Bytecodes::depth(code));
 979       stack->push(bci, Signature::basic_type(signature));
 980       break;
 981     }
 982 
 983     case Bytecodes::_withfield:
 984     case Bytecodes::_putstatic:
 985     case Bytecodes::_putfield: {
 986       int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
 987       ConstantPool* cp = _method->constants();
 988       int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
 989       int type_index = cp->signature_ref_index_at(name_and_type_index);
 990       Symbol* signature = cp->symbol_at(type_index);
 991       BasicType bt = Signature::basic_type(signature);
 992       stack->pop(type2size[bt] - Bytecodes::depth(code) - 1);
 993       break;
 994     }
 995 
 996     case Bytecodes::_invokevirtual:
 997     case Bytecodes::_invokespecial:
 998     case Bytecodes::_invokestatic:
 999     case Bytecodes::_invokeinterface:
1000     case Bytecodes::_invokedynamic: {
1001       ConstantPool* cp = _method->constants();
1002       int cp_index;
1003 

1096 }
1097 
1098 #define INVALID_BYTECODE_ENCOUNTERED -1
1099 #define NPE_EXPLICIT_CONSTRUCTED -2
1100 int ExceptionMessageBuilder::get_NPE_null_slot(int bci) {
1101   // Get the bytecode.
1102   address code_base = _method->constMethod()->code_base();
1103   Bytecodes::Code code = Bytecodes::java_code_at(_method, code_base + bci);
1104   int pos = bci + 1;  // Position of argument of the bytecode.
1105   if (code == Bytecodes::_wide) {
1106     code = Bytecodes::java_code_at(_method, code_base + bci + 1);
1107     pos += 1;
1108   }
1109 
1110   switch (code) {
1111     case Bytecodes::_getfield:
1112     case Bytecodes::_arraylength:
1113     case Bytecodes::_athrow:
1114     case Bytecodes::_monitorenter:
1115     case Bytecodes::_monitorexit:
1116     case Bytecodes::_checkcast:
1117       return 0;
1118     case Bytecodes::_iaload:
1119     case Bytecodes::_faload:
1120     case Bytecodes::_aaload:
1121     case Bytecodes::_baload:
1122     case Bytecodes::_caload:
1123     case Bytecodes::_saload:
1124     case Bytecodes::_laload:
1125     case Bytecodes::_daload:
1126       return 1;
1127     case Bytecodes::_iastore:
1128     case Bytecodes::_fastore:
1129     case Bytecodes::_aastore:
1130     case Bytecodes::_bastore:
1131     case Bytecodes::_castore:
1132     case Bytecodes::_sastore:
1133       return 2;
1134     case Bytecodes::_lastore:
1135     case Bytecodes::_dastore:
1136       return 3;
1137     case Bytecodes::_withfield:
1138     case Bytecodes::_putfield: {
1139         int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1140         ConstantPool* cp = _method->constants();
1141         int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
1142         int type_index = cp->signature_ref_index_at(name_and_type_index);
1143         Symbol* signature = cp->symbol_at(type_index);
1144         BasicType bt = Signature::basic_type(signature);
1145         return type2size[bt];
1146       }
1147     case Bytecodes::_invokevirtual:
1148     case Bytecodes::_invokespecial:
1149     case Bytecodes::_invokeinterface: {
1150         int cp_index = Bytes::get_native_u2(code_base+ pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1151         ConstantPool* cp = _method->constants();
1152         int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
1153         int name_index = cp->name_ref_index_at(name_and_type_index);
1154         Symbol* name = cp->symbol_at(name_index);
1155 
1156         // Assume the the call of a constructor can never cause a NullPointerException
1157         // (which is true in Java). This is mainly used to avoid generating wrong
1158         // messages for NullPointerExceptions created explicitly by new in Java code.
1159         if (name != vmSymbols::object_initializer_name()) {
1160           int     type_index = cp->signature_ref_index_at(name_and_type_index);
1161           Symbol* signature  = cp->symbol_at(type_index);
1162           // The 'this' parameter was null. Return the slot of it.
1163           return ArgumentSizeComputer(signature).size();
1164         } else {
1165           return NPE_EXPLICIT_CONSTRUCTED;
1166         }
1167       }
1168 
1169     default:
1170       break;
1171   }
1172 
1173   return INVALID_BYTECODE_ENCOUNTERED;
1174 }
1175 
1176 bool ExceptionMessageBuilder::print_NPE_cause(outputStream* os, int bci, int slot) {
1177   if (print_NPE_cause0(os, bci, slot, _max_cause_detail, false, " because \"")) {
1178     address code_base = _method->constMethod()->code_base();
1179     Bytecodes::Code code = Bytecodes::java_code_at(_method, code_base + bci);
1180     if (code == Bytecodes::_aastore) {
1181       os->print("\" is null or is a null-free array and there's an attempt to store null in it");
1182     } else {
1183       os->print("\" is null");
1184     }
1185     return true;
1186   }
1187   return false;
1188 }
1189 
1190 // Recursively print what was null.
1191 //
1192 // Go to the bytecode that pushed slot 'slot' on the operand stack
1193 // at bytecode 'bci'. Compute a message for that bytecode. If
1194 // necessary (array, field), recur further.
1195 // At most do max_detail recursions.
1196 // Prefix is used to print a proper beginning of the whole
1197 // sentence.
1198 // inner_expr is used to omit some text, like 'static' in
1199 // inner expressions like array subscripts.
1200 //
1201 // Returns true if something was printed.
1202 //
1203 bool ExceptionMessageBuilder::print_NPE_cause0(outputStream* os, int bci, int slot,
1204                                                int max_detail,

1414       os->print("Cannot store to long array"); break;
1415     case Bytecodes::_dastore:
1416       os->print("Cannot store to double array"); break;
1417 
1418     case Bytecodes::_arraylength:
1419       os->print("Cannot read the array length"); break;
1420     case Bytecodes::_athrow:
1421       os->print("Cannot throw exception"); break;
1422     case Bytecodes::_monitorenter:
1423       os->print("Cannot enter synchronized block"); break;
1424     case Bytecodes::_monitorexit:
1425       os->print("Cannot exit synchronized block"); break;
1426     case Bytecodes::_getfield: {
1427         int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1428         ConstantPool* cp = _method->constants();
1429         int name_and_type_index = cp->name_and_type_ref_index_at(cp_index);
1430         int name_index = cp->name_ref_index_at(name_and_type_index);
1431         Symbol* name = cp->symbol_at(name_index);
1432         os->print("Cannot read field \"%s\"", name->as_C_string());
1433       } break;
1434     case Bytecodes::_withfield:
1435     case Bytecodes::_putfield: {
1436         int cp_index = Bytes::get_native_u2(code_base + pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1437         os->print("Cannot assign field \"%s\"", get_field_name(_method, cp_index));
1438       } break;
1439     case Bytecodes::_invokevirtual:
1440     case Bytecodes::_invokespecial:
1441     case Bytecodes::_invokeinterface: {
1442         int cp_index = Bytes::get_native_u2(code_base+ pos) DEBUG_ONLY(+ ConstantPool::CPCACHE_INDEX_TAG);
1443         os->print("Cannot invoke \"");
1444         print_method_name(os, _method, cp_index);
1445         os->print("\"");
1446       } break;
1447     case Bytecodes::_checkcast: {
1448         int cp_index = Bytes::get_Java_u2(code_base + pos);
1449         ConstantPool* cp = _method->constants();
1450         os->print("Cannot cast to null-free type \"%s\"", cp->klass_at_noresolve(cp_index)->as_C_string());
1451       } break;
1452 
1453     default:
1454       assert(0, "We should have checked this bytecode in get_NPE_null_slot().");
1455       break;
1456   }
1457 }
1458 
1459 // Main API
1460 bool BytecodeUtils::get_NPE_message_at(outputStream* ss, Method* method, int bci) {
1461 
1462   NoSafepointVerifier _nsv;   // Cannot use this object over a safepoint.
1463 
1464   // If this NPE was created via reflection, we have no real NPE.
1465   if (method->method_holder() ==
1466       vmClasses::reflect_NativeConstructorAccessorImpl_klass()) {
1467     return false;
1468   }
1469 
1470   // Analyse the bytecodes.
1471   ResourceMark rm;
< prev index next >