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 ++++++++-------------- 1 file changed, 26 insertions(+), 46 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/raw') 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; } } -- cgit v1.2.3