missing changes
[IRC.git] / Robust / src / Runtime / object.c
1 #include "object.h"
2 #ifdef MULTICORE
3 #include "runtime_arch.h"
4 #else
5 #include "stdio.h"
6 #endif
7 #include "stdlib.h"
8
9 #ifdef THREADS
10 #include "thread.h"
11 #endif
12 #ifndef MULTICORE
13 #include "mlp_lock.h"
14 #endif
15
16 #ifndef MAC
17 __thread struct lockvector lvector;
18 __thread int mythreadid;
19 #else
20
21 #endif
22
23 #ifdef D___Object______nativehashCode____
24 int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___) {
25   return (int)((INTPTR) VAR(___this___));
26 }
27 #endif
28
29 #ifdef D___Object______hashCode____
30 int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
31   if (!VAR(___this___)->___cachedHash___) {
32     VAR(___this___)->___cachedHash___=1;
33     VAR(___this___)->___cachedCode___=(int)((INTPTR)VAR(___this___));
34   }
35   return VAR(___this___)->___cachedCode___;
36 }
37 #endif
38
39 #ifdef D___Object______getType____
40 int CALL01(___Object______getType____, struct ___Object___ * ___this___) {
41   return ((int *)VAR(___this___))[0];
42 }
43 #endif
44
45 #ifdef THREADS
46 #ifdef D___Object______MonitorEnter____
47 void CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
48 #ifdef MAC
49   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
50   int self=(int)(long)pthread_getspecific(macthreadid);
51 #else
52   struct lockvector *lptr=&lvector;
53   int self=mythreadid;
54 #endif
55   struct lockpair *lpair=&lptr->locks[lptr->index++];
56   lpair->object=VAR(___this___);
57
58   if (self==VAR(___this___)->tid) {
59     lpair->islastlock=0;
60   } else {
61     lpair->islastlock=1;
62     while(1) {
63       if (VAR(___this___)->tid==0) {
64         if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
65           return;
66         }
67       }
68       {
69 #ifdef PRECISE_GC
70         if (unlikely(needtocollect))
71           checkcollect((struct garbagelist *)___params___);
72 #endif
73       }
74     }
75   }
76 }
77 #endif
78
79
80 #ifdef D___Object______notify____
81 void CALL01(___Object______notify____, struct ___Object___ * ___this___) {
82   VAR(___this___)->notifycount++;
83 }
84 #endif
85
86 #ifdef D___Object______notifyAll____
87 void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___) {
88   VAR(___this___)->notifycount++;
89 }
90 #endif
91
92 #ifdef D___Object______wait____
93 void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
94 #ifdef MAC
95   int self=(int)(long)pthread_getspecific(macthreadid);
96 #else
97   int self=mythreadid;
98 #endif
99   int notifycount=VAR(___this___)->notifycount;
100   BARRIER();
101   VAR(___this___)->tid=0;
102   BARRIER();
103   
104   while(notifycount==VAR(___this___)->notifycount) {
105 #ifdef PRECISE_GC
106     if (unlikely(needtocollect))
107       checkcollect((struct garbagelist *)___params___);
108 #endif
109   }
110
111   while(1) {
112     if (VAR(___this___)->tid==0) {
113       if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
114         BARRIER();
115         return;
116       }
117     }
118 #ifdef PRECISE_GC
119     if (unlikely(needtocollect))
120       checkcollect((struct garbagelist *)___params___);
121 #endif
122   }
123 }
124 #endif
125
126 #ifdef D___Object______MonitorExit____
127 void CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
128 #ifdef MAC
129   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
130 #else
131   struct lockvector *lptr=&lvector;
132 #endif
133   struct lockpair *lpair=&lptr->locks[--lptr->index];
134   
135   if (lpair->islastlock) {
136     MBARRIER();
137     lpair->object->tid=0;
138   }
139 }
140 #endif
141 #endif