summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon/carbonado')
-rw-r--r--src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java72
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java2
-rw-r--r--src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java4
3 files changed, 29 insertions, 49 deletions
diff --git a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java
index ce55ddb..7f26238 100644
--- a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java
+++ b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java
@@ -1929,8 +1929,11 @@ public class GenericEncodingStrategy<S extends Storable> {
LocalVariable[] bigDecimalRefRef = new LocalVariable[1];
LocalVariable[] valueRefRef = new LocalVariable[1];
+ // Used by SERIAL mode.
+ LocalVariable[] stateVars = null;
+
if (mode == Mode.SERIAL) {
- decodePropertyStates(a, encodedVar, constantOffset, properties);
+ stateVars = decodePropertyStates(a, encodedVar, constantOffset, properties);
constantOffset += (properties.length + 3) / 4;
// Some properties are skipped at runtime, so offset variable is required.
@@ -1980,14 +1983,6 @@ public class GenericEncodingStrategy<S extends Storable> {
}
}
- LocalVariable stateFieldVar;
- if (mode != Mode.SERIAL) {
- stateFieldVar = null;
- } else {
- stateFieldVar = a.createLocalVariable(null, TypeDesc.INT);
- }
- int lastFieldOrdinal = -1;
-
for (int i=0; i<properties.length; i++) {
StorableProperty<S> property = properties[i];
StorablePropertyInfo info = infos[i];
@@ -2001,18 +1996,7 @@ public class GenericEncodingStrategy<S extends Storable> {
if (mode == Mode.SERIAL) {
// Load property if initialized, else reset it.
- int fieldOrdinal = property.getNumber() >> 4;
-
- if (fieldOrdinal == lastFieldOrdinal) {
- a.loadLocal(stateFieldVar);
- } else {
- a.loadThis();
- a.loadField(PROPERTY_STATE_FIELD_NAME + fieldOrdinal, TypeDesc.INT);
- a.storeLocal(stateFieldVar);
- a.loadLocal(stateFieldVar);
- lastFieldOrdinal = fieldOrdinal;
- }
-
+ a.loadLocal(stateVars[property.getNumber() >> 4]);
a.loadConstant(PROPERTY_STATE_MASK << ((property.getNumber() & 0xf) * 2));
a.math(Opcode.IAND);
Label isInitialized = a.createLabel();
@@ -2131,6 +2115,14 @@ public class GenericEncodingStrategy<S extends Storable> {
nextPropertyLocation.setLocation();
}
+
+ if (stateVars != null) {
+ for (int i=0; i<stateVars.length; i++) {
+ a.loadThis();
+ a.loadLocal(stateVars[i]);
+ a.storeField(PROPERTY_STATE_FIELD_NAME + i, TypeDesc.INT);
+ }
+ }
}
/**
@@ -2582,32 +2574,25 @@ public class GenericEncodingStrategy<S extends Storable> {
*
* @param encodedVar references a byte array
* @param offset offset into byte array
+ * @return local variables with state values
*/
- private void decodePropertyStates(CodeAssembler a, LocalVariable encodedVar,
- int offset, StorableProperty<S>[] properties)
+ private LocalVariable[] decodePropertyStates(CodeAssembler a, LocalVariable encodedVar,
+ int offset, StorableProperty<S>[] properties)
{
- LocalVariable stateFieldVar = a.createLocalVariable(null, TypeDesc.INT);
- int lastFieldOrdinal = -1;
-
+ LocalVariable[] stateVars = new LocalVariable[(properties.length + 15) >> 4];
LocalVariable accumVar = a.createLocalVariable(null, TypeDesc.INT);
int accumShift = 8;
for (int i=0; i<properties.length; i++) {
StorableProperty<S> property = properties[i];
- int fieldOrdinal = property.getNumber() >> 4;
+ int stateVarOrdinal = property.getNumber() >> 4;
- if (fieldOrdinal != lastFieldOrdinal) {
- if (lastFieldOrdinal >= 0) {
- // Copy states to field.
- a.loadThis();
- a.loadLocal(stateFieldVar);
- a.storeField(PROPERTY_STATE_FIELD_NAME + lastFieldOrdinal, TypeDesc.INT);
- }
+ if (stateVars[stateVarOrdinal] == null) {
+ stateVars[stateVarOrdinal] = a.createLocalVariable(null, TypeDesc.INT);
a.loadThis();
- a.loadField(PROPERTY_STATE_FIELD_NAME + fieldOrdinal, TypeDesc.INT);
- a.storeLocal(stateFieldVar);
- lastFieldOrdinal = fieldOrdinal;
+ a.loadField(PROPERTY_STATE_FIELD_NAME + stateVarOrdinal, TypeDesc.INT);
+ a.storeLocal(stateVars[stateVarOrdinal]);
}
if (accumShift >= 8) {
@@ -2637,7 +2622,7 @@ public class GenericEncodingStrategy<S extends Storable> {
// Properties are not consecutive.
break;
}
- if (fieldOrdinal != (nextProperty.getNumber() >> 4)) {
+ if (stateVarOrdinal != (nextProperty.getNumber() >> 4)) {
// Property states are stored in different fields.
break;
}
@@ -2659,20 +2644,15 @@ public class GenericEncodingStrategy<S extends Storable> {
a.loadConstant(mask);
a.math(Opcode.IAND);
- a.loadLocal(stateFieldVar);
+ a.loadLocal(stateVars[stateVarOrdinal]);
a.loadConstant(~mask);
a.math(Opcode.IAND);
a.math(Opcode.IOR);
- a.storeLocal(stateFieldVar);
+ a.storeLocal(stateVars[stateVarOrdinal]);
accumShift += accumPack;
}
- if (lastFieldOrdinal >= 0) {
- // Copy remaining states to last state field.
- a.loadThis();
- a.loadLocal(stateFieldVar);
- a.storeField(PROPERTY_STATE_FIELD_NAME + lastFieldOrdinal, TypeDesc.INT);
- }
+ return stateVars;
}
}
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java
index 872b5b4..61c087b 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java
@@ -99,7 +99,7 @@ class IndexedCursor<S extends Storable> extends AbstractCursor<S> {
// the risk of seeing it multiple times. This is
// better than seeing it never.
LogFactory.getLog(getClass()).warn
- ("Inconsistent index entry: " + indexEntry);
+ ("Inconsistent index entry: " + indexEntry + ", " + master);
mNext = master;
}
diff --git a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java
index 75f1701..9a44574 100644
--- a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java
+++ b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceBuilder.java
@@ -418,7 +418,7 @@ public class SyntheticStorableReferenceBuilder<S extends Storable>
TypeDesc masterStorableType = TypeDesc.forClass(mMasterStorableClass);
// Add a method which tests all properties of index entry object
- // against master object, excluding the version property.
+ // against master object, excluding version and derived properties.
{
TypeDesc[] params = new TypeDesc[] {masterStorableType};
MethodInfo mi = cf.addMethod
@@ -426,7 +426,7 @@ public class SyntheticStorableReferenceBuilder<S extends Storable>
CodeBuilder b = new CodeBuilder(mi);
for (StorableProperty prop : mCommonProps) {
- if (prop.isVersion()) {
+ if (prop.isVersion() || prop.isDerived()) {
continue;
}
Label propsAreEqual = b.createLabel();