1 /* jit/i386/asmpart.S - Java-C interface functions for i386
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Andreas Krall
32 $Id: asmpart.S 1112 2004-05-31 15:47:20Z jowenn $
40 /* data segment offsets */
42 #define MethodPointer -4
48 #define LineNumberTableSize -28
49 #define LineNumberTableStart -32
50 #define ExTableSize -36
51 #define ExTableStart -36
53 #define ExEntrySize -16
56 #define ExHandlerPC -12
57 #define ExCatchType -16
60 #define LineEntrySize -8
73 /********************* exported functions and variables ***********************/
75 .globl asm_calljavafunction
76 .globl asm_calljavafunction2
77 .globl asm_calljavafunction2long
78 .globl asm_calljavafunction2double
80 .globl asm_call_jit_compiler
81 .globl asm_handle_builtin_exception
82 .globl asm_handle_nat_exception
83 .globl asm_handle_exception
84 .globl asm_check_clinit
85 .globl asm_builtin_checkcast
86 .globl asm_builtin_checkarraycast
87 .globl asm_builtin_newarray
88 .globl asm_builtin_anewarray
89 .globl asm_builtin_newarray_array
90 .globl asm_builtin_aastore
91 .globl asm_builtin_monitorenter
92 .globl asm_builtin_monitorexit
93 .globl asm_builtin_ldiv
94 .globl asm_builtin_lrem
95 .globl asm_builtin_f2i
96 .globl asm_builtin_f2l
97 .globl asm_builtin_d2i
98 .globl asm_builtin_d2l
99 .globl asm_builtin_arrayinstanceof
100 .globl asm_perform_threadswitch
101 .globl asm_initialize_thread_stack
102 .globl asm_switchstackandcall
103 .globl asm_getcallingmethod
104 .globl Java_java_lang_VMSecurityManager_getClassContext
105 .globl Java_java_lang_VMSecurityManager_currentClassLoader
106 .globl asm_builtin_new
107 .globl asm_get_stackTrace
108 .globl asm_criticalsections
109 .globl asm_getclassvalues_atomic
111 /*************************** imported functions *******************************/
114 .globl builtin_monitorexit
115 .globl builtin_throw_exception
116 .globl builtin_trace_exception
117 .globl class_java_lang_Object
118 .globl codegen_findmethod
119 /* .globl codegen_findmethod1*/
120 .globl builtin_asm_createclasscontextarray
121 .globl builtin_asm_getclassloader
122 .globl callgetexceptionptrptr
123 .globl asm_throw_and_handle_exception
124 .globl asm_throw_and_handle_hardware_arithmetic_exception
127 /********************* function asm_calljavafunction ***************************
129 * This function calls a Java-method (which possibly needs compilation) *
130 * with up to 4 address parameters. *
132 * This functions calls the JIT-compiler which eventually translates the *
133 * method into machine code. *
136 * javaobject_header *asm_calljavamethod (methodinfo *m, *
137 * void *arg1, void *arg2, void *arg3, void *arg4); *
139 *******************************************************************************/
142 .ascii "calljavafunction\0\0"
145 .long 0 /* catch type all */
146 .long calljava_xhandler /* handler pc */
147 .long calljava_xhandler /* end pc */
148 .long asm_calljavafunction /* start pc */
149 .long 1 /* extable size */
150 .long 0 /* line number table start */
151 .long 0 /* line number table size */
152 .long 0 /* fltsave */
153 .long 0 /* intsave */
156 .long 32 /* frame size */
157 .long 0 /* method pointer (pointer to name) */
159 asm_calljavafunction:
160 push %ebp /* allocate stack space */
163 push %ebx /* save registers */
167 sub $32,%esp /* pass the remaining parameters */
170 mov %edx,28(%esp) /* convert parms to 8 byte */
186 mov 8(%ebp),%eax /* move function pointer to %eax */
188 lea asm_call_jit_compiler,%edx
189 call *%edx /* call JIT compiler */
193 pop %edi /* restore registers */
200 push %eax /* pass exception pointer */
201 call builtin_throw_exception
205 pop %edi /* restore registers */
212 /********************* function asm_calljavafunction ***************************
214 * This function calls a Java-method (which possibly needs compilation) *
215 * with up to 4 address parameters. *
217 * This functions calls the JIT-compiler which eventually translates the *
218 * method into machine code. *
221 * javaobject_header *asm_calljavafunction2(methodinfo *m, *
222 * u4 count, u4 size, void *callblock); *
224 *******************************************************************************/
227 .ascii "calljavafunction2\0\0"
230 .long 0 /* catch type all */
231 .long calljava_xhandler2 /* handler pc */
232 .long calljava_xhandler2 /* end pc */
233 .long asm_calljavafunction2 /* start pc */
234 .long 1 /* extable size */
235 .long 0 /* line number table start */
236 .long 0 /* line number table size */
237 .long 0 /* fltsave */
238 .long 0 /* intsave */
241 .long 32 /* frame size */
242 .long 0 /* method pointer (pointer to name) */
244 asm_calljavafunction2:
245 asm_calljavafunction2double:
246 asm_calljavafunction2long:
248 mov %esp,%ebp /* save stackptr */
250 push %ebx /* save registers */
254 mov 20(%ebp),%eax /* pointer to arg block */
255 mov 12(%ebp),%ecx /* arg count */
256 test %ecx,%ecx /* maybe we have no args */
257 jle calljava_copydone
259 mov %ecx,%edx /* calculate stack size */
261 mov %edx,%esi /* save in callee saved register */
262 sub %esi,%esp /* stack frame for arguments */
266 mov offjniitem(%eax),%edx
268 mov offjniitem+4(%eax),%edx
271 sub $1,%ecx /* are there any args left? */
273 jle calljava_copydone
275 add $sizejniblock,%eax /* goto next argument block */
276 add $8,%edi /* increase sp to next argument */
277 jmp calljava_copyloop
280 mov 8(%ebp),%eax /* move function pointer to %eax */
282 lea asm_call_jit_compiler,%edx
283 call *%edx /* call JIT compiler */
286 add %esi,%esp /* remove arg stack frame */
287 pop %edi /* restore registers */
294 push %eax /* pass exception pointer */
295 call builtin_throw_exception
298 add %esi,%esp /* remove arg stack frame */
299 pop %edi /* restore registers */
306 /****************** function asm_call_jit_compiler *****************************
308 * invokes the compiler for untranslated JavaVM methods. *
310 * Register R0 contains a pointer to the method info structure (prepared *
311 * by createcompilerstub). Using the return address in R26 and the *
312 * offset in the LDA instruction or using the value in methodptr R28 the *
313 * patching address for storing the method address can be computed: *
315 * method address was either loaded using *
317 * i386_mov_imm_reg(a, REG_ITMP2) ; invokestatic/special *
318 * i386_call_reg(REG_ITMP2) *
322 * i386_mov_membase_reg(REG_SP, 0, REG_ITMP1) ; invokevirtual/interface *
323 * i386_mov_membase_reg(REG_ITMP1, OFFSET(, vftbl), REG_ITMP2) *
324 * i386_mov_membase_reg(REG_ITMP2, OFFSET(vftbl, table[0]) + \ *
325 * sizeof(methodptr) * m->vftblindex, REG_ITMP1) *
326 * i386_call_reg(REG_ITMP1) *
328 * in the static case the method pointer can be computed using the *
329 * return address and the lda function following the jmp instruction *
331 *******************************************************************************/
333 asm_call_jit_compiler:
334 push %ebx /* save register */
337 mov 8(%esp),%ebp /* get return address (2 push) */
338 mov -1(%ebp),%bl /* get function code */
339 cmp $0xd1,%bl /* called with `call *REG_ITMP2' (%ecx)? */
340 jne L_not_static_special
342 sub $6,%ebp /* calculate address of immediate */
343 jmp L_call_jit_compile
345 L_not_static_special:
346 cmp $0xd0,%bl /* called with `call *REG_ITMP1' (%eax) */
347 jne L_not_virtual_interface
349 sub $6,%ebp /* calculate address of offset */
350 mov (%ebp),%ebp /* get offset */
351 add itmp2,%ebp /* add base address to get method address */
352 jmp L_call_jit_compile
354 L_not_virtual_interface: /* a call from asm_calljavafunction */
358 push %ebp /* save address for method pointer */
360 push %eax /* push methodpointer on stack */
364 pop %ebp /* restore address for method pointer */
366 test %eax,%eax /* check for exception */
369 test %ebp,%ebp /* is address == 0 (asm_calljavafunction) */
372 mov %eax,(%ebp) /* and now save the new pointer */
375 pop %ebp /* restore registers */
378 jmp *%eax /* ...and now call the new method */
381 pop %ebp /* restore registers */
384 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
385 call builtin_asm_get_exceptionptrptr
387 mov (%ecx),%eax /* get the exception pointer */
388 movl $0,(%ecx) /* clear the exception pointer */
390 lea _exceptionptr,%ecx
391 mov (%ecx),%eax /* get the exception pointer */
392 movl $0,(%ecx) /* clear the exception pointer */
395 pop %ecx /* delete return address */
396 sub $2,%ecx /* faulting address is return adress - 2 */
398 L_refillinStacktrace:
399 push %ecx /* store fault adress */
400 push %eax /* temporarily save exception pointer*/
401 call builtin_asm_get_stackframeinfo
402 push %eax /* save location of thread specific stack info head pointer */
403 mov (%eax),%ecx /* save old value of pointer*/
405 mov %esp,(%eax) /*store pointer to this structure*/
406 mov 8(%esp),%eax /* get the exception pointer again*/
407 movl $0,8(%esp) /*mark this block as native*/
408 push $0 /*used for the jni_callblock structure*/
409 push %eax /*save eax for later */
410 /* get fillInStackTrace method*/
411 push utf_fillInStackTrace_desc
412 push utf_fillInStackTrace_name
413 mov offobjvftbl(%eax),%ecx
414 mov offclass(%ecx),%eax
416 call class_resolvemethod
424 call asm_calljavafunction2
427 /*remove native stack info */
436 jmp asm_handle_exception
439 /********************* function asm_handle_exception ***************************
441 * This function handles an exception. It does not use the usual calling *
442 * conventions. The exception pointer is passed in REG_ITMP1 and the *
443 * pc from the exception raising position is passed in REG_ITMP2. It searches *
444 * the local exception table for a handler. If no one is found, it unwinds *
445 * stacks and continues searching the callers. *
447 * void asm_handle_exception (exceptionptr, exceptionpc); *
449 *******************************************************************************/
451 asm_handle_nat_exception:
452 add $4,%esp /* clear return address of native stub */
454 asm_handle_exception:
458 push %eax /* exception pointer */
459 push %ecx /* excepiton pc */
461 call asm_get_stackTrace
467 asm_handle_exception_loop:
471 push %eax /* save exception pointer */
472 push %ecx /* save exception pc */
474 call codegen_findmethod /* get the data segment ptr */
478 mov -8(%ebp),%ecx /* could be changed in findmethod */
480 push %edx /* save data segment pointer */
487 mov %eax,(%esp) /* exception pointer */
488 mov MethodPointer(%edx),%eax /* method pointer */
490 mov %ecx,8(%esp) /* exception pc */
491 movl $0,12(%esp) /* line number */
492 movl $1,16(%esp) /* set no unwind flag */
493 call builtin_trace_exception
495 mov -12(%ebp),%esi /* %esi = data segment pointer */
496 mov ExTableSize(%esi),%ecx /* %ecx = exception table size */
497 test %ecx,%ecx /* if empty table skip */
500 lea ExTableStart(%esi),%edi /* %edi = start of exception table*/
501 mov -4(%ebp),%eax /* get xptr */
504 mov -8(%ebp),%edx /* get xpc */
506 mov ExStartPC(%edi),%ebx /* %ebx = exception start pc */
507 cmp %edx,%ebx /* %ebx = (startpc <= xpc) */
508 jg ex_table_cont /* if (false) continue */
509 mov ExEndPC(%edi),%ebx /* %ebx = exception end pc */
510 cmp %ebx,%edx /* %ebx = (xpc < endpc) */
511 jge ex_table_cont /* if (false) continue */
512 mov ExCatchType(%edi),%ebx /* arg1 = exception catch type */
513 test %ebx,%ebx /* NULL catches everything */
516 cmpl $0,offclassloaded(%ebx) /* check if class is loaded */
520 mov %eax,1*4(%esp) /* save not callee saved regs */
523 mov %ebx,0*4(%esp) /* exception class is argument */
531 cmpl $0,offclasslinked(%ebx)
535 mov %eax,1*4(%esp) /* save not callee saved regs */
538 mov %ebx,0*4(%esp) /* exception class is argument */
546 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
554 mov offobjvftbl(%eax),%esi /* %esi = vftblptr(xptr) */
555 mov offclassvftbl(%ebx),%ebx /* %ebx = vftblptr(catchtype) class (not obj) */
556 mov offbaseval(%esi),%esi /* %esi = baseval(xptr) */
557 mov offbaseval(%ebx),%edx /* %edx = baseval(catchtype) */
558 mov offdiffval(%ebx),%ebx /* %ebx = diffval(catchtype) */
560 sub %edx,%esi /* %esi = baseval(xptr) - baseval(catchtype) */
562 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
566 cmp %ebx,%esi /* xptr is instanceof catchtype */
570 mov ExHandlerPC(%edi),%edx
572 pop %edi /* restore registers */
575 add $8,%esp /* suck %ecx, %edx */
576 pop %eax /* restore xptr */
579 jmp *%edx /* jump to exception handler */
582 lea ExEntrySize(%edi),%edi
591 pop %edx /* restore data segment pointer */
596 push %eax /* save exception pointer */
599 mov IsSync(%edx),%eax /* %eax = SyncOffset */
600 test %eax,%eax /* if zero no monitorexit */
604 mov -4(%eax),%eax /* we have the xptr on the stack */
605 push %edx /* save regs */
607 call builtin_monitorexit
609 pop %edx /* restore regs */
613 add FrameSize(%edx),%eax /* %eax = frame size */
614 add $4,%eax /* we have the xptr on the stack */
616 mov IntSave(%edx),%ecx /* %ecx = saved int register count*/
638 shl $3,%ecx /* multiply by 8 bytes */
642 mov FltSave(%edx),%ecx /* %ecx = saved flt register count */
669 pop %eax /* restore exception pointer */
671 mov FrameSize(%edx),%ecx /* %ecx = frame size */
672 add %ecx,%esp /* unwind stack */
674 pop %ecx /* the new xpc is return address */
677 jmp asm_handle_exception_loop
680 /********************* function asm_check_clinit *******************************
682 * Does null check and calls monitorenter or throws an exception *
684 *******************************************************************************/
687 mov offclassinit(%eax),%ecx /* get initialized flag */
691 sub $16,%esp /* build stack frame (4 * 4 bytes) */
693 call builtin_asm_get_stackframeinfo
703 call class_init /* call class_init function */
711 test %eax,%eax /* we had an exception */
712 je L_initializererror
715 mov (%esp),%eax /* get return address */
716 sub $12,%eax /* asm_putstatic call code size */
717 movb $0xeb,(%eax) /* jmp rel8 */
718 movb $10,1(%eax) /* 8-bit offset */
722 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
723 call builtin_asm_get_exceptionptrptr
725 mov (%ecx),%eax /* get the exception pointer */
726 movl $0,(%ecx) /* clear the exception pointer */
728 lea _exceptionptr,%ecx
729 mov (%ecx),%eax /* get the exception pointer */
730 movl $0,(%ecx) /* clear the exception pointer */
733 pop %ecx /* delete return address */
734 sub $2,%ecx /* faulting address is return adress - 2 */
736 jmp asm_handle_exception
739 /********************* function asm_builtin_monitorenter ***********************
741 * Does null check and calls monitorenter or throws an exception *
743 *******************************************************************************/
745 asm_builtin_monitorenter:
747 je nb_monitorenter /* if (null) throw exception */
748 jmp builtin_monitorenter /* else call builtin_monitorenter */
751 mov string_java_lang_NullPointerException,%eax
754 jmp asm_throw_and_handle_exception
757 push string_java_lang_NullPointerException
761 pop %ecx /* delete return address */
762 sub $2,%ecx /* faulting address is return adress - 2 */
763 jmp asm_handle_exception
766 /********************* function asm_builtin_monitorexit ************************
768 * Does null check and calls monitorexit or throws an exception *
770 *******************************************************************************/
772 asm_builtin_monitorexit:
775 je nb_monitorexit /* if (null) throw exception */
776 push %ecx /* save registers which could be used */
779 call builtin_monitorexit /* else call builtin_monitorenter */
781 pop %edx /* restore registers which could be used */
786 mov string_java_lang_NullPointerException,%eax
789 jmp asm_throw_and_handle_exception
792 push string_java_lang_NullPointerException
796 pop %ecx /* delete return address */
797 sub $2,%ecx /* faulting address is return adress - 2 */
798 jmp asm_handle_exception
801 /************************ function asm_builtin_ldiv ****************************
803 * Does null check and calls ldiv or throws an exception *
805 *******************************************************************************/
810 test %eax,%eax /* if (null) throw exception */
818 jmp asm_throw_and_handle_hardware_arithmetic_exception
820 push string_java_lang_ArithmeticException_message
821 push string_java_lang_ArithmeticException
822 call new_exception_message
825 pop %ecx /* delete return address */
826 sub $2,%ecx /* faulting address is return adress - 2 */
827 jmp asm_handle_exception
830 /************************ function asm_builtin_lrem ****************************
832 * Does null check and calls lrem or throws an exception *
834 *******************************************************************************/
839 test %eax,%eax /* if (null) throw exception */
847 jmp asm_throw_and_handle_hardware_arithmetic_exception
849 push string_java_lang_ArithmeticException_message
850 push string_java_lang_ArithmeticException
851 call new_exception_message
854 pop %ecx /* delete return address */
855 sub $2,%ecx /* faulting address is return adress - 2 */
856 jmp asm_handle_exception
859 /************************ function asm_builtin_x2x *****************************
861 * Wrapper functions for corner cases *
863 *******************************************************************************/
894 /******************* function asm_builtin_checkarraycast ***********************
896 * Does the cast check and eventually throws an exception *
898 *******************************************************************************/
900 asm_builtin_checkarraycast:
901 sub $8,%esp /* build stack frame (2 * 4 bytes) */
903 mov 12(%esp),%eax /* 8 (frame) + 4 (return) */
904 mov %eax,(%esp) /* save object pointer */
909 call builtin_checkarraycast /* builtin_checkarraycast */
911 test %eax,%eax /* if (false) throw exception */
914 mov 12(%esp),%eax /* return object pointer */
920 mov string_java_lang_ClassCastException,%eax
923 jmp asm_throw_and_handle_exception
925 push string_java_lang_ClassCastException
931 pop %ecx /* delete return address */
932 sub $2,%ecx /* faulting address is return adress - 2 */
933 jmp asm_handle_exception
936 /******************* function asm_builtin_newarray *****************************
938 * Does the cast check and eventually throws an exception *
940 *******************************************************************************/
942 asm_builtin_newarray:
943 sub $8,%esp /* build stack frame (2 * 4 bytes) */
951 call builtin_newarray
957 /******************* function asm_builtin_aastore ******************************
959 * Does the cast check and eventually throws an exception *
961 *******************************************************************************/
964 sub $12,%esp /* build stack frame (3 * 4 bytes) */
966 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
967 test %eax,%eax /* if null pointer throw exception */
970 mov offarraysize(%eax),%edx /* load size */
971 mov 24(%esp),%ecx /* index */
972 cmp %edx,%ecx /* do bound check */
973 jae nb_aastore_bound /* if out of bounds throw exception */
975 shl $2,%ecx /* index * 4 */
976 add %eax,%ecx /* add index * 4 to arrayref */
978 mov %ecx,8(%esp) /* save store position */
980 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
983 mov 32(%esp),%eax /* object is second argument */
986 call builtin_canstore /* builtin_canstore(arrayref,object) */
988 test %eax,%eax /* if (false) throw exception */
993 mov %eax,offobjarrdata(%ecx) /* store objectptr in array */
1000 mov string_java_lang_NullPointerException,%eax
1003 jmp asm_throw_and_handle_exception
1006 push string_java_lang_NullPointerException
1011 pop %ecx /* delete return address */
1012 sub $2,%ecx /* faulting address is return adress - 2 */
1013 jmp asm_handle_exception
1016 push %ecx /* itmp2 contains array index */
1017 push string_java_lang_ArrayIndexOutOfBoundsException
1018 call new_exception_int
1022 pop %ecx /* delete return address */
1023 sub $2,%ecx /* faulting address is return adress - 2 */
1024 jmp asm_handle_exception
1029 mov string_java_lang_ArrayStoreException,%eax
1032 jmp asm_throw_and_handle_exception
1035 push string_java_lang_ArrayStoreException
1040 pop %ecx /* delete return address */
1041 sub $2,%ecx /* faulting address is return adress - 2 */
1042 jmp asm_handle_exception
1045 /******************* function asm_builtin_arrayinstanceof **********************
1047 * Does the instanceof check of arrays *
1049 *******************************************************************************/
1051 asm_builtin_arrayinstanceof:
1052 sub $8,%esp /* build stack frame (2 * 4 bytes) */
1060 call builtin_arrayinstanceof
1066 /******************* function asm_initialize_thread_stack **********************
1068 * initialized a thread stack *
1069 * (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), (to)->stackEnd)*
1071 *******************************************************************************/
1073 asm_initialize_thread_stack:
1074 mov 8(%esp),%eax /* (to)->stackEnd */
1075 sub $36,%eax /* 4 bytes * 8 regs + 4 bytes func */
1087 mov 4(%esp),%edx /* save (u1*) (func) */
1090 ret /* return restorepoint in %eax */
1093 /******************* function asm_perform_threadswitch *************************
1095 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1097 * performs a threadswitch *
1099 *******************************************************************************/
1101 asm_perform_threadswitch:
1113 mov 36(%esp),%eax /* save current return address */
1116 mov 40(%esp),%eax /* first argument **from */
1119 mov 48(%esp),%eax /* third argument **stackTop */
1122 mov 44(%esp),%eax /* second argument **to */
1123 mov 0(%eax),%esp /* load new stack pointer */
1129 /* skip stack pointer */
1134 add $32,%esp /* leave return address on stack */
1138 /********************* function asm_switchstackandcall *************************
1140 * int asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1143 * Switches to a new stack, calls a function and switches back. *
1144 * a0 new stack pointer *
1145 * a1 function pointer *
1146 * a2 pointer to variable where stack top should be stored *
1147 * a3 pointer to user data, is passed to the function *
1149 *******************************************************************************/
1151 asm_switchstackandcall:
1152 mov 4(%esp),%edx /* first argument *stack */
1153 sub $8,%edx /* allocate new stack */
1155 mov (%esp),%eax /* save return address on new stack */
1158 mov %esp,4(%edx) /* save old stack pointer on new stack */
1160 mov 12(%esp),%eax /* third argument **stacktopsave */
1161 mov %esp,(%eax) /* save old stack pointer to variable */
1163 mov 8(%esp),%eax /* load function pointer */
1164 mov 16(%esp),%ecx /* fourth argument *p */
1166 mov %edx,%esp /* switch to new stack */
1169 mov %ecx,0(%esp) /* pass pointer */
1170 call *%eax /* and call function */
1173 mov (%esp),%edx /* load return address */
1174 mov 4(%esp),%esp /* switch to old stack */
1179 Java_java_lang_VMSecurityManager_currentClassLoader:
1180 lea builtin_asm_getclassloader,%eax
1181 push %eax /*store collector function pointer*/
1182 jmp getClassContext_begin
1183 Java_java_lang_VMSecurityManager_getClassContext:
1184 lea builtin_asm_createclasscontextarray,%eax
1185 push %eax /*store collector function pointer*/
1186 getClassContext_begin: /*start the real work*/
1190 sub $68,%esp /*64 memory location without overwriting return adress and collector function adress*/
1191 mov %esp,%ebx /*end of allocated memory block for classpointers is the adress of the working data block +4 */
1192 push $0 /*%esp+32 was native*/
1193 push %eax /*%esp+24 blkbegin*/
1194 push %eax /*%esp+20 currentpos*/
1195 push %ebx /*%esp+16 blkend*/
1197 call builtin_asm_get_threadrootmethod
1198 push %eax /*%esp+12*/
1199 movl 104(%esp),%eax /*(stack contains: threadRootMethod,blkend,blkpos,blkbegin,was native, data(64kB),collector,ret,env,class,frame stack info of stub, we want the frame stack info of thestub*/
1202 push %edx /*esp+8*/ /*position of return address of native stub*/
1203 call builtin_asm_get_stackframeinfo
1204 movl (%eax),%eax /*comment ??*/
1205 push 0(%eax) /*esp+4*/ /*address of frame info block*/
1212 call i386_native_stub_debug
1215 push %edx /*esp+0*/ /*return adress out of native stub*/
1216 call codegen_findmethod /*find calling java method, this one is still to be skipped (==SecurityManager.getClassContext (or .currentClassLoader)*/
1220 movl MethodPointer(%eax),%eax
1222 call temporaryGetClassContextHelper
1224 call traverseStackInfo
1229 movl MethodPointer(%eax),%ebx
1230 movl offclassmethodinfo(%ebx),%ecx
1235 mov 8(%esp),%ebx /*pos of return adress */
1236 add FrameSize(%eax),%ebx
1237 add $4,%ebx /*adress of new return adress (out of Securitymanager.*/
1241 /* by now we have skipped this method call*/
1243 getClassContext_next:
1246 movl %eax,(%esp) /*return adress*/
1248 call codegen_findmethod
1252 add FrameSize(%eax),%ebx
1254 mov %ebx,8(%esp) /*store adress of next return adress*/
1255 getClassContext_nextRetStored:
1257 mov MethodPointer(%eax),%ecx /*get struct methodinfo*/
1260 je getClassContext_nativeCall
1261 /*save class pointer*/
1263 getClassContext_saveClassPointer:
1264 movl 20(%esp),%ebx /*get temporary memory adress in stack*/
1265 movl offclassmethodinfo(%ecx),%edx /* get class pointer of method*/
1266 movl %edx,(%ebx) /*save */
1267 sub $4,%ebx /*calculate next position */
1268 movl %ebx,20(%esp) /* check if the new adress would overwrite our working data */
1270 je getClassContext_incStack
1271 getClassContext_checkLeave:
1273 cmp 12(%esp),%ecx /*check if we reached the toplevel method of our thread*/
1274 je getClassContext_leave /*yes ->leave*/
1278 call temporaryGetClassContextHelper
1282 jmp getClassContext_next /*continue*/
1285 getClassContext_nativeCall:
1287 movl 4(%esp),%eax /*get top most element on stackframe help information stack*/
1296 je getClassContext_checkLeave
1297 jmp getClassContext_saveClassPointer
1299 getClassContext_incStack:
1300 /*make another 64 in our temporary storage free and store the workingdata */
1302 subl $40,%esp /*should be 32*/
1314 jmp getClassContext_checkLeave /* continue */
1316 getClassContext_leave:
1319 call temporaryGetClassContextHelper*/
1321 /*call collector function with begin/end of temporary classarray*/
1330 /* free stack memory of this function*/
1336 asm_throw_and_handle_exception:
1337 sub $20,%esp /*build stack frame*/
1338 mov %ecx,16(%esp) /*save eip of problem */
1340 movl $0,12(%esp) /*internal function -> no function description */
1341 call builtin_asm_get_stackframeinfo
1349 /* mov string_java_lang_NullPointerException,%eax
1359 jmp asm_handle_exception
1360 ret /*should never be reached */
1362 asm_throw_and_handle_hardware_arithmetic_exception:
1363 sub $24,%esp /*build stack frame*/
1364 mov %ecx,20(%esp) /*save eip of problem */
1366 movl $0,16(%esp) /*internal function -> no function description */
1367 call builtin_asm_get_stackframeinfo
1375 mov string_java_lang_ArithmeticException,%eax
1377 mov string_java_lang_ArithmeticException_message,%eax
1380 call new_exception_message
1389 jmp asm_handle_exception
1390 ret /*should never be reached */
1393 /*optimize a littlebit */
1397 call i386_native_stub_debug
1401 mov offclassinit(%eax),%ecx /* get initialized flag */
1403 jnz L_builtin_new_noinit
1405 sub $16,%esp /* build stack frame (4 * 4 bytes) */
1410 call builtin_asm_get_stackframeinfo
1427 jmp L_builtin_new_patch
1430 L_builtin_new_noinit:
1435 /*jmp L_builtin_new_patch*/
1437 L_builtin_new_patch:
1438 /*add patching code here */
1439 lea builtin_new,%edx
1441 mov %edx,-6(%ecx) /*patch calling instruction, t directly call builtin_new the next time*/
1449 push %ebp /*(%ebp-4)*/
1452 push %edi /*(%ebp-8)*/
1453 push %esi /*(%ebp-12)*/
1454 push %ebx /*(%ebp-16)*/
1455 call builtin_asm_get_stackframeinfo
1457 pushl 0(%eax) /*(%ebp-20)*/
1459 call builtin_asm_get_threadrootmethod
1460 pushl %eax /*(%ebp-24)*/
1463 asm_get_stackTraceLoop:
1464 call codegen_findmethod
1467 pushl $1 /*no indent*/
1472 get_stackTrace_line:
1473 movl LineNumberTableSize(%esi),%ecx
1474 test %ecx,%ecx /* skip if empty line table */
1475 je get_stackTrace_noLineInfo
1477 movl LineNumberTableStart(%esi),%ebx
1479 get_stackTrace_lineLoop:
1480 cmp %edx,LinePC(%ebx)
1481 jg get_stackTrace_nextLineInfo
1483 pushl LineLine(%ebx)
1484 jmp get_stackTrace_cont
1486 get_stackTrace_nextLineInfo:
1487 lea LineEntrySize(%ebx),%ebx
1491 jne get_stackTrace_lineLoop
1493 get_stackTrace_noLineInfo:
1497 get_stackTrace_cont:
1499 pushl MethodPointer(%esi)
1500 pushl $0 /*8(%ebp)*/ /*exception ptr*/
1501 call builtin_trace_exception
1504 movl MethodPointer(%esi),%eax
1507 je get_stackTrace_nat
1510 je get_stackTrace_leave
1512 mov FrameSize(%esi),%eax
1516 jmp asm_get_stackTraceLoop
1522 je get_stackTrace_leave
1529 jmp asm_get_stackTraceLoop
1531 get_stackTrace_leave:
1537 call builtin_stacktrace_copy
1546 asm_getclassvalues_atomic:
1548 mov 4(%esp),%ecx /* super */
1549 mov 8(%esp),%edx /* sub */
1551 mov offbaseval(%ecx),%eax
1552 mov offdiffval(%ecx),%ecx
1553 mov offbaseval(%edx),%edx
1556 mov 16(%esp),%ebx /* out */
1557 mov %eax,offcast_super_baseval(%ebx)
1558 mov %ecx,offcast_super_diffval(%ebx)
1559 mov %edx,offcast_sub_baseval(%ebx)
1565 asm_criticalsections:
1566 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1569 .long _crit_restart1
1572 .long _crit_restart2
1577 * These are local overrides for various environment variables in Emacs.
1578 * Please do not remove this and leave it at the end of the file, where
1579 * Emacs will automagically detect them.
1580 * ---------------------------------------------------------------------
1583 * indent-tabs-mode: t