src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp

Wed, 14 Oct 2020 17:44:48 +0800

author
aoqi
date
Wed, 14 Oct 2020 17:44:48 +0800
changeset 9931
fd44df5e3bc3
parent 9465
1556c6d89036
parent 9858
b985cbb00e68
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2002, 2014, 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  *
    23  */
    25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
    26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
    28 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
    29 #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
    30 #include "gc_implementation/parallelScavenge/psPromotionLAB.inline.hpp"
    31 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
    32 #include "oops/oop.psgc.inline.hpp"
    34 inline PSPromotionManager* PSPromotionManager::manager_array(int index) {
    35   assert(_manager_array != NULL, "access of NULL manager_array");
    36   assert(index >= 0 && index <= (int)ParallelGCThreads, "out of range manager_array access");
    37   return &_manager_array[index];
    38 }
    40 template <class T>
    41 inline void PSPromotionManager::claim_or_forward_internal_depth(T* p) {
    42   if (p != NULL) { // XXX: error if p != NULL here
    43     oop o = oopDesc::load_decode_heap_oop_not_null(p);
    44     if (o->is_forwarded()) {
    45       o = o->forwardee();
    46       // Card mark
    47       if (PSScavenge::is_obj_in_young(o)) {
    48         PSScavenge::card_table()->inline_write_ref_field_gc(p, o);
    49       }
    50       oopDesc::encode_store_heap_oop_not_null(p, o);
    51     } else {
    52       push_depth(p);
    53     }
    54   }
    55 }
    57 template <class T>
    58 inline void PSPromotionManager::claim_or_forward_depth(T* p) {
    59   assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
    60   assert(Universe::heap()->kind() == CollectedHeap::ParallelScavengeHeap,
    61          "Sanity");
    62   assert(Universe::heap()->is_in(p), "pointer outside heap");
    64   claim_or_forward_internal_depth(p);
    65 }
    67 inline void PSPromotionManager::promotion_trace_event(oop new_obj, oop old_obj,
    68                                                       size_t obj_size,
    69                                                       uint age, bool tenured,
    70                                                       const PSPromotionLAB* lab) {
    71   // Skip if memory allocation failed
    72   if (new_obj != NULL) {
    73     const ParallelScavengeTracer* gc_tracer = PSScavenge::gc_tracer();
    75     if (lab != NULL) {
    76       // Promotion of object through newly allocated PLAB
    77       if (gc_tracer->should_report_promotion_in_new_plab_event()) {
    78         size_t obj_bytes = obj_size * HeapWordSize;
    79         size_t lab_size = lab->capacity();
    80         gc_tracer->report_promotion_in_new_plab_event(old_obj->klass(), obj_bytes,
    81                                                       age, tenured, lab_size);
    82       }
    83     } else {
    84       // Promotion of object directly to heap
    85       if (gc_tracer->should_report_promotion_outside_plab_event()) {
    86         size_t obj_bytes = obj_size * HeapWordSize;
    87         gc_tracer->report_promotion_outside_plab_event(old_obj->klass(), obj_bytes,
    88                                                        age, tenured);
    89       }
    90     }
    91   }
    92 }
    94 //
    95 // This method is pretty bulky. It would be nice to split it up
    96 // into smaller submethods, but we need to be careful not to hurt
    97 // performance.
    98 //
    99 template<bool promote_immediately>
   100 oop PSPromotionManager::copy_to_survivor_space(oop o) {
   101   assert(PSScavenge::should_scavenge(&o), "Sanity");
   103   oop new_obj = NULL;
   105 #if defined MIPS && !defined ZERO
   106   if (UseSyncLevel >= 2000) OrderAccess::fence();
   107 #endif
   109   // NOTE! We must be very careful with any methods that access the mark
   110   // in o. There may be multiple threads racing on it, and it may be forwarded
   111   // at any time. Do not use oop methods for accessing the mark!
   112   markOop test_mark = o->mark();
   114 #if defined MIPS && !defined ZERO
   115   if (UseSyncLevel >= 2000) OrderAccess::fence();
   116 #endif
   118   // The same test as "o->is_forwarded()"
   119   if (!test_mark->is_marked()) {
   120     bool new_obj_is_tenured = false;
   121     size_t new_obj_size = o->size();
   123     // Find the objects age, MT safe.
   124     uint age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
   125       test_mark->displaced_mark_helper()->age() : test_mark->age();
   127     if (!promote_immediately) {
   128       // Try allocating obj in to-space (unless too old)
   129       if (age < PSScavenge::tenuring_threshold()) {
   130         new_obj = (oop) _young_lab.allocate(new_obj_size);
   131         if (new_obj == NULL && !_young_gen_is_full) {
   132           // Do we allocate directly, or flush and refill?
   133           if (new_obj_size > (YoungPLABSize / 2)) {
   134             // Allocate this object directly
   135             new_obj = (oop)young_space()->cas_allocate(new_obj_size);
   136             promotion_trace_event(new_obj, o, new_obj_size, age, false, NULL);
   137           } else {
   138             // Flush and fill
   139             _young_lab.flush();
   141             HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
   142             if (lab_base != NULL) {
   143               _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
   144               // Try the young lab allocation again.
   145               new_obj = (oop) _young_lab.allocate(new_obj_size);
   146               promotion_trace_event(new_obj, o, new_obj_size, age, false, &_young_lab);
   147             } else {
   148               _young_gen_is_full = true;
   149             }
   150           }
   151         }
   153 #if defined MIPS && !defined ZERO
   154         if (UseSyncLevel >= 2000) OrderAccess::fence();
   155 #endif
   156       }
   157     }
   159     // Otherwise try allocating obj tenured
   160     if (new_obj == NULL) {
   161 #ifndef PRODUCT
   162       if (Universe::heap()->promotion_should_fail()) {
   163         return oop_promotion_failed(o, test_mark);
   164       }
   165 #endif  // #ifndef PRODUCT
   167       new_obj = (oop) _old_lab.allocate(new_obj_size);
   168       new_obj_is_tenured = true;
   170       if (new_obj == NULL) {
   171         if (!_old_gen_is_full) {
   172           // Do we allocate directly, or flush and refill?
   173           if (new_obj_size > (OldPLABSize / 2)) {
   174             // Allocate this object directly
   175             new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
   176             promotion_trace_event(new_obj, o, new_obj_size, age, true, NULL);
   177           } else {
   178             // Flush and fill
   179             _old_lab.flush();
   181             HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
   182             if(lab_base != NULL) {
   183 #ifdef ASSERT
   184               // Delay the initialization of the promotion lab (plab).
   185               // This exposes uninitialized plabs to card table processing.
   186               if (GCWorkerDelayMillis > 0) {
   187                 os::sleep(Thread::current(), GCWorkerDelayMillis, false);
   188               }
   189 #endif
   190               _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
   191               // Try the old lab allocation again.
   192               new_obj = (oop) _old_lab.allocate(new_obj_size);
   193               promotion_trace_event(new_obj, o, new_obj_size, age, true, &_old_lab);
   194             }
   195           }
   196         }
   198         // This is the promotion failed test, and code handling.
   199         // The code belongs here for two reasons. It is slightly
   200         // different than the code below, and cannot share the
   201         // CAS testing code. Keeping the code here also minimizes
   202         // the impact on the common case fast path code.
   204         if (new_obj == NULL) {
   205           _old_gen_is_full = true;
   206           return oop_promotion_failed(o, test_mark);
   207         }
   208       }
   209     }
   211     assert(new_obj != NULL, "allocation should have succeeded");
   213     // Copy obj
   214     Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size);
   215 #if defined MIPS && !defined ZERO
   216     if (UseSyncLevel >= 2000) OrderAccess::fence();
   217 #endif
   219     // Now we have to CAS in the header.
   220     if (o->cas_forward_to(new_obj, test_mark)) {
   221       // We won any races, we "own" this object.
   222       assert(new_obj == o->forwardee(), "Sanity");
   224       // Increment age if obj still in new generation. Now that
   225       // we're dealing with a markOop that cannot change, it is
   226       // okay to use the non mt safe oop methods.
   227       if (!new_obj_is_tenured) {
   228         new_obj->incr_age();
   229         assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj");
   230       }
   232       // Do the size comparison first with new_obj_size, which we
   233       // already have. Hopefully, only a few objects are larger than
   234       // _min_array_size_for_chunking, and most of them will be arrays.
   235       // So, the is->objArray() test would be very infrequent.
   236       if (new_obj_size > _min_array_size_for_chunking &&
   237           new_obj->is_objArray() &&
   238           PSChunkLargeArrays) {
   239         // we'll chunk it
   240         oop* const masked_o = mask_chunked_array_oop(o);
   241         push_depth(masked_o);
   242         TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes);
   243       } else {
   244         // we'll just push its contents
   245         new_obj->push_contents(this);
   246       }
   247     }  else {
   248       // We lost, someone else "owns" this object
   249       guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed.");
   251       // Try to deallocate the space.  If it was directly allocated we cannot
   252       // deallocate it, so we have to test.  If the deallocation fails,
   253       // overwrite with a filler object.
   254       if (new_obj_is_tenured) {
   255         if (!_old_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
   256           CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
   257         }
   258       } else if (!_young_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
   259         CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
   260       }
   262       // don't update this before the unallocation!
   263       new_obj = o->forwardee();
   264     }
   266 #if defined MIPS && !defined ZERO
   267     if (UseSyncLevel >= 2000) OrderAccess::fence();
   268 #endif
   269   } else {
   270     assert(o->is_forwarded(), "Sanity");
   271     new_obj = o->forwardee();
   272   }
   274 #ifndef PRODUCT
   275   // This code must come after the CAS test, or it will print incorrect
   276   // information.
   277   if (TraceScavenge) {
   278     gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (%d)}",
   279        PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring",
   280        new_obj->klass()->internal_name(), p2i((void *)o), p2i((void *)new_obj), new_obj->size());
   281   }
   282 #endif
   284   return new_obj;
   285 }
   288 inline void PSPromotionManager::process_popped_location_depth(StarTask p) {
   289   if (is_oop_masked(p)) {
   290     assert(PSChunkLargeArrays, "invariant");
   291     oop const old = unmask_chunked_array_oop(p);
   292     process_array_chunk(old);
   293   } else {
   294     if (p.is_narrow()) {
   295       assert(UseCompressedOops, "Error");
   296       PSScavenge::copy_and_push_safe_barrier<narrowOop, /*promote_immediately=*/false>(this, p);
   297     } else {
   298       PSScavenge::copy_and_push_safe_barrier<oop, /*promote_immediately=*/false>(this, p);
   299     }
   300   }
   301 }
   303 #if TASKQUEUE_STATS
   304 void PSPromotionManager::record_steal(StarTask& p) {
   305   if (is_oop_masked(p)) {
   306     ++_masked_steals;
   307   }
   308 }
   309 #endif // TASKQUEUE_STATS
   311 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP

mercurial