changeset 9420:d21a3fc77eca

Merge
author andrew
date Wed, 17 Mar 2021 20:41:55 +0000
parents 9d362a0bae2c (diff) 616812f93bca (current diff)
children 2d0ba7271ce2
files
diffstat 14 files changed, 251 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/src/cpu/aarch64/vm/c1_Runtime1_aarch64.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/cpu/aarch64/vm/c1_Runtime1_aarch64.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -143,9 +143,9 @@
 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2, Register arg3) {
   // if there is any conflict use the stack
   if (arg1 == c_rarg2 || arg1 == c_rarg3 ||
-      arg2 == c_rarg1 || arg1 == c_rarg3 ||
-      arg3 == c_rarg1 || arg1 == c_rarg2) {
-    stp(arg3, arg2, Address(pre(sp, 2 * wordSize)));
+      arg2 == c_rarg1 || arg2 == c_rarg3 ||
+      arg3 == c_rarg1 || arg3 == c_rarg2) {
+    stp(arg3, arg2, Address(pre(sp, -2 * wordSize)));
     stp(arg1, zr, Address(pre(sp, -2 * wordSize)));
     ldp(c_rarg1, zr, Address(post(sp, 2 * wordSize)));
     ldp(c_rarg3, c_rarg2, Address(post(sp, 2 * wordSize)));
--- a/src/cpu/aarch64/vm/vm_version_aarch64.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/cpu/aarch64/vm/vm_version_aarch64.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -138,6 +138,17 @@
     if (PrefetchCopyIntervalInBytes >= 32768)
       PrefetchCopyIntervalInBytes = 32760;
   }
+
+  if (AllocatePrefetchDistance !=-1 && (AllocatePrefetchDistance & 7)) {
+    warning("AllocatePrefetchDistance must be multiple of 8");
+    AllocatePrefetchDistance &= ~7;
+  }
+
+  if (AllocatePrefetchStepSize & 7) {
+    warning("AllocatePrefetchStepSize must be multiple of 8");
+    AllocatePrefetchStepSize &= ~7;
+  }
+
   FLAG_SET_DEFAULT(UseSSE42Intrinsics, true);
 
   unsigned long auxv = getauxval(AT_HWCAP);
--- a/src/cpu/x86/vm/c1_Runtime1_x86.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/cpu/x86/vm/c1_Runtime1_x86.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -172,8 +172,8 @@
 #ifdef _LP64
   // if there is any conflict use the stack
   if (arg1 == c_rarg2 || arg1 == c_rarg3 ||
-      arg2 == c_rarg1 || arg1 == c_rarg3 ||
-      arg3 == c_rarg1 || arg1 == c_rarg2) {
+      arg2 == c_rarg1 || arg2 == c_rarg3 ||
+      arg3 == c_rarg1 || arg3 == c_rarg2) {
     push(arg3);
     push(arg2);
     push(arg1);
--- a/src/share/vm/c1/c1_IR.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/c1/c1_IR.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -578,11 +578,8 @@
     assert(is_visited(cur), "block must be visisted when block is active");
     assert(parent != NULL, "must have parent");
 
-    cur->set(BlockBegin::linear_scan_loop_header_flag);
     cur->set(BlockBegin::backward_branch_target_flag);
 
-    parent->set(BlockBegin::linear_scan_loop_end_flag);
-
     // When a loop header is also the start of an exception handler, then the backward branch is
     // an exception edge. Because such edges are usually critical edges which cannot be split, the
     // loop must be excluded here from processing.
@@ -591,6 +588,10 @@
       _iterative_dominators = true;
       return;
     }
+
+    cur->set(BlockBegin::linear_scan_loop_header_flag);
+    parent->set(BlockBegin::linear_scan_loop_end_flag);
+
     assert(parent->number_of_sux() == 1 && parent->sux_at(0) == cur,
            "loop end blocks must have one successor (critical edges are split)");
 
--- a/src/share/vm/c1/c1_Instruction.hpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/c1/c1_Instruction.hpp	Wed Mar 17 20:41:55 2021 +0000
@@ -2124,11 +2124,11 @@
   // creation
   TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
     : Switch(tag, sux, state_before, is_safepoint)
-  , _lo_key(lo_key) {}
+  , _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); }
 
   // accessors
   int lo_key() const                             { return _lo_key; }
