< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page




  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"
  48 #include "oops/access.inline.hpp"
  49 #include "oops/constantPool.hpp"
  50 #include "oops/fieldStreams.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/method.hpp"
  53 #include "oops/objArrayKlass.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "prims/jvm_misc.hpp"
  57 #include "prims/jvmtiExport.hpp"
  58 #include "prims/jvmtiThreadState.hpp"
  59 #include "prims/nativeLookup.hpp"
  60 #include "prims/stackwalk.hpp"
  61 #include "runtime/arguments.hpp"
  62 #include "runtime/atomic.hpp"

  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/init.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/deoptimization.hpp"
  67 #include "runtime/handshake.hpp"
  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/jfieldIDWorkaround.hpp"
  71 #include "runtime/jniHandles.inline.hpp"
  72 #include "runtime/orderAccess.hpp"
  73 #include "runtime/os.inline.hpp"
  74 #include "runtime/perfData.hpp"
  75 #include "runtime/reflection.hpp"
  76 #include "runtime/thread.inline.hpp"
  77 #include "runtime/threadSMR.hpp"
  78 #include "runtime/vframe.inline.hpp"
  79 #include "runtime/vmOperations.hpp"
  80 #include "runtime/vm_version.hpp"
  81 #include "services/attachListener.hpp"
  82 #include "services/management.hpp"


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


 539 JVM_END
 540 
 541 
 542 // java.lang.StackTraceElement //////////////////////////////////////////////
 543 
 544 
 545 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
 546   JVMWrapper("JVM_InitStackTraceElementArray");
 547   Handle exception(THREAD, JNIHandles::resolve(throwable));
 548   objArrayOop st = objArrayOop(JNIHandles::resolve(elements));
 549   objArrayHandle stack_trace(THREAD, st);
 550   // Fill in the allocated stack trace
 551   java_lang_Throwable::get_stack_trace_elements(exception, stack_trace, CHECK);
 552 JVM_END
 553 
 554 
 555 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 556   JVMWrapper("JVM_InitStackTraceElement");
 557   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 558   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 559   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, THREAD);
 560 JVM_END
 561 
 562 
 563 // java.lang.StackWalker //////////////////////////////////////////////////////
 564 
 565 
 566 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode,
 567                                      jint skip_frames, jint frame_count, jint start_index,
 568                                      jobjectArray frames))
 569   JVMWrapper("JVM_CallStackWalk");
 570   JavaThread* jt = (JavaThread*) THREAD;
 571   if (!jt->is_Java_thread() || !jt->has_last_Java_frame()) {
 572     THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", NULL);
 573   }
 574 
 575   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 576 

 577   // frames array is a Class<?>[] array when only getting caller reference,
 578   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 579   // be null.
 580   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 581   objArrayHandle frames_array_h(THREAD, fa);
 582 
 583   int limit = start_index + frame_count;
 584   if (frames_array_h->length() < limit) {
 585     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL);
 586   }
 587 
 588   oop result = StackWalk::walk(stackStream_h, mode, skip_frames, frame_count,
 589                                start_index, frames_array_h, CHECK_NULL);
 590   return JNIHandles::make_local(env, result);
 591 JVM_END
 592 
 593 
 594 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor,
 595                                   jint frame_count, jint start_index,
 596                                   jobjectArray frames))
 597   JVMWrapper("JVM_MoreStackWalk");
 598   JavaThread* jt = (JavaThread*) THREAD;
 599 
 600   // frames array is a Class<?>[] array when only getting caller reference,
 601   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 602   // be null.
 603   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 604   objArrayHandle frames_array_h(THREAD, fa);
 605 
 606   int limit = start_index+frame_count;
 607   if (frames_array_h->length() < limit) {
 608     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 609   }
 610 
 611   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 612   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 613                                    start_index, frames_array_h, THREAD);











 614 JVM_END
 615 
 616 // java.lang.Object ///////////////////////////////////////////////
 617 
 618 
 619 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 620   JVMWrapper("JVM_IHashCode");
 621   // as implemented in the classic virtual machine; return 0 if object is NULL
 622   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
 623 JVM_END
 624 
 625 
 626 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 627   JVMWrapper("JVM_MonitorWait");
 628   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 629   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 630   if (JvmtiExport::should_post_monitor_wait()) {
 631     JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
 632 
 633     // The current thread already owns the monitor and it has not yet


 689     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 690                                                    /* do_zero */ true, CHECK_NULL);
 691   } else {
 692     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 693   }
 694 
 695   HeapAccess<>::clone(obj(), new_obj_oop, size);
 696 
 697   Handle new_obj(THREAD, new_obj_oop);
 698   // Caution: this involves a java upcall, so the clone should be
 699   // "gc-robust" by this stage.
 700   if (klass->has_finalizer()) {
 701     assert(obj->is_instance(), "should be instanceOop");
 702     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 703     new_obj = Handle(THREAD, new_obj_oop);
 704   }
 705 
 706   return JNIHandles::make_local(env, new_obj());
 707 JVM_END
 708 






 709 // java.io.File ///////////////////////////////////////////////////////////////
 710 
 711 JVM_LEAF(char*, JVM_NativePath(char* path))
 712   JVMWrapper("JVM_NativePath");
 713   return os::native_path(path);
 714 JVM_END
 715 
 716 
 717 // Misc. class handling ///////////////////////////////////////////////////////////
 718 
 719 
 720 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
 721   JVMWrapper("JVM_GetCallerClass");
 722 
 723   // Getting the class of the caller frame.
 724   //
 725   // The call stack at this point looks something like this:
 726   //
 727   // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
 728   // [1] [ @CallerSensitive API.method                                   ]


