/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "memory/allocation.hpp"
#include "memory/allocation.inline.hpp"
#include "utilities/globalDefinitions.hpp"
// A growable array.
/*************************************************************************/
/* */
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
/* */
/* Should you use GrowableArrays to contain handles you must be certain */
/* the the GrowableArray does not outlive the HandleMark that contains */
/* the handles. Since GrowableArrays are typically resource allocated */
/* the following is an example of INCORRECT CODE, */
/* */
/* ResourceMark rm; */
/* GrowableArray<Handle>* arr = new GrowableArray<Handle>(size); */
/* if (blah) { */
/* while (...) { */
/* HandleMark hm; */
/* ... */
/* Handle h(THREAD, some_oop); */
/* arr->append(h); */
/* } */
/* } */
/* if (arr->length() != 0 ) { */
/* oop bad_oop = arr->at(0)(); // Handle is BAD HERE. */
/* ... */
/* } */
/* */
/* If the GrowableArrays you are creating is C_Heap allocated then it */
/* hould not old handles since the handles could trivially try and */
/* outlive their HandleMark. In some situations you might need to do */
/* this and it would be legal but be very careful and see if you can do */
/* the code in some other manner. */
/* */
/*************************************************************************/
// To call default constructor the placement operator new() is used.
// It should be empty (it only returns the passed void* pointer).
// The definition of placement operator new(size_t, void*) in the <new>.
#include <new>
// Need the correct linkage to call qsort without warnings
extern "C" {
typedef int (*_sort_Fn)(const void *, const void *);
}
friend class VMStructs;
protected:
// 0 means default ResourceArea
// 1 means on C heap
// otherwise, allocate in _arena
#ifdef ASSERT
void set_nesting();
void check_nesting();
#else
#define set_nesting();
#define check_nesting();
#endif
// Where are we going to allocate memory?
// This GA will use the resource stack for storage if c_heap==false,
// Else it will use the C heap. Use clear_and_deallocate to avoid leaks.
_len = initial_len;
_max = initial_size;
// memory type has to be specified for C heap allocation
set_nesting();
(allocated_on_res_area() || allocated_on_stack()),
"growable array must be on stack if elements are not on arena and not on C heap");
}
// This GA will use the given arena for storage.
// Consider using new(arena) GrowableArray<T> to allocate the header.
_len = initial_len;
_max = initial_size;
// Relax next assert to allow object allocation on resource area,
// on stack or embedded into an other object.
"growable array must be on arena or on stack if elements are on arena");
}
void* raw_allocate(int elementSize);
// some uses pass the Thread explicitly for speed (4990299 tuning)
}
};
friend class VMStructs;
private:
void grow(int j);
void raw_at_put_grow(int i, const E& p, const E& fill);
void clear_and_deallocate();
public:
}
_data = (E*)raw_allocate(sizeof(E));
}
GrowableArray(int initial_size, int initial_len, const E& filler, bool C_heap = false, MEMFLAGS memflags = mtInternal)
_data = (E*)raw_allocate(sizeof(E));
int i = 0;
}
GrowableArray(Arena* arena, int initial_size, int initial_len, const E& filler) : GenericGrowableArray(arena, initial_size, initial_len) {
_data = (E*)raw_allocate(sizeof(E));
int i = 0;
}
_data = (E*)raw_allocate(sizeof(E));
::new ((void*)&_data[0]) E();
::new ((void*)&_data[1]) E();
}
// Does nothing for resource and arena objects
void print();
return idx;
}
// Returns TRUE if elem is added.
return missed;
}
E at(int i) const {
return _data[i];
}
E* adr_at(int i) const {
return &_data[i];
}
E first() const {
return _data[0];
}
E top() const {
}
E pop() {
}
}
assert(0 <= i, "negative index");
if (i >= _len) {
for (int j = _len; j <= i; j++)
_len = i+1;
}
return _data[i];
}
assert(0 <= i, "negative index");
}
for (int i = 0; i < _len; i++) {
}
return false;
}
for (int i = 0; i < _len; i++) {
}
return -1;
}
for (int i = 0; i < _len; i++) {
}
return -1;
}
// start at the end of the array
for (int i = _len-1; i >= 0; i--) {
}
return -1;
}
for (int i = 0; i < _len; i++) {
_len--;
return;
}
}
}
// The order is preserved.
_len--;
}
// The order is changed.
// Replace removed element with last one.
}
}
// inserts the given element before the element at index i
}
_len++;
}
for (int i = 0; i < l->_len; i++) {
}
}
void sort(int f(E*,E*)) {
}
// sort by fixed-stride sub arrays:
}
};
// Global GrowableArray methods (one instance in the library per each 'E' type).
// grow the array by doubling its size (amortized growth)
// j < _max
int i = 0;
}
}
if (i >= _len) {
for (int j = _len; j < i; j++)
_len = i+1;
}
_data[i] = p;
}
// This function clears and deallocate the data in the growable array that
// has been allocated on the C heap. It's not public - called by the
// destructor.
"clear_and_deallocate should only be called when on C heap");
clear();
}
}
}
#endif // SHARE_VM_UTILITIES_GROWABLEARRAY_HPP