-  int hi_key() const                             { return _lo_key + length() - 1; }
+  int hi_key() const                             { return _lo_key + (length() - 1); }
 };
 
 
--- a/src/share/vm/c1/c1_LIRGenerator.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/c1/c1_LIRGenerator.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -2520,8 +2520,8 @@
   move_to_phi(x->state());
 
   int lo_key = x->lo_key();
-  int hi_key = x->hi_key();
   int len = x->length();
+  assert(lo_key <= (lo_key + (len - 1)), "integer overflow");
   LIR_Opr value = tag.result();
   if (UseTableRanges) {
     do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
--- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -22,10 +22,6 @@
  *
  */
 
-#if !defined(__clang_major__) && defined(__GNUC__)
-#define ATTRIBUTE_PRINTF(x,y) // FIXME, formats are a mess.
-#endif
-
 #include "precompiled.hpp"
 #include "classfile/metadataOnStackMark.hpp"
 #include "code/codeCache.hpp"
@@ -232,7 +228,7 @@
     if (!curr->is_young()) {
       gclog_or_tty->print_cr("### YOUNG REGION " PTR_FORMAT "-" PTR_FORMAT " "
                              "incorrectly tagged (y: %d, surv: %d)",
-                             curr->bottom(), curr->end(),
+                             p2i(curr->bottom()), p2i(curr->end()),
                              curr->is_young(), curr->is_survivor());
       ret = false;
     }
@@ -361,8 +357,8 @@
     while (curr != NULL) {
       gclog_or_tty->print_cr("  " HR_FORMAT ", P: " PTR_FORMAT ", N: " PTR_FORMAT ", age: %4d",
                              HR_FORMAT_PARAMS(curr),
-                             curr->prev_top_at_mark_start(),
-                             curr->next_top_at_mark_start(),
+                             p2i(curr->prev_top_at_mark_start()),
+                             p2i(curr->next_top_at_mark_start()),
                              curr->age_in_surv_rate_group_cond());
       curr = curr->get_next_young_region();
     }
@@ -487,7 +483,7 @@
   RedirtyLoggedCardTableEntryClosure redirty;
   dcqs.apply_closure_to_all_completed_buffers(&redirty);
   dcqs.iterate_closure_all_threads(&redirty, false);
-  gclog_or_tty->print_cr("Log entries = %d, dirty cards = %d.",
+  gclog_or_tty->print_cr("Log entries = " SIZE_FORMAT ", dirty cards = %d.",
                          clear.num_processed(), orig_count);
   guarantee(redirty.num_processed() == clear.num_processed(),
             err_msg("Redirtied " SIZE_FORMAT " cards, bug cleared " SIZE_FORMAT,
@@ -2690,8 +2686,8 @@
         gclog_or_tty->print_cr("Region " HR_FORMAT ", "
                                "HS = " PTR_FORMAT ", should be " PTR_FORMAT,
                                HR_FORMAT_PARAMS(r),
-                               r->humongous_start_region(),
-                               _sh_region);
+                               p2i(r->humongous_start_region()),
+                               p2i(_sh_region));
         ++_failures;
       }
     }
@@ -3002,9 +2998,9 @@
       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
       if (_g1h->is_obj_dead_cond(obj, _vo)) {
         gclog_or_tty->print_cr("Root location " PTR_FORMAT " "
-                              "points to dead obj " PTR_FORMAT, p, (void*) obj);
+                               "points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
         if (_vo == VerifyOption_G1UseMarkWord) {
-          gclog_or_tty->print_cr("  Mark word: " PTR_FORMAT, (void*)(obj->mark()));
+          gclog_or_tty->print_cr("  Mark word: " INTPTR_FORMAT, (intptr_t)obj->mark());
         }
         obj->print_on(gclog_or_tty);
         _failures = true;
@@ -3052,9 +3048,9 @@
       // contains the nmethod
       if (!hrrs->strong_code_roots_list_contains(_nm)) {
         gclog_or_tty->print_cr("Code root location " PTR_FORMAT " "
-                              "from nmethod " PTR_FORMAT " not in strong "
-                              "code roots for region [" PTR_FORMAT "," PTR_FORMAT ")",
-                              p, _nm, hr->bottom(), hr->end());
+                               "from nmethod " PTR_FORMAT " not in strong "
+                               "code roots for region [" PTR_FORMAT "," PTR_FORMAT ")",
+                               p2i(p), p2i(_nm), p2i(hr->bottom()), p2i(hr->end()));
         _failures = true;
       }
     }
