[vmkit-commits] [PATCH] Better handle virtual calls through casted 'this' pointers.

Will Dietz wdietz2 at illinois.edu
Wed Nov 16 11:29:49 PST 2011


Inlined below.

I opted to do the assignable check, as opposed to just handling the
case when customizeFor->lookupMethod fails, because if the classes
aren't assignable then I'm concerned lookupMethod could conceivably
return the *wrong* method, although I can't make a test case
demonstrating that.

This fixes the test case I checked in earlier, as well as the
inspiration for that test case: java/awt/Toolkit.getDesktopProperty()
(in OpenJDK anyway).

Thoughts welcome, and thanks for your time! :)

~Will

>From 6295ae789713baf56d5cc49500f2193812151db6 Mon Sep 17 00:00:00 2001
From: Will Dietz <w at wdtz.org>
Date: Wed, 16 Nov 2011 13:21:45 -0600
Subject: [PATCH] Better handle virtual calls through casted 'this' pointers.

* Being a 'thisReference' doesn't mean we don't need to dynamically resolve
* Only customize if the call is valid for the current customization class.
    This is checked by "if(customizeFor instanceof calleeClass)"
---
 lib/J3/Compiler/JavaJIT.cpp |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/J3/Compiler/JavaJIT.cpp b/lib/J3/Compiler/JavaJIT.cpp
index 202c1dc..0b87881 100644
--- a/lib/J3/Compiler/JavaJIT.cpp
+++ b/lib/J3/Compiler/JavaJIT.cpp
@@ -121,10 +121,10 @@ void JavaJIT::invokeVirtual(uint16 index) {
   bool customized = false;
   bool thisReference =
     isThisReference(stackSize() - signature->getNumberOfSlots() - 1);
-  if (thisReference) {
-    assert(meth != NULL);
+  if (thisReference && meth) {
     isCustomizable = true;
-    if (customizeFor != NULL) {
+    if ((customizeFor != NULL)
+        && cl->isAssignableFrom(customizeFor)) {
       meth = customizeFor->lookupMethodDontThrow(
           meth->name, meth->type, false, true, NULL);
       assert(meth);
-- 
1.7.5.1



More information about the vmkit-commits mailing list