--- a/src/hotspot/share/prims/jvm.cpp Tue Oct 22 08:50:27 2019 +0200
+++ b/src/hotspot/share/prims/jvm.cpp Tue Oct 22 08:51:18 2019 +0200
@@ -38,6 +38,7 @@
#include "classfile/vmSymbols.hpp"
#include "gc/shared/collectedHeap.inline.hpp"
#include "interpreter/bytecode.hpp"
+#include "interpreter/bytecodeUtils.hpp"
#include "jfr/jfrEvents.hpp"
#include "logging/log.hpp"
#include "memory/heapShared.hpp"
@@ -531,13 +532,37 @@
// java.lang.Throwable //////////////////////////////////////////////////////
-
JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
JVMWrapper("JVM_FillInStackTrace");
Handle exception(thread, JNIHandles::resolve_non_null(receiver));
java_lang_Throwable::fill_in_stack_trace(exception);
JVM_END
+// java.lang.NullPointerException ///////////////////////////////////////////
+
+JVM_ENTRY(jstring, JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwable))
+ if (!ShowCodeDetailsInExceptionMessages) return NULL;
+
+ oop exc = JNIHandles::resolve_non_null(throwable);
+
+ Method* method;
+ int bci;
+ if (!java_lang_Throwable::get_top_method_and_bci(exc, &method, &bci)) {
+ return NULL;
+ }
+ if (method->is_native()) {
+ return NULL;
+ }
+
+ stringStream ss;
+ bool ok = BytecodeUtils::get_NPE_message_at(&ss, method, bci);
+ if (ok) {
+ oop result = java_lang_String::create_oop_from_str(ss.base(), CHECK_0);
+ return (jstring) JNIHandles::make_local(env, result);
+ } else {
+ return NULL;
+ }
+JVM_END
// java.lang.StackTraceElement //////////////////////////////////////////////