< prev index next >

src/hotspot/share/oops/typeArrayKlass.cpp

Print this page

 78 TypeArrayKlass::TypeArrayKlass(BasicType type, Symbol* name) : ArrayKlass(name, ID) {
 79   set_layout_helper(array_layout_helper(type));
 80   assert(is_array_klass(), "sanity");
 81   assert(is_typeArray_klass(), "sanity");
 82 
 83   set_max_length(arrayOopDesc::max_array_length(type));
 84   assert(size() >= TypeArrayKlass::header_size(), "bad size");
 85 
 86   set_class_loader_data(ClassLoaderData::the_null_class_loader_data());
 87 }
 88 
 89 typeArrayOop TypeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
 90   assert(log2_element_size() >= 0, "bad scale");
 91   check_array_allocation_length(length, max_length(), CHECK_NULL);
 92   size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
 93   return (typeArrayOop)Universe::heap()->array_allocate(this, (int)size, length,
 94                                                         do_zero, CHECK_NULL);
 95 }
 96 
 97 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
 98   // For typeArrays this is only called for the last dimension
 99   assert(rank == 1, "just checking");
100   int length = *last_size;
101   return allocate(length, THREAD);
102 }
103 
104 
105 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
106   assert(s->is_typeArray(), "must be type array");
107 
108   // Check destination type.
109   if (!d->is_typeArray()) {
110     ResourceMark rm(THREAD);
111     stringStream ss;
112     if (d->is_objArray()) {
113       ss.print("arraycopy: type mismatch: can not copy %s[] into object array[]",
114                type2name_tab[ArrayKlass::cast(s->klass())->element_type()]);
115     } else {
116       ss.print("arraycopy: destination type %s is not an array", d->klass()->external_name());
117     }
118     THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());

171 }
172 
173 // create a klass of array holding typeArrays
174 Klass* TypeArrayKlass::array_klass(int n, TRAPS) {
175   int dim = dimension();
176   assert(dim <= n, "check order of chain");
177     if (dim == n)
178       return this;
179 
180   // lock-free read needs acquire semantics
181   if (higher_dimension_acquire() == NULL) {
182 
183     ResourceMark rm;
184     JavaThread *jt = THREAD;
185     {
186       // Atomic create higher dimension and link into list
187       MutexLocker mu(THREAD, MultiArray_lock);
188 
189       if (higher_dimension() == NULL) {
190         Klass* oak = ObjArrayKlass::allocate_objArray_klass(
191               class_loader_data(), dim + 1, this, CHECK_NULL);
192         ObjArrayKlass* h_ak = ObjArrayKlass::cast(oak);
193         h_ak->set_lower_dimension(this);
194         // use 'release' to pair with lock-free load
195         release_set_higher_dimension(h_ak);
196         assert(h_ak->is_objArray_klass(), "incorrect initialization of ObjArrayKlass");
197       }
198     }
199   }
200 
201   ObjArrayKlass* h_ak = ObjArrayKlass::cast(higher_dimension());
202   THREAD->check_possible_safepoint();
203   return h_ak->array_klass(n, THREAD);
204 }
205 
206 // return existing klass of array holding typeArrays
207 Klass* TypeArrayKlass::array_klass_or_null(int n) {
208   int dim = dimension();
209   assert(dim <= n, "check order of chain");
210     if (dim == n)
211       return this;

 78 TypeArrayKlass::TypeArrayKlass(BasicType type, Symbol* name) : ArrayKlass(name, ID) {
 79   set_layout_helper(array_layout_helper(type));
 80   assert(is_array_klass(), "sanity");
 81   assert(is_typeArray_klass(), "sanity");
 82 
 83   set_max_length(arrayOopDesc::max_array_length(type));
 84   assert(size() >= TypeArrayKlass::header_size(), "bad size");
 85 
 86   set_class_loader_data(ClassLoaderData::the_null_class_loader_data());
 87 }
 88 
 89 typeArrayOop TypeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
 90   assert(log2_element_size() >= 0, "bad scale");
 91   check_array_allocation_length(length, max_length(), CHECK_NULL);
 92   size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
 93   return (typeArrayOop)Universe::heap()->array_allocate(this, (int)size, length,
 94                                                         do_zero, CHECK_NULL);
 95 }
 96 
 97 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {

 98   assert(rank == 1, "just checking");
 99   int length = *last_size;
100   return allocate(length, THREAD);
101 }
102 
103 
104 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
105   assert(s->is_typeArray(), "must be type array");
106 
107   // Check destination type.
108   if (!d->is_typeArray()) {
109     ResourceMark rm(THREAD);
110     stringStream ss;
111     if (d->is_objArray()) {
112       ss.print("arraycopy: type mismatch: can not copy %s[] into object array[]",
113                type2name_tab[ArrayKlass::cast(s->klass())->element_type()]);
114     } else {
115       ss.print("arraycopy: destination type %s is not an array", d->klass()->external_name());
116     }
117     THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());

170 }
171 
172 // create a klass of array holding typeArrays
173 Klass* TypeArrayKlass::array_klass(int n, TRAPS) {
174   int dim = dimension();
175   assert(dim <= n, "check order of chain");
176     if (dim == n)
177       return this;
178 
179   // lock-free read needs acquire semantics
180   if (higher_dimension_acquire() == NULL) {
181 
182     ResourceMark rm;
183     JavaThread *jt = THREAD;
184     {
185       // Atomic create higher dimension and link into list
186       MutexLocker mu(THREAD, MultiArray_lock);
187 
188       if (higher_dimension() == NULL) {
189         Klass* oak = ObjArrayKlass::allocate_objArray_klass(
190               class_loader_data(), dim + 1, this, false, false, CHECK_NULL);
191         ObjArrayKlass* h_ak = ObjArrayKlass::cast(oak);
192         h_ak->set_lower_dimension(this);
193         // use 'release' to pair with lock-free load
194         release_set_higher_dimension(h_ak);
195         assert(h_ak->is_objArray_klass(), "incorrect initialization of ObjArrayKlass");
196       }
197     }
198   }
199 
200   ObjArrayKlass* h_ak = ObjArrayKlass::cast(higher_dimension());
201   THREAD->check_possible_safepoint();
202   return h_ak->array_klass(n, THREAD);
203 }
204 
205 // return existing klass of array holding typeArrays
206 Klass* TypeArrayKlass::array_klass_or_null(int n) {
207   int dim = dimension();
208   assert(dim <= n, "check order of chain");
209     if (dim == n)
210       return this;
< prev index next >