Skip to content

Instantly share code, notes, and snippets.

@Fuud
Created May 7, 2014 17:34
Show Gist options
  • Save Fuud/7b401c0a408c82f09c45 to your computer and use it in GitHub Desktop.
Save Fuud/7b401c0a408c82f09c45 to your computer and use it in GitHub Desktop.
Obtain method name and signature for NPE in compiled methods.
diff -r 8748849ebea5 src/share/vm/interpreter/bytecode.hpp
--- a/src/share/vm/interpreter/bytecode.hpp Tue Apr 15 15:37:36 2014 -0700
+++ b/src/share/vm/interpreter/bytecode.hpp Wed May 07 21:31:18 2014 +0400
@@ -213,6 +213,23 @@
// Abstraction for invoke_{virtual, static, interface, special}
class Bytecode_invoke: public Bytecode_member_ref {
+ public:
+ const char* name_and_sig_as_C_string() {
+ if (klass() == NULL || name() == NULL || signature() == NULL) {
+ return "UNKNOWN";
+ }
+ const char* klass_name = klass()->as_C_string();
+ int klass_name_len = (int) strlen(klass_name);
+ int method_name_len = name()->utf8_length();
+ int len = klass_name_len + 1 + method_name_len + signature()->utf8_length();
+ char* dest = NEW_RESOURCE_ARRAY(char, len + 1);
+ strcpy(dest, klass_name);
+ dest[klass_name_len] = '.';
+ strcpy(&dest[klass_name_len + 1], name()->as_C_string());
+ strcpy(&dest[klass_name_len + 1 + method_name_len], signature()->as_C_string());
+ dest[len] = 0;
+ return dest;
+ }
protected:
// Constructor that skips verification
Bytecode_invoke(methodHandle method, int bci, bool unused) : Bytecode_member_ref(method, bci) {}
diff -r 8748849ebea5 src/share/vm/runtime/sharedRuntime.cpp
--- a/src/share/vm/runtime/sharedRuntime.cpp Tue Apr 15 15:37:36 2014 -0700
+++ b/src/share/vm/runtime/sharedRuntime.cpp Wed May 07 21:31:18 2014 +0400
@@ -769,6 +769,8 @@
}
#endif // !CC_INTERP
} else {
+ fprintf(stdout, "continuation_for_implicit_exception pc=%p\n", pc);
+ fflush(stdout);
switch (exception_kind) {
case STACK_OVERFLOW: {
// Stack overflow only occurs upon frame setup; the callee is
@@ -826,6 +828,34 @@
// Otherwise, it's an nmethod. Consult its exception handlers.
nmethod* nm = (nmethod*)cb;
+
+ stringStream comment;
+ nm->print_code_comment_on(&comment, 0, pc, pc + 5);
+ ScopeDesc* sd = nm->scope_desc_in(pc, pc + 5);
+ fprintf(stdout, "\nscopeDesc = %p\n\n", sd);
+ if (sd != NULL) {
+ fprintf(stdout, "\nmethod = %p\n\n", sd->method());
+ if (sd->method() != NULL) {
+ fprintf(stdout, "\nnative = %d\n\n", sd->method()->is_native());
+ if (!sd->method()->is_native()) {
+ Bytecodes::Code bc = sd->method()->java_code_at(sd->bci());
+ switch (bc) {
+ case Bytecodes::_invokevirtual:
+ case Bytecodes::_invokespecial:
+ case Bytecodes::_invokestatic:
+ case Bytecodes::_invokeinterface:
+ {
+ Bytecode_invoke invoke(sd->method(), sd->bci());
+ fprintf(stdout, "\nsig = %s\n\n", invoke.name_and_sig_as_C_string());
+ break;
+ }
+ }
+ }
+ }
+ }
+ fprintf(stdout, "\nstr= %s\n\n", comment.as_string());
+ fflush(stdout);
+
if (nm->inlinecache_check_contains(pc)) {
// exception happened inside inline-cache check code
// => the nmethod is not yet active (i.e., the frame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment