< prev index next >

src/hotspot/share/prims/unsafe.cpp

Print this page
rev 49674 : 8198285: More consistent Access API for arraycopy


 745   assert(host_class != NULL, "host_class must not be NULL");
 746   assert(data != NULL, "data must not be NULL");
 747 
 748   if (UsePerfData) {
 749     ClassLoader::unsafe_defineClassCallCounter()->inc();
 750   }
 751 
 752   jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length();
 753   assert(length >= 0, "class_bytes_length must not be negative: %d", length);
 754 
 755   int class_bytes_length = (int) length;
 756 
 757   u1* class_bytes = NEW_C_HEAP_ARRAY(u1, length, mtInternal);
 758   if (class_bytes == NULL) {
 759     THROW_0(vmSymbols::java_lang_OutOfMemoryError());
 760   }
 761 
 762   // caller responsible to free it:
 763   *temp_alloc = class_bytes;
 764 
 765   jbyte* array_base = typeArrayOop(JNIHandles::resolve_non_null(data))->byte_at_addr(0);
 766   Copy::conjoint_jbytes(array_base, class_bytes, length);
 767 
 768   objArrayHandle cp_patches_h;
 769   if (cp_patches_jh != NULL) {
 770     oop p = JNIHandles::resolve_non_null(cp_patches_jh);
 771     assert(p->is_objArray(), "cp_patches must be an object[]");
 772     cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p);
 773   }
 774 
 775   const Klass* host_klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(host_class));
 776 
 777   // Make sure it's the real host class, not another anonymous class.
 778   while (host_klass != NULL && host_klass->is_instance_klass() &&
 779          InstanceKlass::cast(host_klass)->is_anonymous()) {
 780     host_klass = InstanceKlass::cast(host_klass)->host_klass();
 781   }
 782 
 783   // Primitive types have NULL Klass* fields in their java.lang.Class instances.
 784   if (host_klass == NULL) {
 785     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Host class is null");
 786   }




 745   assert(host_class != NULL, "host_class must not be NULL");
 746   assert(data != NULL, "data must not be NULL");
 747 
 748   if (UsePerfData) {
 749     ClassLoader::unsafe_defineClassCallCounter()->inc();
 750   }
 751 
 752   jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length();
 753   assert(length >= 0, "class_bytes_length must not be negative: %d", length);
 754 
 755   int class_bytes_length = (int) length;
 756 
 757   u1* class_bytes = NEW_C_HEAP_ARRAY(u1, length, mtInternal);
 758   if (class_bytes == NULL) {
 759     THROW_0(vmSymbols::java_lang_OutOfMemoryError());
 760   }
 761 
 762   // caller responsible to free it:
 763   *temp_alloc = class_bytes;
 764 
 765   HeapAccess<>::arraycopy<jbyte>(arrayOop(JNIHandles::resolve_non_null(data)), typeArrayOopDesc::element_offset<jbyte>(0), NULL,
 766                                  NULL, 0, reinterpret_cast<jbyte*>(class_bytes), length);
 767 
 768   objArrayHandle cp_patches_h;
 769   if (cp_patches_jh != NULL) {
 770     oop p = JNIHandles::resolve_non_null(cp_patches_jh);
 771     assert(p->is_objArray(), "cp_patches must be an object[]");
 772     cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p);
 773   }
 774 
 775   const Klass* host_klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(host_class));
 776 
 777   // Make sure it's the real host class, not another anonymous class.
 778   while (host_klass != NULL && host_klass->is_instance_klass() &&
 779          InstanceKlass::cast(host_klass)->is_anonymous()) {
 780     host_klass = InstanceKlass::cast(host_klass)->host_klass();
 781   }
 782 
 783   // Primitive types have NULL Klass* fields in their java.lang.Class instances.
 784   if (host_klass == NULL) {
 785     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Host class is null");
 786   }


< prev index next >