< prev index next >
src/share/vm/utilities/growableArray.hpp
Print this page
rev 10358 : imported patch c1_LIR
rev 10368 : imported patch minor fixes
rev 10374 : imported patch Avoid eager initialization for some types
*** 23,37 ****
--- 23,40 ----
*/
#ifndef SHARE_VM_UTILITIES_GROWABLEARRAY_HPP
#define SHARE_VM_UTILITIES_GROWABLEARRAY_HPP
+ #include <limits>
+
#include "memory/allocation.hpp"
#include "memory/allocation.inline.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/top.hpp"
+ #include "utilities/traits.hpp"
// A growable array.
/*************************************************************************/
/* */
*** 143,152 ****
--- 146,171 ----
// some uses pass the Thread explicitly for speed (4990299 tuning)
void* raw_allocate(Thread* thread, int elementSize) {
assert(on_stack(), "fast ResourceObj path only");
return (void*)resource_allocate_bytes(thread, elementSize * _max);
}
+
+ template<typename T1, typename T2 = T1> class Initializer {
+ STATIC_ASSERT((same_types<T1, T2>::value));
+ public:
+ static void init(T1* data, int from, int to) {
+ for (int i = from; i < to; i++) {
+ ::new((void*) &data[i]) T1();
+ }
+ }
+
+ static void deinit(T1* data, int from, int to) {
+ for (int i = from; i < to; i++) {
+ data[i].~T1();
+ }
+ }
+ };
};
template<class E> class GrowableArrayIterator;
template<class E, class UnaryPredicate> class GrowableArrayFilterIterator;
*** 157,201 ****
E* _data; // data array
void grow(int j);
void raw_at_put_grow(int i, const E& p, const E& fill);
void clear_and_deallocate();
public:
GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) {
_data = (E*)raw_allocate(thread, sizeof(E));
! for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
}
GrowableArray(int initial_size, bool C_heap = false, MEMFLAGS F = mtInternal)
: GenericGrowableArray(initial_size, 0, C_heap, F) {
_data = (E*)raw_allocate(sizeof(E));
// Needed for Visual Studio 2012 and older
#ifdef _MSC_VER
#pragma warning(suppress: 4345)
#endif
! for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
}
GrowableArray(int initial_size, int initial_len, const E& filler, bool C_heap = false, MEMFLAGS memflags = mtInternal)
: GenericGrowableArray(initial_size, initial_len, C_heap, memflags) {
_data = (E*)raw_allocate(sizeof(E));
int i = 0;
for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
! for (; i < _max; i++) ::new ((void*)&_data[i]) E();
}
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;
for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
! for (; i < _max; i++) ::new ((void*)&_data[i]) E();
}
GrowableArray() : GenericGrowableArray(2, 0, false) {
_data = (E*)raw_allocate(sizeof(E));
! ::new ((void*)&_data[0]) E();
! ::new ((void*)&_data[1]) E();
}
// Does nothing for resource and arena objects
~GrowableArray() { if (on_C_heap()) clear_and_deallocate(); }
--- 176,220 ----
E* _data; // data array
void grow(int j);
void raw_at_put_grow(int i, const E& p, const E& fill);
void clear_and_deallocate();
+
public:
GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) {
_data = (E*)raw_allocate(thread, sizeof(E));
! GenericGrowableArray::Initializer<E>::init(_data, 0, _max);
}
GrowableArray(int initial_size, bool C_heap = false, MEMFLAGS F = mtInternal)
: GenericGrowableArray(initial_size, 0, C_heap, F) {
_data = (E*)raw_allocate(sizeof(E));
// Needed for Visual Studio 2012 and older
#ifdef _MSC_VER
#pragma warning(suppress: 4345)
#endif
! GenericGrowableArray::Initializer<E>::init(_data, 0, _max);
}
GrowableArray(int initial_size, int initial_len, const E& filler, bool C_heap = false, MEMFLAGS memflags = mtInternal)
: GenericGrowableArray(initial_size, initial_len, C_heap, memflags) {
_data = (E*)raw_allocate(sizeof(E));
int i = 0;
for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
! GenericGrowableArray::Initializer<E>::init(_data, _len, _max);
}
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;
for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
! GenericGrowableArray::Initializer<E>::init(_data, _len, _max);
}
GrowableArray() : GenericGrowableArray(2, 0, false) {
_data = (E*)raw_allocate(sizeof(E));
! GenericGrowableArray::Initializer<E>::init(_data, 0, 2);
}
// Does nothing for resource and arena objects
~GrowableArray() { if (on_C_heap()) clear_and_deallocate(); }
*** 447,458 ****
for ( ; i < _len; i++) ::new ((void*)&newData[i]) E(_data[i]);
// Needed for Visual Studio 2012 and older
#ifdef _MSC_VER
#pragma warning(suppress: 4345)
#endif
! for ( ; i < _max; i++) ::new ((void*)&newData[i]) E();
! for (i = 0; i < old_max; i++) _data[i].~E();
if (on_C_heap() && _data != NULL) {
FreeHeap(_data);
}
_data = newData;
}
--- 466,477 ----
for ( ; i < _len; i++) ::new ((void*)&newData[i]) E(_data[i]);
// Needed for Visual Studio 2012 and older
#ifdef _MSC_VER
#pragma warning(suppress: 4345)
#endif
! GenericGrowableArray::Initializer<E>::init(newData, i, _max);
! GenericGrowableArray::Initializer<E>::deinit(_data, 0, old_max);
if (on_C_heap() && _data != NULL) {
FreeHeap(_data);
}
_data = newData;
}
*** 473,483 ****
template<class E> void GrowableArray<E>::clear_and_deallocate() {
assert(on_C_heap(),
"clear_and_deallocate should only be called when on C heap");
clear();
if (_data != NULL) {
! for (int i = 0; i < _max; i++) _data[i].~E();
FreeHeap(_data);
_data = NULL;
}
}
--- 492,502 ----
template<class E> void GrowableArray<E>::clear_and_deallocate() {
assert(on_C_heap(),
"clear_and_deallocate should only be called when on C heap");
clear();
if (_data != NULL) {
! GenericGrowableArray::Initializer<E>::deinit(_data, 0, _max);
FreeHeap(_data);
_data = NULL;
}
}
*** 565,570 ****
--- 584,599 ----
assert(_array == rhs._array, "iterator belongs to different array");
return _position != rhs._position;
}
};
+ template <typename T1>
+ class GenericGrowableArray::Initializer<T1,
+ typename enable_if<std::numeric_limits<T1>::is_integer
+ || is_floating_point<T1>::value
+ || is_pointer<T1>::value, T1>::type> {
+ public:
+ static void init(T1* data, int from, int to) {}
+ static void deinit(T1* data, int from, int to) {}
+ };
+
#endif // SHARE_VM_UTILITIES_GROWABLEARRAY_HPP
< prev index next >