Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Virtual Threads: performance impact with Helidon integration #2175

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.ListIterator;
import java.util.Spliterator;
import java.util.Vector;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
Expand Down Expand Up @@ -98,6 +100,8 @@ public class IndirectList<E> extends Vector<E> implements CollectionChangeTracke
*/
private boolean useLazyInstantiation = true;

private final Lock instanceLock = new ReentrantLock();

/**
* PUBLIC:
* Construct an empty IndirectList so that its internal data array
Expand Down Expand Up @@ -350,13 +354,18 @@ public void clearDeferredChanges(){
before merging collections (again, "un-instantiated" collections are not merged).
*/
@Override
public synchronized Object clone() {
IndirectList<E> result = (IndirectList<E>)super.clone();
result.delegate = (Vector<E>)this.getDelegate().clone();
result.valueHolder = new ValueHolder<>(result.delegate);
result.attributeName = null;
result.changeListener = null;
return result;
public Object clone() {
instanceLock.lock();
try {
IndirectList<E> result = (IndirectList<E>)super.clone();
result.delegate = (Vector<E>)this.getDelegate().clone();
result.valueHolder = new ValueHolder<>(result.delegate);
result.attributeName = null;
result.changeListener = null;
return result;
} finally {
instanceLock.unlock();
}
}

/**
Expand Down Expand Up @@ -391,8 +400,13 @@ public boolean containsAll(Collection<?> c) {
* @see java.util.Vector#copyInto(java.lang.Object[])
*/
@Override
public synchronized void copyInto(Object[] anArray) {
getDelegate().copyInto(anArray);
public void copyInto(Object[] anArray) {
instanceLock.lock();
try {
getDelegate().copyInto(anArray);
} finally {
instanceLock.unlock();
}
}

/**
Expand Down Expand Up @@ -452,11 +466,14 @@ public E get(int index) {
protected Vector<E> getDelegate() {
Vector<E> v = this.delegate;
if (v == null) {
synchronized(this){
instanceLock.lock();
try {
v = this.delegate;
if (v == null) {
this.delegate = v = this.buildDelegate();
}
} finally {
instanceLock.unlock();
}
}
return v;
Expand All @@ -482,11 +499,14 @@ public ValueHolderInterface<List<E>> getValueHolder() {
ValueHolderInterface<List<E>> vh = this.valueHolder;
// PERF: lazy initialize value holder and vector as are normally set after creation.
if (vh == null) {
synchronized(this) {
instanceLock.lock();
try {
vh = this.valueHolder;
if (vh == null) {
this.valueHolder = vh = new ValueHolder<>(new Vector<>(this.initialCapacity, this.capacityIncrement));
}
} finally {
instanceLock.unlock();
}
}
return vh;
Expand Down Expand Up @@ -877,33 +897,43 @@ public Spliterator<E> spliterator() {
}

@Override
public synchronized void replaceAll(UnaryOperator<E> operator) {
// Must trigger remove/add events if tracked or uow.
if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
List<E> del = getDelegate();
for (int i = 0; i < del.size(); i++) {
set(i, operator.apply(del.get(i)));
public void replaceAll(UnaryOperator<E> operator) {
instanceLock.lock();
try {
// Must trigger remove/add events if tracked or uow.
if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
List<E> del = getDelegate();
for (int i = 0; i < del.size(); i++) {
set(i, operator.apply(del.get(i)));
}
} else {
getDelegate().replaceAll(operator);
}
} else {
getDelegate().replaceAll(operator);
} finally {
instanceLock.unlock();
}
}

@Override
public synchronized boolean removeIf(Predicate<? super E> filter) {
// Must trigger remove events if tracked or uow.
if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
boolean hasChanged = false;
Iterator<E> objects = iterator();
while (objects.hasNext()) {
if (filter.test(objects.next())) {
objects.remove();
hasChanged |= true;
public boolean removeIf(Predicate<? super E> filter) {
instanceLock.lock();
try {
// Must trigger remove events if tracked or uow.
if (hasBeenRegistered() || hasTrackedPropertyChangeListener()) {
boolean hasChanged = false;
Iterator<E> objects = iterator();
while (objects.hasNext()) {
if (filter.test(objects.next())) {
objects.remove();
hasChanged |= true;
}
}
return hasChanged;
}
return hasChanged;
return getDelegate().removeIf(filter);
} finally {
instanceLock.unlock();
}
return getDelegate().removeIf(filter);
}

@Override
Expand Down
Loading
Loading