@@ -3110,7 +3106,7 @@
     _young_ref_counter_closure.reset_count();
     k->oops_do(&_young_ref_counter_closure);
     if (_young_ref_counter_closure.count() > 0) {
-      guarantee(k->has_modified_oops(), err_msg("Klass %p, has young refs but is not dirty.", k));
+      guarantee(k->has_modified_oops(), err_msg("Klass " PTR_FORMAT ", has young refs but is not dirty.", p2i(k)));
     }
   }
 };
@@ -3185,7 +3181,7 @@
       size_t word_sz = o->size();
       gclog_or_tty->print("\nPrinting obj " PTR_FORMAT " of size " SIZE_FORMAT
                           " isMarkedPrev %d isMarkedNext %d isAllocSince %d\n",
-                          (void*) o, word_sz,
+                          p2i(o), word_sz,
                           _g1->isMarkedPrev(o),
                           _g1->isMarkedNext(o),
                           _hr->obj_allocated_since_prev_marking(o));
@@ -3194,7 +3190,7 @@
       int *val;
       for (cur = start; cur < end; cur++) {
         val = (int *) cur;
-        gclog_or_tty->print("\t " PTR_FORMAT ":" PTR_FORMAT "\n", val, *val);
+        gclog_or_tty->print("\t " PTR_FORMAT ": %d\n", p2i(val), *val);
       }
     }
   }
@@ -3232,7 +3228,7 @@
             gclog_or_tty->print_cr("[" PTR_FORMAT "," PTR_FORMAT "] "
                                    "max_live_bytes " SIZE_FORMAT " "
                                    "< calculated " SIZE_FORMAT,
-                                   r->bottom(), r->end(),
+                                   p2i(r->bottom()), p2i(r->end()),
                                    r->max_live_bytes(),
                                  not_dead_yet_cl.live_bytes());
             _failures = true;
@@ -3449,10 +3445,10 @@
   st->print(" %-20s", "garbage-first heap");
   st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
             capacity()/K, used_unlocked()/K);
-  st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
-            _hrm.reserved().start(),
-            _hrm.reserved().start() + _hrm.length() + HeapRegion::GrainWords,
-            _hrm.reserved().end());
+  st->print(" [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ")",
+            p2i(_hrm.reserved().start()),
+            p2i(_hrm.reserved().start() + _hrm.length() + HeapRegion::GrainWords),
+            p2i(_hrm.reserved().end()));
   st->cr();
   st->print("  region size " SIZE_FORMAT "K, ", HeapRegion::GrainBytes / K);
   uint young_regions = _young_list->length();
@@ -4450,7 +4446,7 @@
                                                oop old) {
   assert(obj_in_cs(old),
          err_msg("obj: " PTR_FORMAT " should still be in the CSet",
-                 (HeapWord*) old));
+                 p2i(old)));
   markOop m = old->mark();
   oop forward_ptr = old->forward_to_atomic(old);
   if (forward_ptr == NULL) {
@@ -4485,7 +4481,7 @@
     assert(old == forward_ptr || !obj_in_cs(forward_ptr),
            err_msg("obj: " PTR_FORMAT " forwarded to: " PTR_FORMAT " "
                    "should not be in the CSet",
-                   (HeapWord*) old, (HeapWord*) forward_ptr));
+                   p2i(old), p2i(forward_ptr)));
     return forward_ptr;
   }
 }
@@ -5379,8 +5375,7 @@
         _par_scan_state->push_on_queue(p);
       } else {
         assert(!Metaspace::contains((const void*)p),
-               err_msg("Unexpectedly found a pointer from metadata: "
-                              PTR_FORMAT, p));
+               err_msg("Unexpectedly found a pointer from metadata: " PTR_FORMAT, p2i(p)));
         _copy_non_heap_obj_cl->do_oop(p);
       }
     }
