Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/array.cpp
32285 views
/*1* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "memory/resourceArea.hpp"26#include "runtime/thread.inline.hpp"27#include "utilities/array.hpp"282930#ifdef ASSERT31void ResourceArray::init_nesting() {32_nesting = Thread::current()->resource_area()->nesting();33}34#endif353637void ResourceArray::sort(size_t esize, ftype f) {38if (!is_empty()) qsort(_data, length(), esize, f);39}40template <MEMFLAGS F> void CHeapArray<F>::sort(size_t esize, ftype f) {41if (!is_empty()) qsort(_data, length(), esize, f);42}434445void ResourceArray::expand(size_t esize, int i, int& size) {46// make sure we are expanding within the original resource mark47assert(48_nesting == Thread::current()->resource_area()->nesting(),49"allocating outside original resource mark"50);51// determine new size52if (size == 0) size = 4; // prevent endless loop53while (i >= size) size *= 2;54// allocate and initialize new data section55void* data = resource_allocate_bytes(esize * size);56memcpy(data, _data, esize * length());57_data = data;58}596061template <MEMFLAGS F> void CHeapArray<F>::expand(size_t esize, int i, int& size) {62// determine new size63if (size == 0) size = 4; // prevent endless loop64while (i >= size) size *= 2;65// allocate and initialize new data section66void* data = NEW_C_HEAP_ARRAY(char*, esize * size, F);67memcpy(data, _data, esize * length());68FREE_C_HEAP_ARRAY(char*, _data, F);69_data = data;70}717273void ResourceArray::remove_at(size_t esize, int i) {74assert(0 <= i && i < length(), "index out of bounds");75_length--;76void* dst = (char*)_data + i*esize;77void* src = (char*)dst + esize;78size_t cnt = (length() - i)*esize;79memmove(dst, src, cnt);80}8182template <MEMFLAGS F> void CHeapArray<F>::remove_at(size_t esize, int i) {83assert(0 <= i && i < length(), "index out of bounds");84_length--;85void* dst = (char*)_data + i*esize;86void* src = (char*)dst + esize;87size_t cnt = (length() - i)*esize;88memmove(dst, src, cnt);89}909192