< prev index next >

src/share/vm/prims/jvm.cpp

Print this page




 534   oop exception = JNIHandles::resolve(throwable);
 535   return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
 536 JVM_END
 537 
 538 
 539 JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
 540   JVMWrapper("JVM_GetStackTraceElement");
 541   JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
 542   oop exception = JNIHandles::resolve(throwable);
 543   oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
 544   return JNIHandles::make_local(env, element);
 545 JVM_END
 546 
 547 
 548 // java.lang.Object ///////////////////////////////////////////////
 549 
 550 
 551 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 552   JVMWrapper("JVM_IHashCode");
 553   // as implemented in the classic virtual machine; return 0 if object is NULL
 554   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
 555 JVM_END
 556 
 557 
 558 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 559   JVMWrapper("JVM_MonitorWait");
 560   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));


 561   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 562   if (JvmtiExport::should_post_monitor_wait()) {
 563     JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
 564 
 565     // The current thread already owns the monitor and it has not yet
 566     // been added to the wait queue so the current thread cannot be
 567     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 568     // event handler cannot accidentally consume an unpark() meant for
 569     // the ParkEvent associated with this ObjectMonitor.
 570   }
 571   ObjectSynchronizer::wait(obj, ms, CHECK);
 572 JVM_END
 573 
 574 
 575 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 576   JVMWrapper("JVM_MonitorNotify");
 577   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 578   ObjectSynchronizer::notify(obj, CHECK);
 579 JVM_END
 580 
 581 
 582 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 583   JVMWrapper("JVM_MonitorNotifyAll");
 584   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 585   ObjectSynchronizer::notifyall(obj, CHECK);
 586 JVM_END
 587 
 588 
 589 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 590   JVMWrapper("JVM_Clone");
 591   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 592   const KlassHandle klass (THREAD, obj->klass());
 593   JvmtiVMObjectAllocEventCollector oam;
 594 
 595 #ifdef ASSERT
 596   // Just checking that the cloneable flag is set correct
 597   if (obj->is_array()) {
 598     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 599   } else {
 600     guarantee(obj->is_instance(), "should be instanceOop");
 601     bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
 602     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 603   }
 604 #endif
 605 
 606   // Check if class of obj supports the Cloneable interface.
 607   // All arrays are considered to be cloneable (See JLS 20.1.5)
 608   if (!klass->is_cloneable()) {
 609     ResourceMark rm(THREAD);
 610     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 611   }
 612 
 613   // Make shallow object copy
 614   const int size = obj->size();
 615   oop new_obj_oop = NULL;
 616   if (obj->is_array()) {
 617     const int length = ((arrayOop)obj())->length();
 618     new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
 619   } else {
 620     new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
 621   }
 622 
 623   // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
 624   // is modifying a reference field in the clonee, a non-oop-atomic copy might
 625   // be suspended in the middle of copying the pointer and end up with parts
 626   // of two different pointers in the field.  Subsequent dereferences will crash.
 627   // 4846409: an oop-copy of objects with long or double fields or arrays of same
 628   // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
 629   // of oops.  We know objects are aligned on a minimum of an jlong boundary.
 630   // The same is true of StubRoutines::object_copy and the various oop_copy
 631   // variants, and of the code generated by the inline_native_clone intrinsic.

 632   assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
 633   Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
 634                                (size_t)align_object_size(size) / HeapWordsPerLong);
 635   // Clear the header
 636   new_obj_oop->init_mark();
 637 
 638   // Store check (mark entire object and let gc sort it out)
 639   BarrierSet* bs = Universe::heap()->barrier_set();
 640   assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
 641   bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
 642 
 643   Handle new_obj(THREAD, new_obj_oop);
 644   // Special handling for MemberNames.  Since they contain Method* metadata, they
 645   // must be registered so that RedefineClasses can fix metadata contained in them.
 646   if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
 647       java_lang_invoke_MemberName::is_method(new_obj())) {
 648     Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
 649     // MemberName may be unresolved, so doesn't need registration until resolved.
 650     if (method != NULL) {
 651       methodHandle m(THREAD, method);


 878 
 879   if (UsePerfData) {
 880     ClassLoader::perf_app_classfile_bytes_read()->inc(len);
 881   }
 882 
 883   // Since exceptions can be thrown, class initialization can take place
 884   // if name is NULL no check for class name in .class stream has to be made.
 885   TempNewSymbol class_name = NULL;
 886   if (name != NULL) {
 887     const int str_len = (int)strlen(name);
 888     if (str_len > Symbol::max_length()) {
 889       // It's impossible to create this class;  the name cannot fit
 890       // into the constant pool.
 891       THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 892     }
 893     class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL);
 894   }
 895 
 896   ResourceMark rm(THREAD);
 897   ClassFileStream st((u1*) buf, len, (char *)source);
 898   Handle class_loader (THREAD, JNIHandles::resolve(loader));
 899   if (UsePerfData) {
 900     is_lock_held_by_thread(class_loader,
 901                            ClassLoader::sync_JVMDefineClassLockFreeCounter(),
 902                            THREAD);
 903   }
 904   Handle protection_domain (THREAD, JNIHandles::resolve(pd));
 905   Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
 906                                                      protection_domain, &st,
 907                                                      verify != 0,
 908                                                      CHECK_NULL);
 909 
 910   if (TraceClassResolution && k != NULL) {
 911     trace_class_resolution(k);
 912   }
 913 
 914   return (jclass) JNIHandles::make_local(env, k->java_mirror());
 915 }
 916 
 917 
 918 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))


 942   ResourceMark rm(THREAD);
 943 
 944   Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
 945   Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
 946 
 947   const char* str   = java_lang_String::as_utf8_string(string());
 948   // Sanity check, don't expect null
 949   if (str == NULL) return NULL;
 950 
 951   const int str_len = (int)strlen(str);
 952   if (str_len > Symbol::max_length()) {
 953     // It's impossible to create this class;  the name cannot fit
 954     // into the constant pool.
 955     return NULL;
 956   }
 957   TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL);
 958 
 959   // Security Note:
 960   //   The Java level wrapper will perform the necessary security check allowing
 961   //   us to pass the NULL as the initiating class loader.
 962   Handle h_loader(THREAD, JNIHandles::resolve(loader));
 963   if (UsePerfData) {
 964     is_lock_held_by_thread(h_loader,
 965                            ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
 966                            THREAD);
 967   }
 968 
 969   Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name,
 970                                                               h_loader,
 971                                                               Handle(),
 972                                                               CHECK_NULL);
 973 #if INCLUDE_CDS
 974   if (k == NULL) {
 975     // If the class is not already loaded, try to see if it's in the shared
 976     // archive for the current classloader (h_loader).
 977     instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class(
 978         klass_name, h_loader, CHECK_NULL);
 979     k = ik();
 980   }
 981 #endif
 982   return (k == NULL) ? NULL :


