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 1460 2004-11-05 16:23:29Z twisti $
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 calljava_xhandler
77 .globl asm_calljavafunction2
78 .globl asm_calljavafunction2long
79 .globl asm_calljavafunction2double
80 .globl calljava_xhandler2
82 .globl asm_call_jit_compiler
83 .globl asm_handle_builtin_exception
84 .globl asm_handle_nat_exception
85 .globl asm_handle_exception
86 .globl asm_check_clinit
87 .globl asm_builtin_checkcast
88 .globl asm_builtin_checkarraycast
89 .globl asm_builtin_newarray
90 .globl asm_builtin_anewarray
91 .globl asm_builtin_newarray_array
92 .globl asm_builtin_aastore
93 .globl asm_builtin_monitorenter
94 .globl asm_builtin_monitorexit
95 .globl asm_builtin_ldiv
96 .globl asm_builtin_lrem
97 .globl asm_builtin_f2i
98 .globl asm_builtin_f2l
99 .globl asm_builtin_d2i
100 .globl asm_builtin_d2l
101 .globl asm_builtin_arrayinstanceof
102 .globl asm_perform_threadswitch
103 .globl asm_initialize_thread_stack
104 .globl asm_switchstackandcall
105 .globl asm_getcallingmethod
106 .globl Java_java_lang_VMSecurityManager_getClassContext
107 .globl Java_java_lang_VMSecurityManager_currentClassLoader
108 .globl asm_builtin_new
109 .globl asm_get_stackTrace
110 .globl asm_criticalsections
111 .globl asm_getclassvalues_atomic
113 /*************************** imported functions *******************************/
116 .globl builtin_monitorexit
117 .globl builtin_throw_exception
118 .globl builtin_trace_exception
119 .globl class_java_lang_Object
120 .globl codegen_findmethod
121 /* .globl codegen_findmethod1*/
122 .globl builtin_asm_createclasscontextarray
123 .globl builtin_asm_getclassloader
124 .globl callgetexceptionptrptr
125 .globl asm_throw_and_handle_exception
126 .globl asm_throw_and_handle_hardware_arithmetic_exception
129 /********************* function asm_calljavafunction ***************************
131 * This function calls a Java-method (which possibly needs compilation) *
132 * with up to 4 address parameters. *
134 * This functions calls the JIT-compiler which eventually translates the *
135 * method into machine code. *
138 * javaobject_header *asm_calljavamethod (methodinfo *m, *
139 * void *arg1, void *arg2, void *arg3, void *arg4); *
141 *******************************************************************************/
144 .ascii "calljavafunction\0\0"
147 .long 0 /* catch type all */
148 .long calljava_xhandler /* handler pc */
149 .long calljava_xhandler /* end pc */
150 .long asm_calljavafunction /* start pc */
151 .long 1 /* extable size */
152 .long 0 /* line number table start */
153 .long 0 /* line number table size */
154 .long 0 /* fltsave */
155 .long 0 /* intsave */
158 .long 32 /* frame size */
159 .long 0 /* method pointer (pointer to name) */
161 asm_calljavafunction:
162 push %ebp /* allocate stack space */
165 push %ebx /* save registers */
169 sub $32,%esp /* pass the remaining parameters */
172 mov %edx,28(%esp) /* convert parms to 8 byte */
188 mov 8(%ebp),%eax /* move function pointer to %eax */
190 lea asm_call_jit_compiler,%edx
191 call *%edx /* call JIT compiler */
194 pop %edi /* restore registers */
201 push %eax /* pass exception pointer */
202 call builtin_throw_exception
206 pop %edi /* restore registers */
213 /********************* function asm_calljavafunction ***************************
215 * This function calls a Java-method (which possibly needs compilation) *
216 * with up to 4 address parameters. *
218 * This functions calls the JIT-compiler which eventually translates the *
219 * method into machine code. *
222 * javaobject_header *asm_calljavafunction2(methodinfo *m, *
223 * u4 count, u4 size, void *callblock); *
225 *******************************************************************************/
228 .ascii "calljavafunction2\0\0"
231 .long 0 /* catch type all */
232 .long calljava_xhandler2 /* handler pc */
233 .long calljava_xhandler2 /* end pc */
234 .long asm_calljavafunction2 /* start pc */
235 .long 1 /* extable size */
236 .long 0 /* line number table start */
237 .long 0 /* line number table size */
238 .long 0 /* fltsave */
239 .long 0 /* intsave */
242 .long 32 /* frame size */
243 .long 0 /* method pointer (pointer to name) */
245 asm_calljavafunction2:
246 asm_calljavafunction2double:
247 asm_calljavafunction2long:
249 mov %esp,%ebp /* save stackptr */
251 push %ebx /* save registers */
255 mov 20(%ebp),%eax /* pointer to arg block */
256 mov 12(%ebp),%ecx /* arg count */
257 test %ecx,%ecx /* maybe we have no args */
258 jle calljava_copydone
260 mov %ecx,%edx /* calculate stack size */
262 mov %edx,%esi /* save in callee saved register */
263 sub %esi,%esp /* stack frame for arguments */
267 mov offjniitem(%eax),%edx
269 mov offjniitem+4(%eax),%edx
272 sub $1,%ecx /* are there any args left? */
274 jle calljava_copydone
276 add $sizejniblock,%eax /* goto next argument block */
277 add $8,%edi /* increase sp to next argument */
278 jmp calljava_copyloop
281 mov 8(%ebp),%eax /* move function pointer to %eax */
283 lea asm_call_jit_compiler,%edx
284 call *%edx /* call JIT compiler */
287 add %esi,%esp /* remove arg stack frame */
288 pop %edi /* restore registers */
295 push %eax /* pass exception pointer */
296 call builtin_throw_exception
299 add %esi,%esp /* remove arg stack frame */
300 pop %edi /* restore registers */
307 /****************** function asm_call_jit_compiler *****************************
309 * invokes the compiler for untranslated JavaVM methods. *
311 * Register R0 contains a pointer to the method info structure (prepared *
312 * by createcompilerstub). Using the return address in R26 and the *
313 * offset in the LDA instruction or using the value in methodptr R28 the *
314 * patching address for storing the method address can be computed: *
316 * method address was either loaded using *
318 * i386_mov_imm_reg(a, REG_ITMP2) ; invokestatic/special *
319 * i386_call_reg(REG_ITMP2) *
323 * i386_mov_membase_reg(REG_SP, 0, REG_ITMP1) ; invokevirtual/interface *
324 * i386_mov_membase_reg(REG_ITMP1, OFFSET(, vftbl), REG_ITMP2) *
325 * i386_mov_membase_reg(REG_ITMP2, OFFSET(vftbl, table[0]) + \ *
326 * sizeof(methodptr) * m->vftblindex, REG_ITMP1) *
327 * i386_call_reg(REG_ITMP1) *
329 * in the static case the method pointer can be computed using the *
330 * return address and the lda function following the jmp instruction *
332 *******************************************************************************/
334 asm_call_jit_compiler:
335 push %ebx /* save register */
338 mov 8(%esp),%ebp /* get return address (2 push) */
339 mov -1(%ebp),%bl /* get function code */
340 cmp $0xd1,%bl /* called with `call *REG_ITMP2' (%ecx)? */
341 jne L_not_static_special
343 sub $6,%ebp /* calculate address of immediate */
344 jmp L_call_jit_compile
346 L_not_static_special:
347 cmp $0xd0,%bl /* called with `call *REG_ITMP1' (%eax) */
348 jne L_not_virtual_interface
350 sub $6,%ebp /* calculate address of offset */
351 mov (%ebp),%ebp /* get offset */
352 add itmp2,%ebp /* add base address to get method address */
353 jmp L_call_jit_compile
355 L_not_virtual_interface: /* a call from asm_calljavafunction */
359 push %ebp /* save address for method pointer */
361 push %eax /* push methodpointer on stack */
365 pop %ebp /* restore address for method pointer */
367 test %eax,%eax /* check for exception */
370 test %ebp,%ebp /* is address == 0 (asm_calljavafunction) */
373 mov %eax,(%ebp) /* and now save the new pointer */
376 pop %ebp /* restore registers */
379 jmp *%eax /* ...and now call the new method */
382 pop %ebp /* restore registers */
385 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
386 call builtin_asm_get_exceptionptrptr
388 mov (%ecx),%eax /* get the exception pointer */
389 movl $0,(%ecx) /* clear the exception pointer */
391 lea _exceptionptr,%ecx
392 mov (%ecx),%eax /* get the exception pointer */
393 movl $0,(%ecx) /* clear the exception pointer */
396 pop %ecx /* delete return address */
397 sub $2,%ecx /* faulting address is return adress - 2 */
399 L_refillinStacktrace:
400 push %ecx /* store fault adress */
401 push %eax /* temporarily save exception pointer*/
402 call builtin_asm_get_stackframeinfo
403 push %eax /* save location of thread specific stack info head pointer */
404 mov (%eax),%ecx /* save old value of pointer*/
406 mov %esp,(%eax) /*store pointer to this structure*/
407 mov 8(%esp),%eax /* get the exception pointer again*/
408 movl $0,8(%esp) /*mark this block as native*/
409 push $0 /*used for the jni_callblock structure*/
410 push %eax /*save eax for later */
411 /* get fillInStackTrace method*/
412 push utf_fillInStackTrace_desc
413 push utf_fillInStackTrace_name
414 mov offobjvftbl(%eax),%ecx
415 mov offclass(%ecx),%eax
417 call class_resolvemethod
425 call asm_calljavafunction2
428 /*remove native stack info */
437 jmp asm_handle_exception
440 /********************* function asm_handle_exception ***************************
442 * This function handles an exception. It does not use the usual calling *
443 * conventions. The exception pointer is passed in REG_ITMP1 and the *
444 * pc from the exception raising position is passed in REG_ITMP2. It searches *
445 * the local exception table for a handler. If no one is found, it unwinds *
446 * stacks and continues searching the callers. *
448 * void asm_handle_exception (exceptionptr, exceptionpc); *
450 *******************************************************************************/
452 asm_handle_nat_exception:
453 add $4,%esp /* clear return address of native stub */
455 asm_handle_exception:
459 push %eax /* exception pointer */
460 push %ecx /* excepiton pc */
462 call asm_get_stackTrace
468 asm_handle_exception_loop:
472 push %eax /* save exception pointer */
473 push %ecx /* save exception pc */
475 call codegen_findmethod /* get the data segment ptr */
479 mov -8(%ebp),%ecx /* could be changed in findmethod */
481 push %edx /* save data segment pointer */
488 mov %eax,(%esp) /* exception pointer */
489 mov MethodPointer(%edx),%eax /* method pointer */
491 mov %ecx,8(%esp) /* exception pc */
492 movl $0,12(%esp) /* line number */
493 movl $1,16(%esp) /* set no unwind flag */
494 call builtin_trace_exception
496 mov -12(%ebp),%esi /* %esi = data segment pointer */
497 mov ExTableSize(%esi),%ecx /* %ecx = exception table size */
498 test %ecx,%ecx /* if empty table skip */
501 lea ExTableStart(%esi),%edi /* %edi = start of exception table*/
502 mov -4(%ebp),%eax /* get xptr */
505 mov -8(%ebp),%edx /* get xpc */
507 mov ExStartPC(%edi),%ebx /* %ebx = exception start pc */
508 cmp %edx,%ebx /* %ebx = (startpc <= xpc) */
509 jg ex_table_cont /* if (false) continue */
510 mov ExEndPC(%edi),%ebx /* %ebx = exception end pc */
511 cmp %ebx,%edx /* %ebx = (xpc < endpc) */
512 jge ex_table_cont /* if (false) continue */
513 mov ExCatchType(%edi),%ebx /* arg1 = exception catch type */
514 test %ebx,%ebx /* NULL catches everything */
517 cmpl $0,offclassloaded(%ebx) /* check if class is loaded */
521 mov %eax,1*4(%esp) /* save not callee saved regs */
524 mov %ebx,0*4(%esp) /* exception class is argument */
533 cmpl $0,offclasslinked(%ebx)
537 mov %eax,1*4(%esp) /* save not callee saved regs */
540 mov %ebx,0*4(%esp) /* exception class is argument */
549 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
557 mov offobjvftbl(%eax),%esi /* %esi = vftblptr(xptr) */
558 mov offclassvftbl(%ebx),%ebx /* %ebx = vftblptr(catchtype) class (not obj) */
559 mov offbaseval(%esi),%esi /* %esi = baseval(xptr) */
560 mov offbaseval(%ebx),%edx /* %edx = baseval(catchtype) */
561 mov offdiffval(%ebx),%ebx /* %ebx = diffval(catchtype) */
563 sub %edx,%esi /* %esi = baseval(xptr) - baseval(catchtype) */
565 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
569 cmp %ebx,%esi /* xptr is instanceof catchtype */
573 mov ExHandlerPC(%edi),%edx
575 pop %edi /* restore registers */
578 add $8,%esp /* suck %ecx, %edx */
579 pop %eax /* restore xptr */
582 jmp *%edx /* jump to exception handler */
585 lea ExEntrySize(%edi),%edi
594 pop %edx /* restore data segment pointer */
599 push %eax /* save exception pointer */
602 mov IsSync(%edx),%eax /* %eax = SyncOffset */
603 test %eax,%eax /* if zero no monitorexit */
607 mov -4(%eax),%eax /* we have the xptr on the stack */
608 push %edx /* save regs */
610 call builtin_monitorexit
612 pop %edx /* restore regs */
616 add FrameSize(%edx),%eax /* %eax = frame size */
617 add $4,%eax /* we have the xptr on the stack */
619 mov IntSave(%edx),%ecx /* %ecx = saved int register count*/
641 shl $3,%ecx /* multiply by 8 bytes */
645 mov FltSave(%edx),%ecx /* %ecx = saved flt register count */
672 pop %eax /* restore exception pointer */
674 mov FrameSize(%edx),%ecx /* %ecx = frame size */
675 add %ecx,%esp /* unwind stack */
677 pop %ecx /* the new xpc is return address */
680 jmp asm_handle_exception_loop
683 /********************* function asm_check_clinit *******************************
685 * Does null check and calls monitorenter or throws an exception *
687 *******************************************************************************/
690 mov offclassinit(%eax),%ecx /* get initialized flag */
694 sub $16,%esp /* build stack frame (4 * 4 bytes) */
695 mov %eax,(%esp) /* put classpointer on stack */
696 call builtin_asm_get_stackframeinfo
706 call class_init /* call class_init function */
714 test %eax,%eax /* we had an exception */
715 je L_initializererror
718 mov (%esp),%eax /* get return address */
719 sub $12,%eax /* asm_check_clinit call code size */
720 movw $0x0aeb,(%eax) /* 0xeb = jmp rel8, 0x0a = 10 byte */
725 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
726 call builtin_asm_get_exceptionptrptr
728 mov (%ecx),%eax /* get the exception pointer */
729 movl $0,(%ecx) /* clear the exception pointer */
731 lea _exceptionptr,%ecx
732 mov (%ecx),%eax /* get the exception pointer */
733 movl $0,(%ecx) /* clear the exception pointer */
736 pop %ecx /* delete return address */
737 sub $2,%ecx /* faulting address is return adress - 2 */
739 jmp asm_handle_exception
742 /********************* function asm_builtin_monitorenter ***********************
744 * Does null check and calls monitorenter or throws an exception *
746 *******************************************************************************/
748 asm_builtin_monitorenter:
750 je nb_monitorenter /* if (null) throw exception */
751 jmp builtin_monitorenter /* else call builtin_monitorenter */
754 mov string_java_lang_NullPointerException,%eax
757 jmp asm_throw_and_handle_exception
760 push string_java_lang_NullPointerException
764 pop %ecx /* delete return address */
765 sub $2,%ecx /* faulting address is return adress - 2 */
766 jmp asm_handle_exception
769 /********************* function asm_builtin_monitorexit ************************
771 * Does null check and calls monitorexit or throws an exception *
773 *******************************************************************************/
775 asm_builtin_monitorexit:
778 je nb_monitorexit /* if (null) throw exception */
779 push %ecx /* save registers which could be used */
782 call builtin_monitorexit /* else call builtin_monitorenter */
784 pop %edx /* restore registers which could be used */
789 mov string_java_lang_NullPointerException,%eax
792 jmp asm_throw_and_handle_exception
795 push string_java_lang_NullPointerException
799 pop %ecx /* delete return address */
800 sub $2,%ecx /* faulting address is return adress - 2 */
801 jmp asm_handle_exception
804 /************************ function asm_builtin_ldiv ****************************
806 * Does null check and calls ldiv or throws an exception *
808 *******************************************************************************/
813 test %eax,%eax /* if (null) throw exception */
821 jmp asm_throw_and_handle_hardware_arithmetic_exception
823 push string_java_lang_ArithmeticException_message
824 push string_java_lang_ArithmeticException
825 call new_exception_message
828 pop %ecx /* delete return address */
829 sub $2,%ecx /* faulting address is return adress - 2 */
830 jmp asm_handle_exception
833 /************************ function asm_builtin_lrem ****************************
835 * Does null check and calls lrem or throws an exception *
837 *******************************************************************************/
842 test %eax,%eax /* if (null) throw exception */
850 jmp asm_throw_and_handle_hardware_arithmetic_exception
852 push string_java_lang_ArithmeticException_message
853 push string_java_lang_ArithmeticException
854 call new_exception_message
857 pop %ecx /* delete return address */
858 sub $2,%ecx /* faulting address is return adress - 2 */
859 jmp asm_handle_exception
862 /************************ function asm_builtin_x2x *****************************
864 * Wrapper functions for corner cases *
866 *******************************************************************************/
897 /******************* function asm_builtin_checkarraycast ***********************
899 * Does the cast check and eventually throws an exception *
901 *******************************************************************************/
903 asm_builtin_checkarraycast:
904 sub $8,%esp /* build stack frame (2 * 4 bytes) */
906 mov 12(%esp),%eax /* 8 (frame) + 4 (return) */
907 mov %eax,(%esp) /* save object pointer */
912 call builtin_checkarraycast /* builtin_checkarraycast */
914 test %eax,%eax /* if (false) throw exception */
917 mov 12(%esp),%eax /* return object pointer */
923 mov string_java_lang_ClassCastException,%eax
926 jmp asm_throw_and_handle_exception
928 push string_java_lang_ClassCastException
934 pop %ecx /* delete return address */
935 sub $2,%ecx /* faulting address is return adress - 2 */
936 jmp asm_handle_exception
939 /******************* function asm_builtin_newarray *****************************
941 * Does the cast check and eventually throws an exception *
943 *******************************************************************************/
945 asm_builtin_newarray:
946 sub $8,%esp /* build stack frame (2 * 4 bytes) */
954 call builtin_newarray
960 /******************* function asm_builtin_aastore ******************************
962 * Does the cast check and eventually throws an exception *
964 *******************************************************************************/
967 sub $12,%esp /* build stack frame (3 * 4 bytes) */
969 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
970 test %eax,%eax /* if null pointer throw exception */
973 mov offarraysize(%eax),%edx /* load size */
974 mov 24(%esp),%ecx /* index */
975 cmp %edx,%ecx /* do bound check */
976 jae nb_aastore_bound /* if out of bounds throw exception */
978 shl $2,%ecx /* index * 4 */
979 add %eax,%ecx /* add index * 4 to arrayref */
981 mov %ecx,8(%esp) /* save store position */
983 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
986 mov 32(%esp),%eax /* object is second argument */
989 call builtin_canstore /* builtin_canstore(arrayref,object) */
991 test %eax,%eax /* if (false) throw exception */
996 mov %eax,offobjarrdata(%ecx) /* store objectptr in array */
1003 mov string_java_lang_NullPointerException,%eax
1006 jmp asm_throw_and_handle_exception
1009 push string_java_lang_NullPointerException
1014 pop %ecx /* delete return address */
1015 sub $2,%ecx /* faulting address is return adress - 2 */
1016 jmp asm_handle_exception
1019 push %ecx /* itmp2 contains array index */
1020 call new_arrayindexoutofboundsexception
1024 pop %ecx /* delete return address */
1025 sub $2,%ecx /* faulting address is return adress - 2 */
1026 jmp asm_handle_exception
1031 mov string_java_lang_ArrayStoreException,%eax
1034 jmp asm_throw_and_handle_exception
1037 push string_java_lang_ArrayStoreException
1042 pop %ecx /* delete return address */
1043 sub $2,%ecx /* faulting address is return adress - 2 */
1044 jmp asm_handle_exception
1047 /******************* function asm_builtin_arrayinstanceof **********************
1049 * Does the instanceof check of arrays *
1051 *******************************************************************************/
1053 asm_builtin_arrayinstanceof:
1054 sub $8,%esp /* build stack frame (2 * 4 bytes) */
1062 call builtin_arrayinstanceof
1068 /******************* function asm_initialize_thread_stack **********************
1070 * initialized a thread stack *
1071 * (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), (to)->stackEnd)*
1073 *******************************************************************************/
1075 asm_initialize_thread_stack:
1076 mov 8(%esp),%eax /* (to)->stackEnd */
1077 sub $36,%eax /* 4 bytes * 8 regs + 4 bytes func */
1089 mov 4(%esp),%edx /* save (u1*) (func) */
1092 ret /* return restorepoint in %eax */
1095 /******************* function asm_perform_threadswitch *************************
1097 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1099 * performs a threadswitch *
1101 *******************************************************************************/
1103 asm_perform_threadswitch:
1115 mov 36(%esp),%eax /* save current return address */
1118 mov 40(%esp),%eax /* first argument **from */
1121 mov 48(%esp),%eax /* third argument **stackTop */
1124 mov 44(%esp),%eax /* second argument **to */
1125 mov 0(%eax),%esp /* load new stack pointer */
1131 /* skip stack pointer */
1136 add $32,%esp /* leave return address on stack */
1140 /********************* function asm_switchstackandcall *************************
1142 * int asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1145 * Switches to a new stack, calls a function and switches back. *
1146 * a0 new stack pointer *
1147 * a1 function pointer *
1148 * a2 pointer to variable where stack top should be stored *
1149 * a3 pointer to user data, is passed to the function *
1151 *******************************************************************************/
1153 asm_switchstackandcall:
1154 mov 4(%esp),%edx /* first argument *stack */
1155 sub $8,%edx /* allocate new stack */
1157 mov (%esp),%eax /* save return address on new stack */
1160 mov %esp,4(%edx) /* save old stack pointer on new stack */
1162 mov 12(%esp),%eax /* third argument **stacktopsave */
1163 mov %esp,(%eax) /* save old stack pointer to variable */
1165 mov 8(%esp),%eax /* load function pointer */
1166 mov 16(%esp),%ecx /* fourth argument *p */
1168 mov %edx,%esp /* switch to new stack */
1171 mov %ecx,0(%esp) /* pass pointer */
1172 call *%eax /* and call function */
1175 mov (%esp),%edx /* load return address */
1176 mov 4(%esp),%esp /* switch to old stack */
1181 Java_java_lang_VMSecurityManager_currentClassLoader:
1182 mov cacao_initializing,%eax
1184 jz Java_java_lang_VMSecurityManager_cont
1188 Java_java_lang_VMSecurityManager_cont:
1189 lea builtin_asm_getclassloader,%eax
1190 push %eax /*store collector function pointer*/
1191 jmp getClassContext_begin
1192 Java_java_lang_VMSecurityManager_getClassContext:
1193 lea builtin_asm_createclasscontextarray,%eax
1194 push %eax /*store collector function pointer*/
1195 getClassContext_begin: /*start the real work*/
1199 sub $68,%esp /*64 memory location without overwriting return adress and collector function adress*/
1200 mov %esp,%ebx /*end of allocated memory block for classpointers is the adress of the working data block +4 */
1201 push $0 /*%esp+32 was native*/
1202 push %eax /*%esp+24 blkbegin*/
1203 push %eax /*%esp+20 currentpos*/
1204 push %ebx /*%esp+16 blkend*/
1206 call builtin_asm_get_threadrootmethod
1207 push %eax /*%esp+12*/
1208 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*/
1211 push %edx /*esp+8*/ /*position of return address of native stub*/
1212 call builtin_asm_get_stackframeinfo
1213 /* movl (%eax),%eax*/ /*TEST*/
1214 push 0(%eax) /*esp+4*/ /*address of frame info block*/
1221 call i386_native_stub_debug
1224 push %edx /*esp+0*/ /*return adress out of native stub*/
1225 call codegen_findmethod /*find calling java method, this one is still to be skipped (==SecurityManager.getClassContext (or .currentClassLoader)*/
1229 movl MethodPointer(%eax),%eax
1231 call temporaryGetClassContextHelper
1233 call traverseStackInfo
1238 movl MethodPointer(%eax),%ebx
1239 movl offclassmethodinfo(%ebx),%ecx
1244 mov 8(%esp),%ebx /*pos of return adress */
1245 add FrameSize(%eax),%ebx
1246 add $4,%ebx /*adress of new return adress (out of Securitymanager.*/
1250 /* by now we have skipped this method call*/
1252 getClassContext_next:
1255 movl %eax,(%esp) /*return adress*/
1257 call codegen_findmethod
1261 add FrameSize(%eax),%ebx
1263 mov %ebx,8(%esp) /*store adress of next return adress*/
1264 getClassContext_nextRetStored:
1266 mov MethodPointer(%eax),%ecx /*get struct methodinfo*/
1269 je getClassContext_nativeCall
1270 /*save class pointer*/
1272 getClassContext_saveClassPointer:
1273 movl 20(%esp),%ebx /*get temporary memory adress in stack*/
1274 movl offclassmethodinfo(%ecx),%edx /* get class pointer of method*/
1275 movl %edx,(%ebx) /*save */
1276 sub $4,%ebx /*calculate next position */
1277 movl %ebx,20(%esp) /* check if the new adress would overwrite our working data */
1279 je getClassContext_incStack
1280 getClassContext_checkLeave:
1282 cmp 12(%esp),%ecx /*check if we reached the toplevel method of our thread*/
1283 je getClassContext_leave /*yes ->leave*/
1287 call temporaryGetClassContextHelper
1291 jmp getClassContext_next /*continue*/
1294 getClassContext_nativeCall:
1296 movl 4(%esp),%eax /*get top most element on stackframe help information stack*/
1298 jz getClassContext_leave
1307 je getClassContext_checkLeave
1308 jmp getClassContext_saveClassPointer
1310 getClassContext_incStack:
1311 /*make another 64 in our temporary storage free and store the workingdata */
1313 subl $40,%esp /*should be 32*/
1325 jmp getClassContext_checkLeave /* continue */
1327 getClassContext_leave:
1330 call temporaryGetClassContextHelper*/
1332 /*call collector function with begin/end of temporary classarray*/
1341 /* free stack memory of this function*/
1347 asm_throw_and_handle_exception:
1348 sub $20,%esp /*build stack frame*/
1349 mov %ecx,16(%esp) /*save eip of problem */
1351 movl $0,12(%esp) /*internal function -> no function description */
1352 call builtin_asm_get_stackframeinfo
1360 /* mov string_java_lang_NullPointerException,%eax
1370 jmp asm_handle_exception
1371 ret /*should never be reached */
1373 asm_throw_and_handle_hardware_arithmetic_exception:
1374 sub $24,%esp /*build stack frame*/
1375 mov %ecx,20(%esp) /*save eip of problem */
1377 movl $0,16(%esp) /*internal function -> no function description */
1378 call builtin_asm_get_stackframeinfo
1386 mov string_java_lang_ArithmeticException,%eax
1388 mov string_java_lang_ArithmeticException_message,%eax
1391 call new_exception_message
1400 jmp asm_handle_exception
1401 ret /*should never be reached */
1404 /*optimize a littlebit */
1408 call i386_native_stub_debug
1412 mov offclassinit(%eax),%ecx /* get initialized flag */
1414 jnz L_builtin_new_noinit
1416 sub $16,%esp /* build stack frame (4 * 4 bytes) */
1421 call builtin_asm_get_stackframeinfo
1438 jmp L_builtin_new_patch
1441 L_builtin_new_noinit:
1446 /*jmp L_builtin_new_patch*/
1448 L_builtin_new_patch:
1449 /*add patching code here */
1450 lea builtin_new,%edx
1452 mov %edx,-6(%ecx) /*patch calling instruction, t directly call builtin_new the next time*/
1460 push %ebp /*(%ebp-4)*/
1463 push %edi /*(%ebp-8)*/
1464 push %esi /*(%ebp-12)*/
1465 push %ebx /*(%ebp-16)*/
1466 call builtin_asm_get_stackframeinfo
1468 pushl 0(%eax) /*(%ebp-20)*/
1470 call builtin_asm_get_threadrootmethod
1471 pushl %eax /*(%ebp-24)*/
1474 asm_get_stackTraceLoop:
1475 call codegen_findmethod
1478 pushl $1 /*no indent*/
1483 get_stackTrace_line:
1484 movl LineNumberTableSize(%esi),%ecx
1485 test %ecx,%ecx /* skip if empty line table */
1486 je get_stackTrace_noLineInfo
1488 movl LineNumberTableStart(%esi),%ebx
1490 get_stackTrace_lineLoop:
1491 cmp %edx,LinePC(%ebx)
1492 jg get_stackTrace_nextLineInfo
1494 pushl LineLine(%ebx)
1495 jmp get_stackTrace_cont
1497 get_stackTrace_nextLineInfo:
1498 lea LineEntrySize(%ebx),%ebx
1502 jne get_stackTrace_lineLoop
1504 get_stackTrace_noLineInfo:
1508 get_stackTrace_cont:
1510 pushl MethodPointer(%esi)
1511 pushl $0 /*8(%ebp)*/ /*exception ptr*/
1512 call builtin_trace_exception
1515 movl MethodPointer(%esi),%eax
1518 je get_stackTrace_nat
1521 je get_stackTrace_leave
1523 mov FrameSize(%esi),%eax
1527 jmp asm_get_stackTraceLoop
1533 je get_stackTrace_leave
1540 jmp asm_get_stackTraceLoop
1542 get_stackTrace_leave:
1548 call builtin_stacktrace_copy
1558 asm_getclassvalues_atomic:
1560 mov 4(%esp),%ecx /* super */
1561 mov 8(%esp),%edx /* sub */
1563 mov offbaseval(%ecx),%eax
1564 mov offdiffval(%ecx),%ecx
1565 mov offbaseval(%edx),%edx
1568 mov 16(%esp),%ebx /* out */
1569 mov %eax,offcast_super_baseval(%ebx)
1570 mov %ecx,offcast_super_diffval(%ebx)
1571 mov %edx,offcast_sub_baseval(%ebx)
1577 asm_criticalsections:
1578 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1581 .long _crit_restart1
1584 .long _crit_restart2
1589 * These are local overrides for various environment variables in Emacs.
1590 * Please do not remove this and leave it at the end of the file, where
1591 * Emacs will automagically detect them.
1592 * ---------------------------------------------------------------------
1595 * indent-tabs-mode: t