OSDN Git Service

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