3 * Contains conterparts of special classes as C structs.
11 #define CLASS_MASK 0x00FF
14 #define GC_MASK 0x2000
17 #define IS_ARRAY_MASK 0x4000
18 #define IS_ARRAY_SHIFT 14
20 #define IS_ALLOCATED_MASK 0x8000
21 #define IS_ALLOCATED_SHIFT 15
23 #define ARRAY_LENGTH_MASK 0x01FF
24 #define ARRAY_LENGTH_SHIFT 0
26 #define ELEM_TYPE_MASK 0x1E00
27 #define ELEM_TYPE_SHIFT 9
29 #define FREE_BLOCK_SIZE_MASK 0x7FFF
30 #define FREE_BLOCK_SIZE_SHIFT 0
32 #define is_array(OBJ_) ((OBJ_)->flags.objects.isArray)
33 #define is_allocated(OBJ_) ((OBJ_)->flags.freeBlock.isAllocated)
34 #define get_monitor_count(OBJ_) ((OBJ_)->monitorCount)
35 #define is_gc(OBJ_) ((OBJ_)->flags.objects.mark)
37 // Double-check these data structures with the
38 // Java declaration of each corresponding class.
41 * Object class native structure
43 typedef struct S_Object
48 * -- bits 0-14: Size of free block in words.
49 * -- bit 15 : Zero (not allocated).
51 * -- bits 0-7 : Class index.
52 * -- bits 8-12: Unused.
53 * -- bit 13 : Garbage collection mark.
54 * -- bit 14 : Zero (not an array).
55 * -- bit 15 : One (allocated).
57 * -- bits 0-8 : Array length (0-511).
58 * -- bits 9-12: Element type.
59 * -- bit 13 : Garbage collection mark.
60 * -- bit 14 : One (is an array).
61 * -- bit 15 : One (allocated).
69 TWOBYTES isAllocated:1;
70 } __attribute__((packed)) freeBlock;
78 } __attribute__((packed)) objects;
85 TWOBYTES isAllocated:1;
86 } __attribute__((packed)) arrays;
87 } __attribute__((packed)) flags;
90 * Synchronization state.
95 } __attribute__((packed)) Object;
98 * Thread class native structure
100 typedef struct S_Thread
102 Object _super; // Superclass object storage
104 REFERENCE nextThread; // Intrinsic circular list of threads
105 JINT waitingOn; // Object who's monitor we want
106 JINT sleepUntil; // Time to wake up
107 JINT stackFrameArray; // Array of stack frames
108 JINT stackArray; // The stack itself
109 JBYTE stackFrameArraySize; // Number of stack frames in use.
110 JBYTE monitorCount; // Saved monitor depth for context switches
111 JBYTE threadId; // Unique thread ID
112 JBYTE state; // RUNNING, DEAD, etc.
113 JBYTE priority; // The priority
114 JBYTE interruptState; // INTERRUPT_CLEARED, INTERRUPT_REQUESTED, ...
115 JBYTE daemon; // true == daemon thread
119 * Runtime class native structure. Doesn't actually contain
120 * any instance data. Maybe it ought to? Like ALL of the leJOS
121 * specific runtime instance data?
123 typedef struct S_Runtime
129 * String class native structure
131 typedef struct S_String
135 REFERENCE characters;
141 static inline TWOBYTES get_array_length (Object *obj)
144 aux = obj->flags.all & ARRAY_LENGTH_MASK;
145 #if (ARRAY_LENGTH_SHIFT == 0)
148 return (aux >> ARRAY_LENGTH_SHIFT);
152 static inline TWOBYTES get_element_type (Object *obj)
155 aux = obj->flags.all & ELEM_TYPE_MASK;
156 #if (ELEM_TYPE_SHIFT == 0)
159 return (aux >> ELEM_TYPE_SHIFT);
163 static inline TWOBYTES get_na_class_index (Object *obj)
166 aux = obj->flags.all & CLASS_MASK;
167 #if (CLASS_SHIFT == 0)
170 return (aux >> CLASS_SHIFT);
177 #define get_array_length(ARR_) (((ARR_)->flags.all & ARRAY_LENGTH_MASK) >> ARRAY_LENGTH_SHIFT)
178 #define get_element_type(ARR_) ((ARR_)->flags.all & ELEM_TYPE_MASK) >> ELEM_TYPE_SHIFT
179 #define get_na_class_index(OBJ_) (((OBJ_)->flags.all & CLASS_MASK) >> CLASS_SHIFT)
180 #define get_free_length(OBJ_) (((OBJ_)->flags.all & FREE_BLOCK_SIZE_MASK) >> FREE_BLOCK_SIZE_SHIFT)
182 #define get_array_length(ARR_) ((ARR_)->flags.arrays.length)
183 #define get_element_type(ARR_) ((ARR_)->flags.arrays.type)
184 #define get_na_class_index(OBJ_) ((OBJ_)->flags.objects.class)
185 #define get_free_length(OBJ_) ((OBJ_)->flags.freeBlock.size)