< prev index next >

src/hotspot/share/c1/c1_Canonicalizer.cpp

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 278,11 ***
    IntConstant* index = x->index()->type()->as_IntConstant();
  
    assert(array == nullptr || FoldStableValues, "not enabled");
  
    // Constant fold loads from stable arrays.
!   if (!x->mismatched() && array != nullptr && index != nullptr) {
      jint idx = index->value();
      if (idx < 0 || idx >= array->value()->length()) {
        // Leave the load as is. The range check will handle it.
        return;
      }
--- 278,11 ---
    IntConstant* index = x->index()->type()->as_IntConstant();
  
    assert(array == nullptr || FoldStableValues, "not enabled");
  
    // Constant fold loads from stable arrays.
!   if (!x->should_profile() && !x->mismatched() && array != nullptr && index != nullptr) {
      jint idx = index->value();
      if (idx < 0 || idx >= array->value()->length()) {
        // Leave the load as is. The range check will handle it.
        return;
      }

*** 466,15 ***
    }
  }
  
  
  void Canonicalizer::do_IfOp(IfOp* x) {
!   // Currently, Canonicalizer is only used by GraphBuilder,
!   // and IfOp is not created by GraphBuilder but only later
-   // when eliminating conditional expressions with CE_Eliminator,
-   // so this method will not be called.
-   ShouldNotReachHere();
  }
  
  
  void Canonicalizer::do_Intrinsic      (Intrinsic*       x) {
    switch (x->id()) {
--- 466,12 ---
    }
  }
  
  
  void Canonicalizer::do_IfOp(IfOp* x) {
!   // Currently, Canonicalizer is only used by GraphBuilder, and IfOp is only created by
!   // GraphBuilder when loading/storing flat fields, do nothing for now.
  }
  
  
  void Canonicalizer::do_Intrinsic      (Intrinsic*       x) {
    switch (x->id()) {

*** 646,17 ***
      if (klass != nullptr && klass->is_loaded()) {
        bool is_interface = klass->is_instance_klass() &&
                            klass->as_instance_klass()->is_interface();
        // Interface casts can't be statically optimized away since verifier doesn't
        // enforce interface types in bytecode.
!       if (!is_interface && klass->is_subtype_of(x->klass())) {
          set_canonical(obj);
          return;
        }
      }
!     // checkcast of null returns null
!     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
        set_canonical(obj);
      }
    }
  }
  void Canonicalizer::do_InstanceOf     (InstanceOf*      x) {
--- 643,18 ---
      if (klass != nullptr && klass->is_loaded()) {
        bool is_interface = klass->is_instance_klass() &&
                            klass->as_instance_klass()->is_interface();
        // Interface casts can't be statically optimized away since verifier doesn't
        // enforce interface types in bytecode.
!       if (!is_interface && klass->is_subtype_of(x->klass()) && (!x->is_null_free() || obj->is_null_free())) {
+         assert(!x->klass()->is_inlinetype() || x->klass() == klass, "Inline klasses can't have subtypes");
          set_canonical(obj);
          return;
        }
      }
!     // checkcast of null returns null for non null-free klasses
!     if (!x->is_null_free() && obj->is_null_obj()) {
        set_canonical(obj);
      }
    }
  }
  void Canonicalizer::do_InstanceOf     (InstanceOf*      x) {

*** 666,11 ***
      if (exact != nullptr && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
        set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
        return;
      }
      // instanceof null returns false
!     if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
        set_constant(0);
      }
    }
  
  }
--- 664,11 ---
      if (exact != nullptr && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
        set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
        return;
      }
      // instanceof null returns false
!     if (obj->as_Constant() && obj->is_null_obj()) {
        set_constant(0);
      }
    }
  
  }

*** 843,12 ***
  void Canonicalizer::do_UnsafeGet      (UnsafeGet*       x) {}
  void Canonicalizer::do_UnsafePut      (UnsafePut*       x) {}
  void Canonicalizer::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {}
  void Canonicalizer::do_ProfileCall    (ProfileCall*     x) {}
  void Canonicalizer::do_ProfileReturnType(ProfileReturnType* x) {}
! void Canonicalizer::do_ProfileInvoke  (ProfileInvoke*   x) {}
! void Canonicalizer::do_RuntimeCall    (RuntimeCall*     x) {}
  void Canonicalizer::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
  #ifdef ASSERT
  void Canonicalizer::do_Assert         (Assert*          x) {}
  #endif
  void Canonicalizer::do_MemBar         (MemBar*          x) {}
--- 841,13 ---
  void Canonicalizer::do_UnsafeGet      (UnsafeGet*       x) {}
  void Canonicalizer::do_UnsafePut      (UnsafePut*       x) {}
  void Canonicalizer::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {}
  void Canonicalizer::do_ProfileCall    (ProfileCall*     x) {}
  void Canonicalizer::do_ProfileReturnType(ProfileReturnType* x) {}
! void Canonicalizer::do_ProfileInvoke    (ProfileInvoke* x) {}
! void Canonicalizer::do_ProfileACmpTypes (ProfileACmpTypes* x) {}
+ void Canonicalizer::do_RuntimeCall      (RuntimeCall* x) {}
  void Canonicalizer::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
  #ifdef ASSERT
  void Canonicalizer::do_Assert         (Assert*          x) {}
  #endif
  void Canonicalizer::do_MemBar         (MemBar*          x) {}
< prev index next >