@@ -6062,14 +6057,14 @@
 bool G1CollectedHeap::verify_no_bits_over_tams(const char* bitmap_name, CMBitMapRO* bitmap,
                                                HeapWord* tams, HeapWord* end) {
   guarantee(tams <= end,
-            err_msg("tams: " PTR_FORMAT " end: " PTR_FORMAT, tams, end));
+            err_msg("tams: " PTR_FORMAT " end: " PTR_FORMAT, p2i(tams), p2i(end)));
   HeapWord* result = bitmap->getNextMarkedWordAddress(tams, end);
   if (result < end) {
     gclog_or_tty->cr();
     gclog_or_tty->print_cr("## wrong marked address on %s bitmap: " PTR_FORMAT,
-                           bitmap_name, result);
+                           bitmap_name, p2i(result));
     gclog_or_tty->print_cr("## %s tams: " PTR_FORMAT " end: " PTR_FORMAT,
-                           bitmap_name, tams, end);
+                           bitmap_name, p2i(tams), p2i(end));
     return false;
   }
   return true;
@@ -6406,10 +6401,10 @@
         !r->rem_set()->is_empty()) {
 
       if (G1TraceEagerReclaimHumongousObjects) {
-        gclog_or_tty->print_cr("Live humongous region %u size " SIZE_FORMAT " start " PTR_FORMAT " length " UINT32_FORMAT " with remset " SIZE_FORMAT " code roots " SIZE_FORMAT " is marked %d reclaim candidate %d type array %d",
+        gclog_or_tty->print_cr("Live humongous region %u size " SIZE_FORMAT " start " PTR_FORMAT " length %u with remset " SIZE_FORMAT " code roots " SIZE_FORMAT " is marked %d reclaim candidate %d type array %d",
                                region_idx,
-                               obj->size()*HeapWordSize,
-                               r->bottom(),
+                               (size_t)obj->size()*HeapWordSize,
+                               p2i(r->bottom()),
                                r->region_num(),
                                r->rem_set()->occupied(),
                                r->rem_set()->strong_code_roots_list_length(),
@@ -6425,13 +6420,13 @@
     guarantee(obj->is_typeArray(),
               err_msg("Only eagerly reclaiming type arrays is supported, but the object "
                       PTR_FORMAT " is not.",
-                      r->bottom()));
+                      p2i(r->bottom())));
 
     if (G1TraceEagerReclaimHumongousObjects) {
-      gclog_or_tty->print_cr("Dead humongous region %u size " SIZE_FORMAT " start " PTR_FORMAT " length " UINT32_FORMAT " with remset " SIZE_FORMAT " code roots " SIZE_FORMAT " is marked %d reclaim candidate %d type array %d",
+      gclog_or_tty->print_cr("Dead humongous region %u size " SIZE_FORMAT " start " PTR_FORMAT " length %u with remset " SIZE_FORMAT " code roots " SIZE_FORMAT " is marked %d reclaim candidate %d type array %d",
                              region_idx,
-                             obj->size()*HeapWordSize,
-                             r->bottom(),
+                             (size_t)obj->size()*HeapWordSize,
+                             p2i(r->bottom()),
                              r->region_num(),
                              r->rem_set()->occupied(),
                              r->rem_set()->strong_code_roots_list_length(),
@@ -6585,7 +6580,7 @@
   bool doHeapRegion(HeapRegion* r) {
     if (r->is_young()) {
       gclog_or_tty->print_cr("Region [" PTR_FORMAT ", " PTR_FORMAT ") tagged as young",
-                             r->bottom(), r->end());
+                             p2i(r->bottom()), p2i(r->end()));
       _success = false;
     }
     return false;
@@ -6936,7 +6931,7 @@
       assert(!hr->continuesHumongous(),
              err_msg("trying to add code root " PTR_FORMAT " in continuation of humongous region " HR_FORMAT
                      " starting at " HR_FORMAT,
-                     _nm, HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region())));
+                     p2i(_nm), HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region())));
 
       // HeapRegion::add_strong_code_root_locked() avoids adding duplicate entries.
       hr->add_strong_code_root_locked(_nm);
@@ -6963,7 +6958,7 @@
       assert(!hr->continuesHumongous(),
              err_msg("trying to remove code root " PTR_FORMAT " in continuation of humongous region " HR_FORMAT
                      " starting at " HR_FORMAT,
-                     _nm, HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region())));
+                     p2i(_nm), HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region())));
 
       hr->remove_strong_code_root(_nm);
     }
