(localref_native_enter): Renamed from localref_fill.
* src/native/localref.h (localref_native_exit): Added prototype.
(localref_native_enter): Renamed from localref_fill.
* src/vm/jit/argument.c (argument_jitreturn_store): Implemented.
* src/vm/jit/argument.h (argument_jitreturn_store): Added prototype.
* src/vm/jit/codegen-common.c (codegen_start_native_call): Improved comments
and adapted to above changes.
(codegen_finish_native_call): Likewise.
}
-/* localref_fill ***************************************************************
+/* localref_native_enter *******************************************************
Insert arguments to a native method into the local reference table.
This is done by the native stub through codegen_start_native_call.
*******************************************************************************/
-void localref_fill(methodinfo *m, uint64_t *args_regs, uint64_t *args_stack)
+void localref_native_enter(methodinfo *m, uint64_t *argument_regs, uint64_t *argument_stack)
{
localref_table *lrt;
methoddesc *md;
/* load TYPE_ADR parameters ... */
if (md->paramtypes[i].type == TYPE_ADR) {
- arg = argument_jitarray_load(md, i, args_regs, args_stack);
+ arg = argument_jitarray_load(md, i, argument_regs, argument_stack);
if (arg.a == NULL)
continue;
h = localref_add((java_object_t *) arg.a);
- /* update the parameter */
+#if defined(ENABLE_HANDLES)
+ /* update the modified parameter if necesarry */
arg.a = (void *) h;
- argument_jitarray_store(md, i, args_regs, args_stack, arg);
+ argument_jitarray_store(md, i, argument_regs, argument_stack, arg);
+#endif
}
}
}
+/* localref_native_exit ********************************************************
+
+ Undo the wrapping of the return value of a native method. This is
+ done by the native stub through codegen_finish_native_call.
+
+ NOTE: This function is only useful if handles are enabled.
+
+*******************************************************************************/
+
+#if defined(ENABLE_HANDLES)
+void localref_native_exit(methodinfo *m, uint64_t *return_regs)
+{
+ localref_table *lrt;
+ methoddesc *md;
+ imm_union ret;
+ java_handle_t *h;
+
+ /* get local reference table from thread */
+
+ lrt = LOCALREFTABLE;
+
+ assert(lrt != NULL);
+ assert(m != NULL);
+
+ md = m->parseddesc;
+
+ /* load TYPE_ADR return values ... */
+
+ if (md->returntype.type == TYPE_ADR) {
+ ret = argument_jitreturn_load(md, return_regs);
+
+ if (ret.a == NULL)
+ return;
+
+ h = (java_handle_t *) ret.a;
+
+ /* update the modified return valie */
+
+ ret.a = (void *) h->heap_object;
+ argument_jitreturn_store(md, return_regs, ret);
+
+#if !defined(NDEBUG)
+ /* removing the entry from the local reference table is not really
+ necesarry, but gives us warnings if the entry does not exist. */
+
+ localref_del(h);
+#endif
+ }
+}
+#endif /* defined(ENABLE_HANDLES) */
+
+
/* localref_dump ***************************************************************
Dumps all local reference tables, including all frames.
java_handle_t *localref_add(java_object_t *o);
void localref_del(java_handle_t *localref);
-void localref_fill(methodinfo *m, uint64_t *args_regs, uint64_t *args_stack);
+void localref_native_enter(methodinfo *m, uint64_t *argument_regs, uint64_t *argument_stack);
+void localref_native_exit(methodinfo *m, uint64_t *return_regs);
#if !defined(NDEBUG)
void localref_dump(void);
assert(0);
#endif
} else {
- arg_regs[pd->index] = param.l;
+ arg_regs[index] = param.l;
}
break;
default:
- vm_abort("_array_store_param: type not implemented");
+ vm_abort("argument_jitarray_store: type not implemented");
break;
}
}
}
+/* argument_jitreturn_store ****************************************************
+
+ Stores the proper return value into the return registers.
+
+*******************************************************************************/
+
+void argument_jitreturn_store(methoddesc *md, uint64_t *return_regs, imm_union ret)
+{
+ switch (md->returntype.type) {
+ case TYPE_ADR:
+#if (SIZEOF_VOID_P == 8)
+ return_regs[0] = ret.l;
+#else
+ assert(0);
+#endif
+ break;
+ default:
+ vm_abort("argument_jitreturn_store: type not implemented");
+ break;
+ }
+}
+
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
imm_union argument_jitarray_load(methoddesc *md, int32_t index,
uint64_t *arg_regs, uint64_t *stack);
-
-void argument_jitarray_store(methoddesc *md, int32_t index,
- uint64_t *arg_regs, uint64_t *stack,
- imm_union param);
+void argument_jitarray_store(methoddesc *md, int32_t index,
+ uint64_t *arg_regs, uint64_t *stack,
+ imm_union param);
imm_union argument_jitreturn_load(methoddesc *md, uint64_t *return_regs);
+void argument_jitreturn_store(methoddesc *md, uint64_t *return_regs,
+ imm_union ret);
#endif /* _VM_JIT_ARGUMENT_H */
vm_abort("codegen_start_native_call: unsupported architecture");
#endif
-#if !defined(NDEBUG)
-# if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) || defined(__S390__)
- /* print the call-trace if necesarry */
-
- if (opt_TraceJavaCalls)
- trace_java_call_enter(m, arg_regs, arg_stack);
-# endif
-#endif
-
/* get data structures from stack */
sfi = (stackframeinfo *) (datasp - sizeof(stackframeinfo));
localref_table_add(lrt);
#endif
+#if !defined(NDEBUG)
+# if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) || defined(__S390__)
+ /* print the call-trace if necesarry */
+ /* BEFORE: filling the local reference table */
+
+ if (opt_TraceJavaCalls)
+ trace_java_call_enter(m, arg_regs, arg_stack);
+# endif
+#endif
+
#if defined(ENABLE_HANDLES)
/* place all references into the local reference table */
+ /* BEFORE: creating stackframeinfo */
- localref_fill(m, arg_regs, arg_stack);
+ localref_native_enter(m, arg_regs, arg_stack);
#endif
/* add a stackframeinfo to the chain */
vm_abort("codegen_finish_native_call: unsupported architecture");
#endif
-
-#if !defined(NDEBUG)
-# if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) || defined(__S390__)
- /* print the call-trace if necesarry */
-
- if (opt_TraceJavaCalls)
- trace_java_call_exit(m, ret_regs);
-# endif
-#endif
-
/* get data structures from stack */
sfi = (stackframeinfo *) (datasp - sizeof(stackframeinfo));
stacktrace_remove_stackframeinfo(sfi);
- /* XXX unfill lrt here!!! */
+#if defined(ENABLE_HANDLES)
+ /* unwrap the return value from the local reference table */
+ /* AFTER: removing the stackframeinfo */
+ /* BEFORE: releasing the local reference table */
+
+ localref_native_exit(m, ret_regs);
+#endif
/* get and unwrap the exception */
- /* ATTENTION: do the this _after_ the stackframeinfo was
- removed but _before_ the localref_table gets removed! */
+ /* AFTER: removing the stackframe info */
+ /* BEFORE: releasing the local reference table */
e = exceptions_get_and_clear_exception();
o = LLNI_UNWRAP(e);
localref_table_remove();
#endif
+#if !defined(NDEBUG)
+# if defined(__ALPHA__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__X86_64__) || defined(__S390__)
+ /* print the call-trace if necesarry */
+ /* AFTER: unwrapping the return value */
+
+ if (opt_TraceJavaCalls)
+ trace_java_call_exit(m, ret_regs);
+# endif
+#endif
+
return o;
}