changeset 1880:8783e4b809e0

2009-06-06 Gary Benson <gbenson@redhat.com> * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp (SharkTopLevelBlock::do_optimized_instance_check): New method. (SharkTopLevelBlock::do_full_instance_check): Add class argument. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp (SharkTopLevelBlock::do_instance_check): Add compile time type checks. (SharkTopLevelBlock::do_optimized_instance_check): New method. (SharkTopLevelBlock::do_trapping_instance_check): Update the object with the new class if its a checkcast that passes.
author Gary Benson <gbenson@redhat.com>
date Fri, 05 Jun 2009 14:46:31 +0100
parents 2493b242458e
children 085521a03c8b
files ChangeLog ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
diffstat 3 files changed, 63 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jun 05 08:17:22 2009 -0400
+++ b/ChangeLog	Fri Jun 05 14:46:31 2009 +0100
@@ -1,3 +1,15 @@
+2009-06-06  Gary Benson  <gbenson@redhat.com>
+
+	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
+	(SharkTopLevelBlock::do_optimized_instance_check): New method.
+	(SharkTopLevelBlock::do_full_instance_check): Add class argument.	
+	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
+	(SharkTopLevelBlock::do_instance_check): Add compile time type
+	checks.
+	(SharkTopLevelBlock::do_optimized_instance_check): New method.
+	(SharkTopLevelBlock::do_trapping_instance_check): Update the
+	object with the new class if its a checkcast that passes.
+
 2009-06-05  Gary Benson  <gbenson@redhat.com>
 
 	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Fri Jun 05 08:17:22 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Fri Jun 05 14:46:31 2009 +0100
@@ -1166,15 +1166,55 @@
 
 void SharkTopLevelBlock::do_instance_check()
 {
+  // Get the class we're checking against
   bool will_link;
-  ciKlass *klass = iter()->get_klass(will_link);
+  ciKlass *check_klass = iter()->get_klass(will_link);
+
+  // If the class we're checking against is java.lang.Object
+  // then this is a no brainer.  Apparently this can happen
+  // in reflective code...
+  if (check_klass == function()->env()->Object_klass()) {
+    do_optimized_instance_check();
+    return;
+  }
+  
+  // Get the class of the object we're checking
+  ciKlass *object_klass = xstack(0)->type()->as_klass();
 
+  // If the classes are defined enough now then we
+  // don't need a runtime check.  NB opto's code for
+  // this (GraphKit::static_subtype_check) says we
+  // cannot trust static interface types yet, hence
+  // the extra check
+  if (!object_klass->is_interface()) {
+    if (object_klass == check_klass) {
+      do_optimized_instance_check();
+      return;
+    }
+
+    if (object_klass->is_loaded() && check_klass->is_loaded()) {
+      if (object_klass->is_subtype_of(check_klass)) {
+        do_optimized_instance_check();
+        return;
+      }
+    }
+  }
+
+  // Need to check this one at runtime
   if (will_link)
-    do_full_instance_check(klass);
+    do_full_instance_check(check_klass);
   else
-    do_trapping_instance_check();
+    do_trapping_instance_check(check_klass);
 }
-
+                
+void SharkTopLevelBlock::do_optimized_instance_check()
+{
+  if (bc() == Bytecodes::_instanceof) {
+    pop();
+    push(SharkValue::jint_constant(1));
+  }
+}
+    
 void SharkTopLevelBlock::do_full_instance_check(ciKlass* klass)
 { 
   BasicBlock *not_null      = function()->CreateBlock("not_null");
@@ -1275,7 +1315,7 @@
   }
 }
 
-void SharkTopLevelBlock::do_trapping_instance_check()
+void SharkTopLevelBlock::do_trapping_instance_check(ciKlass* klass)
 {
   BasicBlock *not_null = function()->CreateBlock("not_null");
   BasicBlock *is_null  = function()->CreateBlock("null");
@@ -1297,7 +1337,10 @@
   // If it's null then we're ok
   builder()->SetInsertPoint(is_null);
   set_current_state(saved_state);
-  if (bc() == Bytecodes::_instanceof) {
+  if (bc() == Bytecodes::_checkcast) {
+    push(SharkValue::create_generic(klass, pop()->jobject_value(), false));    
+  }
+  else {
     pop();
     push(SharkValue::jint_constant(0));
   }
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp	Fri Jun 05 08:17:22 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp	Fri Jun 05 14:46:31 2009 +0100
@@ -386,8 +386,9 @@
 
   // checkcast and instanceof
  private:
+  void do_optimized_instance_check();
   void do_full_instance_check(ciKlass* klass);
-  void do_trapping_instance_check();
+  void do_trapping_instance_check(ciKlass* klass);
 
   void do_instance_check();