--- a/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -22,10 +22,6 @@
  *
  */
 
-#ifndef __clang_major__
-#define ATTRIBUTE_PRINTF(x,y) // FIXME, formats are a mess.
-#endif
-
 #include "precompiled.hpp"
 #include "gc_implementation/g1/concurrentG1Refine.hpp"
 #include "gc_implementation/g1/concurrentMark.hpp"
@@ -288,7 +284,7 @@
   if (confidence_perc > 100) {
     confidence_perc = 100;
     warning("G1ConfidencePercent is set to a value that is too large, "
-            "it's been updated to %u", confidence_perc);
+            "it's been updated to " UINTX_FORMAT, confidence_perc);
   }
   _sigma = (double) confidence_perc / 100.0;
 
@@ -310,7 +306,7 @@
   if (reserve_perc > 50) {
     reserve_perc = 50;
     warning("G1ReservePercent is set to a value that is too large, "
-            "it's been updated to %u", reserve_perc);
+            "it's been updated to " UINTX_FORMAT, reserve_perc);
   }
   _reserve_factor = (double) reserve_perc / 100.0;
   // This will be set when the heap is expanded
@@ -1853,7 +1849,7 @@
     assert(csr->in_collection_set(), "bad CS");
     st->print_cr("  " HR_FORMAT ", P: " PTR_FORMAT "N: " PTR_FORMAT ", age: %4d",
                  HR_FORMAT_PARAMS(csr),
-                 csr->prev_top_at_mark_start(), csr->next_top_at_mark_start(),
+                 p2i(csr->prev_top_at_mark_start()), p2i(csr->next_top_at_mark_start()),
                  csr->age_in_surv_rate_group_cond());
     csr = next;
   }
@@ -2219,7 +2215,7 @@
 void TraceGen0TimeData::print_summary_sd(const char* str,
                                          const NumberSeq* seq) const {
   print_summary(str, seq);
-  gclog_or_tty->print_cr("%+45s = %5d, std dev = %8.2lf ms, max = %8.2lf ms)",
+  gclog_or_tty->print_cr("%45s = %5d, std dev = %8.2lf ms, max = %8.2lf ms)",
                 "(num", seq->num(), seq->sd(), seq->maximum());
 }
 
--- a/src/share/vm/gc_implementation/g1/g1ErgoVerbose.hpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/gc_implementation/g1/g1ErgoVerbose.hpp	Wed Mar 17 20:41:55 2021 +0000
@@ -160,40 +160,43 @@
   } while (0)
 
 
-#define ergo_verbose(_tag_, _action_)                                   \
-  ergo_verbose_common(_tag_, _action_, "", 0, 0, 0, 0, 0, 0)
-
-#define ergo_verbose0(_tag_, _action_, _extra_format_)                  \
-  ergo_verbose_common(_tag_, _action_, _extra_format_, 0, 0, 0, 0, 0, 0)
-
-#define ergo_verbose1(_tag_, _action_, _extra_format_,                  \
-                      _arg0_)                                           \
-  ergo_verbose_common(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, 0, 0, 0, 0, 0)
-
-#define ergo_verbose2(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_)                                   \
-  ergo_verbose_common(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_, 0, 0, 0, 0)
-
-#define ergo_verbose3(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_, _arg2_)                           \
-  ergo_verbose_common(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_, _arg2_, 0, 0, 0)
-
-#define ergo_verbose4(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_, _arg2_, _arg3_)                   \
-  ergo_verbose_common(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_, _arg2_, _arg3_, 0, 0)
-
-#define ergo_verbose5(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_, _arg2_, _arg3_, _arg4_)           \
-  ergo_verbose_common(_tag_, _action_, _extra_format_,                  \
-                      _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, 0)
-
 #define ergo_verbose6(_tag_, _action_, _extra_format_,                  \
                       _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_)   \
   ergo_verbose_common(_tag_, _action_, _extra_format_,                  \
                       _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_)
 