3649   int num_args = Arguments::num_jvm_args();
3650 
3651   InstanceKlass* ik = SystemDictionary::String_klass();
3652   objArrayOop r = oopFactory::new_objArray(ik, num_args + num_flags, CHECK_NULL);
3653   objArrayHandle result_h(THREAD, r);
3654 
3655   int index = 0;
3656   for (int j = 0; j < num_flags; j++, index++) {
3657     Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
3658     result_h->obj_at_put(index, h());
3659   }
3660   for (int i = 0; i < num_args; i++, index++) {
3661     Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL);
3662     result_h->obj_at_put(index, h());
3663   }
3664   return (jobjectArray) JNIHandles::make_local(env, result_h());
3665 JVM_END
3666 
3667 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
3668   return os::get_signal_number(name);




























3669 JVM_END


  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"
  48 #include "oops/access.inline.hpp"
  49 #include "oops/constantPool.hpp"
  50 #include "oops/fieldStreams.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/method.hpp"
  53 #include "oops/objArrayKlass.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "prims/jvm_misc.hpp"
  57 #include "prims/jvmtiExport.hpp"
  58 #include "prims/jvmtiThreadState.hpp"
  59 #include "prims/nativeLookup.hpp"
  60 #include "prims/stackwalk.hpp"
  61 #include "runtime/arguments.hpp"
  62 #include "runtime/atomic.hpp"
  63 #include "runtime/continuation.hpp"
  64 #include "runtime/handles.inline.hpp"
  65 #include "runtime/init.hpp"
  66 #include "runtime/interfaceSupport.inline.hpp"
  67 #include "runtime/deoptimization.hpp"
  68 #include "runtime/handshake.hpp"
  69 #include "runtime/java.hpp"
  70 #include "runtime/javaCalls.hpp"
  71 #include "runtime/jfieldIDWorkaround.hpp"
  72 #include "runtime/jniHandles.inline.hpp"
  73 #include "runtime/orderAccess.hpp"
  74 #include "runtime/os.inline.hpp"
  75 #include "runtime/perfData.hpp"
  76 #include "runtime/reflection.hpp"
  77 #include "runtime/thread.inline.hpp"
  78 #include "runtime/threadSMR.hpp"
  79 #include "runtime/vframe.inline.hpp"
  80 #include "runtime/vmOperations.hpp"
  81 #include "runtime/vm_version.hpp"
  82 #include "services/attachListener.hpp"
  83 #include "services/management.hpp"


 516 JVM_END
 517 
 518 
 519 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
 520   JVMWrapper("JVM_MaxMemory");
 521   size_t n = Universe::heap()->max_capacity();
 522   return convert_size_t_to_jlong(n);
 523 JVM_END
 524 
 525 
 526 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
 527   JVMWrapper("JVM_ActiveProcessorCount");
 528   return os::active_processor_count();
 529 JVM_END
 530 
 531 
 532 
 533 // java.lang.Throwable //////////////////////////////////////////////////////
 534 
 535 
 536 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver, jobject contScope))
 537   JVMWrapper("JVM_FillInStackTrace");
 538   Handle exception(thread, JNIHandles::resolve_non_null(receiver));
 539   Handle scope(thread, JNIHandles::resolve(contScope));
 540   
 541   java_lang_Throwable::fill_in_stack_trace(exception, scope);
 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
 564 
 565 
 566 // java.lang.StackWalker //////////////////////////////////////////////////////
 567 
 568 
 569 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode,
 570                                      jint skip_frames, jobject contScope, jobject cont,
 571                                      jint frame_count, jint start_index, jobjectArray frames))
 572   JVMWrapper("JVM_CallStackWalk");
 573   JavaThread* jt = (JavaThread*) THREAD;
 574   if (!jt->is_Java_thread() || !jt->has_last_Java_frame()) {
 575     THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", NULL);
 576   }
 577 
 578   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 579   Handle contScope_h(THREAD, JNIHandles::resolve(contScope));
 580   Handle cont_h(THREAD, JNIHandles::resolve(cont));
 581   // frames array is a Class<?>[] array when only getting caller reference,
 582   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 583   // be null.
 584   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 585   objArrayHandle frames_array_h(THREAD, fa);
 586 
 587   int limit = start_index + frame_count;
 588   if (frames_array_h->length() < limit) {
 589     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL);
 590   }
 591 
 592   oop result = StackWalk::walk(stackStream_h, mode, skip_frames, contScope_h, cont_h,
 593                                frame_count, start_index, frames_array_h, CHECK_NULL);
 594   return JNIHandles::make_local(env, result);
 595 JVM_END
 596 
 597 
 598 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor,
 599                                   jint frame_count, jint start_index, 
 600                                   jobjectArray frames))
 601   JVMWrapper("JVM_MoreStackWalk");

 602 
 603   // frames array is a Class<?>[] array when only getting caller reference,
 604   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 605   // be null.
 606   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 607   objArrayHandle frames_array_h(THREAD, fa);
 608 
 609   int limit = start_index+frame_count;
 610   if (frames_array_h->length() < limit) {
 611     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 612   }
 613 
 614   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 615   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count, 
 616                                   start_index, frames_array_h, THREAD);
 617 JVM_END
 618 
 619 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 620     JVMWrapper("JVM_SetStackWalkContinuation");
 621 
 622     objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 623     objArrayHandle frames_array_h(THREAD, fa);
 624     Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 625     Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 626 
 627     StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 628 JVM_END
 629 
 630 // java.lang.Object ///////////////////////////////////////////////
 631 
 632 
 633 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 634   JVMWrapper("JVM_IHashCode");
 635   // as implemented in the classic virtual machine; return 0 if object is NULL
 636   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
 637 JVM_END
 638 
 639 
 640 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 641   JVMWrapper("JVM_MonitorWait");
 642   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 643   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 644   if (JvmtiExport::should_post_monitor_wait()) {
 645     JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
 646 
 647     // The current thread already owns the monitor and it has not yet


 703     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 704                                                    /* do_zero */ true, CHECK_NULL);
 705   } else {
 706     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 707   }
 708 
 709   HeapAccess<>::clone(obj(), new_obj_oop, size);
 710 
 711   Handle new_obj(THREAD, new_obj_oop);
 712   // Caution: this involves a java upcall, so the clone should be
 713   // "gc-robust" by this stage.
 714   if (klass->has_finalizer()) {
 715     assert(obj->is_instance(), "should be instanceOop");
 716     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 717     new_obj = Handle(THREAD, new_obj_oop);
 718   }
 719 
 720   return JNIHandles::make_local(env, new_obj());
 721 JVM_END
 722 
 723 // java.lang.Continuation /////////////////////////////////////////////////////
 724 
 725 JVM_ENTRY(void, JVM_RegisterContinuationMethods(JNIEnv *env, jclass cls))
 726   CONT_RegisterNativeMethods(env, cls);
 727 JVM_END
 728 
 729 // java.io.File ///////////////////////////////////////////////////////////////
 730 
 731 JVM_LEAF(char*, JVM_NativePath(char* path))
 732   JVMWrapper("JVM_NativePath");
 733   return os::native_path(path);
 734 JVM_END
 735 
 736 
 737 // Misc. class handling ///////////////////////////////////////////////////////////
 738 
 739 
 740 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
 741   JVMWrapper("JVM_GetCallerClass");
 742 
 743   // Getting the class of the caller frame.
 744   //
 745   // The call stack at this point looks something like this:
 746   //
 747   // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
 748   // [1] [ @CallerSensitive API.method                                   ]


