< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page
rev 54075 : 8218627: Add detailed message to NullPointerException describing what is null.


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"

  27 #include "classfile/classFileStream.hpp"
  28 #include "classfile/classLoader.hpp"
  29 #include "classfile/classLoaderData.inline.hpp"
  30 #include "classfile/javaAssertions.hpp"
  31 #include "classfile/javaClasses.inline.hpp"
  32 #include "classfile/moduleEntry.hpp"
  33 #include "classfile/modules.hpp"
  34 #include "classfile/packageEntry.hpp"
  35 #include "classfile/stringTable.hpp"
  36 #include "classfile/systemDictionary.hpp"
  37 #include "classfile/vmSymbols.hpp"
  38 #include "gc/shared/collectedHeap.inline.hpp"
  39 #include "interpreter/bytecode.hpp"
  40 #include "jfr/jfrEvents.hpp"
  41 #include "logging/log.hpp"
  42 #include "memory/heapShared.hpp"
  43 #include "memory/oopFactory.hpp"
  44 #include "memory/referenceType.hpp"
  45 #include "memory/resourceArea.hpp"
  46 #include "memory/universe.hpp"


 517   return convert_size_t_to_jlong(n);
 518 JVM_END
 519 
 520 
 521 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
 522   JVMWrapper("JVM_MaxMemory");
 523   size_t n = Universe::heap()->max_capacity();
 524   return convert_size_t_to_jlong(n);
 525 JVM_END
 526 
 527 
 528 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
 529   JVMWrapper("JVM_ActiveProcessorCount");
 530   return os::active_processor_count();
 531 JVM_END
 532 
 533 
 534 
 535 // java.lang.Throwable //////////////////////////////////////////////////////
 536 
 537 
 538 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
 539   JVMWrapper("JVM_FillInStackTrace");
 540   Handle exception(thread, JNIHandles::resolve_non_null(receiver));
 541   java_lang_Throwable::fill_in_stack_trace(exception);
 542 JVM_END
 543 








































 544 
 545 // java.lang.StackTraceElement //////////////////////////////////////////////
 546 
 547 
 548 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
 549   JVMWrapper("JVM_InitStackTraceElementArray");
 550   Handle exception(THREAD, JNIHandles::resolve(throwable));
 551   objArrayOop st = objArrayOop(JNIHandles::resolve(elements));
 552   objArrayHandle stack_trace(THREAD, st);
 553   // Fill in the allocated stack trace
 554   java_lang_Throwable::get_stack_trace_elements(exception, stack_trace, CHECK);
 555 JVM_END
 556 
 557 
 558 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 559   JVMWrapper("JVM_InitStackTraceElement");
 560   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 561   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 562   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, THREAD);
 563 JVM_END




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/bytecodeUtils.hpp"
  28 #include "classfile/classFileStream.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/classLoaderData.inline.hpp"
  31 #include "classfile/javaAssertions.hpp"
  32 #include "classfile/javaClasses.inline.hpp"
  33 #include "classfile/moduleEntry.hpp"
  34 #include "classfile/modules.hpp"
  35 #include "classfile/packageEntry.hpp"
  36 #include "classfile/stringTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "gc/shared/collectedHeap.inline.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/heapShared.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/referenceType.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "memory/universe.hpp"


 518   return convert_size_t_to_jlong(n);
 519 JVM_END
 520 
 521 
 522 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
 523   JVMWrapper("JVM_MaxMemory");
 524   size_t n = Universe::heap()->max_capacity();
 525   return convert_size_t_to_jlong(n);
 526 JVM_END
 527 
 528 
 529 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
 530   JVMWrapper("JVM_ActiveProcessorCount");
 531   return os::active_processor_count();
 532 JVM_END
 533 
 534 
 535 
 536 // java.lang.Throwable //////////////////////////////////////////////////////
 537 

 538 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
 539   JVMWrapper("JVM_FillInStackTrace");
 540   Handle exception(thread, JNIHandles::resolve_non_null(receiver));
 541   java_lang_Throwable::fill_in_stack_trace(exception);
 542 JVM_END
 543 
 544 // java.lang.NullPointerException ///////////////////////////////////////////
 545 
 546 JVM_ENTRY(jstring, JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwable))
 547   oop exc = JNIHandles::resolve_non_null(throwable);
 548 
 549   Method* method;
 550   int bci;
 551   if (!java_lang_Throwable::get_method_and_bci(exc, &method, &bci)) {
 552     return NULL;
 553   }
 554   if (method->is_native()) {
 555     return NULL;
 556   }
 557 
 558   ResourceMark rm(THREAD);
 559   TrackingStackCreator stc(method, bci);
 560   char const* reason;
 561   int slot = stc.get_null_pointer_slot(bci, &reason);
 562 
 563   // Build the message.
 564   stringStream ss;
 565   if (slot == -2) {
 566     return NULL;
 567   } else if (slot == -1) {
 568     ss.print("There cannot be a NullPointerException at bci %d of method %s",
 569              bci, method->name_and_sig_as_C_string());
 570   } else if (reason == NULL) {
 571     ss.print("Cannot get the reason for the NullPointerException at bci %d of method %s",
 572              bci, method->name_and_sig_as_C_string());
 573   } else {
 574     TrackingStackSource source = stc.get_source(bci, slot, 2);
 575     ss.print("%s", reason);
 576     if (source.get_type() != TrackingStackSource::INVALID) {
 577       ss.print(" %s", source.as_string());
 578     }
 579   }
 580 
 581   oop result = java_lang_String::create_oop_from_str(ss.as_string(), CHECK_0);
 582   return (jstring) JNIHandles::make_local(env, result);
 583 JVM_END
 584 
 585 // java.lang.StackTraceElement //////////////////////////////////////////////
 586 
 587 
 588 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
 589   JVMWrapper("JVM_InitStackTraceElementArray");
 590   Handle exception(THREAD, JNIHandles::resolve(throwable));
 591   objArrayOop st = objArrayOop(JNIHandles::resolve(elements));
 592   objArrayHandle stack_trace(THREAD, st);
 593   // Fill in the allocated stack trace
 594   java_lang_Throwable::get_stack_trace_elements(exception, stack_trace, CHECK);
 595 JVM_END
 596 
 597 
 598 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 599   JVMWrapper("JVM_InitStackTraceElement");
 600   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 601   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 602   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, THREAD);
 603 JVM_END


< prev index next >