Skip to content

Commit

Permalink
[#699] Make use of proper mutable attribute count for updatable inher…
Browse files Browse the repository at this point in the history
…itance type
  • Loading branch information
beikov committed Dec 16, 2018
1 parent 3a3f369 commit 23b96fe
Showing 1 changed file with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -106,13 +111,29 @@ public class ProxyFactory {
private static final Logger LOG = Logger.getLogger(ProxyFactory.class.getName());
// This has to be static since runtime generated correlation providers can't be matched in a later run, so we always create a new one with a unique name
private static final ConcurrentMap<Class<?>, AtomicInteger> CORRELATION_PROVIDER_CLASS_COUNT = new ConcurrentHashMap<>();
private static final Path DEBUG_DUMP_DIRECTORY;
private final ConcurrentMap<ProxyClassKey, Class<?>> proxyClasses = new ConcurrentHashMap<>();
private final ConcurrentMap<ProxyClassKey, Class<?>> unsafeProxyClasses = new ConcurrentHashMap<>();
private final Object proxyLock = new Object();
private final ClassPool pool;
private final boolean unsafeDisabled;
private final PackageOpener packageOpener;

static {
String property = System.getProperty("entityview.debugDumpDirectory");
if (property == null) {
DEBUG_DUMP_DIRECTORY = null;
} else {
Path p = Paths.get(property);
if (Files.exists(p)) {
DEBUG_DUMP_DIRECTORY = p.toAbsolutePath();
} else {
DEBUG_DUMP_DIRECTORY = null;
Logger.getLogger(ProxyFactory.class.getName()).severe("The given debug dump directory does not exist: " + p.toAbsolutePath());
}
}
}

/**
* @author Christian Beikov
* @since 1.0.0
Expand Down Expand Up @@ -485,6 +506,10 @@ private <T> Class<? extends T> defineOrGetClass(EntityViewManager entityViewMana
// Ask the package opener to allow deep access, otherwise defining the class will fail
packageOpener.openPackageIfNeeded(clazz, clazz.getPackage().getName(), ProxyFactory.class);

if (DEBUG_DUMP_DIRECTORY != null) {
cc.writeFile(DEBUG_DUMP_DIRECTORY.toString());
}

Class<? extends T> c;
if (unsafe) {
c = (Class<? extends T>) UnsafeHelper.define(cc.getName(), cc.toBytecode(), clazz);
Expand Down Expand Up @@ -572,8 +597,26 @@ private <T> void createInheritanceConstructors(EntityViewManager entityViewManag
}
AbstractMethodAttribute<?, ?> attribute = entry.getValue().getSubAttribute(managedView);
if (attribute.getDirtyStateIndex() != -1) {
subtypeMutableAttributes[j] = attribute;
subtypeMutableAttributeCount++;
if (entry.getValue().getSelectionConstrainedAttributes().isEmpty()) {
subtypeMutableAttributes[j] = attribute;
subtypeMutableAttributeCount++;
} else {
// Collect the subtype indexes where this attribute is mutable
SortedSet<Integer> indexes = new TreeSet<>();
// If the attributes are different, we are working on a "subAttribute"
if (entry.getValue().getAttribute() != attribute) {
indexes.add(subtypeIndex);
}
for (ConstrainedAttribute.Entry<AbstractMethodAttribute<?, ?>> selectionConstrainedAttribute : entry.getValue().getSelectionConstrainedAttributes()) {
for (int index : selectionConstrainedAttribute.getSubtypeIndexes()) {
indexes.add(index);
}
}
if (indexes.contains(subtypeIndex)) {
subtypeMutableAttributes[j] = attribute;
subtypeMutableAttributeCount++;
}
}
}

CtField field = fieldMap.get(attributeName);
Expand Down Expand Up @@ -628,7 +671,7 @@ private <T> void createInheritanceConstructors(EntityViewManager entityViewManag

overallConstructorParameterTypes.put(constructor.getName(), constructorAttributeTypes);
int superConstructorParameterEndPosition = constructorParameterStartPosition + constructor.getParameterAttributes().size();
cc.addConstructor(createConstructor(entityViewManager, managedView, cc, constructorParameterStartPosition, superConstructorParameterEndPosition, fields, constructorAttributeTypes, initialStateField, mutableStateField, mutableAttributes, mutableAttributeCount, ConstructorKind.NORMAL, null, unsafe));
cc.addConstructor(createConstructor(entityViewManager, managedView, cc, constructorParameterStartPosition, superConstructorParameterEndPosition, fields, constructorAttributeTypes, initialStateField, mutableStateField, subtypeMutableAttributes, subtypeMutableAttributeCount, ConstructorKind.NORMAL, null, unsafe));
}
}

Expand Down

0 comments on commit 23b96fe

Please sign in to comment.