JNI/Win32 Patch #4: Make "stdcall"-based JNI method calls possible for compiled code
Ranjit Mathew
rmathew@hotmail.com
Tue Dec 10 04:09:00 GMT 2002
Andrew Haley wrote:
> Please note that for gcc patches I'd rather have "diff -c2p" diffs.
> Also, please add a comment to describe what _Jv_LookupJNIMethod is
> passed. (Yeah, I know we are missing many such comments in the
> existing code!)
Ok. I've attached the modified patch below. See if it looks
right.
> This hunk is weird;
>
> - meth_var, meth_var,
> - build (MODIFY_EXPR, ptr_type_node,
> - meth_var,
> - build (CALL_EXPR, ptr_type_node,
> - build_address_of (soft_lookupjnimethod_node),
> - lookup_arg, NULL_TREE)));
> + meth_var, meth_var,
> + build (MODIFY_EXPR, ptr_type_node,
> + meth_var,
> + build (CALL_EXPR, ptr_type_node,
> + build_address_of (soft_lookupjnimethod_node),
> + lookup_arg, NULL_TREE)));
>
Sorry, that represents my struggles with Tabs and Spaces in
VIM - please ignore it.
(In autoindent mode, VIM insists on consolidating blocks
of 8 spaces into tabs - the "+", "-" or "!" inserted by
diff therefore SNAFUs the formatting! :-( )
ChangeLog:
2002-12-10 Ranjit Mathew <rmathew@hotmail.com>
* decl.c (java_init_decl_processing): Change
soft_lookupjnimethod_node to reflect the change in signature
of _Jv_LookupJNIMethod( ) in libjava/jni.cc.
* expr.c (build_jni_stub): Calculate and pass the size
on the stack of the arguments to a JNI function. Use new
target macro MODIFY_JNI_METHOD_CALL to allow a target to
modify the call to a JNI method.
-------------------------------- 8< --------------------------------
*** decl.c Tue Dec 10 16:36:36 2002
--- decl.c Tue Dec 10 16:50:30 2002
*************** java_init_decl_processing ()
*** 880,886 ****
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = tree_cons (NULL_TREE, object_ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node,
! tree_cons (NULL_TREE, ptr_type_node, endlink)));
soft_lookupjnimethod_node
= builtin_function ("_Jv_LookupJNIMethod",
--- 880,894 ----
0, NOT_BUILT_IN, NULL, NULL_TREE);
+
+ /* The "_Jv_LookupJNIMethod" method returns a pointer to a JNI
+ function, if found, given the class, the name of the function,
+ its signature and the number of bytes taken up by its arguments,
+ respectively. */
+
t = tree_cons (NULL_TREE, object_ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node,
! tree_cons (NULL_TREE, ptr_type_node,
! tree_cons (NULL_TREE, int_type_node,
! endlink)));
soft_lookupjnimethod_node
= builtin_function ("_Jv_LookupJNIMethod",
*** expr.c Tue Dec 10 16:50:50 2002
--- expr.c Tue Dec 10 17:02:40 2002
*************** build_jni_stub (method)
*** 2174,2177 ****
--- 2174,2179 ----
tree meth_var;
+ int args_size = 0;
+
tree klass = DECL_CONTEXT (method);
int from_class = ! CLASS_FROM_SOURCE_P (klass);
*************** build_jni_stub (method)
*** 2235,2239 ****
args = NULL_TREE;
for (tem = method_args; tem != NULL_TREE; tem = TREE_CHAIN (tem))
! args = tree_cons (NULL_TREE, tem, args);
args = nreverse (args);
arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
--- 2237,2252 ----
args = NULL_TREE;
for (tem = method_args; tem != NULL_TREE; tem = TREE_CHAIN (tem))
! {
! int arg_bits = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (tem)));
!
! #ifdef PARM_BOUNDARY
! arg_bits = (((arg_bits + PARM_BOUNDARY - 1) / PARM_BOUNDARY) *
! PARM_BOUNDARY);
! #endif
!
! args_size += (arg_bits / BITS_PER_UNIT);
!
! args = tree_cons (NULL_TREE, tem, args);
! }
args = nreverse (args);
arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
*************** build_jni_stub (method)
*** 2244,2247 ****
--- 2257,2261 ----
if (METHOD_STATIC (method))
{
+ args_size += int_size_in_bytes (TREE_TYPE (klass));
args = tree_cons (NULL_TREE, klass, args);
arg_types = tree_cons (NULL_TREE, object_ptr_type_node, arg_types);
*************** build_jni_stub (method)
*** 2249,2252 ****
--- 2263,2267 ----
/* The JNIEnv structure is the first argument to the JNI function. */
+ args_size += int_size_in_bytes (TREE_TYPE (env_var));
args = tree_cons (NULL_TREE, env_var, args);
arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
*************** build_jni_stub (method)
*** 2255,2264 ****
function pointer. _Jv_LookupJNIMethod will throw the appropriate
exception if this function is not found at runtime. */
method_sig = build_java_signature (TREE_TYPE (method));
lookup_arg =
! build_tree_list (NULL_TREE,
! build_utf8_ref (unmangle_classname
! (IDENTIFIER_POINTER (method_sig),
! IDENTIFIER_LENGTH (method_sig))));
tem = DECL_NAME (method);
lookup_arg
--- 2270,2281 ----
function pointer. _Jv_LookupJNIMethod will throw the appropriate
exception if this function is not found at runtime. */
+ tem = build_tree_list (NULL_TREE, build_int_2 (args_size, 0));
method_sig = build_java_signature (TREE_TYPE (method));
lookup_arg =
! tree_cons (NULL_TREE,
! build_utf8_ref (unmangle_classname
! (IDENTIFIER_POINTER (method_sig),
! IDENTIFIER_LENGTH (method_sig))),
! tem);
tem = DECL_NAME (method);
lookup_arg
*************** build_jni_stub (method)
*** 2266,2272 ****
tree_cons (NULL_TREE, build_utf8_ref (tem), lookup_arg));
! jni_func_type
! = build_pointer_type (build_function_type (TREE_TYPE (TREE_TYPE (method)),
! arg_types));
jnifunc = build (COND_EXPR, ptr_type_node,
--- 2283,2293 ----
tree_cons (NULL_TREE, build_utf8_ref (tem), lookup_arg));
! tem = build_function_type (TREE_TYPE (TREE_TYPE (method)), arg_types);
!
! #ifdef MODIFY_JNI_METHOD_CALL
! tem = MODIFY_JNI_METHOD_CALL (tem);
! #endif
!
! jni_func_type = build_pointer_type (tem);
jnifunc = build (COND_EXPR, ptr_type_node,
-------------------------------- 8< --------------------------------
Sincerely Yours,
Ranjit.
--
Ranjit Mathew Email: rmathew AT hotmail DOT com
Bangalore, INDIA. Web: http://ranjitmathew.tripod.com/
More information about the Java-patches
mailing list