GammaTxnConfig implements TxnConfig, GammaConstants { public GammaTxnConfig init() { if (!writeSkewAllowed && !trackReads && !readonly) { String msg = format("'[%s] If no writeskew is allowed, read tracking should be enabled", familyName); throw new IllegalTxnFactoryException(msg); } if (blockingAllowed && !trackReads) { String msg = format("[%s] If blocking is allowed, read tracking should be enabled", familyName); throw new IllegalTxnFactoryException(msg); } if (readLockModeAsInt > writeLockModeAsInt) { String msg = format("[%s] The used write LockMode [%s] should be equal or higher than the read LockMode [%s]", familyName, readLockMode, writeLockMode); throw new IllegalTxnFactoryException(msg); } if (readLockMode != LockMode.None && !trackReads) { String msg = format("[%s] If readLockMode is [%s] , read tracking should be enabled", familyName, readLockMode); throw new IllegalTxnFactoryException(msg); } if (speculativeConfiguration.get() == null) { SpeculativeGammaConfiguration newSpeculativeConfiguration; if (speculative) { newSpeculativeConfiguration = new SpeculativeGammaConfiguration( isFat(), false, false, false, false, false, false, false, false, false, 1); } else { newSpeculativeConfiguration = new SpeculativeGammaConfiguration( true, true, true, true, true, true, true, true, true, true, Integer.MAX_VALUE); } if (maximumPoorMansConflictScanLength == 0) { newSpeculativeConfiguration = newSpeculativeConfiguration.newWithRichMansConflictScan(); } speculativeConfiguration.compareAndSet(null, newSpeculativeConfiguration); } return this; } GammaTxnConfig(GammaStm stm);  GammaTxnConfig(GammaStm stm, GammaStmConfig config); private  GammaTxnConfig(GammaTxnConfig config);  GammaTxnConfig(GammaStm stm, int maxFixedLengthTransactionSize); @Override LockMode getReadLockMode(); @Override LockMode getWriteLockMode(); @Override IsolationLevel getIsolationLevel(); @Override boolean isControlFlowErrorsReused(); SpeculativeGammaConfiguration getSpeculativeConfiguration(); @Override long getTimeoutNs(); @Override TraceLevel getTraceLevel(); @Override boolean isInterruptible(); @Override BackoffPolicy getBackoffPolicy(); @Override boolean isSpeculative(); @Override String getFamilyName(); @Override boolean isReadonly(); @Override int getSpinCount(); @Override boolean isDirtyCheckEnabled(); @Override GammaStm getStm(); GlobalConflictCounter getGlobalConflictCounter(); @Override boolean isReadTrackingEnabled(); @Override boolean isBlockingAllowed(); @Override int getMaxRetries(); @Override PropagationLevel getPropagationLevel(); @Override List<TxnListener> getPermanentListeners(); void updateSpeculativeConfigurationToUseNonRefType(); void updateSpeculativeConfigurationToUseListeners(); void updateSpeculativeConfigureToUseAbortOnly(); void updateSpeculativeConfigurationToUseCommute(); void updateSpeculativeConfigurationToUseExplicitLocking(); void updateSpeculativeConfigurationToUseConstructedObjects(); void updateSpeculativeConfigurationToUseRichMansConflictScan(); void updateSpeculativeConfigurationToUseMinimalTransactionLength(int newLength); void updateSpeculativeConfigurationToUseEnsure(); GammaTxnConfig init(); GammaTxnConfig setTimeoutNs(long timeoutNs); GammaTxnConfig setFamilyName(String familyName); GammaTxnConfig setMaxRetries(int maxRetries); GammaTxnConfig setMaximumPoorMansConflictScanLength(int maximumPoorMansConflictScanLength); GammaTxnConfig setReadTrackingEnabled(boolean trackReads); GammaTxnConfig setSpeculative(boolean speculativeConfigEnabled); GammaTxnConfig setReadonly(boolean readonly); GammaTxnConfig setDirtyCheckEnabled(boolean dirtyCheck); GammaTxnConfig setBlockingAllowed(boolean blockingAllowed); GammaTxnConfig setInterruptible(boolean interruptible); GammaTxnConfig setControlFlowErrorsReused(boolean controlFlowErrorsReused); GammaTxnConfig setSpinCount(int spinCount); GammaTxnConfig setBackoffPolicy(BackoffPolicy backoffPolicy); GammaTxnConfig setTraceLevel(TraceLevel traceLevel); GammaTxnConfig setPropagationLevel(PropagationLevel propagationLevel); GammaTxnConfig setIsolationLevel(IsolationLevel isolationLevel); GammaTxnConfig setWriteLockMode(LockMode writeLockMode); GammaTxnConfig setReadLockMode(LockMode readLockMode); GammaTxnConfig setFat(); GammaTxnConfig addPermanentListener(TxnListener listener); @Override String toString(); final static AtomicLong idGenerator; final AtomicReference<SpeculativeGammaConfiguration> speculativeConfiguration; final GammaStm stm; final GlobalConflictCounter globalConflictCounter; public PropagationLevel propagationLevel; public IsolationLevel isolationLevel; public boolean writeSkewAllowed; public boolean inconsistentReadAllowed; public LockMode readLockMode; public LockMode writeLockMode; public int readLockModeAsInt; public int writeLockModeAsInt; public String familyName; public boolean isAnonymous; public boolean interruptible; public boolean readonly; public int spinCount; public boolean dirtyCheck; public int minimalArrayTreeSize; public boolean trackReads; public boolean blockingAllowed; public int maxRetries; public boolean speculative; public int maxFixedLengthTransactionSize; public BackoffPolicy backoffPolicy; public long timeoutNs; public TraceLevel traceLevel; public boolean controlFlowErrorsReused; public boolean isFat; public int maximumPoorMansConflictScanLength; public ArrayList<TxnListener> permanentListeners; public boolean unrepeatableReadAllowed; }
@Test public void testIsRichMansConflictScanRequired() { GammaStmConfig stmConfig = new GammaStmConfig(); stmConfig.maximumPoorMansConflictScanLength = 0; stmConfig.speculativeConfigEnabled = true; GammaStm stm = new GammaStm(stmConfig); GammaTxnConfig txConfig = new GammaTxnConfig(stm, stmConfig); txConfig.init(); assertTrue(txConfig.speculativeConfiguration.get().richMansConflictScanRequired); }
@Test public void testIsRichMansConflictScanRequiredIfMaximumPoorMansConflictScanLengthIsZero() { GammaStmConfig stmConfig = new GammaStmConfig(); stmConfig.maximumPoorMansConflictScanLength = 10; stmConfig.speculativeConfigEnabled = true; stmConfig.dirtyCheck = false; GammaStm stm = new GammaStm(stmConfig); GammaTxnConfig txConfig = new GammaTxnConfig(stm, stmConfig); txConfig.init(); assertFalse(txConfig.speculativeConfiguration.get().richMansConflictScanRequired); }