+#define ergo_verbose5(_tag_, _action_, _extra_format_,                  \
+                      _arg0_, _arg1_, _arg2_, _arg3_, _arg4_)           \
+  ergo_verbose6(_tag_, _action_, _extra_format_ "%s",                   \
+                _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, "")
+
+#define ergo_verbose4(_tag_, _action_, _extra_format_,                  \
+                      _arg0_, _arg1_, _arg2_, _arg3_)                   \
+  ergo_verbose5(_tag_, _action_, _extra_format_ "%s",                   \
+                _arg0_, _arg1_, _arg2_, _arg3_, "")
+
+#define ergo_verbose3(_tag_, _action_, _extra_format_,                  \
+                      _arg0_, _arg1_, _arg2_)                           \
+  ergo_verbose4(_tag_, _action_, _extra_format_ "%s",                   \
+                _arg0_, _arg1_, _arg2_, "")
+
+#define ergo_verbose2(_tag_, _action_, _extra_format_,                  \
+                      _arg0_, _arg1_)                                   \
+  ergo_verbose3(_tag_, _action_, _extra_format_ "%s",                   \
+                _arg0_, _arg1_, "")
+
+#define ergo_verbose1(_tag_, _action_, _extra_format_,                  \
+                      _arg0_)                                           \
+  ergo_verbose2(_tag_, _action_, _extra_format_ "%s",                   \
+                _arg0_, "")
+
+
+#define ergo_verbose0(_tag_, _action_, _extra_format_)                  \
+  ergo_verbose1(_tag_, _action_, _extra_format_ "%s",                   \
+                "")
+
+#define ergo_verbose(_tag_, _action_)                                   \
+  ergo_verbose0(_tag_, _action_, "")
+
+
 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP
--- a/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2021, 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
@@ -401,7 +401,9 @@
   start_array()->set_covered_region(new_memregion);
   Universe::heap()->barrier_set()->resize_covered_region(new_memregion);
 
-  // ALWAYS do this last!!
+  // The update of the space's end is done by this call.  As that
+  // makes the new space available for concurrent allocation, this
+  // must be the last step when expanding.
   object_space()->initialize(new_memregion,
                              SpaceDecorator::DontClear,
                              SpaceDecorator::DontMangle);
--- a/src/share/vm/gc_implementation/shared/mutableSpace.cpp	Tue Mar 16 08:08:47 2021 +0000
+++ b/src/share/vm/gc_implementation/shared/mutableSpace.cpp	Wed Mar 17 20:41:55 2021 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2021, 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
@@ -28,6 +28,7 @@
 #include "gc_implementation/shared/mutableSpace.hpp"
 #include "gc_implementation/shared/spaceDecorator.hpp"
 #include "oops/oop.inline.hpp"
+#include "runtime/orderAccess.hpp"
 #include "runtime/safepoint.hpp"
 #include "runtime/thread.hpp"
 #endif // INCLUDE_ALL_GCS
@@ -124,7 +125,11 @@
   }
 
   set_bottom(mr.start());
