< prev index next >

src/share/vm/prims/jvm.cpp

Print this page




  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/init.hpp"
  58 #include "runtime/interfaceSupport.hpp"
  59 #include "runtime/java.hpp"
  60 #include "runtime/javaCalls.hpp"
  61 #include "runtime/jfieldIDWorkaround.hpp"
  62 #include "runtime/orderAccess.inline.hpp"
  63 #include "runtime/os.hpp"
  64 #include "runtime/perfData.hpp"
  65 #include "runtime/reflection.hpp"
  66 #include "runtime/vframe.hpp"
  67 #include "runtime/vm_operations.hpp"
  68 #include "services/attachListener.hpp"
  69 #include "services/management.hpp"
  70 #include "services/threadService.hpp"
  71 #include "utilities/copy.hpp"
  72 #include "utilities/defaultStream.hpp"
  73 #include "utilities/dtrace.hpp"
  74 #include "utilities/events.hpp"
  75 #include "utilities/histogram.hpp"

  76 #include "utilities/top.hpp"
  77 #include "utilities/utf8.hpp"
  78 #ifdef TARGET_OS_FAMILY_linux
  79 # include "jvm_linux.h"
  80 #endif
  81 #ifdef TARGET_OS_FAMILY_solaris
  82 # include "jvm_solaris.h"
  83 #endif
  84 #ifdef TARGET_OS_FAMILY_windows
  85 # include "jvm_windows.h"
  86 #endif
  87 #ifdef TARGET_OS_FAMILY_aix
  88 # include "jvm_aix.h"
  89 #endif
  90 #ifdef TARGET_OS_FAMILY_bsd
  91 # include "jvm_bsd.h"
  92 #endif
  93 
  94 #if INCLUDE_ALL_GCS
  95 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"

  96 #endif // INCLUDE_ALL_GCS
  97 
  98 #include <errno.h>
  99 #include <jfr/recorder/jfrRecorder.hpp>
 100 
 101 #ifndef USDT2
 102 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
 103 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
 104 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
 105 #endif /* !USDT2 */
 106 
 107 /*
 108   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
 109   such ctors and calls MUST NOT come between an oop declaration/init and its
 110   usage because if objects are move this may cause various memory stomps, bus
 111   errors and segfaults. Here is a cookbook for causing so called "naked oop
 112   failures":
 113 
 114       JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
 115           JVMWrapper("JVM_GetClassDeclaredFields");


 592 
 593 
 594 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 595   JVMWrapper("JVM_MonitorNotify");
 596   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 597   ObjectSynchronizer::notify(obj, CHECK);
 598 JVM_END
 599 
 600 
 601 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 602   JVMWrapper("JVM_MonitorNotifyAll");
 603   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 604   ObjectSynchronizer::notifyall(obj, CHECK);
 605 JVM_END
 606 
 607 
 608 static void fixup_cloned_reference(ReferenceType ref_type, oop src, oop clone) {
 609   // If G1 is enabled then we need to register a non-null referent
 610   // with the SATB barrier.
 611 #if INCLUDE_ALL_GCS
 612   if (UseG1GC) {
 613     oop referent = java_lang_ref_Reference::referent(clone);
 614     if (referent != NULL) {
 615       G1SATBCardTableModRefBS::enqueue(referent);
 616     }
 617   }
 618 #endif // INCLUDE_ALL_GCS
 619   if ((java_lang_ref_Reference::next(clone) != NULL) ||
 620       (java_lang_ref_Reference::queue(clone) == java_lang_ref_ReferenceQueue::ENQUEUED_queue())) {
 621     // If the source has been enqueued or is being enqueued, don't
 622     // register the clone with a queue.
 623     java_lang_ref_Reference::set_queue(clone, java_lang_ref_ReferenceQueue::NULL_queue());
 624   }
 625   // discovered and next are list links; the clone is not in those lists.
 626   java_lang_ref_Reference::set_discovered(clone, NULL);
 627   java_lang_ref_Reference::set_next(clone, NULL);
 628 }
 629 
 630 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 631   JVMWrapper("JVM_Clone");
 632   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));


 649   if (!klass->is_cloneable()) {
 650     ResourceMark rm(THREAD);
 651     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 652   }
 653 
 654   // Make shallow object copy
 655   ReferenceType ref_type = REF_NONE;
 656   const int size = obj->size();
 657   oop new_obj_oop = NULL;
 658   if (obj->is_array()) {
 659     const int length = ((arrayOop)obj())->length();
 660     new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
 661   } else {
 662     ref_type = InstanceKlass::cast(klass())->reference_type();
 663     assert((ref_type == REF_NONE) ==
 664            !klass->is_subclass_of(SystemDictionary::Reference_klass()),
 665            "invariant");
 666     new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
 667   }
 668 






 669   // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
 670   // is modifying a reference field in the clonee, a non-oop-atomic copy might
 671   // be suspended in the middle of copying the pointer and end up with parts
 672   // of two different pointers in the field.  Subsequent dereferences will crash.
 673   // 4846409: an oop-copy of objects with long or double fields or arrays of same
 674   // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
 675   // of oops.  We know objects are aligned on a minimum of an jlong boundary.
 676   // The same is true of StubRoutines::object_copy and the various oop_copy
 677   // variants, and of the code generated by the inline_native_clone intrinsic.
 678   assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
 679   Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
 680                                (size_t)align_object_size(size) / HeapWordsPerLong);
 681   // Clear the header
 682   new_obj_oop->init_mark();
 683 
 684   // Store check (mark entire object and let gc sort it out)
 685   BarrierSet* bs = Universe::heap()->barrier_set();
 686   assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
 687   bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
 688 


1154   ResourceMark rm(THREAD);
1155   ClassFileStream st((u1*) buf, len, (char *)source);
1156   Handle class_loader (THREAD, JNIHandles::resolve(loader));
1157   if (UsePerfData) {
1158     is_lock_held_by_thread(class_loader,
1159                            ClassLoader::sync_JVMDefineClassLockFreeCounter(),
1160                            THREAD);
1161   }
1162   Handle protection_domain (THREAD, JNIHandles::resolve(pd));
1163   Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
1164                                                      protection_domain, &st,
1165                                                      verify != 0,
1166                                                      CHECK_NULL);
1167 
1168   if (TraceClassResolution && k != NULL) {
1169     trace_class_resolution(k);
1170   }
1171 
1172   return (jclass) JNIHandles::make_local(env, k->java_mirror());
1173 }
1174 
1175 
1176 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
1177   JVMWrapper2("JVM_DefineClass %s", name);
1178 
1179   return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, true, THREAD);
1180 JVM_END
1181 
1182 
1183 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
1184   JVMWrapper2("JVM_DefineClassWithSource %s", name);
1185 
1186   return jvm_define_class_common(env, name, loader, buf, len, pd, source, true, THREAD);
1187 JVM_END
1188 
1189 JVM_ENTRY(jclass, JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name,
1190                                                 jobject loader, const jbyte *buf,
1191                                                 jsize len, jobject pd,
1192                                                 const char *source, jboolean verify))
1193   JVMWrapper2("JVM_DefineClassWithSourceCond %s", name);
1194 




  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/init.hpp"
  58 #include "runtime/interfaceSupport.hpp"
  59 #include "runtime/java.hpp"
  60 #include "runtime/javaCalls.hpp"
  61 #include "runtime/jfieldIDWorkaround.hpp"
  62 #include "runtime/orderAccess.inline.hpp"
  63 #include "runtime/os.hpp"
  64 #include "runtime/perfData.hpp"
  65 #include "runtime/reflection.hpp"
  66 #include "runtime/vframe.hpp"
  67 #include "runtime/vm_operations.hpp"
  68 #include "services/attachListener.hpp"
  69 #include "services/management.hpp"
  70 #include "services/threadService.hpp"
  71 #include "utilities/copy.hpp"
  72 #include "utilities/defaultStream.hpp"
  73 #include "utilities/dtrace.hpp"
  74 #include "utilities/events.hpp"
  75 #include "utilities/histogram.hpp"
  76 #include "utilities/macros.hpp"
  77 #include "utilities/top.hpp"
  78 #include "utilities/utf8.hpp"
  79 #ifdef TARGET_OS_FAMILY_linux
  80 # include "jvm_linux.h"
  81 #endif
  82 #ifdef TARGET_OS_FAMILY_solaris
  83 # include "jvm_solaris.h"
  84 #endif
  85 #ifdef TARGET_OS_FAMILY_windows
  86 # include "jvm_windows.h"
  87 #endif
  88 #ifdef TARGET_OS_FAMILY_aix
  89 # include "jvm_aix.h"
  90 #endif
  91 #ifdef TARGET_OS_FAMILY_bsd
  92 # include "jvm_bsd.h"
  93 #endif
  94 
  95 #if INCLUDE_ALL_GCS
  96 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  97 #include "gc_implementation/shenandoah/shenandoahBarrierSetClone.inline.hpp"
  98 #endif // INCLUDE_ALL_GCS
  99 
 100 #include <errno.h>
 101 #include <jfr/recorder/jfrRecorder.hpp>
 102 
 103 #ifndef USDT2
 104 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
 105 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
 106 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
 107 #endif /* !USDT2 */
 108 
 109 /*
 110   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
 111   such ctors and calls MUST NOT come between an oop declaration/init and its
 112   usage because if objects are move this may cause various memory stomps, bus
 113   errors and segfaults. Here is a cookbook for causing so called "naked oop
 114   failures":
 115 
 116       JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
 117           JVMWrapper("JVM_GetClassDeclaredFields");


 594 
 595 
 596 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 597   JVMWrapper("JVM_MonitorNotify");
 598   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 599   ObjectSynchronizer::notify(obj, CHECK);
 600 JVM_END
 601 
 602 
 603 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 604   JVMWrapper("JVM_MonitorNotifyAll");
 605   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 606   ObjectSynchronizer::notifyall(obj, CHECK);
 607 JVM_END
 608 
 609 
 610 static void fixup_cloned_reference(ReferenceType ref_type, oop src, oop clone) {
 611   // If G1 is enabled then we need to register a non-null referent
 612   // with the SATB barrier.
 613 #if INCLUDE_ALL_GCS
 614   if (UseG1GC || (UseShenandoahGC && ShenandoahSATBBarrier)) {
 615     oop referent = java_lang_ref_Reference::referent(clone);
 616     if (referent != NULL) {
 617       G1SATBCardTableModRefBS::enqueue(referent);
 618     }
 619   }
 620 #endif // INCLUDE_ALL_GCS
 621   if ((java_lang_ref_Reference::next(clone) != NULL) ||
 622       (java_lang_ref_Reference::queue(clone) == java_lang_ref_ReferenceQueue::ENQUEUED_queue())) {
 623     // If the source has been enqueued or is being enqueued, don't
 624     // register the clone with a queue.
 625     java_lang_ref_Reference::set_queue(clone, java_lang_ref_ReferenceQueue::NULL_queue());
 626   }
 627   // discovered and next are list links; the clone is not in those lists.
 628   java_lang_ref_Reference::set_discovered(clone, NULL);
 629   java_lang_ref_Reference::set_next(clone, NULL);
 630 }
 631 
 632 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 633   JVMWrapper("JVM_Clone");
 634   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));


 651   if (!klass->is_cloneable()) {
 652     ResourceMark rm(THREAD);
 653     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 654   }
 655 
 656   // Make shallow object copy
 657   ReferenceType ref_type = REF_NONE;
 658   const int size = obj->size();
 659   oop new_obj_oop = NULL;
 660   if (obj->is_array()) {
 661     const int length = ((arrayOop)obj())->length();
 662     new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
 663   } else {
 664     ref_type = InstanceKlass::cast(klass())->reference_type();
 665     assert((ref_type == REF_NONE) ==
 666            !klass->is_subclass_of(SystemDictionary::Reference_klass()),
 667            "invariant");
 668     new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
 669   }
 670 
 671 #if INCLUDE_ALL_GCS
 672   if (UseShenandoahGC && ShenandoahCloneBarrier) {
 673     ShenandoahBarrierSet::barrier_set()->clone_barrier_runtime(obj());
 674   }
 675 #endif
 676 
 677   // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
 678   // is modifying a reference field in the clonee, a non-oop-atomic copy might
 679   // be suspended in the middle of copying the pointer and end up with parts
 680   // of two different pointers in the field.  Subsequent dereferences will crash.
 681   // 4846409: an oop-copy of objects with long or double fields or arrays of same
 682   // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
 683   // of oops.  We know objects are aligned on a minimum of an jlong boundary.
 684   // The same is true of StubRoutines::object_copy and the various oop_copy
 685   // variants, and of the code generated by the inline_native_clone intrinsic.
 686   assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
 687   Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
 688                                (size_t)align_object_size(size) / HeapWordsPerLong);
 689   // Clear the header
 690   new_obj_oop->init_mark();
 691 
 692   // Store check (mark entire object and let gc sort it out)
 693   BarrierSet* bs = Universe::heap()->barrier_set();
 694   assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
 695   bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
 696 


1162   ResourceMark rm(THREAD);
1163   ClassFileStream st((u1*) buf, len, (char *)source);
1164   Handle class_loader (THREAD, JNIHandles::resolve(loader));
1165   if (UsePerfData) {
1166     is_lock_held_by_thread(class_loader,
1167                            ClassLoader::sync_JVMDefineClassLockFreeCounter(),
1168                            THREAD);
1169   }
1170   Handle protection_domain (THREAD, JNIHandles::resolve(pd));
1171   Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
1172                                                      protection_domain, &st,
1173                                                      verify != 0,
1174                                                      CHECK_NULL);
1175 
1176   if (TraceClassResolution && k != NULL) {
1177     trace_class_resolution(k);
1178   }
1179 
1180   return (jclass) JNIHandles::make_local(env, k->java_mirror());
1181 }

1182 
1183 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
1184   JVMWrapper2("JVM_DefineClass %s", name);
1185 
1186   return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, true, THREAD);
1187 JVM_END
1188 
1189 
1190 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
1191   JVMWrapper2("JVM_DefineClassWithSource %s", name);
1192 
1193   return jvm_define_class_common(env, name, loader, buf, len, pd, source, true, THREAD);
1194 JVM_END
1195 
1196 JVM_ENTRY(jclass, JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name,
1197                                                 jobject loader, const jbyte *buf,
1198                                                 jsize len, jobject pd,
1199                                                 const char *source, jboolean verify))
1200   JVMWrapper2("JVM_DefineClassWithSourceCond %s", name);
1201 


< prev index next >