From 5d9feb86cf7e8b7ea8e00d512f774c20d92e7365 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 15 Oct 2009 22:06:16 +0000 Subject: Generated readFrom method sets properties states at the end, to ensure that adapted properties in the primary key can be always set. --- .../carbonado/raw/GenericEncodingStrategy.java | 72 ++++++++-------------- .../carbonado/repo/indexed/IndexedCursor.java | 2 +- .../SyntheticStorableReferenceBuilder.java | 4 +- 3 files changed, 29 insertions(+), 49 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') 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 { 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 { } } - LocalVariable stateFieldVar; - if (mode != Mode.SERIAL) { - stateFieldVar = null; - } else { - stateFieldVar = a.createLocalVariable(null, TypeDesc.INT); - } - int lastFieldOrdinal = -1; - for (int i=0; i property = properties[i]; StorablePropertyInfo info = infos[i]; @@ -2001,18 +1996,7 @@ public class GenericEncodingStrategy { 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 { nextPropertyLocation.setLocation(); } + + if (stateVars != null) { + for (int i=0; i { * * @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[] properties) + private LocalVariable[] decodePropertyStates(CodeAssembler a, LocalVariable encodedVar, + int offset, StorableProperty[] 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 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 { // 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 { 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 extends AbstractCursor { // 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 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 CodeBuilder b = new CodeBuilder(mi); for (StorableProperty prop : mCommonProps) { - if (prop.isVersion()) { + if (prop.isVersion() || prop.isDerived()) { continue; } Label propsAreEqual = b.createLabel(); -- cgit v1.2.3