< prev index next >
src/hotspot/share/interpreter/bytecodeUtils.cpp
Print this page
rev 56281 : 8218628: Add detailed message to NullPointerException describing what is null.
Summary: This is the implementation of JEP 358: Helpful NullPointerExceptions.
Reviewed-by: coleenp
rev 56283 : [mq]: fixes_review_of_16.patch
@@ -29,10 +29,11 @@
#include "interpreter/bytecodeUtils.hpp"
#include "memory/resourceArea.hpp"
#include "runtime/signature.hpp"
#include "runtime/safepointVerifiers.hpp"
#include "utilities/events.hpp"
+#include "utilities/ostream.hpp"
class SimulatedOperandStack;
class ExceptionMessageBuilder;
// The entries of a SimulatedOperandStack. They carry the analysis
@@ -209,15 +210,12 @@
// Prints a string describing the failed action.
void print_NPE_failed_action(outputStream *os, int bci);
};
-
-/*
- * Prints the name of the method that is described at constant pool
- * index cp_index in the constant pool of method 'method'.
- */
+// Prints the name of the method that is described at constant pool
+// index cp_index in the constant pool of method 'method'.
static void print_method_name(outputStream *os, Method* method, int cp_index) {
ConstantPool* cp = method->constants();
Symbol* klass = cp->klass_ref_at_noresolve(cp_index);
Symbol* name = cp->name_ref_at(cp_index);
Symbol* signature = cp->signature_ref_at(cp_index);
@@ -225,25 +223,21 @@
os->print("%s.%s(", klass->as_klass_external_name(), name->as_C_string());
signature->print_as_signature_external_parameters(os);
os->print(")");
}
-/*
- * Prints the name of the field that is described at constant pool
- * index cp_index in the constant pool of method 'method'.
- */
+// Prints the name of the field that is described at constant pool
+// index cp_index in the constant pool of method 'method'.
static void print_field_and_class(outputStream *os, Method* method, int cp_index) {
ConstantPool* cp = method->constants();
Symbol* klass = cp->klass_ref_at_noresolve(cp_index);
Symbol *name = cp->name_ref_at(cp_index);
os->print("%s.%s", klass->as_klass_external_name(), name->as_C_string());
}
-/*
- * Returns the name of the field that is described at constant pool
- * index cp_index in the constant pool of method 'method'.
- */
+// Returns the name of the field that is described at constant pool
+// index cp_index in the constant pool of method 'method'.
static char const* get_field_name(Method* method, int cp_index) {
Symbol* name = method->constants()->name_ref_at(cp_index);
return name->as_C_string();
}
@@ -386,12 +380,14 @@
}
ExceptionMessageBuilder::ExceptionMessageBuilder(Method* method, int bci) :
_method(method), _nr_of_entries(0),
_added_one(true), _all_processed(false) {
- ConstMethod* const_method = method->constMethod();
+ assert(bci >= 0, "BCI too low");
+ assert(bci < get_size(), "BCI too large");
+ ConstMethod* const_method = method->constMethod();
const int len = const_method->code_size();
_stacks = new GrowableArray<SimulatedOperandStack*> (len+1);
for (int i = 0; i <= len; ++i) {
@@ -1356,10 +1352,11 @@
SystemDictionary::reflect_NativeConstructorAccessorImpl_klass()) {
return false;
}
// Analyse the bytecodes.
+ ResourceMark rm;
ExceptionMessageBuilder emb(method, bci);
// The slot of the operand stack that contains the null reference.
// Also checks for NPE explicitly constructed and returns -2.
int slot = emb.get_NPE_null_slot(bci);
< prev index next >