< 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  *


 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_CheckCast      (CheckCast*       x) {
 652   if (x->klass()->is_loaded() && !x->is_never_null()) {
 653     // Don't canonicalize for non-nullable types -- we need to throw NPE.
 654     Value obj = x->obj();
 655     ciType* klass = obj->exact_type();
 656     if (klass == NULL) {
 657       klass = obj->declared_type();
 658     }
 659     if (klass != NULL && klass->is_loaded()) {
 660       bool is_interface = klass->is_instance_klass() &&
 661                           klass->as_instance_klass()->is_interface();
 662       // Interface casts can't be statically optimized away since verifier doesn't
 663       // enforce interface types in bytecode.
 664       if (!is_interface && klass->is_subtype_of(x->klass())) {
 665         set_canonical(obj);
 666         return;
 667       }
 668     }
 669     // checkcast of null returns null
 670     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {


   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  *


 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()) {


< prev index next >