3011   MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
3012   // We need to re-resolve the java_thread, since a GC might have happened during the
3013   // acquire of the lock
3014   JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
3015   if (thr == NULL) {
3016     return JNI_FALSE;
3017   } else {
3018     return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
3019   }
3020 JVM_END
3021 
3022 
3023 // Return true iff the current thread has locked the object passed in
3024 
3025 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3026   JVMWrapper("JVM_HoldsLock");
3027   assert(THREAD->is_Java_thread(), "sanity check");
3028   if (obj == NULL) {
3029     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3030   }
3031   Handle h_obj(THREAD, JNIHandles::resolve(obj));
3032   return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
3033 JVM_END
3034 
3035 
3036 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
3037   JVMWrapper("JVM_DumpAllStacks");
3038   VM_PrintThreads op;
3039   VMThread::execute(&op);
3040   if (JvmtiExport::should_post_data_dump()) {
3041     JvmtiExport::post_data_dump();
3042   }
3043 JVM_END
3044 
3045 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3046   JVMWrapper("JVM_SetNativeThreadName");
3047   ResourceMark rm(THREAD);
3048   oop java_thread = JNIHandles::resolve_non_null(jthread);
3049   JavaThread* thr = java_lang_Thread::thread(java_thread);
3050   // Thread naming only supported for the current thread, doesn't work for
3051   // target threads.




 534   oop exception = JNIHandles::resolve(throwable);
 535   return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
 536 JVM_END
 537 
 538 
 539 JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
 540   JVMWrapper("JVM_GetStackTraceElement");
 541   JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
 542   oop exception = JNIHandles::resolve(throwable);
 543   oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
 544   return JNIHandles::make_local(env, element);
 545 JVM_END
 546 
 547 
 548 // java.lang.Object ///////////////////////////////////////////////
 549 
 550 
 551 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 552   JVMWrapper("JVM_IHashCode");
 553   // as implemented in the classic virtual machine; return 0 if object is NULL
 554   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve_non_null(handle))) ;
 555 JVM_END
 556 
 557 
 558 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 559   JVMWrapper("JVM_MonitorWait");
 560   oop o = JNIHandles::resolve_non_null(handle);
 561   o = oopDesc::bs()->write_barrier(o);
 562   Handle obj(THREAD, o);
 563   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 564   if (JvmtiExport::should_post_monitor_wait()) {
 565     JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
 566 
 567     // The current thread already owns the monitor and it has not yet
 568     // been added to the wait queue so the current thread cannot be
 569     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 570     // event handler cannot accidentally consume an unpark() meant for
 571     // the ParkEvent associated with this ObjectMonitor.
 572   }
 573   ObjectSynchronizer::wait(obj, ms, CHECK);
 574 JVM_END
 575 
 576 
 577 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 578   JVMWrapper("JVM_MonitorNotify");
 579   Handle obj(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve_non_null(handle)));
 580   ObjectSynchronizer::notify(obj, CHECK);
 581 JVM_END
 582 
 583 
 584 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 585   JVMWrapper("JVM_MonitorNotifyAll");
 586   Handle obj(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve_non_null(handle)));
 587   ObjectSynchronizer::notifyall(obj, CHECK);
 588 JVM_END
 589 
 590 
 591 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 592   JVMWrapper("JVM_Clone");
 593   Handle obj(THREAD, oopDesc::bs()->read_barrier(JNIHandles::resolve_non_null(handle)));
 594   const KlassHandle klass (THREAD, obj->klass());
 595   JvmtiVMObjectAllocEventCollector oam;
 596 
 597 #ifdef ASSERT
 598   // Just checking that the cloneable flag is set correct
 599   if (obj->is_array()) {
 600     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 601   } else {
 602     guarantee(obj->is_instance(), "should be instanceOop");
 603     bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
 604     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 605   }
 606 #endif
 607 
 608   // Check if class of obj supports the Cloneable interface.
 609   // All arrays are considered to be cloneable (See JLS 20.1.5)
 610   if (!klass->is_cloneable()) {
 611     ResourceMark rm(THREAD);
 612     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 613   }
 614 
 615   // Make shallow object copy
 616   const int size = obj->size();
 617   oop new_obj_oop = NULL;
 618   if (obj->is_array()) {
 619     const int length = ((arrayOop)obj())->length();
 620     new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
 621   } else {
 622     new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
 623   }
 624 
 625   // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
 626   // is modifying a reference field in the clonee, a non-oop-atomic copy might
 627   // be suspended in the middle of copying the pointer and end up with parts
 628   // of two different pointers in the field.  Subsequent dereferences will crash.
 629   // 4846409: an oop-copy of objects with long or double fields or arrays of same
 630   // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
 631   // of oops.  We know objects are aligned on a minimum of an jlong boundary.
 632   // The same is true of StubRoutines::object_copy and the various oop_copy
 633   // variants, and of the code generated by the inline_native_clone intrinsic.
 634   assert(new_obj_oop == oopDesc::bs()->read_barrier(new_obj_oop), "expect to-space copy");
 635   assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
 636   Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
 637                                (size_t)align_object_size(size) / HeapWordsPerLong);
 638   // Clear the header
 639   new_obj_oop->init_mark();
 640 
 641   // Store check (mark entire object and let gc sort it out)
 642   BarrierSet* bs = Universe::heap()->barrier_set();
 643   assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
 644   bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
 645 
 646   Handle new_obj(THREAD, new_obj_oop);
 647   // Special handling for MemberNames.  Since they contain Method* metadata, they
 648   // must be registered so that RedefineClasses can fix metadata contained in them.
 649   if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
 650       java_lang_invoke_MemberName::is_method(new_obj())) {
 651     Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
 652     // MemberName may be unresolved, so doesn't need registration until resolved.
 653     if (method != NULL) {
 654       methodHandle m(THREAD, method);


 881 
 882   if (UsePerfData) {
 883     ClassLoader::perf_app_classfile_bytes_read()->inc(len);
 884   }
 885 
 886   // Since exceptions can be thrown, class initialization can take place
 887   // if name is NULL no check for class name in .class stream has to be made.
 888   TempNewSymbol class_name = NULL;
 889   if (name != NULL) {
 890     const int str_len = (int)strlen(name);
 891     if (str_len > Symbol::max_length()) {
 892       // It's impossible to create this class;  the name cannot fit
 893       // into the constant pool.
 894       THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 895     }
 896     class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL);
 897   }
 898 
 899   ResourceMark rm(THREAD);
 900   ClassFileStream st((u1*) buf, len, (char *)source);
 901   Handle class_loader (THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve(loader)));
 902   if (UsePerfData) {
 903     is_lock_held_by_thread(class_loader,
 904                            ClassLoader::sync_JVMDefineClassLockFreeCounter(),
 905                            THREAD);
 906   }
 907   Handle protection_domain (THREAD, JNIHandles::resolve(pd));
 908   Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
 909                                                      protection_domain, &st,
 910                                                      verify != 0,
 911                                                      CHECK_NULL);
 912 
 913   if (TraceClassResolution && k != NULL) {
 914     trace_class_resolution(k);
 915   }
 916 
 917   return (jclass) JNIHandles::make_local(env, k->java_mirror());
 918 }
 919 
 920 
 921 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))


 945   ResourceMark rm(THREAD);
 946 
 947   Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
 948   Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
 949 
 950   const char* str   = java_lang_String::as_utf8_string(string());
 951   // Sanity check, don't expect null
 952   if (str == NULL) return NULL;
 953 
 954   const int str_len = (int)strlen(str);
 955   if (str_len > Symbol::max_length()) {
 956     // It's impossible to create this class;  the name cannot fit
 957     // into the constant pool.
 958     return NULL;
 959   }
 960   TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL);
 961 
 962   // Security Note:
 963   //   The Java level wrapper will perform the necessary security check allowing
 964   //   us to pass the NULL as the initiating class loader.
 965   Handle h_loader(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve(loader)));
 966   if (UsePerfData) {
 967     is_lock_held_by_thread(h_loader,
 968                            ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
 969                            THREAD);
 970   }
 971 
 972   Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name,
 973                                                               h_loader,
 974                                                               Handle(),
 975                                                               CHECK_NULL);
 976 #if INCLUDE_CDS
 977   if (k == NULL) {
 978     // If the class is not already loaded, try to see if it's in the shared
 979     // archive for the current classloader (h_loader).
 980     instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class(
 981         klass_name, h_loader, CHECK_NULL);
 982     k = ik();
 983   }
 984 #endif
 985   return (k == NULL) ? NULL :


