From: Andrew Haley <aph@redhat.com>
To: GCC Development <gcc@gcc.gnu.org>, GCJ <java@gcc.gnu.org>
Subject: java: Add new rewite rule for VMCPStringBuilder.toString()
Date: Mon, 22 Sep 2008 13:34:00 -0000 [thread overview]
Message-ID: <48D79EC9.8000404@redhat.com> (raw)
VMCPStringBuilder.toString() relies on backdoor access to a private
constructor for String. We can do this via a native method, but it's
easier and more efficient to add a compiler builtin. This one performs
the transformation:
gnu.java.lang.VMCPStringBuilder.toString(char[],int,int)
--> java.lang.String.toString(char[],int,int)
I've also had to add a new field to the rewrite rules, that of the
destination class, but unless I've made a mistake this won't make
any difference to the existing rules.
Andrew.
2008-09-22 Andrew Haley <aph@redhat.com>
* expr.c (rules): Add new rule for
gnu.java.lang.VMCPStringBuilder.toString.
(rewrite_rule.new_classname): New field.
(maybe_rewrite_invocation): Use new_classname field instead of
DECL_CONTEXT (*method_p).
Allow rewrite_arglist to be NULL.
Index: gcc/java/expr.c
===================================================================
--- gcc/java/expr.c (revision 140485)
+++ gcc/java/expr.c (working copy)
@@ -2075,6 +2075,7 @@
const char *classname;
const char *method;
const char *signature;
+ const char *new_classname;
const char *new_signature;
int flags;
tree (*rewrite_arglist) (tree arglist);
@@ -2109,20 +2110,27 @@
static rewrite_rule rules[] =
{{"java.lang.Class", "getClassLoader", "()Ljava/lang/ClassLoader;",
- "(Ljava/lang/Class;)Ljava/lang/ClassLoader;",
+ "java.lang.Class", "(Ljava/lang/Class;)Ljava/lang/ClassLoader;",
ACC_FINAL|ACC_PRIVATE, rewrite_arglist_getclass},
+
{"java.lang.Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;",
- "(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Class;",
+ "java.lang.Class", "(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Class;",
ACC_FINAL|ACC_PRIVATE|ACC_STATIC, rewrite_arglist_getclass},
+
{"gnu.classpath.VMStackWalker", "getCallingClass", "()Ljava/lang/Class;",
- "(Lgnu/gcj/RawData;)Ljava/lang/Class;",
+ "gnu.classpath.VMStackWalker", "(Lgnu/gcj/RawData;)Ljava/lang/Class;",
ACC_FINAL|ACC_PRIVATE|ACC_STATIC, rewrite_arglist_getcaller},
+
{"gnu.classpath.VMStackWalker", "getCallingClassLoader",
"()Ljava/lang/ClassLoader;",
- "(Lgnu/gcj/RawData;)Ljava/lang/ClassLoader;",
+ "gnu.classpath.VMStackWalker", "(Lgnu/gcj/RawData;)Ljava/lang/ClassLoader;",
ACC_FINAL|ACC_PRIVATE|ACC_STATIC, rewrite_arglist_getcaller},
- {NULL, NULL, NULL, NULL, 0, NULL}};
+ {"gnu.java.lang.VMCPStringBuilder", "toString", "([CII)Ljava/lang/String;",
+ "java.lang.String", "([CII)Ljava/lang/String;",
+ ACC_FINAL|ACC_PRIVATE|ACC_STATIC, NULL},
+
+ {NULL, NULL, NULL, NULL, NULL, 0, NULL}};
/* True if this method is special, i.e. it's a private method that
should be exported from a DSO. */
@@ -2163,20 +2171,25 @@
if (get_identifier (p->method) == method
&& get_identifier (p->signature) == *method_signature_p)
{
- tree maybe_method
- = lookup_java_method (DECL_CONTEXT (*method_p),
+ tree maybe_method;
+ tree destination_class
+ = lookup_class (get_identifier (p->new_classname));
+ gcc_assert (destination_class);
+ maybe_method
+ = lookup_java_method (destination_class,
method,
get_identifier (p->new_signature));
if (! maybe_method && ! flag_verify_invocations)
{
maybe_method
- = add_method (DECL_CONTEXT (*method_p), p->flags,
+ = add_method (destination_class, p->flags,
method, get_identifier (p->new_signature));
DECL_EXTERNAL (maybe_method) = 1;
}
*method_p = maybe_method;
gcc_assert (*method_p);
- *arg_list_p = p->rewrite_arglist (*arg_list_p);
+ if (p->rewrite_arglist)
+ *arg_list_p = p->rewrite_arglist (*arg_list_p);
*method_signature_p = get_identifier (p->new_signature);
*special = integer_one_node;
reply other threads:[~2008-09-22 13:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48D79EC9.8000404@redhat.com \
--to=aph@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=java@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).