From 00dcefdce4e16a0b78618d713f9b8a82871c1512 Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Wed, 14 Feb 2007 20:08:43 +0300 Subject: [PATCH] Fix of memory leak from rth_throw_lazy runtime helper. Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix of memory leak from rth_throw_lazy runtime helper. Patch adds: • allocation handlers on the stack for rth_throw_lazy runtime helper. • free of handlers in exn_throw_for_JIT befor control transfering. Fix spelling of si_set_callback function. --- vm/port/include/stack_iterator.h | 2 - vm/port/src/lil/em64t/pim/stack_iterator_em64t.cpp | 2 - vm/port/src/lil/ia32/pim/stack_iterator_ia32.cpp | 2 - vm/vmcore/src/exception/exceptions_jit.cpp | 49 ++++++++++++++++++-- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/vm/port/include/stack_iterator.h b/vm/port/include/stack_iterator.h old mode 100644 new mode 100755 index e860806..363480a --- a/vm/port/include/stack_iterator.h +++ b/vm/port/include/stack_iterator.h @@ -296,6 +296,6 @@ uint32 si_get_inline_depth(StackIterator * @param[in] callback - pointer to the native cose adress which should be * called, after transfer control */ -void si_set_callbak(StackIterator* si, NativeCodePtr* callback); +void si_set_callback(StackIterator* si, NativeCodePtr* callback); #endif //!_STACK_ITERATOR_H_ diff --git a/vm/port/src/lil/em64t/pim/stack_iterator_em64t.cpp b/vm/port/src/lil/em64t/pim/stack_iterator_em64t.cpp old mode 100644 new mode 100755 index ca7b6f7..ce2b358 --- a/vm/port/src/lil/em64t/pim/stack_iterator_em64t.cpp +++ b/vm/port/src/lil/em64t/pim/stack_iterator_em64t.cpp @@ -372,7 +372,7 @@ void si_copy_to_registers(StackIterator regs->r11 = *si->jit_frame_context.p_r11; } -void si_set_callbak(StackIterator* si, NativeCodePtr* callback) { +void si_set_callback(StackIterator* si, NativeCodePtr* callback) { si->jit_frame_context.rsp = si->jit_frame_context.rsp - 4; *((uint64*) si->jit_frame_context.rsp) = *(si->jit_frame_context.p_rip); si->jit_frame_context.p_rip = ((uint64*)callback); diff --git a/vm/port/src/lil/ia32/pim/stack_iterator_ia32.cpp b/vm/port/src/lil/ia32/pim/stack_iterator_ia32.cpp old mode 100644 new mode 100755 index a5f2abf..cf849ea --- a/vm/port/src/lil/ia32/pim/stack_iterator_ia32.cpp +++ b/vm/port/src/lil/ia32/pim/stack_iterator_ia32.cpp @@ -512,7 +512,7 @@ void si_copy_to_registers(StackIterator* regs->eax = unref_reg(si->c.p_eax); } -void si_set_callbak(StackIterator* si, NativeCodePtr* callback) { +void si_set_callback(StackIterator* si, NativeCodePtr* callback) { si->c.esp = si->c.esp - 4; *((uint32*) si->c.esp) = *(si->c.p_eip); si->c.p_eip = ((uint32*)callback); diff --git a/vm/vmcore/src/exception/exceptions_jit.cpp b/vm/vmcore/src/exception/exceptions_jit.cpp old mode 100644 new mode 100755 index 3017fef..28c206d --- a/vm/vmcore/src/exception/exceptions_jit.cpp +++ b/vm/vmcore/src/exception/exceptions_jit.cpp @@ -439,12 +439,20 @@ #endif // _IPF_ exn_propagate_exception(si, &local_exn_obj, exn_class, exn_constr, jit_exn_constr_args, vm_exn_constr_args); + M2nFrame* m2nFrame = m2n_get_last_frame(); + ObjectHandles* last_m2n_frame_handles = m2nFrame->local_object_handles; + + if (last_m2n_frame_handles) { + free_local_object_handles2(m2n_get_last_frame()->local_object_handles); + } + if (ti->get_global_capability(DebugUtilsTI::TI_GC_ENABLE_EXCEPTION_EVENT)) { NativeCodePtr callback = (NativeCodePtr) asm_jvmti_exception_catch_callback; - si_set_callbak(si, &callback); + si_set_callback(si, &callback); } + // don't put any call here si_transfer_control(si); } //exn_throw_for_JIT @@ -605,9 +613,25 @@ NativeCodePtr exn_get_rth_throw_lazy() return addr; } - LilCodeStub *cs = lil_parse_code_stub("entry 0:managed:pint:void;" - "push_m2n 0, 0;" - "m2n_save_all;" "in2out platform:void;" "call.noret %0i;", + const unsigned cap_off = (unsigned)(POINTER_SIZE_INT)&((ObjectHandlesNew*)0)->capacity; + const unsigned next_off = (unsigned)(POINTER_SIZE_INT)&((ObjectHandlesNew*)0)->next; + const unsigned handles_size = (unsigned)(sizeof(ObjectHandlesNew)+sizeof(ManagedObject*)*16); + const unsigned cap_and_size = (unsigned)((0<<16) | 16); + + LilCodeStub *cs = lil_parse_code_stub( + "entry 0:managed:pint:void;" + "push_m2n 0, 0, handles;" + "m2n_save_all;" + "locals 1;" + "alloc l0, %0i;" + "st[l0+%1i:g4], %2i;" + "st[l0+%3i:pint], 0;" + "handles=l0;" + "in2out platform:void;" + "call.noret %4i;", + handles_size, + cap_off, cap_and_size, + next_off, rth_throw_lazy); assert(lil_is_valid(cs)); addr = LilCodeGenerator::get_platform()->compile(cs); @@ -628,11 +652,24 @@ NativeCodePtr exn_get_rth_throw_lazy_tra return addr; } + const unsigned cap_off = (unsigned)(POINTER_SIZE_INT)&((ObjectHandlesNew*)0)->capacity; + const unsigned next_off = (unsigned)(POINTER_SIZE_INT)&((ObjectHandlesNew*)0)->next; + const unsigned handles_size = (unsigned)(sizeof(ObjectHandlesNew)+sizeof(ManagedObject*)*16); + const unsigned cap_and_size = (unsigned)((0<<16) | 16); + LilCodeStub *cs = lil_parse_code_stub("entry 1:managed::void;" - "push_m2n 0, 0;" + "push_m2n 0, 0, handles;" "m2n_save_all;" + "locals 1;" + "alloc l0, %0i;" + "st[l0+%1i:g4], %2i;" + "st[l0+%3i:pint], 0;" + "handles=l0;" "out platform:ref,pint,pint,pint:void;" - "o0=0:ref;" "o1=sp0;" "o2=0;" "o3=0;" "call.noret %0i;", + "o0=0:ref;" "o1=sp0;" "o2=0;" "o3=0;" "call.noret %4i;", + handles_size, + cap_off, cap_and_size, + next_off, exn_athrow); assert(lil_is_valid(cs)); addr = LilCodeGenerator::get_platform()->compile(cs); -- 1.4.1