< prev index next >

src/hotspot/share/memory/oopFactory.cpp

Print this page




  67 // int or long depending on pointer size.  Only stack trace elements in Throwable use
  68 // this.  They cast Symbol* into this type.
  69 typeArrayOop oopFactory::new_symbolArray(int length, TRAPS) {
  70   BasicType type = LP64_ONLY(T_LONG) NOT_LP64(T_INT);
  71   Klass* type_asKlassOop = Universe::typeArrayKlassObj(type);
  72   TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop);
  73   typeArrayOop result = type_asArrayKlass->allocate(length, THREAD);
  74   return result;
  75 }
  76 
  77 typeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS) {
  78   Klass* type_asKlassOop = Universe::typeArrayKlassObj(type);
  79   TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop);
  80   typeArrayOop result = type_asArrayKlass->allocate_common(length, false, THREAD);
  81   return result;
  82 }
  83 
  84 
  85 objArrayOop oopFactory::new_objArray(Klass* klass, int length, TRAPS) {
  86   assert(klass->is_klass(), "must be instance class");
  87   assert(!klass->is_value() || (!ValueKlass::cast(klass)->flatten_array()),
  88            "Did not expect flatten array of value klass");
  89   if (klass->is_array_klass()) {
  90     return ArrayKlass::cast(klass)->allocate_arrayArray(1, length, THREAD);
  91   } else {
  92     return InstanceKlass::cast(klass)->allocate_objArray(1, length, THREAD);
  93   }
  94 }
  95 
  96 arrayOop oopFactory::new_valueArray(Klass* klass, int length, TRAPS) {
  97   assert(klass->is_value(), "Klass must be value type");
  98   Klass* array_klass = klass->array_klass(CHECK_NULL); // Flat value array or object array ?
  99   assert(array_klass->is_valueArray_klass() || array_klass->is_objArray_klass(),
 100          "Expect an array class here");
 101 

 102   if (array_klass->is_valueArray_klass()) {
 103     return (arrayOop) ValueArrayKlass::cast(array_klass)->allocate(length, THREAD);
 104   }
 105 
 106   ValueKlass* vklass = ValueKlass::cast(klass);
 107   objArrayOop array = oopFactory::new_objArray(klass, length, CHECK_NULL);
 108   if (length == 0) {
 109     return array;
 110   }
 111 
 112   // Populate default values...
 113   objArrayHandle array_h(THREAD, array);
 114   instanceOop value = (instanceOop)vklass->default_value();
 115   for (int i = 0; i < length; i++) {
 116     array_h->obj_at_put(i, value);
 117   }
 118   return array_h();
 119 }
 120 
 121 arrayOop oopFactory::new_array(Klass* klass, int length, TRAPS) {
 122   return (klass->is_value()) ? new_valueArray(klass, length, THREAD) :
 123       (arrayOop)new_objArray(klass, length, THREAD);
 124 }
 125 
 126 objArrayHandle oopFactory::new_objArray_handle(Klass* klass, int length, TRAPS) {
 127   objArrayOop obj = new_objArray(klass, length, CHECK_(objArrayHandle()));
 128   return objArrayHandle(THREAD, obj);
 129 }
 130 
 131 typeArrayHandle oopFactory::new_byteArray_handle(int length, TRAPS) {
 132   typeArrayOop obj = new_byteArray(length, CHECK_(typeArrayHandle()));
 133   return typeArrayHandle(THREAD, obj);
 134 }


  67 // int or long depending on pointer size.  Only stack trace elements in Throwable use
  68 // this.  They cast Symbol* into this type.
  69 typeArrayOop oopFactory::new_symbolArray(int length, TRAPS) {
  70   BasicType type = LP64_ONLY(T_LONG) NOT_LP64(T_INT);
  71   Klass* type_asKlassOop = Universe::typeArrayKlassObj(type);
  72   TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop);
  73   typeArrayOop result = type_asArrayKlass->allocate(length, THREAD);
  74   return result;
  75 }
  76 
  77 typeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS) {
  78   Klass* type_asKlassOop = Universe::typeArrayKlassObj(type);
  79   TypeArrayKlass* type_asArrayKlass = TypeArrayKlass::cast(type_asKlassOop);
  80   typeArrayOop result = type_asArrayKlass->allocate_common(length, false, THREAD);
  81   return result;
  82 }
  83 
  84 
  85 objArrayOop oopFactory::new_objArray(Klass* klass, int length, TRAPS) {
  86   assert(klass->is_klass(), "must be instance class");


  87   if (klass->is_array_klass()) {
  88     return ArrayKlass::cast(klass)->allocate_arrayArray(1, length, THREAD);
  89   } else {
  90     return InstanceKlass::cast(klass)->allocate_objArray(1, length, THREAD);
  91   }
  92 }
  93 
  94 arrayOop oopFactory::new_valueArray(Klass* klass, int length, TRAPS) {
  95   assert(klass->is_value(), "Klass must be value type");
  96   // Request flattened, but we might not actually get it...either way "null-free" are the aaload/aastore semantics
  97   Klass* array_klass = klass->array_klass(ArrayStorageProperties::flattened_and_null_free, 1, CHECK_NULL);
  98   assert(ArrayKlass::cast(array_klass)->storage_properties().is_null_free(), "Expect a null-free array class here");
  99 
 100   arrayOop oop;
 101   if (array_klass->is_valueArray_klass()) {
 102     oop = (arrayOop) ValueArrayKlass::cast(array_klass)->allocate(length, THREAD);
 103   } else {
 104     oop = (arrayOop) ObjArrayKlass::cast(array_klass)->allocate(length, THREAD);











 105   }
 106   assert(oop->array_storage_properties().is_null_free(), "Bad array storage encoding");
 107   return oop;




 108 }
 109 
 110 objArrayHandle oopFactory::new_objArray_handle(Klass* klass, int length, TRAPS) {
 111   objArrayOop obj = new_objArray(klass, length, CHECK_(objArrayHandle()));
 112   return objArrayHandle(THREAD, obj);
 113 }
 114 
 115 typeArrayHandle oopFactory::new_byteArray_handle(int length, TRAPS) {
 116   typeArrayOop obj = new_byteArray(length, CHECK_(typeArrayHandle()));
 117   return typeArrayHandle(THREAD, obj);
 118 }
< prev index next >