< prev index next >

src/hotspot/share/c1/c1_Canonicalizer.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 627 void Canonicalizer::do_NullCheck      (NullCheck*       x) {
 628   if (x->obj()->as_NewArray() != NULL || x->obj()->as_NewInstance() != NULL) {
 629     set_canonical(x->obj());
 630   } else {
 631     Constant* con = x->obj()->as_Constant();
 632     if (con) {
 633       ObjectType* c = con->type()->as_ObjectType();
 634       if (c && c->is_loaded()) {
 635         ObjectConstant* oc = c->as_ObjectConstant();
 636         if (!oc || !oc->value()->is_null_object()) {
 637           set_canonical(con);
 638         }
 639       }
 640     }
 641   }
 642 }
 643 
 644 void Canonicalizer::do_TypeCast       (TypeCast*        x) {}
 645 void Canonicalizer::do_Invoke         (Invoke*          x) {}
 646 void Canonicalizer::do_NewInstance    (NewInstance*     x) {}

 647 void Canonicalizer::do_NewTypeArray   (NewTypeArray*    x) {}
 648 void Canonicalizer::do_NewObjectArray (NewObjectArray*  x) {}
 649 void Canonicalizer::do_NewMultiArray  (NewMultiArray*   x) {}


 650 void Canonicalizer::do_CheckCast      (CheckCast*       x) {
 651   if (x->klass()->is_loaded()) {

 652     Value obj = x->obj();
 653     ciType* klass = obj->exact_type();
 654     if (klass == NULL) {
 655       klass = obj->declared_type();
 656     }
 657     if (klass != NULL && klass->is_loaded()) {
 658       bool is_interface = klass->is_instance_klass() &&
 659                           klass->as_instance_klass()->is_interface();
 660       // Interface casts can't be statically optimized away since verifier doesn't
 661       // enforce interface types in bytecode.
 662       if (!is_interface && klass->is_subtype_of(x->klass())) {
 663         set_canonical(obj);
 664         return;
 665       }
 666     }
 667     // checkcast of null returns null
 668     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
 669       set_canonical(obj);
 670     }
 671   }


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 627 void Canonicalizer::do_NullCheck      (NullCheck*       x) {
 628   if (x->obj()->as_NewArray() != NULL || x->obj()->as_NewInstance() != NULL) {
 629     set_canonical(x->obj());
 630   } else {
 631     Constant* con = x->obj()->as_Constant();
 632     if (con) {
 633       ObjectType* c = con->type()->as_ObjectType();
 634       if (c && c->is_loaded()) {
 635         ObjectConstant* oc = c->as_ObjectConstant();
 636         if (!oc || !oc->value()->is_null_object()) {
 637           set_canonical(con);
 638         }
 639       }
 640     }
 641   }
 642 }
 643 
 644 void Canonicalizer::do_TypeCast       (TypeCast*        x) {}
 645 void Canonicalizer::do_Invoke         (Invoke*          x) {}
 646 void Canonicalizer::do_NewInstance    (NewInstance*     x) {}
 647 void Canonicalizer::do_NewValueTypeInstance(NewValueTypeInstance* x) {}
 648 void Canonicalizer::do_NewTypeArray   (NewTypeArray*    x) {}
 649 void Canonicalizer::do_NewObjectArray (NewObjectArray*  x) {}
 650 void Canonicalizer::do_NewMultiArray  (NewMultiArray*   x) {}
 651 void Canonicalizer::do_WithField      (WithField*       x) {}
 652 void Canonicalizer::do_DefaultValue   (DefaultValue*    x) {}
 653 void Canonicalizer::do_CheckCast      (CheckCast*       x) {
 654   if (x->klass()->is_loaded() && !x->is_never_null()) {
 655     // Don't canonicalize for non-nullable types -- we need to throw NPE.
 656     Value obj = x->obj();
 657     ciType* klass = obj->exact_type();
 658     if (klass == NULL) {
 659       klass = obj->declared_type();
 660     }
 661     if (klass != NULL && klass->is_loaded()) {
 662       bool is_interface = klass->is_instance_klass() &&
 663                           klass->as_instance_klass()->is_interface();
 664       // Interface casts can't be statically optimized away since verifier doesn't
 665       // enforce interface types in bytecode.
 666       if (!is_interface && klass->is_subtype_of(x->klass())) {
 667         set_canonical(obj);
 668         return;
 669       }
 670     }
 671     // checkcast of null returns null
 672     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
 673       set_canonical(obj);
 674     }
 675   }


< prev index next >