e1f82af36c195b6e4c736ab89d98ef8796c176cb
[cacao.git] / src / vm / jit / alpha / patcher.c
1 /* src/vm/jit/alpha/patcher.c - Alpha code patching functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: patcher.c 3883 2005-12-05 19:56:54Z twisti $
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include "mm/memory.h"
40 #include "native/native.h"
41 #include "vm/builtin.h"
42 #include "vm/class.h"
43 #include "vm/field.h"
44 #include "vm/initialize.h"
45 #include "vm/options.h"
46 #include "vm/references.h"
47 #include "vm/resolve.h"
48 #include "vm/jit/asmpart.h"
49 #include "vm/jit/patcher.h"
50
51
52 /* patcher_get_putstatic *******************************************************
53
54    Machine code:
55
56    <patched call position>
57    a73bff98    ldq     t11,-104(pv)
58    a2590000    ldl     a2,0(t11)
59
60 *******************************************************************************/
61
62 bool patcher_get_putstatic(u1 *sp)
63 {
64         u1                *ra;
65         java_objectheader *o;
66         u4                 mcode;
67         unresolved_field  *uf;
68         s4                 disp;
69         u1                *pv;
70         fieldinfo         *fi;
71
72         /* get stuff from the stack */
73
74         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
75         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
76         mcode =                       *((u4 *)     (sp + 3 * 8));
77         uf    = (unresolved_field *)  *((ptrint *) (sp + 2 * 8));
78         disp  =                       *((s4 *)     (sp + 1 * 8));
79         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
80
81         /* calculate and set the new return address */
82
83         ra = ra - 1 * 4;
84         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
85
86         PATCHER_MONITORENTER;
87
88         /* get the fieldinfo */
89
90         if (!(fi = resolve_field_eager(uf))) {
91                 PATCHER_MONITOREXIT;
92
93                 return false;
94         }
95
96         /* check if the field's class is initialized */
97
98         if (!(fi->class->state & CLASS_INITIALIZED)) {
99                 if (!initialize_class(fi->class)) {
100                         PATCHER_MONITOREXIT;
101
102                         return false;
103                 }
104         }
105
106         /* patch back original code */
107
108         *((u4 *) ra) = mcode;
109
110         /* synchronize instruction cache */
111
112         asm_sync_instruction_cache();
113
114         /* patch the field value's address */
115
116         *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
117
118         PATCHER_MARK_PATCHED_MONITOREXIT;
119
120         return true;
121 }
122
123
124 /* patcher_get_putfield ********************************************************
125
126    Machine code:
127
128    <patched call position>
129    a2af0020    ldl     a5,32(s6)
130
131 *******************************************************************************/
132
133 bool patcher_get_putfield(u1 *sp)
134 {
135         u1                *ra;
136         java_objectheader *o;
137         u4                 mcode;
138         unresolved_field  *uf;
139         fieldinfo         *fi;
140
141         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
142         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
143         mcode =                       *((u4 *)     (sp + 3 * 8));
144         uf    = (unresolved_field *)  *((ptrint *) (sp + 2 * 8));
145
146         /* calculate and set the new return address */
147
148         ra = ra - 1 * 4;
149         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
150
151         PATCHER_MONITORENTER;
152
153         /* get the fieldinfo */
154
155         if (!(fi = resolve_field_eager(uf))) {
156                 PATCHER_MONITOREXIT;
157
158                 return false;
159         }
160
161         /* patch back original code */
162
163         *((u4 *) ra) = mcode;
164
165         /* if we show disassembly, we have to skip the nop */
166
167         if (opt_showdisassemble)
168                 ra = ra + 4;
169
170         /* patch the field's offset */
171
172         *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
173
174         /* synchronize instruction cache */
175
176         asm_sync_instruction_cache();
177
178         PATCHER_MARK_PATCHED_MONITOREXIT;
179
180         return true;
181 }
182
183
184 /* patcher_aconst **************************************************************
185
186    Machine code:
187
188    <patched call postition>
189    a61bff80    ldq     a0,-128(pv)
190
191 *******************************************************************************/
192
193 bool patcher_aconst(u1 *sp)
194 {
195         u1                *ra;
196         java_objectheader *o;
197         u4                 mcode;
198         constant_classref *cr;
199         s4                 disp;
200         u1                *pv;
201         classinfo         *c;
202
203         /* get stuff from the stack */
204
205         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
206         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
207         mcode =                       *((u4 *)     (sp + 3 * 8));
208         cr    = (constant_classref *) *((ptrint *) (sp + 2 * 8));
209         disp  =                       *((s4 *)     (sp + 1 * 8));
210         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
211
212         /* calculate and set the new return address */
213
214         ra = ra - 1 * 4;
215         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
216
217         PATCHER_MONITORENTER;
218
219         /* get the classinfo */
220
221         if (!(c = resolve_classref_eager(cr))) {
222                 PATCHER_MONITOREXIT;
223
224                 return false;
225         }
226
227         /* patch back original code */
228
229         *((u4 *) ra) = mcode;
230
231         /* synchronize instruction cache */
232
233         asm_sync_instruction_cache();
234
235         /* patch the classinfo pointer */
236
237         *((ptrint *) (pv + disp)) = (ptrint) c;
238
239         PATCHER_MARK_PATCHED_MONITOREXIT;
240
241         return true;
242 }
243
244
245 /* patcher_builtin_multianewarray **********************************************
246
247    Machine code:
248
249    <patched call position>
250    a63bff80    ldq     a1,-128(pv)
251    47de0412    mov     sp,a2
252    a77bff78    ldq     pv,-136(pv)
253    6b5b4000    jsr     (pv)
254
255 *******************************************************************************/
256
257 bool patcher_builtin_multianewarray(u1 *sp)
258 {
259         u1                *ra;
260         java_objectheader *o;
261         u4                 mcode;
262         constant_classref *cr;
263         s4                 disp;
264         u1                *pv;
265         classinfo         *c;
266
267         /* get stuff from the stack */
268
269         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
270         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
271         mcode =                       *((u4 *)     (sp + 3 * 8));
272         cr    = (constant_classref *) *((ptrint *) (sp + 2 * 8));
273         disp  =                       *((s4 *)     (sp + 1 * 8));
274         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
275
276         /* calculate and set the new return address */
277
278         ra = ra - 1 * 4;
279         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
280
281         PATCHER_MONITORENTER;
282
283         /* get the classinfo */
284
285         if (!(c = resolve_classref_eager(cr))) {
286                 PATCHER_MONITOREXIT;
287
288                 return false;
289         }
290
291         /* patch back original code */
292
293         *((u4 *) ra) = mcode;
294
295         /* synchronize instruction cache */
296
297         asm_sync_instruction_cache();
298
299         /* patch the classinfo pointer */
300
301         *((ptrint *) (pv + disp)) = (ptrint) c;
302
303         PATCHER_MARK_PATCHED_MONITOREXIT;
304
305         return true;
306 }
307
308
309 /* patcher_builtin_arraycheckcast **********************************************
310
311    Machine code:
312
313    <patched call position>
314    a63bfe60    ldq     a1,-416(pv)
315    a77bfe58    ldq     pv,-424(pv)
316    6b5b4000    jsr     (pv)
317
318 *******************************************************************************/
319
320 bool patcher_builtin_arraycheckcast(u1 *sp)
321 {
322         u1                *ra;
323         java_objectheader *o;
324         u4                 mcode;
325         constant_classref *cr;
326         s4                 disp;
327         u1                *pv;
328         classinfo         *c;
329
330         /* get stuff from the stack */
331
332         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
333         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
334         mcode =                       *((u4 *)     (sp + 3 * 8));
335         cr    = (constant_classref *) *((ptrint *) (sp + 2 * 8));
336         disp  =                       *((s4 *)     (sp + 1 * 8));
337         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
338
339         /* calculate and set the new return address */
340
341         ra = ra - 1 * 4;
342         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
343
344         PATCHER_MONITORENTER;
345
346         /* get the classinfo */
347
348         if (!(c = resolve_classref_eager(cr))) {
349                 PATCHER_MONITOREXIT;
350
351                 return false;
352         }
353
354         /* patch back original code */
355
356         *((u4 *) ra) = mcode;
357
358         /* synchronize instruction cache */
359
360         asm_sync_instruction_cache();
361
362         /* patch the classinfo pointer */
363
364         *((ptrint *) (pv + disp)) = (ptrint) c;
365
366         PATCHER_MARK_PATCHED_MONITOREXIT;
367
368         return true;
369 }
370
371
372 /* patcher_invokestatic_special ************************************************
373
374    Machine code:
375
376    <patched call position>
377    a77bffa8    ldq     pv,-88(pv)
378    6b5b4000    jsr     (pv)
379
380 ******************************************************************************/
381
382 bool patcher_invokestatic_special(u1 *sp)
383 {
384         u1                *ra;
385         java_objectheader *o;
386         u4                 mcode;
387         unresolved_method *um;
388         s4                 disp;
389         u1                *pv;
390         methodinfo        *m;
391
392         /* get stuff from the stack */
393
394         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
395         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
396         mcode =                       *((u4 *)     (sp + 3 * 8));
397         um    = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
398         disp  =                       *((s4 *)     (sp + 1 * 8));
399         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
400
401         /* calculate and set the new return address */
402
403         ra = ra - 1 * 4;
404         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
405
406         PATCHER_MONITORENTER;
407
408         /* get the fieldinfo */
409
410         if (!(m = resolve_method_eager(um))) {
411                 PATCHER_MONITOREXIT;
412
413                 return false;
414         }
415
416         /* patch back original code */
417
418         *((u4 *) ra) = mcode;
419
420         /* synchronize instruction cache */
421
422         asm_sync_instruction_cache();
423
424         /* patch stubroutine */
425
426         *((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
427
428         PATCHER_MARK_PATCHED_MONITOREXIT;
429
430         return true;
431 }
432
433
434 /* patcher_invokevirtual *******************************************************
435
436    Machine code:
437
438    <patched call position>
439    a7900000    ldq     at,0(a0)
440    a77c0100    ldq     pv,256(at)
441    6b5b4000    jsr     (pv)
442
443 *******************************************************************************/
444
445 bool patcher_invokevirtual(u1 *sp)
446 {
447         u1                *ra;
448         java_objectheader *o;
449         u4                 mcode;
450         unresolved_method *um;
451         methodinfo        *m;
452
453         /* get stuff from the stack */
454
455         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
456         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
457         mcode =                       *((u4 *)     (sp + 3 * 8));
458         um    = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
459
460         /* calculate and set the new return address */
461
462         ra = ra - 1 * 4;
463         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
464
465         PATCHER_MONITORENTER;
466
467         /* get the fieldinfo */
468
469         if (!(m = resolve_method_eager(um))) {
470                 PATCHER_MONITOREXIT;
471
472                 return false;
473         }
474
475         /* patch back original code */
476
477         *((u4 *) ra) = mcode;
478
479         /* if we show disassembly, we have to skip the nop */
480
481         if (opt_showdisassemble)
482                 ra = ra + 4;
483
484         /* patch vftbl index */
485
486         *((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
487                                                                  sizeof(methodptr) * m->vftblindex) & 0x0000ffff);
488
489         /* synchronize instruction cache */
490
491         asm_sync_instruction_cache();
492
493         PATCHER_MARK_PATCHED_MONITOREXIT;
494
495         return true;
496 }
497
498
499 /* patcher_invokeinterface *****************************************************
500
501    Machine code:
502
503    <patched call position>
504    a7900000    ldq     at,0(a0)
505    a79cffa0    ldq     at,-96(at)
506    a77c0018    ldq     pv,24(at)
507    6b5b4000    jsr     (pv)
508
509 *******************************************************************************/
510
511 bool patcher_invokeinterface(u1 *sp)
512 {
513         u1                *ra;
514         java_objectheader *o;
515         u4                 mcode;
516         unresolved_method *um;
517         methodinfo        *m;
518
519         /* get stuff from the stack */
520
521         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
522         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
523         mcode =                       *((u4 *)     (sp + 3 * 8));
524         um    = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
525
526         /* calculate and set the new return address */
527
528         ra = ra - 1 * 4;
529         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
530
531         PATCHER_MONITORENTER;
532
533         /* get the fieldinfo */
534
535         if (!(m = resolve_method_eager(um))) {
536                 PATCHER_MONITOREXIT;
537
538                 return false;
539         }
540
541         /* patch back original code */
542
543         *((u4 *) ra) = mcode;
544
545         /* if we show disassembly, we have to skip the nop */
546
547         if (opt_showdisassemble)
548                 ra = ra + 4;
549
550         /* patch interfacetable index */
551
552         *((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
553                                                                  sizeof(methodptr*) * m->class->index) & 0x0000ffff);
554
555         /* patch method offset */
556
557         *((s4 *) (ra + 4 + 4)) |=
558                 (s4) ((sizeof(methodptr) * (m - m->class->methods)) & 0x0000ffff);
559
560         /* synchronize instruction cache */
561
562         asm_sync_instruction_cache();
563
564         PATCHER_MARK_PATCHED_MONITOREXIT;
565
566         return true;
567 }
568
569
570 /* patcher_checkcast_instanceof_flags ******************************************
571
572    Machine code:
573
574    <patched call position>
575
576 *******************************************************************************/
577
578 bool patcher_checkcast_instanceof_flags(u1 *sp)
579 {
580         u1                *ra;
581         java_objectheader *o;
582         u4                 mcode;
583         constant_classref *cr;
584         s4                 disp;
585         u1                *pv;
586         classinfo         *c;
587
588         /* get stuff from the stack */
589
590         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
591         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
592         mcode =                       *((u4 *)     (sp + 3 * 8));
593         cr    = (constant_classref *) *((ptrint *) (sp + 2 * 8));
594         disp  =                       *((s4 *)     (sp + 1 * 8));
595         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
596
597         /* calculate and set the new return address */
598
599         ra = ra - 1 * 4;
600         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
601
602         PATCHER_MONITORENTER;
603
604         /* get the fieldinfo */
605
606         if (!(c = resolve_classref_eager(cr))) {
607                 PATCHER_MONITOREXIT;
608
609                 return false;
610         }
611
612         /* patch back original code */
613
614         *((u4 *) ra) = mcode;
615
616         /* synchronize instruction cache */
617
618         asm_sync_instruction_cache();
619
620         /* patch class flags */
621
622         *((s4 *) (pv + disp)) = (s4) c->flags;
623
624         PATCHER_MARK_PATCHED_MONITOREXIT;
625
626         return true;
627 }
628
629
630 /* patcher_checkcast_instanceof_interface **************************************
631
632    Machine code:
633
634    <patched call position>
635    a78e0000    ldq     at,0(s5)
636    a3bc001c    ldl     gp,28(at)
637    23bdfffd    lda     gp,-3(gp)
638    efa0002e    ble     gp,0x00000200002bf6b0
639    a7bcffe8    ldq     gp,-24(at)
640
641 *******************************************************************************/
642
643 bool patcher_checkcast_instanceof_interface(u1 *sp)
644 {
645         u1                *ra;
646         java_objectheader *o;
647         u4                 mcode;
648         constant_classref *cr;
649         classinfo         *c;
650
651         /* get stuff from the stack */
652
653         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
654         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
655         mcode =                       *((u4 *)     (sp + 3 * 8));
656         cr    = (constant_classref *) *((ptrint *) (sp + 2 * 8));
657
658         /* calculate and set the new return address */
659
660         ra = ra - 1 * 4;
661         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
662
663         PATCHER_MONITORENTER;
664
665         /* get the fieldinfo */
666
667         if (!(c = resolve_classref_eager(cr))) {
668                 PATCHER_MONITOREXIT;
669
670                 return false;
671         }
672
673         /* patch back original code */
674
675         *((u4 *) ra) = mcode;
676
677         /* if we show disassembly, we have to skip the nop */
678
679         if (opt_showdisassemble)
680                 ra = ra + 4;
681
682         /* patch super class index */
683
684         *((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
685
686         *((s4 *) (ra + 4 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
687                                                                          c->index * sizeof(methodptr*)) & 0x0000ffff);
688
689         /* synchronize instruction cache */
690
691         asm_sync_instruction_cache();
692
693         PATCHER_MARK_PATCHED_MONITOREXIT;
694
695         return true;
696 }
697
698
699 /* patcher_checkcast_instanceof_class ******************************************
700
701    Machine code:
702
703    <patched call position>
704    a7940000    ldq     at,0(a4)
705    a7bbff28    ldq     gp,-216(pv)
706
707 *******************************************************************************/
708
709 bool patcher_checkcast_instanceof_class(u1 *sp)
710 {
711         u1                *ra;
712         java_objectheader *o;
713         u4                 mcode;
714         constant_classref *cr;
715         s4                 disp;
716         u1                *pv;
717         classinfo         *c;
718
719         /* get stuff from the stack */
720
721         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
722         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
723         mcode =                       *((u4 *)     (sp + 3 * 8));
724         cr    = (constant_classref *) *((ptrint *) (sp + 2 * 8));
725         disp  =                       *((s4 *)     (sp + 1 * 8));
726         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
727
728         /* calculate and set the new return address */
729
730         ra = ra - 1 * 4;
731         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
732
733         PATCHER_MONITORENTER;
734
735         /* get the fieldinfo */
736
737         if (!(c = resolve_classref_eager(cr))) {
738                 PATCHER_MONITOREXIT;
739
740                 return false;
741         }
742
743         /* patch back original code */
744
745         *((u4 *) ra) = mcode;
746
747         /* synchronize instruction cache */
748
749         asm_sync_instruction_cache();
750
751         /* patch super class' vftbl */
752
753         *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
754
755         PATCHER_MARK_PATCHED_MONITOREXIT;
756
757         return true;
758 }
759
760
761 /* patcher_clinit **************************************************************
762
763    XXX
764
765 *******************************************************************************/
766
767 bool patcher_clinit(u1 *sp)
768 {
769         u1                *ra;
770         java_objectheader *o;
771         u4                 mcode;
772         classinfo         *c;
773
774         /* get stuff from the stack */
775
776         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
777         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
778         mcode =                       *((u4 *)     (sp + 3 * 8));
779         c     = (classinfo *)         *((ptrint *) (sp + 2 * 8));
780
781         /* calculate and set the new return address */
782
783         ra = ra - 1 * 4;
784         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
785
786         PATCHER_MONITORENTER;
787
788         /* check if the class is initialized */
789
790         if (!(c->state & CLASS_INITIALIZED)) {
791                 if (!initialize_class(c)) {
792                         PATCHER_MONITOREXIT;
793
794                         return false;
795                 }
796         }
797
798         /* patch back original code */
799
800         *((u4 *) ra) = mcode;
801
802         /* synchronize instruction cache */
803
804         asm_sync_instruction_cache();
805
806         PATCHER_MARK_PATCHED_MONITOREXIT;
807
808         return true;
809 }
810
811
812 /* patcher_athrow_areturn ******************************************************
813
814    Machine code:
815
816    <patched call position>
817
818 *******************************************************************************/
819
820 #ifdef ENABLE_VERIFIER
821 bool patcher_athrow_areturn(u1 *sp)
822 {
823         u1                *ra;
824         java_objectheader *o;
825         u4                 mcode;
826         unresolved_class  *uc;
827         classinfo         *c;
828
829         /* get stuff from the stack */
830
831         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
832         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
833         mcode =                       *((u4 *)     (sp + 3 * 8));
834         uc    = (unresolved_class *)  *((ptrint *) (sp + 2 * 8));
835
836         /* calculate and set the new return address */
837
838         ra = ra - 1 * 4;
839         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
840
841         PATCHER_MONITORENTER;
842
843         /* resolve the class */
844
845         if (!resolve_class(uc, resolveEager, false, &c)) {
846                 PATCHER_MONITOREXIT;
847
848                 return false;
849         }
850
851         /* patch back original code */
852
853         *((u4 *) ra) = mcode;
854
855         /* synchronize instruction cache */
856
857         asm_sync_instruction_cache();
858
859         PATCHER_MARK_PATCHED_MONITOREXIT;
860
861         return true;
862 }
863 #endif /* ENABLE_VERIFIER */
864
865
866 /* patcher_resolve_native ******************************************************
867
868    XXX
869
870 *******************************************************************************/
871
872 #if !defined(ENABLE_STATICVM)
873 bool patcher_resolve_native(u1 *sp)
874 {
875         u1                *ra;
876         java_objectheader *o;
877         u4                 mcode;
878         methodinfo        *m;
879         s4                 disp;
880         u1                *pv;
881         functionptr        f;
882
883         /* get stuff from the stack */
884
885         ra    = (u1 *)                *((ptrint *) (sp + 5 * 8));
886         o     = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
887         mcode =                       *((u4 *)     (sp + 3 * 8));
888         m     = (methodinfo *)        *((ptrint *) (sp + 2 * 8));
889         disp  =                       *((s4 *)     (sp + 1 * 8));
890         pv    = (u1 *)                *((ptrint *) (sp + 0 * 8));
891
892         /* calculate and set the new return address */
893
894         ra = ra - 1 * 4;
895         *((ptrint *) (sp + 5 * 8)) = (ptrint) ra;
896
897         PATCHER_MONITORENTER;
898
899         /* resolve native function */
900
901         if (!(f = native_resolve_function(m))) {
902                 PATCHER_MONITOREXIT;
903
904                 return false;
905         }
906
907         /* patch back original code */
908
909         *((u4 *) ra) = mcode;
910
911         /* synchronize instruction cache */
912
913         asm_sync_instruction_cache();
914
915         /* patch native function pointer */
916
917         *((ptrint *) (pv + disp)) = (ptrint) f;
918
919         PATCHER_MARK_PATCHED_MONITOREXIT;
920
921         return true;
922 }
923 #endif /* !defined(ENABLE_STATICVM) */
924
925
926 /*
927  * These are local overrides for various environment variables in Emacs.
928  * Please do not remove this and leave it at the end of the file, where
929  * Emacs will automagically detect them.
930  * ---------------------------------------------------------------------
931  * Local variables:
932  * mode: c
933  * indent-tabs-mode: t
934  * c-basic-offset: 4
935  * tab-width: 4
936  * End:
937  * vim:noexpandtab:sw=4:ts=4:
938  */