private Transaction writer;
private ReadSet readers;
long version;
+
private final String FORMAT = "Unexpected transaction state: %s";
/** Creates a new instance of AtomicArray */
readers = new ReadSet();
version = 0;
}
+ public int size(){
+ return array.length;
+ }
public T get(int i) {
Transaction me = Thread.getTransaction();
*
* @see dstm2.ContentionManager
*/
-public class Thread extends java.lang.Thread {
+public class Thread extends java.lang.Thread{
/**
* Contention manager class.
*/
private void parseProperties(Class _class) {
// Make sure implied field types are scalar or atomic.
// Enough to check return type of getField() methods.
- for (java.lang.reflect.Method method : _class.getMethods()) {
- if (method.getName().substring(0,3).equals("get")) {
+ for (java.lang.reflect.Method method : _class.getMethods()) {
+ if (method.getName().substring(0,3).equals("get") &&
+ !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.LinkedList") &&
+ !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.Hashtable") &&
+ !method.getDeclaringClass().getCanonicalName().contains("dstm2.util.HashMap")) {
if (!isAtomicOrScalar(method.getReturnType())) {
throw new PanicException("Method %s return type %s not scalar or atomic.",
method.getName(), method.getReturnType().getName());
import com.enea.jcarder.common.contexts.ContextWriterIfc;
import com.enea.jcarder.common.events.EventFileWriter;
import com.enea.jcarder.common.events.LockEventListenerIfc;
+import com.enea.jcarder.transactionalinterfaces.trEventListener;
import com.enea.jcarder.util.Counter;
//import com.enea.jcarder.util.TransactionalCounter;
import com.enea.jcarder.util.TransactionalCounter;
//@ThreadSafe
import java.util.Vector;
import java.util.concurrent.Callable;
+import java.util.logging.Level;
final class EventListener implements EventListenerIfc {
+ trEventListener listener;
private final ThreadLocalEnteredMonitors mEnteredMonitors;
private final LockEventListenerIfc mLockEventListener;
private final LockIdGenerator mLockIdGenerator;
private final LockingContextIdCache mContextCache;
private final Logger mLogger;
- private final Counter mNumberOfEnteredMonitors;
-
-
+ //private final Counter mNumberOfEnteredMonitors;
private final TransactionalCounter trmNumberOfEnteredMonitors;
public static EventListener create(Logger logger, File outputdir)
public EventListener(Logger logger,
LockEventListenerIfc lockEventListener,
- ContextWriterIfc contextWriter) {
- mLogger = logger;
+ /*ContextWriterIfc contextWriter*/ContextFileWriter contextWriter) {
+
+ mLogger = logger;
mEnteredMonitors = new ThreadLocalEnteredMonitors();
mLockEventListener = lockEventListener;
mLockIdGenerator = new LockIdGenerator(mLogger, contextWriter);
mContextCache = new LockingContextIdCache(mLogger, contextWriter);
- mNumberOfEnteredMonitors =
- new Counter("Entered Monitors", mLogger, 100000);
+ // mNumberOfEnteredMonitors =
+ // new Counter("Entered Monitors", mLogger, 100000);
trmNumberOfEnteredMonitors =
new TransactionalCounter("Entered Monitors", mLogger, 100000);
+
+ /* listener = new trEventListener();
+ listener.atmoicfileds = trEventListener.factory.create();
+ this.listener.atmoicfileds.setCCByteBuffer(this.getMContextCache().getMContextWriter().getMbuff().mbuffer);
+ listener.atmoicfileds.setCCPosiiton(getMContextCache().getMContextWriter().getTest().pos);
+ listener.atmoicfileds.setCCShutdown(getMContextCache().getMContextWriter().getShutdownHookExecuted().boolif);
+
+
+ listener.atmoicfileds.setHMap1Capacity(getMContextCache().getMCache().capacity);
+ listener.atmoicfileds.setHMap1Position(getMContextCache().getMCache().position);
+ listener.atmoicfileds.setHMap1Values(getMContextCache().getMCache().values);
+
+ listener.atmoicfileds.setELNumberofMonitors(getTrmNumberOfEnteredMonitors().mValue);
+
+ listener.atmoicfileds.setLIGByteBuffer(getMLockIdGenerator().getMContextWriter().getMbuff().mbuffer);
+ listener.atmoicfileds.setLIGPosiiton(getMLockIdGenerator().getMContextWriter().getTest().pos);
+ listener.atmoicfileds.setLIGShutdown(getMLockIdGenerator().getMContextWriter().getShutdownHookExecuted().boolif);
+
+ listener.atmoicfileds.setHMap2Capacity(getMLockIdGenerator().getMIdMap().capacity);
+ listener.atmoicfileds.setHMap2Position(getMLockIdGenerator().getMIdMap().position);
+ listener.atmoicfileds.setHMap2Values(getMLockIdGenerator().getMIdMap().values);
+
+ listener.atmoicfileds.setEFWByteBuffer(((EventFileWriter)this.getMLockEventListener()).getMbuff().mbuffer);
+ listener.atmoicfileds.setEFWShutdown(((EventFileWriter)this.getMLockEventListener()).getShutdownHookExecuted().boolif);
+ listener.atmoicfileds.setEFWCounter(((EventFileWriter)this.getMLockEventListener()).getTrmWrittenLockEvents().mValue);*/
+
+
+ }
+
+
+ public EventListener(EventListener other) {
+ this.mLogger = other.mLogger;
+ this.mEnteredMonitors = other.mEnteredMonitors;
+ this.trmNumberOfEnteredMonitors = other.trmNumberOfEnteredMonitors;
+ //this.trmNumberOfEnteredMonitors.mValue.setPosition(other.trmNumberOfEnteredMonitors.mValue.getPosition());
+ this.mContextCache = new LockingContextIdCache(other.mContextCache);
+ this.mLockIdGenerator =new LockIdGenerator(other.mLockIdGenerator);
+ this.mLockEventListener = new EventFileWriter((EventFileWriter) (other.mLockEventListener));
}
public void beforeMonitorEnter(Object monitor, LockingContext context)
}
- private synchronized void enteringNewMonitor(Object monitor,
+ /* private synchronized void enteringNewMonitor(Object monitor,
LockingContext context)
throws Exception {
mNumberOfEnteredMonitors.increment();
int newLockId = mLockIdGenerator.acquireLockId(monitor);
+ System.out.println("monitor " + monitor.getClass());
int newContextId = mContextCache.acquireContextId(context);
EnteredMonitor lastMonitor = mEnteredMonitors.getFirst();
newLockId,
newContextId));
- }
+ }*/
- private synchronized void trenteringNewMonitor(Object monitor,
- Vector context)
+ private void trenteringNewMonitor(Vector arguments)
throws Exception {
- mNumberOfEnteredMonitors.increment();
- int newLockId = mLockIdGenerator.acquireLockId(monitor);
- int newContextId = mContextCache.acquireContextId((LockingContext)context.get(0));
+
+ trmNumberOfEnteredMonitors.increment();
+ final int newLockId = mLockIdGenerator.acquireLockId((Object)arguments.get(1));
+ final int newContextId = mContextCache.acquireContextId((LockingContext)arguments.get(0));
+ arguments.add(newLockId);
+ arguments.add(newContextId);
EnteredMonitor lastMonitor = mEnteredMonitors.getFirst();
if (lastMonitor != null) {
java.lang.Thread performingThread = Thread.currentThread();
Vector args = new Vector();
+
+
+
args.add(newLockId);
args.add(newContextId);
args.add(lastMonitor.getLockId());
mLockEventListener.tronLockEvent(args);
}
- mEnteredMonitors.addFirst(new EnteredMonitor(monitor,
- newLockId,
- newContextId));
+ // mEnteredMonitors.addFirst(new EnteredMonitor((Object)context.get(1),
+ // newLockId,
+ // newContextId));
}
- private void trenteringNewMonitorWrapper(Object monitor,
+
+
+ private void enteringNewMonitor(Object monitor,
LockingContext context)
throws Exception {
final Vector arguments = new Vector();
arguments.add(context);
- Thread.doIt(new Callable<Boolean>() {
+ arguments.add(monitor);
+ Thread.doIt(new Callable<Boolean>() {
public Boolean call() throws Exception {
- trenteringNewMonitor(mLogger, arguments);
+ trenteringNewMonitor(arguments);
+
return true;
}
});
+ // System.out.println(arguments.size());
+ mEnteredMonitors.addFirst(new EnteredMonitor(monitor, ((Integer)(arguments.get(2))).intValue(), ((Integer)(arguments.get(3))).intValue()));
+ arguments.clear();
-
}
+
+ public LockingContextIdCache getMContextCache() {
+ return mContextCache;
+ }
+
+ public ThreadLocalEnteredMonitors getMEnteredMonitors() {
+ return mEnteredMonitors;
+ }
+
+ public LockEventListenerIfc getMLockEventListener() {
+ return mLockEventListener;
+ }
+
+ public LockIdGenerator getMLockIdGenerator() {
+ return mLockIdGenerator;
+ }
+
+ public Logger getMLogger() {
+ return mLogger;
+ }
+
+ public TransactionalCounter getTrmNumberOfEnteredMonitors() {
+ return trmNumberOfEnteredMonitors;
+ }
+
+
+
+
+
+
}
package com.enea.jcarder.agent;
import com.enea.jcarder.common.LockingContext;
+import dstm2.AtomicSuperClass;
-public interface EventListenerIfc {
+public interface EventListenerIfc extends AtomicSuperClass{
void beforeMonitorEnter(Object monitor,
LockingContext context) throws Exception;
initLogger();
mLogger.info("Starting " + BuildInformation.getShortInfo() + " agent");
logJvmInfo();
+ Thread t;
EventListener listener = EventListener.create(mLogger, mOutputDir);
ClassTransformer classTransformer =
new ClassTransformer(mLogger, mOutputDir, mConfig);
return;
}
mLogWriter = new PrintWriter(new BufferedWriter(fileWriter));
- AppendableHandler fileHandler = new AppendableHandler(mLogWriter);
- // AppendableHandler fileHandler = new AppendableHandler(mLogWriter, new TransactionalFile(LOG_FILENAME, "rw"));
- AppendableHandler consoleHandler =
- new AppendableHandler(System.err, Logger.Level.INFO, "{message}\n");
+ // AppendableHandler fileHandler = new AppendableHandler(mLogWriter);
+ AppendableHandler fileHandler = new AppendableHandler(mLogWriter, new TransactionalFile(LOG_FILENAME, "rw"));
+ //AppendableHandler consoleHandler =
+ // new AppendableHandler(System.err, Logger.Level.INFO, "{message}\n");
- /* File logFile2 = new File(mOutputDir, LOG2_FILENAME);
+ File logFile2 = new File(mOutputDir, LOG2_FILENAME);
if (logFile2.exists()) {
logFile2.delete();
}
AppendableHandler consoleHandler =
new AppendableHandler(new PrintWriter(new BufferedWriter(fileWriter)), Logger.Level.INFO, "{message}\n", new TransactionalFile(LOG2_FILENAME, "rw"));
-*/
+
Thread hook = new Thread() {
public void run() {
mLogWriter.flush();
//import net.jcip.annotations.NotThreadSafe;
import com.enea.jcarder.common.Lock;
+import com.enea.jcarder.common.contexts.ContextFileWriter;
import com.enea.jcarder.common.contexts.ContextWriterIfc;
+//import com.enea.jcarder.transactionalinterfaces.trHashMap;
import com.enea.jcarder.util.IdentityWeakHashMap;
import com.enea.jcarder.util.logging.Logger;
+import dstm2.util.IntHashMap;
+import com.enea.jcarder.transactionalinterfaces.Intif;
+//import java.util.HashMap;
+import sun.misc.VM;
/**
* This class is responsible for generating unique IDs for objects.
*/
//@NotThreadSafe
final class LockIdGenerator {
- private final IdentityWeakHashMap<Integer> mIdMap;
- private final ContextWriterIfc mContextWriter;
+ //private final IdentityWeakHashMap<Integer> mIdMap;
+ // private final HashMap<Intif.positionif> mIdMap;
+ private final IntHashMap mIdMap;
+ //private final ContextWriterIfc mContextWriter;
+ private final ContextFileWriter mContextWriter;
private final Logger mLogger;
/**
* Create a LockIdGenerator backed by a ContextWriterIfc
*/
- public LockIdGenerator(Logger logger, ContextWriterIfc writer) {
+ public LockIdGenerator(LockIdGenerator other){
+ this.mIdMap = other.mIdMap;
+ // this.mIdMap.values.setValues(other.mIdMap.values.getValues());
+ // this.mIdMap.position.setPosition(other.mIdMap.position.getPosition());
+ // this.mIdMap.capacity.setPosition(other.mIdMap.capacity.getPosition());
+ //this.mIdMap.keys = other.mIdMap.keys;
+ this.mContextWriter = other.mContextWriter;
+ this.mLogger = other.mLogger;
+
+
+ }
+
+ public LockIdGenerator(Logger logger, /*ContextWriterIfc writer*/ContextFileWriter writer) {
mLogger = logger;
- mIdMap = new IdentityWeakHashMap<Integer>();
+ // mIdMap = new IdentityWeakHashMap<Integer>();
+// mIdMap = new HashMap<Intif.positionif>();
+ mIdMap = new IntHashMap();
mContextWriter = writer;
+
}
/**
*/
public int acquireLockId(Object o) throws IOException {
assert o != null;
- Integer id = mIdMap.get(o);
- if (id == null) {
+ Integer id = (Integer)mIdMap.get(System.identityHashCode(o));
+ // if (mIdMap.get(HashMap.hash(o)) == null){
+ if (id == null){
+ id = mContextWriter.writeLock(new Lock(o));
+ // Intif.positionif tmp = Intif.factory.create();
+ // tmp.setPosition(id);
+ // mIdMap.put(HashMap.hash(o), tmp);
+ //mIdMap.put(o, tmp);
+ mIdMap.put(System.identityHashCode(o), id);
+ mLogger.finest("Created new lock ID: " + id);
+ }
+ // else
+ // id = mIdMap.get(HashMap.hash(o)).getPosition();
+
+ /* if (id == null) {
id = mContextWriter.writeLock(new Lock(o));
- mIdMap.put(o, id);
+ tmp.setPosition(id);
+ mIdMap.put(System.identityHashCode(o), tmp);
mLogger.finest("Created new lock ID: " + id);
- }
+ }*/
return id;
}
+
+ public ContextFileWriter getMContextWriter() {
+ return mContextWriter;
+ }
+
+
+
+ public Logger getMLogger() {
+ return mLogger;
+ }
+
+
+
}
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
-import java.util.HashMap;
+
+
+//import dstm2.util.HashMap;
//import net.jcip.annotations.NotThreadSafe;
import com.enea.jcarder.common.LockingContext;
+import com.enea.jcarder.common.contexts.ContextFileWriter;
import com.enea.jcarder.common.contexts.ContextWriterIfc;
+import com.enea.jcarder.transactionalinterfaces.Intif;
+import com.enea.jcarder.transactionalinterfaces.trHashMap;
import com.enea.jcarder.util.logging.Logger;
+import dstm2.util.IntHashMap;
+//import dstm2.util.HashMap;
/**
* This class is responsible for mapping LockingContext instances to locking
*/
//@NotThreadSafe
final class LockingContextIdCache {
- private final HashMap<EqualsComparableKey, Integer> mCache;
- private final ReferenceQueue<Object> mReferenceQueue;
- private final ContextWriterIfc mContextWriter;
+ //private final HashMap<EqualsComparableKey, Integer> mCache;
+ //private final HashMap<Intif.positionif> mCache;
+ private final IntHashMap mCache;
+ //private final ReferenceQueue<Object> mReferenceQueue;
+ //private final ContextWriterIfc mContextWriter;
+ private final ContextFileWriter mContextWriter;
private final Logger mLogger;
+
/**
* Create a LockingContextIdCache backed by a ContextWriterIfc.
*/
+ public LockingContextIdCache(LockingContextIdCache other){
+ this.mCache = other.mCache;
+ // this.mCache.values.setValues(other.mCache.values.getValues());
+ //this.mCache.position.setPosition(other.mCache.position.getPosition());
+ //this.mCache.capacity.setPosition(other.mCache.capacity.getPosition());
+ //this.mCache.keys = other.mCache.keys;;
+ this.mContextWriter = other.mContextWriter;
+ this.mLogger = other.mLogger;
+
+ }
+
public LockingContextIdCache(Logger logger, ContextWriterIfc writer) {
mLogger = logger;
- mCache = new HashMap<EqualsComparableKey, Integer>();
- mReferenceQueue = new ReferenceQueue<Object>();
- mContextWriter = writer;
+ //mCache = new HashMap<EqualsComparableKey, Integer>();
+// mCache = new HashMap<Intif.positionif>();
+ mCache = new IntHashMap();
+ // mReferenceQueue = new ReferenceQueue<Object>();
+ mContextWriter = (ContextFileWriter) writer;
}
/**
*/
public int acquireContextId(LockingContext context) throws IOException {
assert context != null;
- removeGarbageCollectedKeys();
- Integer id = mCache.get(new StrongKey(context));
- if (id == null) {
+ // removeGarbageCollectedKeys();
+ //Integer id = mCache.get(new StrongKey(context));
+ Integer id = mCache.get(context.hashCode());
+ // if (mCache.get(HashMap.hash(context)) == null) {
+ if (id == null){
mLogger.finest("Creating new context ID");
id = mContextWriter.writeContext(context);
- mCache.put((new SoftKey(context, mReferenceQueue)), id);
- }
+ //mCache.put((new SoftKey(context, mReferenceQueue)), id);
+ // Intif.positionif tmp = Intif.factory.create();
+ // tmp.setPosition(id);
+ //intval.setPosition(id);
+ // mCache.put(HashMap.hash(context),tmp);
+ mCache.put(context.hashCode(),id);
+ }
+ //else
+ // id = mCache.get(HashMap.hash(context)).getPosition();
return id;
}
- private void removeGarbageCollectedKeys() {
+ public IntHashMap getMCache() {
+ return mCache;
+ }
+
+ public ContextFileWriter getMContextWriter() {
+ return mContextWriter;
+ }
+
+ public Logger getMLogger() {
+ return mLogger;
+ }
+
+
+
+ /* private void removeGarbageCollectedKeys() {
Reference e;
while ((e = mReferenceQueue.poll()) != null) {
mLogger.finest("Removing garbage-collected cached context");
public int hashCode() {
return mHash;
}
- }
+ }*/
}
//import net.jcip.annotations.ThreadSafe;
import com.enea.jcarder.common.LockingContext;
+import com.enea.jcarder.common.events.EventFileWriter;
+import com.enea.jcarder.transactionalinterfaces.trEventListener;
+import dstm2.AtomicSuperClass;
+import java.util.concurrent.Callable;
+import dstm2.Thread;
+import java.util.HashMap;
+import java.util.Vector;
/**
* This class provides static methods that are supposed to be invoked directly
* from the instrumented classes.
*/
//@ThreadSafe
-public final class StaticEventListener {
+public final class StaticEventListener{
private StaticEventListener() { }
+ //private static EventListenerIfc smListener;
private static EventListenerIfc smListener;
+ private static HashMap map= new HashMap();
+
- public synchronized static void setListener(EventListenerIfc listener) {
- smListener = listener;
+ //public synchronized static void setListener(EventListenerIfc listener) {
+ // smListener = (EventListener)listener;
+ //}
+
+ public static void trsetListener(Vector listener) {
+ //smListener = ((EventListener)(arg.get(0)));
+ smListener = (EventListenerIfc)listener.get(0);
+ // smListener = new EventListener((EventListener)(arg.get(0)));
+ // smListener.listener = new trEventListener();
+ // smListener.listener.atmoicfileds = trEventListener.factory.create();
+ // smListener.listener.atmoicfileds = ((EventListener)(arg.get(0))).listener.atmoicfileds;
+
+ /*smListener2.atmoicfileds.setCCByteBuffer(((EventListener)(arg.get(0))).getMContextCache().getMContextWriter().getMbuff().mbuffer);
+ smListener2.atmoicfileds.setCCPosiiton(((EventListener)(arg.get(0))).getMContextCache().getMContextWriter().getTest().pos);
+ smListener2.atmoicfileds.setCCShutdown(((EventListener)(arg.get(0))).getMContextCache().getMContextWriter().getShutdownHookExecuted().boolif);
+
+
+
+ smListener2.atmoicfileds.setHMap1Capacity(((EventListener)(arg.get(0))).getMContextCache().getMCache().capacity);
+ smListener2.atmoicfileds.setHMap1Position(((EventListener)(arg.get(0))).getMContextCache().getMCache().position);
+ smListener2.atmoicfileds.setHMap1Values(((EventListener)(arg.get(0))).getMContextCache().getMCache().values);
+
+ smListener2.atmoicfileds.setELNumberofMonitors(((EventListener)(arg.get(0))).getTrmNumberOfEnteredMonitors().mValue);
+
+ smListener2.atmoicfileds.setLIGByteBuffer(((EventListener)(arg.get(0))).getMLockIdGenerator().getMContextWriter().getMbuff().mbuffer);
+ smListener2.atmoicfileds.setLIGPosiiton(((EventListener)(arg.get(0))).getMLockIdGenerator().getMContextWriter().getTest().pos);
+ smListener2.atmoicfileds.setLIGShutdown(((EventListener)(arg.get(0))).getMLockIdGenerator().getMContextWriter().getShutdownHookExecuted().boolif);
+
+ smListener2.atmoicfileds.setHMap2Capacity(((EventListener)(arg.get(0))).getMLockIdGenerator().getMIdMap().capacity);
+ smListener2.atmoicfileds.setHMap2Position(((EventListener)(arg.get(0))).getMLockIdGenerator().getMIdMap().position);
+ smListener2.atmoicfileds.setHMap2Values(((EventListener)(arg.get(0))).getMLockIdGenerator().getMIdMap().values);
+
+ smListener2.atmoicfileds.setEFWByteBuffer(((EventFileWriter)((EventListener)(arg.get(0))).getMLockEventListener()).getMbuff().mbuffer);
+ smListener2.atmoicfileds.setEFWShutdown(((EventFileWriter)((EventListener)(arg.get(0))).getMLockEventListener()).getShutdownHookExecuted().boolif);
+ smListener2.atmoicfileds.setEFWCounter(((EventFileWriter)((EventListener)(arg.get(0))).getMLockEventListener()).getTrmWrittenLockEvents().mValue);*/
+
}
+
+ public static void setListener(EventListenerIfc listener) {
+ final Vector arg = new Vector();
+ arg.add(listener);
+ Thread.doIt(new Callable<Boolean>() {
+ public Boolean call() throws Exception {
+ trsetListener(arg);
+ return true;
+ }
+ });
+ }
+
+ // }
- public synchronized static EventListenerIfc getListener() {
+ public static EventListenerIfc trgetListener() {
+ /*
+ ((EventListener)smListener).getMContextCache().getMCache().capacity.getPosition();
+ ((EventListener)smListener).getMContextCache().getMCache().position.getPosition();
+ ((EventListener)smListener).getMContextCache().getMCache().values.getValues();
+ ((EventListener)smListener).getTrmNumberOfEnteredMonitors().mValue.getPosition();
+ ((EventListener)smListener).getMLockIdGenerator().getMIdMap().capacity.getPosition();
+ ((EventListener)smListener).getMLockIdGenerator().getMIdMap().position.getPosition();
+ ((EventListener)smListener).getMLockIdGenerator().getMIdMap().values.getValues();*/
return smListener;
}
+
+ public static EventListenerIfc getListener() {
+ return Thread.doIt(new Callable<EventListenerIfc>() {
+ public EventListenerIfc call() throws Exception {
+ return trgetListener();
+ }
+ });
+
+ }
/**
* This method is expected to be called from the instrumented classes.
} catch (Throwable t) {
handleError(t);
}
+ // System.out.println("here finito");
}
private static void handleError(Throwable t) {
if (className.startsWith("java.")
|| className.startsWith("javax.")
|| className.startsWith("sun.") || className.startsWith("TransactionalIO.")
- || className.startsWith("dstm2")) {
+ || className.startsWith("dstm2") || className.startsWith("org")) {
return "standard library class";
}
private void initLogger() {
Collection<Handler> handlers = new ArrayList<Handler>();
- // try {
- handlers.add(new AppendableHandler(System.out,
- Logger.Level.CONFIG,
- "{message}\n"));
- // handlers.add(new AppendableHandler(new PrintStream(new File("analyzer.log")), Logger.Level.CONFIG, "{message}\n", new TransactionalFile("analyzer.log", "rw")));
- /// } catch (FileNotFoundException ex) {
- // java.util.logging.Logger.getLogger(Analyzer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- // }
+ try {
+ // handlers.add(new AppendableHandler(System.out,
+ // Logger.Level.CONFIG,
+ // "{message}\n"));
+ handlers.add(new AppendableHandler(new PrintStream(new File("analyzer.log")), Logger.Level.CONFIG, "{message}\n", new TransactionalFile("analyzer.log", "rw")));
+ } catch (FileNotFoundException ex) {
+ java.util.logging.Logger.getLogger(Analyzer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
mLogger = new Logger(handlers, mLogLevel);
}
import com.enea.jcarder.transactionalinterfaces.Bool;
import com.enea.jcarder.transactionalinterfaces.Intif;
import com.enea.jcarder.transactionalinterfaces.bytebuffer;
-import com.enea.jcarder.transactionalinterfaces.bytebuffer.byteholder;
+import com.enea.jcarder.transactionalinterfaces.jcbuffer;
+import com.enea.jcarder.util.Counter;
import com.enea.jcarder.util.logging.Logger;
import dstm2.Init;
import dstm2.atomic;
public final class ContextFileWriter
implements ContextWriterIfc {
- private final FileChannel mChannel;
- private int mNextFilePosition = 0;
+// private final FileChannel mChannel;
+// private int mNextFilePosition = 0;
private final Logger mLogger;
- private ByteBuffer mBuffer;// = ByteBuffer.allocateDirect(8192);
- private byte[] data;
+// private ByteBuffer mBuffer = ByteBuffer.allocateDirect(8192);
RandomAccessFile raFile;
-
+// byte[] data;
+
+ //private jcbuffer mbuff;
+ //byteholder[] bytes;
private bytebuffer mbuff;
- private Intif filePosition;
private Intif test;
private Bool ShutdownHookExecuted;
TransactionalFile trraFile;
- private boolean mShutdownHookExecuted = false;
+ // private boolean mShutdownHookExecuted = false;
public ContextFileWriter(Logger logger, File file) throws IOException {
- System.out.println("d");
mbuff = new bytebuffer();
+ // mbuff = new jcbuffer();
mbuff.allocateDirect(8192);
- filePosition = new Intif();
- filePosition.init();
+
test = new Intif();
test.init();
ShutdownHookExecuted = new Bool();
ShutdownHookExecuted.init();
- data = new byte[8192];
- mBuffer = ByteBuffer.wrap(data);
+
+// data = new byte[8192];
+// mBuffer = ByteBuffer.wrap(data);
mLogger = logger;
mLogger.info("Opening for writing: " + file.getAbsolutePath());
raFile = new RandomAccessFile(file, "rw");
-
- trraFile = new TransactionalFile(file.getAbsolutePath(), "rw");
+ System.out.println(file.getAbsolutePath());
+ trraFile = new TransactionalFile(file.getPath(), "rw");
trraFile.file.setLength(0);
-// ShutdownHookExecuted.init();
+ ShutdownHookExecuted.init();
raFile.setLength(0);
- mChannel = raFile.getChannel();
+// mChannel = raFile.getChannel();
- // writeHeader();
+ writeHeader();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() { shutdownHook(); }
private void writeBuffer() throws IOException {
mbuff.flip();
- System.out.println(Thread.currentThread());
-
- // System.out.println(mbuff.remaining());
trraFile.write(mbuff.getBytes());
+
while (mbuff.hasRemaining()) {
Thread.yield();
trraFile.write(mbuff.getBytes());
- }
+ }
mbuff.clear();
}
mBuffer.putInt(ContextFileReader.MAJOR_VERSION);
mBuffer.putInt(ContextFileReader.MINOR_VERSION);
mBuffer.rewind();
- for (int i=0; i<16; i++){
- mbuff.put(mBuffer.get());
- }
+ // mybyte[0] =(byte)( foo >> 24 );
+ // mybyte[1] =(byte)( (foo << 8) >> 24 );
+ // mybyte[2] =(byte)( (foo << 16) >> 24 );
+ // mybyte[3] =(byte)( (foo << 24) >> 24 );
+ // for (int i=0; i<16; i++){
+ // mbuff.putar(mBuffer.get());
+ // }
+
//filePosition.get();
+ mbuff.put(mBuffer);
test.increment(8+4+4);
//filePosition.increment(8+4+4);
}
mBuffer.putInt(length);
mBuffer.put(encodedString);
mBuffer.rewind();
- System.out.println("---------------");
- System.out.println("int: " + length);
- System.out.println("str: " + encodedString);
- System.out.println("---------------");
- //test.increment(8+length);
+ mbuff.put(mBuffer);
- //for (int i=0; i<4+length; i++)
- // mbuff.put(mBuffer.get());
- // while (mBuffer.hasRemaining())
- // mbuff.put(mBuffer.get());
- // mbuff.put(mBuffer);
- // mbuff.put(encodedString);
- //filePosition.get();
- // test.increment(4+length);
- // test.increment(4);
- //filePosition.increment(4 + length);
+ //for (int j=0; j<4+length; j++){
+ // mbuff.factory2.create();
+ //}
+ //mbuff.put(mBuffer.get());
+ test.increment(4+length);
+ //
+
}
private void writeInteger(int i) throws IOException {
- // System.out.println("int");
assureBufferCapacity(4);
ByteBuffer mBuffer = ByteBuffer.allocateDirect(4);
mBuffer.putInt(i);
- System.out.println("---------------");
- System.out.println("int: " + i);
-
-
- System.out.println("---------------");
- for (int j=0; j<4; j++){
- // mbuff.put(mBuffer.get());
- }
- // filePosition.get();
- //test.increment(4);
- //filePosition.increment(4);
+ mBuffer.rewind();
+ mbuff.put(mBuffer);
+ //for (int j=0; j<4; j++){
+ // mbuff.factory2.create();
+ //mbuff.put(mBuffer.get());
+ //}
+ test.increment(4);
}
- public int trwriteLock(Vector arg) throws IOException {
+ public int writeLock(Lock lock) throws IOException {
int startPosition = test.get();
- //writeString(((Lock)arg.get(0)).getClassName());
- //writeInteger(((Lock)arg.get(0)).getObjectId());
+ writeString(lock.getClassName());
+ writeInteger(lock.getObjectId());
- ByteBuffer encodedString = ContextFileReader.CHARSET.encode(((Lock)arg.get(0)).getClassName());
- final int length = encodedString.remaining();
- ByteBuffer mBuffer = ByteBuffer.allocateDirect(8+ length);
- mBuffer.putInt(length);
- mBuffer.put(encodedString);
- mBuffer.putInt(((Lock)arg.get(0)).getObjectId());
- mBuffer.rewind();
- // assureBufferCapacity(8+length);
- for (int j=0; j<(8+length); j++){
- byte value = mBuffer.get();
- //if (mbuff.mbuffer.getByteHolder().get(mbuff.mbuffer.getPosition()) == null)
- // mbuff.mbuffer.getByteHolder().set(mbuff.mbuffer.getPosition(), mbuff.factory2.create());
- AtomicArray<byteholder> ar = mbuff.mbuffer.getByteHolder();
- byteholder bh = mbuff.factory2.create();
- bh.setByte(value);
- mbuff.mbuffer.getByteHolder().set(mbuff.mbuffer.getPosition(),bh);
- mbuff.mbuffer.setPosition(mbuff.mbuffer.getPosition()+1);
- }
-
- /*System.out.println("---------------");
- System.out.println("int: " + length);
- System.out.println("str: " + encodedString);
- System.out.println("int: " + ((Lock)arg.get(0)).getObjectId());
- System.out.println("---------------");*/
- test.increment(8+length);
+ // ByteBuffer encodedString = ContextFileReader.CHARSET.encode(((Lock)arg.get(0)).getClassName());
+ // final int length = encodedString.remaining();
+ // ByteBuffer mBuffer = ByteBuffer.allocateDirect(8+ length);
+ // mBuffer.putInt(length);
+ // mBuffer.put(encodedString);
+ // mBuffer.putInt(((Lock)arg.get(0)).getObjectId());
+ // mBuffer.rewind();
+ // assureBufferCapacity(8+length);
+ // for (int j=0; j<(8+length); j++){
+ // byte value = mBuffer.get();
+ // mbuff.put(value);
+ // }
+ // mbuff.put(mBuffer);
+ // test.increment(8+length);
flushBufferIfNeeded();
return startPosition;
+
}
- public int writeLock(Lock lock) throws IOException {
+ /* public int writeLockWrapper(Lock lock) throws IOException {
// System.out.println("lock");
int result = 0;
try{
public Integer call() {
try {
// System.out.println(Thread.currentThread() + " alockborted in committing");
- return trwriteLock(arg);
+ return writeLock(arg);
// System.out.println(Thread.currentThread() + " NO???? alockborted in committing");
} catch (IOException ex) {
java.util.logging.Logger.getLogger(ContextFileWriter.class.getName()).log(Level.SEVERE, null, ex);
}finally{
return result;
}
- }
+ }*/
- public int trwriteContext(LockingContext context)
+ public int writeContext(LockingContext context)
throws IOException {
int startPosition = test.get();
+ writeString(context.getThreadName());
+ writeString(context.getLockReference());
+ writeString(context.getMethodWithClass());
- // writeString(context.getThreadName());
- // writeString(context.getLockReference());
- // writeString(context.getMethodWithClass());
-
- ByteBuffer encodedString = ContextFileReader.CHARSET.encode(context.getThreadName());
- final int length = encodedString.remaining();
- ByteBuffer encodedString2 = ContextFileReader.CHARSET.encode(context.getLockReference());
- final int length2 = encodedString2.remaining();
- ByteBuffer encodedString3 = ContextFileReader.CHARSET.encode(context.getMethodWithClass());
- final int length3 = encodedString3.remaining();
- ByteBuffer mBuffer = ByteBuffer.allocateDirect(12+length+length2+length3);
+ // ByteBuffer encodedString = ContextFileReader.CHARSET.encode(context.getThreadName());
+ // final int length = encodedString.remaining();
+ // ByteBuffer encodedString2 = ContextFileReader.CHARSET.encode(context.getLockReference());
+ // final int length2 = encodedString2.remaining();
+ // ByteBuffer encodedString3 = ContextFileReader.CHARSET.encode(context.getMethodWithClass());
+ // final int length3 = encodedString3.remaining();
+ // ByteBuffer mBuffer = ByteBuffer.allocateDirect(12+length+length2+length3);
- mBuffer.putInt(length);
- mBuffer.put(encodedString);
- mBuffer.putInt(length2);
- mBuffer.put(encodedString2);
- mBuffer.putInt(length3);
- mBuffer.put(encodedString3);
- mBuffer.rewind();
- /* System.out.println("------");
- System.out.println("int: " + length);
- System.out.println("str: " + encodedString);
- System.out.println("int: " + length2);
- System.out.println("str: " + encodedString2);
- System.out.println("int: " + length3);
- System.out.println("str: " + encodedString3);
- System.out.println("------");*/
+ // mBuffer.putInt(length);
+ // mBuffer.put(encodedString);
+ // mBuffer.putInt(length2);
+ // mBuffer.put(encodedString2);
+ // mBuffer.putInt(length3);
+ // mBuffer.put(encodedString3);
+ // mBuffer.rewind();
+
- // assureBufferCapacity(12 + length + length2 + length3);
- for (int j=0;j<(12+length +length2 +length3);j++){
- // mbuff.put(mBuffer.get());
- byte value = mBuffer.get();
- //if (mbuff.mbuffer.getByteHolder().get(mbuff.mbuffer.getPosition()) == null)
- // mbuff.mbuffer.getByteHolder().set(mbuff.mbuffer.getPosition(), mbuff.factory2.create());
- AtomicArray<byteholder> ar = mbuff.mbuffer.getByteHolder();
- byteholder bh = mbuff.factory2.create();
- bh.setByte(value);
- mbuff.mbuffer.getByteHolder().set(mbuff.mbuffer.getPosition(),bh);
- mbuff.mbuffer.getByteHolder().get(mbuff.mbuffer.getPosition()).setByte(value);
- mbuff.mbuffer.setPosition(mbuff.mbuffer.getPosition()+1);
- }
+ // assureBufferCapacity(12 + length + length2 + length3);
+ //for (int j=0;j<(12+length +length2 +length3);j++){
+ // byte value = mBuffer.get();
+ // mbuff.put(value);
+ // }
+ // mbuff.put(mBuffer);
- test.increment(12+length +length2 +length3);
+ //test.increment(12+length +length2 +length3);
flushBufferIfNeeded();
return startPosition;
+ // mbuff.put((byte)2);
+ // return -1;
}
- public int writeContext(LockingContext context)
+/* public int writeContext(LockingContext context)
{
-
int startPosition = -2;
try{
final LockingContext c = context;
System.out.println(Thread.currentThread() + " context graceful exc");
}
finally{
- // System.out.println(Thread.currentThread() + " con");
+ // System.out.println(Thread.currentThread() + " con");
+ // Throwable t = new Throwable();
+//StackTraceElement[] es = t.getStackTrace();
+//for ( int i=0; i<es.length; i++ )
+ //{
+ //StackTraceElement e = es[i];
+ //System.out.println( " in class:" + e.getClassName()
+ // + " in source file:" + e.getFileName()
+ // + " in method:" + e.getMethodName()
+ // + " at line:" + e.getLineNumber()
+ // + " " + ( e.isNativeMethod() ? "native" : "" ) );
+ //}
+
return startPosition;
}
- }
+ }*/
private void flushBufferIfNeeded() throws IOException {
if (ShutdownHookExecuted.isTrue()) {
writeBuffer();
}
}
+
+ public Bool getShutdownHookExecuted() {
+ return ShutdownHookExecuted;
+ }
+
+ public void setShutdownHookExecuted(Bool ShutdownHookExecuted) {
+ this.ShutdownHookExecuted = ShutdownHookExecuted;
+ }
+
+
+
+ public bytebuffer getMbuff() {
+ return mbuff;
+ }
+
+ public void setMbuff(bytebuffer mbuff) {
+ this.mbuff = mbuff;
+ }
+
+ public RandomAccessFile getRaFile() {
+ return raFile;
+ }
+
+ public void setRaFile(RandomAccessFile raFile) {
+ this.raFile = raFile;
+ }
+
+ public Intif getTest() {
+ return test;
+ }
+
+ public void setTest(Intif test) {
+ this.test = test;
+ }
+
+ public TransactionalFile getTrraFile() {
+ return trraFile;
+ }
+
+ public void setTrraFile(TransactionalFile trraFile) {
+ this.trraFile = trraFile;
+ }
+
- /*
- private void writeString(String s) throws IOException {
+
+ /* private void writeString(String s) throws IOException {
ByteBuffer encodedString = ContextFileReader.CHARSET.encode(s);
final int length = encodedString.remaining();
assureBufferCapacity(4 + length);
mBuffer.putInt(length);
mBuffer.put(encodedString);
- System.out.println("------");
- System.out.println("int: " + length);
- System.out.println("str: " + encodedString);
- System.out.println("------");
+ for (int j =0; j<4+length; j++)
+ mbuff.put(mBuffer.get());
+ // datastindex++;
+ //}
mNextFilePosition += 4 + length;
}
System.out.println("shut");
try {
if (mChannel.isOpen()) {
+ System.out.println("shut");
writeBuffer();
}
} catch (IOException e) {
private void writeInteger(int i) throws IOException {
assureBufferCapacity(4);
mBuffer.putInt(i);
- System.out.println("------");
- System.out.println("int: " + i);
- System.out.println("------");
+ System.out.println("ffff");
+ for (int j =0; j<4; j++)
+ mbuff.put(mBuffer.get());
+ // data[dataendindex+i] = mBuffer.get();
+// datastindex++;
+ // }
mNextFilePosition += 4;
}
// Grow buffer if it can't hold the requested size.
while (mBuffer.capacity() < size) {
+ System.out.println("be ga raftam");
mBuffer = ByteBuffer.allocateDirect(2 * mBuffer.capacity());
}
}
private void writeBuffer() throws IOException {
mBuffer.flip();
- System.out.println("here " + mBuffer.array().length);
- System.out.println("Written" + mChannel.write(mBuffer));
- while (mBuffer.hasRemaining()) {
+ int rem = mBuffer.remaining();
+ int i = 0;
+ //while (mBuffer.hasRemaining()) {
+ while (i< rem) {
Thread.yield();
raFile.write(data);
- //mChannel.write(mBuffer);
+ // int written = mChannel.write(mBuffer);
+ i++;
+ // mBuffer.position(mBuffer.position() + written);
+
}
mBuffer.clear();
}
mBuffer.putInt(ContextFileReader.MAJOR_VERSION);
mBuffer.putInt(ContextFileReader.MINOR_VERSION);
mNextFilePosition += 8 + 4 + 4;
-
- // LongBuffer g;
- // Long.
- // Long.valueOf(ContextFileReader.MAGIC_COOKIE).
- // mBuffer.putLong(ContextFileReader.MAGIC_COOKIE);
- // mBuffer.putInt(ContextFileReader.MAJOR_VERSION);
- // mBuffer.putInt(ContextFileReader.MINOR_VERSION);
- // mNextFilePosition += 8 + 4 + 4;
+
}*/
}
//@ThreadSafe
import java.util.Vector;
public final class EventFileWriter implements LockEventListenerIfc {
- private final ByteBuffer mBuffer =
- ByteBuffer.allocateDirect(EVENT_LENGTH * 1024);
- private final FileChannel mFileChannel;
+// private final ByteBuffer mBuffer =
+ // ByteBuffer.allocateDirect(EVENT_LENGTH * 1024);
+ // private final FileChannel mFileChannel;
private final Logger mLogger;
- private final Counter mWrittenLockEvents;
- private boolean mShutdownHookExecuted = false;
+// private final Counter mWrittenLockEvents;
+// private boolean mShutdownHookExecuted = false;
private bytebuffer mbuff;
private Bool ShutdownHookExecuted;
- TransactionalFile traf;
- TransactionalCounter trmWrittenLockEvents;
+ private TransactionalFile traf;
+ private TransactionalCounter trmWrittenLockEvents;
+ public EventFileWriter(EventFileWriter other){
+ this.ShutdownHookExecuted = other.ShutdownHookExecuted;
+ this.ShutdownHookExecuted.boolif.setValue(other.ShutdownHookExecuted.boolif.getValue());
+ this.mLogger = other.mLogger;
+ this.mbuff = other.mbuff;
+ // this.mbuff.mbuffer.setByteHolder(other.mbuff.mbuffer.getByteHolder());
+ this.traf = other.traf;
+ this.trmWrittenLockEvents = other.trmWrittenLockEvents;
+ this.trmWrittenLockEvents.mValue.setPosition(other.trmWrittenLockEvents.mValue.getPosition());
+ }
+
public EventFileWriter(Logger logger, File file) throws IOException {
mLogger.info("Opening for writing: " + file.getAbsolutePath());
RandomAccessFile raFile = new RandomAccessFile(file, "rw");
raFile.setLength(0);
- mFileChannel = raFile.getChannel();
- mWrittenLockEvents = new Counter("Written Lock Events",
- mLogger,
- 100000);
+ // mFileChannel = raFile.getChannel();
+ // mWrittenLockEvents = new Counter("Written Lock Events",
+ // mLogger,
+ // 100000);
mbuff = new bytebuffer();
mbuff.allocateDirect(8192);
});
}
- private void writeHeader() throws IOException {
+ /* private void writeHeader() throws IOException {
mBuffer.putLong(EventFileReader.MAGIC_COOKIE);
mBuffer.putInt(EventFileReader.MAJOR_VERSION);
mBuffer.putInt(EventFileReader.MINOR_VERSION);
writeBuffer();
- }
+ }*/
- private void trwriteHeader() throws IOException {
+ private void writeHeader() throws IOException {
ByteBuffer mBuffer = ByteBuffer.allocateDirect(16);
mBuffer.putLong(EventFileReader.MAGIC_COOKIE);
mBuffer.putInt(EventFileReader.MAJOR_VERSION);
mBuffer.putInt(EventFileReader.MINOR_VERSION);
mBuffer.rewind();
- for (int i=0; i<16; i++){
+ /*for (int i=0; i<16; i++){
mbuff.put(mBuffer.get());
- }
+ }*/
+
+ mbuff.put(mBuffer);
writeBuffer();
}
- public synchronized void onLockEvent(int lockId,
+ /*public synchronized void onLockEvent(int lockId,
int lockingContextId,
int lastTakenLockId,
int lastTakenLockingContextId,
if (mBuffer.remaining() < EVENT_LENGTH || mShutdownHookExecuted) {
writeBuffer();
}
- }
+ }*/
public void tronLockEvent(Vector arg) throws IOException {
mBuffer.putLong((Long)arg.get(4));
mBuffer.rewind();
- for (int i=0; i<24; i++){
- mbuff.put(mBuffer.get());
- }
+ //for (int i=0; i<24; i++){
+ // mbuff.put(mBuffer.get());
+ //}
+
+ mbuff.put(mBuffer);
trmWrittenLockEvents.increment();
if (mbuff.remaining() < EVENT_LENGTH || ShutdownHookExecuted.isTrue()) {
}
}
- public void trLockEventWrapper(int lockId,
+ public void onLockEvent(int lockId,
int lockingContextId,
int lastTakenLockId,
int lastTakenLockingContextId,
}
- private void writeBuffer() throws IOException {
+ /* private void writeBuffer() throws IOException {
mBuffer.flip();
mFileChannel.write(mBuffer);
while (mBuffer.hasRemaining()) {
mFileChannel.write(mBuffer);
}
mBuffer.clear();
- }
+ }*/
- private void trwriteBuffer() throws IOException {
+ private void writeBuffer() throws IOException {
mbuff.flip();
traf.write(mbuff.getBytes());
while (mbuff.hasRemaining()) {
}
- public synchronized void close() throws IOException {
+ /*public synchronized void close() throws IOException {
writeBuffer();
mFileChannel.close();
- }
+ }*/
- public void trclose() throws IOException {
+ public void close() throws IOException {
// System.out.println("clo");
try{
Thread.doIt(new Callable<Boolean>() {
}
}
- private synchronized void shutdownHook() {
+ /* private synchronized void shutdownHook() {
try {
if (mFileChannel.isOpen()) {
writeBuffer();
e.printStackTrace();
}
mShutdownHookExecuted = true;
- }
+ }*/
- private void trshutdownHook() {
+ private void shutdownHook() {
System.out.println(Thread.currentThread() + " ashut ddddddborted in committing");
try{
Thread.doIt(new Callable<Boolean>() {
System.out.println(Thread.currentThread() + " shut graceful exc");
}
}
+
+ public Bool getShutdownHookExecuted() {
+ return ShutdownHookExecuted;
+ }
+
+ public void setShutdownHookExecuted(Bool ShutdownHookExecuted) {
+ this.ShutdownHookExecuted = ShutdownHookExecuted;
+ }
+
+ public bytebuffer getMbuff() {
+ return mbuff;
+ }
+
+ public void setMbuff(bytebuffer mbuff) {
+ this.mbuff = mbuff;
+ }
+
+ public TransactionalFile getTraf() {
+ return traf;
+ }
+
+ public void setTraf(TransactionalFile traf) {
+ this.traf = traf;
+ }
+
+ public TransactionalCounter getTrmWrittenLockEvents() {
+ return trmWrittenLockEvents;
+ }
+
+ public void setTrmWrittenLockEvents(TransactionalCounter trmWrittenLockEvents) {
+ this.trmWrittenLockEvents = trmWrittenLockEvents;
+ }
+
+
}
*/
-import com.enea.jcarder.transactionalinterfaces.bytebuffer.byteholder;
+
import dstm2.AtomicArray;
import dstm2.atomic;
import dstm2.Thread;
*
* @author navid
*/
-public class Bool {
+public class Bool{
static Factory<boolif> factory = Thread.makeFactory(boolif.class);
- boolif boolif;
+ public boolif boolif;
public void init(){
boolif = factory.create();
package com.enea.jcarder.transactionalinterfaces;
+import dstm2.AtomicSuperClass;
import dstm2.atomic;
import dstm2.Thread;
import dstm2.factory.Factory;
public static Factory<positionif> factory = Thread.makeFactory(positionif.class);
- positionif pos;
+ public positionif pos;
public void init(){
return pos.getPosition();
}
- @atomic public interface positionif{
+ @atomic public interface positionif extends AtomicSuperClass{
public int getPosition();
public void setPosition(int pos);
}
package com.enea.jcarder.transactionalinterfaces;
-import com.enea.jcarder.transactionalinterfaces.bytebuffer.byteholder;
+//import com.enea.jcarder.transactionalinterfaces.bytebuffer.byteholder;
+import com.enea.jcarder.util.Counter;
import dstm2.AtomicArray;
+import dstm2.AtomicByteArray;
import dstm2.atomic;
import dstm2.Thread;
import dstm2.factory.Factory;
static Factory<bytebufferif> factory = Thread.makeFactory(bytebufferif.class);
- public static Factory<byteholder> factory2 = Thread.makeFactory(byteholder.class);
+// public static Factory<byteholder> factory2 = Thread.makeFactory(byteholder.class);
public bytebufferif mbuffer;
}
public void put(byte value){
- if (mbuffer.getByteHolder().get(mbuffer.getPosition()) == null)
- mbuffer.getByteHolder().set(mbuffer.getPosition(), factory2.create());
- mbuffer.getByteHolder().get(mbuffer.getPosition()).setByte(value);
- mbuffer.setPosition(mbuffer.getPosition()+1);
+
+ AtomicByteArray ar = mbuffer.getByteHolderar();
+
+ ar.set(mbuffer.getPosition(),value);
+ mbuffer.setPosition(mbuffer.getPosition()+1);
+
}
+
+
public void put(ByteBuffer value){
if (remaining() < value.remaining())
throw new BufferOverflowException();
- for (int i=0; i<value.remaining(); i++){
- if (mbuffer.getByteHolder().get(mbuffer.getPosition()) == null)
- mbuffer.getByteHolder().set(mbuffer.getPosition(), factory2.create());
- mbuffer.getByteHolder().get(mbuffer.getPosition()).setByte(value.get());
+ /*AtomicArray<byteholder> ar = mbuffer.getByteHolder();
+ while(value.hasRemaining()){
+ byteholder bh = mbuffer.getByteHolder().get(mbuffer.getPosition());
+ if ((bh = mbuffer.getByteHolder().get(mbuffer.getPosition())) == null){
+ bh = factory2.create();
+ }
+ bh.setByte(value.get());
+ ar.set(mbuffer.getPosition(),bh);
mbuffer.setPosition(mbuffer.getPosition()+1);
+ }*/
+ AtomicByteArray ar = mbuffer.getByteHolderar();
+ while(value.hasRemaining()){
+
+
+ ar.set(mbuffer.getPosition(),Byte.valueOf(value.get()));
+ mbuffer.setPosition(mbuffer.getPosition()+1);
+ }
+ // while(value.hasRemaining()){
+ // if (mbuffer.getByteHolder().get(mbuffer.getPosition()) == null)
+ // mbuffer.getByteHolder().set(mbuffer.getPosition(), factory2.create());
+ // mbuffer.getByteHolder.set((mbuffer.getPosition()), value.get());
+ // mbuffer.setPosition(mbuffer.getPosition()+1);
//System.out.println("sss");
- }
+ //}
}
public bytebuffer allocateDirect(int capacity){
+ System.out.println("allocate " + capacity);
mbuffer = factory.create();
- mbuffer.setByteHolder(new AtomicArray<byteholder>(byteholder.class,capacity));
+ mbuffer.setByteHolderar(new AtomicByteArray(Byte.class,capacity));
mbuffer.setPosition(0);
mbuffer.setLimit(capacity);
mbuffer.setCapacity(capacity);
- AtomicArray<byteholder> ar = mbuffer.getByteHolder();
- //for (int i=0; i<capacity; i++){
+ // for (int i=0; i<capacity; i++){
// ar.set(i, factory2.create());
//}
// for (int i=0; i<capacity; i++)
- // mbuffer.getByteHolder().set(i, factory2.create());
+ // mbuffer.getByteHolder().set(i, factory2.create());
// mbuffer.getByteHolder().set(0, factory2.create());
// mbuffer.getByteHolder().get(0).setByte((byte)2);
return this;
}
public byte[] getBytes(){
+ // System.out.println("getbytes");
int length = remaining();
byte[] result = new byte[length];
int i = 0;
- while (hasRemaining()) {
+ /* while (hasRemaining()) {
result[i] = mbuffer.getByteHolder().get(mbuffer.getPosition()).getByte();
mbuffer.setPosition(mbuffer.getPosition()+1);
i++;
+ }*/
+ while (hasRemaining()) {
+ result[i] = mbuffer.getByteHolderar().get(mbuffer.getPosition()).byteValue();
+ mbuffer.setPosition(mbuffer.getPosition()+1);
+ i++;
}
return result;
}
void setPosition(int value);
int getCapacity();
void setCapacity(int value);
- AtomicArray<byteholder> getByteHolder();
- void setByteHolder(AtomicArray<byteholder> bytes);
- }
-
- @atomic public interface byteholder{
- byte getByte();
- void setByte(byte value);
+ AtomicByteArray getByteHolderar();
+ void setByteHolderar(AtomicByteArray bytes);
+
}
+
Properties props = new Properties();
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
props.load(classLoader.getResourceAsStream("build.properties"));
+ // return null;
return props;
}
}
final Logger mLogger;
int mValue = 0;
+
public Counter(String name, Logger logger, int logInterval) {
mName = name;
mLogger = logger;
*/
public class TransactionalCounter {
- final int mLogIntervall;
- final String mName;
- final Logger mLogger;
- Intif.positionif mValue;
+ public final int mLogIntervall;
+ public final String mName;
+ public final Logger mLogger;
+ public Intif.positionif mValue;
public TransactionalCounter(String name, Logger logger, int logInterval) {
mValue = Intif.factory.create();
String formattedMessage = mMessageFormat
.replace("{level}", level.toString())
.replace("{message}", message);
- synchronized (mDestination) {
- mDestination.append(formattedMessage);
- }
- //traf.write(formattedMessage.getBytes());
+ // synchronized (mDestination) {
+ // mDestination.append(formattedMessage);
+ // }
+ traf.write(formattedMessage.getBytes());
} catch (IOException e) {
// Ignore.
}