3669   int num_args = Arguments::num_jvm_args();
3670 
3671   InstanceKlass* ik = SystemDictionary::String_klass();
3672   objArrayOop r = oopFactory::new_objArray(ik, num_args + num_flags, CHECK_NULL);
3673   objArrayHandle result_h(THREAD, r);
3674 
3675   int index = 0;
3676   for (int j = 0; j < num_flags; j++, index++) {
3677     Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
3678     result_h->obj_at_put(index, h());
3679   }
3680   for (int i = 0; i < num_args; i++, index++) {
3681     Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL);
3682     result_h->obj_at_put(index, h());
3683   }
3684   return (jobjectArray) JNIHandles::make_local(env, result_h());
3685 JVM_END
3686 
3687 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
3688   return os::get_signal_number(name);
3689 JVM_END
3690 
3691 JVM_ENTRY(void, JVM_FiberStarted(JNIEnv* env, jclass fiber_class, jthread event_hread, jobject fiber))
3692   JVMWrapper("JVM_FiberStarted");
3693   if (JvmtiExport::should_post_fiber_scheduled()) {
3694     JvmtiExport::post_fiber_scheduled(event_hread, fiber);
3695   }
3696 JVM_END
3697 
3698 JVM_ENTRY(void, JVM_FiberTerminated(JNIEnv* env, jclass fiber_class, jthread event_hread, jobject fiber))
3699   JVMWrapper("JVM_FiberTerminated");
3700   if (JvmtiExport::should_post_fiber_terminated()) {
3701     JvmtiExport::post_fiber_terminated(event_hread, fiber);
3702   }
3703 JVM_END
3704 
3705 JVM_ENTRY(void, JVM_FiberMount(JNIEnv* env, jclass fiber_class, jthread event_hread, jobject fiber))
3706   JVMWrapper("JVM_FiberMount");
3707   if (JvmtiExport::should_post_fiber_mount()) {
3708     JvmtiExport::post_fiber_mount(event_hread, fiber);
3709   }
3710 JVM_END
3711 
3712 JVM_ENTRY(void, JVM_FiberUnmount(JNIEnv* env, jclass fiber_class, jthread event_hread, jobject fiber))
3713   JVMWrapper("JVM_FiberUnmount");
3714   if (JvmtiExport::should_post_fiber_unmount()) {
3715     JvmtiExport::post_fiber_unmount(event_hread, fiber);
3716   }
3717 JVM_END
< prev index next >