< prev index next >

src/hotspot/share/oops/valueArrayKlass.cpp

Print this page




  82 }
  83 
  84 ValueArrayKlass* ValueArrayKlass::allocate_klass(Klass*  element_klass,
  85                                                  Symbol* name,
  86                                                  TRAPS) {
  87   assert(ValueArrayFlatten, "Flatten array required");
  88   assert(ValueKlass::cast(element_klass)->is_atomic() || (!ValueArrayAtomicAccess), "Atomic by-default");
  89 
  90   /*
  91    *  MVT->LWorld, now need to allocate secondaries array types, just like objArrayKlass...
  92    *  ...so now we are trying out covariant array types, just copy objArrayKlass
  93    *  TODO refactor any remaining commonality
  94    */
  95 
  96   // Eagerly allocate the direct array supertype.
  97   Klass* super_klass = NULL;
  98   if (!Universe::is_bootstrapping() || SystemDictionary::Object_klass_loaded()) {
  99     Klass* element_super = element_klass->super();
 100     if (element_super != NULL) {
 101       // The element type has a direct super.  E.g., String[] has direct super of Object[].
 102       super_klass = element_super->array_klass_or_null();
 103       bool supers_exist = super_klass != NULL;
 104       // Also, see if the element has secondary supertypes.
 105       // We need an array type for each.
 106       Array<Klass*>* element_supers = element_klass->secondary_supers();
 107       for( int i = element_supers->length()-1; i >= 0; i-- ) {
 108         Klass* elem_super = element_supers->at(i);
 109         if (elem_super->array_klass_or_null() == NULL) {
 110           supers_exist = false;
 111           break;
 112         }
 113       }
 114       if (!supers_exist) {
 115         // Oops.  Not allocated yet.  Back out, allocate it, and retry.
 116         Klass* ek = NULL;
 117         {
 118           MutexUnlocker mu(MultiArray_lock);
 119           super_klass = element_super->array_klass(CHECK_0);
 120           for( int i = element_supers->length()-1; i >= 0; i-- ) {
 121             Klass* elem_super = element_supers->at(i);
 122             elem_super->array_klass(CHECK_0);
 123           }
 124           // Now retry from the beginning
 125           ek = element_klass->array_klass(1, CHECK_0);
 126         }  // re-lock
 127         return ValueArrayKlass::cast(ek);
 128       }
 129     } else {
 130       ShouldNotReachHere(); // Value array klass cannot be the object array klass
 131     }
 132   }
 133 
 134 
 135   ClassLoaderData* loader_data = element_klass->class_loader_data();
 136   int size = ArrayKlass::static_size(ValueArrayKlass::header_size());
 137   ValueArrayKlass* vak = new (loader_data, size, THREAD) ValueArrayKlass(element_klass, name);
 138   if (vak == NULL) {
 139     return NULL;
 140   }
 141   loader_data->add_class(vak);
 142 
 143   ModuleEntry* module = vak->module();
 144   assert(module != NULL, "No module entry for array");
 145   complete_create_array_klass(vak, super_klass, module, CHECK_NULL);
 146   return vak;
 147 }
 148 
 149 ValueArrayKlass* ValueArrayKlass::allocate_klass(Klass* element_klass, TRAPS) {
 150   Symbol* name = ArrayKlass::create_element_klass_array_name(element_klass, CHECK_NULL);

 151   return allocate_klass(element_klass, name, THREAD);
 152 }
 153 
 154 void ValueArrayKlass::initialize(TRAPS) {
 155   element_klass()->initialize(THREAD);
 156 }
 157 
 158 // Oops allocation...
 159 valueArrayOop ValueArrayKlass::allocate(int length, TRAPS) {
 160   if (length < 0) {
 161     THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
 162   }
 163   if (length > max_elements()) {
 164     report_java_out_of_memory("Requested array size exceeds VM limit");
 165     JvmtiExport::post_array_size_exhausted();
 166     THROW_OOP_0(Universe::out_of_memory_error_array_size());
 167   }
 168 
 169   int size = valueArrayOopDesc::object_size(layout_helper(), length);
 170   return (valueArrayOop) Universe::heap()->array_allocate(this, size, length, true, THREAD);


 304      int src_end = src_pos + length;
 305      int delem_incr = 1 << dk->log2_element_size();
 306      address dst = (address) da->value_at_addr(dst_pos, layout_helper());
 307      while (src_pos < src_end) {
 308        oop se = sa->obj_at(src_pos);
 309        if (se == NULL) {
 310          THROW(vmSymbols::java_lang_NullPointerException());
 311        }
 312        // Check exact type per element
 313        if (se->klass() != d_elem_klass) {
 314          THROW(vmSymbols::java_lang_ArrayStoreException());
 315        }
 316        d_elem_vklass->value_store(d_elem_vklass->data_for_oop(se), dst, true, false);
 317        dst += delem_incr;
 318        src_pos++;
 319      }
 320    }
 321 }
 322 
 323 
 324 Klass* ValueArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
 325 
 326   assert(dimension() <= n, "check order of chain");
 327   int dim = dimension();
 328   if (dim == n) return this;
 329 
 330   if (higher_dimension() == NULL) {
 331     if (or_null)  return NULL;
 332 
 333     ResourceMark rm;
 334     JavaThread *jt = (JavaThread *)THREAD;
 335     {
 336       // Ensure atomic creation of higher dimensions
 337       MutexLocker mu(MultiArray_lock, THREAD);
 338 
 339       // Check if another thread beat us
 340       if (higher_dimension() == NULL) {
 341 
 342         // Create multi-dim klass object and link them together
 343         Klass* k =
 344           ObjArrayKlass::allocate_objArray_klass(class_loader_data(), dim + 1, this, CHECK_NULL);
 345         ObjArrayKlass* ak = ObjArrayKlass::cast(k);
 346         ak->set_lower_dimension(this);
 347         OrderAccess::storestore();
 348         set_higher_dimension(ak);
 349         assert(ak->is_objArray_klass(), "incorrect initialization of ObjArrayKlass");
 350       }
 351     }
 352   } else {
 353     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 354   }
 355 
 356   ObjArrayKlass *ak = ObjArrayKlass::cast(higher_dimension());
 357   if (or_null) {
 358     return ak->array_klass_or_null(n);
 359   }
 360   return ak->array_klass(n, THREAD);
 361 }
 362 
 363 Klass* ValueArrayKlass::array_klass_impl(bool or_null, TRAPS) {
 364   return array_klass_impl(or_null, dimension() +  1, THREAD);
 365 }
 366 
 367 ModuleEntry* ValueArrayKlass::module() const {
 368   assert(element_klass() != NULL, "ValueArrayKlass returned unexpected NULL bottom_klass");
 369   // The array is defined in the module of its bottom class
 370   return element_klass()->module();
 371 }
 372 
 373 PackageEntry* ValueArrayKlass::package() const {
 374   assert(element_klass() != NULL, "ValuerrayKlass returned unexpected NULL bottom_klass");
 375   return element_klass()->package();
 376 }
 377 
 378 bool ValueArrayKlass::can_be_primary_super_slow() const {
 379     return true;
 380 }
 381 
 382 GrowableArray<Klass*>* ValueArrayKlass::compute_secondary_supers(int num_extra_slots,
 383                                                                  Array<InstanceKlass*>* transitive_interfaces) {
 384   assert(transitive_interfaces == NULL, "sanity");
 385   // interfaces = { cloneable_klass, serializable_klass, elemSuper[], ... };
 386   Array<Klass*>* elem_supers = element_klass()->secondary_supers();
 387   int num_elem_supers = elem_supers == NULL ? 0 : elem_supers->length();
 388   int num_secondaries = num_extra_slots + 2 + num_elem_supers;
 389   if (num_secondaries == 2) {
 390     // Must share this for correct bootstrapping!
 391     set_secondary_supers(Universe::the_array_interfaces_array());
 392     return NULL;
 393   } else {
 394     GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(num_elem_supers+2);
 395     secondaries->push(SystemDictionary::Cloneable_klass());
 396     secondaries->push(SystemDictionary::Serializable_klass());
 397     for (int i = 0; i < num_elem_supers; i++) {
 398       Klass* elem_super = (Klass*) elem_supers->at(i);
 399       Klass* array_super = elem_super->array_klass_or_null();
 400       assert(array_super != NULL, "must already have been created");
 401       secondaries->push(array_super);
 402     }
 403     return secondaries;
 404   }
 405 }
 406 
 407 void ValueArrayKlass::print_on(outputStream* st) const {
 408 #ifndef PRODUCT
 409   assert(!is_objArray_klass(), "Unimplemented");
 410 
 411   st->print("Value Type Array: ");
 412   Klass::print_on(st);
 413 
 414   st->print(" - element klass: ");
 415   element_klass()->print_value_on(st);
 416   st->cr();
 417 
 418   int elem_size = element_byte_size();
 419   st->print(" - element size %i ", elem_size);




  82 }
  83 
  84 ValueArrayKlass* ValueArrayKlass::allocate_klass(Klass*  element_klass,
  85                                                  Symbol* name,
  86                                                  TRAPS) {
  87   assert(ValueArrayFlatten, "Flatten array required");
  88   assert(ValueKlass::cast(element_klass)->is_atomic() || (!ValueArrayAtomicAccess), "Atomic by-default");
  89 
  90   /*
  91    *  MVT->LWorld, now need to allocate secondaries array types, just like objArrayKlass...
  92    *  ...so now we are trying out covariant array types, just copy objArrayKlass
  93    *  TODO refactor any remaining commonality
  94    */
  95 
  96   // Eagerly allocate the direct array supertype.
  97   Klass* super_klass = NULL;
  98   if (!Universe::is_bootstrapping() || SystemDictionary::Object_klass_loaded()) {
  99     Klass* element_super = element_klass->super();
 100     if (element_super != NULL) {
 101       // The element type has a direct super.  E.g., String[] has direct super of Object[].
 102       super_klass = element_super->array_klass_or_null(ArrayStorageProperties::empty);
 103       bool supers_exist = super_klass != NULL;
 104       // Also, see if the element has secondary supertypes.
 105       // We need an array type for each.
 106       Array<Klass*>* element_supers = element_klass->secondary_supers();
 107       for( int i = element_supers->length()-1; i >= 0; i-- ) {
 108         Klass* elem_super = element_supers->at(i);
 109         if (elem_super->array_klass_or_null(ArrayStorageProperties::empty) == NULL) {
 110           supers_exist = false;
 111           break;
 112         }
 113       }
 114       if (!supers_exist) {
 115         // Oops.  Not allocated yet.  Back out, allocate it, and retry.
 116         Klass* ek = NULL;
 117         {
 118           MutexUnlocker mu(MultiArray_lock);
 119           super_klass = element_super->array_klass(CHECK_0);
 120           for( int i = element_supers->length()-1; i >= 0; i-- ) {
 121             Klass* elem_super = element_supers->at(i);
 122             elem_super->array_klass(CHECK_0);
 123           }
 124           // Now retry from the beginning
 125           ek = element_klass->array_klass(ArrayStorageProperties::flattened_and_null_free, 1, CHECK_0);
 126         }  // re-lock
 127         return ValueArrayKlass::cast(ek);
 128       }
 129     } else {
 130       ShouldNotReachHere(); // Value array klass cannot be the object array klass
 131     }
 132   }
 133 
 134 
 135   ClassLoaderData* loader_data = element_klass->class_loader_data();
 136   int size = ArrayKlass::static_size(ValueArrayKlass::header_size());
 137   ValueArrayKlass* vak = new (loader_data, size, THREAD) ValueArrayKlass(element_klass, name);
 138   if (vak == NULL) {
 139     return NULL;
 140   }
 141   loader_data->add_class(vak);
 142 
 143   ModuleEntry* module = vak->module();
 144   assert(module != NULL, "No module entry for array");
 145   complete_create_array_klass(vak, super_klass, module, CHECK_NULL);
 146   return vak;
 147 }
 148 
 149 ValueArrayKlass* ValueArrayKlass::allocate_klass(ArrayStorageProperties storage_props, Klass* element_klass, TRAPS) {
 150   assert(storage_props.is_flattened(), "Expected flat storage");
 151   Symbol* name = ArrayKlass::create_element_klass_array_name(true, element_klass, CHECK_NULL);
 152   return allocate_klass(element_klass, name, THREAD);
 153 }
 154 
 155 void ValueArrayKlass::initialize(TRAPS) {
 156   element_klass()->initialize(THREAD);
 157 }
 158 
 159 // Oops allocation...
 160 valueArrayOop ValueArrayKlass::allocate(int length, TRAPS) {
 161   if (length < 0) {
 162     THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
 163   }
 164   if (length > max_elements()) {
 165     report_java_out_of_memory("Requested array size exceeds VM limit");
 166     JvmtiExport::post_array_size_exhausted();
 167     THROW_OOP_0(Universe::out_of_memory_error_array_size());
 168   }
 169 
 170   int size = valueArrayOopDesc::object_size(layout_helper(), length);
 171   return (valueArrayOop) Universe::heap()->array_allocate(this, size, length, true, THREAD);


 305      int src_end = src_pos + length;
 306      int delem_incr = 1 << dk->log2_element_size();
 307      address dst = (address) da->value_at_addr(dst_pos, layout_helper());
 308      while (src_pos < src_end) {
 309        oop se = sa->obj_at(src_pos);
 310        if (se == NULL) {
 311          THROW(vmSymbols::java_lang_NullPointerException());
 312        }
 313        // Check exact type per element
 314        if (se->klass() != d_elem_klass) {
 315          THROW(vmSymbols::java_lang_ArrayStoreException());
 316        }
 317        d_elem_vklass->value_store(d_elem_vklass->data_for_oop(se), dst, true, false);
 318        dst += delem_incr;
 319        src_pos++;
 320      }
 321    }
 322 }
 323 
 324 
 325 Klass* ValueArrayKlass::array_klass_impl(ArrayStorageProperties storage_props, bool or_null, int n, TRAPS) {
 326   assert(storage_props.is_flattened() || n > 1, "Expected flat storage");
 327   assert(dimension() <= n, "check order of chain");
 328   int dim = dimension();
 329   if (dim == n) return this;
 330 
 331   if (higher_dimension() == NULL) {
 332     if (or_null)  return NULL;
 333 
 334     ResourceMark rm;
 335     JavaThread *jt = (JavaThread *)THREAD;
 336     {
 337       // Ensure atomic creation of higher dimensions
 338       MutexLocker mu(MultiArray_lock, THREAD);
 339 
 340       // Check if another thread beat us
 341       if (higher_dimension() == NULL) {
 342 
 343         // Create multi-dim klass object and link them together
 344         Klass* k =
 345           ObjArrayKlass::allocate_objArray_klass(storage_props, dim + 1, this, CHECK_NULL);
 346         ObjArrayKlass* ak = ObjArrayKlass::cast(k);
 347         ak->set_lower_dimension(this);
 348         OrderAccess::storestore();
 349         set_higher_dimension(ak);
 350         assert(ak->is_objArray_klass(), "incorrect initialization of ObjArrayKlass");
 351       }
 352     }
 353   } else {
 354     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
 355   }
 356 
 357   ObjArrayKlass *ak = ObjArrayKlass::cast(higher_dimension());
 358   if (or_null) {
 359     return ak->array_klass_or_null(storage_props, n);
 360   }
 361   return ak->array_klass(storage_props, n, THREAD);
 362 }
 363 
 364 Klass* ValueArrayKlass::array_klass_impl(ArrayStorageProperties storage_props, bool or_null, TRAPS) {
 365   return array_klass_impl(storage_props, or_null, dimension() +  1, THREAD);
 366 }
 367 
 368 ModuleEntry* ValueArrayKlass::module() const {
 369   assert(element_klass() != NULL, "ValueArrayKlass returned unexpected NULL bottom_klass");
 370   // The array is defined in the module of its bottom class
 371   return element_klass()->module();
 372 }
 373 
 374 PackageEntry* ValueArrayKlass::package() const {
 375   assert(element_klass() != NULL, "ValuerrayKlass returned unexpected NULL bottom_klass");
 376   return element_klass()->package();
 377 }
 378 
 379 bool ValueArrayKlass::can_be_primary_super_slow() const {
 380     return true;
 381 }
 382 
 383 GrowableArray<Klass*>* ValueArrayKlass::compute_secondary_supers(int num_extra_slots,
 384                                                                  Array<InstanceKlass*>* transitive_interfaces) {
 385   assert(transitive_interfaces == NULL, "sanity");
 386   // interfaces = { cloneable_klass, serializable_klass, elemSuper[], ... };
 387   Array<Klass*>* elem_supers = element_klass()->secondary_supers();
 388   int num_elem_supers = elem_supers == NULL ? 0 : elem_supers->length();
 389   int num_secondaries = num_extra_slots + 2 + num_elem_supers;
 390   if (num_secondaries == 2) {
 391     // Must share this for correct bootstrapping!
 392     set_secondary_supers(Universe::the_array_interfaces_array());
 393     return NULL;
 394   } else {
 395     GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(num_elem_supers+2);
 396     secondaries->push(SystemDictionary::Cloneable_klass());
 397     secondaries->push(SystemDictionary::Serializable_klass());
 398     for (int i = 0; i < num_elem_supers; i++) {
 399       Klass* elem_super = (Klass*) elem_supers->at(i);
 400       Klass* array_super = elem_super->array_klass_or_null(ArrayStorageProperties::empty);
 401       assert(array_super != NULL, "must already have been created");
 402       secondaries->push(array_super);
 403     }
 404     return secondaries;
 405   }
 406 }
 407 
 408 void ValueArrayKlass::print_on(outputStream* st) const {
 409 #ifndef PRODUCT
 410   assert(!is_objArray_klass(), "Unimplemented");
 411 
 412   st->print("Value Type Array: ");
 413   Klass::print_on(st);
 414 
 415   st->print(" - element klass: ");
 416   element_klass()->print_value_on(st);
 417   st->cr();
 418 
 419   int elem_size = element_byte_size();
 420   st->print(" - element size %i ", elem_size);


< prev index next >