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


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


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






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


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


1569   oop previous_protection_domain = NULL;
1570   Handle privileged_context(thread, NULL);
1571   bool is_privileged = false;
1572   oop protection_domain = NULL;
1573 
1574   for(; !vfst.at_end(); vfst.next()) {
1575     // get method of frame
1576     Method* method = vfst.method();
1577     intptr_t* frame_id   = vfst.frame_id();
1578 
1579     // check the privileged frames to see if we have a match
1580     if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) {
1581       // this frame is privileged
1582       is_privileged = true;
1583       privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
1584       protection_domain  = thread->privileged_stack_top()->protection_domain();
1585     } else {
1586       protection_domain = method->method_holder()->protection_domain();
1587     }
1588 
1589     if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
1590       local_array->push(protection_domain);
1591       previous_protection_domain = protection_domain;
1592     }
1593 
1594     if (is_privileged) break;
1595   }
1596 
1597 
1598   // either all the domains on the stack were system domains, or
1599   // we had a privileged system domain
1600   if (local_array->is_empty()) {
1601     if (is_privileged && privileged_context.is_null()) return NULL;
1602 
1603     oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
1604     return JNIHandles::make_local(env, result);
1605   }
1606 
1607   // the resource area must be registered in case of a gc
1608   RegisterArrayForGC ragc(thread, local_array);
1609   objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(),




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


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


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


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

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


1576   oop previous_protection_domain = NULL;
1577   Handle privileged_context(thread, NULL);
1578   bool is_privileged = false;
1579   oop protection_domain = NULL;
1580 
1581   for(; !vfst.at_end(); vfst.next()) {
1582     // get method of frame
1583     Method* method = vfst.method();
1584     intptr_t* frame_id   = vfst.frame_id();
1585 
1586     // check the privileged frames to see if we have a match
1587     if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) {
1588       // this frame is privileged
1589       is_privileged = true;
1590       privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
1591       protection_domain  = thread->privileged_stack_top()->protection_domain();
1592     } else {
1593       protection_domain = method->method_holder()->protection_domain();
1594     }
1595 
1596     if ((previous_protection_domain != protection_domain) && protection_domain != NULL) {
1597       local_array->push(protection_domain);
1598       previous_protection_domain = protection_domain;
1599     }
1600 
1601     if (is_privileged) break;
1602   }
1603 
1604 
1605   // either all the domains on the stack were system domains, or
1606   // we had a privileged system domain
1607   if (local_array->is_empty()) {
1608     if (is_privileged && privileged_context.is_null()) return NULL;
1609 
1610     oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
1611     return JNIHandles::make_local(env, result);
1612   }
1613 
1614   // the resource area must be registered in case of a gc
1615   RegisterArrayForGC ragc(thread, local_array);
1616   objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(),


< prev index next >