-  set_end(mr.end());
+  // When expanding concurrently with callers of cas_allocate, setting end
+  // makes the new space available for allocation by other threads.  So this
+  // assignment must follow all other configuration and initialization that
+  // might be done for expansion.
+  OrderAccess::release_store_ptr(end_addr(), mr.end());
 
   if (clear_space) {
     clear(mangle_space);
@@ -192,7 +197,11 @@
 // This version is lock-free.
 HeapWord* MutableSpace::cas_allocate(size_t size) {
   do {
-    HeapWord* obj = top();
+    // Read top before end, else the range check may pass when it shouldn't.
+    // If end is read first, other threads may advance end and top such that
+    // current top > old end and current top + size > current end.  Then
+    // pointer_delta underflows, allowing installation of top > current end.
+    HeapWord* obj = (HeapWord*)OrderAccess::load_ptr_acquire(top_addr());
     if (pointer_delta(end(), obj) >= size) {
       HeapWord* new_top = obj + size;
       HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/rangechecks/TestRangeCheckExceptionHandlerLoop.jasm	Wed Mar 17 20:41:55 2021 +0000
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+super public class TestRangeCheckExceptionHandlerLoop
+	version 51:0
+{
+
+
+public Method "<init>":"()V"
+	stack 1 locals 1
+{
+		aload_0;
+		invokespecial	Method java/lang/Object."<init>":"()V";
+		return;
+}
+
+/* This method has an irreducible loop, with 2 entries, one is the exception handler
+
+    static void test(boolean flag, int[] array, Exception exception) throws Exception {
+        int i = 0;
+        if (flag) {
+            try {
+                throw exception;
+            } catch(Exception e) {
+                array[i] = 0;
+                i++;
+            }
+        }
+        if (i < 10) {
+            throw exception; // caught by exception handler above as well
+        }
+    }
+*/
+public static Method test:"(Z[ILjava/lang/Exception;)V"
+	throws java/lang/Exception
+	stack 3 locals 5
+{
+		iconst_0;
+		istore_3;
+		iload_0;
+		ifeq	L17;
+		try t0;
+		aload_2;
+		athrow;
+		endtry t0;
+		catch t0 java/lang/Exception;
+		catch t1 java/lang/Exception;
+		stack_frame_type full;
+		locals_map int, class "[I", class java/lang/Exception, int;
+		stack_map class java/lang/Exception;
+		astore	4;
+		aload_1;
+		iload_3;
+		iconst_0;
+		iastore;
+		iinc	3, 1;
+	L17:	stack_frame_type same;
+		iload_3;
+		bipush	10;
+		if_icmpge	L25;
+		try t1;
+		aload_2;
+		athrow;
+		endtry t1;
+	L25:	stack_frame_type same;
+		return;
+}
+} // end Class TestRangeCheckExceptionHandlerLoop
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/rangechecks/TestRangeCheckExceptionHandlerLoopMain.java	Wed Mar 17 20:41:55 2021 +0000
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @bug 8134883
+ * @summary C1's range check elimination breaks with a non-natural loop that an exception handler as one entry
+ * @compile TestRangeCheckExceptionHandlerLoop.jasm
+ * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestRangeCheckExceptionHandlerLoopMain
+ */
+
+public class TestRangeCheckExceptionHandlerLoopMain {
+    public static void main(String[] args) throws Exception {
+        Exception exception = new Exception();
+        int[] array = new int[10];
+        for (int i = 0; i < 20000; i++) {
+            TestRangeCheckExceptionHandlerLoop.test(false, array, exception);
+        }
+    }
+}
--- a/test/gc/survivorAlignment/TestPromotionFromSurvivorToTenuredAfterMinorGC.java	Tue Mar 16 08:08:47 2021 +0000
+++ b/test/gc/survivorAlignment/TestPromotionFromSurvivorToTenuredAfterMinorGC.java	Wed Mar 17 20:41:55 2021 +0000
@@ -96,11 +96,18 @@
                 .getActualMemoryUsage();
 
         test.allocate();
-        for (int i = 0; i <= SurvivorAlignmentTestMain.MAX_TENURING_THRESHOLD;
-             i++) {
+        for (int i = 0; i <= SurvivorAlignmentTestMain.MAX_TENURING_THRESHOLD; i++) {
             SurvivorAlignmentTestMain.WHITE_BOX.youngGC();
         }
 
+        // Sometimes we see that data unrelated to the test has been allocated during
+        // the loop. This data is included in the expectedMemoryUsage since we look
+        // through all threads to see what they allocated. If this data is still in
+        // the survivor area however, it should not be included in expectedMemoryUsage
+        // since the verification below only look at what's in tenured space.
+        expectedMemoryUsage -= SurvivorAlignmentTestMain.getAlignmentHelper(
+                                   SurvivorAlignmentTestMain.HeapSpace.SURVIVOR)
+                                   .getActualMemoryUsage();
         test.verifyMemoryUsage(expectedMemoryUsage);
     }
 }