Skip to content

Commit

Permalink
8254878: Move last piece of ZArray to GrowableArray
Browse files Browse the repository at this point in the history
Reviewed-by: stefank, eosterlund
  • Loading branch information
pliden committed Oct 20, 2020
1 parent 294e070 commit cdc8c40
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 27 deletions.
9 changes: 1 addition & 8 deletions src/hotspot/share/gc/z/zArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@
#define SHARE_GC_Z_ZARRAY_HPP

#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/growableArray.hpp"

template <typename T>
class ZArray : public GrowableArrayCHeap<T, mtGC> {
public:
ZArray();

void transfer(ZArray<T>* from);
};
template <typename T> using ZArray = GrowableArrayCHeap<T, mtGC>;

template <typename T, bool parallel>
class ZArrayIteratorImpl : public StackObj {
Expand Down
16 changes: 0 additions & 16 deletions src/hotspot/share/gc/z/zArray.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,8 @@
#define SHARE_GC_Z_ZARRAY_INLINE_HPP

#include "gc/z/zArray.hpp"
#include "memory/allocation.inline.hpp"
#include "runtime/atomic.hpp"

template <typename T>
inline ZArray<T>::ZArray() :
GrowableArrayCHeap<T, mtGC>(0) {}

template <typename T>
inline void ZArray<T>::transfer(ZArray<T>* from) {
assert(this->_data == NULL, "Should be empty");
this->_data = from->_data;
this->_len = from->_len;
this->_max = from->_max;
from->_data = NULL;
from->_len = 0;
from->_max = 0;
}

template <typename T, bool parallel>
inline ZArrayIteratorImpl<T, parallel>::ZArrayIteratorImpl(ZArray<T>* array) :
_array(array),
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/z/zSafeDelete.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ZSafeDeleteImpl<T>::disable_deferred_delete() {
ZLocker<ZLock> locker(_lock);
assert(_enabled > 0, "Invalid state");
if (--_enabled == 0) {
deferred.transfer(&_deferred);
deferred.swap(&_deferred);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/share/utilities/growableArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
return this->at(location);
}

void swap(GrowableArrayWithAllocator<E, Derived>* other) {
::swap(this->_data, other->_data);
::swap(this->_len, other->_len);
::swap(this->_max, other->_max);
}

void clear_and_deallocate();
};

Expand Down Expand Up @@ -687,7 +693,7 @@ class GrowableArrayCHeap : public GrowableArrayWithAllocator<E, GrowableArrayCHe
}

public:
GrowableArrayCHeap(int initial_max) :
GrowableArrayCHeap(int initial_max = 0) :
GrowableArrayWithAllocator<E, GrowableArrayCHeap<E, F> >(
allocate(initial_max, F),
initial_max) {}
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/gtest/gc/z/test_zArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST(ZArray, sanity) {

ZArray<int> b;

b.transfer(&a);
b.swap(&a);

// Check size
ASSERT_EQ(a.length(), 0);
Expand Down

1 comment on commit cdc8c40

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on cdc8c40 Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.