Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/growableArray.cpp
32285 views
/*1* Copyright (c) 1997, 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/growableArray.hpp"2829#ifdef ASSERT30void GenericGrowableArray::set_nesting() {31if (on_stack()) {32_nesting = Thread::current()->resource_area()->nesting();33}34}3536void GenericGrowableArray::check_nesting() {37// Check for insidious allocation bug: if a GrowableArray overflows, the38// grown array must be allocated under the same ResourceMark as the original.39// Otherwise, the _data array will be deallocated too early.40if (on_stack() &&41_nesting != Thread::current()->resource_area()->nesting()) {42fatal("allocation bug: GrowableArray could grow within nested ResourceMark");43}44}45#endif4647void* GenericGrowableArray::raw_allocate(int elementSize) {48assert(_max >= 0, "integer overflow");49size_t byte_size = elementSize * (size_t) _max;50if (on_stack()) {51return (void*)resource_allocate_bytes(byte_size);52} else if (on_C_heap()) {53return (void*)AllocateHeap(byte_size, _memflags);54} else {55return _arena->Amalloc(byte_size);56}57}585960