8193927: Optimize scanning code for oops.
authorgoetz
Thu, 21 Dec 2017 09:05:32 +0100
changeset 48486 bda5211e7876
parent 48485 258a4dab74a7
child 48487 abf1d797e380
8193927: Optimize scanning code for oops. Reviewed-by: simonis, mdoerr, aph
src/hotspot/cpu/aarch64/relocInfo_aarch64.hpp
src/hotspot/cpu/arm/relocInfo_arm.hpp
src/hotspot/cpu/ppc/relocInfo_ppc.hpp
src/hotspot/cpu/s390/relocInfo_s390.hpp
src/hotspot/cpu/sparc/relocInfo_sparc.hpp
src/hotspot/cpu/x86/relocInfo_x86.hpp
src/hotspot/cpu/zero/relocInfo_zero.hpp
src/hotspot/share/code/nmethod.cpp
src/hotspot/share/code/relocInfo.hpp
--- a/src/hotspot/cpu/aarch64/relocInfo_aarch64.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/cpu/aarch64/relocInfo_aarch64.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -35,4 +35,10 @@
     format_width       =  0
   };
 
+ public:
+
+  // This platform has no oops in the code that are not also
+  // listed in the oop section.
+  static bool mustIterateImmediateOopsInCode() { return false; }
+
 #endif // CPU_AARCH64_VM_RELOCINFO_AARCH64_HPP
--- a/src/hotspot/cpu/arm/relocInfo_arm.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/cpu/arm/relocInfo_arm.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, 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
@@ -32,4 +32,10 @@
     format_width = 0
   };
 
+ public:
+
+  // This platform has no oops in the code that are not also
+  // listed in the oop section.
+  static bool mustIterateImmediateOopsInCode() { return false; }
+
 #endif // CPU_ARM_VM_RELOCINFO_ARM_HPP
--- a/src/hotspot/cpu/ppc/relocInfo_ppc.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/cpu/ppc/relocInfo_ppc.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018 SAP SE. 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
@@ -43,4 +43,10 @@
 #endif
   };
 
+ public:
+
+  // This platform has no oops in the code that are not also
+  // listed in the oop section.
+  static bool mustIterateImmediateOopsInCode() { return false; }
+
 #endif // CPU_PPC_VM_RELOCINFO_PPC_HPP
--- a/src/hotspot/cpu/s390/relocInfo_s390.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/cpu/s390/relocInfo_s390.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2016 SAP SE. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018 SAP SE. 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
@@ -110,6 +110,10 @@
     pcrel_data_format   = 3   // Relocation is for the target data of a pc-relative instruction.
   };
 
+  // This platform has no oops in the code that are not also
+  // listed in the oop section.
+  static bool mustIterateImmediateOopsInCode() { return false; }
+
   // Store the new target address into an oop_Relocation cell, if any.
   // Return indication if update happened.
   static bool update_oop_pool(address begin, address end, address newTarget, CodeBlob* cb);
--- a/src/hotspot/cpu/sparc/relocInfo_sparc.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/cpu/sparc/relocInfo_sparc.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -38,6 +38,11 @@
     format_width       =  1
   };
 
+ public:
+
+  // This platform has no oops in the code that are not also
+  // listed in the oop section.
+  static bool mustIterateImmediateOopsInCode() { return false; }
 
 //Reconciliation History
 // 1.3 97/10/15 15:38:36 relocInfo_i486.hpp
--- a/src/hotspot/cpu/x86/relocInfo_x86.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/cpu/x86/relocInfo_x86.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -40,4 +40,10 @@
 #endif
   };
 
+ public:
+
+  // Instruct loadConP of x86_64.ad places oops in code that are not also
+  // listed in the oop section.
+  static bool mustIterateImmediateOopsInCode() { return true; }
+
 #endif // CPU_X86_VM_RELOCINFO_X86_HPP
--- a/src/hotspot/cpu/zero/relocInfo_zero.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/cpu/zero/relocInfo_zero.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2007 Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -34,4 +34,8 @@
     format_width =  1
   };
 
+ public:
+
+  static bool mustIterateImmediateOopsInCode() { return true; }
+
 #endif // CPU_ZERO_VM_RELOCINFO_ZERO_HPP
--- a/src/hotspot/share/code/nmethod.cpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/share/code/nmethod.cpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -1485,16 +1485,18 @@
 
 bool nmethod::do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred) {
   // Compiled code
-  {
-  RelocIterator iter(this, low_boundary);
-  while (iter.next()) {
-    if (iter.type() == relocInfo::oop_type) {
-      if (unload_if_dead_at(&iter, is_alive, unloading_occurred)) {
-        return true;
+
+  // Prevent extra code cache walk for platforms that don't have immediate oops.
+  if (relocInfo::mustIterateImmediateOopsInCode()) {
+    RelocIterator iter(this, low_boundary);
+    while (iter.next()) {
+      if (iter.type() == relocInfo::oop_type) {
+        if (unload_if_dead_at(&iter, is_alive, unloading_occurred)) {
+          return true;
+        }
       }
     }
   }
-  }
 
   return do_unloading_scopes(is_alive, unloading_occurred);
 }
@@ -1584,18 +1586,21 @@
     // (See comment above.)
   }
 
-  RelocIterator iter(this, low_boundary);
+  // Prevent extra code cache walk for platforms that don't have immediate oops.
+  if (relocInfo::mustIterateImmediateOopsInCode()) {
+    RelocIterator iter(this, low_boundary);
 
-  while (iter.next()) {
-    if (iter.type() == relocInfo::oop_type ) {
-      oop_Relocation* r = iter.oop_reloc();
-      // In this loop, we must only follow those oops directly embedded in
-      // the code.  Other oops (oop_index>0) are seen as part of scopes_oops.
-      assert(1 == (r->oop_is_immediate()) +
-                   (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()),
-             "oop must be found in exactly one place");
-      if (r->oop_is_immediate() && r->oop_value() != NULL) {
-        f->do_oop(r->oop_addr());
+    while (iter.next()) {
+      if (iter.type() == relocInfo::oop_type ) {
+        oop_Relocation* r = iter.oop_reloc();
+        // In this loop, we must only follow those oops directly embedded in
+        // the code.  Other oops (oop_index>0) are seen as part of scopes_oops.
+        assert(1 == (r->oop_is_immediate()) +
+               (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()),
+               "oop must be found in exactly one place");
+        if (r->oop_is_immediate() && r->oop_value() != NULL) {
+          f->do_oop(r->oop_addr());
+        }
       }
     }
   }
--- a/src/hotspot/share/code/relocInfo.hpp	Tue Jan 02 07:50:17 2018 -0500
+++ b/src/hotspot/share/code/relocInfo.hpp	Thu Dec 21 09:05:32 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -910,6 +910,10 @@
   }
   // an oop in the instruction stream
   static RelocationHolder spec_for_immediate() {
+    // If no immediate oops are generated, we can skip some walks over nmethods.
+    // Assert that they don't get generated accidently!
+    assert(relocInfo::mustIterateImmediateOopsInCode(),
+           "Must return true so we will search for oops as roots etc. in the code.");
     const int oop_index = 0;
     const int offset    = 0;    // if you want an offset, use the oop pool
     RelocationHolder rh = newHolder();