1 /* src/vm/jit/mips/patcher.c - MIPS code patching functions
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: patcher.c 3002 2005-07-12 16:02:45Z twisti $
37 #include "vm/jit/mips/types.h"
39 #include "mm/memory.h"
40 #include "native/native.h"
41 #include "vm/builtin.h"
43 #include "vm/initialize.h"
44 #include "vm/options.h"
45 #include "vm/references.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/helper.h"
48 #include "vm/jit/patcher.h"
51 /* patcher_get_putstatic *******************************************************
55 <patched call position>
56 dfc1ffb8 ld at,-72(s8)
59 *******************************************************************************/
61 bool patcher_get_putstatic(u1 *sp)
71 /* get stuff from the stack */
73 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
74 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
75 mcode = *((u8 *) (sp + 2 * 8));
76 uf = (unresolved_field *) *((ptrint *) (sp + 1 * 8));
77 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
79 /* calculate and set the new return address */
82 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
86 /* get the fieldinfo */
88 if (!(fi = helper_resolve_fieldinfo(uf))) {
94 /* check if the field's class is initialized */
96 if (!fi->class->initialized)
97 if (!initialize_class(fi->class))
100 /* patch back original code */
102 *((u4 *) (ra + 0 * 4)) = mcode;
103 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
105 /* if we show disassembly, we have to skip the nop's */
107 if (opt_showdisassemble)
110 /* get the offset from machine instruction */
112 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
114 /* patch the field value's address */
116 *((ptrint *) (pv + offset)) = (ptrint) &(fi->value);
118 /* synchronize instruction cache */
120 docacheflush(ra, 2 * 4);
122 PATCHER_MARK_PATCHED_MONITOREXIT;
128 /* patcher_get_putfield ********************************************************
132 <patched call position>
133 8ee90020 lw a5,32(s7)
135 *******************************************************************************/
137 bool patcher_get_putfield(u1 *sp)
140 java_objectheader *o;
142 unresolved_field *uf;
145 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
146 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
147 mcode = *((u8 *) (sp + 2 * 8));
148 uf = (unresolved_field *) *((ptrint *) (sp + 1 * 8));
150 /* calculate and set the new return address */
153 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
155 PATCHER_MONITORENTER;
157 /* get the fieldinfo */
159 if (!(fi = helper_resolve_fieldinfo(uf))) {
165 /* patch back original code */
167 *((u4 *) (ra + 0 * 4)) = mcode;
168 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
170 /* if we show disassembly, we have to skip the nop's */
172 if (opt_showdisassemble)
175 /* patch the field's offset */
177 *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
179 /* synchronize instruction cache */
181 docacheflush(ra, 2 * 4);
183 PATCHER_MARK_PATCHED_MONITOREXIT;
189 /* patcher_builtin_new *********************************************************
193 dfc4ff98 ld a0,-104(s8)
194 <patched call postition>
195 dfd9ff90 ld t9,-112(s8)
199 *******************************************************************************/
201 bool patcher_builtin_new(u1 *sp)
204 java_objectheader *o;
206 constant_classref *cr;
211 /* get stuff from the stack */
213 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
214 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
215 mcode = *((u8 *) (sp + 2 * 8));
216 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
217 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
219 /* calculate and set the new return address */
221 ra = ra - (4 + 2 * 4);
222 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
224 PATCHER_MONITORENTER;
226 /* get the classinfo */
228 if (!(c = helper_resolve_classinfo(cr))) {
234 /* patch back original code */
236 *((u4 *) (ra + 1 * 4)) = mcode;
237 *((u4 *) (ra + 2 * 4)) = mcode >> 32;
239 /* get the offset from machine instruction */
241 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
243 /* patch the classinfo pointer */
245 *((ptrint *) (pv + offset)) = (ptrint) c;
247 /* if we show disassembly, we have to skip the nop's */
249 if (opt_showdisassemble)
252 /* get the offset from machine instruction */
254 offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
256 /* patch new function address */
258 *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_new;
260 /* synchronize instruction cache */
262 docacheflush(ra + 4, 2 * 4);
264 PATCHER_MARK_PATCHED_MONITOREXIT;
270 /* patcher_builtin_newarray ****************************************************
274 dfc5ffa0 ld a1,-96(s8)
275 <patched call position>
276 dfd9ff98 ld t9,-104(s8)
280 *******************************************************************************/
282 bool patcher_builtin_newarray(u1 *sp)
285 java_objectheader *o;
287 constant_classref *cr;
292 /* get stuff from the stack */
294 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
295 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
296 mcode = *((u8 *) (sp + 2 * 8));
297 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
298 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
300 /* calculate and set the new return address */
302 ra = ra - (4 + 2 * 4);
303 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
305 PATCHER_MONITORENTER;
307 /* get the classinfo */
309 if (!(c = helper_resolve_classinfo(cr))) {
315 /* patch back original code */
317 *((u4 *) (ra + 1 * 4)) = mcode;
318 *((u4 *) (ra + 2 * 4)) = mcode >> 32;
320 /* get the offset from machine instruction */
322 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
324 /* patch the class' vftbl pointer */
326 *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
328 /* if we show disassembly, we have to skip the nop */
330 if (opt_showdisassemble)
333 /* get the offset from machine instruction */
335 offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
337 /* patch new function address */
339 *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_newarray;
341 /* synchronize instruction cache */
343 docacheflush(ra + 4, 2 * 4);
345 PATCHER_MARK_PATCHED_MONITOREXIT;
351 /* patcher_builtin_multianewarray **********************************************
355 <patched call position>
356 24040002 addiu a0,zero,2
357 dfc5ff90 ld a1,-112(s8)
359 dfd9ff88 ld t9,-120(s8)
363 *******************************************************************************/
365 bool patcher_builtin_multianewarray(u1 *sp)
368 java_objectheader *o;
370 constant_classref *cr;
375 /* get stuff from the stack */
377 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
378 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
379 mcode = *((u8 *) (sp + 2 * 8));
380 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
381 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
383 /* calculate and set the new return address */
386 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
388 PATCHER_MONITORENTER;
390 /* get the classinfo */
392 if (!(c = helper_resolve_classinfo(cr))) {
398 /* patch back original code */
400 *((u4 *) (ra + 0 * 4)) = mcode;
401 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
403 /* if we show disassembly, we have to skip the nop's */
405 if (opt_showdisassemble)
408 /* get the offset from machine instruction */
410 offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
412 /* patch the class' vftbl pointer */
414 *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
416 /* synchronize instruction cache */
418 docacheflush(ra, 2 * 4);
420 PATCHER_MARK_PATCHED_MONITOREXIT;
426 /* patcher_builtin_arraycheckcast **********************************************
430 <patched call position>
431 dfc5ffc0 ld a1,-64(s8)
432 dfd9ffb8 ld t9,-72(s8)
436 *******************************************************************************/
438 bool patcher_builtin_arraycheckcast(u1 *sp)
441 java_objectheader *o;
443 constant_classref *cr;
448 /* get stuff from the stack */
450 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
451 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
452 mcode = *((u8 *) (sp + 2 * 8));
453 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
454 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
456 /* calculate and set the new return address */
459 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
461 PATCHER_MONITORENTER;
463 /* get the classinfo */
465 if (!(c = helper_resolve_classinfo(cr))) {
471 /* patch back original code */
473 *((u4 *) (ra + 0 * 4)) = mcode;
474 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
476 /* if we show disassembly, we have to skip the nop's */
478 if (opt_showdisassemble)
481 /* get the offset from machine instruction */
483 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
485 /* patch the class' vftbl pointer */
487 *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
489 /* get the offset from machine instruction */
491 offset = (s2) (*((u4 *) (ra + 1 * 4)) & 0x0000ffff);
493 /* patch new function address */
495 *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_arraycheckcast;
497 /* synchronize instruction cache */
499 docacheflush(ra, 2 * 4);
501 PATCHER_MARK_PATCHED_MONITOREXIT;
507 /* patcher_builtin_arrayinstanceof *********************************************
511 dfc5fe98 ld a1,-360(s8)
512 <patched call position>
513 dfd9fe90 ld t9,-368(s8)
517 *******************************************************************************/
519 bool patcher_builtin_arrayinstanceof(u1 *sp)
522 java_objectheader *o;
524 constant_classref *cr;
529 /* get stuff from the stack */
531 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
532 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
533 mcode = *((u8 *) (sp + 2 * 8));
534 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
535 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
537 /* calculate and set the new return address */
540 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
542 PATCHER_MONITORENTER;
544 /* get the classinfo */
546 if (!(c = helper_resolve_classinfo(cr))) {
552 /* patch back original code */
554 *((u4 *) (ra + 1 * 4)) = mcode;
555 *((u4 *) (ra + 2 * 4)) = mcode >> 32;
557 /* get the offset from machine instruction */
559 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
561 /* patch the class' vftbl pointer */
563 *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
565 /* if we show disassembly, we have to skip the nop's */
567 if (opt_showdisassemble)
570 /* get the offset from machine instruction */
572 offset = (s2) (*((u4 *) (ra + 1 * 4)) & 0x0000ffff);
574 /* patch new function address */
576 *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_arrayinstanceof;
578 /* synchronize instruction cache */
580 docacheflush(ra + 4, 2 * 4);
582 PATCHER_MARK_PATCHED_MONITOREXIT;
588 /* patcher_invokestatic_special ************************************************
592 <patched call position>
593 dfdeffc0 ld s8,-64(s8)
597 ******************************************************************************/
599 bool patcher_invokestatic_special(u1 *sp)
602 java_objectheader *o;
604 unresolved_method *um;
609 /* get stuff from the stack */
611 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
612 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
613 mcode = *((u8 *) (sp + 2 * 8));
614 um = (unresolved_method *) *((ptrint *) (sp + 1 * 8));
615 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
617 /* calculate and set the new return address */
620 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
622 PATCHER_MONITORENTER;
624 /* get the fieldinfo */
626 if (!(m = helper_resolve_methodinfo(um))) {
632 /* patch back original code */
634 *((u4 *) (ra + 0 * 4)) = mcode;
635 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
637 /* if we show disassembly, we have to skip the nop's */
639 if (opt_showdisassemble)
642 /* get the offset from machine instruction */
644 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
646 /* patch stubroutine */
648 *((ptrint *) (pv + offset)) = (ptrint) m->stubroutine;
650 /* synchronize instruction cache */
652 docacheflush(ra, 2 * 4);
654 PATCHER_MARK_PATCHED_MONITOREXIT;
660 /* patcher_invokevirtual *******************************************************
664 <patched call position>
666 df3e0040 ld s8,64(t9)
670 *******************************************************************************/
672 bool patcher_invokevirtual(u1 *sp)
675 java_objectheader *o;
677 unresolved_method *um;
680 /* get stuff from the stack */
682 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
683 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
684 mcode = *((u8 *) (sp + 2 * 8));
685 um = (unresolved_method *) *((ptrint *) (sp + 1 * 8));
687 /* calculate and set the new return address */
690 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
692 PATCHER_MONITORENTER;
694 /* get the fieldinfo */
696 if (!(m = helper_resolve_methodinfo(um))) {
702 /* patch back original code */
704 *((u4 *) (ra + 0 * 4)) = mcode;
705 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
707 /* if we show disassembly, we have to skip the nop's */
709 if (opt_showdisassemble)
712 /* patch vftbl index */
714 *((s4 *) (ra + 1 * 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
715 sizeof(methodptr) * m->vftblindex) & 0x0000ffff);
717 /* synchronize instruction cache */
719 docacheflush(ra, 2 * 4);
721 PATCHER_MARK_PATCHED_MONITOREXIT;
727 /* patcher_invokeinterface *****************************************************
731 <patched call position>
733 df39ffa0 ld t9,-96(t9)
734 df3e0018 ld s8,24(t9)
738 *******************************************************************************/
740 bool patcher_invokeinterface(u1 *sp)
743 java_objectheader *o;
745 unresolved_method *um;
748 /* get stuff from the stack */
750 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
751 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
752 mcode = *((u8 *) (sp + 2 * 8));
753 um = (unresolved_method *) *((ptrint *) (sp + 1 * 8));
755 /* calculate and set the new return address */
758 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
760 PATCHER_MONITORENTER;
762 /* get the fieldinfo */
764 if (!(m = helper_resolve_methodinfo(um))) {
770 /* patch back original code */
772 *((u4 *) (ra + 0 * 4)) = mcode;
773 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
775 /* if we show disassembly, we have to skip the nop's */
777 if (opt_showdisassemble)
780 /* patch interfacetable index */
782 *((s4 *) (ra + 1 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
783 sizeof(methodptr*) * m->class->index) & 0x0000ffff);
785 /* patch method offset */
787 *((s4 *) (ra + 2 * 4)) |=
788 (s4) ((sizeof(methodptr) * (m - m->class->methods)) & 0x0000ffff);
790 /* synchronize instruction cache */
792 docacheflush(ra, 2 * 4);
794 PATCHER_MARK_PATCHED_MONITOREXIT;
800 /* patcher_checkcast_instanceof_flags ******************************************
804 <patched call position>
805 8fc3ff24 lw v1,-220(s8)
806 30630200 andi v1,v1,512
807 1060000d beq v1,zero,0x000000001051824c
810 *******************************************************************************/
812 bool patcher_checkcast_instanceof_flags(u1 *sp)
815 java_objectheader *o;
817 constant_classref *cr;
822 /* get stuff from the stack */
824 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
825 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
826 mcode = *((u8 *) (sp + 2 * 8));
827 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
828 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
830 /* calculate and set the new return address */
833 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
835 PATCHER_MONITORENTER;
837 /* get the fieldinfo */
839 if (!(c = helper_resolve_classinfo(cr))) {
845 /* patch back original code */
847 *((u4 *) (ra + 0 * 4)) = mcode;
848 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
850 /* if we show disassembly, we have to skip the nop's */
852 if (opt_showdisassemble)
855 /* get the offset from machine instruction */
857 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
859 /* patch class flags */
861 *((s4 *) (pv + offset)) = (s4) c->flags;
863 /* synchronize instruction cache */
865 docacheflush(ra, 2 * 4);
867 PATCHER_MARK_PATCHED_MONITOREXIT;
873 /* patcher_checkcast_instanceof_interface **************************************
877 <patched call position>
879 8c79001c lw t9,28(v1)
880 27390000 addiu t9,t9,0
881 1b200082 blez t9,zero,0x000000001051843c
885 *******************************************************************************/
887 bool patcher_checkcast_instanceof_interface(u1 *sp)
890 java_objectheader *o;
892 constant_classref *cr;
895 /* get stuff from the stack */
897 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
898 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
899 mcode = *((u8 *) (sp + 2 * 8));
900 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
902 /* calculate and set the new return address */
905 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
907 PATCHER_MONITORENTER;
909 /* get the fieldinfo */
911 if (!(c = helper_resolve_classinfo(cr))) {
917 /* patch back original code */
919 *((u4 *) (ra + 0 * 4)) = mcode;
920 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
922 /* if we show disassembly, we have to skip the nop's */
924 if (opt_showdisassemble)
927 /* patch super class index */
929 *((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
931 *((s4 *) (ra + 5 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
932 c->index * sizeof(methodptr*)) & 0x0000ffff);
934 /* synchronize instruction cache */
936 docacheflush(ra, 6 * 4);
938 PATCHER_MARK_PATCHED_MONITOREXIT;
944 /* patcher_checkcast_instanceof_class ******************************************
948 <patched call position>
950 dfd9ff18 ld t9,-232(s8)
952 *******************************************************************************/
954 bool patcher_checkcast_instanceof_class(u1 *sp)
957 java_objectheader *o;
959 constant_classref *cr;
964 /* get stuff from the stack */
966 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
967 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
968 mcode = *((u8 *) (sp + 2 * 8));
969 cr = (constant_classref *) *((ptrint *) (sp + 1 * 8));
970 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
972 /* calculate and set the new return address */
975 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
977 PATCHER_MONITORENTER;
979 /* get the fieldinfo */
981 if (!(c = helper_resolve_classinfo(cr))) {
987 /* patch back original code */
989 *((u4 *) (ra + 0 * 4)) = mcode;
990 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
992 /* if we show disassembly, we have to skip the nop's */
994 if (opt_showdisassemble)
997 /* get the offset from machine instruction */
999 offset = (s2) (*((u4 *) (ra + 1 * 4)) & 0x0000ffff);
1001 /* patch super class' vftbl */
1003 *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
1005 /* synchronize instruction cache */
1007 docacheflush(ra, 2 * 4);
1009 PATCHER_MARK_PATCHED_MONITOREXIT;
1015 /* patcher_clinit **************************************************************
1019 *******************************************************************************/
1021 bool patcher_clinit(u1 *sp)
1024 java_objectheader *o;
1028 /* get stuff from the stack */
1030 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
1031 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
1032 mcode = *((u8 *) (sp + 2 * 8));
1033 c = (classinfo *) *((ptrint *) (sp + 1 * 8));
1035 /* calculate and set the new return address */
1038 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
1040 PATCHER_MONITORENTER;
1042 /* check if the class is initialized */
1044 if (!c->initialized) {
1045 if (!initialize_class(c)) {
1046 PATCHER_MONITOREXIT;
1052 /* patch back original code */
1054 *((u4 *) (ra + 0)) = mcode;
1055 *((u4 *) (ra + 4)) = mcode >> 32;
1057 /* synchronize instruction cache */
1059 docacheflush(ra, 2 * 4);
1061 PATCHER_MARK_PATCHED_MONITOREXIT;
1067 /* patcher_resolve_native ******************************************************
1071 *******************************************************************************/
1073 #if !defined(ENABLE_STATICVM)
1074 bool patcher_resolve_native(u1 *sp)
1077 java_objectheader *o;
1084 /* get stuff from the stack */
1086 ra = (u1 *) *((ptrint *) (sp + 4 * 8));
1087 o = (java_objectheader *) *((ptrint *) (sp + 3 * 8));
1088 mcode = *((u8 *) (sp + 2 * 8));
1089 m = (methodinfo *) *((ptrint *) (sp + 1 * 8));
1090 pv = (u1 *) *((ptrint *) (sp + 0 * 8));
1092 /* calculate and set the new return address */
1095 *((ptrint *) (sp + 4 * 8)) = (ptrint) ra;
1097 PATCHER_MONITORENTER;
1099 /* resolve native function */
1101 if (!(f = native_resolve_function(m))) {
1102 PATCHER_MONITOREXIT;
1107 /* patch back original code */
1109 *((u4 *) (ra + 0 * 4)) = mcode;
1110 *((u4 *) (ra + 1 * 4)) = mcode >> 32;
1112 /* if we show disassembly, we have to skip the nop's */
1114 if (opt_showdisassemble)
1117 /* get the offset from machine instruction */
1119 offset = (s2) (*((u4 *) ra) & 0x0000ffff);
1121 /* patch native function pointer */
1123 *((ptrint *) (pv + offset)) = (ptrint) f;
1125 /* synchronize instruction cache */
1127 docacheflush(ra, 2 * 4);
1129 PATCHER_MARK_PATCHED_MONITOREXIT;
1133 #endif /* !defined(ENABLE_STATICVM) */
1137 * These are local overrides for various environment variables in Emacs.
1138 * Please do not remove this and leave it at the end of the file, where
1139 * Emacs will automagically detect them.
1140 * ---------------------------------------------------------------------
1143 * indent-tabs-mode: t
1147 * vim:noexpandtab:sw=4:ts=4: