*/
#include "tm.h"
+#include "garbage.h"
/* Thread transaction variables */
__thread objstr_t *t_cache;
* This function creates objects in the transaction record
* =======================================================
*/
-objheader_t *transCreateObj(unsigned int size) {
- objheader_t *tmp = (objheader_t *) objstrAlloc(&t_cache, (sizeof(objheader_t) + size));
- OID(tmp) = getNewOID();
+objheader_t *transCreateObj(void * ptr, unsigned int size) {
+ objheader_t *tmp = mygcmalloc(ptr, (sizeof(objheader_t) + size));
+ objheader_t *retval=&tmp[1];
tmp->version = 1;
- STATUS(tmp) = NEW;
- t_chashInsert(OID(tmp), tmp);
+ t_chashInsert((unsigned int) retval, retval);
-#ifdef COMPILER
- return &tmp[1]; //want space after object header
-#else
- return tmp;
-#endif
+ return retval; //want space after object header
}
/* This functions inserts randowm wait delays in the order of msec
int size;
/* Read from the main heap */
- objheader_t *header = (objheader_t *)(((char *)(&oid)) - sizeof(objheader_t));
+ objheader_t *header = (objheader_t *)(((char *)oid) - sizeof(objheader_t));
if(read_trylock(STATUSPTR(header))) { //Can further acquire read locks
GETSIZE(size, header);
size += sizeof(objheader_t);
/* Insert into cache's lookup table */
STATUS(objcopy)=0;
t_chashInsert(OID(header), objcopy);
-#ifdef COMPILER
return &objcopy[1];
-#else
- return objcopy;
-#endif
}
read_unlock(STATUSPTR(header));
}
* ================================================================
*/
int transCommit() {
- char finalResponse;
+ int finalResponse;
char treplyretry; /* keeps track of the common response that needs to be sent */
do {
if(treplyretry && (finalResponse == TRANS_SOFT_ABORT)) {
randomdelay();
}
- if(finalResponse != TRANS_ABORT || finalResponse != TRANS_COMMIT || finalResponse != TRANS_SOFT_ABORT) {
+ if(finalResponse != TRANS_ABORT && finalResponse != TRANS_COMMIT && finalResponse != TRANS_SOFT_ABORT) {
printf("Error: in %s() Unknown outcome", __func__);
exit(-1);
}
* - decides if a transaction should commit or abort
* ==================================================
*/
-char traverseCache(char *treplyretry) {
+int traverseCache(char *treplyretry) {
/* Create info for newly creately objects */
int numcreated=0;
unsigned int oidcreated[c_numelements];
int vnomatch;
int numoidread;
int numoidmod;
- char response;
+ int response;
int i;
chashlistnode_t *ptr = c_table;
* - updates the oids locked and oids newly created
* ===========================================================================
*/
-char decideResponse(objheader_t *headeraddr, unsigned int *oidcreated, int *numcreated, unsigned int* oidrdlocked, int *numoidrdlocked,
+int decideResponse(objheader_t *headeraddr, unsigned int *oidcreated, int *numcreated, unsigned int* oidrdlocked, int *numoidrdlocked,
unsigned int*oidwrlocked, int *numoidwrlocked, int *vmatch_lock, int *vmatch_nolock, int *vnomatch, int *numoidmod, int *numoidread) {
unsigned short version = headeraddr->version;
unsigned int oid = OID(headeraddr);
#include "prelookup.h"
#include "prefetch.h"
#endif
+#ifdef STM
+#include "tm.h"
+#endif
extern int classsize[];
extern int typearray[];
#endif
-#ifdef PRECISE_GC
+#ifdef STM
+// STM Versions of allocation functions
+
+/* Object allocation function */
+__attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
+ struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
+ v->type=type;
+ return v;
+}
+
+/* Array allocation function */
+
+__attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
+ struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
+ if (length<0) {
+ printf("ERROR: negative array\n");
+ return NULL;
+ }
+ v->type=type;
+ v->___length___=length;
+ return v;
+}
+__attribute__((malloc)) void * allocate_new(void * ptr, int type) {
+ objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
+ struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
+ tmp->version = 1;
+ v->type = type;
+ return v;
+}
+
+/* Array allocation function */
+
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
+ objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
+ struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
+ tmp->version=1;
+ v->type=type;
+ if (length<0) {
+ printf("ERROR: negative array\n");
+ return NULL;
+ }
+ v->___length___=length;
+ return v;
+}
+#endif
+
+#ifndef STM
+#if defined(PRECISE_GC)
__attribute__((malloc)) void * allocate_new(void * ptr, int type) {
struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
v->type=type;
return v;
}
#endif
+#endif
/* Converts C character arrays into Java strings */