00001
00002
00003
00004
00005
00006
00007 SLATE_INLINE void heap_store_into(struct object_heap* oh, struct Object* src, struct Object* dest) {
00008
00009 if (!object_is_smallint(dest)) {
00010 assert(object_hash(dest) < ID_HASH_RESERVED);
00011 assert(object_hash(src) < ID_HASH_RESERVED);
00012 }
00013
00014 if (object_is_young(oh, dest) && object_is_old(oh, src)) {
00015 heap_remember_old_object(oh, src);
00016 }
00017 }
00018
00019 SLATE_INLINE bool_t object_is_smallint(struct Object* xxx) { return ((((word_t)xxx)&SMALLINT_MASK) == 1);}
00020 SLATE_INLINE word_t object_to_smallint(struct Object* xxx) {return ((((word_t)xxx)>>1)); }
00021 SLATE_INLINE struct Object* smallint_to_object(word_t xxx) {return ((struct Object*)(((xxx)<<1)|1)); }
00022
00023
00024 SLATE_INLINE bool_t oop_is_object(word_t xxx) { return ((((word_t)xxx)&SMALLINT_MASK) == 0); }
00025 SLATE_INLINE bool_t oop_is_smallint(word_t xxx) { return ((((word_t)xxx)&SMALLINT_MASK) == 1);}
00026 SLATE_INLINE word_t object_markbit(struct Object* xxx) { return (((xxx)->header)&MARK_MASK); }
00027 SLATE_INLINE word_t object_hash(struct Object* xxx) { return ((((xxx)->header)>>1)&ID_HASH_MAX);}
00028 SLATE_INLINE word_t object_size(struct Object* xxx) {return xxx->objectSize;}
00029 SLATE_INLINE word_t payload_size(struct Object* xxx) {return xxx->payloadSize;}
00030 SLATE_INLINE word_t object_type(struct Object* xxx) {return ((((xxx)->header)>>30)&0x3);}
00031 SLATE_INLINE word_t object_pin_count(struct Object* xxx) {return ((((xxx)->header)>>PINNED_OFFSET)&PINNED_MASK);}
00032
00033 SLATE_INLINE struct Object* get_special(struct object_heap* oh, word_t special_index) {
00034 return oh->special_objects_oop->elements[special_index];
00035 }
00036
00037 SLATE_INLINE struct Map* object_get_map(struct object_heap* oh, struct Object* o) {
00038 if (object_is_smallint(o)) return get_special(oh, SPECIAL_OOP_SMALL_INT_PROTO)->map;
00039 return o->map;
00040 }
00041
00042 SLATE_INLINE word_t object_array_size(struct Object* o) {
00043
00044 assert(object_type(o) != TYPE_OBJECT);
00045 return (payload_size(o) + sizeof(word_t) - 1) / sizeof(word_t);
00046
00047 }
00048
00049 SLATE_INLINE word_t byte_array_size(struct ByteArray* o) {
00050 return payload_size((struct Object*)o);
00051 }
00052
00053
00054 SLATE_INLINE word_t array_size(struct OopArray* x) {
00055 return object_array_size((struct Object*) x);
00056 }
00057
00058
00059 SLATE_INLINE word_t object_byte_size(struct Object* o) {
00060 if (object_type(o) == TYPE_OBJECT) {
00061 return object_array_offset(o);
00062 }
00063 return object_array_offset(o) + payload_size(o);
00064
00065 }
00066
00067 SLATE_INLINE word_t object_total_size(struct Object* o) {
00068
00069
00070 return object_word_size(o)*sizeof(word_t);
00071
00072 }
00073
00074
00075 SLATE_INLINE void heap_pin_object(struct object_heap* oh, struct Object* x) {
00076
00077
00078 if (object_is_smallint(x)) return;
00079 assert(object_hash(x) < ID_HASH_RESERVED);
00080
00081 object_increment_pin_count(x);
00082 }
00083
00084 SLATE_INLINE void heap_unpin_object(struct object_heap* oh, struct Object* x) {
00085
00086
00087
00088 if (object_is_smallint(x)) return;
00089 object_decrement_pin_count(x);
00090 }
00091
00092
00093 SLATE_INLINE void object_increment_pin_count(struct Object* xxx) {
00094 word_t count = ((((xxx)->header)>>PINNED_OFFSET)&PINNED_MASK);
00095 assert (count != PINNED_MASK);
00096 count++;
00097 #if GC_BUG_CHECK
00098 if (count > 10) {
00099 printf("inc %d ", (int)count); print_object(xxx);
00100 }
00101 #endif
00102 if (count == PINNED_MASK) {
00103 assert(0);
00104 }
00105 xxx->header &= ~(PINNED_MASK << PINNED_OFFSET);
00106 xxx->header |= count << PINNED_OFFSET;
00107 }
00108
00109
00110 SLATE_INLINE void object_decrement_pin_count(struct Object* xxx) {
00111 word_t count = ((((xxx)->header)>>PINNED_OFFSET)&PINNED_MASK);
00112
00113
00114 #if GC_BUG_CHECK
00115 if (count > 10) {
00116 printf("dec %d ", (int)count); print_object(xxx);
00117 }
00118 #endif
00119 if (count == 0) return;
00120 count--;
00121 xxx->header &= ~(PINNED_MASK << PINNED_OFFSET);
00122 xxx->header |= count << PINNED_OFFSET;
00123 }
00124
00125
00126 SLATE_INLINE bool_t object_is_old(struct object_heap* oh, struct Object* oop) {
00127 return (oh->memoryOld <= (byte_t*)oop && (byte_t*)oh->memoryOld + oh->memoryOldSize > (byte_t*)oop);
00128
00129 }
00130
00131 SLATE_INLINE bool_t object_is_young(struct object_heap* oh, struct Object* obj) {
00132 return (oh->memoryYoung <= (byte_t*)obj && (byte_t*)oh->memoryYoung + oh->memoryYoungSize > (byte_t*)obj);
00133
00134 }
00135
00136 SLATE_INLINE bool_t object_in_memory(struct object_heap* oh, struct Object* oop, byte_t* memory, word_t memorySize) {
00137 return (memory <= (byte_t*)oop && (byte_t*)memory + memorySize > (byte_t*)oop);
00138
00139 }
00140
00141 SLATE_INLINE struct Object* object_after(struct object_heap* heap, struct Object* o) {
00142
00143 assert(object_total_size(o) != 0);
00144
00145 return (struct Object*)inc_ptr(o, object_total_size(o));
00146 }
00147
00148 SLATE_INLINE bool_t object_is_free(struct Object* o) {
00149
00150 return (object_hash(o) >= ID_HASH_RESERVED);
00151 }
00152
00153 SLATE_INLINE byte_t* inc_ptr(struct Object* obj, word_t amt) {
00154 return ((byte_t*)obj + amt);
00155 }
00156
00157 SLATE_INLINE word_t object_word_size(struct Object* o) {
00158
00159 if (object_type(o) == TYPE_OBJECT) {
00160 return object_size(o);
00161 }
00162 return object_size(o) + (payload_size(o) + sizeof(word_t) - 1) / sizeof(word_t);
00163
00164 }
00165
00166 SLATE_INLINE struct Object* object_slot_value_at_offset(struct Object* o, word_t offset) {
00167
00168 return (struct Object*)*((word_t*)inc_ptr(o, offset));
00169
00170 }
00171
00172 SLATE_INLINE word_t hash_selector(struct object_heap* oh, struct Symbol* name, struct Object* arguments[], word_t n) {
00173 word_t hash = (word_t) name;
00174 word_t i;
00175 for (i = 0; i < n; i++) {
00176 hash ^= object_hash((struct Object*)object_get_map(oh, arguments[i]));
00177 }
00178 return hash;
00179 }
00180
00181
00182 #ifdef SLATE_USE_RDTSC
00183 SLATE_INLINE volatile int64_t getRealTimeClock() {
00184 register long long TSC asm("eax");
00185 asm volatile (".byte 15, 49" : : : "eax", "edx");
00186 return TSC;
00187 }
00188 #else
00189 SLATE_INLINE volatile int64_t getRealTimeClock() {
00190 return getTickCount();
00191 }
00192 #endif