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 1140 2004-06-05 20:58:14Z 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 */
195 pop %edi /* restore registers */
202 push %eax /* pass exception pointer */
203 call builtin_throw_exception
207 pop %edi /* restore registers */
214 /********************* function asm_calljavafunction ***************************
216 * This function calls a Java-method (which possibly needs compilation) *
217 * with up to 4 address parameters. *
219 * This functions calls the JIT-compiler which eventually translates the *
220 * method into machine code. *
223 * javaobject_header *asm_calljavafunction2(methodinfo *m, *
224 * u4 count, u4 size, void *callblock); *
226 *******************************************************************************/
229 .ascii "calljavafunction2\0\0"
232 .long 0 /* catch type all */
233 .long calljava_xhandler2 /* handler pc */
234 .long calljava_xhandler2 /* end pc */
235 .long asm_calljavafunction2 /* start pc */
236 .long 1 /* extable size */
237 .long 0 /* line number table start */
238 .long 0 /* line number table size */
239 .long 0 /* fltsave */
240 .long 0 /* intsave */
243 .long 32 /* frame size */
244 .long 0 /* method pointer (pointer to name) */
246 asm_calljavafunction2:
247 asm_calljavafunction2double:
248 asm_calljavafunction2long:
250 mov %esp,%ebp /* save stackptr */
252 push %ebx /* save registers */
256 mov 20(%ebp),%eax /* pointer to arg block */
257 mov 12(%ebp),%ecx /* arg count */
258 test %ecx,%ecx /* maybe we have no args */
259 jle calljava_copydone
261 mov %ecx,%edx /* calculate stack size */
263 mov %edx,%esi /* save in callee saved register */
264 sub %esi,%esp /* stack frame for arguments */
268 mov offjniitem(%eax),%edx
270 mov offjniitem+4(%eax),%edx
273 sub $1,%ecx /* are there any args left? */
275 jle calljava_copydone
277 add $sizejniblock,%eax /* goto next argument block */
278 add $8,%edi /* increase sp to next argument */
279 jmp calljava_copyloop
282 mov 8(%ebp),%eax /* move function pointer to %eax */
284 lea asm_call_jit_compiler,%edx
285 call *%edx /* call JIT compiler */
288 add %esi,%esp /* remove arg stack frame */
289 pop %edi /* restore registers */
296 push %eax /* pass exception pointer */
297 call builtin_throw_exception
300 add %esi,%esp /* remove arg stack frame */
301 pop %edi /* restore registers */
308 /****************** function asm_call_jit_compiler *****************************
310 * invokes the compiler for untranslated JavaVM methods. *
312 * Register R0 contains a pointer to the method info structure (prepared *
313 * by createcompilerstub). Using the return address in R26 and the *
314 * offset in the LDA instruction or using the value in methodptr R28 the *
315 * patching address for storing the method address can be computed: *
317 * method address was either loaded using *
319 * i386_mov_imm_reg(a, REG_ITMP2) ; invokestatic/special *
320 * i386_call_reg(REG_ITMP2) *
324 * i386_mov_membase_reg(REG_SP, 0, REG_ITMP1) ; invokevirtual/interface *
325 * i386_mov_membase_reg(REG_ITMP1, OFFSET(, vftbl), REG_ITMP2) *
326 * i386_mov_membase_reg(REG_ITMP2, OFFSET(vftbl, table[0]) + \ *
327 * sizeof(methodptr) * m->vftblindex, REG_ITMP1) *
328 * i386_call_reg(REG_ITMP1) *
330 * in the static case the method pointer can be computed using the *
331 * return address and the lda function following the jmp instruction *
333 *******************************************************************************/
335 asm_call_jit_compiler:
336 push %ebx /* save register */
339 mov 8(%esp),%ebp /* get return address (2 push) */
340 mov -1(%ebp),%bl /* get function code */
341 cmp $0xd1,%bl /* called with `call *REG_ITMP2' (%ecx)? */
342 jne L_not_static_special
344 sub $6,%ebp /* calculate address of immediate */
345 jmp L_call_jit_compile
347 L_not_static_special:
348 cmp $0xd0,%bl /* called with `call *REG_ITMP1' (%eax) */
349 jne L_not_virtual_interface
351 sub $6,%ebp /* calculate address of offset */
352 mov (%ebp),%ebp /* get offset */
353 add itmp2,%ebp /* add base address to get method address */
354 jmp L_call_jit_compile
356 L_not_virtual_interface: /* a call from asm_calljavafunction */
360 push %ebp /* save address for method pointer */
362 push %eax /* push methodpointer on stack */
366 pop %ebp /* restore address for method pointer */
368 test %eax,%eax /* check for exception */
371 test %ebp,%ebp /* is address == 0 (asm_calljavafunction) */
374 mov %eax,(%ebp) /* and now save the new pointer */
377 pop %ebp /* restore registers */
380 jmp *%eax /* ...and now call the new method */
383 pop %ebp /* restore registers */
386 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
387 call builtin_asm_get_exceptionptrptr
389 mov (%ecx),%eax /* get the exception pointer */
390 movl $0,(%ecx) /* clear the exception pointer */
392 lea _exceptionptr,%ecx
393 mov (%ecx),%eax /* get the exception pointer */
394 movl $0,(%ecx) /* clear the exception pointer */
397 pop %ecx /* delete return address */
398 sub $2,%ecx /* faulting address is return adress - 2 */
400 L_refillinStacktrace:
401 push %ecx /* store fault adress */
402 push %eax /* temporarily save exception pointer*/
403 call builtin_asm_get_stackframeinfo
404 push %eax /* save location of thread specific stack info head pointer */
405 mov (%eax),%ecx /* save old value of pointer*/
407 mov %esp,(%eax) /*store pointer to this structure*/
408 mov 8(%esp),%eax /* get the exception pointer again*/
409 movl $0,8(%esp) /*mark this block as native*/
410 push $0 /*used for the jni_callblock structure*/
411 push %eax /*save eax for later */
412 /* get fillInStackTrace method*/
413 push utf_fillInStackTrace_desc
414 push utf_fillInStackTrace_name
415 mov offobjvftbl(%eax),%ecx
416 mov offclass(%ecx),%eax
418 call class_resolvemethod
426 call asm_calljavafunction2
429 /*remove native stack info */
438 jmp asm_handle_exception
441 /********************* function asm_handle_exception ***************************
443 * This function handles an exception. It does not use the usual calling *
444 * conventions. The exception pointer is passed in REG_ITMP1 and the *
445 * pc from the exception raising position is passed in REG_ITMP2. It searches *
446 * the local exception table for a handler. If no one is found, it unwinds *
447 * stacks and continues searching the callers. *
449 * void asm_handle_exception (exceptionptr, exceptionpc); *
451 *******************************************************************************/
453 asm_handle_nat_exception:
454 add $4,%esp /* clear return address of native stub */
456 asm_handle_exception:
460 push %eax /* exception pointer */
461 push %ecx /* excepiton pc */
463 call asm_get_stackTrace
469 asm_handle_exception_loop:
473 push %eax /* save exception pointer */
474 push %ecx /* save exception pc */
476 call codegen_findmethod /* get the data segment ptr */
480 mov -8(%ebp),%ecx /* could be changed in findmethod */
482 push %edx /* save data segment pointer */
489 mov %eax,(%esp) /* exception pointer */
490 mov MethodPointer(%edx),%eax /* method pointer */
492 mov %ecx,8(%esp) /* exception pc */
493 movl $0,12(%esp) /* line number */
494 movl $1,16(%esp) /* set no unwind flag */
495 call builtin_trace_exception
497 mov -12(%ebp),%esi /* %esi = data segment pointer */
498 mov ExTableSize(%esi),%ecx /* %ecx = exception table size */
499 test %ecx,%ecx /* if empty table skip */
502 lea ExTableStart(%esi),%edi /* %edi = start of exception table*/
503 mov -4(%ebp),%eax /* get xptr */
506 mov -8(%ebp),%edx /* get xpc */
508 mov ExStartPC(%edi),%ebx /* %ebx = exception start pc */
509 cmp %edx,%ebx /* %ebx = (startpc <= xpc) */
510 jg ex_table_cont /* if (false) continue */
511 mov ExEndPC(%edi),%ebx /* %ebx = exception end pc */
512 cmp %ebx,%edx /* %ebx = (xpc < endpc) */
513 jge ex_table_cont /* if (false) continue */
514 mov ExCatchType(%edi),%ebx /* arg1 = exception catch type */
515 test %ebx,%ebx /* NULL catches everything */
518 cmpl $0,offclassloaded(%ebx) /* check if class is loaded */
522 mov %eax,1*4(%esp) /* save not callee saved regs */
525 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 */
548 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
556 mov offobjvftbl(%eax),%esi /* %esi = vftblptr(xptr) */
557 mov offclassvftbl(%ebx),%ebx /* %ebx = vftblptr(catchtype) class (not obj) */
558 mov offbaseval(%esi),%esi /* %esi = baseval(xptr) */
559 mov offbaseval(%ebx),%edx /* %edx = baseval(catchtype) */
560 mov offdiffval(%ebx),%ebx /* %ebx = diffval(catchtype) */
562 sub %edx,%esi /* %esi = baseval(xptr) - baseval(catchtype) */
564 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
568 cmp %ebx,%esi /* xptr is instanceof catchtype */
572 mov ExHandlerPC(%edi),%edx
574 pop %edi /* restore registers */
577 add $8,%esp /* suck %ecx, %edx */
578 pop %eax /* restore xptr */
581 jmp *%edx /* jump to exception handler */
584 lea ExEntrySize(%edi),%edi
593 pop %edx /* restore data segment pointer */
598 push %eax /* save exception pointer */
601 mov IsSync(%edx),%eax /* %eax = SyncOffset */
602 test %eax,%eax /* if zero no monitorexit */
606 mov -4(%eax),%eax /* we have the xptr on the stack */
607 push %edx /* save regs */
609 call builtin_monitorexit
611 pop %edx /* restore regs */
615 add FrameSize(%edx),%eax /* %eax = frame size */
616 add $4,%eax /* we have the xptr on the stack */
618 mov IntSave(%edx),%ecx /* %ecx = saved int register count*/
640 shl $3,%ecx /* multiply by 8 bytes */
644 mov FltSave(%edx),%ecx /* %ecx = saved flt register count */
671 pop %eax /* restore exception pointer */
673 mov FrameSize(%edx),%ecx /* %ecx = frame size */
674 add %ecx,%esp /* unwind stack */
676 pop %ecx /* the new xpc is return address */
679 jmp asm_handle_exception_loop
682 /********************* function asm_check_clinit *******************************
684 * Does null check and calls monitorenter or throws an exception *
686 *******************************************************************************/
689 mov offclassinit(%eax),%ecx /* get initialized flag */
693 sub $16,%esp /* build stack frame (4 * 4 bytes) */
695 call builtin_asm_get_stackframeinfo
705 call class_init /* call class_init function */
713 test %eax,%eax /* we had an exception */
714 je L_initializererror
717 mov (%esp),%eax /* get return address */
718 sub $12,%eax /* asm_putstatic call code size */
719 movb $0xeb,(%eax) /* jmp rel8 */
720 movb $10,1(%eax) /* 8-bit offset */
724 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
725 call builtin_asm_get_exceptionptrptr
727 mov (%ecx),%eax /* get the exception pointer */
728 movl $0,(%ecx) /* clear the exception pointer */
730 lea _exceptionptr,%ecx
731 mov (%ecx),%eax /* get the exception pointer */
732 movl $0,(%ecx) /* clear the exception pointer */
735 pop %ecx /* delete return address */
736 sub $2,%ecx /* faulting address is return adress - 2 */
738 jmp asm_handle_exception
741 /********************* function asm_builtin_monitorenter ***********************
743 * Does null check and calls monitorenter or throws an exception *
745 *******************************************************************************/
747 asm_builtin_monitorenter:
749 je nb_monitorenter /* if (null) throw exception */
750 jmp builtin_monitorenter /* else call builtin_monitorenter */
753 mov string_java_lang_NullPointerException,%eax
756 jmp asm_throw_and_handle_exception
759 push string_java_lang_NullPointerException
763 pop %ecx /* delete return address */
764 sub $2,%ecx /* faulting address is return adress - 2 */
765 jmp asm_handle_exception
768 /********************* function asm_builtin_monitorexit ************************
770 * Does null check and calls monitorexit or throws an exception *
772 *******************************************************************************/
774 asm_builtin_monitorexit:
777 je nb_monitorexit /* if (null) throw exception */
778 push %ecx /* save registers which could be used */
781 call builtin_monitorexit /* else call builtin_monitorenter */
783 pop %edx /* restore registers which could be used */
788 mov string_java_lang_NullPointerException,%eax
791 jmp asm_throw_and_handle_exception
794 push string_java_lang_NullPointerException
798 pop %ecx /* delete return address */
799 sub $2,%ecx /* faulting address is return adress - 2 */
800 jmp asm_handle_exception
803 /************************ function asm_builtin_ldiv ****************************
805 * Does null check and calls ldiv or throws an exception *
807 *******************************************************************************/
812 test %eax,%eax /* if (null) throw exception */
820 jmp asm_throw_and_handle_hardware_arithmetic_exception
822 push string_java_lang_ArithmeticException_message
823 push string_java_lang_ArithmeticException
824 call new_exception_message
827 pop %ecx /* delete return address */
828 sub $2,%ecx /* faulting address is return adress - 2 */
829 jmp asm_handle_exception
832 /************************ function asm_builtin_lrem ****************************
834 * Does null check and calls lrem or throws an exception *
836 *******************************************************************************/
841 test %eax,%eax /* if (null) throw exception */
849 jmp asm_throw_and_handle_hardware_arithmetic_exception
851 push string_java_lang_ArithmeticException_message
852 push string_java_lang_ArithmeticException
853 call new_exception_message
856 pop %ecx /* delete return address */
857 sub $2,%ecx /* faulting address is return adress - 2 */
858 jmp asm_handle_exception
861 /************************ function asm_builtin_x2x *****************************
863 * Wrapper functions for corner cases *
865 *******************************************************************************/
896 /******************* function asm_builtin_checkarraycast ***********************
898 * Does the cast check and eventually throws an exception *
900 *******************************************************************************/
902 asm_builtin_checkarraycast:
903 sub $8,%esp /* build stack frame (2 * 4 bytes) */
905 mov 12(%esp),%eax /* 8 (frame) + 4 (return) */
906 mov %eax,(%esp) /* save object pointer */
911 call builtin_checkarraycast /* builtin_checkarraycast */
913 test %eax,%eax /* if (false) throw exception */
916 mov 12(%esp),%eax /* return object pointer */
922 mov string_java_lang_ClassCastException,%eax
925 jmp asm_throw_and_handle_exception
927 push string_java_lang_ClassCastException
933 pop %ecx /* delete return address */
934 sub $2,%ecx /* faulting address is return adress - 2 */
935 jmp asm_handle_exception
938 /******************* function asm_builtin_newarray *****************************
940 * Does the cast check and eventually throws an exception *
942 *******************************************************************************/
944 asm_builtin_newarray:
945 sub $8,%esp /* build stack frame (2 * 4 bytes) */
953 call builtin_newarray
959 /******************* function asm_builtin_aastore ******************************
961 * Does the cast check and eventually throws an exception *
963 *******************************************************************************/
966 sub $12,%esp /* build stack frame (3 * 4 bytes) */
968 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
969 test %eax,%eax /* if null pointer throw exception */
972 mov offarraysize(%eax),%edx /* load size */
973 mov 24(%esp),%ecx /* index */
974 cmp %edx,%ecx /* do bound check */
975 jae nb_aastore_bound /* if out of bounds throw exception */
977 shl $2,%ecx /* index * 4 */
978 add %eax,%ecx /* add index * 4 to arrayref */
980 mov %ecx,8(%esp) /* save store position */
982 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
985 mov 32(%esp),%eax /* object is second argument */
988 call builtin_canstore /* builtin_canstore(arrayref,object) */
990 test %eax,%eax /* if (false) throw exception */
995 mov %eax,offobjarrdata(%ecx) /* store objectptr in array */
1002 mov string_java_lang_NullPointerException,%eax
1005 jmp asm_throw_and_handle_exception
1008 push string_java_lang_NullPointerException
1013 pop %ecx /* delete return address */
1014 sub $2,%ecx /* faulting address is return adress - 2 */
1015 jmp asm_handle_exception
1018 push %ecx /* itmp2 contains array index */
1019 push string_java_lang_ArrayIndexOutOfBoundsException
1020 call new_exception_int
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 lea builtin_asm_getclassloader,%eax
1183 push %eax /*store collector function pointer*/
1184 jmp getClassContext_begin
1185 Java_java_lang_VMSecurityManager_getClassContext:
1186 lea builtin_asm_createclasscontextarray,%eax
1187 push %eax /*store collector function pointer*/
1188 getClassContext_begin: /*start the real work*/
1192 sub $68,%esp /*64 memory location without overwriting return adress and collector function adress*/
1193 mov %esp,%ebx /*end of allocated memory block for classpointers is the adress of the working data block +4 */
1194 push $0 /*%esp+32 was native*/
1195 push %eax /*%esp+24 blkbegin*/
1196 push %eax /*%esp+20 currentpos*/
1197 push %ebx /*%esp+16 blkend*/
1199 call builtin_asm_get_threadrootmethod
1200 push %eax /*%esp+12*/
1201 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*/
1204 push %edx /*esp+8*/ /*position of return address of native stub*/
1205 call builtin_asm_get_stackframeinfo
1206 movl (%eax),%eax /*comment ??*/
1207 push 0(%eax) /*esp+4*/ /*address of frame info block*/
1214 call i386_native_stub_debug
1217 push %edx /*esp+0*/ /*return adress out of native stub*/
1218 call codegen_findmethod /*find calling java method, this one is still to be skipped (==SecurityManager.getClassContext (or .currentClassLoader)*/
1222 movl MethodPointer(%eax),%eax
1224 call temporaryGetClassContextHelper
1226 call traverseStackInfo
1231 movl MethodPointer(%eax),%ebx
1232 movl offclassmethodinfo(%ebx),%ecx
1237 mov 8(%esp),%ebx /*pos of return adress */
1238 add FrameSize(%eax),%ebx
1239 add $4,%ebx /*adress of new return adress (out of Securitymanager.*/
1243 /* by now we have skipped this method call*/
1245 getClassContext_next:
1248 movl %eax,(%esp) /*return adress*/
1250 call codegen_findmethod
1254 add FrameSize(%eax),%ebx
1256 mov %ebx,8(%esp) /*store adress of next return adress*/
1257 getClassContext_nextRetStored:
1259 mov MethodPointer(%eax),%ecx /*get struct methodinfo*/
1262 je getClassContext_nativeCall
1263 /*save class pointer*/
1265 getClassContext_saveClassPointer:
1266 movl 20(%esp),%ebx /*get temporary memory adress in stack*/
1267 movl offclassmethodinfo(%ecx),%edx /* get class pointer of method*/
1268 movl %edx,(%ebx) /*save */
1269 sub $4,%ebx /*calculate next position */
1270 movl %ebx,20(%esp) /* check if the new adress would overwrite our working data */
1272 je getClassContext_incStack
1273 getClassContext_checkLeave:
1275 cmp 12(%esp),%ecx /*check if we reached the toplevel method of our thread*/
1276 je getClassContext_leave /*yes ->leave*/
1280 call temporaryGetClassContextHelper
1284 jmp getClassContext_next /*continue*/
1287 getClassContext_nativeCall:
1289 movl 4(%esp),%eax /*get top most element on stackframe help information stack*/
1298 je getClassContext_checkLeave
1299 jmp getClassContext_saveClassPointer
1301 getClassContext_incStack:
1302 /*make another 64 in our temporary storage free and store the workingdata */
1304 subl $40,%esp /*should be 32*/
1316 jmp getClassContext_checkLeave /* continue */
1318 getClassContext_leave:
1321 call temporaryGetClassContextHelper*/
1323 /*call collector function with begin/end of temporary classarray*/
1332 /* free stack memory of this function*/
1338 asm_throw_and_handle_exception:
1339 sub $20,%esp /*build stack frame*/
1340 mov %ecx,16(%esp) /*save eip of problem */
1342 movl $0,12(%esp) /*internal function -> no function description */
1343 call builtin_asm_get_stackframeinfo
1351 /* mov string_java_lang_NullPointerException,%eax
1361 jmp asm_handle_exception
1362 ret /*should never be reached */
1364 asm_throw_and_handle_hardware_arithmetic_exception:
1365 sub $24,%esp /*build stack frame*/
1366 mov %ecx,20(%esp) /*save eip of problem */
1368 movl $0,16(%esp) /*internal function -> no function description */
1369 call builtin_asm_get_stackframeinfo
1377 mov string_java_lang_ArithmeticException,%eax
1379 mov string_java_lang_ArithmeticException_message,%eax
1382 call new_exception_message
1391 jmp asm_handle_exception
1392 ret /*should never be reached */
1395 /*optimize a littlebit */
1399 call i386_native_stub_debug
1403 mov offclassinit(%eax),%ecx /* get initialized flag */
1405 jnz L_builtin_new_noinit
1407 sub $16,%esp /* build stack frame (4 * 4 bytes) */
1412 call builtin_asm_get_stackframeinfo
1429 jmp L_builtin_new_patch
1432 L_builtin_new_noinit:
1437 /*jmp L_builtin_new_patch*/
1439 L_builtin_new_patch:
1440 /*add patching code here */
1441 lea builtin_new,%edx
1443 mov %edx,-6(%ecx) /*patch calling instruction, t directly call builtin_new the next time*/
1451 push %ebp /*(%ebp-4)*/
1454 push %edi /*(%ebp-8)*/
1455 push %esi /*(%ebp-12)*/
1456 push %ebx /*(%ebp-16)*/
1457 call builtin_asm_get_stackframeinfo
1459 pushl 0(%eax) /*(%ebp-20)*/
1461 call builtin_asm_get_threadrootmethod
1462 pushl %eax /*(%ebp-24)*/
1465 asm_get_stackTraceLoop:
1466 call codegen_findmethod
1469 pushl $1 /*no indent*/
1474 get_stackTrace_line:
1475 movl LineNumberTableSize(%esi),%ecx
1476 test %ecx,%ecx /* skip if empty line table */
1477 je get_stackTrace_noLineInfo
1479 movl LineNumberTableStart(%esi),%ebx
1481 get_stackTrace_lineLoop:
1482 cmp %edx,LinePC(%ebx)
1483 jg get_stackTrace_nextLineInfo
1485 pushl LineLine(%ebx)
1486 jmp get_stackTrace_cont
1488 get_stackTrace_nextLineInfo:
1489 lea LineEntrySize(%ebx),%ebx
1493 jne get_stackTrace_lineLoop
1495 get_stackTrace_noLineInfo:
1499 get_stackTrace_cont:
1501 pushl MethodPointer(%esi)
1502 pushl $0 /*8(%ebp)*/ /*exception ptr*/
1503 call builtin_trace_exception
1506 movl MethodPointer(%esi),%eax
1509 je get_stackTrace_nat
1512 je get_stackTrace_leave
1514 mov FrameSize(%esi),%eax
1518 jmp asm_get_stackTraceLoop
1524 je get_stackTrace_leave
1531 jmp asm_get_stackTraceLoop
1533 get_stackTrace_leave:
1539 call builtin_stacktrace_copy
1548 asm_getclassvalues_atomic:
1550 mov 4(%esp),%ecx /* super */
1551 mov 8(%esp),%edx /* sub */
1553 mov offbaseval(%ecx),%eax
1554 mov offdiffval(%ecx),%ecx
1555 mov offbaseval(%edx),%edx
1558 mov 16(%esp),%ebx /* out */
1559 mov %eax,offcast_super_baseval(%ebx)
1560 mov %ecx,offcast_super_diffval(%ebx)
1561 mov %edx,offcast_sub_baseval(%ebx)
1567 asm_criticalsections:
1568 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1571 .long _crit_restart1
1574 .long _crit_restart2
1579 * These are local overrides for various environment variables in Emacs.
1580 * Please do not remove this and leave it at the end of the file, where
1581 * Emacs will automagically detect them.
1582 * ---------------------------------------------------------------------
1585 * indent-tabs-mode: t