Skip to content

Commit

Permalink
Merge pull request #982 from arjantijms/4.0.0-prepare
Browse files Browse the repository at this point in the history
4.0.0 prepare
  • Loading branch information
dmatej committed Feb 16, 2024
2 parents be9e3dd + d1ed479 commit 1718cbf
Show file tree
Hide file tree
Showing 77 changed files with 3,357 additions and 1,748 deletions.
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -39,6 +39,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -62,6 +63,8 @@ public class Parser implements Closeable {
private final ParsingContext context;
private final Map<String, Types> processedURI = Collections.synchronizedMap(new HashMap<String, Types>());

private final ReentrantLock thislock = new ReentrantLock();
private final ReentrantLock futuresLock = new ReentrantLock();
private final Stack<Future<Result>> futures = new Stack<>();
private final ExecutorService executorService;
private final boolean ownES;
Expand Down Expand Up @@ -90,13 +93,14 @@ public Exception[] awaitTermination(int timeOut, TimeUnit unit) throws Interrupt
context.logger.log(Level.FINE, "Await iterating at " + System.currentTimeMillis() + " waiting for " + futures.size());
}
Future<Result> f;
synchronized(futures) {
futuresLock.lock();
try {
f = futures.pop();
} catch(EmptyStackException e) {
// it's ok, another thread took the load from us.
f = null;
}
} finally {
futuresLock.unlock();
}
if (f!=null) {
try {
Expand Down Expand Up @@ -298,8 +302,11 @@ public Result call() throws Exception {
}
}
});
synchronized(futures) {
futuresLock.lock();
try {
futures.add(future);
} finally {
futuresLock.unlock();
}
if (immediateShutdown) {
es.shutdown();
Expand All @@ -310,12 +317,22 @@ public Result call() throws Exception {
}
}

private synchronized Types getResult(URI uri) {
return processedURI.get(uri.getSchemeSpecificPart());
private Types getResult(URI uri) {
thislock.lock();
try {
return processedURI.get(uri.getSchemeSpecificPart());
} finally {
thislock.unlock();
}
}

private synchronized void saveResult(URI uri, Types types) {
this.processedURI.put(uri.getPath(), types);
private void saveResult(URI uri, Types types) {
thislock.lock();
try {
this.processedURI.put(uri.getPath(), types);
} finally {
thislock.unlock();
}
}

private void doJob(final ArchiveAdapter adapter, final Runnable doneHook) throws Exception {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.locks.ReentrantLock;
import java.net.URI;
import java.util.logging.Logger;

Expand Down Expand Up @@ -149,6 +150,7 @@ public ParsingContext build() {
final Logger logger;
final ParsingConfig config;
final ResourceLocator locator;
final ReentrantLock lock = new ReentrantLock();

private ParsingContext(Builder builder) {
// Runtime runtime = Runtime.getRuntime();
Expand Down Expand Up @@ -178,13 +180,18 @@ public boolean modelUnAnnotatedMembers() {

Map<URI, TypeBuilder> builders = new HashMap<URI, TypeBuilder>();

public synchronized TypeBuilder getTypeBuilder(URI definingURI) {
TypeBuilder builder = builders.get(definingURI);
if (builder==null) {
builder = new TypesImpl(types, definingURI);
builders.put(definingURI, builder);
public TypeBuilder getTypeBuilder(URI definingURI) {
lock.lock();
try {
TypeBuilder builder = builders.get(definingURI);
if (builder==null) {
builder = new TypesImpl(types, definingURI);
builders.put(definingURI, builder);
}
return builder;
} finally {
lock.unlock();
}
return builder;
}

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,6 +18,7 @@

import org.glassfish.hk2.classmodel.reflect.*;

import java.util.concurrent.locks.ReentrantLock;
import java.util.*;

/**
Expand All @@ -26,7 +27,8 @@
* @author Jerome Dochez
*/
public class AnnotatedElementImpl implements AnnotatedElement {


private final ReentrantLock lock = new ReentrantLock();
private final String name;

private final List<AnnotationModel> annotations = new ArrayList<AnnotationModel>();
Expand All @@ -42,8 +44,13 @@ public String getName() {
return name;
}

synchronized void addAnnotation(AnnotationModel annotation) {
annotations.add(annotation);
void addAnnotation(AnnotationModel annotation) {
lock.lock();
try {
annotations.add(annotation);
} finally {
lock.unlock();
}
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -19,21 +19,28 @@
import org.glassfish.hk2.classmodel.reflect.*;

import java.util.*;
import java.util.concurrent.locks.ReentrantLock;

/**
* Implementation of a class model
*/
public class ClassModelImpl extends ExtensibleTypeImpl<ClassModel> implements ClassModel {

private final ReentrantLock lock = new ReentrantLock();
final List<FieldModel> fields = new ArrayList<>();

public ClassModelImpl(String name, TypeProxy<Type> sink, TypeProxy parent) {
super(name, sink, parent);
}

@Override
synchronized void addField(FieldModel field) {
fields.add(field);
void addField(FieldModel field) {
lock.lock();
try {
fields.add(field);
} finally {
lock.unlock();
}
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,12 +18,14 @@

import org.glassfish.hk2.classmodel.reflect.*;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;

/**
* Implementation of an extensible type (Class or Interface)
*/
public abstract class ExtensibleTypeImpl<T extends ExtensibleType> extends TypeImpl implements ExtensibleType<T> {

private final ReentrantLock lock = new ReentrantLock();
protected TypeProxy<?> parent;
private final List<FieldModel> staticFields = new ArrayList<>();
private final List<TypeProxy<InterfaceModel>> implementedIntf = new ArrayList<>();
Expand Down Expand Up @@ -76,22 +78,37 @@ public String getSimpleName() {
return simpleName;
}

public synchronized TypeProxy<?> setParent(final TypeProxy<?> parent) {
if (null == this.parent) {
this.parent = parent;
public TypeProxy<?> setParent(final TypeProxy<?> parent) {
lock.lock();
try {
if (null == this.parent) {
this.parent = parent;
}
return this.parent;
} finally {
lock.unlock();
}
return this.parent;
}

synchronized void isImplementing(TypeProxy<InterfaceModel> intf) {
implementedIntf.add(intf);
void isImplementing(TypeProxy<InterfaceModel> intf) {
try {
lock.lock();
implementedIntf.add(intf);
} finally {
lock.unlock();
}
}

synchronized void isImplementing(ParameterizedInterfaceModelImpl pim) {
if (pim.getRawInterface() instanceof InterfaceModel) {
implementedIntf.add((TypeProxy<InterfaceModel>) pim.getRawInterfaceProxy());
void isImplementing(ParameterizedInterfaceModelImpl pim) {
try {
lock.lock();
if (pim.getRawInterface() instanceof InterfaceModel) {
implementedIntf.add((TypeProxy<InterfaceModel>) pim.getRawInterfaceProxy());
}
implementedParameterizedIntf.add(pim);
} finally {
lock.unlock();
}
implementedParameterizedIntf.add(pim);
}

@Override
Expand Down Expand Up @@ -132,8 +149,13 @@ public Collection<T> allSubTypes() {
return allTypes;
}

synchronized void addStaticField(FieldModel field) {
staticFields.add(field);
void addStaticField(FieldModel field) {
try {
lock.lock();
staticFields.add(field);
} finally {
lock.unlock();
}
}

void addField(FieldModel field) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -19,6 +19,7 @@
import org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel;

import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import org.glassfish.hk2.classmodel.reflect.ExtensibleType;

Expand All @@ -29,15 +30,21 @@
*/
class ParameterizedInterfaceModelImpl implements ParameterizedInterfaceModel {

private final ReentrantLock lock = new ReentrantLock();
final TypeProxy<ExtensibleType> rawInterface;
final List<ParameterizedInterfaceModel> parameterizedTypes = new ArrayList<>();

ParameterizedInterfaceModelImpl(TypeProxy<ExtensibleType> rawInterface) {
this.rawInterface = rawInterface;
}

synchronized void addParameterizedType(ParameterizedInterfaceModel type) {
parameterizedTypes.add(type);
void addParameterizedType(ParameterizedInterfaceModel type) {
lock.lock();
try {
parameterizedTypes.add(type);
} finally {
lock.unlock();
}
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.net.URI;

/**
Expand All @@ -31,6 +32,7 @@
*/
public class TypeImpl extends AnnotatedElementImpl implements Type {

private final ReentrantLock lock = new ReentrantLock();
private final TypeProxy<Type> sink;
private final List<MethodModel> methods = new ArrayList<MethodModel>();
private final Set<URI> definingURIs= new HashSet<URI>();
Expand All @@ -46,8 +48,13 @@ public Collection<URI> getDefiningURIs() {
return Collections.unmodifiableSet(definingURIs);
}

synchronized void addDefiningURI(URI uri) {
definingURIs.add(uri);
void addDefiningURI(URI uri) {
lock.lock();
try {
definingURIs.add(uri);
} finally {
lock.unlock();
}
}

@Override
Expand All @@ -60,8 +67,13 @@ public boolean wasDefinedIn(Collection<URI> uris) {
return false;
}

synchronized void addMethod(MethodModelImpl m) {
methods.add(m);
void addMethod(MethodModelImpl m) {
lock.lock();
try {
methods.add(m);
} finally {
lock.unlock();
}
}

@Override
Expand Down

0 comments on commit 1718cbf

Please sign in to comment.