3014   MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
3015   // We need to re-resolve the java_thread, since a GC might have happened during the
3016   // acquire of the lock
3017   JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
3018   if (thr == NULL) {
3019     return JNI_FALSE;
3020   } else {
3021     return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
3022   }
3023 JVM_END
3024 
3025 
3026 // Return true iff the current thread has locked the object passed in
3027 
3028 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3029   JVMWrapper("JVM_HoldsLock");
3030   assert(THREAD->is_Java_thread(), "sanity check");
3031   if (obj == NULL) {
3032     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3033   }
3034   Handle h_obj(THREAD, oopDesc::bs()->write_barrier(JNIHandles::resolve(obj)));
3035   return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
3036 JVM_END
3037 
3038 
3039 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
3040   JVMWrapper("JVM_DumpAllStacks");
3041   VM_PrintThreads op;
3042   VMThread::execute(&op);
3043   if (JvmtiExport::should_post_data_dump()) {
3044     JvmtiExport::post_data_dump();
3045   }
3046 JVM_END
3047 
3048 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3049   JVMWrapper("JVM_SetNativeThreadName");
3050   ResourceMark rm(THREAD);
3051   oop java_thread = JNIHandles::resolve_non_null(jthread);
3052   JavaThread* thr = java_lang_Thread::thread(java_thread);
3053   // Thread naming only supported for the current thread, doesn't work for
3054   // target threads.


< prev index next >