8223504: Improve performance of forall loops by better inlining of "iterator()" methods
authorskuksenko
Thu, 30 May 2019 12:45:02 -0700
changeset 55115 a0d4e61acb6b
parent 55114 6515a96809a1
child 55116 5212c250f9a8
8223504: Improve performance of forall loops by better inlining of "iterator()" methods Reviewed-by: vlivanov, shade
src/hotspot/share/classfile/systemDictionary.hpp
src/hotspot/share/classfile/vmSymbols.hpp
src/hotspot/share/opto/bytecodeInfo.cpp
--- a/src/hotspot/share/classfile/systemDictionary.hpp	Thu May 30 10:29:55 2019 +0800
+++ b/src/hotspot/share/classfile/systemDictionary.hpp	Thu May 30 12:45:02 2019 -0700
@@ -214,6 +214,9 @@
   do_klass(Integer_klass,                               java_lang_Integer                                     ) \
   do_klass(Long_klass,                                  java_lang_Long                                        ) \
                                                                                                                 \
+  /* force inline of iterators */                                                                               \
+  do_klass(Iterator_klass,                              java_util_Iterator                                    ) \
+                                                                                                                \
   /*end*/
 
 
--- a/src/hotspot/share/classfile/vmSymbols.hpp	Thu May 30 10:29:55 2019 +0800
+++ b/src/hotspot/share/classfile/vmSymbols.hpp	Thu May 30 12:45:02 2019 -0700
@@ -126,6 +126,7 @@
   template(getBootClassPathEntryForClass_name,        "getBootClassPathEntryForClass")            \
   template(jdk_internal_vm_PostVMInitHook,            "jdk/internal/vm/PostVMInitHook")           \
   template(sun_net_www_ParseUtil,                     "sun/net/www/ParseUtil")                    \
+  template(java_util_Iterator,                        "java/util/Iterator")                       \
                                                                                                   \
   template(jdk_internal_loader_ClassLoaders_AppClassLoader,      "jdk/internal/loader/ClassLoaders$AppClassLoader")      \
   template(jdk_internal_loader_ClassLoaders_PlatformClassLoader, "jdk/internal/loader/ClassLoaders$PlatformClassLoader") \
--- a/src/hotspot/share/opto/bytecodeInfo.cpp	Thu May 30 10:29:55 2019 +0800
+++ b/src/hotspot/share/opto/bytecodeInfo.cpp	Thu May 30 12:45:02 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, 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
@@ -77,6 +77,8 @@
  *  Return true when EA is ON and a java constructor is called or
  *  a super constructor is called from an inlined java constructor.
  *  Also return true for boxing methods.
+ *  Also return true for methods returning Iterator (including Iterable::iterator())
+ *  that is essential for forall-loops performance.
  */
 static bool is_init_with_ea(ciMethod* callee_method,
                             ciMethod* caller_method, Compile* C) {
@@ -94,6 +96,11 @@
   if (C->eliminate_boxing() && callee_method->is_boxing_method()) {
     return true;
   }
+  ciType *retType = callee_method->signature()->return_type();
+  ciKlass *iter = C->env()->Iterator_klass();
+  if(retType->is_loaded() && iter->is_loaded() && retType->is_subtype_of(iter)) {
+    return true;
+  }
   return false;
 }