OSDN Git Service

lejos_NXJ_win32_0_5_0beta.zip
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / src / nxtvm / javavm / op_objects.hc
1 /**
2  * This is included inside a switch statement.
3  */
4
5 case OP_NEW:
6   // Stack: +1
7   // Arguments: 2
8   // Hi byte unused
9   tempBytePtr = (byte *) new_object_checked (pc[1], pc - 1);
10   if (tempBytePtr != JNULL)
11   { 
12     #if 0
13     trace (-1, (short) pc[1], 1);
14     trace (-1, (short) tempBytePtr, 2);
15     trace (-1, get_class_index((Object *) tempBytePtr), 3);
16     #endif
17     push_ref (ptr2ref(tempBytePtr));
18     pc += 2;
19   }
20   goto LABEL_ENGINELOOP;
21 case OP_GETSTATIC:
22 case OP_PUTSTATIC:
23
24   // Stack: +1 or +2 for GETSTATIC, -1 or -2 for PUTSTATIC
25   {
26     STATICFIELD fieldRecord;
27     byte *fbase1 = null;
28     byte fieldType;
29 #if RECORD_REFERENCES
30     byte isRef;
31 #endif
32     byte fieldSize;
33     boolean wideWord;
34
35     #if DEBUG_FIELDS
36     printf ("---  GET/PUTSTATIC --- (%d, %d)\n", (int) pc[0], (int) pc[1]);
37     #endif
38
39 #if EXECUTE_FROM_FLASH
40     if (!is_initialized_idx (pc[0]))
41 #endif
42       if (dispatch_static_initializer (get_class_record (pc[0]), pc - 1))
43         goto LABEL_ENGINELOOP;
44
45     fieldRecord = ((STATICFIELD *) get_static_fields_base())[pc[1]];
46
47     fieldType = (fieldRecord >> 12) & 0x0F;
48 #if RECORD_REFERENCES
49     isRef = (fieldType == T_REFERENCE);
50 #endif
51     fieldSize = typeSize[fieldType];
52     wideWord = false;
53     if (fieldSize > 4)
54     {
55        wideWord = true;
56        fieldSize = 4;
57     }
58
59     fbase1 = get_static_state_base() + get_static_field_offset (fieldRecord);
60
61     #if DEBUG_FIELDS
62     printf ("fieldSize  = %d\n", (int) fieldSize);
63     printf ("fbase1  = %d\n", (int) fbase1);
64     #endif
65
66     if (*(pc-1) == OP_GETSTATIC)
67     {
68       make_word (fbase1, fieldSize, &tempStackWord);
69
70 #if RECORD_REFERENCES
71       if (isRef)
72         push_ref(tempStackWord);
73       else
74 #endif
75       push_word (tempStackWord);
76       if (wideWord)
77       {
78         make_word (fbase1 + 4, 4, &tempStackWord);
79         push_word (tempStackWord);
80       }
81     }
82     else
83     {
84       if (wideWord)
85         store_word (fbase1 + 4, 4, pop_word());
86 #if RECORD_REFERENCES
87       if (isRef)
88         store_word (fbase1, fieldSize, pop_ref());
89       else
90 #endif
91       store_word (fbase1, fieldSize, pop_word());
92     }
93
94     pc += 2;
95
96   }
97   goto LABEL_ENGINELOOP;
98 case OP_GETFIELD:
99   {
100     byte *fbase2 = null;
101     byte fieldType;
102     byte fieldSize;
103     boolean wideWord;
104
105     tempStackWord = get_top_ref();
106     if (tempStackWord == JNULL)
107     {
108       throw_exception (nullPointerException);
109       goto LABEL_ENGINELOOP;
110     }
111     fieldType = get_pgfield_type(pc[0]);
112     fieldSize = typeSize[fieldType];
113     wideWord = fieldSize > 4;
114     if (wideWord)
115     {
116       fieldSize = 4;
117     }
118
119     fbase2 = ((byte *) word2ptr (tempStackWord)) + 
120                 get_pgfield_offset(pc[0], pc[1]);
121
122     #ifdef DEBUG_FIELDS
123     printf ("--- GETFIELD ---\n");
124     printf ("fieldType: %d\n", (int) fieldType);
125     printf ("fieldSize: %d\n", (int) fieldSize);
126     printf ("wideWord: %d\n", (int) wideWord);
127     printf ("reference: %d\n", (int) tempStackWord);
128     printf ("stackTop: %d\n", (int) stackTop);
129     #endif
130
131     #ifdef DEBUG_FIELDS
132     printf ("### get_field base=%d size=%d pushed=%d\n", (int) fbase2, (int) fieldSize, (int) tempStackWord);
133     #endif
134
135     make_word (fbase2, fieldSize, &tempStackWord);
136    
137     #ifdef DEBUG_FIELDS
138     printf ("### get_field base=%d size=%d pushed=%d\n", (int) fbase2, (int) fieldSize, (int) tempStackWord);
139     #endif
140
141 #ifdef RECORD_REFERENCES
142     if (fieldType == T_REFERENCE)
143       set_top_ref (tempStackWord);
144     else
145 #endif
146     set_top_word (tempStackWord);
147     #ifdef DEBUG_FIELDS
148     printf("Set top word done\n");
149     if (wideWord)
150         printf("Wide word\n");
151     #endif
152     if (wideWord)
153     {
154       make_word (fbase2 + 4, 4, &tempStackWord);
155       push_word (tempStackWord);
156     }
157     pc += 2;
158   }
159 #ifdef DEBUG_FIELDS
160         printf("Going home\n");
161 #endif
162   goto LABEL_ENGINELOOP;
163 case OP_PUTFIELD:
164   {
165     byte *fbase3;
166     byte fieldType;
167     byte fieldSize;
168     boolean wideWord;
169
170     fieldType = get_pgfield_type(pc[0]);
171     fieldSize = typeSize[fieldType];
172     wideWord = (fieldSize > 4);
173     if (wideWord)
174       fieldSize = 4;
175     tempStackWord = get_ref_at (wideWord ? 2 : 1);
176
177     #ifdef DEBUG_FIELDS
178     printf ("--- PUTFIELD ---\n");
179     printf ("fieldType: %d\n", (int) fieldType);
180     printf ("fieldSize: %d\n", (int) fieldSize);
181     printf ("wideWord: %d\n", (int) wideWord);
182     printf ("reference: %d\n", (int) tempStackWord);
183     #endif
184
185
186     if (tempStackWord == JNULL)
187     {
188       throw_exception (nullPointerException);
189       goto LABEL_ENGINELOOP;
190     }
191     fbase3 = ((byte *) word2ptr (tempStackWord)) +
192                 get_pgfield_offset (pc[0], pc[1]); 
193     if (wideWord)
194       store_word (fbase3 + 4, 4, pop_word());
195
196     #if 0
197     printf ("### put_field base=%d size=%d stored=%d\n", (int) fbase3, (int) fieldSize, (int) get_top_word());
198     #endif
199
200 #ifdef RECORD_REFERENCES
201     if (fieldType == T_REFERENCE)
202       store_word (fbase3, fieldSize, pop_ref());
203     else
204 #endif
205     store_word (fbase3, fieldSize, pop_word());
206     just_pop_ref();
207     pc += 2;
208   }
209   goto LABEL_ENGINELOOP;
210 case OP_INSTANCEOF:
211   // Stack: unchanged
212   // Arguments: 2
213   // Ignore hi byte
214   set_top_word (instance_of (word2obj (get_top_ref()),  pc[1]));
215   pc += 2;
216   goto LABEL_ENGINELOOP;
217 case OP_CHECKCAST:
218   // Stack: -1 +1 (same)
219   // Arguments: 2
220   // Ignore hi byte
221   pc++;
222   tempStackWord = get_top_ref();
223   if (tempStackWord != JNULL && !instance_of (word2obj (tempStackWord), pc[0]))
224     throw_exception (classCastException);
225   pc++;
226   goto LABEL_ENGINELOOP;
227
228 // Notes:
229 // - NEW, INSTANCEOF, CHECKCAST: 8 bits ignored, 8-bit class index
230 // - GETSTATIC and PUTSTATIC: 8-bit class index, 8-bit static field record
231 // - GETFIELD and PUTFIELD: 4-bit field type, 12-bit field data offset
232
233 /*end*/
234
235
236
237
238
239
240
241