void typeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
  assert(s->is_typeArray(), "must be type array");

  // Check destination
  if (!d->is_typeArray() || element_type() != typeArrayKlass::cast(d->klass())->element_type()) {
    THROW(vmSymbols::java_lang_ArrayStoreException());
  }

  // Check is all offsets and lengths are non negative
  if (src_pos < 0 || dst_pos < 0 || length < 0) {
    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
  }
  // Check if the ranges are valid
  if  ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
     || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
  }
  // Check zero copy
  if (length == 0)
    return;

  // This is an attempt to make the copy_array fast.
  int l2es = log2_element_size();
  int ihs = array_header_in_bytes() / wordSize;
  char* src = (char*) ((oop*)s + ihs) + ((size_t)src_pos << l2es);
  char* dst = (char*) ((oop*)d + ihs) + ((size_t)dst_pos << l2es);
  Copy::conjoint_memory_atomic(src, dst, (size_t)length << l2es);
}
typeArrayOop TypeArrayKlass::allocate(int length, HeapColor color, TRAPS) {
    assert(log2_element_size() >= 0, "bad scale");
    if (length >= 0) {
        if (length <= max_length()) {
            size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
            KlassHandle h_k(THREAD, this);
            typeArrayOop t;
            CollectedHeap* ch = Universe::heap();
            /*
            if (size < ch->large_typearray_limit()) {
            */
            t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length,
                    color, CHECK_NULL);
            /*
            } else {
              t = (typeArrayOop)CollectedHeap::large_typearray_allocate(h_k, (int)size,
                                               length, color, CHECK_NULL);
            }
            */
            //assert(t->is_parsable(), "Don't publish unless parsable");
            return t;
        } else {
            report_java_out_of_memory("Requested array size exceeds VM limit");
            THROW_OOP_0(Universe::out_of_memory_error_array_size());
        }
    } else {
        THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
    }
}
示例#3
0
void typeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
  assert(s->is_typeArray(), "must be type array");

  // Check destination
  if (!d->is_typeArray() || element_type() != typeArrayKlass::cast(d->klass())->element_type()) {
    THROW(vmSymbols::java_lang_ArrayStoreException());
  }

  // Check is all offsets and lengths are non negative
  if (src_pos < 0 || dst_pos < 0 || length < 0) {
    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
  }
  // Check if the ranges are valid
  if  ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
     || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
    THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
  }

  // This is an attempt to make the copy_array fast.
  // NB: memmove takes care of overlapping memory segments.
  // Potential problem: memmove is not guaranteed to be word atomic
  // Revisit in Merlin
  int l2es = log2_element_size();
  int ihs = array_header_in_bytes() / wordSize;
  char* src = (char*) ((oop*)s + ihs) + (src_pos << l2es);
  char* dst = (char*) ((oop*)d + ihs) + (dst_pos << l2es);
  memmove(dst, src, length << l2es);
}
void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
    assert(s->is_typeArray(), "must be type array");

    // Check destination
    if (!d->is_typeArray() || element_type() != TypeArrayKlass::cast(d->klass())->element_type()) {
        THROW(vmSymbols::java_lang_ArrayStoreException());
    }

    // Check is all offsets and lengths are non negative
    if (src_pos < 0 || dst_pos < 0 || length < 0) {
        THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
    }
    // Check if the ranges are valid
    if  ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
            || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
        THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
    }
    // Check zero copy
    if (length == 0)
        return;

#ifdef PROFILE_OBJECT_INFO
    if (ProfileObjectInfo) {
        ResourceMark rm;
        if (s->poi()) {
            s->poi()->batch_mark_load(length);
        }
        if (d->poi()) {
            d->poi()->batch_mark_store(length);
        }
    }
#endif
#ifdef PROFILE_OBJECT_ADDRESS_INFO
    if (ProfileObjectAddressInfo) {
        ObjectAddressInfoTable *oait = Universe::object_address_info_table();
        oait->batch_mark_load (s, length);
        oait->batch_mark_store(d, length);
    }
#endif

    // This is an attempt to make the copy_array fast.
    int l2es = log2_element_size();
    int ihs = array_header_in_bytes() / wordSize;
    char* src = (char*) ((oop*)s + ihs) + ((size_t)src_pos << l2es);
    char* dst = (char*) ((oop*)d + ihs) + ((size_t)dst_pos << l2es);
    Copy::conjoint_memory_atomic(src, dst, (size_t)length << l2es);
}
typeArrayOop TypeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
    assert(log2_element_size() >= 0, "bad scale");
    if (length >= 0) {
        if (length <= max_length()) {
            size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
            KlassHandle h_k(THREAD, this);
            typeArrayOop t;
            CollectedHeap* ch = Universe::heap();
            if (do_zero) {
                t = (typeArrayOop)CollectedHeap::array_allocate(h_k, (int)size, length, CHECK_NULL);
            } else {
                t = (typeArrayOop)CollectedHeap::array_allocate_nozero(h_k, (int)size, length, CHECK_NULL);
            }
            return t;
        } else {
            report_java_out_of_memory("Requested array size exceeds VM limit");
            JvmtiExport::post_array_size_exhausted();
            THROW_OOP_0(Universe::out_of_memory_error_array_size());
        }
    } else {
        THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
    }
}